Fix item model no update if missing the switch event
This commit is contained in:
parent
e4eb1513fc
commit
90daf4ce87
@ -157,11 +157,9 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
|||||||
m_was_available_previously = true;
|
m_was_available_previously = true;
|
||||||
m_distance_2 = 1.2f;
|
m_distance_2 = 1.2f;
|
||||||
initItem(type, xyz);
|
initItem(type, xyz);
|
||||||
|
m_graphical_type = type;
|
||||||
m_original_rotation = shortestArcQuat(Vec3(0, 1, 0), normal);
|
m_original_rotation = shortestArcQuat(Vec3(0, 1, 0), normal);
|
||||||
m_rotation_angle = 0.0f;
|
m_rotation_angle = 0.0f;
|
||||||
m_original_mesh = mesh;
|
|
||||||
m_original_lowmesh = lowres_mesh;
|
|
||||||
m_listener = NULL;
|
m_listener = NULL;
|
||||||
|
|
||||||
LODNode* lodnode =
|
LODNode* lodnode =
|
||||||
@ -209,10 +207,9 @@ Item::Item(const Vec3& xyz, float distance, TriggerItemListener* trigger)
|
|||||||
{
|
{
|
||||||
m_distance_2 = distance*distance;
|
m_distance_2 = distance*distance;
|
||||||
initItem(ITEM_TRIGGER, xyz);
|
initItem(ITEM_TRIGGER, xyz);
|
||||||
|
m_graphical_type = ITEM_TRIGGER;
|
||||||
m_original_rotation = btQuaternion(0, 0, 0, 1);
|
m_original_rotation = btQuaternion(0, 0, 0, 1);
|
||||||
m_rotation_angle = 0.0f;
|
m_rotation_angle = 0.0f;
|
||||||
m_original_mesh = NULL;
|
|
||||||
m_original_lowmesh = NULL;
|
|
||||||
m_node = NULL;
|
m_node = NULL;
|
||||||
m_listener = trigger;
|
m_listener = trigger;
|
||||||
m_was_available_previously = true;
|
m_was_available_previously = true;
|
||||||
@ -226,8 +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_rotate = (getType()!=ITEM_BUBBLEGUM) &&
|
|
||||||
(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
|
||||||
// from the center within this quad.
|
// from the center within this quad.
|
||||||
m_graph_node = Graph::UNKNOWN_SECTOR;
|
m_graph_node = Graph::UNKNOWN_SECTOR;
|
||||||
@ -265,19 +260,6 @@ void Item::initItem(ItemType type, const Vec3 &xyz)
|
|||||||
void Item::setType(ItemType type)
|
void Item::setType(ItemType type)
|
||||||
{
|
{
|
||||||
ItemState::setType(type);
|
ItemState::setType(type);
|
||||||
m_rotate = (type!=ITEM_BUBBLEGUM) && (type!=ITEM_TRIGGER);
|
|
||||||
|
|
||||||
if (m_node != NULL)
|
|
||||||
{
|
|
||||||
for (auto* node : m_node->getAllNodes())
|
|
||||||
{
|
|
||||||
SP::SPMeshNode* spmn = dynamic_cast<SP::SPMeshNode*>(node);
|
|
||||||
if (spmn)
|
|
||||||
{
|
|
||||||
spmn->setGlowColor(ItemManager::get()->getGlowColor(type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // setType
|
} // setType
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -287,7 +269,6 @@ void Item::setType(ItemType type)
|
|||||||
*/
|
*/
|
||||||
void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh)
|
void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh)
|
||||||
{
|
{
|
||||||
setMesh(mesh, lowmesh);
|
|
||||||
ItemState::switchTo(type, mesh, lowmesh);
|
ItemState::switchTo(type, mesh, lowmesh);
|
||||||
} // switchTo
|
} // switchTo
|
||||||
|
|
||||||
@ -299,17 +280,9 @@ void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh)
|
|||||||
*/
|
*/
|
||||||
bool Item::switchBack()
|
bool Item::switchBack()
|
||||||
{
|
{
|
||||||
setMesh(m_original_mesh, m_original_lowmesh);
|
|
||||||
|
|
||||||
if (ItemState::switchBack())
|
if (ItemState::switchBack())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (m_node != NULL)
|
|
||||||
{
|
|
||||||
Vec3 hpr;
|
|
||||||
hpr.setHPR(m_original_rotation);
|
|
||||||
m_node->setRotation(hpr.toIrrHPR());
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
} // switchBack
|
} // switchBack
|
||||||
|
|
||||||
@ -371,8 +344,27 @@ void Item::reset()
|
|||||||
m_node->setScale(core::vector3df(1,1,1));
|
m_node->setScale(core::vector3df(1,1,1));
|
||||||
m_node->setVisible(true);
|
m_node->setVisible(true);
|
||||||
}
|
}
|
||||||
|
handleNewMesh(getType());
|
||||||
} // reset
|
} // reset
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void Item::handleNewMesh(ItemType type)
|
||||||
|
{
|
||||||
|
if (m_node == NULL)
|
||||||
|
return;
|
||||||
|
setMesh(ItemManager::get()->getItemModel(type),
|
||||||
|
ItemManager::get()->getItemLowResolutionModel(type));
|
||||||
|
for (auto* node : m_node->getAllNodes())
|
||||||
|
{
|
||||||
|
SP::SPMeshNode* spmn = dynamic_cast<SP::SPMeshNode*>(node);
|
||||||
|
if (spmn)
|
||||||
|
spmn->setGlowColor(ItemManager::get()->getGlowColor(type));
|
||||||
|
}
|
||||||
|
Vec3 hpr;
|
||||||
|
hpr.setHPR(m_original_rotation);
|
||||||
|
m_node->setRotation(hpr.toIrrHPR());
|
||||||
|
} // handleNewMesh
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Updated the item - rotates it, takes care of items coming back into
|
/** Updated the item - rotates it, takes care of items coming back into
|
||||||
* the game after it has been collected.
|
* the game after it has been collected.
|
||||||
@ -383,6 +375,12 @@ void Item::updateGraphics(float dt)
|
|||||||
if (m_node == NULL)
|
if (m_node == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (m_graphical_type != getType())
|
||||||
|
{
|
||||||
|
handleNewMesh(getType());
|
||||||
|
m_graphical_type = getType();
|
||||||
|
}
|
||||||
|
|
||||||
float time_till_return = stk_config->ticks2Time(getTicksTillReturn());
|
float time_till_return = stk_config->ticks2Time(getTicksTillReturn());
|
||||||
bool is_visible = isAvailable() || time_till_return <= 1.0f ||
|
bool is_visible = isAvailable() || time_till_return <= 1.0f ||
|
||||||
(getType() == ITEM_BUBBLEGUM &&
|
(getType() == ITEM_BUBBLEGUM &&
|
||||||
@ -403,7 +401,7 @@ void Item::updateGraphics(float dt)
|
|||||||
m_node->setVisible(true);
|
m_node->setVisible(true);
|
||||||
m_node->setScale(core::vector3df(1, 1, 1)*(1 - time_till_return));
|
m_node->setScale(core::vector3df(1, 1, 1)*(1 - time_till_return));
|
||||||
}
|
}
|
||||||
if (isAvailable() && m_rotate)
|
if (isAvailable() && rotating())
|
||||||
{
|
{
|
||||||
// have it rotate
|
// have it rotate
|
||||||
m_rotation_angle += dt * M_PI;
|
m_rotation_angle += dt * M_PI;
|
||||||
@ -419,7 +417,7 @@ void Item::updateGraphics(float dt)
|
|||||||
m_node->setRotation(hpr.toIrrHPR());
|
m_node->setRotation(hpr.toIrrHPR());
|
||||||
} // if item is available
|
} // if item is available
|
||||||
m_was_available_previously = isAvailable();
|
m_was_available_previously = isAvailable();
|
||||||
} // update
|
} // updateGraphics
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Is called when the item is hit by a kart. It sets the flag that the item
|
/** Is called when the item is hit by a kart. It sets the flag that the item
|
||||||
|
@ -202,7 +202,7 @@ public:
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
/** Resets an item to its start state. */
|
/** Resets an item to its start state. */
|
||||||
void reset()
|
virtual void reset()
|
||||||
{
|
{
|
||||||
m_deactive_ticks = 0;
|
m_deactive_ticks = 0;
|
||||||
m_ticks_till_return = 0;
|
m_ticks_till_return = 0;
|
||||||
@ -332,12 +332,8 @@ private:
|
|||||||
/** Scene node of this item. */
|
/** Scene node of this item. */
|
||||||
LODNode *m_node;
|
LODNode *m_node;
|
||||||
|
|
||||||
/** Stores the original mesh in order to reset it. */
|
/** Graphical type of the mesh. */
|
||||||
scene::IMesh *m_original_mesh;
|
ItemType m_graphical_type;
|
||||||
scene::IMesh *m_original_lowmesh;
|
|
||||||
|
|
||||||
/** Set to false if item should not rotate. */
|
|
||||||
bool m_rotate;
|
|
||||||
|
|
||||||
/** Stores if the item was available in the previously rendered frame. */
|
/** Stores if the item was available in the previously rendered frame. */
|
||||||
bool m_was_available_previously;
|
bool m_was_available_previously;
|
||||||
@ -363,6 +359,7 @@ private:
|
|||||||
void setType(ItemType type) OVERRIDE;
|
void setType(ItemType type) OVERRIDE;
|
||||||
void initItem(ItemType type, const Vec3 &xyz);
|
void initItem(ItemType type, const Vec3 &xyz);
|
||||||
void setMesh(scene::IMesh* mesh, scene::IMesh* lowres_mesh);
|
void setMesh(scene::IMesh* mesh, scene::IMesh* lowres_mesh);
|
||||||
|
void handleNewMesh(ItemType type);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||||
@ -374,7 +371,7 @@ public:
|
|||||||
virtual ~Item ();
|
virtual ~Item ();
|
||||||
virtual void updateGraphics(float dt) OVERRIDE;
|
virtual void updateGraphics(float dt) OVERRIDE;
|
||||||
virtual void collected(const AbstractKart *kart) OVERRIDE;
|
virtual void collected(const AbstractKart *kart) OVERRIDE;
|
||||||
void reset();
|
virtual void reset() OVERRIDE;
|
||||||
virtual void switchTo(ItemType type, scene::IMesh *mesh,
|
virtual void switchTo(ItemType type, scene::IMesh *mesh,
|
||||||
scene::IMesh *lowmesh) OVERRIDE;
|
scene::IMesh *lowmesh) OVERRIDE;
|
||||||
virtual bool switchBack() OVERRIDE;
|
virtual bool switchBack() OVERRIDE;
|
||||||
@ -397,6 +394,9 @@ public:
|
|||||||
lc.setY(lc.getY() / 2.0f);
|
lc.setY(lc.getY() / 2.0f);
|
||||||
return lc.length2() < m_distance_2;
|
return lc.length2() < m_distance_2;
|
||||||
} // hitKart
|
} // hitKart
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
bool rotating() const
|
||||||
|
{ return getType() != ITEM_BUBBLEGUM && getType() != ITEM_TRIGGER; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -84,6 +84,10 @@ public:
|
|||||||
static scene::IMesh* getItemModel(ItemState::ItemType type)
|
static scene::IMesh* getItemModel(ItemState::ItemType type)
|
||||||
{ return m_item_mesh[type]; }
|
{ return m_item_mesh[type]; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the low resolution mesh for a certain item. */
|
||||||
|
static scene::IMesh* getItemLowResolutionModel(ItemState::ItemType type)
|
||||||
|
{ return m_item_lowres_mesh[type]; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the glow color for an item. */
|
/** Returns the glow color for an item. */
|
||||||
static video::SColorf& getGlowColor(ItemState::ItemType type)
|
static video::SColorf& getGlowColor(ItemState::ItemType type)
|
||||||
{ return m_glow_color[type]; }
|
{ return m_glow_color[type]; }
|
||||||
@ -101,7 +105,6 @@ protected:
|
|||||||
/** The vector of all items of the current track. */
|
/** The vector of all items of the current track. */
|
||||||
typedef std::vector<ItemState*> AllItemTypes;
|
typedef std::vector<ItemState*> AllItemTypes;
|
||||||
AllItemTypes m_all_items;
|
AllItemTypes m_all_items;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Stores which items are on which quad. m_items_in_quads[#quads]
|
/** Stores which items are on which quad. m_items_in_quads[#quads]
|
||||||
* contains all items that are not on a quad. Note that this
|
* contains all items that are not on a quad. Note that this
|
||||||
|
Loading…
Reference in New Issue
Block a user