From: Daniel Karbach Date: Tue, 4 Aug 2015 16:12:04 +0000 (+0200) Subject: move init out of Application class X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=bfa8d0303d57e62fb73dad96d1b521760d475cf8;p=blank.git move init out of Application class --- diff --git a/src/app/Application.hpp b/src/app/Application.hpp index 636b82e..5909e3b 100644 --- a/src/app/Application.hpp +++ b/src/app/Application.hpp @@ -3,7 +3,6 @@ #include "Assets.hpp" #include "FrameCounter.hpp" -#include "init.hpp" #include "RandomWalk.hpp" #include "../audio/Audio.hpp" #include "../graphics/Viewport.hpp" @@ -15,6 +14,8 @@ namespace blank { +class Window; + class Application { public: @@ -27,7 +28,7 @@ public: World::Config world = World::Config(); }; - explicit Application(const Config &); + Application(Window &, const Config &); ~Application(); Application(const Application &) = delete; @@ -56,7 +57,7 @@ public: static Entity &MakeTestEntity(World &); private: - Init init; + Window &window; Viewport viewport; Assets assets; Audio audio; diff --git a/src/app/Runtime.cpp b/src/app/Runtime.cpp index e5f74b4..6a4c783 100644 --- a/src/app/Runtime.cpp +++ b/src/app/Runtime.cpp @@ -1,5 +1,7 @@ #include "Runtime.hpp" +#include "init.hpp" + #include #include #include @@ -141,7 +143,8 @@ int Runtime::Execute() { return 1; } - Application app(config); + Init init(config.doublebuf, config.multisampling); + Application app(init.window, config); switch (mode) { default: case NORMAL: diff --git a/src/app/app.cpp b/src/app/app.cpp index 59070a5..3111091 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -2,6 +2,7 @@ #include "Assets.hpp" #include "FrameCounter.hpp" +#include "init.hpp" #include "../audio/Sound.hpp" #include "../graphics/Font.hpp" #include "../world/BlockType.hpp" @@ -27,8 +28,8 @@ string get_asset_path() { namespace blank { -Application::Application(const Config &config) -: init(config.doublebuf, config.multisampling) +Application::Application(Window &win, const Config &config) +: window(win) , viewport() , assets(get_asset_path()) , audio() @@ -87,7 +88,7 @@ void Application::RunS(size_t n, size_t t) { void Application::Run() { running = true; Uint32 last = SDL_GetTicks(); - init.window.GrabMouse(); + window.GrabMouse(); while (running) { Uint32 now = SDL_GetTicks(); int delta = now - last; @@ -144,10 +145,10 @@ void Application::HandleEvents() { void Application::Handle(const SDL_WindowEvent &event) { switch (event.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: - init.window.GrabMouse(); + window.GrabMouse(); break; case SDL_WINDOWEVENT_FOCUS_LOST: - init.window.ReleaseMouse(); + window.ReleaseMouse(); break; case SDL_WINDOWEVENT_RESIZED: viewport.Resize(event.data1, event.data2); @@ -183,7 +184,7 @@ void Application::Render() { interface.Render(viewport); counter.ExitRender(); - init.window.Flip(); + window.Flip(); }