M*SYNCs
This commit is contained in:
parent
bd3f677118
commit
981d66c730
@ -200,6 +200,22 @@ void Server::Run() {
|
||||
sync.timer = m_game.countdown;
|
||||
sendPack<Sync>(conn->getSock(), &sync, &m_buf);
|
||||
}
|
||||
int clients_ready = 0;
|
||||
|
||||
while (clients_ready < players) {
|
||||
Packet pck = getPack(&m_buf);
|
||||
if (pck.type != PACKET_TYPE::SYNC) {
|
||||
Log("Paquet invalide.", true, false);
|
||||
if (pck.type != PACKET_TYPE::ERR)
|
||||
netprot::emptyPack(pck);
|
||||
continue;
|
||||
}
|
||||
Sync* sync = (Sync*)pck.ptr;
|
||||
clients_ready++;
|
||||
//m_players[sync->sid]
|
||||
delete sync;
|
||||
}
|
||||
|
||||
|
||||
while (!endgame) {
|
||||
for (auto& [key, conn] : m_players) {
|
||||
|
@ -1280,6 +1280,7 @@ void Engine::Render(float elapsedTime) {
|
||||
}
|
||||
|
||||
if (m_networkgame) { // Pour se gerer le paquet.
|
||||
static bool has_synced = false;
|
||||
using namespace std::chrono;
|
||||
using namespace netprot;
|
||||
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count();
|
||||
@ -1290,14 +1291,17 @@ void Engine::Render(float elapsedTime) {
|
||||
static uint64_t sync_acc = 0;
|
||||
sync_acc += tstamp;
|
||||
|
||||
if (sync_acc >= 1000) {
|
||||
if (sync_acc >= 1000 || !has_synced) {
|
||||
sync_acc -= 1000;
|
||||
sync.sid = id;
|
||||
sync.timestamp = tstamp;
|
||||
sync.position = m_player.GetPositionAbs();
|
||||
sync.hp = m_player.GetHP();
|
||||
|
||||
// TODO: Garrocher ca quelque-part.
|
||||
if (!has_synced) {
|
||||
has_synced = true;
|
||||
sendPackTo<Sync>(m_conn.m_sock_udp, &sync, &m_bufout, &m_conn.m_srvsockaddr);
|
||||
}
|
||||
m_syncs[sync.timestamp] = sync;
|
||||
}
|
||||
|
||||
input.sid = id;
|
||||
|
@ -166,7 +166,8 @@ private:
|
||||
|
||||
bool m_networkgame = false;
|
||||
netprot::PlayerInfo m_pinfo;
|
||||
RemotePlayer m_remotePlayer = RemotePlayer(netprot::PlayerInfo(),Vector3f(5.5f, CHUNK_SIZE_Y + 1.8f, 5.5f));
|
||||
std::unordered_map<uint64_t, netprot::Sync> m_syncs;
|
||||
//RemotePlayer m_remotePlayer = RemotePlayer(netprot::PlayerInfo(),Vector3f(5.5f, CHUNK_SIZE_Y + 1.8f, 5.5f));
|
||||
std::string m_messageNotification = "";
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user