More work for library nodes. Remove some code that hardcoded search paths, let's just use our file manager for that, it does it right and easier
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14843 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -1513,7 +1513,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
||||
loadMainTrack(*root);
|
||||
unsigned int main_track_count = m_all_nodes.size();
|
||||
|
||||
loadObjects(root, path);
|
||||
loadObjects(root, path, true);
|
||||
|
||||
// ---- Fog
|
||||
// It's important to execute this BEFORE the code that creates the skycube,
|
||||
@@ -1665,11 +1665,14 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void Track::loadObjects(const XMLNode* root, const std::string& path)
|
||||
void Track::loadObjects(const XMLNode* root, const std::string& path,
|
||||
bool create_lod_definitions)
|
||||
{
|
||||
LodNodeLoader lod_loader;
|
||||
unsigned int start_position_counter = 0;
|
||||
|
||||
std::map<std::string, XMLNode*> library_nodes;
|
||||
|
||||
unsigned int node_count = root->getNumNodes();
|
||||
for (unsigned int i = 0; i < node_count; i++)
|
||||
{
|
||||
@@ -1680,22 +1683,51 @@ void Track::loadObjects(const XMLNode* root, const std::string& path)
|
||||
if (name == "track" || name == "default-start") continue;
|
||||
if (name == "object")
|
||||
{
|
||||
lod_loader.check(node);
|
||||
bool is_instance = false;
|
||||
node->get("lod_instance", &is_instance);
|
||||
|
||||
float lod_distance = -1;
|
||||
node->get("lod_distance", &lod_distance);
|
||||
|
||||
if (lod_distance > 0.0f && !is_instance)
|
||||
{
|
||||
// lod definition
|
||||
if (create_lod_definitions)
|
||||
lod_loader.check(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
lod_loader.check(node);
|
||||
}
|
||||
m_track_object_manager->add(*node);
|
||||
}
|
||||
else if (name == "library")
|
||||
{
|
||||
std::string name;
|
||||
node->get("name", &name);
|
||||
std::string lib_node_path = file_manager->getAsset("library/" + name + "/node.xml");
|
||||
|
||||
XMLNode* libroot;
|
||||
std::string lib_path = file_manager->getAsset("library/" + name);
|
||||
XMLNode *libroot = file_manager->createXMLTree(lib_node_path);
|
||||
if (libroot == NULL) continue;
|
||||
bool create_lod_definitions = true;
|
||||
|
||||
if (library_nodes.find(name) == library_nodes.end())
|
||||
{
|
||||
std::string lib_node_path = file_manager->getAsset("library/" + name + "/node.xml");
|
||||
libroot = file_manager->createXMLTree(lib_node_path);
|
||||
if (libroot == NULL) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
libroot = library_nodes[name];
|
||||
create_lod_definitions = false; // LOD definitions are already created, don't create them again
|
||||
}
|
||||
|
||||
library_nodes[name] = libroot;
|
||||
|
||||
file_manager->pushTextureSearchPath(lib_path + "/");
|
||||
file_manager->pushModelSearchPath (lib_path);
|
||||
|
||||
loadObjects(libroot, lib_path);
|
||||
loadObjects(libroot, lib_path, create_lod_definitions);
|
||||
|
||||
file_manager->popTextureSearchPath();
|
||||
file_manager->popModelSearchPath();
|
||||
@@ -1822,13 +1854,13 @@ void Track::loadObjects(const XMLNode* root, const std::string& path)
|
||||
const XMLNode* track_node = root->getNode("track");
|
||||
if (track_node != NULL)
|
||||
{
|
||||
for(unsigned int i=0; i<track_node->getNumNodes(); i++)
|
||||
for (unsigned int i=0; i<track_node->getNumNodes(); i++)
|
||||
{
|
||||
const XMLNode* n = track_node->getNode(i);
|
||||
bool is_instance = false;
|
||||
n->get("lod_instance", &is_instance);
|
||||
|
||||
if (!is_instance) lod_loader.check(n);
|
||||
if (!is_instance && create_lod_definitions) lod_loader.check(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -399,7 +399,8 @@ private:
|
||||
std::vector<MusicInformation*>& m_music );
|
||||
void loadCurves(const XMLNode &node);
|
||||
void handleSky(const XMLNode &root, const std::string &filename);
|
||||
void loadObjects(const XMLNode* root, const std::string& path);
|
||||
void loadObjects(const XMLNode* root, const std::string& path,
|
||||
bool create_lod_definitions);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -160,41 +160,25 @@ TrackObjectPresentationMesh::TrackObjectPresentationMesh(const XMLNode& xml_node
|
||||
m_is_in_skybox = true;
|
||||
}
|
||||
|
||||
std::string full_path =
|
||||
World::getWorld()->getTrack()->getTrackFile(model_name);
|
||||
//std::string full_path =
|
||||
// World::getWorld()->getTrack()->getTrackFile(model_name);
|
||||
|
||||
bool animated = (UserConfigParams::m_graphical_effects ||
|
||||
World::getWorld()->getIdent() == IDENT_CUSTSCENE);
|
||||
|
||||
|
||||
if (file_manager->fileExists(full_path))
|
||||
if (animated)
|
||||
{
|
||||
if (animated)
|
||||
{
|
||||
m_mesh = irr_driver->getAnimatedMesh(full_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mesh = irr_driver->getMesh(full_path);
|
||||
}
|
||||
m_mesh = irr_driver->getAnimatedMesh(model_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mesh = irr_driver->getMesh(model_name);
|
||||
}
|
||||
|
||||
if (!m_mesh)
|
||||
{
|
||||
// If the model isn't found in the track directory, look
|
||||
// in STK's model directory.
|
||||
full_path = file_manager->getAsset(FileManager::MODEL,model_name);
|
||||
m_mesh = irr_driver->getAnimatedMesh(full_path);
|
||||
|
||||
if (!m_mesh)
|
||||
{
|
||||
m_mesh = irr_driver->getAnimatedMesh(model_name);
|
||||
|
||||
if (!m_mesh)
|
||||
{
|
||||
throw std::runtime_error("Model '" + model_name + "' cannot be found");
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Model '" + model_name + "' cannot be found");
|
||||
}
|
||||
|
||||
init(&xml_node, enabled);
|
||||
|
||||
Reference in New Issue
Block a user