#1 - quicr module
This commit is contained in:
@@ -25,7 +25,6 @@ ZoneServer::ZoneServer(ZoneServerConfiguration config)
|
||||
m_network_receiver(std::make_unique<NetworkReceiver>(
|
||||
m_player_session_registry.get(), config.quicr_port, m_metrics_reporter.get()
|
||||
)),
|
||||
m_message_dispatcher(std::make_unique<MessageDispatcher>(m_network_receiver.get())),
|
||||
m_replicator(std::make_unique<StateReplicator<SpatialBackendType>>(
|
||||
m_player_session_registry.get(),
|
||||
m_network_receiver.get()
|
||||
@@ -58,9 +57,16 @@ ZoneServer::ZoneServer(ZoneServerConfiguration config)
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneServer::player_update_handler(SessionId session_id, mmo::PlayerMoveMessage&& message) {
|
||||
void ZoneServer::player_update_handler(SessionId session_id, mmo::PlayerMoveMessage message) {
|
||||
auto it = m_session_zone.find(session_id);
|
||||
if (it == m_session_zone.end()) return;
|
||||
|
||||
// Echoed back in the next snapshot, so the client can tell how long its
|
||||
// input took to come back.
|
||||
if (auto* session = m_player_session_registry->session(session_id)) {
|
||||
session->last_frame = message.frame_idx();
|
||||
}
|
||||
|
||||
it->second->on_player_move(session_id, std::move(message));
|
||||
}
|
||||
|
||||
@@ -80,7 +86,6 @@ static void register_signal_handler() {
|
||||
|
||||
void ZoneServer::update_clients(uint32_t frame_idx) {
|
||||
m_network_receiver->update();
|
||||
m_message_dispatcher->drain_queue();
|
||||
|
||||
while (m_network_receiver->peek_new_session()) {
|
||||
auto session_id = m_network_receiver->pop_new_session();
|
||||
@@ -96,6 +101,10 @@ void ZoneServer::update_clients(uint32_t frame_idx) {
|
||||
zone->add_client(session_id, entity);
|
||||
m_session_zone[session_id] = zone;
|
||||
|
||||
mmo::SetControlledEntity mesg = {};
|
||||
mesg.set_entity_id((uint32_t)entity);
|
||||
m_network_receiver->send_mesg(session_id, mesg);
|
||||
|
||||
spdlog::info("Client {} connected", session_id);
|
||||
}
|
||||
}
|
||||
@@ -106,13 +115,13 @@ void ZoneServer::run() {
|
||||
|
||||
uint32_t frame_idx = 1;
|
||||
|
||||
m_message_dispatcher->set_handler<mmo::PlayerMoveMessage>(
|
||||
[&](uint64_t session_id, mmo::PlayerMoveMessage mesg) {
|
||||
player_update_handler(static_cast<SessionId>(session_id), std::move(mesg));
|
||||
m_network_receiver->set_handler<mmo::PlayerMoveMessage>(
|
||||
[this](SessionId session_id, const mmo::PlayerMoveMessage& mesg) {
|
||||
player_update_handler(session_id, mesg);
|
||||
});
|
||||
|
||||
m_message_dispatcher->set_handler<mmo::chat::SendChatMessageRequest>(
|
||||
[&](uint64_t session_id, mmo::chat::SendChatMessageRequest mesg) {
|
||||
m_network_receiver->set_handler<mmo::chat::SendChatMessageRequest>(
|
||||
[this](SessionId session_id, const mmo::chat::SendChatMessageRequest& mesg) {
|
||||
});
|
||||
|
||||
while (!quit.load()) {
|
||||
@@ -127,6 +136,16 @@ void ZoneServer::run() {
|
||||
for (auto& zone : m_zones) {
|
||||
zone->tick(frame_idx, lock_step.delta_time());
|
||||
|
||||
// Copy acked frames from zone to sessions before replication.
|
||||
// This ensures snapshots carry the input frame actually consumed by this tick,
|
||||
// not frames that arrive in the trailing network update.
|
||||
for (const auto& [session_id, session_zone] : m_session_zone) {
|
||||
if (session_zone != zone.get()) continue;
|
||||
if (auto* session = m_player_session_registry->session(session_id)) {
|
||||
session->acked_frame = zone->acked_input_frame(session_id);
|
||||
}
|
||||
}
|
||||
|
||||
m_replicator->replicate(zone->registry(), zone->interest());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user