diff --git a/TODO b/TODO index 9f27f7f..62f648f 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,6 @@ Micropolis::map[] array- *Consider changing type from 'char' to 'short' -Simulator speeds- - *Do not change behavior of sim based on speed, i.e. crime scans - should be done every cycle, even at the high speeds. - *Do not have sprite's movement speed be dependent on speed. - Finances- *Pay operating costs either every week or at the beginning of the year, instead of at the end of the year. This will fix an issue where it is diff --git a/src/micropolisj/engine/Micropolis.java b/src/micropolisj/engine/Micropolis.java index f20a8ae..eda3bdd 100644 --- a/src/micropolisj/engine/Micropolis.java +++ b/src/micropolisj/engine/Micropolis.java @@ -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(); } diff --git a/src/micropolisj/engine/Speed.java b/src/micropolisj/engine/Speed.java index 935e038..17c3b21 100644 --- a/src/micropolisj/engine/Speed.java +++ b/src/micropolisj/engine/Speed.java @@ -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; } } diff --git a/src/micropolisj/gui/MainWindow.java b/src/micropolisj/gui/MainWindow.java index db91cef..ac69843 100644 --- a/src/micropolisj/gui/MainWindow.java +++ b/src/micropolisj/gui/MainWindow.java @@ -1069,7 +1069,6 @@ public class MainWindow extends JFrame private void startTimer() { final Micropolis engine = getEngine(); - final int updateCycle = engine.simSpeed.aniFramesPerStep; final int count = engine.simSpeed.simStepsPerUpdate; assert !isTimerActive(); @@ -1096,23 +1095,18 @@ public class MainWindow extends JFrame ActionListener taskPerformer = new ActionListener() { public void actionPerformed(ActionEvent evt) { - engine.acycle = (engine.acycle+1) % 960; - if (engine.acycle % updateCycle == 0) + for (int i = 0; i < count; i++) { - for (int i = 0; i < count; i++) + engine.animate(); + if (!engine.autoBudget && engine.isBudgetTime()) { - if (!engine.autoBudget && engine.isBudgetTime()) - { - stopTimer(); //redundant - showBudgetWindow(true); - return; - } - engine.step(); - dirty2 = true; + stopTimer(); //redundant + showBudgetWindow(true); + return; } } - engine.animate(); updateDateLabel(); + dirty2 = true; }}; assert simTimer == null; @@ -1308,11 +1302,6 @@ public class MainWindow extends JFrame BudgetDialog dlg = new BudgetDialog(this, getEngine()); dlg.setModal(true); dlg.setVisible(true); - - if (isEndOfYear) { - getEngine().step(); - } - startTimer(); }