Refactor demo speed setting, add 1.5x speed (fixes #568)

This commit is contained in:
Dennis Felsing 2016-10-28 09:31:22 +02:00
parent 795e68ec2b
commit c92e10914a
4 changed files with 17 additions and 32 deletions

View file

@ -10,6 +10,8 @@ enum
MAX_TIMELINE_MARKERS=64 MAX_TIMELINE_MARKERS=64
}; };
const double g_aSpeeds[] = {0.1f, 0.25f, 0.5f, 0.75f, 1.0f, 1.5f, 2.0f, 4.0f, 8.0f};
struct CDemoHeader struct CDemoHeader
{ {
unsigned char m_aMarker[7]; unsigned char m_aMarker[7];
@ -56,6 +58,7 @@ public:
~IDemoPlayer() {} ~IDemoPlayer() {}
virtual void SetSpeed(float Speed) = 0; virtual void SetSpeed(float Speed) = 0;
virtual void SetSpeedIndex(int Offset) = 0;
virtual int SetPos(float Percent) = 0; virtual int SetPos(float Percent) = 0;
virtual void Pause() = 0; virtual void Pause() = 0;
virtual void Unpause() = 0; virtual void Unpause() = 0;

View file

@ -369,6 +369,7 @@ CDemoPlayer::CDemoPlayer(class CSnapshotDelta *pSnapshotDelta)
{ {
m_File = 0; m_File = 0;
m_pKeyFrames = 0; m_pKeyFrames = 0;
m_SpeedIndex = 4;
m_pSnapshotDelta = pSnapshotDelta; m_pSnapshotDelta = pSnapshotDelta;
m_LastSnapshotDataSize = -1; m_LastSnapshotDataSize = -1;
@ -657,6 +658,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
m_Info.m_Info.m_CurrentTick = -1; m_Info.m_Info.m_CurrentTick = -1;
m_Info.m_PreviousTick = -1; m_Info.m_PreviousTick = -1;
m_Info.m_Info.m_Speed = 1; m_Info.m_Info.m_Speed = 1;
m_SpeedIndex = 4;
m_LastSnapshotDataSize = -1; m_LastSnapshotDataSize = -1;
@ -818,6 +820,12 @@ void CDemoPlayer::SetSpeed(float Speed)
m_Info.m_Info.m_Speed = Speed; m_Info.m_Info.m_Speed = Speed;
} }
void CDemoPlayer::SetSpeedIndex(int Offset)
{
m_SpeedIndex = clamp(m_SpeedIndex + Offset, 0, (int)(sizeof(g_aSpeeds)/sizeof(g_aSpeeds[0])-1));
SetSpeed(g_aSpeeds[m_SpeedIndex]);
}
int CDemoPlayer::Update(bool RealTime) int CDemoPlayer::Update(bool RealTime)
{ {
int64 Now = time_get(); int64 Now = time_get();

View file

@ -101,6 +101,7 @@ private:
char m_aFilename[256]; char m_aFilename[256];
CKeyFrame *m_pKeyFrames; CKeyFrame *m_pKeyFrames;
CMapInfo m_MapInfo; CMapInfo m_MapInfo;
int m_SpeedIndex;
CPlaybackInfo m_Info; CPlaybackInfo m_Info;
int m_DemoType; int m_DemoType;
@ -125,6 +126,7 @@ public:
void Unpause(); void Unpause();
int Stop(); int Stop();
void SetSpeed(float Speed); void SetSpeed(float Speed);
void SetSpeedIndex(int Offset);
int SetPos(float Percent); int SetPos(float Percent);
const CInfo *BaseInfo() const { return &m_Info.m_Info; } const CInfo *BaseInfo() const { return &m_Info.m_Info; }
void GetDemoName(char *pBuffer, int BufferSize) const; void GetDemoName(char *pBuffer, int BufferSize) const;

View file

@ -148,26 +148,12 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
// handle mousewheel independent of active menu // handle mousewheel independent of active menu
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
{ {
if(pInfo->m_Speed < 0.1f) DemoPlayer()->SetSpeed(0.1f); DemoPlayer()->SetSpeedIndex(+1);
else if(pInfo->m_Speed < 0.25f) DemoPlayer()->SetSpeed(0.25f);
else if(pInfo->m_Speed < 0.5f) DemoPlayer()->SetSpeed(0.5f);
else if(pInfo->m_Speed < 0.75f) DemoPlayer()->SetSpeed(0.75f);
else if(pInfo->m_Speed < 1.0f) DemoPlayer()->SetSpeed(1.0f);
else if(pInfo->m_Speed < 2.0f) DemoPlayer()->SetSpeed(2.0f);
else if(pInfo->m_Speed < 4.0f) DemoPlayer()->SetSpeed(4.0f);
else DemoPlayer()->SetSpeed(8.0f);
LastSpeedChange = time_get(); LastSpeedChange = time_get();
} }
else if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) else if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
{ {
if(pInfo->m_Speed > 4.0f) DemoPlayer()->SetSpeed(4.0f); DemoPlayer()->SetSpeedIndex(-1);
else if(pInfo->m_Speed > 2.0f) DemoPlayer()->SetSpeed(2.0f);
else if(pInfo->m_Speed > 1.0f) DemoPlayer()->SetSpeed(1.0f);
else if(pInfo->m_Speed > 0.75f) DemoPlayer()->SetSpeed(0.75f);
else if(pInfo->m_Speed > 0.5f) DemoPlayer()->SetSpeed(0.5f);
else if(pInfo->m_Speed > 0.25f) DemoPlayer()->SetSpeed(0.25f);
else if(pInfo->m_Speed > 0.1f) DemoPlayer()->SetSpeed(0.1f);
else DemoPlayer()->SetSpeed(0.05f);
LastSpeedChange = time_get(); LastSpeedChange = time_get();
} }
@ -422,26 +408,12 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
if(IncreaseDemoSpeed) if(IncreaseDemoSpeed)
{ {
if(pInfo->m_Speed < 0.1f) DemoPlayer()->SetSpeed(0.1f); DemoPlayer()->SetSpeedIndex(+1);
else if(pInfo->m_Speed < 0.25f) DemoPlayer()->SetSpeed(0.25f);
else if(pInfo->m_Speed < 0.5f) DemoPlayer()->SetSpeed(0.5f);
else if(pInfo->m_Speed < 0.75f) DemoPlayer()->SetSpeed(0.75f);
else if(pInfo->m_Speed < 1.0f) DemoPlayer()->SetSpeed(1.0f);
else if(pInfo->m_Speed < 2.0f) DemoPlayer()->SetSpeed(2.0f);
else if(pInfo->m_Speed < 4.0f) DemoPlayer()->SetSpeed(4.0f);
else DemoPlayer()->SetSpeed(8.0f);
LastSpeedChange = time_get(); LastSpeedChange = time_get();
} }
else if(DecreaseDemoSpeed) else if(DecreaseDemoSpeed)
{ {
if(pInfo->m_Speed > 4.0f) DemoPlayer()->SetSpeed(4.0f); DemoPlayer()->SetSpeedIndex(-1);
else if(pInfo->m_Speed > 2.0f) DemoPlayer()->SetSpeed(2.0f);
else if(pInfo->m_Speed > 1.0f) DemoPlayer()->SetSpeed(1.0f);
else if(pInfo->m_Speed > 0.75f) DemoPlayer()->SetSpeed(0.75f);
else if(pInfo->m_Speed > 0.5f) DemoPlayer()->SetSpeed(0.5f);
else if(pInfo->m_Speed > 0.25f) DemoPlayer()->SetSpeed(0.25f);
else if(pInfo->m_Speed > 0.1f) DemoPlayer()->SetSpeed(0.1f);
else DemoPlayer()->SetSpeed(0.05f);
LastSpeedChange = time_get(); LastSpeedChange = time_get();
} }
} }