Skip to main content
GameDev.net gamedev.net
🔒 Locked

Level transition - multiple threads problem

Started by satanD Aug 27, 2008 at 5:05 PM 2 replies 750+ views
Original Post
satanD
satanD
Hi all, I writing a small game in java & openGL (hope its the forum to ask). The game is represents by 'World' class, which holds fields Board & Player. When the player finishes the level (i.e he visited each square on the board), he should continue to the next level (new board). I use animator class (FPS animator) in order to animate the game. When the player finished the level, I replace the current board with a new board with different fields (size,color). Probably, because the animator uses several threads, I get exceptions which relate to the old board, i.e out of bounds exceptions. How do I stop all the other threads and update the new board atomically? I tried to stop the animator, but unfortunatly, the others threads still running (excpetions are thrown gracefully :) Do you have any suggestions? Thanks & Good day
Wyrframe
Wyrframe
Try a message-queue system; the game logic will inject messages such as "abort animation X" or "abort animations", which are pushed onto the animators' queues (mind the thread-safety; synchronize your queue methods). At the start of animators' update ticks, they check for messages, and if the messages pertain to themselves, they deal with those messages before continuing. If it's a cancel message, the animator aborts.

You'll probably want an animation master, who tracks the animator threads and can tell you how many are running at a given time. You'll call its abort() method, which will (within a synchronization block) send out the cancel messages, and then wait() on a particular object. The animator threads will call their master's aborting(animator) method, which is synchronized on the same object as in abort() so they don't slip through early. When the last animator aborts, the animation master notify()'s the waiting thread, which will come back to life and continue as soon as the animators are aborted.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
satanD
satanD
Quote:
Original post by Wyrframe
Try a message-queue system; the game logic will inject messages such as "abort animation X" or "abort animations", which are pushed onto the animators' queues (mind the thread-safety; synchronize your queue methods). At the start of animators' update ticks, they check for messages, and if the messages pertain to themselves, they deal with those messages before continuing. If it's a cancel message, the animator aborts.


Thanks for the answer, but how do I impelement such a message-queue system?

* In the FBSAnimtor doco, it says that a background thread is executed and calls "display" function over and over, so can I assume that only 2 threads are working?

[Edited by - satanD on August 28, 2008 5:55:38 AM]
Wyrframe
Wyrframe
So you're using someone else's animation framework? Are you certain their framework doesn't have a method to cancel running animations?
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.