X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fanim.c;h=9d1f0b5c734dc75200cc077ff88d826051ceb443;hp=48393eb3141f320c38f1f58fe9c88afd7676a651;hb=b20de5f2d7dd54c56af6bda51748d2c03446bcdd;hpb=897c46a2720672a49ce6d0803b08eed23fd2dd90 diff --git a/src/anim.c b/src/anim.c index 48393eb3..9d1f0b5c 100644 --- a/src/anim.c +++ b/src/anim.c @@ -19,6 +19,9 @@ #include "screens.h" +#define DEBUG_ANIM_EVENTS 0 + + // values for global toon animation definition #define NUM_GLOBAL_TOON_ANIMS 1 #define NUM_GLOBAL_TOON_PARTS MAX_NUM_TOONS @@ -113,6 +116,7 @@ struct GlobalAnimPartControlInfo boolean init_event_state; boolean anim_event_state; + boolean triggered; boolean clickable; boolean clicked; @@ -205,6 +209,7 @@ struct AnimClassGameMode }; // forward declaration for internal use +static boolean DoGlobalAnim_EventAction(struct GlobalAnimPartControlInfo *); static void HandleGlobalAnim(int, int); static void DoAnimationExt(void); static void ResetGlobalAnim_Clickable(void); @@ -849,10 +854,20 @@ static boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part } else if (part->control_info.class == get_hash_from_key("door_2")) { - viewport_x = VX; - viewport_y = VY; - viewport_width = VXSIZE; - viewport_height = VYSIZE; + if (part->mode_nr == GAME_MODE_EDITOR) + { + viewport_x = EX; + viewport_y = EY; + viewport_width = EXSIZE; + viewport_height = EYSIZE; + } + else + { + viewport_x = VX; + viewport_y = VY; + viewport_width = VXSIZE; + viewport_height = VYSIZE; + } } else // default: "playfield" { @@ -998,6 +1013,8 @@ static boolean checkGlobalAnimEvent(int anim_event, int mask) return (anim_event & ANIM_EVENT_ANY); else if (mask & ANIM_EVENT_SELF) return (anim_event & ANIM_EVENT_SELF); + else if (mask & ANIM_EVENT_UNCLICK_ANY) + return (anim_event & ANIM_EVENT_UNCLICK_ANY); else return (anim_event == mask || anim_event == mask_anim_only); @@ -1064,6 +1081,85 @@ static boolean clickConsumed(struct GlobalAnimPartControlInfo *part) return (part->control_info.style & STYLE_PASSTHROUGH ? FALSE : TRUE); } +static void InitGlobalAnim_Triggered(struct GlobalAnimPartControlInfo *part, + boolean *anything_clicked, + boolean *any_event_action, + int event_value, char *info_text) +{ + struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[part->mode_nr]; + + int gic_anim_nr = part->old_anim_nr + 1; // X as in "anim_X" + int gic_part_nr = part->old_nr + 1; // Y as in "part_Y" + int mask = event_value | (gic_anim_nr << ANIM_EVENT_ANIM_BIT); + + if (!part->is_base) + mask |= gic_part_nr << ANIM_EVENT_PART_BIT; + + int anim2_nr; + + for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++) + { + struct GlobalAnimMainControlInfo *anim2 = &ctrl->anim[anim2_nr]; + int part2_nr; + + for (part2_nr = 0; part2_nr < anim2->num_parts_all; part2_nr++) + { + struct GlobalAnimPartControlInfo *part2 = &anim2->part[part2_nr]; + + if (part2->state != ANIM_STATE_RUNNING) + continue; + + if (isClickablePart(part2, mask)) + { + part2->triggered = TRUE; + *anything_clicked = clickConsumed(part); // click was on "part"! + +#if DEBUG_ANIM_EVENTS + printf("::: => %d.%d TRIGGERED BY %s OF %d.%d\n", + part2->old_anim_nr + 1, part2->old_nr + 1, info_text, + part->old_anim_nr + 1, part->old_nr + 1); +#endif +#if 0 + printf("::: %d.%d TRIGGER CLICKED [%d]\n", anim2_nr, part2_nr, + part2->control_info.anim_event_action); +#endif + + // after executing event action, ignore any further actions + if (!*any_event_action && DoGlobalAnim_EventAction(part2)) + *any_event_action = TRUE; + } + +#if 0 + struct GraphicInfo *c = &part2->control_info; + + printf("::: - %d.%d: 0x%08x, 0x%08x [0x%08x]", + anim2_nr, part2_nr, c->init_event, c->anim_event, mask); + + if (isClickablePart(part2, mask)) + printf(" <--- TRIGGERED BY %d.%d", + anim_nr, part_nr); + + printf("\n"); +#endif + } + } +} + +static void HandleGlobalAnimEvent(struct GlobalAnimPartControlInfo *part, + int event_value, char *info_text) +{ +#if DEBUG_ANIM_EVENTS + printf("::: %d.%d %s\n", part->old_anim_nr + 1, part->old_nr + 1, info_text); +#endif + + boolean anything_clicked = FALSE; + boolean any_event_action = FALSE; + + // check if this event is defined to trigger other animations + InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action, + event_value, info_text); +} + static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state) { @@ -1180,7 +1276,15 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, if (part->init_delay_counter == 0 && !part->init_event_state) + { PlayGlobalAnimSoundAndMusic(part); + + HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]"); + } + else + { + HandleGlobalAnimEvent(part, ANIM_EVENT_INIT, "START [INIT_DELAY/EVENT]"); + } } if (part->clicked && @@ -1213,6 +1317,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, part->init_event_state = FALSE; PlayGlobalAnimSoundAndMusic(part); + + HandleGlobalAnimEvent(part, ANIM_EVENT_START, "START [ANIM]"); } return ANIM_STATE_WAITING; @@ -1239,6 +1345,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, { StopGlobalAnimSoundAndMusic(part); + HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM/OFF-SCREEN]"); + part->post_delay_counter = (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random)); @@ -1260,6 +1368,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, StopGlobalAnimSoundAndMusic(part); + HandleGlobalAnimEvent(part, ANIM_EVENT_END, "END [ANIM_DELAY/EVENT]"); + part->post_delay_counter = (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random)); @@ -1276,7 +1386,11 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, part->post_delay_counter--; if (part->post_delay_counter == 0) + { + HandleGlobalAnimEvent(part, ANIM_EVENT_POST, "END [POST_DELAY]"); + return ANIM_STATE_RESTART; + } return ANIM_STATE_WAITING; } @@ -1540,13 +1654,21 @@ static void InitGlobalAnim_Clickable(void) { struct GlobalAnimPartControlInfo *part = &anim->part[part_nr]; + if (part->triggered) + part->clicked = TRUE; + + part->triggered = FALSE; part->clickable = FALSE; } } } } -static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked) +#define ANIM_CLICKED_RESET 0 +#define ANIM_CLICKED_PRESSED 1 +#define ANIM_CLICKED_RELEASED 2 + +static boolean InitGlobalAnim_Clicked(int mx, int my, int clicked_event) { boolean anything_clicked = FALSE; boolean any_part_clicked = FALSE; @@ -1570,7 +1692,7 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked) { struct GlobalAnimPartControlInfo *part = &anim->part[part_nr]; - if (!clicked) + if (clicked_event == ANIM_CLICKED_RESET) { part->clicked = FALSE; @@ -1584,8 +1706,27 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked) continue; // always handle "any" click events (clicking anywhere on screen) ... - if (isClickablePart(part, ANIM_EVENT_ANY)) + if (clicked_event == ANIM_CLICKED_PRESSED && + isClickablePart(part, ANIM_EVENT_ANY)) { +#if DEBUG_ANIM_EVENTS + printf("::: => %d.%d TRIGGERED BY ANY\n", + part->old_anim_nr + 1, part->old_nr + 1); +#endif + + part->clicked = TRUE; + anything_clicked = clickConsumed(part); + } + + // always handle "unclick:any" events (releasing anywhere on screen) ... + if (clicked_event == ANIM_CLICKED_RELEASED && + isClickablePart(part, ANIM_EVENT_UNCLICK_ANY)) + { +#if DEBUG_ANIM_EVENTS + printf("::: => %d.%d TRIGGERED BY UNCLICK:ANY\n", + part->old_anim_nr + 1, part->old_nr + 1); +#endif + part->clicked = TRUE; anything_clicked = clickConsumed(part); } @@ -1594,7 +1735,8 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked) if (any_part_clicked) continue; - if (isClickedPart(part, mx, my, clicked)) + if (clicked_event == ANIM_CLICKED_PRESSED && + isClickedPart(part, mx, my, TRUE)) { #if 0 printf("::: %d.%d CLICKED [%d]\n", anim_nr, part_nr, @@ -1610,61 +1752,18 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked) if (isClickablePart(part, ANIM_EVENT_SELF)) { +#if DEBUG_ANIM_EVENTS + printf("::: => %d.%d TRIGGERED BY SELF\n", + part->old_anim_nr + 1, part->old_nr + 1); +#endif + part->clicked = TRUE; anything_clicked = clickConsumed(part); } // check if this click is defined to trigger other animations - int gic_anim_nr = part->old_anim_nr + 1; // X as in "anim_X" - int gic_part_nr = part->old_nr + 1; // Y as in "part_Y" - int mask = ANIM_EVENT_CLICK | (gic_anim_nr << ANIM_EVENT_ANIM_BIT); - - if (!part->is_base) - mask |= gic_part_nr << ANIM_EVENT_PART_BIT; - - int anim2_nr; - - for (anim2_nr = 0; anim2_nr < ctrl->num_anims; anim2_nr++) - { - struct GlobalAnimMainControlInfo *anim2 = &ctrl->anim[anim2_nr]; - int part2_nr; - - for (part2_nr = 0; part2_nr < anim2->num_parts_all; part2_nr++) - { - struct GlobalAnimPartControlInfo *part2 = &anim2->part[part2_nr]; - - if (part2->state != ANIM_STATE_RUNNING) - continue; - - if (isClickablePart(part2, mask)) - { - part2->clicked = TRUE; - anything_clicked = clickConsumed(part); // click was on "part"! - -#if 0 - printf("::: %d.%d TRIGGER CLICKED [%d]\n", anim2_nr, part2_nr, - part2->control_info.anim_event_action); -#endif - - // after executing event action, ignore any further actions - if (!any_event_action && DoGlobalAnim_EventAction(part2)) - any_event_action = TRUE; - } - -#if 0 - struct GraphicInfo *c = &part2->control_info; - - printf("::: - %d.%d: 0x%08x, 0x%08x [0x%08x]", - anim2_nr, part2_nr, c->init_event, c->anim_event, mask); - - if (isClickablePart(part2, mask)) - printf(" <--- TRIGGERED BY %d.%d", - anim_nr, part_nr); - - printf("\n"); -#endif - } - } + InitGlobalAnim_Triggered(part, &anything_clicked, &any_event_action, + ANIM_EVENT_CLICK, "CLICK"); } } } @@ -1680,7 +1779,7 @@ static void ResetGlobalAnim_Clickable(void) static void ResetGlobalAnim_Clicked(void) { - InitGlobalAnim_Clicked(-1, -1, FALSE); + InitGlobalAnim_Clicked(-1, -1, ANIM_CLICKED_RESET); } boolean HandleGlobalAnimClicks(int mx, int my, int button) @@ -1698,12 +1797,15 @@ boolean HandleGlobalAnimClicks(int mx, int my, int button) if (press_event) { - click_consumed = InitGlobalAnim_Clicked(mx, my, TRUE); + click_consumed = InitGlobalAnim_Clicked(mx, my, ANIM_CLICKED_PRESSED); click_consumed_current = click_consumed; } if (release_event) + { + InitGlobalAnim_Clicked(mx, my, ANIM_CLICKED_RELEASED); click_consumed = FALSE; + } return click_consumed_current; }