Skip to content

Commit

Permalink
refactor simulator State outside of Simulation
Browse files Browse the repository at this point in the history
the contents of `State` concern the graphical rendering/playing of
the simulation and are not endogenous to the Simulation itself
  • Loading branch information
MichaelBuhler committed Jun 20, 2020
1 parent fb6d752 commit 0c6d722
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
18 changes: 10 additions & 8 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

public class Main : MonoBehaviour {

private float elaspedTime = 0;

void Start () {
private void Start () {
Simulation.Init();
Simulation.Render();
}

void Update () {
elaspedTime += Time.deltaTime;
float secondsPerStep = 1.0f / Simulation.Parameters.STEPS_PER_SECOND;
for ( int i = (int) ( this.elaspedTime / secondsPerStep ) ; i > 0 ; i-- ) {
private void Update () {
if ( State.PAUSED ) {
return;
}
State.DELTA_TIME += Time.deltaTime;
float secondsPerStep = 1.0f / State.STEPS_PER_SECOND;
for ( int i = (int) ( State.DELTA_TIME / secondsPerStep ) ; i > 0 ; i-- ) {
State.DELTA_TIME -= secondsPerStep;
Simulation.Step();
Simulation.Render();
this.elaspedTime -= secondsPerStep;
}
}

}
1 change: 0 additions & 1 deletion Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
public class Simulation {

public static class Parameters {
public static float STEPS_PER_SECOND = 4;
public static int NUMBER_OF_AGENTS = 400;
public static int SUGAR_GROWTH_RATE = 1;
public static class Endowment {
Expand Down
8 changes: 8 additions & 0 deletions State.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

public class State {

public static float DELTA_TIME = 0;
public static bool PAUSED = true;
public static int STEPS_PER_SECOND = 4;

}

0 comments on commit 0c6d722

Please sign in to comment.