mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Start race recording immediately so we can also record the preparation steps
This commit is contained in:
parent
0721b895ae
commit
456a67fe2d
|
@ -9,7 +9,7 @@
|
||||||
#include "race.h"
|
#include "race.h"
|
||||||
#include "race_demo.h"
|
#include "race_demo.h"
|
||||||
|
|
||||||
CRaceDemo::CRaceDemo() : m_RaceState(RACE_NONE), m_RecordStartTick(-1), m_RecordStopTick(-1), m_Time(0) {}
|
CRaceDemo::CRaceDemo() : m_RaceState(RACE_NONE), m_RaceStartTick(-1), m_RecordStopTick(-1), m_Time(0) {}
|
||||||
|
|
||||||
void CRaceDemo::OnStateChange(int NewState, int OldState)
|
void CRaceDemo::OnStateChange(int NewState, int OldState)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,8 @@ void CRaceDemo::OnRender()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// start the demo
|
// start the demo
|
||||||
if((m_RaceState == RACE_NONE || !m_IsSolo) && m_RecordStartTick + Client()->GameTickSpeed() < Client()->GameTick())
|
bool AllowRestart = !m_IsSolo && m_RaceStartTick + 10 * Client()->GameTickSpeed() < Client()->GameTick();
|
||||||
|
if(m_RaceState == RACE_IDLE || m_RaceState == RACE_PREPARE || (m_RaceState == RACE_STARTED && AllowRestart))
|
||||||
{
|
{
|
||||||
vec2 PrevPos = vec2(m_pClient->m_Snap.m_pLocalPrevCharacter->m_X, m_pClient->m_Snap.m_pLocalPrevCharacter->m_Y);
|
vec2 PrevPos = vec2(m_pClient->m_Snap.m_pLocalPrevCharacter->m_X, m_pClient->m_Snap.m_pLocalPrevCharacter->m_Y);
|
||||||
vec2 Pos = vec2(m_pClient->m_Snap.m_pLocalCharacter->m_X, m_pClient->m_Snap.m_pLocalCharacter->m_Y);
|
vec2 Pos = vec2(m_pClient->m_Snap.m_pLocalCharacter->m_X, m_pClient->m_Snap.m_pLocalCharacter->m_Y);
|
||||||
|
@ -37,13 +38,29 @@ void CRaceDemo::OnRender()
|
||||||
if(CRaceHelper::IsStart(m_pClient, m_pClient->m_PredictedPrevChar.m_Pos, m_pClient->m_LocalCharacterPos))
|
if(CRaceHelper::IsStart(m_pClient, m_pClient->m_PredictedPrevChar.m_Pos, m_pClient->m_LocalCharacterPos))
|
||||||
{
|
{
|
||||||
if(m_RaceState == RACE_STARTED)
|
if(m_RaceState == RACE_STARTED)
|
||||||
OnReset();
|
Client()->RaceRecord_Stop();
|
||||||
|
if(m_RaceState != RACE_PREPARE) // start recording again
|
||||||
Client()->RaceRecord_Start();
|
Client()->RaceRecord_Start();
|
||||||
m_RecordStartTick = Client()->GameTick();
|
m_RaceStartTick = Client()->GameTick();
|
||||||
m_RaceState = RACE_STARTED;
|
m_RaceState = RACE_STARTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start recording before the player passes the start line, so we can see some preparation steps
|
||||||
|
if(m_RaceState == RACE_NONE)
|
||||||
|
{
|
||||||
|
Client()->RaceRecord_Start();
|
||||||
|
m_RaceStartTick = Client()->GameTick();
|
||||||
|
m_RaceState = RACE_PREPARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop recording if the player did not pass the start line after 20 seconds
|
||||||
|
if(m_RaceState == RACE_PREPARE && Client()->GameTick() - m_RaceStartTick >= Client()->GameTickSpeed() * 20)
|
||||||
|
{
|
||||||
|
OnReset();
|
||||||
|
m_RaceState = RACE_IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
// stop the demo
|
// stop the demo
|
||||||
if(m_RaceState == RACE_FINISHED && m_RecordStopTick <= Client()->GameTick())
|
if(m_RaceState == RACE_FINISHED && m_RecordStopTick <= Client()->GameTick())
|
||||||
StopRecord(m_Time);
|
StopRecord(m_Time);
|
||||||
|
@ -118,7 +135,7 @@ void CRaceDemo::StopRecord(int Time)
|
||||||
|
|
||||||
m_Time = 0;
|
m_Time = 0;
|
||||||
m_RaceState = RACE_NONE;
|
m_RaceState = RACE_NONE;
|
||||||
m_RecordStartTick = -1;
|
m_RaceStartTick = -1;
|
||||||
m_RecordStopTick = -1;
|
m_RecordStopTick = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,14 @@ class CRaceDemo : public CComponent
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
RACE_NONE = 0,
|
RACE_NONE = 0,
|
||||||
|
RACE_IDLE,
|
||||||
|
RACE_PREPARE,
|
||||||
RACE_STARTED,
|
RACE_STARTED,
|
||||||
RACE_FINISHED,
|
RACE_FINISHED,
|
||||||
};
|
};
|
||||||
|
|
||||||
int m_RaceState;
|
int m_RaceState;
|
||||||
int m_RecordStartTick;
|
int m_RaceStartTick;
|
||||||
int m_RecordStopTick;
|
int m_RecordStopTick;
|
||||||
int m_Time;
|
int m_Time;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue