- hook up the savegame code in Exhumed. Superficially it looks like it works but it will require a lot more testing.

- fixed per-frame sound system update in Exhumed.

Sound is still quite broken and will require more work.
This commit is contained in:
Christoph Oelckers 2019-12-27 17:07:09 +01:00
parent 8e5b9111bd
commit 7e758a5e48
4 changed files with 55 additions and 32 deletions

View file

@ -1680,15 +1680,6 @@ void ExitGame()
fclose(vcrfp); fclose(vcrfp);
} }
FadeSong();
if (CDplaying()) {
fadecdaudio();
}
StopAllSounds();
StopLocalSound();
mysaveconfig();
if (bSerialPlay) if (bSerialPlay)
{ {
if (nNetPlayerCount != 0) { if (nNetPlayerCount != 0) {
@ -1704,7 +1695,7 @@ void ExitGame()
} }
ShutDown(); ShutDown();
exit(0); throw ExitEvent(0);
} }
static int32_t nonsharedtimer; static int32_t nonsharedtimer;
@ -2026,6 +2017,8 @@ MENU:
case 3: case 3:
forcelevel = 0; forcelevel = 0;
goto STARTGAME2; goto STARTGAME2;
case 6:
goto GAMELOOP;
case 9: case 9:
vcrfp = fopen("demo.vcr", "rb"); vcrfp = fopen("demo.vcr", "rb");
if (vcrfp == NULL) { if (vcrfp == NULL) {
@ -2192,6 +2185,7 @@ LOOP3:
//int edi = totalclock; //int edi = totalclock;
tclocks2 = totalclock; tclocks2 = totalclock;
// Game Loop // Game Loop
GAMELOOP:
while (1) while (1)
{ {
if (levelnew >= 0) if (levelnew >= 0)
@ -2408,6 +2402,8 @@ LOOP3:
goto STARTGAME2; goto STARTGAME2;
} }
case 6:
goto GAMELOOP;
} }
totalclock = ototalclock = tclocks; totalclock = ototalclock = tclocks;
@ -2615,9 +2611,11 @@ void DoTitle()
var_18 += theArray[0]; var_18 += theArray[0];
inputState.ClearAllKeyStatus();
while (LocalSoundPlaying()) while (LocalSoundPlaying())
{ {
HandleAsync(); HandleAsync();
if (inputState.CheckAllInput()) break;
menu_DoPlasma(); menu_DoPlasma();
overwritesprite(160, 100, nTile, 0, 3, kPalNormal); overwritesprite(160, 100, nTile, 0, 3, kPalNormal);
@ -2636,7 +2634,7 @@ void DoTitle()
{ {
nCount++; nCount++;
assert(nCount <= 12); if (nCount > 12) break;
var_18 = nStartTime + theArray[nCount]; var_18 = nStartTime + theArray[nCount];
var_4 = var_4 == 0; var_4 = var_4 == 0;

View file

@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "init.h" #include "init.h"
#include "music/z_music.h"
//#include <fcntl.h> //#include <fcntl.h>
//#include <sys/stat.h> //#include <sys/stat.h>
//#include <io.h> //#include <io.h>
@ -30,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS BEGIN_PS_NS
extern int MenuExitCondition;
void SaveTextureState(); void SaveTextureState();
void LoadTextureState(); void LoadTextureState();
@ -113,7 +115,7 @@ bool GameInterface::LoadGame(FSaveGameNode* sv)
fr.Read(show2dwall, sizeof(show2dwall)); fr.Read(show2dwall, sizeof(show2dwall));
fr.Read(show2dsprite, sizeof(show2dsprite)); fr.Read(show2dsprite, sizeof(show2dsprite));
fr.Read(show2dsector, sizeof(show2dsector)); fr.Read(show2dsector, sizeof(show2dsector));
fr.Close();
} }
for (auto sgh : sghelpers) sgh->Load(); for (auto sgh : sghelpers) sgh->Load();
@ -133,7 +135,8 @@ bool GameInterface::LoadGame(FSaveGameNode* sv)
parallaxtype = 2; parallaxtype = 2;
g_visibility = 2048; g_visibility = 2048;
ototalclock = totalclock; ototalclock = totalclock;
MenuExitCondition = 6;
Mus_ResumeSaved();
return 1; // CHECKME return 1; // CHECKME
} }

View file

