Skip to content

Commit

Permalink
#5482: Extend IModelDef interface by an additional defFilename property
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 5, 2021
1 parent 192c9b8 commit 81bc118
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
3 changes: 3 additions & 0 deletions include/ieclass.h
Expand Up @@ -341,6 +341,9 @@ class IModelDef :

std::string modName;

// The mod-relative path to the file this DEF was declared in
std::string defFilename;

IModelDef() :
resolved(false),
modName("base")
Expand Down
17 changes: 9 additions & 8 deletions radiantcore/eclass/Doom3ModelDef.h
@@ -1,17 +1,21 @@
#ifndef DOOM3MODELDEF_H_
#define DOOM3MODELDEF_H_
#pragma once

#include "ieclass.h"
#include "ifilesystem.h"
#include "parser/DefTokeniser.h"

namespace eclass {
namespace eclass
{

class Doom3ModelDef :
public IModelDef
{
private:
std::size_t _parseStamp;

public:
using Ptr = std::shared_ptr<Doom3ModelDef>;

Doom3ModelDef(const std::string& modelDefName) :
_parseStamp(0)
{
Expand All @@ -36,13 +40,13 @@ class Doom3ModelDef :
void clear()
{
// Don't clear the name

resolved = false;
mesh.clear();
skin.clear();
parent.clear();
anims.clear();
modName = "base";
defFileName.clear();
}

// Reads the data from the given tokens into the member variables
Expand Down Expand Up @@ -98,8 +102,5 @@ class Doom3ModelDef :
}
}
};
typedef std::shared_ptr<Doom3ModelDef> Doom3ModelDefPtr;

} // namespace eclass

#endif /*DOOM3MODELDEF_H_*/
} // namespace
25 changes: 11 additions & 14 deletions radiantcore/eclass/EClassManager.cpp
Expand Up @@ -89,7 +89,7 @@ Doom3EntityClassPtr EClassManager::insertUnique(const Doom3EntityClassPtr& eclas
return i.first->second;
}

void EClassManager::resolveModelInheritance(const std::string& name, const Doom3ModelDefPtr& model)
void EClassManager::resolveModelInheritance(const std::string& name, const Doom3ModelDef::Ptr& model)
{
if (model->resolved == true) {
return; // inheritance already resolved
Expand Down Expand Up @@ -253,7 +253,7 @@ IModelDefPtr EClassManager::findModel(const std::string& name)
ensureDefsLoaded();

Models::const_iterator found = _models.find(name);
return (found != _models.end()) ? found->second : Doom3ModelDefPtr();
return (found != _models.end()) ? found->second : Doom3ModelDef::Ptr();
}

void EClassManager::forEachModelDef(ModelDefVisitor& visitor)
Expand Down Expand Up @@ -447,25 +447,21 @@ void EClassManager::parse(TextInputStream& inStr, const vfs::FileInfo& fileInfo,

// Ensure that an Entity class with this name already exists
// When reloading entityDef declarations, most names will already be registered
Models::iterator i = _models.find(modelDefName);
auto foundModel = _models.find(modelDefName);

if (i == _models.end())
if (foundModel == _models.end())
{
// Does not exist yet, allocate a new one

// Allocate an empty ModelDef
Doom3ModelDefPtr model(new Doom3ModelDef(modelDefName));
auto model = std::make_shared<Doom3ModelDef>(modelDefName);

std::pair<Models::iterator, bool> result = _models.insert(
Models::value_type(modelDefName, model)
);

i = result.first;
foundModel = _models.emplace(modelDefName, model).first;
}
else
{
// Model already exists, compare the parse stamp
if (i->second->getParseStamp() == _curParseStamp)
if (foundModel->second->getParseStamp() == _curParseStamp)
{
rWarning() << "[eclassmgr]: Model "
<< modelDefName << " redefined" << std::endl;
Expand All @@ -474,10 +470,11 @@ void EClassManager::parse(TextInputStream& inStr, const vfs::FileInfo& fileInfo,

// Model structure is allocated and in the map,
// invoke the parser routine
i->second->setParseStamp(_curParseStamp);
foundModel->second->setParseStamp(_curParseStamp);

i->second->parseFromTokens(tokeniser);
i->second->setModName(modDir);
foundModel->second->parseFromTokens(tokeniser);
foundModel->second->setModName(modDir);
foundModel->second->defFilename = fileInfo.fullPath();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/eclass/EClassManager.h
Expand Up @@ -39,7 +39,7 @@ class EClassManager :
typedef std::map<std::string, Doom3EntityClassPtr> EntityClasses;
EntityClasses _entityClasses;

typedef std::map<std::string, Doom3ModelDefPtr> Models;
typedef std::map<std::string, Doom3ModelDef::Ptr> Models;
Models _models;

// The worker thread loading the eclasses will be managed by this
Expand Down Expand Up @@ -109,7 +109,7 @@ class EClassManager :
void parse(TextInputStream& inStr, const vfs::FileInfo& fileInfo, const std::string& modDir);

// Recursively resolves the inheritance of the model defs
void resolveModelInheritance(const std::string& name, const Doom3ModelDefPtr& model);
void resolveModelInheritance(const std::string& name, const Doom3ModelDef::Ptr& model);

void parseDefFiles();
void resolveInheritance();
Expand Down

0 comments on commit 81bc118

Please sign in to comment.