From 2eeaeafb40a6b04b811714c793fb97ce4de41254 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Jan 2021 14:14:01 +0000 Subject: Split into main app and library the rest for testing --- Jamroot.jam | 22 ++++++++---- application/inputHandler.h | 13 ------- application/main.cpp | 16 ++++----- application/manualCameraController.cpp | 65 ---------------------------------- application/manualCameraController.h | 25 ------------- gfx/inputHandler.h | 18 ++++++++++ gfx/manualCameraController.cpp | 65 ++++++++++++++++++++++++++++++++++ gfx/manualCameraController.h | 25 +++++++++++++ utility/special_members.hpp | 6 ++++ 9 files changed, 138 insertions(+), 117 deletions(-) delete mode 100644 application/inputHandler.h delete mode 100644 application/manualCameraController.cpp delete mode 100644 application/manualCameraController.h create mode 100644 gfx/inputHandler.h create mode 100644 gfx/manualCameraController.cpp create mode 100644 gfx/manualCameraController.h diff --git a/Jamroot.jam b/Jamroot.jam index 9b79df6..0c030aa 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -14,8 +14,8 @@ project : requirements debug:extra debug:on release:on - tidy:bin/gfx/gl/shaders/fs-basicShader.h - tidy:bin/gfx/gl/shaders/vs-basicShader.h + tidy:gfx/gl/shaders/fs-basicShader.h + tidy:gfx/gl/shaders/vs-basicShader.h tidy:boost-* tidy:bugprone-* tidy:clang-* @@ -45,14 +45,24 @@ actions xxd.i } IMPORT $(__name__) : xxd.i : : xxd.i ; -exe test : +exe iliketrains : + application/main.cpp + : + ilt + . + utility + lib + ; + +lib ilt : [ glob-tree *.cpp *.c *.vs *.fs : bin ] : + release:static . utility lib - sdl2 - glew - pthread + sdl2/shared + glew/shared + pthread/shared stb ; diff --git a/application/inputHandler.h b/application/inputHandler.h deleted file mode 100644 index bcb900b..0000000 --- a/application/inputHandler.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef INPUT_HANDLER_H -#define INPUT_HANDLER_H - -union SDL_Event; - -class InputHandler { -public: - virtual ~InputHandler() = default; - - virtual bool handleInput(SDL_Event &) = 0; -}; - -#endif diff --git a/application/main.cpp b/application/main.cpp index b2c2a5e..94a3b0f 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,16 +1,16 @@ -#include "game/terrain.h" -#include "gfx/window.h" -#include "inputHandler.h" -#include "manualCameraController.h" #include #include #include +#include #include #include #include #include #include +#include +#include #include +#include #include #include #include @@ -53,7 +53,7 @@ public: return false; } - void + int run() { Collection windows; @@ -92,6 +92,8 @@ public: } t_start = t_end; } + + return 0; } private: @@ -111,7 +113,5 @@ private: int main(int, char **) { - std::make_shared()->run(); - - return 0; + return std::make_shared()->run(); } diff --git a/application/manualCameraController.cpp b/application/manualCameraController.cpp deleted file mode 100644 index 36f3312..0000000 --- a/application/manualCameraController.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "manualCameraController.h" -#include -#include - -bool -ManualCameraController::handleInput(SDL_Event & e) -{ - switch (e.type) { - case SDL_KEYDOWN: - switch (e.key.keysym.sym) { - case SDLK_LCTRL: - case SDLK_RCTRL: - ctrl = true; - return true; - } - break; - case SDL_KEYUP: - switch (e.key.keysym.sym) { - case SDLK_LCTRL: - case SDLK_RCTRL: - ctrl = false; - return true; - } - break; - case SDL_MOUSEBUTTONDOWN: - switch (e.button.button) { - case SDL_BUTTON_RIGHT: - SDL_SetRelativeMouseMode(SDL_TRUE); - mrb = true; - return true; - } - break; - case SDL_MOUSEBUTTONUP: - switch (e.button.button) { - case SDL_BUTTON_RIGHT: - SDL_SetRelativeMouseMode(SDL_FALSE); - mrb = false; - return true; - } - break; - case SDL_MOUSEMOTION: - if (mrb) { - motion = e.motion; - } - return true; - } - return false; -} - -void -ManualCameraController::updateCamera(Camera * camera, Shader * shader) const -{ - if (motion) { - if (ctrl) { - camera->RotateY(-0.01F * motion->xrel); - camera->Pitch(-0.01F * motion->yrel); - } - else { - camera->MoveRight(motion->xrel); - camera->SlideForward(motion->yrel); - } - shader->setView(camera->GetViewProjection()); - motion.reset(); - } -} diff --git a/application/manualCameraController.h b/application/manualCameraController.h deleted file mode 100644 index 112ec5c..0000000 --- a/application/manualCameraController.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MANUAL_CAMERA_CONTROLLER_H -#define MANUAL_CAMERA_CONTROLLER_H - -#include "game/worldobject.h" -#include "inputHandler.h" -#include -#include -#include - -class Camera; -class Shader; - -class ManualCameraController : public CameraController, public InputHandler { -public: - bool handleInput(SDL_Event & e) override; - - void tick(TickDuration) override { } - - void updateCamera(Camera * camera, Shader * shader) const override; - -private: - bool ctrl {false}, mrb {false}; - mutable std::optional motion; -}; -#endif diff --git a/gfx/inputHandler.h b/gfx/inputHandler.h new file mode 100644 index 0000000..5b426c7 --- /dev/null +++ b/gfx/inputHandler.h @@ -0,0 +1,18 @@ +#ifndef INPUT_HANDLER_H +#define INPUT_HANDLER_H + +#include + +union SDL_Event; + +class InputHandler { +public: + InputHandler() = default; + virtual ~InputHandler() = default; + + DEFAULT_MOVE_COPY(InputHandler); + + virtual bool handleInput(SDL_Event &) = 0; +}; + +#endif diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp new file mode 100644 index 0000000..36f3312 --- /dev/null +++ b/gfx/manualCameraController.cpp @@ -0,0 +1,65 @@ +#include "manualCameraController.h" +#include +#include + +bool +ManualCameraController::handleInput(SDL_Event & e) +{ + switch (e.type) { + case SDL_KEYDOWN: + switch (e.key.keysym.sym) { + case SDLK_LCTRL: + case SDLK_RCTRL: + ctrl = true; + return true; + } + break; + case SDL_KEYUP: + switch (e.key.keysym.sym) { + case SDLK_LCTRL: + case SDLK_RCTRL: + ctrl = false; + return true; + } + break; + case SDL_MOUSEBUTTONDOWN: + switch (e.button.button) { + case SDL_BUTTON_RIGHT: + SDL_SetRelativeMouseMode(SDL_TRUE); + mrb = true; + return true; + } + break; + case SDL_MOUSEBUTTONUP: + switch (e.button.button) { + case SDL_BUTTON_RIGHT: + SDL_SetRelativeMouseMode(SDL_FALSE); + mrb = false; + return true; + } + break; + case SDL_MOUSEMOTION: + if (mrb) { + motion = e.motion; + } + return true; + } + return false; +} + +void +ManualCameraController::updateCamera(Camera * camera, Shader * shader) const +{ + if (motion) { + if (ctrl) { + camera->RotateY(-0.01F * motion->xrel); + camera->Pitch(-0.01F * motion->yrel); + } + else { + camera->MoveRight(motion->xrel); + camera->SlideForward(motion->yrel); + } + shader->setView(camera->GetViewProjection()); + motion.reset(); + } +} diff --git a/gfx/manualCameraController.h b/gfx/manualCameraController.h new file mode 100644 index 0000000..112ec5c --- /dev/null +++ b/gfx/manualCameraController.h @@ -0,0 +1,25 @@ +#ifndef MANUAL_CAMERA_CONTROLLER_H +#define MANUAL_CAMERA_CONTROLLER_H + +#include "game/worldobject.h" +#include "inputHandler.h" +#include +#include +#include + +class Camera; +class Shader; + +class ManualCameraController : public CameraController, public InputHandler { +public: + bool handleInput(SDL_Event & e) override; + + void tick(TickDuration) override { } + + void updateCamera(Camera * camera, Shader * shader) const override; + +private: + bool ctrl {false}, mrb {false}; + mutable std::optional motion; +}; +#endif diff --git a/utility/special_members.hpp b/utility/special_members.hpp index f396813..0d63f58 100644 --- a/utility/special_members.hpp +++ b/utility/special_members.hpp @@ -9,4 +9,10 @@ TYPE(TYPE &&) = delete; \ void operator=(TYPE &&) = delete +#define DEFAULT_MOVE_COPY(TYPE) \ + TYPE(const TYPE &) = default; \ + TYPE(TYPE &&) = default; \ + TYPE & operator=(const TYPE &) = default; \ + TYPE & operator=(TYPE &&) = default + #endif -- cgit v1.2.3