From aa48bc82d8ab323f4474f376b201c3283b78b172 Mon Sep 17 00:00:00 2001
From: Atdunbg <979541498@qq.com>
Date: Thu, 17 Apr 2025 17:25:14 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE=E4=B8=BACm?=
=?UTF-8?q?ake=E7=AE=A1=E7=90=86=EF=BC=8C=E6=B7=BB=E5=8A=A0spdlog=E5=92=8C?=
=?UTF-8?q?SDL=E4=B8=A4=E4=B8=AA=E5=BA=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 6 +++
.gitmodules | 6 +++
CMakeLists.txt | 20 +++++++
Hazel.sln | 31 -----------
Hazel/CMakeLists.txt | 28 ++++++++++
Hazel/Hazel.vcxproj | 94 --------------------------------
Hazel/Hazel.vcxproj.filters | 36 -------------
Hazel/src/Hazel.h | 2 +-
Hazel/src/Hazel/Application.cpp | 8 +--
Hazel/src/Hazel/EntryPoint.h | 38 +++++++++++--
Hazel/src/Hazel/Log.cpp | 20 +++++++
Hazel/src/Hazel/Log.h | 43 +++++++++++++++
Hazel/vendor/SDL | 1 +
Hazel/vendor/spdlog | 1 +
Sandbox/CMakeLists.txt | 9 ++++
Sandbox/Sandbox.vcxproj | 95 ---------------------------------
Sandbox/Sandbox.vcxproj.filters | 22 --------
Sandbox/src/SandboxApp.cpp | 10 ++--
18 files changed, 174 insertions(+), 296 deletions(-)
create mode 100644 .gitmodules
create mode 100644 CMakeLists.txt
delete mode 100644 Hazel.sln
create mode 100644 Hazel/CMakeLists.txt
delete mode 100644 Hazel/Hazel.vcxproj
delete mode 100644 Hazel/Hazel.vcxproj.filters
create mode 100644 Hazel/src/Hazel/Log.cpp
create mode 100644 Hazel/src/Hazel/Log.h
create mode 160000 Hazel/vendor/SDL
create mode 160000 Hazel/vendor/spdlog
create mode 100644 Sandbox/CMakeLists.txt
delete mode 100644 Sandbox/Sandbox.vcxproj
delete mode 100644 Sandbox/Sandbox.vcxproj.filters
diff --git a/.gitignore b/.gitignore
index 3304ed3..6abc828 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,12 @@
.vs/
bin/
bin-int/
+.idea/
+
+
+# Clion
+cmake-build-debug/
+cmake-build-release/
# Files
*.user
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..e2d35f8
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,6 @@
+[submodule "Hazel/vendor/spdlog"]
+ path = Hazel/vendor/spdlog
+ url = https://github.com/gabime/spdlog
+[submodule "Hazel/vendor/SDL"]
+ path = Hazel/vendor/SDL
+ url = https://github.com/libsdl-org/SDL
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..88bc931
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 3.10)
+project(MyProject)
+
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(BUILD_SHARED_LIBS OFF)
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251")
+
+add_subdirectory(Hazel/vendor/spdlog)
+
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+add_compile_options(/utf-8)
+
+
+add_subdirectory(Hazel)
+add_subdirectory(Sandbox)
\ No newline at end of file
diff --git a/Hazel.sln b/Hazel.sln
deleted file mode 100644
index b97861e..0000000
--- a/Hazel.sln
+++ /dev/null
@@ -1,31 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 17
-VisualStudioVersion = 17.13.35825.156 d17.13
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hazel", "Hazel\Hazel.vcxproj", "{849C6C03-8690-44EE-AD89-7022698623BC}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Sandbox", "Sandbox\Sandbox.vcxproj", "{67A786AC-E29D-4DEC-9CD8-4654B86AB54A}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|x64 = Debug|x64
- Release|x64 = Release|x64
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {849C6C03-8690-44EE-AD89-7022698623BC}.Debug|x64.ActiveCfg = Debug|x64
- {849C6C03-8690-44EE-AD89-7022698623BC}.Debug|x64.Build.0 = Debug|x64
- {849C6C03-8690-44EE-AD89-7022698623BC}.Release|x64.ActiveCfg = Release|x64
- {849C6C03-8690-44EE-AD89-7022698623BC}.Release|x64.Build.0 = Release|x64
- {67A786AC-E29D-4DEC-9CD8-4654B86AB54A}.Debug|x64.ActiveCfg = Debug|x64
- {67A786AC-E29D-4DEC-9CD8-4654B86AB54A}.Debug|x64.Build.0 = Debug|x64
- {67A786AC-E29D-4DEC-9CD8-4654B86AB54A}.Release|x64.ActiveCfg = Release|x64
- {67A786AC-E29D-4DEC-9CD8-4654B86AB54A}.Release|x64.Build.0 = Release|x64
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {FAA4817D-A037-4E07-9AE8-B264EF56EEBF}
- EndGlobalSection
-EndGlobal
diff --git a/Hazel/CMakeLists.txt b/Hazel/CMakeLists.txt
new file mode 100644
index 0000000..4e3fd37
--- /dev/null
+++ b/Hazel/CMakeLists.txt
@@ -0,0 +1,28 @@
+project(Hazel)
+
+file(GLOB_RECURSE SOURCES "src/*.cpp")
+
+add_library(Hazel SHARED ${SOURCES})
+
+set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE)
+add_subdirectory(vendor/SDL)
+set(SDL3_SHARED ON CACHE BOOL "Build SDL as shared library" FORCE)
+
+
+target_include_directories(Hazel
+ PUBLIC
+ vendor/spdlog/include
+ vendor/SDL/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/src # 暴露头文件给其他项目
+)
+
+
+target_link_libraries(Hazel PUBLIC spdlog::spdlog SDL3::SDL3)
+
+target_compile_definitions(Hazel PRIVATE HZ_BUILD_DLL)# 编译DLL时定义
+
+if(WIN32)
+ target_compile_definitions(Hazel PUBLIC HZ_PLATFORM_WINDOWS)# 编译DLL时定义
+endif ()
+
+
diff --git a/Hazel/Hazel.vcxproj b/Hazel/Hazel.vcxproj
deleted file mode 100644
index ba03db0..0000000
--- a/Hazel/Hazel.vcxproj
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
-
-
-
-
-
-
-
-
-
- 17.0
- Win32Proj
- {849c6c03-8690-44ee-ad89-7022698623bc}
- Hazel
- 10.0
-
-
-
- DynamicLibrary
- true
- v143
- Unicode
-
-
- DynamicLibrary
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $(SolutionDir)bin\$(Configuration)-$(Platform)\$(ProjectName)\
- $(SolutionDir)bin-int\$(Configuration)-$(Platform)\$(ProjectName)\
-
-
- $(SolutionDir)bin\${Configuration)-$(Platform)\$(Project)\
- $(SolutionDir)bin-int\${Configuration)-$(Platform)\$(Project)\
-
-
-
- Level3
- true
- HZ_PLATFORM_WINDOWS;HZ_BUILD_DLL;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- HZ_PLATFORM_WINDOWS;HZ_BUILD_DLL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- Console
- true
- true
- true
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Hazel/Hazel.vcxproj.filters b/Hazel/Hazel.vcxproj.filters
deleted file mode 100644
index 21bb94f..0000000
--- a/Hazel/Hazel.vcxproj.filters
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
-
-
- 头文件
-
-
- 头文件
-
-
- 头文件
-
-
- 头文件
-
-
-
-
- 源文件
-
-
-
\ No newline at end of file
diff --git a/Hazel/src/Hazel.h b/Hazel/src/Hazel.h
index b3ef289..7fbf837 100644
--- a/Hazel/src/Hazel.h
+++ b/Hazel/src/Hazel.h
@@ -1,8 +1,8 @@
#pragma once
// For use by Hazel Applications
-
#include "Hazel/Application.h"
+#include "Hazel/Log.h"
// ------------------------ Entry Point ------------------------
diff --git a/Hazel/src/Hazel/Application.cpp b/Hazel/src/Hazel/Application.cpp
index 93533e3..73a6cb5 100644
--- a/Hazel/src/Hazel/Application.cpp
+++ b/Hazel/src/Hazel/Application.cpp
@@ -2,13 +2,9 @@
namespace Hazel {
- Application::Application() {
+ Application::Application() = default;
- }
-
- Application::~Application() {
-
- }
+ Application::~Application() = default;
void Application::Run() {
while (true)
diff --git a/Hazel/src/Hazel/EntryPoint.h b/Hazel/src/Hazel/EntryPoint.h
index a85e8fc..1ec3a50 100644
--- a/Hazel/src/Hazel/EntryPoint.h
+++ b/Hazel/src/Hazel/EntryPoint.h
@@ -2,14 +2,44 @@
#ifdef HZ_PLATFORM_WINDOWS
-#include
+#include
extern Hazel::Application* Hazel::CreateApplication();
-int main(int argc, char** argv[]) {
- printf("hazel engine!");
+int main(int argc, char* argv[]) {
+ Hazel::Log::init();
+
+ HZ_CORE_TRACE("hello");
+ HZ_CORE_DEBUG("hello");
+ HZ_CORE_INFO("hello");
+ HZ_CORE_WARN("hello");
+ HZ_CORE_ERROR("hello");
+ HZ_CORE_FATAL("hello");
+
+ HZ_CLIENT_TRACE("hello");
+ HZ_CLIENT_DEBUG("hello");
+ HZ_CLIENT_INFO("hello");
+ HZ_CLIENT_WARN("hello");
+ HZ_CLIENT_ERROR("hello");
+ HZ_CLIENT_FATAL("hello");
+
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Window* window = SDL_CreateWindow("demo", 800, 600, 0);
+
+ bool should_quit = false;
+
+ while (!should_quit) {
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ if (event.type == SDL_EVENT_QUIT) {
+ should_quit = true;
+ }
+ }
+ }
+
+
auto app = Hazel::CreateApplication();
- app->Run();
+// app->Run();
}
#endif // HZ_PLATFORM_WINDOWS
diff --git a/Hazel/src/Hazel/Log.cpp b/Hazel/src/Hazel/Log.cpp
new file mode 100644
index 0000000..43056b8
--- /dev/null
+++ b/Hazel/src/Hazel/Log.cpp
@@ -0,0 +1,20 @@
+#include "Log.h"
+
+#include
+
+
+namespace Hazel {
+
+ std::shared_ptr Log::s_CoreLogger;
+ std::shared_ptr Log::s_ClientLogger;
+
+ void Log::init() {
+ spdlog::set_pattern("%^[%T] %n: %v%$");
+ s_CoreLogger = spdlog::stdout_color_mt("Hazel");
+ s_CoreLogger->set_level(spdlog::level::trace);
+
+ s_ClientLogger = spdlog::stdout_color_mt("App");
+ s_ClientLogger->set_level(spdlog::level::trace);
+
+ }
+}
diff --git a/Hazel/src/Hazel/Log.h b/Hazel/src/Hazel/Log.h
new file mode 100644
index 0000000..97db579
--- /dev/null
+++ b/Hazel/src/Hazel/Log.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "Core.h"
+#include
+
+
+
+namespace Hazel {
+
+
+ class HAZEL_API Log
+ {
+ public:
+
+ static void init();
+
+ inline static std::shared_ptr& getCoreLogger() { return s_CoreLogger; }
+ inline static std::shared_ptr& getClientLogger() { return s_ClientLogger; }
+
+ private:
+ static std::shared_ptr s_CoreLogger;
+ static std::shared_ptr s_ClientLogger;
+
+
+
+ };
+
+}
+
+#define HZ_CORE_TRACE(...) ::Hazel::Log::getCoreLogger()->trace(__VA_ARGS__)
+#define HZ_CORE_DEBUG(...) ::Hazel::Log::getCoreLogger()->debug(__VA_ARGS__)
+#define HZ_CORE_INFO(...) ::Hazel::Log::getCoreLogger()->info(__VA_ARGS__)
+#define HZ_CORE_WARN(...) ::Hazel::Log::getCoreLogger()->warn(__VA_ARGS__)
+#define HZ_CORE_ERROR(...) ::Hazel::Log::getCoreLogger()->error(__VA_ARGS__)
+#define HZ_CORE_FATAL(...) ::Hazel::Log::getCoreLogger()->critical(__VA_ARGS__)
+
+
+#define HZ_CLIENT_TRACE(...) ::Hazel::Log::getClientLogger()->trace(__VA_ARGS__)
+#define HZ_CLIENT_DEBUG(...) ::Hazel::Log::getClientLogger()->debug(__VA_ARGS__)
+#define HZ_CLIENT_INFO(...) ::Hazel::Log::getClientLogger()->info(__VA_ARGS__)
+#define HZ_CLIENT_WARN(...) ::Hazel::Log::getClientLogger()->warn(__VA_ARGS__)
+#define HZ_CLIENT_ERROR(...) ::Hazel::Log::getClientLogger()->error(__VA_ARGS__)
+#define HZ_CLIENT_FATAL(...) ::Hazel::Log::getClientLogger()->critical(__VA_ARGS__)
diff --git a/Hazel/vendor/SDL b/Hazel/vendor/SDL
new file mode 160000
index 0000000..9da46bc
--- /dev/null
+++ b/Hazel/vendor/SDL
@@ -0,0 +1 @@
+Subproject commit 9da46bc37fb9920f5ee12b187f165a30339985cc
diff --git a/Hazel/vendor/spdlog b/Hazel/vendor/spdlog
new file mode 160000
index 0000000..bb8694b
--- /dev/null
+++ b/Hazel/vendor/spdlog
@@ -0,0 +1 @@
+Subproject commit bb8694b50f186cb005d32cec76fe94ae25998c0d
diff --git a/Sandbox/CMakeLists.txt b/Sandbox/CMakeLists.txt
new file mode 100644
index 0000000..da66604
--- /dev/null
+++ b/Sandbox/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(PROJECT_NAME "Sandbox")
+project(${PROJECT_NAME})
+
+
+file(GLOB_RECURSE SOURCES "src/*.cpp")
+
+add_executable(${PROJECT_NAME} ${SOURCES})
+
+target_link_libraries(${PROJECT_NAME} PRIVATE Hazel)
diff --git a/Sandbox/Sandbox.vcxproj b/Sandbox/Sandbox.vcxproj
deleted file mode 100644
index f001947..0000000
--- a/Sandbox/Sandbox.vcxproj
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 17.0
- Win32Proj
- {67a786ac-e29d-4dec-9cd8-4654b86ab54a}
- Sandbox
- 10.0
-
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $(SolutionDir)bin\$(Configuration)-$(Platform)\$(ProjectName)\
- $(SolutionDir)bin-int\$(Configuration)-$(Platform)\$(ProjectName)\
-
-
- $(SolutionDir)bin\${Configuration)-$(Platform)\$(Project)\
- $(SolutionDir)bin-int\${Configuration)-$(Platform)\$(Project)\
-
-
-
- Level3
- true
- HZ_PLATFORM_WINDOWS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- $(SolutionDir)Hazel\src
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- HZ_PLATFORM_WINDOWS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- $(SolutionDir)Hazel\src
-
-
- Console
- true
- true
- true
-
-
-
-
- {849c6c03-8690-44ee-ad89-7022698623bc}
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Sandbox/Sandbox.vcxproj.filters b/Sandbox/Sandbox.vcxproj.filters
deleted file mode 100644
index 3b6d14b..0000000
--- a/Sandbox/Sandbox.vcxproj.filters
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
-
-
- 源文件
-
-
-
\ No newline at end of file
diff --git a/Sandbox/src/SandboxApp.cpp b/Sandbox/src/SandboxApp.cpp
index 47ca95b..8bc1bbc 100644
--- a/Sandbox/src/SandboxApp.cpp
+++ b/Sandbox/src/SandboxApp.cpp
@@ -1,5 +1,6 @@
#include
+
class Sandbox : public Hazel::Application
{
public:
@@ -10,14 +11,9 @@ private:
};
-Sandbox::Sandbox()
-{
+Sandbox::Sandbox() = default;
-}
-
-Sandbox::~Sandbox()
-{
-}
+Sandbox::~Sandbox() = default;
Hazel::Application* Hazel::CreateApplication() {
return new Sandbox();