From a861309936ea580e90d3321670a5a2fd8165ff4f Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Fri, 7 Oct 2016 01:04:48 +0100 Subject: [PATCH] Change special and cutscene logic to load and unload models --- rwengine/src/data/ModelData.hpp | 12 ++++++++++++ rwengine/src/engine/GameWorld.cpp | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/rwengine/src/data/ModelData.hpp b/rwengine/src/data/ModelData.hpp index 3fb70ef5..5f7aed46 100644 --- a/rwengine/src/data/ModelData.hpp +++ b/rwengine/src/data/ModelData.hpp @@ -74,6 +74,8 @@ public: /// @todo replace with proper streaming implementation virtual bool isLoaded() const = 0; + virtual void unload() = 0; + static std::string getTypeName(ModelDataType type) { switch (type) { case ModelDataType::SimpleInfo: @@ -157,6 +159,11 @@ public: return model_ != nullptr; } + void unload() override { + delete model_; + model_ = nullptr; + } + enum { /// Cull model if player doesn't look at it. Ignored in GTA 3. NORMAL_CULL = 1, @@ -226,6 +233,11 @@ public: return model_ != nullptr; } + void unload() override { + delete model_; + model_ = nullptr; + } + private: Model* model_ = nullptr; }; diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 733711ad..a8bb3484 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -257,8 +257,7 @@ CutsceneObject* GameWorld::createCutsceneObject(const uint16_t id, auto clumpmodel = static_cast(modelinfo); std::string texturename; - /// @todo track if the current cutscene model is loaded - if (true || !modelinfo->isLoaded()) { + if (!clumpmodel->isLoaded()) { data->loadModel(id); } auto model = clumpmodel->getModel(); @@ -810,20 +809,32 @@ bool GameWorld::isCutsceneDone() { void GameWorld::loadSpecialCharacter(const unsigned short index, const std::string& name) { + constexpr uint16_t kFirstSpecialActor = 26; + logger->info("Data", "Loading special actor " + name + " to " + + std::to_string(index)); + auto modelid = kFirstSpecialActor + index - 1; + auto model = data->findModelInfo(modelid); + if (model && model->isLoaded()) { + model->unload(); + } std::string lowerName(name); std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); - // Need to replace any existing loaded model - /// @todo a bit more smarter than this state->specialCharacters[index] = lowerName; } void GameWorld::loadSpecialModel(const unsigned short index, const std::string& name) { + logger->info("Data", "Loading cutscene object " + name + " to " + + std::to_string(index)); + // Tell the HIER model to discard the currently loaded model + auto model = data->findModelInfo(index); + if (model && model->isLoaded()) { + model->unload(); + } std::string lowerName(name); std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); - /// @todo a bit more smarter than this state->specialModels[index] = lowerName; }