Skip to content

Commit 0be5072

Browse files
Merge pull request #158 from JacobDomagala/152-address-staticanalysis-issues
[#152]: Address `StaticAnalysis` issues
2 parents 5c14f16 + d69e485 commit 0be5072

File tree

15 files changed

+44
-90
lines changed

15 files changed

+44
-90
lines changed

editor/editor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Editor::HandleMouseDrag(const glm::vec2& currentCursorPos, const glm::vec2& axis
246246
}
247247

248248
void
249-
Editor::SetMouseOnObject()
249+
Editor::SetMouseOnObject() const
250250
{
251251
if (m_mouseDrag && (m_movementOnEditorObject || m_movementOnGameObject))
252252
{
@@ -467,9 +467,8 @@ Editor::SetRenderLayerToDraw(int32_t layer)
467467
renderLayerToDraw_ = layer;
468468
}
469469

470-
471470
void
472-
Editor::SetupRendererData()
471+
Editor::SetupRendererData() const
473472
{
474473
renderer::VulkanRenderer::SetupData();
475474

@@ -715,7 +714,7 @@ Editor::DrawBoundingBoxes()
715714
}
716715

717716
void
718-
Editor::DrawGrid()
717+
Editor::DrawGrid() const
719718
{
720719
const auto levelSize = m_currentLevel->GetSize();
721720
const auto grad = m_gridCellSize;

editor/editor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Editor : public Application
118118
GetRenderNodes() const;
119119

120120
void
121-
DrawGrid();
121+
DrawGrid() const;
122122

123123
void
124124
DrawBoundingBoxes();
@@ -178,7 +178,7 @@ class Editor : public Application
178178
// GetEditorObjectByID(Object::ID ID);
179179

180180
void
181-
SetupRendererData();
181+
SetupRendererData() const;
182182

183183
void
184184
DrawEditorObjects();
@@ -217,7 +217,7 @@ class Editor : public Application
217217
ShowCursor(bool choice);
218218

219219
void
220-
SetMouseOnObject();
220+
SetMouseOnObject() const;
221221

222222
void
223223
FreeLevelData();

engine/core/work_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace looper {
88
void
99
WorkQueue::PushWorkUnit(const WorkQueue::Precondition& prec, const WorkQueue::WorkUnit& work)
1010
{
11-
queue_.push_back({prec, work});
11+
queue_.emplace_back(prec, work);
1212
}
1313

1414
void

engine/game/animatable.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,15 @@ Animatable::SetCorrectAnimationPoint(time::milliseconds& updateTime)
8585
auto animationDurationMs =
8686
time::Timer::ConvertToMs(currentState_.m_currentAnimationPoint->m_timeDuration);
8787

88-
if (updateTime >= animationDurationMs)
88+
while (updateTime >= animationDurationMs
89+
&& currentState_.m_currentAnimationPoint != m_animationPoints.begin())
8990
{
90-
do
91-
{
92-
updateTime -= animationDurationMs;
93-
animationValue +=
94-
currentState_.m_currentAnimationEnd - currentState_.m_currentAnimationBegin;
91+
updateTime -= animationDurationMs;
92+
animationValue += currentState_.m_currentAnimationEnd - currentState_.m_currentAnimationBegin;
9593

96-
UpdateAnimationPoint();
97-
animationDurationMs =
98-
time::Timer::ConvertToMs(currentState_.m_currentAnimationPoint->m_timeDuration);
99-
} while (updateTime >= animationDurationMs
100-
&& currentState_.m_currentAnimationPoint != m_animationPoints.begin());
94+
UpdateAnimationPoint();
95+
animationDurationMs =
96+
time::Timer::ConvertToMs(currentState_.m_currentAnimationPoint->m_timeDuration);
10197
}
10298

10399
return animationValue;

engine/game/level.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ Level::GenerateTextureForCollision()
469469
const size_t numChannels = 4;
470470
const auto size = static_cast< size_t >(width * height * numChannels);
471471

472-
auto* data = new unsigned char[size];
472+
auto data = FileManager::ImageHandleType{new unsigned char[size],
473+
[](const uint8_t* ptr) { delete[] ptr; }};
473474
const auto& nodes = m_pathFinder.GetAllNodes();
474475

475476
for (size_t h = 0; h < height; ++h)
@@ -488,10 +489,7 @@ Level::GenerateTextureForCollision()
488489
}
489490
}
490491

491-
collisionTextureData_ = {FileManager::ImageHandleType{reinterpret_cast< unsigned char* >(data),
492-
[](const uint8_t* ptr) { delete[] ptr; }},
493-
{width, height},
494-
numChannels};
492+
collisionTextureData_ = {std::move(data), {width, height}, numChannels};
495493

496494
// To avoid blurry edges
497495
renderer::TextureProperties props;

engine/game/object.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "object.hpp"
22

33
namespace looper {
4-
5-
static std::string
4+
namespace {
5+
std::string
66
TypeToString(ObjectType type)
77
{
88
std::string typeStr;
@@ -41,6 +41,7 @@ TypeToString(ObjectType type)
4141

4242
return typeStr;
4343
}
44+
} // namespace
4445

4546
ObjectType
4647
Object::GetTypeFromString(const std::string& stringType)

engine/game/player.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ class Player : public GameObject
5757
/*void
5858
CreateSprite(const glm::vec2& position, const glm::ivec2& size, const std::string& fileName);*/
5959

60-
void
61-
Hit(int32_t /*dmg*/) override
62-
{
63-
}
64-
6560
private:
6661
void
6762
UpdateInternal(bool isReverse) override;

engine/input/input_manager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BroadcastEvent(const auto& listeners, auto& event)
2525
}
2626

2727
void
28+
// cppcheck-suppress constParameterCallback
2829
InputManager::InternalKeyCallback(GLFWwindow* window, int32_t key, int32_t scancode,
2930
int32_t action, int32_t mods)
3031
{
@@ -37,6 +38,7 @@ InputManager::InternalKeyCallback(GLFWwindow* window, int32_t key, int32_t scanc
3738
}
3839

3940
void
41+
// cppcheck-suppress constParameterCallback
4042
InputManager::InternalCharCallback(GLFWwindow* window, uint32_t key)
4143
{
4244
Logger::Trace("GLFW char {}", key);
@@ -47,6 +49,7 @@ InputManager::InternalCharCallback(GLFWwindow* window, uint32_t key)
4749
}
4850

4951
void
52+
// cppcheck-suppress constParameterCallback
5053
InputManager::InternalMouseButtonCallback(GLFWwindow* window, int32_t button, int32_t action,
5154
int32_t mods)
5255
{
@@ -58,6 +61,7 @@ InputManager::InternalMouseButtonCallback(GLFWwindow* window, int32_t button, in
5861
}
5962

6063
void
64+
// cppcheck-suppress constParameterCallback
6165
InputManager::InternalCursorPositionCallback(GLFWwindow* window, double xPos, double yPos)
6266
{
6367
Logger::Trace("GLFW cursor pos {} {}", xPos, yPos);
@@ -69,6 +73,7 @@ InputManager::InternalCursorPositionCallback(GLFWwindow* window, double xPos, do
6973
}
7074

7175
void
76+
// cppcheck-suppress constParameterCallback
7277
InputManager::InternalMouseScrollCallback(GLFWwindow* window, double xOffset, double yOffset)
7378
{
7479
Logger::Trace("GLFW scroll {} {}", xOffset, yOffset);
@@ -79,6 +84,7 @@ InputManager::InternalMouseScrollCallback(GLFWwindow* window, double xOffset, do
7984
}
8085

8186
void
87+
// cppcheck-suppress constParameterCallback
8288
InputManager::InternalWindowFocusCallback(GLFWwindow* window, int32_t focused)
8389
{
8490
Logger::Trace("GLFW window focus {}", focused);

engine/renderer/buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Buffer::CopyData(const void* data) const
5454
}
5555

5656
void
57-
Buffer::CopyDataWithStaging(void* data, size_t dataSize) const
57+
Buffer::CopyDataWithStaging(const void* data, const size_t dataSize) const
5858
{
5959
VkBuffer stagingBuffer = {};
6060
VkDeviceMemory stagingBufferMemory = {};
@@ -72,7 +72,7 @@ Buffer::CopyDataWithStaging(void* data, size_t dataSize) const
7272
}
7373

7474
void
75-
Buffer::CopyDataToImageWithStaging(VkImage image, void* data, size_t dataSize,
75+
Buffer::CopyDataToImageWithStaging(VkImage image, const void* data, const size_t dataSize,
7676
const std::vector< VkBufferImageCopy >& copyRegions)
7777
{
7878
VkBuffer stagingBuffer = {};

engine/renderer/buffer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class Buffer
3939
CopyData(const void* data) const;
4040

4141
void
42-
CopyDataWithStaging(void* data, size_t dataSize) const;
42+
CopyDataWithStaging(const void* data, const size_t dataSize) const;
4343

4444
static void
45-
CopyDataToImageWithStaging(VkImage image, void* data, size_t dataSize,
45+
CopyDataToImageWithStaging(VkImage image, const void* data, const size_t dataSize,
4646
const std::vector< VkBufferImageCopy >& copyRegions);
4747

4848
void

0 commit comments

Comments
 (0)