Project

General

Profile

Revision 243

changed macros a bit to only compile what i want

View differences:

proj.c
52 52
int(proj_main_loop)(int argc, char *argv[]) {
53 53

  
54 54
    int r;
55
    #ifndef DIOGO
56
        font_t *consolas = font_ctor("/home/lcom/labs/proj/media/font/Consolas/xpm2");
57
        if(consolas == NULL){ printf("Failed to load consolas\n"); return 1; }
55 58

  
56
    font_t *consolas = font_ctor("/home/lcom/labs/proj/media/font/Consolas/xpm2");
57
    if(consolas == NULL){ printf("Failed to load consolas\n"); return 1; }
59
        /// subscribe interrupts
60
        if (subscribe_all()) { return 1; }
58 61

  
59
    /// subscribe interrupts
60
    if (subscribe_all()) { return 1; }
62
        /// initialize graphics
63
        if(graph_init(GRAPH_MODE)){
64
            printf("%s: failed to initalize graphics.\n", __func__);
65
            if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
66
            return 1;
67
        }
61 68

  
62
    /// initialize graphics
63
    if(graph_init(GRAPH_MODE)){
64
        printf("%s: failed to initalize graphics.\n", __func__);
65
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
66
        return 1;
67
    }
69
        /// Load stuff
70
        basic_sprite_t       *bsp_crosshair = NULL;
71
        basic_sprite_t       *bsp_shooter   = NULL;
72
        basic_sprite_t       *bsp_pistol    = NULL;
73
        basic_sprite_t       *bsp_nothing   = NULL;
74
        basic_sprite_t       *bsp_bullet    = NULL;
75
        map_t                *map1          = NULL;
76
        sprite_t             *sp_crosshair  = NULL;
77
        {
78
            graph_clear_screen();
79
            text_t *txt = text_ctor(consolas, "Loading...");
80
            text_draw(txt);
81
            text_dtor(txt);
82
            graph_draw();
68 83

  
69
    /// Load stuff
70
    basic_sprite_t       *bsp_crosshair = NULL;
71
    basic_sprite_t       *bsp_shooter   = NULL;
72
    basic_sprite_t       *bsp_pistol    = NULL;
73
    basic_sprite_t       *bsp_nothing   = NULL;
74
    basic_sprite_t       *bsp_bullet    = NULL;
75
    map_t                *map1          = NULL;
76
    sprite_t             *sp_crosshair  = NULL;
77
    {
78
        graph_clear_screen();
79
        text_t *txt = text_ctor(consolas, "Loading...");
80
        text_draw(txt);
81
        text_dtor(txt);
82
        graph_draw();
84
            bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n");
85
            bsp_shooter   = get_shooter  (); if(bsp_shooter   == NULL) printf("Failed to get shooter\n");
86
            bsp_pistol    = get_pistol   (); if(bsp_pistol    == NULL) printf("Failed to get pistol\n");
87
            bsp_nothing   = get_nothing  (); if(bsp_nothing   == NULL) printf("Failed to get nothing\n");
88
            bsp_bullet    = get_bullet   (); if(bsp_bullet    == NULL) printf("Failed to get bullet\n");
89
            map1          = get_map1     (); if(map1          == NULL) printf("Failed to get map1\n");
83 90

  
84
        bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n");
85
        bsp_shooter   = get_shooter  (); if(bsp_shooter   == NULL) printf("Failed to get shooter\n");
86
        bsp_pistol    = get_pistol   (); if(bsp_pistol    == NULL) printf("Failed to get pistol\n");
87
        bsp_nothing   = get_nothing  (); if(bsp_nothing   == NULL) printf("Failed to get nothing\n");
88
        bsp_bullet    = get_bullet   (); if(bsp_bullet    == NULL) printf("Failed to get bullet\n");
89
        map1          = get_map1     (); if(map1          == NULL) printf("Failed to get map1\n");
91
            sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n");
92
        }
93
    #endif
90 94

  
91
        sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n");
92
    }
93

  
94 95
    #ifdef DIOGO
95 96
        /*
96 97
        graph_clear_screen();
......
156 157
        printf("Date: %d, %02d/%02d/%02d\n", date[0], date[1], date[2], date[3]);
157 158
        */
158 159
        //UART
160
        unsigned long bits = 8;
161
        unsigned long stop = 2;
162
        long parity = -1;
163
        unsigned long rate = 9600;
164
        unsigned char tx = 0;
165
        int stringc = 2;
166
        char *strings[] = {"Hello.", "world."};
159 167
        if((r = ser_test_conf(COM1_ADDR))) return r;
160
        if((r = ser_test_set(COM1_ADDR, 6, 2, 0, 9800))) return r;
161
        if((r = ser_test_conf(COM1_ADDR))) return r;
168
        if((r = ser_test_set(COM1_ADDR, bits, stop, parity, rate))) return r;
169
        if((r = ser_test_poll(COM1_ADDR, tx, bits, stop, parity, rate, stringc, strings))) return r;
162 170
    #endif
171
    #ifndef DIOGO
172
        #ifdef TELMO
173
            ent_set_scale(DEFAULT_SCALE);
163 174

  
164
    #ifdef TELMO
165
        ent_set_scale(DEFAULT_SCALE);
175
            list_t *shooter_list = list_ctor();
166 176

  
167
        list_t *shooter_list = list_ctor();
177
            gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n");
178
            gunner_set_spawn(shooter1, 75, 75);
179
            gunner_set_pos(shooter1, 75, 75);
168 180

  
169
        gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n");
170
        gunner_set_spawn(shooter1, 75, 75);
171
        gunner_set_pos(shooter1, 75, 75);
181
            gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing);
