Original Post
My game has loads of Structs, and for each struct I have allocated many copies of the struct. For example I have a character struct which has about 50 vars...
struct CHARACTER
{
bool bActive;
POINT ptPos;
RECT rcDest;
bla blabla;
bla etc;
};
Then I assign about 100 instances of the same struct ...
CHARACTER Character[100];
Each Character instance is "worked on" at every frame to calculate its new position and velocities etc.. therefore I loop through all the character instances about 5 times each.
When I program, I make sure my functions work, so I dont do any optimizations until it works to my satisfaction.
My problem is when I have over 50-70 characters (depends on the PC) the game loses frames BIG TIME. Obviously I have to optimize my code...
But how?
Question: Many of my functions use alot of temporary variables to do calculations. Is this good?
For example:
UpdateVel(WORD n)
{
float newXVel;
WORD ...
long ...
// Here im using lotza temporary vars,
// minimizing struct vars.
newXVel = Character[n].XVel + 10.0f * Delta;
Character[n].XVel = newXVel;
Character[n].XPos += newXVel;
}
Would it be better to do it this way...
UpdateVel(WORD n)
{
// Here im using no temporary vars, but im
// using more struct vars.
Character[n].XVel = Character[n].XVel + 10.0f * Delta;
Character[n].XPos += Character[n].XVel;
}
What else can I do to optimize my loop even further?