From 9d204bd64bfe69b97383be65c5baffd871dc2d99 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 18 Jul 2008 17:48:39 +0100 Subject: [PATCH] Make Emitter::Draw const --- src/Emitter.cpp | 21 ++++++++++++++------- src/Emitter.hpp | 3 ++- src/Game.cpp | 10 ++++++---- src/HighScores.cpp | 10 ++++------ src/Ship.cpp | 23 ++++++++++++----------- src/Ship.hpp | 5 +++-- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/Emitter.cpp b/src/Emitter.cpp index dd27bc0..2261bc9 100644 --- a/src/Emitter.cpp +++ b/src/Emitter.cpp @@ -99,10 +99,8 @@ void Emitter::NewCluster(int x, int y) /* * Draws all the particles created by this emitter. */ -void Emitter::Draw(float adjust_x, float adjust_y, bool createnew, bool evolve) +void Emitter::Draw(float adjust_x, float adjust_y) const { - int i, created = 0; - glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); @@ -110,7 +108,7 @@ void Emitter::Draw(float adjust_x, float adjust_y, bool createnew, bool evolve) glBindTexture(GL_TEXTURE_2D, texture->GetGLTexture()); - for (i = 0; i < MAX_PARTICLES; i++) { + for (int i = 0; i < MAX_PARTICLES; i++) { if (particle[i].active) { float x = particle[i].x - adjust_x; float y = particle[i].y - adjust_y; @@ -123,6 +121,18 @@ void Emitter::Draw(float adjust_x, float adjust_y, bool createnew, bool evolve) glTexCoord2d(0, 0); glVertex3f(x-partsize, y-partsize, 0); glEnd(); + + } + } + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +} + +void Emitter::Process(bool createnew, bool evolve) +{ + int created = 0; + for (int i = 0; i < MAX_PARTICLES; i++) { + if (particle[i].active) { if (evolve) { // Move particle particle[i].x += particle[i].xi/(slowdown*1000); @@ -154,11 +164,8 @@ void Emitter::Draw(float adjust_x, float adjust_y, bool createnew, bool evolve) created++; } } - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - /* * Creates one new particle at the specified index. */ diff --git a/src/Emitter.hpp b/src/Emitter.hpp index bde55b6..ef70153 100644 --- a/src/Emitter.hpp +++ b/src/Emitter.hpp @@ -35,9 +35,10 @@ public: float life=1.0f, float max_speed=10.0f, float size=2.0f, float slowdown=2.0f); virtual ~Emitter() { } - void Draw(float adjust_x=0.0f, float adjust_y=0.0f, bool bCreateNew=true, bool evolve=true); + void Draw(float adjust_x=0.0f, float adjust_y=0.0f) const; void NewCluster(int x, int y); void Reset(); + void Process(bool createnew, bool evolve = true); virtual void ProcessEffect(int particle) { } diff --git a/src/Game.cpp b/src/Game.cpp index bb5875e..b6759cc 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -185,6 +185,8 @@ void Game::Process() ship.Move(); } + ship.ProcessEffects(state == gsPaused, state == gsExplode); + // Move mines for (MineListIt it = mines.begin(); it != mines.end(); ++it) (*it).Move(); @@ -579,16 +581,16 @@ void Game::Display() (*it).Draw(nKeysRemaining > 0); // Draw the exhaust - ship.DrawExhaust(state == gsPaused); + ship.DrawExhaust(); if (state != gsDeathWait && state != gsGameOver && state != gsFadeToDeath && state != gsFadeToRestart) { ship.Display(); } - + // Draw the explosion if necessary if (state == gsExplode) { - ship.DrawExplosion(true); + ship.DrawExplosion(); glColor3f(0.0f, 1.0f, 0.0f); const char *sdeath = i18n("Press SPACE to continue"); int x = (opengl.GetWidth() - normalFont.GetStringWidth(sdeath)) / 2; @@ -597,7 +599,7 @@ void Game::Display() } else if (state == gsDeathWait || state == gsGameOver || state == gsFadeToDeath || state == gsFadeToRestart) { - ship.DrawExplosion(false); + ship.DrawExplosion(); } // Draw the arrows diff --git a/src/HighScores.cpp b/src/HighScores.cpp index 909f629..408cc06 100644 --- a/src/HighScores.cpp +++ b/src/HighScores.cpp @@ -128,6 +128,8 @@ void HighScores::Process() fw[i].em->ypos = (float)fw[i].y; fw[i].active = true; } + + fw[i].em->Process(fw[i].active); } // Fade in or out @@ -157,12 +159,8 @@ void HighScores::Display() OpenGL &opengl = OpenGL::GetInstance(); // Draw the fireworks - for (int i = 0; i < MAX_FIREWORKS; i++) { - if (fw[i].active) - fw[i].em->Draw(); - else - fw[i].em->Draw(0, 0, false); - } + for (int i = 0; i < MAX_FIREWORKS; i++) + fw[i].em->Draw(0, 0); // Draw scores if (state == hssDisplay) { diff --git a/src/Ship.cpp b/src/Ship.cpp index 6895664..395cd3a 100644 --- a/src/Ship.cpp +++ b/src/Ship.cpp @@ -43,7 +43,7 @@ void Ship::Display() shipImage.Draw(dx, dy, angle); } -void Ship::DrawExhaust(bool paused) +void Ship::DrawExhaust() { static double xlast, ylast; @@ -53,24 +53,19 @@ void Ship::DrawExhaust(bool paused) ((int)(exhaust.xpos + (exhaust.xpos - xlast)/2), (int)(exhaust.ypos + (exhaust.ypos - ylast)/2)); } - exhaust.Draw((double)viewport->GetXAdjust(), - (double)viewport->GetYAdjust(), true); } - else if (paused) - exhaust.Draw((double)viewport->GetXAdjust(), - (double)viewport->GetYAdjust(), false, false); - else - exhaust.Draw((double)viewport->GetXAdjust(), - (double)viewport->GetYAdjust(), false); + + exhaust.Draw((double)viewport->GetXAdjust(), + (double)viewport->GetYAdjust()); xlast = exhaust.xpos; ylast = exhaust.ypos; } -void Ship::DrawExplosion(bool createNew) +void Ship::DrawExplosion() { explosion.Draw((double)viewport->GetXAdjust(), - (double)viewport->GetYAdjust(), createNew); + (double)viewport->GetYAdjust()); } void Ship::Move() @@ -115,6 +110,12 @@ void Ship::Move() explosion.ypos = ypos + shipImage.GetHeight()/2; } +void Ship::ProcessEffects(bool paused, bool exploding) +{ + exhaust.Process(thrusting, !paused); + explosion.Process(exploding); +} + void Ship::ThrustOn() { thrusting = true; diff --git a/src/Ship.hpp b/src/Ship.hpp index c0630fe..a4e87a6 100644 --- a/src/Ship.hpp +++ b/src/Ship.hpp @@ -32,9 +32,10 @@ public: void Reset(); void Display(); - void DrawExhaust(bool paused); - void DrawExplosion(bool createNew); + void DrawExhaust(); + void DrawExplosion(); void Move(); + void ProcessEffects(bool paused, bool exploding); void ThrustOn(); void ThrustOff(); void Thrust(double speed); -- 2.39.2