Fixed bubble gum collection in networking (at least the problem
that you would on the client collect the gum you just dropped).
This commit is contained in:
parent
5955166931
commit
9211b26251
@ -37,6 +37,22 @@
|
|||||||
#include <ISceneManager.h>
|
#include <ISceneManager.h>
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Constructor.
|
||||||
|
* \param type Type of the item.
|
||||||
|
* \param owner If not NULL it is the kart that dropped this item; NULL
|
||||||
|
* indicates an item that's part of the track.
|
||||||
|
* \param id Index of this item in the array of all items.
|
||||||
|
*/
|
||||||
|
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));
|
||||||
|
} // ItemState(ItemType)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Sets the disappear counter depending on type. */
|
/** Sets the disappear counter depending on type. */
|
||||||
void ItemState::setDisappearCounter()
|
void ItemState::setDisappearCounter()
|
||||||
@ -52,9 +68,23 @@ void ItemState::setDisappearCounter()
|
|||||||
} // switch
|
} // switch
|
||||||
} // setDisappearCounter
|
} // setDisappearCounter
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
/** Initialises an item.
|
||||||
|
* \param type Type for this item.
|
||||||
|
*/
|
||||||
|
void ItemState::initItem(ItemType type, const Vec3& xyz)
|
||||||
|
{
|
||||||
|
m_xyz = xyz;
|
||||||
|
m_original_type = ITEM_NONE;
|
||||||
|
m_ticks_till_return = 0;
|
||||||
|
setDisappearCounter();
|
||||||
|
} // initItem
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Update the state of the item, called once per physics frame.
|
/** Update the state of the item, called once per physics frame.
|
||||||
* \param ticks Number of ticks to simulate (typically 1).
|
* \param ticks Number of ticks to simulate. While this value is 1 when
|
||||||
|
* called during the normal game loop, during a rewind this value
|
||||||
|
* can be (much) larger than 1.
|
||||||
*/
|
*/
|
||||||
void ItemState::update(int ticks)
|
void ItemState::update(int ticks)
|
||||||
{
|
{
|
||||||
@ -117,7 +147,7 @@ void ItemState::collected(const AbstractKart *kart)
|
|||||||
Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||||
scene::IMesh* mesh, scene::IMesh* lowres_mesh,
|
scene::IMesh* mesh, scene::IMesh* lowres_mesh,
|
||||||
const AbstractKart *owner, bool is_predicted)
|
const AbstractKart *owner, bool is_predicted)
|
||||||
: ItemState(type)
|
: ItemState(type, owner)
|
||||||
{
|
{
|
||||||
assert(type != ITEM_TRIGGER); // use other constructor for that
|
assert(type != ITEM_TRIGGER); // use other constructor for that
|
||||||
|
|
||||||
@ -163,11 +193,6 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
|||||||
hpr.setHPR(m_original_rotation);
|
hpr.setHPR(m_original_rotation);
|
||||||
m_node->setRotation(hpr.toIrrHPR());
|
m_node->setRotation(hpr.toIrrHPR());
|
||||||
m_node->grab();
|
m_node->grab();
|
||||||
if (owner)
|
|
||||||
{
|
|
||||||
m_previous_owner = owner;
|
|
||||||
ItemState::setDeactivatedTicks(stk_config->time2Ticks(1.5f));
|
|
||||||
}
|
|
||||||
} // Item(type, xyz, normal, mesh, lowres_mesh)
|
} // Item(type, xyz, normal, mesh, lowres_mesh)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -198,7 +223,6 @@ Item::Item(const Vec3& xyz, float distance, TriggerItemListener* trigger)
|
|||||||
void Item::initItem(ItemType type, const Vec3 &xyz)
|
void Item::initItem(ItemType type, const Vec3 &xyz)
|
||||||
{
|
{
|
||||||
ItemState::initItem(type, xyz);
|
ItemState::initItem(type, xyz);
|
||||||
m_previous_owner = NULL;
|
|
||||||
m_rotate = (getType()!=ITEM_BUBBLEGUM) &&
|
m_rotate = (getType()!=ITEM_BUBBLEGUM) &&
|
||||||
(getType()!=ITEM_TRIGGER );
|
(getType()!=ITEM_TRIGGER );
|
||||||
// Now determine in which quad this item is, and its distance
|
// Now determine in which quad this item is, and its distance
|
||||||
|
@ -122,34 +122,25 @@ private:
|
|||||||
* and then converting this value to a Vec3. */
|
* and then converting this value to a Vec3. */
|
||||||
Vec3 m_xyz;
|
Vec3 m_xyz;
|
||||||
|
|
||||||
protected:
|
|
||||||
/** The 'owner' of the item, i.e. the kart that dropped this item.
|
/** The 'owner' of the item, i.e. the kart that dropped this item.
|
||||||
* Is NULL if the item is part of the track. */
|
* Is NULL if the item is part of the track. */
|
||||||
const AbstractKart *m_previous_owner;
|
const AbstractKart *m_previous_owner;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
friend class ItemManager;
|
friend class ItemManager;
|
||||||
friend class NetworkItemManager;
|
friend class NetworkItemManager;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setType(ItemType type) { m_type = type; }
|
void setType(ItemType type) { m_type = type; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Constructor.
|
ItemState(ItemType type, const AbstractKart *owner=NULL, int id = -1);
|
||||||
* \param type Type of the item.
|
void initItem(ItemType type, const Vec3& xyz);
|
||||||
* \param id Index of this item in the array of all items.
|
void update(int ticks);
|
||||||
* \param kart_id If !=-1 the kart that dropped this item; -1
|
void setDisappearCounter();
|
||||||
* indicates an item that's part of the track. */
|
virtual void collected(const AbstractKart *kart);
|
||||||
ItemState(ItemType type, int id=-1, const AbstractKart *kart=NULL)
|
|
||||||
{
|
|
||||||
setType(type);
|
|
||||||
m_item_id = id;
|
|
||||||
m_previous_owner = kart;
|
|
||||||
} // ItemState(ItemType)
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual ~ItemState() {}
|
virtual ~ItemState() {}
|
||||||
void setDisappearCounter();
|
|
||||||
void update(int ticks);
|
|
||||||
virtual void collected(const AbstractKart *kart);
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
void reset()
|
void reset()
|
||||||
@ -165,19 +156,6 @@ public:
|
|||||||
}
|
}
|
||||||
} // reset
|
} // reset
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
/** Initialises an item.
|
|
||||||
* \param type Type for this item.
|
|
||||||
*/
|
|
||||||
void initItem(ItemType type, const Vec3& xyz)
|
|
||||||
{
|
|
||||||
m_xyz = xyz;
|
|
||||||
m_original_type = ITEM_NONE;
|
|
||||||
m_deactive_ticks = 0;
|
|
||||||
m_ticks_till_return = 0;
|
|
||||||
setDisappearCounter();
|
|
||||||
} // initItem
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Switches an item to be of a different type. Used for the switch
|
/** Switches an item to be of a different type. Used for the switch
|
||||||
* powerup.
|
* powerup.
|
||||||
@ -333,11 +311,10 @@ public:
|
|||||||
void updateGraphics(float dt);
|
void updateGraphics(float dt);
|
||||||
virtual void collected(const AbstractKart *kart) OVERRIDE;
|
virtual void collected(const AbstractKart *kart) OVERRIDE;
|
||||||
void reset();
|
void reset();
|
||||||
void switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh);
|
void switchTo(ItemType type, scene::IMesh *mesh,
|
||||||
|
scene::IMesh *lowmesh);
|
||||||
void switchBack();
|
void switchBack();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns true if the Kart is close enough to hit this item, the item is
|
/** Returns true if the Kart is close enough to hit this item, the item is
|
||||||
* not deactivated anymore, and it wasn't placed by this kart (this is
|
* not deactivated anymore, and it wasn't placed by this kart (this is
|
||||||
@ -348,7 +325,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool hitKart(const Vec3 &xyz, const AbstractKart *kart=NULL) const
|
bool hitKart(const Vec3 &xyz, const AbstractKart *kart=NULL) const
|
||||||
{
|
{
|
||||||
if (m_previous_owner == kart && getDeactivatedTicks() > 0)
|
if (getPreviousOwner() == kart && getDeactivatedTicks() > 0)
|
||||||
return false;
|
return false;
|
||||||
Vec3 lc = quatRotate(m_original_rotation, xyz - getXYZ());
|
Vec3 lc = quatRotate(m_original_rotation, xyz - getXYZ());
|
||||||
// Don't be too strict if the kart is a bit above the item
|
// Don't be too strict if the kart is a bit above the item
|
||||||
@ -369,7 +346,8 @@ protected:
|
|||||||
bool hitLine(const core::line3df &line,
|
bool hitLine(const core::line3df &line,
|
||||||
const AbstractKart *kart=NULL) const
|
const AbstractKart *kart=NULL) const
|
||||||
{
|
{
|
||||||
if (m_previous_owner == kart && getDeactivatedTicks() >0) return false;
|
if (getPreviousOwner() == kart && getDeactivatedTicks() > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
Vec3 closest = line.getClosestPoint(getXYZ().toIrrVector());
|
Vec3 closest = line.getClosestPoint(getXYZ().toIrrVector());
|
||||||
return hitKart(closest, kart);
|
return hitKart(closest, kart);
|
||||||
|
@ -103,7 +103,7 @@ void NetworkItemManager::collectedItem(Item *item, AbstractKart *kart)
|
|||||||
m_item_events.lock();
|
m_item_events.lock();
|
||||||
m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(),
|
m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(),
|
||||||
item->getItemId(),
|
item->getItemId(),
|
||||||
kart->getWorldKartId());
|
kart->getWorldKartId() );
|
||||||
m_item_events.unlock();
|
m_item_events.unlock();
|
||||||
ItemManager::collectedItem(item, kart);
|
ItemManager::collectedItem(item, kart);
|
||||||
}
|
}
|
||||||
@ -315,8 +315,8 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
|||||||
else if(iei.isNewItem())
|
else if(iei.isNewItem())
|
||||||
{
|
{
|
||||||
AbstractKart *kart = World::getWorld()->getKart(iei.getKartId());
|
AbstractKart *kart = World::getWorld()->getKart(iei.getKartId());
|
||||||
ItemState *is = new ItemState(iei.getNewItemType(), iei.getIndex(),
|
ItemState *is = new ItemState(iei.getNewItemType(), kart,
|
||||||
kart);
|
iei.getIndex() );
|
||||||
is->initItem(iei.getNewItemType(), iei.getXYZ());
|
is->initItem(iei.getNewItemType(), iei.getXYZ());
|
||||||
if (m_confirmed_state.size() <= is->getItemId())
|
if (m_confirmed_state.size() <= is->getItemId())
|
||||||
{
|
{
|
||||||
|
@ -560,11 +560,6 @@ void Powerup::hitBonusBox(const ItemState &item_state)
|
|||||||
|
|
||||||
new_powerup = powerup_manager->getRandomPowerup(position, &n,
|
new_powerup = powerup_manager->getRandomPowerup(position, &n,
|
||||||
random_number);
|
random_number);
|
||||||
// FIXME Disable switch and bubblegum for now in network
|
|
||||||
if (NetworkConfig::get()->isNetworking() &&
|
|
||||||
(new_powerup == PowerupManager::POWERUP_BUBBLEGUM ||
|
|
||||||
new_powerup == PowerupManager::POWERUP_SWITCH))
|
|
||||||
new_powerup = PowerupManager::POWERUP_BOWLING;
|
|
||||||
|
|
||||||
// Always add a new powerup in ITEM_MODE_NEW (or if the kart
|
// Always add a new powerup in ITEM_MODE_NEW (or if the kart
|
||||||
// doesn't have a powerup atm).
|
// doesn't have a powerup atm).
|
||||||
|
Loading…
Reference in New Issue
Block a user