diff --git a/sc2/src/sc2code/fmv.c b/sc2/src/sc2code/fmv.c index d4b87495b..78bfd894d 100644 --- a/sc2/src/sc2code/fmv.c +++ b/sc2/src/sc2code/fmv.c @@ -39,7 +39,6 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic) { #ifdef WANT_SHIP_SPINS char vnbuf[32]; - char snbuf[32]; BYTE clut_buf[1]; RECT old_r, r; @@ -57,25 +56,13 @@ DoShipSpin (COUNT index, MUSIC_REF hMusic) FreeHyperData (); - sprintf (vnbuf, "slides/spins/ship%02u.duk", (unsigned)index); - sprintf (snbuf, "slides/spins/ship%02u.aif", (unsigned)index); - if (optWhichIntro == OPT_PC || !DoFMVEx (vnbuf, "slides/spins/spin.aif", snbuf, SHIP_SPIN_LOOP_FRAME)) - { - STRING f; + // TODO: It would be nice to have better resource names for these. + sprintf (vnbuf, "slides.spins.%02u", (unsigned)index); + ShowPresentation (vnbuf); - sprintf (vnbuf, "slides/spins/ship%02u.txt", (unsigned)index); - f = CaptureStringTable (LoadStringTableFile (contentDir, vnbuf)); - if (f) - { - ShowPresentation (f); - /* BUG: Leak? This is also in ShowPresentationFile */ - /* DestroyStringTable (ReleaseStringTable (f)); */ - - clut_buf[0] = FadeAllToBlack; - SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); - FlushColorXForms (); - } - } + clut_buf[0] = FadeAllToBlack; + SleepThreadUntil (XFormColorMap ((COLORMAPPTR)clut_buf, ONE_SECOND / 4)); + FlushColorXForms (); GetContextClipRect (&old_r); r.corner.x = r.corner.y = 0; @@ -156,11 +143,7 @@ Introduction (void) { BYTE xform_buf[1]; - /* by default we do 3DO cinematics; or PC slides when 3DO files are - * not present */ - if (optWhichIntro == OPT_PC || !DoFMV ("slides/intro/intro.duk")) - ShowPresentation ( CaptureStringTable ( - LoadStringTable (INTROPRES_STRTAB))); + ShowPresentation (INTROPRES_STRTAB); xform_buf[0] = FadeAllToBlack; SleepThreadUntil (XFormColorMap ((COLORMAPPTR)xform_buf, ONE_SECOND / 2)); @@ -176,9 +159,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")) - ShowPresentation ( CaptureStringTable ( - LoadStringTable (FINALPRES_STRTAB))); + ShowPresentation (FINALPRES_STRTAB); xform_buf[0] = FadeAllToBlack; XFormColorMap ((COLORMAPPTR)xform_buf, 0); diff --git a/sc2/src/sc2code/fmv.h b/sc2/src/sc2code/fmv.h index 9e1393383..d9191f98e 100644 --- a/sc2/src/sc2code/fmv.h +++ b/sc2/src/sc2code/fmv.h @@ -33,7 +33,7 @@ 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 ShowPresentation (RESOURCE presentation); extern BOOLEAN ShowPresentationFile (const char *name); #endif /* _FMV_H */ diff --git a/sc2/src/sc2code/intro.c b/sc2/src/sc2code/intro.c index ff9e26785..8dad072d2 100644 --- a/sc2/src/sc2code/intro.c +++ b/sc2/src/sc2code/intro.c @@ -31,8 +31,12 @@ #include "libs/inplib.h" #include "libs/log.h" +// TODO: Fold DoFMV and friends into libs/video; then we can get rid of this. +#include "libs/video/vidintrn.h" + #include +static BOOLEAN ShowSlidePresentation (STRING PresStr); typedef struct { @@ -85,7 +89,6 @@ typedef struct { } SPINANIM_INPUT_STATE; static BOOLEAN DoPresentation (void *pIS); -static BOOLEAN DoSpinAnim (void *pIS); BOOLEAN DoFMVEx (const char *name, const char *audname, const char *speechname, @@ -313,7 +316,7 @@ Present_DrawMovieFrame (PRESENTATION_INPUT_STATE* pPIS) BOOLEAN ShowPresentationFile (const char *name) { - return ShowPresentation (CaptureStringTable ( + return ShowSlidePresentation (CaptureStringTable ( LoadStringTableFile (contentDir, name))); } @@ -788,8 +791,8 @@ DoPresentation (void *pIS) return FALSE; } -BOOLEAN -ShowPresentation (STRING PresStr) +static BOOLEAN +ShowSlidePresentation (STRING PresStr) { CONTEXT OldContext; FONT OldFont; @@ -840,3 +843,27 @@ ShowPresentation (STRING PresStr) return TRUE; } + +BOOLEAN +ShowPresentation (RESOURCE res) +{ + const char *resType = res_GetResourceType (res); + if (!resType) + { + return FALSE; + } + if (!strcmp (resType, "STRTAB")) + { + return ShowSlidePresentation (CaptureStringTable ( + LoadStringTable (res))); + } + else if (!strcmp (resType, "3DOVID")) + { + LEGACY_VIDEO vid = LoadLegacyVideoInstance (res); + return DoFMVEx (vid->video, vid->audio, vid->speech, vid->loop); + DestroyLegacyVideo (vid); + } + + log_add (log_Warning, "Tried to present '%s', of non-presentable type '%s'", res, resType); + return FALSE; +} diff --git a/sc2/src/sc2code/libs/resource/resinit.c b/sc2/src/sc2code/libs/resource/resinit.c index 2658750ad..ef78553f0 100644 --- a/sc2/src/sc2code/libs/resource/resinit.c +++ b/sc2/src/sc2code/libs/resource/resinit.c @@ -24,6 +24,7 @@ #include "libs/log.h" #include "libs/gfxlib.h" #include "libs/sndlib.h" +#include "libs/vidlib.h" #include "coderes.h" #include "propfile.h" #include @@ -182,6 +183,7 @@ InitResourceSystem (void) InstallGraphicResTypes (); InstallStringTableResType (); InstallAudioResTypes (); + InstallVideoResType (); InstallCodeResType (); return ndx; diff --git a/sc2/src/sc2code/libs/video/Makeinfo b/sc2/src/sc2code/libs/video/Makeinfo index 76c206752..0c4151ede 100644 --- a/sc2/src/sc2code/libs/video/Makeinfo +++ b/sc2/src/sc2code/libs/video/Makeinfo @@ -1 +1 @@ -uqm_CFILES="vfileins.c video.c videodec.c vidplayer.c dukvid.c" +uqm_CFILES="vfileins.c vresins.c video.c videodec.c vidplayer.c dukvid.c" diff --git a/sc2/src/sc2code/libs/video/vidintrn.h b/sc2/src/sc2code/libs/video/vidintrn.h new file mode 100644 index 000000000..047f21bd0 --- /dev/null +++ b/sc2/src/sc2code/libs/video/vidintrn.h @@ -0,0 +1,29 @@ +// Copyright 2008 Michael Martin + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef VIDINTERN_H_ +#define VIDINTERN_H_ + +#include "libs/vidlib.h" + +typedef struct legacy_video_desc { + char *video, *audio, *speech; + DWORD loop; +} LEGACY_VIDEO_DESC; + +#endif diff --git a/sc2/src/sc2code/libs/video/vresins.c b/sc2/src/sc2code/libs/video/vresins.c new file mode 100644 index 000000000..192f5a674 --- /dev/null +++ b/sc2/src/sc2code/libs/video/vresins.c @@ -0,0 +1,184 @@ +// Copyright 2008 Michael Martin + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include "vidintrn.h" +#include "libs/log.h" + +static BOOLEAN +FreeLegacyVideoData (void *data) +{ + LEGACY_VIDEO pLV; + if (!data) + return FALSE; + + pLV = (LEGACY_VIDEO) data; + if (pLV->video) + HFree (pLV->video); + if (pLV->audio) + HFree (pLV->audio); + if (pLV->speech) + HFree (pLV->video); + HFree (pLV); + + return TRUE; +} + +static void +GetLegacyVideoData (const char *path, RESOURCE_DATA *resdata) +{ + void *result = NULL; + char paths[1024], *audio_path, *speech_path, *loop_str; + DWORD LoopFrame = VID_NO_LOOP; + + /* Parse out the video components. */ + strncpy (paths, path, 1023); + paths[1023] = '\0'; + audio_path = strchr (paths, ':'); + if (audio_path == NULL) + { + speech_path = NULL; + loop_str = NULL; + } + else + { + *audio_path = '\0'; + audio_path++; + + speech_path = strchr (audio_path, ':'); + if (speech_path == NULL) + { + loop_str = NULL; + } + else + { + *speech_path = '\0'; + speech_path++; + + loop_str = strchr (speech_path, ':'); + if (loop_str != NULL) { + *loop_str = '\0'; + loop_str++; + } + } + } + + log_add (log_Info, "\t'%s' -- video", paths); + if (audio_path) + log_add (log_Info, "\t'%s' -- audio", audio_path); + else + log_add (log_Info, "\tNo associated audio"); + if (speech_path) + log_add (log_Info, "\t'%s' -- speech path", speech_path); + else + log_add (log_Info, "\tNo associated speech"); + if (loop_str) + { + char *end; + LoopFrame = (DWORD) strtol (loop_str, &end, 10); + // We allow whitespace at the end, but nothing printable. + if (*end > 32) { + log_add (log_Warning, "Warning: Unparsable loop frame '%s'. Disabling loop.", loop_str); + LoopFrame = VID_NO_LOOP; + } + log_add (log_Info, "\tLoop frame is %d", LoopFrame); + } + else + log_add (log_Info, "\tNo specified loop frame"); + + result = HMalloc (sizeof (LEGACY_VIDEO_DESC)); + if (result) + { + LEGACY_VIDEO pLV = (LEGACY_VIDEO) result; + int len; + pLV->video = NULL; + pLV->audio = NULL; + pLV->speech = NULL; + pLV->loop = LoopFrame; + + len = strlen(paths)+1; + pLV->video = (char *)HMalloc (len); + if (!pLV->video) + { + log_add (log_Warning, "Warning: Couldn't allocate space for '%s'", paths); + goto err; + } + strncpy(pLV->video, paths, len); + + if (audio_path) + { + len = strlen(audio_path)+1; + pLV->audio = (char *)HMalloc (len); + if (!pLV->audio) + { + log_add (log_Warning, "Warning: Couldn't allocate space for '%s'", audio_path); + goto err; + } + strncpy(pLV->audio, audio_path, len); + } + + if (speech_path) + { + len = strlen(speech_path)+1; + pLV->speech = (char *)HMalloc (len); + if (!pLV->speech) + { + log_add (log_Warning, "Warning: Couldn't allocate space for '%s'", speech_path); + goto err; + } + strncpy(pLV->speech, speech_path, len); + } + + resdata->ptr = result; + } + return; +err: + if (result) + FreeLegacyVideoData ((LEGACY_VIDEO)result); + + resdata->ptr = NULL; + return; +} + +BOOLEAN +InstallVideoResType (void) +{ + InstallResTypeVectors ("3DOVID", GetLegacyVideoData, FreeLegacyVideoData); + return TRUE; +} + +LEGACY_VIDEO +LoadLegacyVideoInstance (RESOURCE res) +{ + void *data; + + data = res_GetResource (res); + if (data) + { + res_DetachResource (res); + } + + return (LEGACY_VIDEO)data; +} + +BOOLEAN +DestroyLegacyVideo (LEGACY_VIDEO vid) +{ + return FreeLegacyVideoData (vid); +} diff --git a/sc2/src/sc2code/libs/vidlib.h b/sc2/src/sc2code/libs/vidlib.h index 35be544d8..250e32662 100644 --- a/sc2/src/sc2code/libs/vidlib.h +++ b/sc2/src/sc2code/libs/vidlib.h @@ -21,6 +21,7 @@ #include "libs/compiler.h" #include "libs/sndlib.h" +#include "libs/reslib.h" typedef enum { @@ -29,9 +30,10 @@ typedef enum SOFTWARE_FMV } VIDEO_TYPE; -struct tfb_videoclip; - typedef struct tfb_videoclip *VIDEO_REF; +typedef struct legacy_video_desc *LEGACY_VIDEO; + +extern BOOLEAN InstallVideoResType (void); extern BOOLEAN InitVideoPlayer (BOOLEAN UseCDROM); extern void UninitVideoPlayer (void); @@ -46,4 +48,7 @@ extern void VidStop (void); extern VIDEO_REF VidPlaying (void); extern void VidDoInput (void); +LEGACY_VIDEO LoadLegacyVideoInstance (RESOURCE res); +BOOLEAN DestroyLegacyVideo (LEGACY_VIDEO vid); + #endif /* _VIDLIB_H */