Refractor
Christian Immanuel · 2026-04-19 16:58 · bea5caf19ac47ba6f79f8cff43efe77b52896c4f
CMakeLists.txt | 34 +++++++++++-----------
game.cpp => src/core/game.cpp | 4 +--
game.hpp => src/core/game.hpp | 8 ++---
main.cpp => src/core/main.cpp | 10 +++----
camera.hpp => src/entities/camera.hpp | 4 +--
player.cpp => src/entities/player.cpp | 2 +-
player.hpp => src/entities/player.hpp | 2 +-
world.cpp => src/entities/world.cpp | 2 +-
world.hpp => src/entities/world.hpp | 4 +--
input_system.cpp => src/systems/input_system.cpp | 2 +-
input_system.hpp => src/systems/input_system.hpp | 2 +-
.../systems/physics_system.cpp | 2 +-
.../systems/physics_system.hpp | 2 +-
config.hpp => src/utils/config.hpp | 0
math.hpp => src/utils/math.hpp | 0
15 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9889770..ddf828b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,34 +1,34 @@
cmake_minimum_required(VERSION 3.20)
-
project(idk_game LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
find_package(SDL3 REQUIRED)
-add_executable(idk_game
- main.cpp
- game.cpp
- input_system.cpp
- physics_system.cpp
- player.cpp
- world.cpp
-)
+file(GLOB_RECURSE SOURCES "src/*.cpp")
+
+add_executable(idk_game ${SOURCES})
+
+target_include_directories(idk_game PRIVATE src)
+
+if(NOT EXISTS "${CMAKE_SOURCE_DIR}/compile_commands.json")
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E create_symlink
+ "${CMAKE_BINARY_DIR}/compile_commands.json"
+ "${CMAKE_SOURCE_DIR}/compile_commands.json"
+ )
+endif()
target_compile_options(idk_game PRIVATE
- -Wall
- -Wextra
- -Wshadow
- -Wconversion
- -Wsign-conversion
- -Wnull-dereference
- -Wdouble-promotion
+ -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion
+ -Wnull-dereference -Wdouble-promotion
)
target_link_libraries(idk_game PRIVATE SDL3::SDL3)
-# cmake -B build -DCMAKE_BUILD_TYPE=Debug
target_compile_options(idk_game PRIVATE
$<$<CONFIG:Debug>:-fsanitize=address>
$<$<CONFIG:Debug>:-fno-omit-frame-pointer>
diff --git a/game.cpp b/src/core/game.cpp
similarity index 97%
rename from game.cpp
rename to src/core/game.cpp
index f245a2b..0e961cb 100644
--- a/game.cpp
+++ b/src/core/game.cpp
@@ -1,5 +1,5 @@
-#include "game.hpp"
-#include "config.hpp"
+#include "core/game.hpp"
+#include "utils/config.hpp"
bool Game::init()
{
diff --git a/game.hpp b/src/core/game.hpp
similarity index 79%
rename from game.hpp
rename to src/core/game.hpp
index 293b491..72c0fe5 100644
--- a/game.hpp
+++ b/src/core/game.hpp
@@ -2,10 +2,10 @@
#include <SDL3/SDL.h>
-#include "input_system.hpp"
-#include "physics_system.hpp"
-#include "world.hpp"
-#include "player.hpp"
+#include "systems/input_system.hpp"
+#include "systems/physics_system.hpp"
+#include "entities/world.hpp"
+#include "entities/player.hpp"
struct AppState {
SDL_Window* window{};
diff --git a/main.cpp b/src/core/main.cpp
similarity index 90%
rename from main.cpp
rename to src/core/main.cpp
index e9f757b..0b6a178 100644
--- a/main.cpp
+++ b/src/core/main.cpp
@@ -2,11 +2,11 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
-#include "config.hpp"
-#include "math.hpp"
-#include "game.hpp"
-#include "world.hpp"
-#include "player.hpp"
+#include "utils/config.hpp"
+#include "utils/math.hpp"
+#include "core/game.hpp"
+#include "entities/world.hpp"
+#include "entities/player.hpp"
static const struct {
diff --git a/camera.hpp b/src/entities/camera.hpp
similarity index 93%
rename from camera.hpp
rename to src/entities/camera.hpp
index d5fccfc..c9840ee 100644
--- a/camera.hpp
+++ b/src/entities/camera.hpp
@@ -2,8 +2,8 @@
#include <SDL3/SDL.h>
-#include "math.hpp"
-#include "player.hpp"
+#include "utils/math.hpp"
+#include "entities/player.hpp"
struct Camera {
Vec3 pos{};
diff --git a/player.cpp b/src/entities/player.cpp
similarity index 97%
rename from player.cpp
rename to src/entities/player.cpp
index 84fb27d..f170db0 100644
--- a/player.cpp
+++ b/src/entities/player.cpp
@@ -1,4 +1,4 @@
-#include "player.hpp"
+#include "entities/player.hpp"
Player::Player()
diff --git a/player.hpp b/src/entities/player.hpp
similarity index 97%
rename from player.hpp
rename to src/entities/player.hpp
index 431a5f0..db76dcf 100644
--- a/player.hpp
+++ b/src/entities/player.hpp
@@ -2,7 +2,7 @@
#include <SDL3/SDL.h>
-#include "math.hpp"
+#include "utils/math.hpp"
struct PlayerInputState
{
diff --git a/world.cpp b/src/entities/world.cpp
similarity index 99%
rename from world.cpp
rename to src/entities/world.cpp
index b741a65..afe94e0 100644
--- a/world.cpp
+++ b/src/entities/world.cpp
@@ -1,4 +1,4 @@
-#include "world.hpp"
+#include "entities/world.hpp"
World::World()
{
diff --git a/world.hpp b/src/entities/world.hpp
similarity index 90%
rename from world.hpp
rename to src/entities/world.hpp
index cf6ab44..50fa63c 100644
--- a/world.hpp
+++ b/src/entities/world.hpp
@@ -2,8 +2,8 @@
#include <array>
-#include "player.hpp"
-#include "camera.hpp"
+#include "entities/player.hpp"
+#include "entities/camera.hpp"
#define MAP_BOX_SCALE 16
#define MAP_BOX_EDGES_LEN (12 + MAP_BOX_SCALE * 2)
diff --git a/input_system.cpp b/src/systems/input_system.cpp
similarity index 95%
rename from input_system.cpp
rename to src/systems/input_system.cpp
index d4ca304..93698a9 100644
--- a/input_system.cpp
+++ b/src/systems/input_system.cpp
@@ -1,4 +1,4 @@
-#include "input_system.hpp"
+#include "systems/input_system.hpp"
void InputSystem::handleEvent(const SDL_Event& e, PlayerInputState& input, Player& player)
{
diff --git a/input_system.hpp b/src/systems/input_system.hpp
similarity index 82%
rename from input_system.hpp
rename to src/systems/input_system.hpp
index 2c8e219..4bdf929 100644
--- a/input_system.hpp
+++ b/src/systems/input_system.hpp
@@ -1,6 +1,6 @@
#pragma once
#include <SDL3/SDL.h>
-#include "player.hpp"
+#include "entities/player.hpp"
class InputSystem {
public:
diff --git a/physics_system.cpp b/src/systems/physics_system.cpp
similarity index 94%
rename from physics_system.cpp
rename to src/systems/physics_system.cpp
index f45fddd..6fb8ad7 100644
--- a/physics_system.cpp
+++ b/src/systems/physics_system.cpp
@@ -1,4 +1,4 @@
-#include "physics_system.hpp"
+#include "systems/physics_system.hpp"
#include <SDL3/SDL.h>
void PhysicsSystem::update(Player& p, double acc_x, double acc_z, double dt) {
diff --git a/physics_system.hpp b/src/systems/physics_system.hpp
similarity index 79%
rename from physics_system.hpp
rename to src/systems/physics_system.hpp
index 0f2ad93..57986f0 100644
--- a/physics_system.hpp
+++ b/src/systems/physics_system.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "player.hpp"
+#include "entities/player.hpp"
class PhysicsSystem {
public:
diff --git a/config.hpp b/src/utils/config.hpp
similarity index 100%
rename from config.hpp
rename to src/utils/config.hpp
diff --git a/math.hpp b/src/utils/math.hpp
similarity index 100%
rename from math.hpp
rename to src/utils/math.hpp