add StateMachine
This commit is contained in:
24
src/main.cpp
24
src/main.cpp
@@ -1,6 +1,7 @@
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <fstream>
|
||||
#include <td/game/World.h>
|
||||
#include <td/input/Display.h>
|
||||
#include <td/protocol/packet/PacketSerialize.h>
|
||||
@@ -102,6 +103,14 @@ void FastForward(td::game::World& a_World, const td::sim::GameHistory& a_LockSte
|
||||
}
|
||||
}
|
||||
|
||||
float GetDelta() {
|
||||
static std::chrono::time_point<std::chrono::system_clock> m_LastTime = std::chrono::system_clock::now();
|
||||
auto timeElapsed = std::chrono::system_clock::now() - m_LastTime;
|
||||
float timeSeconds = std::chrono::duration<float, std::chrono::seconds::period>(timeElapsed).count();
|
||||
m_LastTime = std::chrono::system_clock::now();
|
||||
return timeSeconds;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
td::game::WorldPtr serverWorld = GetWorld();
|
||||
|
||||
@@ -132,7 +141,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
td::sim::ClientSimulation simulation(*clientWorld, td::STEP_TIME);
|
||||
ClientHandler clientHandler(simulation);
|
||||
|
||||
|
||||
// packets from the server to the client
|
||||
clientFakeSocket->OnReceive.Connect([&clientHandler](const td::protocol::PacketBase& a_Packet) {
|
||||
a_Packet.Dispatch(clientHandler);
|
||||
@@ -151,14 +160,15 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
});
|
||||
|
||||
server.UpdateState(std::make_shared<td::server::GameState>(serverWorld));
|
||||
client.UpdateState(std::make_shared<td::client::GameState>(clientWorld));
|
||||
server.ChangeState<td::server::GameState>(serverWorld);
|
||||
client.ChangeState<td::client::GameState>(clientWorld);
|
||||
|
||||
while (!display.IsCloseRequested()) {
|
||||
display.PollEvents();
|
||||
server.Update();
|
||||
client.Update();
|
||||
float lerp = simulation.Update();
|
||||
float delta = GetDelta();
|
||||
server.Update(delta);
|
||||
client.Update(delta);
|
||||
float lerp = simulation.Update(delta);
|
||||
renderer.Render(lerp);
|
||||
display.Update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user