Project

General

Profile

Revision 315

simplified hltp

View differences:

proj/libs/uart/src/hltp.c
50 50
    return ret;
51 51
}
52 52
int hltp_send_host_info(const host_info_t *p) {
53
    // struct size
54
    size_t struct_size = sizeof(double) * (8 + 4*p->no_bullets) + p->no_bullets * sizeof(bool) + sizeof(size_t);
55
    uint8_t *base = (uint8_t*)malloc(struct_size);
56
    uint8_t *aux = base;
57
    // players information
58
    memcpy(aux, p, sizeof(double) * 8);
59
    aux = aux + sizeof(double) * 8;
60
    // size of arrays
61
    memcpy(aux, &(p->no_bullets), sizeof(size_t));
62
    aux = aux + sizeof(size_t);
63
    // array containing the X positions of the bullets
64
    memcpy(aux, p->bullets_x, sizeof(double) * (p->no_bullets));
65
    aux = aux + sizeof(double) * (p->no_bullets);
66
    // array containing the Y positions of the bullets
67
    memcpy(aux, p->bullets_y, sizeof(double) * (p->no_bullets));
68
    aux = aux + sizeof(double) * (p->no_bullets);
69
    // array containing the X velocity of the bullets
70
    memcpy(aux, p->bullets_vx, sizeof(double) * (p->no_bullets));
71
    aux = aux + sizeof(double) * (p->no_bullets);
72
    // array containing the Y velocity of the bullets
73
    memcpy(aux, p->bullets_vy, sizeof(double) * (p->no_bullets));
74
    aux = aux + sizeof(double) * (p->no_bullets);
75
    // array containing the shooter id of the bullets
76
    memcpy(aux, p->bullets_shooter, sizeof(bool) * (p->no_bullets));
77 53

  
78 54
    uint8_t type = hltp_type_host;
79
    uint8_t* ptr[2]; ptr[0] = &type; ptr[1] = base;
80
    size_t    sz[2]; sz [0] =     1; sz [1] = struct_size;
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;
81 71
    return nctp_send(2, ptr, sz);
82 72
}
83 73

  
......
112 102
    return ret;
113 103
}
114 104
int hltp_send_remote_info(const remote_info_t *p) {
115
    // struct size
116
    size_t struct_size = sizeof(keys_t) + sizeof(int32_t) * 2 + sizeof(size_t) + sizeof(double) * (3 *p->bullets_shot);
117
    uint8_t *base = (uint8_t*)malloc(struct_size);
118
    uint8_t *aux = base;
119
    memcpy(aux, p, sizeof(keys_t));
120
    aux = aux + sizeof(keys_t);
121
    memcpy(aux, p, sizeof(int32_t)*2);
122
    aux = aux + sizeof(int32_t)*2;
123
    memcpy(aux, &(p->bullets_shot), sizeof(size_t));
124
    aux = aux + sizeof(size_t);
125
    memcpy(aux, p->bullets_x, sizeof(double)*(p->bullets_shot));
126
    aux = aux + sizeof(double)*(p->bullets_shot);
127
    memcpy(aux, p->bullets_y, sizeof(double)*(p->bullets_shot));
128
    aux = aux + sizeof(double)*(p->bullets_shot);
129
    memcpy(aux, p->bullets_angle, sizeof(double)*(p->bullets_shot));
130 105

  
131 106
    uint8_t type = hltp_type_remote;
132
    uint8_t* ptr[2]; ptr[0] = &type; ptr[1] = base;
133
    size_t    sz[2]; sz [0] =     1; sz [1] = struct_size;
107
    uint8_t* ptr[8]; size_t sz[8];
108
    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;
134 116
    return nctp_send(2, ptr, sz);
135 117
}
136 118

  

Also available in: Unified diff