Project

General

Profile

Revision 342

identified error

View differences:

proj/include/proj_func.h
55 55

  
56 56
int16_t* get_mouse_Y(void);
57 57

  
58
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote, list_t *bullet_list);
58
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote);
59 59

  
60 60
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle);
61 61

  
proj/include/proj_structures.h
84 84
    int16_t    remote_health;
85 85
    /// @brief Remote player current health
86 86
    int16_t    remote_current_health;
87

  
87
    /*
88 88
    // bullets
89 89
    /// @brief Number of bullets
90 90
    uint8_t    no_bullets;
......
98 98
    int16_t   *bullets_vy;
99 99
    /// @brief Who shot each bullet
100 100
    bool      *bullets_shooter; // false for host, true for remote
101
    */
101 102
} host_info_t;
102 103
/**
103 104
 * @brief Construct host information.
proj/libs/uart/src/hltp.c
17 17
    return nctp_send(2, ptr, sz);
18 18
}
19 19

  
20
static host_info_t* hltp_interpret_host_info(const uint8_t *p) {
20
static host_info_t* hltp_interpret_host_info(const uint8_t *p, const size_t sz) {
21
    if (sz != sizeof(host_info_t)) { printf("%d should equal %d\n", sz, sizeof(host_info_t)); return NULL;}
21 22
    host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t));
22
    size_t pos = 0;
23
    //size_t pos = 0;
23 24
    // players information
24
    memcpy(ret, p + pos, sizeof(int16_t)*10);
25
    memcpy(ret, p, sz);
26
    /*
25 27
    pos += sizeof(int16_t)*10;
26 28
    // size of arrays
27 29
    memcpy(&(ret->no_bullets), p + pos, sizeof(uint8_t));
......
46 48
    // array containing the shooter id of the bullets
47 49
    (ret->bullets_shooter) = (bool*)malloc(sizeof(bool)*(ret->no_bullets));
48 50
    memcpy((ret->bullets_shooter), p + pos, sizeof(bool)*sz);
49

  
51
    */
50 52
    return ret;
51 53
}
52 54
int hltp_send_host_info(const host_info_t *p) {
53 55

  
54 56
    uint8_t type = hltp_type_host;
55
    const uint8_t* ptr[17]; size_t sz[17];
57
    const uint8_t* ptr[11]; size_t sz[11];
56 58
    ptr[0]  = (uint8_t*)&   type                  ;     sz[0]   = 1;
57 59
    ptr[1]  = (uint8_t*)&p->host_x                ;     sz[1]   = sizeof(int16_t);
58 60
    ptr[2]  = (uint8_t*)&p->host_y                ;     sz[2]   = sizeof(int16_t);
......
64 66
    ptr[8]  = (uint8_t*)&p->remote_angle          ;     sz[8]   = sizeof(int16_t);
65 67
    ptr[9]  = (uint8_t*)&p->remote_health         ;     sz[9]   = sizeof(int16_t);
66 68
    ptr[10] = (uint8_t*)&p->remote_current_health ;     sz[10]  = sizeof(int16_t);
69
    /*
67 70
    ptr[11] = (uint8_t*)&p->no_bullets            ;     sz[11]  = sizeof(uint8_t);
68 71
    ptr[12] = (uint8_t*) p->bullets_x             ;     sz[12]  = sizeof(int16_t) * p->no_bullets;
69 72
    ptr[13] = (uint8_t*) p->bullets_y             ;     sz[13]  = sizeof(int16_t) * p->no_bullets;
70 73
    ptr[14] = (uint8_t*) p->bullets_vx            ;     sz[14]  = sizeof(int16_t) * p->no_bullets;
71 74
    ptr[15] = (uint8_t*) p->bullets_vy            ;     sz[15]  = sizeof(int16_t) * p->no_bullets;
72 75
    ptr[16] = (uint8_t*) p->bullets_shooter       ;     sz[16]  = sizeof(bool) * p->no_bullets;
73
    return nctp_send(17, ptr, sz);
76
    */
77
    return nctp_send(11, ptr, sz);
74 78
}
75 79

  
76 80
static remote_info_t* hltp_interpret_remote_info(const uint8_t *p) {
......
113 117
    uint8_t ret = p[0];
114 118
    switch(ret){
115 119
        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;
120
        case hltp_type_host  : *dest = hltp_interpret_host_info  (p+1, sz-1);   break;
121
        case hltp_type_remote: *dest = hltp_interpret_remote_info(p+1);   break;
122
        case hltp_type_bullet: *dest = hltp_interpret_bullet_info(p+1);   break;
119 123
        default: *dest = NULL; break;
120 124
    }
121 125
    return ret;
proj/src/interrupts_func.c
187 187

  
188 188
void (interrupt_handler)(uint8_t handler) {
189 189
    if (handler >= 32)              return;
190
    if ((*ih[handler]) == NULL)     return;
190
    if ((ih[handler]) == NULL)      return;
191 191
    (*ih[handler])();
192 192
}
193 193

  
proj/src/proj.c
192 192
static void multiplayer_process(const uint8_t *p, const size_t sz) {
193 193
    void *dest = NULL;
194 194
    hltp_type tp = hltp_interpret(p, sz, &dest);
195
    if (dest == NULL) return;
195 196
    switch(tp){
196 197
        case hltp_type_host:
197
            host_info_dtor(host_info);
198 198
            host_info = (host_info_t*)dest;
199 199
            break;
200 200
        case hltp_type_remote:
201
            remote_info_dtor(remote_info);
202 201
            remote_info = (remote_info_t*)dest;
203 202
            break;
204 203
        case hltp_type_bullet:
205
            bullet_info_dtor(bullet_info);
206 204
            bullet_info = (bullet_info_t*)dest;
207 205
            break;
208 206
        case hltp_type_invalid: break;
......
326 324
                switch (i) {
327 325
                    case TIMER0_IRQ:
328 326
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
329

  
330 327
                    update_movement(map1, shooter1, keys, shooter_list);
331 328
                    update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list);
332 329

  
......
348 345
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
349 346

  
350 347
                    gunner_set_angle(shooter2, remote_info->remote_angle);
348
                    if (timer_get_no_interrupts() % 6 == 0) {
349
                        build_host_structure(host_info, shooter1, shooter2);
351 350

  
352
                    build_host_structure(host_info, shooter1, shooter2, bullet_list);
351
                        hltp_send_host_info(host_info);
352
                    }
353 353

  
354

  
355

  
356
                    hltp_send_host_info(host_info);
357

  
358 354
                    graph_clear_screen();
359 355
                    map_draw   (map1);
360 356
                    bullet_draw_list(bullet_list);
......
468 464

  
469 465
                    build_remote_structure(remote_info, keys, angle);
470 466

  
467

  
471 468
                    //hltp_send_remote_info(remote_info);
472

  
473 469
                    gunner_set_pos(shooter1, (double)host_info->remote_x, (double)host_info->remote_y);
474 470
                    gunner_set_angle(shooter1, (double)host_info->remote_angle);
475 471
                    gunner_set_health(shooter1, (double)host_info->remote_health);
......
483 479
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
484 480
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
485 481

  
482
                    /*
486 483
                    for (size_t j = 0; j < host_info->no_bullets; j++) {
487 484
                        if (host_info->bullets_shooter[j]) { // remote
488 485
                            bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, (double)host_info->bullets_x[j], (double)host_info->bullets_y[j], (double)host_info->bullets_vx[j], (double)host_info->bullets_vy[j]);
......
491 488
                            bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, (double)host_info->bullets_x[j], (double)host_info->bullets_y[j], (double)host_info->bullets_vx[j], (double)host_info->bullets_vy[j]);
492 489
                            list_insert(bullet_list, list_end(bullet_list), bullet);
493 490
                        }
494
                    }
491
                    }*/
495 492

  
496 493
                    graph_clear_screen();
497 494
                    map_draw   (map1);
......
503 500
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
504 501
                    sprite_draw(sp_crosshair);
505 502
                    graph_draw();
506

  
503
                    /*
507 504
                    while(list_size(bullet_list) > 0){
508 505
                        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
509 506
                        bullet_dtor(p);
510 507
                    }
508
                    */
511 509

  
512 510
                    break;
513 511
                    case KBC_IRQ:
......
528 526
                    }
529 527
                    break;
530 528

  
531
                    case COM1_IRQ: nctp_ih(); break;
529
                    case COM1_IRQ:
530
                        nctp_ih();
531
                        break;
532 532
                }
533 533
            }
