113 lines
3.2 KiB
C++
113 lines
3.2 KiB
C++
#ifndef APP_H
|
|
#define APP_H
|
|
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include <glm/vec2.hpp>
|
|
|
|
#include <destrum/AppLayer.h>
|
|
#include <destrum/Window.h>
|
|
#include <destrum/Graphics/Camera.h>
|
|
#include <destrum/Graphics/GfxDevice.h>
|
|
#include <destrum/Graphics/Renderer.h>
|
|
#include <destrum/Graphics/RenderResources.h>
|
|
#include <destrum/Graphics/Pipelines/ImguiPass.h>
|
|
#include <destrum/Input/InputManager.h>
|
|
|
|
class App {
|
|
public:
|
|
struct AppParams {
|
|
glm::ivec2 windowSize{};
|
|
glm::ivec2 renderSize{};
|
|
std::string appName{"Destrum App"};
|
|
std::string windowTitle;
|
|
std::filesystem::path exeDir;
|
|
WindowMode windowMode{WindowMode::Windowed};
|
|
bool startMaximized{false};
|
|
};
|
|
|
|
struct SimulationControls {
|
|
bool paused{false};
|
|
bool stepOnce{false};
|
|
float timeScale{1.0f};
|
|
int stepsLastFrame{0};
|
|
float accumulator{0.0f};
|
|
float fixedDeltaTime{0.0f};
|
|
};
|
|
|
|
App();
|
|
virtual ~App();
|
|
|
|
App(const App&) = delete;
|
|
App& operator=(const App&) = delete;
|
|
|
|
void init(const AppParams& params);
|
|
void attachLayer(std::unique_ptr<AppLayer> layer);
|
|
void run();
|
|
void cleanup();
|
|
|
|
virtual void customInit() = 0;
|
|
virtual void customUpdate(float) {}
|
|
virtual void customFixedUpdate(float) {}
|
|
virtual void customRender(GameRenderer&) {}
|
|
virtual void customCleanup() {}
|
|
virtual void customWindowsMenu() {}
|
|
virtual void onWindowResize(int, int) {}
|
|
virtual void onPlayModeChanged(bool) {}
|
|
[[nodiscard]] virtual Camera* gameCamera() { return nullptr; }
|
|
|
|
[[nodiscard]] bool isPlaying() const;
|
|
[[nodiscard]] bool isPaused() const;
|
|
|
|
[[nodiscard]] Window& getWindow() { return window; }
|
|
[[nodiscard]] GfxDevice& getGfxDevice() { return gfxDevice; }
|
|
[[nodiscard]] GameRenderer& getRenderer() { return renderer; }
|
|
[[nodiscard]] RenderResources& getResources() { return resources; }
|
|
[[nodiscard]] ImguiPass& getImguiPass() { return imguiPass; }
|
|
[[nodiscard]] const AppParams& getParams() const { return m_params; }
|
|
[[nodiscard]] SimulationControls& getSimulation() { return simulation; }
|
|
[[nodiscard]] float getAverageFps() const { return avgFPS; }
|
|
[[nodiscard]] float getRenderAspectRatio() const;
|
|
|
|
[[nodiscard]] Camera& getViewCamera();
|
|
void resizeRenderTarget(const glm::ivec2& size);
|
|
void collectUnusedResources();
|
|
void requestQuit() { isRunning = false; }
|
|
|
|
protected:
|
|
Window window;
|
|
AppParams m_params{};
|
|
|
|
GfxDevice gfxDevice;
|
|
GameRenderer renderer;
|
|
RenderResources resources;
|
|
ImguiPass imguiPass;
|
|
|
|
bool cleanedUp{false};
|
|
|
|
private:
|
|
void initDevices();
|
|
void processEvents();
|
|
void runFixedSteps();
|
|
void handleSwapchainResize(bool& skipFrame);
|
|
void renderFrame();
|
|
|
|
std::unique_ptr<AppLayer> layer;
|
|
Camera fallbackCamera{glm::vec3{0.0f, 2.0f, -5.0f}, glm::vec3{0.0f, 1.0f, 0.0f}};
|
|
SimulationControls simulation{};
|
|
|
|
bool isRunning{false};
|
|
bool cleaningUp{false};
|
|
bool customInitStarted{false};
|
|
bool frameLimit{false};
|
|
float avgFPS{0.0f};
|
|
|
|
bool resizePending{false};
|
|
std::chrono::steady_clock::time_point lastResizeTime{};
|
|
};
|
|
|
|
#endif // APP_H
|