ci: add static_analysis (#2)
Some checks failed
continuous-integration/drone/push Build is failing

Reviewed-on: #2
Co-authored-by: light7734 <light7734@tuta.io>
Co-committed-by: light7734 <light7734@tuta.io>
This commit is contained in:
light7734 2025-07-14 08:45:09 +00:00 committed by light7734
parent 3ef3760967
commit 1247b1ac69
28 changed files with 213 additions and 85 deletions

View file

@ -239,7 +239,6 @@ misc-header-include-cycle,
misc-definitions-in-headers,
misc-coroutine-hostile-raii,
misc-const-correctness,
misc-confusable-identifiers,
hicpp-signed-bitwise,
hicpp-no-assembler,

View file

@ -1,6 +1,9 @@
kind: pipeline
type: docker
name: clang format
clone:
recursive: true
submodule_update_remote: true
trigger:
branch:
@ -24,3 +27,25 @@ steps:
done
echo "✅ All files are properly formatted"
---
kind: pipeline
type: docker
name: static analysis
clone:
recursive: true
submodule_update_remote: true
trigger:
branch:
- main
steps:
- name: static_analysis
image: static_analysis:latest
pull: if-not-exists
privileged: true
commands:
- git submodule update --init --recursive
- conan build . -s build_type=Release -o enable_static_analysis=True --build=missing

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 4.0)
cmake_minimum_required(VERSION 3.14)
project(Light)
set(CMAKE_CXX_STANDARD 23)

View file

@ -1,9 +1,6 @@
# GLAD #
add_subdirectory(./glad)
# IMGUI #
cmake_minimum_required(VERSION 3.14)
set(MIRROR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../modules/mirror/)
set(DEPENDENCIES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/)

View file

@ -52,7 +52,7 @@ Application::Application(): m_window(nullptr)
m_renderer = Renderer::create(
(GLFWwindow *)m_window->get_handle(),
m_graphics_context->get_shared_context(),
lt::GraphicsContext::get_shared_context(),
Renderer::CreateInfo {
.quad_renderer_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_QUAD_SHADER"),
.texture_renderer_shader = AssetManager::get_shader(
@ -68,7 +68,7 @@ Application::Application(): m_window(nullptr)
m_user_interface = UserInterface::create(
(GLFWwindow *)m_window->get_handle(),
m_graphics_context->get_shared_context()
lt::GraphicsContext::get_shared_context()
);
m_layer_stack = create_scope<LayerStack>();

View file

@ -131,7 +131,7 @@ public:
return "TextLoader";
}
[[nodiscard]] auto load(std::filesystem::path file_path) const -> Assets::TextAsset::PackageData
[[nodiscard]] auto load(const std::filesystem::path& file_path) const -> Assets::TextAsset::PackageData
{
auto stream = std::ifstream { file_path, std::ios::binary };
if (!stream.good())

View file

@ -35,19 +35,19 @@ public:
void set_viewport_size(unsigned int width, unsigned int height);
void set_projection_type(ProjectionType projectionType);
void set_projection_type(ProjectionType projection_type);
void set_orthographic_size(float size);
void set_orthographic_far_plane(float farPlane);
void set_orthographic_far_plane(float far_plane);
void set_orthographic_near_plane(float nearPlane);
void set_orthographic_near_plane(float near_plane);
void set_perspective_vertical_fov(float verticalFov);
void set_perspective_vertical_fov(float vertical_fov);
void set_perspective_far_plane(float farPlane);
void set_perspective_far_plane(float far_plane);
void set_perspective_near_plane(float nearPlane);
void set_perspective_near_plane(float near_plane);
[[nodiscard]] auto get_orthographic_size() const -> float
{

View file

@ -24,9 +24,15 @@ public:
return ss.str();
}
event_type(SetChar);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::SetChar;
}
event_category(InputEventCategory | KeyboardEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | KeyboardEventCategory) & category;
}
private:
const unsigned int m_character;

View file

@ -2,7 +2,7 @@
namespace lt {
enum class EventType
enum class EventType : uint8_t
{
None = 0,
@ -24,7 +24,7 @@ enum class EventType
WindowGainFocus,
};
enum EventCategory
enum EventCategory : uint8_t
{
None = 0,
@ -34,18 +34,6 @@ enum EventCategory
MouseEventCategory = bit(3),
};
#define event_type(type) \
EventType get_event_type() const override \
{ \
return ::lt::EventType::type; \
}
#define event_category(eCategory) \
inline bool has_category(EventCategory category) const override \
{ \
return (eCategory) & category; \
}
class Event
{
public:

View file

@ -24,9 +24,15 @@ public:
return ss.str();
}
event_type(KeyPressed);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::KeyPressed;
}
event_category(InputEventCategory | KeyboardEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | KeyboardEventCategory) & category;
}
private:
const int m_key;
@ -51,9 +57,15 @@ public:
return ss.str();
}
event_type(KeyRepeated);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::KeyRepeated;
}
event_category(InputEventCategory | KeyboardEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | KeyboardEventCategory) & category;
}
private:
const int m_key;
@ -78,9 +90,15 @@ public:
return ss.str();
}
event_type(KeyReleased);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::KeyReleased;
}
event_category(InputEventCategory | KeyboardEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | KeyboardEventCategory) & category;
}
private:
const int m_key;

