Any Time slicing tips?

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
shadowghost21
Posts: 56
Joined: Wed Nov 23, 2011 11:53 pm

Any Time slicing tips?

Post by shadowghost21 »

I was running into some issues the other day with my framerate dropping because I was running A* on every cell that had data to find if it was connected to another specific cell in my matrix. As I added more nodes the frame rate drop started getting really bad. I have since put in a timer to check in the loop; if it's spent more than a certain amount of time bail out and the next time it enters in the loop it will pick up where it left off. Another thought I had would be to thread the simulation engine that loops over all the cells. I deal with plenty of threading on a daily bases at work (so please none of the usual noob+threads= destroyer of worlds, legit reasons it would or wouldn't work would be greatly appreciated.) I remember a while back at a previous company we wrote the AI in a thread so as to not lock up the GUI. Would the same kind of approach work ? I am working on a inter-object messaging system to hook into my game at the moment.

What are some pointers to time slice the CPU properly when implementing AI, simulation processing, physics, additional graphics, and audio?

I should probably back up and give a little background on my project. It's a cell based grid overlayed on top of a terrain. I have an engine that loops through any cells that have data and performs calculations on them such as checking if one cell is connected to another cell (using A*) I noticed the performance stuttering after I placed about 10-20 cells worth of data.

So people who have already solved these issues, how did you solve and what would you do better in the future? Sorta looking for a bit of a post mortem here I suppose but if you have any ideas I would love to hear them and I am sure it would be good knowledge to throw in the open.
docWild
Posts: 38
Joined: Wed Nov 30, 2011 4:29 pm

Re: Any Time slicing tips?

Post by docWild »

Multithreading is always an option, but you must ensure that tasks are finished before using their data. Some kind of event system is the norm but from the sound of your problem it seems that you need to know which cells are interconnected before you continue. In this case you may want to look into selective processing, i.e only processing the checks which are essential at the time (if that is possible). As an example, you might loop through a sorted list of objects to determine the distance from origin and then break out of the loop when the distance gets too large for you to bother with.

A mix of those two methods is also a possibility.
Post Reply