Author Topic: ExtendedObjects and Animate library  (Read 14765 times)

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
ExtendedObjects and Animate library
« on: June 04, 2014, 08:38:55 PM »
This is a set of extensions I am working on for Attract-Mode:

https://github.com/liquid8d/attract-extra/tree/master/layouts/extended

I say extensions because it's a set of .nut files that can be added to any layout that will extend the capabilities of AM.

ExtendedObjects
Currently, ExtendedObjects is primarily a wrapper around the current Fe.Text, Fe.Image, Fe.ListBox objects with some helper functions to  make it easier to work with your layout objects.

ExtendedObjects has the typical .add_text, .add_image, .add_artwork, and .add_listbox functions, just with an addition of an object id as the first parameter. Returned to you is a new class of that object: ExtendedText, ExtendedImage, ExtendedArtwork and ExtendedListBox. One major difference in these new classes is you don't get or set variables directly:
obj.x becomes obj.getX() or obj.setX(x)
obj.y becomes obj.getY() or obj.setY(y)
...

This is so the extended objects class can do some stuff whenever variables are changed. My initial reason for doing this was to add animation to the objects (modify x and y), but it kind of grew from there.

Benefits

Custom Objects:
You can extend the new classes which not only will take advantage of the additions of ExtendedObjects but allow you to combine multiple objects as one. This would allow someone to create for instance a full marquee wheel that can then be its own object.

Layers:
With the addition of surfaces in 1.3, ExtendedObjects will create a layered system where you can add objects to different layers. This means you don't have to create objects in the order you want them displayed.

Debugging System:
I wrote a debug system that makes use of ExtendedObjects. When enabled, text boxes are overlayed over every object in your layout which can help with debugging.

Positioning:
A full set of functions to help you position objects, you can use something like obj.setPosition("center") instead of having to do something like (fe.layout.width / 2) - (obj.width / 2), (fe.layout.height / 2) - (obj.height / 2)

Animations:
Why I originally wrote this, you can add animation effects to any object.

Animation
As I played with the onTick and onTransition functions and looked at examples, I saw how powerful it could be. I thought it would be a pain to create some animation effects every time I wanted something in a layout, so I began building the animate extension.

I did a lot of research to get animation working, since I know very little about it :) I had to write a custom onTick and onTransition to handle everything and it includes all kinds of neat easing functions. Everything is pretty much done by just telling it which object to animate and providing a config table. It looks like this:

Code: [Select]
local animConfig = {
   which = "translate",
   when = Transition.FromOldSelection,
   duration = 1500,
   from = "offleft",
   to = "left"
}
obj.animate(animConfig);

Benefits

Builtin easing functions:
You can specify the animation "effects" using the easing and tween config options. For examples, you can look at something like:
http://matthewlein.com/experiments/easing.html

Pre-included animations:
I have two currently, property and translate. Property animates a property (like alpha, skew, size or rotation) and translate moves objects.

Custom animations:
I have a boiler-plate template for creating your own animations where all you initialize, then handle start, frame and stop functions. There is an example animations on github to check out.

Animation sets:
I haven't done much with this yet, but intend on creating some already put together configs for common animations, for instance fade out a snapshot on transition, then fade it back in.

Particle animations:
A new animation I am working on which will essentially mirror the particle effects of HyperTheme. It's pretty cool.

Feedback
I'm still trying to figure out what all to do with this thing, but I want it to be user friendly and provide helpful functions to make creating layouts easier. If you get a chance to play around with it, I'd love to hear some feedback. It's fairly well documented on the github page, but as I make changes, some things might not have been updated. Let me know if you have any issues or questions!

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #1 on: June 04, 2014, 10:48:32 PM »
hi liquid8d,

one other thing that got added in 1.3 and that hopefully helps your project is the "fe.add_module()" command.  The idea is that if you put your ExtendedObjects.nut file in a subdirectory named "modules" in the attract mode config dir, then layout and plugins can load it by simply calling 'fe.load_module( "ExtendedObjects" );".  so this provides a consistent way to access common libraries without needing to copy the library files to each layout that uses them.

my goal is to start including libraries like ExtendedObjects and Animate in with future versions of the frontend...

Luke_Nukem

  • Sr. Member
  • ****
  • Posts: 135
    • View Profile
    • Blogging about Rust lang
Re: ExtendedObjects and Animate library
« Reply #2 on: June 05, 2014, 01:45:15 AM »
Wow, top work. I will be looking forward to seeing this in action.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #3 on: June 05, 2014, 03:25:21 PM »
raygun,

That sounds great, I'll definitely take a look at it.. at some point once it's a little more polished, I want to make sure it is as easy as possible to add in. I wonder does that conflict or overlap with plugins? Something to think about.

Luke,
Thanks! Looking forward to some people trying it out.

It still has a few kinks to work out..  the addition of system should be extremely helpful with clock() because I was having to do a workaround on tracking animation times between onTick (which stops while onTransition returns true) and onTransition :)

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #4 on: June 10, 2014, 09:51:26 PM »
raygun,

That sounds great, I'll definitely take a look at it.. at some point once it's a little more polished, I want to make sure it is as easy as possible to add in. I wonder does that conflict or overlap with plugins? Something to think about.

it shouldn't conflict.  all its really doing is adding a common place to store code libraries that are easily accessible to both layouts and plugins

cools

  • Full Member
  • ***
  • Posts: 83
  • Arcade Otaku Sysadmin
    • View Profile
    • Arcade Otaku
