Merge branch 'network-item-debugging' of github.com:supertuxkart/stk-code into network-item-debugging
This commit is contained in:
commit
465df8dcac
@ -49,8 +49,11 @@ ItemState::ItemState(ItemType type, const AbstractKart *owner, int id)
|
||||
setType(type);
|
||||
m_item_id = id;
|
||||
m_previous_owner = owner;
|
||||
if (owner)
|
||||
setDeactivatedTicks(stk_config->time2Ticks(1.5f));
|
||||
m_used_up_counter = -1;
|
||||
if (owner)
|
||||
setDeactivatedTicks(stk_config->time2Ticks(1.5f));
|
||||
else
|
||||
setDeactivatedTicks(0);
|
||||
} // ItemState(ItemType)
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -31,6 +31,7 @@
|
||||
*/
|
||||
ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count)
|
||||
{
|
||||
m_ticks_till_return = 0;
|
||||
m_type = (EventType)buffer->getUInt8();
|
||||
m_ticks = buffer->getTime();
|
||||
*count -= 5;
|
||||
@ -44,11 +45,15 @@ ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count)
|
||||
m_xyz = buffer->getVec3();
|
||||
*count -= 12;
|
||||
}
|
||||
else // IEI_COLLECT
|
||||
{
|
||||
m_ticks_till_return = buffer->getUInt16();
|
||||
*count -= 2;
|
||||
}
|
||||
} // is not switch
|
||||
else // switch
|
||||
{
|
||||
m_kart_id = -1;
|
||||
|
||||
}
|
||||
} // ItemEventInfo(BareNetworkString, int *count)
|
||||
|
||||
@ -66,8 +71,7 @@ void ItemEventInfo::saveState(BareNetworkString *buffer)
|
||||
buffer->addUInt8(m_kart_id).addUInt16(m_index);
|
||||
if (m_type == IEI_NEW)
|
||||
buffer->add(m_xyz);
|
||||
else if (m_type == IEI_COLLECT)
|
||||
buffer->addUInt16(m_ticks_till_return);
|
||||
}
|
||||
} // saveState
|
||||
|
||||
|
||||
|
@ -51,13 +51,20 @@ private:
|
||||
/** In case of new items the position of the new item. */
|
||||
Vec3 m_xyz;
|
||||
|
||||
/** Ticks for the item to return, atm used by collecting banana
|
||||
* with bomb to delay the return for banana. */
|
||||
int16_t m_ticks_till_return;
|
||||
|
||||
public:
|
||||
/** Constructor for collecting an existing item.
|
||||
* \param ticks Time of the event.
|
||||
* \param item_id The index of the item that was collected.
|
||||
* \param kart_id the kart that collected the item. */
|
||||
ItemEventInfo(int ticks, int index, int kart_id)
|
||||
: m_ticks(ticks), m_index(index), m_kart_id(kart_id)
|
||||
* \param kart_id the kart that collected the item.
|
||||
* \param ttr Ticks till return after being collected. */
|
||||
|
||||
ItemEventInfo(int ticks, int index, int kart_id, int16_t ttr)
|
||||
: m_ticks(ticks), m_index(index), m_kart_id(kart_id),
|
||||
m_ticks_till_return(ttr)
|
||||
{
|
||||
m_type = IEI_COLLECT;
|
||||
} // ItemEventInfo(collected existing item)
|
||||
@ -69,14 +76,15 @@ public:
|
||||
*/
|
||||
ItemEventInfo(int ticks, ItemState::ItemType type, int index,
|
||||
int kart_id, const Vec3 &xyz)
|
||||
: m_ticks(ticks), m_index(index), m_kart_id(kart_id), m_xyz(xyz)
|
||||
: m_ticks(ticks), m_index(index), m_kart_id(kart_id), m_xyz(xyz),
|
||||
m_ticks_till_return(0)
|
||||
{
|
||||
m_type = IEI_NEW;
|
||||
} // ItemEventInfo(new item)
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Constructor for switching items. */
|
||||
ItemEventInfo(int ticks) : m_ticks(ticks)
|
||||
ItemEventInfo(int ticks) : m_ticks(ticks), m_ticks_till_return(0)
|
||||
{
|
||||
m_type = IEI_SWITCH;
|
||||
} // ItemEventInfo(switch)
|
||||
@ -116,6 +124,9 @@ public:
|
||||
return m_xyz;
|
||||
} // getXYZ
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the ticks till return, used only by collection events. */
|
||||
int getTicksTillReturn() const { return m_ticks_till_return; }
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the type of this item. Note at this stage only bubble gums
|
||||
* can be created during a race. */
|
||||
ItemState::ItemType getNewItemType() const
|
||||
|
19
src/items/network_item_manager.cpp
Executable file → Normal file
19
src/items/network_item_manager.cpp
Executable file → Normal file
@ -101,13 +101,14 @@ void NetworkItemManager::collectedItem(ItemState *item, AbstractKart *kart)
|
||||
{
|
||||
if(NetworkConfig::get()->isServer())
|
||||
{
|
||||
ItemManager::collectedItem(item, kart);
|
||||
// The server saves the collected item as item event info
|
||||
m_item_events.lock();
|
||||
m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(),
|
||||
item->getItemId(),
|
||||
kart->getWorldKartId() );
|
||||
kart->getWorldKartId(),
|
||||
item->getTicksTillReturn());
|
||||
m_item_events.unlock();
|
||||
ItemManager::collectedItem(item, kart);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -360,9 +361,17 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
// example, bubble gum torque depends on time, and would be wrong
|
||||
// otherwise resulting in stuttering).
|
||||
int old_time = world->getTicksSinceStart(); // Save time we rewind to
|
||||
world->setTicks(iei.getTicks()); // Set time of event
|
||||
collectedItem(m_confirmed_state[index], kart);// Collect item
|
||||
world->setTicks(old_time); // Set time to rewind-to
|
||||
world->setTicksForRewind(iei.getTicks()); // Set time of event
|
||||
|
||||
if (m_confirmed_state[index] != NULL)
|
||||
{
|
||||
m_confirmed_state[index]->collected(kart);// Collect item
|
||||
// Reset till ticks return from state (required for eating banana with bomb)
|
||||
int ttr = iei.getTicksTillReturn();
|
||||
m_confirmed_state[index]->setTicksTillReturn(ttr);
|
||||
}
|
||||
|
||||
world->setTicksForRewind(old_time); // Set time to rewind-to
|
||||
|
||||
if (m_confirmed_state[index]->isUsedUp())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user