From ff6d5119b4f58943b5004fdcfa74595096801242 Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 10 May 2018 23:23:23 +1000 Subject: [PATCH] CLients now predict item (predictions are not synched with server, so the item will chance once the server update is received atm). --- src/items/network_item_manager.cpp | 12 +++++++++--- src/items/network_item_manager.hpp | 3 --- src/karts/kart.cpp | 7 +------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/items/network_item_manager.cpp b/src/items/network_item_manager.cpp index 71777f4ed..f4d9848b1 100644 --- a/src/items/network_item_manager.cpp +++ b/src/items/network_item_manager.cpp @@ -22,6 +22,7 @@ #include "modes/world.hpp" #include "network/network_config.hpp" #include "network/protocols/game_protocol.hpp" +#include "network/rewind_manager.hpp" #include "network/stk_host.hpp" @@ -60,7 +61,6 @@ NetworkItemManager::~NetworkItemManager() //----------------------------------------------------------------------------- void NetworkItemManager::reset() { - m_last_confirmed_event = 0; ItemManager::reset(); } // reset @@ -70,7 +70,6 @@ void NetworkItemManager::reset() void NetworkItemManager::saveInitialState() { m_confirmed_state_time = 0; - m_last_confirmed_event = 0; m_confirmed_state.clear(); for(auto i : m_all_items) @@ -100,6 +99,12 @@ void NetworkItemManager::collectedItem(Item *item, AbstractKart *kart, m_item_events.unlock(); ItemManager::collectedItem(item, kart, add_info); } + else if (!RewindManager::get()->isRewinding()) + { + // If we are predicting (i.e. not rewinding), the client + // predicts item collection: + ItemManager::collectedItem(item, kart, add_info); + } } // collectedItem //----------------------------------------------------------------------------- @@ -265,9 +270,10 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count) Item *item = m_all_items[i]; const ItemState *is = m_confirmed_state[i]; item->setTicksTillReturn(is->getTicksTillReturn()); + *(ItemState*)item = *is; } // Now we save the current local - m_confirmed_state_time = m_last_confirmed_event; + m_confirmed_state_time = World::getWorld()->getTimeTicks(); } // restoreState diff --git a/src/items/network_item_manager.hpp b/src/items/network_item_manager.hpp index 11907d9e8..273073563 100644 --- a/src/items/network_item_manager.hpp +++ b/src/items/network_item_manager.hpp @@ -102,9 +102,6 @@ private: /** List of all items events. */ Synchronised< std::vector > m_item_events; - /** Time of the last confirmed event. */ - int m_last_confirmed_event; - void forwardTime(int ticks); NetworkItemManager(); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 5e1984752..0dabe5975 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -1612,12 +1612,7 @@ void Kart::update(int ticks) } // if there is material PROFILER_POP_CPU_MARKER(); - // Check if any item was hit. - // check it if we're not in a network world, or if we're on the server - // (when network mode is on) - if(!NetworkConfig::get()->isNetworking() || - NetworkConfig::get()->isServer() ) - ItemManager::get()->checkItemHit(this); + ItemManager::get()->checkItemHit(this); const bool emergency = getKartAnimation()!=NULL;