Revision 320
multiplayer almost working, serial data not being transmitted?
proj/include/ent.h | ||
---|---|---|
49 | 49 |
void (bullet_dtor)(bullet_t *p); |
50 | 50 |
double (bullet_get_x) (const bullet_t *p); |
51 | 51 |
double (bullet_get_y) (const bullet_t *p); |
52 |
double (bullet_get_vx) (const bullet_t *p); |
|
53 |
double (bullet_get_vy) (const bullet_t *p); |
|
52 | 54 |
int16_t (bullet_get_x_screen)(const bullet_t *p); |
53 | 55 |
int16_t (bullet_get_y_screen)(const bullet_t *p); |
54 | 56 |
double (bullet_get_damage) (const bullet_t *p); |
proj/include/proj_func.h | ||
---|---|---|
37 | 37 |
|
38 | 38 |
int32_t* get_mouse_Y(void); |
39 | 39 |
|
40 |
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote, list_t *bullet_list); |
|
41 |
|
|
42 |
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle); |
|
43 |
|
|
40 | 44 |
/** |
41 | 45 |
* @brief |
42 | 46 |
* @param |
proj/include/proj_structures.h | ||
---|---|---|
2 | 2 |
#define PROJ_STRUCTURES_H_INCLUDED |
3 | 3 |
|
4 | 4 |
#include <stdint.h> |
5 |
#include "ent.h" |
|
5 | 6 |
|
6 | 7 |
typedef struct keys { |
7 | 8 |
uint8_t w_pressed : 1; |
... | ... | |
18 | 19 |
// host |
19 | 20 |
double host_x; |
20 | 21 |
double host_y; |
22 |
double host_angle; |
|
21 | 23 |
double host_health; |
22 | 24 |
double host_current_health; |
23 | 25 |
|
24 | 26 |
// remote |
25 | 27 |
double remote_x; |
26 | 28 |
double remote_y; |
29 |
double remote_angle; |
|
27 | 30 |
double remote_health; |
28 | 31 |
double remote_current_health; |
29 | 32 |
|
... | ... | |
38 | 41 |
|
39 | 42 |
typedef struct __attribute__((packed)) { |
40 | 43 |
keys_t remote_keys_pressed; |
41 |
int32_t remote_mouse_x; |
|
42 |
int32_t remote_mouse_y; |
|
43 |
size_t bullets_shot; |
|
44 |
double *bullets_x; |
|
45 |
double *bullets_y; |
|
46 |
double *bullets_angle; |
|
44 |
double remote_angle; |
|
47 | 45 |
} remote_info_t; |
48 | 46 |
|
47 |
typedef struct __attribute__((packed)) { |
|
48 |
bool new_bullet; |
|
49 |
} bullet_info_t; |
|
50 |
|
|
51 |
host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote); |
|
52 |
|
|
49 | 53 |
void host_info_dtor(host_info_t *p); |
50 | 54 |
|
55 |
remote_info_t* remote_info_ctor(); |
|
56 |
|
|
51 | 57 |
void remote_info_dtor(remote_info_t *p); |
52 | 58 |
|
59 |
bullet_info_t* bullet_info_ctor(); |
|
60 |
|
|
61 |
void bullet_info_dtor(bullet_info_t *p); |
|
62 |
|
|
53 | 63 |
#endif /* end of include guard: PROJ_STRUCTURES_H_INCLUDED */ |
proj/libs/uart/include/hltp.h | ||
---|---|---|
7 | 7 |
typedef enum{ |
8 | 8 |
hltp_type_invalid = 0x00, |
9 | 9 |
hltp_type_string = 0x53, |
10 |
hltp_type_host = 0x54, |
|
11 |
hltp_type_remote = 0x55 |
|
10 |
hltp_type_host = 0x48, |
|
11 |
hltp_type_remote = 0x52, |
|
12 |
hltp_type_bullet = 0x42 |
|
12 | 13 |
} hltp_type; |
13 | 14 |
|
14 | 15 |
int hltp_send_string(const char *p); |
15 | 16 |
int hltp_send_host_info(const host_info_t *p); |
16 | 17 |
int hltp_send_remote_info(const remote_info_t *p); |
18 |
int hltp_send_bullet_info(const bullet_info_t *p); |
|
17 | 19 |
hltp_type hltp_interpret(const uint8_t *p, const size_t sz, void **dest); |
18 | 20 |
#endif //HLTP_H_INCLUDED |
proj/libs/uart/src/hltp.c | ||
---|---|---|
21 | 21 |
host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t)); |
22 | 22 |
size_t pos = 0; |
23 | 23 |
// players information |
24 |
memcpy(ret, p + pos, sizeof(double)*8);
|
|
25 |
pos += sizeof(double)*8;
|
|
24 |
memcpy(ret, p + pos, sizeof(double)*10);
|
|
25 |
pos += sizeof(double)*10;
|
|
26 | 26 |
// size of arrays |
27 | 27 |
memcpy(&(ret->no_bullets), p + pos, sizeof(size_t)); |
28 | 28 |
pos += sizeof(size_t); |
... | ... | |
52 | 52 |
int hltp_send_host_info(const host_info_t *p) { |
53 | 53 |
|
54 | 54 |
uint8_t type = hltp_type_host; |
55 |
uint8_t* ptr[15]; size_t sz[15]; |
|
56 |
ptr[0] = (uint8_t*)& type ; sz[0] = 1; |
|
57 |
ptr[1] = (uint8_t*)&p->host_x ; sz[0] = sizeof(double); |
|
58 |
ptr[2] = (uint8_t*)&p->host_y ; sz[0] = sizeof(double); |
|
59 |
ptr[3] = (uint8_t*)&p->host_health ; sz[0] = sizeof(double); |
|
60 |
ptr[4] = (uint8_t*)&p->host_current_health ; sz[0] = sizeof(double); |
|
61 |
ptr[5] = (uint8_t*)&p->remote_x ; sz[0] = sizeof(double); |
|
62 |
ptr[6] = (uint8_t*)&p->remote_y ; sz[0] = sizeof(double); |
|
63 |
ptr[7] = (uint8_t*)&p->remote_health ; sz[0] = sizeof(double); |
|
64 |
ptr[8] = (uint8_t*)&p->remote_current_health ; sz[0] = sizeof(double); |
|
65 |
ptr[9] = (uint8_t*)&p->no_bullets ; sz[0] = sizeof(size_t); |
|
66 |
ptr[10] = (uint8_t*) p->bullets_x ; sz[0] = sizeof(double) * p->no_bullets; |
|
67 |
ptr[11] = (uint8_t*) p->bullets_y ; sz[0] = sizeof(double) * p->no_bullets; |
|
68 |
ptr[12] = (uint8_t*) p->bullets_vx ; sz[0] = sizeof(double) * p->no_bullets; |
|
69 |
ptr[13] = (uint8_t*) p->bullets_vy ; sz[0] = sizeof(double) * p->no_bullets; |
|
70 |
ptr[14] = (uint8_t*) p->bullets_shooter ; sz[0] = sizeof(double) * p->no_bullets; |
|
71 |
return nctp_send(2, ptr, sz); |
|
55 |
uint8_t* ptr[17]; size_t sz[17]; |
|
56 |
ptr[0] = (uint8_t*)& type ; sz[0] = 1; |
|
57 |
ptr[1] = (uint8_t*)&p->host_x ; sz[1] = sizeof(double); |
|
58 |
ptr[2] = (uint8_t*)&p->host_y ; sz[2] = sizeof(double); |
|
59 |
ptr[3] = (uint8_t*)&p->host_angle ; sz[3] = sizeof(double); |
|
60 |
ptr[4] = (uint8_t*)&p->host_health ; sz[4] = sizeof(double); |
|
61 |
ptr[5] = (uint8_t*)&p->host_current_health ; sz[5] = sizeof(double); |
|
62 |
ptr[6] = (uint8_t*)&p->remote_x ; sz[6] = sizeof(double); |
|
63 |
ptr[7] = (uint8_t*)&p->remote_y ; sz[7] = sizeof(double); |
|
64 |
ptr[8] = (uint8_t*)&p->remote_angle ; sz[8] = sizeof(double); |
|
65 |
ptr[9] = (uint8_t*)&p->remote_health ; sz[9] = sizeof(double); |
|
66 |
ptr[10] = (uint8_t*)&p->remote_current_health ; sz[10] = sizeof(double); |
|
67 |
ptr[11] = (uint8_t*)&p->no_bullets ; sz[11] = sizeof(size_t); |
|
68 |
ptr[12] = (uint8_t*) p->bullets_x ; sz[12] = sizeof(double) * p->no_bullets; |
|
69 |
ptr[13] = (uint8_t*) p->bullets_y ; sz[13] = sizeof(double) * p->no_bullets; |
|
70 |
ptr[14] = (uint8_t*) p->bullets_vx ; sz[14] = sizeof(double) * p->no_bullets; |
|
71 |
ptr[15] = (uint8_t*) p->bullets_vy ; sz[15] = sizeof(double) * p->no_bullets; |
|
72 |
ptr[16] = (uint8_t*) p->bullets_shooter ; sz[16] = sizeof(double) * p->no_bullets; |
|
73 |
return nctp_send(17, ptr, sz); |
|
72 | 74 |
} |
73 | 75 |
|
74 | 76 |
static remote_info_t* hltp_interpret_remote_info(const uint8_t *p) { |
... | ... | |
78 | 80 |
memcpy(&(ret->remote_keys_pressed), p + pos, sizeof(keys_t)); |
79 | 81 |
pos += sizeof(keys_t); |
80 | 82 |
// mouse positions |
81 |
memcpy(&(ret->remote_mouse_x), p + pos, sizeof(int32_t)); |
|
82 |
pos += sizeof(int32_t); |
|
83 |
memcpy(&(ret->remote_mouse_y), p + pos, sizeof(int32_t)); |
|
84 |
pos += sizeof(int32_t); |
|
85 |
// bullets shot |
|
86 |
memcpy(&(ret->bullets_shot), p + pos, sizeof(size_t)); |
|
87 |
pos += sizeof(size_t); |
|
88 |
size_t sz = ret->bullets_shot; |
|
89 |
// array containing the X positions of the bullets |
|
90 |
(ret->bullets_x) = (double*)malloc(sizeof(double)*sz); |
|
91 |
memcpy((ret->bullets_x), p + pos, sizeof(double)*sz); |
|
92 |
pos += sizeof(double)*sz; |
|
93 |
// array containing the Y positions of the bullets |
|
94 |
(ret->bullets_y) = (double*)malloc(sizeof(double)*sz); |
|
95 |
memcpy((ret->bullets_y), p + pos, sizeof(double)*sz); |
|
96 |
pos += sizeof(double)*sz; |
|
97 |
// array containing the angle of the bullets |
|
98 |
(ret->bullets_angle) = (double*)malloc(sizeof(double)*sz); |
|
99 |
memcpy((ret->bullets_angle), p + pos, sizeof(double)*sz); |
|
100 |
pos += sizeof(double)*sz; |
|
83 |
memcpy(&(ret->remote_angle), p + pos, sizeof(double)); |
|
101 | 84 |
|
102 | 85 |
return ret; |
103 | 86 |
} |
104 | 87 |
int hltp_send_remote_info(const remote_info_t *p) { |
105 | 88 |
|
106 | 89 |
uint8_t type = hltp_type_remote; |
107 |
uint8_t* ptr[8]; size_t sz[8];
|
|
90 |
uint8_t* ptr[3]; size_t sz[3];
|
|
108 | 91 |
ptr[0] = (uint8_t*)& type ; sz[0] = 1; |
109 |
ptr[1] = (uint8_t*)&p->remote_keys_pressed ; sz[0] = sizeof(keys_t); |
|
110 |
ptr[2] = (uint8_t*)&p->remote_mouse_x ; sz[0] = sizeof(int32_t); |
|
111 |
ptr[3] = (uint8_t*)&p->remote_mouse_y ; sz[0] = sizeof(int32_t); |
|
112 |
ptr[4] = (uint8_t*)&p->bullets_shot ; sz[0] = sizeof(size_t); |
|
113 |
ptr[5] = (uint8_t*) p->bullets_x ; sz[0] = sizeof(double) * p->bullets_shot; |
|
114 |
ptr[6] = (uint8_t*) p->bullets_y ; sz[0] = sizeof(double) * p->bullets_shot; |
|
115 |
ptr[7] = (uint8_t*) p->bullets_angle ; sz[0] = sizeof(double) * p->bullets_shot; |
|
92 |
ptr[1] = (uint8_t*)&p->remote_keys_pressed ; sz[1] = sizeof(keys_t); |
|
93 |
ptr[2] = (uint8_t*)&p->remote_angle ; sz[2] = sizeof(double); |
|
94 |
return nctp_send(3, ptr, sz); |
|
95 |
} |
|
96 |
|
|
97 |
static bullet_info_t* hltp_interpret_bullet_info(const uint8_t *p) { |
|
98 |
bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t)); |
|
99 |
memcpy(&(ret->new_bullet), p, sizeof(bool)); |
|
100 |
|
|
101 |
return ret; |
|
102 |
} |
|
103 |
|
|
104 |
int hltp_send_bullet_info(const bullet_info_t *p) { |
|
105 |
uint8_t type = hltp_type_bullet; |
|
106 |
uint8_t* ptr[2]; size_t sz[2]; |
|
107 |
ptr[0] = (uint8_t*)& type ; sz[0] = 1; |
|
108 |
ptr[1] = (uint8_t*)&p->new_bullet ; sz[1] = sizeof(bool); |
|
116 | 109 |
return nctp_send(2, ptr, sz); |
117 | 110 |
} |
118 | 111 |
|
119 | 112 |
hltp_type hltp_interpret(const uint8_t *p, const size_t sz, void **dest){ |
120 | 113 |
uint8_t ret = p[0]; |
121 | 114 |
switch(ret){ |
122 |
case hltp_type_string: *dest = hltp_interpret_string(p+1, sz-1); break; |
|
123 |
case hltp_type_host : *dest = hltp_interpret_host_info(p+1); break; |
|
124 |
case hltp_type_remote: *dest = hltp_interpret_remote_info(p+1); break; |
|
115 |
case hltp_type_string: *dest = hltp_interpret_string (p+1, sz-1); break; |
|
116 |
case hltp_type_host : *dest = hltp_interpret_host_info (p+1); break; |
|
117 |
case hltp_type_remote: *dest = hltp_interpret_remote_info(p+1); break; |
|
118 |
case hltp_type_bullet: *dest = hltp_interpret_bullet_info(p+1); break; |
|
125 | 119 |
default: *dest = NULL; break; |
126 | 120 |
} |
127 | 121 |
return ret; |
proj/src/ent.c | ||
---|---|---|
155 | 155 |
sprite_set_angle(ret->b, angle-M_PI_2); |
156 | 156 |
return ret; |
157 | 157 |
} |
158 |
|
|
158 | 159 |
void (bullet_dtor)(bullet_t *p){ |
159 | 160 |
if(p == NULL) return; |
160 | 161 |
sprite_dtor(p->b); |
... | ... | |
162 | 163 |
} |
163 | 164 |
double (bullet_get_x) (const bullet_t *p){ return p->x; } |
164 | 165 |
double (bullet_get_y) (const bullet_t *p){ return p->y; } |
166 |
double (bullet_get_vx) (const bullet_t *p){ return p->vx; } |
|
167 |
double (bullet_get_vy) (const bullet_t *p){ return p->vy; } |
|
165 | 168 |
int16_t (bullet_get_x_screen)(const bullet_t *p){ return (p->x-x_origin)*scale; } |
166 | 169 |
int16_t (bullet_get_y_screen)(const bullet_t *p){ return (p->y-y_origin)*scale; } |
167 | 170 |
double (bullet_get_damage) (const bullet_t *p){ return p->damage; } |
... | ... | |
384 | 387 |
} |
385 | 388 |
|
386 | 389 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) { |
390 |
if (shooter1 == shooter2) return false; |
|
387 | 391 |
double shooter1_radius = max(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0; |
388 | 392 |
double shooter2_radius = max(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0; |
389 | 393 |
double distance = distance_gunners(shooter1, shooter2); |
proj/src/proj.c | ||
---|---|---|
182 | 182 |
return 0; |
183 | 183 |
} |
184 | 184 |
|
185 |
host_info_t *host = NULL; |
|
186 |
remote_info_t *remote = NULL; |
|
185 |
host_info_t *host_info = NULL; |
|
186 |
remote_info_t *remote_info = NULL; |
|
187 |
bullet_info_t *bullet_info = NULL; |
|
187 | 188 |
|
188 | 189 |
static void multiplayer_process(const uint8_t *p, const size_t sz) { |
189 | 190 |
void *dest = NULL; |
190 | 191 |
hltp_type tp = hltp_interpret(p, sz, &dest); |
191 | 192 |
switch(tp){ |
192 | 193 |
case hltp_type_host: |
193 |
host_info_dtor(host); |
|
194 |
host = (host_info_t*)dest; |
|
194 |
host_info_dtor(host_info);
|
|
195 |
host_info = (host_info_t*)dest;
|
|
195 | 196 |
break; |
196 | 197 |
case hltp_type_remote: |
197 |
remote_info_dtor(remote); |
|
198 |
remote = (remote_info_t*)dest; |
|
198 |
remote_info_dtor(remote_info);
|
|
199 |
remote_info = (remote_info_t*)dest;
|
|
199 | 200 |
break; |
201 |
case hltp_type_bullet: |
|
202 |
bullet_info_dtor(bullet_info); |
|
203 |
bullet_info = (bullet_info_t*)dest; |
|
204 |
break; |
|
200 | 205 |
default: break; |
201 | 206 |
} |
202 | 207 |
} |
... | ... | |
264 | 269 |
} |
265 | 270 |
|
266 | 271 |
static int (multiplayer_host)(void) { |
267 |
//int r;
|
|
272 |
int r; |
|
268 | 273 |
|
269 | 274 |
nctp_dump(); |
270 |
nctp_set_processor(multiplayer_process);/*
|
|
275 |
nctp_set_processor(multiplayer_process); |
|
271 | 276 |
|
272 | 277 |
ent_set_scale(DEFAULT_SCALE); |
273 | 278 |
text_timer_t *in_game_timer = timer_ctor(font_get_default()); |
... | ... | |
277 | 282 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
278 | 283 |
gunner_set_spawn(shooter1, 75, 75); |
279 | 284 |
|
280 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n");
|
|
285 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 2); if(shooter2 == NULL) printf("Failed to get shooter2\n");
|
|
281 | 286 |
gunner_set_spawn(shooter2, 975, 75); |
282 | 287 |
|
283 | 288 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
... | ... | |
286 | 291 |
do { |
287 | 292 |
get_random_spawn(map1, shooter1, shooter_list); |
288 | 293 |
get_random_spawn(map1, shooter2, shooter_list); |
289 |
} while (distance_gunners(shooter1, shooter2) < 700);
|
|
294 |
} while (distance_gunners(shooter1, shooter2) < 500);
|
|
290 | 295 |
|
296 |
host_info = host_info_ctor(shooter1, shooter2); |
|
297 |
remote_info = remote_info_ctor(); |
|
298 |
bullet_info = bullet_info_ctor(); |
|
299 |
|
|
291 | 300 |
list_t *bullet_list = list_ctor(); |
292 | 301 |
|
293 | 302 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
... | ... | |
297 | 306 |
uint8_t last_lb = 0; |
298 | 307 |
struct packet pp; |
299 | 308 |
keys_t *keys = get_key_presses(); |
300 |
|
|
301 | 309 |
/// loop stuff |
302 | 310 |
uint32_t int_vector = 0; |
303 | 311 |
int good = true; |
304 | 312 |
int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
313 |
list_node_t *p1, *p2; // player states |
|
314 |
int state_1, state_2; |
|
305 | 315 |
while (good) { |
306 | 316 |
if ((r = get_interrupts_vector(&int_vector))) return r; |
307 | 317 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
308 |
interrupt_handler(i); |
|
309 |
switch (i) { |
|
310 |
case TIMER0_IRQ: |
|
318 |
if (int_vector & n) { |
|
319 |
interrupt_handler(i); |
|
320 |
switch (i) { |
|
321 |
case TIMER0_IRQ: |
|
322 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
311 | 323 |
|
312 |
break; |
|
324 |
update_movement(map1, shooter1, keys, shooter_list); |
|
325 |
update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list); |
|
313 | 326 |
|
314 |
case KBC_IRQ:
|
|
327 |
update_game_state(map1, shooter_list, bullet_list);
|
|
315 | 328 |
|
316 |
break; |
|
329 |
p1 = list_find(shooter_list, shooter1); |
|
330 |
p2 = list_find(shooter_list, shooter2); |
|
317 | 331 |
|
318 |
case MOUSE_IRQ: |
|
332 |
if ((state_1 = (p1 == list_end(shooter_list))) || (state_2 = (p2 == list_end(shooter_list)))) { |
|
333 |
state = state_1 - state_2; |
|
334 |
good = false; |
|
335 |
break; |
|
336 |
} |
|
319 | 337 |
|
338 |
double angle = get_mouse_angle(shooter1); |
|
339 |
gunner_set_angle(shooter1, angle - M_PI_2); |
|
320 | 340 |
|
321 |
break; |
|
341 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
342 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
322 | 343 |
|
323 |
case COM1_IRQ: nctp_ih(); break; |
|
344 |
gunner_set_angle(shooter2, remote_info->remote_angle); |
|
345 |
|
|
346 |
build_host_structure(host_info, shooter1, shooter2, bullet_list); |
|
347 |
|
|
348 |
hltp_send_host_info(host_info); |
|
349 |
|
|
350 |
graph_clear_screen(); |
|
351 |
map_draw (map1); |
|
352 |
bullet_draw_list(bullet_list); |
|
353 |
gunner_draw_list(shooter_list); |
|
354 |
|
|
355 |
text_draw(in_game_timer->text); |
|
356 |
|
|
357 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
358 |
sprite_draw(sp_crosshair); |
|
359 |
graph_draw(); |
|
360 |
|
|
361 |
break; |
|
362 |
case KBC_IRQ: |
|
363 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
364 |
good = false; |
|
365 |
} |
|
366 |
break; |
|
367 |
case MOUSE_IRQ: |
|
368 |
if (counter_mouse_ih >= 3) { |
|
369 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
370 |
update_mouse(&pp); |
|
371 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) |
|
372 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
373 |
last_lb = keys->lb_pressed; |
|
374 |
counter_mouse_ih = 0; |
|
375 |
} |
|
376 |
break; |
|
377 |
|
|
378 |
case COM1_IRQ: |
|
379 |
nctp_ih(); |
|
380 |
if (bullet_info->new_bullet) { |
|
381 |
shoot_bullet(shooter2, bullet_list, bsp_bullet); |
|
382 |
bullet_info->new_bullet = false; |
|
383 |
} |
|
384 |
break; |
|
385 |
} |
|
324 | 386 |
} |
325 | 387 |
} |
326 |
}*/
|
|
388 |
} |
|
327 | 389 |
|
390 |
while(list_size(shooter_list) > 0){ |
|
391 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
392 |
gunner_dtor(p); |
|
393 |
} |
|
394 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
395 |
|
|
396 |
while(list_size(bullet_list) > 0){ |
|
397 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
398 |
bullet_dtor(p); |
|
399 |
} |
|
400 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
401 |
|
|
402 |
host_info_dtor(host_info); |
|
403 |
remote_info_dtor(remote_info); |
|
404 |
bullet_info_dtor(bullet_info); |
|
405 |
|
|
406 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
|
407 |
|
|
328 | 408 |
return 0; |
329 | 409 |
} |
330 |
static int (multiplayer_remote)(void) {/*
|
|
410 |
static int (multiplayer_remote)(void) { |
|
331 | 411 |
int r; |
332 | 412 |
|
333 | 413 |
nctp_dump(); |
... | ... | |
338 | 418 |
|
339 | 419 |
list_t *shooter_list = list_ctor(); |
340 | 420 |
|
341 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
|
421 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 2); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
|
342 | 422 |
gunner_set_spawn(shooter1, 75, 75); |
343 | 423 |
|
344 | 424 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n"); |
... | ... | |
347 | 427 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
348 | 428 |
list_insert(shooter_list, list_end(shooter_list), shooter2); |
349 | 429 |
|
350 |
do { |
|
351 |
get_random_spawn(map1, shooter1, shooter_list); |
|
352 |
get_random_spawn(map1, shooter2, shooter_list); |
|
353 |
} while (distance_gunners(shooter1, shooter2) < 700); |
|
430 |
host_info = host_info_ctor(shooter2, shooter1); |
|
431 |
remote_info = remote_info_ctor(); |
|
432 |
bullet_info = bullet_info_ctor(); |
|
354 | 433 |
|
355 | 434 |
list_t *bullet_list = list_ctor(); |
356 | 435 |
|
... | ... | |
365 | 444 |
/// loop stuff |
366 | 445 |
uint32_t int_vector = 0; |
367 | 446 |
int good = true; |
368 |
int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
|
369 | 447 |
while (good) { |
370 | 448 |
if ((r = get_interrupts_vector(&int_vector))) return r; |
371 | 449 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
372 |
interrupt_handler(i); |
|
373 |
switch (i) { |
|
374 |
case TIMER0_IRQ: |
|
450 |
if (int_vector & n) { |
|
451 |
interrupt_handler(i); |
|
452 |
switch (i) { |
|
453 |
case TIMER0_IRQ: |
|
454 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
375 | 455 |
|
376 |
break;
|
|
456 |
double angle = get_mouse_angle(shooter1);
|
|
377 | 457 |
|
378 |
case KBC_IRQ:
|
|
458 |
build_remote_structure(remote_info, keys, angle);
|
|
379 | 459 |
|
380 |
break;
|
|
460 |
hltp_send_remote_info(remote_info);
|
|
381 | 461 |
|
382 |
case MOUSE_IRQ: |
|
462 |
gunner_set_pos(shooter1, host_info->remote_x, host_info->remote_y); |
|
463 |
gunner_set_angle(shooter1, host_info->remote_angle); |
|
464 |
gunner_set_health(shooter1, host_info->remote_health); |
|
465 |
gunner_set_curr_health(shooter1, host_info->remote_current_health); |
|
383 | 466 |
|
467 |
gunner_set_pos(shooter2, host_info->host_x, host_info->host_y); |
|
468 |
gunner_set_angle(shooter2, host_info->host_angle); |
|
469 |
gunner_set_health(shooter2, host_info->host_health); |
|
470 |
gunner_set_curr_health(shooter2, host_info->host_current_health); |
|
384 | 471 |
|
385 |
break; |
|
472 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
473 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
386 | 474 |
|
387 |
case COM1_IRQ: nctp_ih(); break; |
|
475 |
for (size_t i = 0; i < host_info->no_bullets; i++) { |
|
476 |
if (host_info->bullets_shooter[i]) { // remote |
|
477 |
bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, host_info->bullets_x[i], host_info->bullets_y[i], host_info->bullets_vx[i], host_info->bullets_vy[i]); |
|
478 |
list_insert(bullet_list, list_end(bullet_list), bullet); |
|
479 |
} else { // host |
|
480 |
bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, host_info->bullets_x[i], host_info->bullets_y[i], host_info->bullets_vx[i], host_info->bullets_vy[i]); |
|
481 |
list_insert(bullet_list, list_end(bullet_list), bullet); |
|
482 |
} |
|
483 |
} |
|
484 |
|
|
485 |
graph_clear_screen(); |
|
486 |
map_draw (map1); |
|
487 |
bullet_draw_list(bullet_list); |
|
488 |
gunner_draw_list(shooter_list); |
|
489 |
|
|
490 |
text_draw(in_game_timer->text); |
|
491 |
|
|
492 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
493 |
sprite_draw(sp_crosshair); |
|
494 |
graph_draw(); |
|
495 |
|
|
496 |
while(list_size(bullet_list) > 0){ |
|
497 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
498 |
bullet_dtor(p); |
|
499 |
} |
|
500 |
|
|
501 |
break; |
|
502 |
case KBC_IRQ: |
|
503 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
504 |
good = false; |
|
505 |
} |
|
506 |
break; |
|
507 |
case MOUSE_IRQ: |
|
508 |
if (counter_mouse_ih >= 3) { |
|
509 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
510 |
update_mouse(&pp); |
|
511 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) { |
|
512 |
bullet_info->new_bullet = true; |
|
513 |
hltp_send_bullet_info(bullet_info); |
|
514 |
} |
|
515 |
last_lb = keys->lb_pressed; |
|
516 |
counter_mouse_ih = 0; |
|
517 |
} |
|
518 |
break; |
|
519 |
|
|
520 |
case COM1_IRQ: nctp_ih(); break; |
|
521 |
} |
|
388 | 522 |
} |
389 | 523 |
} |
390 |
}*/
|
|
524 |
} |
|
391 | 525 |
|
526 |
while(list_size(shooter_list) > 0){ |
|
527 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
528 |
gunner_dtor(p); |
|
529 |
} |
|
530 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
531 |
|
|
532 |
while(list_size(bullet_list) > 0){ |
|
533 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
534 |
bullet_dtor(p); |
|
535 |
} |
|
536 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
537 |
|
|
538 |
host_info_dtor(host_info); |
|
539 |
remote_info_dtor(remote_info); |
|
540 |
bullet_info_dtor(bullet_info); |
|
541 |
|
|
542 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
|
543 |
|
|
392 | 544 |
return 0; |
393 | 545 |
} |
394 | 546 |
|
proj/src/proj_func.c | ||
---|---|---|
27 | 27 |
|
28 | 28 |
static keys_t key_presses; |
29 | 29 |
|
30 |
host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote) { |
|
31 |
host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t)); |
|
32 |
if (ret == NULL) return ret; |
|
33 |
|
|
34 |
ret->host_x = gunner_get_x (host); |
|
35 |
ret->host_y = gunner_get_y (host); |
|
36 |
ret->host_angle = gunner_get_angle (host); |
|
37 |
ret->host_health = gunner_get_health (host); |
|
38 |
ret->host_current_health = gunner_get_curr_health(host); |
|
39 |
|
|
40 |
// remote |
|
41 |
ret->remote_x = gunner_get_x (remote); |
|
42 |
ret->remote_y = gunner_get_y (remote); |
|
43 |
ret->remote_angle = gunner_get_angle (remote); |
|
44 |
ret->remote_health = gunner_get_health (remote); |
|
45 |
ret->remote_current_health = gunner_get_curr_health(remote); |
|
46 |
|
|
47 |
ret->no_bullets = 0; |
|
48 |
|
|
49 |
return ret; |
|
50 |
} |
|
51 |
|
|
30 | 52 |
void host_info_dtor(host_info_t *p) { |
31 | 53 |
if (p==NULL) return; |
32 | 54 |
|
... | ... | |
43 | 65 |
free(p); |
44 | 66 |
} |
45 | 67 |
|
68 |
remote_info_t* remote_info_ctor() { |
|
69 |
remote_info_t *ret = (remote_info_t*)malloc(sizeof(remote_info_t)); |
|
70 |
if (ret == NULL) return ret; |
|
71 |
|
|
72 |
memset(&(ret->remote_keys_pressed), 0, sizeof(keys_t)); |
|
73 |
|
|
74 |
ret->remote_angle = 0; |
|
75 |
|
|
76 |
return ret; |
|
77 |
} |
|
78 |
|
|
46 | 79 |
void remote_info_dtor(remote_info_t *p) { |
47 | 80 |
if (p==NULL) return; |
81 |
free(p); |
|
82 |
} |
|
48 | 83 |
|
49 |
if ((p->bullets_x) != NULL){ free(p->bullets_x); p->bullets_x = NULL; } |
|
84 |
bullet_info_t* bullet_info_ctor() { |
|
85 |
bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t)); |
|
86 |
if (ret == NULL) return ret; |
|
50 | 87 |
|
51 |
if ((p->bullets_y) != NULL){ free(p->bullets_y); p->bullets_y = NULL; }
|
|
88 |
ret->new_bullet = false;
|
|
52 | 89 |
|
53 |
if ((p->bullets_angle) != NULL){ free(p->bullets_angle); p->bullets_angle = NULL; } |
|
90 |
return ret; |
|
91 |
} |
|
54 | 92 |
|
93 |
void bullet_info_dtor(bullet_info_t *p) { |
|
94 |
if (p == NULL) return; |
|
55 | 95 |
free(p); |
56 | 96 |
} |
57 | 97 |
|
... | ... | |
278 | 318 |
return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p)); |
279 | 319 |
} |
280 | 320 |
|
321 |
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote, list_t *bullet_list) { |
|
322 |
// host |
|
323 |
p->host_x = gunner_get_x (host); |
|
324 |
p->host_y = gunner_get_y (host); |
|
325 |
p->host_angle = gunner_get_angle (host); |
|
326 |
p->host_health = gunner_get_health (host); |
|
327 |
p->host_current_health = gunner_get_curr_health(host); |
|
328 |
|
|
329 |
// remote |
|
330 |
p->remote_x = gunner_get_x (remote); |
|
331 |
p->remote_y = gunner_get_y (remote); |
|
332 |
p->remote_angle = gunner_get_angle (remote); |
|
333 |
p->remote_health = gunner_get_health (remote); |
|
334 |
p->remote_current_health = gunner_get_curr_health(remote); |
|
335 |
|
|
336 |
// bullets |
|
337 |
size_t sz = list_size(bullet_list); |
|
338 |
p->no_bullets = sz; |
|
339 |
p->bullets_x = (double*)realloc(p->bullets_x , sz * sizeof(double)); |
|
340 |
p->bullets_y = (double*)realloc(p->bullets_y , sz * sizeof(double)); |
|
341 |
p->bullets_vx = (double*)realloc(p->bullets_vx , sz * sizeof(double)); |
|
342 |
p->bullets_vy = (double*)realloc(p->bullets_vy , sz * sizeof(double)); |
|
343 |
p->bullets_shooter = (bool*) realloc(p->bullets_shooter , sz * sizeof(bool )); |
|
344 |
|
|
345 |
list_node_t *it = list_begin(bullet_list); |
|
346 |
size_t i = 0; |
|
347 |
while (it != list_end(bullet_list)) { |
|
348 |
bullet_t *bullet = *list_node_val(it); |
|
349 |
p->bullets_x [i] = bullet_get_x (bullet); |
|
350 |
p->bullets_y [i] = bullet_get_y (bullet); |
|
351 |
p->bullets_vx [i] = bullet_get_vx (bullet); |
|
352 |
p->bullets_vy [i] = bullet_get_vy (bullet); |
|
353 |
p->bullets_shooter [i] = gunner_get_team(bullet_get_shooter(bullet)) != gunner_get_team(host); |
|
354 |
it = list_node_next(it); |
|
355 |
i++; |
|
356 |
} |
|
357 |
} |
|
358 |
|
|
359 |
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle) { |
|
360 |
memcpy(&(p->remote_keys_pressed), keys, sizeof(keys_t)); |
|
361 |
p->remote_angle = angle; |
|
362 |
} |
|
363 |
|
|
281 | 364 |
text_timer_t* (timer_ctor)(const font_t *fnt){ |
282 | 365 |
if(fnt == NULL) return NULL; |
283 | 366 |
text_timer_t *ret = malloc(sizeof(timer_t)); |
Also available in: Unified diff