#pragma once #include "resource_manager.hpp" #include "gfx.hpp" #include "gfx_device.hpp" #include #include #include #include #include #include namespace engine { class Window; // "window.hpp" class GFXDevice; // "gfx_device.hpp" class InputManager; // "input_manager.hpp" class SceneManager; // "scene_manager.hpp" namespace resources { class Shader; class Texture; } struct RenderData { std::unique_ptr gfxdev; gfx::DrawBuffer* drawBuffer = nullptr; /* uniforms for engine globals */ const gfx::DescriptorSetLayout* setZeroLayout; const gfx::DescriptorSet* setZero; struct SetZeroBuffer { glm::mat4 proj; }; const gfx::Image* myImage = nullptr; const gfx::Sampler* mySampler = nullptr; gfx::UniformBuffer* setZeroBuffer; /* uniforms for per-frame data */ const gfx::DescriptorSetLayout* setOneLayout; const gfx::DescriptorSet* setOne; struct SetOneBuffer { glm::mat4 view; }; gfx::UniformBuffer* setOneBuffer; }; class Application { public: Application(const char* appName, const char* appVersion, gfx::GraphicsSettings graphicsSettings); ~Application(); Application(const Application&) = delete; Application& operator=(const Application&) = delete; /* resource stuff */ template void registerResourceManager() { size_t hash = typeid(T).hash_code(); assert(m_resourceManagers.contains(hash) == false && "Registering resource manager type more than once."); m_resourceManagers.emplace(hash, std::make_unique>()); } template std::shared_ptr addResource(const std::string& name, std::unique_ptr&& resource) { auto resourceManager = getResourceManager(); return resourceManager->add(name, std::move(resource)); } template std::shared_ptr getResource(const std::string& name) { auto resourceManager = getResourceManager(); return resourceManager->get(name); } /* methods */ void gameLoop(); void setFrameLimiter(bool on) { m_enableFrameLimiter = on; } /* getters */ Window* window() { return m_window.get(); } GFXDevice* gfx() { return renderData.gfxdev.get(); } InputManager* inputManager() { return m_inputManager.get(); } SceneManager* sceneManager() { return m_sceneManager.get(); } std::string getResourcePath(const std::string relativePath) { return (m_resourcesPath / relativePath).string(); } RenderData renderData{}; private: std::unique_ptr m_window; std::unique_ptr m_inputManager; std::unique_ptr m_sceneManager; std::filesystem::path m_resourcesPath; bool m_enableFrameLimiter = true; /* resource stuff */ std::unordered_map> m_resourceManagers{}; template ResourceManager* getResourceManager() { size_t hash = typeid(T).hash_code(); auto it = m_resourceManagers.find(hash); if (it == m_resourceManagers.end()) { throw std::runtime_error("Cannot find resource manager."); } auto ptr = it->second.get(); auto castedPtr = dynamic_cast*>(ptr); assert(castedPtr != nullptr); return castedPtr; } }; }