From 60a3890c78e5a4e00a7948e8130954adae22b6be Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 1 Dec 2017 13:59:00 +0800 Subject: [PATCH] Add support for meta library objects --- src/tracks/track.cpp | 9 +++++++++ src/tracks/track.hpp | 6 ++++++ src/tracks/track_object.cpp | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index f29266e26..ca3fabb63 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -466,6 +466,7 @@ void Track::cleanup() } #endif + m_meta_library.clear(); Scripting::ScriptEngine::getInstance()->cleanupCache(); m_current_track = NULL; @@ -1757,6 +1758,14 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) loadObjects(root, path, model_def_loader, true, NULL, NULL); + // Correct the parenting of meta library + for (auto& p : m_meta_library) + { + auto* ln = p.first->getPresentation(); + assert(ln); + p.second->setParent(ln->getNode()); + } + model_def_loader.cleanLibraryNodesAfterLoad(); Scripting::ScriptEngine::getInstance()->compileLoadedScripts(); diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index a0d5a5adb..4a4603547 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -374,6 +374,8 @@ private: /** List of all bezier curves in the track - for e.g. camera, ... */ std::vector m_all_curves; + std::vector > m_meta_library; + /** The number of laps the track will be raced in a random GP. * m_actual_number_of_laps is initialised with this value.*/ int m_default_number_of_laps; @@ -672,6 +674,10 @@ public: // ------------------------------------------------------------------------ /** Adds mesh to cleanup list */ void addCachedMesh(scene::IMesh* mesh) { m_all_cached_meshes.push_back(mesh); } + // ------------------------------------------------------------------------ + /** Adds the parent of the meta library for correction later */ + void addMetaLibrary(TrackObject* parent, scene::ISceneNode* meta_library) + { m_meta_library.emplace_back(parent, meta_library); } }; // class Track #endif diff --git a/src/tracks/track_object.cpp b/src/tracks/track_object.cpp index 0d441d123..0e11cd069 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -31,6 +31,7 @@ #include "physics/physical_object.hpp" #include "race/race_manager.hpp" #include "scriptengine/script_engine.hpp" +#include "tracks/track.hpp" #include "tracks/model_definition_loader.hpp" #include @@ -160,6 +161,11 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent, { xml_node.get("name", &m_name); m_presentation = new TrackObjectPresentationLibraryNode(this, xml_node, model_def_loader); + if (parent_library != NULL) + { + Track::getCurrentTrack()->addMetaLibrary(parent_library, + (dynamic_cast(m_presentation))->getNode()); + } } else if (type == "sfx-emitter") {