182
            gunner_set_spawn(shooter2, 975, 75);
183
            gunner_set_pos(shooter2, 775, 75);
172 184

  
173
        gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing);
174
        gunner_set_spawn(shooter2, 975, 75);
175
        gunner_set_pos(shooter2, 775, 75);
185
            list_insert(shooter_list, list_end(shooter_list), shooter1);
186
            list_insert(shooter_list, list_end(shooter_list), shooter2);
176 187

  
177
        list_insert(shooter_list, list_end(shooter_list), shooter1);
178
        list_insert(shooter_list, list_end(shooter_list), shooter2);
188
            //bullet_t *bullet = bullet_ctor(get_bullet(), 400.0, 400.0, 2.0, -1.0);
179 189

  
180
        //bullet_t *bullet = bullet_ctor(get_bullet(), 400.0, 400.0, 2.0, -1.0);
190
            list_t *bullet_list  = list_ctor();
181 191

  
182
        list_t *bullet_list  = list_ctor();
192
            ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
193
                           gunner_get_y(shooter1)-ent_get_YLength()/2.0);
183 194

  
184
        ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
185
                       gunner_get_y(shooter1)-ent_get_YLength()/2.0);
195
            uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
186 196

  
187
        uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
197
            uint8_t last_lb = 0;
198
        #endif
188 199

  
189
        uint8_t last_lb = 0;
190
    #endif
200
        /// loop stuff
201
        int ipc_status;
202
        message msg;
203
        int good = 1;
191 204

  
192
    /// loop stuff
193
    int ipc_status;
194
    message msg;
195
    int good = 1;
205
        while (good) {
206
            /* Get a request message. */
207
            if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
208
                printf("driver_receive failed with %d", r);
209
                continue;
210
            }
