From 2f2a128e06716327c7483333b59c347509413eff Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 21 Sep 2018 16:12:04 +0800 Subject: [PATCH 1/4] Fix missing initialized values --- src/items/item.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/items/item.cpp b/src/items/item.cpp index c0b375d53..ad68f7bbb 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -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) // ------------------------------------------------------------------------ From aa2d94481322847ba62b6b77b8bb463bd303d86c Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 21 Sep 2018 16:13:19 +0800 Subject: [PATCH 2/4] Use setTicksForRewind for count down game timer --- src/items/network_item_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/items/network_item_manager.cpp b/src/items/network_item_manager.cpp index a6ed824e3..76eb030ba 100644 --- a/src/items/network_item_manager.cpp +++ b/src/items/network_item_manager.cpp @@ -317,9 +317,9 @@ 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 + world->setTicksForRewind(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(old_time); // Set time to rewind-to if (m_confirmed_state[index]->isUsedUp()) { From b1a535b21ffdcdda7b38498fb2e2075bb21da9c5 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 21 Sep 2018 20:06:47 +0800 Subject: [PATCH 3/4] Save ticks till return for eating banana with bomb --- src/items/item_event_info.cpp | 12 ++++++++---- src/items/item_event_info.hpp | 21 ++++++++++++++++----- src/items/network_item_manager.cpp | 10 ++++++++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/items/item_event_info.cpp b/src/items/item_event_info.cpp index f9d97ea49..6acb38d5b 100644 --- a/src/items/item_event_info.cpp +++ b/src/items/item_event_info.cpp @@ -31,6 +31,7 @@ */ ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count) { + m_ticks_till_return = 0; m_type = (EventType)buffer->getUInt8(); m_ticks = buffer->getTime(); m_kart_id = buffer->getInt8(); @@ -41,7 +42,11 @@ ItemEventInfo::ItemEventInfo(BareNetworkString *buffer, int *count) m_xyz = buffer->getVec3(); *count -= 12; } - + else if (m_type == IEI_COLLECT) + { + m_ticks_till_return = buffer->getUInt16(); + *count -= 2; + } } // ItemEventInfo(BareNetworkString, int *count) //----------------------------------------------------------------------------- @@ -55,7 +60,6 @@ void ItemEventInfo::saveState(BareNetworkString *buffer) .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 - - - \ No newline at end of file diff --git a/src/items/item_event_info.hpp b/src/items/item_event_info.hpp index 35499baf2..ddb246922 100644 --- a/src/items/item_event_info.hpp +++ b/src/items/item_event_info.hpp @@ -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 diff --git a/src/items/network_item_manager.cpp b/src/items/network_item_manager.cpp index 76eb030ba..b77cce037 100644 --- a/src/items/network_item_manager.cpp +++ b/src/items/network_item_manager.cpp @@ -99,13 +99,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 { @@ -319,6 +320,11 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count) int old_time = world->getTicksSinceStart(); // Save time we rewind to world->setTicksForRewind(iei.getTicks()); // Set time of event collectedItem(m_confirmed_state[index], 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()) From 553747237e052ff0b9c968ae8a8538b3423f0261 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 22 Sep 2018 00:54:37 +0800 Subject: [PATCH 4/4] Check for possible null m_confirmed_state --- src/items/network_item_manager.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/items/network_item_manager.cpp b/src/items/network_item_manager.cpp index b77cce037..5882b0f87 100644 --- a/src/items/network_item_manager.cpp +++ b/src/items/network_item_manager.cpp @@ -319,11 +319,14 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count) // otherwise resulting in stuttering). int old_time = world->getTicksSinceStart(); // Save time we rewind to world->setTicksForRewind(iei.getTicks()); // Set time of event - collectedItem(m_confirmed_state[index], 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); + 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