Fast Percentage

Started by
12 comments, last by Jiia 20 years, 1 month ago
My current algorithmic approach is to use a percentage of a character''s current stamina points to increase time delay on his animation frames. Trivial, perhaps. But there may be well into the hundreds of characters changing frames every 30 milliseconds.

I don''t see how another algorithm will help me.

I can''t count the number of professional games I''ve played that slow down when the enemies begin to mass around you. Do these companies not profile and improve the biggest bottlenecks? Or did they just ignore too many small bottlenecks?

Although using the 128 or 256 based percentage would be a bit difficult to read, just defining a 100-based GETPERCENT(cur,max) which shifts things around is not.

If it''s about wasting time thinking about small details, I waste far more time typing on forums
Advertisement
quote:Original post by Jiia
My current algorithmic approach is to use a percentage of a character''s current stamina points to increase time delay on his animation frames. Trivial, perhaps. But there may be well into the hundreds of characters changing frames every 30 milliseconds.

I don''t see how another algorithm will help me.

I can''t count the number of professional games I''ve played that slow down when the enemies begin to mass around you. Do these companies not profile and improve the biggest bottlenecks? Or did they just ignore too many small bottlenecks?


To be honest I don''t see a percentage calculation being your major bottle-neck; things I''d worry about more are say the AI for NPCs, the physics engine and the overall renderer.

What I was trying to get at earlier is that you should be examining the higher [than percentage calculation] level algorithms.

If you''re really keen on going as low level as possible I seem to remember that the AAD instruction on the x86 can be hacked to do division to an arbirary (small, < 1 byte) denominator.

WRT professional games, don''t forget they are making an engineering decision about when the game will run sufficiently well on most user systems, because they need to get it out of the door as quickly as possible to start making money, where as the longer they keep it in development the more money it costs them. So yes, they will optimise the game as much as possible, starting with the largest bottlenecks and working down until the remaining bottlenecks are so small they don''t impact too severly on most consumers (note: this still means that it might be acceptible for a consumer to have a noticable, but not game degrading, slowdown for perhaps one or two climatic points in the game)
quote:Original post by Jiia
If it''s about wasting time thinking about small details
It is; time spent on very small optimizations is time not spent on more important optimizations.

Furthermore, there is another reason why we say "Make it work, then make it fast"; clarity of intent. 34 / 2 is much clearer than 34 >> 1, for instance.

Cédric
Hrm, animation frames eh? I can see the need for using a faster algorythm. However, there may be a better algorythm than using percentages.

For instance. Lets assume that we want Stamina 20 to be twice as fast as Stamina 10. And Stamina 40 to be twice as fast as 20. What we do first is find who has the fastest stamina, through a quick search you can perform during the fade in of the level. Make that number accessable for all objects. Lets assume its 40. Next, every object gets a frame counter, and a frame wait meter. Then, for all objects, do like so:
FrameWaitMeter += Stamina ;if ( FrameWaitMeter > MaxLevelStamina ) {  FrameWaitMeter -= MaxLevelStamina ;  FrameCounter += 1 ;} 


1 addition and cmp/jmp operator, with perhaps an extra sub and add operator, depending on the stamina of the object.
william bubel

This topic is closed to new replies.

Advertisement