From 67c66f1c8a73ac98a06116dd03fa00a05fd070a0 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 14 Jul 2008 13:22:19 +0100 Subject: [PATCH] Some performance hacks --- src/Emitter.hpp | 2 +- src/Game.cpp | 1 + src/Makefile.am | 3 ++- src/Surface.cpp | 14 +++++++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Emitter.hpp b/src/Emitter.hpp index c557af0..d7cad84 100644 --- a/src/Emitter.hpp +++ b/src/Emitter.hpp @@ -23,7 +23,7 @@ #include "Platform.hpp" #include "Texture.hpp" -#define MAX_PARTICLES 1024 +#define MAX_PARTICLES 256 /* diff --git a/src/Game.cpp b/src/Game.cpp index 9ed0ba9..14303fd 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -548,6 +548,7 @@ void Game::Display() for (int i = 0; i < nStarCount; i++) { int x = stars[i].xpos - viewport.GetXAdjust(); int y = stars[i].ypos - viewport.GetYAdjust(); + starImage.Draw(x, y, starrotate, stars[i].scale); starrotate += 0.005f; } diff --git a/src/Makefile.am b/src/Makefile.am index c3346a5..f08faf8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,7 @@ bin_PROGRAMS = lander -AM_CXXFLAGS=$(LANDER_CFLAGS) $(SDL_CFLAGS) -Wall +# Add -pg for profiling +AM_CXXFLAGS=$(LANDER_CFLAGS) $(SDL_CFLAGS) -Wall -pg AM_LDFLAGS=$(LANDER_LIBS) $(SDL_LIBS) -lGLU $(LTLIBINTL) lander_SOURCES = Main.cpp Game.hpp Game.cpp \ Font.cpp Font.hpp HighScores.cpp HighScores.hpp Input.cpp \ diff --git a/src/Surface.cpp b/src/Surface.cpp index 9bae746..4a885c2 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -117,12 +117,17 @@ void Surface::Generate(int surftex, LandingPadList &pads) void Surface::Display() { - OpenGL &opengl = OpenGL::GetInstance(); - for (int i = 0; i < viewport->GetLevelWidth()/SURFACE_SIZE; i++) { + int left = viewport->GetXAdjust()/SURFACE_SIZE; + int right = left + OpenGL::GetInstance().GetWidth()/SURFACE_SIZE + 1; + int max = viewport->GetLevelWidth()/SURFACE_SIZE; + if (right > max) + right = max; + + for (int i = left; i < right; i++) { surface[i].xpos = i*SURFACE_SIZE - viewport->GetXAdjust(); surface[i].ypos = viewport->GetLevelHeight() - viewport->GetYAdjust() - MAX_SURFACE_HEIGHT; - opengl.Draw(&surface[i]); + OpenGL::GetInstance().Draw(&surface[i]); } } @@ -139,6 +144,9 @@ bool Surface::CheckCollisions(Ship &ship, LandingPadList &pads, int *padIndex) if (lookmax >= viewport->GetLevelWidth()/SURFACE_SIZE) lookmax = viewport->GetLevelWidth()/SURFACE_SIZE - 1; + if (ship.GetY() < viewport->GetLevelHeight() - MAX_SURFACE_HEIGHT) + return false; + *padIndex = -1; for (int i = lookmin; i <= lookmax; i++) { -- 2.39.2