From 7f7a5769618acc3b96379f74b5618186eeac0559 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Oct 2020 00:36:21 +0200 Subject: [PATCH] - music code. --- source/games/whaven/CMakeLists.txt | 1 + source/games/whaven/src/main.cpp | 3 +- source/games/whaven/src/music.cpp | 85 ++++++++++++++++++++++++++++++ source/games/whaven/src/wh.h | 10 ++-- wadsrc/static/engine/grpinfo.txt | 4 +- 5 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 source/games/whaven/src/music.cpp diff --git a/source/games/whaven/CMakeLists.txt b/source/games/whaven/CMakeLists.txt index af6bf148a..bb8c169b4 100644 --- a/source/games/whaven/CMakeLists.txt +++ b/source/games/whaven/CMakeLists.txt @@ -40,6 +40,7 @@ set( PCH_SOURCES src/whtag.cpp src/wh.cpp src/main.cpp + src/music.cpp ) add_game_library2( whaven ) diff --git a/source/games/whaven/src/main.cpp b/source/games/whaven/src/main.cpp index b164d2bfa..f7a89bbf3 100644 --- a/source/games/whaven/src/main.cpp +++ b/source/games/whaven/src/main.cpp @@ -228,6 +228,7 @@ void GameInterface::app_init() } FadeInit(); + setupmidi(); //sndInit(); //initpaletteshifts(); InitOriginalEpisodes(); @@ -243,8 +244,6 @@ void GameInterface::Startup() */ } - - ::GameInterface* CreateInterface() { return new GameInterface; diff --git a/source/games/whaven/src/music.cpp b/source/games/whaven/src/music.cpp new file mode 100644 index 000000000..55ff9a712 --- /dev/null +++ b/source/games/whaven/src/music.cpp @@ -0,0 +1,85 @@ +#include "ns.h" +#include "wh.h" +#include "raze_music.h" +#include "mapinfo.h" + +BEGIN_WH_NS + + + +enum +{ + NUMLEVELS = 17, + SONGSPERLEVEL = 4, + + BASE_SONG = 0, + songelements = 3, + totallevels = 6, + arrangements = 3, + +}; +static int songsperlevel; +static int oldsong; + +static bool playthesong(int which, bool looped) +{ + char buffer[40]; + mysnprintf(buffer, 40, "%s/%04", isWh2()? "F_SONGS" : "SONGS", which); + return Mus_Play(currentLevel->labelName, buffer, looped); +} + +static bool loadlevelsongs(int which) +{ + oldsong = which; + return true; +} + +void startsong(int which) // 0, 1, 2 or 3 +{ + int index = (oldsong * SONGSPERLEVEL) + which; + bool result = playthesong(index, !attacktheme); + if (result && which < 2) attacktheme = 0; +} + +void startmusic(int level) +{ + if (!isWh2()) + { + level %= 6; + int index = (songsperlevel * level) + (songelements * 2) + BASE_SONG; + playthesong(index, true); + } + else + { + if (level < 0 || level > NUMLEVELS - 1) + level = 0; + + loadlevelsongs(level); + startsong(0); + } +} + +void SND_MenuMusic() +{ + if (isWh2()) + { + startmusic(NUMLEVELS - 1); + } + else + { + int which = (totallevels * songsperlevel) + BASE_SONG + 2; + playthesong(which, true); + } +} + + +void setupmidi() +{ + if (isWh2()) + songsperlevel = 4; + else + songsperlevel = songelements * arrangements; +} + + +END_WH_NS diff --git a/source/games/whaven/src/wh.h b/source/games/whaven/src/wh.h index dbdf8eff8..43716babd 100644 --- a/source/games/whaven/src/wh.h +++ b/source/games/whaven/src/wh.h @@ -447,13 +447,11 @@ inline void SND_StopLoop(int) inline void SND_CheckLoops() {} +void startmusic(int); +void startsong(int); +void setupmidi(); + extern int attacktheme; -inline void startsong(int) -{ -} -inline void startmusic(int) -{ -} diff --git a/wadsrc/static/engine/grpinfo.txt b/wadsrc/static/engine/grpinfo.txt index 7420e2429..bea158709 100644 --- a/wadsrc/static/engine/grpinfo.txt +++ b/wadsrc/static/engine/grpinfo.txt @@ -662,13 +662,13 @@ grpinfo grpinfo { - // The file identification info here is for joesnd which is one of two containers in the game data. + // The file identification info here is for joesnd which is one of three containers in the game data. name "Witchaven 2" flags GAMEFLAG_WITCHAVEN2 crc 0x2F673425 size 3051520 defname "witchaven2.def" - loadgrp "SONGS" + loadgrp "F_SONGS", "W_SONGS" gamefilter "Witchaven.Witchaven2" }