Compare commits
3 Commits
6d09afdf09
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d563a7907 | |||
| 942ce2a6ff | |||
| e92498fd16 |
@@ -1,6 +1,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
#include "jdraw.h"
|
||||||
|
|
||||||
namespace config
|
namespace config
|
||||||
{
|
{
|
||||||
@@ -88,6 +89,7 @@ namespace config
|
|||||||
{
|
{
|
||||||
kiosk_mode = value;
|
kiosk_mode = value;
|
||||||
file::setConfigValue("kiosk", kiosk_mode ? "yes" : "no");
|
file::setConfigValue("kiosk", kiosk_mode ? "yes" : "no");
|
||||||
|
draw::reinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool getKioskMode()
|
const bool getKioskMode()
|
||||||
|
|||||||
@@ -14,12 +14,18 @@ namespace audio
|
|||||||
JA_Sound_t *chunk;
|
JA_Sound_t *chunk;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct music_cache_t
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
JA_Music_t *chunk;
|
||||||
|
};
|
||||||
|
|
||||||
//char *music_buffer = nullptr;
|
//char *music_buffer = nullptr;
|
||||||
//JA_Music_t *music = nullptr;
|
//JA_Music_t *music = nullptr;
|
||||||
std::vector<sound_cache_t> sounds;
|
std::vector<sound_cache_t> sounds;
|
||||||
std::vector<sound_cache_t> songs;
|
std::vector<music_cache_t> songs;
|
||||||
std::string musica_actual = "";
|
std::string musica_actual = "";
|
||||||
int musica = -1;
|
//int musica = -1;
|
||||||
|
|
||||||
// Inicialitza el sistema de só
|
// Inicialitza el sistema de só
|
||||||
void init()
|
void init()
|
||||||
@@ -33,7 +39,7 @@ namespace audio
|
|||||||
void quit()
|
void quit()
|
||||||
{
|
{
|
||||||
//if (music) JA_DeleteMusic(music);
|
//if (music) JA_DeleteMusic(music);
|
||||||
for (auto sound : songs) JA_DeleteSound(sound.chunk);
|
for (auto music : songs) JA_DeleteMusic(music.chunk);
|
||||||
songs.clear();
|
songs.clear();
|
||||||
for (auto sound : sounds) JA_DeleteSound(sound.chunk); // Mix_FreeChunk(sound.chunk);
|
for (auto sound : sounds) JA_DeleteSound(sound.chunk); // Mix_FreeChunk(sound.chunk);
|
||||||
sounds.clear();
|
sounds.clear();
|
||||||
@@ -44,12 +50,12 @@ namespace audio
|
|||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
char *buffer = file::getFileBuffer(filename, size);
|
char *buffer = file::getFileBuffer(filename, size);
|
||||||
auto chunk = JA_LoadSound((uint8_t *)buffer, size);
|
auto chunk = JA_LoadMusic((uint8_t *)buffer, size);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
//auto chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
|
//auto chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
|
||||||
//if (!chunk) printf("ERROR: %s\n", SDL_GetError());
|
//if (!chunk) printf("ERROR: %s\n", SDL_GetError());
|
||||||
sound_cache_t sound = { filename, chunk };
|
music_cache_t sound = { filename, chunk };
|
||||||
songs.push_back(sound);
|
songs.push_back(sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +72,15 @@ namespace audio
|
|||||||
//free(buffer);
|
//free(buffer);
|
||||||
//JA_PlayMusic(music, loop);
|
//JA_PlayMusic(music, loop);
|
||||||
|
|
||||||
|
//int song_index = 0;
|
||||||
for (auto song : songs)
|
for (auto song : songs)
|
||||||
{
|
{
|
||||||
if (song.name == filename) {
|
if (song.name == filename) {
|
||||||
musica = JA_PlaySound(song.chunk, loop);
|
JA_PlayMusic(song.chunk, loop);
|
||||||
|
//musica = song_index;
|
||||||
musica_actual = filename;
|
musica_actual = filename;
|
||||||
return;
|
return;
|
||||||
|
//song_index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,24 +88,24 @@ namespace audio
|
|||||||
// Pausa la música que està sonant ara
|
// Pausa la música que està sonant ara
|
||||||
void pauseMusic()
|
void pauseMusic()
|
||||||
{
|
{
|
||||||
//JA_PauseMusic(); //Mix_PauseMusic();
|
JA_PauseMusic(); //Mix_PauseMusic();
|
||||||
if (musica != -1) JA_PauseChannel(musica);
|
//if (musica != -1) JA_PauseChannel(musica);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continua la música pausada
|
// Continua la música pausada
|
||||||
void resumeMusic()
|
void resumeMusic()
|
||||||
{
|
{
|
||||||
if (!config::isMusicEnabled()) return;
|
if (!config::isMusicEnabled()) return;
|
||||||
//JA_ResumeMusic(); //Mix_ResumeMusic();
|
JA_ResumeMusic(); //Mix_ResumeMusic();
|
||||||
if (musica != -1) JA_ResumeChannel(musica);
|
//if (musica != -1) JA_ResumeChannel(musica);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Para la música que estava sonant
|
// Para la música que estava sonant
|
||||||
void stopMusic()
|
void stopMusic()
|
||||||
{
|
{
|
||||||
//JA_StopMusic(); //Mix_HaltMusic();
|
JA_StopMusic(); //Mix_HaltMusic();
|
||||||
if (musica != -1) JA_StopChannel(musica);
|
//if (musica != -1) JA_StopChannel(musica);
|
||||||
musica = -1;
|
//musica = -1;
|
||||||
musica_actual = "";
|
musica_actual = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "gif.h"
|
#include "gif.h"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
|
#include "config.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace draw
|
namespace draw
|
||||||
@@ -24,6 +25,7 @@ namespace draw
|
|||||||
static int screen_height = 240;
|
static int screen_height = 240;
|
||||||
std::string screen_title = "";
|
std::string screen_title = "";
|
||||||
static int screen_mode = SCREEN_MODE_NORMAL;
|
static int screen_mode = SCREEN_MODE_NORMAL;
|
||||||
|
static bool any_fullscreen = false;
|
||||||
|
|
||||||
surface *screen = nullptr; // La superficie screen, que representa la pantalla. Se crea i destrueix internament
|
surface *screen = nullptr; // La superficie screen, que representa la pantalla. Se crea i destrueix internament
|
||||||
surface *destination = nullptr; // Punter a la actual superficie de destí
|
surface *destination = nullptr; // Punter a la actual superficie de destí
|
||||||
@@ -43,6 +45,8 @@ namespace draw
|
|||||||
surface* managed[50];
|
surface* managed[50];
|
||||||
int num_managed = 0;
|
int num_managed = 0;
|
||||||
|
|
||||||
|
bool console = false;
|
||||||
|
|
||||||
namespace stencil
|
namespace stencil
|
||||||
{
|
{
|
||||||
static bool enabled = false;
|
static bool enabled = false;
|
||||||
@@ -87,20 +91,44 @@ namespace draw
|
|||||||
screen_height = height;
|
screen_height = height;
|
||||||
|
|
||||||
// [TODO] Incloure gestió de pantalla completa
|
// [TODO] Incloure gestió de pantalla completa
|
||||||
|
const char *driver = SDL_GetCurrentVideoDriver();
|
||||||
|
if (!driver) {
|
||||||
|
// No video driver at all → likely a text console with no graphics
|
||||||
|
printf("No video driver, probably running in a text console.\n");
|
||||||
|
console = true;
|
||||||
|
} else {
|
||||||
|
printf("Video driver: %s\n", driver);
|
||||||
|
|
||||||
|
if (strcmp(driver, "x11") == 0) {
|
||||||
|
printf("Running under X11.\n");
|
||||||
|
} else if (strcmp(driver, "wayland") == 0) {
|
||||||
|
printf("Running under Wayland.\n");
|
||||||
|
} else if (strcmp(driver, "kmsdrm") == 0) {
|
||||||
|
printf("Running on a text console using KMS/DRM.\n");
|
||||||
|
console = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (console) {
|
||||||
|
SDL_DisplayID display = SDL_GetPrimaryDisplay();
|
||||||
|
const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(display);
|
||||||
|
if (mode) {
|
||||||
|
printf("Native resolution: %dx%d @ %d Hz\n", mode->w, mode->h, mode->refresh_rate);
|
||||||
|
}
|
||||||
|
screen_fullscreen = true;
|
||||||
|
sdl_window = SDL_CreateWindow(screen_title.c_str(), mode->w, mode->h, SDL_WINDOW_FULLSCREEN);
|
||||||
|
} else {
|
||||||
|
sdl_window = SDL_CreateWindow(screen_title.c_str(), screen_width * screen_zoom, screen_height * screen_zoom, screen_fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Inicialització de les estructures de SDL
|
// Inicialització de les estructures de SDL
|
||||||
sdl_window = SDL_CreateWindow(screen_title.c_str(), screen_width * screen_zoom, screen_height * screen_zoom, screen_fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
|
|
||||||
sdl_renderer = SDL_CreateRenderer(sdl_window, nullptr);
|
sdl_renderer = SDL_CreateRenderer(sdl_window, nullptr);
|
||||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||||
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
||||||
|
|
||||||
const int num_render_drivers = SDL_GetNumRenderDrivers();
|
const int num_render_drivers = SDL_GetNumRenderDrivers();
|
||||||
printf("Available renderers:\n");
|
printf("Available renderers:\n");
|
||||||
for (int i=0; i<num_render_drivers; ++i)
|
for (int i=0; i<num_render_drivers; ++i) printf(" - %i: %s\n", i, SDL_GetRenderDriver(i));
|
||||||
{
|
|
||||||
printf(" - %i: %s\n", i, SDL_GetRenderDriver(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\nRenderer: %s\n", SDL_GetRendererName(sdl_renderer));
|
printf("\nRenderer: %s\n", SDL_GetRendererName(sdl_renderer));
|
||||||
|
|
||||||
SDL_HideCursor();
|
SDL_HideCursor();
|
||||||
@@ -181,16 +209,25 @@ namespace draw
|
|||||||
SDL_DestroyTexture(sdl_texture);
|
SDL_DestroyTexture(sdl_texture);
|
||||||
SDL_DestroyRenderer(sdl_renderer);
|
SDL_DestroyRenderer(sdl_renderer);
|
||||||
SDL_DestroyWindow(sdl_window);
|
SDL_DestroyWindow(sdl_window);
|
||||||
|
any_fullscreen = screen_fullscreen || config::getKioskMode() || console;
|
||||||
|
|
||||||
const int zoom = screen_fullscreen ? 1 : screen_zoom;
|
const int zoom = any_fullscreen ? 1 : screen_zoom;
|
||||||
sdl_window = SDL_CreateWindow(screen_title.c_str(), screen_width * zoom, screen_height * zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN:0);
|
|
||||||
|
if (any_fullscreen) {
|
||||||
|
SDL_DisplayID display = SDL_GetPrimaryDisplay();
|
||||||
|
const SDL_DisplayMode *mode = SDL_GetDesktopDisplayMode(display);
|
||||||
|
sdl_window = SDL_CreateWindow(screen_title.c_str(), mode->w, mode->h, SDL_WINDOW_FULLSCREEN);
|
||||||
|
} else {
|
||||||
|
sdl_window = SDL_CreateWindow(screen_title.c_str(), screen_width * zoom, screen_height * zoom, 0);
|
||||||
|
}
|
||||||
|
|
||||||
sdl_renderer = SDL_CreateRenderer(sdl_window, nullptr);
|
sdl_renderer = SDL_CreateRenderer(sdl_window, nullptr);
|
||||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||||
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
||||||
|
|
||||||
SDL_HideCursor();
|
SDL_HideCursor();
|
||||||
|
|
||||||
if (screen_fullscreen)
|
if (any_fullscreen)
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_GetWindowSize(sdl_window, &w, &h);
|
SDL_GetWindowSize(sdl_window, &w, &h);
|
||||||
@@ -213,6 +250,7 @@ namespace draw
|
|||||||
|
|
||||||
void setZoom(const int value)
|
void setZoom(const int value)
|
||||||
{
|
{
|
||||||
|
if (screen_fullscreen || config::getKioskMode() || console) return;
|
||||||
if (value < 1) return;
|
if (value < 1) return;
|
||||||
const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(sdl_window));
|
const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(sdl_window));
|
||||||
|
|
||||||
@@ -225,22 +263,26 @@ namespace draw
|
|||||||
|
|
||||||
void incZoom()
|
void incZoom()
|
||||||
{
|
{
|
||||||
|
if (screen_fullscreen || config::getKioskMode() || console) return;
|
||||||
setZoom(screen_zoom+1);
|
setZoom(screen_zoom+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void decZoom()
|
void decZoom()
|
||||||
{
|
{
|
||||||
|
if (screen_fullscreen || config::getKioskMode() || console) return;
|
||||||
setZoom(screen_zoom-1);
|
setZoom(screen_zoom-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleFullscreen()
|
void toggleFullscreen()
|
||||||
{
|
{
|
||||||
|
if (config::getKioskMode() || console) return;
|
||||||
screen_fullscreen = !screen_fullscreen;
|
screen_fullscreen = !screen_fullscreen;
|
||||||
reinit();
|
reinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFullscreen(const bool value)
|
void setFullscreen(const bool value)
|
||||||
{
|
{
|
||||||
|
if (config::getKioskMode() || console) return;
|
||||||
if (screen_fullscreen == value) return;
|
if (screen_fullscreen == value) return;
|
||||||
screen_fullscreen = value;
|
screen_fullscreen = value;
|
||||||
reinit();
|
reinit();
|
||||||
@@ -723,7 +765,7 @@ bool SaveIndexedAsBMP(const char *filename,
|
|||||||
// Desbloquejem la textura
|
// Desbloquejem la textura
|
||||||
SDL_UnlockTexture(sdl_texture);
|
SDL_UnlockTexture(sdl_texture);
|
||||||
|
|
||||||
if (screen_fullscreen)
|
if (any_fullscreen)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 255);
|
||||||
SDL_RenderClear(sdl_renderer);
|
SDL_RenderClear(sdl_renderer);
|
||||||
@@ -734,9 +776,10 @@ bool SaveIndexedAsBMP(const char *filename,
|
|||||||
|
|
||||||
if (screen_mode & SCREEN_MODE_SCANLINES)
|
if (screen_mode & SCREEN_MODE_SCANLINES)
|
||||||
{
|
{
|
||||||
if (screen_zoom>=3 || screen_fullscreen)
|
|
||||||
|
if (screen_zoom>=3 || any_fullscreen)
|
||||||
{
|
{
|
||||||
int zoom = screen_fullscreen ? fullscreen_scale : screen_zoom;
|
int zoom = any_fullscreen ? fullscreen_scale : screen_zoom;
|
||||||
SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND);
|
||||||
for (int y=0; y<screen_height; ++y)
|
for (int y=0; y<screen_height; ++y)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ namespace draw
|
|||||||
/// @param height es el alt de la finestra "virtual"
|
/// @param height es el alt de la finestra "virtual"
|
||||||
/// @param zoom es com de grans son els pixels.
|
/// @param zoom es com de grans son els pixels.
|
||||||
void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom, const bool fullscreen=false);
|
void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom, const bool fullscreen=false);
|
||||||
|
void reinit();
|
||||||
|
|
||||||
/// @brief Finalització del sistema (tancar coses de SDL, superficies fixes, etc...)
|
/// @brief Finalització del sistema (tancar coses de SDL, superficies fixes, etc...)
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
|
#include "versio.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
namespace menu
|
namespace menu
|
||||||
@@ -122,7 +124,7 @@ namespace modules
|
|||||||
//draw::print2(input::getPadBtnPressed(), 3, 0, 24, RED, FONT_ZOOM_NONE);
|
//draw::print2(input::getPadBtnPressed(), 3, 0, 24, RED, FONT_ZOOM_NONE);
|
||||||
|
|
||||||
draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE);
|
draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE);
|
||||||
draw::print("v1.5b", 299, 233, WHITE, PAPER);
|
draw::print(VERSIO, 299, 233, WHITE, PAPER);
|
||||||
|
|
||||||
draw::render();
|
draw::render();
|
||||||
return OPTION_NONE;
|
return OPTION_NONE;
|
||||||
|
|||||||
@@ -116,14 +116,14 @@ void game::init()
|
|||||||
draw::init("The Pool", 320, 240, zoom, fullscreen);
|
draw::init("The Pool", 320, 240, zoom, fullscreen);
|
||||||
console::init();
|
console::init();
|
||||||
|
|
||||||
printf("Carregant mus_menu.ogg...");
|
printf("Carregant mus_menu.ogg...\n");
|
||||||
audio::loadMusic("mus_menu.ogg");
|
audio::loadMusic("mus_menu.ogg");
|
||||||
printf("Carregant mus_ingame.ogg...");
|
printf("Carregant mus_ingame.ogg...\n");
|
||||||
audio::loadMusic("mus_ingame.ogg");
|
audio::loadMusic("mus_ingame.ogg");
|
||||||
printf("Carregant mus_gameover.ogg...");
|
printf("Carregant mus_gameover.ogg...\n");
|
||||||
audio::loadMusic("mus_gameover.ogg");
|
audio::loadMusic("mus_gameover.ogg");
|
||||||
|
|
||||||
printf("Carregant arxius de só...");
|
printf("Carregant arxius de só...\n");
|
||||||
audio::loadSound("snd_logo.wav");
|
audio::loadSound("snd_logo.wav");
|
||||||
audio::loadSound("snd_walk.wav");
|
audio::loadSound("snd_walk.wav");
|
||||||
audio::loadSound("snd_push.wav");
|
audio::loadSound("snd_push.wav");
|
||||||
|
|||||||
3
source/versio.h
Normal file
3
source/versio.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define VERSIO "v1.7"
|
||||||
Reference in New Issue
Block a user