aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2021-03-08 07:57:41 +0000
committerrodri <rgl@antares-labs.eu>2021-03-08 07:57:41 +0000
commitc24c56fa9ac83b61a6ad6732f9704b9dddf79b22 (patch)
tree925da220a16fb9b06df78a9a6476ed54f36aba86
parent0c736f207ccb206e4f099186735ac4ab8d11f7b6 (diff)
downloadgamephysics-c24c56fa9ac83b61a6ad6732f9704b9dddf79b22.tar.gz
gamephysics-c24c56fa9ac83b61a6ad6732f9704b9dddf79b22.tar.bz2
gamephysics-c24c56fa9ac83b61a6ad6732f9704b9dddf79b22.zip
enable reset of the entire simulation.
-rw-r--r--main.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/main.c b/main.c
index 20a27d0..106b31f 100644
--- a/main.c
+++ b/main.c
@@ -10,7 +10,7 @@
RFrame screenrf;
State state;
-double timestep;
+double t, Δt;
double min(double a, double b) { return a < b? a: b; }
@@ -152,7 +152,7 @@ redraw(void)
lockdisplay(display);
draw(screen, screen->r, display->black, nil, ZP);
- drawtimestep(timestep);
+ drawtimestep(t);
drawbar(state.min); drawbar(state.max); drawbar(state.avg);
fillellipse(screen, toscreen(Pt2(0,state.x,1)), 2, 2, display->white, ZP);
@@ -172,6 +172,14 @@ resized(void)
}
void
+resetsim(void)
+{
+ memset(&state, 0, sizeof(State));
+ state.x = 100;
+ t = 0;
+}
+
+void
rmb(Mousectl *mc)
{
enum {
@@ -185,7 +193,7 @@ rmb(Mousectl *mc)
switch(menuhit(3, mc, &menu, _screen)){
case RESET:
- //resetsim();
+ resetsim();
break;
}
}
@@ -220,7 +228,6 @@ threadmain(int argc, char *argv[])
Mousectl *mc;
Keyboardctl *kc;
Rune r;
- double t, Δt;
ARGBEGIN{
default: usage();
@@ -238,10 +245,8 @@ threadmain(int argc, char *argv[])
screenrf.bx = Vec2(1, 0);
screenrf.by = Vec2(0,-1);
- t = 0;
Δt = 0.01;
- state.x = 100;
- state.v = 0;
+ resetsim();
display->locking = 1;
unlockdisplay(display);
@@ -278,7 +283,6 @@ threadmain(int argc, char *argv[])
redraw();
t += Δt;
- timestep = t;
sleep(66);
}