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

View file

@ -123,13 +123,13 @@ void GetInputInternal(InputPacket &inputParm)
static int32_t turnHeldTime;
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
// the speed to match the other games.
float const mlookScale = 3.25f;
lastInputClock = gameclock;
lastInputClock = gFrameClock;
if (turnLeft || turnRight)
turnHeldTime += elapsedTics;

View file

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

View file

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

View file

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

View file

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

View file

@ -504,7 +504,6 @@ bool GameInterface::LoadGame(FSaveGameNode* node)
for (int i = 0; i < gNetPlayers; i++)
playerSetRace(&gPlayer[i], gPlayer[i].lifeMode);
viewSetErrorMessage("");
gFrameCount = 0;
Net_ClearFifo();
paused = 0;
gamestate = GS_LEVEL;
@ -598,7 +597,6 @@ void MyLoadSave::Load(void)
Read(gotsector, sizeof(gotsector));
Read(&gFrameClock, sizeof(gFrameClock));
Read(&gFrameCount, sizeof(gFrameCount));
Read(&gLevelTime, sizeof(gLevelTime));
Read(&paused, sizeof(paused));
Read(baseWall, sizeof(baseWall[0])*numwalls);
Read(baseSprite, sizeof(baseSprite[0])*nNumSprites);
@ -687,7 +685,6 @@ void MyLoadSave::Save(void)
Write(gotsector, sizeof(gotsector));
Write(&gFrameClock, sizeof(gFrameClock));
Write(&gFrameCount, sizeof(gFrameCount));
Write(&gLevelTime, sizeof(gLevelTime));
Write(&paused, sizeof(paused));
Write(baseWall, sizeof(baseWall[0])*numwalls);
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
extern bool gameRestart;
PROFILE gProfile[kMaxPlayers];
PLAYER gPlayer[kMaxPlayers];
@ -1370,7 +1368,7 @@ void ProcessInput(PLAYER *pPlayer)
playerReset(pPlayer);
if (gGameOptions.nGameType == 0 && numplayers == 1)
{
gameRestart = 1;
gStartNewGame = currentLevel;
}
else
playerStart(pPlayer->nPlayer);

View file

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

View file

@ -224,7 +224,7 @@ void InitStatusBar(void)
}
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)
@ -234,9 +234,9 @@ void viewDrawMapTitle(void)
int const fadeStartTic = kTicsPerSec;
int const fadeEndTic = int(1.5f*kTicsPerSec);
if (gLevelTime > fadeEndTic)
if (gFrameCount > fadeEndTic)
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)
{
@ -762,7 +762,7 @@ void viewDrawScreen(bool sceneonly)
tmp--;
}
PLAYER* pOther = &gPlayer[i];
//othercameraclock = gGameClock;
//othercameraclock = gFrameClock + mulscale16(4, (int)gInterpolate);;
if (!tileData(4079))
{
TileFiles.tileCreate(4079, 128, 128);