Optimizaciones de código

This commit is contained in:
2022-09-24 19:16:39 +02:00
parent f3aeed9428
commit b44869341c
99 changed files with 441 additions and 509 deletions

View File

@@ -11,7 +11,7 @@ LTexture::LTexture(SDL_Renderer *renderer, std::string path)
this->path = path;
// Inicializa
texture = NULL;
texture = nullptr;
width = 0;
height = 0;
@@ -35,7 +35,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
int req_format = STBI_rgb_alpha;
int width, height, orig_format;
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
if (data == NULL)
if (data == nullptr)
{
SDL_Log("Loading image failed: %s", stbi_failure_reason());
exit(1);
@@ -60,11 +60,11 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
unload();
// La textura final
SDL_Texture *newTexture = NULL;
SDL_Texture *newTexture = nullptr;
// Carga la imagen desde una ruta específica
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
if (loadedSurface == NULL)
if (loadedSurface == nullptr)
{
printf("Unable to load image %s!\n", path.c_str());
}
@@ -72,7 +72,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
{
// Crea la textura desde los pixels de la surface
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if (newTexture == NULL)
if (newTexture == nullptr)
{
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
}
@@ -89,7 +89,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
// Return success
texture = newTexture;
return texture != NULL;
return texture != nullptr;
}
// Crea una textura en blanco
@@ -97,7 +97,7 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
{
// Crea una textura sin inicializar
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
if (texture == NULL)
if (texture == nullptr)
{
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
}
@@ -107,17 +107,17 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
this->height = height;
}
return texture != NULL;
return texture != nullptr;
}
// Libera la memoria de la textura
void LTexture::unload()
{
// Libera la textura si existe
if (texture != NULL)
if (texture != nullptr)
{
SDL_DestroyTexture(texture);
texture = NULL;
texture = nullptr;
width = 0;
height = 0;
}
@@ -148,7 +148,7 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, floa
SDL_Rect renderQuad = {x, y, width, height};
// Obtiene las dimesiones del clip de renderizado
if (clip != NULL)
if (clip != nullptr)
{
renderQuad.w = clip->w;
renderQuad.h = clip->h;