1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Change special and cutscene logic to load and unload models

This commit is contained in:
Daniel Evans 2016-10-07 01:04:48 +01:00
parent 17315c7974
commit a861309936
2 changed files with 28 additions and 5 deletions

View File

@ -74,6 +74,8 @@ public:
/// @todo replace with proper streaming implementation /// @todo replace with proper streaming implementation
virtual bool isLoaded() const = 0; virtual bool isLoaded() const = 0;
virtual void unload() = 0;
static std::string getTypeName(ModelDataType type) { static std::string getTypeName(ModelDataType type) {
switch (type) { switch (type) {
case ModelDataType::SimpleInfo: case ModelDataType::SimpleInfo:
@ -157,6 +159,11 @@ public:
return model_ != nullptr; return model_ != nullptr;
} }
void unload() override {
delete model_;
model_ = nullptr;
}
enum { enum {
/// Cull model if player doesn't look at it. Ignored in GTA 3. /// Cull model if player doesn't look at it. Ignored in GTA 3.
NORMAL_CULL = 1, NORMAL_CULL = 1,
@ -226,6 +233,11 @@ public:
return model_ != nullptr; return model_ != nullptr;
} }
void unload() override {
delete model_;
model_ = nullptr;
}
private: private:
Model* model_ = nullptr; Model* model_ = nullptr;
}; };

View File

@ -257,8 +257,7 @@ CutsceneObject* GameWorld::createCutsceneObject(const uint16_t id,
auto clumpmodel = static_cast<ClumpModelInfo*>(modelinfo); auto clumpmodel = static_cast<ClumpModelInfo*>(modelinfo);
std::string texturename; std::string texturename;
/// @todo track if the current cutscene model is loaded if (!clumpmodel->isLoaded()) {
if (true || !modelinfo->isLoaded()) {
data->loadModel(id); data->loadModel(id);
} }
auto model = clumpmodel->getModel(); auto model = clumpmodel->getModel();
@ -810,20 +809,32 @@ bool GameWorld::isCutsceneDone() {
void GameWorld::loadSpecialCharacter(const unsigned short index, void GameWorld::loadSpecialCharacter(const unsigned short index,
const std::string& name) { 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<PedModelInfo>(modelid);
if (model && model->isLoaded()) {
model->unload();
}
std::string lowerName(name); std::string lowerName(name);
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
::tolower); ::tolower);
// Need to replace any existing loaded model
/// @todo a bit more smarter than this
state->specialCharacters[index] = lowerName; state->specialCharacters[index] = lowerName;
} }
void GameWorld::loadSpecialModel(const unsigned short index, void GameWorld::loadSpecialModel(const unsigned short index,
const std::string& name) { 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<ClumpModelInfo>(index);
if (model && model->isLoaded()) {
model->unload();
}
std::string lowerName(name); std::string lowerName(name);
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
::tolower); ::tolower);
/// @todo a bit more smarter than this
state->specialModels[index] = lowerName; state->specialModels[index] = lowerName;
} }