diff options
Diffstat (limited to 'main')
| -rw-r--r-- | main/app.cpp | 33 | ||||
| -rw-r--r-- | main/app.hpp | 2 | ||||
| -rw-r--r-- | main/keyboard.cpp | 43 | ||||
| -rw-r--r-- | main/main.cpp | 65 |
4 files changed, 78 insertions, 65 deletions
diff --git a/main/app.cpp b/main/app.cpp new file mode 100644 index 00000000..66857860 --- /dev/null +++ b/main/app.cpp @@ -0,0 +1,33 @@ +#include "app.hpp" + +namespace Magnum::Examples { + +app::app(const Arguments& arguments): + Platform::Application{ + arguments, + Configuration{} + .setTitle("Test") + .setSize({1024, 768}, dpi_policy::Physical), + GLConfiguration{} + .setSampleCount(4) + .setFlags(GLConfiguration::Flag::GpuValidation) + } +{ + reset_camera_offset(); + timeline.start(); +} + +void app::update_window_scale() +{ + auto sz = windowSize(); + _shader.set_scale({ (float)sz[0], (float)sz[1] }); +} + +void app::update(float dt) +{ + do_camera(dt); + if (keys[key::quit]) + Platform::Sdl2Application::exit(0); +} + +} // namespace Magnum::Examples diff --git a/main/app.hpp b/main/app.hpp index 4cea0a32..06ad882e 100644 --- a/main/app.hpp +++ b/main/app.hpp @@ -5,6 +5,7 @@ #include "src/loader.hpp" #include "floor-mesh.hpp" #include "wall-mesh.hpp" +#include "wireframe-mesh.hpp" #include "compat/enum-bitset.hpp" #include <Magnum/Timeline.h> #include <Magnum/Platform/Sdl2Application.h> @@ -44,6 +45,7 @@ struct app final : Platform::Application chunk _chunk = make_test_chunk(); floor_mesh _floor_mesh; wall_mesh _wall_mesh; + wireframe_quad_mesh _wireframe_quad; Vector2 camera_offset; enum_bitset<key> keys; diff --git a/main/keyboard.cpp b/main/keyboard.cpp new file mode 100644 index 00000000..14daa19c --- /dev/null +++ b/main/keyboard.cpp @@ -0,0 +1,43 @@ +#include "app.hpp" +namespace Magnum::Examples { + +void app::do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated) +{ + //using Mods = KeyEvent::Modifiers; + + (void)m; + (void)repeated; + + const key x = progn(switch (k) { + using enum KeyEvent::Key; + using enum key; + + case W: return camera_up; + case A: return camera_left; + case S: return camera_down; + case D: return camera_right; + case Home: return camera_reset; + case Esc: return quit; + default: return MAX; + }); + + if (x != key::MAX) + keys[x] = pressed; +} + +app::~app() +{ + loader_::destroy(); +} + +void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event) +{ + do_key(event.key(), event.modifiers(), true, event.isRepeated()); +} + +void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event) +{ + do_key(event.key(), event.modifiers(), false, false); +} + +} // namespace Magnum::Examples diff --git a/main/main.cpp b/main/main.cpp index 5a555c97..34a7ae4a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -5,21 +5,6 @@ namespace Magnum::Examples { -app::app(const Arguments& arguments): - Platform::Application{ - arguments, - Configuration{} - .setTitle("Test") - .setSize({1024, 768}, dpi_policy::Physical), - GLConfiguration{} - .setSampleCount(4) - .setFlags(GLConfiguration::Flag::GpuValidation) - } -{ - reset_camera_offset(); - timeline.start(); -} - chunk app::make_test_chunk() { constexpr auto N = TILE_MAX_DIM; @@ -60,12 +45,6 @@ void app::drawEvent() { timeline.nextFrame(); } -void app::update_window_scale() -{ - auto sz = windowSize(); - _shader.set_scale({ (float)sz[0], (float)sz[1] }); -} - void app::draw_chunk(chunk& c) { _floor_mesh.draw(_shader, c); @@ -96,51 +75,7 @@ void app::reset_camera_offset() //camera_offset = {}; } -void app::update(float dt) -{ - do_camera(dt); - if (keys[key::quit]) - Platform::Sdl2Application::exit(0); -} -void app::do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated) -{ - //using Mods = KeyEvent::Modifiers; - - (void)m; - (void)repeated; - - const key x = progn(switch (k) { - using enum KeyEvent::Key; - using enum key; - - case W: return camera_up; - case A: return camera_left; - case S: return camera_down; - case D: return camera_right; - case Home: return camera_reset; - case Esc: return quit; - default: return MAX; - }); - - if (x != key::MAX) - keys[x] = pressed; -} - -app::~app() -{ - loader_::destroy(); -} - -void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event) -{ - do_key(event.key(), event.modifiers(), true, event.isRepeated()); -} - -void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event) -{ - do_key(event.key(), event.modifiers(), false, false); -} } // namespace Magnum::Examples |
