Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ set(libdevilutionx_SRCS
utils/str_cat.cpp
utils/str_case.cpp
utils/surface_to_clx.cpp
utils/timer.cpp
utils/utf8.cpp)

if(SUPPORTS_MPQ)
Expand Down
19 changes: 14 additions & 5 deletions Source/engine/demomode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ bool FetchMessage(SDL_Event *event, uint16_t *modState)
void RecordGameLoopResult(bool runGameLoop)
{
WriteDemoMsgHeader(runGameLoop ? DemoMsg::GameTick : DemoMsg::Rendering);

if (runGameLoop && !IsRunning())
LogicTick++;
}

void RecordMessage(const SDL_Event &event, uint16_t modState)
Expand Down Expand Up @@ -790,6 +793,12 @@ void RecordMessage(const SDL_Event &event, uint16_t modState)

void NotifyGameLoopStart()
{
LogicTick = 0;

if (IsRunning()) {
StartTime = SDL_GetTicks();
}

if (IsRecording()) {
const std::string path = StrCat(paths::PrefPath(), "demo_", RecordNumber, ".dmo");
DemoRecording = OpenFile(path.c_str(), "wb");
Expand All @@ -803,11 +812,6 @@ void NotifyGameLoopStart()
WriteLE32(DemoRecording, gSaveNumber);
WriteSettings(DemoRecording);
}

if (IsRunning()) {
StartTime = SDL_GetTicks();
LogicTick = 0;
}
}

void NotifyGameLoopEnd()
Expand Down Expand Up @@ -843,6 +847,11 @@ void NotifyGameLoopEnd()
}
}

uint32_t SimulateMillisecondsSinceStartup()
{
return LogicTick * 50;
}

} // namespace demo

} // namespace devilution
6 changes: 6 additions & 0 deletions Source/engine/demomode.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void RecordMessage(const SDL_Event &event, uint16_t modState);

void NotifyGameLoopStart();
void NotifyGameLoopEnd();

uint32_t SimulateMillisecondsSinceStartup();
#else
inline void OverrideOptions()
{
Expand Down Expand Up @@ -60,6 +62,10 @@ inline void NotifyGameLoopStart()
inline void NotifyGameLoopEnd()
{
}
inline uint32_t SimulateMillisecondsSinceStartup()
{
return 0;
}
#endif

} // namespace demo
Expand Down
5 changes: 3 additions & 2 deletions Source/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "stores.h"
#include "utils/algorithm/container.hpp"
#include "utils/language.h"
#include "utils/timer.hpp"

namespace devilution {

Expand All @@ -30,7 +31,7 @@ const int LineWidth = 418;

void InitNextLines()
{
msgdelay = SDL_GetTicks();
msgdelay = GetMillisecondsSinceStartup();
TextLines.clear();

const std::string paragraphs = WordWrapString(DiabloMessages.front(), LineWidth, GameFont12, 1);
Expand Down Expand Up @@ -172,7 +173,7 @@ void DrawDiabloMsg(const Surface &out)
lineNumber += 1;
}

if (msgdelay > 0 && msgdelay <= SDL_GetTicks() - 3500) {
if (msgdelay > 0 && msgdelay <= GetMillisecondsSinceStartup() - 3500) {
msgdelay = 0;
}
if (msgdelay == 0) {
Expand Down
5 changes: 3 additions & 2 deletions Source/minitext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "playerdat.hpp"
#include "textdat.h"
#include "utils/language.h"
#include "utils/timer.hpp"

namespace devilution {

Expand Down Expand Up @@ -81,7 +82,7 @@ uint32_t CalculateTextSpeed(int nSFX)

int CalculateTextPosition()
{
uint32_t currTime = SDL_GetTicks();
uint32_t currTime = GetMillisecondsSinceStartup();

int y = (currTime - ScrollStart) / qtextSpd - 260;

Expand Down Expand Up @@ -165,7 +166,7 @@ void InitQTextMsg(_speech_id m)
LoadText(_(Speeches[m].txtstr));
qtextflag = true;
qtextSpd = CalculateTextSpeed(sfxnr);
ScrollStart = SDL_GetTicks();
ScrollStart = GetMillisecondsSinceStartup();
}
PlaySFX(sfxnr);
}
Expand Down
10 changes: 10 additions & 0 deletions Source/utils/timer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "engine/demomode.h"

namespace devilution {

uint32_t GetMillisecondsSinceStartup()
{
return (demo::IsRunning() || demo::IsRecording()) ? demo::SimulateMillisecondsSinceStartup() : SDL_GetTicks();
}

} // namespace devilution
7 changes: 7 additions & 0 deletions Source/utils/timer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace devilution {

uint32_t GetMillisecondsSinceStartup();

}