From c323e17c2e3149b08d0eb6c3920e95e27799d20b Mon Sep 17 00:00:00 2001 From: Julie Marchant Date: Wed, 12 Jun 2019 10:46:56 -0400 Subject: [PATCH] Replaced SDL_UpdateTexture with SDL_LockTexture. The SDL wiki indicates that this is the preferred way to do this for textures like renderer_texture that are updated often, since it is faster. --- src/game.c | 6 +++--- src/renderer.c | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/game.c b/src/game.c index aa664a3..555ea0c 100644 --- a/src/game.c +++ b/src/game.c @@ -2661,12 +2661,12 @@ int game_mainLoop() if ((game.area == MISN_MARS) && (engine.addAliens > -1)) { if ((rand() % 5) == 0) - // XXX: The originally specified range for x was [800, 100], + // Note: The originally specified range for x was [800, 100], // which with the original rrand function caused the result // returned to be `800 + rand() % -699`. Clearly a mistake, // but I'm not entirely sure what the original intention was. - // For now, I've set the range to [800, 1500], which - // approximately replicates the original's results. + // I've set the range to [800, 1500] (modified for screen + // width), which approximately replicates the original's results. collectable_add(screen->w + RANDRANGE(0, 700), RANDRANGE(-screen->h / 3, (4 * screen->h) / 3), P_MINE, 25, 180 * screen->w / 800 + RANDRANGE(0, 60)); diff --git a/src/renderer.c b/src/renderer.c index 5474f2e..7f3d9f7 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -30,11 +30,9 @@ SDL_Texture *renderer_texture; void renderer_update() { - // XXX: The SDL wiki says that SDL_UpdateTexture is slow and shouldn't - // be used for textures that are updated often. This should be looked - // into. - SDL_UpdateTexture(renderer_texture, NULL, screen->pixels, screen->w * 4); + SDL_LockTexture(renderer_texture, NULL, &(screen->pixels), &(screen->pitch)); SDL_RenderCopy(renderer, renderer_texture, NULL, NULL); + SDL_UnlockTexture(renderer_texture); SDL_RenderPresent(renderer); }