Compare commits
6 Commits
d8a9847f48
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d563a7907 | |||
| 942ce2a6ff | |||
| e92498fd16 | |||
| 6d09afdf09 | |||
| 00c4a08915 | |||
| 5529777ccb |
@@ -1,4 +1,4 @@
|
|||||||
libs = -lSDL2
|
libs = -lSDL3
|
||||||
cppflags = -D DEBUG -g
|
cppflags = -D DEBUG -g
|
||||||
executable = thepool_debug
|
executable = thepool_debug
|
||||||
sourcepath = source
|
sourcepath = source
|
||||||
|
|||||||
@@ -2118,7 +2118,7 @@ namespace actor
|
|||||||
|
|
||||||
void setLives(int value)
|
void setLives(int value)
|
||||||
{
|
{
|
||||||
lives = value;
|
lives = config::getInfiniteLives() ? 8 : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void die()
|
void die()
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -9,6 +10,8 @@ namespace config
|
|||||||
uint8_t keys[7] = {SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_SPACE, SDL_SCANCODE_RETURN, SDL_SCANCODE_ESCAPE};
|
uint8_t keys[7] = {SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_SPACE, SDL_SCANCODE_RETURN, SDL_SCANCODE_ESCAPE};
|
||||||
int8_t pad_btns[7] = {SDL_GAMEPAD_BUTTON_DPAD_UP, SDL_GAMEPAD_BUTTON_DPAD_DOWN, SDL_GAMEPAD_BUTTON_DPAD_LEFT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT, SDL_GAMEPAD_BUTTON_SOUTH, SDL_GAMEPAD_BUTTON_EAST, SDL_GAMEPAD_BUTTON_START};
|
int8_t pad_btns[7] = {SDL_GAMEPAD_BUTTON_DPAD_UP, SDL_GAMEPAD_BUTTON_DPAD_DOWN, SDL_GAMEPAD_BUTTON_DPAD_LEFT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT, SDL_GAMEPAD_BUTTON_SOUTH, SDL_GAMEPAD_BUTTON_EAST, SDL_GAMEPAD_BUTTON_START};
|
||||||
bool prologo_desbloquejat = false;
|
bool prologo_desbloquejat = false;
|
||||||
|
bool kiosk_mode = false;
|
||||||
|
bool infinite_lives = false;
|
||||||
|
|
||||||
void setMusic(const bool value)
|
void setMusic(const bool value)
|
||||||
{
|
{
|
||||||
@@ -82,4 +85,28 @@ namespace config
|
|||||||
return prologo_desbloquejat;
|
return prologo_desbloquejat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setKioskMode(const bool value)
|
||||||
|
{
|
||||||
|
kiosk_mode = value;
|
||||||
|
file::setConfigValue("kiosk", kiosk_mode ? "yes" : "no");
|
||||||
|
draw::reinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool getKioskMode()
|
||||||
|
{
|
||||||
|
return kiosk_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setInifiniteLives(const bool value)
|
||||||
|
{
|
||||||
|
infinite_lives= value;
|
||||||
|
file::setConfigValue("infinitelives", infinite_lives? "yes" : "no");
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool getInfiniteLives()
|
||||||
|
{
|
||||||
|
return infinite_lives;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,4 +30,10 @@ namespace config
|
|||||||
|
|
||||||
void setProgoloDesbloquejat();
|
void setProgoloDesbloquejat();
|
||||||
const bool isProgoloDesbloquejat();
|
const bool isProgoloDesbloquejat();
|
||||||
|
|
||||||
|
void setKioskMode(const bool value);
|
||||||
|
const bool getKioskMode();
|
||||||
|
|
||||||
|
void setInifiniteLives(const bool value);
|
||||||
|
const bool getInfiniteLives();
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "jgame.h"
|
#include "jgame.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
namespace console
|
namespace console
|
||||||
{
|
{
|
||||||
@@ -134,10 +135,11 @@ namespace console
|
|||||||
#define CMD_EXIT 4
|
#define CMD_EXIT 4
|
||||||
#define CMD_SHOW 5
|
#define CMD_SHOW 5
|
||||||
#define CMD_HIDE 6
|
#define CMD_HIDE 6
|
||||||
#define CMD_HELP 7
|
#define CMD_SET 7
|
||||||
#define NUM_CMDS 8
|
#define CMD_HELP 8
|
||||||
|
#define NUM_CMDS 9
|
||||||
|
|
||||||
const char *command_text[NUM_CMDS] = { "GIVE", "DROP", "GOTO", "MOVE", "EXIT", "SHOW", "HIDE", "HELP" };
|
const char *command_text[NUM_CMDS] = { "GIVE", "DROP", "GOTO", "MOVE", "EXIT", "SHOW", "HIDE", "SET", "HELP" };
|
||||||
|
|
||||||
#define PARAM_UNKNOWN -1
|
#define PARAM_UNKNOWN -1
|
||||||
#define PARAM_RUN 0
|
#define PARAM_RUN 0
|
||||||
@@ -283,9 +285,28 @@ namespace console
|
|||||||
debug::disable(value);
|
debug::disable(value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CMD_SET:
|
||||||
|
if (!tokens[1]) {
|
||||||
|
strcpy(msg, "ERROR: Nothing to set.");
|
||||||
|
} else {
|
||||||
|
strcpy(msg, "Ok.");
|
||||||
|
const int value = getIndexFromString(tokens[1], {"KIOSK", "INFINITELIVES"});
|
||||||
|
if (value==-1)
|
||||||
|
strcpy(msg, "ERROR: Cannot set that.");
|
||||||
|
else
|
||||||
|
switch (value) {
|
||||||
|
case 0:
|
||||||
|
config::setKioskMode(!config::getKioskMode());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
config::setInifiniteLives(!config::getInfiniteLives());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
case CMD_HELP:
|
case CMD_HELP:
|
||||||
if (!tokens[1]) {
|
if (!tokens[1]) {
|
||||||
strcpy(msg, "GIVE DROP GOTO MOVE EXIT SHOW HIDE HELP");
|
strcpy(msg, "GIVE DROP GOTO MOVE EXIT SHOW HIDE SET HELP");
|
||||||
} else {
|
} else {
|
||||||
int command = getCommand();
|
int command = getCommand();
|
||||||
switch (command)
|
switch (command)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#define EXTENSION_INTRODUCER 0x21
|
#define EXTENSION_INTRODUCER 0x21
|
||||||
#define IMAGE_DESCRIPTOR 0x2C
|
#define IMAGE_DESCRIPTOR 0x2C
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
#ifndef JA_USESDLMIXER
|
#ifndef JA_USESDLMIXER
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "stb_vorbis.c"
|
#include "stb_vorbis.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
||||||
|
|
||||||
@@ -45,6 +46,11 @@ bool JA_soundEnabled { true };
|
|||||||
SDL_AudioDeviceID sdlAudioDevice { 0 };
|
SDL_AudioDeviceID sdlAudioDevice { 0 };
|
||||||
SDL_TimerID JA_timerID { 0 };
|
SDL_TimerID JA_timerID { 0 };
|
||||||
|
|
||||||
|
bool fading = false;
|
||||||
|
int fade_start_time;
|
||||||
|
int fade_duration;
|
||||||
|
int fade_initial_volume;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
||||||
SDL_memset(stream, 0, len);
|
SDL_memset(stream, 0, len);
|
||||||
@@ -87,10 +93,24 @@ Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
|
|||||||
{
|
{
|
||||||
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING)
|
if (JA_musicEnabled && current_music && current_music->state == JA_MUSIC_PLAYING)
|
||||||
{
|
{
|
||||||
|
if (fading) {
|
||||||
|
int time = SDL_GetTicks();
|
||||||
|
if (time > (fade_start_time+fade_duration)) {
|
||||||
|
fading = false;
|
||||||
|
JA_StopMusic();
|
||||||
|
return 30;
|
||||||
|
} else {
|
||||||
|
const int time_passed = time - fade_start_time;
|
||||||
|
const float percent = (float)time_passed / (float)fade_duration;
|
||||||
|
SDL_SetAudioStreamGain(current_music->stream, 1.0 - percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (current_music->times != 0)
|
if (current_music->times != 0)
|
||||||
{
|
{
|
||||||
if (SDL_GetAudioStreamAvailable(current_music->stream) < int(current_music->length/2))
|
if (SDL_GetAudioStreamAvailable(current_music->stream) < int(current_music->length/2)) {
|
||||||
SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length);
|
SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length);
|
||||||
|
}
|
||||||
if (current_music->times>0) current_music->times--;
|
if (current_music->times>0) current_music->times--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -123,10 +143,19 @@ Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval)
|
|||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
|
||||||
|
#endif
|
||||||
|
|
||||||
JA_audioSpec = {format, channels, freq };
|
JA_audioSpec = {format, channels, freq };
|
||||||
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
|
||||||
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
|
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice);
|
if (!sdlAudioDevice) {
|
||||||
|
log_msg(LOG_FAIL, "Failed to initialize SDL audio: %s\n", SDL_GetError());
|
||||||
|
} else {
|
||||||
|
log_msg(LOG_OK, "Audio subsytem initialized\n");
|
||||||
|
}
|
||||||
|
//SDL_PauseAudioDevice(sdlAudioDevice);
|
||||||
JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
|
JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +180,7 @@ JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
|
|||||||
music->spec.format = SDL_AUDIO_S16;
|
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);
|
SDL_memcpy(music->buffer, output, music->length);
|
||||||
SDL_free(output);
|
free(output);
|
||||||
music->pos = 0;
|
music->pos = 0;
|
||||||
music->state = JA_MUSIC_STOPPED;
|
music->state = JA_MUSIC_STOPPED;
|
||||||
|
|
||||||
@@ -180,19 +209,18 @@ void JA_PlayMusic(JA_Music_t *music, const int loop)
|
|||||||
{
|
{
|
||||||
if (!JA_musicEnabled) return;
|
if (!JA_musicEnabled) return;
|
||||||
|
|
||||||
if (current_music != NULL) {
|
JA_StopMusic();
|
||||||
current_music->pos = 0;
|
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
|
||||||
}
|
|
||||||
current_music = music;
|
current_music = music;
|
||||||
current_music->pos = 0;
|
current_music->pos = 0;
|
||||||
current_music->state = JA_MUSIC_PLAYING;
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
current_music->times = loop;
|
current_music->times = loop;
|
||||||
|
|
||||||
current_music->stream = SDL_CreateAudioStream(¤t_music->spec, &JA_audioSpec);
|
current_music->stream = SDL_CreateAudioStream(¤t_music->spec, &JA_audioSpec);
|
||||||
if (!SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length)) printf("[ERROR] SDL_PutAudioStreamData failed!\n");
|
if (!SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length)) log_msg(LOG_FAIL, "SDL_PutAudioStreamData failed!\n");
|
||||||
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
|
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
|
||||||
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream)) printf("[ERROR] SDL_BindAudioStream failed!\n");
|
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream)) log_msg(LOG_FAIL, "SDL_BindAudioStream failed!\n");
|
||||||
|
//SDL_ResumeAudioStreamDevice(current_music->stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_PauseMusic()
|
void JA_PauseMusic()
|
||||||
@@ -201,7 +229,8 @@ void JA_PauseMusic()
|
|||||||
if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
|
if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
|
|
||||||
current_music->state = JA_MUSIC_PAUSED;
|
current_music->state = JA_MUSIC_PAUSED;
|
||||||
SDL_PauseAudioStreamDevice(current_music->stream);
|
//SDL_PauseAudioStreamDevice(current_music->stream);
|
||||||
|
SDL_UnbindAudioStream(current_music->stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_ResumeMusic()
|
void JA_ResumeMusic()
|
||||||
@@ -210,7 +239,8 @@ void JA_ResumeMusic()
|
|||||||
if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
|
if (!current_music || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
|
|
||||||
current_music->state = JA_MUSIC_PLAYING;
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
SDL_ResumeAudioStreamDevice(current_music->stream);
|
//SDL_ResumeAudioStreamDevice(current_music->stream);
|
||||||
|
SDL_BindAudioStream(sdlAudioDevice, current_music->stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_StopMusic()
|
void JA_StopMusic()
|
||||||
@@ -220,11 +250,22 @@ void JA_StopMusic()
|
|||||||
|
|
||||||
current_music->pos = 0;
|
current_music->pos = 0;
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
SDL_PauseAudioStreamDevice(current_music->stream);
|
//SDL_PauseAudioStreamDevice(current_music->stream);
|
||||||
SDL_DestroyAudioStream(current_music->stream);
|
SDL_DestroyAudioStream(current_music->stream);
|
||||||
current_music->stream = nullptr;
|
current_music->stream = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JA_FadeOutMusic(const int milliseconds)
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled) return;
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
||||||
|
|
||||||
|
fading = true;
|
||||||
|
fade_start_time = SDL_GetTicks();
|
||||||
|
fade_duration = milliseconds;
|
||||||
|
fade_initial_volume = JA_musicVolume;
|
||||||
|
}
|
||||||
|
|
||||||
JA_Music_state JA_GetMusicState()
|
JA_Music_state JA_GetMusicState()
|
||||||
{
|
{
|
||||||
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
|
if (!JA_musicEnabled) return JA_MUSIC_DISABLED;
|
||||||
@@ -237,7 +278,7 @@ void JA_DeleteMusic(JA_Music_t *music)
|
|||||||
{
|
{
|
||||||
if (current_music == music) current_music = nullptr;
|
if (current_music == music) current_music = nullptr;
|
||||||
SDL_free(music->buffer);
|
SDL_free(music->buffer);
|
||||||
SDL_DestroyAudioStream(music->stream);
|
if (music->stream) SDL_DestroyAudioStream(music->stream);
|
||||||
delete music;
|
delete music;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +289,18 @@ float JA_SetMusicVolume(float volume)
|
|||||||
return JA_musicVolume;
|
return JA_musicVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JA_SetMusicPosition(float value)
|
||||||
|
{
|
||||||
|
if (!current_music) return;
|
||||||
|
current_music->pos = value * current_music->spec.freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
float JA_GetMusicPosition()
|
||||||
|
{
|
||||||
|
if (!current_music) return 0;
|
||||||
|
return float(current_music->pos)/float(current_music->spec.freq);
|
||||||
|
}
|
||||||
|
|
||||||
void JA_EnableMusic(const bool value)
|
void JA_EnableMusic(const bool value)
|
||||||
{
|
{
|
||||||
if ( !value && current_music && (current_music->state==JA_MUSIC_PLAYING) ) JA_StopMusic();
|
if ( !value && current_music && (current_music->state==JA_MUSIC_PLAYING) ) JA_StopMusic();
|
||||||
@@ -255,6 +308,10 @@ void JA_EnableMusic(const bool value)
|
|||||||
JA_musicEnabled = value;
|
JA_musicEnabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool JA_IsMusicEnabled()
|
||||||
|
{
|
||||||
|
return JA_musicEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -290,6 +347,26 @@ int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
|||||||
int channel = 0;
|
int channel = 0;
|
||||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
||||||
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
|
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
|
||||||
|
JA_StopChannel(channel);
|
||||||
|
|
||||||
|
channels[channel].sound = sound;
|
||||||
|
channels[channel].times = loop;
|
||||||
|
channels[channel].pos = 0;
|
||||||
|
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
|
channels[channel].stream = SDL_CreateAudioStream(&channels[channel].sound->spec, &JA_audioSpec);
|
||||||
|
SDL_PutAudioStreamData(channels[channel].stream, channels[channel].sound->buffer, channels[channel].sound->length);
|
||||||
|
SDL_SetAudioStreamGain(channels[channel].stream, JA_soundVolume);
|
||||||
|
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
|
||||||
|
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
JA_StopChannel(channel);
|
||||||
|
|
||||||
channels[channel].sound = sound;
|
channels[channel].sound = sound;
|
||||||
channels[channel].times = loop;
|
channels[channel].times = loop;
|
||||||
@@ -322,7 +399,8 @@ void JA_PauseChannel(const int channel)
|
|||||||
if (channels[i].state == JA_CHANNEL_PLAYING)
|
if (channels[i].state == JA_CHANNEL_PLAYING)
|
||||||
{
|
{
|
||||||
channels[i].state = JA_CHANNEL_PAUSED;
|
channels[i].state = JA_CHANNEL_PAUSED;
|
||||||
SDL_PauseAudioStreamDevice(channels[i].stream);
|
//SDL_PauseAudioStreamDevice(channels[i].stream);
|
||||||
|
SDL_UnbindAudioStream(channels[i].stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
@@ -330,7 +408,8 @@ void JA_PauseChannel(const int channel)
|
|||||||
if (channels[channel].state == JA_CHANNEL_PLAYING)
|
if (channels[channel].state == JA_CHANNEL_PLAYING)
|
||||||
{
|
{
|
||||||
channels[channel].state = JA_CHANNEL_PAUSED;
|
channels[channel].state = JA_CHANNEL_PAUSED;
|
||||||
SDL_PauseAudioStreamDevice(channels[channel].stream);
|
//SDL_PauseAudioStreamDevice(channels[channel].stream);
|
||||||
|
SDL_UnbindAudioStream(channels[channel].stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,7 +424,8 @@ void JA_ResumeChannel(const int channel)
|
|||||||
if (channels[i].state == JA_CHANNEL_PAUSED)
|
if (channels[i].state == JA_CHANNEL_PAUSED)
|
||||||
{
|
{
|
||||||
channels[i].state = JA_CHANNEL_PLAYING;
|
channels[i].state = JA_CHANNEL_PLAYING;
|
||||||
SDL_ResumeAudioStreamDevice(channels[i].stream);
|
//SDL_ResumeAudioStreamDevice(channels[i].stream);
|
||||||
|
SDL_BindAudioStream(sdlAudioDevice, channels[i].stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
@@ -353,7 +433,8 @@ void JA_ResumeChannel(const int channel)
|
|||||||
if (channels[channel].state == JA_CHANNEL_PAUSED)
|
if (channels[channel].state == JA_CHANNEL_PAUSED)
|
||||||
{
|
{
|
||||||
channels[channel].state = JA_CHANNEL_PLAYING;
|
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
SDL_ResumeAudioStreamDevice(channels[channel].stream);
|
//SDL_ResumeAudioStreamDevice(channels[channel].stream);
|
||||||
|
SDL_BindAudioStream(sdlAudioDevice, channels[channel].stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,18 +446,20 @@ void JA_StopChannel(const int channel)
|
|||||||
if (channel == -1)
|
if (channel == -1)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
|
if (channels[i].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[i].stream);
|
||||||
|
channels[channel].stream = nullptr;
|
||||||
channels[i].state = JA_CHANNEL_FREE;
|
channels[i].state = JA_CHANNEL_FREE;
|
||||||
channels[i].pos = 0;
|
channels[i].pos = 0;
|
||||||
channels[i].sound = NULL;
|
channels[i].sound = NULL;
|
||||||
SDL_DestroyAudioStream(channels[i].stream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
{
|
{
|
||||||
|
if (channels[channel].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[channel].stream);
|
||||||
|
channels[channel].stream = nullptr;
|
||||||
channels[channel].state = JA_CHANNEL_FREE;
|
channels[channel].state = JA_CHANNEL_FREE;
|
||||||
channels[channel].pos = 0;
|
channels[channel].pos = 0;
|
||||||
channels[channel].sound = NULL;
|
channels[channel].sound = NULL;
|
||||||
SDL_DestroyAudioStream(channels[channel].stream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,6 +492,11 @@ void JA_EnableSound(const bool value)
|
|||||||
JA_soundEnabled = value;
|
JA_soundEnabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool JA_IsSoundEnabled()
|
||||||
|
{
|
||||||
|
return JA_soundEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
float JA_SetVolume(float volume)
|
float JA_SetVolume(float volume)
|
||||||
{
|
{
|
||||||
JA_SetSoundVolume(JA_SetMusicVolume(volume) / 2.0f);
|
JA_SetSoundVolume(JA_SetMusicVolume(volume) / 2.0f);
|
||||||
|
|||||||
@@ -16,15 +16,20 @@ void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
|
|||||||
void JA_PauseMusic();
|
void JA_PauseMusic();
|
||||||
void JA_ResumeMusic();
|
void JA_ResumeMusic();
|
||||||
void JA_StopMusic();
|
void JA_StopMusic();
|
||||||
|
void JA_FadeOutMusic(const int milliseconds);
|
||||||
JA_Music_state JA_GetMusicState();
|
JA_Music_state JA_GetMusicState();
|
||||||
void JA_DeleteMusic(JA_Music_t *music);
|
void JA_DeleteMusic(JA_Music_t *music);
|
||||||
float JA_SetMusicVolume(float volume);
|
float JA_SetMusicVolume(float volume);
|
||||||
|
void JA_SetMusicPosition(float value);
|
||||||
|
float JA_GetMusicPosition();
|
||||||
void JA_EnableMusic(const bool value);
|
void JA_EnableMusic(const bool value);
|
||||||
|
const bool JA_IsMusicEnabled();
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
|
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
|
||||||
JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length);
|
JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length);
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename);
|
JA_Sound_t *JA_LoadSound(const char* filename);
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
|
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_PauseChannel(const int channel);
|
||||||
void JA_ResumeChannel(const int channel);
|
void JA_ResumeChannel(const int channel);
|
||||||
void JA_StopChannel(const int channel);
|
void JA_StopChannel(const int channel);
|
||||||
@@ -32,5 +37,6 @@ 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);
|
float JA_SetSoundVolume(float volume);
|
||||||
void JA_EnableSound(const bool value);
|
void JA_EnableSound(const bool value);
|
||||||
|
const bool JA_IsSoundEnabled();
|
||||||
|
|
||||||
float JA_SetVolume(float volume);
|
float JA_SetVolume(float volume);
|
||||||
|
|||||||
@@ -14,10 +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<music_cache_t> songs;
|
||||||
std::string musica_actual = "";
|
std::string musica_actual = "";
|
||||||
|
//int musica = -1;
|
||||||
|
|
||||||
// Inicialitza el sistema de só
|
// Inicialitza el sistema de só
|
||||||
void init()
|
void init()
|
||||||
@@ -30,36 +38,58 @@ namespace audio
|
|||||||
// Tanca el sistema de só (no shit, sherlock)
|
// Tanca el sistema de só (no shit, sherlock)
|
||||||
void quit()
|
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);
|
for (auto sound : sounds) JA_DeleteSound(sound.chunk); // Mix_FreeChunk(sound.chunk);
|
||||||
sounds.clear();
|
sounds.clear();
|
||||||
JA_Quit(); // Mix_CloseAudio();
|
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ó
|
// Comença a reproduïr la música en questió
|
||||||
void playMusic(const std::string filename, const int loop)
|
void playMusic(const std::string filename, const int loop)
|
||||||
{
|
{
|
||||||
if (!config::isMusicEnabled()) return;
|
if (!config::isMusicEnabled()) return;
|
||||||
// Si hi havia musica carregada, alliberem memòria
|
// 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;
|
//int song_index = 0;
|
||||||
char *buffer = file::getFileBuffer(filename, size);
|
for (auto song : songs)
|
||||||
music = JA_LoadMusic((uint8_t*)buffer, size);
|
{
|
||||||
free(buffer);
|
if (song.name == filename) {
|
||||||
//auto rwops = SDL_RWFromMem(music_buffer, size);
|
JA_PlayMusic(song.chunk, loop);
|
||||||
//auto mus = Mix_LoadMUS_RW(rwops, 1);
|
//musica = song_index;
|
||||||
//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;
|
musica_actual = filename;
|
||||||
|
return;
|
||||||
|
//song_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continua la música pausada
|
// Continua la música pausada
|
||||||
@@ -67,12 +97,15 @@ namespace audio
|
|||||||
{
|
{
|
||||||
if (!config::isMusicEnabled()) return;
|
if (!config::isMusicEnabled()) return;
|
||||||
JA_ResumeMusic(); //Mix_ResumeMusic();
|
JA_ResumeMusic(); //Mix_ResumeMusic();
|
||||||
|
//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);
|
||||||
|
//musica = -1;
|
||||||
musica_actual = "";
|
musica_actual = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ namespace audio
|
|||||||
/// @brief Tanca el sistema de só
|
/// @brief Tanca el sistema de só
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
void loadMusic(const std::string filename);
|
||||||
|
|
||||||
/// @brief Comença a reproduïr la música des d'un arxiu
|
/// @brief Comença a reproduïr la música des d'un arxiu
|
||||||
/// @param filename nom de l'arxiu
|
/// @param filename nom de l'arxiu
|
||||||
/// @param loop quants bucles farà (-1=infinit, 0=no repeteix, 1=repeteix 1 vegada...)
|
/// @param loop quants bucles farà (-1=infinit, 0=no repeteix, 1=repeteix 1 vegada...)
|
||||||
|
|||||||
103
source/jdraw.cpp
103
source/jdraw.cpp
@@ -1,7 +1,8 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "gif.c"
|
#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,19 +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);
|
||||||
|
|
||||||
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();
|
||||||
@@ -135,10 +164,12 @@ namespace draw
|
|||||||
char *p = buffer;
|
char *p = buffer;
|
||||||
char *n = buffer;
|
char *n = buffer;
|
||||||
while (*n!=0) {
|
while (*n!=0) {
|
||||||
while (*n!='\n') n++;
|
while (*n!='\n' && *n!='\r') n++;
|
||||||
*n=0;
|
*n=0;
|
||||||
loadSurface(p);
|
loadSurface(p);
|
||||||
p=++n;
|
n++;
|
||||||
|
while (*n=='\n' || *n=='\r') n++;
|
||||||
|
p=n;
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
@@ -178,15 +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 = 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);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
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_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);
|
||||||
@@ -209,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));
|
||||||
|
|
||||||
@@ -221,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();
|
||||||
@@ -672,9 +718,33 @@ namespace draw
|
|||||||
print2(buffer, x, y, color, zoom);
|
print2(buffer, x, y, color, zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SaveIndexedAsBMP(const char *filename,
|
||||||
|
const uint8_t *pixels,
|
||||||
|
const uint32_t *palette,
|
||||||
|
int w, int h)
|
||||||
|
{
|
||||||
|
SDL_Surface *surface = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_ARGB8888);
|
||||||
|
if (!surface) return false;
|
||||||
|
|
||||||
|
uint32_t *dst = (uint32_t *)surface->pixels;
|
||||||
|
int pitch32 = surface->pitch / 4;
|
||||||
|
|
||||||
|
for (int y = 0; y < h; y++) {
|
||||||
|
for (int x = 0; x < w; x++) {
|
||||||
|
uint8_t idx = pixels[y * w + x];
|
||||||
|
dst[y * pitch32 + x] = palette[idx]; // assumes ARGB8888
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok = SDL_SaveBMP(surface, filename);
|
||||||
|
SDL_DestroySurface(surface);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
// Refresca la pantalla
|
// Refresca la pantalla
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
|
//SaveIndexedAsBMP("screen.bmp", screen->pixels, palette, 320, 240);
|
||||||
|
|
||||||
Uint32 *sdl_pixels; // Punter al array de pixels que enstornarà SDL_LockTexture
|
Uint32 *sdl_pixels; // Punter al array de pixels que enstornarà SDL_LockTexture
|
||||||
int sdl_pitch; // Ací estarà guardat el pitch de la textura, com es de 32 bits, no m'afecta
|
int sdl_pitch; // Ací estarà guardat el pitch de la textura, com es de 32 bits, no m'afecta
|
||||||
@@ -689,13 +759,13 @@ namespace draw
|
|||||||
// i el enviem a la textura SDL
|
// i el enviem a la textura SDL
|
||||||
for (uint32_t i = 0; i < size; ++i)
|
for (uint32_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
sdl_pixels[i] = palette[screen->pixels[i]];
|
sdl_pixels[i] = 0xff000000 | palette[screen->pixels[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -706,9 +776,10 @@ namespace draw
|
|||||||
|
|
||||||
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,6 +38,7 @@ 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();
|
||||||
|
|||||||
27
source/log.h
Normal file
27
source/log.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
enum LogLevel { LOG_OK, LOG_FAIL, LOG_WARN, LOG_INFO, LOG_LUART, LOG_LUALD, LOG_VERBOSE, LOG_UNSALTED };
|
||||||
|
|
||||||
|
static inline void log_msg(enum LogLevel level, const char *fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
|
||||||
|
switch (level) {
|
||||||
|
case LOG_OK: printf("[\033[1;32m OK \033[0m] "); break;
|
||||||
|
case LOG_FAIL: printf("[\033[1;31mFAIL\033[0m] "); break;
|
||||||
|
case LOG_WARN: printf("[\033[1;33mWARN\033[0m] "); break;
|
||||||
|
case LOG_INFO: printf("[\033[1;34mINFO\033[0m] "); break;
|
||||||
|
case LOG_LUART: printf("[\033[1;35mLUA RUNTIME ERROR\033[0m] "); break;
|
||||||
|
case LOG_LUALD: printf("[\033[1;35mLUA LOADING ERROR\033[0m] "); break;
|
||||||
|
case LOG_VERBOSE: printf(" - "); break;
|
||||||
|
case LOG_UNSALTED: break;
|
||||||
|
}
|
||||||
|
vprintf(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define log_msg(...) ((void)0)
|
||||||
|
#endif
|
||||||
@@ -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
|
||||||
@@ -32,19 +34,21 @@ namespace modules
|
|||||||
|
|
||||||
int loop()
|
int loop()
|
||||||
{
|
{
|
||||||
if (controller::pressed(KEY_MENU)) {
|
int max_option = config::getKioskMode() ? 4 : 5;
|
||||||
|
|
||||||
|
if (controller::pressed(KEY_MENU) && !config::getKioskMode()) {
|
||||||
return OPTION_EIXIR;
|
return OPTION_EIXIR;
|
||||||
}
|
}
|
||||||
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
|
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
|
||||||
{
|
{
|
||||||
audio::playSound("snd_push.wav", SOUND_BASIC);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
selected_option++; if (selected_option==6) selected_option=min_option;
|
selected_option++; if (selected_option==max_option+1) selected_option=min_option;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller::pressed(KEY_UP) || input::keyPressed(SDL_SCANCODE_UP))
|
if (controller::pressed(KEY_UP) || input::keyPressed(SDL_SCANCODE_UP))
|
||||||
{
|
{
|
||||||
audio::playSound("snd_push.wav", SOUND_BASIC);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
selected_option--; if (selected_option<min_option) selected_option=5;
|
selected_option--; if (selected_option<min_option) selected_option=max_option;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_RETURN) )
|
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_RETURN) )
|
||||||
@@ -72,7 +76,7 @@ namespace modules
|
|||||||
draw::print2("de REDEFINIR TECLES", 11, 17, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR TECLES", 11, 17, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de REDEFINIR GAMEPAD", 11, 19, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR GAMEPAD", 11, 19, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
if (!config::getKioskMode()) draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
||||||
break;
|
break;
|
||||||
case OPTION_JUGAR:
|
case OPTION_JUGAR:
|
||||||
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
||||||
@@ -80,7 +84,7 @@ namespace modules
|
|||||||
draw::print2("de REDEFINIR TECLES", 11, 17, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR TECLES", 11, 17, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de REDEFINIR GAMEPAD", 11, 19, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR GAMEPAD", 11, 19, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
if (!config::getKioskMode()) draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
||||||
break;
|
break;
|
||||||
case OPTION_TECLES:
|
case OPTION_TECLES:
|
||||||
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
||||||
@@ -88,7 +92,7 @@ namespace modules
|
|||||||
draw::print2("fg REDEFINIR TECLES", 11, 16, YELLOW, FONT_ZOOM_VERTICAL);
|
draw::print2("fg REDEFINIR TECLES", 11, 16, YELLOW, FONT_ZOOM_VERTICAL);
|
||||||
draw::print2("de REDEFINIR GAMEPAD", 11, 19, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR GAMEPAD", 11, 19, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
if (!config::getKioskMode()) draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
||||||
break;
|
break;
|
||||||
case OPTION_GAMEPAD:
|
case OPTION_GAMEPAD:
|
||||||
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
||||||
@@ -96,7 +100,7 @@ namespace modules
|
|||||||
draw::print2("de REDEFINIR TECLES", 11, 16, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR TECLES", 11, 16, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("fg REDEFINIR GAMEPAD", 11, 18, YELLOW, FONT_ZOOM_VERTICAL);
|
draw::print2("fg REDEFINIR GAMEPAD", 11, 18, YELLOW, FONT_ZOOM_VERTICAL);
|
||||||
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de CONFIGURAR AUDIO", 11, 21, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
if (!config::getKioskMode()) draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
||||||
break;
|
break;
|
||||||
case OPTION_AUDIO:
|
case OPTION_AUDIO:
|
||||||
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
||||||
@@ -104,7 +108,7 @@ namespace modules
|
|||||||
draw::print2("de REDEFINIR TECLES", 11, 16, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR TECLES", 11, 16, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("de REDEFINIR GAMEPAD", 11, 18, GREEN, FONT_ZOOM_NONE);
|
draw::print2("de REDEFINIR GAMEPAD", 11, 18, GREEN, FONT_ZOOM_NONE);
|
||||||
draw::print2("fg CONFIGURAR AUDIO", 11, 20, YELLOW, FONT_ZOOM_VERTICAL);
|
draw::print2("fg CONFIGURAR AUDIO", 11, 20, YELLOW, FONT_ZOOM_VERTICAL);
|
||||||
draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
if (!config::getKioskMode()) draw::print2("de EIXIR", 11, 23, GREEN, FONT_ZOOM_NONE);
|
||||||
break;
|
break;
|
||||||
case OPTION_EIXIR:
|
case OPTION_EIXIR:
|
||||||
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
if (config::isProgoloDesbloquejat()) draw::print2("de JUGAR AL PROLOGO", 11, 12, GREEN, FONT_ZOOM_NONE);
|
||||||
@@ -120,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;
|
||||||
|
|||||||
@@ -98,6 +98,10 @@ void loadConfig()
|
|||||||
const int value = SDL_atoi( file::getConfigValue(nombotons[i]).c_str() );
|
const int value = SDL_atoi( file::getConfigValue(nombotons[i]).c_str() );
|
||||||
if (value != 0) config::definePadBtn(i, value);
|
if (value != 0) config::definePadBtn(i, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(file::getConfigValue("kiosk").c_str(), "yes")==0) config::setKioskMode(true);
|
||||||
|
if (strcmp(file::getConfigValue("infinitelives").c_str(), "yes")==0) config::setInifiniteLives(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void game::init()
|
void game::init()
|
||||||
@@ -112,6 +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...\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_logo.wav");
|
||||||
audio::loadSound("snd_walk.wav");
|
audio::loadSound("snd_walk.wav");
|
||||||
audio::loadSound("snd_push.wav");
|
audio::loadSound("snd_push.wav");
|
||||||
@@ -132,8 +144,11 @@ void game::init()
|
|||||||
current_module = M_GAME;
|
current_module = M_GAME;
|
||||||
modules::game::init();
|
modules::game::init();
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
|
//current_module = M_GAME;
|
||||||
|
//modules::game::init();
|
||||||
modules::logo::init();
|
modules::logo::init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool game::loop()
|
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