Project

General

Profile

Revision 329

trying to make it work

View differences:

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

  

Also available in: Unified diff