Compare commits
5 Commits
5529777ccb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d563a7907 | |||
| 942ce2a6ff | |||
| e92498fd16 | |||
| 6d09afdf09 | |||
| 00c4a08915 |
@@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
#include "jfile.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include "jdraw.h"
|
||||
|
||||
namespace config
|
||||
{
|
||||
@@ -88,6 +89,7 @@ namespace config
|
||||
{
|
||||
kiosk_mode = value;
|
||||
file::setConfigValue("kiosk", kiosk_mode ? "yes" : "no");
|
||||
draw::reinit();
|
||||
}
|
||||
|
||||
const bool getKioskMode()
|
||||
|
||||
@@ -14,10 +14,18 @@ namespace audio
|
||||
JA_Sound_t *chunk;
|
||||
};
|
||||
|
||||
struct music_cache_t
|
||||
{
|
||||
std::string name;
|
||||
JA_Music_t *chunk;
|
||||
};
|
||||
|
||||
//char *music_buffer = nullptr;
|
||||
JA_Music_t *music = nullptr;
|
||||
//JA_Music_t *music = nullptr;
|
||||
std::vector<sound_cache_t> sounds;
|
||||
std::vector<music_cache_t> songs;
|
||||
std::string musica_actual = "";
|
||||
//int musica = -1;
|
||||
|
||||
// Inicialitza el sistema de só
|
||||
void init()
|
||||
@@ -30,36 +38,58 @@ namespace audio
|
||||
// Tanca el sistema de só (no shit, sherlock)
|
||||
void quit()
|
||||
{
|
||||
if (music) JA_DeleteMusic(music);
|
||||
//if (music) JA_DeleteMusic(music);
|
||||
for (auto music : songs) JA_DeleteMusic(music.chunk);
|
||||
songs.clear();
|
||||
for (auto sound : sounds) JA_DeleteSound(sound.chunk); // Mix_FreeChunk(sound.chunk);
|
||||
sounds.clear();
|
||||
JA_Quit(); // Mix_CloseAudio();
|
||||
}
|
||||
|
||||
void loadMusic(const std::string filename)
|
||||
{
|
||||
int size;
|
||||
char *buffer = file::getFileBuffer(filename, size);
|
||||
auto chunk = JA_LoadMusic((uint8_t *)buffer, size);
|
||||
free(buffer);
|
||||
|
||||
//auto chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
|
||||
//if (!chunk) printf("ERROR: %s\n", SDL_GetError());
|
||||
music_cache_t sound = { filename, chunk };
|
||||
songs.push_back(sound);
|
||||
}
|
||||
|
||||
// Comença a reproduïr la música en questió
|
||||
void playMusic(const std::string filename, const int loop)
|
||||
{
|
||||
if (!config::isMusicEnabled()) return;
|
||||
// Si hi havia musica carregada, alliberem memòria
|
||||
//if (music_buffer) free(music_buffer);
|
||||
if (music) JA_DeleteMusic(music); //Mix_FreeMusic(music);
|
||||
//if (music) JA_DeleteMusic(music); //Mix_FreeMusic(music);
|
||||
stopMusic();
|
||||
//int size;
|
||||
//char *buffer = file::getFileBuffer(filename, size);
|
||||
//music = JA_LoadMusic((uint8_t*)buffer, size);
|
||||
//free(buffer);
|
||||
//JA_PlayMusic(music, loop);
|
||||
|
||||
int size;
|
||||
char *buffer = file::getFileBuffer(filename, size);
|
||||
music = JA_LoadMusic((uint8_t*)buffer, size);
|
||||
free(buffer);
|
||||
//auto rwops = SDL_RWFromMem(music_buffer, size);
|
||||
//auto mus = Mix_LoadMUS_RW(rwops, 1);
|
||||
//free(music_buffer); // [RZC 03/10/2024] Si allibere el buffer, no funciona la música. Porca miseria! Per aixó l'allibere abans de carregar si ja estava usat.
|
||||
//Mix_PlayMusic((Mix_Music *)mus, loop);
|
||||
JA_PlayMusic(music, loop);
|
||||
musica_actual = filename;
|
||||
//int song_index = 0;
|
||||
for (auto song : songs)
|
||||
{
|
||||
if (song.name == filename) {
|
||||
JA_PlayMusic(song.chunk, loop);
|
||||
//musica = song_index;
|
||||
musica_actual = filename;
|
||||
return;
|
||||
//song_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pausa la música que està sonant ara
|
||||
void pauseMusic()
|
||||
{
|
||||
JA_PauseMusic(); //Mix_PauseMusic();
|
||||
//if (musica != -1) JA_PauseChannel(musica);
|
||||
}
|
||||
|
||||
// Continua la música pausada
|
||||
@@ -67,12 +97,15 @@ namespace audio
|
||||
{
|
||||
if (!config::isMusicEnabled()) return;
|
||||
JA_ResumeMusic(); //Mix_ResumeMusic();
|
||||
//if (musica != -1) JA_ResumeChannel(musica);
|
||||
}
|
||||
|
||||
// Para la música que estava sonant
|
||||
void stopMusic()
|
||||
{
|
||||
JA_StopMusic(); //Mix_HaltMusic();
|
||||
//if (musica != -1) JA_StopChannel(musica);
|
||||
//musica = -1;
|
||||
musica_actual = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace audio
|
||||
/// @brief Tanca el sistema de só
|
||||
void quit();
|
||||
|
||||
void loadMusic(const std::string filename);
|
||||
|
||||
/// @brief Comença a reproduïr la música des d'un arxiu
|
||||
/// @param filename nom de l'arxiu
|
||||
/// @param loop quants bucles farà (-1=infinit, 0=no repeteix, 1=repeteix 1 vegada...)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include "gif.h"
|
||||
#include "jfile.h"
|
||||
#include "config.h"
|
||||
#include <vector>
|
||||
|
||||
namespace draw
|
||||
@@ -24,6 +25,7 @@ namespace draw
|
||||
static int screen_height = 240;
|
||||
std::string screen_title = "";
|
||||
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 *destination = nullptr; // Punter a la actual superficie de destí
|
||||
@@ -43,6 +45,8 @@ namespace draw
|
||||
surface* managed[50];
|
||||
int num_managed = 0;
|
||||
|
||||
bool console = false;
|
||||
|
||||
namespace stencil
|
||||
{
|
||||
static bool enabled = false;
|
||||
@@ -87,20 +91,44 @@ namespace draw
|
||||
screen_height = height;
|
||||
|
||||
// [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
|
||||
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_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
||||
|
||||
const int num_render_drivers = SDL_GetNumRenderDrivers();
|
||||
printf("Available renderers:\n");
|
||||
for (int i=0; i<num_render_drivers; ++i)
|
||||
{
|
||||
printf(" - %i: %s\n", i, SDL_GetRenderDriver(i));
|
||||
}
|
||||
|
||||
for (int i=0; i<num_render_drivers; ++i) printf(" - %i: %s\n", i, SDL_GetRenderDriver(i));
|
||||
printf("\nRenderer: %s\n", SDL_GetRendererName(sdl_renderer));
|
||||
|
||||
SDL_HideCursor();
|
||||
@@ -181,16 +209,25 @@ namespace draw
|
||||
SDL_DestroyTexture(sdl_texture);
|
||||
SDL_DestroyRenderer(sdl_renderer);
|
||||
SDL_DestroyWindow(sdl_window);
|
||||
any_fullscreen = screen_fullscreen || config::getKioskMode() || console;
|
||||
|
||||
const int zoom = screen_fullscreen ? 1 : screen_zoom;
|
||||
sdl_window = SDL_CreateWindow(screen_title.c_str(), screen_width * zoom, screen_height * zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN:0);
|
||||
const int zoom = any_fullscreen ? 1 : screen_zoom;
|
||||
|
||||
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_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
||||
|
||||
SDL_HideCursor();
|
||||
|
||||
if (screen_fullscreen)
|
||||
if (any_fullscreen)
|
||||
{
|
||||
int w, h;
|
||||
SDL_GetWindowSize(sdl_window, &w, &h);
|
||||
@@ -213,6 +250,7 @@ namespace draw
|
||||
|
||||
void setZoom(const int value)
|
||||
{
|
||||
if (screen_fullscreen || config::getKioskMode() || console) return;
|
||||
if (value < 1) return;
|
||||
const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(sdl_window));
|
||||
|
||||
@@ -225,22 +263,26 @@ namespace draw
|
||||
|
||||
void incZoom()
|
||||
{
|
||||
if (screen_fullscreen || config::getKioskMode() || console) return;
|
||||
setZoom(screen_zoom+1);
|
||||
}
|
||||
|
||||
void decZoom()
|
||||
{
|
||||
if (screen_fullscreen || config::getKioskMode() || console) return;
|
||||
setZoom(screen_zoom-1);
|
||||
}
|
||||
|
||||
void toggleFullscreen()
|
||||
{
|
||||
if (config::getKioskMode() || console) return;
|
||||
screen_fullscreen = !screen_fullscreen;
|
||||
reinit();
|
||||
}
|
||||
|
||||
void setFullscreen(const bool value)
|
||||
{
|
||||
if (config::getKioskMode() || console) return;
|
||||
if (screen_fullscreen == value) return;
|
||||
screen_fullscreen = value;
|
||||
reinit();
|
||||
@@ -723,7 +765,7 @@ bool SaveIndexedAsBMP(const char *filename,
|
||||
// Desbloquejem la textura
|
||||
SDL_UnlockTexture(sdl_texture);
|
||||
|
||||
if (screen_fullscreen)
|
||||
if (any_fullscreen)
|
||||
{
|
||||
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(sdl_renderer);
|
||||
@@ -734,9 +776,10 @@ bool SaveIndexedAsBMP(const char *filename,
|
||||
|
||||
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);
|
||||
for (int y=0; y<screen_height; ++y)
|
||||
{
|
||||
|
||||
@@ -38,7 +38,8 @@ namespace draw
|
||||
/// @param height es el alt de la finestra "virtual"
|
||||
/// @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 reinit();
|
||||
|
||||
/// @brief Finalització del sistema (tancar coses de SDL, superficies fixes, etc...)
|
||||
void quit();
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include "jaudio.h"
|
||||
#include "actor.h"
|
||||
#include "versio.h"
|
||||
|
||||
namespace modules
|
||||
{
|
||||
namespace menu
|
||||
@@ -122,7 +124,7 @@ namespace modules
|
||||
//draw::print2(input::getPadBtnPressed(), 3, 0, 24, RED, 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();
|
||||
return OPTION_NONE;
|
||||
|
||||
@@ -116,6 +116,14 @@ void game::init()
|
||||
draw::init("The Pool", 320, 240, zoom, fullscreen);
|
||||
console::init();
|
||||
|
||||
printf("Carregant mus_menu.ogg...\n");
|
||||
audio::loadMusic("mus_menu.ogg");
|
||||
printf("Carregant mus_ingame.ogg...\n");
|
||||
audio::loadMusic("mus_ingame.ogg");
|
||||
printf("Carregant mus_gameover.ogg...\n");
|
||||
audio::loadMusic("mus_gameover.ogg");
|
||||
|
||||
printf("Carregant arxius de só...\n");
|
||||
audio::loadSound("snd_logo.wav");
|
||||
audio::loadSound("snd_walk.wav");
|
||||
audio::loadSound("snd_push.wav");
|
||||
@@ -136,8 +144,11 @@ void game::init()
|
||||
current_module = M_GAME;
|
||||
modules::game::init();
|
||||
|
||||
} else
|
||||
} else {
|
||||
//current_module = M_GAME;
|
||||
//modules::game::init();
|
||||
modules::logo::init();
|
||||
}
|
||||
}
|
||||
|
||||
bool game::loop()
|
||||
|
||||
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