-Blood: merge redundant gFrameCount and gLevelTime variables, reset the timers as the first thing when loading a level.

They need to be reset when level data gets set because the current value is used as base.
It was most easily observed at the start of the first level where the grave only would open after a lengthy delay - which was the play time of the last level being played.
This commit is contained in:
Christoph Oelckers 2020-09-02 07:47:26 +02:00
parent b21f49a1e1
commit 4feae913cd
10 changed files with 11 additions and 39 deletions

View file

@ -69,7 +69,6 @@ BEGIN_BLD_NS
void InitCheats(); void InitCheats();
bool bNoDemo = false; bool bNoDemo = false;
bool gameRestart;
int gNetPlayers; int gNetPlayers;
int gQuitRequest; int gQuitRequest;
int gChokeCounter = 0; int gChokeCounter = 0;
@ -100,6 +99,8 @@ void EndLevel(void)
void StartLevel(MapRecord* level) void StartLevel(MapRecord* level)
{ {
if (!level) return; if (!level) return;
gFrameCount = 0;
gFrameClock = 0;
STAT_Update(0); STAT_Update(0);
EndLevel(); EndLevel();
gInput = {}; gInput = {};
@ -142,7 +143,6 @@ void StartLevel(MapRecord* level)
wsrand(dbReadMapCRC(currentLevel->LabelName())); wsrand(dbReadMapCRC(currentLevel->LabelName()));
gKillMgr.Clear(); gKillMgr.Clear();
gSecretMgr.Clear(); gSecretMgr.Clear();
gLevelTime = 0;
automapping = 1; automapping = 1;
int modernTypesErased = 0; int modernTypesErased = 0;
@ -239,15 +239,12 @@ void StartLevel(MapRecord* level)
sfxSetReverb(0); sfxSetReverb(0);
ambInit(); ambInit();
Net_ClearFifo(); Net_ClearFifo();
gFrameCount = 0;
gChokeCounter = 0; gChokeCounter = 0;
M_ClearMenus(); M_ClearMenus();
// viewSetMessage(""); // viewSetMessage("");
viewSetErrorMessage(""); viewSetErrorMessage("");
gameclock = 0;
paused = 0; paused = 0;
levelTryPlayMusic(); levelTryPlayMusic();
gFrameClock = 0;
gChoke.reset(); gChoke.reset();
} }
@ -261,15 +258,6 @@ static void commonTicker()
FireProcess(); FireProcess();
ClearBitString(gotpic, 2342); ClearBitString(gotpic, 2342);
} }
// This is single player only.
if (gameRestart)
{
gameRestart = false;
levelRestart();
gamestate = GS_LEVEL;
return;
}
if (gStartNewGame) if (gStartNewGame)
{ {
auto sng = gStartNewGame; auto sng = gStartNewGame;
@ -331,6 +319,7 @@ void GameInterface::Ticker()
} }
viewClearInterpolations(); viewClearInterpolations();
if (!(paused || (gGameOptions.nGameType == 0 && M_Active()))) if (!(paused || (gGameOptions.nGameType == 0 && M_Active())))
{ {
thinktime.Reset(); thinktime.Reset();
@ -370,7 +359,6 @@ void GameInterface::Ticker()
} }
thinktime.Unclock(); thinktime.Unclock();
gLevelTime++;
gFrameCount++; gFrameCount++;
gFrameClock += 4; gFrameClock += 4;

View file

@ -123,13 +123,13 @@ void GetInputInternal(InputPacket &inputParm)
static int32_t turnHeldTime; static int32_t turnHeldTime;
static int32_t lastInputClock; // MED static int32_t lastInputClock; // MED
int32_t const elapsedTics = gameclock - lastInputClock; int32_t const elapsedTics = gFrameClock - lastInputClock;
// Blood's q16mlook scaling is different from the other games, therefore use the below constant to attenuate // Blood's q16mlook scaling is different from the other games, therefore use the below constant to attenuate
// the speed to match the other games. // the speed to match the other games.
float const mlookScale = 3.25f; float const mlookScale = 3.25f;
lastInputClock = gameclock; lastInputClock = gFrameClock;
if (turnLeft || turnRight) if (turnLeft || turnRight)
turnHeldTime += elapsedTics; turnHeldTime += elapsedTics;

