X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fcartoons.c;h=101d0ef1c5614298e06f35db36eecca853136684;hb=c9338238a6f7a351df83aa4739b165c377bbdb17;hp=c2072a2067c51cc279d018e135b2df5ac7c94524;hpb=da028195db34242cd7a82d82de768109963509cb;p=rocksndiamonds.git diff --git a/src/cartoons.c b/src/cartoons.c index c2072a20..101d0ef1 100644 --- a/src/cartoons.c +++ b/src/cartoons.c @@ -26,21 +26,24 @@ #define ANIM_CLASS_BIT_TITLE_INITIAL 0 #define ANIM_CLASS_BIT_TITLE 1 -#define ANIM_CLASS_BIT_SUBMENU 2 -#define ANIM_CLASS_BIT_MENU 3 -#define ANIM_CLASS_BIT_TOONS 4 +#define ANIM_CLASS_BIT_MAIN 2 +#define ANIM_CLASS_BIT_SUBMENU 3 +#define ANIM_CLASS_BIT_MENU 4 +#define ANIM_CLASS_BIT_TOONS 5 -#define NUM_ANIM_CLASSES 5 +#define NUM_ANIM_CLASSES 6 #define ANIM_CLASS_NONE 0 #define ANIM_CLASS_TITLE_INITIAL (1 << ANIM_CLASS_BIT_TITLE_INITIAL) #define ANIM_CLASS_TITLE (1 << ANIM_CLASS_BIT_TITLE) +#define ANIM_CLASS_MAIN (1 << ANIM_CLASS_BIT_MAIN) #define ANIM_CLASS_SUBMENU (1 << ANIM_CLASS_BIT_SUBMENU) #define ANIM_CLASS_MENU (1 << ANIM_CLASS_BIT_MENU) #define ANIM_CLASS_TOONS (1 << ANIM_CLASS_BIT_TOONS) -#define ANIM_CLASS_TOONS_MENU (ANIM_CLASS_TOONS | \ - ANIM_CLASS_MENU) +#define ANIM_CLASS_TOONS_MENU_MAIN (ANIM_CLASS_TOONS | \ + ANIM_CLASS_MENU | \ + ANIM_CLASS_MAIN) #define ANIM_CLASS_TOONS_MENU_SUBMENU (ANIM_CLASS_TOONS | \ ANIM_CLASS_MENU | \ @@ -52,7 +55,9 @@ struct GlobalAnimPartControlInfo int anim_nr; int mode_nr; + int sound; int graphic; + struct GraphicInfo graphic_info; struct GraphicInfo control_info; @@ -128,7 +133,8 @@ struct GameModeAnimClass { GAME_MODE_LEVELNR, ANIM_CLASS_TOONS_MENU_SUBMENU }, { GAME_MODE_INFO, ANIM_CLASS_TOONS_MENU_SUBMENU }, { GAME_MODE_SETUP, ANIM_CLASS_TOONS_MENU_SUBMENU }, - { GAME_MODE_MAIN, ANIM_CLASS_TOONS_MENU }, + { GAME_MODE_PSEUDO_MAINONLY, ANIM_CLASS_TOONS_MENU_MAIN }, + { GAME_MODE_PSEUDO_TYPENAME, ANIM_CLASS_TOONS_MENU_MAIN }, { GAME_MODE_SCORES, ANIM_CLASS_TOONS }, { -1, -1 } @@ -142,6 +148,7 @@ struct AnimClassGameMode { { ANIM_CLASS_BIT_TITLE_INITIAL, GAME_MODE_TITLE_INITIAL }, { ANIM_CLASS_BIT_TITLE, GAME_MODE_TITLE }, + { ANIM_CLASS_BIT_MAIN, GAME_MODE_MAIN }, { ANIM_CLASS_BIT_SUBMENU, GAME_MODE_PSEUDO_SUBMENU }, { ANIM_CLASS_BIT_MENU, GAME_MODE_PSEUDO_MENU }, { ANIM_CLASS_BIT_TOONS, GAME_MODE_PSEUDO_TOONS }, @@ -157,8 +164,6 @@ static struct GlobalAnimControlInfo global_anim_ctrl[NUM_GAME_MODES]; static struct ToonInfo toons[MAX_NUM_TOONS]; static unsigned int anim_sync_frame = 0; -static unsigned int anim_sync_frame_delay = 0; -static unsigned int anim_sync_frame_delay_value = GAME_FRAME_DELAY; static int game_mode_anim_classes[NUM_GAME_MODES]; static int anim_class_game_modes[NUM_ANIM_CLASSES]; @@ -304,12 +309,14 @@ static void InitToonControls() for (i = 0; i < num_toons; i++) { struct GlobalAnimPartControlInfo *part = &anim->part[part_nr]; + int sound = SND_UNDEFINED; int graphic = IMG_TOON_1 + i; int control = graphic; part->nr = part_nr; part->anim_nr = anim_nr; part->mode_nr = mode_nr; + part->sound = sound; part->graphic = graphic; part->graphic_info = graphic_info[graphic]; part->control_info = graphic_info[control]; @@ -341,12 +348,10 @@ void InitGlobalAnimControls() { int i, m, a, p; int mode_nr, anim_nr, part_nr; - int graphic, control; + int sound, graphic, control; anim_sync_frame = 0; - ResetDelayCounter(&anim_sync_frame_delay); - for (m = 0; m < NUM_GAME_MODES; m++) { mode_nr = m; @@ -389,6 +394,7 @@ void InitGlobalAnimControls() { struct GlobalAnimPartControlInfo *part = &anim->part[part_nr]; + sound = global_anim_info[a].sound[p][m]; graphic = global_anim_info[a].graphic[p][m]; control = global_anim_info[ctrl_id].graphic[p][m]; @@ -401,9 +407,15 @@ void InitGlobalAnimControls() m, a, p, mode_nr, anim_nr, part_nr, control); #endif +#if 0 + printf("::: mode == %d, anim = %d, part = %d [%d, %d, %d] [%d]\n", + m, a, p, mode_nr, anim_nr, part_nr, sound); +#endif + part->nr = part_nr; part->anim_nr = anim_nr; part->mode_nr = mode_nr; + part->sound = sound; part->graphic = graphic; part->graphic_info = graphic_info[graphic]; part->control_info = graphic_info[control]; @@ -699,6 +711,44 @@ boolean SetGlobalAnimPart_Viewport(struct GlobalAnimPartControlInfo *part) return changed; } +void PlayGlobalAnimSound(struct GlobalAnimPartControlInfo *part) +{ + int sound = part->sound; + + if (sound == SND_UNDEFINED) + return; + + if ((!setup.sound_simple && !IS_LOOP_SOUND(sound)) || + (!setup.sound_loops && IS_LOOP_SOUND(sound))) + return; + + // !!! TODO: ADD STEREO POSITION FOR MOVING ANIMATIONS !!! + if (IS_LOOP_SOUND(sound)) + PlaySoundLoop(sound); + else + PlaySound(sound); + +#if 0 + printf("::: PLAY %d.%d.%d: %d\n", + part->anim_nr, part->nr, part->mode_nr, sound); +#endif +} + +void StopGlobalAnimSound(struct GlobalAnimPartControlInfo *part) +{ + int sound = part->sound; + + if (sound == SND_UNDEFINED) + return; + + StopSound(sound); + +#if 0 + printf("::: STOP %d.%d.%d: %d\n", + part->anim_nr, part->nr, part->mode_nr, sound); +#endif +} + int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state) { struct GraphicInfo *g = &part->graphic_info; @@ -793,12 +843,18 @@ int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state) part->step_xoffset = c->step_xoffset; if (c->step_yoffset != ARG_UNDEFINED_VALUE) part->step_yoffset = c->step_yoffset; + + if (part->init_delay_counter == 0) + PlayGlobalAnimSound(part); } if (part->init_delay_counter > 0) { part->init_delay_counter--; + if (part->init_delay_counter == 0) + PlayGlobalAnimSound(part); + return ANIM_STATE_WAITING; } @@ -812,12 +868,15 @@ int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state) if (part->anim_delay_counter == 0 && part->post_delay_counter == 0) { + StopGlobalAnimSound(part); + part->post_delay_counter = (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random)); if (part->post_delay_counter > 0) return ANIM_STATE_RUNNING; + // drawing last frame not needed here -- animation not visible anymore return ANIM_STATE_RESTART; } } @@ -828,6 +887,8 @@ int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, int state) if (part->anim_delay_counter == 0) { + StopGlobalAnimSound(part); + part->post_delay_counter = (c->post_delay_fixed + GetSimpleRandom(c->post_delay_random)); @@ -916,6 +977,14 @@ void HandleGlobalAnim_Main(struct GlobalAnimMainControlInfo *anim, int action) case ANIM_STOP: anim->state = ANIM_STATE_INACTIVE; + { + int num_parts = anim->num_parts + (anim->has_base ? 1 : 0); + int i; + + for (i = 0; i < num_parts; i++) + StopGlobalAnimSound(&anim->part[i]); + } + return; default: @@ -1054,13 +1123,8 @@ static void DoAnimationExt() printf("::: DoAnimation [%d, %d]\n", anim_sync_frame, Counter()); #endif -#if 1 - WaitUntilDelayReached(&anim_sync_frame_delay, anim_sync_frame_delay_value); + // global animations now synchronized with frame delay of screen update anim_sync_frame++; -#else - if (DelayReached(&anim_sync_frame_delay, anim_sync_frame_delay_value)) - anim_sync_frame++; -#endif for (i = 0; i < NUM_GAME_MODES; i++) HandleGlobalAnim(ANIM_CONTINUE, i);