Config.yaml + Screen::Config desacoblat via Options (v0.3.0)
This commit is contained in:
1 parent
de5a670fdb
commit
0348acb0eb
8 files changed
+335
-16
No files matched your search
@@ -8,7 +8,6 @@
|
||||
#include <cstdlib>
|
||||
#include <ranges>
|
||||
|
||||
#include "utils/defaults.hpp"
|
||||
#include "utils/defines.hpp"
|
||||
|
||||
namespace {
|
||||
@@ -48,12 +47,41 @@ Screen::Screen()
|
||||
std::fprintf(stderr, "SDL_InitSubSystem(VIDEO) failed: %s\n", SDL_GetError());
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
// Els recursos SDL (finestra, renderer, textura) es creen a configure().
|
||||
}
|
||||
|
||||
const int WIN_W = GameCanvas::WIDTH * Defaults::Window::ZOOM;
|
||||
const int WIN_H = GameCanvas::HEIGHT * Defaults::Window::ZOOM;
|
||||
Screen::~Screen() {
|
||||
destroySdl();
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
}
|
||||
|
||||
void Screen::configure(const Config& config) {
|
||||
destroySdl();
|
||||
config_ = config;
|
||||
createSdl();
|
||||
}
|
||||
|
||||
void Screen::destroySdl() {
|
||||
if (game_texture_ != nullptr) {
|
||||
SDL_DestroyTexture(game_texture_);
|
||||
game_texture_ = nullptr;
|
||||
}
|
||||
if (renderer_ != nullptr) {
|
||||
SDL_DestroyRenderer(renderer_);
|
||||
renderer_ = nullptr;
|
||||
}
|
||||
if (window_ != nullptr) {
|
||||
SDL_DestroyWindow(window_);
|
||||
window_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::createSdl() {
|
||||
const int WIN_W = GameCanvas::WIDTH * config_.zoom;
|
||||
const int WIN_H = GameCanvas::HEIGHT * config_.zoom;
|
||||
|
||||
Uint32 win_flags = SDL_WINDOW_RESIZABLE;
|
||||
if (Defaults::Window::FULLSCREEN) { win_flags |= SDL_WINDOW_FULLSCREEN; }
|
||||
if (config_.fullscreen) { win_flags |= SDL_WINDOW_FULLSCREEN; }
|
||||
|
||||
window_ = SDL_CreateWindow(Texts::WINDOW_TITLE, WIN_W, WIN_H, win_flags);
|
||||
if (window_ == nullptr) {
|
||||
@@ -67,8 +95,8 @@ Screen::Screen()
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
SDL_SetRenderVSync(renderer_, Defaults::Video::VSYNC ? 1 : 0);
|
||||
SDL_SetRenderLogicalPresentation(renderer_, GameCanvas::WIDTH, GameCanvas::HEIGHT, toSdlPresentation(Defaults::Video::SCALING_MODE));
|
||||
SDL_SetRenderVSync(renderer_, config_.vsync ? 1 : 0);
|
||||
SDL_SetRenderLogicalPresentation(renderer_, GameCanvas::WIDTH, GameCanvas::HEIGHT, toSdlPresentation(config_.scaling_mode));
|
||||
|
||||
// STREAMING: el framebuffer ARGB del joc s'actualitza per CPU cada frame
|
||||
// i s'envia a la GPU via SDL_UpdateTexture en present().
|
||||
@@ -77,14 +105,7 @@ Screen::Screen()
|
||||
std::fprintf(stderr, "SDL_CreateTexture failed: %s\n", SDL_GetError());
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
SDL_SetTextureScaleMode(game_texture_, toSdlScaleMode(Defaults::Video::TEXTURE_FILTER));
|
||||
}
|
||||
|
||||
Screen::~Screen() {
|
||||
if (game_texture_ != nullptr) { SDL_DestroyTexture(game_texture_); }
|
||||
if (renderer_ != nullptr) { SDL_DestroyRenderer(renderer_); }
|
||||
if (window_ != nullptr) { SDL_DestroyWindow(window_); }
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
SDL_SetTextureScaleMode(game_texture_, toSdlScaleMode(config_.texture_filter));
|
||||
}
|
||||
|
||||
void Screen::clear(std::uint8_t r, std::uint8_t g, std::uint8_t b) {
|
||||
|
||||
Reference in new issue
Block a user