211
            if (is_ipc_notify(ipc_status)) { /* received notification */
212
                switch (_ENDPOINT_P(msg.m_source)) {
213
                    case HARDWARE: /* hardware interrupt notification */
214
                        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
215
                            if (msg.m_notify.interrupts & n) {
216
                                interrupt_handler(i);
217
                                if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
218
                                #ifdef TELMO
219
                                if (i == 0) {
220
                                    if (no_interrupts % refresh_count_value == 0) {
221
                                        update_movement(map1, shooter1, shooter2);
222
                                        //bullet_update_movement(bullet);
196 223

  
197
    #ifdef DIOGO
198
        good = 0;
199
    #endif
224
                                        if (no_interrupts % 180 == 0) gunner_set_pos(shooter2, 775, 75);
200 225

  
201
    while (good) {
202
        /* Get a request message. */
203
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
204
            printf("driver_receive failed with %d", r);
205
            continue;
206
        }
207
        if (is_ipc_notify(ipc_status)) { /* received notification */
208
            switch (_ENDPOINT_P(msg.m_source)) {
209
                case HARDWARE: /* hardware interrupt notification */
210
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
211
                        if (msg.m_notify.interrupts & n) {
212
                            interrupt_handler(i);
213
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
214
                            #ifdef TELMO
215
                            if (i == 0) {
216
                                if (no_interrupts % refresh_count_value == 0) {
217
                                    update_movement(map1, shooter1, shooter2);
218
                                    //bullet_update_movement(bullet);
226
                                        update_game_state(map1, shooter_list, bullet_list);
219 227

  
220
                                    if (no_interrupts % 180 == 0) gunner_set_pos(shooter2, 775, 75);
228
                                        if(map_collides_gunner(map1, shooter1)){
229
                                            printf("COLLIDING\n");
230
                                        }
221 231

  
222
                                    update_game_state(map1, shooter_list, bullet_list);
232
                                        update_scale();
223 233

  
224
                                    if(map_collides_gunner(map1, shooter1)){
225
                                        printf("COLLIDING\n");
226
                                    }
234
                                        ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
235
                                                       gunner_get_y(shooter1)-ent_get_YLength()/2.0);
227 236

  
228
                                    update_scale();
237
                                        sprite_set_pos(sp_crosshair, get_mouse_X(), get_mouse_Y());
238
                                        double angle = get_mouse_angle(shooter1);
239
                                        gunner_set_angle(shooter1, angle - M_PI_2);
240
                                        graph_clear_screen();
229 241

  
230
                                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
231
                                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
242
                                        clock_t t = clock();
232 243

  
233
                                    sprite_set_pos(sp_crosshair, get_mouse_X(), get_mouse_Y());
234
                                    double angle = get_mouse_angle(shooter1);
235
                                    gunner_set_angle(shooter1, angle - M_PI_2);
236
                                    graph_clear_screen();
244
                                        map_draw   (map1);
245
                                        gunner_draw(shooter2);
246
                                        gunner_draw(shooter1);
247
                                        bullet_draw_list(bullet_list);
237 248

  
238
                                    clock_t t = clock();
249
                                        t = clock()-t; //printf("%d\n", (t*1000)/CLOCKS_PER_SEC);
239 250

  
240
                                    map_draw   (map1);
241
                                    gunner_draw(shooter2);
242
                                    gunner_draw(shooter1);
243
                                    bullet_draw_list(bullet_list);
251
                                        sprite_draw(sp_crosshair);
252
                                        graph_draw();
253
                                    }
254
                                }
255
                                if (i == 12) {
256
                                    if (counter_mouse_ih >= 3) {
257
                                        struct packet pp = mouse_parse_packet(packet_mouse_ih);
258
                                        update_mouse(&pp);
259
                                        //printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y());
260
                                        counter_mouse_ih = 0;
244 261

  
245
                                    t = clock()-t; //printf("%d\n", (t*1000)/CLOCKS_PER_SEC);
262
                                        if (last_lb ^ get_key_presses()->lb_pressed && get_key_presses()->lb_pressed) {
263
                                            shoot_bullet(shooter1, bullet_list, bsp_bullet);
264
                                        }
246 265

  
247
                                    sprite_draw(sp_crosshair);
248
                                    graph_draw();
249
                                }
250
                            }
251
                            if (i == 12) {
252
                                if (counter_mouse_ih >= 3) {
253
                                    struct packet pp = mouse_parse_packet(packet_mouse_ih);
254
                                    update_mouse(&pp);
255
                                    //printf("X: %d Y: %d\n", get_mouse_X(), get_mouse_Y());
256
                                    counter_mouse_ih = 0;
257

  
258
                                    if (last_lb ^ get_key_presses()->lb_pressed && get_key_presses()->lb_pressed) {
259
                                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
266
                                        last_lb = get_key_presses()->lb_pressed;
260 267
                                    }
261

  
262
                                    last_lb = get_key_presses()->lb_pressed;
263 268
                                }
269
                                #endif
264 270
                            }
265
                            #endif
266 271
                        }
267
                    }
268 272

  
269
                    break;
270
                default:
271
                    break; /* no other notifications expected: do nothing */
273
                        break;
274
                    default:
275
                        break; /* no other notifications expected: do nothing */
276
                }
277
            } else { /* received standart message, not a notification */
278
                /* no standart message expected: do nothing */
272 279
            }
273
        } else { /* received standart message, not a notification */
274
            /* no standart message expected: do nothing */
275 280
        }
276
    }
277 281

  
278
    #ifdef TELMO
279
        while(list_size(shooter_list) > 0){
280
            gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
281
            gunner_dtor(p);
282
        }
282
        #ifdef TELMO
283
            while(list_size(shooter_list) > 0){
284
                gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
285
                gunner_dtor(p);
286
            }
283 287

  
284
        while(list_size(bullet_list) > 0){
285
            bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
286
            bullet_dtor(p);
288
            while(list_size(bullet_list) > 0){
289
                bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
290
                bullet_dtor(p);
291
            }
292
            if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
293
        #endif
294

  
295
        basic_sprite_dtor      (bsp_crosshair); bsp_crosshair = NULL;
296
        basic_sprite_dtor      (bsp_shooter  ); bsp_shooter   = NULL;
297
        sprite_dtor            (sp_crosshair ); sp_crosshair  = NULL;
298
        basic_sprite_dtor      (bsp_pistol   ); bsp_pistol    = NULL;
299
        basic_sprite_dtor      (bsp_nothing  ); bsp_nothing   = NULL;
300
        map_dtor               (map1         ); map1          = NULL;
301
        font_dtor              (consolas     ); consolas      = NULL;
302

  
303
        // Unsubscribe interrupts
304
        if (unsubscribe_all()) {
305
            if (cleanup())
306
                printf("%s: failed to cleanup.\n", __func__);
307
            return 1;
287 308
        }
288
        if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
289
    #endif
290 309

  
291
    basic_sprite_dtor      (bsp_crosshair); bsp_crosshair = NULL;
292
    basic_sprite_dtor      (bsp_shooter  ); bsp_shooter   = NULL;
293
    sprite_dtor            (sp_crosshair ); sp_crosshair  = NULL;
294
    basic_sprite_dtor      (bsp_pistol   ); bsp_pistol    = NULL;
295
    basic_sprite_dtor      (bsp_nothing  ); bsp_nothing   = NULL;
296
    map_dtor               (map1         ); map1          = NULL;
297
    font_dtor              (consolas     ); consolas      = NULL;
298 310

  
299
    // Unsubscribe interrupts
300
    if (unsubscribe_all()) {
301
        if (cleanup())
311
        if (cleanup()) {
302 312
            printf("%s: failed to cleanup.\n", __func__);
303
        return 1;
304
    }
313
            return 1;
314
        }
305 315

  
316
    #endif
306 317

  
307
    if (cleanup()) {
308
        printf("%s: failed to cleanup.\n", __func__);
309
        return 1;
310
    }
311

  
312 318
    return 0;
313 319
}

Also available in: Unified diff