relatively okay i guess
This commit is contained in:
+18
-13
@@ -10,6 +10,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# 1. Platform & Dist Paths
|
# 1. Platform & Dist Paths
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
if(BUILD_FOR_WEB OR EMSCRIPTEN)
|
if(BUILD_FOR_WEB OR EMSCRIPTEN)
|
||||||
set(DIST_PLATFORM "web")
|
set(DIST_PLATFORM "web")
|
||||||
else()
|
else()
|
||||||
@@ -93,19 +94,19 @@ install(EXPORT ${PROJECT_NAME}Targets
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# 5. Standalone Sandbox App / Executable
|
# 5. Standalone Sandbox App / Executable
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
file(GLOB_RECURSE APP_SRC "src/*.cpp")
|
# file(GLOB_RECURSE APP_SRC "src/*.cpp")
|
||||||
add_executable(${PROJECT_NAME} ${APP_SRC})
|
# add_executable(${PROJECT_NAME} ${APP_SRC})
|
||||||
|
#
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib)
|
# target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib)
|
||||||
|
#
|
||||||
if(EMSCRIPTEN)
|
# if(EMSCRIPTEN)
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index" SUFFIX ".html")
|
# set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index" SUFFIX ".html")
|
||||||
target_link_options(${PROJECT_NAME} PRIVATE
|
# target_link_options(${PROJECT_NAME} PRIVATE
|
||||||
"-sUSE_GLFW=3"
|
# "-sUSE_GLFW=3"
|
||||||
"-sASYNCIFY"
|
# "-sASYNCIFY"
|
||||||
"--shell-file" "${CMAKE_CURRENT_SOURCE_DIR}/html/shell_custom.html"
|
# "--shell-file" "${CMAKE_CURRENT_SOURCE_DIR}/html/shell_custom.html"
|
||||||
)
|
# )
|
||||||
endif()
|
# endif()
|
||||||
|
|
||||||
# #------------------------------------------------------------------------------------------
|
# #------------------------------------------------------------------------------------------
|
||||||
# # Make Assets
|
# # Make Assets
|
||||||
@@ -165,5 +166,9 @@ add_custom_target( run
|
|||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (BUILD_EXAMPLES)
|
||||||
|
add_subdirectory(examples/example1)
|
||||||
|
add_subdirectory(examples/example2)
|
||||||
|
endif()
|
||||||
# enable_testing()
|
# enable_testing()
|
||||||
# add_subdirectory(tests)
|
# add_subdirectory(tests)
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "engine/ecs/components.hpp"
|
#include "engine/ecs/components.hpp"
|
||||||
#include "engine/scene/scene.hpp"
|
#include "engine/scene/scene.hpp"
|
||||||
|
|
||||||
#include "game/scenes/menu-scene/menu.hpp"
|
#include "scenes/menu-scene/menu.hpp"
|
||||||
|
|
||||||
#include <entt/entt.hpp>
|
#include <entt/entt.hpp>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
@@ -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)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
#pragma once
|
||||||
@@ -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 <entt/entt.hpp>
|
||||||
|
#include <raylib.h>
|
||||||
|
|
||||||
|
class Game : public varicle::Application {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void on_init() override {
|
||||||
|
auto &scene_manager =
|
||||||
|
varicle::ServiceLocator::get<varicle::SceneManager>();
|
||||||
|
scene_manager.register_scene(
|
||||||
|
"menu", []() { return std::make_unique<MenuScene>(); });
|
||||||
|
|
||||||
|
change_scene("menu");
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_shutdown() override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Game game;
|
||||||
|
game.run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -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 <imgui.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
using namespace entt::literals;
|
||||||
|
|
||||||
|
void MenuScene::init() {
|
||||||
|
using namespace varicle;
|
||||||
|
ServiceLocator::provide(std::make_unique<RaylibAssetLoader>());
|
||||||
|
|
||||||
|
auto &asset_loader = ServiceLocator::get<RaylibAssetLoader>();
|
||||||
|
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<varicle::GlobalTransform2D>(e, 650.0f, 150.0f, 1.0f,0.0f);
|
||||||
|
// registry.emplace<Position>(e, 650.0f, 150.0f);
|
||||||
|
registry.emplace<Sprite>(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<PropertyDatabase>();
|
||||||
|
|
||||||
|
registry.emplace<varicle::LocalTransform2D>(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<v::SceneManager>().switch_to_scene("main");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Dummy(ImVec2(0, 10)); // Gap
|
||||||
|
|
||||||
|
if (ImGui::Button("Quit", button_size)) {
|
||||||
|
v::ServiceLocator::get<v::SceneManager>().quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "engine/scene/scene.hpp"
|
||||||
|
#include <entt/entt.hpp>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
@@ -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}
|
||||||
|
)
|
||||||
|
|
||||||
Reference in New Issue
Block a user