@ -555,45 +555,67 @@ void UpdateSounds()
int nLocalSectFlags = SectFlag[nPlayerViewSect[nLocalPlayer]]; int nLocalSectFlags = SectFlag[nPlayerViewSect[nLocalPlayer]];
int x, y; vec3_t pos;
short ang; short ang;
if (nSnakeCam > -1) if (nSnakeCam > -1)
{ {
Snake *pSnake = &SnakeList[nSnakeCam]; Snake *pSnake = &SnakeList[nSnakeCam];
spritetype *pSnakeSprite = &sprite[pSnake->nSprites[0]]; spritetype *pSnakeSprite = &sprite[pSnake->nSprites[0]];
x = pSnakeSprite->x; pos = pSnakeSprite->pos;
y = pSnakeSprite->y;
ang = pSnakeSprite->ang; ang = pSnakeSprite->ang;
} }
else else
{ {
x = initx; pos = { initx, inity, initz };
y = inity;
ang = inita; ang = inita;
} }
auto fv = GetSoundPos(&pos);
SoundListener listener;
listener.angle = -(float)ang * pi::pi() / 1024; // Build uses a period of 2048.
listener.velocity.Zero();
listener.position = GetSoundPos(&pos);
listener.underwater = false;
// This should probably use a real environment instead of the pitch hacking in S_PlaySound3D.
// listenactor->waterlevel == 3;
//assert(primaryLevel->Zones.Size() > listenactor->Sector->ZoneNumber);
listener.Environment = 0;// primaryLevel->Zones[listenactor->Sector->ZoneNumber].Environment;
listener.valid = true;
soundEngine->SetListener(listener);
soundEngine->UpdateSounds((int)totalclock);
ActiveSound* pASound = sActiveSound; ActiveSound* pASound = sActiveSound;
pASound++; pASound++;
for (int i = 1; i < kMaxActiveSounds; i++, pASound++) for (int i = 1; i < kMaxActiveSounds; i++, pASound++)
{ {
if (pASound->snd_channel != nullptr) if (pASound->snd_channel != nullptr)
{ {
short nSoundSprite = pASound->snd_sprite; if (pASound->snd_channel->ChanFlags & CHANF_FORGETTABLE)
int nPitch = pASound->snd_pitch;
short nSoundSect;
if (nSoundSprite >= 0)
{ {
if (nSoundSprite == nLocalSpr) // If the channel has become invalid, remove the reference.
nSoundSect = nPlayerViewSect[nLocalPlayer]; // ChannelEnded may be called late so waiting for it is problematic.
else pASound->snd_channel = nullptr;
nSoundSect = sprite[nSoundSprite].sectnum;
} }
else else
nSoundSect = pASound->snd_sector; {
short nSoundSprite = pASound->snd_sprite;
int nPitch = pASound->snd_pitch;
short nSoundSect;
if (nSoundSprite >= 0)
{
if (nSoundSprite == nLocalSpr)
nSoundSect = nPlayerViewSect[nLocalPlayer];
else
nSoundSect = sprite[nSoundSprite].sectnum;
}
else
nSoundSect = pASound->snd_sector;
int nVolume = pASound->snd_volume; int nVolume = pASound->snd_volume;
GetSpriteSoundPitch(nSoundSect, &nVolume, &nPitch, nLocalSectFlags); GetSpriteSoundPitch(nSoundSect, &nVolume, &nPitch, nLocalSectFlags);
soundEngine->SetPitch(pASound->snd_channel, (11025 + nPitch) / 11025.f); soundEngine->SetPitch(pASound->snd_channel, (11025 + nPitch) / 11025.f);
soundEngine->SetVolume(pASound->snd_channel, nVolume / 255.f); soundEngine->SetVolume(pASound->snd_channel, nVolume / 255.f);
}
} }
} }
} }

View file

@ -354,7 +354,7 @@ static void DoTimedSound(AmbientSound* amb)
amb->curIndex += synctics; amb->curIndex += synctics;
if (amb->curIndex >= amb->maxIndex) if (amb->curIndex >= amb->maxIndex)
{ {
if (amb->sndChan == nullptr) if (amb->sndChan == nullptr || (amb->sndChan->ChanFlags & CHANF_FORGETTABLE))
{ {
// Check for special case ambient sounds. Since the sound is stopped and doesn't occupy a real channel at this time we can just swap out the sound ID before restarting it. // Check for special case ambient sounds. Since the sound is stopped and doesn't occupy a real channel at this time we can just swap out the sound ID before restarting it.
int ambid = RandomizeAmbientSpecials(amb->vocIndex); int ambid = RandomizeAmbientSpecials(amb->vocIndex);