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:
parent
d17084261d
commit
9c045da206
4 changed files with 27 additions and 38 deletions
5
TODO
5
TODO
|
@ -1,11 +1,6 @@
|
||||||
Micropolis::map[] array-
|
Micropolis::map[] array-
|
||||||
*Consider changing type from 'char' to 'short'
|
*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-
|
Finances-
|
||||||
*Pay operating costs either every week or at the beginning of the year,
|
*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
|
instead of at the end of the year. This will fix an issue where it is
|
||||||
|
|
|
@ -15,7 +15,7 @@ import static micropolisj.engine.TileConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main simulation engine for Micropolis.
|
* 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.
|
* to move the simulation forward in time.
|
||||||
*/
|
*/
|
||||||
public class Micropolis
|
public class Micropolis
|
||||||
|
@ -189,7 +189,7 @@ public class Micropolis
|
||||||
public int cityTime; //counts "weeks" (actually, 1/48'ths years)
|
public int cityTime; //counts "weeks" (actually, 1/48'ths years)
|
||||||
int scycle; //same as cityTime, except mod 1024
|
int scycle; //same as cityTime, except mod 1024
|
||||||
int fcycle; //counts simulation steps (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;
|
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.
|
* process the budget.
|
||||||
*/
|
*/
|
||||||
public boolean isBudgetTime()
|
public boolean isBudgetTime()
|
||||||
|
@ -456,11 +456,12 @@ public class Micropolis
|
||||||
return (
|
return (
|
||||||
cityTime != 0 &&
|
cityTime != 0 &&
|
||||||
(cityTime % TAXFREQ) == 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;
|
fcycle = (fcycle + 1) % 1024;
|
||||||
simulate(fcycle % 16);
|
simulate(fcycle % 16);
|
||||||
|
@ -2115,6 +2116,10 @@ public class Micropolis
|
||||||
|
|
||||||
public void animate()
|
public void animate()
|
||||||
{
|
{
|
||||||
|
this.acycle = (this.acycle+1) % 960;
|
||||||
|
if (this.acycle % 2 == 0) {
|
||||||
|
step();
|
||||||
|
}
|
||||||
moveObjects();
|
moveObjects();
|
||||||
animateTiles();
|
animateTiles();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,28 +10,28 @@ package micropolisj.engine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists the simulation speeds available.
|
* 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
|
public enum Speed
|
||||||
{
|
{
|
||||||
PAUSED ( 999,999, 0),
|
PAUSED ( 999, 0),
|
||||||
SLOW ( 250, 5, 1), //one step every 1250 ms
|
SLOW ( 625, 1), //one sim step every 1250 ms
|
||||||
NORMAL ( 125, 2, 1), //one step every 250 ms
|
NORMAL ( 125, 1), //one sim step every 250 ms
|
||||||
FAST ( 50, 1, 1), //one step every 50 ms
|
FAST ( 25, 1), //one sim step every 50 ms
|
||||||
SUPER_FAST( 50, 1, 5); //one step every 10 ms
|
SUPER_FAST( 25, 5); //one sim step every 10 ms
|
||||||
|
|
||||||
/** The animation speed, expressed as an interval in milliseconds. */
|
/** The animation speed, expressed as an interval in milliseconds. */
|
||||||
public final int animationDelay;
|
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
|
/** For faster speeds, how many simulation steps should occur for every
|
||||||
* update to the screen. */
|
* update to the screen. */
|
||||||
public final int simStepsPerUpdate;
|
public final int simStepsPerUpdate;
|
||||||
|
|
||||||
private Speed(int delay, int aniFrames, int simSteps)
|
private Speed(int delay, int simSteps)
|
||||||
{
|
{
|
||||||
this.animationDelay = delay;
|
this.animationDelay = delay;
|
||||||
this.aniFramesPerStep = aniFrames;
|
|
||||||
this.simStepsPerUpdate = simSteps;
|
this.simStepsPerUpdate = simSteps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1069,7 +1069,6 @@ public class MainWindow extends JFrame
|
||||||
private void startTimer()
|
private void startTimer()
|
||||||
{
|
{
|
||||||
final Micropolis engine = getEngine();
|
final Micropolis engine = getEngine();
|
||||||
final int updateCycle = engine.simSpeed.aniFramesPerStep;
|
|
||||||
final int count = engine.simSpeed.simStepsPerUpdate;
|
final int count = engine.simSpeed.simStepsPerUpdate;
|
||||||
|
|
||||||
assert !isTimerActive();
|
assert !isTimerActive();
|
||||||
|
@ -1096,23 +1095,18 @@ public class MainWindow extends JFrame
|
||||||
ActionListener taskPerformer = new ActionListener() {
|
ActionListener taskPerformer = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent evt)
|
public void actionPerformed(ActionEvent evt)
|
||||||
{
|
{
|
||||||
engine.acycle = (engine.acycle+1) % 960;
|
for (int i = 0; i < count; i++)
|
||||||
if (engine.acycle % updateCycle == 0)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count; i++)
|
engine.animate();
|
||||||
|
if (!engine.autoBudget && engine.isBudgetTime())
|
||||||
{
|
{
|
||||||
if (!engine.autoBudget && engine.isBudgetTime())
|
stopTimer(); //redundant
|
||||||
{
|
showBudgetWindow(true);
|
||||||
stopTimer(); //redundant
|
return;
|
||||||
showBudgetWindow(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
engine.step();
|
|
||||||
dirty2 = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
engine.animate();
|
|
||||||
updateDateLabel();
|
updateDateLabel();
|
||||||
|
dirty2 = true;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
assert simTimer == null;
|
assert simTimer == null;
|
||||||
|
@ -1308,11 +1302,6 @@ public class MainWindow extends JFrame
|
||||||
BudgetDialog dlg = new BudgetDialog(this, getEngine());
|
BudgetDialog dlg = new BudgetDialog(this, getEngine());
|
||||||
dlg.setModal(true);
|
dlg.setModal(true);
|
||||||
dlg.setVisible(true);
|
dlg.setVisible(true);
|
||||||
|
|
||||||
if (isEndOfYear) {
|
|
||||||
getEngine().step();
|
|
||||||
}
|
|
||||||
|
|
||||||
startTimer();
|
startTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue