X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FApplication.hpp;h=359599ef73750de04c0ee3de16c489690114a005;hb=7354c74fb8f409336db3a6d70455fbc10232ae64;hp=c8236ffbf27a72281364c87a69454103845a358a;hpb=b7d09e1e35ef90282c97509e0020b20db3c7ea9f;p=blank.git diff --git a/src/app/Application.hpp b/src/app/Application.hpp index c8236ff..359599e 100644 --- a/src/app/Application.hpp +++ b/src/app/Application.hpp @@ -1,37 +1,34 @@ #ifndef BLANK_APP_APPLICATION_HPP_ #define BLANK_APP_APPLICATION_HPP_ -#include "init.hpp" -#include "RandomWalk.hpp" -#include "../graphics/BlockLighting.hpp" -#include "../graphics/Camera.hpp" -#include "../graphics/DirectionalLighting.hpp" -#include "../ui/Interface.hpp" -#include "../world/World.hpp" +#include +#include namespace blank { -class Application { +class Environment; +class HeadlessEnvironment; +class State; +class Window; -public: - struct Config { - bool vsync = true; - bool doublebuf = true; - int multisampling = 1; - - Interface::Config interface = Interface::Config(); - World::Config world = World::Config(); - }; +class HeadlessApplication { - explicit Application(const Config &); +public: + explicit HeadlessApplication(HeadlessEnvironment &); + ~HeadlessApplication(); - Application(const Application &) = delete; - Application &operator =(const Application &) = delete; + void PushState(State *); + State *PopState(); + State *SwitchState(State *); + State &GetState(); + void CommitStates(); + bool HasState() const noexcept; - /// run until user quits + /// run until out of states void Run(); - void Loop(int dt); + /// evaluate a single frame of dt milliseconds + virtual void Loop(int dt); /// run for n frames void RunN(size_t n); @@ -40,29 +37,42 @@ public: /// run for n frames, assuming t milliseconds for each void RunS(size_t n, size_t t); + /// process all events in SDL's queue void HandleEvents(); + void Handle(const SDL_Event &); + /// integrate to the next step with dt milliseconds passed void Update(int dt); - void Render(); - static Entity &MakeTestEntity(World &); +private: + HeadlessEnvironment &env; + std::stack states; + +}; + + +class Application +: public HeadlessApplication { + +public: + explicit Application(Environment &); + ~Application(); + + Application(const Application &) = delete; + Application &operator =(const Application &) = delete; + + void Loop(int dt) override; + + /// process all events in SDL's queue + void HandleEvents(); + void Handle(const SDL_Event &); + void Handle(const SDL_WindowEvent &); + /// integrate to the next step with dt milliseconds passed + void Update(int dt); + /// push the current state to display + void Render(); private: - InitSDL init_sdl; - InitIMG init_img; - InitGL init_gl; - Window window; - GLContext ctx; - InitGLEW init_glew; - BlockLighting chunk_prog; - DirectionalLighting entity_prog; - - Camera cam; - World world; - Interface interface; - - RandomWalk test_controller; - - bool running; + Environment &env; };