ref: 0e9973c80f994cd92f099ae1e08fec1b92ecabd1
parent: a4895f5e44dc98b96eacf82e379246f79c8b57c4
author: spew <devnull@localhost>
date: Wed Mar 1 10:59:26 EST 2017
games/galaxy: Change button 2 to reposition the galaxy, remove "move" from the button 3 menu
--- a/sys/man/1/galaxy
+++ b/sys/man/1/galaxy
@@ -45,14 +45,11 @@
changes the initial velocity of the body. Releasing button 1
restarts the simulator with the new body in motion. When new
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
Mouse button 3 opens a menu with the following options:
-.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
Prompts for a floating point value to change the scale of the
--- a/sys/src/games/galaxy/galaxy.c
+++ b/sys/src/games/galaxy/galaxy.c
@@ -35,8 +35,7 @@
enum {
STK = 8192,
- MOVE = 0,
- ZOOM,
+ ZOOM = 0,
SPEED,
GRAV,
SAVE,
@@ -57,7 +56,7 @@
LIM = 10,
dt²;
char *file;
-int showv, showa, throttle, moving;
+int showv, showa, throttle;
char *menustr[] = {
[SAVE] "save",
@@ -65,7 +64,6 @@
[ZOOM] "zoom",
[SPEED] "speed",
[GRAV] "gravity",
- [MOVE] "move",
[EXIT] "exit",
[MEND] nil
};
@@ -313,31 +311,24 @@
}
void
-move(void)
+domove(void)
{
- Point od;
+ Point oldp, off;
+
setcursor(mc, &crosscursor);
+ pause(0, 0);
+ oldp = mc->xy;
for(;;) {
- for(;;) {
- readmouse(mc);
- if(mc->buttons & 1)
- break;
- if(mc->buttons & 4) {
- moving = 0;
- setcursor(mc, cursor);
- return;
- }
- }
- moving = 1;
- od = subpt(orig, mc->xy);
- for(;;) {
- readmouse(mc);
- if(!(mc->buttons & 1))
- break;
- orig = addpt(od, mc->xy);
- drawglxy();
- }
+ readmouse(mc);
+ if(mc->buttons != 2)
+ break;
+ off = subpt(mc->xy, oldp);
+ oldp = mc->xy;
+ orig = addpt(orig, off);
+ drawglxy();
}
+ setcursor(mc, cursor);
+ pause(1, 0);
}
void
@@ -413,9 +404,6 @@
break;
G *= z;
break;
- case MOVE:
- move();
- break;
case EXIT:
threadexitsall(nil);
break;
@@ -434,6 +422,9 @@
case 1:
dobody();
break;
+ case 2:
+ domove();
+ break;
case 4:
domenu();
break;
@@ -488,8 +479,6 @@
showa ^= 1;
break;
case ' ':
- if(moving)
- break;
paused ^= 1;
if(paused) {
cursor = &pausecursor;
@@ -537,7 +526,7 @@
b->a.y = b->newa.y;
b->newa.x = b->newa.y = 0;
STATS(calcs = 0;)
- quadcalc(space, b, LIM);
+ quadcalc(b, space, LIM);
STATS(avgcalcs += calcs;)
}
STATS(avgcalcs /= glxy.l;)
--- a/sys/src/games/galaxy/galaxy.h
+++ b/sys/src/games/galaxy/galaxy.h
@@ -64,7 +64,7 @@
void writeglxy(int);
int Bfmt(Fmt*);
-void quadcalc(QB, Body*, double);
+void quadcalc(Body*, QB, double);
int quadins(Body*, double);
void growquads(void);
void quadsinit(void);
--- a/sys/src/games/galaxy/mkgalaxy.c
+++ b/sys/src/games/galaxy/mkgalaxy.c
@@ -12,7 +12,7 @@
av, avrand;
int new, c = 1;
-void quadcalc(QB, Body*, double){}
+void quadcalc(Body*, QB, double){}
Image *randcol(void){ return nil; }
void
--- a/sys/src/games/galaxy/quad.c
+++ b/sys/src/games/galaxy/quad.c
@@ -84,7 +84,7 @@
}
void
-quadcalc(QB qb, Body *b, double size)
+quadcalc(Body *b, QB qb, double size)
{
double fx÷❨m₁m₂❩, fy÷❨m₁m₂❩, dx, dy, h, G÷h³;
@@ -121,9 +121,9 @@
return;
}
size /= 2;
- quadcalc(qb.q->c[0], b, size);
- quadcalc(qb.q->c[1], b, size);
- quadcalc(qb.q->c[2], b, size);
+ quadcalc(b, qb.q->c[0], size);
+ quadcalc(b, qb.q->c[1], size);
+ quadcalc(b, qb.q->c[2], size);
qb = qb.q->c[3];
break; /* quadcalc(q->q[3], b, size); */
}