migrant a SDL3

This commit is contained in:
2025-03-27 08:14:37 +01:00
parent a9c869baf6
commit d2286905dc
83 changed files with 570 additions and 541 deletions

View File

@@ -1,14 +1,15 @@
#define _USE_MATH_DEFINES
#include "utils.h"
#include <SDL3/SDL_rwops.h> // Para SDL_RWFromFile, SDL_RWclose, SDL_RWread
#include <stddef.h> // Para size_t
#include <algorithm> // Para min, clamp, find_if_not, find, transform
#include <cctype> // Para tolower, isspace
#include <cmath> // Para pow, sin, M_PI, cos
#include <compare> // Para operator<
#include <filesystem> // Para path
#include <iostream> // Para basic_ostream, cout, basic_ios, endl, ios
#include <stdexcept> // Para runtime_error
#include <string> // Para basic_string, string, char_traits, opera...
#include <SDL3/SDL.h> // Para SDL_IOFromFile, SDL_CloseIO, SDL_RIO
#include <stddef.h> // Para size_t
#include <algorithm> // Para min, clamp, find_if_not, find, transform
#include <cctype> // Para tolower, isspace
#include <cmath> // Para pow, sin, M_PI, cos
#include <compare> // Para operator<
#include <filesystem> // Para path
#include <iostream> // Para basic_ostream, cout, basic_ios, endl, ios
#include <stdexcept> // Para runtime_error
#include <string> // Para basic_string, string, char_traits, opera...
#include "lang.h"
// Variables
@@ -72,11 +73,11 @@ bool checkCollision(const Circle &a, const Circle &b)
bool checkCollision(const Circle &a, const SDL_FRect &b)
{
// Encuentra el punto más cercano en el rectángulo
int cX = std::clamp(a.x, b.x, b.x + b.w);
int cY = std::clamp(a.y, b.y, b.y + b.h);
float cX = std::clamp(static_cast<float>(a.x), b.x, b.x + b.w);
float cY = std::clamp(static_cast<float>(a.y), b.y, b.y + b.h);
// Si el punto más cercano está dentro del círculo
return distanceSquared(a.x, a.y, cX, cY) < a.r * a.r;
return distanceSquared(static_cast<float>(a.x), static_cast<float>(a.y), cX, cY) < static_cast<float>(a.r) * a.r;
}
// Detector de colisiones entre dos rectangulos
@@ -98,7 +99,7 @@ bool checkCollision(const SDL_FRect &a, const SDL_FRect &b)
}
// Detector de colisiones entre un punto y un rectangulo
bool checkCollision(const SDL_Point &p, const SDL_FRect &r)
bool checkCollision(const SDL_FPoint &p, const SDL_FRect &r)
{
if (p.x < r.x || p.x > r.x + r.w)
return false;
@@ -149,14 +150,14 @@ void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_
while (x >= y)
{
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint(renderer, centerX + x, centerY - y);
SDL_RenderDrawPoint(renderer, centerX + x, centerY + y);
SDL_RenderDrawPoint(renderer, centerX - x, centerY - y);
SDL_RenderDrawPoint(renderer, centerX - x, centerY + y);
SDL_RenderDrawPoint(renderer, centerX + y, centerY - x);
SDL_RenderDrawPoint(renderer, centerX + y, centerY + x);
SDL_RenderDrawPoint(renderer, centerX - y, centerY - x);
SDL_RenderDrawPoint(renderer, centerX - y, centerY + x);
SDL_RenderPoint(renderer, centerX + x, centerY - y);
SDL_RenderPoint(renderer, centerX + x, centerY + y);
SDL_RenderPoint(renderer, centerX - x, centerY - y);
SDL_RenderPoint(renderer, centerX - x, centerY + y);
SDL_RenderPoint(renderer, centerX + y, centerY - x);
SDL_RenderPoint(renderer, centerX + y, centerY + x);
SDL_RenderPoint(renderer, centerX - y, centerY - x);
SDL_RenderPoint(renderer, centerX - y, centerY + x);
if (error <= 0)
{
@@ -317,7 +318,7 @@ DemoData loadDemoDataFromFile(const std::string &file_path)
DemoData dd;
// Indicador de éxito en la carga
auto file = SDL_RWFromFile(file_path.c_str(), "r+b");
auto file = SDL_IOFromFile(file_path.c_str(), "r+b");
if (!file)
{
std::cerr << "Error: Fichero no encontrado " << file_path << std::endl;
@@ -331,12 +332,12 @@ DemoData loadDemoDataFromFile(const std::string &file_path)
for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
{
DemoKeys dk = DemoKeys();
SDL_RWread(file, &dk, sizeof(DemoKeys), 1);
SDL_ReadIO(file, &dk, sizeof(DemoKeys));
dd.push_back(dk);
}
// Cierra el fichero
SDL_RWclose(file);
SDL_CloseIO(file);
}
return dd;
@@ -347,7 +348,7 @@ DemoData loadDemoDataFromFile(const std::string &file_path)
bool saveDemoFile(const std::string &file_path, const DemoData &dd)
{
auto success = true;
auto file = SDL_RWFromFile(file_path.c_str(), "w+b");
auto file = SDL_IOFromFile(file_path.c_str(), "w+b");
if (file)
{
@@ -366,7 +367,7 @@ bool saveDemoFile(const std::string &file_path, const DemoData &dd)
std::cout << "Writing file " << getFileName(file_path).c_str() << std::endl;
}
// Cierra el fichero
SDL_RWclose(file);
SDL_CloseIO(file);
}
else
{