Restructure project directories
This commit is contained in:
parent
e85ca1348e
commit
a4823f3887
3
Apps/CMakeLists.txt
Normal file
3
Apps/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
add_subdirectory(Demos)
|
||||||
|
#add_subdirectory(Editors)
|
@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.26)
|
cmake_minimum_required(VERSION 3.26)
|
||||||
|
|
||||||
# Additional paths to search for custom and third-party CMake modules
|
# Additional paths to search for custom and third-party CMake modules
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
|
||||||
|
|
||||||
include(BuildProperties)
|
include(BuildProperties)
|
||||||
|
|
||||||
@ -24,7 +24,6 @@ project(Elemental
|
|||||||
include(CPM)
|
include(CPM)
|
||||||
|
|
||||||
SET(${PROJECT_NAME}_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
SET(${PROJECT_NAME}_CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
SET(${PROJECT_NAME}_INCLUDE_DIRS ${IOCore_CMAKE_SOURCE_DIR}/include)
|
|
||||||
|
|
||||||
option(CI_BUILD "Mark this as a CI/CD system build. Defines a C++ preprocessor macro CI_BUILD=1.")
|
option(CI_BUILD "Mark this as a CI/CD system build. Defines a C++ preprocessor macro CI_BUILD=1.")
|
||||||
if (CI_BUILD)
|
if (CI_BUILD)
|
||||||
@ -40,7 +39,7 @@ ON
|
|||||||
# enable compile_commands.json generation for clangd
|
# enable compile_commands.json generation for clangd
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
|
||||||
|
|
||||||
IF( NOT CMAKE_BUILD_TYPE )
|
IF(NOT CMAKE_BUILD_TYPE)
|
||||||
SET( CMAKE_BUILD_TYPE Debug )
|
SET( CMAKE_BUILD_TYPE Debug )
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
@ -149,22 +148,13 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|||||||
add_compile_definitions(-DDEBUG=1)
|
add_compile_definitions(-DDEBUG=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Include directories
|
|
||||||
include_directories(${Elemental_CMAKE_SOURCE_DIR}/include)
|
|
||||||
|
|
||||||
# Add a target to copy application resource files to the build dir
|
|
||||||
add_custom_target(copy_assets
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/data ${Elemental_ARTIFACT_DIR}/share/data
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/data ${CMAKE_BINARY_DIR}/tests/data
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add subdirectories
|
# Add subdirectories
|
||||||
add_subdirectory(src)
|
add_subdirectory(Modules)
|
||||||
add_subdirectory(demo)
|
|
||||||
#add_subdirectory(apps)
|
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(Tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(Apps)
|
||||||
|
|
||||||
# vim: ts=2 sw=2 noet foldmethod=indent :
|
# vim: ts=2 sw=2 noet foldmethod=indent :
|
||||||
|
1
Modules/CMakeLists.txt
Normal file
1
Modules/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
add_subdirectory(elemental)
|
@ -15,9 +15,13 @@ target_include_directories(elemental SYSTEM BEFORE
|
|||||||
PUBLIC ${NLOHMANN_JSON_INCLUDE_DIRS}
|
PUBLIC ${NLOHMANN_JSON_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_include_directories(elemental BEFORE
|
||||||
|
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
# Add a target to copy this project's header files to the build dir
|
# Add a target to copy this project's header files to the build dir
|
||||||
add_custom_target(include_files
|
add_custom_target(include_files
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${Elemental_CMAKE_SOURCE_DIR}/include ${Elemental_ARTIFACT_DIR}/include
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include ${Elemental_ARTIFACT_DIR}/include
|
||||||
)
|
)
|
||||||
add_dependencies(elemental include_files)
|
add_dependencies(elemental include_files)
|
||||||
|
|
||||||
@ -30,9 +34,9 @@ set(ELEMENTAL_LINK_DEPS
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Add additional link options for boost::stacktrace
|
# Add additional link options for boost::stacktrace
|
||||||
if (USE_BOOST_STACKTRACE)
|
#if (USE_BOOST_STACKTRACE)
|
||||||
target_link_options(elemental PUBLIC -rdynamic)
|
# target_link_options(elemental PUBLIC -rdynamic)
|
||||||
endif()
|
#endif()
|
||||||
|
|
||||||
# Link the library dependencies publicly so that that users of this library
|
# Link the library dependencies publicly so that that users of this library
|
||||||
# Also get the same dependencies.
|
# Also get the same dependencies.
|
@ -1,6 +1,6 @@
|
|||||||
# Define the executable 'test-runner'
|
# Define the executable 'test-runner'
|
||||||
set(test-runner_SOURCES
|
add_executable(test-runner
|
||||||
runtime.test.cpp
|
runtime.test.cpp
|
||||||
Singleton.template.test.cpp
|
Singleton.template.test.cpp
|
||||||
IRenderer.test.cpp
|
IRenderer.test.cpp
|
||||||
LoopRegulator.test.cpp
|
LoopRegulator.test.cpp
|
||||||
@ -10,10 +10,7 @@ set(test-runner_SOURCES
|
|||||||
SDL_Memory.test.cpp
|
SDL_Memory.test.cpp
|
||||||
JsonConfigFile.test.cpp
|
JsonConfigFile.test.cpp
|
||||||
paths.test.cpp
|
paths.test.cpp
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(test-runner
|
|
||||||
${test-runner_SOURCES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(test-runner PROPERTIES EXCLUDE_FROM_ALL 1)
|
set_target_properties(test-runner PROPERTIES EXCLUDE_FROM_ALL 1)
|
||||||
@ -38,8 +35,8 @@ target_include_directories(test-runner SYSTEM BEFORE
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(test-runner
|
target_include_directories(test-runner
|
||||||
PRIVATE ${CMAKE_SOURCE_DIR}/include
|
#PRIVATE ${CMAKE_CURRENTSOURCE_DIR}/include
|
||||||
PRIVATE ${CMAKE_SOURCE_DIR}/tests
|
PRIVATE ${CMAKE_SOURCE_DIR}/Tests
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_directories(test-runner PRIVATE
|
target_link_directories(test-runner PRIVATE
|
||||||
@ -53,7 +50,7 @@ PRIVATE
|
|||||||
|
|
||||||
# Set output directories for build targets
|
# Set output directories for build targets
|
||||||
set_target_properties(test-runner PROPERTIES
|
set_target_properties(test-runner PROPERTIES
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${Elemental_ARTIFACT_DIR}/tests"
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(test_bin)
|
add_custom_target(test_bin)
|
||||||
@ -61,7 +58,6 @@ add_dependencies(test_bin
|
|||||||
test-runner
|
test-runner
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# extras: catch2 ctest integration.
|
# extras: catch2 ctest integration.
|
||||||
# add catch2's ctest cmake module and register the tests defined by mdml-tests
|
# add catch2's ctest cmake module and register the tests defined by mdml-tests
|
||||||
# using catch_discover_tests
|
# using catch_discover_tests
|
||||||
@ -72,12 +68,15 @@ catch_discover_tests(test-runner)
|
|||||||
# bonus: add a custom ctest target to the build system, to run tests in the
|
# bonus: add a custom ctest target to the build system, to run tests in the
|
||||||
# correct directory
|
# correct directory
|
||||||
add_custom_target(ctest
|
add_custom_target(ctest
|
||||||
COMMAND ctest -c $configuration --test-dir . --allow-running-no-tests --output-on-failure
|
COMMAND ctest -c $configuration --test-dir ${CMAKE_BINARY_DIR}/Tests --allow-running-no-tests --output-on-failure
|
||||||
|
)
|
||||||
|
add_custom_target(copy_test_assets
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/data ${CMAKE_BINARY_DIR}/tests/data
|
||||||
)
|
)
|
||||||
set_target_properties(ctest PROPERTIES EXCLUDE_FROM_ALL 1)
|
set_target_properties(ctest PROPERTIES EXCLUDE_FROM_ALL 1)
|
||||||
add_dependencies(ctest
|
add_dependencies(ctest
|
||||||
test_bin
|
test_bin
|
||||||
copy_assets
|
copy_test_assets
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(sdl)
|
add_subdirectory(sdl)
|
Before Width: | Height: | Size: 707 B After Width: | Height: | Size: 707 B |
Before Width: | Height: | Size: 580 KiB After Width: | Height: | Size: 580 KiB |
@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
#add_subdirectory(game)
|
|
||||||
|
|
||||||
#add_subdirectory(editors/sprite)
|
|
||||||
#add_subdirectory(editors/level)
|
|
@ -1,22 +0,0 @@
|
|||||||
|
|
||||||
set(game_SOURCES
|
|
||||||
main.cpp
|
|
||||||
ElementalGame.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(game
|
|
||||||
${game_SOURCES}
|
|
||||||
)
|
|
||||||
|
|
||||||
#target_include_directories(app PRIVATE
|
|
||||||
# ${CMAKE_SOURCE_DIR}/src/
|
|
||||||
#)
|
|
||||||
|
|
||||||
target_link_libraries(game PRIVATE
|
|
||||||
elemental
|
|
||||||
)
|
|
||||||
|
|
||||||
# Manually adds a predefined target as a dependency
|
|
||||||
add_dependencies(game copy_assets)
|
|
||||||
|
|
||||||
# vim: ts=2 sw=2 noet foldmethod=indent :
|
|
@ -1,131 +0,0 @@
|
|||||||
/* ElementalGame.cpp
|
|
||||||
* Copyright © 2023 Saul D. Beniquez
|
|
||||||
* License: Mozilla Public License v. 2.0
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
||||||
* v.2.0. If a copy of the MPL was not distributed with this file, You can
|
|
||||||
* obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "./ElementalGame.hpp"
|
|
||||||
|
|
||||||
#include "Singleton.hpp"
|
|
||||||
|
|
||||||
#include "Exception.hpp"
|
|
||||||
#include "IRenderer.hpp"
|
|
||||||
#include "LoopRegulator.hpp"
|
|
||||||
#include "SdlRenderer.hpp"
|
|
||||||
|
|
||||||
#include "util/debug.hpp"
|
|
||||||
|
|
||||||
#include "SdlEventSource.hpp"
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <iostream>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
using namespace elemental;
|
|
||||||
|
|
||||||
/**! \name Helper Functions */
|
|
||||||
/// \{
|
|
||||||
void
|
|
||||||
print_cycle_rate(milliseconds& cycle_length,
|
|
||||||
c::const_string label = "cycle_length")
|
|
||||||
{
|
|
||||||
DBG_PRINT(label << cycle_length.count() << "ms.");
|
|
||||||
}
|
|
||||||
/// \}
|
|
||||||
|
|
||||||
ElementalGame::~ElementalGame()
|
|
||||||
{
|
|
||||||
video_renderer.deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto
|
|
||||||
ElementalGame::run() -> int
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
LoopRegulator frame_regulator(60_Hz);
|
|
||||||
|
|
||||||
this->is_running = true;
|
|
||||||
this->running_threads["simulation_thread"] =
|
|
||||||
std::thread([this]() { this->simulation_thread_loop(); });
|
|
||||||
|
|
||||||
while (this->is_running) {
|
|
||||||
frame_regulator.startUpdate();
|
|
||||||
this->video_renderer.clearScreen();
|
|
||||||
|
|
||||||
this->event_emitter.pollEvents();
|
|
||||||
|
|
||||||
auto cycle_delay_ms = frame_regulator.delay();
|
|
||||||
print_cycle_rate(cycle_delay_ms, "frame delay");
|
|
||||||
video_renderer.flip();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->is_running = false;
|
|
||||||
|
|
||||||
/* threading clean-up:
|
|
||||||
* wait for all child threads to finish */
|
|
||||||
for (auto& [key, values] : this->running_threads) {
|
|
||||||
values.join();
|
|
||||||
}
|
|
||||||
return kSUCCESS;
|
|
||||||
} catch (Exception& exc) {
|
|
||||||
throw;
|
|
||||||
} catch (std::exception& excp) {
|
|
||||||
throw Exception(excp);
|
|
||||||
}
|
|
||||||
return kERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ElementalGame::recieveMessage(const Observable& sender, std::any message)
|
|
||||||
{
|
|
||||||
ASSERT(message.has_value());
|
|
||||||
auto event = std::any_cast<SDL_Event>(message);
|
|
||||||
if (event.type == SDL_QUIT) {
|
|
||||||
this->is_running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementalGame::ElementalGame()
|
|
||||||
: Application()
|
|
||||||
, IObserver()
|
|
||||||
, video_renderer(IRenderer::GetInstance<SdlRenderer>())
|
|
||||||
, event_emitter(Singleton::getReference<SdlEventSource>())
|
|
||||||
{
|
|
||||||
RendererSettings renderer_settings = {
|
|
||||||
{ "Test",
|
|
||||||
WindowMode::Windowed, // mode
|
|
||||||
WindowPlacement::Centered, // placement
|
|
||||||
{ 0, 0 }, // window.pos
|
|
||||||
{ 1024_px, 768_px } }, // window.size
|
|
||||||
{ 1024_px, 768_px } // internal resolution
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set up video renderer
|
|
||||||
video_renderer.init(renderer_settings);
|
|
||||||
|
|
||||||
// Initialize event_emitter
|
|
||||||
event_emitter.registerObserver(*this);
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
event_emitter.pollEvents();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ElementalGame::simulation_thread_loop()
|
|
||||||
{
|
|
||||||
LoopRegulator loop_regulator(30_Hz);
|
|
||||||
do {
|
|
||||||
loop_regulator.startUpdate();
|
|
||||||
this->event_emitter.transmitEvents();
|
|
||||||
// Scene.Update()
|
|
||||||
|
|
||||||
auto cycle_delay_ms = loop_regulator.delay();
|
|
||||||
print_cycle_rate(cycle_delay_ms);
|
|
||||||
} while (this->is_running);
|
|
||||||
}
|
|
||||||
// clang-format off
|
|
||||||
// vim: set foldmethod=syntax textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :
|
|
@ -1,60 +0,0 @@
|
|||||||
/* ElementalGame.hpp
|
|
||||||
* Copyright © 2023 Saul D. Beniquez
|
|
||||||
* License: Mozilla Public License v. 2.0
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
||||||
* v.2.0. If a copy of the MPL was not distributed with this file, You can
|
|
||||||
* obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "IApplication.hpp"
|
|
||||||
#include "IObserver.hpp"
|
|
||||||
#include "IRenderer.hpp"
|
|
||||||
|
|
||||||
#include "Application.hpp"
|
|
||||||
#include "LoopRegulator.hpp"
|
|
||||||
|
|
||||||
#include "Singleton.hpp"
|
|
||||||
#include "types.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <stack>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
namespace elemental {
|
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
class IRenderer;
|
|
||||||
class IInputDriver;
|
|
||||||
class SdlEventSource;
|
|
||||||
|
|
||||||
class ElementalGame
|
|
||||||
: public Application
|
|
||||||
, public IObserver
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class Singleton;
|
|
||||||
|
|
||||||
~ElementalGame() override;
|
|
||||||
|
|
||||||
auto run() -> int override;
|
|
||||||
void recieveMessage(const Observable& sender,
|
|
||||||
std::any message = std::any()) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ElementalGame();
|
|
||||||
void simulation_thread_loop();
|
|
||||||
|
|
||||||
Dictionary<std::thread> running_threads;
|
|
||||||
bool is_running{ false };
|
|
||||||
|
|
||||||
IRenderer& video_renderer;
|
|
||||||
SdlEventSource& event_emitter;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace elemental
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
// vim: set foldmethod=syntax textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :
|
|
@ -1,37 +0,0 @@
|
|||||||
/* main.cpp
|
|
||||||
* Copyright © 2023 Saul D. Beniquez
|
|
||||||
* License: Mozilla Public License v. 2.0
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
||||||
* v.2.0. If a copy of the MPL was not distributed with this file, You can
|
|
||||||
* obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "ElementalGame.hpp"
|
|
||||||
#include "Exception.hpp"
|
|
||||||
#include "IApplication.hpp"
|
|
||||||
#include "Singleton.hpp"
|
|
||||||
|
|
||||||
using namespace elemental;
|
|
||||||
|
|
||||||
auto
|
|
||||||
main(int argc, c::const_string argv[], c::const_string envp[]) -> int
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
auto& game_instance = Singleton::getReference<ElementalGame>();
|
|
||||||
game_instance.init(argc, argv, envp);
|
|
||||||
|
|
||||||
return game_instance.run();
|
|
||||||
} catch (elemental::Exception& custom_exception) {
|
|
||||||
std::cerr << custom_exception.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
} catch (std::exception& stl_exception) {
|
|
||||||
std::cerr << stl_exception.what() << std::endl;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
// vim: set foldmethod=syntax textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :
|
|
Loading…
Reference in New Issue
Block a user