Skip to content

Commit 0e8f753

Browse files
authored
Merge pull request #244 from Architector4/patch-some-code-cleanups
cppcheck lints - change a lot of method params to use const ref, etc etc
2 parents 2906eb8 + 193ef3d commit 0e8f753

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+369
-346
lines changed

Source/Activities/AssemblyEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ void AssemblyEditor::Draw(BITMAP* pTargetBitmap, const Vector& targetPos) {
377377
EditorActivity::Draw(pTargetBitmap, targetPos);
378378
}
379379

380-
BunkerAssembly* AssemblyEditor::BuildAssembly(std::string saveAsName) {
380+
BunkerAssembly* AssemblyEditor::BuildAssembly(const std::string& saveAsName) {
381381
// Create new bunker assembly to save
382382
BunkerAssembly* pBA = new BunkerAssembly();
383383
pBA->Create(m_pEditorGUI->GetCurrentAssemblyScheme());

Source/Activities/AssemblyEditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace RTE {
107107
/// it's pointer. Owhership IS transfered.
108108
/// @param saveAsName New assembly name.
109109
/// @return Built BunkerAssembly
110-
BunkerAssembly* BuildAssembly(std::string saveAsName);
110+
BunkerAssembly* BuildAssembly(const std::string& saveAsName);
111111

112112
/// Saves the current BunkerAssembly to an appropriate ini file, and asks user if they want to overwrite first if a BunkerAssembly of this name exists.
113113
/// @param saveAsName The name of the new BunkerAssembly to be saved.

Source/Activities/GAScripted.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ namespace RTE {
4949
/// @return An error return value signaling sucess or any particular failure.
5050
/// Anything below 0 is an error signal.
5151
int Create(std::string scriptPath, std::string scriptClassName) {
52-
m_ScriptPath = scriptPath;
53-
m_LuaClassName = scriptClassName;
52+
m_ScriptPath = std::move(scriptPath);
53+
m_LuaClassName = std::move(scriptClassName);
5454
return Create();
5555
};
5656

Source/Activities/GATutorial.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ GATutorial::~GATutorial() {
3535
Destroy(true);
3636
}
3737

38-
GATutorial::TutStep::TutStep(std::string text, int stepDuration, std::string screensPath, int frameCount, int frameDuration) {
39-
m_Text = text;
40-
m_Duration = stepDuration;
41-
m_FrameDuration = frameDuration;
38+
GATutorial::TutStep::TutStep(std::string text, int stepDuration, const std::string& screensPath, int frameCount, int frameDuration) :
39+
m_Text(std::move(text)),
40+
m_Duration(stepDuration),
41+
m_FrameDuration(frameDuration)
42+
{
4243

4344
if (!screensPath.empty()) {
4445
ContentFile(screensPath.c_str()).GetAsAnimation(m_pScreens, frameCount);
@@ -677,7 +678,7 @@ void GATutorial::DrawGUI(BITMAP* pTargetBitmap, const Vector& targetPos, int whi
677678
int timePhase = (int)m_AreaTimer.GetElapsedRealTimeMS() % 1200;
678679
revealText = revealText + (timePhase > 900 ? "..." : (timePhase > 600 ? ".. " : (timePhase > 300 ? ". " : " ")));
679680
}
680-
g_FrameMan.GetSmallFont()->DrawAligned(&pBitmapInt, screenTextPos.m_X, screenTextPos.m_Y, revealText.c_str(), GUIFont::Centre);
681+
g_FrameMan.GetSmallFont()->DrawAligned(&pBitmapInt, screenTextPos.m_X, screenTextPos.m_Y, revealText, GUIFont::Centre);
681682
}
682683
}
683684

Source/Activities/GATutorial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace RTE {
150150
// The duration of one frame
151151
int m_FrameDuration;
152152

153-
TutStep(std::string text, int stepDuration, std::string screensPath = "", int frameCount = 1, int frameDuration = 250);
153+
TutStep(std::string text, int stepDuration, const std::string& screensPath = "", int frameCount = 1, int frameDuration = 250);
154154
};
155155

156156
// Member variables

Source/Activities/GameActivity.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void GameActivity::Destroy(bool notInherited) {
282282
Clear();
283283
}
284284

285-
void GameActivity::SetTeamTech(int team, std::string tech) {
285+
void GameActivity::SetTeamTech(int team, const std::string& tech) {
286286
if (team >= Teams::TeamOne && team < Teams::MaxTeamCount) {
287287
if (tech == "-All-" || tech == "-Random-")
288288
m_TeamTech[team] = tech;
@@ -388,7 +388,7 @@ void GameActivity::SwitchToPrevActor(int player, int team, Actor* pSkip) {
388388
}
389389
}
390390

391-
void GameActivity::AddObjectivePoint(std::string description, Vector objPos, int whichTeam, ObjectiveArrowDir arrowDir) {
391+
void GameActivity::AddObjectivePoint(const std::string& description, Vector objPos, int whichTeam, ObjectiveArrowDir arrowDir) {
392392
m_Objectives.push_back(ObjectivePoint(description, objPos, whichTeam, arrowDir));
393393
}
394394

@@ -468,7 +468,7 @@ int GameActivity::SetOverridePurchaseList(const Loadout* pLoadout, int player) {
468468
return finalListCost;
469469
}
470470

471-
int GameActivity::SetOverridePurchaseList(std::string loadoutName, int player) {
471+
int GameActivity::SetOverridePurchaseList(const std::string& loadoutName, int player) {
472472
// Find out the native module of this player
473473
int nativeModule = 0;
474474
MetaPlayer* pMetaPlayer = g_MetaMan.GetMetaPlayerOfInGamePlayer(player);
@@ -664,7 +664,7 @@ void GameActivity::SetupPlayers() {
664664

665665
int GameActivity::Start() {
666666
// Set the split screen config before the Scene (and it SceneLayers, specifially) are loaded
667-
int humanCount = GetHumanCount();
667+
uint8_t humanCount = GetHumanCount();
668668
// Depending on the resolution aspect ratio, split first horizontally (if wide screen)
669669
if (((float)g_WindowMan.GetResX() / (float)g_WindowMan.GetResY()) >= 1.6)
670670
g_FrameMan.ResetSplitScreens(humanCount > 1, humanCount > 2);
@@ -2474,7 +2474,7 @@ void GameActivity::ObjectivePoint::Draw(BITMAP* pTargetBitmap, BITMAP* pArrowBit
24742474
}
24752475
}
24762476

2477-
std::string& GameActivity::GetNetworkPlayerName(int player) {
2477+
const std::string& GameActivity::GetNetworkPlayerName(int player) {
24782478
if (player >= Players::PlayerOne && player < Players::MaxPlayerCount)
24792479
return m_NetworkPlayerNames[player];
24802480
else
@@ -2483,5 +2483,5 @@ std::string& GameActivity::GetNetworkPlayerName(int player) {
24832483

24842484
void GameActivity::SetNetworkPlayerName(int player, std::string name) {
24852485
if (player >= Players::PlayerOne && player < Players::MaxPlayerCount)
2486-
m_NetworkPlayerNames[player] = name;
2486+
m_NetworkPlayerNames[player] = std::move(name);
24872487
}

Source/Activities/GameActivity.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ namespace RTE {
238238
/// @param objPos The very short description of what the objective is (three short words max)
239239
/// @param whichTeam The absolute scene coordiante position of the objective. (default: Teams::TeamOne)
240240
/// @param arrowDir The desired direction of the arrow when the point is on screen. (default: ARROWDOWN)
241-
void AddObjectivePoint(std::string description, Vector objPos, int whichTeam = Teams::TeamOne, ObjectiveArrowDir arrowDir = ARROWDOWN);
241+
void AddObjectivePoint(const std::string& description, Vector objPos, int whichTeam = Teams::TeamOne, ObjectiveArrowDir arrowDir = ARROWDOWN);
242242

243243
/// Sorts all objective points according to their positions on the Y axis.
244244
void YSortObjectivePoints();
@@ -265,7 +265,7 @@ namespace RTE {
265265
/// @param loadoutName The name of the Loadout preset to set the override purchase list to
266266
/// represent.
267267
/// @return The new total value of what's in the override purchase list.
268-
int SetOverridePurchaseList(std::string loadoutName, int player);
268+
int SetOverridePurchaseList(const std::string& loadoutName, int player);
269269

270270
/// Clears all items from a specific player's override purchase list.
271271
/// @param m_PurchaseOverride[player].clear( Which player's override purchase list to clear.
@@ -352,7 +352,7 @@ namespace RTE {
352352

353353
/// Sets tech module name for specified team. Module must set must be loaded.
354354
/// @param team Team to set module, module name, for example Dummy.rte
355-
void SetTeamTech(int team, std::string tech);
355+
void SetTeamTech(int team, const std::string& tech);
356356

357357
/// Indicates whether a specific team is assigned a CPU player in the current game.
358358
/// @param team Which team index to check.
@@ -448,7 +448,7 @@ namespace RTE {
448448
/// Returns network player name
449449
/// @param player Player
450450
/// @return Network player name
451-
std::string& GetNetworkPlayerName(int player);
451+
const std::string& GetNetworkPlayerName(int player);
452452

453453
/// Sets network player name
454454
/// @param player Player number, player name
@@ -470,12 +470,13 @@ namespace RTE {
470470
m_Team = Teams::NoTeam;
471471
m_ArrowDir = ARROWDOWN;
472472
}
473-
ObjectivePoint(const std::string& desc, const Vector& pos, int team = -1, ObjectiveArrowDir arrowDir = ARROWDOWN) {
474-
m_Description = desc;
475-
m_ScenePos = pos;
476-
m_Team = (Teams)team;
477-
m_ArrowDir = arrowDir;
478-
}
473+
474+
ObjectivePoint(std::string desc, const Vector& pos, int team = -1, ObjectiveArrowDir arrowDir = ARROWDOWN) :
475+
m_Description(std::move(desc)),
476+
m_ScenePos(pos),
477+
m_Team((Teams)team),
478+
m_ArrowDir(arrowDir)
479+
{}
479480

480481
/// Simply draws this' arrow relative to a point on a bitmap.
481482
/// @param pTargetBitmap A pointer to the BITMAP to draw on.

Source/Entities/AHuman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ bool AHuman::EquipFirearm(bool doEquip) {
686686
return false;
687687
}
688688

689-
bool AHuman::EquipDeviceInGroup(std::string group, bool doEquip) {
689+
bool AHuman::EquipDeviceInGroup(const std::string& group, bool doEquip) {
690690
if (!(m_pFGArm && m_pFGArm->IsAttached())) {
691691
return false;
692692
}
@@ -748,7 +748,7 @@ bool AHuman::EquipDeviceInGroup(std::string group, bool doEquip) {
748748
return false;
749749
}
750750

751-
bool AHuman::EquipLoadedFirearmInGroup(std::string group, std::string excludeGroup, bool doEquip) {
751+
bool AHuman::EquipLoadedFirearmInGroup(const std::string& group, const std::string& excludeGroup, bool doEquip) {
752752
if (!(m_pFGArm && m_pFGArm->IsAttached())) {
753753
return false;
754754
}

Source/Entities/AHuman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ namespace RTE {
243243
/// @param doEquip Whether to actually equip any matching item found in the inventory, (default: true)
244244
/// or just report that it's there or not.
245245
/// @return Whether a firearm was successfully switched to, or already held.
246-
bool EquipDeviceInGroup(std::string group, bool doEquip = true);
246+
bool EquipDeviceInGroup(const std::string& group, bool doEquip = true);
247247

248248
/// Switches the currently held device (if any) to the first loaded HDFirearm
249249
/// of the specified group in the inventory. If no such weapon is in the
@@ -253,7 +253,7 @@ namespace RTE {
253253
/// @param doEquip Whether to actually equip any matching item found in the inventory, (default: true)
254254
/// or just report that it's there or not.
255255
/// @return Whether a firearm was successfully switched to, or already held.
256-
bool EquipLoadedFirearmInGroup(std::string group, std::string exludeGroup, bool doEquip = true);
256+
bool EquipLoadedFirearmInGroup(const std::string& group, const std::string& exludeGroup, bool doEquip = true);
257257

258258
/// Switches the equipped HeldDevice (if any) to the first found device with the specified preset name in the inventory.
259259
/// If the equipped HeldDevice is of that module and preset name, nothing happens.

Source/Entities/Activity.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ void Activity::ClearPlayers(bool resetFunds) {
467467
m_PlayerCount = m_TeamCount = 0;
468468
}
469469

470-
int Activity::GetHumanCount() const {
471-
int humans = 0;
470+
uint8_t Activity::GetHumanCount() const {
471+
uint8_t humans = 0;
472472
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
473473
if (m_IsActive[player] && m_IsHuman[player]) {
474474
humans++;

0 commit comments

Comments
 (0)