From 618b7bd257d5d6e711054a700025b14564191f5e Mon Sep 17 00:00:00 2001 From: Connor Date: Tue, 27 Jan 2026 00:59:20 +0900 Subject: [PATCH] Starting point --- .gitignore | 29 +++++++++++++++++++++++++++++ CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ cmake/FetchDependencies.cmake | 20 ++++++++++++++++++++ src/CMakeLists.txt | 1 + src/core/CMakeLists.txt | 21 +++++++++++++++++++++ src/core/factory_core.cpp | 5 +++++ src/core/factory_core.hpp | 25 +++++++++++++++++++++++++ tests/CMakeLists.txt | 15 +++++++++++++++ tests/test_example.cpp | 30 ++++++++++++++++++++++++++++++ tests/test_main.cpp | 2 ++ 10 files changed, 181 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 cmake/FetchDependencies.cmake create mode 100644 src/CMakeLists.txt create mode 100644 src/core/CMakeLists.txt create mode 100644 src/core/factory_core.cpp create mode 100644 src/core/factory_core.hpp create mode 100644 tests/CMakeLists.txt create mode 100644 tests/test_example.cpp create mode 100644 tests/test_main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f16c16d --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Build directories +build/ +cmake-build-*/ +out/ + +# IDE files +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# Compiled files +*.o +*.a +*.so +*.dylib + +# CMake generated files +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +compile_commands.json +CTestTestfile.cmake +Testing/ + +# OS files +.DS_Store +Thumbs.db diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7482775 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.16) +project(factory_hole_core + VERSION 0.1.0 + DESCRIPTION "High-performance ECS-based factory game engine core" + LANGUAGES CXX +) + +# C++17 standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Options +option(FACTORY_CORE_BUILD_TESTS "Build tests" ON) +option(FACTORY_CORE_BUILD_EXAMPLES "Build examples" ON) + +# Export compile commands for IDE support +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Include dependency management +include(cmake/FetchDependencies.cmake) + +# Add subdirectories +add_subdirectory(src) + +if(FACTORY_CORE_BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif() + +if(FACTORY_CORE_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() diff --git a/cmake/FetchDependencies.cmake b/cmake/FetchDependencies.cmake new file mode 100644 index 0000000..6e9959d --- /dev/null +++ b/cmake/FetchDependencies.cmake @@ -0,0 +1,20 @@ +include(FetchContent) + +# Fetch flecs - high-performance ECS library +FetchContent_Declare( + flecs + GIT_REPOSITORY https://github.com/SanderMertens/flecs.git + GIT_TAG v4.0.4 + GIT_SHALLOW TRUE +) + +# Fetch doctest - testing framework (same as Godot uses) +FetchContent_Declare( + doctest + GIT_REPOSITORY https://github.com/doctest/doctest.git + GIT_TAG v2.4.11 + GIT_SHALLOW TRUE +) + +# Make dependencies available +FetchContent_MakeAvailable(flecs doctest) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..ad6d478 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(core) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt new file mode 100644 index 0000000..1fd77cb --- /dev/null +++ b/src/core/CMakeLists.txt @@ -0,0 +1,21 @@ +# Factory Core library +add_library(factory_core STATIC + factory_core.cpp +) + +# Add alias for consistent usage +add_library(factory::core ALIAS factory_core) + +target_include_directories(factory_core + PUBLIC + $ + $ +) + +target_link_libraries(factory_core + PUBLIC + flecs::flecs_static +) + +# Set compile features +target_compile_features(factory_core PUBLIC cxx_std_17) diff --git a/src/core/factory_core.cpp b/src/core/factory_core.cpp new file mode 100644 index 0000000..4d6896e --- /dev/null +++ b/src/core/factory_core.cpp @@ -0,0 +1,5 @@ +#include "factory_core.hpp" + +// Implementation file for factory_core +// Currently empty as Core is header-only, but needed for static library target +// Future implementations will go here diff --git a/src/core/factory_core.hpp b/src/core/factory_core.hpp new file mode 100644 index 0000000..4cc712a --- /dev/null +++ b/src/core/factory_core.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +namespace factory { + +// Core engine class wrapping flecs world +class Core { +public: + Core() : world_() {} + + // Access the underlying flecs world + flecs::world& world() { return world_; } + const flecs::world& world() const { return world_; } + + // Progress the simulation by one tick + bool progress(float delta_time = 0.0f) { + return world_.progress(delta_time); + } + +private: + flecs::world world_; +}; + +} // namespace factory diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..cb9bc6d --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +# Test executable +add_executable(factory_core_tests + test_main.cpp + test_example.cpp +) + +target_link_libraries(factory_core_tests + PRIVATE + factory_core + doctest::doctest +) + +# Register with CTest +include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake) +doctest_discover_tests(factory_core_tests) diff --git a/tests/test_example.cpp b/tests/test_example.cpp new file mode 100644 index 0000000..363ac9d --- /dev/null +++ b/tests/test_example.cpp @@ -0,0 +1,30 @@ +#include +#include "factory_core.hpp" + +TEST_CASE("Core initialization") { + factory::Core core; + + SUBCASE("World is valid after construction") { + CHECK(core.world().id() != 0); + } + + SUBCASE("Progress returns true") { + CHECK(core.progress() == true); + } +} + +TEST_CASE("Basic ECS operations") { + factory::Core core; + auto& world = core.world(); + + SUBCASE("Can create entity") { + auto entity = world.entity(); + CHECK(entity.is_valid()); + } + + SUBCASE("Can create entity with name") { + auto entity = world.entity("test_entity"); + CHECK(entity.is_valid()); + CHECK(entity.name() == std::string("test_entity")); + } +} diff --git a/tests/test_main.cpp b/tests/test_main.cpp new file mode 100644 index 0000000..0a3f254 --- /dev/null +++ b/tests/test_main.cpp @@ -0,0 +1,2 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include