Wednesday, December 30, 2009

ViruZ update 7

I still tweaked the render-code a bit today. Well, for threaded drawing at least.
I have a loop, in which I update and then draw the viruses. The mutex is only required for drawing, that's why I didn't put both in one function.
I also can then update while the window should not be drawn (e.g. minimized Window).

So, before I was like

for each(virus) {
  virus.update(dt);
  obtainMutex();
  virus.draw();
  releaseMutex();
}


now it's alike

for each(virus) {
  virus.update(dt);
  while(!tryObtainingMutex()) {
    queue.push(virus);
    virus = next_virus;
    virus.update(dt);
  }
  queue.push(virus);
  //we have the mutex now
  for each(virus in queue)
    virus.draw();
  releaseMutex();
}
if(!queue.empty()) {
  obtainMutex();
  for each(virus in queue)
    virus.draw();
  releaseMutex();
}


It's much more code, but I still got 10-20 more FPS out of it on my dual-core.
I also cleaned the thread-class. I guess I'm gonna keep it.

I also implemented the serum. Well, partly. Mostly just the drawing- and animation-part.
Sadly the FPS get cut in half while drawing it D:
I guess I'm doing something wrong.. but I'll get behind that at another time.

No comments: