Revision 329
trying to make it work
proj/include/proj_structures.h | ||
---|---|---|
17 | 17 |
|
18 | 18 |
typedef struct { |
19 | 19 |
// host |
20 |
float host_x;
|
|
21 |
float host_y;
|
|
22 |
float host_angle;
|
|
23 |
float host_health;
|
|
24 |
float host_current_health;
|
|
20 |
int16_t host_x;
|
|
21 |
int16_t host_y;
|
|
22 |
int16_t host_angle;
|
|
23 |
int16_t host_health;
|
|
24 |
int16_t host_current_health;
|
|
25 | 25 |
|
26 | 26 |
// remote |
27 |
float remote_x;
|
|
28 |
float remote_y;
|
|
29 |
float remote_angle;
|
|
30 |
float remote_health;
|
|
31 |
float remote_current_health;
|
|
27 |
int16_t remote_x;
|
|
28 |
int16_t remote_y;
|
|
29 |
int16_t remote_angle;
|
|
30 |
int16_t remote_health;
|
|
31 |
int16_t remote_current_health;
|
|
32 | 32 |
|
33 | 33 |
// bullets |
34 |
uint8_t no_bullets; |
|
35 |
float *bullets_x;
|
|
36 |
float *bullets_y;
|
|
37 |
float *bullets_vx;
|
|
38 |
float *bullets_vy;
|
|
39 |
bool *bullets_shooter; // false for host, true for remote |
|
34 |
uint8_t no_bullets;
|
|
35 |
int16_t *bullets_x;
|
|
36 |
int16_t *bullets_y;
|
|
37 |
int16_t *bullets_vx;
|
|
38 |
int16_t *bullets_vy;
|
|
39 |
bool *bullets_shooter; // false for host, true for remote
|
|
40 | 40 |
} host_info_t; |
41 | 41 |
|
42 | 42 |
typedef struct { |
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(float)*10);
|
|
25 |
pos += sizeof(float)*10;
|
|
24 |
memcpy(ret, p + pos, sizeof(int16_t)*10);
|
|
25 |
pos += sizeof(int16_t)*10;
|
|
26 | 26 |
// size of arrays |
27 | 27 |
memcpy(&(ret->no_bullets), p + pos, sizeof(uint8_t)); |
28 | 28 |
pos += sizeof(uint8_t); |
29 | 29 |
size_t sz = ret->no_bullets; |
30 | 30 |
// array containing the X positions of the bullets |
31 |
(ret->bullets_x) = (float*)malloc(sizeof(float)*sz);
|
|
32 |
memcpy((ret->bullets_x), p + pos, sizeof(float)*sz);
|
|
33 |
pos += sizeof(float)*sz;
|
|
31 |
(ret->bullets_x) = (int16_t*)malloc(sizeof(int16_t)*sz);
|
|
32 |
memcpy((ret->bullets_x), p + pos, sizeof(int16_t)*sz);
|
|
33 |
pos += sizeof(int16_t)*sz;
|
|
34 | 34 |
// array containing the Y positions of the bullets |
35 |
(ret->bullets_y) = (float*)malloc(sizeof(float)*(ret->no_bullets));
|
|
36 |
memcpy((ret->bullets_y), p + pos, sizeof(float)*sz);
|
|
37 |
pos += sizeof(float)*sz;
|
|
35 |
(ret->bullets_y) = (int16_t*)malloc(sizeof(int16_t)*(ret->no_bullets));
|
|
36 |
memcpy((ret->bullets_y), p + pos, sizeof(int16_t)*sz);
|
|
37 |
pos += sizeof(int16_t)*sz;
|
|
38 | 38 |
// array containing the X velocity of the bullets |
39 |
(ret->bullets_vx) = (float*)malloc(sizeof(float)*(ret->no_bullets));
|
|
40 |
memcpy((ret->bullets_vx), p + pos, sizeof(float)*sz);
|
|
41 |
pos += sizeof(float)*sz;
|
|
39 |
(ret->bullets_vx) = (int16_t*)malloc(sizeof(int16_t)*(ret->no_bullets));
|
|
40 |
memcpy((ret->bullets_vx), p + pos, sizeof(int16_t)*sz);
|
|
41 |
pos += sizeof(int16_t)*sz;
|
|
42 | 42 |
// array containing the Y velocity of the bullets |
43 |
(ret->bullets_vy) = (float*)malloc(sizeof(float)*(ret->no_bullets));
|
|
44 |
memcpy((ret->bullets_vy), p + pos, sizeof(float)*sz);
|
|
45 |
pos += sizeof(float)*sz;
|
|
43 |
(ret->bullets_vy) = (int16_t*)malloc(sizeof(int16_t)*(ret->no_bullets));
|
|
44 |
memcpy((ret->bullets_vy), p + pos, sizeof(int16_t)*sz);
|
|
45 |
pos += sizeof(int16_t)*sz;
|
|
46 | 46 |
// array containing the shooter id of the bullets |
47 | 47 |
(ret->bullets_shooter) = (bool*)malloc(sizeof(bool)*(ret->no_bullets)); |
48 | 48 |
memcpy((ret->bullets_shooter), p + pos, sizeof(bool)*sz); |
... | ... | |
54 | 54 |
uint8_t type = hltp_type_host; |
55 | 55 |
const uint8_t* ptr[17]; size_t sz[17]; |
56 | 56 |
ptr[0] = (uint8_t*)& type ; sz[0] = 1; |
57 |
ptr[1] = (uint8_t*)&p->host_x ; sz[1] = sizeof(float);
|
|
58 |
ptr[2] = (uint8_t*)&p->host_y ; sz[2] = sizeof(float);
|
|
59 |
ptr[3] = (uint8_t*)&p->host_angle ; sz[3] = sizeof(float);
|
|
60 |
ptr[4] = (uint8_t*)&p->host_health ; sz[4] = sizeof(float);
|
|
61 |
ptr[5] = (uint8_t*)&p->host_current_health ; sz[5] = sizeof(float);
|
|
62 |
ptr[6] = (uint8_t*)&p->remote_x ; sz[6] = sizeof(float);
|
|
63 |
ptr[7] = (uint8_t*)&p->remote_y ; sz[7] = sizeof(float);
|
|
64 |
ptr[8] = (uint8_t*)&p->remote_angle ; sz[8] = sizeof(float);
|
|
65 |
ptr[9] = (uint8_t*)&p->remote_health ; sz[9] = sizeof(float);
|
|
66 |
ptr[10] = (uint8_t*)&p->remote_current_health ; sz[10] = sizeof(float);
|
|
57 |
ptr[1] = (uint8_t*)&p->host_x ; sz[1] = sizeof(int16_t);
|
|
58 |
ptr[2] = (uint8_t*)&p->host_y ; sz[2] = sizeof(int16_t);
|
|
59 |
ptr[3] = (uint8_t*)&p->host_angle ; sz[3] = sizeof(int16_t);
|
|
60 |
ptr[4] = (uint8_t*)&p->host_health ; sz[4] = sizeof(int16_t);
|
|
61 |
ptr[5] = (uint8_t*)&p->host_current_health ; sz[5] = sizeof(int16_t);
|
|
62 |
ptr[6] = (uint8_t*)&p->remote_x ; sz[6] = sizeof(int16_t);
|
|
63 |
ptr[7] = (uint8_t*)&p->remote_y ; sz[7] = sizeof(int16_t);
|
|
64 |
ptr[8] = (uint8_t*)&p->remote_angle ; sz[8] = sizeof(int16_t);
|
|
65 |
ptr[9] = (uint8_t*)&p->remote_health ; sz[9] = sizeof(int16_t);
|
|
66 |
ptr[10] = (uint8_t*)&p->remote_current_health ; sz[10] = sizeof(int16_t);
|
|
67 | 67 |
ptr[11] = (uint8_t*)&p->no_bullets ; sz[11] = sizeof(uint8_t); |
68 |
ptr[12] = (uint8_t*) p->bullets_x ; sz[12] = sizeof(float) * p->no_bullets;
|
|
69 |
ptr[13] = (uint8_t*) p->bullets_y ; sz[13] = sizeof(float) * p->no_bullets;
|
|
70 |
ptr[14] = (uint8_t*) p->bullets_vx ; sz[14] = sizeof(float) * p->no_bullets;
|
|
71 |
ptr[15] = (uint8_t*) p->bullets_vy ; sz[15] = sizeof(float) * p->no_bullets;
|
|
72 |
ptr[16] = (uint8_t*) p->bullets_shooter ; sz[16] = sizeof(float) * p->no_bullets;
|
|
68 |
ptr[12] = (uint8_t*) p->bullets_x ; sz[12] = sizeof(int16_t) * p->no_bullets;
|
|
69 |
ptr[13] = (uint8_t*) p->bullets_y ; sz[13] = sizeof(int16_t) * p->no_bullets;
|
|
70 |
ptr[14] = (uint8_t*) p->bullets_vx ; sz[14] = sizeof(int16_t) * p->no_bullets;
|
|
71 |
ptr[15] = (uint8_t*) p->bullets_vy ; sz[15] = sizeof(int16_t) * p->no_bullets;
|
|
72 |
ptr[16] = (uint8_t*) p->bullets_shooter ; sz[16] = sizeof(bool) * p->no_bullets;
|
|
73 | 73 |
return nctp_send(17, ptr, sz); |
74 | 74 |
} |
75 | 75 |
|
proj/src/proj_func.c | ||
---|---|---|
31 | 31 |
host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t)); |
32 | 32 |
if (ret == NULL) return ret; |
33 | 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); |
|
34 |
ret->host_x = (int16_t)gunner_get_x (host);
|
|
35 |
ret->host_y = (int16_t)gunner_get_y (host);
|
|
36 |
ret->host_angle = (int16_t)gunner_get_angle (host);
|
|
37 |
ret->host_health = (int16_t)gunner_get_health (host);
|
|
38 |
ret->host_current_health = (int16_t)gunner_get_curr_health(host);
|
|
39 | 39 |
|
40 | 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); |
|
41 |
ret->remote_x = (int16_t)gunner_get_x (remote);
|
|
42 |
ret->remote_y = (int16_t)gunner_get_y (remote);
|
|
43 |
ret->remote_angle = (int16_t)gunner_get_angle (remote);
|
|
44 |
ret->remote_health = (int16_t)gunner_get_health (remote);
|
|
45 |
ret->remote_current_health = (int16_t)gunner_get_curr_health(remote);
|
|
46 | 46 |
|
47 | 47 |
ret->no_bullets = 0; |
48 | 48 |
|
... | ... | |
320 | 320 |
|
321 | 321 |
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote, list_t *bullet_list) { |
322 | 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); |
|
323 |
p->host_x = (int16_t)gunner_get_x (host);
|
|
324 |
p->host_y = (int16_t)gunner_get_y (host);
|
|
325 |
p->host_angle = (int16_t)gunner_get_angle (host);
|
|
326 |
p->host_health = (int16_t)gunner_get_health (host);
|
|
327 |
p->host_current_health = (int16_t)gunner_get_curr_health(host);
|
|
328 | 328 |
|
329 | 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); |
|
330 |
p->remote_x = (int16_t)gunner_get_x (remote);
|
|
331 |
p->remote_y = (int16_t)gunner_get_y (remote);
|
|
332 |
p->remote_angle = (int16_t)gunner_get_angle (remote);
|
|
333 |
p->remote_health = (int16_t)gunner_get_health (remote);
|
|
334 |
p->remote_current_health = (int16_t)gunner_get_curr_health(remote);
|
|
335 | 335 |
|
336 | 336 |
// bullets |
337 | 337 |
size_t sz = list_size(bullet_list); |
338 | 338 |
p->no_bullets = sz; |
339 |
p->bullets_x = (float*)realloc(p->bullets_x , sz * sizeof(float));
|
|
340 |
p->bullets_y = (float*)realloc(p->bullets_y , sz * sizeof(float));
|
|
341 |
p->bullets_vx = (float*)realloc(p->bullets_vx , sz * sizeof(float));
|
|
342 |
p->bullets_vy = (float*)realloc(p->bullets_vy , sz * sizeof(float));
|
|
343 |
p->bullets_shooter = (bool*) realloc(p->bullets_shooter , sz * sizeof(bool )); |
|
339 |
p->bullets_x = (int16_t*)realloc(p->bullets_x , sz * sizeof(int16_t));
|
|
340 |
p->bullets_y = (int16_t*)realloc(p->bullets_y , sz * sizeof(int16_t));
|
|
341 |
p->bullets_vx = (int16_t*)realloc(p->bullets_vx , sz * sizeof(int16_t));
|
|
342 |
p->bullets_vy = (int16_t*)realloc(p->bullets_vy , sz * sizeof(int16_t));
|
|
343 |
p->bullets_shooter = (bool*) realloc(p->bullets_shooter , sz * sizeof(bool ));
|
|
344 | 344 |
|
345 | 345 |
list_node_t *it = list_begin(bullet_list); |
346 | 346 |
size_t i = 0; |
347 | 347 |
while (it != list_end(bullet_list)) { |
348 | 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); |
|
349 |
p->bullets_x [i] = (int16_t)bullet_get_x (bullet);
|
|
350 |
p->bullets_y [i] = (int16_t)bullet_get_y (bullet);
|
|
351 |
p->bullets_vx [i] = (int16_t)bullet_get_vx (bullet);
|
|
352 |
p->bullets_vy [i] = (int16_t)bullet_get_vy (bullet);
|
|
353 | 353 |
p->bullets_shooter [i] = gunner_get_team(bullet_get_shooter(bullet)) != gunner_get_team(host); |
354 | 354 |
it = list_node_next(it); |
355 | 355 |
i++; |
Also available in: Unified diff