afegits metodes per a poder ciclar presets i altres opcions
esc en el joc + menu ja no tanca la app
This commit is contained in:
@@ -11,30 +11,30 @@
|
||||
struct JA_Sound_t {
|
||||
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
||||
Uint32 length{0};
|
||||
Uint8 *buffer{NULL};
|
||||
Uint8* buffer{NULL};
|
||||
};
|
||||
|
||||
struct JA_Channel_t {
|
||||
JA_Sound_t *sound{nullptr};
|
||||
JA_Sound_t* sound{nullptr};
|
||||
int pos{0};
|
||||
int times{0};
|
||||
SDL_AudioStream *stream{nullptr};
|
||||
SDL_AudioStream* stream{nullptr};
|
||||
JA_Channel_state state{JA_CHANNEL_FREE};
|
||||
};
|
||||
|
||||
struct JA_Music_t {
|
||||
SDL_AudioSpec spec{SDL_AUDIO_S16, 2, 48000};
|
||||
Uint32 length{0};
|
||||
Uint8 *buffer{nullptr};
|
||||
char *filename{nullptr};
|
||||
Uint8* buffer{nullptr};
|
||||
char* filename{nullptr};
|
||||
|
||||
int pos{0};
|
||||
int times{0};
|
||||
SDL_AudioStream *stream{nullptr};
|
||||
SDL_AudioStream* stream{nullptr};
|
||||
JA_Music_state state{JA_MUSIC_INVALID};
|
||||
};
|
||||
|
||||
JA_Music_t *current_music{nullptr};
|
||||
JA_Music_t* current_music{nullptr};
|
||||
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
||||
|
||||
SDL_AudioSpec JA_audioSpec{SDL_AUDIO_S16, 2, 48000};
|
||||
@@ -88,7 +88,7 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||
}
|
||||
*/
|
||||
|
||||
Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval) {
|
||||
Uint32 JA_UpdateCallback(void* userdata, SDL_TimerID timerID, Uint32 interval) {
|
||||
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING) {
|
||||
if (fading) {
|
||||
int time = SDL_GetTicks();
|
||||
@@ -152,47 +152,47 @@ void JA_Quit() {
|
||||
sdlAudioDevice = 0;
|
||||
}
|
||||
|
||||
JA_Music_t *JA_LoadMusic(Uint8 *buffer, Uint32 length, const char *filename) {
|
||||
JA_Music_t *music = new JA_Music_t();
|
||||
JA_Music_t* JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename) {
|
||||
JA_Music_t* music = new JA_Music_t();
|
||||
|
||||
int chan, samplerate;
|
||||
short *output;
|
||||
short* output;
|
||||
music->length = stb_vorbis_decode_memory(buffer, length, &chan, &samplerate, &output) * chan * 2;
|
||||
|
||||
music->spec.channels = chan;
|
||||
music->spec.freq = samplerate;
|
||||
music->spec.format = SDL_AUDIO_S16;
|
||||
music->buffer = (Uint8 *)SDL_malloc(music->length);
|
||||
music->buffer = (Uint8*)SDL_malloc(music->length);
|
||||
SDL_memcpy(music->buffer, output, music->length);
|
||||
free(output);
|
||||
music->pos = 0;
|
||||
music->state = JA_MUSIC_STOPPED;
|
||||
if (filename) {
|
||||
music->filename = (char *)malloc(strlen(filename) + 1);
|
||||
music->filename = (char*)malloc(strlen(filename) + 1);
|
||||
strcpy(music->filename, filename);
|
||||
}
|
||||
|
||||
return music;
|
||||
}
|
||||
|
||||
JA_Music_t *JA_LoadMusic(const char *filename) {
|
||||
JA_Music_t* JA_LoadMusic(const char* filename) {
|
||||
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||
FILE *f = fopen(filename, "rb");
|
||||
FILE* f = fopen(filename, "rb");
|
||||
fseek(f, 0, SEEK_END);
|
||||
long fsize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
Uint8 *buffer = (Uint8 *)malloc(fsize + 1);
|
||||
Uint8* buffer = (Uint8*)malloc(fsize + 1);
|
||||
if (fread(buffer, fsize, 1, f) != 1) return NULL;
|
||||
fclose(f);
|
||||
|
||||
JA_Music_t *music = JA_LoadMusic(buffer, fsize, filename);
|
||||
JA_Music_t* music = JA_LoadMusic(buffer, fsize, filename);
|
||||
|
||||
free(buffer);
|
||||
|
||||
return music;
|
||||
}
|
||||
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
||||
void JA_PlayMusic(JA_Music_t* music, const int loop) {
|
||||
if (!JA_musicEnabled) return;
|
||||
|
||||
JA_StopMusic();
|
||||
@@ -209,7 +209,7 @@ void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
||||
// SDL_ResumeAudioStreamDevice(current_music->stream);
|
||||
}
|
||||
|
||||
char *JA_GetMusicFilename(JA_Music_t *music) {
|
||||
char* JA_GetMusicFilename(JA_Music_t* music) {
|
||||
if (!music) music = current_music;
|
||||
return music->filename;
|
||||
}
|
||||
@@ -262,7 +262,7 @@ JA_Music_state JA_GetMusicState() {
|
||||
return current_music->state;
|
||||
}
|
||||
|
||||
void JA_DeleteMusic(JA_Music_t *music) {
|
||||
void JA_DeleteMusic(JA_Music_t* music) {
|
||||
if (current_music == music) current_music = nullptr;
|
||||
SDL_free(music->buffer);
|
||||
if (music->stream) SDL_DestroyAudioStream(music->stream);
|
||||
@@ -291,28 +291,28 @@ void JA_EnableMusic(const bool value) {
|
||||
JA_musicEnabled = value;
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8 *buffer, Uint32 length) {
|
||||
JA_Sound_t *sound = new JA_Sound_t();
|
||||
JA_Sound_t* JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||
JA_Sound_t* sound = new JA_Sound_t();
|
||||
sound->buffer = buffer;
|
||||
sound->length = length;
|
||||
return sound;
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_LoadSound(uint8_t *buffer, uint32_t size) {
|
||||
JA_Sound_t *sound = new JA_Sound_t();
|
||||
JA_Sound_t* JA_LoadSound(uint8_t* buffer, uint32_t size) {
|
||||
JA_Sound_t* sound = new JA_Sound_t();
|
||||
SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &sound->buffer, &sound->length);
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
JA_Sound_t *JA_LoadSound(const char *filename) {
|
||||
JA_Sound_t *sound = new JA_Sound_t();
|
||||
JA_Sound_t* JA_LoadSound(const char* filename) {
|
||||
JA_Sound_t* sound = new JA_Sound_t();
|
||||
SDL_LoadWAV(filename, &sound->spec, &sound->buffer, &sound->length);
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
||||
int JA_PlaySound(JA_Sound_t* sound, const int loop) {
|
||||
if (!JA_soundEnabled) return -1;
|
||||
|
||||
int channel = 0;
|
||||
@@ -332,7 +332,7 @@ int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
||||
return channel;
|
||||
}
|
||||
|
||||
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop) {
|
||||
int JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop) {
|
||||
if (!JA_soundEnabled) return -1;
|
||||
|
||||
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1;
|
||||
@@ -350,7 +350,7 @@ int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
|
||||
return channel;
|
||||
}
|
||||
|
||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
||||
void JA_DeleteSound(JA_Sound_t* sound) {
|
||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||
if (channels[i].sound == sound) JA_StopChannel(i);
|
||||
}
|
||||
|
||||
@@ -18,31 +18,31 @@ struct JA_Music_t;
|
||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels);
|
||||
void JA_Quit();
|
||||
|
||||
JA_Music_t *JA_LoadMusic(const char *filename);
|
||||
JA_Music_t *JA_LoadMusic(Uint8 *buffer, Uint32 length, const char *filename = nullptr);
|
||||
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
|
||||
char *JA_GetMusicFilename(JA_Music_t *music = nullptr);
|
||||
JA_Music_t* JA_LoadMusic(const char* filename);
|
||||
JA_Music_t* JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename = nullptr);
|
||||
void JA_PlayMusic(JA_Music_t* music, const int loop = -1);
|
||||
char* JA_GetMusicFilename(JA_Music_t* music = nullptr);
|
||||
void JA_PauseMusic();
|
||||
void JA_ResumeMusic();
|
||||
void JA_StopMusic();
|
||||
void JA_FadeOutMusic(const int milliseconds);
|
||||
JA_Music_state JA_GetMusicState();
|
||||
void JA_DeleteMusic(JA_Music_t *music);
|
||||
void JA_DeleteMusic(JA_Music_t* music);
|
||||
float JA_SetMusicVolume(float volume);
|
||||
void JA_SetMusicPosition(float value);
|
||||
float JA_GetMusicPosition();
|
||||
void JA_EnableMusic(const bool value);
|
||||
|
||||
JA_Sound_t *JA_NewSound(Uint8 *buffer, Uint32 length);
|
||||
JA_Sound_t *JA_LoadSound(Uint8 *buffer, Uint32 length);
|
||||
JA_Sound_t *JA_LoadSound(const char *filename);
|
||||
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
|
||||
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0);
|
||||
JA_Sound_t* JA_NewSound(Uint8* buffer, Uint32 length);
|
||||
JA_Sound_t* JA_LoadSound(Uint8* buffer, Uint32 length);
|
||||
JA_Sound_t* JA_LoadSound(const char* filename);
|
||||
int JA_PlaySound(JA_Sound_t* sound, const int loop = 0);
|
||||
int JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop = 0);
|
||||
void JA_PauseChannel(const int channel);
|
||||
void JA_ResumeChannel(const int channel);
|
||||
void JA_StopChannel(const int channel);
|
||||
JA_Channel_state JA_GetChannelState(const int channel);
|
||||
void JA_DeleteSound(JA_Sound_t *sound);
|
||||
void JA_DeleteSound(JA_Sound_t* sound);
|
||||
float JA_SetSoundVolume(float volume);
|
||||
void JA_EnableSound(const bool value);
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
JD8_Surface screen = NULL;
|
||||
JD8_Palette main_palette = NULL;
|
||||
Uint32 *pixel_data = NULL;
|
||||
Uint32* pixel_data = NULL;
|
||||
|
||||
void JD8_Init() {
|
||||
screen = (JD8_Surface)calloc(1, 64000);
|
||||
main_palette = (JD8_Palette)calloc(1, 768);
|
||||
pixel_data = (Uint32 *)calloc(1, 320 * 200 * 4);
|
||||
pixel_data = (Uint32*)calloc(1, 320 * 200 * 4);
|
||||
}
|
||||
|
||||
void JD8_Quit() {
|
||||
@@ -32,12 +32,12 @@ JD8_Surface JD8_NewSurface() {
|
||||
return surface;
|
||||
}
|
||||
|
||||
JD8_Surface JD8_LoadSurface(const char *file) {
|
||||
JD8_Surface JD8_LoadSurface(const char* file) {
|
||||
int filesize = 0;
|
||||
char *buffer = file_getfilebuffer(file, filesize);
|
||||
char* buffer = file_getfilebuffer(file, filesize);
|
||||
|
||||
unsigned short w, h;
|
||||
Uint8 *pixels = LoadGif((unsigned char *)buffer, &w, &h);
|
||||
Uint8* pixels = LoadGif((unsigned char*)buffer, &w, &h);
|
||||
|
||||
free(buffer);
|
||||
|
||||
@@ -53,12 +53,12 @@ JD8_Surface JD8_LoadSurface(const char *file) {
|
||||
return image;
|
||||
}
|
||||
|
||||
JD8_Palette JD8_LoadPalette(const char *file) {
|
||||
JD8_Palette JD8_LoadPalette(const char* file) {
|
||||
int filesize = 0;
|
||||
char *buffer = NULL;
|
||||
char* buffer = NULL;
|
||||
buffer = file_getfilebuffer(file, filesize);
|
||||
|
||||
JD8_Palette palette = (JD8_Palette)LoadPalette((unsigned char *)buffer);
|
||||
JD8_Palette palette = (JD8_Palette)LoadPalette((unsigned char*)buffer);
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ struct Color {
|
||||
Uint8 b;
|
||||
};
|
||||
|
||||
typedef Uint8 *JD8_Surface;
|
||||
typedef Color *JD8_Palette;
|
||||
typedef Uint8* JD8_Surface;
|
||||
typedef Color* JD8_Palette;
|
||||
|
||||
void JD8_Init();
|
||||
|
||||
@@ -18,9 +18,9 @@ void JD8_ClearScreen(Uint8 color);
|
||||
|
||||
JD8_Surface JD8_NewSurface();
|
||||
|
||||
JD8_Surface JD8_LoadSurface(const char *file);
|
||||
JD8_Surface JD8_LoadSurface(const char* file);
|
||||
|
||||
JD8_Palette JD8_LoadPalette(const char *file);
|
||||
JD8_Palette JD8_LoadPalette(const char* file);
|
||||
|
||||
void JD8_SetScreenPalette(JD8_Palette palette);
|
||||
|
||||
|
||||
@@ -34,22 +34,22 @@ struct keyvalue_t {
|
||||
std::string key, value;
|
||||
};
|
||||
|
||||
char *resource_filename = NULL;
|
||||
char *resource_folder = NULL;
|
||||
char* resource_filename = NULL;
|
||||
char* resource_folder = NULL;
|
||||
int file_source = SOURCE_FILE;
|
||||
char scratch[255];
|
||||
static std::string config_folder;
|
||||
std::vector<keyvalue_t> config;
|
||||
|
||||
void file_setresourcefilename(const char *str) {
|
||||
void file_setresourcefilename(const char* str) {
|
||||
if (resource_filename != NULL) free(resource_filename);
|
||||
resource_filename = (char *)malloc(strlen(str) + 1);
|
||||
resource_filename = (char*)malloc(strlen(str) + 1);
|
||||
strcpy(resource_filename, str);
|
||||
}
|
||||
|
||||
void file_setresourcefolder(const char *str) {
|
||||
void file_setresourcefolder(const char* str) {
|
||||
if (resource_folder != NULL) free(resource_folder);
|
||||
resource_folder = (char *)malloc(strlen(str) + 1);
|
||||
resource_folder = (char*)malloc(strlen(str) + 1);
|
||||
strcpy(resource_folder, str);
|
||||
}
|
||||
|
||||
@@ -66,16 +66,16 @@ bool file_getdictionary() {
|
||||
char header[4];
|
||||
fi.read(header, 4);
|
||||
uint32_t num_files, toc_offset;
|
||||
fi.read((char *)&num_files, 4);
|
||||
fi.read((char *)&toc_offset, 4);
|
||||
fi.read((char*)&num_files, 4);
|
||||
fi.read((char*)&toc_offset, 4);
|
||||
fi.seekg(toc_offset);
|
||||
|
||||
for (uint32_t i = 0; i < num_files; ++i) {
|
||||
uint32_t file_offset, file_size;
|
||||
fi.read((char *)&file_offset, 4);
|
||||
fi.read((char *)&file_size, 4);
|
||||
fi.read((char*)&file_offset, 4);
|
||||
fi.read((char*)&file_size, 4);
|
||||
uint8_t path_size;
|
||||
fi.read((char *)&path_size, 1);
|
||||
fi.read((char*)&path_size, 1);
|
||||
char file_name[path_size + 1];
|
||||
fi.read(file_name, path_size);
|
||||
file_name[path_size] = 0;
|
||||
@@ -86,18 +86,18 @@ bool file_getdictionary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
char *file_getfilenamewithfolder(const char *filename) {
|
||||
char* file_getfilenamewithfolder(const char* filename) {
|
||||
strcpy(scratch, resource_folder);
|
||||
strcat(scratch, filename);
|
||||
return scratch;
|
||||
}
|
||||
|
||||
FILE *file_getfilepointer(const char *resourcename, int &filesize, const bool binary) {
|
||||
FILE* file_getfilepointer(const char* resourcename, int& filesize, const bool binary) {
|
||||
if (file_source == SOURCE_FILE and toc.size() == 0) {
|
||||
if (not file_getdictionary()) file_setsource(SOURCE_FOLDER);
|
||||
}
|
||||
|
||||
FILE *f;
|
||||
FILE* f;
|
||||
|
||||
if (file_source == SOURCE_FILE) {
|
||||
bool found = false;
|
||||
@@ -129,9 +129,9 @@ FILE *file_getfilepointer(const char *resourcename, int &filesize, const bool bi
|
||||
return f;
|
||||
}
|
||||
|
||||
char *file_getfilebuffer(const char *resourcename, int &filesize, const bool zero_terminate) {
|
||||
FILE *f = file_getfilepointer(resourcename, filesize, true);
|
||||
char *buffer = (char *)malloc(zero_terminate ? filesize : filesize + 1);
|
||||
char* file_getfilebuffer(const char* resourcename, int& filesize, const bool zero_terminate) {
|
||||
FILE* f = file_getfilepointer(resourcename, filesize, true);
|
||||
char* buffer = (char*)malloc(zero_terminate ? filesize : filesize + 1);
|
||||
fread(buffer, filesize, 1, f);
|
||||
if (zero_terminate) buffer[filesize] = 0;
|
||||
fclose(f);
|
||||
@@ -140,23 +140,23 @@ char *file_getfilebuffer(const char *resourcename, int &filesize, const bool zer
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos.
|
||||
// Acepta rutas con subdirectorios (ej: "jailgames/aee") y crea toda la jerarquía.
|
||||
void file_setconfigfolder(const char *foldername) {
|
||||
void file_setconfigfolder(const char* foldername) {
|
||||
#ifdef _WIN32
|
||||
config_folder = std::string(getenv("APPDATA")) + "/" + foldername;
|
||||
#elif __APPLE__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
struct passwd* pw = getpwuid(getuid());
|
||||
const char* homedir = pw->pw_dir;
|
||||
config_folder = std::string(homedir) + "/Library/Application Support/" + foldername;
|
||||
#elif __linux__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
struct passwd* pw = getpwuid(getuid());
|
||||
const char* homedir = pw->pw_dir;
|
||||
config_folder = std::string(homedir) + "/.config/" + foldername;
|
||||
#endif
|
||||
|
||||
std::filesystem::create_directories(config_folder);
|
||||
}
|
||||
|
||||
const char *file_getconfigfolder() {
|
||||
const char* file_getconfigfolder() {
|
||||
static std::string folder;
|
||||
folder = config_folder + "/";
|
||||
return folder.c_str();
|
||||
@@ -165,12 +165,12 @@ const char *file_getconfigfolder() {
|
||||
void file_loadconfigvalues() {
|
||||
config.clear();
|
||||
std::string config_file = config_folder + "/config.txt";
|
||||
FILE *f = fopen(config_file.c_str(), "r");
|
||||
FILE* f = fopen(config_file.c_str(), "r");
|
||||
if (!f) return;
|
||||
|
||||
char line[1024];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *value = strchr(line, '=');
|
||||
char* value = strchr(line, '=');
|
||||
if (value) {
|
||||
*value = '\0';
|
||||
value++;
|
||||
@@ -183,7 +183,7 @@ void file_loadconfigvalues() {
|
||||
|
||||
void file_saveconfigvalues() {
|
||||
std::string config_file = config_folder + "/config.txt";
|
||||
FILE *f = fopen(config_file.c_str(), "w");
|
||||
FILE* f = fopen(config_file.c_str(), "w");
|
||||
if (f) {
|
||||
for (auto pair : config) {
|
||||
fprintf(f, "%s=%s\n", pair.key.c_str(), pair.value.c_str());
|
||||
@@ -192,7 +192,7 @@ void file_saveconfigvalues() {
|
||||
}
|
||||
}
|
||||
|
||||
const char *file_getconfigvalue(const char *key) {
|
||||
const char* file_getconfigvalue(const char* key) {
|
||||
if (config.empty()) file_loadconfigvalues();
|
||||
for (auto pair : config) {
|
||||
if (pair.key == std::string(key)) {
|
||||
@@ -203,9 +203,9 @@ const char *file_getconfigvalue(const char *key) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void file_setconfigvalue(const char *key, const char *value) {
|
||||
void file_setconfigvalue(const char* key, const char* value) {
|
||||
if (config.empty()) file_loadconfigvalues();
|
||||
for (auto &pair : config) {
|
||||
for (auto& pair : config) {
|
||||
if (pair.key == std::string(key)) {
|
||||
pair.value = value;
|
||||
file_saveconfigvalues();
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
#define SOURCE_FILE 0
|
||||
#define SOURCE_FOLDER 1
|
||||
|
||||
void file_setconfigfolder(const char *foldername);
|
||||
const char *file_getconfigfolder();
|
||||
void file_setconfigfolder(const char* foldername);
|
||||
const char* file_getconfigfolder();
|
||||
|
||||
void file_setresourcefilename(const char *str);
|
||||
void file_setresourcefolder(const char *str);
|
||||
void file_setresourcefilename(const char* str);
|
||||
void file_setresourcefolder(const char* str);
|
||||
void file_setsource(const int src);
|
||||
|
||||
FILE *file_getfilepointer(const char *resourcename, int &filesize, const bool binary = false);
|
||||
char *file_getfilebuffer(const char *resourcename, int &filesize, const bool zero_terminate = false);
|
||||
FILE* file_getfilepointer(const char* resourcename, int& filesize, const bool binary = false);
|
||||
char* file_getfilebuffer(const char* resourcename, int& filesize, const bool zero_terminate = false);
|
||||
|
||||
const char *file_getconfigvalue(const char *key);
|
||||
void file_setconfigvalue(const char *key, const char *value);
|
||||
const char* file_getconfigvalue(const char* key);
|
||||
void file_setconfigvalue(const char* key, const char* value);
|
||||
|
||||
@@ -64,63 +64,46 @@ namespace Menu {
|
||||
items_.clear();
|
||||
|
||||
// ZOOM
|
||||
items_.push_back({"ZOOM", ItemKind::IntRange,
|
||||
[] {
|
||||
items_.push_back({"ZOOM", ItemKind::IntRange, [] {
|
||||
char buf[16];
|
||||
std::snprintf(buf, sizeof(buf), "%dX", Screen::get()->getZoom());
|
||||
return std::string(buf);
|
||||
},
|
||||
[](int dir) {
|
||||
return std::string(buf); }, [](int dir) {
|
||||
if (dir < 0) Screen::get()->decZoom();
|
||||
else if (dir > 0) Screen::get()->incZoom();
|
||||
}});
|
||||
else if (dir > 0) Screen::get()->incZoom(); }});
|
||||
|
||||
// PANTALLA (fullscreen)
|
||||
items_.push_back({"PANTALLA", ItemKind::Toggle,
|
||||
[] { return std::string(Screen::get()->isFullscreen() ? "COMPLETA" : "FINESTRA"); },
|
||||
[](int) { Screen::get()->toggleFullscreen(); }});
|
||||
items_.push_back({"PANTALLA", ItemKind::Toggle, [] { return std::string(Screen::get()->isFullscreen() ? "COMPLETA" : "FINESTRA"); }, [](int) { Screen::get()->toggleFullscreen(); }});
|
||||
|
||||
// SHADER
|
||||
items_.push_back({"SHADER", ItemKind::Toggle,
|
||||
[] { return onOff(Options::video.shader_enabled); },
|
||||
[](int) { Screen::get()->toggleShaders(); }});
|
||||
items_.push_back({"SHADER", ItemKind::Toggle, [] { return onOff(Options::video.shader_enabled); }, [](int) { Screen::get()->toggleShaders(); }});
|
||||
|
||||
// ASPECTE 4:3
|
||||
items_.push_back({"ASPECTE 4:3", ItemKind::Toggle,
|
||||
[] { return yesNo(Options::video.aspect_ratio_4_3); },
|
||||
[](int) { Screen::get()->toggleAspectRatio(); }});
|
||||
items_.push_back({"ASPECTE 4:3", ItemKind::Toggle, [] { return yesNo(Options::video.aspect_ratio_4_3); }, [](int) { Screen::get()->toggleAspectRatio(); }});
|
||||
|
||||
// SUPERSAMPLING
|
||||
items_.push_back({"SUPERSAMPLING", ItemKind::Toggle,
|
||||
[] { return onOff(Options::video.supersampling); },
|
||||
[](int) { Screen::get()->toggleSupersampling(); }});
|
||||
items_.push_back({"SUPERSAMPLING", ItemKind::Toggle, [] { return onOff(Options::video.supersampling); }, [](int) { Screen::get()->toggleSupersampling(); }});
|
||||
|
||||
// TIPUS SHADER
|
||||
items_.push_back({"TIPUS SHADER", ItemKind::Cycle,
|
||||
[] { return std::string(Screen::get()->getActiveShaderName()); },
|
||||
[](int) { Screen::get()->nextShaderType(); }});
|
||||
items_.push_back({"TIPUS SHADER", ItemKind::Cycle, [] { return std::string(Screen::get()->getActiveShaderName()); }, [](int dir) {
|
||||
if (dir < 0) Screen::get()->prevShaderType();
|
||||
else Screen::get()->nextShaderType(); }});
|
||||
|
||||
// PRESET
|
||||
items_.push_back({"PRESET", ItemKind::Cycle,
|
||||
[] { return std::string(Screen::get()->getCurrentPresetName()); },
|
||||
[](int) { Screen::get()->nextPreset(); }});
|
||||
items_.push_back({"PRESET", ItemKind::Cycle, [] { return std::string(Screen::get()->getCurrentPresetName()); }, [](int dir) {
|
||||
if (dir < 0) Screen::get()->prevPreset();
|
||||
else Screen::get()->nextPreset(); }});
|
||||
|
||||
// FILTRE 4:3
|
||||
items_.push_back({"FILTRE 4:3", ItemKind::Toggle,
|
||||
[] { return std::string(Options::video.stretch_filter_linear ? "LINEAR" : "NEAREST"); },
|
||||
[](int) { Screen::get()->toggleStretchFilter(); }});
|
||||
items_.push_back({"FILTRE 4:3", ItemKind::Toggle, [] { return std::string(Options::video.stretch_filter_linear ? "LINEAR" : "NEAREST"); }, [](int) { Screen::get()->toggleStretchFilter(); }});
|
||||
|
||||
// RENDER INFO
|
||||
items_.push_back({"RENDER INFO", ItemKind::Cycle,
|
||||
[] {
|
||||
items_.push_back({"RENDER INFO", ItemKind::Cycle, [] {
|
||||
switch (Options::render_info.position) {
|
||||
case Options::RenderInfoPosition::OFF: return std::string("OFF");
|
||||
case Options::RenderInfoPosition::TOP: return std::string("TOP");
|
||||
case Options::RenderInfoPosition::BOTTOM: return std::string("BOTTOM");
|
||||
}
|
||||
return std::string("OFF");
|
||||
},
|
||||
[](int) { Overlay::toggleRenderInfo(); }});
|
||||
return std::string("OFF"); }, [](int dir) { Overlay::cycleRenderInfo(dir); }});
|
||||
}
|
||||
|
||||
// --- Dibuix ---
|
||||
|
||||
@@ -170,19 +170,13 @@ namespace Overlay {
|
||||
notifications_.push_back(notif);
|
||||
}
|
||||
|
||||
void toggleRenderInfo() {
|
||||
// Cicla: OFF → TOP → BOTTOM → OFF
|
||||
switch (Options::render_info.position) {
|
||||
case Options::RenderInfoPosition::OFF:
|
||||
Options::render_info.position = Options::RenderInfoPosition::TOP;
|
||||
break;
|
||||
case Options::RenderInfoPosition::TOP:
|
||||
Options::render_info.position = Options::RenderInfoPosition::BOTTOM;
|
||||
break;
|
||||
case Options::RenderInfoPosition::BOTTOM:
|
||||
Options::render_info.position = Options::RenderInfoPosition::OFF;
|
||||
break;
|
||||
}
|
||||
void toggleRenderInfo() { cycleRenderInfo(+1); }
|
||||
|
||||
void cycleRenderInfo(int dir) {
|
||||
// Seqüència: OFF → TOP → BOTTOM → OFF
|
||||
int pos = static_cast<int>(Options::render_info.position);
|
||||
pos = (pos + (dir >= 0 ? 1 : -1) + 3) % 3;
|
||||
Options::render_info.position = static_cast<Options::RenderInfoPosition>(pos);
|
||||
}
|
||||
|
||||
void setRenderInfoText(const char* text) {
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Overlay {
|
||||
|
||||
// Activa/desactiva la info de renderitzat (FPS, driver, shader, preset)
|
||||
void toggleRenderInfo();
|
||||
void cycleRenderInfo(int dir); // dir=+1 avant, -1 endarrere
|
||||
void setRenderInfoText(const char* text);
|
||||
|
||||
// Gestió d'eixida amb doble ESC
|
||||
|
||||
@@ -240,6 +240,29 @@ void Screen::nextPreset() {
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::prevShaderType() {
|
||||
// Només dues opcions — prev == next
|
||||
nextShaderType();
|
||||
}
|
||||
|
||||
void Screen::prevPreset() {
|
||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) return;
|
||||
|
||||
if (shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX) {
|
||||
if (Options::postfx_presets.empty()) return;
|
||||
int n = static_cast<int>(Options::postfx_presets.size());
|
||||
Options::current_postfx_preset = (Options::current_postfx_preset - 1 + n) % n;
|
||||
Options::video.current_postfx_preset = Options::postfx_presets[Options::current_postfx_preset].name;
|
||||
applyCurrentPostFXPreset();
|
||||
} else {
|
||||
if (Options::crtpi_presets.empty()) return;
|
||||
int n = static_cast<int>(Options::crtpi_presets.size());
|
||||
Options::current_crtpi_preset = (Options::current_crtpi_preset - 1 + n) % n;
|
||||
Options::video.current_crtpi_preset = Options::crtpi_presets[Options::current_crtpi_preset].name;
|
||||
applyCurrentCrtPiPreset();
|
||||
}
|
||||
}
|
||||
|
||||
auto Screen::getCurrentPresetName() const -> const char* {
|
||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) return "---";
|
||||
if (shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX) {
|
||||
|
||||
@@ -29,7 +29,9 @@ class Screen {
|
||||
void toggleIntegerScale();
|
||||
void toggleStretchFilter();
|
||||
void nextShaderType(); // Cicla PostFX ↔ CrtPi (F7)
|
||||
void prevShaderType(); // Cicla al revés
|
||||
void nextPreset(); // Cicla presets del shader actiu (F8)
|
||||
void prevPreset(); // Cicla presets al revés
|
||||
[[nodiscard]] auto getCurrentPresetName() const -> const char*;
|
||||
void setActiveShader(Rendering::ShaderType type);
|
||||
void applyCurrentPostFXPreset();
|
||||
|
||||
@@ -120,6 +120,8 @@ void Director::handleEvents() {
|
||||
if (event.key.scancode == SDL_SCANCODE_ESCAPE) {
|
||||
Menu::close();
|
||||
JI_SetInputBlocked(false);
|
||||
// Empassa l'ESC fins al release perquè el joc no la veja per polling
|
||||
esc_swallow_until_release_ = true;
|
||||
} else {
|
||||
Menu::handleKey(event.key.scancode);
|
||||
}
|
||||
@@ -128,6 +130,11 @@ void Director::handleEvents() {
|
||||
if (Menu::isOpen() && event.type == SDL_EVENT_KEY_UP) {
|
||||
continue; // no deixem passar KEY_UP al joc tampoc
|
||||
}
|
||||
// Allibera el bloqueig d'ESC quan l'usuari la deixa anar
|
||||
if (event.type == SDL_EVENT_KEY_UP && event.key.scancode == SDL_SCANCODE_ESCAPE && esc_swallow_until_release_) {
|
||||
esc_swallow_until_release_ = false;
|
||||
continue;
|
||||
}
|
||||
// ESC: interceptem KEY_DOWN per bloquejar-la ABANS que el joc la veja per polling
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.scancode == SDL_SCANCODE_ESCAPE && !event.key.repeat) {
|
||||
esc_blocked_ = true; // Bloqueja ESC per polling immediatament
|
||||
|
||||
@@ -32,7 +32,7 @@ class Director {
|
||||
auto consumeKeyPressed() -> bool;
|
||||
|
||||
// Indica si ESC està bloquejada (el joc no l'ha de veure)
|
||||
auto isEscBlocked() const -> bool { return esc_blocked_; }
|
||||
auto isEscBlocked() const -> bool { return esc_blocked_ || esc_swallow_until_release_; }
|
||||
|
||||
private:
|
||||
Director() = default;
|
||||
@@ -56,4 +56,7 @@ class Director {
|
||||
std::atomic<bool> game_thread_done_{false};
|
||||
std::atomic<bool> key_pressed_{false};
|
||||
std::atomic<bool> esc_blocked_{false};
|
||||
// Quan el menú tanca amb ESC, empassem-nos l'ESC fins que l'usuari la deixe anar,
|
||||
// per no fer eixir el joc al proper poll de JI_KeyPressed.
|
||||
std::atomic<bool> esc_swallow_until_release_{false};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user