Treballant en la conversió a SDL3
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace config
|
namespace config
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef JA_USESDLMIXER
|
#ifndef JA_USESDLMIXER
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "stb_vorbis.c"
|
#include "stb_vorbis.c"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
||||||
@@ -30,23 +30,25 @@ JA_Music_t *current_music{NULL};
|
|||||||
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
||||||
|
|
||||||
int JA_freq {48000};
|
int JA_freq {48000};
|
||||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
SDL_AudioFormat JA_format {SDL_AUDIO_S16LE};
|
||||||
Uint8 JA_channels {2};
|
Uint8 JA_channels {2};
|
||||||
int JA_musicVolume = 128;
|
int JA_musicVolume = 128;
|
||||||
int JA_soundVolume = 64;
|
int JA_soundVolume = 64;
|
||||||
bool JA_musicEnabled = true;
|
bool JA_musicEnabled = true;
|
||||||
bool JA_soundEnabled = true;
|
bool JA_soundEnabled = true;
|
||||||
SDL_AudioDeviceID sdlAudioDevice = 0;
|
SDL_AudioStream *sdlAudioStream = nullptr;
|
||||||
|
|
||||||
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
void audioCallback(void * userdata, SDL_AudioStream* stream, int additional_amount, int total_amount) {
|
||||||
|
int len = total_amount;
|
||||||
SDL_memset(stream, 0, len);
|
SDL_memset(stream, 0, len);
|
||||||
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
||||||
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
||||||
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_musicVolume);
|
SDL_PutAudioStreamData(sdlAudioStream, (Uint8*)(current_music->output+current_music->pos), size);
|
||||||
|
SDL_MixAudio(stream, (Uint8*)(current_music->output+current_music->pos), SDL_AUDIO_S16LE, size, JA_musicVolume);
|
||||||
current_music->pos += size/2;
|
current_music->pos += size/2;
|
||||||
if (size < len) {
|
if (size < len) {
|
||||||
if (current_music->times != 0) {
|
if (current_music->times != 0) {
|
||||||
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_musicVolume);
|
SDL_MixAudio(stream+size, (Uint8*)current_music->output, SDL_AUDIO_S16LE, len-size, JA_musicVolume);
|
||||||
current_music->pos = (len-size)/2;
|
current_music->pos = (len-size)/2;
|
||||||
if (current_music->times > 0) current_music->times--;
|
if (current_music->times > 0) current_music->times--;
|
||||||
} else {
|
} else {
|
||||||
@@ -59,11 +61,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) {
|
|||||||
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_PLAYING) {
|
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
||||||
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
||||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_soundVolume);
|
SDL_MixAudio(stream, channels[i].sound->buffer + channels[i].pos, SDL_AUDIO_S16LE, size, JA_soundVolume);
|
||||||
channels[i].pos += size;
|
channels[i].pos += size;
|
||||||
if (size < len) {
|
if (size < len) {
|
||||||
if (channels[i].times != 0) {
|
if (channels[i].times != 0) {
|
||||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_soundVolume);
|
SDL_MixAudio(stream + size, channels[i].sound->buffer, SDL_AUDIO_S16LE, len-size, JA_soundVolume);
|
||||||
channels[i].pos = len-size;
|
channels[i].pos = len-size;
|
||||||
if (channels[i].times > 0) channels[i].times--;
|
if (channels[i].times > 0) channels[i].times--;
|
||||||
} else {
|
} else {
|
||||||
@@ -78,16 +80,16 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
|||||||
JA_freq = freq;
|
JA_freq = freq;
|
||||||
JA_format = format;
|
JA_format = format;
|
||||||
JA_channels = channels;
|
JA_channels = channels;
|
||||||
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
|
SDL_AudioSpec audioSpec{JA_format, JA_channels, JA_freq}; //, 0, 1024, 0, 0, audioCallback, NULL};
|
||||||
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice);
|
if (sdlAudioStream) SDL_DestroyAudioStream(sdlAudioStream);
|
||||||
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
sdlAudioStream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audioSpec, audioCallback, NULL);
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
SDL_PauseAudioStreamDevice(sdlAudioStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JA_Quit() {
|
void JA_Quit() {
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 1);
|
SDL_ResumeAudioStreamDevice(sdlAudioStream);
|
||||||
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice);
|
if (sdlAudioStream) SDL_DestroyAudioStream(sdlAudioStream);
|
||||||
sdlAudioDevice = 0;
|
sdlAudioStream = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
|
JA_Music_t *JA_LoadMusic(Uint8* buffer, Uint32 length)
|
||||||
@@ -212,7 +214,7 @@ JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
|||||||
JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size) {
|
JA_Sound_t *JA_LoadSound(uint8_t* buffer, uint32_t size) {
|
||||||
JA_Sound_t *sound = new JA_Sound_t();
|
JA_Sound_t *sound = new JA_Sound_t();
|
||||||
SDL_AudioSpec wavSpec;
|
SDL_AudioSpec wavSpec;
|
||||||
SDL_LoadWAV_RW(SDL_RWFromMem(buffer, size),1, &wavSpec, &sound->buffer, &sound->length);
|
SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size),1, &wavSpec, &sound->buffer, &sound->length);
|
||||||
|
|
||||||
SDL_AudioCVT cvt;
|
SDL_AudioCVT cvt;
|
||||||
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED };
|
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED, JA_SOUND_DISABLED };
|
||||||
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED };
|
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED, JA_MUSIC_DISABLED };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -22,7 +22,7 @@ namespace audio
|
|||||||
// Inicialitza el sistema de só
|
// Inicialitza el sistema de só
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
JA_Init(48000, AUDIO_S16, 2);
|
JA_Init(48000, SDL_AUDIO_S16LE, 2);
|
||||||
//Mix_Init(MIX_INIT_OGG);// | MIX_INIT_WAVPACK);
|
//Mix_Init(MIX_INIT_OGG);// | MIX_INIT_WAVPACK);
|
||||||
//Mix_OpenAudio(48000, AUDIO_S16, 2, 512);
|
//Mix_OpenAudio(48000, AUDIO_S16, 2, 512);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "gif.c"
|
#include "gif.c"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -15,7 +15,7 @@ namespace draw
|
|||||||
SDL_Renderer *sdl_renderer = nullptr; // El renderer de SDL
|
SDL_Renderer *sdl_renderer = nullptr; // El renderer de SDL
|
||||||
SDL_Texture *sdl_texture = nullptr; // La textura de SDL a la que pintarem la nostra superficie "screen" i que despres volcarem a pantalla
|
SDL_Texture *sdl_texture = nullptr; // La textura de SDL a la que pintarem la nostra superficie "screen" i que despres volcarem a pantalla
|
||||||
|
|
||||||
SDL_Rect dest_rect = {0, 0, 320, 240};
|
SDL_FRect dest_rect = {0, 0, 320, 240};
|
||||||
static int fullscreen_scale = 1;
|
static int fullscreen_scale = 1;
|
||||||
|
|
||||||
static int screen_zoom = 1;
|
static int screen_zoom = 1;
|
||||||
@@ -89,23 +89,22 @@ namespace draw
|
|||||||
// [TODO] Incloure gestió de pantalla completa
|
// [TODO] Incloure gestió de pantalla completa
|
||||||
|
|
||||||
// Inicialització de les estructures de SDL
|
// Inicialització de les estructures de SDL
|
||||||
sdl_window = SDL_CreateWindow(screen_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width * screen_zoom, screen_height * screen_zoom, screen_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_SHOWN);
|
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, -1, 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_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||||
|
|
||||||
SDL_RendererInfo info;
|
char *driver_name;
|
||||||
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)
|
||||||
{
|
{
|
||||||
SDL_GetRenderDriverInfo(i, &info);
|
SDL_GetRenderDriver(i);
|
||||||
printf(" - %i: %s\n", i, info.name);
|
printf(" - %i: %s\n", i, driver_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GetRendererInfo(sdl_renderer, &info);
|
printf("\nRenderer: %s\n", SDL_GetRendererName(sdl_renderer));
|
||||||
printf("\nRenderer: %s\n", info.name);
|
|
||||||
|
|
||||||
SDL_ShowCursor(false);
|
SDL_HideCursor();
|
||||||
|
|
||||||
if (screen_fullscreen)
|
if (screen_fullscreen)
|
||||||
{
|
{
|
||||||
@@ -183,11 +182,11 @@ namespace draw
|
|||||||
SDL_DestroyWindow(sdl_window);
|
SDL_DestroyWindow(sdl_window);
|
||||||
|
|
||||||
const int zoom = screen_fullscreen ? 1 : screen_zoom;
|
const int zoom = screen_fullscreen ? 1 : screen_zoom;
|
||||||
sdl_window = SDL_CreateWindow(screen_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width * zoom, screen_height * zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN);
|
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, -1, 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_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||||
|
|
||||||
SDL_ShowCursor(false);
|
SDL_HideCursor();
|
||||||
|
|
||||||
if (screen_fullscreen)
|
if (screen_fullscreen)
|
||||||
{
|
{
|
||||||
@@ -213,12 +212,10 @@ namespace draw
|
|||||||
void setZoom(const int value)
|
void setZoom(const int value)
|
||||||
{
|
{
|
||||||
if (value < 1) return;
|
if (value < 1) return;
|
||||||
|
const SDL_DisplayMode *dm = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(sdl_window));
|
||||||
|
|
||||||
SDL_DisplayMode dm;
|
if (screen_width*value > dm->w) return;
|
||||||
SDL_GetCurrentDisplayMode(0, &dm);
|
if (screen_height*value > dm->h) return;
|
||||||
|
|
||||||
if (screen_width*value > dm.w) return;
|
|
||||||
if (screen_height*value > dm.h) return;
|
|
||||||
|
|
||||||
screen_zoom = value;
|
screen_zoom = value;
|
||||||
reinit();
|
reinit();
|
||||||
@@ -707,7 +704,7 @@ namespace draw
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pintem la textura a pantalla
|
// Pintem la textura a pantalla
|
||||||
SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, &dest_rect);
|
SDL_RenderTexture(sdl_renderer, sdl_texture, NULL, &dest_rect);
|
||||||
|
|
||||||
if (screen_mode & SCREEN_MODE_SCANLINES)
|
if (screen_mode & SCREEN_MODE_SCANLINES)
|
||||||
{
|
{
|
||||||
@@ -718,14 +715,14 @@ namespace draw
|
|||||||
for (int y=0; y<screen_height; ++y)
|
for (int y=0; y<screen_height; ++y)
|
||||||
{
|
{
|
||||||
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 192);
|
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 192);
|
||||||
SDL_RenderDrawLine(sdl_renderer, dest_rect.x, dest_rect.y + y*zoom, dest_rect.x + dest_rect.w, dest_rect.y + y*zoom);
|
SDL_RenderLine(sdl_renderer, dest_rect.x, dest_rect.y + y*zoom, dest_rect.x + dest_rect.w, dest_rect.y + y*zoom);
|
||||||
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 96);
|
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 96);
|
||||||
if (zoom>3) SDL_RenderDrawLine(sdl_renderer, dest_rect.x, 1+dest_rect.y + y*zoom, dest_rect.x + dest_rect.w, 1+dest_rect.y + y*zoom);
|
if (zoom>3) SDL_RenderLine(sdl_renderer, dest_rect.x, 1+dest_rect.y + y*zoom, dest_rect.x + dest_rect.w, 1+dest_rect.y + y*zoom);
|
||||||
}
|
}
|
||||||
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 16);
|
SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 16);
|
||||||
for (int x=0; x<screen_width; ++x)
|
for (int x=0; x<screen_width; ++x)
|
||||||
{
|
{
|
||||||
SDL_RenderDrawLine(sdl_renderer, dest_rect.x + x*zoom, dest_rect.y, dest_rect.x + x*zoom, dest_rect.y + dest_rect.h);
|
SDL_RenderLine(sdl_renderer, dest_rect.x + x*zoom, dest_rect.y, dest_rect.x + x*zoom, dest_rect.y + dest_rect.h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
|
|||||||
game::param_count = argc;
|
game::param_count = argc;
|
||||||
game::params = argv;
|
game::params = argv;
|
||||||
|
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD);
|
||||||
|
|
||||||
input::init();
|
input::init();
|
||||||
audio::init();
|
audio::init();
|
||||||
@@ -47,26 +47,26 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
while(SDL_PollEvent(&e))
|
while(SDL_PollEvent(&e))
|
||||||
{
|
{
|
||||||
if (e.type==SDL_QUIT) { game::should_exit = true; break; }
|
if (e.type==SDL_EVENT_QUIT) { game::should_exit = true; break; }
|
||||||
if (e.type==SDL_KEYDOWN)
|
if (e.type==SDL_EVENT_KEY_DOWN)
|
||||||
{
|
{
|
||||||
input::updateKey(e.key.keysym.scancode);
|
input::updateKey(e.key.scancode);
|
||||||
}
|
}
|
||||||
if (e.type==SDL_KEYUP)
|
if (e.type==SDL_EVENT_KEY_UP)
|
||||||
{
|
{
|
||||||
input::updateKeypressed(e.key.keysym.scancode);
|
input::updateKeypressed(e.key.scancode);
|
||||||
}
|
}
|
||||||
if (e.type==SDL_MOUSEBUTTONUP)
|
if (e.type==SDL_EVENT_MOUSE_BUTTON_UP)
|
||||||
{
|
{
|
||||||
input::updateClk(e.button.button);
|
input::updateClk(e.button.button);
|
||||||
}
|
}
|
||||||
if (e.type==SDL_MOUSEWHEEL)
|
if (e.type==SDL_EVENT_MOUSE_WHEEL)
|
||||||
{
|
{
|
||||||
input::updateWheel(e.wheel.y);
|
input::updateWheel(e.wheel.y);
|
||||||
}
|
}
|
||||||
if (e.type==SDL_CONTROLLERBUTTONDOWN) {
|
if (e.type==SDL_EVENT_GAMEPAD_BUTTON_DOWN) {
|
||||||
input::updatePadBtn(e.cbutton.button);
|
input::updatePadBtn(e.gbutton.button);
|
||||||
input::updatePadBtnPressed(e.cbutton.button);
|
input::updatePadBtnPressed(e.gbutton.button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,8 +78,8 @@ int main(int argc, char *argv[])
|
|||||||
input::updateKeypressed(SDL_SCANCODE_UNKNOWN);
|
input::updateKeypressed(SDL_SCANCODE_UNKNOWN);
|
||||||
input::updateClk(0);
|
input::updateClk(0);
|
||||||
input::updateWheel(0);
|
input::updateWheel(0);
|
||||||
input::updatePadBtn(SDL_CONTROLLER_BUTTON_INVALID);
|
input::updatePadBtn(SDL_GAMEPAD_BUTTON_INVALID);
|
||||||
input::updatePadBtnPressed(SDL_CONTROLLER_BUTTON_INVALID);
|
input::updatePadBtnPressed(SDL_GAMEPAD_BUTTON_INVALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
|
|
||||||
namespace input
|
namespace input
|
||||||
{
|
{
|
||||||
static const uint8_t *keys = nullptr;
|
static const bool *keys = nullptr;
|
||||||
static uint8_t keypressed = 0;
|
static uint8_t keypressed = 0;
|
||||||
static uint8_t keydown = 0;
|
static uint8_t keydown = 0;
|
||||||
static uint8_t btnClicked = 0;
|
static uint8_t btnClicked = 0;
|
||||||
static int wheel = 0;
|
static int wheel = 0;
|
||||||
static SDL_GameController *gamepad = NULL;
|
static SDL_Gamepad *gamepad = NULL;
|
||||||
static int8_t pad_btn_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
static int8_t pad_btn_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||||
static int8_t pad_btn_down = SDL_CONTROLLER_BUTTON_INVALID;
|
static int8_t pad_btn_down = SDL_CONTROLLER_BUTTON_INVALID;
|
||||||
|
|
||||||
@@ -18,14 +18,23 @@ namespace input
|
|||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
char *buffer = file::getFileBuffer("gamecontrollerdb.txt", size);
|
char *buffer = file::getFileBuffer("gamecontrollerdb.txt", size);
|
||||||
if (SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(buffer, size), 1) < 0) printf("No s'ha pogut carregar el gamecontrollersdb.txt\n");
|
if (SDL_AddGamepadMappingsFromIO(SDL_IOFromMem(buffer, size), 1) < 0) printf("No s'ha pogut carregar el gamecontrollersdb.txt\n");
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
|
int num_gamepads;
|
||||||
|
SDL_JoystickID *gamepads = SDL_GetGamepads(&num_gamepads);
|
||||||
|
if (num_gamepads>0)
|
||||||
|
{
|
||||||
|
gamepad = SDL_OpenGamepad(gamepads[0]);
|
||||||
|
SDL_SetGamepadEventsEnabled(true);
|
||||||
|
SDL_free(gamepads);
|
||||||
|
}
|
||||||
|
/*
|
||||||
const int num_joysticks = SDL_NumJoysticks();
|
const int num_joysticks = SDL_NumJoysticks();
|
||||||
if (num_joysticks>=1) {
|
if (num_joysticks>=1) {
|
||||||
for (int i=0; i<num_joysticks; ++i) {
|
for (int i=0; i<num_joysticks; ++i) {
|
||||||
if (SDL_IsGameController(i)) {
|
if (SDL_IsGameController(i)) {
|
||||||
gamepad = SDL_GameControllerOpen(i);
|
gamepad = SDL_OpenGamepad() GameControllerOpen(i);
|
||||||
if (SDL_GameControllerGetAttached(gamepad) == SDL_TRUE) {
|
if (SDL_GameControllerGetAttached(gamepad) == SDL_TRUE) {
|
||||||
SDL_GameControllerEventState(SDL_ENABLE);
|
SDL_GameControllerEventState(SDL_ENABLE);
|
||||||
return;
|
return;
|
||||||
@@ -33,6 +42,7 @@ namespace input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
@@ -76,7 +86,7 @@ namespace input
|
|||||||
bool padBtnDown(const int8_t btn)
|
bool padBtnDown(const int8_t btn)
|
||||||
{
|
{
|
||||||
if (!gamepad) return false;
|
if (!gamepad) return false;
|
||||||
return SDL_GameControllerGetButton(gamepad, SDL_GameControllerButton(btn)) == 1;
|
return SDL_GetGamepadButton(gamepad, SDL_GamepadButton(btn)) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determina si el botó del pad especificat ha sigut polsat, pero no tornarà a ser true fins
|
// Determina si el botó del pad especificat ha sigut polsat, pero no tornarà a ser true fins
|
||||||
@@ -144,7 +154,7 @@ namespace input
|
|||||||
// Torna la posició X actual del ratolí
|
// Torna la posició X actual del ratolí
|
||||||
const int mouseX()
|
const int mouseX()
|
||||||
{
|
{
|
||||||
int x;
|
float x;
|
||||||
SDL_GetMouseState(&x, NULL);
|
SDL_GetMouseState(&x, NULL);
|
||||||
return x/draw::getZoom();
|
return x/draw::getZoom();
|
||||||
}
|
}
|
||||||
@@ -152,7 +162,7 @@ namespace input
|
|||||||
// Torna la posició Y actual del ratolí
|
// Torna la posició Y actual del ratolí
|
||||||
const int mouseY()
|
const int mouseY()
|
||||||
{
|
{
|
||||||
int y;
|
float y;
|
||||||
SDL_GetMouseState(NULL, &y);
|
SDL_GetMouseState(NULL, &y);
|
||||||
return y/draw::getZoom();
|
return y/draw::getZoom();
|
||||||
}
|
}
|
||||||
@@ -160,7 +170,7 @@ namespace input
|
|||||||
// Determina si el botó del ratolí especificat està sent polsada ara mateix
|
// Determina si el botó del ratolí especificat està sent polsada ara mateix
|
||||||
const bool mouseBtn(const int btn)
|
const bool mouseBtn(const int btn)
|
||||||
{
|
{
|
||||||
return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(btn));
|
return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_MASK(btn));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determina si el botó especificat ha sigut polsat, pero no tornarà a ser true fins
|
// Determina si el botó especificat ha sigut polsat, pero no tornarà a ser true fins
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "jutil.h"
|
#include "jutil.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
int stringToInt(const char *value, std::vector<const char*> strings, std::vector<int> values)
|
int stringToInt(const char *value, std::vector<const char*> strings, std::vector<int> values)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "m_editor_bitmap.h"
|
#include "m_editor_bitmap.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "m_game.h"
|
#include "m_game.h"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "m_game.h"
|
#include "m_game.h"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "m_editor_colors.h"
|
#include "m_editor_colors.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
namespace modules
|
namespace modules
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
@@ -106,7 +106,7 @@ void game::init()
|
|||||||
|
|
||||||
if (editor::isDevMode()) {
|
if (editor::isDevMode()) {
|
||||||
draw::init("The Pool", 520, 240, zoom);
|
draw::init("The Pool", 520, 240, zoom);
|
||||||
SDL_ShowCursor(true);
|
SDL_ShowCursor();
|
||||||
} else {
|
} else {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
draw::init("The Pool", 320, 240, zoom, fullscreen);
|
draw::init("The Pool", 320, 240, zoom, fullscreen);
|
||||||
|
|||||||
Reference in New Issue
Block a user