Add LOD to item. Say hello to a 5-10 FPS boost\!
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8579 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<items>
|
||||
<bonus-box model="gift-box.b3d" />
|
||||
<banana model="banana.b3d" />
|
||||
<nitro-big model="nitrotank-big.b3d" />
|
||||
<nitro-small model="nitrotank-small.b3d" />
|
||||
<bonus-box model="gift-box.b3d" lowmodel="gift-box-low.b3d" />
|
||||
<banana model="banana.b3d" lowmodel="banana-low.b3d" />
|
||||
<nitro-big model="nitrotank-big.b3d" lowmodel="nitrotank-big-low.b3d" />
|
||||
<nitro-small model="nitrotank-small.b3d" lowmodel="nitrotank-small-low.b3d" />
|
||||
<!-- While a bubble gum technically
|
||||
isn't an item, it is internally
|
||||
handled as one, so list it here -->
|
||||
|
||||
BIN
data/models/banana-low.b3d
Executable file
BIN
data/models/banana-low.b3d
Executable file
Binary file not shown.
BIN
data/models/gift-box-low.b3d
Executable file
BIN
data/models/gift-box-low.b3d
Executable file
Binary file not shown.
BIN
data/models/nitrotank-big-low.b3d
Executable file
BIN
data/models/nitrotank-big-low.b3d
Executable file
Binary file not shown.
Binary file not shown.
BIN
data/models/nitrotank-small-low.b3d
Executable file
BIN
data/models/nitrotank-small-low.b3d
Executable file
Binary file not shown.
Binary file not shown.
@@ -77,6 +77,8 @@ public:
|
||||
/** Get the highest level of detail node */
|
||||
scene::ISceneNode* getFirstNode() { return m_nodes[0]; }
|
||||
|
||||
std::vector<scene::ISceneNode*>& getAllNodes() { return m_nodes; }
|
||||
|
||||
virtual void OnRegisterSceneNode();
|
||||
virtual void render();
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "items/item.hpp"
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/lod_node.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "modes/three_strikes_battle.hpp"
|
||||
#include "modes/world.hpp"
|
||||
@@ -28,7 +29,7 @@
|
||||
#include "utils/vec3.hpp"
|
||||
|
||||
Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||
scene::IMesh* mesh, unsigned int item_id)
|
||||
scene::IMesh* mesh, scene::IMesh* lowres_mesh, unsigned int item_id)
|
||||
{
|
||||
setType(type);
|
||||
m_event_handler = NULL;
|
||||
@@ -43,8 +44,26 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||
m_disappear_counter = m_type==ITEM_BUBBLEGUM
|
||||
? stk_config->m_bubble_gum_counter
|
||||
: -1 ;
|
||||
m_original_mesh = mesh;
|
||||
m_node = irr_driver->addMesh(mesh);
|
||||
m_original_mesh = mesh;
|
||||
m_original_lowmesh = lowres_mesh;
|
||||
|
||||
LODNode* lodnode = new LODNode(irr_driver->getSceneManager()->getRootSceneNode(), irr_driver->getSceneManager());
|
||||
scene::IMeshSceneNode* meshnode = irr_driver->addMesh(mesh);
|
||||
|
||||
if (lowres_mesh != NULL)
|
||||
{
|
||||
lodnode->add(35, meshnode, true);
|
||||
scene::IMeshSceneNode* meshnode = irr_driver->addMesh(lowres_mesh);
|
||||
lodnode->add(100, meshnode, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
lodnode->add(100, meshnode, true);
|
||||
}
|
||||
|
||||
m_node = lodnode;
|
||||
|
||||
//m_node = irr_driver->addMesh(mesh);
|
||||
#ifdef DEBUG
|
||||
std::string debug_name("item: ");
|
||||
debug_name += m_type;
|
||||
@@ -74,11 +93,19 @@ void Item::setType(ItemType type)
|
||||
* \param type New type of this item.
|
||||
* \param mesh Mesh to use to display this item.
|
||||
*/
|
||||
void Item::switchTo(ItemType type, scene::IMesh *mesh)
|
||||
void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh)
|
||||
{
|
||||
m_original_type = m_type;
|
||||
setType(type);
|
||||
m_node->setMesh(mesh);
|
||||
|
||||
scene::ISceneNode* node = m_node->getAllNodes()[0];
|
||||
((scene::IMeshSceneNode*)node)->setMesh(mesh);
|
||||
if (lowmesh != NULL)
|
||||
{
|
||||
node = m_node->getAllNodes()[1];
|
||||
((scene::IMeshSceneNode*)node)->setMesh(lowmesh);
|
||||
}
|
||||
|
||||
World::getWorld()->getTrack()->adjustForFog(m_node);
|
||||
} // switchTo
|
||||
|
||||
@@ -95,7 +122,15 @@ void Item::switchBack()
|
||||
|
||||
setType(m_original_type);
|
||||
m_original_type = ITEM_NONE;
|
||||
m_node->setMesh(m_original_mesh);
|
||||
|
||||
scene::ISceneNode* node = m_node->getAllNodes()[0];
|
||||
((scene::IMeshSceneNode*)node)->setMesh(m_original_mesh);
|
||||
if (m_original_lowmesh != NULL)
|
||||
{
|
||||
node = m_node->getAllNodes()[1];
|
||||
((scene::IMeshSceneNode*)node)->setMesh(m_original_lowmesh);
|
||||
}
|
||||
|
||||
World::getWorld()->getTrack()->adjustForFog(m_node);
|
||||
m_node->setRotation(m_original_hpr.toIrrHPR());
|
||||
} // switchBack
|
||||
@@ -174,6 +209,7 @@ void Item::update(float dt)
|
||||
core::vector3df r = m_node->getRotation();
|
||||
r.Y += dt*180.0f;
|
||||
if(r.Y>360.0f) r.Y -= 360.0f;
|
||||
|
||||
m_node->setRotation(r);
|
||||
return;
|
||||
} // not m_collected
|
||||
|
||||
@@ -30,6 +30,8 @@ using namespace irr;
|
||||
#include "karts/kart.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
class LODNode;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -79,10 +81,11 @@ private:
|
||||
float m_time_till_return;
|
||||
|
||||
/** Scene node of this item. */
|
||||
scene::IMeshSceneNode *m_node;
|
||||
LODNode *m_node;
|
||||
|
||||
/** Stores the original mesh in order to reset it. */
|
||||
scene::IMesh *m_original_mesh;
|
||||
scene::IMesh *m_original_lowmesh;
|
||||
|
||||
/** The original position - saves calls to m_node->getPosition()
|
||||
* and then converting this value to a Vec3. */
|
||||
@@ -111,7 +114,7 @@ private:
|
||||
void setType(ItemType type);
|
||||
public:
|
||||
Item (ItemType type, const Vec3& xyz, const Vec3& normal,
|
||||
scene::IMesh* mesh, unsigned int item_id);
|
||||
scene::IMesh* mesh, scene::IMesh* lowres_mesh, unsigned int item_id);
|
||||
virtual ~Item ();
|
||||
void update (float delta);
|
||||
virtual void collected(const Kart *kart, float t=2.0f);
|
||||
@@ -159,7 +162,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
void setParent(Kart* parent);
|
||||
void reset();
|
||||
void switchTo(ItemType type, scene::IMesh *mesh);
|
||||
void switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh);
|
||||
void switchBack();
|
||||
}; // class Item
|
||||
|
||||
|
||||
@@ -79,7 +79,12 @@ void ItemManager::removeTextures()
|
||||
{
|
||||
i->second->drop();
|
||||
}
|
||||
for(CI_type i=m_all_low_meshes.begin(); i!=m_all_low_meshes.end(); ++i)
|
||||
{
|
||||
i->second->drop();
|
||||
}
|
||||
m_all_meshes.clear();
|
||||
m_all_low_meshes.clear();
|
||||
} // removeTextures
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -90,6 +95,12 @@ ItemManager::~ItemManager()
|
||||
i->second->drop();
|
||||
}
|
||||
m_all_meshes.clear();
|
||||
|
||||
for(CI_type i=m_all_low_meshes.begin(); i!=m_all_low_meshes.end(); ++i)
|
||||
{
|
||||
i->second->drop();
|
||||
}
|
||||
m_all_low_meshes.clear();
|
||||
} // ~ItemManager
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -106,10 +117,19 @@ void ItemManager::loadDefaultItems()
|
||||
for(unsigned int i=Item::ITEM_FIRST; i<=Item::ITEM_LAST; i++)
|
||||
{
|
||||
const XMLNode *node = root->getNode(item_names[i]);
|
||||
std::string model_filename;
|
||||
std::string model_filename, lowres_model_filename;
|
||||
if (node)
|
||||
{
|
||||
node->get("model", &model_filename);
|
||||
node->get("lowmodel", &lowres_model_filename);
|
||||
}
|
||||
|
||||
scene::IMesh *mesh = irr_driver->getAnimatedMesh(model_filename);
|
||||
scene::IMesh *lowres_mesh = NULL;
|
||||
|
||||
if (lowres_model_filename.size() > 0)
|
||||
lowres_mesh = irr_driver->getMesh(lowres_model_filename);
|
||||
|
||||
if(!node || model_filename.size()==0 || !mesh)
|
||||
{
|
||||
fprintf(stderr, "Item model '%s' in items.xml could not be loaded - aborting",
|
||||
@@ -118,9 +138,14 @@ void ItemManager::loadDefaultItems()
|
||||
}
|
||||
std::string shortName =
|
||||
StringUtils::getBasename(StringUtils::removeExtension(model_filename));
|
||||
m_all_meshes[shortName] = mesh;
|
||||
m_item_mesh[i] = mesh;
|
||||
m_all_meshes[shortName] = mesh;
|
||||
m_item_mesh[i] = mesh;
|
||||
m_item_lowres_mesh[i] = lowres_mesh;
|
||||
mesh->grab();
|
||||
|
||||
if (lowres_mesh != NULL)
|
||||
m_all_low_meshes[shortName] = lowres_mesh;
|
||||
if (lowres_mesh != NULL) lowres_mesh->grab();
|
||||
} // for i
|
||||
delete root;
|
||||
} // loadDefaultItems
|
||||
@@ -143,12 +168,12 @@ Item* ItemManager::newItem(Item::ItemType type, const Vec3& xyz,
|
||||
|
||||
if(index==-1) index = m_all_items.size();
|
||||
Item* item;
|
||||
item = new Item(type, xyz, normal, m_item_mesh[type], index);
|
||||
item = new Item(type, xyz, normal, m_item_mesh[type], m_item_lowres_mesh[type], index);
|
||||
if(parent != NULL) item->setParent(parent);
|
||||
if(m_switch_time>=0)
|
||||
{
|
||||
Item::ItemType new_type = m_switch_to[item->getType()];
|
||||
item->switchTo(new_type, m_item_mesh[(int)new_type]);
|
||||
item->switchTo(new_type, m_item_mesh[(int)new_type], m_item_lowres_mesh[(int)new_type]);
|
||||
}
|
||||
if(index<(int)m_all_items.size())
|
||||
m_all_items[index] = item;
|
||||
@@ -293,7 +318,7 @@ void ItemManager::switchItems()
|
||||
Item::ItemType new_type = m_switch_to[(*i)->getType()];
|
||||
|
||||
if(m_switch_time<0)
|
||||
(*i)->switchTo(new_type, m_item_mesh[(int)new_type]);
|
||||
(*i)->switchTo(new_type, m_item_mesh[(int)new_type], m_item_lowres_mesh[(int)new_type]);
|
||||
else
|
||||
(*i)->switchBack();
|
||||
} // for m_all_items
|
||||
|
||||
@@ -42,9 +42,11 @@ private:
|
||||
|
||||
/** This stores all item models. */
|
||||
scene::IMesh *m_item_mesh[Item::ITEM_LAST-Item::ITEM_FIRST+1];
|
||||
scene::IMesh *m_item_lowres_mesh[Item::ITEM_LAST-Item::ITEM_FIRST+1];
|
||||
|
||||
/** Stores all meshes for all items. */
|
||||
std::map<std::string,scene::IMesh*> m_all_meshes;
|
||||
std::map<std::string,scene::IMesh*> m_all_low_meshes;
|
||||
|
||||
std::string m_user_filename;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user