1
0
mirror of https://github.com/blawar/ooot.git synced 2024-06-30 16:29:55 +00:00

framete class tweaks

This commit is contained in:
Blake Warner 2022-04-09 17:18:40 -04:00
parent 14faa84c73
commit 1640ea6068
2 changed files with 88 additions and 17 deletions

View File

@ -76,9 +76,23 @@ u64 frameRateDivisor();
class Timer class Timer
{ {
public: public:
enum class Type
{
U8 = 0xFF,
S8 = 0X7F,
U16 = 0xFFFF,
S16 = 0x8000
};
Timer(); Timer();
Timer(const Timer& t); Timer(const Timer& t);
Timer(float n); Timer(float n);
Timer(float n, s64 min, s64 max);
Timer(s64 min, s64 max) : m_counter(0), m_counterInt(0), m_min(min), m_max(max)
{
}
float frac() const;
static Timer invalid(); static Timer invalid();
@ -121,19 +135,55 @@ class Timer
return (u16)m_counter; return (u16)m_counter;
} }
void setRange(s64 min, s64 max);
constexpr static float INVALID = -FRAMERATE_MAX / 20.0f; constexpr static float INVALID = -FRAMERATE_MAX / 20.0f;
protected: protected:
void update(); void update();
float m_counter; float m_counter;
s64 m_counterInt; s64 m_counterInt;
s64 m_min;
s64 m_max;
}; };
typedef Timer Counter; class TimerU8 : public Timer
{
public:
TimerU8() : Timer(-0x80, 0x7F)
{
}
TimerU8(const Timer& t) : Timer(t)
{
}
TimerU8(float n) : Timer(n, -0x80, 0x7F)
{
}
};
class TimerU16 : public Timer
{
public:
TimerU16() : Timer(-0x8000, 0x7FFF)
{
}
TimerU16(const Timer& t) : Timer(t)
{
}
TimerU16(float n) : Timer(n, -0x8000, 0x7FFF)
{
}
};
typedef TimerU16 Counter;
typedef Timer Rotation; typedef Timer Rotation;
typedef Timer Position; typedef Timer Position;
typedef Timer TimerU8; //typedef Timer TimerU8;
typedef Timer TimerU16; //typedef Timer TimerU16;
typedef Timer TimerS16; typedef Timer TimerS16;
typedef Timer TimerS32; typedef Timer TimerS32;
typedef Timer TimerU32; typedef Timer TimerU32;

View File

@ -79,7 +79,7 @@ u64 frameRateDivisor()
return R_UPDATE_RATE; return R_UPDATE_RATE;
} }
Timer::Timer() : m_counter(0), m_counterInt(0) Timer::Timer() : m_counter(0), m_counterInt(0), m_min(-0x8000), m_max(0x7FFF)
{ {
} }
@ -87,27 +87,38 @@ Timer::Timer(const Timer& t)
{ {
m_counter = t.m_counter; m_counter = t.m_counter;
m_counterInt = t.m_counterInt; m_counterInt = t.m_counterInt;
m_min = t.m_min;
m_max = t.m_max;
} }
Timer::Timer(float n) : m_counter(n), m_counterInt(n * COUNTER_SCALER)
Timer::Timer(float n) : m_counter(n), m_counterInt(n * COUNTER_SCALER), m_min(-0x8000), m_max(0x7FFF)
{ {
if(n == 0xFFFF) if(n == 0xFFFF)
{ {
bool error = true; bool error = true;
} }
/*if(m_counterInt == 0) }
Timer::Timer(float n, s64 min, s64 max) : m_counter(n), m_counterInt(n * COUNTER_SCALER), m_min(min), m_max(max)
{
if(n == 0xFFFF)
{ {
if(n < 1.0f && n > 0.0f) bool error = true;
{ }
m_counterInt = 1; }
update();
} void Timer::setRange(s64 min, s64 max)
else if(n > -1.0f && n < 0.0f) {
{ m_min = min;
m_counterInt = -1; m_max = max;
update(); }
}
}*/ float Timer::frac() const
{
float integer;
return modf(m_counter, &integer);
//return (m_counterInt % (s64)FRAMERATE_SCALER_INV) / (float)FRAMERATE_SCALER_INV;
} }
Timer Timer::invalid() Timer Timer::invalid()
@ -119,6 +130,16 @@ Timer Timer::invalid()
void Timer::update() void Timer::update()
{ {
while(m_counterInt > m_max * COUNTER_SCALER)
{
m_counterInt = (m_min * COUNTER_SCALER) + (m_counterInt - (m_max * COUNTER_SCALER + 1));
}
while(m_counterInt < m_min * COUNTER_SCALER)
{
m_counterInt = (m_max * COUNTER_SCALER) + (m_counterInt - (m_min * COUNTER_SCALER - 1));
}
m_counter = (float)m_counterInt * COUNTER_STEP; m_counter = (float)m_counterInt * COUNTER_STEP;
} }