Skip to content

Commit

Permalink
[#26]: Fix cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Aug 1, 2021
1 parent 34e4ccd commit 8a188b6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
18 changes: 9 additions & 9 deletions engine/FileManager/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ FileManager::FileDialog(const std::filesystem::path& defaultPath,
#else


auto cmd = fmt::format("zenity --file-selection --filename={} {} --file-filter=\"",
defaultPath.string(), save ? "--save " : "");

for (const auto& [description, extension] : fileTypes)
{
cmd.append(fmt::format("\"*.{}\" ", extension));
}

cmd.append("\"");
const auto cmd = fmt::format("zenity --file-selection --filename={} {} --file-filter=\"{}\"",
defaultPath.string(), save ? "--save " : "", [&fileTypes] {
std::string types;
for ([[maybe_unused]] const auto& [_, extension] : fileTypes)
{
types.append(fmt::format("\"*.{}\" ", extension));
}
return types;
}());

auto* output = popen(cmd.c_str(), "r");
assert(output);
Expand Down
5 changes: 2 additions & 3 deletions engine/Game/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Level::Load(Application* context, const std::string& pathToLevel)
{
const auto json = FileManager::LoadJsonFile(pathToLevel);

for (auto& [key, value] : json.items())
for (const auto& [key, value] : json.items())
{
if (key == "BACKGROUND")
{
Expand Down Expand Up @@ -174,8 +174,7 @@ Level::Save(const std::string& pathToLevel)
{
case Object::TYPE::PLAYER: {
json["PLAYER"]["name"] = m_player->GetName();
json["PLAYER"]["position"] = {m_player->GetPosition().x,
m_player->GetPosition().y};
json["PLAYER"]["position"] = {m_player->GetPosition().x, m_player->GetPosition().y};
json["PLAYER"]["scale"] = {m_player->GetSprite().GetScale().x,
m_player->GetSprite().GetScale().y};
json["PLAYER"]["rotation"] = m_player->GetSprite().GetRotation();
Expand Down
20 changes: 8 additions & 12 deletions engine/Game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ Player::CheckCollision(const glm::vec2& bulletPosition, Enemy const* enemy, bool
glm::vec2
Player::GetScreenPosition() const
{
glm::vec4 screenPosition =
m_appHandle.GetProjection()
* glm::vec4(m_currentGameObjectState.m_centeredPosition, 0.0f, 1.0f);
glm::vec4 screenPosition = m_appHandle.GetProjection()
* glm::vec4(m_currentGameObjectState.m_centeredPosition, 0.0f, 1.0f);
return glm::vec2(screenPosition.x, screenPosition.y);
}

Expand All @@ -81,15 +80,12 @@ Player::UpdateInternal(bool isReverse)
{
if (m_appHandle.IsGame())
{
if (!isReverse)
{
const auto gameHandle = ConvertToGameHandle();
const auto cursorPos = gameHandle->ScreenToGlobal(gameHandle->GetCursor());
const auto spritePosition = m_currentGameObjectState.m_position;

m_currentState.m_viewAngle =
glm::atan(spritePosition.y - cursorPos.y, spritePosition.x - cursorPos.x);
}
const auto gameHandle = ConvertToGameHandle();
const auto cursorPos = gameHandle->ScreenToGlobal(gameHandle->GetCursor());
const auto spritePosition = m_currentGameObjectState.m_position;

m_currentState.m_viewAngle =
glm::atan(spritePosition.y - cursorPos.y, spritePosition.x - cursorPos.x);
}

m_sprite.Rotate(m_currentState.m_viewAngle);
Expand Down
32 changes: 16 additions & 16 deletions engine/Render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "TextureLibrary.hpp"
#include "VertexArray.hpp"

#include <array>
#include <glm/gtc/matrix_transform.hpp>
#include <memory>
#include <array>

namespace dgame {

Expand All @@ -28,10 +28,10 @@ struct LineVertex

struct RendererData
{
static inline const uint32_t MaxQuads = 20000;
static inline const uint32_t MaxVertices = MaxQuads * 4;
static inline const uint32_t MaxIndices = MaxQuads * 6;
static inline const uint32_t MaxTextureSlots = 32; // TODO: RenderCaps
static constexpr uint32_t MaxQuads = 20000;
static constexpr uint32_t MaxVertices = MaxQuads * 4;
static constexpr uint32_t MaxIndices = MaxQuads * 6;
static constexpr uint32_t MaxTextureSlots = 32; // TODO: RenderCaps

std::shared_ptr< VertexArray > QuadVertexArray;
std::shared_ptr< VertexBuffer > QuadVertexBuffer;
Expand All @@ -48,8 +48,8 @@ struct RendererData

struct LineRendererData
{
static inline const uint32_t MaxLines = 200000;
static inline const uint32_t MaxVertices = MaxLines * 2;
static constexpr uint32_t MaxLines = 200000;
static constexpr uint32_t MaxVertices = MaxLines * 2;
uint32_t NumLines = 0;

std::shared_ptr< VertexArray > LineVertexArray;
Expand All @@ -70,11 +70,11 @@ Renderer::Init()

s_Data.QuadVertexBuffer = std::make_shared< VertexBuffer >(
static_cast< uint32_t >(s_Data.MaxVertices * sizeof(QuadVertex)));
s_Data.QuadVertexBuffer->SetLayout({{ShaderDataType::Float3, "a_Position"},
{ShaderDataType::Float4, "a_Color"},
{ShaderDataType::Float2, "a_TexCoord"},
{ShaderDataType::Float, "a_TexIndex"},
{ShaderDataType::Float, "a_TilingFactor"}});
s_Data.QuadVertexBuffer->SetLayout(BufferLayout{{ShaderDataType::Float3, "a_Position"},
{ShaderDataType::Float4, "a_Color"},
{ShaderDataType::Float2, "a_TexCoord"},
{ShaderDataType::Float, "a_TexIndex"},
{ShaderDataType::Float, "a_TilingFactor"}});
s_Data.QuadVertexArray->AddVertexBuffer(s_Data.QuadVertexBuffer);

s_Data.QuadVertexBufferBase = new QuadVertex[s_Data.MaxVertices];
Expand Down Expand Up @@ -119,7 +119,7 @@ Renderer::Init()
s_LineData.LineVertexBuffer = std::make_shared< VertexBuffer >(
static_cast< uint32_t >(s_LineData.MaxVertices * sizeof(LineVertex)));
s_LineData.LineVertexBuffer->SetLayout(
{{ShaderDataType::Float3, "a_Position"}, {ShaderDataType::Float4, "a_Color"}});
BufferLayout{{ShaderDataType::Float3, "a_Position"}, {ShaderDataType::Float4, "a_Color"}});
s_LineData.LineVertexArray->AddVertexBuffer(s_LineData.LineVertexBuffer);

s_LineData.LineVertexBufferBase = new LineVertex[s_LineData.MaxVertices];
Expand Down Expand Up @@ -279,9 +279,9 @@ Renderer::DrawQuad(const glm::vec2& position, const glm::vec2& size, float radia
s_Data.TextureSlotIndex++;
}

constexpr auto positions = std::to_array({
glm::vec4(0.5f, 0.5f, 0.0f, 1.0f), glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f),
glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f), glm::vec4(0.5f, -0.5f, 0.0f, 1.0f)});
constexpr auto positions =
std::to_array({glm::vec4(0.5f, 0.5f, 0.0f, 1.0f), glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f),
glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f), glm::vec4(0.5f, -0.5f, 0.0f, 1.0f)});

glm::mat4 transformMat = glm::translate(glm::mat4(1.0f), glm::vec3(position, 0.0f))
* glm::rotate(glm::mat4(1.0f), radiansRotation, {0.0f, 0.0f, 1.0f})
Expand Down
2 changes: 1 addition & 1 deletion engine/Render/VertexBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class BufferLayout
{
}

BufferLayout(const std::initializer_list< BufferElement >& elements)
explicit BufferLayout(const std::initializer_list< BufferElement >& elements)
: m_Elements(elements)
{
CalculateOffsetsAndStride();
Expand Down

0 comments on commit 8a188b6

Please sign in to comment.