From 21700cec12fd1604102c6a919e7ffa3b0d9c7761 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 5 Jun 2009 12:43:38 +0100 Subject: [PATCH] Remove a few more instances of LOAD_ONCE --- src/ElectricGate.cpp | 14 ++++---------- src/ElectricGate.hpp | 3 +-- src/Emitter.cpp | 14 ++++---------- src/Emitter.hpp | 8 +++++--- src/LandingPad.cpp | 19 ++++++------------- src/LandingPad.hpp | 3 ++- 6 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/ElectricGate.cpp b/src/ElectricGate.cpp index 854c6bb..71a4a36 100644 --- a/src/ElectricGate.cpp +++ b/src/ElectricGate.cpp @@ -18,17 +18,11 @@ #include "ElectricGate.hpp" #include "Ship.hpp" -#include "LoadOnce.hpp" - -Image* ElectricGate::gateImage = NULL; ElectricGate::ElectricGate(Viewport* v, int length, bool vertical, int x, int y) - : StaticObject(x, y), length(length), vertical(vertical), viewport(v) + : StaticObject(x, y), length(length), vertical(vertical), viewport(v), + gateImage("images/gateway.png") { - LOAD_ONCE { - gateImage = new Image("images/gateway.png"); - } - lightning.Build(length * OBJ_GRID_SIZE, vertical); timer = rand() % 70 + 10; @@ -67,7 +61,7 @@ void ElectricGate::Draw() // Draw first sphere int draw_x = xpos*OBJ_GRID_SIZE - viewport->GetXAdjust(); int draw_y = ypos*OBJ_GRID_SIZE + OBJ_GRID_TOP - viewport->GetYAdjust(); - gateImage->Draw(draw_x, draw_y); + gateImage.Draw(draw_x, draw_y); // Draw second sphere if (vertical) { @@ -78,7 +72,7 @@ void ElectricGate::Draw() draw_x = (xpos+length)*OBJ_GRID_SIZE - viewport->GetXAdjust(); draw_y = ypos*OBJ_GRID_SIZE + OBJ_GRID_TOP - viewport->GetYAdjust(); } - gateImage->Draw(draw_x, draw_y); + gateImage.Draw(draw_x, draw_y); // Draw the electricity stuff if (--timer < GATEWAY_ACTIVE) { diff --git a/src/ElectricGate.hpp b/src/ElectricGate.hpp index abe2d07..783f75c 100644 --- a/src/ElectricGate.hpp +++ b/src/ElectricGate.hpp @@ -67,8 +67,7 @@ private: bool vertical; Viewport* viewport; Lightning lightning; - - static Image* gateImage; + Image gateImage; }; #endif diff --git a/src/Emitter.cpp b/src/Emitter.cpp index 10e6f62..0f461fa 100644 --- a/src/Emitter.cpp +++ b/src/Emitter.cpp @@ -19,9 +19,6 @@ #include "Emitter.hpp" #include "OpenGL.hpp" -#include "LoadOnce.hpp" - -Texture* Emitter::texture = NULL; // // Creates a new particle emitter. @@ -40,12 +37,9 @@ Emitter::Emitter(int x, int y, float r, float g, float b, bool createnew, float max_speed, float size, float slowdown) : partsize(size), r(r), g(g), b(b), deviation(deviation), xg(xg), yg(yg), life(life), maxspeed(max_speed), xpos((float)x), ypos((float)y), - slowdown(slowdown), createrate(128.0f), xi_bias(0.0f), yi_bias(0.0f) -{ - LOAD_ONCE { - texture = new Texture("images/particle.png"); - } - + slowdown(slowdown), createrate(128.0f), xi_bias(0.0f), yi_bias(0.0f), + texture_(LoadTexture("images/particle.png")) +{ // Set up the particles for (int i = 0; i < MAX_PARTICLES; i++) { if (createnew) @@ -106,7 +100,7 @@ void Emitter::Draw(float adjust_x, float adjust_y) const glBlendFunc(GL_SRC_ALPHA,GL_ONE); glLoadIdentity(); - glBindTexture(GL_TEXTURE_2D, texture->GetGLTexture()); + glBindTexture(GL_TEXTURE_2D, texture_->GetGLTexture()); for (int i = 0; i < MAX_PARTICLES; i++) { if (particle[i].active) { diff --git a/src/Emitter.hpp b/src/Emitter.hpp index 4a41f4d..3e87b52 100644 --- a/src/Emitter.hpp +++ b/src/Emitter.hpp @@ -31,8 +31,10 @@ // class Emitter { public: - Emitter(int x, int y, float r, float g, float b, bool createnew=true, float deviation=0.0f, float xg=0.0f, float yg=0.0f, - float life=1.0f, float max_speed=10.0f, float size=2.0f, float slowdown=2.0f); + Emitter(int x, int y, float r, float g, float b, bool createnew=true, + float deviation=0.0f, float xg=0.0f, float yg=0.0f, + 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) const; @@ -59,7 +61,7 @@ protected: float xg, yg; } particle[MAX_PARTICLES]; - static Texture* texture; + Texture* texture_; }; diff --git a/src/LandingPad.cpp b/src/LandingPad.cpp index f76ec02..1e7e05c 100644 --- a/src/LandingPad.cpp +++ b/src/LandingPad.cpp @@ -17,26 +17,19 @@ #include "LandingPad.hpp" #include "Surface.hpp" -#include "LoadOnce.hpp" #include "OpenGL.hpp" #include "Texture.hpp" #include "Viewport.hpp" -Texture* LandingPad::landTexture = NULL; -Texture* LandingPad::noLandTexture = NULL; - LandingPad::LandingPad(Viewport* v, int index, int length) - : index(index), length(length), viewport(v) -{ - LOAD_ONCE { - landTexture = new Texture("images/landingpad.png"); - noLandTexture = new Texture("images/landingpadred.png"); - } - + : index(index), length(length), viewport(v), + landTexture_(LoadTexture("images/landingpad.png")), + noLandTexture_(LoadTexture("images/landingpadred.png")) +{ quad.x = index * Surface::SURFACE_SIZE; quad.width = length * Surface::SURFACE_SIZE; quad.height = 16; - quad.uTexture = landTexture->GetGLTexture(); + quad.uTexture = landTexture_->GetGLTexture(); } // @@ -45,7 +38,7 @@ LandingPad::LandingPad(Viewport* v, int index, int length) // void LandingPad::Draw(bool locked) { - quad.uTexture = (locked ? noLandTexture : landTexture)->GetGLTexture(); + quad.uTexture = (locked ? noLandTexture_ : landTexture_)->GetGLTexture(); quad.x = index * Surface::SURFACE_SIZE - viewport->GetXAdjust(); quad.y = viewport->GetLevelHeight() - viewport->GetYAdjust() - Surface::MAX_SURFACE_HEIGHT + ypos; diff --git a/src/LandingPad.hpp b/src/LandingPad.hpp index b5819c7..038224a 100644 --- a/src/LandingPad.hpp +++ b/src/LandingPad.hpp @@ -40,7 +40,8 @@ private: int index, length, ypos; Viewport* viewport; - static Texture* landTexture, *noLandTexture; + Texture* landTexture_; + Texture* noLandTexture_; }; typedef vector LandingPadList; -- 2.39.2