Segmentation fault

This commit is contained in:
2023-05-07 18:08:36 +02:00
parent 90ebea4807
commit c1f8e16963
17 changed files with 163 additions and 73 deletions

View File

@@ -5,13 +5,12 @@
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
{
//std::cout << "Construido Screen" << std::endl;
// Inicializa variables
this->window = window;
this->renderer = renderer;
this->options = options;
gameCanvasWidth = options->screen.nativeWidth;
gameCanvasHeight = options->screen.nativeHeight;
borderWidth = options->screen.borderWidth * 2;
borderHeight = options->screen.borderHeight * 2;
@@ -22,7 +21,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
borderColor = {0x00, 0x00, 0x00};
// Crea la textura donde se dibujan los graficos del juego
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options->screen.nativeWidth, options->screen.nativeHeight);
if (gameCanvas == nullptr)
{
if (options->console)
@@ -38,6 +37,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
// Destructor
Screen::~Screen()
{
//std::cout << "Destruido Screen" << std::endl;
if (notify != nullptr)
{
delete notify;
@@ -92,23 +92,25 @@ void Screen::setVideoMode(int videoMode)
if (options->screen.borderEnabled)
{
windowWidth = gameCanvasWidth + borderWidth;
windowHeight = gameCanvasHeight + borderHeight;
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
windowWidth = options->screen.nativeWidth + borderWidth;
windowHeight = options->screen.nativeHeight + borderHeight;
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), options->screen.nativeWidth, options->screen.nativeHeight};
}
else
{
//windowWidth = gameCanvasWidth;
windowWidth = gameCanvasWidth * options->screen.nativeZoom * options->screen.windowZoom;
//windowHeight = gameCanvasHeight;
windowHeight = gameCanvasHeight * options->screen.nativeZoom * options->screen.windowZoom;
//dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
dest = {0, 0, windowWidth, windowHeight};
// windowWidth = options->screen.nativeWidth;
windowWidth = options->screen.nativeWidth * options->screen.nativeZoom * options->screen.windowZoom;
// windowHeight = options->screen.nativeHeight;
windowHeight = options->screen.nativeHeight * options->screen.nativeZoom * options->screen.windowZoom;
// dest = {0, 0, options->screen.nativeWidth, options->screen.nativeHeight};
gameWidth = options->screen.nativeWidth * options->screen.nativeZoom;
gameHeight = options->screen.nativeHeight * options->screen.nativeZoom;
dest = {0, 0, gameWidth, gameHeight};
}
// Modifica el tamaño de la ventana
//SDL_SetWindowSize(window, windowWidth * options->screen.windowZoom, windowHeight * options->screen.windowZoom);
// SDL_SetWindowSize(window, windowWidth * options->screen.windowZoom, windowHeight * options->screen.windowZoom);
SDL_SetWindowSize(window, windowWidth, windowHeight);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
@@ -127,20 +129,20 @@ void Screen::setVideoMode(int videoMode)
{
// Calcula el tamaño de la escala máxima
int scale = 0;
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight))
while (((options->screen.nativeWidth * (scale + 1)) <= windowWidth) && ((options->screen.nativeHeight * (scale + 1)) <= windowHeight))
{
scale++;
}
dest.w = gameCanvasWidth * scale;
dest.h = gameCanvasHeight * scale;
dest.w = options->screen.nativeWidth * scale;
dest.h = options->screen.nativeHeight * scale;
dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2;
}
else if (options->screen.keepAspect)
{
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
float ratio = (float)options->screen.nativeWidth / (float)options->screen.nativeHeight;
if ((windowWidth - options->screen.nativeWidth) >= (windowHeight - options->screen.nativeHeight))
{
dest.h = windowHeight;
dest.w = (int)((windowHeight * ratio) + 0.5f);
@@ -164,7 +166,8 @@ void Screen::setVideoMode(int videoMode)
}
// Modifica el tamaño del renderizador
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
// SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
SDL_RenderSetLogicalSize(renderer, gameWidth, gameHeight);
// Actualiza las opciones
options->screen.mode = videoMode;
@@ -302,7 +305,7 @@ void Screen::renderFade()
return;
}
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
const SDL_Rect rect = {0, 0, options->screen.nativeWidth, options->screen.nativeHeight};
color_t color = {0, 0, 0};
const float step = (float)fadeCounter / (float)fadeLenght;
const int alpha = 0 + (255 - 0) * step;