From c8badc08c284a9ded7d9ee72e9537f37b38839ad Mon Sep 17 00:00:00 2001 From: mcmartin Date: Thu, 8 Mar 2007 00:46:46 +0000 Subject: [PATCH] Preliminary ship spin support. This includes perhaps 2/3s of the patch on Bugzilla -- the remainder no longer works with the current repository. As a result, ship spins in the Shipyard are disabled in this patch. This will be addressed in a later patch. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2711 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/fmv.c | 4 +- sc2/src/sc2code/fmv.h | 2 +- sc2/src/sc2code/libs/video/dukvid.c | 9 +++- sc2/src/sc2code/libs/video/video.c | 25 ++++++++++- sc2/src/sc2code/libs/video/video.h | 1 + sc2/src/sc2code/libs/video/vidplayer.c | 60 ++++++++++++++++++++++---- sc2/src/sc2code/melee.c | 7 ++- sc2/src/sc2code/shipyard.c | 4 ++ 8 files changed, 98 insertions(+), 14 deletions(-) diff --git a/sc2/src/sc2code/fmv.c b/sc2/src/sc2code/fmv.c index 3e5bd796d..e871ce339 100644 --- a/sc2/src/sc2code/fmv.c +++ b/sc2/src/sc2code/fmv.c @@ -50,8 +50,8 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic) FreeHyperData (); - sprintf (buf, "ship%02d", index); - DoFMV (buf, "spin", FALSE); + sprintf (buf, "slides/spins/ship%02d.duk", index); + DoFMV (buf, "slides/spins/spin.aif", FALSE); GetContextClipRect (&old_r); r.corner.x = r.corner.y = 0; diff --git a/sc2/src/sc2code/fmv.h b/sc2/src/sc2code/fmv.h index 307f9a3e8..4910e65fe 100644 --- a/sc2/src/sc2code/fmv.h +++ b/sc2/src/sc2code/fmv.h @@ -18,7 +18,7 @@ #define _FMV_H #include "libs/compiler.h" - +#define WANT_SHIP_SPINS extern void Logo (void); extern void SplashScreen (void (* DoProcessing)(DWORD TimeOut)); diff --git a/sc2/src/sc2code/libs/video/dukvid.c b/sc2/src/sc2code/libs/video/dukvid.c index ba55f124a..0e51354ba 100644 --- a/sc2/src/sc2code/libs/video/dukvid.c +++ b/sc2/src/sc2code/libs/video/dukvid.c @@ -111,6 +111,8 @@ typedef struct tfb_duckvideodecoder #define DUCK_GENERAL_FPS 14.622f #define DUCK_MAX_FRAME_SIZE 0x8000U #define DUCK_END_OF_SEQUENCE 1 +/* Some ship spin animations contain extra frames that must be discarded. */ +#define VIDEO_SPIN_LOOP_FRAME 89 static void dukv_DecodeFrame (uint8* src_p, uint32* dst_p, uint32 wb, uint32 hb, @@ -529,7 +531,8 @@ dukv_RenderFrame (THIS_PTR) default: ; } - + if (!This->audio_synced) + This->callbacks.SetTimer (This, (uint32) (1000.0f / DUCK_GENERAL_FPS)); } static const char* @@ -702,6 +705,10 @@ dukv_DecodeNext (THIS_PTR) dukv_RenderFrame (This); + if (dukv->decoder.looping + && (dukv->decoder.cur_frame == VIDEO_SPIN_LOOP_FRAME)) + VideoDecoder_SeekFrame (&dukv->decoder, 0); + return 1; } diff --git a/sc2/src/sc2code/libs/video/video.c b/sc2/src/sc2code/libs/video/video.c index cc5b7eba8..dbeb10cea 100644 --- a/sc2/src/sc2code/libs/video/video.c +++ b/sc2/src/sc2code/libs/video/video.c @@ -83,6 +83,12 @@ VidPlay (VIDEO_REF VidRef, const char *loopname, BOOLEAN uninit) if (!vid) return NO_FMV; + if (loopname != NULL) { + vid->hAudio2 = LoadMusicFile (loopname); + vid->decoder->audio_synced = FALSE; + vid->decoder->looping = TRUE; + } + if (_cur_video) TFB_StopVideo (_cur_video); _cur_video = NULL_VIDEO_REF; @@ -105,7 +111,6 @@ VidPlay (VIDEO_REF VidRef, const char *loopname, BOOLEAN uninit) UnlockMutex (GraphicsLock); /* dodge compiler warnings */ - (void) loopname; (void) uninit; return ret; @@ -123,6 +128,9 @@ _init_video_file(const char *pStr) { TFB_VideoClip* vid; TFB_VideoDecoder* dec; + char* filename; + char* pext; + MUSIC_REF altsound; dec = VideoDecoder_Load (contentDir, pStr); if (!dec) @@ -135,6 +143,21 @@ _init_video_file(const char *pStr) vid->h = vid->decoder->h; vid->guard = CreateMutex ("video guard", SYNC_CLASS_VIDEO); + /* Override main sound with .wav if available. */ + filename = HMalloc (strlen (pStr) + 5); + strcpy (filename, pStr); + pext = strrchr (filename, '.'); + if (pext) + *pext = 0; + strcat (filename, ".wav"); + altsound = LoadMusicFile (filename); + if (altsound != 0) { + DestroyMusic (vid->hAudio); + vid->hAudio = altsound; + } else + vid->hAudio = 0; + vid->hAudio2 = 0; + return (VIDEO_REF) vid; } diff --git a/sc2/src/sc2code/libs/video/video.h b/sc2/src/sc2code/libs/video/video.h index fbb910dfb..dc9f500a0 100644 --- a/sc2/src/sc2code/libs/video/video.h +++ b/sc2/src/sc2code/libs/video/video.h @@ -37,6 +37,7 @@ typedef struct tfb_videoclip RECT dst_rect; // destination screen rect RECT src_rect; // source rect MUSIC_REF hAudio; + MUSIC_REF hAudio2; Task play_task; uint32 frame_time; // time when next frame should be rendered TFB_Image* frame; // frame preped and optimized for rendering diff --git a/sc2/src/sc2code/libs/video/vidplayer.c b/sc2/src/sc2code/libs/video/vidplayer.c index 80139896d..3ff6cc3a8 100644 --- a/sc2/src/sc2code/libs/video/vidplayer.c +++ b/sc2/src/sc2code/libs/video/vidplayer.c @@ -29,6 +29,29 @@ static void* vp_GetCanvasLine (TFB_VideoDecoder*, uint32 line); static uint32 vp_GetTicks (TFB_VideoDecoder*); static bool vp_SetTimer (TFB_VideoDecoder*, uint32 msecs); +void +startAudioStream (MUSIC_REF aud, uint32 ss, BOOLEAN loop) +{ + TFB_SoundSample **pmus; + + LockMusicData (aud, &pmus); + if (pmus) + { + LockMutex (soundSource[ss].stream_mutex); + PlayStream ((*pmus), ss, loop, false, true); + UnlockMutex (soundSource[ss].stream_mutex); + } +} + +void +stopAudioStream (MUSIC_REF aud, uint32 ss) +{ + LockMutex (soundSource[ss].stream_mutex); + StopStream (ss); + UnlockMutex (soundSource[ss].stream_mutex); + UnlockMusicData (aud); +} + TFB_VideoCallbacks vp_DecoderCBs = { vp_GetCanvasLine, @@ -123,7 +146,10 @@ as_video_play_task (void *data) LockMutex (vid->guard); want_frame = vid->want_frame; - PlayMusic (vid->hAudio, FALSE, 1); + if (vid->hAudio) + startAudioStream (vid->hAudio, SPEECH_SOURCE, FALSE); + if (vid->hAudio2) + startAudioStream (vid->hAudio2, MUSIC_SOURCE, TRUE); UnlockMutex (vid->guard); clagged = 0; @@ -208,7 +234,10 @@ as_video_play_task (void *data) ret = VideoDecoder_Decode (vid->decoder); } - StopMusic (); + if (vid->hAudio) + stopAudioStream (vid->hAudio, SPEECH_SOURCE); + if (vid->hAudio2) + stopAudioStream (vid->hAudio2, MUSIC_SOURCE); vid->playing = false; FinishTask (task); @@ -232,7 +261,11 @@ video_play_task (void *data) LockMutex (vid->guard); if (vid->hAudio) - PlayMusic (vid->hAudio, FALSE, 1); + startAudioStream (vid->hAudio, SPEECH_SOURCE, FALSE); + + if (vid->hAudio2) + startAudioStream (vid->hAudio2, MUSIC_SOURCE, TRUE); + UnlockMutex (vid->guard); // this works like so: @@ -264,7 +297,9 @@ video_play_task (void *data) } vid->playing = false; if (vid->hAudio) - StopMusic (); + stopAudioStream (vid->hAudio, SPEECH_SOURCE); + if (vid->hAudio2) + stopAudioStream (vid->hAudio2, MUSIC_SOURCE); FinishTask (task); @@ -315,7 +350,9 @@ TFB_PlayVideo (VIDEO_REF VidRef, uint32 x, uint32 y) vid->cur_frame = -1; vid->want_frame = -1; - vid->hAudio = LoadMusicFile (vid->decoder->filename); + if (vid->hAudio == 0) + vid->hAudio = LoadMusicFile (vid->decoder->filename); + StopMusic (); if (vid->decoder->audio_synced) @@ -375,9 +412,16 @@ TFB_StopVideo (VIDEO_REF VidRef) if (vid->hAudio) { - StopMusic (); - DestroyMusic (vid->hAudio); - vid->hAudio = 0; + if (vid->hAudio) { + stopAudioStream (vid->hAudio, SPEECH_SOURCE); + DestroyMusic (vid->hAudio); + vid->hAudio = 0; + } + if (vid->hAudio2) { + stopAudioStream (vid->hAudio2, MUSIC_SOURCE); + DestroyMusic (vid->hAudio2); + vid->hAudio2 = 0; + } } if (vid->frame) { diff --git a/sc2/src/sc2code/melee.c b/sc2/src/sc2code/melee.c index 767060096..31457b26c 100644 --- a/sc2/src/sc2code/melee.c +++ b/sc2/src/sc2code/melee.c @@ -1733,9 +1733,14 @@ DoPickShip (MELEE_STATE *pMS) return (TRUE); } - else if (PulsedInputState.menu[KEY_MENU_SPECIAL]) + else if (PulsedInputState.menu[KEY_MENU_SPECIAL] + && (pMeleeState->CurIndex != (BYTE)~0)) { + BOOLEAN (*InputFunc) (struct melee_state *pInputState); + InputFunc = pMS->InputFunc; + pMS->InputFunc = 0; /* disable ship flashing */ DoShipSpin (pMS->CurIndex, (MUSIC_REF)0); + pMS->InputFunc = InputFunc; return (TRUE); } diff --git a/sc2/src/sc2code/shipyard.c b/sc2/src/sc2code/shipyard.c index 515b1ada8..1f827a604 100644 --- a/sc2/src/sc2code/shipyard.c +++ b/sc2/src/sc2code/shipyard.c @@ -66,6 +66,10 @@ static const COORD hangar_x_coords[HANGAR_SHIPS_ROW] = #define HANGAR_ROWS (HANGAR_SHIPS / HANGAR_SHIPS_ROW) #define HANGAR_ANIM_RATE 15 // fps +/* This is a temporary stopgap to disable shipspin attempts here until + they actually work */ +#undef WANT_SHIP_SPINS + enum { SHIPYARD_CREW,