View file

@ -35,9 +35,15 @@ public:
return ss.str();
}
event_type(MouseMoved);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::MouseMoved;
}
event_category(InputEventCategory | MouseEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | MouseEventCategory) & category;
}
private:
const glm::vec2 m_position;
@ -62,9 +68,15 @@ public:
return ss.str();
}
event_type(WheelScrolled);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WheelScrolled;
}
event_category(InputEventCategory | MouseEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | MouseEventCategory) & category;
}
private:
const float m_offset;
@ -89,9 +101,15 @@ public:
return ss.str();
}
event_type(ButtonPressed);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::ButtonPressed;
}
event_category(InputEventCategory | MouseEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | MouseEventCategory) & category;
}
private:
const int m_button;
@ -116,9 +134,15 @@ public:
return ss.str();
}
event_type(ButtonReleased);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::ButtonReleased;
}
event_category(InputEventCategory | MouseEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(InputEventCategory | MouseEventCategory) & category;
}
private:
const int m_button;

View file

@ -14,9 +14,15 @@ public:
return "WindowClosedEvent";
}
event_type(WindowClosed);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowClosed;
}
event_category(WindowEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
};
class WindowMovedEvent: public Event
@ -39,9 +45,15 @@ public:
;
}
event_type(WindowMoved);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowMoved;
}
event_category(WindowEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
private:
const glm::ivec2 m_position;
@ -66,9 +78,15 @@ public:
return ss.str();
}
event_type(WindowResized);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowResized;
}
event_category(WindowEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
private:
const glm::uvec2 m_size;
@ -82,9 +100,15 @@ public:
return "WindowLostFocus";
}
event_type(WindowLostFocus);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowLostFocus;
}
event_category(WindowEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
};
class WindowGainFocusEvent: public Event
@ -95,9 +119,15 @@ public:
return "WindowGainFocus";
}
event_type(WindowGainFocus);
[[nodiscard]] auto get_event_type() const -> EventType override
{
return ::lt::EventType::WindowGainFocus;
}
event_category(WindowEventCategory);
[[nodiscard]] auto has_category(EventCategory category) const -> bool override
{
return static_cast<uint8_t>(WindowEventCategory) & category;
}
};
} // namespace lt

View file

@ -8,7 +8,7 @@ namespace lt {
class glBlender: public Blender
{
public:
virtual ~glBlender() = default;
~glBlender() override = default;
glBlender();
void enable(BlendFactor srcFactor, BlendFactor dstFactor) override;

View file

@ -10,7 +10,7 @@ class glConstantBuffer: public ConstantBuffer
public:
glConstantBuffer(ConstantBufferIndex index, unsigned int size);
virtual ~glConstantBuffer();
~glConstantBuffer() override;
void bind() override;

View file

@ -10,7 +10,7 @@ class glFramebuffer: public Framebuffer
public:
glFramebuffer(const FramebufferSpecification &specification);
virtual ~glFramebuffer();
~glFramebuffer() override;
void bind_as_target(const glm::vec4 &clearColor) override;

View file

@ -16,7 +16,7 @@ class Shader;
class QuadRendererProgram: RendererProgram
{
public:
virtual ~QuadRendererProgram() = default;
~QuadRendererProgram() override = default;
struct QuadVertexData
{
glm::vec4 position;
@ -25,7 +25,7 @@ public:
};
QuadRendererProgram(
unsigned int maxVertices,
unsigned int max_vertices,
const Ref<SharedContext> &shared_context,
Ref<Shader> shader
);

View file

@ -25,7 +25,7 @@ public:
};
TextureRendererProgram(
unsigned int maxVertices,
unsigned int max_vertices,
const Ref<SharedContext> &shared_context,
Ref<Shader> shader
);

View file

@ -16,7 +16,7 @@ class SharedContext;
class TintedTextureRendererProgram: RendererProgram
{
public:
virtual ~TintedTextureRendererProgram() = default;
~TintedTextureRendererProgram() override = default;
struct TintedTextureVertexData
{
glm::vec4 position;
@ -27,8 +27,8 @@ public:
};
TintedTextureRendererProgram(
unsigned int maxVertices,
const Ref<SharedContext> &sharedContext,
unsigned int max_vertices,
const Ref<SharedContext> &shared_context,
Ref<Shader> shader
);

View file

@ -42,8 +42,8 @@ public:
};
static auto create(
GLFWwindow *window_handle,
Ref<SharedContext> shared_context,
GLFWwindow *windowHandle,
Ref<SharedContext> sharedContext,
CreateInfo create_info
) -> Scope<Renderer>;
@ -67,9 +67,13 @@ public:
s_context->draw_quad_impl(position, size, std::move(texture));
}
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture)
static void draw_quad(
const glm::mat4 &transform,
const glm::vec4 &tint,
const Ref<Texture> &texture
)
{
s_context->draw_quad_impl(transform, tint, std::move(texture));
s_context->draw_quad_impl(transform, tint, texture);
}
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint)
@ -77,9 +81,9 @@ public:
s_context->draw_quad_impl(transform, tint);
}
static void draw_quad(const glm::mat4 &transform, Ref<Texture> texture)
static void draw_quad(const glm::mat4 &transform, const Ref<Texture> &texture)
{
s_context->draw_quad_impl(transform, std::move(texture));
s_context->draw_quad_impl(transform, texture);
}
static void begin_scene(
@ -123,7 +127,11 @@ private:
bool m_should_clear_backbuffer { false };
Renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext, CreateInfo create_info);
Renderer(
GLFWwindow *window_handle,
const Ref<SharedContext> &shared_context,
CreateInfo create_info
);
void draw_quad_impl(
const glm::vec3 &position,

View file

@ -25,8 +25,8 @@ public:
};
static auto create(
Ref<Assets::TextAsset> vertex_asset,
Ref<Assets::TextAsset> pixel_asset,
const Ref<Assets::TextAsset>& vertex_asset,
const Ref<Assets::TextAsset>& pixel_asset,
const Ref<SharedContext> &shared_context
) -> Ref<Shader>;

