simspeed: no matter speed, always two animation cycles per sim step

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@614 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-04-29 22:02:29 +00:00
parent d17084261d
commit 9c045da206
4 changed files with 27 additions and 38 deletions

View file

@ -15,7 +15,7 @@ import static micropolisj.engine.TileConstants.*;
/**
* The main simulation engine for Micropolis.
* The front-end should call step() and animate() periodically
* The front-end should call animate() periodically
* to move the simulation forward in time.
*/
public class Micropolis
@ -189,7 +189,7 @@ public class Micropolis
public int cityTime; //counts "weeks" (actually, 1/48'ths years)
int scycle; //same as cityTime, except mod 1024
int fcycle; //counts simulation steps (mod 1024)
public int acycle; //animation cycle (mod 960)
int acycle; //animation cycle (mod 960)
public CityEval evaluation;
@ -448,7 +448,7 @@ public class Micropolis
}
/**
* Checks whether the next call to step() will collect taxes and
* Checks whether the next call to animate() will collect taxes and
* process the budget.
*/
public boolean isBudgetTime()
@ -456,11 +456,12 @@ public class Micropolis
return (
cityTime != 0 &&
(cityTime % TAXFREQ) == 0 &&
((fcycle + 1) % 16) == 10
((fcycle + 1) % 16) == 10 &&
((acycle + 1) % 2) == 0
);
}
public void step()
void step()
{
fcycle = (fcycle + 1) % 1024;
simulate(fcycle % 16);
@ -2115,6 +2116,10 @@ public class Micropolis
public void animate()
{
this.acycle = (this.acycle+1) % 960;
if (this.acycle % 2 == 0) {
step();
}
moveObjects();
animateTiles();
}

View file

@ -10,28 +10,28 @@ package micropolisj.engine;
/**
* Lists the simulation speeds available.
* Contains properties identifying how often the animation timer fires,
* and how many animation steps are fired at each interval.
* Note: for every 2 animation steps, one simulation step is triggered.
*/
public enum Speed
{
PAUSED ( 999,999, 0),
SLOW ( 250, 5, 1), //one step every 1250 ms
NORMAL ( 125, 2, 1), //one step every 250 ms
FAST ( 50, 1, 1), //one step every 50 ms
SUPER_FAST( 50, 1, 5); //one step every 10 ms
PAUSED ( 999, 0),
SLOW ( 625, 1), //one sim step every 1250 ms
NORMAL ( 125, 1), //one sim step every 250 ms
FAST ( 25, 1), //one sim step every 50 ms
SUPER_FAST( 25, 5); //one sim step every 10 ms
/** The animation speed, expressed as an interval in milliseconds. */
public final int animationDelay;
/** For slower speeds, how many animation occur for every simulation step.
* Faster speeds should set this to one. */
public final int aniFramesPerStep;
/** For faster speeds, how many simulation steps should occur for every
* update to the screen. */
public final int simStepsPerUpdate;
private Speed(int delay, int aniFrames, int simSteps)
private Speed(int delay, int simSteps)
{
this.animationDelay = delay;
this.aniFramesPerStep = aniFrames;
this.simStepsPerUpdate = simSteps;
}
}