Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a 2nd set of cleanups and optimizations #1517

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ void plClient::IChangeResolution(int width, int height)
HMONITOR monitor = MonitorFromWindow(fWindowHndl, MONITOR_DEFAULTTONULL);
if (!monitor)
return;
MONITORINFOEXW moninfo;
memset(&moninfo, 0, sizeof(moninfo));
MONITORINFOEXW moninfo = {};
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
moninfo.cbSize = sizeof(moninfo);
GetMonitorInfoW(monitor, &moninfo);

// Fetch a base display settings
DEVMODEW devmode;
memset(&devmode, 0, sizeof(devmode));
DEVMODEW devmode = {};
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
devmode.dmSize = sizeof(devmode);
EnumDisplaySettingsW(moninfo.szDevice, ENUM_REGISTRY_SETTINGS, &devmode);

Expand Down
18 changes: 8 additions & 10 deletions Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /*
hsAssert(fEngine != nullptr, "Cannot do a dir execute without an engine!");

std::vector<plFileName> files = plFileSystem::ListDir(path, mask);
for (auto iter = files.begin(); iter != files.end(); ++iter)
for (auto& file : files)
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
{
plFileName name = iter->GetFileName();
plFileName name = file.GetFileName();
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
if (AlreadyProcessedFile(path, name))
continue;
AddProcessedFile(path, name);
if (!fEngine->ExecuteFile(*iter))
if (!fEngine->ExecuteFile(file))
{
// Change the following line once we have a better way of reporting
// errors in the parsing
Expand All @@ -90,9 +90,8 @@ bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /*

void pfConsoleDirSrc::ResetProcessedFiles()
{
int i;
for(i=0;i<fProcessedFiles.size(); i++)
delete fProcessedFiles[i];
for (const auto& fProcessedFile : fProcessedFiles)
delete fProcessedFile;
fProcessedFiles.clear();
}

Expand All @@ -104,10 +103,9 @@ bool pfConsoleDirSrc::AlreadyProcessedFile(const plFileName& path, const plFileN
{
if (fCheckProcessedFiles)
{
int i;
for (i=0; i<fProcessedFiles.size(); i++)
{
if (file == fProcessedFiles[i]->fFile && path == fProcessedFiles[i]->fPath)
for (const auto& fProcessedFile : fProcessedFiles)
{
if (file == fProcessedFile->fFile && path == fProcessedFile->fPath)
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "pfConsoleCmd.h"

static const char kTokenSeparators[] = " =\r\n\t,";
static const char kTokenGrpSeps[] = " =\r\n._\t,";
static constexpr char kTokenSeparators[] = " =\r\n\t,";
static constexpr char kTokenGrpSeps[] = " =\r\n._\t,";

std::optional<ST::string> pfConsoleTokenizer::NextNamePart()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,8 @@ void plAgeDescription::CopyFrom(const plAgeDescription& other)

bool plAgeDescription::FindLocation(const plLocation& loc) const
{
for (const plAgePage& page : fPages)
return std::any_of(fPages.begin(), fPages.end(), [this, loc](const plAgePage& page)
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
{
plLocation pageLoc = CalcPageLocation(page.GetName());
if (pageLoc == loc)
return true;
}
return false;
return loc == CalcPageLocation(page.GetName());
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
});
}
12 changes: 6 additions & 6 deletions Sources/Plasma/PubUtilLib/plAnimation/plAGAnim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,17 @@ void plATCAnim::Write(hsStream *stream, hsResMgr *mgr)
stream->WriteLEFloat(fEaseOutLength);

stream->WriteLE32((uint32_t)fMarkers.size());
for (MarkerMap::iterator it = fMarkers.begin(); it != fMarkers.end(); it++)
for (auto& fMarker : fMarkers)
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
{
stream->WriteSafeString(it->first);
stream->WriteLEFloat(it->second);
stream->WriteSafeString(fMarker.first);
stream->WriteLEFloat(fMarker.second);
}

stream->WriteLE32((uint32_t)fLoops.size());
for (LoopMap::iterator loopIt = fLoops.begin(); loopIt != fLoops.end(); loopIt++)
for (auto& fLoop : fLoops)
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
{
stream->WriteSafeString(loopIt->first);
std::pair<float,float>& loop = loopIt->second;
stream->WriteSafeString(fLoop.first);
std::pair<float,float>& loop = fLoop.second;
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
stream->WriteLEFloat(loop.first);
stream->WriteLEFloat(loop.second);
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ plArmatureModBase::~plArmatureModBase()
{
delete fController;

while (fUnusedBones.size() > 0)
while (!fUnusedBones.empty())
{
delete fUnusedBones.back();
fUnusedBones.pop_back();
Expand All @@ -143,7 +143,7 @@ plArmatureModBase::~plArmatureModBase()
bool plArmatureModBase::MsgReceive(plMessage* msg)
{
plArmatureBrain *curBrain = nullptr;
if (fBrains.size() > 0)
if (!fBrains.empty())
{
curBrain = fBrains.back();
if(curBrain->MsgReceive(msg))
Expand Down Expand Up @@ -179,7 +179,7 @@ bool plArmatureModBase::IEval(double time, float elapsed, uint32_t dirty)
{
if (IsFinal())
{
if (fBrains.size())
if (!fBrains.empty())
{
plArmatureBrain *curBrain = fBrains.back();
if (curBrain)
Expand Down Expand Up @@ -345,7 +345,7 @@ void plArmatureModBase::PushBrain(plArmatureBrain *brain)
void plArmatureModBase::PopBrain()
{
plArmatureBrain *oldBrain = nullptr;
if (fBrains.size() > 0)
if (!fBrains.empty())
{
oldBrain = fBrains.back();
oldBrain->Deactivate();
Expand All @@ -362,7 +362,7 @@ void plArmatureModBase::PopBrain()
plArmatureBrain *plArmatureModBase::GetCurrentBrain() const
{
plArmatureBrain *result = nullptr;
if (fBrains.size() > 0)
if (!fBrains.empty())
result = fBrains.back();

return result;
Expand Down
21 changes: 5 additions & 16 deletions Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ void plAvBrainHuman::Activate(plArmatureModBase *avMod)

void plAvBrainHuman::IInitBoneMap()
{
struct tuple {
HumanBoneID fID;
const char * fName;
};

tuple tupleMap[] =
static constexpr std::tuple<HumanBoneID, std::string_view> BoneMap[] =
{
{ Pelvis, "Bone_Root" },
// left leg
Expand Down Expand Up @@ -304,20 +299,14 @@ void plAvBrainHuman::IInitBoneMap()
{ RThumb3, "Bone_RThumb3" },
};

int numTuples = sizeof(tupleMap) / sizeof(tuple);

for(int i = 0; i < numTuples; i++)
for (const auto& [BoneID, BoneName] : BoneMap)
{
HumanBoneID id = tupleMap[i].fID;
ST::string name = tupleMap[i].fName;

const plSceneObject * bone = this->fAvMod->FindBone(name);
if( bone )
if( const plSceneObject * bone = this->fAvMod->FindBone(BoneName) )
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
{
fAvMod->AddBoneMapping(id, bone);
fAvMod->AddBoneMapping(BoneID, bone);
}
else
hsStatusMessageF("Couldn't find standard bone %s.", name.c_str());
hsStatusMessageF("Couldn't find standard bone %s.", BoneName.data());
jfmherokiller marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading