@@ -25,7 +25,6 @@ Gekko::MessageSystem::MessageSystem()
2525 std::srand ((unsigned int )std::time (nullptr ));
2626 _session_magic = std::rand ();
2727
28- history = AdvantageHistory ();
2928 session_events = SessionEventSystem ();
3029}
3130
@@ -36,7 +35,6 @@ void Gekko::MessageSystem::Init(u8 num_players, u32 input_size)
3635
3736 _net_player_queue.resize (num_players);
3837
39- history.Init ();
4038}
4139
4240
@@ -198,7 +196,7 @@ void Gekko::MessageSystem::SendSyncResponse(NetAddress* addr, u16 magic)
198196 message->pkt .body = std::move (body);
199197}
200198
201- void Gekko::MessageSystem::SendInputAck (Handle player, Frame frame)
199+ void Gekko::MessageSystem::SendInputAck (Handle player, Frame frame, i8 local_advantage )
202200{
203201 auto plyr = GetPlayerByHandle (player);
204202
@@ -215,7 +213,7 @@ void Gekko::MessageSystem::SendInputAck(Handle player, Frame frame)
215213
216214 auto body = std::make_unique<InputAckMsg>();
217215 body->ack_frame = frame;
218- body->frame_advantage = history. GetLocalAdvantage () ;
216+ body->frame_advantage = local_advantage ;
219217
220218 message->pkt .body = std::move (body);
221219}
@@ -619,7 +617,6 @@ void Gekko::MessageSystem::OnInputs(NetAddress& addr, NetPacket& pkt)
619617
620618 const Frame start_frame = body->start_frame ;
621619 const u32 input_count = body->input_count ;
622- const Frame end_frame = start_frame + input_count;
623620
624621 const bool is_spectator = (pkt.header .type == SpectatorInputs);
625622
@@ -657,29 +654,19 @@ void Gekko::MessageSystem::OnInputs(NetAddress& addr, NetPacket& pkt)
657654void Gekko::MessageSystem::OnInputAck (NetAddress& addr, NetPacket& pkt)
658655{
659656 auto body = (InputAckMsg*)pkt.body .get ();
660- // we should just update the ack frame for all handles where the address matches
661- const Frame ack_frame = body->ack_frame ;
662- const i32 remote_advantage = body->frame_advantage ;
663- bool added_advantage = false ;
657+ const Frame ack_frame = body->ack_frame ;
658+ const i8 remote_advantage = (i8 )body->frame_advantage ;
664659
665- std::vector<std::unique_ptr<Player>>* current = &remotes;
666- for (u32 i = 0 ; i < 2 ; i++)
667- {
668- if (i == 1 ) {
669- current = &spectators;
660+ for (auto & player : remotes) {
661+ if (player->address .Equals (addr) && player->stats .last_acked_frame < ack_frame) {
662+ player->stats .last_acked_frame = ack_frame;
663+ player->adv_history .SetRemoteAdvantage (remote_advantage);
670664 }
665+ }
671666
672- for (auto & player : *current) {
673- if (player->address .Equals (addr)) {
674- if (player->stats .last_acked_frame < ack_frame) {
675- player->stats .last_acked_frame = ack_frame;
676- // only add remote advantages once
677- if (!added_advantage && i == 0 ) {
678- history.SetRemoteAdvantage (remote_advantage);
679- added_advantage = true ;
680- }
681- }
682- }
667+ for (auto & player : spectators) {
668+ if (player->address .Equals (addr) && player->stats .last_acked_frame < ack_frame) {
669+ player->stats .last_acked_frame = ack_frame;
683670 }
684671 }
685672}
@@ -923,6 +910,3 @@ void Gekko::AdvantageHistory::SetRemoteAdvantage(i8 adv) {
923910 _remote_frame_adv = adv;
924911}
925912
926- i8 Gekko::AdvantageHistory::GetLocalAdvantage () {
927- return _local_frame_adv;
928- }
0 commit comments