Skip to content

Pvs studio fixes #186

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

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Source/Activities/AreaEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void AreaEditor::Update() {
}
// Open the save scene dialog to ask user where to save it then
else {
m_PreviousMode = m_PreviousMode;
m_PreviousMode = m_EditorMode;
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Activities/AssemblyEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void AssemblyEditor::Update() {
}
// Open the save scene dialog to ask user where to save it then
else {
m_PreviousMode = m_PreviousMode;
m_PreviousMode = m_EditorMode;
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Activities/GibEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void GibEditor::Update() {
}
// Open the save object dialog to ask user where to save it then
else {
m_PreviousMode = m_PreviousMode;
m_PreviousMode = m_EditorMode;
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
Expand Down
7 changes: 2 additions & 5 deletions Source/Activities/MultiplayerServerLobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,8 @@ void MultiplayerServerLobby::DrawGUI(BITMAP* pTargetBitmap, const Vector& target
m_pRootBox->SetPositionAbs(0, 0);

// We need to manually draw UI's to intermediate buffer first, then to the player's backbuffer to make it centered on each player's screen.
for (int i = 0; i < 4; i++) {
if (i < c_MaxClients)
finalDestBitmap = g_FrameMan.GetNetworkBackBufferIntermediateGUI8Current(i);
else
finalDestBitmap = pTargetBitmap;
for (int i = 0; i < c_MaxClients; i++) {
finalDestBitmap = g_FrameMan.GetNetworkBackBufferIntermediateGUI8Current(i);

AllegroScreen drawScreen(drawBitmap);
m_pGUIController->Draw(&drawScreen);
Expand Down
2 changes: 1 addition & 1 deletion Source/Activities/SceneEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void SceneEditor::Update() {
}
// Open the save scene dialog to ask user where to save it then
else {
m_PreviousMode = m_PreviousMode;
m_PreviousMode = m_EditorMode;
m_EditorMode = EditorActivity::SAVEDIALOG;
m_ModeChange = true;
}
Expand Down
19 changes: 5 additions & 14 deletions Source/Entities/ACRocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,11 @@ void ACRocket::PreControllerUpdate() {
m_Paths[RIGHT][m_GearState].SetHFlip(m_HFlipped);
m_Paths[LEFT][m_GearState].SetHFlip(!m_HFlipped);

if (!m_LimbPushForcesAndCollisionsDisabled) {
if (m_pRLeg) {
m_pRFootGroup->PushAsLimb(m_Pos.GetFloored() + RotateOffset(m_pRLeg->GetParentOffset()), m_pRLeg->GetMaxLength(), m_Vel, m_Rotation, m_Paths[RIGHT][m_GearState], deltaTime, nullptr, true);
}
if (m_pLLeg) {
m_pLFootGroup->PushAsLimb(m_Pos.GetFloored() + RotateOffset(m_pLLeg->GetParentOffset()), m_pLLeg->GetMaxLength(), m_Vel, m_Rotation, m_Paths[LEFT][m_GearState], deltaTime, nullptr, true);
}
} else {
if (m_pRLeg) {
m_pRFootGroup->PushAsLimb(m_Pos.GetFloored() + RotateOffset(m_pRLeg->GetParentOffset()), m_pRLeg->GetMaxLength(), m_Vel, m_Rotation, m_Paths[RIGHT][m_GearState], deltaTime, nullptr, true);
}
if (m_pLLeg) {
m_pLFootGroup->PushAsLimb(m_Pos.GetFloored() + RotateOffset(m_pLLeg->GetParentOffset()), m_pLLeg->GetMaxLength(), m_Vel, m_Rotation, m_Paths[LEFT][m_GearState], deltaTime, nullptr, true);
}
if (m_pRLeg) {
m_pRFootGroup->PushAsLimb(m_Pos.GetFloored() + RotateOffset(m_pRLeg->GetParentOffset()), m_pRLeg->GetMaxLength(), m_Vel, m_Rotation, m_Paths[RIGHT][m_GearState], deltaTime, nullptr, true);
}
if (m_pLLeg) {
m_pLFootGroup->PushAsLimb(m_Pos.GetFloored() + RotateOffset(m_pLLeg->GetParentOffset()), m_pLLeg->GetMaxLength(), m_Vel, m_Rotation, m_Paths[LEFT][m_GearState], deltaTime, nullptr, true);
}
}

Expand Down
6 changes: 0 additions & 6 deletions Source/Entities/ACraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ bool ACraft::HandlePieCommand(PieSliceType pieSliceIndex) {
} else if (pieSliceIndex == PieSliceType::Sentry) {
m_AIMode = AIMODE_SENTRY;
m_DeliveryState = FALL;
} else if (pieSliceIndex == PieSliceType::Return) {
m_AIMode = AIMODE_RETURN;
m_DeliveryState = LAUNCH;
} else if (pieSliceIndex == PieSliceType::GoTo) {
m_AIMode = AIMODE_GOTO;
m_DeliveryState = FALL;
Expand Down Expand Up @@ -552,7 +549,6 @@ void ACraft::DropAllInventory() {
m_Inventory.erase(exitee);
// Reset timer interval and quit until next one is due
m_ExitTimer.Reset();
break;
} else {
(*exitee)->SetVel(m_Vel + exitVel * antiGravBoost);
(*exitee)->SetAngularVel(5.0F * RandomNormalNum());
Expand All @@ -566,9 +562,7 @@ void ACraft::DropAllInventory() {
m_Inventory.erase(exitee);
// Reset timer interval and quit until next one is due
m_ExitTimer.Reset();
break;
}
droppedSomething = true;
}

if (m_Inventory.empty()) {
Expand Down
28 changes: 15 additions & 13 deletions Source/Entities/Attachable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,23 +381,25 @@ void Attachable::Update() {
m_Team = m_Parent->GetTeam();

MOSRotating* rootParentAsMOSR = dynamic_cast<MOSRotating*>(GetRootParent());
float currentRotAngleOffset = (GetRotAngle() * GetFlipFactor()) - rootParentAsMOSR->GetRotAngle();
if (rootParentAsMOSR && CanCollideWithTerrain()) {
// Note: This safety check exists to ensure the parent's AtomGroup contains this Attachable's Atoms in a subgroup. Hardcoded Attachables need this in order to work, since they're cloned before their parent's AtomGroup exists.
if (!rootParentAsMOSR->GetAtomGroup()->ContainsSubGroup(m_AtomSubgroupID)) {
AddOrRemoveAtomsFromRootParentAtomGroup(true, false);
}
if (rootParentAsMOSR) {
float currentRotAngleOffset = (GetRotAngle() * GetFlipFactor()) - rootParentAsMOSR->GetRotAngle();
if (CanCollideWithTerrain()) {
// Note: This safety check exists to ensure the parent's AtomGroup contains this Attachable's Atoms in a subgroup. Hardcoded Attachables need this in order to work, since they're cloned before their parent's AtomGroup exists.
if (!rootParentAsMOSR->GetAtomGroup()->ContainsSubGroup(m_AtomSubgroupID)) {
AddOrRemoveAtomsFromRootParentAtomGroup(true, false);
}

if (std::abs(currentRotAngleOffset - m_PrevRotAngleOffset) > 0.01745F) { // Update for 1 degree differences
Matrix atomRotationForSubgroup(rootParentAsMOSR->FacingAngle(GetRotAngle()) - rootParentAsMOSR->FacingAngle(rootParentAsMOSR->GetRotAngle()));
Vector atomOffsetForSubgroup(g_SceneMan.ShortestDistance(rootParentAsMOSR->GetPos(), m_Pos, g_SceneMan.SceneWrapsX()).FlipX(rootParentAsMOSR->IsHFlipped()));
Matrix rootParentAngleToUse(rootParentAsMOSR->GetRotAngle() * rootParentAsMOSR->GetFlipFactor());
atomOffsetForSubgroup /= rootParentAngleToUse;
rootParentAsMOSR->GetAtomGroup()->UpdateSubAtoms(GetAtomSubgroupID(), atomOffsetForSubgroup, atomRotationForSubgroup);
if (std::abs(currentRotAngleOffset - m_PrevRotAngleOffset) > 0.01745F) { // Update for 1 degree differences
Matrix atomRotationForSubgroup(rootParentAsMOSR->FacingAngle(GetRotAngle()) - rootParentAsMOSR->FacingAngle(rootParentAsMOSR->GetRotAngle()));
Vector atomOffsetForSubgroup(g_SceneMan.ShortestDistance(rootParentAsMOSR->GetPos(), m_Pos, g_SceneMan.SceneWrapsX()).FlipX(rootParentAsMOSR->IsHFlipped()));
Matrix rootParentAngleToUse(rootParentAsMOSR->GetRotAngle() * rootParentAsMOSR->GetFlipFactor());
atomOffsetForSubgroup /= rootParentAngleToUse;
rootParentAsMOSR->GetAtomGroup()->UpdateSubAtoms(GetAtomSubgroupID(), atomOffsetForSubgroup, atomRotationForSubgroup);
}
}
m_PrevRotAngleOffset = currentRotAngleOffset;
}
m_DeepCheck = false;
m_PrevRotAngleOffset = currentRotAngleOffset;
}

MOSRotating::Update();
Expand Down
6 changes: 0 additions & 6 deletions Source/Entities/MOSParticle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ void MOSParticle::Travel() {
m_Atom->ClearMOIDIgnoreList();

if (m_SpriteAnimMode == ONCOLLIDE) {
// Change angular velocity after collision.
if (hitCount >= 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also makes hitCount unused

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should actually return hitcount from Atom travel instead?

m_AngularVel *= 0.5F * velMag * RandomNormalNum();
m_AngularVel = -m_AngularVel;
}

// TODO: Rework this so it's less incomprehensible black magic math and not driven by AngularVel.
double newFrame = m_Rotation.GetRadAngle();

Expand Down
2 changes: 0 additions & 2 deletions Source/Entities/MOSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ bool MOSprite::HitTestAtPixel(int pixelX, int pixelY, bool validOnly) const {
}

void MOSprite::SetFrame(unsigned int newFrame) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure this is lua accessible so I'd rather this accept int instead, to avoid underflow issues

if (newFrame < 0)
newFrame = 0;
if (newFrame >= m_FrameCount)
newFrame = m_FrameCount - 1;

Expand Down
5 changes: 0 additions & 5 deletions Source/GUI/GUIBanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ GUIBanner::GUIBanner() {
m_BannerPosY = 240;
m_FlySpeed = 1500;
m_FlySpacing = 100;
m_BannerChars.clear();
m_AnimMode = BLINKING;
m_AnimState = NOTSTARTED;
m_TotalAnimTimer.Reset();
Expand Down Expand Up @@ -328,8 +327,6 @@ void GUIBanner::Draw(BITMAP* pTargetBitmap) {
}
if (c == '\t') {
}
if (c < 0)
c += m_CharIndexCap;
if (c < 32 || c >= m_CharIndexCap)
continue;

Expand Down Expand Up @@ -362,8 +359,6 @@ int GUIBanner::CalculateWidth(const std::string text, FontMode mode) const {
*/
continue;
}
if (c < 0)
c += m_CharIndexCap;
if (c < 32 || c >= m_CharIndexCap)
continue;

Expand Down
6 changes: 0 additions & 6 deletions Source/GUI/GUIFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ void GUIFont::Draw(GUIBitmap* Bitmap, int X, int Y, const std::string& Text, uns
if (c == '\t') {
X += m_Characters[' '].m_Width * 4;
}
if (c < 0) {
c += m_CharIndexCap;
}
if (c < 32 || c >= m_CharIndexCap) {
continue;
}
Expand Down Expand Up @@ -270,9 +267,6 @@ int GUIFont::CalculateWidth(const std::string& Text) {
Width = 0;
continue;
}
if (c < 0) {
c += m_CharIndexCap;
}

if (c < 32 || c >= m_CharIndexCap) {
continue;
Expand Down
33 changes: 14 additions & 19 deletions Source/Menus/MetagameGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void MetagameGUI::Clear() {
m_AnimMetaPlayer = Players::NoPlayer;
m_AnimDefenseTeam = Activity::NoTeam;
m_AnimActivityChange = false;
Scene* m_pAnimScene = 0;
m_pAnimScene = 0;
m_AnimRatio = 0;
m_AnimProgress = 0;
m_AnimTotalFunds = 0;
Expand Down Expand Up @@ -4965,24 +4965,19 @@ void MetagameGUI::UpdatePostBattleResidents(float progress) {
m_apPlayerBrainTravelLabel[mp]->SetVisible(progress <= 0);

if (progress <= 0) {
// Death mask
if (progress > 0)
std::snprintf(str, sizeof(str), "%c", -26);
// Brain with line blinking over it and the funds still showing
else {
if (quadIndex <= 1) {
if (m_aAnimDestroyed[mp])
std::snprintf(str, sizeof(str), "%c %.0f oz ", -58, m_aBattleFunds[mp]);
else
std::snprintf(str, sizeof(str), "%c %.0f oz %c%c", -58, m_aBattleFunds[mp], m_aBattleAttacker[mp] ? -46 : -47, -26);
// std::snprintf(str, sizeof(str), "%c %.0f oz %c", -58, m_aBattleFunds[mp], m_AnimTimer2.AlternateReal(200) ? -39 : -26);
} else {
if (m_aAnimDestroyed[mp])
std::snprintf(str, sizeof(str), " %c %.0f oz", -58, m_aBattleFunds[mp]);
else
std::snprintf(str, sizeof(str), "%c%c %c %.0f oz", m_aAnimDestroyed[mp] ? ' ' : -26, m_aBattleAttacker[mp] ? -46 : -47, -58, m_aBattleFunds[mp]);
// std::snprintf(str, sizeof(str), "%c %c %.0f oz", m_AnimTimer2.AlternateReal(200) ? -39 : -26, -58, m_aBattleFunds[mp]);
}
if (quadIndex <= 1) {
if (m_aAnimDestroyed[mp])
std::snprintf(str, sizeof(str), "%c %.0f oz ", -58, m_aBattleFunds[mp]);
else
std::snprintf(str, sizeof(str), "%c %.0f oz %c%c", -58, m_aBattleFunds[mp], m_aBattleAttacker[mp] ? -46 : -47, -26);
// std::snprintf(str, sizeof(str), "%c %.0f oz %c", -58, m_aBattleFunds[mp], m_AnimTimer2.AlternateReal(200) ? -39 : -26);
} else {
if (m_aAnimDestroyed[mp])
std::snprintf(str, sizeof(str), " %c %.0f oz", -58, m_aBattleFunds[mp]);
else
std::snprintf(str, sizeof(str), "%c%c %c %.0f oz", m_aAnimDestroyed[mp] ? ' ' : -26, m_aBattleAttacker[mp] ? -46 : -47, -58, m_aBattleFunds[mp]);
// std::snprintf(str, sizeof(str), "%c %c %.0f oz", m_AnimTimer2.AlternateReal(200) ? -39 : -26, -58, m_aBattleFunds[mp]);
}
m_apPlayerBrainTravelLabel[mp]->SetText(str);
m_apPlayerBrainTravelLabel[mp]->SetToolTip("The specific brain that is being sent in to attack this place, and the funds he has been budgeted to do so with.");
Expand Down Expand Up @@ -5634,7 +5629,7 @@ void MetagameGUI::PlayerTextIndication(int metaPlayer, std::string text, const V

void MetagameGUI::FundsChangeIndication(int metaPlayer, float change, const Vector& screenPos, double animLengthMS) {
char str[256];
std::snprintf(str, sizeof(str), change >= 1.0 ? "%c +%.0f oz" : (change <= -1.0 ? "%c %.0f oz" : "%c %.0f oz"), -58, change);
std::snprintf(str, sizeof(str), change >= 1.0 ? "%c +%.0f oz" : "%c %.0f oz", -58, change);
m_apFundsChangeLabel[metaPlayer]->SetText(str);
m_apFundsChangeLabel[metaPlayer]->SetHAlignment(GUIFont::Right);
m_apFundsChangeLabel[metaPlayer]->SetVAlignment(GUIFont::Top);
Expand Down
2 changes: 2 additions & 0 deletions Source/Menus/MetagameGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ namespace RTE {
m_ChannelHeight = channelHeight;
m_CircleSize = circleSize;
m_Square = squareSite;
m_FundsAmount = 0.f;
m_FundsTarget = 0.f;
}
};

Expand Down
2 changes: 1 addition & 1 deletion Source/Menus/SceneEditorGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void SceneEditorGUI::Update() {
}

// Apply the team to the current actor, if applicable
if (m_pCurrentObject && m_DrawCurrentObject) {
if (m_DrawCurrentObject) {
// Set the team of SceneObject based on what's been selected
// Only if full featured mode, otherwise it's based on the controller when placed
if (m_FeatureSet == ONLOADEDIT)
Expand Down