|
1 | 1 | #include <stdlib.h> |
| 2 | +#include <stdio.h> |
2 | 3 | #include <stdbool.h> |
3 | 4 | #include <math.h> |
4 | 5 |
|
5 | | -#include <SDL2/SDL.h> |
| 6 | +#include <SDL3/SDL.h> |
6 | 7 | #ifdef __EMSCRIPTEN__ |
7 | 8 | #include <emscripten.h> |
8 | 9 | #endif |
@@ -393,7 +394,7 @@ void vec(int x, int y, bool vis) |
393 | 394 | if (vis) { |
394 | 395 | SDL_SetRenderDrawColor(renderer, 255*br/4, 255*br/4, 255*br/4, |
395 | 396 | 255); |
396 | | - SDL_RenderDrawLine(renderer, |
| 397 | + SDL_RenderLine(renderer, |
397 | 398 | wscale*xpos+window_width/2, |
398 | 399 | window_height-(wscale*ypos+window_height/2), |
399 | 400 | wscale*(xpos+sz*x)+window_width/2, |
@@ -523,14 +524,14 @@ void rotate(bool dir) |
523 | 524 | } |
524 | 525 |
|
525 | 526 | bool quit = false; |
526 | | -const uint8_t *pbson; |
| 527 | +const bool *pbson; |
527 | 528 |
|
528 | 529 | void contrl(const SDL_Event *e) |
529 | 530 | { |
530 | 531 | if (e) { |
531 | 532 | switch (e->type) { |
532 | | - case SDL_KEYDOWN: |
533 | | - switch (e->key.keysym.sym) { |
| 533 | + case SDL_EVENT_KEY_DOWN: |
| 534 | + switch (e->key.key) { |
534 | 535 | case SDLK_1: |
535 | 536 | quit = true; |
536 | 537 | break; |
@@ -918,19 +919,16 @@ void main_loop(void) |
918 | 919 | SDL_Event e; |
919 | 920 | static unsigned t0 = 0, t; |
920 | 921 |
|
921 | | - t = SDL_GetTicks64(); |
| 922 | + t = SDL_GetTicks(); |
922 | 923 |
|
923 | 924 | #ifdef __EMSCRIPTEN__ |
924 | 925 | if (t - t0 < 1000/60) return; |
925 | 926 | #endif |
926 | 927 |
|
927 | 928 | if (!quit) { |
928 | 929 | 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_RESIZED) { |
934 | 932 | window_width = e.window.data1; |
935 | 933 | window_height = e.window.data2; |
936 | 934 | wscale = max( |
@@ -991,28 +989,27 @@ int main(void) |
991 | 989 |
|
992 | 990 | dspsca(); |
993 | 991 |
|
994 | | - if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
| 992 | + if (!SDL_Init(SDL_INIT_VIDEO)) { |
995 | 993 | fprintf(stderr, "Failed to initialize SDL: %s\n", |
996 | 994 | SDL_GetError()); |
997 | 995 | return EXIT_FAILURE; |
998 | 996 | } |
999 | 997 |
|
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 |
1003 | 1001 | )) { |
1004 | 1002 | fprintf(stderr, "Failed to create window: %s\n", |
1005 | 1003 | SDL_GetError()); |
1006 | 1004 | SDL_Quit(); |
1007 | 1005 | return EXIT_FAILURE; |
1008 | 1006 | } |
1009 | 1007 |
|
1010 | | - SDL_SetWindowTitle(window, "Space Travel"); |
1011 | 1008 | SDL_SetWindowMinimumSize(window, 848, 848); |
1012 | 1009 |
|
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); |
1016 | 1013 | window_width = window_height = size; |
1017 | 1014 | SDL_SetWindowSize(window, window_width, window_height); |
1018 | 1015 |
|
|
0 commit comments