1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 15:02:34 +02: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
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;
};

View File

@ -257,8 +257,7 @@ CutsceneObject* GameWorld::createCutsceneObject(const uint16_t id,
auto clumpmodel = static_cast<ClumpModelInfo*>(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<PedModelInfo>(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<ClumpModelInfo>(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;
}