diff --git a/demo/main.cpp b/demo/main.cpp index 2a04b5f6bc283fe88e227b0d466c9dd953d68a92..281b687a6dfa8dcda8bf13c47b28ee7fe8ac5125 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -365,53 +365,48 @@ void gamepadDebug(bool* visible) { int main(int argc, const char* argv[]) { fggl::App app( "fggl-demo" ); - app.add_state<MenuScene>("menu"); - app.add_state<GameScene>("game"); - + // FIXME: janky API(s) auto& locator = fggl::util::ServiceLocator::instance(); - - // setup ECS Types - auto types = std::make_shared< fggl::ecs3::TypeRegistry >(); - locator.supply<fggl::ecs3::TypeRegistry>( types ); - - types->make<fggl::math::Transform>(); - fggl::ecs3::ModuleManager modules(*types); - - // setup ECS - //fggl::ecs3::World ecs(types); - - // input management + auto inputs = std::make_shared<fggl::input::Input>(); locator.supply<fggl::input::Input>(inputs); - // window - auto glfwModule = modules.load<fggl::gfx::ecsGlfwModule>(inputs); - auto window = glfwModule->createWindow("Demo Game"); - window->fullscreen( true ); - - // storage API auto storage = std::make_shared<fggl::data::Storage>(); locator.supply<fggl::data::Storage>(storage); - //discover( storage.resolvePath(fggl::data::Data, "../../packs") ); - // Opengl APIs - glModule = modules.load<fggl::gfx::ecsOpenGLModule>(window, storage); + // Would be nice to not take args like this, it messes with lifetimes + auto& windowing = app.use<fggl::gfx::ecsGlfwModule>(inputs); + + // -- should not be our problem - this is a broken api + auto window = windowing.createWindow("Demo Game"); + window->fullscreen( true ); + // -- + + auto& graphics = app.use<fggl::gfx::ecsOpenGLModule>(window, storage); + + // -- should not be out problem - this is a broken api fggl::gfx::loadPipeline(glModule, "unlit", false); fggl::gfx::loadPipeline(glModule, "phong", false); fggl::gfx::loadPipeline(glModule, "normals", false); + // -- + + // and now our states + app.add_state<MenuScene>("menu"); + app.add_state<GameScene>("game"); + // debug layer - std::shared_ptr<fggl::debug::DebugUI> debug = std::make_shared<fggl::debug::DebugUI>(window); - locator.supply<fggl::debug::DebugUI>(debug); - debug->addWindow("gamepad", gamepadDebug); + //std::shared_ptr<fggl::debug::DebugUI> debug = std::make_shared<fggl::debug::DebugUI>(window); + //locator.supply<fggl::debug::DebugUI>(debug); + //debug->addWindow("gamepad", gamepadDebug); //debug->addWindow("imgui-demo", ImGui::ShowDemoWindow); //debug->addWindow("imgui-about", ImGui::ShowAboutWindow); //debug->addWindow("imgui-help", [](bool* val) { ImGui::ShowUserGuide(); } ); - debug->visible(true); + //debug->visible(true); // Scene management - auto scenes = std::make_shared<fggl::scenes::SceneManager>(); - locator.supply<fggl::scenes::SceneManager>(scenes); + //auto scenes = std::make_shared<fggl::scenes::SceneManager>(); + //locator.supply<fggl::scenes::SceneManager>(scenes); //scenes->create("main_menu", std::make_shared<MenuScene>(inputs)); //scenes->create("game", std::make_shared<GameScene>(ecs, inputs)); //scenes->activate("main_menu"); diff --git a/fggl/app.cpp b/fggl/app.cpp index a1b7b065cca9587768d91c101c90d9d7aa98499b..918c3d7814151f798eff232853e05f7f69fbc3ee 100644 --- a/fggl/app.cpp +++ b/fggl/app.cpp @@ -1,14 +1,22 @@ #include <cstdlib> +#include <memory> + #include <fggl/app.hpp> -#include <fggl/util/states.hpp> +#include <fggl/ecs3/types.hpp> +#include <fggl/ecs3/module/module.h> +#include <fggl/util/service.h> namespace fggl { App::App(const Identifer& name) : App::App( name, name ) { } - App::App(const Identifer& name, const Identifer& folder ) : m_running(true), m_states() { + App::App(const Identifer& name, const Identifer& folder ) : + m_running(true), + m_types(std::make_unique<ecs3::TypeRegistry>()), + m_modules(std::make_unique<ecs3::ModuleManager>(*m_types)), + m_states() { } int App::run(int argc, const char** argv) { diff --git a/include/fggl/app.hpp b/include/fggl/app.hpp index 04f2cc329ab4b606618dd3fe92e70d951cdc3529..964cfe597e9e9676fada4008e64c9108635b9491 100644 --- a/include/fggl/app.hpp +++ b/include/fggl/app.hpp @@ -27,6 +27,9 @@ #include <string> #include <memory> #include <unordered_map> + +#include <fggl/ecs3/types.hpp> +#include <fggl/ecs3/module/module.h> #include <fggl/util/states.hpp> namespace fggl { @@ -98,6 +101,12 @@ namespace fggl { m_states.put<T>(name, *this); } + template<typename T, typename... Args> + T& use(Args&& ...args) { + auto ptr = m_modules->load<T>(args...); + return *ptr; + } + inline void change_state(const Identifer& name) { m_states.active().deactivate(); m_states.change(name); @@ -118,6 +127,8 @@ namespace fggl { private: bool m_running; + std::unique_ptr<ecs3::TypeRegistry> m_types; + std::unique_ptr<ecs3::ModuleManager> m_modules; AppMachine m_states; }; diff --git a/include/fggl/gfx/windowing.hpp b/include/fggl/gfx/windowing.hpp new file mode 100644 index 0000000000000000000000000000000000000000..71d9f0e28b5c8cd9d738bed50c3249e3d4f5f814 --- /dev/null +++ b/include/fggl/gfx/windowing.hpp @@ -0,0 +1,34 @@ + +#ifndef FGGL_GFX_WINDOWING_H +#define FGGL_GFX_WINDOWING_H + +#include <memory> + +namespace fggl::gfx { + + class Graphics { + public: + virtual void clear(); + }; + + class Window { + public: + Window(); + + template<typename T> + void make_graphics() { + m_graphics = std::make_unique<T>(); + } + + private: + std::unique_ptr<Graphics> m_graphics; + }; + + class WindowService { + public: + Window& create(); + }; + +} // namespace fggl::gfx + +#endif