Project

General

Profile

Revision 327

progress

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(double)*10);
25
    pos += sizeof(double)*10;
24
    memcpy(ret, p + pos, sizeof(float)*10);
25
    pos += sizeof(float)*10;
26 26
    // size of arrays
27
    memcpy(&(ret->no_bullets), p + pos, sizeof(size_t));
28
    pos += sizeof(size_t);
27
    memcpy(&(ret->no_bullets), p + pos, sizeof(uint8_t));
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) = (double*)malloc(sizeof(double)*sz);
32
    memcpy((ret->bullets_x), p + pos, sizeof(double)*sz);
33
    pos += sizeof(double)*sz;
31
    (ret->bullets_x) = (float*)malloc(sizeof(float)*sz);
32
    memcpy((ret->bullets_x), p + pos, sizeof(float)*sz);
33
    pos += sizeof(float)*sz;
34 34
    // array containing the Y positions of the bullets
35
    (ret->bullets_y) = (double*)malloc(sizeof(double)*(ret->no_bullets));
36
    memcpy((ret->bullets_y), p + pos, sizeof(double)*sz);
37
    pos += sizeof(double)*sz;
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;
38 38
    // array containing the X velocity of the bullets
39
    (ret->bullets_vx) = (double*)malloc(sizeof(double)*(ret->no_bullets));
40
    memcpy((ret->bullets_vx), p + pos, sizeof(double)*sz);
41
    pos += sizeof(double)*sz;
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;
42 42
    // array containing the Y velocity of the bullets
43
    (ret->bullets_vy) = (double*)malloc(sizeof(double)*(ret->no_bullets));
44
    memcpy((ret->bullets_vy), p + pos, sizeof(double)*sz);
45
    pos += sizeof(double)*sz;
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;
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(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;
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);
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;
73 73
    return nctp_send(17, ptr, sz);
74 74
}
75 75

  

Also available in: Unified diff