Revision 320
multiplayer almost working, serial data not being transmitted?
proj.c | ||
---|---|---|
182 | 182 |
return 0; |
183 | 183 |
} |
184 | 184 |
|
185 |
host_info_t *host = NULL; |
|
186 |
remote_info_t *remote = NULL; |
|
185 |
host_info_t *host_info = NULL; |
|
186 |
remote_info_t *remote_info = NULL; |
|
187 |
bullet_info_t *bullet_info = NULL; |
|
187 | 188 |
|
188 | 189 |
static void multiplayer_process(const uint8_t *p, const size_t sz) { |
189 | 190 |
void *dest = NULL; |
190 | 191 |
hltp_type tp = hltp_interpret(p, sz, &dest); |
191 | 192 |
switch(tp){ |
192 | 193 |
case hltp_type_host: |
193 |
host_info_dtor(host); |
|
194 |
host = (host_info_t*)dest; |
|
194 |
host_info_dtor(host_info);
|
|
195 |
host_info = (host_info_t*)dest;
|
|
195 | 196 |
break; |
196 | 197 |
case hltp_type_remote: |
197 |
remote_info_dtor(remote); |
|
198 |
remote = (remote_info_t*)dest; |
|
198 |
remote_info_dtor(remote_info);
|
|
199 |
remote_info = (remote_info_t*)dest;
|
|
199 | 200 |
break; |
201 |
case hltp_type_bullet: |
|
202 |
bullet_info_dtor(bullet_info); |
|
203 |
bullet_info = (bullet_info_t*)dest; |
|
204 |
break; |
|
200 | 205 |
default: break; |
201 | 206 |
} |
202 | 207 |
} |
... | ... | |
264 | 269 |
} |
265 | 270 |
|
266 | 271 |
static int (multiplayer_host)(void) { |
267 |
//int r;
|
|
272 |
int r; |
|
268 | 273 |
|
269 | 274 |
nctp_dump(); |
270 |
nctp_set_processor(multiplayer_process);/*
|
|
275 |
nctp_set_processor(multiplayer_process); |
|
271 | 276 |
|
272 | 277 |
ent_set_scale(DEFAULT_SCALE); |
273 | 278 |
text_timer_t *in_game_timer = timer_ctor(font_get_default()); |
... | ... | |
277 | 282 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
278 | 283 |
gunner_set_spawn(shooter1, 75, 75); |
279 | 284 |
|
280 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n");
|
|
285 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 2); if(shooter2 == NULL) printf("Failed to get shooter2\n");
|
|
281 | 286 |
gunner_set_spawn(shooter2, 975, 75); |
282 | 287 |
|
283 | 288 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
... | ... | |
286 | 291 |
do { |
287 | 292 |
get_random_spawn(map1, shooter1, shooter_list); |
288 | 293 |
get_random_spawn(map1, shooter2, shooter_list); |
289 |
} while (distance_gunners(shooter1, shooter2) < 700);
|
|
294 |
} while (distance_gunners(shooter1, shooter2) < 500);
|
|
290 | 295 |
|
296 |
host_info = host_info_ctor(shooter1, shooter2); |
|
297 |
remote_info = remote_info_ctor(); |
|
298 |
bullet_info = bullet_info_ctor(); |
|
299 |
|
|
291 | 300 |
list_t *bullet_list = list_ctor(); |
292 | 301 |
|
293 | 302 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
... | ... | |
297 | 306 |
uint8_t last_lb = 0; |
298 | 307 |
struct packet pp; |
299 | 308 |
keys_t *keys = get_key_presses(); |
300 |
|
|
301 | 309 |
/// loop stuff |
302 | 310 |
uint32_t int_vector = 0; |
303 | 311 |
int good = true; |
304 | 312 |
int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
313 |
list_node_t *p1, *p2; // player states |
|
314 |
int state_1, state_2; |
|
305 | 315 |
while (good) { |
306 | 316 |
if ((r = get_interrupts_vector(&int_vector))) return r; |
307 | 317 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
308 |
interrupt_handler(i); |
|
309 |
switch (i) { |
|
310 |
case TIMER0_IRQ: |
|
318 |
if (int_vector & n) { |
|
319 |
interrupt_handler(i); |
|
320 |
switch (i) { |
|
321 |
case TIMER0_IRQ: |
|
322 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
311 | 323 |
|
312 |
break; |
|
324 |
update_movement(map1, shooter1, keys, shooter_list); |
|
325 |
update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list); |
|
313 | 326 |
|
314 |
case KBC_IRQ:
|
|
327 |
update_game_state(map1, shooter_list, bullet_list);
|
|
315 | 328 |
|
316 |
break; |
|
329 |
p1 = list_find(shooter_list, shooter1); |
|
330 |
p2 = list_find(shooter_list, shooter2); |
|
317 | 331 |
|
318 |
case MOUSE_IRQ: |
|
332 |
if ((state_1 = (p1 == list_end(shooter_list))) || (state_2 = (p2 == list_end(shooter_list)))) { |
|
333 |
state = state_1 - state_2; |
|
334 |
good = false; |
|
335 |
break; |
|
336 |
} |
|
319 | 337 |
|
338 |
double angle = get_mouse_angle(shooter1); |
|
339 |
gunner_set_angle(shooter1, angle - M_PI_2); |
|
320 | 340 |
|
321 |
break; |
|
341 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
342 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
322 | 343 |
|
323 |
case COM1_IRQ: nctp_ih(); break; |
|
344 |
gunner_set_angle(shooter2, remote_info->remote_angle); |
|
345 |
|
|
346 |
build_host_structure(host_info, shooter1, shooter2, bullet_list); |
|
347 |
|
|
348 |
hltp_send_host_info(host_info); |
|
349 |
|
|
350 |
graph_clear_screen(); |
|
351 |
map_draw (map1); |
|
352 |
bullet_draw_list(bullet_list); |
|
353 |
gunner_draw_list(shooter_list); |
|
354 |
|
|
355 |
text_draw(in_game_timer->text); |
|
356 |
|
|
357 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
358 |
sprite_draw(sp_crosshair); |
|
359 |
graph_draw(); |
|
360 |
|
|
361 |
break; |
|
362 |
case KBC_IRQ: |
|
363 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
364 |
good = false; |
|
365 |
} |
|
366 |
break; |
|
367 |
case MOUSE_IRQ: |
|
368 |
if (counter_mouse_ih >= 3) { |
|
369 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
370 |
update_mouse(&pp); |
|
371 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) |
|
372 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
373 |
last_lb = keys->lb_pressed; |
|
374 |
counter_mouse_ih = 0; |
|
375 |
} |
|
376 |
break; |
|
377 |
|
|
378 |
case COM1_IRQ: |
|
379 |
nctp_ih(); |
|
380 |
if (bullet_info->new_bullet) { |
|
381 |
shoot_bullet(shooter2, bullet_list, bsp_bullet); |
|
382 |
bullet_info->new_bullet = false; |
|
383 |
} |
|
384 |
break; |
|
385 |
} |
|
324 | 386 |
} |
325 | 387 |
} |
326 |
}*/
|
|
388 |
} |
|
327 | 389 |
|
390 |
while(list_size(shooter_list) > 0){ |
|
391 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
392 |
gunner_dtor(p); |
|
393 |
} |
|
394 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
395 |
|
|
396 |
while(list_size(bullet_list) > 0){ |
|
397 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
398 |
bullet_dtor(p); |
|
399 |
} |
|
400 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
401 |
|
|
402 |
host_info_dtor(host_info); |
|
403 |
remote_info_dtor(remote_info); |
|
404 |
bullet_info_dtor(bullet_info); |
|
405 |
|
|
406 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
|
407 |
|
|
328 | 408 |
return 0; |
329 | 409 |
} |
330 |
static int (multiplayer_remote)(void) {/*
|
|
410 |
static int (multiplayer_remote)(void) { |
|
331 | 411 |
int r; |
332 | 412 |
|
333 | 413 |
nctp_dump(); |
... | ... | |
338 | 418 |
|
339 | 419 |
list_t *shooter_list = list_ctor(); |
340 | 420 |
|
341 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
|
421 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 2); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
|
342 | 422 |
gunner_set_spawn(shooter1, 75, 75); |
343 | 423 |
|
344 | 424 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n"); |
... | ... | |
347 | 427 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
348 | 428 |
list_insert(shooter_list, list_end(shooter_list), shooter2); |
349 | 429 |
|
350 |
do { |
|
351 |
get_random_spawn(map1, shooter1, shooter_list); |
|
352 |
get_random_spawn(map1, shooter2, shooter_list); |
|
353 |
} while (distance_gunners(shooter1, shooter2) < 700); |
|
430 |
host_info = host_info_ctor(shooter2, shooter1); |
|
431 |
remote_info = remote_info_ctor(); |
|
432 |
bullet_info = bullet_info_ctor(); |
|
354 | 433 |
|
355 | 434 |
list_t *bullet_list = list_ctor(); |
356 | 435 |
|
... | ... | |
365 | 444 |
/// loop stuff |
366 | 445 |
uint32_t int_vector = 0; |
367 | 446 |
int good = true; |
368 |
int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
|
369 | 447 |
while (good) { |
370 | 448 |
if ((r = get_interrupts_vector(&int_vector))) return r; |
371 | 449 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
372 |
interrupt_handler(i); |
|
373 |
switch (i) { |
|
374 |
case TIMER0_IRQ: |
|
450 |
if (int_vector & n) { |
|
451 |
interrupt_handler(i); |
|
452 |
switch (i) { |
|
453 |
case TIMER0_IRQ: |
|
454 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
375 | 455 |
|
376 |
break;
|
|
456 |
double angle = get_mouse_angle(shooter1);
|
|
377 | 457 |
|
378 |
case KBC_IRQ:
|
|
458 |
build_remote_structure(remote_info, keys, angle);
|
|
379 | 459 |
|
380 |
break;
|
|
460 |
hltp_send_remote_info(remote_info);
|
|
381 | 461 |
|
382 |
case MOUSE_IRQ: |
|
462 |
gunner_set_pos(shooter1, host_info->remote_x, host_info->remote_y); |
|
463 |
gunner_set_angle(shooter1, host_info->remote_angle); |
|
464 |
gunner_set_health(shooter1, host_info->remote_health); |
|
465 |
gunner_set_curr_health(shooter1, host_info->remote_current_health); |
|
383 | 466 |
|
467 |
gunner_set_pos(shooter2, host_info->host_x, host_info->host_y); |
|
468 |
gunner_set_angle(shooter2, host_info->host_angle); |
|
469 |
gunner_set_health(shooter2, host_info->host_health); |
|
470 |
gunner_set_curr_health(shooter2, host_info->host_current_health); |
|
384 | 471 |
|
385 |
break; |
|
472 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
473 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
386 | 474 |
|
387 |
case COM1_IRQ: nctp_ih(); break; |
|
475 |
for (size_t i = 0; i < host_info->no_bullets; i++) { |
|
476 |
if (host_info->bullets_shooter[i]) { // remote |
|
477 |
bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, host_info->bullets_x[i], host_info->bullets_y[i], host_info->bullets_vx[i], host_info->bullets_vy[i]); |
|
478 |
list_insert(bullet_list, list_end(bullet_list), bullet); |
|
479 |
} else { // host |
|
480 |
bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, host_info->bullets_x[i], host_info->bullets_y[i], host_info->bullets_vx[i], host_info->bullets_vy[i]); |
|
481 |
list_insert(bullet_list, list_end(bullet_list), bullet); |
|
482 |
} |
|
483 |
} |
|
484 |
|
|
485 |
graph_clear_screen(); |
|
486 |
map_draw (map1); |
|
487 |
bullet_draw_list(bullet_list); |
|
488 |
gunner_draw_list(shooter_list); |
|
489 |
|
|
490 |
text_draw(in_game_timer->text); |
|
491 |
|
|
492 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
493 |
sprite_draw(sp_crosshair); |
|
494 |
graph_draw(); |
|
495 |
|
|
496 |
while(list_size(bullet_list) > 0){ |
|
497 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
498 |
bullet_dtor(p); |
|
499 |
} |
|
500 |
|
|
501 |
break; |
|
502 |
case KBC_IRQ: |
|
503 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
504 |
good = false; |
|
505 |
} |
|
506 |
break; |
|
507 |
case MOUSE_IRQ: |
|
508 |
if (counter_mouse_ih >= 3) { |
|
509 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
510 |
update_mouse(&pp); |
|
511 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) { |
|
512 |
bullet_info->new_bullet = true; |
|
513 |
hltp_send_bullet_info(bullet_info); |
|
514 |
} |
|
515 |
last_lb = keys->lb_pressed; |
|
516 |
counter_mouse_ih = 0; |
|
517 |
} |
|
518 |
break; |
|
519 |
|
|
520 |
case COM1_IRQ: nctp_ih(); break; |
|
521 |
} |
|
388 | 522 |
} |
389 | 523 |
} |
390 |
}*/
|
|
524 |
} |
|
391 | 525 |
|
526 |
while(list_size(shooter_list) > 0){ |
|
527 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
528 |
gunner_dtor(p); |
|
529 |
} |
|
530 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
531 |
|
|
532 |
while(list_size(bullet_list) > 0){ |
|
533 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
534 |
bullet_dtor(p); |
|
535 |
} |
|
536 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
537 |
|
|
538 |
host_info_dtor(host_info); |
|
539 |
remote_info_dtor(remote_info); |
|
540 |
bullet_info_dtor(bullet_info); |
|
541 |
|
|
542 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
|
543 |
|
|
392 | 544 |
return 0; |
393 | 545 |
} |
394 | 546 |
|
Also available in: Unified diff