aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/Camera.h11
-rw-r--r--src/crepe/api/Config.h9
-rw-r--r--src/crepe/facade/SDLContext.cpp12
-rw-r--r--src/crepe/facade/SDLContext.h4
-rw-r--r--src/example/rendering_particle.cpp1
5 files changed, 22 insertions, 15 deletions
diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h
index eea1b28..ec94c44 100644
--- a/src/crepe/api/Camera.h
+++ b/src/crepe/api/Camera.h
@@ -3,6 +3,7 @@
#include "Color.h"
#include "Component.h"
+#include "api/Config.h"
#include "types.h"
namespace crepe {
@@ -30,19 +31,17 @@ public:
Color bg_color;
//! pos The position of the camera in world units
- vec2 pos = {0, 0};
+ vec2 pos = Config::get_instance().win_set.pos;
//! screen the display size in pixels ( output resolution )
- //vec2 screen = {720, 480};
- vec2 screen = {1080, 720};
+ vec2 screen = Config::get_instance().win_set.def_size;
//! viewport is the area of the world visible through the camera (in world units)
- //vec2 viewport = {720, 480};
- vec2 viewport = {2000, 1000};
+ vec2 viewport = Config::get_instance().win_set.def_size;
//! scale scaling factor from world units to pixel coordinates
//! Zoom level of the camera view.
- double zoom = 1.0f;
+ double zoom = Config::get_instance().win_set.zoom;
public:
/**
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 671fd02..e1aef7d 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -1,6 +1,7 @@
#pragma once
#include "../util/Log.h"
+#include "types.h"
namespace crepe {
@@ -62,6 +63,14 @@ public:
double gravity = 1;
} physics;
+ //! default window settings
+ struct {
+ //TODO make this constexpr because this will never change
+ vec2 def_size = {1080,720};
+ vec2 pos = {0,0};
+ float zoom = 1.0f;
+ } win_set;
+
//! Asset loading options
struct {
/**
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index fc59d84..8b29f8a 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -30,14 +30,13 @@ SDLContext & SDLContext::get_instance() {
SDLContext::SDLContext() {
dbg_trace();
- // FIXME: read window defaults from config manager
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
throw runtime_error(format("SDLContext: SDL_Init error: {}", SDL_GetError()));
}
SDL_Window * tmp_window
= SDL_CreateWindow("Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
- this->viewport.w, this->viewport.h, 0);
+ this->window.x, this->window.y, 0);
if (!tmp_window) {
throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError()));
}
@@ -123,8 +122,8 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos,
pixel_width *= img_scale;
pixel_height *= img_scale;
- int pixel_x = static_cast<int>((pos.x - cam_pos.x + this->viewport.w / 2 - pixel_width / 2));
- int pixel_y = static_cast<int>((pos.y - cam_pos.y + this->viewport.h / 2 - pixel_height / 2));
+ int pixel_x = static_cast<int>((pos.x - cam_pos.x + this->window.x / 2 - pixel_width / 2));
+ int pixel_y = static_cast<int>((pos.y - cam_pos.y + this->window.y / 2 - pixel_height / 2));
return SDL_Rect{
.x = pixel_x,
@@ -167,10 +166,9 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform,
void SDLContext::set_camera(const Camera & cam, vec2 & scale) {
// resize window
- if (this->viewport.w != (int) cam.screen.x || this->viewport.h != (int) cam.screen.y) {
+ if ((int)this->window.x != (int) cam.screen.x || (int)this->window.y != (int) cam.screen.y) {
SDL_SetWindowSize(this->game_window.get(), (int) cam.screen.x, (int) cam.screen.y);
- this->viewport.h = (int)cam.screen.y;
- this->viewport.w = (int)cam.screen.x;
+ this->window = cam.screen;
}
double screen_aspect = cam.screen.x / cam.screen.y;
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index c9f3299..f72eecb 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -13,6 +13,7 @@
#include "../api/Transform.h"
#include "api/Camera.h"
+#include "api/Config.h"
#include "types.h"
namespace crepe {
@@ -179,8 +180,7 @@ private:
std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> game_renderer;
//! viewport for the camera window
- //todo change this so that it becomes a vec2 for only width and height
- SDL_Rect viewport = {0, 0, 1200, 1200};
+ vec2 window = Config::get_instance().win_set.def_size;
};
} // namespace crepe
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
index 80726bc..54a90b5 100644
--- a/src/example/rendering_particle.cpp
+++ b/src/example/rendering_particle.cpp
@@ -64,6 +64,7 @@ int main(int argc, char * argv[]) {
auto & cam = game_object.add_component<Camera>(Color::WHITE);
cam.pos = {500, 200};
+ cam.viewport = {2000,1000};
/*
game_object