aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/DB.cpp2
-rw-r--r--src/crepe/facade/SDLContext.cpp55
-rw-r--r--src/crepe/facade/SDLContext.h4
-rw-r--r--src/crepe/facade/Sound.cpp2
-rw-r--r--src/crepe/facade/SoundContext.cpp2
-rw-r--r--src/crepe/facade/Texture.cpp2
6 files changed, 35 insertions, 32 deletions
diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp
index 95cf606..d45cd82 100644
--- a/src/crepe/facade/DB.cpp
+++ b/src/crepe/facade/DB.cpp
@@ -1,6 +1,6 @@
#include <cstring>
-#include "util/Log.h"
+#include "util/dbg.h"
#include "DB.h"
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 7e19ede..d6e3159 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -19,7 +19,7 @@
#include "../api/Color.h"
#include "../api/Config.h"
#include "../api/Sprite.h"
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "manager/Mediator.h"
#include "SDLContext.h"
@@ -35,10 +35,10 @@ SDLContext::SDLContext(Mediator & mediator) {
throw runtime_error(format("SDLContext: SDL_Init error: {}", SDL_GetError()));
}
- auto & cfg = Config::get_instance().window_settings;
+ auto & cfg = Config::get_instance().window;
SDL_Window * tmp_window
- = SDL_CreateWindow(cfg.window_title.c_str(), SDL_WINDOWPOS_CENTERED,
- SDL_WINDOWPOS_CENTERED, cfg.default_size.x, cfg.default_size.y, 0);
+ = SDL_CreateWindow(cfg.title.c_str(), SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED, cfg.size.x, cfg.size.y, 0);
if (!tmp_window) {
throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError()));
}
@@ -76,12 +76,10 @@ SDLContext::~SDLContext() {
}
Keycode SDLContext::sdl_to_keycode(SDL_Scancode sdl_key) {
- auto it = LOOKUP_TABLE.find(sdl_key);
- if (it != LOOKUP_TABLE.end()) {
- return it->second;
- }
+ if (!LOOKUP_TABLE.contains(sdl_key))
+ return Keycode::NONE;
- return Keycode::NONE;
+ return LOOKUP_TABLE.at(sdl_key);
}
void SDLContext::update_keyboard_state() {
// Array to hold the key states (true if pressed, false if not)
@@ -90,10 +88,8 @@ void SDLContext::update_keyboard_state() {
for (int i = 0; i < SDL_NUM_SCANCODES; ++i) {
Keycode key = sdl_to_keycode(static_cast<SDL_Scancode>(i));
-
- if (key != Keycode::NONE) {
- this->keyboard_state[key] = current_state[i] != 0;
- }
+ if (key == Keycode::NONE) continue;
+ this->keyboard_state[key] = current_state[i] != 0;
}
}
@@ -187,13 +183,13 @@ void SDLContext::draw(const RenderContext & ctx) {
}
void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) {
-
const Camera::Data & cam_data = cam.data;
+ const Config & config = Config::get_instance();
// resize window
int w, h;
SDL_GetWindowSize(this->game_window.get(), &w, &h);
- if (w != cam.screen.x || h != cam.screen.y) {
- SDL_SetWindowSize(this->game_window.get(), cam.screen.x, cam.screen.y);
+ if (w != config.window.size.x || h != config.window.size.y) {
+ SDL_SetWindowSize(this->game_window.get(), config.window.size.x, config.window.size.y);
}
vec2 & zoomed_viewport = this->cam_aux_data.zoomed_viewport;
@@ -202,28 +198,28 @@ void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) {
this->cam_aux_data.cam_pos = new_pos;
zoomed_viewport = cam.viewport_size * cam_data.zoom;
- float screen_aspect = static_cast<float>(cam.screen.x) / cam.screen.y;
+ float screen_aspect = static_cast<float>(config.window.size.x) / config.window.size.y;
float viewport_aspect = zoomed_viewport.x / zoomed_viewport.y;
// calculate black bars
if (screen_aspect > viewport_aspect) {
// pillarboxing
- float scale = cam.screen.y / zoomed_viewport.y;
+ float scale = config.window.size.y / zoomed_viewport.y;
float adj_width = zoomed_viewport.x * scale;
- float bar_width = (cam.screen.x - adj_width) / 2;
- this->black_bars[0] = {0, 0, bar_width, (float) cam.screen.y};
- this->black_bars[1] = {(cam.screen.x - bar_width), 0, bar_width, (float) cam.screen.y};
+ float bar_width = (config.window.size.x - adj_width) / 2;
+ this->black_bars[0] = {0, 0, bar_width, (float) config.window.size.y};
+ this->black_bars[1] = {(config.window.size.x - bar_width), 0, bar_width, (float) config.window.size.y};
bar_size = {bar_width, 0};
render_scale.x = render_scale.y = scale;
} else {
// letterboxing
- float scale = cam.screen.x / (cam.viewport_size.x * cam_data.zoom);
+ float scale = config.window.size.x / (cam.viewport_size.x * cam_data.zoom);
float adj_height = cam.viewport_size.y * scale;
- float bar_height = (cam.screen.y - adj_height) / 2;
- this->black_bars[0] = {0, 0, (float) cam.screen.x, bar_height};
+ float bar_height = (config.window.size.y - adj_height) / 2;
+ this->black_bars[0] = {0, 0, (float) config.window.size.x, bar_height};
this->black_bars[1]
- = {0, (cam.screen.y - bar_height), (float) cam.screen.x, bar_height};
+ = {0, (config.window.size.y - bar_height), (float) config.window.size.x, bar_height};
bar_size = {0, bar_height};
render_scale.x = render_scale.y = scale;
@@ -235,8 +231,8 @@ void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) {
SDL_Rect bg = {
.x = 0,
.y = 0,
- .w = cam.screen.x,
- .h = cam.screen.y,
+ .w = config.window.size.x,
+ .h = config.window.size.y,
};
// fill bg color
@@ -402,3 +398,8 @@ void SDLContext::set_color_texture(const Texture & texture, const Color & color)
SDL_SetTextureColorMod(texture.get_img(), color.r, color.g, color.b);
SDL_SetTextureAlphaMod(texture.get_img(), color.a);
}
+
+const keyboard_state_t & SDLContext::get_keyboard_state() const {
+ return this->keyboard_state;
+}
+
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 7ccefeb..176982f 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -270,6 +270,8 @@ public:
*/
void set_color_texture(const Texture & texture, const Color & color);
+ const keyboard_state_t & get_keyboard_state() const;
+
private:
//! sdl Window
std::unique_ptr<SDL_Window, std::function<void(SDL_Window *)>> game_window;
@@ -288,7 +290,7 @@ private:
CameraAuxiliaryData cam_aux_data;
private:
- std::unordered_map<Keycode, bool> keyboard_state;
+ keyboard_state_t keyboard_state;
const std::unordered_map<SDL_Scancode, Keycode> LOOKUP_TABLE
= {{SDL_SCANCODE_SPACE, Keycode::SPACE},
{SDL_SCANCODE_APOSTROPHE, Keycode::APOSTROPHE},
diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp
index 97e455e..b1e6463 100644
--- a/src/crepe/facade/Sound.cpp
+++ b/src/crepe/facade/Sound.cpp
@@ -1,5 +1,5 @@
#include "../api/Asset.h"
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "Sound.h"
diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp
index b1f8cb3..5091e07 100644
--- a/src/crepe/facade/SoundContext.cpp
+++ b/src/crepe/facade/SoundContext.cpp
@@ -1,4 +1,4 @@
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "SoundContext.h"
diff --git a/src/crepe/facade/Texture.cpp b/src/crepe/facade/Texture.cpp
index b63403d..23a9c8e 100644
--- a/src/crepe/facade/Texture.cpp
+++ b/src/crepe/facade/Texture.cpp
@@ -1,4 +1,4 @@
-#include "../util/Log.h"
+#include "../util/dbg.h"
#include "facade/SDLContext.h"
#include "manager/Mediator.h"