Skip to content

Commit

Permalink
[#152]: Address cppcheck issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Nov 20, 2023
1 parent 3c50796 commit d69e485
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 51 deletions.
7 changes: 3 additions & 4 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Editor::HandleMouseDrag(const glm::vec2& currentCursorPos, const glm::vec2& axis
}

void
Editor::SetMouseOnObject()
Editor::SetMouseOnObject() const
{
if (m_mouseDrag && (m_movementOnEditorObject || m_movementOnGameObject))
{
Expand Down Expand Up @@ -467,9 +467,8 @@ Editor::SetRenderLayerToDraw(int32_t layer)
renderLayerToDraw_ = layer;
}


void
Editor::SetupRendererData()
Editor::SetupRendererData() const
{
renderer::VulkanRenderer::SetupData();

Expand Down Expand Up @@ -715,7 +714,7 @@ Editor::DrawBoundingBoxes()
}

void
Editor::DrawGrid()
Editor::DrawGrid() const
{
const auto levelSize = m_currentLevel->GetSize();
const auto grad = m_gridCellSize;
Expand Down
6 changes: 3 additions & 3 deletions editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Editor : public Application
GetRenderNodes() const;

void
DrawGrid();
DrawGrid() const;

void
DrawBoundingBoxes();
Expand Down Expand Up @@ -178,7 +178,7 @@ class Editor : public Application
// GetEditorObjectByID(Object::ID ID);

void
SetupRendererData();
SetupRendererData() const;

void
DrawEditorObjects();
Expand Down Expand Up @@ -217,7 +217,7 @@ class Editor : public Application
ShowCursor(bool choice);

void
SetMouseOnObject();
SetMouseOnObject() const;

void
FreeLevelData();
Expand Down
5 changes: 0 additions & 5 deletions engine/game/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ class Player : public GameObject
/*void
CreateSprite(const glm::vec2& position, const glm::ivec2& size, const std::string& fileName);*/

void
Hit(int32_t /*dmg*/) override
{
}

private:
void
UpdateInternal(bool isReverse) override;
Expand Down
6 changes: 6 additions & 0 deletions engine/input/input_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ BroadcastEvent(const auto& listeners, auto& event)
}

void
// cppcheck-suppress constParameterCallback
InputManager::InternalKeyCallback(GLFWwindow* window, int32_t key, int32_t scancode,
int32_t action, int32_t mods)
{
Expand All @@ -37,6 +38,7 @@ InputManager::InternalKeyCallback(GLFWwindow* window, int32_t key, int32_t scanc
}

void
// cppcheck-suppress constParameterCallback
InputManager::InternalCharCallback(GLFWwindow* window, uint32_t key)
{
Logger::Trace("GLFW char {}", key);
Expand All @@ -47,6 +49,7 @@ InputManager::InternalCharCallback(GLFWwindow* window, uint32_t key)
}

void
// cppcheck-suppress constParameterCallback
InputManager::InternalMouseButtonCallback(GLFWwindow* window, int32_t button, int32_t action,
int32_t mods)
{
Expand All @@ -58,6 +61,7 @@ InputManager::InternalMouseButtonCallback(GLFWwindow* window, int32_t button, in
}

void
// cppcheck-suppress constParameterCallback
InputManager::InternalCursorPositionCallback(GLFWwindow* window, double xPos, double yPos)
{
Logger::Trace("GLFW cursor pos {} {}", xPos, yPos);
Expand All @@ -69,6 +73,7 @@ InputManager::InternalCursorPositionCallback(GLFWwindow* window, double xPos, do
}

void
// cppcheck-suppress constParameterCallback
InputManager::InternalMouseScrollCallback(GLFWwindow* window, double xOffset, double yOffset)
{
Logger::Trace("GLFW scroll {} {}", xOffset, yOffset);
Expand All @@ -79,6 +84,7 @@ InputManager::InternalMouseScrollCallback(GLFWwindow* window, double xOffset, do
}

void
// cppcheck-suppress constParameterCallback
InputManager::InternalWindowFocusCallback(GLFWwindow* window, int32_t focused)
{
Logger::Trace("GLFW window focus {}", focused);
Expand Down
4 changes: 2 additions & 2 deletions engine/renderer/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Buffer::CopyData(const void* data) const
}

void
Buffer::CopyDataWithStaging(void* data, size_t dataSize) const
Buffer::CopyDataWithStaging(const void* data, const size_t dataSize) const
{
VkBuffer stagingBuffer = {};
VkDeviceMemory stagingBufferMemory = {};
Expand All @@ -72,7 +72,7 @@ Buffer::CopyDataWithStaging(void* data, size_t dataSize) const
}

void
Buffer::CopyDataToImageWithStaging(VkImage image, void* data, size_t dataSize,
Buffer::CopyDataToImageWithStaging(VkImage image, const void* data, const size_t dataSize,
const std::vector< VkBufferImageCopy >& copyRegions)
{
VkBuffer stagingBuffer = {};
Expand Down
4 changes: 2 additions & 2 deletions engine/renderer/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class Buffer
CopyData(const void* data) const;

void
CopyDataWithStaging(void* data, size_t dataSize) const;
CopyDataWithStaging(const void* data, const size_t dataSize) const;

static void
CopyDataToImageWithStaging(VkImage image, void* data, size_t dataSize,
CopyDataToImageWithStaging(VkImage image, const void* data, const size_t dataSize,
const std::vector< VkBufferImageCopy >& copyRegions);

void
Expand Down
34 changes: 8 additions & 26 deletions engine/renderer/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,16 @@ Texture::CreateTextureImage(const FileManager::ImageData& data)
CreateImageView(m_textureImage, m_format, VK_IMAGE_ASPECT_COLOR_BIT, m_mips, false);

CreateTextureSampler();

TransitionImageLayout(VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, m_mips);

CopyBufferToImage(data.m_bytes.get());

// transitioned to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL while generating mipmaps
GenerateMipmaps(m_textureImage, VK_FORMAT_R8G8B8A8_SRGB, static_cast< int32_t >(m_width),
static_cast< int32_t >(m_height), m_mips);
UpdateTexture(data);
}

void
Texture::UpdateTexture(const FileManager::ImageData& data)
Texture::UpdateTexture(const FileManager::ImageData& data) const
{
TransitionImageLayout(VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, m_mips);
TransitionImageLayout(m_textureImage, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, m_mips);

CopyBufferToImage(data.m_bytes.get());
CopyBufferToImage(m_textureImage, m_width, m_height, data.m_bytes.get());

// transitioned to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL while generating mipmaps
GenerateMipmaps(m_textureImage, VK_FORMAT_R8G8B8A8_SRGB, static_cast< int32_t >(m_width),
Expand Down Expand Up @@ -340,7 +334,8 @@ Texture::CreateTextureSampler()
}

void
Texture::CopyBufferToImage(VkImage image, uint32_t texWidth, uint32_t texHeight, uint8_t* data)
Texture::CopyBufferToImage(VkImage image, uint32_t texWidth, uint32_t texHeight,
const uint8_t* data)
{
VkBufferImageCopy region = {};
region.bufferOffset = 0;
Expand All @@ -360,7 +355,7 @@ Texture::CopyBufferToImage(VkImage image, uint32_t texWidth, uint32_t texHeight,

void
Texture::CopyBufferToCubemapImage(VkImage image, uint32_t texWidth, uint32_t texHeight,
uint8_t* data)
const uint8_t* data)
{
constexpr auto num_faces = 6;
const auto single_face_size =
Expand Down Expand Up @@ -394,12 +389,6 @@ Texture::CopyBufferToCubemapImage(VkImage image, uint32_t texWidth, uint32_t tex
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1, true);
}

void
Texture::CopyBufferToImage(uint8_t* data)
{
CopyBufferToImage(m_textureImage, m_width, m_height, data);
}

void
Texture::TransitionImageLayout(VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout,
uint32_t mipLevels, bool cubemap)
Expand Down Expand Up @@ -450,13 +439,6 @@ Texture::TransitionImageLayout(VkImage image, VkImageLayout oldLayout, VkImageLa
Command::EndSingleTimeCommands(commandBuffer);
}

void
Texture::TransitionImageLayout(VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels)
{
TransitionImageLayout(m_textureImage, oldLayout, newLayout, mipLevels);
}


/**************************************************************************************************
*************************************** TEXTURE LIBRARY ******************************************
*************************************************************************************************/
Expand Down
13 changes: 4 additions & 9 deletions engine/renderer/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Texture
Destroy();

void
UpdateTexture(const FileManager::ImageData& data);
UpdateTexture(const FileManager::ImageData& data) const;

static std::pair< VkImage, VkDeviceMemory >
CreateImage(uint32_t width, uint32_t height, uint32_t mipLevels,
Expand All @@ -57,10 +57,11 @@ class Texture
uint32_t mipLevels, bool cubemap = false);

static void
CopyBufferToImage(VkImage image, uint32_t texWidth, uint32_t texHeight, uint8_t* data);
CopyBufferToImage(VkImage image, uint32_t texWidth, uint32_t texHeight, const uint8_t* data);

static void
CopyBufferToCubemapImage(VkImage image, uint32_t texWidth, uint32_t texHeight, uint8_t* data);
CopyBufferToCubemapImage(VkImage image, uint32_t texWidth, uint32_t texHeight,
const uint8_t* data);

static VkDescriptorSet
CreateDescriptorSet(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout,
Expand Down Expand Up @@ -91,12 +92,6 @@ class Texture
void
CreateTextureImage(const FileManager::ImageData& data);

void
TransitionImageLayout(VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels);

void
CopyBufferToImage(uint8_t* data);

private:
TextureID id_ = {};
TextureType m_type = {};
Expand Down

0 comments on commit d69e485

Please sign in to comment.