summaryrefslogtreecommitdiff
path: root/sys/src/games/galaxy/galaxy.h
blob: 9d51aa158e046486566b578680b1386d666863e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
typedef struct QB QB;
typedef struct Body Body;
typedef struct Quad Quad;
typedef struct Vector Vector;

struct QB {
	union {
		Quad *q;
		Body *b;
	};
	int t;
};

struct Vector {
	double x, y;
};

struct Body {
	Vector;
	Vector v, a, newa;
	double size, mass;
	Image *col;
};

struct Quad {
	Vector;
	QB c[4];
	double mass;
};

#pragma varargck type "B" Body*

struct {
	QLock;
	Body *a;
	int nb, max;
} glxy;

struct {
	Quad *a;
	int l, max;
} quads;

#define π2 6.28318530718e0

enum {
	EMPTY,
	QUAD,
	BODY,
};

void quit(char*);

Image *randcol(void);
Point topoint(Vector);
Vector tovector(Point);

Body *body(void);
void drawbody(Body*);
Vector center(void);
void glxyinit(void);
int Bfmt(Fmt*);
void readglxy(int);
void writeglxy(int);
void drawglxy(void);

void simulate(void*);

void quadcalc(Body*, QB, double);
int quadins(Body*, double);
void growquads(void);
void quadsinit(void);

int stats, quaddepth, calcs, extraproc, throttle;
double G, θ, scale, ε, LIM, dt, dt², avgcalcs;
Point orig;
QB space;
Body ZB;

enum {
	STK = 8192,
};

#define STATS(e) if(stats) {e}

#define CHECKLIM(b, f) \
	if(((f) = fabs((b)->x)) > LIM/2)	\
		LIM = (f)*2;	\
	if(((f) = fabs((b)->y)) > LIM/2)	\
		LIM = (f)*2