Author Topic: Critique my various animation techniques  (Read 368 times)

DarkKobold

  • Hero Member
  • *****
  • Posts: 1200
Critique my various animation techniques
« on: December 21, 2016, 08:45:10 AM »
Difficulty - No "Assembly is better"

In our final level, we are using a lot of animations. Big sprites moving around. Lots of combined animations to step through. However, since there is no player input, we don't need to care too much about CPU usage, more just code size.

In reality, I was just curious what people thought of the two techniques I'm alternating between.

#1
char animstate, animtimer;
animtimer = 30;
for (i=0; i < 120; i++)
{
animtimer--;
if (!animtimer)
{  if (!animstate)
    { do stuffs(0)
       animstate = 1;
    }
    else
   {
      do stuffs(1)
       animstate = 0;
  }
 animtimer = 30;
}
 do other stuffs
 vsync();
}

#2

for (i=0; i < 120; i++)
{
if (!(i%60))

   do stuffs(1)
  }
else if (!(i%30))
{
 do stuffs(0)
}
 do other stuffs
 vsync();
}

I really like #2, because its super fast to write, and doesn't require a whole lot of extra variables to keep track of. I have this feeling that (!(i%X)) generates nasty assembly code.
Hey, you.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Critique my various animation techniques
« Reply #1 on: December 21, 2016, 03:44:00 PM »
For the !(i%60) part, I think you can do:
 if(i== 60 || i==0)

 And for !(i%30)
 if(i==90 ||  i==30 )

 Because of your else if, cases of 60 and 0 won't trigger on the i%30 part. And 120 is never a case because the loop maxes at 119.

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: Critique my various animation techniques
« Reply #2 on: December 23, 2016, 08:00:52 PM »
Approach 1 can be simplified assuming stuffs() is indeed a single function that takes in a variable:

Code: [Select]
char animstate, animtimer;

for (i=0, animtimer = 30; i < 120; i++,animtimer--)
{
if (!animtimer)

dostuffs(animstate);
animstate ^= 1; /* this will toggle animstate every 30 frames, like you want */
animtimer = 30;
}
do other stuffs
vsync();
}

you might not be allowed to do multiple variables in a forloop in HuC.  I can't remember if it's possible.

If it doesn't let you, just move animtimer back out of the loop to define it, and decrement it at the start of the loop.


Approach #2 is no longer relevant, because Approach #1 is now easier to write, and I think will also be faster.  I am not 100% sure on the speed without seeing what HuC actually does for the two.

Using what Tom said for your second approach is probably the best idea unless you want to setup a jump table instead.



[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.