re3/src/core/Clock.cpp

118 lines
2.6 KiB
C++
Raw Normal View History

2019-05-15 14:52:37 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2019-05-15 14:52:37 +00:00
#include "Timer.h"
#include "Pad.h"
#include "Clock.h"
2019-06-13 00:35:26 +00:00
#include "Stats.h"
_TODO("gbFastTime");
2020-04-17 05:54:14 +00:00
bool gbFastTime;
2019-05-15 14:52:37 +00:00
2020-04-17 05:54:14 +00:00
uint8 CClock::ms_nGameClockHours;
uint8 CClock::ms_nGameClockMinutes;
uint16 CClock::ms_nGameClockSeconds;
uint8 CClock::ms_Stored_nGameClockHours;
uint8 CClock::ms_Stored_nGameClockMinutes;
uint16 CClock::ms_Stored_nGameClockSeconds;
uint32 CClock::ms_nMillisecondsPerGameMinute;
uint32 CClock::ms_nLastClockTick;
bool CClock::ms_bClockHasBeenStored;
2019-05-15 14:52:37 +00:00
void
CClock::Initialise(uint32 scale)
{
debug("Initialising CClock...\n");
ms_nGameClockHours = 12;
ms_nGameClockMinutes = 0;
ms_nGameClockSeconds = 0;
ms_nMillisecondsPerGameMinute = scale;
ms_nLastClockTick = CTimer::GetTimeInMilliseconds();
ms_bClockHasBeenStored = false;
debug("CClock ready\n");
}
void
CClock::Update(void)
{
2019-06-13 00:35:26 +00:00
if(CPad::GetPad(1)->GetRightShoulder1())
{
2019-05-15 14:52:37 +00:00
ms_nGameClockMinutes += 8;
ms_nLastClockTick = CTimer::GetTimeInMilliseconds();
2019-06-13 00:35:26 +00:00
if(ms_nGameClockMinutes >= 60)
{
2019-05-15 14:52:37 +00:00
ms_nGameClockHours++;
ms_nGameClockMinutes = 0;
if(ms_nGameClockHours >= 24)
ms_nGameClockHours = 0;
}
2019-06-13 00:35:26 +00:00
}
else if(CTimer::GetTimeInMilliseconds() - ms_nLastClockTick > ms_nMillisecondsPerGameMinute || gbFastTime)
{
2019-05-15 14:52:37 +00:00
ms_nGameClockMinutes++;
ms_nLastClockTick += ms_nMillisecondsPerGameMinute;
2019-06-13 00:35:26 +00:00
if ( gbFastTime )
ms_nLastClockTick = CTimer::GetTimeInMilliseconds();
if(ms_nGameClockMinutes >= 60)
{
2019-05-15 14:52:37 +00:00
ms_nGameClockHours++;
ms_nGameClockMinutes = 0;
if(ms_nGameClockHours >= 24)
2019-06-13 00:35:26 +00:00
{
CStats::DaysPassed++;
2019-05-15 14:52:37 +00:00
ms_nGameClockHours = 0;
2019-06-13 00:35:26 +00:00
}
2019-05-15 14:52:37 +00:00
}
}
2019-07-10 09:36:47 +00:00
ms_nGameClockSeconds = 60 * (CTimer::GetTimeInMilliseconds() - ms_nLastClockTick) / ms_nMillisecondsPerGameMinute;
2019-05-15 14:52:37 +00:00
}
void
CClock::SetGameClock(uint8 h, uint8 m)
{
ms_nGameClockHours = h;
ms_nGameClockMinutes = m;
ms_nGameClockSeconds = 0;
ms_nLastClockTick = CTimer::GetTimeInMilliseconds();
}
int32
CClock::GetGameClockMinutesUntil(uint8 h, uint8 m)
{
int32 now, then;
now = ms_nGameClockHours*60 + ms_nGameClockMinutes;
then = h*60 + m;
if(then < now)
then += 24*60;
return then-now;
}
bool
CClock::GetIsTimeInRange(uint8 h1, uint8 h2)
{
if(h1 > h2)
return ms_nGameClockHours >= h1 || ms_nGameClockHours < h2;
else
return ms_nGameClockHours >= h1 && ms_nGameClockHours < h2;
}
void
CClock::StoreClock(void)
{
ms_Stored_nGameClockHours = ms_nGameClockHours;
ms_Stored_nGameClockMinutes = ms_nGameClockMinutes;
ms_Stored_nGameClockSeconds = ms_nGameClockSeconds;
ms_bClockHasBeenStored = true;
}
void
CClock::RestoreClock(void)
{
ms_nGameClockHours = ms_Stored_nGameClockHours;
ms_nGameClockMinutes = ms_Stored_nGameClockMinutes;
ms_nGameClockSeconds = ms_Stored_nGameClockSeconds;
}