Mercurial > MadButterfly
comparison examples/tank/tank_main.c @ 192:54fdc2a65242
Remove factory from observer APIs.
- Save factory that used to new a subject as subject's attribute.
- Get factory from subject himself instead of passing as an argument.
- It make API of observer more simple and clean.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 18 Nov 2008 21:42:30 +0800 |
parents | 0a924eb9ccab |
children | 923d91dfb6af |
comparison
equal
deleted
inserted
replaced
191:18f8c3126cdb | 192:54fdc2a65242 |
---|---|
264 tank->direction = direction; | 264 tank->direction = direction; |
265 } | 265 } |
266 | 266 |
267 /* Clean program when it is completed. */ | 267 /* Clean program when it is completed. */ |
268 comp_sub = mb_progm_get_complete(progm); | 268 comp_sub = mb_progm_get_complete(progm); |
269 subject_add_observer(factory, comp_sub, | 269 subject_add_observer(comp_sub, clean_tank_progm_handler, tank); |
270 clean_tank_progm_handler, tank); | |
271 | 270 |
272 get_now(&now); | 271 get_now(&now); |
273 mb_progm_start(progm, tman, &now); | 272 mb_progm_start(progm, tman, &now); |
274 } | 273 } |
275 | 274 |
490 mb_progm_t *progm; | 489 mb_progm_t *progm; |
491 mb_word_t *word; | 490 mb_word_t *word; |
492 mb_action_t *act; | 491 mb_action_t *act; |
493 mb_timeval_t start, playing; | 492 mb_timeval_t start, playing; |
494 mb_timeval_t now, next; | 493 mb_timeval_t now, next; |
495 ob_factory_t *factory; | |
496 mb_tman_t *tman; | 494 mb_tman_t *tman; |
497 subject_t *subject; | 495 subject_t *subject; |
498 static int map_xy_adj[][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; | 496 static int map_xy_adj[][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; |
499 | 497 |
500 if(tank->bullet != NULL) | 498 if(tank->bullet != NULL) |
544 act = mb_shift_new(shift_x, shift_y, bullet->coord_pos, word); | 542 act = mb_shift_new(shift_x, shift_y, bullet->coord_pos, word); |
545 bullet->progm = progm; | 543 bullet->progm = progm; |
546 | 544 |
547 /*! \todo Simplify the procdure of using observer pattern. */ | 545 /*! \todo Simplify the procdure of using observer pattern. */ |
548 subject = mb_progm_get_complete(progm); | 546 subject = mb_progm_get_complete(progm); |
549 factory = rdman_get_ob_factory(rdman); | 547 subject_add_observer(subject, bullet_go_out_map, tank); |
550 subject_add_observer(factory, subject, bullet_go_out_map, tank); | |
551 | 548 |
552 get_now(&now); | 549 get_now(&now); |
553 MB_TIMEVAL_CP(&bullet->start_time, &now); | 550 MB_TIMEVAL_CP(&bullet->start_time, &now); |
554 mb_progm_start(progm, tman, &now); | 551 mb_progm_start(progm, tman, &now); |
555 | 552 |
612 | 609 |
613 static void init_keyboard(tank_rt_t *tank_rt) { | 610 static void init_keyboard(tank_rt_t *tank_rt) { |
614 X_MB_runtime_t *mb_rt; | 611 X_MB_runtime_t *mb_rt; |
615 subject_t *kbevents; | 612 subject_t *kbevents; |
616 redraw_man_t *rdman; | 613 redraw_man_t *rdman; |
617 ob_factory_t *factory; | |
618 | 614 |
619 mb_rt = tank_rt->mb_rt; | 615 mb_rt = tank_rt->mb_rt; |
620 kbevents = X_MB_kbevents(mb_rt); | 616 kbevents = X_MB_kbevents(mb_rt); |
621 | 617 |
622 rdman = X_MB_rdman(mb_rt); | 618 rdman = X_MB_rdman(mb_rt); |
623 factory = rdman_get_ob_factory(rdman); | |
624 | 619 |
625 tank_rt->kb_observer = | 620 tank_rt->kb_observer = |
626 subject_add_observer(factory, kbevents, keyboard_handler, tank_rt); | 621 subject_add_observer(kbevents, keyboard_handler, tank_rt); |
627 } | 622 } |
628 | 623 |
629 /*! \brief Make coord objects to decorate elfs (tanks). | 624 /*! \brief Make coord objects to decorate elfs (tanks). |
630 * | 625 * |
631 * These coords are used to shift (move) and rotate decorated graphic. | 626 * These coords are used to shift (move) and rotate decorated graphic. |