Skip to content

Commit 2bb9c02

Browse files
committed
Use SDL3
1 parent 654fd71 commit 2bb9c02

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ RM=del /f # \
1111
INSTALL=copy # \
1212
MKDIR=mkdir # \
1313
prefix=. # \
14-
!if [set CL=/DSDL_MAIN_HANDLED SDL2.lib] # \
14+
!if [set CL=/DSDL_MAIN_HANDLED SDL3.lib] # \
1515
!endif # \
1616
!if [set _CL_=/link /subsystem:windows /entry:mainCRTStartup] # \
1717
!endif
1818

19-
LDLIBS = -lm -lSDL2
19+
LDLIBS = -lm -lSDL3
2020

2121
all: st$(EXEEXT)
2222

2323
wasm: html/st.js
2424

2525
html/st.js: st.c
26-
$(EMCC) -s USE_SDL=2 -o $@ st.c
26+
$(EMCC) -s USE_SDL=3 -o $@ st.c
2727

2828
clean:
2929
$(RM) st$(EXEEXT) html/st.js html/*.wasm

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ is available to [play online](https://akr.am/st) via WebAssembly.
88

99
## Install
1010

11-
The SDL2 library is required.
11+
The SDL3 library is required.
1212

1313
Run `make` to build `st`.
1414

st.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include <stdlib.h>
2+
#include <stdio.h>
23
#include <stdbool.h>
34
#include <math.h>
45

5-
#include <SDL2/SDL.h>
6+
#include <SDL3/SDL.h>
67
#ifdef __EMSCRIPTEN__
78
#include <emscripten.h>
89
#endif
@@ -393,7 +394,7 @@ void vec(int x, int y, bool vis)
393394
if (vis) {
394395
SDL_SetRenderDrawColor(renderer, 255*br/4, 255*br/4, 255*br/4,
395396
255);
396-
SDL_RenderDrawLine(renderer,
397+
SDL_RenderLine(renderer,
397398
wscale*xpos+window_width/2,
398399
window_height-(wscale*ypos+window_height/2),
399400
wscale*(xpos+sz*x)+window_width/2,
@@ -523,14 +524,14 @@ void rotate(bool dir)
523524
}
524525

525526
bool quit = false;
526-
const uint8_t *pbson;
527+
const bool *pbson;
527528

528529
void contrl(const SDL_Event *e)
529530
{
530531
if (e) {
531532
switch (e->type) {
532-
case SDL_KEYDOWN:
533-
switch (e->key.keysym.sym) {
533+
case SDL_EVENT_KEY_DOWN:
534+
switch (e->key.key) {
534535
case SDLK_1:
535536
quit = true;
536537
break;
@@ -918,19 +919,16 @@ void main_loop(void)
918919
SDL_Event e;
919920
static unsigned t0 = 0, t;
920921

921-
t = SDL_GetTicks64();
922+
t = SDL_GetTicks();
922923

923924
#ifdef __EMSCRIPTEN__
924925
if (t - t0 < 1000/60) return;
925926
#endif
926927

927928
if (!quit) {
928929
if (SDL_PollEvent(&e)) {
929-
if (e.type == SDL_QUIT) quit = true;
930-
else if (
931-
e.type == SDL_WINDOWEVENT &&
932-
e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED
933-
) {
930+
if (e.type == SDL_EVENT_QUIT) quit = true;
931+
else if (e.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
934932
window_width = e.window.data1;
935933
window_height = e.window.data2;
936934
wscale = max(
@@ -991,28 +989,27 @@ int main(void)
991989

992990
dspsca();
993991

994-
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
992+
if (!SDL_Init(SDL_INIT_VIDEO)) {
995993
fprintf(stderr, "Failed to initialize SDL: %s\n",
996994
SDL_GetError());
997995
return EXIT_FAILURE;
998996
}
999997

1000-
if (SDL_CreateWindowAndRenderer(
1001-
window_width, window_height,
1002-
SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE, &window, &renderer
998+
if (!SDL_CreateWindowAndRenderer(
999+
"Space Travel", window_width, window_height,
1000+
SDL_WINDOW_RESIZABLE, &window, &renderer
10031001
)) {
10041002
fprintf(stderr, "Failed to create window: %s\n",
10051003
SDL_GetError());
10061004
SDL_Quit();
10071005
return EXIT_FAILURE;
10081006
}
10091007

1010-
SDL_SetWindowTitle(window, "Space Travel");
10111008
SDL_SetWindowMinimumSize(window, 848, 848);
10121009

1013-
SDL_DisplayMode dm;
1014-
SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(window), &dm);
1015-
int size = min(min(dm.w, dm.h)-128, 1024);
1010+
const SDL_DisplayMode *dm =
1011+
SDL_GetDesktopDisplayMode(SDL_GetDisplayForWindow(window));
1012+
int size = min(min(dm->w, dm->h)-128, 1024);
10161013
window_width = window_height = size;
10171014
SDL_SetWindowSize(window, window_width, window_height);
10181015

0 commit comments

Comments
 (0)