From d57234e668172ea3be748fb1354a6c47e98e806d Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 25 Jun 2017 11:24:34 +0000 Subject: [PATCH] Replace sound_func function pointer parameter and associate functions for hardcoded ANMs with equivalent animsounds arrays. git-svn-id: https://svn.eduke32.com/eduke32@6285 1a8010ca-5511-0410-912e-c29ae57300e0 --- Android.mk | 1 - GNUmakefile | 1 - .../Apple/EDuke32.xcodeproj/project.pbxproj | 8 - platform/Windows/eduke32.vcxproj | 2 - platform/Windows/eduke32.vcxproj.filters | 6 - platform/Windows/msvc.mak | 1 - source/duke3d/Dependencies.mak | 3 +- source/duke3d/src/anim.cpp | 140 +++++++++++-- source/duke3d/src/anim.h | 1 - source/duke3d/src/animsounds.cpp | 197 ------------------ source/duke3d/src/animsounds.h | 33 --- 11 files changed, 122 insertions(+), 271 deletions(-) delete mode 100644 source/duke3d/src/animsounds.cpp delete mode 100644 source/duke3d/src/animsounds.h diff --git a/Android.mk b/Android.mk index 8c6de458f..a4885dc8b 100644 --- a/Android.mk +++ b/Android.mk @@ -98,7 +98,6 @@ GAME_SRC = \ source/duke3d/src/game.cpp \ source/duke3d/src/actors.cpp \ source/duke3d/src/anim.cpp \ - source/duke3d/src/animsounds.cpp \ source/duke3d/src/common.cpp \ source/duke3d/src/config.cpp \ source/duke3d/src/demo.cpp \ diff --git a/GNUmakefile b/GNUmakefile index bbcd59237..b06e946f3 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -451,7 +451,6 @@ DUKE3D_GAME_OBJS = \ premap.cpp \ sector.cpp \ anim.cpp \ - animsounds.cpp \ common.cpp \ config.cpp \ demo.cpp \ diff --git a/platform/Apple/EDuke32.xcodeproj/project.pbxproj b/platform/Apple/EDuke32.xcodeproj/project.pbxproj index fd9101cf2..3cd5d53a6 100644 --- a/platform/Apple/EDuke32.xcodeproj/project.pbxproj +++ b/platform/Apple/EDuke32.xcodeproj/project.pbxproj @@ -395,8 +395,6 @@ 2038AE9A1A8F12590093B7B2 /* md4.h in Headers */ = {isa = PBXBuildFile; fileRef = 2038AE981A8F12590093B7B2 /* md4.h */; }; 2038AE9C1A8F126C0093B7B2 /* md4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2038AE9B1A8F126C0093B7B2 /* md4.cpp */; }; 2038AE9D1A8F126C0093B7B2 /* md4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2038AE9B1A8F126C0093B7B2 /* md4.cpp */; }; - 2038AEA01A8F12B60093B7B2 /* animsounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2038AE9E1A8F12B60093B7B2 /* animsounds.cpp */; }; - 2038AEA11A8F12B60093B7B2 /* animsounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2038AE9E1A8F12B60093B7B2 /* animsounds.cpp */; }; 2038AEA31A8F137E0093B7B2 /* DUKE.RTS in Resources */ = {isa = PBXBuildFile; fileRef = 2038AEA21A8F137E0093B7B2 /* DUKE.RTS */; }; 2044C9841E089F2500A8C543 /* palette.h in Headers */ = {isa = PBXBuildFile; fileRef = 2044C9831E089F2500A8C543 /* palette.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2044C9851E089F2500A8C543 /* palette.h in Headers */ = {isa = PBXBuildFile; fileRef = 2044C9831E089F2500A8C543 /* palette.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -795,8 +793,6 @@ 2038AE951A8F122D0093B7B2 /* libdivide.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = libdivide.h; path = ../../source/build/include/libdivide.h; sourceTree = SOURCE_ROOT; }; 2038AE981A8F12590093B7B2 /* md4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = md4.h; path = ../../source/build/include/md4.h; sourceTree = SOURCE_ROOT; }; 2038AE9B1A8F126C0093B7B2 /* md4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.c; name = md4.cpp; path = ../../source/build/src/md4.cpp; sourceTree = SOURCE_ROOT; }; - 2038AE9E1A8F12B60093B7B2 /* animsounds.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.c; name = animsounds.cpp; path = ../../source/duke3d/src/animsounds.cpp; sourceTree = SOURCE_ROOT; }; - 2038AE9F1A8F12B60093B7B2 /* animsounds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = animsounds.h; path = ../../source/duke3d/src/animsounds.h; sourceTree = SOURCE_ROOT; }; 2038AEA21A8F137E0093B7B2 /* DUKE.RTS */ = {isa = PBXFileReference; lastKnownFileType = file; name = DUKE.RTS; path = ../../../DUKE.RTS; sourceTree = SOURCE_ROOT; }; 2044C9831E089F2500A8C543 /* palette.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = palette.h; path = ../../source/build/include/palette.h; sourceTree = SOURCE_ROOT; }; 2044C9891E08A66B00A8C543 /* palette.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.c; name = palette.cpp; path = ../../source/build/src/palette.cpp; sourceTree = SOURCE_ROOT; }; @@ -1085,8 +1081,6 @@ 0008E99F19F1AD9B0091588D /* actors.h */, 0008E9A019F1AD9B0091588D /* anim.cpp */, 0008E9A119F1AD9B0091588D /* anim.h */, - 2038AE9E1A8F12B60093B7B2 /* animsounds.cpp */, - 2038AE9F1A8F12B60093B7B2 /* animsounds.h */, 20F712531C6C1A07006B68D0 /* cheats.cpp */, 20F712541C6C1A07006B68D0 /* cheats.h */, 20E16CDF1C7022C300EE8446 /* cmdline.cpp */, @@ -1954,7 +1948,6 @@ 0008E9EB19F1AD9B0091588D /* gamedef.cpp in Sources */, 20F7124D1C6C19E5006B68D0 /* screentext.cpp in Sources */, 0008EA0219F1AD9B0091588D /* soundsdyn.cpp in Sources */, - 2038AEA01A8F12B60093B7B2 /* animsounds.cpp in Sources */, 0008E9EF19F1AD9B0091588D /* gamevars.cpp in Sources */, 0008E9EC19F1AD9B0091588D /* gameexec.cpp in Sources */, 20F712511C6C19F4006B68D0 /* sbar.cpp in Sources */, @@ -2129,7 +2122,6 @@ 000C489D19F35601006E6B52 /* demo.cpp in Sources */, 20F712561C6C1A07006B68D0 /* cheats.cpp in Sources */, 000C48A719F35601006E6B52 /* menus.cpp in Sources */, - 2038AEA11A8F12B60093B7B2 /* animsounds.cpp in Sources */, 000C48A919F35601006E6B52 /* net.cpp in Sources */, 000C48A819F35601006E6B52 /* namesdyn.cpp in Sources */, 000C48B219F35601006E6B52 /* sector.cpp in Sources */, diff --git a/platform/Windows/eduke32.vcxproj b/platform/Windows/eduke32.vcxproj index 118cfecda..c7062c0e9 100644 --- a/platform/Windows/eduke32.vcxproj +++ b/platform/Windows/eduke32.vcxproj @@ -177,7 +177,6 @@ - @@ -319,7 +318,6 @@ - diff --git a/platform/Windows/eduke32.vcxproj.filters b/platform/Windows/eduke32.vcxproj.filters index c6ceca690..68b94214f 100644 --- a/platform/Windows/eduke32.vcxproj.filters +++ b/platform/Windows/eduke32.vcxproj.filters @@ -438,9 +438,6 @@ build\headers - - eduke32\headers - touchcontrols\headers @@ -854,9 +851,6 @@ build\source - - eduke32\source - touchcontrols\source diff --git a/platform/Windows/msvc.mak b/platform/Windows/msvc.mak index f15660736..b52eaabd2 100644 --- a/platform/Windows/msvc.mak +++ b/platform/Windows/msvc.mak @@ -242,7 +242,6 @@ MACT_OBJS=$(MACT_OBJ)\file_lib.$o \ DUKE3D_OBJS=$(DUKE3D_OBJ)\game.$o \ $(DUKE3D_OBJ)\actors.$o \ $(DUKE3D_OBJ)\anim.$o \ - $(DUKE3D_OBJ)\animsounds.$o \ $(DUKE3D_OBJ)\cheats.$o \ $(DUKE3D_OBJ)\sbar.$o \ $(DUKE3D_OBJ)\screentext.$o \ diff --git a/source/duke3d/Dependencies.mak b/source/duke3d/Dependencies.mak index ba9350a16..404c6c345 100644 --- a/source/duke3d/Dependencies.mak +++ b/source/duke3d/Dependencies.mak @@ -38,8 +38,7 @@ game_defs_dep=$(DUKE3D_SRC)/lunatic/_defs_game.lua $(DUKE3D_OBJ)/game.$o: $(DUKE3D_SRC)/game.cpp $(game_defs_dep) $(MACT_INC)/scriplib.h $(duke3d_h) $(DUKE3D_SRC)/input.h $(DUKE3D_SRC)/osdfuncs.h $(DUKE3D_SRC)/osdcmds.h $(DUKE3D_SRC)/grpscan.h $(DUKE3D_SRC)/demo.h $(ENGINE_INC)/hightile.h $(DUKE3D_OBJ)/actors.$o: $(DUKE3D_SRC)/actors.cpp $(duke3d_h) -$(DUKE3D_OBJ)/anim.$o: $(DUKE3D_SRC)/anim.cpp $(duke3d_h) $(DUKE3D_SRC)/input.h $(MACT_INC)/animlib.h $(ENGINE_INC)/animvpx.h $(DUKE3D_SRC)/animsounds.h -$(DUKE3D_OBJ)/animsounds.$o: $(DUKE3D_SRC)/animsounds.cpp $(DUKE3D_SRC)/animsounds.h +$(DUKE3D_OBJ)/anim.$o: $(DUKE3D_SRC)/anim.cpp $(duke3d_h) $(DUKE3D_SRC)/input.h $(MACT_INC)/animlib.h $(ENGINE_INC)/animvpx.h $(DUKE3D_OBJ)/cheats.$o: $(DUKE3D_SRC)/cheats.cpp $(DUKE3D_SRC)/cheats.h $(DUKE3D_OBJ)/cmdline.$o: $(DUKE3D_SRC)/cmdline.cpp $(DUKE3D_SRC)/cmdline.h $(DUKE3D_OBJ)/demo.$o: $(DUKE3D_SRC)/demo.cpp $(duke3d_h) $(DUKE3D_SRC)/input.h diff --git a/source/duke3d/src/anim.cpp b/source/duke3d/src/anim.cpp index 7ffb9a77d..7b6dd48e4 100644 --- a/source/duke3d/src/anim.cpp +++ b/source/duke3d/src/anim.cpp @@ -34,8 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # include "animvpx.h" #endif -#include "animsounds.h" - // animsound_t.sound EDUKE32_STATIC_ASSERT(INT16_MAX >= MAXSOUNDS); @@ -75,39 +73,146 @@ dukeanim_t * Anim_Create(char const * fn) return anim; } +#ifdef DYNSOUNDREMAP_ENABLE +static int32_t const StopAllSounds = -1; +#else +# define StopAllSounds -1 +#endif + void Anim_Init(void) { hash_init(&h_dukeanim); + + struct defaultanmsound { +#ifdef DYNSOUNDREMAP_ENABLE + int32_t const & sound; +#else + int16_t sound; +#endif + uint8_t frame; + }; + + static defaultanmsound const cineov2[] = + { + { WIND_AMBIENCE, 1 }, + { ENDSEQVOL2SND1, 26 }, + { ENDSEQVOL2SND2, 36 }, + { THUD, 54 }, + { ENDSEQVOL2SND3, 62 }, + { ENDSEQVOL2SND4, 75 }, + { ENDSEQVOL2SND5, 81 }, + { ENDSEQVOL2SND6, 115 }, + { ENDSEQVOL2SND7, 124 }, + }; + + static defaultanmsound const cineov3[] = + { + { WIND_REPEAT, 1 }, + { DUKE_GRUNT, 98 }, + { THUD, 82+20 }, + { SQUISHED, 82+20 }, + { ENDSEQVOL3SND3, 104+20 }, + { ENDSEQVOL3SND2, 114+20 }, + { PIPEBOMB_EXPLODE, 158 }, + }; + + static defaultanmsound const logo[] = + { + { FLY_BY, 1 }, + { PIPEBOMB_EXPLODE, 19 }, + }; + + static defaultanmsound const vol42a[] = + { + { INTRO4_B, 1 }, + { SHORT_CIRCUIT, 12 }, + { INTRO4_5, 18 }, + { SHORT_CIRCUIT, 34 }, + }; + + static defaultanmsound const vol41a[] = + { + { INTRO4_1, 1 }, + { INTRO4_3, 7 }, + { INTRO4_2, 12 }, + { INTRO4_4, 26 }, + }; + + static defaultanmsound const vol43a[] = + { + { INTRO4_6, 10 }, + }; + + static defaultanmsound const vol4e1[] = + { + { DUKE_UNDERWATER, 3 }, + { VOL4ENDSND1, 35 }, + }; + + static defaultanmsound const vol4e2[] = + { + { DUKE_UNDERWATER, 11 }, + { VOL4ENDSND1, 20 }, + { VOL4ENDSND2, 39 }, + { StopAllSounds, 50 }, + }; + + static defaultanmsound const vol4e3[] = + { + { BOSS4_DEADSPEECH, 1 }, + { VOL4ENDSND1, 40 }, + { DUKE_UNDERWATER, 40 }, + { BIGBANG, 50 }, + }; + + struct defaultanm { char const *fn; - void (*sound_func)(int32_t); + defaultanmsound const *sounds; + uint8_t numsounds; uint8_t fdelay; }; +#define anmsnd(x) (x), ARRAY_SIZE(x) static defaultanm const anms[] = { - { "logo.anm", logoanimsounds, 9 }, - { "3dr.anm", NULL, 10 }, + { "logo.anm", anmsnd(logo), 9 }, + { "3dr.anm", NULL, 0, 10 }, #ifndef EDUKE32_STANDALONE - { "vol4e1.anm", endanimvol41, 10 }, - { "vol4e2.anm", endanimvol42, 14 }, - { "vol4e3.anm", endanimvol43, 10 }, - { "vol41a.anm", first4animsounds, 14 }, - { "vol42a.anm", intro4animsounds, 18 }, - { "vol43a.anm", intro42animsounds, 10 }, - { "duketeam.anm", NULL, 10 }, - { "radlogo.anm", NULL, 10 }, - { "cineov2.anm", endanimsounds, 18 }, - { "cineov3.anm", endanimsounds, 10 }, + { "vol4e1.anm", anmsnd(vol4e1), 10 }, + { "vol4e2.anm", anmsnd(vol4e2), 14 }, + { "vol4e3.anm", anmsnd(vol4e3), 10 }, + { "vol41a.anm", anmsnd(vol41a), 14 }, + { "vol42a.anm", anmsnd(vol42a), 18 }, + { "vol43a.anm", anmsnd(vol43a), 10 }, + { "duketeam.anm", NULL, 0, 10 }, + { "radlogo.anm", NULL, 0, 10 }, + { "cineov2.anm", anmsnd(cineov2), 18 }, + { "cineov3.anm", anmsnd(cineov3), 10 }, #endif }; +#undef anmsnd for (defaultanm const & anm : anms) { dukeanim_t * anim = Anim_Create(anm.fn); anim->framedelay = anm.fdelay; - anim->sound_func = anm.sound_func; + + if (anm.numsounds) + { + anim->sounds = (animsound_t *)Xmalloc(anm.numsounds * sizeof(animsound_t)); + size_t const numsounds = anm.numsounds; + for (size_t i = 0; i < numsounds; ++i) + { + defaultanmsound const & src = anm.sounds[i]; + animsound_t & dst = anim->sounds[i]; + + dst.sound = src.sound; + dst.frame = src.frame; + } + anim->numsounds = numsounds; + } } } @@ -338,9 +443,6 @@ int32_t Anim_Play(const char *fn) ototalclock += anim->framedelay; - if (!anim->numsounds && anim->sound_func) - anim->sound_func(i); - while (soundidx < anim->numsounds && anim->sounds[soundidx].frame == (uint16_t)i) { int16_t sound = anim->sounds[soundidx].sound; diff --git a/source/duke3d/src/anim.h b/source/duke3d/src/anim.h index bcdd3e19e..c0045e76a 100644 --- a/source/duke3d/src/anim.h +++ b/source/duke3d/src/anim.h @@ -31,7 +31,6 @@ typedef struct { typedef struct { uint8_t* animbuf; - void (*sound_func)(int32_t); animsound_t *sounds; uint16_t numsounds; uint8_t framedelay; diff --git a/source/duke3d/src/animsounds.cpp b/source/duke3d/src/animsounds.cpp deleted file mode 100644 index e9c6677b7..000000000 --- a/source/duke3d/src/animsounds.cpp +++ /dev/null @@ -1,197 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2015 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#include "duke3d.h" -#include "animsounds.h" - -void endanimsounds(int32_t fr) -{ - switch (ud.volume_number) - { - case 0: - break; - case 1: - switch (fr) - { - case 1: - S_PlaySound(WIND_AMBIENCE); - break; - case 26: - S_PlaySound(ENDSEQVOL2SND1); - break; - case 36: - S_PlaySound(ENDSEQVOL2SND2); - break; - case 54: - S_PlaySound(THUD); - break; - case 62: - S_PlaySound(ENDSEQVOL2SND3); - break; - case 75: - S_PlaySound(ENDSEQVOL2SND4); - break; - case 81: - S_PlaySound(ENDSEQVOL2SND5); - break; - case 115: - S_PlaySound(ENDSEQVOL2SND6); - break; - case 124: - S_PlaySound(ENDSEQVOL2SND7); - break; - } - break; - case 2: - switch (fr) - { - case 1: - S_PlaySound(WIND_REPEAT); - break; - case 98: - S_PlaySound(DUKE_GRUNT); - break; - case 82+20: - S_PlaySound(THUD); - S_PlaySound(SQUISHED); - break; - case 104+20: - S_PlaySound(ENDSEQVOL3SND3); - break; - case 114+20: - S_PlaySound(ENDSEQVOL3SND2); - break; - case 158: - S_PlaySound(PIPEBOMB_EXPLODE); - break; - } - break; - } -} - -void logoanimsounds(int32_t fr) -{ - switch (fr) - { - case 1: - S_PlaySound(FLY_BY); - break; - case 19: - S_PlaySound(PIPEBOMB_EXPLODE); - break; - } -} - -void intro4animsounds(int32_t fr) -{ - switch (fr) - { - case 1: - S_PlaySound(INTRO4_B); - break; - case 12: - case 34: - S_PlaySound(SHORT_CIRCUIT); - break; - case 18: - S_PlaySound(INTRO4_5); - break; - } -} - -void first4animsounds(int32_t fr) -{ - switch (fr) - { - case 1: - S_PlaySound(INTRO4_1); - break; - case 12: - S_PlaySound(INTRO4_2); - break; - case 7: - S_PlaySound(INTRO4_3); - break; - case 26: - S_PlaySound(INTRO4_4); - break; - } -} - -void intro42animsounds(int32_t fr) -{ - switch (fr) - { - case 10: - S_PlaySound(INTRO4_6); - break; - } -} - -void endanimvol41(int32_t fr) -{ - switch (fr) - { - case 3: - S_PlaySound(DUKE_UNDERWATER); - break; - case 35: - S_PlaySound(VOL4ENDSND1); - break; - } -} - -void endanimvol42(int32_t fr) -{ - switch (fr) - { - case 11: - S_PlaySound(DUKE_UNDERWATER); - break; - case 20: - S_PlaySound(VOL4ENDSND1); - break; - case 39: - S_PlaySound(VOL4ENDSND2); - break; - case 50: - FX_StopAllSounds(); - break; - } -} - -void endanimvol43(int32_t fr) -{ - switch (fr) - { - case 1: - S_PlaySound(BOSS4_DEADSPEECH); - break; - case 40: - S_PlaySound(VOL4ENDSND1); - S_PlaySound(DUKE_UNDERWATER); - break; - case 50: - S_PlaySound(BIGBANG); - break; - } -} diff --git a/source/duke3d/src/animsounds.h b/source/duke3d/src/animsounds.h deleted file mode 100644 index 64b070887..000000000 --- a/source/duke3d/src/animsounds.h +++ /dev/null @@ -1,33 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2015 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#ifndef animsounds_h__ -#define animsounds_h__ -void endanimsounds(int32_t fr); -void logoanimsounds(int32_t fr); -void intro4animsounds(int32_t fr); -void endanimvol43(int32_t fr); -void endanimvol42(int32_t fr); -void endanimvol41(int32_t fr); -void intro42animsounds(int32_t fr); -void first4animsounds(int32_t fr); -#endif // animsounds_h__