Skip to content

Commit

Permalink
Remove useless code in fgd, and support duplicate
Browse files Browse the repository at this point in the history
Remove useless code in fgd, and support duplicate entries if classtype not equal.
  • Loading branch information
UnrealKaraulov committed Dec 17, 2023
1 parent bad94c0 commit 1537e51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
58 changes: 28 additions & 30 deletions src/editor/Fgd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ Fgd::~Fgd()
}
}

FgdClass* Fgd::getFgdClass(std::string cname)
FgdClass* Fgd::getFgdClass(const std::string & cname)
{
if (classMap.size() && cname.size() && classMap.find(cname) != classMap.end())
{
return classMap[cname];
}
return NULL;
auto it = std::find_if(classes.begin(), classes.end(), [&cname](const auto& fgdClass) {
return fgdClass->name == cname;
});

return (it != classes.end()) ? *it : NULL;
}

void Fgd::merge(Fgd* other)
Expand All @@ -48,23 +48,22 @@ void Fgd::merge(Fgd* other)
this->lineNum = 0;
}

for (auto it : other->classMap)
{
std::string className = it.first;
FgdClass* fgdClass = it.second;
for (FgdClass* otherClass : other->classes)
{
auto it = std::find_if(classes.begin(), classes.end(), [&otherClass](const auto& fgdClass) {
return fgdClass->name == otherClass->name && fgdClass->classType == otherClass->classType;
});

if (classMap.find(className) != classMap.end())
{
print_log(get_localized_string(LANG_0299), className, other->name);
if (it != classes.end())
{
print_log(get_localized_string(LANG_0299), otherClass->name, other->name);
continue;
}

FgdClass* newClass = new FgdClass();
*newClass = *fgdClass;

classes.push_back(newClass);
classMap[className] = newClass;
}
}
else
{
classes.push_back(new FgdClass(*otherClass));
}
}
}

bool Fgd::parse()
Expand Down Expand Up @@ -558,12 +557,6 @@ std::string Fgd::getValueInQuotes(std::string s)

void Fgd::processClassInheritance()
{
for (int i = 0; i < classes.size(); i++)
{
classMap[classes[i]->name] = classes[i];
//print_log(get_localized_string(LANG_0309),classes[i]->name);
}

for (int i = 0; i < classes.size(); i++)
{
if (classes[i]->classType == FGD_CLASS_BASE)
Expand Down Expand Up @@ -736,13 +729,18 @@ void FgdClass::getBaseClasses(Fgd* fgd, std::vector<FgdClass*>& inheritanceList)
{
for (int i = (int)baseClasses.size() - 1; i >= 0; i--)
{
if (fgd->classMap.find(baseClasses[i]) == fgd->classMap.end())
auto it = std::find_if(fgd->classes.begin(), fgd->classes.end(), [this, i](const auto& fgdClass) {
return fgdClass->name == baseClasses[i];
});

if (it == fgd->classes.end())
{
print_log(get_localized_string(LANG_0310), baseClasses[i], name);
continue;
}
inheritanceList.push_back(fgd->classMap[baseClasses[i]]);
fgd->classMap[baseClasses[i]]->getBaseClasses(fgd, inheritanceList);

inheritanceList.push_back(*it);
(*it)->getBaseClasses(fgd, inheritanceList);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/editor/Fgd.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class Fgd
std::string path;
std::string name;
std::vector<FgdClass*> classes;
std::map<std::string, FgdClass*> classMap;

std::vector<FgdGroup> pointEntGroups;
std::vector<FgdGroup> solidEntGroups;
Expand All @@ -129,7 +128,7 @@ class Fgd
bool parse();
void merge(Fgd* other);

FgdClass* getFgdClass(std::string cname);
FgdClass* getFgdClass(const std::string & cname);

private:
int lineNum = 0;
Expand Down

0 comments on commit 1537e51

Please sign in to comment.