2022-09-03 23:36:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-01-20 16:30:35 +00:00
|
|
|
#include "resource_manager.hpp"
|
|
|
|
|
2023-02-19 13:55:08 +00:00
|
|
|
#include "gfx.hpp"
|
|
|
|
|
2022-11-29 14:22:03 +00:00
|
|
|
#include <memory>
|
2022-12-15 15:54:11 +00:00
|
|
|
#include <string>
|
|
|
|
#include <filesystem>
|
2023-01-20 16:30:35 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <assert.h>
|
2022-11-29 14:22:03 +00:00
|
|
|
|
2022-09-03 23:36:17 +00:00
|
|
|
namespace engine {
|
|
|
|
|
2022-11-30 00:46:03 +00:00
|
|
|
class Window; // "window.hpp"
|
|
|
|
class GFXDevice; // "gfx_device.hpp"
|
|
|
|
class InputManager; // "input_manager.hpp"
|
|
|
|
class SceneManager; // "scene_manager.hpp"
|
2023-01-20 20:59:35 +00:00
|
|
|
|
|
|
|
namespace resources {
|
|
|
|
class Shader;
|
|
|
|
class Texture;
|
|
|
|
}
|
2022-10-04 10:54:23 +00:00
|
|
|
|
|
|
|
class Application {
|
2022-11-29 14:22:03 +00:00
|
|
|
|
2022-10-04 10:54:23 +00:00
|
|
|
public:
|
2023-02-19 13:55:08 +00:00
|
|
|
Application(const char* appName, const char* appVersion, gfx::GraphicsSettings graphicsSettings);
|
2022-11-29 14:22:03 +00:00
|
|
|
~Application();
|
2022-10-04 10:54:23 +00:00
|
|
|
Application(const Application&) = delete;
|
|
|
|
Application& operator=(const Application&) = delete;
|
2022-09-03 23:36:17 +00:00
|
|
|
|
2023-01-20 16:30:35 +00:00
|
|
|
/* resource stuff */
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
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<ResourceManager<T>>());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::shared_ptr<T> addResource(const std::string& name, std::unique_ptr<T>&& resource)
|
|
|
|
{
|
|
|
|
auto resourceManager = getResourceManager<T>();
|
|
|
|
return resourceManager->add(name, std::move(resource));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::shared_ptr<T> getResource(const std::string& name)
|
|
|
|
{
|
|
|
|
auto resourceManager = getResourceManager<T>();
|
|
|
|
return resourceManager->get(name);
|
|
|
|
}
|
|
|
|
|
2022-11-29 14:22:03 +00:00
|
|
|
/* methods */
|
2022-10-04 10:54:23 +00:00
|
|
|
void gameLoop();
|
|
|
|
|
2022-12-20 23:51:04 +00:00
|
|
|
void setFrameLimiter(bool on) { m_enableFrameLimiter = on; }
|
|
|
|
|
2022-11-29 14:22:03 +00:00
|
|
|
/* getters */
|
|
|
|
Window* window() { return m_window.get(); }
|
|
|
|
GFXDevice* gfx() { return m_gfx.get(); }
|
|
|
|
InputManager* inputManager() { return m_inputManager.get(); }
|
|
|
|
SceneManager* sceneManager() { return m_sceneManager.get(); }
|
2022-10-31 16:21:07 +00:00
|
|
|
|
2022-12-15 15:54:11 +00:00
|
|
|
std::string getResourcePath(const std::string relativePath) { return (m_resourcesPath / relativePath).string(); }
|
|
|
|
|
2022-10-04 10:54:23 +00:00
|
|
|
private:
|
2022-11-29 14:22:03 +00:00
|
|
|
std::unique_ptr<Window> m_window;
|
|
|
|
std::unique_ptr<GFXDevice> m_gfx;
|
|
|
|
std::unique_ptr<InputManager> m_inputManager;
|
|
|
|
std::unique_ptr<SceneManager> m_sceneManager;
|
2022-11-23 15:40:10 +00:00
|
|
|
|
2022-12-15 15:54:11 +00:00
|
|
|
std::filesystem::path m_resourcesPath;
|
|
|
|
|
2022-12-20 23:51:04 +00:00
|
|
|
bool m_enableFrameLimiter = true;
|
|
|
|
|
2023-01-20 16:30:35 +00:00
|
|
|
/* resource stuff */
|
|
|
|
|
|
|
|
std::unordered_map<size_t, std::unique_ptr<IResourceManager>> m_resourceManagers{};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
ResourceManager<T>* 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<ResourceManager<T>*>(ptr);
|
|
|
|
assert(castedPtr != nullptr);
|
|
|
|
return castedPtr;
|
|
|
|
}
|
|
|
|
|
2022-10-04 10:54:23 +00:00
|
|
|
};
|
2022-09-03 23:36:17 +00:00
|
|
|
|
2022-12-15 15:54:11 +00:00
|
|
|
}
|