534 534
        }
proj/src/proj_func.c
44 44
    ret->remote_health          = (int16_t)gunner_get_health     (remote);
45 45
    ret->remote_current_health  = (int16_t)gunner_get_curr_health(remote);
46 46

  
47
    ret->no_bullets = 0;
47
    //ret->no_bullets = 0;
48 48

  
49 49
    return ret;
50 50
}
51 51

  
52 52
void host_info_dtor(host_info_t *p) {
53 53
    if (p==NULL) return;
54

  
54
    /*
55 55
    if ((p->bullets_x) != NULL){ free(p->bullets_x); p->bullets_x = NULL; }
56 56

  
57 57
    if ((p->bullets_y) != NULL){ free(p->bullets_y); p->bullets_y = NULL; }
......
61 61
    if ((p->bullets_vy) != NULL){ free(p->bullets_vy); p->bullets_vy = NULL; }
62 62

  
63 63
    if ((p->bullets_shooter) != NULL){ free(p->bullets_shooter); p->bullets_shooter = NULL; }
64

  
64
    */
65 65
    free(p);
66 66
}
67 67

  
......
318 318
    return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p));
319 319
}
320 320

  
321
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote, list_t *bullet_list) {
321
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote) {
322 322
    // host
323 323
    p->host_x               = (int16_t)gunner_get_x          (host);
324 324
    p->host_y               = (int16_t)gunner_get_y          (host);
......
332 332
    p->remote_angle           = (int16_t)gunner_get_angle      (remote);
333 333
    p->remote_health          = (int16_t)gunner_get_health     (remote);
334 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;
......
354 354
        it = list_node_next(it);
355 355
        i++;
356 356
    }
357
    */
357 358
}
358 359

  
359 360
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle) {
proj/Makefile
12 12
SRCS= list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c fast_math.c xpm_utils.c rtc.c uart.c makecode_map.c menu.c proj_func.c rectangle.c font.c ent.c proj.c hltp.c
13 13
IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
14 14

  
15
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO -D __LCOM_OPTIMIZED__ -Wall -Wextra -Wshadow -Wunreachable-code #-Weverything -Wno-padded -Wno-unused-macros
15
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED__ -Wall -Wextra -Wshadow -Wunreachable-code #-Weverything -Wno-padded -Wno-unused-macros
16 16

  
17 17

  
18 18
DPADD += ${LIBLCF}

Also available in: Unified diff