CLients now predict item (predictions are not synched with server,

so the item will chance once the server update is received atm).
This commit is contained in:
hiker 2018-05-10 23:23:23 +10:00
parent 8f2b991e6a
commit ff6d5119b4
3 changed files with 10 additions and 12 deletions

View File

@ -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

View File

@ -102,9 +102,6 @@ private:
/** List of all items events. */
Synchronised< std::vector<ItemEventInfo> > m_item_events;
/** Time of the last confirmed event. */
int m_last_confirmed_event;
void forwardTime(int ticks);
NetworkItemManager();

View File

@ -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;