Re: ExtendedObjects and Animate library
« Reply #5 on: July 03, 2014, 05:41:14 AM »
add_surface definitely required.

If everything is drawn onto a surface it makes it easy to do whole screen effects and transitions.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #6 on: November 14, 2014, 11:12:16 PM »
I'm baaaacckkk .. :) Finally. I had other projects and things to work on, but very excited that a lot of cool new things are popping up in 1.4 and looks like interest is picking up. Hopefully the interest is still there with what this can add to layouts.

Since I haven't got to touch this in a while, I will have a look at moving to a module and start working on some improvements. I still had some kinks to work out last I checked.

After I work out a few things, I would like to get some feedback on how best to continue with this in a module form - whether certain parts should be broken up into separate modules or if I should just keep everything together in one. I also don't want to expand too much on some parts of this if having extended class objects (via modules) is something that will be more streamlined in future versions.

cools, I know that I was working to use surfaces as that was still new when I .. suspended .. work on this. I'll check back when I remember where I left off.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #7 on: November 15, 2014, 11:23:59 AM »
So a couple questions regarding modules...

Can modules use do_nut()? It looks like attract is looking in the layout folder for any files/subdirectories.

Can modules be in a subdirectory and/or have their own subdirectories for included files? For ExtendedObjects, I really need subfolders like layouts support for animations or extensions.

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #8 on: November 15, 2014, 10:23:44 PM »
Welcome back liquid8d!  I was wondering where you disappeared to :)

So a couple questions regarding modules...

Can modules use do_nut()? It looks like attract is looking in the layout folder for any files/subdirectories.

Can modules be in a subdirectory and/or have their own subdirectories for included files? For ExtendedObjects, I really need subfolders like layouts support for animations or extensions.

modules can use do_nut().  I'm pretty sure it only looks in the layout folder if you give it a relative path... you can still use absolute paths or squirrel's dofile() command.  You can have subfolders too... I was mucking around with a copy of your library a while back and managed to get it working as a module with subfolders.  I don't remember if what I've done is any good or a complete hack but I'll attach a copy of what I've got to this message ... maybe it will be of some assistance?

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #9 on: November 15, 2014, 11:06:09 PM »
ah, excellent - I'll take a look! I'm really thinking about re-imagining some of it since I did a bunch before surfaces and modules were introduced.

I will have a bunch of questions upcoming for you :)

First is where did fe.objs (the draw list go)? (GRR.. I realized again its fe.obj not objs)

Part of what I do here is create custom classes that hold the AM object that is created - so ExtendedText creates the fe object with add_text and holds a reference so I can do more with it later. That could (and does) get a little hacky, and if or when people start doing modules for custom objects (like Conveyor) or when new features are added, it has to be hard coded into mine to support it. So I was thinking it might be better to hook into the existing drawlist objects. I already add methods dynamically and think I could do something similar for any methods I want to add to AM objects.

I guess the question is, I want to extend your base object classes and I'm trying to find the best way to do it. What I'm mainly interest in doing is catching when the object is added, so i can either inject methods into it or do something to it when a property changes. Not sure how much of the code you got to look at, any thoughts on how to best accomplish this?
« Last Edit: November 16, 2014, 02:25:24 PM by liquid8d »

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #10 on: November 23, 2014, 10:46:04 PM »
In case anyone else is interested, and also so I can find the discussion later: https://github.com/mickelson/attract/issues/93

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #11 on: November 24, 2014, 03:33:03 PM »
In case anyone else is interested, and also so I can find the discussion later: https://github.com/mickelson/attract/issues/93

There's some good technical info there :) I do want to point out you don't have to override the entire fe object as is explained there if you are wanting to say - create your own objects or add new functions. I have some specific reasons for using that and it can get a bit complex.

There is a bunch of ways you can extend things without having to do that, here's a few examples:

Your own table with helper functions:
Code: [Select]
//helper for positioning
Screen <- {
    center = { x = fe.layout.width / 2, y = fe.layout.height / 2 },
    percent_width = function( p ) { return (p.tofloat() / 100) * fe.layout.width; },
    percent_height = function( p ) { return (p.tofloat() / 100) * fe.layout.height; },
}

print( "center is " + Screen.center.x + "," + Screen.center.y + "\n" );

Add functions into fe:
Code: [Select]
fe.say_hello <- function() {
    print( "Hello\n" );
}

Add functions into an AM object:
Code: [Select]
local myText = fe.add_text( "Inject a function", 0, 0, 300, 30 );
myText.getclass().newmember("fun_stuff", function(str) {
            print ( "This is " + str + "\n" );
        });
myText.fun_stuff( "some fun stuff here" );

Your own class (you would need to add any wrapper methods):
Code: [Select]
class MyCustomText
{
    mObj = null;
    constructor(msg, x, y, w, h)
    {
        mObj = fe.add_text(msg, x, y, w, h);
    }
   
    function hello()
    {
        mObj.msg = "Hello";
    }
}

fe.add_custom_text <- function(msg, x, y, w, h) {
    return MyCustomText(msg, x, y, w, h);
}
//Now anyone that loads your module can use:
fe.add_custom_text("My Custom Text Object", 0, 0, 400, 30);


I'm currently rewriting some of extendedobjects using some of that - once I think it's in good working order, it will be up on my github.

If you have ideas or suggestions, I'd love to hear them.

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: ExtendedObjects and Animate library
« Reply #12 on: December 06, 2014, 03:48:29 PM »
thanks for this, lots of stuff I didn't realize you can do w/ squirrel.  Its too bad the documentation available on it is so limited...