View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Squeak Timer by Moctar Diallo

The use of the Squeak timer was very important for our 2D animation studio.
It allowed us to make actions happen sequentially, concurrently and arbitrarily in time.
Before each play starts, it gets loaded first. A play is composed of scenes, which in turn is composed of instructions.
During the loading process, the instructions for each scene are parsed. When parsing the instructions, we added each instruction by the order they will be executed to an OrderCollection that we called "instructionList". For each instruction we determined how long it will take for it to be performed. For instance if the instruction is "Bob walk 50 units in 5000ms" we know that the character Bob will walk for 5 second therefore that specific instruction will take 5 seconds. Next, we have an OrderCollection called “instructionsTime”. This will keep track of when exactly a specific instruction is to be executed. For instance if instructionList contains the following instructions in the following order:
Then “instructionTime” will have the following element
(InstructionTime at:1) is equal to 0 .
(InstructionTime at:2) is equal to 5. (it takes 5 second for bob to finish walking, therefore Bill smiles starts similing when the time is 5s)
(InstructionTime at:3) is equal to 8 = 5+3. (it takes 5 second for bob to walk and 3 seconds for bill to finish smiling)
(InstructionTime at:4) is equal to 10 = 5+3+4. (it takes 5 second for bob to finish walking, 3 seconds for bill to finish smiling, and 4 seconds)

After the loading process is completed, we move to the execution phase. In this phase we used 2 methods step and stepTime for the squeak timer. the methods look like this

stepTime
“call step every 1000 milliseconds”
^1000.


In it we call step. This is the function that will be called by squeak to tell us some amount of time has passed. In our case we want one second to be that amount of time. To achieve that we have a function that return the amount of time in milliseconds. Here is the step method

step
stepNumber:=stepNumber+1.

1 to (IntructionTime size) do:[index |

(stepNumber = (IntructionTime at:index) )
ifTrue:[ self execute: (InstructionTime at:1)]
].
stepNumber is set to zero in the initialize method and increases by 1 every second since step is called every 100ms.

What the following portion of the code does is that it loops through the list of time there is in InstructionTime and checks if it’s time to execute an instruction if it is then the instruction is executed.


1 to (IntructionTime size) do:[index |

(stepNumber = (IntructionTime at:index) )
ifTrue:[ self execute: (InstructionTime at:1)]
].

This allowed us to make actions happen sequentially and we used the same approach to make actions happen concurrently and arbitrarily in time.







Link to this Page