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.
This commit is contained in:
Julie Marchant 2019-06-12 10:46:56 -04:00
parent 5434ce43c4
commit c323e17c2e
2 changed files with 5 additions and 7 deletions

View File

@ -2661,12 +2661,12 @@ int game_mainLoop()
if ((game.area == MISN_MARS) && (engine.addAliens > -1)) if ((game.area == MISN_MARS) && (engine.addAliens > -1))
{ {
if ((rand() % 5) == 0) 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 // which with the original rrand function caused the result
// returned to be `800 + rand() % -699`. Clearly a mistake, // returned to be `800 + rand() % -699`. Clearly a mistake,
// but I'm not entirely sure what the original intention was. // but I'm not entirely sure what the original intention was.
// For now, I've set the range to [800, 1500], which // I've set the range to [800, 1500] (modified for screen
// approximately replicates the original's results. // width), which approximately replicates the original's results.
collectable_add(screen->w + RANDRANGE(0, 700), collectable_add(screen->w + RANDRANGE(0, 700),
RANDRANGE(-screen->h / 3, (4 * screen->h) / 3), P_MINE, 25, RANDRANGE(-screen->h / 3, (4 * screen->h) / 3), P_MINE, 25,
180 * screen->w / 800 + RANDRANGE(0, 60)); 180 * screen->w / 800 + RANDRANGE(0, 60));

View File

@ -30,11 +30,9 @@ SDL_Texture *renderer_texture;
void renderer_update() void renderer_update()
{ {
// XXX: The SDL wiki says that SDL_UpdateTexture is slow and shouldn't SDL_LockTexture(renderer_texture, NULL, &(screen->pixels), &(screen->pitch));
// be used for textures that are updated often. This should be looked
// into.
SDL_UpdateTexture(renderer_texture, NULL, screen->pixels, screen->w * 4);
SDL_RenderCopy(renderer, renderer_texture, NULL, NULL); SDL_RenderCopy(renderer, renderer_texture, NULL, NULL);
SDL_UnlockTexture(renderer_texture);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }