Envoi des millis avec les Inputs

This commit is contained in:
MarcEricMartel 2023-11-02 15:47:15 -04:00
parent f51305bd11
commit ac9174f793
2 changed files with 12 additions and 3 deletions

View File

@ -370,6 +370,8 @@ void Engine::Init() {
// Init Chunks // Init Chunks
m_world.GetChunks().Reset(nullptr); m_world.GetChunks().Reset(nullptr);
m_startTime = std::chrono::high_resolution_clock::now();
// Gestion de souris. // Gestion de souris.
CenterMouse(); CenterMouse();
HideCursor(); HideCursor();
@ -1102,11 +1104,13 @@ void Engine::Render(float elapsedTime) {
} }
if (m_networkgame) { if (m_networkgame) {
netprot::Input input; using namespace std::chrono;
using namespace netprot;
Input input;
input.sid = m_conn.getId(); input.sid = m_conn.getId();
input.direction = m_player.GetDirection(); input.direction = m_player.GetDirection();
input.timestamp = 12345; // TODO: Implémenter input.timestamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count();
input.keys.forward = m_keyW; input.keys.forward = m_keyW;
input.keys.backward = m_keyS; input.keys.backward = m_keyS;
input.keys.left = m_keyA; input.keys.left = m_keyA;
@ -1115,7 +1119,10 @@ void Engine::Render(float elapsedTime) {
input.keys.block = m_mouseR; input.keys.block = m_mouseR;
input.keys.shoot = m_mouseL; input.keys.shoot = m_mouseL;
netprot::sendPackTo<netprot::Input>(m_conn.m_sock_udp, &input, &m_buf, &m_conn.m_srvsockaddr); sendPackTo<Input>(m_conn.m_sock_udp, &input, &m_buf, &m_conn.m_srvsockaddr);
// TODO: Faire la gestion de la réception de paquets.
} }
} }
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS) else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)

View File

@ -2,6 +2,7 @@
#define ENGINE_H__ #define ENGINE_H__
#include <algorithm> #include <algorithm>
#include <chrono>
#include <cmath> #include <cmath>
#include "../SQCSim-common/array2d.h" #include "../SQCSim-common/array2d.h"
#include "../SQCSim-common/blockinfo.h" #include "../SQCSim-common/blockinfo.h"
@ -89,6 +90,7 @@ private:
std::map<uint64_t, Player*> m_players; std::map<uint64_t, Player*> m_players;
netprot::Buffer m_buf; netprot::Buffer m_buf;
std::chrono::high_resolution_clock::time_point m_startTime;
//Menu //Menu
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY }; enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };