diff --git a/CHANGELOG.md b/CHANGELOG.md index b2bf935626..ab1e5ef781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added resource to easily configure magic numbers in solver (#1281, **@GCeSilva**). - Audio Plugin (#1004, **@Dageus**, **@diogomsmiranda**). - Contact caching for collision between box shapes (#1355, **@fallenatlas**). +- Template Cubos project (#1009, **@RiscadoA**). ### Changed diff --git a/tools/tesseratos/CMakeLists.txt b/tools/tesseratos/CMakeLists.txt index b1e13fd411..89ac66ab36 100644 --- a/tools/tesseratos/CMakeLists.txt +++ b/tools/tesseratos/CMakeLists.txt @@ -28,11 +28,13 @@ cubos_common_target_options(tesseratos) if (TESSERATOS_DISTRIBUTE) target_compile_definitions(tesseratos PRIVATE + TEMPLATES_PATH="templates" APP_ASSETS_PATH="assets" BUILTIN_ASSETS_PATH="builtin" ) else() target_compile_definitions(tesseratos PRIVATE + TEMPLATES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/templates" APP_ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets" BUILTIN_ASSETS_PATH="${CUBOS_ENGINE_ASSETS_PATH}" ) @@ -42,6 +44,7 @@ endif() if(TESSERATOS_DISTRIBUTE) install(TARGETS tesseratos RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(DIRECTORY templates/ DESTINATION ${CMAKE_INSTALL_DATADIR}/tesseratos/templates) install(DIRECTORY assets/ DESTINATION ${CMAKE_INSTALL_DATADIR}/tesseratos/assets) install(DIRECTORY ${CUBOS_ENGINE_ASSETS_PATH}/ DESTINATION ${CMAKE_INSTALL_DATADIR}/tesseratos/builtin) endif() diff --git a/tools/tesseratos/templates/simple/CMakeLists.txt b/tools/tesseratos/templates/simple/CMakeLists.txt new file mode 100644 index 0000000000..07535e8bcd --- /dev/null +++ b/tools/tesseratos/templates/simple/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.20.0) +project(game VERSION 0.1.0) + +option(DISTRIBUTE "Build the game for distribution" OFF) + +add_executable(game + src/main.cpp +) + +find_package(cubos REQUIRED) +target_link_libraries(game cubos::engine) + +target_compile_features(game PRIVATE cxx_std_20) +target_compile_options(game PRIVATE + # Enable preprocessor conformance mode in MSVC - required for __VA_ARGS__ to work correctly + $<$: /Zc:preprocessor> +) + +if(DISTRIBUTE) + # If we're building for distribution, we want to use the assets directories in the same directory as the executable + target_compile_definitions(game PRIVATE + APP_ASSETS_PATH="assets" + BUILTIN_ASSETS_PATH="builtin" + ) + + # On installation, copy both the executable and the assets directories to the installation directory + install(TARGETS game RUNTIME DESTINATION .) + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets/ DESTINATION assets) + install(DIRECTORY ${CUBOS_ENGINE_ASSETS_PATH}/ DESTINATION builtin) +else() + # If we're in development, we want to use the assets directory in the project directory + target_compile_definitions(game PRIVATE + APP_ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets" + BUILTIN_ASSETS_PATH="${CUBOS_ENGINE_ASSETS_PATH}" + ) +endif() diff --git a/tools/tesseratos/templates/simple/assets/scenes/main.cubos b/tools/tesseratos/templates/simple/assets/scenes/main.cubos new file mode 100644 index 0000000000..279d4ba152 --- /dev/null +++ b/tools/tesseratos/templates/simple/assets/scenes/main.cubos @@ -0,0 +1,33 @@ +{ + "entities": { + "render-target": { + "cubos::engine::RenderTargetDefaults": {}, + "cubos::engine::GizmosTarget": {} + }, + "camera": { + "cubos::engine::PerspectiveCamera": 70.0, + "cubos::engine::DrawsTo@render-target": {}, + "cubos::engine::Position": { + "x": 0, + "y": 0, + "z": 0 + } + }, + "sun": { + "cubos::engine::DirectionalLight": { + "color": { + "x": 1.0, + "y": 1.0, + "z": 1.0 + }, + "intensity": 1.0 + }, + "cubos::engine::Rotation": { + "w": 1.0, + "x": 0.3, + "y": -0.1, + "z": 0.5 + } + } + } +} \ No newline at end of file diff --git a/tools/tesseratos/templates/simple/assets/scenes/main.cubos.meta b/tools/tesseratos/templates/simple/assets/scenes/main.cubos.meta new file mode 100644 index 0000000000..bb5f9cf193 --- /dev/null +++ b/tools/tesseratos/templates/simple/assets/scenes/main.cubos.meta @@ -0,0 +1,3 @@ +{ + "id": "ba173db6-4e44-45bc-9cef-c4a25bba8823" +} \ No newline at end of file diff --git a/tools/tesseratos/templates/simple/src/main.cpp b/tools/tesseratos/templates/simple/src/main.cpp new file mode 100644 index 0000000000..435fb25a4d --- /dev/null +++ b/tools/tesseratos/templates/simple/src/main.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +using namespace cubos::engine; + +static const Asset MainSceneAsset = AnyAsset("ba173db6-4e44-45bc-9cef-c4a25bba8823"); + +int main(int argc, char** argv) +{ + Cubos cubos{argc, argv}; + cubos.plugin(defaultsPlugin); + + // TODO: add your own game plugins here! + + cubos.startupSystem("set the assets directory path").before(settingsTag).call([](Settings& settings) { + settings.setString("assets.app.osPath", APP_ASSETS_PATH); + settings.setString("assets.builtin.osPath", BUILTIN_ASSETS_PATH); + }); + + cubos.startupSystem("load and spawn the Main Scene") + .tagged(assetsTag) + .call([](Commands cmds, const Assets& assets) { cmds.spawn(assets.read(MainSceneAsset)->blueprint); }); + + cubos.run(); +}