View file

@ -14,7 +14,7 @@ class Texture
{
public:
static Ref<Texture> create(
Ref<Assets::TextureAsset> asset,
const Ref<Assets::TextureAsset>& asset,
const Ref<SharedContext> &shared_context
);

View file

@ -20,7 +20,7 @@ Renderer *Renderer::s_context = nullptr;
Renderer::Renderer(
GLFWwindow *window_handle,
Ref<SharedContext> shared_context,
const Ref<SharedContext>& shared_context,
CreateInfo create_info
)
: m_quad_renderer(

View file

@ -12,8 +12,8 @@
namespace lt {
/* static */ auto Shader::create(
Ref<Assets::TextAsset> vertex_asset,
Ref<Assets::TextAsset> pixel_asset,
const Ref<Assets::TextAsset>& vertex_asset,
const Ref<Assets::TextAsset>& pixel_asset,
const Ref<SharedContext> &shared_context
) -> Ref<Shader>
{

View file

@ -12,8 +12,8 @@
namespace lt {
/* static */ auto Texture::create(
Ref<Assets::TextureAsset> asset,
const Ref<SharedContext> &shared_context
const Ref<Assets::TextureAsset>& asset,
const Ref<SharedContext> & /*shared_context*/
) -> Ref<Texture>
{
switch (GraphicsContext::get_graphics_api())

View file

@ -12,7 +12,7 @@ class SharedContext;
class UserInterface
{
public:
static auto create(GLFWwindow *window_handle, Ref<SharedContext> shared_context)
static auto create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
-> Scope<UserInterface>;
static void dockspace_begin();
@ -25,7 +25,7 @@ public:
virtual ~UserInterface() = default;
void init(GLFWwindow *window_handle, Ref<SharedContext> sharedContext);
void init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
virtual void platform_implementation(
GLFWwindow *window_handle,

View file

@ -9,8 +9,7 @@
namespace lt {
Window::~Window()
{
}
= default;
auto Window::create(const std::function<void(Event &)> &callback) -> Scope<Window>
{
@ -18,7 +17,7 @@ auto Window::create(const std::function<void(Event &)> &callback) -> Scope<Windo
}
lWindow::lWindow(std::function<void(Event &)> callback)
: m_event_callback(std::move(std::move(callback)))
: m_handle(glfwCreateWindow(1u, 1u, "", nullptr, nullptr)), m_event_callback(std::move(std::move(callback)))
{
// init glfw
ensure(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'");
@ -29,7 +28,7 @@ lWindow::lWindow(std::function<void(Event &)> callback)
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
m_handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr);
ensure(m_handle, "lWindow::lWindow: failed to create 'GLFWwindow'");
glfwSetWindowUserPointer(m_handle, &m_event_callback);

View file

@ -6,5 +6,4 @@ RUN apk add --no-cache \
findutils \
git \
libc6-compat \
tar \
clang-extra-tools

View file

@ -0,0 +1,35 @@
FROM alpine:latest
RUN apk add --no-cache \
bash \
clang \
llvm \
cmake \
git \
make \
g++ \
python3 \
py3-pip \
mesa-dev \
mesa-gl \
pkgconf \
clang-extra-tools
RUN pip install --no-cache-dir --break-system-packages conan gitpython \
&& conan profile detect
RUN clang --version \
&& conan --version \
&& pip --version \
&& cmake --version \
&& clang --version \
&& clang-tidy --version
RUN git clone 'https://git.light7734.com/light7734/light.git' --recursive \
&& cd light \
&& conan install . \
-c tools.system.package_manager:mode=install \
-o enable_static_analysis=True \
--build=missing