Enumerator for Spine Strings Names?

obscene

Member
Was just thinking while away from my work PC... is it bad that I have a TON of instances in my game where I'm comparing animation names ( animation_get / animation_set ) , or getting skeleton bone data which are also strings ( ds_map_find_value(map, "worldX") )?

Should I set up all animation names as enumerators like anim_run="Run"? (That should work)

Would it even work to set up something like worldX="worldX" in an enumerator? (Probably will not work)
 
I

Insanebrio

Guest
I dont think that spine functions takes all that CPU, since (tecnically) game maker should load at the start of every step in the RAM all the datas to draw the sprite (which is composed by pieces that are rotated or deformed), so the functions should simply pick those values from the ram without having to make other CPU calculation. And even if increases your CPU usage, it will not have an impact like collisions, physics or surfaces. Of course having something like

var animation = skeleton_animation_get()
if (animation=="animation1") ...
if (animation=="animation2") ...
if (animation=="animation3") ...

is much better than something like

if (skeleton_animation_get()=="animation1") ...
if (skeleton_animation_get()=="animation2") ...
if (skeleton_animation_get()=="animation3") ...
 

obscene

Member
var animation = skeleton_animation_get()
This I do. Actually now that I'm home I'm looking in the profiler and here's what I see....

upload_2016-12-5_16-2-47.png


I think strings definitely have an impact but nothing as bad as ds_map_clear.....

Code:
for (i=1; i<segments+1; i++)
    {
    var bone="Arm Segment Bone "+string(i);
    skeleton_bone_state_get(bone, map);                 
    var xx=ds_map_find_value(map, "worldX");           
    var yy=ds_map_find_value(map, "worldY"); 
    var aa=ds_map_find_value(map, "worldAngle");   
    array[i].x=x+xx;
    array[i].y=y+yy;
    array[i].image_angle=aa*image_xscale;
    if (alpha) array[i].fx_alpha=fx_alpha;                                 
    ds_map_clear(map);   
    }
I've gotta find a way to optimize this better. Basically I have a bunch of tentacles where each segment is an object with it's own mask that can be destroyed. Spine is only being used to get the bone data and not draw itself so that I can position the segments.
 
I

Insanebrio

Guest
Try creating the dsmap 'map' at the start of the for cycle, and destroy it (instead of clearing it) at the end. Not sure but maybe destroying the map could be faster than clearing it.
 

obscene

Member
Try creating the dsmap 'map' at the start of the for cycle, and destroy it (instead of clearing it) at the end. Not sure but maybe destroying the map could be faster than clearing it.
I tested it (after changing these to update every other frame)

upload_2016-12-5_17-52-36.png

upload_2016-12-5_17-52-43.png

Definitely faster to clear than to create/destroy.

EDIT: I pre-created an array of bone names instead of adding i to the string each step (
var bone="Arm Segment Bone "+string(i); ) and that cut off an extra 2% :p
 
Last edited:
S

SyntaxError

Guest
Presumably, you are clearing the map and re-adding data to it, which are probably updates for the co-ords for each segment. Is clearing it really necessary, can't you just update the map entries and forgo the clearing all together?

EDIT: I just looked up skeleton_bone_state_get. I seems like you may be able to forgo the clear after reading it as it reads the same keys each time, so they should effectively be updated with each read.

For extra speed, change those ds_map_find_values to use accessors.
 
Last edited by a moderator:

rIKmAN

Member
EDIT: I just looked up skeleton_bone_state_get. I seems like you may be able to forgo the clear after reading it as it reads the same keys each time, so they should effectively be updated with each read.
I assumed this when first using GM and Spine, but unfortunately unless you clear the map then it just sticks with the information from the first frame of the animation.

No idea why it doesn't overwrite the existing info as the keys are the same each time, but that's what happens and I think it was obscene who told me this in the thread I made as I was thinking along the same lines as you - it didn't make sense to me either and it still doesn't now!
 

obscene

Member
Yeah, traveled that road already. This is a big annoyance in spine that you can't just reuse the map without clearing it.

Where I stand currently with this particular object, the biggest drain by far, above and beyond the drawing of a few hundred tentacle segment sprites... is the dang map clearing.

upload_2016-12-5_20-11-49.png

Code:
if frame
    {   
    for (i=1; i<segments+1; i++)
        {
        skeleton_bone_state_get(bone_name[i], map);               
        var xx=x+ds_map_find_value(map, "worldX");           
        var yy=y+ds_map_find_value(map, "worldY"); 
        var aa=ds_map_find_value(map, "worldAngle")*image_xscale;   
        with array[i]
            {
            x=xx;
            y=yy;
            image_angle=aa
            }                             
        ds_map_clear(map);   
        }
    }
frame=1-frame
 
Last edited:
S

SyntaxError

Guest
Instead of generating this each frame, could you get the data once at creation and load it into a 2d array and use the frame number to reference the array? Or is the animation dynamic in some way?
 

obscene

Member
Now there's an idea. Some animations are dynamic, some are not.... but absolutely some potential in that idea. Thanks!
 

JaimitoEs

Member
Surely your project is already very big and advanced, but if you have any plans to porting your game in GMS2, you can get a great boost performance with Spine functions, and no memory leaks on this like the current GM1.x. I´ve tested this few days ago..
 
Last edited:

obscene

Member
I've thought about it but with the removal of backgrounds and all the many now obsolete functions I think it would take months to change it over. Plus I just like GM the way it is :p Until I can maximize my code window I'm holding out.
 
Top