VERSIÓ 1.2
- [NEW] Convertit a SDL3
This commit is contained in:
84
mini.cpp
84
mini.cpp
@@ -95,15 +95,15 @@ char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAV
|
||||
"AMShAAAQsjAAAwsjAAAeSzAAAcU3AAAEqRAAABVaiAAMezhAAAAAMAADH4wAASb2SAAMAttAQYcefACGOe+AAAVVAAAAbbAA";
|
||||
|
||||
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
|
||||
const Uint8 *keys;
|
||||
const bool *keys;
|
||||
Uint8 key_just_pressed = 0;
|
||||
|
||||
int mouse_x, mouse_y, mouse_wheel;
|
||||
Uint32 mouse_buttons;
|
||||
uint8_t mouse_just_pressed = 0;
|
||||
|
||||
SDL_GameController *gamepad = NULL;
|
||||
int8_t pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
SDL_Gamepad *gamepad = NULL;
|
||||
int8_t pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID;
|
||||
|
||||
#define MAX_SOUNDS 50
|
||||
JA_Music_t *music = NULL;
|
||||
@@ -182,7 +182,7 @@ void reinit() {
|
||||
}
|
||||
|
||||
void initaudio() {
|
||||
JA_Init(48000, AUDIO_S16, 1);
|
||||
JA_Init(48000, SDL_AUDIO_S16, 1);
|
||||
for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL;
|
||||
}
|
||||
|
||||
@@ -300,13 +300,20 @@ void createDisplay() {
|
||||
if (screen_zoom <= 0) screen_zoom = 1;
|
||||
while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--;
|
||||
|
||||
mini_win = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_RESIZABLE);
|
||||
mini_win = SDL_CreateWindow(window_title, screen_width*screen_zoom, screen_height*screen_zoom, screen_fullscreen?SDL_WINDOW_FULLSCREEN:SDL_WINDOW_RESIZABLE);
|
||||
windowID = SDL_GetWindowID(mini_win);
|
||||
mini_ren = SDL_CreateRenderer(mini_win, -1, 0);
|
||||
mini_ren = SDL_CreateRenderer(mini_win, NULL);
|
||||
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
||||
SDL_RenderSetLogicalSize(mini_ren, screen_width, screen_height);
|
||||
SDL_ShowCursor(screen_cursor?SDL_ENABLE:SDL_DISABLE);
|
||||
//SDL_SetRenderLogicalPresentation(mini_ren, screen_width, screen_height);
|
||||
if (screen_cursor) SDL_ShowCursor(); else SDL_HideCursor();
|
||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
||||
SDL_SetTextureScaleMode(mini_bak, SDL_SCALEMODE_NEAREST);
|
||||
SDL_PropertiesID props = SDL_GetTextureProperties(mini_bak);
|
||||
int real_pixelformat = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, -1);
|
||||
if (real_pixelformat != SDL_PIXELFORMAT_ARGB8888) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Pixelformat incorrecte: %i\n", real_pixelformat);
|
||||
exit(1);
|
||||
}
|
||||
//SDL_GetWindowPosition(mini_win, &windowpos_x, &windowpos_y);
|
||||
}
|
||||
|
||||
@@ -317,13 +324,14 @@ void destroyDisplay() {
|
||||
}
|
||||
|
||||
void initGamePad() {
|
||||
const int num_joysticks = SDL_NumJoysticks();
|
||||
if (num_joysticks>=1) {
|
||||
int num_joysticks;
|
||||
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
|
||||
if (joysticks) {
|
||||
for (int i=0; i<num_joysticks; ++i) {
|
||||
if (SDL_IsGameController(i)) {
|
||||
gamepad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(gamepad) == SDL_TRUE) {
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
if (SDL_IsGamepad(joysticks[i])) {
|
||||
gamepad = SDL_OpenGamepad(joysticks[i]);
|
||||
if (SDL_GamepadConnected(gamepad)) {
|
||||
SDL_SetGamepadEventsEnabled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -334,7 +342,7 @@ void initGamePad() {
|
||||
int main(int argc,char*argv[]){
|
||||
|
||||
#ifdef DEBUG
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
|
||||
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
|
||||
#endif
|
||||
|
||||
if (argc>1)
|
||||
@@ -383,16 +391,16 @@ int main(int argc,char*argv[]){
|
||||
|
||||
setdest(newsurf(screen_width, screen_height));
|
||||
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD);
|
||||
|
||||
SDL_DisplayMode dm;
|
||||
if (SDL_GetDesktopDisplayMode(0, &dm) != 0)
|
||||
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
||||
if (!dm)
|
||||
{
|
||||
SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
desktop_width = dm.w;
|
||||
desktop_height = dm.h;
|
||||
desktop_width = dm->w;
|
||||
desktop_height = dm->h;
|
||||
|
||||
createDisplay();
|
||||
|
||||
@@ -412,15 +420,15 @@ int main(int argc,char*argv[]){
|
||||
|
||||
Uint32 dt=SDL_GetTicks();
|
||||
key_just_pressed = 0;
|
||||
pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID;
|
||||
mouse_just_pressed = 0;
|
||||
while(!should_exit) {
|
||||
mouse_wheel = 0;
|
||||
if (update_mode==UPDATE_WAIT) SDL_WaitEvent(NULL);
|
||||
else if (update_mode==UPDATE_TIMEOUT) SDL_WaitEventTimeout(NULL, timeout);
|
||||
while(SDL_PollEvent(&mini_eve)) {
|
||||
if (mini_eve.type == SDL_QUIT) { should_exit=true; should_quit=true; break; }
|
||||
if (mini_eve.type == SDL_KEYDOWN) {
|
||||
if (mini_eve.type == SDL_EVENT_QUIT) { should_exit=true; should_quit=true; break; }
|
||||
if (mini_eve.type == SDL_EVENT_KEY_DOWN) {
|
||||
/*
|
||||
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F2) {
|
||||
screen_zoom+=2; if (screen_zoom>=10) screen_zoom=2;
|
||||
@@ -436,7 +444,7 @@ int main(int argc,char*argv[]){
|
||||
}
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F12) {
|
||||
if (mini_eve.key.scancode == SDL_SCANCODE_F12) {
|
||||
if (lua_is_playing()) {
|
||||
lua_quit();
|
||||
quitaudio();
|
||||
@@ -444,23 +452,23 @@ int main(int argc,char*argv[]){
|
||||
} else {
|
||||
should_exit=true;
|
||||
}
|
||||
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F5) {
|
||||
} else if (mini_eve.key.scancode == SDL_SCANCODE_F5) {
|
||||
should_exit=true;
|
||||
} else {
|
||||
key_just_pressed = mini_eve.key.keysym.scancode;
|
||||
key_just_pressed = mini_eve.key.scancode;
|
||||
}
|
||||
#else
|
||||
key_just_pressed = mini_eve.key.keysym.scancode;
|
||||
key_just_pressed = mini_eve.key.scancode;
|
||||
#endif
|
||||
}
|
||||
if (mini_eve.type == SDL_MOUSEBUTTONUP) {
|
||||
if (mini_eve.type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
||||
mouse_just_pressed = mini_eve.button.button;
|
||||
}
|
||||
if (mini_eve.type == SDL_MOUSEWHEEL) {
|
||||
if (mini_eve.type == SDL_EVENT_MOUSE_WHEEL) {
|
||||
mouse_wheel = mini_eve.wheel.y;
|
||||
}
|
||||
if (mini_eve.type == SDL_CONTROLLERBUTTONDOWN) {
|
||||
pad_just_pressed = mini_eve.cbutton.button;
|
||||
if (mini_eve.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN) {
|
||||
pad_just_pressed = mini_eve.gbutton.button;
|
||||
}
|
||||
/*if ( (mini_eve.type == SDL_WINDOWEVENT) &&
|
||||
(mini_eve.window.windowID == windowID) &&
|
||||
@@ -471,10 +479,10 @@ int main(int argc,char*argv[]){
|
||||
}*/
|
||||
}
|
||||
keys = SDL_GetKeyboardState(NULL);
|
||||
int real_mouse_x, real_mouse_y;
|
||||
float real_mouse_x, real_mouse_y;
|
||||
mouse_buttons = SDL_GetMouseState(&real_mouse_x, &real_mouse_y);
|
||||
float mx, my;
|
||||
SDL_RenderWindowToLogical(mini_ren, real_mouse_x, real_mouse_y, &mx, &my);
|
||||
SDL_RenderCoordinatesFromWindow(mini_ren, real_mouse_x, real_mouse_y, &mx, &my);
|
||||
mouse_x = int(mx);
|
||||
mouse_y = int(my);
|
||||
//mouse_x /= screen_zoom; mouse_y /= screen_zoom;
|
||||
@@ -490,14 +498,14 @@ int main(int argc,char*argv[]){
|
||||
if (beats>0)beats--;
|
||||
key_just_pressed = 0;
|
||||
mouse_just_pressed = 0;
|
||||
pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID;
|
||||
}
|
||||
SDL_SetRenderDrawColor(mini_ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(mini_ren);
|
||||
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
|
||||
for (uint32_t i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
|
||||
SDL_UnlockTexture(mini_bak);
|
||||
SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
|
||||
SDL_RenderTexture(mini_ren, mini_bak, NULL, NULL);
|
||||
SDL_RenderPresent(mini_ren);
|
||||
fps_counter++;
|
||||
if (SDL_GetTicks()>=(fps_timer+1000)) {
|
||||
@@ -1123,7 +1131,7 @@ bool anykey() {
|
||||
|
||||
bool pad(int8_t i) {
|
||||
if (!gamepad) return false;
|
||||
return SDL_GameControllerGetButton(gamepad, SDL_GameControllerButton(i)) == 1;
|
||||
return SDL_GetGamepadButton(gamepad, SDL_GamepadButton(i)) == 1;
|
||||
}
|
||||
|
||||
bool padp(int8_t i) {
|
||||
@@ -1152,7 +1160,7 @@ int mwheel() {
|
||||
}
|
||||
|
||||
bool mbtn(uint8_t i) {
|
||||
return mouse_buttons & SDL_BUTTON(i);
|
||||
return mouse_buttons & SDL_BUTTON_MASK(i);
|
||||
}
|
||||
|
||||
bool mbtnp(uint8_t i) {
|
||||
@@ -1273,7 +1281,7 @@ bool getcursor() {
|
||||
|
||||
void setcursor(const bool value) {
|
||||
screen_cursor=value;
|
||||
SDL_ShowCursor(screen_cursor?SDL_ENABLE:SDL_DISABLE);
|
||||
if (screen_cursor) SDL_ShowCursor(); else SDL_HideCursor();
|
||||
}
|
||||
|
||||
const char* getconfig(const char* key) {
|
||||
|
||||
Reference in New Issue
Block a user