- Exhumed: Migrate to GZDoom time code like Duke and SW.

This commit is contained in:
Mitchell Richters 2020-08-26 08:49:25 +10:00
parent 76b05dbcd6
commit a6cc3c4128
17 changed files with 63 additions and 75 deletions

View file

@ -165,9 +165,10 @@ enum
void menu_DoPlasma()
{
int ptile = nPlasmaTile;
if (totalclock >= nextPlasmaTic || !PlasmaBuffer)
int pclock = I_GetBuildTime();
if (pclock >= nextPlasmaTic || !PlasmaBuffer)
{
nextPlasmaTic = (int)totalclock + 4;
nextPlasmaTic = pclock + 4;
if (!nLogoTile)
nLogoTile = EXHUMED ? kExhumedLogo : kPowerslaveLogo;
@ -366,7 +367,7 @@ void menu_DoPlasma()
DrawRel(nLogoTile, 160, 40);
// draw the fire urn/lamp thingies
int dword_9AB5F = ((int)totalclock / 16) & 3;
int dword_9AB5F = (pclock / 16) & 3;
DrawRel(kTile3512 + dword_9AB5F, 50, 150);
DrawRel(kTile3512 + ((dword_9AB5F + 2) & 3), 270, 150);
@ -683,7 +684,7 @@ public:
{
for (int j = 0; j < MapLevelFires[i].nFires; j++)
{
int nFireFrame = (((int)totalclock >> 4) & 3);
int nFireFrame = ((totalclock >> 4) & 3);
assert(nFireFrame >= 0 && nFireFrame < 4);
int nFireType = MapLevelFires[i].fires[j].nFireType;
@ -699,7 +700,7 @@ public:
}
}
int t = ((((int)totalclock & 16) >> 4));
int t = (((totalclock & 16) >> 4));
int nTile = mapNamePlaques[i].tiles[t].nTile;
@ -713,7 +714,7 @@ public:
if (nLevelNew == i)
{
shade = (Sin(16 * (int)totalclock) + 31) >> 8;
shade = (Sin(16 * totalclock) + 31) >> 8;
}
else if (nLevelBest >= i)
{
@ -733,7 +734,7 @@ public:
// scroll the map every couple of ms
if (totalclock - runtimer >= (kTimerTicks / 32)) {
curYPos += var_2C;
runtimer = (int)totalclock;
runtimer = totalclock;
}
if (inputState.CheckAllInput())
@ -878,12 +879,12 @@ void TextOverlay::DisplayText()
}
}
bool TextOverlay::AdvanceCinemaText(int totalclock)
bool TextOverlay::AdvanceCinemaText(int gameclock)
{
if (nHeight + nCrawlY > 0 || CDplaying())
{
nCrawlY-= (totalclock - lastclock) / 15.; // do proper interpolation.
lastclock = totalclock;
nCrawlY-= (gameclock - lastclock) / 15.; // do proper interpolation.
lastclock = gameclock;
return true;
}
@ -1144,7 +1145,7 @@ private:
nStringTypeOn++;
if (nStringTypeOn >= screentext.Size())
{
nextclock = (kTimerTicks * (screentext.Size() + 2)) + (int)totalclock;
nextclock = (kTimerTicks * (screentext.Size() + 2)) + totalclock;
phase = 3;
}
@ -1153,7 +1154,7 @@ private:
DisplayPhase2();
if (skiprequest)
{
nextclock = (kTimerTicks * (screentext.Size() + 2)) + (int)totalclock;
nextclock = (kTimerTicks * (screentext.Size() + 2)) + totalclock;
phase = 3;
}
break;

View file

@ -96,7 +96,7 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, double xpos, doub
if (state == NIT_SelectedState)
{ // currently selected menu item
shade = Sin((int)totalclock << 4) >> 9;
shade = Sin(I_GetBuildTime() << 4) >> 9;
}
else if (state == NIT_ActiveState) {
shade = 0;

View file

@ -60,8 +60,8 @@ enum {
kSectLava = 0x4000,
};
extern ClockTicks ototalclock;
extern int ogameclock, gameclock;
extern int lastTic;
extern int initx;
extern int inity;
extern int initz;

View file

@ -29,7 +29,9 @@ BEGIN_PS_NS
void resettiming()
{
totalclock = 0;
ogameclock = -1;
gameclock = 0;
lastTic = -1;
}
void doTileLoad(int i)

View file

@ -71,12 +71,7 @@ PlayerInput localInput;
void ResetEngine()
{
EraseScreen(-1);
resettiming();
totalclock = 0;
ototalclock = totalclock;
localclock = (int)totalclock;
}
void InstallEngine()
@ -158,7 +153,6 @@ short nCodeIndex = 0;
//short nScreenHeight = 200;
int moveframes;
int flash;
int localclock;
int totalmoves;
short nCurBodyNum = 0;
@ -190,8 +184,6 @@ int nTimeLimit;
int bVanilla = 0;
ClockTicks tclocks;
void DebugOut(const char *fmt, ...)
{
#ifdef _DEBUG
@ -392,12 +384,12 @@ void DrawClock()
DoEnergyTile();
}
double calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk)
double calc_smoothratio()
{
if (bRecord || bPlayback || nFreeze != 0 || bCamera || paused)
return 65536;
return MaxSmoothRatio;
return CalcSmoothRatio(totalclk, ototalclk, 30);
return I_GetTimeFrac() * MaxSmoothRatio;
}
FString GameInterface::statFPS()
@ -489,18 +481,20 @@ void GameTicker()
{
bInMove = true;
int const currentTic = I_GetTime();
gameclock = I_GetBuildTime();
if (paused)
{
tclocks = totalclock - 4;
buttonMap.ResetButtonStates();
}
else
{
while ((totalclock - ototalclock) >= 1 || !bInMove)
while ((gameclock - ogameclock) >= 1 || !bInMove)
{
ototalclock = ototalclock + 1;
ogameclock = I_GetBuildTime();
if (!((int)ototalclock & 3) && moveframes < 4)
if (!((int)ogameclock & 3) && moveframes < 4)
moveframes++;
GetLocalInput();
@ -527,9 +521,9 @@ void GameTicker()
sPlayerInput[nLocalPlayer].horizon = PlayerList[nLocalPlayer].q16horiz;
while (!EndLevel && totalclock >= tclocks + 4)
while (!EndLevel && currentTic - lastTic >= 1)
{
tclocks += 4;
lastTic = currentTic;
leveltime++;
GameMove();
}
@ -759,9 +753,6 @@ static SavegameHelper sgh("exhumed",
SV(nBodyTotal),
SV(bSnakeCam),
SV(bSlipMode),
SV(localclock),
SV(tclocks),
SV(totalclock),
SV(leveltime),
nullptr);

View file

@ -149,8 +149,6 @@ extern char sHollyStr[];
extern int selectedlevelnew;
extern int GameAction;
extern int localclock;
extern int moveframes;
extern int nNetPlayerCount;
@ -249,7 +247,7 @@ public:
void ComputeCinemaText();
void ReadyCinemaText(uint16_t nVal);
void DisplayText();
bool AdvanceCinemaText(int totalclock);
bool AdvanceCinemaText(int gameclock);
};

View file

@ -55,12 +55,11 @@ static int32_t nonsharedtimer;
int GameAction=-1;
extern uint8_t nCinemaSeen;
extern ClockTicks tclocks;
void RunCinemaScene(int num);
void GameMove(void);
void DrawClock();
double calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk);
double calc_smoothratio();
void DoTitle(CompletionFunc completion);
static int FinishLevel(TArray<JobDesc> &jobs)
@ -83,8 +82,8 @@ static int FinishLevel(TArray<JobDesc> &jobs)
{
// There's really no choice but to enter an active wait loop here to make the sound play out.
PlayLocalSound(StaticSound[59], 0, true, CHANF_UI);
int nTicks = totalclock + 12;
while (nTicks > (int)totalclock) { HandleAsync(); }
int nTicks = gameclock + 12;
while (nTicks > gameclock) { HandleAsync(); }
}
}
else nPlayerLives[0] = 0;
@ -117,9 +116,7 @@ static void GameDisplay(void)
DrawClock();
}
double smoothRatio = calc_smoothratio(totalclock, tclocks);
DrawView(smoothRatio);
DrawView(calc_smoothratio());
DrawStatusBar();
if (paused && !M_Active())
{
@ -152,7 +149,7 @@ void startmainmenu()
void drawmenubackground()
{
auto nLogoTile = EXHUMED ? kExhumedLogo : kPowerslaveLogo;
int dword_9AB5F = ((int)totalclock / 16) & 3;
int dword_9AB5F = (I_GetBuildTime() / 16) & 3;
twod->ClearScreen();
@ -226,7 +223,6 @@ void CheckProgression()
gamestate = GS_LEVEL;
InitLevel(selectedlevelnew);
tclocks = totalclock;
#if 0
// this would be the place to autosave upon level start
if (!bInDemo && selectedlevelnew > nBestLevel && selectedlevelnew != 0 && selectedlevelnew <= kMap20) {
@ -274,8 +270,7 @@ void GameInterface::RunGameFrame()
{
default:
case GS_STARTUP:
totalclock = 0;
ototalclock = 0;
resettiming();
GameAction = -1;
EndLevel = false;

View file

@ -38,7 +38,9 @@ enum
kTagRamses = 61,
};
ClockTicks ototalclock = 0;
int ogameclock = 0;
int gameclock = 0;
int lastTic;
int initx, inity, initz;
short inita, initsect;

View file

@ -160,7 +160,7 @@ void CheckKeys2()
{
if (automapMode != am_off)
{
int const timerOffset = ((int)totalclock - nonsharedtimer);
int const timerOffset = (gameclock - nonsharedtimer);
nonsharedtimer += timerOffset;
if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen))

View file

@ -434,7 +434,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16
if (p == screenpeek || GTFLAGS(GAMETYPE_OTHERPLAYERSINMAP))
{
if (pSprite->xvel > 16 && pPlayer->on_ground)
i = APLAYERTOP+(((int32_t) totalclock>>4)&3);
i = APLAYERTOP+(((int32_t) gameclock>>4)&3);
else
i = APLAYERTOP;

View file

@ -194,7 +194,6 @@ void MoveThings()
void ResetMoveFifo()
{
localclock = (int)totalclock;
movefifoend = 0;
movefifopos = 0;
}

View file

@ -1529,20 +1529,20 @@ void DoFinale()
{
StopLocalSound();
PlayLocalSound(StaticSound[kSound76], 0);
dword_1542FC = (int)totalclock + 120;
dword_1542FC = gameclock + 120;
nFinaleStage++;
}
}
else if (nFinaleStage <= 2)
{
if ((int)totalclock >= dword_1542FC)
if (gameclock >= dword_1542FC)
{
PlayLocalSound(StaticSound[kSound77], 0);
nFinaleStage++;
dword_1542FC = (int)totalclock + 360;
dword_1542FC = gameclock + 360;
}
}
else if (nFinaleStage == 3 && (int)totalclock >= dword_1542FC)
else if (nFinaleStage == 3 && gameclock >= dword_1542FC)
{
EndLevel = true;
}
@ -1706,7 +1706,7 @@ void ExplodeEnergyBlock(int nSprite)
else
{
nFinaleSpr = nSprite;
lFinaleStart = (int)totalclock;
lFinaleStart = gameclock;
if (!lFinaleStart) {
lFinaleStart = lFinaleStart + 1;

View file

@ -127,7 +127,7 @@ void InitSpiritHead()
sprite[nSpiritSprite].cstat &= 0x7FFF;
nHeadTimeStart = (int)totalclock;
nHeadTimeStart = gameclock;
memset(Worktile, TRANSPARENT_INDEX, WorktileSize);
TileFiles.InvalidateTile(kTileRamsesWorkTile);
@ -152,8 +152,8 @@ void InitSpiritHead()
StartSwirlies();
sprintf(filename, "LEV%d.PUP", currentLevel->levelNumber);
lNextStateChange = (int)totalclock;
lHeadStartClock = (int)totalclock;
lNextStateChange = gameclock;
lHeadStartClock = gameclock;
auto headfd = fileSystem.OpenFileReader(filename);
if (!headfd.isOpen())
@ -219,7 +219,7 @@ int DoSpiritHead()
if (nHeadStage < 2 || nHeadStage != 5)
{
nPixelsToShow = ((int)totalclock - nHeadTimeStart) * 15;
nPixelsToShow = (gameclock - nHeadTimeStart) * 15;
if (nPixelsToShow > nPixels) {
nPixelsToShow = nPixels;
@ -242,10 +242,10 @@ int DoSpiritHead()
if (!nHeadStage)
{
if (((int)totalclock - nHeadTimeStart) > 480)
if ((gameclock - nHeadTimeStart) > 480)
{
nHeadStage = 1;
nHeadTimeStart = (int)totalclock + 480;
nHeadTimeStart = gameclock + 480;
}
for (int i = 0; i < nPixelsToShow; i++)
@ -426,7 +426,7 @@ int DoSpiritHead()
Worktile[kSpiritX + ecx] = pixelval[i];
}
if (((int)totalclock - lHeadStartClock) > 600)
if ((gameclock - lHeadStartClock) > 600)
{
CopyHeadToWorkTile(kTileRamsesGold);
}
@ -467,7 +467,7 @@ int DoSpiritHead()
}
else
{
if (lNextStateChange <= (int)totalclock)
if (lNextStateChange <= gameclock)
{
if (nPupData)
{

View file

@ -60,7 +60,7 @@ bool GameInterface::LoadGame(FSaveGameNode* sv)
pSky->yscale = 65536;
parallaxtype = 2;
g_visibility = 2048;
ototalclock = totalclock;
ogameclock = gameclock;
GameAction = 1000;
if (currentLevel->levelNumber > 15)

View file

@ -447,7 +447,7 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3],
else if (type == SOURCE_Swirly)
{
int which = *(int*)source;
float phase = ((int)totalclock << (4 + which)) * (M_PI / 1024);
float phase = (gameclock << (4 + which)) * (M_PI / 1024);
pos->X = fcampos.X + 256 * cos(phase);
pos->Z = fcampos.Z + 256 * sin(phase);
}
@ -522,7 +522,7 @@ void UpdateSounds()
soundEngine->SetListener(listener);
soundEngine->UpdateSounds((int)totalclock);
soundEngine->UpdateSounds(gameclock);
soundEngine->EnumerateChannels([](FSoundChan* chan)
{
if (!(chan->ChanFlags & (CHANF_UI|CHANF_FORGETTABLE)))

View file

@ -676,7 +676,7 @@ private:
int shade;
if ((int)totalclock / kTimerTicks & 1) {
if (gameclock / kTimerTicks & 1) {
shade = -100;
}
else {
@ -694,14 +694,14 @@ private:
if (word_9AD54[i] == nScore)
{
int v9 = dword_9AD64[i];
if (v9 && v9 <= (int)totalclock) {
if (v9 && v9 <= gameclock) {
dword_9AD64[i] = 0;
}
}
else
{
word_9AD54[i] = nScore;
dword_9AD64[i] = (int)totalclock + 30;
dword_9AD64[i] = gameclock + 30;
}
DrawGraphic(tileGetTexture(nTile), x, 7, DI_ITEM_CENTER, 1, -1, -1, 1, 1);

View file

@ -434,7 +434,7 @@ void DrawView(double smoothRatio, bool sceneonly)
if (bSubTitles)
{
subtitleOverlay.Start(totalclock);
subtitleOverlay.Start(gameclock);
if (currentLevel->levelNumber == 1)
subtitleOverlay.ReadyCinemaText(1);
else
@ -443,7 +443,7 @@ void DrawView(double smoothRatio, bool sceneonly)
}
else if (nHeadStage == 6)
{
if ((bSubTitles && !subtitleOverlay.AdvanceCinemaText(totalclock)) || inputState.CheckAllInput())
if ((bSubTitles && !subtitleOverlay.AdvanceCinemaText(gameclock)) || inputState.CheckAllInput())
{
inputState.ClearAllInput();
EndLevel = 2;