708edb9dcff258b5c09b61f7eadac787dd4c5b47 — Leinnan 7 months ago a9f6398
Add logging library, fix camera
M .gitmodules => .gitmodules +3 -0
@@ 4,3 4,6 @@
 [submodule "ext/entt"]
 	path = ext/entt
 	url = https://github.com/skypjack/entt
+[submodule "ext/spdlog"]
+	path = ext/spdlog
+	url = https://github.com/gabime/spdlog

M CMakeLists.txt => CMakeLists.txt +10 -1
@@ 12,19 12,28 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
 
 SET(BUILD_EXAMPLES OFF CACHE BOOL "Build the examples.")
 SET(BUILD_GAMES OFF CACHE BOOL "Build the example games.")
+SET(SPDLOG_BUILD_EXAMPLES OFF CACHE BOOL "Build examples")
 add_subdirectory(ext/raylib)
 add_subdirectory(ext/entt)
+add_subdirectory(ext/spdlog)
+
+if(NOT TARGET spdlog)
+    # Stand-alone build
+    find_package(spdlog REQUIRED)
+endif()
+
 if(${PLATFORM} MATCHES "Web")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 --profiling")
     #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -o index.html --preload-file data ")
 endif()
 
 file(COPY ${CMAKE_SOURCE_DIR}/data DESTINATION ${CMAKE_BINARY_DIR}/output)
+file(MAKE_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/logs")
 
 include_directories(src ext src/controllers src/components src/systems src/utils src/presets src/factories)
 add_executable(${PROJECT_NAME} src/main.cpp src/utils/Arkona.cpp src/utils/JsonParser.cpp  src/systems/SpawnSystem.cpp src/systems/DamageSystem.cpp src/systems/MissileSystem.cpp src/systems/AiSystem.cpp src/systems/CollisionSystem.cpp src/systems/DestroySystem.cpp src/systems/MovementSystem.cpp src/systems/RenderSystem.cpp src/systems/PlayerInputSystem.cpp)
 #set(raylib_VERBOSE 1)
-target_link_libraries(${PROJECT_NAME} raylib EnTT)
+target_link_libraries(${PROJECT_NAME} raylib EnTT spdlog::spdlog_header_only)
 if(${PLATFORM} MATCHES "Web")
     set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-s DEMANGLE_SUPPORT=1 --preload-file ${CMAKE_SOURCE_DIR}/data --bind")
 endif()

A ext/spdlog => ext/spdlog +1 -0
@@ 0,0 1,1 @@
+Subproject commit 34ea38c12e10d617a3cff0e48daada5aac9bff25

M src/factories/UnitFactory.hpp => src/factories/UnitFactory.hpp +1 -0
@@ 78,6 78,7 @@ class UnitFactory final : public Controllers::Controller<UnitFactory> {
         registry.assign<Components::Velocity>(entity);
 
         if(unitPreset->isPlayer) {
+            std::cout << "Create player!\n";
             registry.assign<Components::PlayerInput>(entity);
             registry.assign<Components::Fighter>(entity);
 

M src/main.cpp => src/main.cpp +8 -1
@@ 1,4 1,6 @@
 #include "raylib.h"
+#include "spdlog/spdlog.h"
+#include "spdlog/sinks/basic_file_sink.h"
 
 #include "INIReader.hpp"
 #include "factories/UnitFactory.hpp"


@@ 39,9 41,12 @@ Camera camera;
 
 int main(int argc, char **argv) {
     INIReader reader(argc == 2 ? argv[1] : CONFIG_PATH);
+    auto fileLogger = spdlog::basic_logger_mt("basic_logger", "logs/game.log");
+    spdlog::set_default_logger(fileLogger);    
+    spdlog::set_pattern("[%H:%M:%S] %v");
 
     if(reader.ParseError() != 0) {
-        std::cout << "Can't load " << (argc == 2 ? argv[1] : CONFIG_PATH) << "\n";
+        spdlog::error("Some error message with arg: {}", argc == 2 ? argv[1] : CONFIG_PATH);
         return 1;
     }
     const auto windowName = reader.Get("game", "name", "Raylib");


@@ 63,8 68,10 @@ int main(int argc, char **argv) {
     aiSystem.Init(registry);
     damageSystem.Init();
 
+    spdlog::info("Loading files");
     Factories::UnitFactory::getInstance().loadFromFile(reader.Get("game", "units", "units.json"));
     Components::readFromFile(registry, jsonFile.c_str());
+    spdlog::info("Loading files ended");
 
     camera = {0};
     camera.target = (Vector3){0.0f, 0.5f, 0.0f};

M src/systems/RenderSystem.cpp => src/systems/RenderSystem.cpp +2 -1
@@ 21,6 21,7 @@ void RenderSystem::Init(entt::registry<> &registry) {
 }
 
 void RenderSystem::Update(entt::registry<> &registry, Camera &camera) {
+    UpdateCamera(registry,camera);
     BeginDrawing();
     ClearBackground({180, 180, 180, 255});
     BeginMode3D(camera);


@@ 99,7 100,7 @@ void RenderSystem::UnloadEntityTexture(entt::registry<> &registry, std::uint32_t
     }
 }
 
-void RenderSystem::UpdateCamera(entt::registry<> &registry) {
+void RenderSystem::UpdateCamera(entt::registry<> &registry, Camera &camera) {
     registry.view<Components::Transform, Components::CameraTarget>().each(
         [&](const auto, const auto transform, const auto &target) {
             const Vector3 usedOffset = target.isPerspective ? target.perspectiveOffset : target.orthographicOffset;

M src/systems/RenderSystem.hpp => src/systems/RenderSystem.hpp +1 -3
@@ 15,9 15,7 @@ class RenderSystem {
     void UnloadEntityTexture(entt::registry<> &registry, std::uint32_t entity);
 
   private:
-    void UpdateCamera(entt::registry<> &registry);
-
-    Camera3D camera;
+    void UpdateCamera(entt::registry<> &registry, Camera &camera);
 };
 } // namespace Systems
   // Systems