add debug fastforward
This commit is contained in:
@@ -25,8 +25,8 @@ void GameState::Update(float a_Delta) {
|
|||||||
// TODO: don't make STEP_TIME constant
|
// TODO: don't make STEP_TIME constant
|
||||||
static const float stepTimeSecond = static_cast<float>(STEP_TIME) / 1000.0f;
|
static const float stepTimeSecond = static_cast<float>(STEP_TIME) / 1000.0f;
|
||||||
m_Time += a_Delta;
|
m_Time += a_Delta;
|
||||||
if (m_Time > stepTimeSecond) {
|
while (m_Time > stepTimeSecond) {
|
||||||
m_Time = std::fmod(m_Time, stepTimeSecond);
|
m_Time -= stepTimeSecond;
|
||||||
auto lockStepPacket = m_Simulation.Update();
|
auto lockStepPacket = m_Simulation.Update();
|
||||||
BroadcastPacket(lockStepPacket);
|
BroadcastPacket(lockStepPacket);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ DebugWorldState::DebugWorldState(Display& a_Display) : DisplayState(a_Display) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
list.OnPlayerKick.Connect([this](PlayerID a_Player) {
|
list.OnPlayerKick.Connect([this](PlayerID a_Player) {
|
||||||
auto it = std::find_if(m_FakeClients.begin(), m_FakeClients.end(), [a_Player](auto& clientPtr){
|
auto it = std::find_if(m_FakeClients.begin(), m_FakeClients.end(), [a_Player](auto& clientPtr) {
|
||||||
if (!clientPtr->GetId().has_value())
|
if (!clientPtr->GetId().has_value())
|
||||||
return false;
|
return false;
|
||||||
return clientPtr->GetId().value() == a_Player;
|
return clientPtr->GetId().value() == a_Player;
|
||||||
@@ -85,6 +85,7 @@ void DebugWorldState::OnAspectRatioChange(float a_Ratio) {
|
|||||||
|
|
||||||
void DebugWorldState::OnKeyDown(SDL_Keycode a_Key) {
|
void DebugWorldState::OnKeyDown(SDL_Keycode a_Key) {
|
||||||
// temporary tests
|
// temporary tests
|
||||||
|
constexpr int SECONDS = 10;
|
||||||
switch (a_Key) {
|
switch (a_Key) {
|
||||||
case SDLK_A:
|
case SDLK_A:
|
||||||
m_Client->SendPacket(td::protocol::packets::SpawnTroopPacket(td::EntityType::Zombie, 1));
|
m_Client->SendPacket(td::protocol::packets::SpawnTroopPacket(td::EntityType::Zombie, 1));
|
||||||
@@ -94,6 +95,11 @@ void DebugWorldState::OnKeyDown(SDL_Keycode a_Key) {
|
|||||||
m_Client->SendPacket(td::protocol::packets::PlaceTowerPacket(td::TowerType::Archer, td::TowerCoords(77, 13)));
|
m_Client->SendPacket(td::protocol::packets::PlaceTowerPacket(td::TowerType::Archer, td::TowerCoords(77, 13)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDLK_F:
|
||||||
|
m_Server->Update(SECONDS);
|
||||||
|
m_Client->Update(SECONDS);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ float ClientSimulation::Update(float a_Delta) {
|
|||||||
// TODO: handle freezes (m_CurrentTime > 2 * m_StepTime)
|
// TODO: handle freezes (m_CurrentTime > 2 * m_StepTime)
|
||||||
static const float stepTimeSecond = static_cast<float>(m_StepTime) / 1000.0f;
|
static const float stepTimeSecond = static_cast<float>(m_StepTime) / 1000.0f;
|
||||||
m_CurrentTime += a_Delta;
|
m_CurrentTime += a_Delta;
|
||||||
if (m_CurrentTime > stepTimeSecond) {
|
while (m_CurrentTime > stepTimeSecond) {
|
||||||
m_CurrentTime = std::fmod(m_CurrentTime, stepTimeSecond);
|
m_CurrentTime -= stepTimeSecond;
|
||||||
Step();
|
Step();
|
||||||
}
|
}
|
||||||
return (float)m_CurrentTime / stepTimeSecond;
|
return (float)m_CurrentTime / stepTimeSecond;
|
||||||
|
|||||||
Reference in New Issue
Block a user