diff --git a/CMakeLists.txt b/CMakeLists.txt index 77f8301..92ae37b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # ------------------------------------------------------------------------------ # 1. Platform & Dist Paths # ------------------------------------------------------------------------------ + if(BUILD_FOR_WEB OR EMSCRIPTEN) set(DIST_PLATFORM "web") else() @@ -93,19 +94,19 @@ install(EXPORT ${PROJECT_NAME}Targets # ------------------------------------------------------------------------------ # 5. Standalone Sandbox App / Executable # ------------------------------------------------------------------------------ -file(GLOB_RECURSE APP_SRC "src/*.cpp") -add_executable(${PROJECT_NAME} ${APP_SRC}) - -target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib) - -if(EMSCRIPTEN) - set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index" SUFFIX ".html") - target_link_options(${PROJECT_NAME} PRIVATE - "-sUSE_GLFW=3" - "-sASYNCIFY" - "--shell-file" "${CMAKE_CURRENT_SOURCE_DIR}/html/shell_custom.html" - ) -endif() +# file(GLOB_RECURSE APP_SRC "src/*.cpp") +# add_executable(${PROJECT_NAME} ${APP_SRC}) +# +# target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib) +# +# if(EMSCRIPTEN) +# set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index" SUFFIX ".html") +# target_link_options(${PROJECT_NAME} PRIVATE +# "-sUSE_GLFW=3" +# "-sASYNCIFY" +# "--shell-file" "${CMAKE_CURRENT_SOURCE_DIR}/html/shell_custom.html" +# ) +# endif() # #------------------------------------------------------------------------------------------ # # Make Assets @@ -165,5 +166,9 @@ add_custom_target( run WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) +if (BUILD_EXAMPLES) + add_subdirectory(examples/example1) + add_subdirectory(examples/example2) +endif() # enable_testing() # add_subdirectory(tests) diff --git a/examples/example1/CMakeLists.txt b/examples/example1/CMakeLists.txt new file mode 100644 index 0000000..3fbba30 --- /dev/null +++ b/examples/example1/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.25) + +project(example1 LANGUAGES CXX) + +file(GLOB_RECURSE SRCS "src/*.cpp") + +MESSAGE(STATUS ${SRCS}) + + +add_executable(${PROJECT_NAME} ${SRCS}) + +target_include_directories(${PROJECT_NAME} PRIVATE src) + +target_link_libraries(${PROJECT_NAME} PRIVATE varicle_lib) diff --git a/src/game/ecs/components.hpp b/examples/example1/src/ecs/components.hpp similarity index 100% rename from src/game/ecs/components.hpp rename to examples/example1/src/ecs/components.hpp diff --git a/src/game/main.cpp b/examples/example1/src/main.cpp similarity index 94% rename from src/game/main.cpp rename to examples/example1/src/main.cpp index 3cd0091..c92bd13 100644 --- a/src/game/main.cpp +++ b/examples/example1/src/main.cpp @@ -5,7 +5,7 @@ #include "engine/ecs/components.hpp" #include "engine/scene/scene.hpp" -#include "game/scenes/menu-scene/menu.hpp" +#include "scenes/menu-scene/menu.hpp" #include #include diff --git a/src/game/scenes/menu-scene/menu.cpp b/examples/example1/src/scenes/menu-scene/menu.cpp similarity index 100% rename from src/game/scenes/menu-scene/menu.cpp rename to examples/example1/src/scenes/menu-scene/menu.cpp diff --git a/src/game/scenes/menu-scene/menu.hpp b/examples/example1/src/scenes/menu-scene/menu.hpp similarity index 100% rename from src/game/scenes/menu-scene/menu.hpp rename to examples/example1/src/scenes/menu-scene/menu.hpp diff --git a/examples/example2/CMakeLists.txt b/examples/example2/CMakeLists.txt new file mode 100644 index 0000000..ee85929 --- /dev/null +++ b/examples/example2/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.25) + +project(example2 LANGUAGES CXX) + +file(GLOB_RECURSE SRCS "src/*.cpp") + +MESSAGE(STATUS ${SRCS}) + + +add_executable(${PROJECT_NAME} ${SRCS}) + +target_include_directories(${PROJECT_NAME} PRIVATE src) + +target_link_libraries(${PROJECT_NAME} PRIVATE varicle_lib) diff --git a/examples/example2/src/ecs/components.hpp b/examples/example2/src/ecs/components.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/examples/example2/src/ecs/components.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/examples/example2/src/main.cpp b/examples/example2/src/main.cpp new file mode 100644 index 0000000..c92bd13 --- /dev/null +++ b/examples/example2/src/main.cpp @@ -0,0 +1,32 @@ +#include "engine/core/application.hpp" +#include "engine/core/engine-variant/engine-variant-property.hpp" +#include "engine/core/engine-variant/engine-variant.hpp" +#include "engine/core/service-locator.hpp" +#include "engine/ecs/components.hpp" +#include "engine/scene/scene.hpp" + +#include "scenes/menu-scene/menu.hpp" + +#include +#include + +class Game : public varicle::Application { + + public: + void on_init() override { + auto &scene_manager = + varicle::ServiceLocator::get(); + scene_manager.register_scene( + "menu", []() { return std::make_unique(); }); + + change_scene("menu"); + } + + void on_shutdown() override {} +}; + +int main() { + Game game; + game.run(); + return 0; +} diff --git a/examples/example2/src/scenes/menu-scene/menu.cpp b/examples/example2/src/scenes/menu-scene/menu.cpp new file mode 100644 index 0000000..29e7050 --- /dev/null +++ b/examples/example2/src/scenes/menu-scene/menu.cpp @@ -0,0 +1,95 @@ +#include "menu.hpp" + +#include "engine/asset/raylib-asset.hpp" +#include "engine/core/engine-variant/engine-variant-property.hpp" +#include "engine/core/engine-variant/engine-variant.hpp" +#include "engine/core/service-locator.hpp" +#include "engine/ecs/components.hpp" +#include "engine/render/render-system.hpp" + +#include +#include +#include + +using namespace entt::literals; + +void MenuScene::init() { + using namespace varicle; + ServiceLocator::provide(std::make_unique()); + + auto &asset_loader = ServiceLocator::get(); + asset_loader.load_asset("assets/bird.png"); + auto x = asset_loader.get_reader().get_asset_list(); + for (auto i : x) { + std::cout << i << std::endl; + } + + auto e = registry.create(); + registry.emplace(e, 650.0f, 150.0f, 1.0f,0.0f); + // registry.emplace(e, 650.0f, 150.0f); + registry.emplace(e, "assets/bird.png", 0.0f, 0.f, 100.f, 100.f, + true, false, 0.f); + auto img = + LoadImageFromTexture(*asset_loader.get_texture("assets/bird.png")); + SetWindowIcon(img); + UnloadImage(img); + + auto &p_database = varicle::ServiceLocator::get(); + + registry.emplace(e, 100.0f, 100.0f, 10.0f, + 5.0f); + + EngineVariant current_pos = + p_database.get_value(registry, e, "global_position"_hs); + EngineVariant current_scale = + p_database.get_value(registry, e, "scale"_hs); + EngineVariant current_rot = + p_database.get_value(registry, e, "rotation"_hs); + + std::cout << current_pos << current_scale << current_rot << std::endl; +} + +void MenuScene::update(float dt) {} + +void MenuScene::render() { + varicle::update_render_system(registry); + DrawCircleV({650,400},100,PURPLE); + +} + +void MenuScene::ui() { + + // Get the current screen/viewport size + ImVec2 screen_size = ImGui::GetIO().DisplaySize; + + // size of button container + ImVec2 vbox_size = ImVec2(200.0f, 250.0f); + + // set next container to be center of the screen + ImVec2 screen_center = ImVec2(screen_size.x * 0.5f, screen_size.y * 0.5f); + ImGui::SetNextWindowPos(screen_center, ImGuiCond_Always, + ImVec2(0.5f, 0.5f)); + ImGui::SetNextWindowSize(vbox_size); + + // remove sub window decoration + ImGuiWindowFlags flags = + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBackground; + + ImGui::Begin("VBoxContainer", nullptr, flags); + + // set button width to be size fill container + ImVec2 button_size = ImVec2(ImGui::GetContentRegionAvail().x, 50.0f); + + // ImGui::SetCursorPos(centeredPos); + if (ImGui::Button("Play", button_size)) { + v::ServiceLocator::get().switch_to_scene("main"); + } + + ImGui::Dummy(ImVec2(0, 10)); // Gap + + if (ImGui::Button("Quit", button_size)) { + v::ServiceLocator::get().quit(); + } + + ImGui::End(); +} diff --git a/examples/example2/src/scenes/menu-scene/menu.hpp b/examples/example2/src/scenes/menu-scene/menu.hpp new file mode 100644 index 0000000..f4770a1 --- /dev/null +++ b/examples/example2/src/scenes/menu-scene/menu.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "engine/scene/scene.hpp" +#include + +namespace v = varicle; + +class MenuScene : public v::Scene { + public: + entt::registry registry; + void init() override; + void update(float dt) override; + void render() override; + void ui() override; +}; diff --git a/template/CMakeLists.txt b/template/CMakeLists.txt new file mode 100644 index 0000000..c184225 --- /dev/null +++ b/template/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.25) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +project(farm-space LANGUAGES CXX) + +add_executable(${PROJECT_NAME} src/main.cpp) + + +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_SOURCE_DIR}/dist/include +) +target_link_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_SOURCE_DIR}/dist/lib +) + +target_link_libraries(${PROJECT_NAME} PUBLIC + varicle + raylib + assetpacker +) + +if(EMSCRIPTEN) + # Output an HTML page instead of a raw binary + set_target_properties(${PROJECT_NAME} PROPERTIES + OUTPUT_NAME "index" + SUFFIX ".html" + ) + + # Pass Emscripten linker flags + target_link_options(${PROJECT_NAME} PRIVATE + "-sUSE_GLFW=3" # Needed for Raylib web builds + "-sASYNCIFY" # Allows main loop to yield to the browser + "--shell-file" "${CMAKE_CURRENT_SOURCE_DIR}/html/shell_custom.html" # (Optional) Custom HTML shell + # Pre-pack your assets directory into the WebAssembly virtual filesystem + "--preload-file" "${CMAKE_CURRENT_BINARY_DIR}/data.dat@/data.dat" + ) + +elseif(WIN32) + target_link_libraries(farm-space PRIVATE winmm opengl32 gdi32) +endif() + +add_custom_target(run + COMMAND ${PROJECT_NAME} + DEPENDS ${PROJECT_NAME} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +) +