diff --git a/source/cheevos.cpp b/source/cheevos.cpp index a785a4d..c2956c8 100644 --- a/source/cheevos.cpp +++ b/source/cheevos.cpp @@ -1,11 +1,11 @@ #include "cheevos.h" -#include // for SDL_GetError -#include // for SDL_RWFromFile, SDL_RWclose, SDL_RWwrite -#include // for NULL -#include // for basic_ostream, operator<<, basic_ofstream -#include // for cout, cerr -#include "notifier.h" // for Notifier -#include "options.h" // for Options, options +#include // Para SDL_GetError +#include // Para SDL_RWFromFile, SDL_RWclose, SDL_RWwrite +#include // Para NULL +#include // Para basic_ostream, operator<<, basic_ofstream +#include // Para cout, cerr +#include "notifier.h" // Para Notifier +#include "options.h" // Para Options, options // [SINGLETON] Cheevos *Cheevos::cheevos_ = nullptr; @@ -87,10 +87,10 @@ void Cheevos::unlock(int id) // Marcar el logro como completado cheevos_list_.at(INDEX).completed = true; - + // 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 saveToFile(); } diff --git a/source/cheevos.h b/source/cheevos.h index 1387094..d4b974e 100644 --- a/source/cheevos.h +++ b/source/cheevos.h @@ -1,7 +1,7 @@ #pragma once -#include // for string -#include // for vector +#include // Para string +#include // Para vector // Struct para los logros struct Achievement @@ -73,7 +73,7 @@ public: void enable(bool value) { enabled_ = value; } // Lista los logros - std::vector list() { return cheevos_list_; } + const std::vector& list() const { return cheevos_list_; } // Devuelve el número total de logros desbloqueados int getTotalUnlockedAchievements(); diff --git a/source/credits.cpp b/source/credits.cpp index ee7b7e8..724d2dd 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -1,20 +1,18 @@ #include "credits.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_Rect -#include // for SDL_GetTicks -#include // for min -#include // for basic_ostream, operator<<, cout, endl -#include "s_animated_sprite.h" // for SAnimatedSprite -#include "defines.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "options.h" // for Options, options, OptionsVideo, Sect... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_Rect +#include // Para SDL_GetTicks +#include // Para min +#include "defines.h" // Para GAME_SPEED, PLAY_AREA_CENTER_X, PLAY_... +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "options.h" // Para Options, options, OptionsGame, Sectio... +#include "resource.h" // Para Resource +#include "s_animated_sprite.h" // Para SAnimatedSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR +#include "utils.h" // Para PaletteColor // Constructor Credits::Credits() @@ -186,7 +184,6 @@ void Credits::fillTexture() // El resto se rellena de color sólido SDL_Rect rect = {0, 8, 256, 192}; cover_surface_->fillRect(&rect, color); - } // Actualiza el contador diff --git a/source/credits.h b/source/credits.h index 037c884..157be4a 100644 --- a/source/credits.h +++ b/source/credits.h @@ -1,14 +1,11 @@ #pragma once -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -#include "utils.h" // for Color -#include -#include "surface.h" -class SAnimatedSprite; // lines 9-9 +#include // Para Uint32, Uint8 +#include // Para shared_ptr +#include // Para string +#include // Para vector +class SAnimatedSprite; // lines 11-11 +class Surface; class Credits { @@ -20,8 +17,8 @@ private: }; // Objetos y punteros - std::shared_ptr text_surface_; // Textura para dibujar el texto - std::shared_ptr cover_surface_; // Textura para cubrir el texto + std::shared_ptr text_surface_; // Textura para dibujar el texto + std::shared_ptr cover_surface_; // Textura para cubrir el texto std::shared_ptr shining_sprite_; // Sprite para el brillo del corazón // Variables diff --git a/source/debug.cpp b/source/debug.cpp index 83b9bb3..54de92b 100644 --- a/source/debug.cpp +++ b/source/debug.cpp @@ -1,9 +1,9 @@ #include "debug.h" -#include // for max -#include // for __shared_ptr_access, shared_ptr -#include "resource.h" // for Resource -#include "text.h" // for Text -#include "utils.h" // for Color +#include // Para max +#include // Para __shared_ptr_access, shared_ptr +#include "resource.h" // Para Resource +#include "text.h" // Para Text +#include "utils.h" // Para Color // [SINGLETON] Debug *Debug::debug_ = nullptr; diff --git a/source/debug.h b/source/debug.h index 537a804..d46d498 100644 --- a/source/debug.h +++ b/source/debug.h @@ -1,8 +1,8 @@ #pragma once -#include // for SDL_Point -#include // for string -#include // for vector +#include // Para SDL_Point +#include // Para string +#include // Para vector // Clase Debug class Debug diff --git a/source/director.cpp b/source/director.cpp index 8382983..bc3fab4 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -1,42 +1,41 @@ #include "director.h" -#include // for SDL_Init, SDL_Quit, SDL_INIT_EV... -#include // for AUDIO_S16 -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_CONTROLLER_BUTTON_B, SDL_CO... -#include // for SDL_SetHint, SDL_HINT_RENDER_DR... -#include // for SDL_SCANCODE_A, SDL_SCANCODE_ES... -#include // for Uint32 +#include // Para SDL_Init, SDL_Quit, SDL_INIT_EV... +#include // Para AUDIO_S16 +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_GetError +#include // Para SDL_DISABLE +#include // Para SDL_CONTROLLER_BUTTON_B, SDL_CO... +#include // Para SDL_SetHint, SDL_HINT_RENDER_DR... #include // Para SDL_ShowCursor -#include // for SDL_GetTicks -#include // for errno, EEXIST, EACCES, ENAMETOO... -#include // for printf, perror -#include // for strcmp -#include // for mkdir, stat, S_IRWXU -#include // for getuid -#include // for exit, EXIT_FAILURE, srand -#include // for basic_ostream, operator<<, cout -#include // for make_unique, unique_ptr -#include // for operator+, allocator, char_traits -#include "asset.h" // for Asset, AssetType -#include "cheevos.h" // for Cheevos -#include "credits.h" // for Credits -#include "debug.h" // for Debug -#include "defines.h" // for WINDOW_CAPTION, borderColor -#include "ending.h" // for Ending -#include "ending2.h" // for Ending2 -#include "game.h" // for Game -#include "game_over.h" // for GameOver -#include "input.h" // for Input, inputs_e -#include "jail_audio.h" // for JA_GetMusicState, JA_DeleteMusic -#include "loading_screen.h" // for LoadingScreen -#include "logo.h" // for Logo -#include "notifier.h" // for Notifier -#include "options.h" // for Options, options, Section, Cheat -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "title.h" // for Title -#include "utils.h" // for Color +#include // Para SDL_SCANCODE_A, SDL_SCANCODE_ES... +#include // Para Uint32 +#include // Para SDL_GetTicks +#include // Para errno, EEXIST, EACCES, ENAMETOO... +#include // Para printf, perror +#include // Para mkdir, stat, S_IRWXU +#include // Para getuid +#include // Para exit, EXIT_FAILURE, srand +#include // Para basic_ostream, operator<<, cout +#include // Para make_unique, unique_ptr +#include // Para operator+, allocator, char_traits +#include "asset.h" // Para Asset, AssetType +#include "cheevos.h" // Para Cheevos +#include "credits.h" // Para Credits +#include "debug.h" // Para Debug +#include "defines.h" // Para WINDOW_CAPTION +#include "ending.h" // Para Ending +#include "ending2.h" // Para Ending2 +#include "game.h" // Para Game, GameMode +#include "game_over.h" // Para GameOver +#include "input.h" // Para Input, InputAction +#include "jail_audio.h" // Para JA_SetMusicVolume, JA_SetSoundV... +#include "loading_screen.h" // Para LoadingScreen +#include "logo.h" // Para Logo +#include "notifier.h" // Para Notifier +#include "options.h" // Para Options, options, OptionsVideo +#include "resource.h" // Para Resource +#include "screen.h" // Para Screen +#include "title.h" // Para Title #ifndef _WIN32 #include diff --git a/source/director.h b/source/director.h index 897f9b5..0b77fbe 100644 --- a/source/director.h +++ b/source/director.h @@ -1,8 +1,8 @@ #pragma once -#include // for SDL_Renderer -#include // for SDL_Window -#include // for string +#include // Para SDL_Renderer +#include // Para SDL_Window +#include // Para string class Director { diff --git a/source/ending.cpp b/source/ending.cpp index 75cace4..eeed27f 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -1,23 +1,20 @@ #include "ending.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_Rect -#include // for SDL_GetTicks -#include // for min -#include // for basic_ostream, operator<<, cout, endl -#include "defines.h" // for options.game.height, options.game.width -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... -#include "options.h" // for Options, options, OptionsVideo, Sect... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#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,PaletteColor::PALETTE +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_Rect +#include // Para SDL_GetTicks +#include // Para min +#include "defines.h" // Para GAME_SPEED +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic +#include "options.h" // Para Options, options, OptionsGame, SectionS... +#include "resource.h" // Para Resource +#include "s_sprite.h" // Para SSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "text.h" // Para Text, TEXT_STROKE +#include "utils.h" // Para PaletteColor + // Constructor Ending::Ending() : counter_(-1), @@ -476,7 +473,7 @@ void Ending::checkChangeScene() void Ending::fillCoverTexture() { // 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_); cover_surface_->clear(static_cast(PaletteColor::TRANSPARENT)); diff --git a/source/ending.h b/source/ending.h index c353af7..15aa31f 100644 --- a/source/ending.h +++ b/source/ending.h @@ -1,12 +1,11 @@ #pragma once -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -class SSprite; // lines 12-12 -class Surface; // lines 14-14 +#include // Para Uint32 +#include // Para shared_ptr +#include // Para string +#include // Para vector +class SSprite; // lines 8-8 +class Surface; // lines 9-9 class Ending { diff --git a/source/ending2.cpp b/source/ending2.cpp index 3b58cc8..6b3d4ca 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -1,22 +1,20 @@ #include "ending2.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_Rect -#include // for SDL_RenderDrawPoint, SDL_SetRenderDr... -#include // for SDL_GetTicks -#include // for max, min, replace -#include "s_animated_sprite.h" // for SAnimatedSprite -#include "defines.h" // for options.game.height, GAMECANVAS_CENTER_X -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_SetVolume, JA_PlayMusic, JA_StopM... -#include "s_moving_sprite.h" // for SMovingSprite -#include "options.h" // for Options, options, OptionsVideo, Sect... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for Text -#include "surface.h" // for Surface -#include "utils.h" // for Color, static_cast +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_Rect +#include // Para SDL_GetTicks +#include // Para max, replace +#include "defines.h" // Para GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "jail_audio.h" // Para JA_SetVolume, JA_PlayMusic, JA_StopMusic +#include "options.h" // Para Options, options, OptionsGame, Sectio... +#include "resource.h" // Para Resource +#include "s_animated_sprite.h" // Para SAnimatedSprite +#include "s_moving_sprite.h" // Para SMovingSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "text.h" // Para Text +#include "utils.h" // Para PaletteColor, stringToColor // Constructor Ending2::Ending2() @@ -423,7 +421,7 @@ void Ending2::createSpriteTexts() // Crea la surface auto surface = std::make_shared(W, H); - auto previuos_renderer = Screen::get()->getRendererSurface(); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface); text->write(0, 0, txt); @@ -456,8 +454,8 @@ void Ending2::createTexts() // Crea la surface auto surface = std::make_shared(w, h); - auto previuos_renderer = Screen::get()->getRendererSurface(); - Screen::get()->setRendererSurface(surface); + auto previuos_renderer = Screen::get()->getRendererSurface(); + Screen::get()->setRendererSurface(surface); text->write(0, 0, list[i]); // Crea el sprite @@ -486,7 +484,7 @@ void Ending2::createTexts() // Crea la surface auto surface = std::make_shared(w, h); - auto previuos_renderer = Screen::get()->getRendererSurface(); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface); text->write(0, 0, list[i]); diff --git a/source/ending2.h b/source/ending2.h index 0d2dec0..134aaa8 100644 --- a/source/ending2.h +++ b/source/ending2.h @@ -1,13 +1,12 @@ #pragma once -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -#include "defines.h" // for GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR... -#include "utils.h" // for Color -class SAnimatedSprite; // lines 10-10 -class SMovingSprite; // lines 13-13 +#include // Para Uint32, Uint8 +#include // Para shared_ptr +#include // Para string +#include // Para vector +#include "defines.h" // Para GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR... +class SAnimatedSprite; // lines 9-9 +class SMovingSprite; // lines 10-10 class Ending2 { diff --git a/source/enemy.cpp b/source/enemy.cpp index 40369a7..687fcf1 100644 --- a/source/enemy.cpp +++ b/source/enemy.cpp @@ -1,10 +1,9 @@ #include "enemy.h" -#include // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL... -#include // for rand -#include "s_animated_sprite.h" // for SAnimatedSprite -#include "options.h" // for Options, OptionsVideo, options -#include "resource.h" // for Resource -#include "surface.h" // for Texture +#include // Para SDL_RendererFlip, SDL_FLIP_NONE, SDL_... +#include // Para rand +#include "resource.h" // Para Resource +#include "s_animated_sprite.h" // Para SAnimatedSprite +#include "utils.h" // Para stringToColor // Constructor Enemy::Enemy(const EnemyData &enemy) diff --git a/source/enemy.h b/source/enemy.h index 91ca5ee..7e29ba6 100644 --- a/source/enemy.h +++ b/source/enemy.h @@ -1,10 +1,10 @@ #pragma once -#include // for SDL_Rect -#include // for shared_ptr -#include // for string -#include "utils.h" // for Color -class SAnimatedSprite; +#include // Para SDL_Rect +#include // Para Uint8 +#include // Para shared_ptr +#include // Para string +class SAnimatedSprite; // lines 7-7 // Estructura para pasar los datos de un enemigo struct EnemyData diff --git a/source/game.cpp b/source/game.cpp index 436d507..90c0784 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,30 +1,28 @@ #include "game.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_... -#include // for SDL_GetTicks -#include // for basic_ostream, operator<<, cout, endl -#include // for vector -#include "asset.h" // for Asset -#include "cheevos.h" // for Cheevos -#include "debug.h" // for Debug -#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, GAMECANVAS_... -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "input.h" // for Input, InputAction, REPEAT_FALSE -#include "item_tracker.h" // for ItemTracker -#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu... -#include "notifier.h" // for Notifier, NotificationText -#include "options.h" // for Options, options, Cheat, OptionsVideo -#include "resource.h" // for ResourceRoom, Resource -#include "room.h" // for Room, RoomData -#include "room_tracker.h" // for RoomTracker -#include "scoreboard.h" // for ScoreboardData, Scoreboard -#include "screen.h" // for Screen -#include "stats.h" // for Stats -#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR -#include "utils.h" // for Color, stringToColor, colorAreEqual +#include // Para SDL_FLIP_HORIZONTAL +#include // Para SDL_SCANCODE_7, SDL_SCANCODE_A, SDL_S... +#include // Para SDL_GetTicks +#include // Para vector +#include "asset.h" // Para Asset +#include "cheevos.h" // Para Cheevos +#include "debug.h" // Para Debug +#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, BORDER_BOTTOM +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "input.h" // Para Input, InputAction, REPEAT_FALSE +#include "item_tracker.h" // Para ItemTracker +#include "jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P... +#include "notifier.h" // Para Notifier, NotificationText, CHEEVO_NO... +#include "options.h" // Para Options, options, Cheat, SectionState +#include "resource.h" // Para ResourceRoom, Resource +#include "room.h" // Para Room, RoomData +#include "room_tracker.h" // Para RoomTracker +#include "scoreboard.h" // Para ScoreboardData, Scoreboard +#include "screen.h" // Para Screen +#include "stats.h" // Para Stats +#include "surface.h" // Para Surface +#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR +#include "utils.h" // Para PaletteColor, stringToColor // Constructor Game::Game(GameMode mode) diff --git a/source/game.h b/source/game.h index 941cce9..4ea7df1 100644 --- a/source/game.h +++ b/source/game.h @@ -1,19 +1,19 @@ #pragma once -#include // for SDL_Event -#include // for SDL_Rect -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -#include "player.h" // for PlayerSpawn -#include "surface.h" -class Room; // lines 10-10 -class RoomTracker; // lines 11-11 -class Scoreboard; // lines 12-12 -class Stats; // lines 13-13 -struct ScoreboardData; // lines 14-14 +#include // Para SDL_Event +#include // Para SDL_Rect +#include // Para Uint32 +#include // Para initializer_list +#include // Para shared_ptr +#include // Para string +#include // Para vector +#include "player.h" // Para PlayerSpawn +class Room; // lines 12-12 +class RoomTracker; // lines 13-13 +class Scoreboard; // lines 14-14 +class Stats; // lines 15-15 +class Surface; +struct ScoreboardData; // lines 16-16 enum class GameMode { @@ -162,7 +162,7 @@ private: public: // Constructor - Game(GameMode mode); + explicit Game(GameMode mode); // Destructor ~Game(); diff --git a/source/game_over.cpp b/source/game_over.cpp index 4f9c2cf..67a009f 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -1,18 +1,18 @@ #include "game_over.h" -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_GetTicks -#include // for min, max -#include // for basic_string, operator+, to_string, cha... -#include "s_animated_sprite.h" // for AnimatedSprite -#include "defines.h" // for GAMECANVAS_CENTER_X, GAME_SPEED -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_PlayMusic -#include "options.h" // for Options, options, OptionsStats, Section... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for TEXT_CENTER, TEXT_COLOR, Text -#include "surface.h" // for Texture +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_GetTicks +#include // Para min, max +#include // Para basic_string, operator+, to_string +#include "defines.h" // Para GAMECANVAS_CENTER_X, GAME_SPEED +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "jail_audio.h" // Para JA_PlayMusic +#include "options.h" // Para Options, options, OptionsStats, Secti... +#include "resource.h" // Para Resource +#include "s_animated_sprite.h" // Para SAnimatedSprite +#include "screen.h" // Para Screen +#include "text.h" // Para TEXT_CENTER, TEXT_COLOR, Text +#include "utils.h" // Para PaletteColor, stringToColor // Constructor GameOver::GameOver() diff --git a/source/game_over.h b/source/game_over.h index 6652dce..ee195f6 100644 --- a/source/game_over.h +++ b/source/game_over.h @@ -1,10 +1,9 @@ #pragma once -#include // for Uint32 -#include // for shared_ptr -#include // for vector -#include "utils.h" // for Color -class SAnimatedSprite; // lines 8-8 +#include // Para Uint8, Uint32 +#include // Para shared_ptr +#include // Para vector +class SAnimatedSprite; // lines 7-7 class GameOver { @@ -16,7 +15,7 @@ private: // Objetos y punteros std::shared_ptr player_sprite_; // Sprite con el jugador - std::shared_ptr tv_sprite_; // Sprite con el televisor + std::shared_ptr tv_sprite_; // Sprite con el televisor // Variables int pre_counter_ = 0; // Contador previo diff --git a/source/gif.cpp b/source/gif.cpp index 4d495f9..606683d 100644 --- a/source/gif.cpp +++ b/source/gif.cpp @@ -1,391 +1,316 @@ #include "gif.h" -#include // for NULL, fprintf, stderr -#include // for malloc, realloc, exit, calloc, free +#include // Para std::cout +#include // Para memcpy, size_t +#include // Para runtime_error +#include // Para allocator, char_traits, operator==, basic_string -void uncompress( int code_length, - const unsigned char *input, - int input_length, - unsigned char *out ) +namespace GIF { - //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 ); - stop_code = clear_code + 1; - // To handle clear codes - 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++ ) + // Función inline para reemplazar el macro READ. + // Actualiza el puntero 'buffer' tras copiar 'size' bytes a 'dst'. + inline void readBytes(const uint8_t *&buffer, void *dst, size_t size) { - dictionary[ dictionary_ind ].byte = dictionary_ind; - // XXX this only works because prev is a 32-bit int (> 12 bits) - dictionary[ dictionary_ind ].prev = -1; - dictionary[ dictionary_ind ].len = 1; + std::memcpy(dst, buffer, size); + buffer += size; } - // 2^code_len + 1 is the special "end" code; don't give it an entry here - dictionary_ind++; - dictionary_ind++; - - // TODO verify that the very last byte is clear_code + 1 - while ( input_length ) + void Gif::decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out) { - code = 0x0; - // Always read one more bit than the code length - for ( i = 0; i < ( code_length + 1 ); i++ ) + // Verifica que el code_length tenga un rango razonable. + if (code_length < 2 || code_length > 12) { - // This is different than in the file read example; that - // 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 ); + throw std::runtime_error("Invalid LZW code length"); } - if ( code == clear_code ) - { - code_length = reset_code_length; - dictionary = ( dictionary_entry_t * ) realloc( dictionary, - sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) ); + int i, bit; + int prev = -1; + std::vector dictionary; + int dictionary_ind; + 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; - dictionary_ind < ( 1 << code_length ); - dictionary_ind++ ) - { - dictionary[ dictionary_ind ].byte = dictionary_ind; - // XXX this only works because prev is a 32-bit int (> 12 bits) - dictionary[ dictionary_ind ].prev = -1; - dictionary[ dictionary_ind ].len = 1; - } - dictionary_ind++; - dictionary_ind++; - prev = -1; - continue; + // Inicializamos el diccionario con el tamaño correspondiente. + dictionary.resize(1 << (code_length + 1)); + for (dictionary_ind = 0; dictionary_ind < (1 << code_length); dictionary_ind++) + { + dictionary[dictionary_ind].byte = static_cast(dictionary_ind); + dictionary[dictionary_ind].prev = -1; + dictionary[dictionary_ind].len = 1; } - 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" ); - 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 ) + if (input_length <= 0) { - 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(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(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 Gif::readSubBlocks(const uint8_t *&buffer) + { + std::vector 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 Gif::processImageDescriptor(const uint8_t *&buffer, const std::vector &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 compressed_data = readSubBlocks(buffer); + int uncompressed_data_length = image_descriptor.image_width * image_descriptor.image_height; + std::vector uncompressed_data(uncompressed_data_length); + + decompress(lzw_code_size, compressed_data.data(), static_cast(compressed_data.size()), uncompressed_data.data()); + return uncompressed_data; + } + + std::vector 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 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 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(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 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 { - int 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++; - - // 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 ) ) ); + std::cerr << "Unrecognized block type " << std::hex << static_cast(block_type) << std::endl; + return std::vector{}; } + block_type = *buffer++; } - prev = code; - - // 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 std::vector{}; } - return data_length; -} - -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 Gif::loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h) { - fprintf( stderr, - "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); + return processGifStream(buffer, w, h); } - - while ( block_type != TRAILER ) - { - 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 \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 ); -}*/ \ No newline at end of file +} // namespace GIF diff --git a/source/gif.h b/source/gif.h index 5e6641f..2692da0 100644 --- a/source/gif.h +++ b/source/gif.h @@ -1,66 +1,102 @@ #pragma once -#include // for uint32_t -#include // for memcpy +#include // Para uint8_t, uint16_t, uint32_t +#include // Para vector -#define EXTENSION_INTRODUCER 0x21 -#define IMAGE_DESCRIPTOR 0x2C -#define TRAILER 0x3B -#define GRAPHIC_CONTROL 0xF9 -#define APPLICATION_EXTENSION 0xFF -#define COMMENT_EXTENSION 0xFE -#define PLAINTEXT_EXTENSION 0x01 +namespace GIF +{ -#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 { - unsigned short width; - unsigned short height; - unsigned char fields; - unsigned char background_color_index; - unsigned char pixel_aspect_ratio; -} screen_descriptor_t; +#pragma pack(push, 1) + struct ScreenDescriptor + { + uint16_t width; + uint16_t height; + uint8_t fields; + uint8_t background_color_index; + uint8_t pixel_aspect_ratio; + }; -typedef struct { - unsigned char r, g, b; -} rgb; + struct RGB + { + uint8_t r, g, b; + }; -typedef struct { - unsigned short image_left_position; - unsigned short image_top_position; - unsigned short image_width; - unsigned short image_height; - unsigned char fields; -} image_descriptor_t; + struct ImageDescriptor + { + uint16_t image_left_position; + uint16_t image_top_position; + uint16_t image_width; + uint16_t image_height; + uint8_t fields; + }; +#pragma pack(pop) -typedef struct { - unsigned char byte; - int prev; - int len; -} dictionary_entry_t; + struct DictionaryEntry + { + uint8_t byte; + int prev; + int len; + }; -typedef struct { - unsigned char extension_code; - unsigned char block_size; -} extension_t; + struct Extension + { + uint8_t extension_code; + uint8_t block_size; + }; -typedef struct { - unsigned char fields; - unsigned short delay_time; - unsigned char transparent_color_index; -} graphic_control_extension_t; + struct GraphicControlExtension + { + uint8_t fields; + uint16_t delay_time; + uint8_t transparent_color_index; + }; -typedef struct { - unsigned char application_id[8]; - unsigned char version[3]; -} application_extension_t; + struct ApplicationExtension + { + uint8_t application_id[8]; + uint8_t version[3]; + }; -typedef struct { - unsigned short left, top, width, height; - unsigned char cell_width, cell_height; - unsigned char foreground_color, background_color; -} plaintext_extension_t; + struct PlaintextExtension + { + uint16_t left, top, width, height; + uint8_t cell_width, cell_height; + uint8_t foreground_color, background_color; + }; -void uncompress(int code_length, const unsigned char *input, int input_length, unsigned char *out); -uint32_t* LoadPalette(unsigned char *buffer); -unsigned char* LoadGif(unsigned char *buffer, unsigned short* w, unsigned short* h); \ No newline at end of file + class Gif + { + 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 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 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. + std::vector readSubBlocks(const uint8_t *&buffer); + + // Procesa el Image Descriptor y retorna el vector de datos sin comprimir. + std::vector processImageDescriptor(const uint8_t *&buffer, const std::vector &gct, int resolution_bits); + + // Procesa el stream completo del GIF y devuelve los datos sin comprimir. + std::vector processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h); + }; + +} // namespace GIF diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index c308cd8..e302e42 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -1,11 +1,13 @@ #include "global_inputs.h" -#include // for basic_string -#include // for vector -#include "input.h" // for Input, REPEAT_FALSE, inputs_e -#include "notifier.h" // for Notifier -#include "options.h" // for Section, Options, options, SectionState, Optio... -#include "screen.h" // for Screen -#include "utils.h" // for Palette +#include // Para SDL_RenderSetIntegerScale +#include // Para SDL_FALSE, SDL_TRUE +#include // Para allocator, operator+, char_traits, string +#include // Para vector +#include "input.h" // Para Input, InputAction, REPEAT_FALSE +#include "notifier.h" // Para Notifier, NotificationText +#include "options.h" // Para Options, options, OptionsVideo, Section +#include "screen.h" // Para Screen +#include "utils.h" // Para stringInVector namespace globalInputs { diff --git a/source/item.cpp b/source/item.cpp index 7ad02f0..ca00aa2 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -1,7 +1,6 @@ #include "item.h" -#include "resource.h" +#include "resource.h" // Para Resource #include "s_sprite.h" // Para SSprite -#include "surface.h" // Para Texture // Constructor Item::Item(ItemData item) diff --git a/source/item.h b/source/item.h index 068bdf6..32a431b 100644 --- a/source/item.h +++ b/source/item.h @@ -1,12 +1,11 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for shared_ptr, __shared_ptr_access -#include // for string -#include // for vector -#include "s_sprite.h" // for SSprite -#include "surface.h" // for Texture -#include "utils.h" // for Color +#include // Para SDL_Rect, SDL_Point +#include // Para Uint8 +#include // Para shared_ptr +#include // Para string +#include // Para vector +class SSprite; struct ItemData { diff --git a/source/jail_audio.cpp b/source/jail_audio.cpp index 7df6ae1..0882807 100644 --- a/source/jail_audio.cpp +++ b/source/jail_audio.cpp @@ -1,10 +1,10 @@ #include "jail_audio.h" -#include // for SDL_RWFromMem -#include // for SDL_GetTicks -#include // for uint8_t, uint32_t -#include // for NULL, fseek, fclose, fopen, fread, ftell -#include // for free, malloc -#include "stb_vorbis.c" // for stb_vorbis_decode_memory +#include // Para SDL_RWFromMem +#include // Para SDL_GetTicks +#include // Para uint8_t, uint32_t +#include // Para NULL, fseek, fclose, fopen, fread, ftell +#include // Para free, malloc +#include "stb_vorbis.c" // Para stb_vorbis_decode_memory constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20; diff --git a/source/jail_audio.h b/source/jail_audio.h index 00327d3..2d4a988 100644 --- a/source/jail_audio.h +++ b/source/jail_audio.h @@ -1,9 +1,9 @@ #pragma once -#include // for SDL_AudioFormat -#include // for Uint32, Uint8 -struct JA_Music_t; // lines 5-5 -struct JA_Sound_t; // lines 6-6 +#include // Para SDL_AudioFormat +#include // Para Uint32, Uint8 +struct JA_Music_t; // lines 5-5 +struct JA_Sound_t; // lines 6-6 enum JA_Channel_state { diff --git a/source/jail_shader.cpp b/source/jail_shader.cpp index e6e8f52..b7b832f 100644 --- a/source/jail_shader.cpp +++ b/source/jail_shader.cpp @@ -1,21 +1,22 @@ #include "jail_shader.h" -#include // para SDL_Point -#include // para NULL, free, malloc, exit -#include // para strncmp -#include // para basic_ostream, char_traits, operator<< +#include // Para SDL_Point +#include // Para SDL_bool +#include // Para strncmp +#include // Para basic_ostream, operator<<, endl, cout +#include // Para runtime_error +#include // Para vector #ifdef __APPLE__ -#include "CoreFoundation/CoreFoundation.h" -#include - +#include "CoreFoundation/CoreFoundation.h" // Para Core Foundation en macOS +#include // Para OpenGL en macOS #if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 -#include -#else -#include -#endif //! ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 -#else -#include -#endif +#include // Para OpenGL 3 en macOS +#else // NO ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 +#include // Para OpenGL (compatibilidad) en macOS +#endif // ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 +#else // SI NO ES __APPLE__ +#include // Para GLuint, glTexCoord2f, glVertex2f, GLfloat +#endif // __APPLE__ namespace shader { @@ -25,12 +26,10 @@ namespace shader SDL_Texture *backBuffer = nullptr; SDL_Point win_size = {320 * 4, 256 * 4}; SDL_Point tex_size = {320, 256}; - bool usingOpenGL; + bool usingOpenGL = false; #ifndef __APPLE__ - - // I'm avoiding the use of GLEW or some extensions handler, but that - // doesn't mean you should... + // Declaración de funciones de extensión de OpenGL (evitando GLEW) PFNGLCREATESHADERPROC glCreateShader; PFNGLSHADERSOURCEPROC glShaderSource; PFNGLCOMPILESHADERPROC glCompileShader; @@ -66,120 +65,125 @@ namespace shader glLinkProgram && glValidateProgram && glGetProgramiv && glGetProgramInfoLog && glUseProgram; } - #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 - 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) + if (source.empty()) { - std::cout << "Error en la compilación: " << result << "!" << std::endl; - 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; + throw std::runtime_error("ERROR FATAL: El código fuente del shader está vacío."); } - 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 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 vtxShaderId, fragShaderId; + GLuint idPrograma = glCreateProgram(); - 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); - fragShaderId = compileShader(fragmentShaderSource ? fragmentShaderSource : vertexShaderSource, GL_FRAGMENT_SHADER); - - if (vtxShaderId && fragShaderId) + if (idShaderVertice && idShaderFragmento) { - // Associate shader with program - glAttachShader(programId, vtxShaderId); - glAttachShader(programId, fragShaderId); - glLinkProgram(programId); - glValidateProgram(programId); + // Asociar los shaders al programa + glAttachShader(idPrograma, idShaderVertice); + glAttachShader(idPrograma, idShaderFragmento); + glLinkProgram(idPrograma); + glValidateProgram(idPrograma); - // Check the status of the compile/link - GLint logLen; - glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen); - if (logLen > 0) + // Verificar el estado del enlace + GLint longitudLog; + glGetProgramiv(idPrograma, GL_INFO_LOG_LENGTH, &longitudLog); + if (longitudLog > 0) { - char *log = (char *)malloc(logLen * sizeof(char)); - // Show any errors as appropriate - glGetProgramInfoLog(programId, logLen, &logLen, log); - std::cout << "Prog Info Log: " << std::endl - << log << std::endl; - free(log); + std::vector log(longitudLog); + glGetProgramInfoLog(idPrograma, longitudLog, &longitudLog, log.data()); + std::cout << "Registro de información del programa:" << std::endl + << log.data() << std::endl; } } - 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::renderer = SDL_GetRenderer(win); - shader::backBuffer = backBuffer; - SDL_GetWindowSize(win, &win_size.x, &win_size.y); - int access; - SDL_QueryTexture(backBuffer, NULL, &access, &tex_size.x, &tex_size.y); - if (access != SDL_TEXTUREACCESS_TARGET) + shader::win = ventana; + shader::renderer = SDL_GetRenderer(ventana); + shader::backBuffer = texturaBackBuffer; + SDL_GetWindowSize(ventana, &win_size.x, &win_size.y); + + int acceso; + 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; - exit(1); + throw std::runtime_error("ERROR FATAL: La textura debe tener definido SDL_TEXTUREACCESS_TARGET."); } - SDL_RendererInfo rendererInfo; - SDL_GetRendererInfo(renderer, &rendererInfo); + SDL_RendererInfo infoRenderer; + 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__ 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; return false; } #endif - // Compilar el shader y dejarlo listo para usar. + // Compilar el programa de shaders utilizando std::string programId = compileProgram(vertexShader, fragmentShader); - // std::cout << "programId = " << programId << std::endl; } 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; return false; } @@ -190,48 +194,90 @@ namespace shader void render() { GLint oldProgramId; - // Guarrada para obtener el textureid (en driverdata->texture) - // Detach the texture + // Establece el color de fondo SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - - SDL_SetRenderTarget(renderer, NULL); + SDL_SetRenderTarget(renderer, nullptr); SDL_RenderClear(renderer); if (usingOpenGL) { - SDL_GL_BindTexture(backBuffer, NULL, NULL); + SDL_GL_BindTexture(backBuffer, nullptr, nullptr); if (programId != 0) { glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId); glUseProgram(programId); } - GLfloat minx, miny, maxx, maxy; - GLfloat minu, maxu, minv, maxv; + // Recupera el tamaño lógico configurado con SDL_RenderSetLogicalSize + 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. - minx = 0.0f; - miny = 0.0f; - maxx = tex_size.x; - maxy = tex_size.y; + // Cálculo del viewport + int viewportX = 0, viewportY = 0, viewportW = win_size.x, viewportH = win_size.y; + SDL_bool useIntegerScale = SDL_RenderGetIntegerScale(renderer); + if (useIntegerScale) + { + // 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(win_size.x) / win_size.y; + float logicalAspect = static_cast(logicalW) / logicalH; + if (windowAspect > logicalAspect) + { + viewportW = static_cast(logicalAspect * win_size.y); + viewportX = (win_size.x - viewportW) / 2; + } + else + { + viewportH = static_cast(win_size.x / logicalAspect); + viewportY = (win_size.y - viewportH) / 2; + } + } + glViewport(viewportX, viewportY, viewportW, viewportH); - minu = 0.0f; - maxu = 1.0f; - minv = 0.0f; - maxv = 1.0f; + // Configurar la proyección ortográfica usando el espacio lógico + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); - 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(logicalW), static_cast(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); - glTexCoord2f(minu, minv); - glVertex2f(minx, miny); - glTexCoord2f(maxu, minv); - glVertex2f(maxx, miny); - glTexCoord2f(minu, maxv); - glVertex2f(minx, maxy); - glTexCoord2f(maxu, maxv); - glVertex2f(maxx, maxy); + // Vértice superior izquierdo + glTexCoord2f(0.0f, 1.0f); + glVertex2f(0.0f, 0.0f); + // Vértice superior derecho + glTexCoord2f(1.0f, 1.0f); + glVertex2f(static_cast(logicalW), 0.0f); + // Vértice inferior izquierdo + glTexCoord2f(0.0f, 0.0f); + glVertex2f(0.0f, static_cast(logicalH)); + // Vértice inferior derecho + glTexCoord2f(1.0f, 0.0f); + glVertex2f(static_cast(logicalW), static_cast(logicalH)); glEnd(); + SDL_GL_SwapWindow(win); if (programId != 0) @@ -241,7 +287,7 @@ namespace shader } else { - SDL_RenderCopy(renderer, backBuffer, NULL, NULL); + SDL_RenderCopy(renderer, backBuffer, nullptr, nullptr); SDL_RenderPresent(renderer); } } diff --git a/source/jail_shader.h b/source/jail_shader.h index ba99f0c..9f9ea8b 100644 --- a/source/jail_shader.h +++ b/source/jail_shader.h @@ -1,7 +1,8 @@ #pragma once -#include // para SDL_Texture -#include // para SDL_Window +#include // Para SDL_Texture +#include // Para SDL_Window +#include // TIPS: // ======================================================================= @@ -38,8 +39,7 @@ namespace shader { - const bool init(SDL_Window *win, SDL_Texture *backBuffer, - const char *vertexShader, const char *fragmentShader = nullptr); - + // const bool init(SDL_Window *ventana, SDL_Texture *texturaBackBuffer, 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(); } \ No newline at end of file diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index 0b1abc5..c77ba08 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -1,20 +1,17 @@ #include "loading_screen.h" -#include // for SDL_GetError -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_GetTicks -#include // for rand -#include // for char_traits, basic_ostream, operator<< -#include "defines.h" // for GAME_SPEED -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_PlayMusic, JA_SetVolume, JA_StopMusic -#include "options.h" // for Options, options, OptionsVideo, Section... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "s_sprite.h" // for SSprite -#include "surface.h" // for Texture -#include "utils.h" // for Color, stringToColor, Palette +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_GetTicks +#include // Para rand +#include "defines.h" // Para GAME_SPEED +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "jail_audio.h" // Para JA_PlayMusic, JA_SetVolume, JA_StopMusic +#include "options.h" // Para Options, options, SectionState, Options... +#include "resource.h" // Para Resource +#include "s_sprite.h" // Para SSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "utils.h" // Para stringToColor, PaletteColor // Constructor LoadingScreen::LoadingScreen() diff --git a/source/loading_screen.h b/source/loading_screen.h index 380ec2d..36df935 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -1,11 +1,10 @@ #pragma once -#include // for SDL_Rect -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -class SSprite; // lines 11-11 -class Surface; // lines 12-12 +#include // Para SDL_Rect +#include // Para Uint32 +#include // Para shared_ptr +class SSprite; // lines 7-7 +class Surface; // lines 8-8 class LoadingScreen { diff --git a/source/logo.cpp b/source/logo.cpp index e37fc1f..165b78e 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,17 +1,15 @@ #include "logo.h" -#include // for SDL_PollEvent, SDL_Event -#include // for SDL_GetTicks -#include // for basic_string, string -#include "defines.h" // for GAME_SPEED -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "jail_audio.h" // for JA_StopMusic -#include "options.h" // for Options, options, SectionState, Section -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "s_sprite.h" // for SSprite -#include "surface.h" // for Texture -#include "utils.h" // for Color, stringToColor +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_GetTicks +#include "defines.h" // Para GAME_SPEED +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "options.h" // Para Options, SectionState, options, Section +#include "resource.h" // Para Resource +#include "s_sprite.h" // Para SSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "utils.h" // Para PaletteColor // Constructor Logo::Logo() diff --git a/source/logo.h b/source/logo.h index 6a0faa9..42a9526 100644 --- a/source/logo.h +++ b/source/logo.h @@ -1,11 +1,10 @@ #pragma once -#include // for Uint32 -#include // for shared_ptr -#include // for vector -#include "utils.h" // for Color -class SSprite; // lines 12-12 -class Surface; // lines 13-13 +#include // Para Uint8, Uint32 +#include // Para shared_ptr +#include // Para vector +class SSprite; // lines 7-7 +class Surface; // lines 8-8 class Logo { @@ -20,8 +19,8 @@ private: std::shared_ptr since_1998_surface_; // Textura con los graficos "Since 1998" std::vector> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES std::shared_ptr since_1998_sprite_; // SSprite para manejar la textura2 - Uint8 jailgames_color_ = 0; // Color para el sprite de "JAILGAMES" - Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998" + Uint8 jailgames_color_ = 0; // Color para el sprite de "JAILGAMES" + Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998" // Variables std::vector color_; // Vector con los colores para el fade diff --git a/source/notifier.cpp b/source/notifier.cpp index 9978bc0..3024363 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -1,17 +1,17 @@ #include "notifier.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_RenderFillRect, SDL_RenderClear -#include // for remove_if -#include // for string, basic_string -#include // for vector -#include "jail_audio.h" // for JA_PlaySound -#include "options.h" // for Options, options, OptionsNotification -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "s_sprite.h" // for SSprite -#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR -#include "surface.h" // for Surface +#include // Para SDL_GetTicks +#include // Para remove_if +#include // Para prev +#include // Para string, basic_string +#include // Para vector +#include "jail_audio.h" // Para JA_PlaySound +#include "options.h" // Para Options, options, NotificationPosition +#include "resource.h" // Para Resource +#include "s_sprite.h" // Para SSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR +#include "utils.h" // Para PaletteColor // [SINGLETON] Notifier *Notifier::notifier_ = nullptr; @@ -59,8 +59,8 @@ void Notifier::update() // Si la notificación anterior está "saliendo", no hagas nada if (!notifications_.empty() && ¬ification != ¬ifications_.front()) { - auto &previous_notification = *(std::prev(¬ification)); - if (previous_notification.state == NotificationStatus::RISING) + const auto &PREVIOUS_NOTIFICATION = *(std::prev(¬ification)); + if (PREVIOUS_NOTIFICATION.state == NotificationStatus::RISING) { break; } @@ -236,8 +236,8 @@ void Notifier::show(std::vector texts, NotificationText text_is, Ui else if (SHAPE == NotificationShape::SQUARED) { n.surface->clear(bg_color_); - SDL_Rect rect = {0, 0, n.surface->getWidth(), n.surface->getHeight()}; - n.surface->drawRectBorder(&rect, static_cast(PaletteColor::CYAN)); + SDL_Rect squared_rect = {0, 0, n.surface->getWidth(), n.surface->getHeight()}; + n.surface->drawRectBorder(&squared_rect, static_cast(PaletteColor::CYAN)); } // Dibuja el icono de la notificación diff --git a/source/notifier.h b/source/notifier.h index 479b4ac..6b28a8e 100644 --- a/source/notifier.h +++ b/source/notifier.h @@ -1,13 +1,13 @@ #pragma once -#include // for SDL_Rect -#include // for shared_ptr -#include // for string, basic_string -#include // for vector -#include "utils.h" // for Color -class SSprite; // lines 9-9 -class Text; // lines 10-10 -class Surface; // lines 11-11 +#include // Para SDL_Rect +#include // Para Uint32, Uint8 +#include // Para shared_ptr +#include // Para string, basic_string +#include // Para vector +class SSprite; // lines 8-8 +class Surface; // lines 10-10 +class Text; // lines 9-9 // Constantes constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000; diff --git a/source/options.cpp b/source/options.cpp index fbc334a..fafaee8 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -1,14 +1,14 @@ #include "options.h" -#include // for SDL_WINDOW_FULLSCREEN_DESKTOP -#include // for find_if -#include // for isspace -#include // for basic_ostream, operator<<, basic_ofstream -#include // for function -#include // for cout, cerr -#include // for basic_istringstream -#include // for char_traits, string, operator<<, hash -#include // for unordered_map, operator==, _Node_const_i... -#include // for pair +#include // Para SDL_WINDOW_FULLSCREEN_DESKTOP +#include // Para find_if +#include // Para isspace +#include // Para basic_ostream, operator<<, basic_ofstream +#include // Para function +#include // Para cout, cerr +#include // Para basic_istringstream +#include // Para char_traits, string, operator<<, hash +#include // Para unordered_map, operator==, _Node_const_i... +#include // Para pair // Variables Options options; @@ -41,7 +41,7 @@ bool loadOptionsFromFile(const std::string &file_path) // Variables para manejar el fichero std::ifstream file(file_path); - + // Si el fichero se puede abrir if (file.good()) { @@ -188,7 +188,7 @@ bool setOptions(const std::string &var, const std::string &value) } else { - options.keys = DEFAULT_CONTROL_SCHEME; + options.keys = DEFAULT_CONTROL_SCHEME; } }}, {"window.zoom", [](const std::string &v) @@ -200,7 +200,7 @@ bool setOptions(const std::string &var, const std::string &value) } else { - options.window.zoom = DEFAULT_WINDOW_ZOOM; + options.window.zoom = DEFAULT_WINDOW_ZOOM; } }}, {"video.mode", [](const std::string &v) @@ -212,7 +212,7 @@ bool setOptions(const std::string &var, const std::string &value) } else { - options.video.mode = 0; + options.video.mode = 0; } }}, {"video.filter", [](const std::string &v) @@ -224,7 +224,7 @@ bool setOptions(const std::string &var, const std::string &value) } else { - options.video.filter = DEFAULT_VIDEO_FILTER; + options.video.filter = DEFAULT_VIDEO_FILTER; } }}, {"video.shaders", [](const std::string &v) @@ -246,7 +246,7 @@ bool setOptions(const std::string &var, const std::string &value) } else { - options.video.border.width = DEFAULT_BORDER_WIDTH; + options.video.border.width = DEFAULT_BORDER_WIDTH; } }}, {"video.border.height", [](const std::string &v) @@ -258,7 +258,7 @@ bool setOptions(const std::string &var, const std::string &value) } else { - options.video.border.height = DEFAULT_BORDER_HEIGHT; + options.video.border.height = DEFAULT_BORDER_HEIGHT; } }}, {"video.palette", [](const std::string &v) diff --git a/source/options.h b/source/options.h index 3759e46..7a3acf0 100644 --- a/source/options.h +++ b/source/options.h @@ -1,9 +1,9 @@ #pragma once -#include // for Uint32 -#include // for string, basic_string -#include "screen.h" // for ScreenFilter -#include "utils.h" // for Color, Palette +#include // Para Uint32 +#include // Para string, basic_string +#include "screen.h" // Para ScreenFilter +#include "utils.h" // Para Color, Palette #include // 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 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 -const Uint8 DEFAULT_NOTIFICATION_COLOR = static_cast(PaletteColor::BLUE); // Color de las notificaciones por defecto +const Uint8 DEFAULT_NOTIFICATION_COLOR = static_cast(PaletteColor::BLUE); // Color de las notificaciones por defecto constexpr bool DEFAULT_CONSOLE = false; // Consola desactivada por defecto constexpr const char *DEFAULT_VERSION = "1.10"; // Versión por defecto @@ -212,7 +212,7 @@ struct OptionsStats worst_nightmare("") {} // Constructor - OptionsStats(int r, int i, const std::string wn) + OptionsStats(int r, int i, const std::string& wn) : rooms(r), items(i), worst_nightmare(wn) {} @@ -279,7 +279,7 @@ struct OptionsVideo palette(DEFAULT_PALETTE) {} // 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), filter(f), vertical_sync(vs), diff --git a/source/player.cpp b/source/player.cpp index 481ff91..c00a1a9 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1,18 +1,15 @@ // IWYU pragma: no_include #include "player.h" -#include // for rand -#include // for max, min -#include // for ceil, abs -#include "s_animated_sprite.h" // for SAnimatedSprite -#include "debug.h" // for Debug -#include "defines.h" // for BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT -#include "input.h" // for Input, InputAction -#include "jail_audio.h" // for JA_PlaySound -#include "options.h" // for Options, options, Cheat, OptionsVideo -#include "resource.h" // for Resource -#include "room.h" // for Room, JA_Sound_t, TileType -#include "screen.h" // for Screen -#include "surface.h" // for Texture +#include // Para max, min +#include // Para ceil, abs +#include "debug.h" // Para Debug +#include "defines.h" // Para BORDER_BOTTOM, BORDER_LEFT, BORDER_RIGHT +#include "input.h" // Para Input, InputAction +#include "jail_audio.h" // Para JA_PlaySound +#include "options.h" // Para Cheat, Options, options +#include "resource.h" // Para Resource +#include "room.h" // Para Room, TileType +#include "s_animated_sprite.h" // Para SAnimatedSprite // Constructor Player::Player(const PlayerData &player) diff --git a/source/player.h b/source/player.h index ca6eb13..3f3a572 100644 --- a/source/player.h +++ b/source/player.h @@ -1,16 +1,16 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for SDL_RendererFlip, SDL_FLIP_NONE -#include // for shared_ptr, __shared_ptr_access -#include // for string -#include // for vector -#include "s_animated_sprite.h" // for SAnimatedSprite -#include "defines.h" // for BORDER_TOP, BLOCK -#include "surface.h" // for Texture -#include "utils.h" // for Color -class Room; // lines 16-16 -struct JA_Sound_t; // lines 17-17 +#include // Para SDL_Rect, SDL_Point +#include // Para SDL_RendererFlip, SDL_FLIP_NONE +#include // Para Uint8 +#include // Para shared_ptr, __shared_ptr_access +#include // Para string +#include // Para vector +#include "defines.h" // Para BORDER_TOP, BLOCK +#include "s_animated_sprite.h" // Para SAnimatedSprite +#include "utils.h" // Para Color +class Room; // lines 12-12 +struct JA_Sound_t; // lines 13-13 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 // Objetos y punteros - std::shared_ptr room_; // Objeto encargado de gestionar cada habitación del juego + std::shared_ptr room_; // Objeto encargado de gestionar cada habitación del juego std::shared_ptr sprite_; // Sprite del jugador // Variables diff --git a/source/resource.cpp b/source/resource.cpp index 0ab5ea8..c9d3bb4 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -1,21 +1,21 @@ #include "resource.h" -#include // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN -#include // for SDLK_ESCAPE -#include // for SDL_Rect -#include // for SDL_RenderDrawRect, SDL_RenderFillRect -#include // for exit, size_t -#include // for find_if -#include // for basic_ostream, operator<<, endl, cout -#include // for runtime_error -#include "asset.h" // for AssetType, Asset -#include "jail_audio.h" // for JA_DeleteMusic, JA_DeleteSound, JA_Loa... -#include "options.h" // for Options, OptionsGame, options -#include "screen.h" // for Screen -#include "text.h" // for Text, loadTextFile -#include "utils.h" // for getFileName, printWithDots, Color -#include "room.h" -struct JA_Music_t; // lines 12-12 -struct JA_Sound_t; // lines 13-13 +#include // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN +#include // Para SDLK_ESCAPE +#include // Para SDL_Rect +#include // Para Uint8 +#include // Para exit, size_t +#include // Para find_if +#include // Para basic_ostream, operator<<, endl, cout +#include // Para runtime_error +#include "asset.h" // Para AssetType, Asset +#include "jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa... +#include "options.h" // Para Options, OptionsGame, options +#include "room.h" // Para RoomData, loadRoomFile, loadRoomTileFile +#include "screen.h" // Para Screen +#include "text.h" // Para Text, loadTextFile +#include "utils.h" // Para getFileName, printWithDots, PaletteColor +struct JA_Music_t; // lines 17-17 +struct JA_Sound_t; // lines 18-18 // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado Resource *Resource::resource_ = nullptr; diff --git a/source/resource.h b/source/resource.h index 7147430..4c34a2c 100644 --- a/source/resource.h +++ b/source/resource.h @@ -1,12 +1,12 @@ #pragma once -#include // for shared_ptr -#include // for string -#include // for vector -#include "s_animated_sprite.h" // for AnimationsFileBuffer -#include "room.h" // for room_t -#include "text.h" // for Text, TextFile -#include "surface.h" // for Surface +#include // Para shared_ptr +#include // Para string +#include // Para vector +#include "s_animated_sprite.h" // Para AnimationsFileBuffer +#include "room.h" // Para room_t +#include "text.h" // Para Text, TextFile +#include "surface.h" // Para Surface struct JA_Music_t; // lines 11-11 struct JA_Sound_t; // lines 12-12 @@ -145,7 +145,7 @@ private: std::vector sounds_; // Vector con los sonidos std::vector musics_; // Vector con las musicas std::vector surfaces_; // Vector con las surfaces - std::vector palettes_; // Vector con las paletas + std::vector palettes_; // Vector con las paletas std::vector text_files_; // Vector con los ficheros de texto std::vector texts_; // Vector con los objetos de texto std::vector animations_; // Vector con las animaciones diff --git a/source/room.cpp b/source/room.cpp index 23d612d..21d31bc 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -1,23 +1,19 @@ #include "room.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for rand -#include // for exception -#include // for basic_ostream, operator<<, basic_ist... -#include // for cout, cerr -#include // for basic_stringstream -#include "debug.h" // for Debug -#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W... -#include "item_tracker.h" // for ItemTracker -#include "jail_audio.h" // for JA_PlaySound -#include "options.h" // for Options, options, OptionsVideo, Opti... -#include "resource.h" // for Resource -#include "scoreboard.h" // for ScoreboardData -#include "screen.h" // for Screen -#include "s_sprite.h" // for SSprite -#include "surface.h" // for Texture -#include "utils.h" // for LineHorizontal, LineDiagonal, LineVe... +#include // Para exception +#include // Para basic_ostream, operator<<, basic_istream +#include // Para cout, cerr +#include // Para basic_stringstream +#include "debug.h" // Para Debug +#include "defines.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH +#include "item_tracker.h" // Para ItemTracker +#include "jail_audio.h" // Para JA_PlaySound +#include "options.h" // Para Options, OptionsStats, options +#include "resource.h" // Para Resource +#include "s_sprite.h" // Para SSprite +#include "scoreboard.h" // Para ScoreboardData +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "utils.h" // Para LineHorizontal, LineDiagonal, LineVertical // Carga las variables y texturas desde un fichero de mapa de tiles std::vector loadRoomTileFile(const std::string &file_path, bool verbose) @@ -474,7 +470,7 @@ void Room::initializeRoom(const RoomData &room) void Room::fillMapTexture() { const Uint8 color = stringToColor(bg_color_); - auto previuos_renderer = Screen::get()->getRendererSurface(); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(map_surface_); map_surface_->clear(color); diff --git a/source/room.h b/source/room.h index 990deb0..db0d66c 100644 --- a/source/room.h +++ b/source/room.h @@ -1,18 +1,16 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for SDL_Texture -#include // for shared_ptr -#include // for string -#include // for vector -#include "enemy.h" // for EnemyData -#include "item.h" // for ItemData -#include "options.h" // for Options, OptionsVideo, options -#include "utils.h" // for stringToColor, Color -class SSprite; // lines 17-17 -class Surface; // lines 18-18 -struct JA_Sound_t; // lines 19-19 -struct ScoreboardData; // lines 20-20 +#include // Para SDL_Rect, SDL_Point +#include // Para Uint8 +#include // Para shared_ptr +#include // Para string +#include // Para vector +#include "enemy.h" // Para EnemyData +#include "item.h" // Para ItemData +#include "utils.h" // Para LineHorizontal, LineDiagonal, LineVertical +class SSprite; // lines 12-12 +class Surface; // lines 13-13 +struct ScoreboardData; // lines 15-15 enum class TileType { @@ -96,7 +94,6 @@ private: std::string tile_map_file_; // Fichero con el mapa de indices de tile std::vector 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 - JA_Sound_t *item_sound_; // Sonido producido al coger un objeto std::vector bottom_floors_; // Lista con las superficies inferiores de la habitación std::vector top_floors_; // Lista con las superficies superiores de la habitación std::vector left_walls_; // Lista con las superficies laterales de la parte izquierda de la habitación @@ -161,7 +158,7 @@ public: ~Room() = default; // 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 Uint8 getBGColor() const { return stringToColor(bg_color_); } diff --git a/source/s_animated_sprite.h b/source/s_animated_sprite.h index 21f3022..4ec4fd2 100644 --- a/source/s_animated_sprite.h +++ b/source/s_animated_sprite.h @@ -46,7 +46,7 @@ public: : SMovingSprite(surface) {} // Destructor - virtual ~SAnimatedSprite() = default; + virtual ~SAnimatedSprite() override = default; // Actualiza las variables del objeto void update() override; diff --git a/source/s_moving_sprite.cpp b/source/s_moving_sprite.cpp index fb99538..0cda10c 100644 --- a/source/s_moving_sprite.cpp +++ b/source/s_moving_sprite.cpp @@ -1,5 +1,5 @@ #include "s_moving_sprite.h" -#include "surface.h" // for Surface +#include "surface.h" // Para Surface // Constructor SMovingSprite::SMovingSprite(std::shared_ptr surface, SDL_Rect pos, SDL_RendererFlip flip) diff --git a/source/s_moving_sprite.h b/source/s_moving_sprite.h index 2711acd..88e2d2a 100644 --- a/source/s_moving_sprite.h +++ b/source/s_moving_sprite.h @@ -1,17 +1,16 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for SDL_RendererFlip, SDL_FLIP_HORIZONTAL -#include // for max -#include // for shared_ptr -#include "s_sprite.h" // for SSprite -class Surface; // lines 9-9 +#include // Para SDL_Rect +#include // Para SDL_RendererFlip, SDL_FLIP_HORIZONTAL +#include // Para Uint8 +#include // Para shared_ptr +#include "s_sprite.h" // Para SSprite +class Surface; // lines 8-8 // Clase SMovingSprite. Añade movimiento y flip al sprite class SMovingSprite : public SSprite { public: - protected: float x_; // Posición en el eje X float y_; // Posición en el eje Y @@ -34,7 +33,7 @@ public: explicit SMovingSprite(std::shared_ptr surface); // Destructor - virtual ~SMovingSprite() = default; + virtual ~SMovingSprite() override = default; // Actualiza las variables internas del objeto virtual void update(); diff --git a/source/s_sprite.h b/source/s_sprite.h index 8fc83f2..7ef8f07 100644 --- a/source/s_sprite.h +++ b/source/s_sprite.h @@ -1,8 +1,9 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para shared_ptr -class Surface; +#include // Para SDL_Rect, SDL_Point +#include // Para Uint8 +#include // Para shared_ptr +class Surface; // lines 5-5 // Clase SSprite class SSprite diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index f63f0c9..66af1b0 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -1,27 +1,25 @@ #include "scoreboard.h" -#include // for SDL_GetError -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_Rect -#include // for SDL_GetTicks -#include // for basic_ostream, operator<<, cout, endl -#include "s_animated_sprite.h" // for SAnimatedSprite -#include "defines.h" // for BLOCK -#include "options.h" // for Options, options, OptionsVideo, Cheat -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#include "text.h" // for Text -#include "surface.h" // for Texture +#include // Para SDL_Rect +#include // Para SDL_GetTicks +#include "defines.h" // Para BLOCK +#include "options.h" // Para Options, options, Cheat, OptionsGame +#include "resource.h" // Para Resource +#include "s_animated_sprite.h" // Para SAnimatedSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "text.h" // Para Text +#include "utils.h" // Para stringToColor // Constructor Scoreboard::Scoreboard(std::shared_ptr data) - : data_(data), + : item_surface_(Resource::get()->getSurface("items.gif")), + data_(data), clock_(ClockData()) { const int SURFACE_WIDTH_ = options.game.width; constexpr int SURFACE_HEIGHT_ = 6 * BLOCK; // 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_animations = Resource::get()->getAnimations(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani"); player_sprite_ = std::make_shared(player_texture, player_animations); @@ -136,7 +134,7 @@ int Scoreboard::getMinutes() void Scoreboard::fillTexture() { // Empieza a dibujar en la textura - auto previuos_renderer = Screen::get()->getRendererSurface(); + auto previuos_renderer = Screen::get()->getRendererSurface(); Screen::get()->setRendererSurface(surface_); // Limpia la textura diff --git a/source/scoreboard.h b/source/scoreboard.h index add11e0..ce85f4d 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -1,14 +1,12 @@ #pragma once -#include // for SDL_Rect -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -#include // for string, basic_string -#include // for vector -#include "utils.h" // for Color -class SAnimatedSprite; // lines 9-9 -class Surface; // lines 13-13 +#include // Para SDL_Rect +#include // Para Uint32, Uint8 +#include // Para shared_ptr +#include // Para string, basic_string +#include // Para vector +class SAnimatedSprite; // lines 10-10 +class Surface; // lines 11-11 struct ScoreboardData { diff --git a/source/screen.cpp b/source/screen.cpp index 16a5d2a..684661b 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -2,19 +2,20 @@ #include // Para SDL_GetError #include // Para SDL_DISABLE, SDL_ENABLE #include // Para SDL_ShowCursor -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para max, min -#include // Para basic_ostream, operator<<, basic_ifstream -#include // Para cout -#include // Para istreambuf_iterator, operator!= -#include // Para basic_string, char_traits, string -#include "asset.h" // Para Asset +#include // Para SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORM... +#include // Para toupper +#include // Para max, min, transform +#include // Para basic_ostream, operator<<, endl, basic_... +#include // Para cerr +#include // Para istreambuf_iterator, operator== +#include // Para char_traits, string, operator+, operator== +#include "asset.h" // Para Asset, AssetType #include "jail_shader.h" // Para init, render -#include "notifier.h" // Para Notify -#include "options.h" -#include "mouse.h" -#include "surface.h" -#include "resource.h" +#include "mouse.h" // Para updateCursorVisibility +#include "notifier.h" // Para Notifier +#include "options.h" // Para Options, options, OptionsVideo, Border +#include "resource.h" // Para Resource +#include "surface.h" // Para Surface, readPalFile // [SINGLETON] Screen *Screen::screen_ = nullptr; @@ -334,7 +335,7 @@ void Screen::resetShaders() std::ifstream f(Asset::get()->get(GLSL_FILE).c_str()); std::string source((std::istreambuf_iterator(f)), std::istreambuf_iterator()); - shader::init(window_, shaders_texture_, source.c_str()); + shader::init(window_, shaders_texture_, source); } } diff --git a/source/screen.h b/source/screen.h index 2126f4a..d066d75 100644 --- a/source/screen.h +++ b/source/screen.h @@ -1,13 +1,16 @@ #pragma once -#include // for SDL_BlendMode -#include // for SDL_Rect -#include // for SDL_Texture, SDL_Renderer -#include // for Uint32 -#include // for SDL_Window -#include "utils.h" // for Color -#include "surface.h" // for Surface -#include // for shared_ptr +#include // Para SDL_BlendMode +#include // Para SDL_Rect +#include // Para SDL_Renderer, SDL_Texture +#include // Para Uint8, Uint32 +#include // Para SDL_Window +#include // Para size_t +#include // Para shared_ptr, __shared_ptr_access +#include // Para string +#include // Para vector +#include "utils.h" // Para Color +class Surface; // Tipos de filtro enum class ScreenFilter : Uint32 diff --git a/source/stats.cpp b/source/stats.cpp index de7a9ff..e7e5a2e 100644 --- a/source/stats.cpp +++ b/source/stats.cpp @@ -1,7 +1,7 @@ #include "stats.h" -#include // for basic_ostream, basic_ifstream, basic_istream -#include // for basic_stringstream -#include "options.h" // for Options, OptionsStats, options +#include // Para basic_ostream, basic_ifstream, basic_istream +#include // Para basic_stringstream +#include "options.h" // Para Options, OptionsStats, options // Constructor Stats::Stats(const std::string &file, const std::string &buffer) diff --git a/source/stats.h b/source/stats.h index bf670d3..1fe0464 100644 --- a/source/stats.h +++ b/source/stats.h @@ -1,7 +1,7 @@ #pragma once -#include // for string -#include // for vector +#include // Para string +#include // Para vector class Stats { @@ -21,10 +21,10 @@ private: // Variables std::vector dictionary; // Lista con la equivalencia nombre-numero de habitacion - std::vector bufferList; // Lista con las estadisticas temporales por habitación - std::vector list; // Lista con las estadisticas completas por habitación - std::string bufferPath; // Fichero con las estadísticas temporales - std::string filePath; // Fichero con las estadísticas completas + std::vector bufferList; // Lista con las estadisticas temporales por habitación + std::vector list; // Lista con las estadisticas completas por habitación + std::string bufferPath; // Fichero con las estadísticas temporales + std::string filePath; // Fichero con las estadísticas completas // Busca una entrada en la lista por nombre int findByName(const std::string &name, const std::vector &list); diff --git a/source/surface.cpp b/source/surface.cpp index dcda9c0..2c80637 100644 --- a/source/surface.cpp +++ b/source/surface.cpp @@ -1,21 +1,18 @@ #include "surface.h" -#include // for SDL_GetError -#include // for size_t -#include // for min, copy, fill -#include // for basic_ostream, basic_ifstream, basic_ios -#include // for cerr, cout -#include // for shared_ptr, __shared_ptr_access, unique_ptr -#include // for runtime_error -#include // for vector -#include "asset.h" // for Asset -#include "screen.h" -#include "gif.h" // for LoadGif, LoadPalette -#include -#include -#include -#include -#include -#include +#include // Para SDL_GetError +#include // Para abs +#include // Para abs +#include // Para min, max, copy_n, fill +#include // Para uint32_t +#include // Para memcpy, size_t +#include // Para basic_ifstream, basic_ostream, basic_ist... +#include // Para cerr +#include // Para shared_ptr, __shared_ptr_access, default... +#include // Para basic_istringstream +#include // Para runtime_error +#include // Para vector +#include "gif.h" // Para Gif +#include "screen.h" // Para Screen // Carga una paleta desde un archivo .gif 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); } - // Leer el contenido del archivo en un buffer + // Obtener el tamaño del archivo y leerlo en un buffer std::streamsize size = file.tellg(); 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 - std::unique_ptr pal(LoadPalette(buffer.data())); - if (pal == nullptr) + GIF::Gif gif; + std::vector 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 - Palette palette; - std::copy(pal.get(), pal.get() + palette.size(), palette.begin()); + // Crear la paleta y copiar los datos desde 'pal' + Palette palette = {}; // Inicializa la paleta con ceros + std::copy_n(pal.begin(), std::min(pal.size(), palette.size()), palette.begin()); // Mensaje de depuración 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 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); - if (!file.is_open()) { std::cerr << "Error opening file: " << file_path << std::endl; throw std::runtime_error("Error opening file"); } + // Obtener el tamaño del archivo std::streamsize size = file.tellg(); file.seekg(0, std::ios::beg); + // Leer el contenido del archivo en un buffer std::vector buffer(size); - if (!file.read((char *)buffer.data(), size)) + if (!file.read(reinterpret_cast(buffer.data()), size)) { std::cerr << "Error reading file: " << file_path << std::endl; throw std::runtime_error("Error reading file"); } - Uint16 w, h; - Uint8 *pixels = LoadGif(buffer.data(), &w, &h); - if (pixels == nullptr) + // Crear un objeto Gif y llamar a la función loadGif + GIF::Gif gif; + Uint16 w = 0, h = 0; + std::vector rawPixels = gif.loadGif(buffer.data(), w, h); + if (rawPixels.empty()) { std::cerr << "Error loading GIF from file: " << file_path << std::endl; throw std::runtime_error("Error loading GIF"); } + // Si el constructor de Surface espera un std::shared_ptr, + // reservamos un bloque dinámico y copiamos los datos del vector. + size_t pixelCount = rawPixels.size(); + auto pixels = std::shared_ptr(new Uint8[pixelCount], std::default_delete()); + std::memcpy(pixels.get(), rawPixels.data(), pixelCount); + // Crear y devolver directamente el objeto SurfaceData printWithDots("Surface : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); return SurfaceData(w, h, pixels); @@ -171,7 +179,8 @@ void Surface::setColor(int index, Uint32 color) void Surface::clear(Uint8 color) { 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 @@ -183,14 +192,14 @@ void Surface::putPixel(int x, int y, Uint8 color) } 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 -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 -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 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) { 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 -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 int x_start = std::max(0, rect->x); @@ -223,11 +232,11 @@ void Surface::drawRectBorder(SDL_Rect *rect, Uint8 color) { // Borde superior 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 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 @@ -235,11 +244,11 @@ void Surface::drawRectBorder(SDL_Rect *rect, Uint8 color) { // Borde izquierdo 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 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 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 @@ -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) { - 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 - 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 (color != transparent_color_) + if (int dest_y = dy + iy; dest_y >= 0 && dest_y < surface_data->height) { - 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) { // 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_) { 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); // Coordenadas de destino - int dest_x = dx + ix; - 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_) + if (int dest_x = dx + ix; dest_x >= 0 && dest_x < surface_data->width) { - 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 - 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_) { 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."); } - 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."); } @@ -481,7 +494,7 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture) int pitch = 0; // 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(&pixels), &pitch) != 0) { 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 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]]; } } diff --git a/source/surface.h b/source/surface.h index dee7a77..f019079 100644 --- a/source/surface.h +++ b/source/surface.h @@ -1,12 +1,14 @@ #pragma once -#include // Para SDL_Renderer -#include // Para Uint8, Uint32 -#include -#include -#include -#include -#include "utils.h" +#include // Para SDL_Rect +#include // Para SDL_FLIP_NONE, SDL_RendererFlip, SDL_Re... +#include // Para Uint8, Uint16, Uint32 +#include // Para array +#include // Para default_delete, shared_ptr, __shared_pt... +#include // Para iota +#include // Para string +#include // Para move +#include "utils.h" // Para PaletteColor // Alias using Palette = std::array; @@ -20,53 +22,30 @@ Palette readPalFile(const std::string &file_path); struct SurfaceData { - Uint8 *data; // Listado de indices de la paleta que conforman la imagen almacenada - Uint16 width; // Ancho de la imagen - Uint16 height; // Alto de la imagen + std::shared_ptr data; // Usa std::shared_ptr para gestión automática + Uint16 width; // Ancho de la imagen + Uint16 height; // Alto de la imagen // Constructor por defecto SurfaceData() : data(nullptr), width(0), height(0) {} // Constructor que inicializa dimensiones y asigna memoria SurfaceData(Uint16 w, Uint16 h) - : data(new Uint8[w * h]()), width(w), height(h) {} + : data(std::shared_ptr(new Uint8[w * h](), std::default_delete())), width(w), height(h) {} // Constructor para inicializar directamente con datos - SurfaceData(Uint16 w, Uint16 h, Uint8 *pixels) - : data(pixels), width(w), height(h) {} + SurfaceData(Uint16 w, Uint16 h, std::shared_ptr pixels) + : data(std::move(pixels)), width(w), height(h) {} - // Destructor para liberar memoria - ~SurfaceData() { delete[] data; } + // Constructor de movimiento + 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 &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 @@ -80,7 +59,7 @@ private: public: // Constructor Surface(int w, int h); - Surface(const std::string &file_path); + explicit Surface(const std::string &file_path); // Destructor ~Surface() = default; @@ -120,10 +99,10 @@ public: Uint8 getPixel(int x, int y); // 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 - void drawRectBorder(SDL_Rect *rect, Uint8 color); + void drawRectBorder(const SDL_Rect *rect, Uint8 color); // Dibuja una linea void drawLine(int x1, int y1, int x2, int y2, Uint8 color); diff --git a/source/text.cpp b/source/text.cpp index e1240a5..a8d368b 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -1,16 +1,13 @@ #include "text.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_Rect -#include // Para SDL_TEXTUREACCESS_TARGET -#include // Para size_t -#include // Para basic_ifstream, basic_istream, basic... -#include // Para cerr -#include // Para runtime_error -#include "screen.h" // Para Screen -#include "s_sprite.h" // Para SSprite -#include "surface.h" // Para Surface -#include "utils.h" // Para Uint8, getFileName, printWithDots +#include // Para SDL_Rect +#include // Para size_t +#include // Para basic_ifstream, basic_istream, basic_ostream +#include // Para cerr +#include // Para runtime_error +#include "s_sprite.h" // Para SSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "utils.h" // Para getFileName, stringToColor, printWithDots // Llena una estructuta TextFile desde un fichero std::shared_ptr 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 { writeColored(x, y, text, textColor, kerning, lenght); - //write(x, y, text, kerning, lenght); + // write(x, y, text, kerning, lenght); } } diff --git a/source/text.h b/source/text.h index 1584dd9..706ee54 100644 --- a/source/text.h +++ b/source/text.h @@ -1,11 +1,10 @@ #pragma once -#include // Para Uint8 -#include // Para unique_ptr, shared_ptr +#include // Para Uint8 +#include // Para shared_ptr, unique_ptr #include // Para string -#include "s_sprite.h" // Para SSprite -#include "utils.h" // Para Uint8 -class Surface; // lines 9-9 +#include "s_sprite.h" // Para SSprite +class Surface; // lines 8-8 constexpr int TEXT_COLOR = 1; constexpr int TEXT_SHADOW = 2; diff --git a/source/texture.cpp b/source/texture.cpp index cf212f0..c498680 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -1,12 +1,12 @@ #include "texture.h" -#include // for SDL_GetError -#include // for SDL_CreateRGBSurfaceWithFormatFrom -#include // for basic_ostream, operator<<, endl, cout -#include // for runtime_error -#include // for char_traits, operator<<, string, opera... -#include // for vector -#include "utils.h" // for getFileName, Color, printWithDots +#include // Para SDL_GetError +#include // Para SDL_CreateRGBSurfaceWithFormatFrom +#include // Para basic_ostream, operator<<, endl, cout +#include // Para runtime_error +#include // Para char_traits, operator<<, string, opera... +#include // Para vector +#include "utils.h" // Para getFileName, Color, printWithDots #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" // para stbi_failure_reason, stbi_image_free diff --git a/source/texture.h b/source/texture.h index d65d594..0e7d569 100644 --- a/source/texture.h +++ b/source/texture.h @@ -1,20 +1,20 @@ #pragma once -#include // for SDL_BlendMode -#include // for SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... -#include // for SDL_Point, SDL_Rect -#include // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... -#include // for Uint8, Uint32 -#include // for string -#include // for vector -struct Color; // lines 11-11 +#include // Para SDL_BlendMode +#include // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... +#include // Para SDL_Point, SDL_Rect +#include // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... +#include // Para Uint8, Uint32 +#include // Para string +#include // Para vector +struct Color; // lines 11-11 class Texture { private: // Objetos y punteros - SDL_Renderer *renderer_; // Renderizador donde dibujar la textura - SDL_Texture *texture_ = nullptr; // La textura + SDL_Renderer *renderer_; // Renderizador donde dibujar la textura + SDL_Texture *texture_ = nullptr; // La textura // Variables std::string path_; // Ruta de la imagen de la textura diff --git a/source/title.cpp b/source/title.cpp index 3e5c33d..dd15dbc 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,24 +1,20 @@ #include "title.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_GetError -#include // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for SDL_SCANCODE_1, SDL_SCANCODE_2 -#include // for SDL_GetTicks -#include // for basic_ostream, operator<<, cout, endl -#include "asset.h" // for Asset -#include "cheevos.h" // for Achievement, Cheevos -#include "defines.h" // for PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH -#include "global_events.h" // for check -#include "global_inputs.h" // for check -#include "input.h" // for Input, inputs_e, REPEAT_FALSE, REPEA... -#include "options.h" // for Options, options, OptionsVideo, Sect... -#include "resource.h" // for Resource -#include "screen.h" // for Screen -#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 +#include // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN +#include // Para SDL_SCANCODE_1, SDL_SCANCODE_2 +#include // Para SDL_GetTicks +#include // Para clamp +#include "cheevos.h" // Para Cheevos, Achievement +#include "defines.h" // Para PLAY_AREA_CENTER_X, GAMECANVAS_WIDTH +#include "global_events.h" // Para check +#include "global_inputs.h" // Para check +#include "input.h" // Para Input, InputAction, REPEAT_FALSE, REP... +#include "options.h" // Para Options, options, SectionState, Section +#include "resource.h" // Para Resource +#include "s_sprite.h" // Para SSprite +#include "screen.h" // Para Screen +#include "surface.h" // Para Surface +#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR +#include "utils.h" // Para stringToColor, PaletteColor, playMusic // Constructor Title::Title() diff --git a/source/title.h b/source/title.h index eabb8f5..516c633 100644 --- a/source/title.h +++ b/source/title.h @@ -1,13 +1,12 @@ #pragma once -#include // for SDL_Rect -#include // for SDL_Texture -#include // for Uint32 -#include // for shared_ptr -#include // for string -#include // for vector -class SSprite; // lines 13-13 -class Surface; // lines 15-15 +#include // Para SDL_Rect +#include // Para Uint32 +#include // Para shared_ptr +#include // Para string +#include // Para vector +class SSprite; // lines 9-9 +class Surface; // lines 10-10 class Title { diff --git a/source/utils.cpp b/source/utils.cpp index 2d28917..28b6ba0 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,16 +1,16 @@ #include "utils.h" -#include // for abs -#include // for find, transform -#include // for tolower -#include // for round, abs -#include // for exception -#include // for path -#include // for basic_ostream, cout, basic_ios, ios, endl -#include // for basic_string, string, char_traits, allocator -#include // for unordered_map, operator==, _Node_const_iter... -#include // for pair -#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_PlayMusic -#include "resource.h" // for Resource +#include // Para abs +#include // Para find, transform +#include // Para tolower +#include // Para round, abs +#include // Para exception +#include // Para path +#include // Para basic_ostream, cout, basic_ios, ios, endl +#include // Para basic_string, string, char_traits, allocator +#include // Para unordered_map, operator==, _Node_const_iter... +#include // Para pair +#include "jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_PlayMusic +#include "resource.h" // Para Resource // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2) diff --git a/source/utils.h b/source/utils.h index 4320980..6974a85 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,10 +1,10 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for SDL_Renderer, SDL_Texture -#include // for Uint8 -#include // for string -#include // for vector +#include // Para SDL_Rect, SDL_Point +#include // Para SDL_Renderer, SDL_Texture +#include // Para Uint8 +#include // Para string +#include // Para vector enum class PaletteColor : Uint8 { @@ -35,52 +35,51 @@ enum class PaletteColor : Uint8 TRANSPARENT = 255, }; - // Estructura para definir un circulo struct Circle { - int x; - int y; - int r; + int x; + int y; + int r; }; // Estructura para definir una linea horizontal struct LineHorizontal { - int x1, x2, y; + int x1, x2, y; }; // Estructura para definir una linea vertical struct LineVertical { - int x, y1, y2; + int x, y1, y2; }; // Estructura para definir una linea diagonal struct LineDiagonal { - int x1, y1, x2, y2; + int x1, y1, x2, y2; }; // Estructura para definir una linea struct Line { - int x1, y1, x2, y2; + int x1, y1, x2, y2; }; // Estructura para definir un color struct Color { - Uint8 r; - Uint8 g; - Uint8 b; + Uint8 r; + Uint8 g; + Uint8 b; - // Constructor por defecto - Color() : r(0), g(0), b(0) {} + // Constructor por defecto + Color() : r(0), g(0), b(0) {} - // Constructor - Color(Uint8 red, Uint8 green, Uint8 blue) - : r(red), g(green), b(blue) {} + // Constructor + Color(Uint8 red, Uint8 green, Uint8 blue) + : r(red), g(green), b(blue) {} }; // Calcula el cuadrado de la distancia entre dos puntos