Hi Dooley,
Do you have any general tips on reducing function complexity?
I'm dealing with the same issues, since a RTS gots tons of functions with loops.
For analyzing which part of the functions took most time to calculate I used dtimer() and displayed the time on screen.
void* gameloop()
{
...
dtimer();
check_unit_integrity();
time_unit_loop = dtimer();
dtimer();
levelloop();
time_level_loop = dtimer();
...
}
function show_info_txt()
{
STRING* s1 = " ";
...
str_for_num(s1, time_unit_loop);
draw_text("Rechenzeit Unitloop", 10, 275, WHITE);
draw_text(s1, 140, 275, WHITE);
str_for_num(s1, time_units);
draw_text("Rechenzeit Einheiten", 10, 315, WHITE);
draw_text(s1, 140, 315, WHITE);
...
}
Searching structures took most of the execution time, so I would start from there. At start I even used ent_next to search for specific entities, obviously that takes a lot of time. Saving specific objects (like the units) in its own search lists saved a lot of time for me:
//search list for units
int no_of_units;
int max_units = 256;
UNIT_STRUCT unit[256];
//search list for buildings
int no_of_buildings = 0;
int max_buildings = 64;
ENTITY* building_array[64];
...
Another thing you might consider is to "update" some functions less frequently (not every frame, but every other frame or even less frequent).
Best regards