X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fanim.c;h=cb2dc8816789d722f60e419e35dc54fd784d7bb5;hp=861364d727e4606a7ff284cb9f0893eb85a0f7c9;hb=912fcafbd1601312dcf94837380480638fa3f4b3;hpb=f93552d6cd84e880ee73d4864018167aefc1bb79 diff --git a/src/anim.c b/src/anim.c index 861364d7..cb2dc881 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); @@ -990,25 +995,43 @@ static void PlayGlobalAnimSoundIfLoop(struct GlobalAnimPartControlInfo *part) PlayGlobalAnimSound(part); } -static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask) +static boolean checkGlobalAnimEvent(int anim_event, int mask) { - struct GraphicInfo *c = &part->control_info; - int trigger_mask = ANIM_EVENT_ANIM_MASK | ANIM_EVENT_PART_MASK; - int mask_anim_only = mask & ANIM_EVENT_ANIM_MASK; - int init_event = GetGlobalAnimEventValue(c->init_event, 0); - int anim_event = GetGlobalAnimEventValue(c->anim_event, 0); + int mask_anim_only = mask & ~ANIM_EVENT_PART_MASK; if (mask & ANIM_EVENT_ANY) - return (init_event & ANIM_EVENT_ANY || - anim_event & ANIM_EVENT_ANY); + return (anim_event & ANIM_EVENT_ANY); else if (mask & ANIM_EVENT_SELF) - return (init_event & ANIM_EVENT_SELF || - anim_event & ANIM_EVENT_SELF); + return (anim_event & ANIM_EVENT_SELF); else - return ((init_event & trigger_mask) == mask || - (anim_event & trigger_mask) == mask || - (init_event & trigger_mask) == mask_anim_only || - (anim_event & trigger_mask) == mask_anim_only); + return (anim_event == mask || + anim_event == mask_anim_only); +} + +static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask) +{ + struct GraphicInfo *c = &part->control_info; + int num_init_events = GetGlobalAnimEventValueCount(c->init_event); + int num_anim_events = GetGlobalAnimEventValueCount(c->anim_event); + int i; + + for (i = 0; i < num_init_events; i++) + { + int init_event = GetGlobalAnimEventValue(c->init_event, i); + + if (checkGlobalAnimEvent(init_event, mask)) + return TRUE; + } + + for (i = 0; i < num_anim_events; i++) + { + int anim_event = GetGlobalAnimEventValue(c->anim_event, i); + + if (checkGlobalAnimEvent(anim_event, mask)) + return TRUE; + } + + return FALSE; } static boolean isClickedPart(struct GlobalAnimPartControlInfo *part, @@ -1046,6 +1069,70 @@ 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) +{ + 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 %d.%d\n", + part2->old_anim_nr + 1, part2->old_nr + 1, + 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 int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state) { @@ -1073,8 +1160,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, part->anim_delay_counter = (c->anim_delay_fixed + GetSimpleRandom(c->anim_delay_random)); - part->init_event_state = GetGlobalAnimEventValue(c->init_event, 0); - part->anim_event_state = GetGlobalAnimEventValue(c->anim_event, 0); + part->init_event_state = (c->init_event != ANIM_EVENT_UNDEFINED); + part->anim_event_state = (c->anim_event != ANIM_EVENT_UNDEFINED); part->initial_anim_sync_frame = (g->anim_global_sync ? 0 : anim_sync_frame + part->init_delay_counter); @@ -1161,27 +1248,27 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, part->step_yoffset = c->step_yoffset; if (part->init_delay_counter == 0 && - part->init_event_state == ANIM_EVENT_NONE) + !part->init_event_state) PlayGlobalAnimSoundAndMusic(part); } if (part->clicked && - part->init_event_state != ANIM_EVENT_NONE) + part->init_event_state) { if (part->initial_anim_sync_frame > 0) part->initial_anim_sync_frame -= part->init_delay_counter - 1; part->init_delay_counter = 1; - part->init_event_state = ANIM_EVENT_NONE; + part->init_event_state = FALSE; part->clicked = FALSE; } if (part->clicked && - part->anim_event_state != ANIM_EVENT_NONE) + part->anim_event_state) { part->anim_delay_counter = 1; - part->anim_event_state = ANIM_EVENT_NONE; + part->anim_event_state = FALSE; part->clicked = FALSE; } @@ -1192,7 +1279,7 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, if (part->init_delay_counter == 0) { - part->init_event_state = ANIM_EVENT_NONE; + part->init_event_state = FALSE; PlayGlobalAnimSoundAndMusic(part); } @@ -1200,7 +1287,7 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, return ANIM_STATE_WAITING; } - if (part->init_event_state != ANIM_EVENT_NONE) + if (part->init_event_state) return ANIM_STATE_WAITING; // animation part is now running/visible and therefore clickable @@ -1213,7 +1300,7 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, (part->y >= part->viewport_height && part->step_yoffset >= 0)) { // do not wait for "anim" events for off-screen animations - part->anim_event_state = ANIM_EVENT_NONE; + part->anim_event_state = FALSE; // do not stop animation before "anim" or "post" counter are finished if (part->anim_delay_counter == 0 && @@ -1238,7 +1325,7 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, if (part->anim_delay_counter == 0) { - part->anim_event_state = ANIM_EVENT_NONE; + part->anim_event_state = FALSE; StopGlobalAnimSoundAndMusic(part); @@ -1522,6 +1609,10 @@ static void InitGlobalAnim_Clickable(void) { struct GlobalAnimPartControlInfo *part = &anim->part[part_nr]; + if (part->triggered) + part->clicked = TRUE; + + part->triggered = FALSE; part->clickable = FALSE; } } @@ -1568,6 +1659,11 @@ static boolean InitGlobalAnim_Clicked(int mx, int my, boolean clicked) // always handle "any" click events (clicking anywhere on screen) ... if (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); } @@ -1592,61 +1688,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 = 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); } } }