Quellcode durchsuchen

Optimize map drawing performance

Draw map only once at the program start.
DricomDragon vor 4 Jahren
Ursprung
Commit
b2c416b74a
1 geänderte Dateien mit 5 neuen und 1 gelöschten Zeilen
  1. 5 1
      main.cpp

+ 5 - 1
main.cpp

@@ -87,6 +87,10 @@ int main()
 
 	// [2.5] Surface containers
 	SDL_Surface* tileSet[BLOC_TOTAL] = {water, mountain, grass, desert};
+	SDL_Surface* map = SDL_CreateRGBSurface(SDL_HWSURFACE, WIDTH * BLOC_SIZE, HEIGHT * BLOC_SIZE, 32, 0x0, 0x0, 0x0, 0x0);
+
+	// [2.6] First map render
+	drawWorld(world, tileSet, map);
 
 	/// [3] Main loop
 	bool done(false);
@@ -118,7 +122,7 @@ int main()
 		// [3.3] Draw phase
 		SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
 
-		drawWorld(world, tileSet, screen);
+		SDL_BlitSurface(map, NULL, screen, NULL);
 
 		SDL_BlitSurface(pawn, NULL, screen, &pawnPos);