titiritero: design decisions

During this week I refactored titiritero and in particular the implementation of the gameloop.  The gameloop is a control structure that runs the simulation (give live to model) and updates the views. There are to ways of implementing it:

The first one, is with an infinite loop with a Thread.sleep inside, something like this:

shouldExecuteGameloop = true;
while(shouldExecuteGameloop ){
   this.runSimulation();
   this.updateView();
   Thread.sleep(simulationInterval);
}

The other alternative is using a Timer object and making the gameloop class to implement TimerTask interface, something like this:

Timer timer = new Timer(gameloop);
timer.start(simulationInterval);
...
gameloop.onTimerTask(){
   this.runSimulation();
   this.updateView();
}

I choose the first alternative because with the second one it could happen that the execution of a single loop of the gameloop takes to much time, so there could be more than one thread working simultaneously on the same object, producing an anomalous behaviors of the application.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s