Browse Source

Bisschen Datentypen aufgeräumt

Insbesondere ein cluster_t der außer den coordinaten einen
safety_radius enthält. Damit sind unterschiedlich große Cluster möglich.
Viel Spaß beim rebasen Lemmi. *g*
Patrick Kilian 9 years ago
parent
commit
9579ada8ab
6 changed files with 103 additions and 114 deletions
  1. 3
    3
      gitter/json_output.c
  2. 1
    1
      gitter/json_output.h
  3. 38
    52
      gitter/route.c
  4. 3
    10
      gitter/route.h
  5. 44
    44
      gitter/screen.c
  6. 14
    4
      gitter/screen.h

+ 3
- 3
gitter/json_output.c View File

@@ -4,16 +4,16 @@
4 4
 #include "globals.h"
5 5
 #include "json_output.h"
6 6
 
7
-void json_output(pixel_t* planets, int n_planets) {
7
+void json_output(cluster_t* planets, int n_planets) {
8 8
 	int i;
9 9
 
10 10
 	printf("{ \"world\":\n");
11 11
 	printf("  { \"bounding-box\": { \"xmin\": 0, \"xmax\": %d, \"ymin\": 0, \"ymax\": %d},\n", GLOBALS.WIDTH, GLOBALS.HEIGHT);
12 12
 	printf("    \"planets\": [\n");
13 13
 	for(i = 0; i < n_planets-1; i++) {
14
-		printf("      {\"id\":%d, \"x\": %f, \"y\": %f, \"owner\": null},\n", i, planets[i].x, planets[i].y);
14
+		printf("      {\"id\":%d, \"x\": %f, \"y\": %f, \"owner\": null},\n", i, planets[i].center.x, planets[i].center.y);
15 15
 	}
16
-	printf("      {\"id\":%d, \"x\": %f, \"y\": %f, \"owner\": null}\n", i, planets[n_planets-1].x, planets[n_planets-1].y);
16
+	printf("      {\"id\":%d, \"x\": %f, \"y\": %f, \"owner\": null}\n", i, planets[n_planets-1].center.x, planets[n_planets-1].center.y);
17 17
 	printf("    ],\n");
18 18
 	printf("    \"ships\": [ ],\n");
19 19
 	printf("    \"asteroids\": [ ],\n");

+ 1
- 1
gitter/json_output.h View File

@@ -4,7 +4,7 @@
4 4
 #include "screen.h"
5 5
 #include "route.h"
6 6
 
7
-void json_output(pixel_t* planets, int n_planets);
7
+void json_output(cluster_t* planets, int n_planets);
8 8
 void json_update(waypoint_t* route1, waypoint_t* route2i, int n_planets);
9 9
 
10 10
 #endif  /*JSON_H*/

+ 38
- 52
gitter/route.c View File

@@ -5,7 +5,7 @@
5 5
 #include "globals.h"
6 6
 
7 7
 // Abstand zwischen zwei Punkten
8
-double dist(pixel_t* A, pixel_t* B) {
8
+double dist(vector_t* A, vector_t* B) {
9 9
 	return hypotf(B->x - A->x, B->y - A->y);
10 10
 }
11 11
 
@@ -14,7 +14,7 @@ double dist(pixel_t* A, pixel_t* B) {
14 14
 // Werte zwischen 0 und 1 geben an nach welchem Bruchteil von AB der Fußpunkt kommt
15 15
 // Werte größer 1 bedeuten daß der Fußpunkt auf der Verlängerung von AB hinter B liegt
16 16
 // Wert den Code mit A=B aufruf ist doof und verdient daß alles platzt
17
-double dividing_ratio(pixel_t* A, pixel_t* B, pixel_t* C) {
17
+double dividing_ratio(vector_t* A, vector_t* B, vector_t* C) {
18 18
 	return ((C->x - A->x)*(B->x - A->x) + (C->y - A->y)*(B->y - A->y))/pow(dist(A, B),2);
19 19
 }
20 20
 
@@ -22,16 +22,14 @@ double dividing_ratio(pixel_t* A, pixel_t* B, pixel_t* C) {
22 22
 // Achtung dies liefert den vorzeichenbehafteten Abstand
23 23
 // Werte kleiner Null bedeuten das C "links" der Verbindungslinie liegt wenn man von A Richtung B schaut
24 24
 // Werte größer Null dementsprechend recht, exakt null auf der Verbindungslinie
25
-double dist_to_line(pixel_t* A, pixel_t* B, pixel_t* C) {
26
-	//return ((A->y - B->y)*C->x + (A->x - B->x)*C->y + (A->x * B->y - A->y * B->x))/dist(A,B);
27
-	//return ((B->y - A->y)*C->x + (A->x - B->x)* C->y - ((B->y - A->y)* A->x + (A->x - B->x)* A->y))/dist(A,B);
25
+double dist_to_line(vector_t* A, vector_t* B, vector_t* C) {
28 26
 	return ((A->y - B->y)*C->x - (A->x - B->x)* C->y + ((B->y - A->y)* A->x + (A->x - B->x)* A->y))/dist(A,B);
29 27
 }
30 28
 
31 29
 // Was ist der Minimal-Abstand von C zum Liniensegment AB?
32 30
 // Die ist der Abstand zwischen C und dem Fußpunkt des Lots auf AB fall dieser zwischen A und B fällt
33 31
 // Ansonsten der Abstand zu A btw B
34
-double dist_to_seg(pixel_t* A, pixel_t* B, pixel_t* C) {
32
+double dist_to_seg(vector_t* A, vector_t* B, vector_t* C) {
35 33
 	double r = dividing_ratio(A, B, C);
36 34
 	if(r <= 0) {
37 35
 		return dist(A, C);
@@ -42,10 +40,10 @@ double dist_to_seg(pixel_t* A, pixel_t* B, pixel_t* C) {
42 40
 	}
43 41
 }
44 42
 
45
-waypoint_t* go_around(pixel_t* A, pixel_t* B, pixel_t* C, double r) {
46
-	pixel_t X = { A->x + r*(B->x - A->x), A->y + r*(B->y - A->y) };
47
-	double d = dist(&X, C);
48
-	pixel_t W = {C->x + safety_radius*sqrt(2)*(X.x - C->x) / d, C->y + safety_radius*sqrt(2)*(X.y - C->y) / d};
43
+waypoint_t* go_around(vector_t* A, vector_t* B, cluster_t* C, double r) {
44
+	vector_t X = { A->x + r*(B->x - A->x), A->y + r*(B->y - A->y) };
45
+	double d = dist(&X, &(C->center));
46
+	vector_t W = {C->center.x + C->safety_radius*sqrt(2)*(X.x - C->center.x) / d, C->center.y + C->safety_radius*sqrt(2)*(X.y - C->center.y) / d};
49 47
 	waypoint_t* wp = malloc(sizeof(waypoint_t));
50 48
 	wp->next = NULL;
51 49
 	wp->point.x = W.x;
@@ -53,29 +51,17 @@ waypoint_t* go_around(pixel_t* A, pixel_t* B, pixel_t* C, double r) {
53 51
 	return wp;
54 52
 }
55 53
 
56
-waypoint_t* route(pixel_t* start, pixel_t* stop, pixel_t* points, int n_points) {
54
+waypoint_t* route(vector_t* start, vector_t* stop, cluster_t* cluster, int n_points) {
57 55
 	int i;
58 56
 
59 57
 	int i_min = -1;
60 58
 	double r_min = 1;
61 59
 
62 60
 	for(i = 0; i < n_points; i++) {
63
-		if((points[i].x < start->x - safety_radius) && (points[i].x < stop->x - safety_radius)) {
64
-			continue;
65
-		}
66
-		if((points[i].x > start->x + safety_radius) && (points[i].x > stop->x + safety_radius)) {
67
-			continue;
68
-		}
69
-		if((points[i].y < start->y - safety_radius) && (points[i].y < stop->y - safety_radius)) {
70
-			continue;
71
-		}
72
-		if((points[i].y > start->y + safety_radius) && (points[i].y > stop->y + safety_radius)) {
73
-			continue;
74
-		}
75
-		double r = dividing_ratio(start, stop, &(points[i]));
61
+		double r = dividing_ratio(start, stop, &(cluster[i].center));
76 62
 		if (r > 0 && r < 1) {
77
-			double d = dist_to_line(start, stop, &(points[i]));
78
-			if (fabs(d) < safety_radius) {
63
+			double d = dist_to_line(start, stop, &(cluster[i].center));
64
+			if (fabs(d) < cluster[i].safety_radius) {
79 65
 				if(fabs(r-0.5) < fabs(r_min-0.5)) {
80 66
 					i_min = i;
81 67
 					r_min = r;
@@ -85,9 +71,9 @@ waypoint_t* route(pixel_t* start, pixel_t* stop, pixel_t* points, int n_points)
85 71
 	}
86 72
 
87 73
 	if(i_min >= 0) {
88
-		waypoint_t* wp = go_around(start, stop, &(points[i_min]), r_min);
74
+		waypoint_t* wp = go_around(start, stop, &(cluster[i_min]), r_min);
89 75
 
90
-		waypoint_t* part1 = route(start, &(wp->point), points, n_points);
76
+		waypoint_t* part1 = route(start, &(wp->point), cluster, n_points);
91 77
 		if(part1 == NULL) {
92 78
 			part1 = wp;
93 79
 		} else {
@@ -97,7 +83,7 @@ waypoint_t* route(pixel_t* start, pixel_t* stop, pixel_t* points, int n_points)
97 83
 			}
98 84
 			t->next = wp;
99 85
 		}
100
-		waypoint_t* part2 = route(&(wp->point), stop, points, n_points);
86
+		waypoint_t* part2 = route(&(wp->point), stop, cluster, n_points);
101 87
 		if(part2 != 0) {
102 88
 			waypoint_t* t = part1;
103 89
 			while(t->next != NULL) {
@@ -111,7 +97,7 @@ waypoint_t* route(pixel_t* start, pixel_t* stop, pixel_t* points, int n_points)
111 97
 	}
112 98
 }
113 99
 
114
-waypoint_t* plotCourse(pixel_t* start, pixel_t* stop, pixel_t* points, int n) {
100
+waypoint_t* plotCourse(vector_t* start, vector_t* stop, cluster_t* cluster, int n) {
115 101
 	int n_points = n*n;
116 102
 	waypoint_t* wp_start = malloc(sizeof(waypoint_t));
117 103
 	waypoint_t* wp_stop = malloc(sizeof(waypoint_t));
@@ -119,7 +105,7 @@ waypoint_t* plotCourse(pixel_t* start, pixel_t* stop, pixel_t* points, int n) {
119 105
 	wp_start->point.y = start->y;
120 106
 	wp_stop->point.x = stop->x;
121 107
 	wp_stop->point.y = stop->y;
122
-	wp_start->next = route(start, stop, points, n_points);
108
+	wp_start->next = route(start, stop, cluster, n_points);
123 109
 	wp_stop->next = NULL;
124 110
 	waypoint_t* t = wp_start;
125 111
 
@@ -131,14 +117,14 @@ waypoint_t* plotCourse(pixel_t* start, pixel_t* stop, pixel_t* points, int n) {
131 117
 	return wp_start;
132 118
 }
133 119
 
134
-void get_surrounding_points(pixel_t *surrounding_points, pixel_t *points, int n, int face_x, int face_y) {
135
-	surrounding_points[0] = points[(face_y - 1) * n + (face_x - 1)];
136
-	surrounding_points[1] = points[(face_y) * n + (face_x - 1)];
137
-	surrounding_points[2] = points[(face_y) * n + (face_x)];
138
-	surrounding_points[3] = points[(face_y - 1) * n + (face_x)];
120
+void get_surrounding_points(vector_t *surrounding_points, cluster_t *clusters, int n, int face_x, int face_y) {
121
+	surrounding_points[0] = clusters[(face_y - 1) * n + (face_x - 1)].center;
122
+	surrounding_points[1] = clusters[(face_y) * n + (face_x - 1)].center;
123
+	surrounding_points[2] = clusters[(face_y) * n + (face_x)].center;
124
+	surrounding_points[3] = clusters[(face_y - 1) * n + (face_x)].center;
139 125
 }
140 126
 
141
-int get_line_intersection(pixel_t *P0, pixel_t *P1, pixel_t *P2, pixel_t *P3, pixel_t *result)
127
+int get_line_intersection(vector_t *P0, vector_t *P1, vector_t *P2, vector_t *P3, vector_t *result)
142 128
 {
143 129
 	float s1_x, s1_y, s2_x, s2_y;
144 130
 	s1_x = P1->x - P0->x;
@@ -162,18 +148,18 @@ int get_line_intersection(pixel_t *P0, pixel_t *P1, pixel_t *P2, pixel_t *P3, pi
162 148
 	return 0;
163 149
 }
164 150
 
165
-void find_face(pixel_t *p, pixel_t *points, int n, int *x, int *y) {
151
+void find_face(vector_t *p, cluster_t *cluster, int n, int *x, int *y) {
166 152
 	int face_x = p->x / (GLOBALS.WIDTH / (n + 1));
167 153
 	int face_y = p->y / (GLOBALS.HEIGHT / (n + 1));
168 154
 	int edge;
169 155
 	int retry = 1;
170 156
 	int count = 0;
171 157
 
172
-	pixel_t surrounding[4];
158
+	vector_t surrounding[4];
173 159
 
174 160
 	while (retry && count < 4) {
175 161
 		retry = 0;
176
-		get_surrounding_points(surrounding, points, n, face_x, face_y);
162
+		get_surrounding_points(surrounding, cluster, n, face_x, face_y);
177 163
 
178 164
 		for (edge = 0; edge < 4; edge++) {
179 165
 			double r = dist_to_line(surrounding + edge, surrounding + (edge + 1) % 4, p);
@@ -213,12 +199,12 @@ waypoint_t *smooth(waypoint_t *way, int res) {
213 199
 	waypoint_t *working_start;
214 200
 	waypoint_t *working;
215 201
 
216
-	pixel_t startp;
217
-	pixel_t midp;
218
-	pixel_t endp;
219
-	pixel_t t1, t2;
220
-	pixel_t v1, v2;
221
-	pixel_t s;
202
+	vector_t startp;
203
+	vector_t midp;
204
+	vector_t endp;
205
+	vector_t t1, t2;
206
+	vector_t v1, v2;
207
+	vector_t s;
222 208
 
223 209
 	int i;
224 210
 
@@ -275,14 +261,14 @@ waypoint_t *smooth(waypoint_t *way, int res) {
275 261
 	return working_start;
276 262
 }
277 263
 
278
-waypoint_t* plotCourse_gridbased(pixel_t *start, pixel_t *stop, pixel_t *points, int n) {
264
+waypoint_t* plotCourse_gridbased(vector_t *start, vector_t *stop, cluster_t *cluster, int n) {
279 265
 	int face_x, face_y, face_s_x, face_s_y;
280 266
 	int edge;
281 267
 	int last_edge = -1;
282 268
 
283
-	find_face(start, points, n, &face_x, &face_y);
284
-	find_face(stop, points, n, &face_s_x, &face_s_y);
285
-	pixel_t surrounding[4];
269
+	find_face(start, cluster, n, &face_x, &face_y);
270
+	find_face(stop, cluster, n, &face_s_x, &face_s_y);
271
+	vector_t surrounding[4];
286 272
 	waypoint_t *wp_start = malloc (sizeof(waypoint_t));
287 273
 	wp_start->point = *start;
288 274
 	wp_start->next  = NULL;
@@ -290,8 +276,8 @@ waypoint_t* plotCourse_gridbased(pixel_t *start, pixel_t *stop, pixel_t *points,
290 276
 	waypoint_t *working = wp_start;
291 277
 
292 278
 	while (face_x != face_s_x || face_y != face_s_y) {
293
-		pixel_t c;
294
-		get_surrounding_points(surrounding, points, n, face_x, face_y);
279
+		vector_t c;
280
+		get_surrounding_points(surrounding, cluster, n, face_x, face_y);
295 281
 
296 282
 		for (edge = 0; edge < 4; edge++) {
297 283
 			if (edge == last_edge) continue;

+ 3
- 10
gitter/route.h View File

@@ -3,15 +3,8 @@
3 3
 
4 4
 #include "screen.h"
5 5
 
6
-typedef struct wp_t waypoint_t;
7
-
8
-struct wp_t {
9
-        pixel_t point;
10
-        waypoint_t* next;
11
-};
12
-
13
-waypoint_t *smooth(waypoint_t *way, int res);
14
-waypoint_t* plotCourse(pixel_t* start, pixel_t* stop, pixel_t* points, int n);
15
-waypoint_t* plotCourse_gridbased(pixel_t* start, pixel_t* stop, pixel_t* points, int n);
6
+waypoint_t* smooth(waypoint_t *way, int res);
7
+waypoint_t* plotCourse(vector_t* start, vector_t* stop, cluster_t* clusters, int n);
8
+waypoint_t* plotCourse_gridbased(vector_t* start, vector_t* stop, cluster_t* clusters, int n);
16 9
 
17 10
 #endif  /*ROUTE_H*/

+ 44
- 44
gitter/screen.c View File

@@ -51,37 +51,37 @@ void sdl_init() {
51 51
 	}
52 52
 }
53 53
 
54
-void draw_line(pixel_t *p1, pixel_t *p2) {
54
+void draw_line(vector_t* p1, vector_t* p2) {
55 55
 	aalineRGBA(screen, p1->x, p1->y, p2->x, p2->y, 255, 255, 255, 255);
56 56
 }
57 57
 
58
-void draw_blob(pixel_t *p1) {
59
-	aacircleRGBA(screen, p1->x, p1->y, 2, 255, 255, 255, 255);
60
-	aacircleRGBA(screen, p1->x, p1->y, safety_radius, 64, 64, 64, 255);
58
+void draw_blob(cluster_t* p) {
59
+	aacircleRGBA(screen, p->center.x, p->center.y, 2, 255, 255, 255, 255);
60
+	aacircleRGBA(screen, p->center.x, p->center.y, p->safety_radius, 64, 64, 64, 255);
61 61
 }
62 62
 
63
-void draw_points(pixel_t *points, int n) {
63
+void draw_clusters(cluster_t* clusters, int n) {
64 64
 	int x, y;
65 65
 
66 66
 	for (y = 0; y < n; y++) {
67 67
 		for (x = 0; x < n; x++) {
68
-			draw_blob(&points[y*n + x]);
68
+			draw_blob(&clusters[y*n + x]);
69 69
 		}
70 70
 	}
71 71
 }
72 72
 
73
-void draw_grid(pixel_t *points, int n) {
73
+void draw_grid(cluster_t *clusters, int n) {
74 74
 	int x, y;
75 75
 
76 76
 	for (y = 0; y < n - 1; y++) {
77 77
 		for (x = 0; x < n - 1; x++) {
78
-			draw_line(&points[y*n + x], &points[y*n + x + 1]);
79
-			draw_line(&points[y*n + x], &points[(y + 1)*n + x]);
78
+			draw_line(&(clusters[y*n + x].center), &(clusters[y*n + x + 1].center));
79
+			draw_line(&(clusters[y*n + x].center), &(clusters[(y + 1)*n + x].center));
80 80
 		}
81
-		draw_line(&points[y*n + x], &points[(y + 1)*n + x]);
81
+		draw_line(&(clusters[y*n + x].center), &(clusters[(y + 1)*n + x].center));
82 82
 	}
83 83
 	for (x = 0; x < n - 1; x++) {
84
-		draw_line(&points[y*n + x], &points[y*n + x + 1]);
84
+		draw_line(&(clusters[y*n + x].center), &(clusters[y*n + x + 1].center));
85 85
 	}
86 86
 }
87 87
 
@@ -96,45 +96,46 @@ void draw_route(waypoint_t* route, int r, int g, int b, int with_blobs) {
96 96
 	aacircleRGBA(screen, t->point.x, t->point.y, 2, r, g, g, 255);
97 97
 }
98 98
 
99
-void squirl(pixel_t *points, int n) {
99
+void squirl(cluster_t *clusters, int n) {
100 100
 	int i, j;
101 101
 
102 102
 	for (i = 0; i < n; i++) {
103 103
 		for (j = 0; j < n; j++) {
104
-			float x = points[i*n + j].x;
105
-			float y = points[i*n + j].y;
104
+			float x = clusters[i*n + j].center.x;
105
+			float y = clusters[i*n + j].center.y;
106 106
 			float r = hypotf(x-GLOBALS.WIDTH / 2, y - GLOBALS.HEIGHT/2);
107 107
 			float phi = atan2f(y-GLOBALS.HEIGHT / 2, x - GLOBALS.WIDTH/2);
108 108
 			float angle = (1e-3 * r - 0.5);
109 109
 			phi += angle;
110 110
 			x = GLOBALS.WIDTH/2 + r*cos(phi);
111 111
 			y = GLOBALS.HEIGHT/2 + r * sin(phi);
112
-			points[i*n + j].x = x;
113
-			points[i*n + j].y = y;
112
+			clusters[i*n + j].center.x = x;
113
+			clusters[i*n + j].center.y = y;
114 114
 		}
115 115
 	}
116 116
 }
117 117
 
118
-void randomize(pixel_t *points, int n, float fac) {
118
+void randomize(cluster_t *clusters, int n, float fac) {
119 119
 	int i;
120 120
 
121 121
 	for (i = 0; i < n * n; i++) {
122
-		points[i].x += (((float) rand() / RAND_MAX) - 0.5) * 2 * fac;
123
-		points[i].y += (((float) rand() / RAND_MAX) - 0.5) * 2 * fac;
122
+		clusters[i].center.x += (((float) rand() / RAND_MAX) - 0.5) * 2 * fac;
123
+		clusters[i].center.y += (((float) rand() / RAND_MAX) - 0.5) * 2 * fac;
124 124
 	}
125 125
 }
126 126
 
127
-void set(pixel_t *points, int n) {
127
+void set(cluster_t *clusters, int n, float safety_radius) {
128 128
 	int x, y;
129 129
 
130 130
 	for (y = 0; y < n; y++) {
131 131
 		for (x = 0; x < n; x++) {
132
-			points[y*n + x].x = GLOBALS.WIDTH  * (x + 1) / (n + 1);
133
-			points[y*n + x].y = GLOBALS.HEIGHT * (y + 1) / (n + 1);
132
+			clusters[y*n + x].center.x = GLOBALS.WIDTH  * (x + 1) / (n + 1);
133
+			clusters[y*n + x].center.y = GLOBALS.HEIGHT * (y + 1) / (n + 1);
134
+			clusters[y*n + x].safety_radius = (y*n+x)%5 ? safety_radius : safety_radius/2;
134 135
 		}
135 136
 	}
136 137
 
137
-	squirl(points, n);
138
+	squirl(clusters, n);
138 139
 }
139 140
 
140 141
 int main_loop() {
@@ -147,9 +148,8 @@ int main_loop() {
147 148
 	int view_json = 0;
148 149
 	float fac = GLOBALS.WIDTH / (n + 1) * 0.3;
149 150
 	SDL_Event e;
150
-	pixel_t *points;
151
-	pixel_t start = {0, 0};
152
-	pixel_t stop = {0, 0};
151
+	vector_t start = {0, 0};
152
+	vector_t stop = {0, 0};
153 153
 	waypoint_t* route1 = NULL;
154 154
 	waypoint_t* route1s = NULL;
155 155
 	waypoint_t* route2 = NULL;
@@ -159,19 +159,19 @@ int main_loop() {
159 159
 	struct timeval t1, t2;
160 160
 	double elapsedTime;
161 161
 
162
-	points = (pixel_t *) malloc (sizeof(pixel_t) * n * n);
162
+	cluster_t* clusters = malloc (sizeof(cluster_t) * n * n);
163 163
 
164
-	set(points, n);
164
+	set(clusters, n, safety_radius);
165 165
 
166 166
 	while (!quit) {
167 167
 		safety_radius = GLOBALS.HEIGHT / (n + 1) / 5 ;
168 168
 		SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
169 169
 		if (view_grid) {
170
-			draw_grid(points, n);
170
+			draw_grid(clusters, n);
171 171
 		}
172 172
 
173 173
 		if (view_points) {
174
-			draw_points(points, n);
174
+			draw_clusters(clusters, n);
175 175
 		}
176 176
 
177 177
 		if (view_waypoints) {
@@ -214,7 +214,7 @@ int main_loop() {
214 214
 					fprintf(stderr, "\n\nRoute from (%f,%f) to (%f,%f)\n", start.x, start.y, stop.x, stop.y);
215 215
 
216 216
 					gettimeofday(&t1, NULL);
217
-					route1 = plotCourse(&start, &stop, points, n);
217
+					route1 = plotCourse(&start, &stop, clusters, n);
218 218
 					gettimeofday(&t2, NULL);
219 219
 					elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
220 220
 					elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
@@ -228,7 +228,7 @@ int main_loop() {
228 228
 					fprintf(stderr, "smoth scanline based route took %f ms\n", elapsedTime);
229 229
 
230 230
 					gettimeofday(&t1, NULL);
231
-					route2 = plotCourse_gridbased(&start, &stop, points, n);
231
+					route2 = plotCourse_gridbased(&start, &stop, clusters, n);
232 232
 					gettimeofday(&t2, NULL);
233 233
 					elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
234 234
 					elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
@@ -266,39 +266,39 @@ int main_loop() {
266 266
 						needJsonOutput = view_json;
267 267
 						break;
268 268
 					case SDLK_r:
269
-						randomize(points, n, fac);
269
+						randomize(clusters, n, fac);
270 270
 						break;
271 271
 					case SDLK_BACKSPACE:
272
-						set(points, n);
272
+						set(clusters, n, safety_radius);
273 273
 						break;
274 274
 					case SDLK_q:
275 275
 						quit = 1;
276 276
 						break;
277 277
 					case SDLK_UP:
278 278
 						n++;
279
-						points = (pixel_t *) realloc (points, sizeof(pixel_t) * n * n);
279
+						clusters = realloc(clusters, sizeof(cluster_t) * n * n);
280 280
 						fac = GLOBALS.WIDTH / (n + 1) * 0.3;
281
-						set(points, n);
281
+						set(clusters, n, safety_radius);
282 282
 						break;
283 283
 					case SDLK_DOWN:
284 284
 						n--;
285
-						points = (pixel_t *) realloc (points, sizeof(pixel_t) * n * n);
285
+						clusters = realloc (clusters, sizeof(cluster_t) * n * n);
286 286
 						fac = GLOBALS.WIDTH / (n + 1) * 0.3;
287
-						set(points, n);
287
+						set(clusters, n, safety_radius);
288 288
 						break;
289 289
 					case SDLK_PLUS:
290 290
 					case SDLK_KP_PLUS:
291 291
 						fac *= 1.1;
292 292
 						fprintf(stderr, "fac: %f\n", fac);
293
-						set(points, n);
294
-						randomize(points, n, fac);
293
+						set(clusters, n, safety_radius);
294
+						randomize(clusters, n, fac);
295 295
 						break;
296 296
 					case SDLK_MINUS:
297 297
 					case SDLK_KP_MINUS:
298 298
 						fac /= 1.1;
299 299
 						fprintf(stderr, "fac: %f\n", fac);
300
-						set(points, n);
301
-						randomize(points, n, fac);
300
+						set(clusters, n, safety_radius);
301
+						randomize(clusters, n, fac);
302 302
 						break;
303 303
 					default:
304 304
 						needJsonOutput = 0;
@@ -315,11 +315,11 @@ int main_loop() {
315 315
 				break;
316 316
 		}
317 317
 		if(needJsonOutput) {
318
-			json_output(points, n*n);
318
+			json_output(clusters, n*n);
319 319
 		}
320 320
 	}
321 321
 
322
-	free(points);
322
+	free(clusters);
323 323
 
324 324
 	return 0;
325 325
 }

+ 14
- 4
gitter/screen.h View File

@@ -6,14 +6,24 @@
6 6
 typedef struct {
7 7
 	float x;
8 8
 	float y;
9
-} pixel_t;
9
+} vector_t;
10 10
 
11
-extern int safety_radius;
11
+typedef struct {
12
+	vector_t center;
13
+	float safety_radius;
14
+} cluster_t;
15
+
16
+typedef struct wp_t waypoint_t;
17
+
18
+struct wp_t {
19
+        vector_t point;
20
+        waypoint_t* next;
21
+};
12 22
 
13 23
 void sdl_init();
14 24
 int main_loop();
15 25
 
16
-void draw_line(pixel_t *p1, pixel_t *p2);
17
-void draw_blob(pixel_t *p1);
26
+void draw_line(vector_t *p1, vector_t *p2);
27
+void draw_blob(cluster_t* p);
18 28
 
19 29
 #endif  /*SCREEN_H*/