View file

@ -35,7 +35,6 @@ BEGIN_BLD_NS
bool bVanilla = false; bool bVanilla = false;
int gFrameClock; int gFrameClock;
int gFrameCount; int gFrameCount;
//int volatile gGameClock;
static const char *_module; static const char *_module;
static int _line; static int _line;

View file

@ -32,7 +32,6 @@ BEGIN_BLD_NS
extern int gFrameClock; extern int gFrameClock;
extern int gFrameCount; extern int gFrameCount;
//extern int gGameClock;
extern bool bVanilla; extern bool bVanilla;
#define MAXPLAYERNAME 16 #define MAXPLAYERNAME 16

View file

@ -54,8 +54,6 @@ int gSkill = 2;
int gEpisodeCount; int gEpisodeCount;
int gNextLevel; // fixme: let this contain a full level number. int gNextLevel; // fixme: let this contain a full level number.
int gLevelTime;
char BloodIniFile[BMAX_PATH] = "BLOOD.INI"; char BloodIniFile[BMAX_PATH] = "BLOOD.INI";
bool bINIOverride = false; bool bINIOverride = false;
IniFile *BloodINI; IniFile *BloodINI;
@ -235,11 +233,6 @@ void levelEndLevel(int arg)
} }
} }
void levelRestart(void)
{
gStartNewGame = currentLevel;
}
void levelTryPlayMusic() void levelTryPlayMusic()
{ {
FString buffer; FString buffer;

View file

@ -85,7 +85,6 @@ extern bool bINIOverride;
extern int gEpisodeCount; extern int gEpisodeCount;
extern int gNextLevel; extern int gNextLevel;
extern bool gGameStarted; extern bool gGameStarted;
extern int gLevelTime;
void levelInitINI(const char *pzIni); void levelInitINI(const char *pzIni);
void levelOverrideINI(const char *pzIni); void levelOverrideINI(const char *pzIni);
@ -98,7 +97,6 @@ void CheckKeyAbend(const char *pzSection, const char *pzKey);
void levelLoadDefaults(void); void levelLoadDefaults(void);
// arg: 0 is normal exit, 1 is secret level // arg: 0 is normal exit, 1 is secret level
void levelEndLevel(int arg); void levelEndLevel(int arg);
void levelRestart(void);
void levelTryPlayMusic(); void levelTryPlayMusic();
END_BLD_NS END_BLD_NS

View file

@ -504,7 +504,6 @@ bool GameInterface::LoadGame(FSaveGameNode* node)
for (int i = 0; i < gNetPlayers; i++) for (int i = 0; i < gNetPlayers; i++)
playerSetRace(&gPlayer[i], gPlayer[i].lifeMode); playerSetRace(&gPlayer[i], gPlayer[i].lifeMode);
viewSetErrorMessage(""); viewSetErrorMessage("");
gFrameCount = 0;
Net_ClearFifo(); Net_ClearFifo();
paused = 0; paused = 0;
gamestate = GS_LEVEL; gamestate = GS_LEVEL;
@ -598,7 +597,6 @@ void MyLoadSave::Load(void)
Read(gotsector, sizeof(gotsector)); Read(gotsector, sizeof(gotsector));
Read(&gFrameClock, sizeof(gFrameClock)); Read(&gFrameClock, sizeof(gFrameClock));
Read(&gFrameCount, sizeof(gFrameCount)); Read(&gFrameCount, sizeof(gFrameCount));
Read(&gLevelTime, sizeof(gLevelTime));
Read(&paused, sizeof(paused)); Read(&paused, sizeof(paused));
Read(baseWall, sizeof(baseWall[0])*numwalls); Read(baseWall, sizeof(baseWall[0])*numwalls);
Read(baseSprite, sizeof(baseSprite[0])*nNumSprites); Read(baseSprite, sizeof(baseSprite[0])*nNumSprites);
@ -687,7 +685,6 @@ void MyLoadSave::Save(void)
Write(gotsector, sizeof(gotsector)); Write(gotsector, sizeof(gotsector));
Write(&gFrameClock, sizeof(gFrameClock)); Write(&gFrameClock, sizeof(gFrameClock));
Write(&gFrameCount, sizeof(gFrameCount)); Write(&gFrameCount, sizeof(gFrameCount));
Write(&gLevelTime, sizeof(gLevelTime));
Write(&paused, sizeof(paused)); Write(&paused, sizeof(paused));
Write(baseWall, sizeof(baseWall[0])*numwalls); Write(baseWall, sizeof(baseWall[0])*numwalls);
Write(baseSprite, sizeof(baseSprite[0])*nNumSprites); Write(baseSprite, sizeof(baseSprite[0])*nNumSprites);

View file

@ -50,8 +50,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
extern bool gameRestart;
PROFILE gProfile[kMaxPlayers]; PROFILE gProfile[kMaxPlayers];
PLAYER gPlayer[kMaxPlayers]; PLAYER gPlayer[kMaxPlayers];
@ -1370,7 +1368,7 @@ void ProcessInput(PLAYER *pPlayer)
playerReset(pPlayer); playerReset(pPlayer);
if (gGameOptions.nGameType == 0 && numplayers == 1) if (gGameOptions.nGameType == 0 && numplayers == 1)
{ {
gameRestart = 1; gStartNewGame = currentLevel;
} }
else else
playerStart(pPlayer->nPlayer); playerStart(pPlayer->nPlayer);

View file

@ -222,7 +222,7 @@ private:
stats.font = SmallFont; stats.font = SmallFont;
stats.letterColor = CR_DARKRED; stats.letterColor = CR_DARKRED;
stats.standardColor = CR_DARKGRAY; stats.standardColor = CR_DARKGRAY;
stats.time = Scale(gLevelTime, 1000, kTicsPerSec); stats.time = Scale(gFrameCount, 1000, kTicsPerSec);
if (automapMode == am_full) if (automapMode == am_full)
{ {

View file

@ -224,7 +224,7 @@ void InitStatusBar(void)
} }
GameStats GameInterface::getStats() GameStats GameInterface::getStats()
{ {
return { gKillMgr.Kills, gKillMgr.TotalKills, gSecretMgr.Founds, gSecretMgr.Total, gLevelTime / kTicsPerSec, gPlayer[myconnectindex].fragCount }; return { gKillMgr.Kills, gKillMgr.TotalKills, gSecretMgr.Founds, gSecretMgr.Total, gFrameCount / kTicsPerSec, gPlayer[myconnectindex].fragCount };
} }
void viewDrawMapTitle(void) void viewDrawMapTitle(void)
@ -234,9 +234,9 @@ void viewDrawMapTitle(void)
int const fadeStartTic = kTicsPerSec; int const fadeStartTic = kTicsPerSec;
int const fadeEndTic = int(1.5f*kTicsPerSec); int const fadeEndTic = int(1.5f*kTicsPerSec);
if (gLevelTime > fadeEndTic) if (gFrameCount > fadeEndTic)
return; return;
int const alpha = 255 - clamp((gLevelTime-fadeStartTic)*255/(fadeEndTic-fadeStartTic), 0, 255); int const alpha = 255 - clamp((gFrameCount-fadeStartTic)*255/(fadeEndTic-fadeStartTic), 0, 255);
if (alpha != 0) if (alpha != 0)
{ {
@ -762,7 +762,7 @@ void viewDrawScreen(bool sceneonly)
tmp--; tmp--;
} }
PLAYER* pOther = &gPlayer[i]; PLAYER* pOther = &gPlayer[i];
//othercameraclock = gGameClock; //othercameraclock = gFrameClock + mulscale16(4, (int)gInterpolate);;
if (!tileData(4079)) if (!tileData(4079))
{ {
TileFiles.tileCreate(4079, 128, 128); TileFiles.tileCreate(4079, 128, 128);