Skip to content

Commit

Permalink
TimeTypes: Replace PlatformDurationMs()
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Aug 4, 2021
1 parent 013c289 commit 4e7f367
Show file tree
Hide file tree
Showing 32 changed files with 71 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/ai/PathFinderManager.cpp
Expand Up @@ -67,7 +67,7 @@ static constexpr const float PATHFINDER_HEURISTIC_RANGE = PATHFINDER_HEURISTIC_M
static constexpr const float PATHFINDER_DISTANCE_MAX = 5000.0f;

// Pathfinder Definitions
static const PlatformDuration PATHFINDER_UPDATE_INTERVAL = PlatformDurationMs(10);
static const PlatformDuration PATHFINDER_UPDATE_INTERVAL = 10ms;

class PathFinderThread : public StoppableThread {

Expand Down
6 changes: 3 additions & 3 deletions src/audio/Ambiance.cpp
Expand Up @@ -113,7 +113,7 @@ struct KeySetting {
!file->read(&_flags, 4)) {
return false;
}
min = _min, max = _max, interval = PlatformDurationMs(_interval);
min = _min, max = _max, interval = std::chrono::milliseconds(_interval);
flags = KeyFlags::load(_flags); // TODO save/load flags

return true;
Expand Down Expand Up @@ -200,8 +200,8 @@ struct TrackKey {
!z.load(file)) {
return false;
}
start = PlatformDurationMs(_start), loop = _loop + 1;
delay_min = PlatformDurationMs(_delay_min), delay_max = PlatformDurationMs(_delay_max);
start = std::chrono::milliseconds(_start), loop = _loop + 1;
delay_min = std::chrono::milliseconds(_delay_min), delay_max = std::chrono::milliseconds(_delay_max);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/audio/Audio.cpp
Expand Up @@ -743,7 +743,7 @@ void ambianceStop(AmbianceId ambianceId, PlatformDuration fadeInterval) {
g_ambiances[ambianceId]->stop(fadeInterval);
}

static const PlatformDuration ARX_SOUND_UPDATE_INTERVAL = PlatformDurationMs(100);
static constexpr PlatformDuration ARX_SOUND_UPDATE_INTERVAL = 100ms;

class SoundUpdateThread : public StoppableThread {

Expand Down
4 changes: 2 additions & 2 deletions src/core/ArxGame.cpp
Expand Up @@ -183,7 +183,7 @@ extern bool START_NEW_QUEST;
SavegameHandle LOADQUEST_SLOT = SavegameHandle(); // OH NO, ANOTHER GLOBAL! - TEMP PATCH TO CLEAN CODE FLOW
static fs::path g_saveToLoad;

static const PlatformDuration runeDrawPointInterval = PlatformDurationMs(16); // ~60fps
static const PlatformDuration runeDrawPointInterval = 16ms; // ~60fps

extern EERIE_3DOBJ * arrowobj;

Expand Down Expand Up @@ -597,7 +597,7 @@ ARX_PROGRAM_OPTION_ARG("loadsave", "", "Load a specific savegame file", &loadSav

static bool HandleGameFlowTransitions() {

const PlatformDuration TRANSITION_DURATION = PlatformDurationMs(3600);
const PlatformDuration TRANSITION_DURATION = 3600ms;
static PlatformInstant TRANSITION_START = 0;

if(GameFlow::getTransition() == GameFlow::InGame) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Core.cpp
Expand Up @@ -844,7 +844,7 @@ void ManageCombatModeAnimations() {
Anglef desired = vectorToAngle(dest - pos);
Anglef actual = unitVectorToAngle(dir);

float t = g_platformTime.lastFrameDuration() / PlatformDurationMs(100) * player.m_bowAimRatio;
float t = g_platformTime.lastFrameDuration() / 100ms * player.m_bowAimRatio;
float dpitch = AngleDifference(actual.getPitch(), desired.getPitch()) * t;
float dyaw = AngleDifference(desired.getYaw(), actual.getYaw()) * t;
player.m_bowAimRotation.setPitch(glm::clamp(player.m_bowAimRotation.getPitch() + dpitch, -90.f, 90.f));
Expand Down
2 changes: 1 addition & 1 deletion src/core/GameTime.cpp
Expand Up @@ -64,7 +64,7 @@ void PlatformTime::updateFrame() {
m_lastFrameDuration = currentTime - m_frameStartTime;

// Limit simulation time per frame
m_lastFrameDuration = std::min(m_lastFrameDuration, PlatformDurationMs(100));
m_lastFrameDuration = std::min(m_lastFrameDuration, PlatformDuration(100ms));

m_frameStartTime = currentTime;
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/TimeTypes.h
Expand Up @@ -262,9 +262,6 @@ typedef DurationType<struct PlatformTimeTag, s64> PlatformDuration;
return PlatformInstant(0) + std::chrono::microseconds(val);
}

[[nodiscard]] inline constexpr PlatformDuration PlatformDurationMs(s64 val) noexcept {
return std::chrono::milliseconds(val);
}
[[nodiscard]] inline constexpr PlatformDuration PlatformDurationMsf(float val) noexcept {
return std::chrono::duration<float, std::milli>(val);
}
Expand Down
16 changes: 8 additions & 8 deletions src/game/Player.cpp
Expand Up @@ -439,12 +439,12 @@ void ARX_PLAYER_ComputePlayerFullStats() {

player.Full_AimTime = PlatformDurationMsf(fFullAimTime);
if(player.Full_AimTime <= 0) {
player.Full_AimTime = PlatformDurationMs(1500);
player.Full_AimTime = 1500ms;
}

player.Full_AimTime -= PlatformDurationMsf(fCalcHandicap);
if(player.Full_AimTime <= PlatformDurationMs(1500)) {
player.Full_AimTime = PlatformDurationMs(1500);
if(player.Full_AimTime <= 1500ms) {
player.Full_AimTime = 1500ms;
}

// TODO make these calculations moddable
Expand Down Expand Up @@ -495,7 +495,7 @@ void ARX_PLAYER_ComputePlayerFullStats() {
miscMod.armorClass = 100;
player.m_miscMod.add(miscMod);

player.Full_AimTime = PlatformDurationMs(100);
player.Full_AimTime = 100ms;
}
if(sp_max) {
PlayerAttribute attributeMod;
Expand Down Expand Up @@ -525,7 +525,7 @@ void ARX_PLAYER_ComputePlayerFullStats() {
miscMod.armorClass = 20;
player.m_miscMod.add(miscMod);

player.Full_AimTime = PlatformDurationMs(100);
player.Full_AimTime = 100ms;
}
if(player.m_cheatPnuxActive) {
PlayerAttribute attributeMod;
Expand Down Expand Up @@ -1839,7 +1839,7 @@ static void PlayerMovementIterate(float DeltaTime) {

if(REQUEST_JUMP != 0) {
PlatformDuration t = g_platformTime.frameStart() - REQUEST_JUMP;
if(t >= 0 && t <= PlatformDurationMs(350)) {
if(t >= 0 && t <= 350ms) {
REQUEST_JUMP = 0;
spawnAudibleSound(player.pos, *entities.player());
ARX_SPEECH_Launch_No_Unicode_Seek("player_jump", entities.player());
Expand Down Expand Up @@ -1971,9 +1971,9 @@ static void PlayerMovementIterate(float DeltaTime) {

float jump_mul = 1.f;
PlatformDuration diff = g_platformTime.frameStart() - LAST_JUMP_ENDTIME;
if(diff < PlatformDurationMs(600)) {
if(diff < 600ms) {
jump_mul = 0.5f;
if(diff >= PlatformDurationMs(300)) {
if(diff >= 300ms) {
jump_mul += (toMs(LAST_JUMP_ENDTIME - g_platformTime.frameStart()) + 300.f) * (1.f / 300);
if(jump_mul > 1.f) {
jump_mul = 1.f;
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells.cpp
Expand Up @@ -545,7 +545,7 @@ void ARX_SPELLS_ManageMagic() {

PlatformInstant now = g_platformTime.frameStart();

const PlatformDuration interval = PlatformDurationMs(1000 / 60);
const PlatformDuration interval = std::chrono::microseconds(1s) / 60;

if(ARX_FLARES_broken) {
g_LastFlarePosition = pos;
Expand Down
6 changes: 3 additions & 3 deletions src/game/spell/Cheat.cpp
Expand Up @@ -79,9 +79,9 @@ void CheatDrawText() {

PlatformDuration elapsed = g_platformTime.frameStart() - sp_max_start;

if(elapsed < PlatformDurationMs(20000)) {
if(elapsed < 20s) {

float modi = (PlatformDurationMs(20000) - elapsed) / PlatformDurationMs(2000) * 0.1f;
float modi = (20s - elapsed) / 2s * 0.1f;
float sizX = 16;

Vec2f p = Vec2f(g_size.center());
Expand All @@ -90,7 +90,7 @@ void CheatDrawText() {
for(size_t i = 0; i < sp_max_ch.length(); i++) {
Vec2f d = p + Vec2f(sizX * i, sp_max_y[i]);

sp_max_y[i] = std::sin(d.x + elapsed / PlatformDurationMs(100)) * 30.f * modi;
sp_max_y[i] = std::sin(d.x + elapsed / 100ms) * 30.f * modi;
std::string tex(1, sp_max_ch[i]);

UNICODE_ARXDrawTextCenter(hFontInGame, d + Vec2f(-1, -1), tex, Color::none);
Expand Down
7 changes: 2 additions & 5 deletions src/game/spell/FlyingEye.cpp
Expand Up @@ -65,14 +65,11 @@ void DrawMagicSightInterface() {
}

EERIEDrawBitmap(Rectf(g_size), 0.0001f, Flying_Eye, Color::gray(col));

if(MagicSightFader > 0.f) {
col = MagicSightFader;

EERIEDrawBitmap(Rectf(g_size), 0.0001f, nullptr, Color::gray(col));

MagicSightFader -= g_platformTime.lastFrameDuration() / PlatformDurationMs(400);

MagicSightFader -= g_platformTime.lastFrameDuration() / 400ms;
if(MagicSightFader < 0.f) {
MagicSightFader = 0.f;
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/particle/MagicFlare.cpp
Expand Up @@ -384,7 +384,7 @@ void ARX_MAGICAL_FLARES_Update() {
flare.tolive -= diff * 6;
}

float z = flare.tolive / PlatformDurationMs(4000);
float z = flare.tolive / 4s;
float size;
if(flare.type == 1) {
size = flare.size * 2 * z;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/CharacterCreation.cpp
Expand Up @@ -92,7 +92,7 @@ static void characterCreationAddDescription(std::string_view text) {
float(g_size.center().x) * 0.82f,
std::string(text),
Color(232 + t, 204 + t, 143 + t),
PlatformDurationMs(1000),
1s,
0.01f,
3,
0);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/CinematicBorder.cpp
Expand Up @@ -84,14 +84,14 @@ void CinematicBorder::set(bool status, bool smooth) {
void CinematicBorder::update() {

if(m_direction == 1) {
CINEMA_DECAL += g_platformTime.lastFrameDuration() / PlatformDurationMs(10);
CINEMA_DECAL += g_platformTime.lastFrameDuration() / 10ms;

if(CINEMA_DECAL > 100.f) {
CINEMA_DECAL = 100.f;
m_direction = 0;
}
} else if(m_direction == -1) {
CINEMA_DECAL -= g_platformTime.lastFrameDuration() / PlatformDurationMs(10);
CINEMA_DECAL -= g_platformTime.lastFrameDuration() / 10ms;

if(CINEMA_DECAL < 0.f) {
CINEMA_DECAL = 0.f;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/Console.cpp
Expand Up @@ -635,7 +635,7 @@ void ScriptConsole::draw() {
// Draw cursor
bool blink = true;
if(mainApp->getWindow()->hasFocus()) {
blink = timeWaveSquare(g_platformTime.frameStart(), PlatformDurationMs(1200));
blink = timeWaveSquare(g_platformTime.frameStart(), 1200ms);
}
if(blink) {
int cursor = x;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/Credits.cpp
Expand Up @@ -473,8 +473,8 @@ void Credits::render() {
static PlatformInstant lastUserScrollTime = 0;
static float scrollDirection = 1.f;

PlatformDuration keyRepeatDelay = PlatformDurationMs(256); // delay after key press before continuous scrolling
PlatformDuration autoScrollDelay = PlatformDurationMs(250); // ms after user input before resuming normal scrolling
PlatformDuration keyRepeatDelay = 256ms; // delay after key press before continuous scrolling
PlatformDuration autoScrollDelay = 250ms; // ms after user input before resuming normal scrolling

// Process user input
float userScroll = 20.f * GInput->getMouseWheelDir();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/Cursor.cpp
Expand Up @@ -193,7 +193,7 @@ class CursorAnimatedHand {
CursorAnimatedHand()
: m_time(0)
, m_frame(0)
, m_delay(PlatformDurationMs(70))
, m_delay(70ms)
{}

void reset() {
Expand Down
35 changes: 17 additions & 18 deletions src/gui/Hud.cpp
Expand Up @@ -117,7 +117,7 @@ void HitStrengthGauge::update() {

if(m_flashActive) {
m_flashTime += g_platformTime.lastFrameDuration();
if(m_flashTime >= PlatformDurationMs(500)) {
if(m_flashTime >= 500ms) {
m_flashActive = false;
m_flashTime = 0;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ void BookIconGui::update(const Rectf & parent) {

if(m_haloActive) {
ulBookHaloTime += g_platformTime.lastFrameDuration();
if(ulBookHaloTime >= PlatformDurationMs(3000)) { // ms
if(ulBookHaloTime >= 3s) {
m_haloActive = false;
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ void BackpackIconGui::updateInput() {
flDelay = g_platformTime.frameStart();
return;
}
if(g_platformTime.frameStart() - flDelay < PlatformDurationMs(300)) {
if(g_platformTime.frameStart() - flDelay < 300ms) {
return;
}
flDelay = 0;
Expand Down Expand Up @@ -424,7 +424,7 @@ void PurseIconGui::update(const Rectf & parent) {

if(m_haloActive) {
m_haloTime += g_platformTime.lastFrameDuration();
if(m_haloTime >= PlatformDurationMs(1000)) {
if(m_haloTime >= 1s) {
m_haloActive = false;
}
}
Expand Down Expand Up @@ -1323,10 +1323,10 @@ void PlayerInterfaceFader::requestFade(FadeDirection showhide, long smooth) {
if(showhide == FadeDirection_In) {
m_current = 0;
} else {
m_current = PlatformDurationMs(1000);
m_current = 1s;
}

lSLID_VALUE = m_current / PlatformDurationMs(10);
lSLID_VALUE = m_current / 10ms;
}
}

Expand All @@ -1344,17 +1344,16 @@ void PlayerInterfaceFader::update() {
bOk = false;

PlatformInstant t = g_platformTime.frameStart();

if(t - SLID_START > PlatformDurationMs(10000)) {
if(t - SLID_START > 10s) {
m_current += g_platformTime.lastFrameDuration();

if(m_current > PlatformDurationMs(1000))
m_current = PlatformDurationMs(1000);

lSLID_VALUE = m_current / PlatformDurationMs(10);
if(m_current > 1s) {
m_current = 1s;
}
lSLID_VALUE = m_current / 10ms;
} else {
bOk = true;
}

}
}

Expand All @@ -1365,26 +1364,26 @@ void PlayerInterfaceFader::update() {
m_current = 0;
}

lSLID_VALUE = m_current / PlatformDurationMs(10);
lSLID_VALUE = m_current / 10ms;
}
}

if(m_direction == 1) {
m_current += g_platformTime.lastFrameDuration();

if(m_current > PlatformDurationMs(1000)) {
m_current = PlatformDurationMs(1000);
if(m_current > 1s) {
m_current = 1s;
m_direction = 0;
}
lSLID_VALUE = m_current / PlatformDurationMs(10);
lSLID_VALUE = m_current / 10ms;
} else if(m_direction == -1) {
m_current -= g_platformTime.lastFrameDuration();

if(m_current < 0) {
m_current = 0;
m_direction = 0;
}
lSLID_VALUE = m_current / PlatformDurationMs(10);
lSLID_VALUE = m_current / 10ms;
}
}

Expand Down

0 comments on commit 4e7f367

Please sign in to comment.