games/galaxy: Change button 2 to reposition the galaxy, remove "move" from the button 3 menu

This commit is contained in:
spew 2017-03-01 15:59:26 -06:00
parent a4895f5e44
commit 0e9973c80f
5 changed files with 29 additions and 43 deletions

View file

@ -45,15 +45,12 @@ of the body. Holding a button 1-3 chord
changes the initial velocity of the body. Releasing button 1 changes the initial velocity of the body. Releasing button 1
restarts the simulator with the new body in motion. When new restarts the simulator with the new body in motion. When new
bodies are created, the simulator maintains the Galilean (inertial) bodies are created, the simulator maintains the Galilean (inertial)
reference frame. reference frame where the center of mass of the galaxy is at rest.
.PP
Mouse button 2 repositions the visible region of the galaxy by dragging.
.PP .PP
Mouse button 3 opens a menu with the following options: Mouse button 3 opens a menu with the following options:
.TP .TP
.B move
Change the visible region of the simulation
by holding button 1 and dragging. Any other mouse
button restarts the simulation.
.TP
.B zoom .B zoom
Prompts for a floating point value to change the scale of the Prompts for a floating point value to change the scale of the
simulation. E.g. a value of 2 will halve the scale (zoom in) simulation. E.g. a value of 2 will halve the scale (zoom in)

View file

@ -35,8 +35,7 @@ Cursor pausecursor={
enum { enum {
STK = 8192, STK = 8192,
MOVE = 0, ZOOM = 0,
ZOOM,
SPEED, SPEED,
GRAV, GRAV,
SAVE, SAVE,
@ -57,7 +56,7 @@ double
LIM = 10, LIM = 10,
dt²; dt²;
char *file; char *file;
int showv, showa, throttle, moving; int showv, showa, throttle;
char *menustr[] = { char *menustr[] = {
[SAVE] "save", [SAVE] "save",
@ -65,7 +64,6 @@ char *menustr[] = {
[ZOOM] "zoom", [ZOOM] "zoom",
[SPEED] "speed", [SPEED] "speed",
[GRAV] "gravity", [GRAV] "gravity",
[MOVE] "move",
[EXIT] "exit", [EXIT] "exit",
[MEND] nil [MEND] nil
}; };
@ -313,31 +311,24 @@ getinput(char *info, char *sug)
} }
void void
move(void) domove(void)
{ {
Point od; Point oldp, off;
setcursor(mc, &crosscursor); setcursor(mc, &crosscursor);
pause(0, 0);
oldp = mc->xy;
for(;;) { for(;;) {
for(;;) { readmouse(mc);
readmouse(mc); if(mc->buttons != 2)
if(mc->buttons & 1) break;
break; off = subpt(mc->xy, oldp);
if(mc->buttons & 4) { oldp = mc->xy;
moving = 0; orig = addpt(orig, off);
setcursor(mc, cursor); drawglxy();
return;
}
}
moving = 1;
od = subpt(orig, mc->xy);
for(;;) {
readmouse(mc);
if(!(mc->buttons & 1))
break;
orig = addpt(od, mc->xy);
drawglxy();
}
} }
setcursor(mc, cursor);
pause(1, 0);
} }
void void
@ -413,9 +404,6 @@ domenu(void)
break; break;
G *= z; G *= z;
break; break;
case MOVE:
move();
break;
case EXIT: case EXIT:
threadexitsall(nil); threadexitsall(nil);
break; break;
@ -434,6 +422,9 @@ mousethread(void*)
case 1: case 1:
dobody(); dobody();
break; break;
case 2:
domove();
break;
case 4: case 4:
domenu(); domenu();
break; break;
@ -488,8 +479,6 @@ kbdthread(void*)
showa ^= 1; showa ^= 1;
break; break;
case ' ': case ' ':
if(moving)
break;
paused ^= 1; paused ^= 1;
if(paused) { if(paused) {
cursor = &pausecursor; cursor = &pausecursor;
@ -537,7 +526,7 @@ Again:
b->a.y = b->newa.y; b->a.y = b->newa.y;
b->newa.x = b->newa.y = 0; b->newa.x = b->newa.y = 0;
STATS(calcs = 0;) STATS(calcs = 0;)
quadcalc(space, b, LIM); quadcalc(b, space, LIM);
STATS(avgcalcs += calcs;) STATS(avgcalcs += calcs;)
} }
STATS(avgcalcs /= glxy.l;) STATS(avgcalcs /= glxy.l;)

View file

@ -64,7 +64,7 @@ void readglxy(int);
void writeglxy(int); void writeglxy(int);
int Bfmt(Fmt*); int Bfmt(Fmt*);
void quadcalc(QB, Body*, double); void quadcalc(Body*, QB, double);
int quadins(Body*, double); int quadins(Body*, double);
void growquads(void); void growquads(void);
void quadsinit(void); void quadsinit(void);

View file

@ -12,7 +12,7 @@ double
av, avrand; av, avrand;
int new, c = 1; int new, c = 1;
void quadcalc(QB, Body*, double){} void quadcalc(Body*, QB, double){}
Image *randcol(void){ return nil; } Image *randcol(void){ return nil; }
void void

View file

@ -84,7 +84,7 @@ quadins(Body *nb, double size)
} }
void void
quadcalc(QB qb, Body *b, double size) quadcalc(Body *b, QB qb, double size)
{ {
double fx÷mm, fy÷mm, dx, dy, h, G÷h³; double fx÷mm, fy÷mm, dx, dy, h, G÷h³;
@ -121,9 +121,9 @@ quadcalc(QB qb, Body *b, double size)
return; return;
} }
size /= 2; size /= 2;
quadcalc(qb.q->c[0], b, size); quadcalc(b, qb.q->c[0], size);
quadcalc(qb.q->c[1], b, size); quadcalc(b, qb.q->c[1], size);
quadcalc(qb.q->c[2], b, size); quadcalc(b, qb.q->c[2], size);
qb = qb.q->c[3]; qb = qb.q->c[3];
break; /* quadcalc(q->q[3], b, size); */ break; /* quadcalc(q->q[3], b, size); */
} }