@@ -44,7 +44,7 @@ void Game::loadSystems(Engine::ECS::Registry ®istry, const std::string &scene
44
44
if (sysName == " position" )
45
45
registry.add_system ([this ](Engine::ECS::Registry &r) { Engine::ECS::Systems::_2D::position (r, _deltaTime); });
46
46
47
- else if (name == " apply_movable" )
47
+ else if (sysName == " apply_movable" )
48
48
registry.add_system (
49
49
[this ](Engine::ECS::Registry &r) { Engine::ECS::Systems::_3D::apply_movable (r, _deltaTime); });
50
50
@@ -158,8 +158,7 @@ void Game::sendOnSameScene(const std::string &sceneName, Protocol::Packet<Protoc
158
158
159
159
packet.header ._apiVersion = player->getApiVersion ();
160
160
161
- ClientManager::GetInstance ().sendPacketToClient (player->getAddress (), packet.serialize ());
162
- ClientManager::UnlockInstance ();
161
+ player->addPacketToSendQueue (packet);
163
162
}
164
163
}
165
164
@@ -179,8 +178,7 @@ void Game::sendOnSameSceneExcept(const std::string &sceneName, Protocol::Packet<
179
178
180
179
packet.header ._apiVersion = player->getApiVersion ();
181
180
182
- ClientManager::GetInstance ().sendPacketToClient (player->getAddress (), packet.serialize ());
183
- ClientManager::UnlockInstance ();
181
+ player->addPacketToSendQueue (packet);
184
182
}
185
183
}
186
184
@@ -343,21 +341,44 @@ void Game::updateIncomingPackets(unsigned char maxMessagePerFrame)
343
341
FLAKKARI_LOG_INFO (" packet received: " + packet.to_string ());
344
342
messageCount--;
345
343
346
- if (packet.header ._commandId == Protocol::CommandId::REQ_USER_UPDATE )
347
- handleEvent (player, packet);
344
+ if (packet.header ._commandId == Protocol::CommandId::REQ_USER_UPDATES )
345
+ handleEvents (player, packet);
348
346
349
- if (packet.header ._commandId == Protocol::CommandId::REQ_HEARTBEAT)
347
+ else if (packet.header ._commandId == Protocol::CommandId::REQ_HEARTBEAT)
350
348
{
351
349
Protocol::Packet<Protocol::CommandId> repPacket;
352
- repPacket.header ._commandId = Protocol::CommandId::REP_HEARTBEAT;
353
350
repPacket.header ._apiVersion = packet.header ._apiVersion ;
354
- ClientManager::GetInstance ().sendPacketToClient (player->getAddress (), repPacket.serialize ());
355
- ClientManager::UnlockInstance ();
351
+ repPacket.header ._commandId = Protocol::CommandId::REP_HEARTBEAT;
352
+
353
+ player->addPacketToSendQueue (repPacket);
356
354
}
357
355
}
358
356
}
359
357
}
360
358
359
+ void Game::updateOutcomingPackets (unsigned char maxMessagePerFrame)
360
+ {
361
+ for (auto &player : _players)
362
+ {
363
+ if (!player->isConnected ())
364
+ continue ;
365
+ auto &packets = player->getSendQueue ();
366
+ auto messageCount = maxMessagePerFrame;
367
+
368
+ Network::Buffer buffer;
369
+
370
+ while (!packets.empty () && messageCount > 0 )
371
+ {
372
+ auto packet = packets.pop_front ();
373
+ messageCount--;
374
+
375
+ buffer += packet.serialize ();
376
+ ClientManager::GetInstance ().sendPacketToClient (player->getAddress (), buffer);
377
+ ClientManager::UnlockInstance ();
378
+ }
379
+ }
380
+ }
381
+
361
382
void Game::update ()
362
383
{
363
384
auto now = std::chrono::steady_clock::now ();
0 commit comments