afegit gif.cpp i jail_shader.cpp desde coffee_crisis_arcade_edition
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
#include "cheevos.h"
|
#include "cheevos.h"
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
|
#include <SDL2/SDL_rwops.h> // Para SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
|
||||||
#include <stddef.h> // for NULL
|
#include <stddef.h> // Para NULL
|
||||||
#include <fstream> // for basic_ostream, operator<<, basic_ofstream
|
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
|
||||||
#include <iostream> // for cout, cerr
|
#include <iostream> // Para cout, cerr
|
||||||
#include "notifier.h" // for Notifier
|
#include "notifier.h" // Para Notifier
|
||||||
#include "options.h" // for Options, options
|
#include "options.h" // Para Options, options
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Cheevos *Cheevos::cheevos_ = nullptr;
|
Cheevos *Cheevos::cheevos_ = nullptr;
|
||||||
@@ -89,7 +89,7 @@ void Cheevos::unlock(int id)
|
|||||||
cheevos_list_.at(INDEX).completed = true;
|
cheevos_list_.at(INDEX).completed = true;
|
||||||
|
|
||||||
// Mostrar notificación en la pantalla
|
// Mostrar notificación en la pantalla
|
||||||
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", cheevos_list_.at(INDEX).caption}, NotificationText::CENTER, CHEEVO_NOTIFICATION_DURATION/*, cheevos_list_.at(INDEX).icon*/);
|
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", cheevos_list_.at(INDEX).caption}, NotificationText::CENTER, CHEEVO_NOTIFICATION_DURATION /*, cheevos_list_.at(INDEX).icon*/);
|
||||||
|
|
||||||
// Guardar el estado de los logros
|
// Guardar el estado de los logros
|
||||||
saveToFile();
|
saveToFile();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
// Struct para los logros
|
// Struct para los logros
|
||||||
struct Achievement
|
struct Achievement
|
||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
void enable(bool value) { enabled_ = value; }
|
void enable(bool value) { enabled_ = value; }
|
||||||
|
|
||||||
// Lista los logros
|
// Lista los logros
|
||||||
std::vector<Achievement> list() { return cheevos_list_; }
|
const std::vector<Achievement>& list() const { return cheevos_list_; }
|
||||||
|
|
||||||
// Devuelve el número total de logros desbloqueados
|
// Devuelve el número total de logros desbloqueados
|
||||||
int getTotalUnlockedAchievements();
|
int getTotalUnlockedAchievements();
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
#include "credits.h"
|
#include "credits.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <algorithm> // Para min
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include "defines.h" // Para GAME_SPEED, PLAY_AREA_CENTER_X, PLAY_...
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include "global_events.h" // Para check
|
||||||
#include <algorithm> // for min
|
#include "global_inputs.h" // Para check
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include "options.h" // Para Options, options, OptionsGame, Sectio...
|
||||||
#include "s_animated_sprite.h" // for SAnimatedSprite
|
#include "resource.h" // Para Resource
|
||||||
#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "global_events.h" // for check
|
#include "screen.h" // Para Screen
|
||||||
#include "global_inputs.h" // for check
|
#include "surface.h" // Para Surface
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "resource.h" // for Resource
|
#include "utils.h" // Para PaletteColor
|
||||||
#include "screen.h" // for Screen
|
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Credits::Credits()
|
Credits::Credits()
|
||||||
@@ -186,7 +184,6 @@ void Credits::fillTexture()
|
|||||||
// El resto se rellena de color sólido
|
// El resto se rellena de color sólido
|
||||||
SDL_Rect rect = {0, 8, 256, 192};
|
SDL_Rect rect = {0, 8, 256, 192};
|
||||||
cover_surface_->fillRect(&rect, color);
|
cover_surface_->fillRect(&rect, color);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <memory> // Para shared_ptr
|
||||||
#include <memory> // for shared_ptr
|
#include <string> // Para string
|
||||||
#include <string> // for string
|
#include <vector> // Para vector
|
||||||
#include <vector> // for vector
|
class SAnimatedSprite; // lines 11-11
|
||||||
#include "utils.h" // for Color
|
class Surface;
|
||||||
#include <memory>
|
|
||||||
#include "surface.h"
|
|
||||||
class SAnimatedSprite; // lines 9-9
|
|
||||||
|
|
||||||
class Credits
|
class Credits
|
||||||
{
|
{
|
||||||
@@ -20,8 +17,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<Surface> text_surface_; // Textura para dibujar el texto
|
std::shared_ptr<Surface> text_surface_; // Textura para dibujar el texto
|
||||||
std::shared_ptr<Surface> cover_surface_; // Textura para cubrir el texto
|
std::shared_ptr<Surface> cover_surface_; // Textura para cubrir el texto
|
||||||
std::shared_ptr<SAnimatedSprite> shining_sprite_; // Sprite para el brillo del corazón
|
std::shared_ptr<SAnimatedSprite> shining_sprite_; // Sprite para el brillo del corazón
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include <algorithm> // for max
|
#include <algorithm> // Para max
|
||||||
#include <memory> // for __shared_ptr_access, shared_ptr
|
#include <memory> // Para __shared_ptr_access, shared_ptr
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // Para Resource
|
||||||
#include "text.h" // for Text
|
#include "text.h" // Para Text
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // Para Color
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Debug *Debug::debug_ = nullptr;
|
Debug *Debug::debug_ = nullptr;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
// Clase Debug
|
// Clase Debug
|
||||||
class Debug
|
class Debug
|
||||||
|
|||||||
@@ -1,42 +1,41 @@
|
|||||||
#include "director.h"
|
#include "director.h"
|
||||||
#include <SDL2/SDL.h> // for SDL_Init, SDL_Quit, SDL_INIT_EV...
|
#include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV...
|
||||||
#include <SDL2/SDL_audio.h> // for AUDIO_S16
|
#include <SDL2/SDL_audio.h> // Para AUDIO_S16
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
#include <SDL2/SDL_events.h> // Para SDL_DISABLE
|
||||||
#include <SDL2/SDL_hints.h> // for SDL_SetHint, SDL_HINT_RENDER_DR...
|
#include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_ES...
|
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
|
||||||
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_A, SDL_SCANCODE_ES...
|
||||||
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <stdio.h> // for printf, perror
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <string.h> // for strcmp
|
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||||
#include <sys/stat.h> // for mkdir, stat, S_IRWXU
|
#include <stdio.h> // Para printf, perror
|
||||||
#include <unistd.h> // for getuid
|
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||||
#include <cstdlib> // for exit, EXIT_FAILURE, srand
|
#include <unistd.h> // Para getuid
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout
|
#include <cstdlib> // Para exit, EXIT_FAILURE, srand
|
||||||
#include <memory> // for make_unique, unique_ptr
|
#include <iostream> // Para basic_ostream, operator<<, cout
|
||||||
#include <string> // for operator+, allocator, char_traits
|
#include <memory> // Para make_unique, unique_ptr
|
||||||
#include "asset.h" // for Asset, AssetType
|
#include <string> // Para operator+, allocator, char_traits
|
||||||
#include "cheevos.h" // for Cheevos
|
#include "asset.h" // Para Asset, AssetType
|
||||||
#include "credits.h" // for Credits
|
#include "cheevos.h" // Para Cheevos
|
||||||
#include "debug.h" // for Debug
|
#include "credits.h" // Para Credits
|
||||||
#include "defines.h" // for WINDOW_CAPTION, borderColor
|
#include "debug.h" // Para Debug
|
||||||
#include "ending.h" // for Ending
|
#include "defines.h" // Para WINDOW_CAPTION
|
||||||
#include "ending2.h" // for Ending2
|
#include "ending.h" // Para Ending
|
||||||
#include "game.h" // for Game
|
#include "ending2.h" // Para Ending2
|
||||||
#include "game_over.h" // for GameOver
|
#include "game.h" // Para Game, GameMode
|
||||||
#include "input.h" // for Input, inputs_e
|
#include "game_over.h" // Para GameOver
|
||||||
#include "jail_audio.h" // for JA_GetMusicState, JA_DeleteMusic
|
#include "input.h" // Para Input, InputAction
|
||||||
#include "loading_screen.h" // for LoadingScreen
|
#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV...
|
||||||
#include "logo.h" // for Logo
|
#include "loading_screen.h" // Para LoadingScreen
|
||||||
#include "notifier.h" // for Notifier
|
#include "logo.h" // Para Logo
|
||||||
#include "options.h" // for Options, options, Section, Cheat
|
#include "notifier.h" // Para Notifier
|
||||||
#include "resource.h" // for Resource
|
#include "options.h" // Para Options, options, OptionsVideo
|
||||||
#include "screen.h" // for Screen
|
#include "resource.h" // Para Resource
|
||||||
#include "title.h" // for Title
|
#include "screen.h" // Para Screen
|
||||||
#include "utils.h" // for Color
|
#include "title.h" // Para Title
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
#include <SDL2/SDL_video.h> // Para SDL_Window
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
|
|
||||||
class Director
|
class Director
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,23 +1,20 @@
|
|||||||
#include "ending.h"
|
#include "ending.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <algorithm> // Para min
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include "defines.h" // Para GAME_SPEED
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include "global_events.h" // Para check
|
||||||
#include <algorithm> // for min
|
#include "global_inputs.h" // Para check
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
|
||||||
#include "defines.h" // for options.game.height, options.game.width
|
#include "options.h" // Para Options, options, OptionsGame, SectionS...
|
||||||
#include "global_events.h" // for check
|
#include "resource.h" // Para Resource
|
||||||
#include "global_inputs.h" // for check
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
#include "screen.h" // Para Screen
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "surface.h" // Para Surface
|
||||||
#include "resource.h" // for Resource
|
#include "text.h" // Para Text, TEXT_STROKE
|
||||||
#include "screen.h" // for Screen
|
#include "utils.h" // Para PaletteColor
|
||||||
#include "s_sprite.h" // for SSprite
|
|
||||||
#include "text.h" // for Text, TEXT_STROKE
|
|
||||||
#include "surface.h" // for Surface
|
|
||||||
#include "utils.h" // for Color, static_cast<Uint8>,PaletteColor::PALETTE
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending::Ending()
|
Ending::Ending()
|
||||||
: counter_(-1),
|
: counter_(-1),
|
||||||
@@ -476,7 +473,7 @@ void Ending::checkChangeScene()
|
|||||||
void Ending::fillCoverTexture()
|
void Ending::fillCoverTexture()
|
||||||
{
|
{
|
||||||
// Rellena la textura que cubre el texto con color transparente
|
// Rellena la textura que cubre el texto con color transparente
|
||||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||||
Screen::get()->setRendererSurface(cover_surface_);
|
Screen::get()->setRendererSurface(cover_surface_);
|
||||||
cover_surface_->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
|
cover_surface_->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <memory> // Para shared_ptr
|
||||||
#include <memory> // for shared_ptr
|
#include <string> // Para string
|
||||||
#include <string> // for string
|
#include <vector> // Para vector
|
||||||
#include <vector> // for vector
|
class SSprite; // lines 8-8
|
||||||
class SSprite; // lines 12-12
|
class Surface; // lines 9-9
|
||||||
class Surface; // lines 14-14
|
|
||||||
|
|
||||||
class Ending
|
class Ending
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
#include "ending2.h"
|
#include "ending2.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RenderDrawPoint, SDL_SetRenderDr...
|
#include <algorithm> // Para max, replace
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include "defines.h" // Para GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y
|
||||||
#include <algorithm> // for max, min, replace
|
#include "global_events.h" // Para check
|
||||||
#include "s_animated_sprite.h" // for SAnimatedSprite
|
#include "global_inputs.h" // Para check
|
||||||
#include "defines.h" // for options.game.height, GAMECANVAS_CENTER_X
|
#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic
|
||||||
#include "global_events.h" // for check
|
#include "options.h" // Para Options, options, OptionsGame, Sectio...
|
||||||
#include "global_inputs.h" // for check
|
#include "resource.h" // Para Resource
|
||||||
#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM...
|
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "s_moving_sprite.h" // for SMovingSprite
|
#include "s_moving_sprite.h" // Para SMovingSprite
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "screen.h" // Para Screen
|
||||||
#include "resource.h" // for Resource
|
#include "surface.h" // Para Surface
|
||||||
#include "screen.h" // for Screen
|
#include "text.h" // Para Text
|
||||||
#include "text.h" // for Text
|
#include "utils.h" // Para PaletteColor, stringToColor
|
||||||
#include "surface.h" // for Surface
|
|
||||||
#include "utils.h" // for Color, static_cast<Uint8>
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending2::Ending2()
|
Ending2::Ending2()
|
||||||
@@ -423,7 +421,7 @@ void Ending2::createSpriteTexts()
|
|||||||
|
|
||||||
// Crea la surface
|
// Crea la surface
|
||||||
auto surface = std::make_shared<Surface>(W, H);
|
auto surface = std::make_shared<Surface>(W, H);
|
||||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||||
Screen::get()->setRendererSurface(surface);
|
Screen::get()->setRendererSurface(surface);
|
||||||
text->write(0, 0, txt);
|
text->write(0, 0, txt);
|
||||||
|
|
||||||
@@ -456,8 +454,8 @@ void Ending2::createTexts()
|
|||||||
|
|
||||||
// Crea la surface
|
// Crea la surface
|
||||||
auto surface = std::make_shared<Surface>(w, h);
|
auto surface = std::make_shared<Surface>(w, h);
|
||||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||||
Screen::get()->setRendererSurface(surface);
|
Screen::get()->setRendererSurface(surface);
|
||||||
text->write(0, 0, list[i]);
|
text->write(0, 0, list[i]);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
@@ -486,7 +484,7 @@ void Ending2::createTexts()
|
|||||||
|
|
||||||
// Crea la surface
|
// Crea la surface
|
||||||
auto surface = std::make_shared<Surface>(w, h);
|
auto surface = std::make_shared<Surface>(w, h);
|
||||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||||
Screen::get()->setRendererSurface(surface);
|
Screen::get()->setRendererSurface(surface);
|
||||||
text->write(0, 0, list[i]);
|
text->write(0, 0, list[i]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR...
|
#include "defines.h" // Para GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR...
|
||||||
#include "utils.h" // for Color
|
class SAnimatedSprite; // lines 9-9
|
||||||
class SAnimatedSprite; // lines 10-10
|
class SMovingSprite; // lines 10-10
|
||||||
class SMovingSprite; // lines 13-13
|
|
||||||
|
|
||||||
class Ending2
|
class Ending2
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#include "enemy.h"
|
#include "enemy.h"
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL...
|
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_NONE, SDL_...
|
||||||
#include <stdlib.h> // for rand
|
#include <stdlib.h> // Para rand
|
||||||
#include "s_animated_sprite.h" // for SAnimatedSprite
|
#include "resource.h" // Para Resource
|
||||||
#include "options.h" // for Options, OptionsVideo, options
|
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "resource.h" // for Resource
|
#include "utils.h" // Para stringToColor
|
||||||
#include "surface.h" // for Texture
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Enemy::Enemy(const EnemyData &enemy)
|
Enemy::Enemy(const EnemyData &enemy)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <memory> // for shared_ptr
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <string> // for string
|
#include <memory> // Para shared_ptr
|
||||||
#include "utils.h" // for Color
|
#include <string> // Para string
|
||||||
class SAnimatedSprite;
|
class SAnimatedSprite; // lines 7-7
|
||||||
|
|
||||||
// Estructura para pasar los datos de un enemigo
|
// Estructura para pasar los datos de un enemigo
|
||||||
struct EnemyData
|
struct EnemyData
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_7, SDL_SCANCODE_A, SDL_S...
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_...
|
#include <vector> // Para vector
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include "asset.h" // Para Asset
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include "cheevos.h" // Para Cheevos
|
||||||
#include <vector> // for vector
|
#include "debug.h" // Para Debug
|
||||||
#include "asset.h" // for Asset
|
#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, BORDER_BOTTOM
|
||||||
#include "cheevos.h" // for Cheevos
|
#include "global_events.h" // Para check
|
||||||
#include "debug.h" // for Debug
|
#include "global_inputs.h" // Para check
|
||||||
#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, GAMECANVAS_...
|
#include "input.h" // Para Input, InputAction, REPEAT_FALSE
|
||||||
#include "global_events.h" // for check
|
#include "item_tracker.h" // Para ItemTracker
|
||||||
#include "global_inputs.h" // for check
|
#include "jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
|
||||||
#include "input.h" // for Input, InputAction, REPEAT_FALSE
|
#include "notifier.h" // Para Notifier, NotificationText, CHEEVO_NO...
|
||||||
#include "item_tracker.h" // for ItemTracker
|
#include "options.h" // Para Options, options, Cheat, SectionState
|
||||||
#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu...
|
#include "resource.h" // Para ResourceRoom, Resource
|
||||||
#include "notifier.h" // for Notifier, NotificationText
|
#include "room.h" // Para Room, RoomData
|
||||||
#include "options.h" // for Options, options, Cheat, OptionsVideo
|
#include "room_tracker.h" // Para RoomTracker
|
||||||
#include "resource.h" // for ResourceRoom, Resource
|
#include "scoreboard.h" // Para ScoreboardData, Scoreboard
|
||||||
#include "room.h" // for Room, RoomData
|
#include "screen.h" // Para Screen
|
||||||
#include "room_tracker.h" // for RoomTracker
|
#include "stats.h" // Para Stats
|
||||||
#include "scoreboard.h" // for ScoreboardData, Scoreboard
|
#include "surface.h" // Para Surface
|
||||||
#include "screen.h" // for Screen
|
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "stats.h" // for Stats
|
#include "utils.h" // Para PaletteColor, stringToColor
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
|
||||||
#include "utils.h" // for Color, stringToColor, colorAreEqual
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(GameMode mode)
|
Game::Game(GameMode mode)
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <initializer_list> // Para initializer_list
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "player.h" // for PlayerSpawn
|
#include "player.h" // Para PlayerSpawn
|
||||||
#include "surface.h"
|
class Room; // lines 12-12
|
||||||
class Room; // lines 10-10
|
class RoomTracker; // lines 13-13
|
||||||
class RoomTracker; // lines 11-11
|
class Scoreboard; // lines 14-14
|
||||||
class Scoreboard; // lines 12-12
|
class Stats; // lines 15-15
|
||||||
class Stats; // lines 13-13
|
class Surface;
|
||||||
struct ScoreboardData; // lines 14-14
|
struct ScoreboardData; // lines 16-16
|
||||||
|
|
||||||
enum class GameMode
|
enum class GameMode
|
||||||
{
|
{
|
||||||
@@ -162,7 +162,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(GameMode mode);
|
explicit Game(GameMode mode);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
#include "game_over.h"
|
#include "game_over.h"
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <algorithm> // for min, max
|
#include <algorithm> // Para min, max
|
||||||
#include <string> // for basic_string, operator+, to_string, cha...
|
#include <string> // Para basic_string, operator+, to_string
|
||||||
#include "s_animated_sprite.h" // for AnimatedSprite
|
#include "defines.h" // Para GAMECANVAS_CENTER_X, GAME_SPEED
|
||||||
#include "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED
|
#include "global_events.h" // Para check
|
||||||
#include "global_events.h" // for check
|
#include "global_inputs.h" // Para check
|
||||||
#include "global_inputs.h" // for check
|
#include "jail_audio.h" // Para JA_PlayMusic
|
||||||
#include "jail_audio.h" // for JA_PlayMusic
|
#include "options.h" // Para Options, options, OptionsStats, Secti...
|
||||||
#include "options.h" // for Options, options, OptionsStats, Section...
|
#include "resource.h" // Para Resource
|
||||||
#include "resource.h" // for Resource
|
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text
|
#include "text.h" // Para TEXT_CENTER, TEXT_COLOR, Text
|
||||||
#include "surface.h" // for Texture
|
#include "utils.h" // Para PaletteColor, stringToColor
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver::GameOver()
|
GameOver::GameOver()
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "utils.h" // for Color
|
class SAnimatedSprite; // lines 7-7
|
||||||
class SAnimatedSprite; // lines 8-8
|
|
||||||
|
|
||||||
class GameOver
|
class GameOver
|
||||||
{
|
{
|
||||||
@@ -16,7 +15,7 @@ private:
|
|||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<SAnimatedSprite> player_sprite_; // Sprite con el jugador
|
std::shared_ptr<SAnimatedSprite> player_sprite_; // Sprite con el jugador
|
||||||
std::shared_ptr<SAnimatedSprite> tv_sprite_; // Sprite con el televisor
|
std::shared_ptr<SAnimatedSprite> tv_sprite_; // Sprite con el televisor
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int pre_counter_ = 0; // Contador previo
|
int pre_counter_ = 0; // Contador previo
|
||||||
|
|||||||
651
source/gif.cpp
651
source/gif.cpp
@@ -1,391 +1,316 @@
|
|||||||
#include "gif.h"
|
#include "gif.h"
|
||||||
#include <stdio.h> // for NULL, fprintf, stderr
|
#include <iostream> // Para std::cout
|
||||||
#include <stdlib.h> // for malloc, realloc, exit, calloc, free
|
#include <cstring> // Para memcpy, size_t
|
||||||
|
#include <stdexcept> // Para runtime_error
|
||||||
|
#include <string> // Para allocator, char_traits, operator==, basic_string
|
||||||
|
|
||||||
void uncompress( int code_length,
|
namespace GIF
|
||||||
const unsigned char *input,
|
|
||||||
int input_length,
|
|
||||||
unsigned char *out )
|
|
||||||
{
|
{
|
||||||
//int maxbits;
|
|
||||||
int i, bit;
|
|
||||||
int code, prev = -1;
|
|
||||||
dictionary_entry_t *dictionary;
|
|
||||||
int dictionary_ind;
|
|
||||||
unsigned int mask = 0x01;
|
|
||||||
int reset_code_length;
|
|
||||||
int clear_code; // This varies depending on code_length
|
|
||||||
int stop_code; // one more than clear code
|
|
||||||
int match_len;
|
|
||||||
|
|
||||||
clear_code = 1 << ( code_length );
|
// Función inline para reemplazar el macro READ.
|
||||||
stop_code = clear_code + 1;
|
// Actualiza el puntero 'buffer' tras copiar 'size' bytes a 'dst'.
|
||||||
// To handle clear codes
|
inline void readBytes(const uint8_t *&buffer, void *dst, size_t size)
|
||||||
reset_code_length = code_length;
|
|
||||||
|
|
||||||
// Create a dictionary large enough to hold "code_length" entries.
|
|
||||||
// Once the dictionary overflows, code_length increases
|
|
||||||
dictionary = ( dictionary_entry_t * )
|
|
||||||
malloc( sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
|
||||||
|
|
||||||
// Initialize the first 2^code_len entries of the dictionary with their
|
|
||||||
// indices. The rest of the entries will be built up dynamically.
|
|
||||||
|
|
||||||
// Technically, it shouldn't be necessary to initialize the
|
|
||||||
// dictionary. The spec says that the encoder "should output a
|
|
||||||
// clear code as the first code in the image data stream". It doesn't
|
|
||||||
// say must, though...
|
|
||||||
for ( dictionary_ind = 0;
|
|
||||||
dictionary_ind < ( 1 << code_length );
|
|
||||||
dictionary_ind++ )
|
|
||||||
{
|
{
|
||||||
dictionary[ dictionary_ind ].byte = dictionary_ind;
|
std::memcpy(dst, buffer, size);
|
||||||
// XXX this only works because prev is a 32-bit int (> 12 bits)
|
buffer += size;
|
||||||
dictionary[ dictionary_ind ].prev = -1;
|
|
||||||
dictionary[ dictionary_ind ].len = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2^code_len + 1 is the special "end" code; don't give it an entry here
|
void Gif::decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out)
|
||||||
dictionary_ind++;
|
|
||||||
dictionary_ind++;
|
|
||||||
|
|
||||||
// TODO verify that the very last byte is clear_code + 1
|
|
||||||
while ( input_length )
|
|
||||||
{
|
{
|
||||||
code = 0x0;
|
// Verifica que el code_length tenga un rango razonable.
|
||||||
// Always read one more bit than the code length
|
if (code_length < 2 || code_length > 12)
|
||||||
for ( i = 0; i < ( code_length + 1 ); i++ )
|
|
||||||
{
|
{
|
||||||
// This is different than in the file read example; that
|
throw std::runtime_error("Invalid LZW code length");
|
||||||
// was a call to "next_bit"
|
|
||||||
bit = ( *input & mask ) ? 1 : 0;
|
|
||||||
mask <<= 1;
|
|
||||||
|
|
||||||
if ( mask == 0x100 )
|
|
||||||
{
|
|
||||||
mask = 0x01;
|
|
||||||
input++;
|
|
||||||
input_length--;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = code | ( bit << i );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( code == clear_code )
|
int i, bit;
|
||||||
{
|
int prev = -1;
|
||||||
code_length = reset_code_length;
|
std::vector<DictionaryEntry> dictionary;
|
||||||
dictionary = ( dictionary_entry_t * ) realloc( dictionary,
|
int dictionary_ind;
|
||||||
sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
unsigned int mask = 0x01;
|
||||||
|
int reset_code_length = code_length;
|
||||||
|
int clear_code = 1 << code_length;
|
||||||
|
int stop_code = clear_code + 1;
|
||||||
|
int match_len = 0;
|
||||||
|
|
||||||
for ( dictionary_ind = 0;
|
// Inicializamos el diccionario con el tamaño correspondiente.
|
||||||
dictionary_ind < ( 1 << code_length );
|
dictionary.resize(1 << (code_length + 1));
|
||||||
dictionary_ind++ )
|
for (dictionary_ind = 0; dictionary_ind < (1 << code_length); dictionary_ind++)
|
||||||
{
|
{
|
||||||
dictionary[ dictionary_ind ].byte = dictionary_ind;
|
dictionary[dictionary_ind].byte = static_cast<uint8_t>(dictionary_ind);
|
||||||
// XXX this only works because prev is a 32-bit int (> 12 bits)
|
dictionary[dictionary_ind].prev = -1;
|
||||||
dictionary[ dictionary_ind ].prev = -1;
|
dictionary[dictionary_ind].len = 1;
|
||||||
dictionary[ dictionary_ind ].len = 1;
|
|
||||||
}
|
|
||||||
dictionary_ind++;
|
|
||||||
dictionary_ind++;
|
|
||||||
prev = -1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if ( code == stop_code )
|
dictionary_ind += 2; // Reservamos espacio para clear y stop codes
|
||||||
|
|
||||||
|
// Bucle principal: procesar el stream comprimido.
|
||||||
|
while (input_length > 0)
|
||||||
{
|
{
|
||||||
/*if ( input_length > 1 )
|
int code = 0;
|
||||||
|
// Lee (code_length + 1) bits para formar el código.
|
||||||
|
for (i = 0; i < (code_length + 1); i++)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Malformed GIF (early stop code)\n" );
|
if (input_length <= 0)
|
||||||
exit( 0 );
|
|
||||||
}*/
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the dictionary with this character plus the _entry_
|
|
||||||
// (character or string) that came before it
|
|
||||||
if ( ( prev > -1 ) && ( code_length < 12 ) )
|
|
||||||
{
|
|
||||||
if ( code > dictionary_ind )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "code = %.02x, but dictionary_ind = %.02x\n",
|
|
||||||
code, dictionary_ind );
|
|
||||||
exit( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special handling for KwKwK
|
|
||||||
if ( code == dictionary_ind )
|
|
||||||
{
|
|
||||||
int ptr = prev;
|
|
||||||
|
|
||||||
while ( dictionary[ ptr ].prev != -1 )
|
|
||||||
{
|
{
|
||||||
ptr = dictionary[ ptr ].prev;
|
throw std::runtime_error("Unexpected end of input in decompress");
|
||||||
}
|
}
|
||||||
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
bit = ((*input & mask) != 0) ? 1 : 0;
|
||||||
|
mask <<= 1;
|
||||||
|
if (mask == 0x100)
|
||||||
|
{
|
||||||
|
mask = 0x01;
|
||||||
|
input++;
|
||||||
|
input_length--;
|
||||||
|
}
|
||||||
|
code |= (bit << i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code == clear_code)
|
||||||
|
{
|
||||||
|
// Reinicia el diccionario.
|
||||||
|
code_length = reset_code_length;
|
||||||
|
dictionary.resize(1 << (code_length + 1));
|
||||||
|
for (dictionary_ind = 0; dictionary_ind < (1 << code_length); dictionary_ind++)
|
||||||
|
{
|
||||||
|
dictionary[dictionary_ind].byte = static_cast<uint8_t>(dictionary_ind);
|
||||||
|
dictionary[dictionary_ind].prev = -1;
|
||||||
|
dictionary[dictionary_ind].len = 1;
|
||||||
|
}
|
||||||
|
dictionary_ind += 2;
|
||||||
|
prev = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (code == stop_code)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev > -1 && code_length < 12)
|
||||||
|
{
|
||||||
|
if (code > dictionary_ind)
|
||||||
|
{
|
||||||
|
std::cerr << "code = " << std::hex << code
|
||||||
|
<< ", but dictionary_ind = " << dictionary_ind << std::endl;
|
||||||
|
throw std::runtime_error("LZW error: code exceeds dictionary_ind.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ptr;
|
||||||
|
if (code == dictionary_ind)
|
||||||
|
{
|
||||||
|
ptr = prev;
|
||||||
|
while (dictionary[ptr].prev != -1)
|
||||||
|
ptr = dictionary[ptr].prev;
|
||||||
|
dictionary[dictionary_ind].byte = dictionary[ptr].byte;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ptr = code;
|
||||||
|
while (dictionary[ptr].prev != -1)
|
||||||
|
ptr = dictionary[ptr].prev;
|
||||||
|
dictionary[dictionary_ind].byte = dictionary[ptr].byte;
|
||||||
|
}
|
||||||
|
dictionary[dictionary_ind].prev = prev;
|
||||||
|
dictionary[dictionary_ind].len = dictionary[prev].len + 1;
|
||||||
|
dictionary_ind++;
|
||||||
|
|
||||||
|
if ((dictionary_ind == (1 << (code_length + 1))) && (code_length < 11))
|
||||||
|
{
|
||||||
|
code_length++;
|
||||||
|
dictionary.resize(1 << (code_length + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = code;
|
||||||
|
|
||||||
|
// Verifica que 'code' sea un índice válido antes de usarlo.
|
||||||
|
if (code < 0 || static_cast<size_t>(code) >= dictionary.size())
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid LZW code " << code
|
||||||
|
<< ", dictionary size " << dictionary.size() << std::endl;
|
||||||
|
throw std::runtime_error("LZW error: invalid code encountered");
|
||||||
|
}
|
||||||
|
|
||||||
|
int curCode = code; // Variable temporal para recorrer la cadena.
|
||||||
|
match_len = dictionary[curCode].len;
|
||||||
|
while (curCode != -1)
|
||||||
|
{
|
||||||
|
// Se asume que dictionary[curCode].len > 0.
|
||||||
|
out[dictionary[curCode].len - 1] = dictionary[curCode].byte;
|
||||||
|
if (dictionary[curCode].prev == curCode)
|
||||||
|
{
|
||||||
|
std::cerr << "Internal error; self-reference detected." << std::endl;
|
||||||
|
throw std::runtime_error("Internal error in decompress: self-reference");
|
||||||
|
}
|
||||||
|
curCode = dictionary[curCode].prev;
|
||||||
|
}
|
||||||
|
out += match_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> Gif::readSubBlocks(const uint8_t *&buffer)
|
||||||
|
{
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
uint8_t block_size = *buffer;
|
||||||
|
buffer++;
|
||||||
|
while (block_size != 0)
|
||||||
|
{
|
||||||
|
data.insert(data.end(), buffer, buffer + block_size);
|
||||||
|
buffer += block_size;
|
||||||
|
block_size = *buffer;
|
||||||
|
buffer++;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> Gif::processImageDescriptor(const uint8_t *&buffer, const std::vector<RGB> &gct, int resolution_bits)
|
||||||
|
{
|
||||||
|
ImageDescriptor image_descriptor;
|
||||||
|
// Lee 9 bytes para el image descriptor.
|
||||||
|
readBytes(buffer, &image_descriptor, sizeof(ImageDescriptor));
|
||||||
|
|
||||||
|
uint8_t lzw_code_size;
|
||||||
|
readBytes(buffer, &lzw_code_size, sizeof(uint8_t));
|
||||||
|
|
||||||
|
std::vector<uint8_t> compressed_data = readSubBlocks(buffer);
|
||||||
|
int uncompressed_data_length = image_descriptor.image_width * image_descriptor.image_height;
|
||||||
|
std::vector<uint8_t> uncompressed_data(uncompressed_data_length);
|
||||||
|
|
||||||
|
decompress(lzw_code_size, compressed_data.data(), static_cast<int>(compressed_data.size()), uncompressed_data.data());
|
||||||
|
return uncompressed_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint32_t> Gif::loadPalette(const uint8_t *buffer)
|
||||||
|
{
|
||||||
|
uint8_t header[6];
|
||||||
|
std::memcpy(header, buffer, 6);
|
||||||
|
buffer += 6;
|
||||||
|
|
||||||
|
ScreenDescriptor screen_descriptor;
|
||||||
|
std::memcpy(&screen_descriptor, buffer, sizeof(ScreenDescriptor));
|
||||||
|
buffer += sizeof(ScreenDescriptor);
|
||||||
|
|
||||||
|
std::vector<uint32_t> global_color_table;
|
||||||
|
if (screen_descriptor.fields & 0x80)
|
||||||
|
{
|
||||||
|
int global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
|
||||||
|
global_color_table.resize(global_color_table_size);
|
||||||
|
for (int i = 0; i < global_color_table_size; ++i)
|
||||||
|
{
|
||||||
|
uint8_t r = buffer[0];
|
||||||
|
uint8_t g = buffer[1];
|
||||||
|
uint8_t b = buffer[2];
|
||||||
|
global_color_table[i] = (r << 16) | (g << 8) | b;
|
||||||
|
buffer += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return global_color_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> Gif::processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h)
|
||||||
|
{
|
||||||
|
// Leer la cabecera de 6 bytes ("GIF87a" o "GIF89a")
|
||||||
|
uint8_t header[6];
|
||||||
|
std::memcpy(header, buffer, 6);
|
||||||
|
buffer += 6;
|
||||||
|
|
||||||
|
// Opcional: Validar header
|
||||||
|
std::string headerStr(reinterpret_cast<char *>(header), 6);
|
||||||
|
if (headerStr != "GIF87a" && headerStr != "GIF89a")
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Formato de archivo GIF inválido.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Leer el Screen Descriptor (7 bytes, empaquetado sin padding)
|
||||||
|
ScreenDescriptor screen_descriptor;
|
||||||
|
readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor));
|
||||||
|
|
||||||
|
// Asigna ancho y alto
|
||||||
|
w = screen_descriptor.width;
|
||||||
|
h = screen_descriptor.height;
|
||||||
|
|
||||||
|
int color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
|
||||||
|
std::vector<RGB> global_color_table;
|
||||||
|
if (screen_descriptor.fields & 0x80)
|
||||||
|
{
|
||||||
|
int global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
|
||||||
|
global_color_table.resize(global_color_table_size);
|
||||||
|
std::memcpy(global_color_table.data(), buffer, 3 * global_color_table_size);
|
||||||
|
buffer += 3 * global_color_table_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Supongamos que 'buffer' es el puntero actual y TRAILER es 0x3B
|
||||||
|
uint8_t block_type = *buffer++;
|
||||||
|
while (block_type != TRAILER)
|
||||||
|
{
|
||||||
|
if (block_type == EXTENSION_INTRODUCER) // 0x21
|
||||||
|
{
|
||||||
|
// Se lee la etiqueta de extensión, la cual indica el tipo de extensión.
|
||||||
|
uint8_t extension_label = *buffer++;
|
||||||
|
switch (extension_label)
|
||||||
|
{
|
||||||
|
case GRAPHIC_CONTROL: // 0xF9
|
||||||
|
{
|
||||||
|
// Procesar Graphic Control Extension:
|
||||||
|
uint8_t blockSize = *buffer++; // Normalmente, blockSize == 4
|
||||||
|
buffer += blockSize; // Saltamos los 4 bytes del bloque fijo
|
||||||
|
// Saltar los sub-bloques
|
||||||
|
uint8_t subBlockSize = *buffer++;
|
||||||
|
while (subBlockSize != 0)
|
||||||
|
{
|
||||||
|
buffer += subBlockSize;
|
||||||
|
subBlockSize = *buffer++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case APPLICATION_EXTENSION: // 0xFF
|
||||||
|
case COMMENT_EXTENSION: // 0xFE
|
||||||
|
case PLAINTEXT_EXTENSION: // 0x01
|
||||||
|
{
|
||||||
|
// Para estas extensiones, saltamos el bloque fijo y los sub-bloques.
|
||||||
|
uint8_t blockSize = *buffer++;
|
||||||
|
buffer += blockSize;
|
||||||
|
uint8_t subBlockSize = *buffer++;
|
||||||
|
while (subBlockSize != 0)
|
||||||
|
{
|
||||||
|
buffer += subBlockSize;
|
||||||
|
subBlockSize = *buffer++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// Si la etiqueta de extensión es desconocida, saltarla también:
|
||||||
|
uint8_t blockSize = *buffer++;
|
||||||
|
buffer += blockSize;
|
||||||
|
uint8_t subBlockSize = *buffer++;
|
||||||
|
while (subBlockSize != 0)
|
||||||
|
{
|
||||||
|
buffer += subBlockSize;
|
||||||
|
subBlockSize = *buffer++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (block_type == IMAGE_DESCRIPTOR)
|
||||||
|
{
|
||||||
|
// Procesar el Image Descriptor y retornar los datos de imagen
|
||||||
|
return processImageDescriptor(buffer, global_color_table, color_resolution_bits);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int ptr = code;
|
std::cerr << "Unrecognized block type " << std::hex << static_cast<int>(block_type) << std::endl;
|
||||||
while ( dictionary[ ptr ].prev != -1 )
|
return std::vector<uint8_t>{};
|
||||||
{
|
|
||||||
ptr = dictionary[ ptr ].prev;
|
|
||||||
}
|
|
||||||
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
|
||||||
}
|
|
||||||
|
|
||||||
dictionary[ dictionary_ind ].prev = prev;
|
|
||||||
|
|
||||||
dictionary[ dictionary_ind ].len = dictionary[ prev ].len + 1;
|
|
||||||
|
|
||||||
dictionary_ind++;
|
|
||||||
|
|
||||||
// GIF89a mandates that this stops at 12 bits
|
|
||||||
if ( ( dictionary_ind == ( 1 << ( code_length + 1 ) ) ) &&
|
|
||||||
( code_length < 11 ) )
|
|
||||||
{
|
|
||||||
code_length++;
|
|
||||||
|
|
||||||
dictionary = ( dictionary_entry_t * ) realloc( dictionary,
|
|
||||||
sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
|
||||||
}
|
}
|
||||||
|
block_type = *buffer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = code;
|
return std::vector<uint8_t>{};
|
||||||
|
|
||||||
// Now copy the dictionary entry backwards into "out"
|
|
||||||
match_len = dictionary[ code ].len;
|
|
||||||
while ( code != -1 )
|
|
||||||
{
|
|
||||||
out[ dictionary[ code ].len - 1 ] = dictionary[ code ].byte;
|
|
||||||
if ( dictionary[ code ].prev == code )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Internal error; self-reference." );
|
|
||||||
exit( 0 );
|
|
||||||
}
|
|
||||||
code = dictionary[ code ].prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
out += match_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read_sub_blocks( unsigned char* buffer, unsigned char **data )
|
|
||||||
{
|
|
||||||
int data_length;
|
|
||||||
int index;
|
|
||||||
unsigned char block_size;
|
|
||||||
|
|
||||||
// Everything following are data sub-blocks, until a 0-sized block is
|
|
||||||
// encountered.
|
|
||||||
data_length = 0;
|
|
||||||
*data = NULL;
|
|
||||||
index = 0;
|
|
||||||
|
|
||||||
while ( 1 )
|
|
||||||
{
|
|
||||||
READ(&block_size, 1);
|
|
||||||
|
|
||||||
if ( block_size == 0 ) // end of sub-blocks
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
data_length += block_size;
|
|
||||||
*data = (unsigned char*)realloc( *data, data_length );
|
|
||||||
|
|
||||||
// TODO this could be split across block size boundaries
|
|
||||||
READ(*data + index, block_size);
|
|
||||||
|
|
||||||
index += block_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data_length;
|
std::vector<uint8_t> Gif::loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h)
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char* process_image_descriptor( unsigned char* buffer,
|
|
||||||
rgb *gct,
|
|
||||||
int gct_size,
|
|
||||||
int resolution_bits )
|
|
||||||
{
|
|
||||||
image_descriptor_t image_descriptor;
|
|
||||||
int compressed_data_length;
|
|
||||||
unsigned char *compressed_data = NULL;
|
|
||||||
unsigned char lzw_code_size;
|
|
||||||
int uncompressed_data_length = 0;
|
|
||||||
unsigned char *uncompressed_data = NULL;
|
|
||||||
|
|
||||||
// TODO there could actually be lots of these
|
|
||||||
READ(&image_descriptor, 9);
|
|
||||||
|
|
||||||
// TODO if LCT = true, read the LCT
|
|
||||||
|
|
||||||
READ(&lzw_code_size, 1);
|
|
||||||
|
|
||||||
compressed_data_length = read_sub_blocks( buffer, &compressed_data );
|
|
||||||
|
|
||||||
// width = image_descriptor.image_width;
|
|
||||||
// height = image_descriptor.image_height;
|
|
||||||
uncompressed_data_length = image_descriptor.image_width *
|
|
||||||
image_descriptor.image_height;
|
|
||||||
uncompressed_data = (unsigned char*)malloc( uncompressed_data_length );
|
|
||||||
|
|
||||||
uncompress( lzw_code_size, compressed_data, compressed_data_length,
|
|
||||||
uncompressed_data );
|
|
||||||
|
|
||||||
if ( compressed_data ) free( compressed_data );
|
|
||||||
|
|
||||||
//if ( uncompressed_data )
|
|
||||||
// free( uncompressed_data );
|
|
||||||
|
|
||||||
return uncompressed_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param gif_file the file descriptor of a file containing a
|
|
||||||
* GIF-encoded file. This should point to the first byte in
|
|
||||||
* the file when invoked.
|
|
||||||
*/
|
|
||||||
#define rb (*(buffer++))
|
|
||||||
|
|
||||||
uint32_t* LoadPalette(unsigned char *buffer) {
|
|
||||||
unsigned char header[7];
|
|
||||||
screen_descriptor_t screen_descriptor;
|
|
||||||
//int color_resolution_bits;
|
|
||||||
|
|
||||||
int global_color_table_size = 0; // number of entries in global_color_table
|
|
||||||
uint32_t *global_color_table = NULL;
|
|
||||||
|
|
||||||
READ(header, 6);
|
|
||||||
READ(&screen_descriptor, 7);
|
|
||||||
|
|
||||||
//color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
|
|
||||||
global_color_table = (uint32_t *)calloc(1, 1024);
|
|
||||||
|
|
||||||
if (screen_descriptor.fields & 0x80) {
|
|
||||||
global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
|
|
||||||
|
|
||||||
//global_color_table = (rgb *)malloc(3 * global_color_table_size);
|
|
||||||
//READ(global_color_table, 3 * global_color_table_size);
|
|
||||||
for (int i=0; i<global_color_table_size;++i) {
|
|
||||||
global_color_table[i] = (buffer[0]<<16) + (buffer[1]<<8) + buffer[2];
|
|
||||||
buffer+=3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return global_color_table;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char* process_gif_stream(unsigned char *buffer, unsigned short* w, unsigned short* h)
|
|
||||||
{
|
|
||||||
unsigned char header[ 7 ];
|
|
||||||
screen_descriptor_t screen_descriptor;
|
|
||||||
int color_resolution_bits;
|
|
||||||
|
|
||||||
int global_color_table_size =0; // number of entries in global_color_table
|
|
||||||
rgb *global_color_table = NULL;
|
|
||||||
|
|
||||||
unsigned char block_type = 0x0;
|
|
||||||
|
|
||||||
// A GIF file starts with a Header (section 17)
|
|
||||||
READ(header, 6);
|
|
||||||
header[ 6 ] = 0x0;
|
|
||||||
|
|
||||||
// XXX there's another format, GIF87a, that you may still find
|
|
||||||
// floating around.
|
|
||||||
/*if ( strcmp( "GIF89a", (char*)header ) )
|
|
||||||
{
|
{
|
||||||
fprintf( stderr,
|
return processGifStream(buffer, w, h);
|
||||||
"Invalid GIF file (header is '%s', should be 'GIF89a')\n",
|
|
||||||
header );
|
|
||||||
return NULL;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Followed by a logical screen descriptor
|
|
||||||
// Note that this works because GIFs specify little-endian order; on a
|
|
||||||
// big-endian machine, the height & width would need to be reversed.
|
|
||||||
|
|
||||||
// Can't use sizeof here since GCC does byte alignment;
|
|
||||||
// sizeof( screen_descriptor_t ) = 8!
|
|
||||||
READ(&screen_descriptor, 7);
|
|
||||||
*w = screen_descriptor.width;
|
|
||||||
*h = screen_descriptor.height;
|
|
||||||
|
|
||||||
color_resolution_bits = ( ( screen_descriptor.fields & 0x70 ) >> 4 ) + 1;
|
|
||||||
|
|
||||||
if ( screen_descriptor.fields & 0x80 )
|
|
||||||
{
|
|
||||||
//int i;
|
|
||||||
// If bit 7 is set, the next block is a global color table; read it
|
|
||||||
global_color_table_size = 1 <<
|
|
||||||
( ( ( screen_descriptor.fields & 0x07 ) + 1 ) );
|
|
||||||
|
|
||||||
global_color_table = ( rgb * ) malloc( 3 * global_color_table_size );
|
|
||||||
|
|
||||||
// XXX this could conceivably return a short count...
|
|
||||||
READ(global_color_table, 3 * global_color_table_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( block_type != TRAILER )
|
} // namespace GIF
|
||||||
{
|
|
||||||
READ(&block_type, 1);
|
|
||||||
|
|
||||||
unsigned char size;
|
|
||||||
switch ( block_type )
|
|
||||||
{
|
|
||||||
case IMAGE_DESCRIPTOR:
|
|
||||||
return process_image_descriptor(buffer,
|
|
||||||
global_color_table,
|
|
||||||
global_color_table_size,
|
|
||||||
color_resolution_bits);
|
|
||||||
break;
|
|
||||||
case EXTENSION_INTRODUCER:
|
|
||||||
buffer++;
|
|
||||||
size = *(buffer++);
|
|
||||||
buffer += size;
|
|
||||||
do {
|
|
||||||
size = *(buffer++);
|
|
||||||
buffer += size;
|
|
||||||
} while (size != 0);
|
|
||||||
|
|
||||||
/*if ( !process_extension( buffer ) )
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}*/
|
|
||||||
break;
|
|
||||||
case TRAILER:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf( stderr, "Bailing on unrecognized block type %.02x\n",
|
|
||||||
block_type );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned char* LoadGif(unsigned char *buffer, unsigned short* w, unsigned short* h) {
|
|
||||||
return process_gif_stream(buffer, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*int main( int argc, char *argv[] )
|
|
||||||
{
|
|
||||||
FILE* gif_file;
|
|
||||||
|
|
||||||
if ( argc < 2 )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Usage: %s <path-to-gif-file>\n", argv[ 0 ] );
|
|
||||||
exit( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
gif_file = fopen( argv[ 1 ], "rb" );
|
|
||||||
|
|
||||||
if ( gif_file == NULL )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Unable to open file '%s'", argv[ 1 ] );
|
|
||||||
perror( ": " );
|
|
||||||
}
|
|
||||||
|
|
||||||
process_gif_stream( gif_file );
|
|
||||||
|
|
||||||
fclose( gif_file );
|
|
||||||
}*/
|
|
||||||
|
|||||||
142
source/gif.h
142
source/gif.h
@@ -1,66 +1,102 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h> // for uint32_t
|
#include <cstdint> // Para uint8_t, uint16_t, uint32_t
|
||||||
#include <string.h> // for memcpy
|
#include <vector> // Para vector
|
||||||
|
|
||||||
#define EXTENSION_INTRODUCER 0x21
|
namespace GIF
|
||||||
#define IMAGE_DESCRIPTOR 0x2C
|
{
|
||||||
#define TRAILER 0x3B
|
|
||||||
#define GRAPHIC_CONTROL 0xF9
|
|
||||||
#define APPLICATION_EXTENSION 0xFF
|
|
||||||
#define COMMENT_EXTENSION 0xFE
|
|
||||||
#define PLAINTEXT_EXTENSION 0x01
|
|
||||||
|
|
||||||
#define READ(dst, size) memcpy(dst, buffer, size); buffer += size
|
// Constantes definidas con constexpr, en lugar de macros
|
||||||
|
constexpr uint8_t EXTENSION_INTRODUCER = 0x21;
|
||||||
|
constexpr uint8_t IMAGE_DESCRIPTOR = 0x2C;
|
||||||
|
constexpr uint8_t TRAILER = 0x3B;
|
||||||
|
constexpr uint8_t GRAPHIC_CONTROL = 0xF9;
|
||||||
|
constexpr uint8_t APPLICATION_EXTENSION = 0xFF;
|
||||||
|
constexpr uint8_t COMMENT_EXTENSION = 0xFE;
|
||||||
|
constexpr uint8_t PLAINTEXT_EXTENSION = 0x01;
|
||||||
|
|
||||||
typedef struct {
|
#pragma pack(push, 1)
|
||||||
unsigned short width;
|
struct ScreenDescriptor
|
||||||
unsigned short height;
|
{
|
||||||
unsigned char fields;
|
uint16_t width;
|
||||||
unsigned char background_color_index;
|
uint16_t height;
|
||||||
unsigned char pixel_aspect_ratio;
|
uint8_t fields;
|
||||||
} screen_descriptor_t;
|
uint8_t background_color_index;
|
||||||
|
uint8_t pixel_aspect_ratio;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct RGB
|
||||||
unsigned char r, g, b;
|
{
|
||||||
} rgb;
|
uint8_t r, g, b;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct ImageDescriptor
|
||||||
unsigned short image_left_position;
|
{
|
||||||
unsigned short image_top_position;
|
uint16_t image_left_position;
|
||||||
unsigned short image_width;
|
uint16_t image_top_position;
|
||||||
unsigned short image_height;
|
uint16_t image_width;
|
||||||
unsigned char fields;
|
uint16_t image_height;
|
||||||
} image_descriptor_t;
|
uint8_t fields;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
typedef struct {
|
struct DictionaryEntry
|
||||||
unsigned char byte;
|
{
|
||||||
int prev;
|
uint8_t byte;
|
||||||
int len;
|
int prev;
|
||||||
} dictionary_entry_t;
|
int len;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct Extension
|
||||||
unsigned char extension_code;
|
{
|
||||||
unsigned char block_size;
|
uint8_t extension_code;
|
||||||
} extension_t;
|
uint8_t block_size;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct GraphicControlExtension
|
||||||
unsigned char fields;
|
{
|
||||||
unsigned short delay_time;
|
uint8_t fields;
|
||||||
unsigned char transparent_color_index;
|
uint16_t delay_time;
|
||||||
} graphic_control_extension_t;
|
uint8_t transparent_color_index;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct ApplicationExtension
|
||||||
unsigned char application_id[8];
|
{
|
||||||
unsigned char version[3];
|
uint8_t application_id[8];
|
||||||
} application_extension_t;
|
uint8_t version[3];
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct PlaintextExtension
|
||||||
unsigned short left, top, width, height;
|
{
|
||||||
unsigned char cell_width, cell_height;
|
uint16_t left, top, width, height;
|
||||||
unsigned char foreground_color, background_color;
|
uint8_t cell_width, cell_height;
|
||||||
} plaintext_extension_t;
|
uint8_t foreground_color, background_color;
|
||||||
|
};
|
||||||
|
|
||||||
void uncompress(int code_length, const unsigned char *input, int input_length, unsigned char *out);
|
class Gif
|
||||||
uint32_t* LoadPalette(unsigned char *buffer);
|
{
|
||||||
unsigned char* LoadGif(unsigned char *buffer, unsigned short* w, unsigned short* h);
|
public:
|
||||||
|
// Descompone (uncompress) el bloque comprimido usando LZW.
|
||||||
|
// Este método puede lanzar std::runtime_error en caso de error.
|
||||||
|
void decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out);
|
||||||
|
|
||||||
|
// Carga la paleta (global color table) a partir de un buffer,
|
||||||
|
// retornándola en un vector de uint32_t (cada color se compone de R, G, B).
|
||||||
|
std::vector<uint32_t> loadPalette(const uint8_t *buffer);
|
||||||
|
|
||||||
|
// Carga el stream GIF; devuelve un vector con los datos de imagen sin comprimir y
|
||||||
|
// asigna el ancho y alto mediante referencias.
|
||||||
|
std::vector<uint8_t> loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Lee los sub-bloques de datos y los acumula en un std::vector<uint8_t>.
|
||||||
|
std::vector<uint8_t> readSubBlocks(const uint8_t *&buffer);
|
||||||
|
|
||||||
|
// Procesa el Image Descriptor y retorna el vector de datos sin comprimir.
|
||||||
|
std::vector<uint8_t> processImageDescriptor(const uint8_t *&buffer, const std::vector<RGB> &gct, int resolution_bits);
|
||||||
|
|
||||||
|
// Procesa el stream completo del GIF y devuelve los datos sin comprimir.
|
||||||
|
std::vector<uint8_t> processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace GIF
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include "global_inputs.h"
|
#include "global_inputs.h"
|
||||||
#include <string> // for basic_string
|
#include <SDL2/SDL_render.h> // Para SDL_RenderSetIntegerScale
|
||||||
#include <vector> // for vector
|
#include <SDL2/SDL_stdinc.h> // Para SDL_FALSE, SDL_TRUE
|
||||||
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
#include <string> // Para allocator, operator+, char_traits, string
|
||||||
#include "notifier.h" // for Notifier
|
#include <vector> // Para vector
|
||||||
#include "options.h" // for Section, Options, options, SectionState, Optio...
|
#include "input.h" // Para Input, InputAction, REPEAT_FALSE
|
||||||
#include "screen.h" // for Screen
|
#include "notifier.h" // Para Notifier, NotificationText
|
||||||
#include "utils.h" // for Palette
|
#include "options.h" // Para Options, options, OptionsVideo, Section
|
||||||
|
#include "screen.h" // Para Screen
|
||||||
|
#include "utils.h" // Para stringInVector
|
||||||
|
|
||||||
namespace globalInputs
|
namespace globalInputs
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "resource.h"
|
#include "resource.h" // Para Resource
|
||||||
#include "s_sprite.h" // Para SSprite
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "surface.h" // Para Texture
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(ItemData item)
|
Item::Item(ItemData item)
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <string> // for string
|
#include <memory> // Para shared_ptr
|
||||||
#include <vector> // for vector
|
#include <string> // Para string
|
||||||
#include "s_sprite.h" // for SSprite
|
#include <vector> // Para vector
|
||||||
#include "surface.h" // for Texture
|
class SSprite;
|
||||||
#include "utils.h" // for Color
|
|
||||||
|
|
||||||
struct ItemData
|
struct ItemData
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromMem
|
#include <SDL2/SDL_rwops.h> // Para SDL_RWFromMem
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <stdint.h> // for uint8_t, uint32_t
|
#include <stdint.h> // Para uint8_t, uint32_t
|
||||||
#include <stdio.h> // for NULL, fseek, fclose, fopen, fread, ftell
|
#include <stdio.h> // Para NULL, fseek, fclose, fopen, fread, ftell
|
||||||
#include <stdlib.h> // for free, malloc
|
#include <stdlib.h> // Para free, malloc
|
||||||
#include "stb_vorbis.c" // for stb_vorbis_decode_memory
|
#include "stb_vorbis.c" // Para stb_vorbis_decode_memory
|
||||||
|
|
||||||
constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20;
|
constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_audio.h> // for SDL_AudioFormat
|
#include <SDL2/SDL_audio.h> // Para SDL_AudioFormat
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||||
struct JA_Music_t; // lines 5-5
|
struct JA_Music_t; // lines 5-5
|
||||||
struct JA_Sound_t; // lines 6-6
|
struct JA_Sound_t; // lines 6-6
|
||||||
|
|
||||||
enum JA_Channel_state
|
enum JA_Channel_state
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
#include "jail_shader.h"
|
#include "jail_shader.h"
|
||||||
#include <SDL2/SDL_rect.h> // para SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||||
#include <stdlib.h> // para NULL, free, malloc, exit
|
#include <SDL2/SDL_stdinc.h> // Para SDL_bool
|
||||||
#include <string.h> // para strncmp
|
#include <cstring> // Para strncmp
|
||||||
#include <iostream> // para basic_ostream, char_traits, operator<<
|
#include <iostream> // Para basic_ostream, operator<<, endl, cout
|
||||||
|
#include <stdexcept> // Para runtime_error
|
||||||
|
#include <vector> // Para vector
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "CoreFoundation/CoreFoundation.h"
|
#include "CoreFoundation/CoreFoundation.h" // Para Core Foundation en macOS
|
||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h> // Para OpenGL en macOS
|
||||||
|
|
||||||
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||||
#include <OpenGL/gl3.h>
|
#include <OpenGL/gl3.h> // Para OpenGL 3 en macOS
|
||||||
#else
|
#else // NO ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||||
#include <OpenGL/gl.h>
|
#include <OpenGL/gl.h> // Para OpenGL (compatibilidad) en macOS
|
||||||
#endif //! ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
#endif // ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||||
#else
|
#else // SI NO ES __APPLE__
|
||||||
#include <SDL2/SDL_opengl.h>
|
#include <SDL2/SDL_opengl.h> // Para GLuint, glTexCoord2f, glVertex2f, GLfloat
|
||||||
#endif
|
#endif // __APPLE__
|
||||||
|
|
||||||
namespace shader
|
namespace shader
|
||||||
{
|
{
|
||||||
@@ -25,12 +26,10 @@ namespace shader
|
|||||||
SDL_Texture *backBuffer = nullptr;
|
SDL_Texture *backBuffer = nullptr;
|
||||||
SDL_Point win_size = {320 * 4, 256 * 4};
|
SDL_Point win_size = {320 * 4, 256 * 4};
|
||||||
SDL_Point tex_size = {320, 256};
|
SDL_Point tex_size = {320, 256};
|
||||||
bool usingOpenGL;
|
bool usingOpenGL = false;
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
|
// Declaración de funciones de extensión de OpenGL (evitando GLEW)
|
||||||
// I'm avoiding the use of GLEW or some extensions handler, but that
|
|
||||||
// doesn't mean you should...
|
|
||||||
PFNGLCREATESHADERPROC glCreateShader;
|
PFNGLCREATESHADERPROC glCreateShader;
|
||||||
PFNGLSHADERSOURCEPROC glShaderSource;
|
PFNGLSHADERSOURCEPROC glShaderSource;
|
||||||
PFNGLCOMPILESHADERPROC glCompileShader;
|
PFNGLCOMPILESHADERPROC glCompileShader;
|
||||||
@@ -66,120 +65,125 @@ namespace shader
|
|||||||
glLinkProgram && glValidateProgram && glGetProgramiv && glGetProgramInfoLog &&
|
glLinkProgram && glValidateProgram && glGetProgramiv && glGetProgramInfoLog &&
|
||||||
glUseProgram;
|
glUseProgram;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GLuint compileShader(const char *source, GLuint shaderType)
|
// Función para compilar un shader a partir de un std::string
|
||||||
|
GLuint compileShader(const std::string &source, GLuint shaderType)
|
||||||
{
|
{
|
||||||
// Create ID for shader
|
if (source.empty())
|
||||||
GLuint result = glCreateShader(shaderType);
|
|
||||||
// Add define depending on shader type
|
|
||||||
const char *sources[2] = {shaderType == GL_VERTEX_SHADER ? "#define VERTEX\n" : "#define FRAGMENT\n", source};
|
|
||||||
// Define shader text
|
|
||||||
glShaderSource(result, 2, sources, NULL);
|
|
||||||
// Compile shader
|
|
||||||
glCompileShader(result);
|
|
||||||
|
|
||||||
// Check vertex shader for errors
|
|
||||||
GLint shaderCompiled = GL_FALSE;
|
|
||||||
glGetShaderiv(result, GL_COMPILE_STATUS, &shaderCompiled);
|
|
||||||
if (shaderCompiled != GL_TRUE)
|
|
||||||
{
|
{
|
||||||
std::cout << "Error en la compilación: " << result << "!" << std::endl;
|
throw std::runtime_error("ERROR FATAL: El código fuente del shader está vacío.");
|
||||||
GLint logLength;
|
|
||||||
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength);
|
|
||||||
if (logLength > 0)
|
|
||||||
{
|
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
|
||||||
glGetShaderInfoLog(result, logLength, &logLength, log);
|
|
||||||
std::cout << "Shader compile log:" << log << std::endl;
|
|
||||||
free(log);
|
|
||||||
}
|
|
||||||
glDeleteShader(result);
|
|
||||||
result = 0;
|
|
||||||
// } else {
|
|
||||||
// std::cout << "Shader compilado correctamente. Id = " << result << std::endl;
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
// Crear identificador del shader
|
||||||
|
GLuint resultado = glCreateShader(shaderType);
|
||||||
|
|
||||||
|
// Agregar una directiva según el tipo de shader
|
||||||
|
std::string directiva = (shaderType == GL_VERTEX_SHADER)
|
||||||
|
? "#define VERTEX\n"
|
||||||
|
: "#define FRAGMENT\n";
|
||||||
|
|
||||||
|
const char *sources[2] = {directiva.c_str(), source.c_str()};
|
||||||
|
|
||||||
|
// Especificar el código fuente del shader
|
||||||
|
glShaderSource(resultado, 2, sources, nullptr);
|
||||||
|
|
||||||
|
// Compilar el shader
|
||||||
|
glCompileShader(resultado);
|
||||||
|
|
||||||
|
// Verificar si la compilación fue exitosa
|
||||||
|
GLint compiladoCorrectamente = GL_FALSE;
|
||||||
|
glGetShaderiv(resultado, GL_COMPILE_STATUS, &compiladoCorrectamente);
|
||||||
|
if (compiladoCorrectamente != GL_TRUE)
|
||||||
|
{
|
||||||
|
std::cout << "Error en la compilación del shader (" << resultado << ")!" << std::endl;
|
||||||
|
GLint longitudLog;
|
||||||
|
glGetShaderiv(resultado, GL_INFO_LOG_LENGTH, &longitudLog);
|
||||||
|
if (longitudLog > 0)
|
||||||
|
{
|
||||||
|
std::vector<GLchar> log(longitudLog);
|
||||||
|
glGetShaderInfoLog(resultado, longitudLog, &longitudLog, log.data());
|
||||||
|
std::cout << "Registro de compilación del shader: " << log.data() << std::endl;
|
||||||
|
}
|
||||||
|
glDeleteShader(resultado);
|
||||||
|
resultado = 0;
|
||||||
|
}
|
||||||
|
return resultado;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint compileProgram(const char *vertexShaderSource, const char *fragmentShaderSource)
|
// Función para compilar un programa de shaders (vertex y fragment) a partir de std::string
|
||||||
|
GLuint compileProgram(const std::string &vertexShaderSource, const std::string &fragmentShaderSource)
|
||||||
{
|
{
|
||||||
GLuint programId = 0;
|
GLuint idPrograma = glCreateProgram();
|
||||||
GLuint vtxShaderId, fragShaderId;
|
|
||||||
|
|
||||||
programId = glCreateProgram();
|
// Si el fragment shader está vacío, reutilizamos el código del vertex shader
|
||||||
|
GLuint idShaderVertice = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||||
|
GLuint idShaderFragmento = compileShader(fragmentShaderSource.empty() ? vertexShaderSource : fragmentShaderSource, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
if (idShaderVertice && idShaderFragmento)
|
||||||
fragShaderId = compileShader(fragmentShaderSource ? fragmentShaderSource : vertexShaderSource, GL_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
if (vtxShaderId && fragShaderId)
|
|
||||||
{
|
{
|
||||||
// Associate shader with program
|
// Asociar los shaders al programa
|
||||||
glAttachShader(programId, vtxShaderId);
|
glAttachShader(idPrograma, idShaderVertice);
|
||||||
glAttachShader(programId, fragShaderId);
|
glAttachShader(idPrograma, idShaderFragmento);
|
||||||
glLinkProgram(programId);
|
glLinkProgram(idPrograma);
|
||||||
glValidateProgram(programId);
|
glValidateProgram(idPrograma);
|
||||||
|
|
||||||
// Check the status of the compile/link
|
// Verificar el estado del enlace
|
||||||
GLint logLen;
|
GLint longitudLog;
|
||||||
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen);
|
glGetProgramiv(idPrograma, GL_INFO_LOG_LENGTH, &longitudLog);
|
||||||
if (logLen > 0)
|
if (longitudLog > 0)
|
||||||
{
|
{
|
||||||
char *log = (char *)malloc(logLen * sizeof(char));
|
std::vector<char> log(longitudLog);
|
||||||
// Show any errors as appropriate
|
glGetProgramInfoLog(idPrograma, longitudLog, &longitudLog, log.data());
|
||||||
glGetProgramInfoLog(programId, logLen, &logLen, log);
|
std::cout << "Registro de información del programa:" << std::endl
|
||||||
std::cout << "Prog Info Log: " << std::endl
|
<< log.data() << std::endl;
|
||||||
<< log << std::endl;
|
|
||||||
free(log);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vtxShaderId)
|
if (idShaderVertice)
|
||||||
{
|
{
|
||||||
glDeleteShader(vtxShaderId);
|
glDeleteShader(idShaderVertice);
|
||||||
}
|
}
|
||||||
if (fragShaderId)
|
if (idShaderFragmento)
|
||||||
{
|
{
|
||||||
glDeleteShader(fragShaderId);
|
glDeleteShader(idShaderFragmento);
|
||||||
}
|
}
|
||||||
return programId;
|
return idPrograma;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool init(SDL_Window *win, SDL_Texture *backBuffer, const char *vertexShader, const char *fragmentShader)
|
bool init(SDL_Window *ventana, SDL_Texture *texturaBackBuffer, const std::string &vertexShader, const std::string &fragmentShader)
|
||||||
{
|
{
|
||||||
shader::win = win;
|
shader::win = ventana;
|
||||||
shader::renderer = SDL_GetRenderer(win);
|
shader::renderer = SDL_GetRenderer(ventana);
|
||||||
shader::backBuffer = backBuffer;
|
shader::backBuffer = texturaBackBuffer;
|
||||||
SDL_GetWindowSize(win, &win_size.x, &win_size.y);
|
SDL_GetWindowSize(ventana, &win_size.x, &win_size.y);
|
||||||
int access;
|
|
||||||
SDL_QueryTexture(backBuffer, NULL, &access, &tex_size.x, &tex_size.y);
|
int acceso;
|
||||||
if (access != SDL_TEXTUREACCESS_TARGET)
|
SDL_QueryTexture(texturaBackBuffer, nullptr, &acceso, &tex_size.x, &tex_size.y);
|
||||||
|
if (acceso != SDL_TEXTUREACCESS_TARGET)
|
||||||
{
|
{
|
||||||
std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl;
|
throw std::runtime_error("ERROR FATAL: La textura debe tener definido SDL_TEXTUREACCESS_TARGET.");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RendererInfo rendererInfo;
|
SDL_RendererInfo infoRenderer;
|
||||||
SDL_GetRendererInfo(renderer, &rendererInfo);
|
SDL_GetRendererInfo(renderer, &infoRenderer);
|
||||||
|
|
||||||
if (!strncmp(rendererInfo.name, "opengl", 6))
|
// Verificar que el renderer sea OpenGL
|
||||||
|
if (!strncmp(infoRenderer.name, "opengl", 6))
|
||||||
{
|
{
|
||||||
// std::cout << "Es OpenGL!" << std::endl;
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
if (!initGLExtensions())
|
if (!initGLExtensions())
|
||||||
{
|
{
|
||||||
std::cout << "WARNING: No s'han pogut inicialitzar les extensions d'OpenGL!" << std::endl;
|
std::cout << "ADVERTENCIA: No se han podido inicializar las extensiones de OpenGL." << std::endl;
|
||||||
usingOpenGL = false;
|
usingOpenGL = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Compilar el shader y dejarlo listo para usar.
|
// Compilar el programa de shaders utilizando std::string
|
||||||
programId = compileProgram(vertexShader, fragmentShader);
|
programId = compileProgram(vertexShader, fragmentShader);
|
||||||
// std::cout << "programId = " << programId << std::endl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl;
|
std::cout << "ADVERTENCIA: El driver del renderer no es OpenGL." << std::endl;
|
||||||
usingOpenGL = false;
|
usingOpenGL = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -190,48 +194,90 @@ namespace shader
|
|||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
GLint oldProgramId;
|
GLint oldProgramId;
|
||||||
// Guarrada para obtener el textureid (en driverdata->texture)
|
// Establece el color de fondo
|
||||||
// Detach the texture
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
SDL_SetRenderTarget(renderer, NULL);
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
if (usingOpenGL)
|
if (usingOpenGL)
|
||||||
{
|
{
|
||||||
SDL_GL_BindTexture(backBuffer, NULL, NULL);
|
SDL_GL_BindTexture(backBuffer, nullptr, nullptr);
|
||||||
if (programId != 0)
|
if (programId != 0)
|
||||||
{
|
{
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
|
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
|
||||||
glUseProgram(programId);
|
glUseProgram(programId);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLfloat minx, miny, maxx, maxy;
|
// Recupera el tamaño lógico configurado con SDL_RenderSetLogicalSize
|
||||||
GLfloat minu, maxu, minv, maxv;
|
int logicalW, logicalH;
|
||||||
|
SDL_RenderGetLogicalSize(renderer, &logicalW, &logicalH);
|
||||||
|
if (logicalW == 0 || logicalH == 0)
|
||||||
|
{
|
||||||
|
logicalW = win_size.x;
|
||||||
|
logicalH = win_size.y;
|
||||||
|
}
|
||||||
|
|
||||||
// Coordenadas de la ventana donde pintar.
|
// Cálculo del viewport
|
||||||
minx = 0.0f;
|
int viewportX = 0, viewportY = 0, viewportW = win_size.x, viewportH = win_size.y;
|
||||||
miny = 0.0f;
|
SDL_bool useIntegerScale = SDL_RenderGetIntegerScale(renderer);
|
||||||
maxx = tex_size.x;
|
if (useIntegerScale)
|
||||||
maxy = tex_size.y;
|
{
|
||||||
|
// Calcula el factor de escalado entero máximo que se puede aplicar
|
||||||
|
int scaleX = win_size.x / logicalW;
|
||||||
|
int scaleY = win_size.y / logicalH;
|
||||||
|
int scale = (scaleX < scaleY ? scaleX : scaleY);
|
||||||
|
if (scale < 1)
|
||||||
|
scale = 1;
|
||||||
|
viewportW = logicalW * scale;
|
||||||
|
viewportH = logicalH * scale;
|
||||||
|
viewportX = (win_size.x - viewportW) / 2;
|
||||||
|
viewportY = (win_size.y - viewportH) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Letterboxing: preserva la relación de aspecto usando una escala flotante
|
||||||
|
float windowAspect = static_cast<float>(win_size.x) / win_size.y;
|
||||||
|
float logicalAspect = static_cast<float>(logicalW) / logicalH;
|
||||||
|
if (windowAspect > logicalAspect)
|
||||||
|
{
|
||||||
|
viewportW = static_cast<int>(logicalAspect * win_size.y);
|
||||||
|
viewportX = (win_size.x - viewportW) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
viewportH = static_cast<int>(win_size.x / logicalAspect);
|
||||||
|
viewportY = (win_size.y - viewportH) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glViewport(viewportX, viewportY, viewportW, viewportH);
|
||||||
|
|
||||||
minu = 0.0f;
|
// Configurar la proyección ortográfica usando el espacio lógico
|
||||||
maxu = 1.0f;
|
glMatrixMode(GL_PROJECTION);
|
||||||
minv = 0.0f;
|
glLoadIdentity();
|
||||||
maxv = 1.0f;
|
|
||||||
|
|
||||||
glViewport(0, 0, win_size.x, win_size.y);
|
// Queremos que el origen esté en la esquina superior izquierda del espacio lógico.
|
||||||
|
glOrtho(0, static_cast<GLdouble>(logicalW), static_cast<GLdouble>(logicalH), 0, -1, 1);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
// Dibuja el quad con las coordenadas ajustadas.
|
||||||
|
// Se asignan las coordenadas de textura "normales" para que no quede espejado horizontalmente,
|
||||||
|
// y se mantiene el flip vertical para que la imagen no aparezca volteada.
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
glTexCoord2f(minu, minv);
|
// Vértice superior izquierdo
|
||||||
glVertex2f(minx, miny);
|
glTexCoord2f(0.0f, 1.0f);
|
||||||
glTexCoord2f(maxu, minv);
|
glVertex2f(0.0f, 0.0f);
|
||||||
glVertex2f(maxx, miny);
|
// Vértice superior derecho
|
||||||
glTexCoord2f(minu, maxv);
|
glTexCoord2f(1.0f, 1.0f);
|
||||||
glVertex2f(minx, maxy);
|
glVertex2f(static_cast<GLfloat>(logicalW), 0.0f);
|
||||||
glTexCoord2f(maxu, maxv);
|
// Vértice inferior izquierdo
|
||||||
glVertex2f(maxx, maxy);
|
glTexCoord2f(0.0f, 0.0f);
|
||||||
|
glVertex2f(0.0f, static_cast<GLfloat>(logicalH));
|
||||||
|
// Vértice inferior derecho
|
||||||
|
glTexCoord2f(1.0f, 0.0f);
|
||||||
|
glVertex2f(static_cast<GLfloat>(logicalW), static_cast<GLfloat>(logicalH));
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
SDL_GL_SwapWindow(win);
|
SDL_GL_SwapWindow(win);
|
||||||
|
|
||||||
if (programId != 0)
|
if (programId != 0)
|
||||||
@@ -241,7 +287,7 @@ namespace shader
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_RenderCopy(renderer, backBuffer, NULL, NULL);
|
SDL_RenderCopy(renderer, backBuffer, nullptr, nullptr);
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // para SDL_Texture
|
#include <SDL2/SDL_render.h> // Para SDL_Texture
|
||||||
#include <SDL2/SDL_video.h> // para SDL_Window
|
#include <SDL2/SDL_video.h> // Para SDL_Window
|
||||||
|
#include <string>
|
||||||
|
|
||||||
// TIPS:
|
// TIPS:
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
@@ -38,8 +39,7 @@
|
|||||||
|
|
||||||
namespace shader
|
namespace shader
|
||||||
{
|
{
|
||||||
const bool init(SDL_Window *win, SDL_Texture *backBuffer,
|
// const bool init(SDL_Window *ventana, SDL_Texture *texturaBackBuffer, const char *vertexShader, const char *fragmentShader = nullptr);
|
||||||
const char *vertexShader, const char *fragmentShader = nullptr);
|
bool init(SDL_Window *ventana, SDL_Texture *texturaBackBuffer, const std::string &vertexShader, const std::string &fragmentShader = "");
|
||||||
|
|
||||||
void render();
|
void render();
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,17 @@
|
|||||||
#include "loading_screen.h"
|
#include "loading_screen.h"
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <stdlib.h> // Para rand
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include "defines.h" // Para GAME_SPEED
|
||||||
#include <stdlib.h> // for rand
|
#include "global_events.h" // Para check
|
||||||
#include <iostream> // for char_traits, basic_ostream, operator<<
|
#include "global_inputs.h" // Para check
|
||||||
#include "defines.h" // for GAME_SPEED
|
#include "jail_audio.h" // Para JA_PlayMusic, JA_SetVolume, JA_StopMusic
|
||||||
#include "global_events.h" // for check
|
#include "options.h" // Para Options, options, SectionState, Options...
|
||||||
#include "global_inputs.h" // for check
|
#include "resource.h" // Para Resource
|
||||||
#include "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Section...
|
#include "screen.h" // Para Screen
|
||||||
#include "resource.h" // for Resource
|
#include "surface.h" // Para Surface
|
||||||
#include "screen.h" // for Screen
|
#include "utils.h" // Para stringToColor, PaletteColor
|
||||||
#include "s_sprite.h" // for SSprite
|
|
||||||
#include "surface.h" // for Texture
|
|
||||||
#include "utils.h" // for Color, stringToColor, Palette
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
LoadingScreen::LoadingScreen()
|
LoadingScreen::LoadingScreen()
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <memory> // Para shared_ptr
|
||||||
#include <memory> // for shared_ptr
|
class SSprite; // lines 7-7
|
||||||
class SSprite; // lines 11-11
|
class Surface; // lines 8-8
|
||||||
class Surface; // lines 12-12
|
|
||||||
|
|
||||||
class LoadingScreen
|
class LoadingScreen
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <string> // for basic_string, string
|
#include "defines.h" // Para GAME_SPEED
|
||||||
#include "defines.h" // for GAME_SPEED
|
#include "global_events.h" // Para check
|
||||||
#include "global_events.h" // for check
|
#include "global_inputs.h" // Para check
|
||||||
#include "global_inputs.h" // for check
|
#include "options.h" // Para Options, SectionState, options, Section
|
||||||
#include "jail_audio.h" // for JA_StopMusic
|
#include "resource.h" // Para Resource
|
||||||
#include "options.h" // for Options, options, SectionState, Section
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "resource.h" // for Resource
|
#include "screen.h" // Para Screen
|
||||||
#include "screen.h" // for Screen
|
#include "surface.h" // Para Surface
|
||||||
#include "s_sprite.h" // for SSprite
|
#include "utils.h" // Para PaletteColor
|
||||||
#include "surface.h" // for Texture
|
|
||||||
#include "utils.h" // for Color, stringToColor
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "utils.h" // for Color
|
class SSprite; // lines 7-7
|
||||||
class SSprite; // lines 12-12
|
class Surface; // lines 8-8
|
||||||
class Surface; // lines 13-13
|
|
||||||
|
|
||||||
class Logo
|
class Logo
|
||||||
{
|
{
|
||||||
@@ -20,8 +19,8 @@ private:
|
|||||||
std::shared_ptr<Surface> since_1998_surface_; // Textura con los graficos "Since 1998"
|
std::shared_ptr<Surface> since_1998_surface_; // Textura con los graficos "Since 1998"
|
||||||
std::vector<std::shared_ptr<SSprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
std::vector<std::shared_ptr<SSprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
std::shared_ptr<SSprite> since_1998_sprite_; // SSprite para manejar la textura2
|
std::shared_ptr<SSprite> since_1998_sprite_; // SSprite para manejar la textura2
|
||||||
Uint8 jailgames_color_ = 0; // Color para el sprite de "JAILGAMES"
|
Uint8 jailgames_color_ = 0; // Color para el sprite de "JAILGAMES"
|
||||||
Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998"
|
Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998"
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<Uint8> color_; // Vector con los colores para el fade
|
std::vector<Uint8> color_; // Vector con los colores para el fade
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#include "notifier.h"
|
#include "notifier.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <algorithm> // Para remove_if
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RenderFillRect, SDL_RenderClear
|
#include <iterator> // Para prev
|
||||||
#include <algorithm> // for remove_if
|
#include <string> // Para string, basic_string
|
||||||
#include <string> // for string, basic_string
|
#include <vector> // Para vector
|
||||||
#include <vector> // for vector
|
#include "jail_audio.h" // Para JA_PlaySound
|
||||||
#include "jail_audio.h" // for JA_PlaySound
|
#include "options.h" // Para Options, options, NotificationPosition
|
||||||
#include "options.h" // for Options, options, OptionsNotification
|
#include "resource.h" // Para Resource
|
||||||
#include "resource.h" // for Resource
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "screen.h" // for Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "s_sprite.h" // for SSprite
|
#include "surface.h" // Para Surface
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "surface.h" // for Surface
|
#include "utils.h" // Para PaletteColor
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Notifier *Notifier::notifier_ = nullptr;
|
Notifier *Notifier::notifier_ = nullptr;
|
||||||
@@ -59,8 +59,8 @@ void Notifier::update()
|
|||||||
// Si la notificación anterior está "saliendo", no hagas nada
|
// Si la notificación anterior está "saliendo", no hagas nada
|
||||||
if (!notifications_.empty() && ¬ification != ¬ifications_.front())
|
if (!notifications_.empty() && ¬ification != ¬ifications_.front())
|
||||||
{
|
{
|
||||||
auto &previous_notification = *(std::prev(¬ification));
|
const auto &PREVIOUS_NOTIFICATION = *(std::prev(¬ification));
|
||||||
if (previous_notification.state == NotificationStatus::RISING)
|
if (PREVIOUS_NOTIFICATION.state == NotificationStatus::RISING)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -236,8 +236,8 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
|
|||||||
else if (SHAPE == NotificationShape::SQUARED)
|
else if (SHAPE == NotificationShape::SQUARED)
|
||||||
{
|
{
|
||||||
n.surface->clear(bg_color_);
|
n.surface->clear(bg_color_);
|
||||||
SDL_Rect rect = {0, 0, n.surface->getWidth(), n.surface->getHeight()};
|
SDL_Rect squared_rect = {0, 0, n.surface->getWidth(), n.surface->getHeight()};
|
||||||
n.surface->drawRectBorder(&rect, static_cast<Uint8>(PaletteColor::CYAN));
|
n.surface->drawRectBorder(&squared_rect, static_cast<Uint8>(PaletteColor::CYAN));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el icono de la notificación
|
// Dibuja el icono de la notificación
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <memory> // for shared_ptr
|
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||||
#include <string> // for string, basic_string
|
#include <memory> // Para shared_ptr
|
||||||
#include <vector> // for vector
|
#include <string> // Para string, basic_string
|
||||||
#include "utils.h" // for Color
|
#include <vector> // Para vector
|
||||||
class SSprite; // lines 9-9
|
class SSprite; // lines 8-8
|
||||||
class Text; // lines 10-10
|
class Surface; // lines 10-10
|
||||||
class Surface; // lines 11-11
|
class Text; // lines 9-9
|
||||||
|
|
||||||
// Constantes
|
// Constantes
|
||||||
constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000;
|
constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN_DESKTOP
|
#include <SDL2/SDL_video.h> // Para SDL_WINDOW_FULLSCREEN_DESKTOP
|
||||||
#include <algorithm> // for find_if
|
#include <algorithm> // Para find_if
|
||||||
#include <cctype> // for isspace
|
#include <cctype> // Para isspace
|
||||||
#include <fstream> // for basic_ostream, operator<<, basic_ofstream
|
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
|
||||||
#include <functional> // for function
|
#include <functional> // Para function
|
||||||
#include <iostream> // for cout, cerr
|
#include <iostream> // Para cout, cerr
|
||||||
#include <sstream> // for basic_istringstream
|
#include <sstream> // Para basic_istringstream
|
||||||
#include <string> // for char_traits, string, operator<<, hash
|
#include <string> // Para char_traits, string, operator<<, hash
|
||||||
#include <unordered_map> // for unordered_map, operator==, _Node_const_i...
|
#include <unordered_map> // Para unordered_map, operator==, _Node_const_i...
|
||||||
#include <utility> // for pair
|
#include <utility> // Para pair
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Options options;
|
Options options;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <string> // for string, basic_string
|
#include <string> // Para string, basic_string
|
||||||
#include "screen.h" // for ScreenFilter
|
#include "screen.h" // Para ScreenFilter
|
||||||
#include "utils.h" // for Color, Palette
|
#include "utils.h" // Para Color, Palette
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
// Secciones del programa
|
// Secciones del programa
|
||||||
@@ -81,7 +81,7 @@ constexpr Subsection DEFAULT_SUBSECTION = Subsection::LOGO_TO_INTRO;
|
|||||||
constexpr ControlScheme DEFAULT_CONTROL_SCHEME = ControlScheme::CURSOR; // Control por defecto
|
constexpr ControlScheme DEFAULT_CONTROL_SCHEME = ControlScheme::CURSOR; // Control por defecto
|
||||||
constexpr NotificationPosition DEFAULT_NOTIFICATION_POSITION = NotificationPosition::UPPER_LEFT; // Posición de las notificaciones por defecto
|
constexpr NotificationPosition DEFAULT_NOTIFICATION_POSITION = NotificationPosition::UPPER_LEFT; // Posición de las notificaciones por defecto
|
||||||
constexpr bool DEFAULT_NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
|
constexpr bool DEFAULT_NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
|
||||||
const Uint8 DEFAULT_NOTIFICATION_COLOR = static_cast<Uint8>(PaletteColor::BLUE); // Color de las notificaciones por defecto
|
const Uint8 DEFAULT_NOTIFICATION_COLOR = static_cast<Uint8>(PaletteColor::BLUE); // Color de las notificaciones por defecto
|
||||||
constexpr bool DEFAULT_CONSOLE = false; // Consola desactivada por defecto
|
constexpr bool DEFAULT_CONSOLE = false; // Consola desactivada por defecto
|
||||||
constexpr const char *DEFAULT_VERSION = "1.10"; // Versión por defecto
|
constexpr const char *DEFAULT_VERSION = "1.10"; // Versión por defecto
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ struct OptionsStats
|
|||||||
worst_nightmare("") {}
|
worst_nightmare("") {}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
OptionsStats(int r, int i, const std::string wn)
|
OptionsStats(int r, int i, const std::string& wn)
|
||||||
: rooms(r),
|
: rooms(r),
|
||||||
items(i),
|
items(i),
|
||||||
worst_nightmare(wn) {}
|
worst_nightmare(wn) {}
|
||||||
@@ -279,7 +279,7 @@ struct OptionsVideo
|
|||||||
palette(DEFAULT_PALETTE) {}
|
palette(DEFAULT_PALETTE) {}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, std::string p)
|
OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, const std::string &p)
|
||||||
: mode(m),
|
: mode(m),
|
||||||
filter(f),
|
filter(f),
|
||||||
vertical_sync(vs),
|
vertical_sync(vs),
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
// IWYU pragma: no_include <bits/std_abs.h>
|
// IWYU pragma: no_include <bits/std_abs.h>
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include <stdlib.h> // for rand
|
#include <algorithm> // Para max, min
|
||||||
#include <algorithm> // for max, min
|
#include <cmath> // Para ceil, abs
|
||||||
#include <cmath> // for ceil, abs
|
#include "debug.h" // Para Debug
|
||||||
#include "s_animated_sprite.h" // for SAnimatedSprite
|
#include "defines.h" // Para BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT
|
||||||
#include "debug.h" // for Debug
|
#include "input.h" // Para Input, InputAction
|
||||||
#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT
|
#include "jail_audio.h" // Para JA_PlaySound
|
||||||
#include "input.h" // for Input, InputAction
|
#include "options.h" // Para Cheat, Options, options
|
||||||
#include "jail_audio.h" // for JA_PlaySound
|
#include "resource.h" // Para Resource
|
||||||
#include "options.h" // for Options, options, Cheat, OptionsVideo
|
#include "room.h" // Para Room, TileType
|
||||||
#include "resource.h" // for Resource
|
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "room.h" // for Room, JA_Sound_t, TileType
|
|
||||||
#include "screen.h" // for Screen
|
|
||||||
#include "surface.h" // for Texture
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(const PlayerData &player)
|
Player::Player(const PlayerData &player)
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE
|
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_NONE
|
||||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <string> // for string
|
#include <memory> // Para shared_ptr, __shared_ptr_access
|
||||||
#include <vector> // for vector
|
#include <string> // Para string
|
||||||
#include "s_animated_sprite.h" // for SAnimatedSprite
|
#include <vector> // Para vector
|
||||||
#include "defines.h" // for BORDER_TOP, BLOCK
|
#include "defines.h" // Para BORDER_TOP, BLOCK
|
||||||
#include "surface.h" // for Texture
|
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // Para Color
|
||||||
class Room; // lines 16-16
|
class Room; // lines 12-12
|
||||||
struct JA_Sound_t; // lines 17-17
|
struct JA_Sound_t; // lines 13-13
|
||||||
|
|
||||||
enum class PlayerState
|
enum class PlayerState
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
|
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
|
||||||
std::shared_ptr<SAnimatedSprite> sprite_; // Sprite del jugador
|
std::shared_ptr<SAnimatedSprite> sprite_; // Sprite del jugador
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||||
#include <SDL2/SDL_keycode.h> // for SDLK_ESCAPE
|
#include <SDL2/SDL_keycode.h> // Para SDLK_ESCAPE
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RenderDrawRect, SDL_RenderFillRect
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <stdlib.h> // for exit, size_t
|
#include <stdlib.h> // Para exit, size_t
|
||||||
#include <algorithm> // for find_if
|
#include <algorithm> // Para find_if
|
||||||
#include <iostream> // for basic_ostream, operator<<, endl, cout
|
#include <iostream> // Para basic_ostream, operator<<, endl, cout
|
||||||
#include <stdexcept> // for runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include "asset.h" // for AssetType, Asset
|
#include "asset.h" // Para AssetType, Asset
|
||||||
#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa...
|
#include "jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
|
||||||
#include "options.h" // for Options, OptionsGame, options
|
#include "options.h" // Para Options, OptionsGame, options
|
||||||
#include "screen.h" // for Screen
|
#include "room.h" // Para RoomData, loadRoomFile, loadRoomTileFile
|
||||||
#include "text.h" // for Text, loadTextFile
|
#include "screen.h" // Para Screen
|
||||||
#include "utils.h" // for getFileName, printWithDots, Color
|
#include "text.h" // Para Text, loadTextFile
|
||||||
#include "room.h"
|
#include "utils.h" // Para getFileName, printWithDots, PaletteColor
|
||||||
struct JA_Music_t; // lines 12-12
|
struct JA_Music_t; // lines 17-17
|
||||||
struct JA_Sound_t; // lines 13-13
|
struct JA_Sound_t; // lines 18-18
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Resource *Resource::resource_ = nullptr;
|
Resource *Resource::resource_ = nullptr;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "s_animated_sprite.h" // for AnimationsFileBuffer
|
#include "s_animated_sprite.h" // Para AnimationsFileBuffer
|
||||||
#include "room.h" // for room_t
|
#include "room.h" // Para room_t
|
||||||
#include "text.h" // for Text, TextFile
|
#include "text.h" // Para Text, TextFile
|
||||||
#include "surface.h" // for Surface
|
#include "surface.h" // Para Surface
|
||||||
struct JA_Music_t; // lines 11-11
|
struct JA_Music_t; // lines 11-11
|
||||||
struct JA_Sound_t; // lines 12-12
|
struct JA_Sound_t; // lines 12-12
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ private:
|
|||||||
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||||
std::vector<ResourceSurface> surfaces_; // Vector con las surfaces
|
std::vector<ResourceSurface> surfaces_; // Vector con las surfaces
|
||||||
std::vector<ResourcePalette> palettes_; // Vector con las paletas
|
std::vector<ResourcePalette> palettes_; // Vector con las paletas
|
||||||
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
std::vector<ResourceTextFile> text_files_; // Vector con los ficheros de texto
|
||||||
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
std::vector<ResourceText> texts_; // Vector con los objetos de texto
|
||||||
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
std::vector<ResourceAnimation> animations_; // Vector con las animaciones
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <exception> // Para exception
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <fstream> // Para basic_ostream, operator<<, basic_istream
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <iostream> // Para cout, cerr
|
||||||
#include <stdlib.h> // for rand
|
#include <sstream> // Para basic_stringstream
|
||||||
#include <exception> // for exception
|
#include "debug.h" // Para Debug
|
||||||
#include <fstream> // for basic_ostream, operator<<, basic_ist...
|
#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH
|
||||||
#include <iostream> // for cout, cerr
|
#include "item_tracker.h" // Para ItemTracker
|
||||||
#include <sstream> // for basic_stringstream
|
#include "jail_audio.h" // Para JA_PlaySound
|
||||||
#include "debug.h" // for Debug
|
#include "options.h" // Para Options, OptionsStats, options
|
||||||
#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W...
|
#include "resource.h" // Para Resource
|
||||||
#include "item_tracker.h" // for ItemTracker
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "jail_audio.h" // for JA_PlaySound
|
#include "scoreboard.h" // Para ScoreboardData
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Opti...
|
#include "screen.h" // Para Screen
|
||||||
#include "resource.h" // for Resource
|
#include "surface.h" // Para Surface
|
||||||
#include "scoreboard.h" // for ScoreboardData
|
#include "utils.h" // Para LineHorizontal, LineDiagonal, LineVertical
|
||||||
#include "screen.h" // for Screen
|
|
||||||
#include "s_sprite.h" // for SSprite
|
|
||||||
#include "surface.h" // for Texture
|
|
||||||
#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe...
|
|
||||||
|
|
||||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||||
std::vector<int> loadRoomTileFile(const std::string &file_path, bool verbose)
|
std::vector<int> loadRoomTileFile(const std::string &file_path, bool verbose)
|
||||||
@@ -474,7 +470,7 @@ void Room::initializeRoom(const RoomData &room)
|
|||||||
void Room::fillMapTexture()
|
void Room::fillMapTexture()
|
||||||
{
|
{
|
||||||
const Uint8 color = stringToColor(bg_color_);
|
const Uint8 color = stringToColor(bg_color_);
|
||||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||||
Screen::get()->setRendererSurface(map_surface_);
|
Screen::get()->setRendererSurface(map_surface_);
|
||||||
map_surface_->clear(color);
|
map_surface_->clear(color);
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "enemy.h" // for EnemyData
|
#include "enemy.h" // Para EnemyData
|
||||||
#include "item.h" // for ItemData
|
#include "item.h" // Para ItemData
|
||||||
#include "options.h" // for Options, OptionsVideo, options
|
#include "utils.h" // Para LineHorizontal, LineDiagonal, LineVertical
|
||||||
#include "utils.h" // for stringToColor, Color
|
class SSprite; // lines 12-12
|
||||||
class SSprite; // lines 17-17
|
class Surface; // lines 13-13
|
||||||
class Surface; // lines 18-18
|
struct ScoreboardData; // lines 15-15
|
||||||
struct JA_Sound_t; // lines 19-19
|
|
||||||
struct ScoreboardData; // lines 20-20
|
|
||||||
|
|
||||||
enum class TileType
|
enum class TileType
|
||||||
{
|
{
|
||||||
@@ -96,7 +94,6 @@ private:
|
|||||||
std::string tile_map_file_; // Fichero con el mapa de indices de tile
|
std::string tile_map_file_; // Fichero con el mapa de indices de tile
|
||||||
std::vector<int> tile_map_; // Indice de los tiles a dibujar en la habitación
|
std::vector<int> tile_map_; // Indice de los tiles a dibujar en la habitación
|
||||||
int conveyor_belt_direction_; // Sentido en el que arrastran las superficies automáticas de la habitación
|
int conveyor_belt_direction_; // Sentido en el que arrastran las superficies automáticas de la habitación
|
||||||
JA_Sound_t *item_sound_; // Sonido producido al coger un objeto
|
|
||||||
std::vector<LineHorizontal> bottom_floors_; // Lista con las superficies inferiores de la habitación
|
std::vector<LineHorizontal> bottom_floors_; // Lista con las superficies inferiores de la habitación
|
||||||
std::vector<LineHorizontal> top_floors_; // Lista con las superficies superiores de la habitación
|
std::vector<LineHorizontal> top_floors_; // Lista con las superficies superiores de la habitación
|
||||||
std::vector<LineVertical> left_walls_; // Lista con las superficies laterales de la parte izquierda de la habitación
|
std::vector<LineVertical> left_walls_; // Lista con las superficies laterales de la parte izquierda de la habitación
|
||||||
@@ -161,7 +158,7 @@ public:
|
|||||||
~Room() = default;
|
~Room() = default;
|
||||||
|
|
||||||
// Devuelve el nombre de la habitación
|
// Devuelve el nombre de la habitación
|
||||||
std::string getName() const { return name_; }
|
const std::string &getName() const { return name_; }
|
||||||
|
|
||||||
// Devuelve el color de la habitación
|
// Devuelve el color de la habitación
|
||||||
Uint8 getBGColor() const { return stringToColor(bg_color_); }
|
Uint8 getBGColor() const { return stringToColor(bg_color_); }
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
: SMovingSprite(surface) {}
|
: SMovingSprite(surface) {}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
virtual ~SAnimatedSprite() = default;
|
virtual ~SAnimatedSprite() override = default;
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "s_moving_sprite.h"
|
#include "s_moving_sprite.h"
|
||||||
#include "surface.h" // for Surface
|
#include "surface.h" // Para Surface
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos, SDL_RendererFlip flip)
|
SMovingSprite::SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos, SDL_RendererFlip flip)
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_HORIZONTAL
|
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_HORIZONTAL
|
||||||
#include <algorithm> // for max
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include "s_sprite.h" // for SSprite
|
#include "s_sprite.h" // Para SSprite
|
||||||
class Surface; // lines 9-9
|
class Surface; // lines 8-8
|
||||||
|
|
||||||
// Clase SMovingSprite. Añade movimiento y flip al sprite
|
// Clase SMovingSprite. Añade movimiento y flip al sprite
|
||||||
class SMovingSprite : public SSprite
|
class SMovingSprite : public SSprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float x_; // Posición en el eje X
|
float x_; // Posición en el eje X
|
||||||
float y_; // Posición en el eje Y
|
float y_; // Posición en el eje Y
|
||||||
@@ -34,7 +33,7 @@ public:
|
|||||||
explicit SMovingSprite(std::shared_ptr<Surface> surface);
|
explicit SMovingSprite(std::shared_ptr<Surface> surface);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
virtual ~SMovingSprite() = default;
|
virtual ~SMovingSprite() override = default;
|
||||||
|
|
||||||
// Actualiza las variables internas del objeto
|
// Actualiza las variables internas del objeto
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include <memory> // Para shared_ptr
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
class Surface;
|
#include <memory> // Para shared_ptr
|
||||||
|
class Surface; // lines 5-5
|
||||||
|
|
||||||
// Clase SSprite
|
// Clase SSprite
|
||||||
class SSprite
|
class SSprite
|
||||||
|
|||||||
@@ -1,27 +1,25 @@
|
|||||||
#include "scoreboard.h"
|
#include "scoreboard.h"
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include "defines.h" // Para BLOCK
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include "options.h" // Para Options, options, Cheat, OptionsGame
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include "resource.h" // Para Resource
|
||||||
#include "s_animated_sprite.h" // for SAnimatedSprite
|
#include "s_animated_sprite.h" // Para SAnimatedSprite
|
||||||
#include "defines.h" // for BLOCK
|
#include "screen.h" // Para Screen
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Cheat
|
#include "surface.h" // Para Surface
|
||||||
#include "resource.h" // for Resource
|
#include "text.h" // Para Text
|
||||||
#include "screen.h" // for Screen
|
#include "utils.h" // Para stringToColor
|
||||||
#include "text.h" // for Text
|
|
||||||
#include "surface.h" // for Texture
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||||
: data_(data),
|
: item_surface_(Resource::get()->getSurface("items.gif")),
|
||||||
|
data_(data),
|
||||||
clock_(ClockData())
|
clock_(ClockData())
|
||||||
{
|
{
|
||||||
const int SURFACE_WIDTH_ = options.game.width;
|
const int SURFACE_WIDTH_ = options.game.width;
|
||||||
constexpr int SURFACE_HEIGHT_ = 6 * BLOCK;
|
constexpr int SURFACE_HEIGHT_ = 6 * BLOCK;
|
||||||
|
|
||||||
// Reserva memoria para los objetos
|
// Reserva memoria para los objetos
|
||||||
item_surface_ = Resource::get()->getSurface("items.gif");
|
|
||||||
auto player_texture = Resource::get()->getSurface(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif");
|
auto player_texture = Resource::get()->getSurface(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif");
|
||||||
auto player_animations = Resource::get()->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani");
|
auto player_animations = Resource::get()->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani");
|
||||||
player_sprite_ = std::make_shared<SAnimatedSprite>(player_texture, player_animations);
|
player_sprite_ = std::make_shared<SAnimatedSprite>(player_texture, player_animations);
|
||||||
@@ -136,7 +134,7 @@ int Scoreboard::getMinutes()
|
|||||||
void Scoreboard::fillTexture()
|
void Scoreboard::fillTexture()
|
||||||
{
|
{
|
||||||
// Empieza a dibujar en la textura
|
// Empieza a dibujar en la textura
|
||||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
auto previuos_renderer = Screen::get()->getRendererSurface();
|
||||||
Screen::get()->setRendererSurface(surface_);
|
Screen::get()->setRendererSurface(surface_);
|
||||||
|
|
||||||
// Limpia la textura
|
// Limpia la textura
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <memory> // Para shared_ptr
|
||||||
#include <memory> // for shared_ptr
|
#include <string> // Para string, basic_string
|
||||||
#include <string> // for string, basic_string
|
#include <vector> // Para vector
|
||||||
#include <vector> // for vector
|
class SAnimatedSprite; // lines 10-10
|
||||||
#include "utils.h" // for Color
|
class Surface; // lines 11-11
|
||||||
class SAnimatedSprite; // lines 9-9
|
|
||||||
class Surface; // lines 13-13
|
|
||||||
|
|
||||||
struct ScoreboardData
|
struct ScoreboardData
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,19 +2,20 @@
|
|||||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <SDL2/SDL_events.h> // Para SDL_DISABLE, SDL_ENABLE
|
#include <SDL2/SDL_events.h> // Para SDL_DISABLE, SDL_ENABLE
|
||||||
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORM...
|
||||||
#include <algorithm> // Para max, min
|
#include <ctype.h> // Para toupper
|
||||||
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream
|
#include <algorithm> // Para max, min, transform
|
||||||
#include <iostream> // Para cout
|
#include <fstream> // Para basic_ostream, operator<<, endl, basic_...
|
||||||
#include <iterator> // Para istreambuf_iterator, operator!=
|
#include <iostream> // Para cerr
|
||||||
#include <string> // Para basic_string, char_traits, string
|
#include <iterator> // Para istreambuf_iterator, operator==
|
||||||
#include "asset.h" // Para Asset
|
#include <string> // Para char_traits, string, operator+, operator==
|
||||||
|
#include "asset.h" // Para Asset, AssetType
|
||||||
#include "jail_shader.h" // Para init, render
|
#include "jail_shader.h" // Para init, render
|
||||||
#include "notifier.h" // Para Notify
|
#include "mouse.h" // Para updateCursorVisibility
|
||||||
#include "options.h"
|
#include "notifier.h" // Para Notifier
|
||||||
#include "mouse.h"
|
#include "options.h" // Para Options, options, OptionsVideo, Border
|
||||||
#include "surface.h"
|
#include "resource.h" // Para Resource
|
||||||
#include "resource.h"
|
#include "surface.h" // Para Surface, readPalFile
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Screen *Screen::screen_ = nullptr;
|
Screen *Screen::screen_ = nullptr;
|
||||||
@@ -334,7 +335,7 @@ void Screen::resetShaders()
|
|||||||
std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
|
std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
|
||||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
shader::init(window_, shaders_texture_, source.c_str());
|
shader::init(window_, shaders_texture_, source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
#include <SDL2/SDL_video.h> // Para SDL_Window
|
||||||
#include "utils.h" // for Color
|
#include <stddef.h> // Para size_t
|
||||||
#include "surface.h" // for Surface
|
#include <memory> // Para shared_ptr, __shared_ptr_access
|
||||||
#include <memory> // for shared_ptr
|
#include <string> // Para string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
#include "utils.h" // Para Color
|
||||||
|
class Surface;
|
||||||
|
|
||||||
// Tipos de filtro
|
// Tipos de filtro
|
||||||
enum class ScreenFilter : Uint32
|
enum class ScreenFilter : Uint32
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
|
#include <fstream> // Para basic_ostream, basic_ifstream, basic_istream
|
||||||
#include <sstream> // for basic_stringstream
|
#include <sstream> // Para basic_stringstream
|
||||||
#include "options.h" // for Options, OptionsStats, options
|
#include "options.h" // Para Options, OptionsStats, options
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Stats::Stats(const std::string &file, const std::string &buffer)
|
Stats::Stats(const std::string &file, const std::string &buffer)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
class Stats
|
class Stats
|
||||||
{
|
{
|
||||||
@@ -21,10 +21,10 @@ private:
|
|||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<StatsDictionary> dictionary; // Lista con la equivalencia nombre-numero de habitacion
|
std::vector<StatsDictionary> dictionary; // Lista con la equivalencia nombre-numero de habitacion
|
||||||
std::vector<StatsData> bufferList; // Lista con las estadisticas temporales por habitación
|
std::vector<StatsData> bufferList; // Lista con las estadisticas temporales por habitación
|
||||||
std::vector<StatsData> list; // Lista con las estadisticas completas por habitación
|
std::vector<StatsData> list; // Lista con las estadisticas completas por habitación
|
||||||
std::string bufferPath; // Fichero con las estadísticas temporales
|
std::string bufferPath; // Fichero con las estadísticas temporales
|
||||||
std::string filePath; // Fichero con las estadísticas completas
|
std::string filePath; // Fichero con las estadísticas completas
|
||||||
|
|
||||||
// Busca una entrada en la lista por nombre
|
// Busca una entrada en la lista por nombre
|
||||||
int findByName(const std::string &name, const std::vector<StatsData> &list);
|
int findByName(const std::string &name, const std::vector<StatsData> &list);
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <stddef.h> // for size_t
|
#include <bits/std_abs.h> // Para abs
|
||||||
#include <algorithm> // for min, copy, fill
|
#include <stdlib.h> // Para abs
|
||||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_ios
|
#include <algorithm> // Para min, max, copy_n, fill
|
||||||
#include <iostream> // for cerr, cout
|
#include <cstdint> // Para uint32_t
|
||||||
#include <memory> // for shared_ptr, __shared_ptr_access, unique_ptr
|
#include <cstring> // Para memcpy, size_t
|
||||||
#include <stdexcept> // for runtime_error
|
#include <fstream> // Para basic_ifstream, basic_ostream, basic_ist...
|
||||||
#include <vector> // for vector
|
#include <iostream> // Para cerr
|
||||||
#include "asset.h" // for Asset
|
#include <memory> // Para shared_ptr, __shared_ptr_access, default...
|
||||||
#include "screen.h"
|
#include <sstream> // Para basic_istringstream
|
||||||
#include "gif.h" // for LoadGif, LoadPalette
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <iostream>
|
#include <vector> // Para vector
|
||||||
#include <fstream>
|
#include "gif.h" // Para Gif
|
||||||
#include <sstream>
|
#include "screen.h" // Para Screen
|
||||||
#include <array>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
// Carga una paleta desde un archivo .gif
|
// Carga una paleta desde un archivo .gif
|
||||||
Palette loadPalette(const std::string &file_path)
|
Palette loadPalette(const std::string &file_path)
|
||||||
@@ -27,7 +24,7 @@ Palette loadPalette(const std::string &file_path)
|
|||||||
throw std::runtime_error("Error opening file: " + file_path);
|
throw std::runtime_error("Error opening file: " + file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leer el contenido del archivo en un buffer
|
// Obtener el tamaño del archivo y leerlo en un buffer
|
||||||
std::streamsize size = file.tellg();
|
std::streamsize size = file.tellg();
|
||||||
file.seekg(0, std::ios::beg);
|
file.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
@@ -38,15 +35,16 @@ Palette loadPalette(const std::string &file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cargar la paleta usando los datos del buffer
|
// Cargar la paleta usando los datos del buffer
|
||||||
std::unique_ptr<Uint32[]> pal(LoadPalette(buffer.data()));
|
GIF::Gif gif;
|
||||||
if (pal == nullptr)
|
std::vector<uint32_t> pal = gif.loadPalette(buffer.data());
|
||||||
|
if (pal.empty())
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Error loading palette from file: " + file_path);
|
throw std::runtime_error("No palette found in GIF file: " + file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crear la paleta y copiar los datos
|
// Crear la paleta y copiar los datos desde 'pal'
|
||||||
Palette palette;
|
Palette palette = {}; // Inicializa la paleta con ceros
|
||||||
std::copy(pal.get(), pal.get() + palette.size(), palette.begin());
|
std::copy_n(pal.begin(), std::min(pal.size(), palette.size()), palette.begin());
|
||||||
|
|
||||||
// Mensaje de depuración
|
// Mensaje de depuración
|
||||||
printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||||
@@ -118,32 +116,42 @@ Surface::Surface(const std::string &file_path)
|
|||||||
// Carga una superficie desde un archivo
|
// Carga una superficie desde un archivo
|
||||||
SurfaceData Surface::loadSurface(const std::string &file_path)
|
SurfaceData Surface::loadSurface(const std::string &file_path)
|
||||||
{
|
{
|
||||||
|
// Abrir el archivo usando std::ifstream para manejo automático del recurso
|
||||||
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||||
|
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Error opening file: " << file_path << std::endl;
|
std::cerr << "Error opening file: " << file_path << std::endl;
|
||||||
throw std::runtime_error("Error opening file");
|
throw std::runtime_error("Error opening file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtener el tamaño del archivo
|
||||||
std::streamsize size = file.tellg();
|
std::streamsize size = file.tellg();
|
||||||
file.seekg(0, std::ios::beg);
|
file.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
|
// Leer el contenido del archivo en un buffer
|
||||||
std::vector<Uint8> buffer(size);
|
std::vector<Uint8> buffer(size);
|
||||||
if (!file.read((char *)buffer.data(), size))
|
if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
|
||||||
{
|
{
|
||||||
std::cerr << "Error reading file: " << file_path << std::endl;
|
std::cerr << "Error reading file: " << file_path << std::endl;
|
||||||
throw std::runtime_error("Error reading file");
|
throw std::runtime_error("Error reading file");
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16 w, h;
|
// Crear un objeto Gif y llamar a la función loadGif
|
||||||
Uint8 *pixels = LoadGif(buffer.data(), &w, &h);
|
GIF::Gif gif;
|
||||||
if (pixels == nullptr)
|
Uint16 w = 0, h = 0;
|
||||||
|
std::vector<Uint8> rawPixels = gif.loadGif(buffer.data(), w, h);
|
||||||
|
if (rawPixels.empty())
|
||||||
{
|
{
|
||||||
std::cerr << "Error loading GIF from file: " << file_path << std::endl;
|
std::cerr << "Error loading GIF from file: " << file_path << std::endl;
|
||||||
throw std::runtime_error("Error loading GIF");
|
throw std::runtime_error("Error loading GIF");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Si el constructor de Surface espera un std::shared_ptr<Uint8[]>,
|
||||||
|
// reservamos un bloque dinámico y copiamos los datos del vector.
|
||||||
|
size_t pixelCount = rawPixels.size();
|
||||||
|
auto pixels = std::shared_ptr<Uint8[]>(new Uint8[pixelCount], std::default_delete<Uint8[]>());
|
||||||
|
std::memcpy(pixels.get(), rawPixels.data(), pixelCount);
|
||||||
|
|
||||||
// Crear y devolver directamente el objeto SurfaceData
|
// Crear y devolver directamente el objeto SurfaceData
|
||||||
printWithDots("Surface : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
printWithDots("Surface : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
|
||||||
return SurfaceData(w, h, pixels);
|
return SurfaceData(w, h, pixels);
|
||||||
@@ -171,7 +179,8 @@ void Surface::setColor(int index, Uint32 color)
|
|||||||
void Surface::clear(Uint8 color)
|
void Surface::clear(Uint8 color)
|
||||||
{
|
{
|
||||||
const size_t total_pixels = surface_data_->width * surface_data_->height;
|
const size_t total_pixels = surface_data_->width * surface_data_->height;
|
||||||
std::fill(surface_data_->data, surface_data_->data + total_pixels, color);
|
Uint8* data_ptr = surface_data_->data.get(); // Explicitly get a typed pointer
|
||||||
|
std::fill(data_ptr, data_ptr + total_pixels, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone un pixel en la SurfaceData
|
// Pone un pixel en la SurfaceData
|
||||||
@@ -183,14 +192,14 @@ void Surface::putPixel(int x, int y, Uint8 color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int index = x + y * surface_data_->width;
|
const int index = x + y * surface_data_->width;
|
||||||
surface_data_->data[index] = color;
|
surface_data_->data.get()[index] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el color de un pixel de la surface_data
|
// Obtiene el color de un pixel de la surface_data
|
||||||
Uint8 Surface::getPixel(int x, int y) { return surface_data_->data[x + y * surface_data_->width]; }
|
Uint8 Surface::getPixel(int x, int y) { return surface_data_->data.get()[x + y * surface_data_->width]; }
|
||||||
|
|
||||||
// Dibuja un rectangulo relleno
|
// Dibuja un rectangulo relleno
|
||||||
void Surface::fillRect(SDL_Rect *rect, Uint8 color)
|
void Surface::fillRect(const SDL_Rect *rect, Uint8 color)
|
||||||
{
|
{
|
||||||
// Limitar los valores del rectángulo al tamaño de la superficie
|
// Limitar los valores del rectángulo al tamaño de la superficie
|
||||||
int x_start = std::max(0, rect->x);
|
int x_start = std::max(0, rect->x);
|
||||||
@@ -204,13 +213,13 @@ void Surface::fillRect(SDL_Rect *rect, Uint8 color)
|
|||||||
for (int x = x_start; x < x_end; ++x)
|
for (int x = x_start; x < x_end; ++x)
|
||||||
{
|
{
|
||||||
const int index = x + y * surface_data_->width;
|
const int index = x + y * surface_data_->width;
|
||||||
surface_data_->data[index] = color;
|
surface_data_->data.get()[index] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el borde de un rectangulo
|
// Dibuja el borde de un rectangulo
|
||||||
void Surface::drawRectBorder(SDL_Rect *rect, Uint8 color)
|
void Surface::drawRectBorder(const SDL_Rect *rect, Uint8 color)
|
||||||
{
|
{
|
||||||
// Limitar los valores del rectángulo al tamaño de la superficie
|
// Limitar los valores del rectángulo al tamaño de la superficie
|
||||||
int x_start = std::max(0, rect->x);
|
int x_start = std::max(0, rect->x);
|
||||||
@@ -223,11 +232,11 @@ void Surface::drawRectBorder(SDL_Rect *rect, Uint8 color)
|
|||||||
{
|
{
|
||||||
// Borde superior
|
// Borde superior
|
||||||
const int top_index = x + y_start * surface_data_->width;
|
const int top_index = x + y_start * surface_data_->width;
|
||||||
surface_data_->data[top_index] = color;
|
surface_data_->data.get()[top_index] = color;
|
||||||
|
|
||||||
// Borde inferior
|
// Borde inferior
|
||||||
const int bottom_index = x + (y_end - 1) * surface_data_->width;
|
const int bottom_index = x + (y_end - 1) * surface_data_->width;
|
||||||
surface_data_->data[bottom_index] = color;
|
surface_data_->data.get()[bottom_index] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibujar bordes verticales
|
// Dibujar bordes verticales
|
||||||
@@ -235,11 +244,11 @@ void Surface::drawRectBorder(SDL_Rect *rect, Uint8 color)
|
|||||||
{
|
{
|
||||||
// Borde izquierdo
|
// Borde izquierdo
|
||||||
const int left_index = x_start + y * surface_data_->width;
|
const int left_index = x_start + y * surface_data_->width;
|
||||||
surface_data_->data[left_index] = color;
|
surface_data_->data.get()[left_index] = color;
|
||||||
|
|
||||||
// Borde derecho
|
// Borde derecho
|
||||||
const int right_index = (x_end - 1) + y * surface_data_->width;
|
const int right_index = (x_end - 1) + y * surface_data_->width;
|
||||||
surface_data_->data[right_index] = color;
|
surface_data_->data.get()[right_index] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +270,7 @@ void Surface::drawLine(int x1, int y1, int x2, int y2, Uint8 color)
|
|||||||
// Asegúrate de no dibujar fuera de los límites de la superficie
|
// Asegúrate de no dibujar fuera de los límites de la superficie
|
||||||
if (x1 >= 0 && x1 < surface_data_->width && y1 >= 0 && y1 < surface_data_->height)
|
if (x1 >= 0 && x1 < surface_data_->width && y1 >= 0 && y1 < surface_data_->height)
|
||||||
{
|
{
|
||||||
surface_data_->data[x1 + y1 * surface_data_->width] = color;
|
surface_data_->data.get()[x1 + y1 * surface_data_->width] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si alcanzamos el punto final, salimos
|
// Si alcanzamos el punto final, salimos
|
||||||
@@ -298,18 +307,19 @@ void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
|||||||
{
|
{
|
||||||
for (int ix = 0; ix < w; ++ix)
|
for (int ix = 0; ix < w; ++ix)
|
||||||
{
|
{
|
||||||
int src_x = sx + ix;
|
|
||||||
int src_y = sy + iy;
|
|
||||||
int dest_x = dx + ix;
|
|
||||||
int dest_y = dy + iy;
|
|
||||||
|
|
||||||
// Verificar que las coordenadas de destino están dentro de los límites
|
// Verificar que las coordenadas de destino están dentro de los límites
|
||||||
if (dest_x >= 0 && dest_x < surface_data->width && dest_y >= 0 && dest_y < surface_data->height)
|
if (int dest_x = dx + ix; dest_x >= 0 && dest_x < surface_data->width)
|
||||||
{
|
{
|
||||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
if (int dest_y = dy + iy; dest_y >= 0 && dest_y < surface_data->height)
|
||||||
if (color != transparent_color_)
|
|
||||||
{
|
{
|
||||||
surface_data->data[dest_x + dest_y * surface_data->width] = sub_palette_[color];
|
int src_x = sx + ix;
|
||||||
|
int src_y = sy + iy;
|
||||||
|
|
||||||
|
Uint8 color = surface_data_->data.get()[src_x + src_y * surface_data_->width];
|
||||||
|
if (color != transparent_color_)
|
||||||
|
{
|
||||||
|
surface_data->data.get()[dest_x + dest_y * surface_data->width] = sub_palette_[color];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -353,7 +363,7 @@ void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
|
|||||||
if (dest_x >= 0 && dest_x < surface_data_dest->width && dest_y >= 0 && dest_y < surface_data_dest->height)
|
if (dest_x >= 0 && dest_x < surface_data_dest->width && dest_y >= 0 && dest_y < surface_data_dest->height)
|
||||||
{
|
{
|
||||||
// Copia el píxel si no es transparente
|
// Copia el píxel si no es transparente
|
||||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
Uint8 color = surface_data_->data.get()[src_x + src_y * surface_data_->width];
|
||||||
if (color != transparent_color_)
|
if (color != transparent_color_)
|
||||||
{
|
{
|
||||||
surface_data_dest->data[dest_x + dest_y * surface_data_dest->width] = sub_palette_[color];
|
surface_data_dest->data[dest_x + dest_y * surface_data_dest->width] = sub_palette_[color];
|
||||||
@@ -406,14 +416,17 @@ void Surface::render(SDL_Rect *srcRect, SDL_Rect *dstRect, SDL_RendererFlip flip
|
|||||||
int src_y = (flip == SDL_FLIP_VERTICAL) ? (sy + final_height - 1 - iy) : (sy + iy);
|
int src_y = (flip == SDL_FLIP_VERTICAL) ? (sy + final_height - 1 - iy) : (sy + iy);
|
||||||
|
|
||||||
// Coordenadas de destino
|
// Coordenadas de destino
|
||||||
int dest_x = dx + ix;
|
if (int dest_x = dx + ix; dest_x >= 0 && dest_x < surface_data->width)
|
||||||
int dest_y = dy + iy;
|
|
||||||
|
|
||||||
// Copiar el píxel si no es transparente
|
|
||||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
|
||||||
if (color != transparent_color_)
|
|
||||||
{
|
{
|
||||||
surface_data->data[dest_x + dest_y * surface_data->width] = sub_palette_[color];
|
if (int dest_y = dy + iy; dest_y >= 0 && dest_y < surface_data->height)
|
||||||
|
{
|
||||||
|
// Copiar el píxel si no es transparente
|
||||||
|
Uint8 color = surface_data_->data.get()[src_x + src_y * surface_data_->width];
|
||||||
|
if (color != transparent_color_)
|
||||||
|
{
|
||||||
|
surface_data->data[dest_x + dest_y * surface_data->width] = sub_palette_[color];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -454,7 +467,7 @@ void Surface::renderWithColorReplace(int x, int y, Uint8 source_color, Uint8 tar
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copia el píxel si no es transparente
|
// Copia el píxel si no es transparente
|
||||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
Uint8 color = surface_data_->data.get()[src_x + src_y * surface_data_->width];
|
||||||
if (color != transparent_color_)
|
if (color != transparent_color_)
|
||||||
{
|
{
|
||||||
surface_data->data[dest_x + dest_y * surface_data->width] =
|
surface_data->data[dest_x + dest_y * surface_data->width] =
|
||||||
@@ -472,7 +485,7 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||||||
throw std::runtime_error("Renderer or texture is null.");
|
throw std::runtime_error("Renderer or texture is null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surface_data_->width <= 0 || surface_data_->height <= 0 || !surface_data_->data)
|
if (surface_data_->width <= 0 || surface_data_->height <= 0 || !surface_data_->data.get())
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid surface dimensions or data.");
|
throw std::runtime_error("Invalid surface dimensions or data.");
|
||||||
}
|
}
|
||||||
@@ -481,7 +494,7 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||||||
int pitch = 0;
|
int pitch = 0;
|
||||||
|
|
||||||
// Bloquea la textura para modificar los píxeles directamente
|
// Bloquea la textura para modificar los píxeles directamente
|
||||||
if (SDL_LockTexture(texture, nullptr, (void **)&pixels, &pitch) != 0)
|
if (SDL_LockTexture(texture, nullptr, reinterpret_cast<void **>(&pixels), &pitch) != 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to lock texture: " + std::string(SDL_GetError()));
|
throw std::runtime_error("Failed to lock texture: " + std::string(SDL_GetError()));
|
||||||
}
|
}
|
||||||
@@ -497,7 +510,7 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||||||
int texture_index = y * row_stride + x;
|
int texture_index = y * row_stride + x;
|
||||||
int surface_index = y * surface_data_->width + x;
|
int surface_index = y * surface_data_->width + x;
|
||||||
|
|
||||||
pixels[texture_index] = palette_[surface_data_->data[surface_index]];
|
pixels[texture_index] = palette_[surface_data_->data.get()[surface_index]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
#include <SDL2/SDL_render.h> // Para SDL_FLIP_NONE, SDL_RendererFlip, SDL_Re...
|
||||||
#include <array>
|
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
|
||||||
#include <numeric>
|
#include <array> // Para array
|
||||||
#include <memory>
|
#include <memory> // Para default_delete, shared_ptr, __shared_pt...
|
||||||
#include <string>
|
#include <numeric> // Para iota
|
||||||
#include "utils.h"
|
#include <string> // Para string
|
||||||
|
#include <utility> // Para move
|
||||||
|
#include "utils.h" // Para PaletteColor
|
||||||
|
|
||||||
// Alias
|
// Alias
|
||||||
using Palette = std::array<Uint32, 256>;
|
using Palette = std::array<Uint32, 256>;
|
||||||
@@ -20,53 +22,30 @@ Palette readPalFile(const std::string &file_path);
|
|||||||
|
|
||||||
struct SurfaceData
|
struct SurfaceData
|
||||||
{
|
{
|
||||||
Uint8 *data; // Listado de indices de la paleta que conforman la imagen almacenada
|
std::shared_ptr<Uint8[]> data; // Usa std::shared_ptr para gestión automática
|
||||||
Uint16 width; // Ancho de la imagen
|
Uint16 width; // Ancho de la imagen
|
||||||
Uint16 height; // Alto de la imagen
|
Uint16 height; // Alto de la imagen
|
||||||
|
|
||||||
// Constructor por defecto
|
// Constructor por defecto
|
||||||
SurfaceData() : data(nullptr), width(0), height(0) {}
|
SurfaceData() : data(nullptr), width(0), height(0) {}
|
||||||
|
|
||||||
// Constructor que inicializa dimensiones y asigna memoria
|
// Constructor que inicializa dimensiones y asigna memoria
|
||||||
SurfaceData(Uint16 w, Uint16 h)
|
SurfaceData(Uint16 w, Uint16 h)
|
||||||
: data(new Uint8[w * h]()), width(w), height(h) {}
|
: data(std::shared_ptr<Uint8[]>(new Uint8[w * h](), std::default_delete<Uint8[]>())), width(w), height(h) {}
|
||||||
|
|
||||||
// Constructor para inicializar directamente con datos
|
// Constructor para inicializar directamente con datos
|
||||||
SurfaceData(Uint16 w, Uint16 h, Uint8 *pixels)
|
SurfaceData(Uint16 w, Uint16 h, std::shared_ptr<Uint8[]> pixels)
|
||||||
: data(pixels), width(w), height(h) {}
|
: data(std::move(pixels)), width(w), height(h) {}
|
||||||
|
|
||||||
// Destructor para liberar memoria
|
// Constructor de movimiento
|
||||||
~SurfaceData() { delete[] data; }
|
SurfaceData(SurfaceData &&other) noexcept = default;
|
||||||
|
|
||||||
// Evita copias accidentales (opcional para mayor seguridad)
|
// Operador de movimiento
|
||||||
|
SurfaceData &operator=(SurfaceData &&other) noexcept = default;
|
||||||
|
|
||||||
|
// Evita copias accidentales
|
||||||
SurfaceData(const SurfaceData &) = delete;
|
SurfaceData(const SurfaceData &) = delete;
|
||||||
SurfaceData &operator=(const SurfaceData &) = delete;
|
SurfaceData &operator=(const SurfaceData &) = delete;
|
||||||
|
|
||||||
// Permite movimiento para evitar copias costosas
|
|
||||||
SurfaceData(SurfaceData &&other) noexcept
|
|
||||||
: data(other.data), width(other.width), height(other.height)
|
|
||||||
{
|
|
||||||
other.data = nullptr;
|
|
||||||
other.width = 0;
|
|
||||||
other.height = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SurfaceData &operator=(SurfaceData &&other) noexcept
|
|
||||||
{
|
|
||||||
if (this != &other)
|
|
||||||
{
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
data = other.data;
|
|
||||||
width = other.width;
|
|
||||||
height = other.height;
|
|
||||||
|
|
||||||
other.data = nullptr;
|
|
||||||
other.width = 0;
|
|
||||||
other.height = 0;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Surface
|
class Surface
|
||||||
@@ -80,7 +59,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Surface(int w, int h);
|
Surface(int w, int h);
|
||||||
Surface(const std::string &file_path);
|
explicit Surface(const std::string &file_path);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Surface() = default;
|
~Surface() = default;
|
||||||
@@ -120,10 +99,10 @@ public:
|
|||||||
Uint8 getPixel(int x, int y);
|
Uint8 getPixel(int x, int y);
|
||||||
|
|
||||||
// Dibuja un rectangulo relleno
|
// Dibuja un rectangulo relleno
|
||||||
void fillRect(SDL_Rect *rect, Uint8 color);
|
void fillRect(const SDL_Rect *rect, Uint8 color);
|
||||||
|
|
||||||
// Dibuja el borde de un rectangulo
|
// Dibuja el borde de un rectangulo
|
||||||
void drawRectBorder(SDL_Rect *rect, Uint8 color);
|
void drawRectBorder(const SDL_Rect *rect, Uint8 color);
|
||||||
|
|
||||||
// Dibuja una linea
|
// Dibuja una linea
|
||||||
void drawLine(int x1, int y1, int x2, int y2, Uint8 color);
|
void drawLine(int x1, int y1, int x2, int y2, Uint8 color);
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
#include <stddef.h> // Para size_t
|
||||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
#include <fstream> // Para basic_ifstream, basic_istream, basic_ostream
|
||||||
#include <SDL2/SDL_render.h> // Para SDL_TEXTUREACCESS_TARGET
|
#include <iostream> // Para cerr
|
||||||
#include <stddef.h> // Para size_t
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <fstream> // Para basic_ifstream, basic_istream, basic...
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include <iostream> // Para cerr
|
#include "screen.h" // Para Screen
|
||||||
#include <stdexcept> // Para runtime_error
|
#include "surface.h" // Para Surface
|
||||||
#include "screen.h" // Para Screen
|
#include "utils.h" // Para getFileName, stringToColor, printWithDots
|
||||||
#include "s_sprite.h" // Para SSprite
|
|
||||||
#include "surface.h" // Para Surface
|
|
||||||
#include "utils.h" // Para Uint8, getFileName, printWithDots
|
|
||||||
|
|
||||||
// Llena una estructuta TextFile desde un fichero
|
// Llena una estructuta TextFile desde un fichero
|
||||||
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
||||||
@@ -245,7 +242,7 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerni
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
writeColored(x, y, text, textColor, kerning, lenght);
|
writeColored(x, y, text, textColor, kerning, lenght);
|
||||||
//write(x, y, text, kerning, lenght);
|
// write(x, y, text, kerning, lenght);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h> // Para Uint8
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <memory> // Para unique_ptr, shared_ptr
|
#include <memory> // Para shared_ptr, unique_ptr
|
||||||
#include <string> // Para string
|
#include <string> // Para string
|
||||||
#include "s_sprite.h" // Para SSprite
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "utils.h" // Para Uint8
|
class Surface; // lines 8-8
|
||||||
class Surface; // lines 9-9
|
|
||||||
|
|
||||||
constexpr int TEXT_COLOR = 1;
|
constexpr int TEXT_COLOR = 1;
|
||||||
constexpr int TEXT_SHADOW = 2;
|
constexpr int TEXT_SHADOW = 2;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <SDL2/SDL_surface.h> // for SDL_CreateRGBSurfaceWithFormatFrom
|
#include <SDL2/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom
|
||||||
#include <iostream> // for basic_ostream, operator<<, endl, cout
|
#include <iostream> // Para basic_ostream, operator<<, endl, cout
|
||||||
#include <stdexcept> // for runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <string> // for char_traits, operator<<, string, opera...
|
#include <string> // Para char_traits, operator<<, string, opera...
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
#include "utils.h" // for getFileName, Color, printWithDots
|
#include "utils.h" // Para getFileName, Color, printWithDots
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "stb_image.h" // para stbi_failure_reason, stbi_image_free
|
#include "stb_image.h" // para stbi_failure_reason, stbi_image_free
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32
|
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
struct Color; // lines 11-11
|
struct Color; // lines 11-11
|
||||||
|
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer_; // Renderizador donde dibujar la textura
|
SDL_Renderer *renderer_; // Renderizador donde dibujar la textura
|
||||||
SDL_Texture *texture_ = nullptr; // La textura
|
SDL_Texture *texture_ = nullptr; // La textura
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::string path_; // Ruta de la imagen de la textura
|
std::string path_; // Ruta de la imagen de la textura
|
||||||
|
|||||||
@@ -1,24 +1,20 @@
|
|||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_1, SDL_SCANCODE_2
|
||||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
#include <algorithm> // Para clamp
|
||||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_1, SDL_SCANCODE_2
|
#include "cheevos.h" // Para Cheevos, Achievement
|
||||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
#include "defines.h" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH
|
||||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
#include "global_events.h" // Para check
|
||||||
#include "asset.h" // for Asset
|
#include "global_inputs.h" // Para check
|
||||||
#include "cheevos.h" // for Achievement, Cheevos
|
#include "input.h" // Para Input, InputAction, REPEAT_FALSE, REP...
|
||||||
#include "defines.h" // for PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH
|
#include "options.h" // Para Options, options, SectionState, Section
|
||||||
#include "global_events.h" // for check
|
#include "resource.h" // Para Resource
|
||||||
#include "global_inputs.h" // for check
|
#include "s_sprite.h" // Para SSprite
|
||||||
#include "input.h" // for Input, inputs_e, REPEAT_FALSE, REPEA...
|
#include "screen.h" // Para Screen
|
||||||
#include "options.h" // for Options, options, OptionsVideo, Sect...
|
#include "surface.h" // Para Surface
|
||||||
#include "resource.h" // for Resource
|
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "screen.h" // for Screen
|
#include "utils.h" // Para stringToColor, PaletteColor, playMusic
|
||||||
#include "s_sprite.h" // for SSprite
|
|
||||||
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
|
|
||||||
#include "surface.h" // for Surface
|
|
||||||
#include "utils.h" // for Color, stringToColor, Palette
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title()
|
Title::Title()
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <memory> // Para shared_ptr
|
||||||
#include <memory> // for shared_ptr
|
#include <string> // Para string
|
||||||
#include <string> // for string
|
#include <vector> // Para vector
|
||||||
#include <vector> // for vector
|
class SSprite; // lines 9-9
|
||||||
class SSprite; // lines 13-13
|
class Surface; // lines 10-10
|
||||||
class Surface; // lines 15-15
|
|
||||||
|
|
||||||
class Title
|
class Title
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <stdlib.h> // for abs
|
#include <stdlib.h> // Para abs
|
||||||
#include <algorithm> // for find, transform
|
#include <algorithm> // Para find, transform
|
||||||
#include <cctype> // for tolower
|
#include <cctype> // Para tolower
|
||||||
#include <cmath> // for round, abs
|
#include <cmath> // Para round, abs
|
||||||
#include <exception> // for exception
|
#include <exception> // Para exception
|
||||||
#include <filesystem> // for path
|
#include <filesystem> // Para path
|
||||||
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
|
#include <iostream> // Para basic_ostream, cout, basic_ios, ios, endl
|
||||||
#include <string> // for basic_string, string, char_traits, allocator
|
#include <string> // Para basic_string, string, char_traits, allocator
|
||||||
#include <unordered_map> // for unordered_map, operator==, _Node_const_iter...
|
#include <unordered_map> // Para unordered_map, operator==, _Node_const_iter...
|
||||||
#include <utility> // for pair
|
#include <utility> // Para pair
|
||||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_PlayMusic
|
#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_PlayMusic
|
||||||
#include "resource.h" // for Resource
|
#include "resource.h" // Para Resource
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
double distanceSquared(int x1, int y1, int x2, int y2)
|
double distanceSquared(int x1, int y1, int x2, int y2)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <string> // for string
|
#include <string> // Para string
|
||||||
#include <vector> // for vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
enum class PaletteColor : Uint8
|
enum class PaletteColor : Uint8
|
||||||
{
|
{
|
||||||
@@ -35,52 +35,51 @@ enum class PaletteColor : Uint8
|
|||||||
TRANSPARENT = 255,
|
TRANSPARENT = 255,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Estructura para definir un circulo
|
// Estructura para definir un circulo
|
||||||
struct Circle
|
struct Circle
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int r;
|
int r;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para definir una linea horizontal
|
// Estructura para definir una linea horizontal
|
||||||
struct LineHorizontal
|
struct LineHorizontal
|
||||||
{
|
{
|
||||||
int x1, x2, y;
|
int x1, x2, y;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para definir una linea vertical
|
// Estructura para definir una linea vertical
|
||||||
struct LineVertical
|
struct LineVertical
|
||||||
{
|
{
|
||||||
int x, y1, y2;
|
int x, y1, y2;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para definir una linea diagonal
|
// Estructura para definir una linea diagonal
|
||||||
struct LineDiagonal
|
struct LineDiagonal
|
||||||
{
|
{
|
||||||
int x1, y1, x2, y2;
|
int x1, y1, x2, y2;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para definir una linea
|
// Estructura para definir una linea
|
||||||
struct Line
|
struct Line
|
||||||
{
|
{
|
||||||
int x1, y1, x2, y2;
|
int x1, y1, x2, y2;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estructura para definir un color
|
// Estructura para definir un color
|
||||||
struct Color
|
struct Color
|
||||||
{
|
{
|
||||||
Uint8 r;
|
Uint8 r;
|
||||||
Uint8 g;
|
Uint8 g;
|
||||||
Uint8 b;
|
Uint8 b;
|
||||||
|
|
||||||
// Constructor por defecto
|
// Constructor por defecto
|
||||||
Color() : r(0), g(0), b(0) {}
|
Color() : r(0), g(0), b(0) {}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Color(Uint8 red, Uint8 green, Uint8 blue)
|
Color(Uint8 red, Uint8 green, Uint8 blue)
|
||||||
: r(red), g(green), b(blue) {}
|
: r(red), g(green), b(blue) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||
Reference in New Issue
Block a user