Hi everybody !
I'm developing an educative game. I've written a "gameEngine" class which does the logic for the general progression in the game : switching between instances of morph subclasses which implement intro screen / mini-games/levels / end screen etc ... Now, i need to synchronize the instance of the gameEngine class with the instances of the other classes. Example : once the gameEngine starts the instance of a morph subclass which implements a mini-game, it must sleep until the mini-game is finished, and then wake up and does further required switching (next mini-game or intro screen or end screen ...). i thought that a "simple" semaphore would quickly give a solution to the problem. But i get a freezed code. I've modelized/simplified the problem with the following workspace code. See also fileout of Class TestSynchro as attachment. TestSynchro has a step method which prints some lines to Transcript, then calls the method stopStepping and signal to the semaphore. The workspace code does a wait, before printing to Transcript 'Hello World'! Problem is that the code freezes , on the line code -> sem wait I first thought that the code freezed because in the same process. And added a fork to the block which creates instance of TestSynchro. But it does'nt help ... Any help will be appreciated ! Thanks by advance, Patrick Dudjalija |ts sem| sem:=Semaphore new. [ts:= TestSynchro new. ts semaphore:sem. ts openInWorld. ts start.] fork. sem wait. Transcript cr; show:'Hello world !';cr. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners TestSynchro.st (2K) Download Attachment |
On 12-08-14 3:24 PM, patrick dudjalija
wrote:
Hi everybody ! I'm developing an educative game. I've written a "gameEngine" class which does the logic for the general progression in the game : switching between instances of morph subclasses which implement intro screen / mini-games/levels / end screen etc ... Now, i need to synchronize the instance of the gameEngine class with the instances of the other classes. Example : once the gameEngine starts the instance of a morph subclass which implements a mini-game, it must sleep until the mini-game is finished, and then wake up and does further required switching (next mini-game or intro screen or end screen ...). i thought that a "simple" semaphore would quickly give a solution to the problem. But i get a freezed code. I've modelized/simplified the problem with the following workspace code. See also fileout of Class TestSynchro as attachment. TestSynchro has a step method which prints some lines to Transcript, then calls the method stopStepping and signal to the semaphore. The workspace code does a wait, before printing to Transcript 'Hello World'! Problem is that the code freezes , on the line code -> sem wait I first thought that the code freezed because in the same process. And added a fork to the block which creates instance of TestSynchro. But it does'nt help ... Any help will be appreciated ! Thanks by ad2vance, Patrick Dudjalija |ts sem| sem:=Semaphore new. [ts:= TestSynchro new. ts semaphore:sem. ts openInWorld. ts start.] fork. sem wait. Transcript cr; show:'Hello world !';cr. http://stephane.ducasse.free.fr/FreeBooks/GuzdialBookDrafts/BuildUI-ch5.pdf I don't know much about this stuff, but using Semaphore for animations seems too low level. Pg. 53 of this pdf describes how step and stepTime work. HTH, Chris _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |