mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 20:20:11 +02:00
update SDL3 to 3.4.10.
This commit is contained in:
@@ -31,9 +31,8 @@ typedef struct {
|
||||
Uint64 tick_acc;
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
SDL_Surface* screen;
|
||||
SDL_Texture* screentex;
|
||||
SDL_Texture* rendertarget; /* we need this render target for text to look good */
|
||||
SDL_Palette* palette;
|
||||
SDL_Texture* texture;
|
||||
SDL_AudioStream* audiostream;
|
||||
char status[SCREEN_W / 8];
|
||||
int status_ticks;
|
||||
@@ -75,6 +74,8 @@ static bool load(BytePusher* vm, SDL_IOStream* stream, bool closeio) {
|
||||
size_t bytes_read = 0;
|
||||
bool ok = true;
|
||||
|
||||
vm->display_help = true; // will set to false if load succeeds.
|
||||
|
||||
SDL_memset(vm->ram, 0, RAM_SIZE);
|
||||
|
||||
if (!stream) {
|
||||
@@ -130,16 +131,12 @@ static void print(BytePusher* vm, int x, int y, const char* str) {
|
||||
|
||||
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
|
||||
BytePusher* vm;
|
||||
SDL_Palette* palette;
|
||||
SDL_Rect usable_bounds;
|
||||
SDL_AudioSpec audiospec = { SDL_AUDIO_S8, 1, SAMPLES_PER_FRAME * FRAMES_PER_SECOND };
|
||||
SDL_DisplayID primary_display;
|
||||
SDL_PropertiesID texprops;
|
||||
int zoom = 2;
|
||||
int i;
|
||||
Uint8 r, g, b;
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
if (!SDL_SetAppMetadata("SDL 3 BytePusher", "1.0", "com.example.SDL3BytePusher")) {
|
||||
return SDL_APP_FAILURE;
|
||||
@@ -185,13 +182,7 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
if (!(vm->screen = SDL_CreateSurfaceFrom(
|
||||
SCREEN_W, SCREEN_H, SDL_PIXELFORMAT_INDEX8, vm->ram, SCREEN_W
|
||||
))) {
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
if (!(palette = SDL_CreateSurfacePalette(vm->screen))) {
|
||||
if (!(vm->palette = SDL_CreatePalette(256))) {
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
i = 0;
|
||||
@@ -199,28 +190,21 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
|
||||
for (g = 0; g < 6; ++g) {
|
||||
for (b = 0; b < 6; ++b, ++i) {
|
||||
SDL_Color color = { (Uint8)(r * 0x33), (Uint8)(g * 0x33), (Uint8)(b * 0x33), SDL_ALPHA_OPAQUE };
|
||||
palette->colors[i] = color;
|
||||
vm->palette->colors[i] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; i < 256; ++i) {
|
||||
SDL_Color color = { 0, 0, 0, SDL_ALPHA_OPAQUE };
|
||||
palette->colors[i] = color;
|
||||
vm->palette->colors[i] = color;
|
||||
}
|
||||
|
||||
texprops = SDL_CreateProperties();
|
||||
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_STREAMING);
|
||||
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, SCREEN_W);
|
||||
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, SCREEN_H);
|
||||
vm->screentex = SDL_CreateTextureWithProperties(vm->renderer, texprops);
|
||||
SDL_SetNumberProperty(texprops, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_TARGET);
|
||||
vm->rendertarget = SDL_CreateTextureWithProperties(vm->renderer, texprops);
|
||||
SDL_DestroyProperties(texprops);
|
||||
if (!vm->screentex || !vm->rendertarget) {
|
||||
vm->texture = SDL_CreateTexture(vm->renderer, SDL_PIXELFORMAT_INDEX8, SDL_TEXTUREACCESS_STREAMING, SCREEN_W, SCREEN_H);
|
||||
if (!vm->texture) {
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
SDL_SetTextureScaleMode(vm->screentex, SDL_SCALEMODE_NEAREST);
|
||||
SDL_SetTextureScaleMode(vm->rendertarget, SDL_SCALEMODE_NEAREST);
|
||||
SDL_SetTexturePalette(vm->texture, vm->palette);
|
||||
SDL_SetTextureScaleMode(vm->texture, SDL_SCALEMODE_NEAREST);
|
||||
|
||||
if (!(vm->audiostream = SDL_OpenAudioDeviceStream(
|
||||
SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audiospec, NULL, NULL
|
||||
@@ -235,6 +219,10 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
|
||||
vm->last_tick = SDL_GetTicksNS();
|
||||
vm->tick_acc = NS_PER_SECOND;
|
||||
|
||||
if (argc > 1) {
|
||||
load_file(vm, argv[1]);
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -283,35 +271,28 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
SDL_Surface *tex;
|
||||
|
||||
SDL_SetRenderTarget(vm->renderer, vm->rendertarget);
|
||||
|
||||
if (!SDL_LockTextureToSurface(vm->screentex, NULL, &tex)) {
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
vm->screen->pixels = &vm->ram[(Uint32)vm->ram[IO_SCREEN_PAGE] << 16];
|
||||
SDL_BlitSurface(vm->screen, NULL, tex, NULL);
|
||||
SDL_UnlockTexture(vm->screentex);
|
||||
|
||||
SDL_RenderTexture(vm->renderer, vm->screentex, NULL, NULL);
|
||||
|
||||
if (vm->display_help) {
|
||||
print(vm, 4, 4, "Drop a BytePusher file in this");
|
||||
print(vm, 8, 12, "window to load and run it!");
|
||||
print(vm, 4, 28, "Press ENTER to switch between");
|
||||
print(vm, 8, 36, "positional and symbolic input.");
|
||||
}
|
||||
|
||||
if (vm->status_ticks > 0) {
|
||||
vm->status_ticks -= 1;
|
||||
print(vm, 4, SCREEN_H - 12, vm->status);
|
||||
}
|
||||
const void *pixels = &vm->ram[(Uint32)vm->ram[IO_SCREEN_PAGE] << 16];
|
||||
SDL_UpdateTexture(vm->texture, NULL, pixels, SCREEN_W);
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(vm->renderer, NULL);
|
||||
SDL_RenderClear(vm->renderer);
|
||||
SDL_RenderTexture(vm->renderer, vm->rendertarget, NULL, NULL);
|
||||
|
||||
if (vm->display_help) {
|
||||
print(vm, 4, 4, "Drop a BytePusher file in this");
|
||||
print(vm, 8, 12, "window to load and run it!");
|
||||
print(vm, 4, 28, "Press ENTER to switch between");
|
||||
print(vm, 8, 36, "positional and symbolic input.");
|
||||
} else {
|
||||
SDL_RenderTexture(vm->renderer, vm->texture, NULL, NULL);
|
||||
}
|
||||
|
||||
if (vm->status_ticks > 0) {
|
||||
if (updated) {
|
||||
vm->status_ticks--;
|
||||
}
|
||||
print(vm, 4, SCREEN_H - 12, vm->status);
|
||||
}
|
||||
|
||||
SDL_RenderPresent(vm->renderer);
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
@@ -405,9 +386,8 @@ void SDL_AppQuit(void* appstate, SDL_AppResult result) {
|
||||
if (appstate) {
|
||||
BytePusher* vm = (BytePusher*)appstate;
|
||||
SDL_DestroyAudioStream(vm->audiostream);
|
||||
SDL_DestroyTexture(vm->rendertarget);
|
||||
SDL_DestroyTexture(vm->screentex);
|
||||
SDL_DestroySurface(vm->screen);
|
||||
SDL_DestroyTexture(vm->texture);
|
||||
SDL_DestroyPalette(vm->palette);
|
||||
SDL_DestroyRenderer(vm->renderer);
|
||||
SDL_DestroyWindow(vm->window);
|
||||
SDL_free(vm);
|
||||
|
||||
Reference in New Issue
Block a user