From 1623663c6e2e8f33f84b37b9f6bd968c8bc6c92d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 14 Dec 2024 12:00:54 +0100 Subject: WIP demo --- src/crepe/api/Camera.cpp | 4 +--- src/crepe/api/Camera.h | 9 ++------- src/crepe/facade/SDLContext.cpp | 28 ++++++++++++++-------------- 3 files changed, 17 insertions(+), 24 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index 19a3296..9befc3f 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -6,10 +6,8 @@ using namespace crepe; -Camera::Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, - const Data & data) +Camera::Camera(game_object_id_t id, const vec2 & viewport_size, const Data & data) : Component(id), - screen(screen), viewport_size(viewport_size), data(data) { dbg_trace(); diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 54d9a73..48f2ff2 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -30,7 +30,7 @@ public: * zoom < 1 --> zoom out * zoom > 1 --> zoom in */ - double zoom = 1; + float zoom = 1.0; //! offset postion from the game object transform component vec2 postion_offset; @@ -40,20 +40,15 @@ public: /** * \brief Constructs a Camera with the specified ID and background color. * \param id Unique identifier for the camera component. - * \param screen is the actual screen size in pixels * \param viewport_size is the view of the world in game units * \param data the camera component data */ - Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, - const Camera::Data & data); + Camera(game_object_id_t id, const vec2 & viewport_size, const Data & data); ~Camera(); // dbg_trace only public: Camera::Data data; - //! screen the display size in pixels ( output resolution ) - const ivec2 screen; - //! viewport is the area of the world visible through the camera (in world units) const vec2 viewport_size; diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index fccc15f..18f40f9 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -279,13 +279,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_settings.default_size.x || h != config.window_settings.default_size.y) { + SDL_SetWindowSize(this->game_window.get(), config.window_settings.default_size.x, config.window_settings.default_size.y); } vec2 & zoomed_viewport = this->cam_aux_data.zoomed_viewport; @@ -294,28 +294,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(cam.screen.x) / cam.screen.y; + float screen_aspect = static_cast(config.window_settings.default_size.x) / config.window_settings.default_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_settings.default_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_settings.default_size.x - adj_width) / 2; + this->black_bars[0] = {0, 0, bar_width, (float) config.window_settings.default_size.y}; + this->black_bars[1] = {(config.window_settings.default_size.x - bar_width), 0, bar_width, (float) config.window_settings.default_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_settings.default_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_settings.default_size.y - adj_height) / 2; + this->black_bars[0] = {0, 0, (float) config.window_settings.default_size.x, bar_height}; this->black_bars[1] - = {0, (cam.screen.y - bar_height), (float) cam.screen.x, bar_height}; + = {0, (config.window_settings.default_size.y - bar_height), (float) config.window_settings.default_size.x, bar_height}; bar_size = {0, bar_height}; render_scale.x = render_scale.y = scale; @@ -327,8 +327,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_settings.default_size.x, + .h = config.window_settings.default_size.y, }; // fill bg color -- cgit v1.2.3