From cdb51cf448b665e85781c3f7c91cfb7b25287549 Mon Sep 17 00:00:00 2001 From: avolkov Date: Thu, 5 Apr 2007 06:28:58 +0000 Subject: [PATCH] Cleanup of 3DO ship spin support git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2721 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/src/sc2code/fmv.c | 19 ++++--- sc2/src/sc2code/fmv.h | 6 ++- sc2/src/sc2code/intro.c | 27 ++++++++-- sc2/src/sc2code/libs/graphics/gfx_common.h | 1 - sc2/src/sc2code/libs/sndlib.h | 2 + sc2/src/sc2code/libs/sound/music.c | 31 ++++++++++++ sc2/src/sc2code/libs/video/dukvid.c | 6 --- sc2/src/sc2code/libs/video/video.c | 58 +++++++++++----------- sc2/src/sc2code/libs/video/video.h | 4 +- sc2/src/sc2code/libs/video/vidplayer.c | 38 ++++++-------- sc2/src/sc2code/libs/vidlib.h | 9 ++-- sc2/src/sc2code/setupmenu.c | 1 + 13 files changed, 127 insertions(+), 76 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 2d25814d5..d4599e5d4 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.7: +- Cleanup of 3DO ship spin support; spin speech works now - Alex - No longer creating and mounting a temporary directory. It is no longer used, but it might be again at some point, for loadable modules. - SvdB - Added RNG functions that work on a supplied state - SvdB diff --git a/sc2/src/sc2code/fmv.c b/sc2/src/sc2code/fmv.c index e871ce339..ca7481c9c 100644 --- a/sc2/src/sc2code/fmv.c +++ b/sc2/src/sc2code/fmv.c @@ -31,11 +31,15 @@ #include "libs/inplib.h" +/* Some ship spin animations contain extra frames that must be discarded. */ +#define SHIP_SPIN_LOOP_FRAME 89 + void DoShipSpin (COUNT index, MUSIC_REF hMusic) { #ifdef WANT_SHIP_SPINS - char buf[30]; + char vnbuf[32]; + char snbuf[32]; BYTE clut_buf[1]; RECT old_r, r; @@ -50,8 +54,9 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic) FreeHyperData (); - sprintf (buf, "slides/spins/ship%02d.duk", index); - DoFMV (buf, "slides/spins/spin.aif", FALSE); + sprintf (vnbuf, "slides/spins/ship%02u.duk", (unsigned)index); + sprintf (snbuf, "slides/spins/ship%02u.aif", (unsigned)index); + DoFMVEx (vnbuf, "slides/spins/spin.aif", snbuf, SHIP_SPIN_LOOP_FRAME); GetContextClipRect (&old_r); r.corner.x = r.corner.y = 0; @@ -138,8 +143,7 @@ Introduction (void) /* by default we do 3DO cinematics; or PC slides when 3DO files are * not present */ - if (optWhichIntro == OPT_PC || - !DoFMV ("slides/intro/intro.duk", NULL, TRUE)) + if (optWhichIntro == OPT_PC || !DoFMV ("slides/intro/intro.duk")) ShowPresentation ( CaptureStringTable ( LoadStringTable (INTROPRES_STRTAB))); @@ -157,8 +161,7 @@ Victory (void) /* by default we do 3DO cinematics; or PC slides when 3DO files are * not present */ - if (optWhichIntro == OPT_PC || - !DoFMV ("slides/ending/victory.duk", NULL, TRUE)) + if (optWhichIntro == OPT_PC || !DoFMV ("slides/ending/victory.duk")) ShowPresentation ( CaptureStringTable ( LoadStringTable (FINALPRES_STRTAB))); @@ -169,7 +172,7 @@ Victory (void) void Logo (void) { - DoFMV ("logo", NULL, FALSE); + DoFMV ("logo"); } diff --git a/sc2/src/sc2code/fmv.h b/sc2/src/sc2code/fmv.h index 4910e65fe..76c6d8c46 100644 --- a/sc2/src/sc2code/fmv.h +++ b/sc2/src/sc2code/fmv.h @@ -28,8 +28,10 @@ extern void Victory (void); #include "libs/sndlib.h" extern void DoShipSpin (COUNT index, MUSIC_REF hMusic); -extern BOOLEAN DoFMV (const char *name, const char *loopname, - BOOLEAN uninit); +extern BOOLEAN DoFMV (const char *name); +extern BOOLEAN DoFMVEx (const char *name, const char *audname, + const char *speechname, DWORD loopframe); + extern BOOLEAN ShowPresentation (STRING PresStr); extern BOOLEAN ShowPresentationFile (const char *name); diff --git a/sc2/src/sc2code/intro.c b/sc2/src/sc2code/intro.c index 51bde8070..7756e9c41 100644 --- a/sc2/src/sc2code/intro.c +++ b/sc2/src/sc2code/intro.c @@ -27,7 +27,7 @@ #include "libs/graphics/gfx_common.h" #include "libs/graphics/drawable.h" #include "libs/sound/sound.h" -//#include "libs/vidlib.h" +#include "libs/vidlib.h" #include "libs/inplib.h" #include "libs/log.h" @@ -73,21 +73,40 @@ static BOOLEAN DoPresentation (void *pIS); BOOLEAN -DoFMV (const char *name, const char *loopname, BOOLEAN uninit) +DoFMVEx (const char *name, const char *audname, const char *speechname, + DWORD loopframe) { VIDEO_REF VidRef; + MUSIC_REF AudRef = 0; + MUSIC_REF SpeechRef = 0; VidRef = LoadVideoFile (name); if (!VidRef) return FALSE; - VidPlay (VidRef, loopname, uninit); + if (audname) + AudRef = LoadMusicFile (audname); + if (speechname) + SpeechRef = LoadMusicFile (speechname); + + VidPlayEx (VidRef, AudRef, SpeechRef, loopframe); VidDoInput (); VidStop (); - DestroyVideo (VidRef); + DestroyVideo (VidRef); + if (SpeechRef) + DestroyMusic (SpeechRef); + if (AudRef) + DestroyMusic (AudRef); + return TRUE; } +BOOLEAN +DoFMV (const char *name) +{ + return DoFMVEx (name, NULL, NULL, VID_NO_LOOP); +} + static BOOLEAN ParseColorString (const char *Src, COLOR* pColor) { diff --git a/sc2/src/sc2code/libs/graphics/gfx_common.h b/sc2/src/sc2code/libs/graphics/gfx_common.h index 7532ff627..60a7b3565 100644 --- a/sc2/src/sc2code/libs/graphics/gfx_common.h +++ b/sc2/src/sc2code/libs/graphics/gfx_common.h @@ -23,7 +23,6 @@ #include #include "libs/gfxlib.h" -#include "libs/vidlib.h" #include "libs/misc.h" // driver for TFB_InitGraphics diff --git a/sc2/src/sc2code/libs/sndlib.h b/sc2/src/sc2code/libs/sndlib.h index 5a824f8dd..3fc1e0b77 100644 --- a/sc2/src/sc2code/libs/sndlib.h +++ b/sc2/src/sc2code/libs/sndlib.h @@ -72,6 +72,8 @@ extern void PLRStop (MUSIC_REF MusicRef); extern BOOLEAN PLRPlaying (MUSIC_REF MusicRef); extern void PLRPause (MUSIC_REF MusicRef); extern void PLRResume (MUSIC_REF MusicRef); +extern void PlaySpeech (MUSIC_REF SpeechRef); +extern void StopSpeech (void); extern void PlayChannel (COUNT channel, void *sample, SoundPosition pos, void *positional_object, unsigned char priority); extern BOOLEAN ChannelPlaying (COUNT Channel); diff --git a/sc2/src/sc2code/libs/sound/music.c b/sc2/src/sc2code/libs/sound/music.c index 15681e3f7..fc2c81e74 100644 --- a/sc2/src/sc2code/libs/sound/music.c +++ b/sc2/src/sc2code/libs/sound/music.c @@ -22,6 +22,7 @@ static MUSIC_REF curMusicRef; +static MUSIC_REF curSpeechRef; void PLRPlaySong (MUSIC_REF MusicRef, BOOLEAN Continuous, BYTE Priority) @@ -95,6 +96,36 @@ PLRResume (MUSIC_REF MusicRef) } } +void +PlaySpeech (MUSIC_REF SpeechRef) +{ + TFB_SoundSample **pmus; + + LockMusicData (SpeechRef, &pmus); + if (pmus) + { + LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + PlayStream (*pmus, SPEECH_SOURCE, false, false, true); + UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + + curSpeechRef = SpeechRef; + } +} + +void +StopSpeech (void) +{ + if (!curSpeechRef) + return; + + LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + StopStream (SPEECH_SOURCE); + UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); + UnlockMusicData (curSpeechRef); + + curSpeechRef = 0; +} + BOOLEAN DestroyMusic (MUSIC_REF MusicRef) { diff --git a/sc2/src/sc2code/libs/video/dukvid.c b/sc2/src/sc2code/libs/video/dukvid.c index 0e51354ba..6cecf8175 100644 --- a/sc2/src/sc2code/libs/video/dukvid.c +++ b/sc2/src/sc2code/libs/video/dukvid.c @@ -111,8 +111,6 @@ 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, @@ -705,10 +703,6 @@ 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 dbeb10cea..3785c3ba2 100644 --- a/sc2/src/sc2code/libs/video/video.c +++ b/sc2/src/sc2code/libs/video/video.c @@ -23,6 +23,7 @@ #define NULL_VIDEO_REF (0) static VIDEO_REF _cur_video = NULL_VIDEO_REF; +static MUSIC_REF _cur_speech = 0; BOOLEAN InitVideoPlayer (BOOLEAN useCDROM) @@ -50,12 +51,14 @@ UninitVideoPlayer (void) void VidStop () { + if (_cur_speech) + StopSpeech (); if (_cur_video) { TFB_StopVideo (_cur_video); TFB_FadeClearScreen (); } - + _cur_speech = 0; _cur_video = NULL_VIDEO_REF; } @@ -73,9 +76,8 @@ VidPlaying () } VIDEO_TYPE -VidPlay (VIDEO_REF VidRef, const char *loopname, BOOLEAN uninit) - // uninit was used to uninit the game kernel - // before spawning duck exe +VidPlayEx (VIDEO_REF VidRef, MUSIC_REF AudRef, MUSIC_REF SpeechRef, + DWORD LoopFrame) { VIDEO_TYPE ret; TFB_VideoClip* vid = (TFB_VideoClip*) VidRef; @@ -83,14 +85,22 @@ VidPlay (VIDEO_REF VidRef, const char *loopname, BOOLEAN uninit) if (!vid) return NO_FMV; - if (loopname != NULL) { - vid->hAudio2 = LoadMusicFile (loopname); + if (AudRef) + { + if (vid->hAudio) + DestroyMusic (vid->hAudio); + vid->hAudio = AudRef; vid->decoder->audio_synced = FALSE; - vid->decoder->looping = TRUE; } + vid->loop_frame = LoopFrame; + vid->loop_to = 0; + + if (_cur_speech) + StopSpeech (); if (_cur_video) TFB_StopVideo (_cur_video); + _cur_speech = 0; _cur_video = NULL_VIDEO_REF; TFB_FadeClearScreen (); @@ -103,6 +113,11 @@ VidPlay (VIDEO_REF VidRef, const char *loopname, BOOLEAN uninit) { _cur_video = VidRef; ret = SOFTWARE_FMV; + if (SpeechRef) + { + PlaySpeech (SpeechRef); + _cur_speech = SpeechRef; + } } else { @@ -110,12 +125,15 @@ VidPlay (VIDEO_REF VidRef, const char *loopname, BOOLEAN uninit) } UnlockMutex (GraphicsLock); - /* dodge compiler warnings */ - (void) uninit; - return ret; } +VIDEO_TYPE +VidPlay (VIDEO_REF VidRef) +{ + return VidPlayEx (VidRef, 0, 0, VID_NO_LOOP); +} + void VidDoInput (void) { @@ -124,13 +142,10 @@ VidDoInput (void) } VIDEO_REF -_init_video_file(const char *pStr) +_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) @@ -143,21 +158,6 @@ _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 dc9f500a0..19fee01df 100644 --- a/sc2/src/sc2code/libs/video/video.h +++ b/sc2/src/sc2code/libs/video/video.h @@ -37,13 +37,15 @@ 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 uint32 cur_frame; // index of frame currently displayed uint32 max_frame_wait; bool playing; + bool own_audio; + uint32 loop_frame; // frame index to loop from + uint32 loop_to; // frame index to loop to Mutex guard; uint32 want_frame; // audio-signaled desired frame index diff --git a/sc2/src/sc2code/libs/video/vidplayer.c b/sc2/src/sc2code/libs/video/vidplayer.c index 3ff6cc3a8..5dfd8135d 100644 --- a/sc2/src/sc2code/libs/video/vidplayer.c +++ b/sc2/src/sc2code/libs/video/vidplayer.c @@ -147,9 +147,7 @@ as_video_play_task (void *data) LockMutex (vid->guard); want_frame = vid->want_frame; if (vid->hAudio) - startAudioStream (vid->hAudio, SPEECH_SOURCE, FALSE); - if (vid->hAudio2) - startAudioStream (vid->hAudio2, MUSIC_SOURCE, TRUE); + PlayMusic (vid->hAudio, FALSE, 1); UnlockMutex (vid->guard); clagged = 0; @@ -231,13 +229,11 @@ as_video_play_task (void *data) // increase timeout with lag-count to allow audio to catch up TimeOut = GetTimeCounter () + vid->decoder->max_frame_wait * ONE_SECOND / 1000 + clagged * ONE_SECOND / 100; - + ret = VideoDecoder_Decode (vid->decoder); } if (vid->hAudio) - stopAudioStream (vid->hAudio, SPEECH_SOURCE); - if (vid->hAudio2) - stopAudioStream (vid->hAudio2, MUSIC_SOURCE); + StopMusic (); vid->playing = false; FinishTask (task); @@ -261,10 +257,7 @@ video_play_task (void *data) LockMutex (vid->guard); if (vid->hAudio) - startAudioStream (vid->hAudio, SPEECH_SOURCE, FALSE); - - if (vid->hAudio2) - startAudioStream (vid->hAudio2, MUSIC_SOURCE, TRUE); + PlayMusic (vid->hAudio, (vid->loop_frame != VID_NO_LOOP), 1); UnlockMutex (vid->guard); @@ -293,13 +286,14 @@ video_play_task (void *data) UnlockMutex (GraphicsLock); FlushGraphics (); // needed to prevent half-frame updates + if (vid->cur_frame == vid->loop_frame) + VideoDecoder_SeekFrame (vid->decoder, vid->loop_to); + ret = VideoDecoder_Decode (vid->decoder); } vid->playing = false; if (vid->hAudio) - stopAudioStream (vid->hAudio, SPEECH_SOURCE); - if (vid->hAudio2) - stopAudioStream (vid->hAudio2, MUSIC_SOURCE); + StopMusic (); FinishTask (task); @@ -350,8 +344,11 @@ TFB_PlayVideo (VIDEO_REF VidRef, uint32 x, uint32 y) vid->cur_frame = -1; vid->want_frame = -1; - if (vid->hAudio == 0) + if (!vid->hAudio) + { vid->hAudio = LoadMusicFile (vid->decoder->filename); + vid->own_audio = true; + } StopMusic (); @@ -412,15 +409,12 @@ TFB_StopVideo (VIDEO_REF VidRef) if (vid->hAudio) { - if (vid->hAudio) { - stopAudioStream (vid->hAudio, SPEECH_SOURCE); + StopMusic (); + if (vid->own_audio) + { DestroyMusic (vid->hAudio); vid->hAudio = 0; - } - if (vid->hAudio2) { - stopAudioStream (vid->hAudio2, MUSIC_SOURCE); - DestroyMusic (vid->hAudio2); - vid->hAudio2 = 0; + vid->own_audio = false; } } if (vid->frame) diff --git a/sc2/src/sc2code/libs/vidlib.h b/sc2/src/sc2code/libs/vidlib.h index 11b9806b1..1ee68b9d7 100644 --- a/sc2/src/sc2code/libs/vidlib.h +++ b/sc2/src/sc2code/libs/vidlib.h @@ -19,7 +19,8 @@ #ifndef _VIDLIB_H #define _VIDLIB_H -#include "compiler.h" +#include "libs/compiler.h" +#include "libs/sndlib.h" typedef enum { @@ -35,8 +36,10 @@ extern void UninitVideoPlayer (void); extern VIDEO_REF LoadVideoFile (const char *pStr); extern BOOLEAN DestroyVideo (VIDEO_REF VideoRef); -extern VIDEO_TYPE VidPlay (VIDEO_REF VidRef, const char *loopname, - BOOLEAN uninit); +extern VIDEO_TYPE VidPlay (VIDEO_REF VidRef); +extern VIDEO_TYPE VidPlayEx (VIDEO_REF VidRef, MUSIC_REF AudRef, + MUSIC_REF SpeechRef, DWORD LoopFrame); +#define VID_NO_LOOP (0U-1) extern void VidStop (void); extern VIDEO_REF VidPlaying (void); extern void VidDoInput (void); diff --git a/sc2/src/sc2code/setupmenu.c b/sc2/src/sc2code/setupmenu.c index e42671489..8ead9625e 100644 --- a/sc2/src/sc2code/setupmenu.c +++ b/sc2/src/sc2code/setupmenu.c @@ -29,6 +29,7 @@ #include "libs/strlib.h" #include "libs/reslib.h" #include "libs/inplib.h" +#include "libs/vidlib.h" #include "libs/sound/sound.h" #include "libs/resource/stringbank.h" #include "libs/log.h"