afegit gif.cpp i jail_shader.cpp desde coffee_crisis_arcade_edition
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "cheevos.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
|
||||
#include <stddef.h> // for NULL
|
||||
#include <fstream> // for basic_ostream, operator<<, basic_ofstream
|
||||
#include <iostream> // for cout, cerr
|
||||
#include "notifier.h" // for Notifier
|
||||
#include "options.h" // for Options, options
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL2/SDL_rwops.h> // Para SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
|
||||
#include <stddef.h> // Para NULL
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include "notifier.h" // Para Notifier
|
||||
#include "options.h" // Para Options, options
|
||||
|
||||
// [SINGLETON]
|
||||
Cheevos *Cheevos::cheevos_ = nullptr;
|
||||
@@ -89,7 +89,7 @@ void Cheevos::unlock(int id)
|
||||
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();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
// Struct para los logros
|
||||
struct Achievement
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
void enable(bool value) { enabled_ = value; }
|
||||
|
||||
// Lista los logros
|
||||
std::vector<Achievement> list() { return cheevos_list_; }
|
||||
const std::vector<Achievement>& list() const { return cheevos_list_; }
|
||||
|
||||
// Devuelve el número total de logros desbloqueados
|
||||
int getTotalUnlockedAchievements();
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
#include "credits.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min
|
||||
#include <iostream> // 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 <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // 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
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
#include <memory>
|
||||
#include "surface.h"
|
||||
class SAnimatedSprite; // lines 9-9
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
class SAnimatedSprite; // lines 11-11
|
||||
class Surface;
|
||||
|
||||
class Credits
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "debug.h"
|
||||
#include <algorithm> // for max
|
||||
#include <memory> // for __shared_ptr_access, shared_ptr
|
||||
#include "resource.h" // for Resource
|
||||
#include "text.h" // for Text
|
||||
#include "utils.h" // for Color
|
||||
#include <algorithm> // Para max
|
||||
#include <memory> // 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;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
// Clase Debug
|
||||
class Debug
|
||||
|
||||
@@ -1,42 +1,41 @@
|
||||
#include "director.h"
|
||||
#include <SDL2/SDL.h> // for SDL_Init, SDL_Quit, SDL_INIT_EV...
|
||||
#include <SDL2/SDL_audio.h> // for AUDIO_S16
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_gamecontroller.h> // for SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||
#include <SDL2/SDL_hints.h> // for SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_ES...
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV...
|
||||
#include <SDL2/SDL_audio.h> // Para AUDIO_S16
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // Para SDL_DISABLE
|
||||
#include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_CO...
|
||||
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
|
||||
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // for printf, perror
|
||||
#include <string.h> // for strcmp
|
||||
#include <sys/stat.h> // for mkdir, stat, S_IRWXU
|
||||
#include <unistd.h> // for getuid
|
||||
#include <cstdlib> // for exit, EXIT_FAILURE, srand
|
||||
#include <iostream> // for basic_ostream, operator<<, cout
|
||||
#include <memory> // for make_unique, unique_ptr
|
||||
#include <string> // 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 <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_A, SDL_SCANCODE_ES...
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // Para printf, perror
|
||||
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
|
||||
#include <unistd.h> // Para getuid
|
||||
#include <cstdlib> // Para exit, EXIT_FAILURE, srand
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout
|
||||
#include <memory> // Para make_unique, unique_ptr
|
||||
#include <string> // 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 <pwd.h>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include <string> // for string
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||
#include <SDL2/SDL_video.h> // Para SDL_Window
|
||||
#include <string> // Para string
|
||||
|
||||
class Director
|
||||
{
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
#include "ending.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min
|
||||
#include <iostream> // 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<Uint8>,PaletteColor::PALETTE
|
||||
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // 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),
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
class SSprite; // lines 12-12
|
||||
class Surface; // lines 14-14
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
class SSprite; // lines 8-8
|
||||
class Surface; // lines 9-9
|
||||
|
||||
class Ending
|
||||
{
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
#include "ending2.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_RenderDrawPoint, SDL_SetRenderDr...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // 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<Uint8>
|
||||
#include <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // 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()
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // 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 <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "defines.h" // Para GAMECANVAS_WIDTH, GAMECANVAS_FIRST_QUAR...
|
||||
class SAnimatedSprite; // lines 9-9
|
||||
class SMovingSprite; // lines 10-10
|
||||
|
||||
class Ending2
|
||||
{
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "enemy.h"
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE, SDL_FL...
|
||||
#include <stdlib.h> // 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 <SDL2/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_NONE, SDL_...
|
||||
#include <stdlib.h> // 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)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include "utils.h" // for Color
|
||||
class SAnimatedSprite;
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
class SAnimatedSprite; // lines 7-7
|
||||
|
||||
// Estructura para pasar los datos de un enemigo
|
||||
struct EnemyData
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
#include "game.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||
#include <vector> // 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 <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL
|
||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_7, SDL_SCANCODE_A, SDL_S...
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <vector> // 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)
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // 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 <SDL2/SDL_events.h> // Para SDL_Event
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <initializer_list> // Para initializer_list
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // 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();
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "game_over.h"
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <algorithm> // for min, max
|
||||
#include <string> // 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 <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // Para min, max
|
||||
#include <string> // 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()
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
class SAnimatedSprite; // lines 8-8
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <vector> // Para vector
|
||||
class SAnimatedSprite; // lines 7-7
|
||||
|
||||
class GameOver
|
||||
{
|
||||
|
||||
545
source/gif.cpp
545
source/gif.cpp
@@ -1,391 +1,316 @@
|
||||
#include "gif.h"
|
||||
#include <stdio.h> // for NULL, fprintf, stderr
|
||||
#include <stdlib.h> // for malloc, realloc, exit, calloc, free
|
||||
#include <iostream> // Para std::cout
|
||||
#include <cstring> // Para memcpy, size_t
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <string> // Para allocator, char_traits, operator==, basic_string
|
||||
|
||||
void uncompress( int code_length,
|
||||
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++;
|
||||
void Gif::decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out)
|
||||
{
|
||||
// Verifica que el code_length tenga un rango razonable.
|
||||
if (code_length < 2 || code_length > 12)
|
||||
{
|
||||
throw std::runtime_error("Invalid LZW code length");
|
||||
}
|
||||
|
||||
// TODO verify that the very last byte is clear_code + 1
|
||||
while ( input_length )
|
||||
int i, bit;
|
||||
int prev = -1;
|
||||
std::vector<DictionaryEntry> 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;
|
||||
|
||||
// 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++)
|
||||
{
|
||||
code = 0x0;
|
||||
// Always read one more bit than the code length
|
||||
for ( i = 0; i < ( code_length + 1 ); i++ )
|
||||
dictionary[dictionary_ind].byte = static_cast<uint8_t>(dictionary_ind);
|
||||
dictionary[dictionary_ind].prev = -1;
|
||||
dictionary[dictionary_ind].len = 1;
|
||||
}
|
||||
dictionary_ind += 2; // Reservamos espacio para clear y stop codes
|
||||
|
||||
// Bucle principal: procesar el stream comprimido.
|
||||
while (input_length > 0)
|
||||
{
|
||||
// This is different than in the file read example; that
|
||||
// was a call to "next_bit"
|
||||
bit = ( *input & mask ) ? 1 : 0;
|
||||
int code = 0;
|
||||
// Lee (code_length + 1) bits para formar el código.
|
||||
for (i = 0; i < (code_length + 1); i++)
|
||||
{
|
||||
if (input_length <= 0)
|
||||
{
|
||||
throw std::runtime_error("Unexpected end of input in decompress");
|
||||
}
|
||||
bit = ((*input & mask) != 0) ? 1 : 0;
|
||||
mask <<= 1;
|
||||
|
||||
if ( mask == 0x100 )
|
||||
if (mask == 0x100)
|
||||
{
|
||||
mask = 0x01;
|
||||
input++;
|
||||
input_length--;
|
||||
}
|
||||
|
||||
code = code | ( bit << i );
|
||||
code |= (bit << i);
|
||||
}
|
||||
|
||||
if ( code == clear_code )
|
||||
if (code == clear_code)
|
||||
{
|
||||
// Reinicia el diccionario.
|
||||
code_length = reset_code_length;
|
||||
dictionary = ( dictionary_entry_t * ) realloc( dictionary,
|
||||
sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
||||
|
||||
for ( dictionary_ind = 0;
|
||||
dictionary_ind < ( 1 << code_length );
|
||||
dictionary_ind++ )
|
||||
dictionary.resize(1 << (code_length + 1));
|
||||
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[dictionary_ind].byte = static_cast<uint8_t>(dictionary_ind);
|
||||
dictionary[dictionary_ind].prev = -1;
|
||||
dictionary[dictionary_ind].len = 1;
|
||||
}
|
||||
dictionary_ind++;
|
||||
dictionary_ind++;
|
||||
dictionary_ind += 2;
|
||||
prev = -1;
|
||||
continue;
|
||||
}
|
||||
else if ( code == stop_code )
|
||||
else if (code == stop_code)
|
||||
{
|
||||
/*if ( input_length > 1 )
|
||||
{
|
||||
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 (prev > -1 && code_length < 12)
|
||||
{
|
||||
if ( code > dictionary_ind )
|
||||
if (code > dictionary_ind)
|
||||
{
|
||||
fprintf( stderr, "code = %.02x, but dictionary_ind = %.02x\n",
|
||||
code, dictionary_ind );
|
||||
exit( 0 );
|
||||
std::cerr << "code = " << std::hex << code
|
||||
<< ", but dictionary_ind = " << dictionary_ind << std::endl;
|
||||
throw std::runtime_error("LZW error: code exceeds dictionary_ind.");
|
||||
}
|
||||
|
||||
// Special handling for KwKwK
|
||||
if ( code == dictionary_ind )
|
||||
int ptr;
|
||||
if (code == dictionary_ind)
|
||||
{
|
||||
int ptr = prev;
|
||||
|
||||
while ( dictionary[ ptr ].prev != -1 )
|
||||
{
|
||||
ptr = dictionary[ ptr ].prev;
|
||||
}
|
||||
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
||||
ptr = prev;
|
||||
while (dictionary[ptr].prev != -1)
|
||||
ptr = dictionary[ptr].prev;
|
||||
dictionary[dictionary_ind].byte = dictionary[ptr].byte;
|
||||
}
|
||||
else
|
||||
{
|
||||
int ptr = code;
|
||||
while ( dictionary[ ptr ].prev != -1 )
|
||||
{
|
||||
ptr = dictionary[ ptr ].prev;
|
||||
ptr = code;
|
||||
while (dictionary[ptr].prev != -1)
|
||||
ptr = dictionary[ptr].prev;
|
||||
dictionary[dictionary_ind].byte = dictionary[ptr].byte;
|
||||
}
|
||||
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
||||
}
|
||||
|
||||
dictionary[ dictionary_ind ].prev = prev;
|
||||
|
||||
dictionary[ dictionary_ind ].len = dictionary[ prev ].len + 1;
|
||||
|
||||
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 ) )
|
||||
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 ) ) );
|
||||
dictionary.resize(1 << (code_length + 1));
|
||||
}
|
||||
}
|
||||
|
||||
prev = code;
|
||||
|
||||
// Now copy the dictionary entry backwards into "out"
|
||||
match_len = dictionary[ code ].len;
|
||||
while ( code != -1 )
|
||||
// Verifica que 'code' sea un índice válido antes de usarlo.
|
||||
if (code < 0 || static_cast<size_t>(code) >= dictionary.size())
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
std::vector<uint8_t> Gif::readSubBlocks(const uint8_t *&buffer)
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
uint8_t block_size = *buffer;
|
||||
buffer++;
|
||||
while (block_size != 0)
|
||||
{
|
||||
data.insert(data.end(), buffer, buffer + block_size);
|
||||
buffer += block_size;
|
||||
block_size = *buffer;
|
||||
buffer++;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
return data_length;
|
||||
}
|
||||
std::vector<uint8_t> Gif::processImageDescriptor(const uint8_t *&buffer, const std::vector<RGB> &gct, int resolution_bits)
|
||||
{
|
||||
ImageDescriptor image_descriptor;
|
||||
// Lee 9 bytes para el image descriptor.
|
||||
readBytes(buffer, &image_descriptor, sizeof(ImageDescriptor));
|
||||
|
||||
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;
|
||||
uint8_t lzw_code_size;
|
||||
readBytes(buffer, &lzw_code_size, sizeof(uint8_t));
|
||||
|
||||
// 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 );
|
||||
std::vector<uint8_t> compressed_data = readSubBlocks(buffer);
|
||||
int uncompressed_data_length = image_descriptor.image_width * image_descriptor.image_height;
|
||||
std::vector<uint8_t> uncompressed_data(uncompressed_data_length);
|
||||
|
||||
decompress(lzw_code_size, compressed_data.data(), static_cast<int>(compressed_data.size()), uncompressed_data.data());
|
||||
return uncompressed_data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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++))
|
||||
std::vector<uint32_t> Gif::loadPalette(const uint8_t *buffer)
|
||||
{
|
||||
uint8_t header[6];
|
||||
std::memcpy(header, buffer, 6);
|
||||
buffer += 6;
|
||||
|
||||
uint32_t* LoadPalette(unsigned char *buffer) {
|
||||
unsigned char header[7];
|
||||
screen_descriptor_t screen_descriptor;
|
||||
//int color_resolution_bits;
|
||||
ScreenDescriptor screen_descriptor;
|
||||
std::memcpy(&screen_descriptor, buffer, sizeof(ScreenDescriptor));
|
||||
buffer += sizeof(ScreenDescriptor);
|
||||
|
||||
int global_color_table_size = 0; // number of entries in global_color_table
|
||||
uint32_t *global_color_table = NULL;
|
||||
|
||||
READ(header, 6);
|
||||
READ(&screen_descriptor, 7);
|
||||
|
||||
//color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
|
||||
global_color_table = (uint32_t *)calloc(1, 1024);
|
||||
|
||||
if (screen_descriptor.fields & 0x80) {
|
||||
global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
|
||||
|
||||
//global_color_table = (rgb *)malloc(3 * global_color_table_size);
|
||||
//READ(global_color_table, 3 * global_color_table_size);
|
||||
for (int i=0; i<global_color_table_size;++i) {
|
||||
global_color_table[i] = (buffer[0]<<16) + (buffer[1]<<8) + buffer[2];
|
||||
buffer+=3;
|
||||
std::vector<uint32_t> global_color_table;
|
||||
if (screen_descriptor.fields & 0x80)
|
||||
{
|
||||
int global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
|
||||
global_color_table.resize(global_color_table_size);
|
||||
for (int i = 0; i < global_color_table_size; ++i)
|
||||
{
|
||||
uint8_t r = buffer[0];
|
||||
uint8_t g = buffer[1];
|
||||
uint8_t b = buffer[2];
|
||||
global_color_table[i] = (r << 16) | (g << 8) | b;
|
||||
buffer += 3;
|
||||
}
|
||||
}
|
||||
return global_color_table;
|
||||
}
|
||||
|
||||
static unsigned char* process_gif_stream(unsigned char *buffer, unsigned short* w, unsigned short* h)
|
||||
{
|
||||
unsigned char header[ 7 ];
|
||||
screen_descriptor_t screen_descriptor;
|
||||
int color_resolution_bits;
|
||||
|
||||
int global_color_table_size =0; // number of entries in global_color_table
|
||||
rgb *global_color_table = NULL;
|
||||
|
||||
unsigned char block_type = 0x0;
|
||||
|
||||
// A GIF file starts with a Header (section 17)
|
||||
READ(header, 6);
|
||||
header[ 6 ] = 0x0;
|
||||
|
||||
// XXX there's another format, GIF87a, that you may still find
|
||||
// floating around.
|
||||
/*if ( strcmp( "GIF89a", (char*)header ) )
|
||||
{
|
||||
fprintf( stderr,
|
||||
"Invalid GIF file (header is '%s', should be 'GIF89a')\n",
|
||||
header );
|
||||
return NULL;
|
||||
}*/
|
||||
|
||||
// Followed by a logical screen descriptor
|
||||
// Note that this works because GIFs specify little-endian order; on a
|
||||
// big-endian machine, the height & width would need to be reversed.
|
||||
|
||||
// Can't use sizeof here since GCC does byte alignment;
|
||||
// sizeof( screen_descriptor_t ) = 8!
|
||||
READ(&screen_descriptor, 7);
|
||||
*w = screen_descriptor.width;
|
||||
*h = screen_descriptor.height;
|
||||
|
||||
color_resolution_bits = ( ( screen_descriptor.fields & 0x70 ) >> 4 ) + 1;
|
||||
|
||||
if ( screen_descriptor.fields & 0x80 )
|
||||
{
|
||||
//int i;
|
||||
// If bit 7 is set, the next block is a global color table; read it
|
||||
global_color_table_size = 1 <<
|
||||
( ( ( screen_descriptor.fields & 0x07 ) + 1 ) );
|
||||
|
||||
global_color_table = ( rgb * ) malloc( 3 * global_color_table_size );
|
||||
|
||||
// XXX this could conceivably return a short count...
|
||||
READ(global_color_table, 3 * global_color_table_size);
|
||||
}
|
||||
|
||||
while ( block_type != TRAILER )
|
||||
std::vector<uint8_t> Gif::processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h)
|
||||
{
|
||||
READ(&block_type, 1);
|
||||
// Leer la cabecera de 6 bytes ("GIF87a" o "GIF89a")
|
||||
uint8_t header[6];
|
||||
std::memcpy(header, buffer, 6);
|
||||
buffer += 6;
|
||||
|
||||
unsigned char size;
|
||||
switch ( block_type )
|
||||
// Opcional: Validar header
|
||||
std::string headerStr(reinterpret_cast<char *>(header), 6);
|
||||
if (headerStr != "GIF87a" && headerStr != "GIF89a")
|
||||
{
|
||||
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);
|
||||
throw std::runtime_error("Formato de archivo GIF inválido.");
|
||||
}
|
||||
|
||||
/*if ( !process_extension( buffer ) )
|
||||
// Leer el Screen Descriptor (7 bytes, empaquetado sin padding)
|
||||
ScreenDescriptor screen_descriptor;
|
||||
readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor));
|
||||
|
||||
// Asigna ancho y alto
|
||||
w = screen_descriptor.width;
|
||||
h = screen_descriptor.height;
|
||||
|
||||
int color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
|
||||
std::vector<RGB> global_color_table;
|
||||
if (screen_descriptor.fields & 0x80)
|
||||
{
|
||||
return NULL;
|
||||
}*/
|
||||
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 TRAILER:
|
||||
}
|
||||
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:
|
||||
fprintf( stderr, "Bailing on unrecognized block type %.02x\n",
|
||||
block_type );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
unsigned char* LoadGif(unsigned char *buffer, unsigned short* w, unsigned short* h) {
|
||||
return process_gif_stream(buffer, w, h);
|
||||
}
|
||||
|
||||
/*int main( int argc, char *argv[] )
|
||||
{
|
||||
FILE* gif_file;
|
||||
|
||||
if ( argc < 2 )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s <path-to-gif-file>\n", argv[ 0 ] );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
gif_file = fopen( argv[ 1 ], "rb" );
|
||||
|
||||
if ( gif_file == NULL )
|
||||
// Si la etiqueta de extensión es desconocida, saltarla también:
|
||||
uint8_t blockSize = *buffer++;
|
||||
buffer += blockSize;
|
||||
uint8_t subBlockSize = *buffer++;
|
||||
while (subBlockSize != 0)
|
||||
{
|
||||
fprintf( stderr, "Unable to open file '%s'", argv[ 1 ] );
|
||||
perror( ": " );
|
||||
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
|
||||
{
|
||||
std::cerr << "Unrecognized block type " << std::hex << static_cast<int>(block_type) << std::endl;
|
||||
return std::vector<uint8_t>{};
|
||||
}
|
||||
block_type = *buffer++;
|
||||
}
|
||||
|
||||
process_gif_stream( gif_file );
|
||||
return std::vector<uint8_t>{};
|
||||
}
|
||||
|
||||
fclose( gif_file );
|
||||
}*/
|
||||
std::vector<uint8_t> Gif::loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h)
|
||||
{
|
||||
return processGifStream(buffer, w, h);
|
||||
}
|
||||
|
||||
} // namespace GIF
|
||||
|
||||
138
source/gif.h
138
source/gif.h
@@ -1,66 +1,102 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h> // for uint32_t
|
||||
#include <string.h> // for memcpy
|
||||
#include <cstdint> // Para uint8_t, uint16_t, uint32_t
|
||||
#include <vector> // 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;
|
||||
struct DictionaryEntry
|
||||
{
|
||||
uint8_t byte;
|
||||
int prev;
|
||||
int len;
|
||||
} dictionary_entry_t;
|
||||
};
|
||||
|
||||
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);
|
||||
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<uint32_t> loadPalette(const uint8_t *buffer);
|
||||
|
||||
// Carga el stream GIF; devuelve un vector con los datos de imagen sin comprimir y
|
||||
// asigna el ancho y alto mediante referencias.
|
||||
std::vector<uint8_t> loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h);
|
||||
|
||||
private:
|
||||
// Lee los sub-bloques de datos y los acumula en un std::vector<uint8_t>.
|
||||
std::vector<uint8_t> readSubBlocks(const uint8_t *&buffer);
|
||||
|
||||
// Procesa el Image Descriptor y retorna el vector de datos sin comprimir.
|
||||
std::vector<uint8_t> processImageDescriptor(const uint8_t *&buffer, const std::vector<RGB> &gct, int resolution_bits);
|
||||
|
||||
// Procesa el stream completo del GIF y devuelve los datos sin comprimir.
|
||||
std::vector<uint8_t> processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h);
|
||||
};
|
||||
|
||||
} // namespace GIF
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "global_inputs.h"
|
||||
#include <string> // for basic_string
|
||||
#include <vector> // 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 <SDL2/SDL_render.h> // Para SDL_RenderSetIntegerScale
|
||||
#include <SDL2/SDL_stdinc.h> // Para SDL_FALSE, SDL_TRUE
|
||||
#include <string> // Para allocator, operator+, char_traits, string
|
||||
#include <vector> // 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
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "s_sprite.h" // for SSprite
|
||||
#include "surface.h" // for Texture
|
||||
#include "utils.h" // for Color
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
class SSprite;
|
||||
|
||||
struct ItemData
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "jail_audio.h"
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromMem
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdint.h> // for uint8_t, uint32_t
|
||||
#include <stdio.h> // for NULL, fseek, fclose, fopen, fread, ftell
|
||||
#include <stdlib.h> // for free, malloc
|
||||
#include "stb_vorbis.c" // for stb_vorbis_decode_memory
|
||||
#include <SDL2/SDL_rwops.h> // Para SDL_RWFromMem
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <stdint.h> // Para uint8_t, uint32_t
|
||||
#include <stdio.h> // Para NULL, fseek, fclose, fopen, fread, ftell
|
||||
#include <stdlib.h> // Para free, malloc
|
||||
#include "stb_vorbis.c" // Para stb_vorbis_decode_memory
|
||||
|
||||
constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_audio.h> // for SDL_AudioFormat
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||
#include <SDL2/SDL_audio.h> // Para SDL_AudioFormat
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||
struct JA_Music_t; // lines 5-5
|
||||
struct JA_Sound_t; // lines 6-6
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
#include "jail_shader.h"
|
||||
#include <SDL2/SDL_rect.h> // para SDL_Point
|
||||
#include <stdlib.h> // para NULL, free, malloc, exit
|
||||
#include <string.h> // para strncmp
|
||||
#include <iostream> // para basic_ostream, char_traits, operator<<
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // Para SDL_bool
|
||||
#include <cstring> // Para strncmp
|
||||
#include <iostream> // Para basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <vector> // Para vector
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "CoreFoundation/CoreFoundation.h"
|
||||
#include <OpenGL/OpenGL.h>
|
||||
|
||||
#include "CoreFoundation/CoreFoundation.h" // Para Core Foundation en macOS
|
||||
#include <OpenGL/OpenGL.h> // Para OpenGL en macOS
|
||||
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
#include <OpenGL/gl3.h>
|
||||
#else
|
||||
#include <OpenGL/gl.h>
|
||||
#endif //! ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
#else
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#endif
|
||||
#include <OpenGL/gl3.h> // Para OpenGL 3 en macOS
|
||||
#else // NO ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
#include <OpenGL/gl.h> // Para OpenGL (compatibilidad) en macOS
|
||||
#endif // ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||
#else // SI NO ES __APPLE__
|
||||
#include <SDL2/SDL_opengl.h> // 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;
|
||||
}
|
||||
return result;
|
||||
throw std::runtime_error("ERROR FATAL: El código fuente del shader está vacío.");
|
||||
}
|
||||
|
||||
GLuint compileProgram(const char *vertexShaderSource, const char *fragmentShaderSource)
|
||||
{
|
||||
GLuint programId = 0;
|
||||
GLuint vtxShaderId, fragShaderId;
|
||||
// Crear identificador del shader
|
||||
GLuint resultado = glCreateShader(shaderType);
|
||||
|
||||
programId = glCreateProgram();
|
||||
// Agregar una directiva según el tipo de shader
|
||||
std::string directiva = (shaderType == GL_VERTEX_SHADER)
|
||||
? "#define VERTEX\n"
|
||||
: "#define FRAGMENT\n";
|
||||
|
||||
vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||
fragShaderId = compileShader(fragmentShaderSource ? fragmentShaderSource : vertexShaderSource, GL_FRAGMENT_SHADER);
|
||||
const char *sources[2] = {directiva.c_str(), source.c_str()};
|
||||
|
||||
if (vtxShaderId && fragShaderId)
|
||||
{
|
||||
// Associate shader with program
|
||||
glAttachShader(programId, vtxShaderId);
|
||||
glAttachShader(programId, fragShaderId);
|
||||
glLinkProgram(programId);
|
||||
glValidateProgram(programId);
|
||||
// Especificar el código fuente del shader
|
||||
glShaderSource(resultado, 2, sources, nullptr);
|
||||
|
||||
// Check the status of the compile/link
|
||||
GLint logLen;
|
||||
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen);
|
||||
if (logLen > 0)
|
||||
// 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (vtxShaderId)
|
||||
std::cout << "Error en la compilación del shader (" << resultado << ")!" << std::endl;
|
||||
GLint longitudLog;
|
||||
glGetShaderiv(resultado, GL_INFO_LOG_LENGTH, &longitudLog);
|
||||
if (longitudLog > 0)
|
||||
{
|
||||
glDeleteShader(vtxShaderId);
|
||||
std::vector<GLchar> log(longitudLog);
|
||||
glGetShaderInfoLog(resultado, longitudLog, &longitudLog, log.data());
|
||||
std::cout << "Registro de compilación del shader: " << log.data() << std::endl;
|
||||
}
|
||||
if (fragShaderId)
|
||||
{
|
||||
glDeleteShader(fragShaderId);
|
||||
glDeleteShader(resultado);
|
||||
resultado = 0;
|
||||
}
|
||||
return programId;
|
||||
return resultado;
|
||||
}
|
||||
|
||||
const bool init(SDL_Window *win, SDL_Texture *backBuffer, const char *vertexShader, const char *fragmentShader)
|
||||
// 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)
|
||||
{
|
||||
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)
|
||||
GLuint idPrograma = 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);
|
||||
|
||||
if (idShaderVertice && idShaderFragmento)
|
||||
{
|
||||
std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl;
|
||||
exit(1);
|
||||
// Asociar los shaders al programa
|
||||
glAttachShader(idPrograma, idShaderVertice);
|
||||
glAttachShader(idPrograma, idShaderFragmento);
|
||||
glLinkProgram(idPrograma);
|
||||
glValidateProgram(idPrograma);
|
||||
|
||||
// Verificar el estado del enlace
|
||||
GLint longitudLog;
|
||||
glGetProgramiv(idPrograma, GL_INFO_LOG_LENGTH, &longitudLog);
|
||||
if (longitudLog > 0)
|
||||
{
|
||||
std::vector<char> log(longitudLog);
|
||||
glGetProgramInfoLog(idPrograma, longitudLog, &longitudLog, log.data());
|
||||
std::cout << "Registro de información del programa:" << std::endl
|
||||
<< log.data() << std::endl;
|
||||
}
|
||||
}
|
||||
if (idShaderVertice)
|
||||
{
|
||||
glDeleteShader(idShaderVertice);
|
||||
}
|
||||
if (idShaderFragmento)
|
||||
{
|
||||
glDeleteShader(idShaderFragmento);
|
||||
}
|
||||
return idPrograma;
|
||||
}
|
||||
|
||||
SDL_RendererInfo rendererInfo;
|
||||
SDL_GetRendererInfo(renderer, &rendererInfo);
|
||||
|
||||
if (!strncmp(rendererInfo.name, "opengl", 6))
|
||||
bool init(SDL_Window *ventana, SDL_Texture *texturaBackBuffer, const std::string &vertexShader, const std::string &fragmentShader)
|
||||
{
|
||||
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)
|
||||
{
|
||||
throw std::runtime_error("ERROR FATAL: La textura debe tener definido SDL_TEXTUREACCESS_TARGET.");
|
||||
}
|
||||
|
||||
SDL_RendererInfo infoRenderer;
|
||||
SDL_GetRendererInfo(renderer, &infoRenderer);
|
||||
|
||||
// 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<float>(win_size.x) / win_size.y;
|
||||
float logicalAspect = static_cast<float>(logicalW) / logicalH;
|
||||
if (windowAspect > logicalAspect)
|
||||
{
|
||||
viewportW = static_cast<int>(logicalAspect * win_size.y);
|
||||
viewportX = (win_size.x - viewportW) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
viewportH = static_cast<int>(win_size.x / logicalAspect);
|
||||
viewportY = (win_size.y - viewportH) / 2;
|
||||
}
|
||||
}
|
||||
glViewport(viewportX, viewportY, viewportW, viewportH);
|
||||
|
||||
minu = 0.0f;
|
||||
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<GLdouble>(logicalW), static_cast<GLdouble>(logicalH), 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// Dibuja el quad con las coordenadas ajustadas.
|
||||
// Se asignan las coordenadas de textura "normales" para que no quede espejado horizontalmente,
|
||||
// y se mantiene el flip vertical para que la imagen no aparezca volteada.
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
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<GLfloat>(logicalW), 0.0f);
|
||||
// Vértice inferior izquierdo
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex2f(0.0f, static_cast<GLfloat>(logicalH));
|
||||
// Vértice inferior derecho
|
||||
glTexCoord2f(1.0f, 0.0f);
|
||||
glVertex2f(static_cast<GLfloat>(logicalW), static_cast<GLfloat>(logicalH));
|
||||
glEnd();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // para SDL_Texture
|
||||
#include <SDL2/SDL_video.h> // para SDL_Window
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Texture
|
||||
#include <SDL2/SDL_video.h> // Para SDL_Window
|
||||
#include <string>
|
||||
|
||||
// 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();
|
||||
}
|
||||
@@ -1,20 +1,17 @@
|
||||
#include "loading_screen.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdlib.h> // for rand
|
||||
#include <iostream> // 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 <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <stdlib.h> // 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()
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
class SSprite; // lines 11-11
|
||||
class Surface; // lines 12-12
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para shared_ptr
|
||||
class SSprite; // lines 7-7
|
||||
class Surface; // lines 8-8
|
||||
|
||||
class LoadingScreen
|
||||
{
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
#include "logo.h"
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <string> // 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 <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event
|
||||
#include <SDL2/SDL_timer.h> // 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()
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
class SSprite; // lines 12-12
|
||||
class Surface; // lines 13-13
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <vector> // Para vector
|
||||
class SSprite; // lines 7-7
|
||||
class Surface; // lines 8-8
|
||||
|
||||
class Logo
|
||||
{
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "notifier.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_render.h> // for SDL_RenderFillRect, SDL_RenderClear
|
||||
#include <algorithm> // for remove_if
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // 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 <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // Para remove_if
|
||||
#include <iterator> // Para prev
|
||||
#include <string> // Para string, basic_string
|
||||
#include <vector> // 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<std::string> 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<Uint8>(PaletteColor::CYAN));
|
||||
SDL_Rect squared_rect = {0, 0, n.surface->getWidth(), n.surface->getHeight()};
|
||||
n.surface->drawRectBorder(&squared_rect, static_cast<Uint8>(PaletteColor::CYAN));
|
||||
}
|
||||
|
||||
// Dibuja el icono de la notificación
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
class SSprite; // lines 9-9
|
||||
class Text; // lines 10-10
|
||||
class Surface; // lines 11-11
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string, basic_string
|
||||
#include <vector> // Para vector
|
||||
class SSprite; // lines 8-8
|
||||
class Surface; // lines 10-10
|
||||
class Text; // lines 9-9
|
||||
|
||||
// Constantes
|
||||
constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "options.h"
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN_DESKTOP
|
||||
#include <algorithm> // for find_if
|
||||
#include <cctype> // for isspace
|
||||
#include <fstream> // for basic_ostream, operator<<, basic_ofstream
|
||||
#include <functional> // for function
|
||||
#include <iostream> // for cout, cerr
|
||||
#include <sstream> // for basic_istringstream
|
||||
#include <string> // for char_traits, string, operator<<, hash
|
||||
#include <unordered_map> // for unordered_map, operator==, _Node_const_i...
|
||||
#include <utility> // for pair
|
||||
#include <SDL2/SDL_video.h> // Para SDL_WINDOW_FULLSCREEN_DESKTOP
|
||||
#include <algorithm> // Para find_if
|
||||
#include <cctype> // Para isspace
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
|
||||
#include <functional> // Para function
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <sstream> // Para basic_istringstream
|
||||
#include <string> // Para char_traits, string, operator<<, hash
|
||||
#include <unordered_map> // Para unordered_map, operator==, _Node_const_i...
|
||||
#include <utility> // Para pair
|
||||
|
||||
// Variables
|
||||
Options options;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <string> // for string, basic_string
|
||||
#include "screen.h" // for ScreenFilter
|
||||
#include "utils.h" // for Color, Palette
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <string> // Para string, basic_string
|
||||
#include "screen.h" // Para ScreenFilter
|
||||
#include "utils.h" // Para Color, Palette
|
||||
#include <algorithm>
|
||||
|
||||
// Secciones del programa
|
||||
@@ -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),
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
// IWYU pragma: no_include <bits/std_abs.h>
|
||||
#include "player.h"
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for max, min
|
||||
#include <cmath> // 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 <algorithm> // Para max, min
|
||||
#include <cmath> // 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)
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_NONE
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string
|
||||
#include <vector> // 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 <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_NONE
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access
|
||||
#include <string> // Para string
|
||||
#include <vector> // 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
|
||||
{
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "resource.h"
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_ESCAPE
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_RenderDrawRect, SDL_RenderFillRect
|
||||
#include <stdlib.h> // for exit, size_t
|
||||
#include <algorithm> // for find_if
|
||||
#include <iostream> // for basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // 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 <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_keycode.h> // Para SDLK_ESCAPE
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <stdlib.h> // Para exit, size_t
|
||||
#include <algorithm> // Para find_if
|
||||
#include <iostream> // Para basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // 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;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // 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 <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // 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
|
||||
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
#include "room.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <stdlib.h> // for rand
|
||||
#include <exception> // for exception
|
||||
#include <fstream> // for basic_ostream, operator<<, basic_ist...
|
||||
#include <iostream> // for cout, cerr
|
||||
#include <sstream> // 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 <exception> // Para exception
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_istream
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <sstream> // 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<int> loadRoomTileFile(const std::string &file_path, bool verbose)
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // 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 <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // 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<int> tile_map_; // Indice de los tiles a dibujar en la habitación
|
||||
int conveyor_belt_direction_; // Sentido en el que arrastran las superficies automáticas de la habitación
|
||||
JA_Sound_t *item_sound_; // Sonido producido al coger un objeto
|
||||
std::vector<LineHorizontal> bottom_floors_; // Lista con las superficies inferiores de la habitación
|
||||
std::vector<LineHorizontal> top_floors_; // Lista con las superficies superiores de la habitación
|
||||
std::vector<LineVertical> left_walls_; // Lista con las superficies laterales de la parte izquierda de la habitación
|
||||
@@ -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_); }
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
: SMovingSprite(surface) {}
|
||||
|
||||
// Destructor
|
||||
virtual ~SAnimatedSprite() = default;
|
||||
virtual ~SAnimatedSprite() override = default;
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update() override;
|
||||
|
||||
@@ -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> surface, SDL_Rect pos, SDL_RendererFlip flip)
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip, SDL_FLIP_HORIZONTAL
|
||||
#include <algorithm> // for max
|
||||
#include <memory> // for shared_ptr
|
||||
#include "s_sprite.h" // for SSprite
|
||||
class Surface; // lines 9-9
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip, SDL_FLIP_HORIZONTAL
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // 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> surface);
|
||||
|
||||
// Destructor
|
||||
virtual ~SMovingSprite() = default;
|
||||
virtual ~SMovingSprite() override = default;
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
virtual void update();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
class Surface;
|
||||
class Surface; // lines 5-5
|
||||
|
||||
// Clase SSprite
|
||||
class SSprite
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
#include "scoreboard.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <iostream> // 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 <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_timer.h> // 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<ScoreboardData> 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<SAnimatedSprite>(player_texture, player_animations);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for Color
|
||||
class SAnimatedSprite; // lines 9-9
|
||||
class Surface; // lines 13-13
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32, Uint8
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string, basic_string
|
||||
#include <vector> // Para vector
|
||||
class SAnimatedSprite; // lines 10-10
|
||||
class Surface; // lines 11-11
|
||||
|
||||
struct ScoreboardData
|
||||
{
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // Para SDL_DISABLE, SDL_ENABLE
|
||||
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <algorithm> // Para max, min
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream
|
||||
#include <iostream> // Para cout
|
||||
#include <iterator> // Para istreambuf_iterator, operator!=
|
||||
#include <string> // Para basic_string, char_traits, string
|
||||
#include "asset.h" // Para Asset
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORM...
|
||||
#include <ctype.h> // Para toupper
|
||||
#include <algorithm> // Para max, min, transform
|
||||
#include <fstream> // Para basic_ostream, operator<<, endl, basic_...
|
||||
#include <iostream> // Para cerr
|
||||
#include <iterator> // Para istreambuf_iterator, operator==
|
||||
#include <string> // 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<char>(f)), std::istreambuf_iterator<char>());
|
||||
|
||||
shader::init(window_, shaders_texture_, source.c_str());
|
||||
shader::init(window_, shaders_texture_, source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||
#include "utils.h" // for Color
|
||||
#include "surface.h" // for Surface
|
||||
#include <memory> // for shared_ptr
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <SDL2/SDL_video.h> // Para SDL_Window
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "utils.h" // Para Color
|
||||
class Surface;
|
||||
|
||||
// Tipos de filtro
|
||||
enum class ScreenFilter : Uint32
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "stats.h"
|
||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_istream
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include "options.h" // for Options, OptionsStats, options
|
||||
#include <fstream> // Para basic_ostream, basic_ifstream, basic_istream
|
||||
#include <sstream> // Para basic_stringstream
|
||||
#include "options.h" // Para Options, OptionsStats, options
|
||||
|
||||
// Constructor
|
||||
Stats::Stats(const std::string &file, const std::string &buffer)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
class Stats
|
||||
{
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
#include "surface.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <stddef.h> // for size_t
|
||||
#include <algorithm> // for min, copy, fill
|
||||
#include <fstream> // for basic_ostream, basic_ifstream, basic_ios
|
||||
#include <iostream> // for cerr, cout
|
||||
#include <memory> // for shared_ptr, __shared_ptr_access, unique_ptr
|
||||
#include <stdexcept> // for runtime_error
|
||||
#include <vector> // for vector
|
||||
#include "asset.h" // for Asset
|
||||
#include "screen.h"
|
||||
#include "gif.h" // for LoadGif, LoadPalette
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <bits/std_abs.h> // Para abs
|
||||
#include <stdlib.h> // Para abs
|
||||
#include <algorithm> // Para min, max, copy_n, fill
|
||||
#include <cstdint> // Para uint32_t
|
||||
#include <cstring> // Para memcpy, size_t
|
||||
#include <fstream> // Para basic_ifstream, basic_ostream, basic_ist...
|
||||
#include <iostream> // Para cerr
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access, default...
|
||||
#include <sstream> // Para basic_istringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <vector> // 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<Uint32[]> pal(LoadPalette(buffer.data()));
|
||||
if (pal == nullptr)
|
||||
GIF::Gif gif;
|
||||
std::vector<uint32_t> pal = gif.loadPalette(buffer.data());
|
||||
if (pal.empty())
|
||||
{
|
||||
throw std::runtime_error("Error loading palette from file: " + file_path);
|
||||
throw std::runtime_error("No palette found in GIF file: " + file_path);
|
||||
}
|
||||
|
||||
// Crear la paleta y copiar los datos
|
||||
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<Uint8> buffer(size);
|
||||
if (!file.read((char *)buffer.data(), size))
|
||||
if (!file.read(reinterpret_cast<char *>(buffer.data()), size))
|
||||
{
|
||||
std::cerr << "Error reading file: " << file_path << std::endl;
|
||||
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<Uint8> 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<Uint8[]>,
|
||||
// reservamos un bloque dinámico y copiamos los datos del vector.
|
||||
size_t pixelCount = rawPixels.size();
|
||||
auto pixels = std::shared_ptr<Uint8[]>(new Uint8[pixelCount], std::default_delete<Uint8[]>());
|
||||
std::memcpy(pixels.get(), rawPixels.data(), pixelCount);
|
||||
|
||||
// Crear y devolver directamente el objeto SurfaceData
|
||||
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
|
||||
@@ -297,19 +306,20 @@ void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
||||
for (int iy = 0; iy < h; ++iy)
|
||||
{
|
||||
for (int ix = 0; ix < w; ++ix)
|
||||
{
|
||||
// Verificar que las coordenadas de destino están dentro de los límites
|
||||
if (int dest_x = dx + ix; dest_x >= 0 && dest_x < surface_data->width)
|
||||
{
|
||||
if (int dest_y = dy + iy; dest_y >= 0 && dest_y < surface_data->height)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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] = sub_palette_[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,17 +416,20 @@ 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;
|
||||
|
||||
if (int dest_x = dx + ix; dest_x >= 0 && dest_x < surface_data->width)
|
||||
{
|
||||
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[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] = sub_palette_[color];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copia una región de la SurfaceData de origen a la SurfaceData de destino reemplazando un color por otro
|
||||
@@ -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<void **>(&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]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "utils.h"
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_NONE, SDL_RendererFlip, SDL_Re...
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
|
||||
#include <array> // Para array
|
||||
#include <memory> // Para default_delete, shared_ptr, __shared_pt...
|
||||
#include <numeric> // Para iota
|
||||
#include <string> // Para string
|
||||
#include <utility> // Para move
|
||||
#include "utils.h" // Para PaletteColor
|
||||
|
||||
// Alias
|
||||
using Palette = std::array<Uint32, 256>;
|
||||
@@ -20,7 +22,7 @@ Palette readPalFile(const std::string &file_path);
|
||||
|
||||
struct SurfaceData
|
||||
{
|
||||
Uint8 *data; // Listado de indices de la paleta que conforman la imagen almacenada
|
||||
std::shared_ptr<Uint8[]> data; // Usa std::shared_ptr para gestión automática
|
||||
Uint16 width; // Ancho de la imagen
|
||||
Uint16 height; // Alto de la imagen
|
||||
|
||||
@@ -29,44 +31,21 @@ struct SurfaceData
|
||||
|
||||
// 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<Uint8[]>(new Uint8[w * h](), std::default_delete<Uint8[]>())), 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<Uint8[]> 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);
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
#include "text.h"
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_TEXTUREACCESS_TARGET
|
||||
#include <stddef.h> // Para size_t
|
||||
#include <fstream> // Para basic_ifstream, basic_istream, basic...
|
||||
#include <fstream> // Para basic_ifstream, basic_istream, basic_ostream
|
||||
#include <iostream> // Para cerr
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include "screen.h" // Para Screen
|
||||
#include "s_sprite.h" // Para SSprite
|
||||
#include "screen.h" // Para Screen
|
||||
#include "surface.h" // Para Surface
|
||||
#include "utils.h" // Para Uint8, getFileName, printWithDots
|
||||
#include "utils.h" // Para getFileName, stringToColor, printWithDots
|
||||
|
||||
// Llena una estructuta TextFile desde un fichero
|
||||
std::shared_ptr<TextFile> loadTextFile(const std::string &file_path)
|
||||
@@ -245,7 +242,7 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerni
|
||||
else
|
||||
{
|
||||
writeColored(x, y, text, textColor, kerning, lenght);
|
||||
//write(x, y, text, kerning, lenght);
|
||||
// write(x, y, text, kerning, lenght);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h> // Para Uint8
|
||||
#include <memory> // Para unique_ptr, shared_ptr
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para string
|
||||
#include "s_sprite.h" // Para SSprite
|
||||
#include "utils.h" // Para Uint8
|
||||
class Surface; // lines 9-9
|
||||
class Surface; // lines 8-8
|
||||
|
||||
constexpr int TEXT_COLOR = 1;
|
||||
constexpr int TEXT_SHADOW = 2;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
|
||||
#include "texture.h"
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_surface.h> // for SDL_CreateRGBSurfaceWithFormatFrom
|
||||
#include <iostream> // for basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // for runtime_error
|
||||
#include <string> // for char_traits, operator<<, string, opera...
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for getFileName, Color, printWithDots
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL2/SDL_surface.h> // Para SDL_CreateRGBSurfaceWithFormatFrom
|
||||
#include <iostream> // Para basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <string> // Para char_traits, operator<<, string, opera...
|
||||
#include <vector> // Para vector
|
||||
#include "utils.h" // Para getFileName, Color, printWithDots
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h" // para stbi_failure_reason, stbi_image_free
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
struct Color; // lines 11-11
|
||||
|
||||
class Texture
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
#include "title.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_1, SDL_SCANCODE_2
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <iostream> // 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 <SDL2/SDL_events.h> // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN
|
||||
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_1, SDL_SCANCODE_2
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // 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()
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
class SSprite; // lines 13-13
|
||||
class Surface; // lines 15-15
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
class SSprite; // lines 9-9
|
||||
class Surface; // lines 10-10
|
||||
|
||||
class Title
|
||||
{
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "utils.h"
|
||||
#include <stdlib.h> // for abs
|
||||
#include <algorithm> // for find, transform
|
||||
#include <cctype> // for tolower
|
||||
#include <cmath> // for round, abs
|
||||
#include <exception> // for exception
|
||||
#include <filesystem> // for path
|
||||
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
|
||||
#include <string> // for basic_string, string, char_traits, allocator
|
||||
#include <unordered_map> // for unordered_map, operator==, _Node_const_iter...
|
||||
#include <utility> // for pair
|
||||
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state, JA_PlayMusic
|
||||
#include "resource.h" // for Resource
|
||||
#include <stdlib.h> // Para abs
|
||||
#include <algorithm> // Para find, transform
|
||||
#include <cctype> // Para tolower
|
||||
#include <cmath> // Para round, abs
|
||||
#include <exception> // Para exception
|
||||
#include <filesystem> // Para path
|
||||
#include <iostream> // Para basic_ostream, cout, basic_ios, ios, endl
|
||||
#include <string> // Para basic_string, string, char_traits, allocator
|
||||
#include <unordered_map> // Para unordered_map, operator==, _Node_const_iter...
|
||||
#include <utility> // 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)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
enum class PaletteColor : Uint8
|
||||
{
|
||||
@@ -35,7 +35,6 @@ enum class PaletteColor : Uint8
|
||||
TRANSPARENT = 255,
|
||||
};
|
||||
|
||||
|
||||
// Estructura para definir un circulo
|
||||
struct Circle
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user