commit c310f8a5
Moved the text manager to global data
Changed files
| M | source/code/BlockGameSdl.inc before |
| M | source/code/TextManager.hpp before |
| M | source/code/global.hpp before |
| M | source/code/main.cpp before |
diff --git a/source/code/BlockGameSdl.inc b/source/code/BlockGameSdl.inc
index 194e238..40c4898 100644
--- a/source/code/BlockGameSdl.inc
+++ b/source/code/BlockGameSdl.inc
@@ -22,6 +22,7 @@ http://www.blockattack.net
*/
#include "BlockGame.hpp"
+#include "global.hpp"
class BlockGameSdl : public BlockGame {
@@ -93,7 +94,7 @@ public:
}
void AddText(int x, int y, const std::string& text, int time) const override {
- theTextManager.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time);
+ globalData.theTextManager.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time);
}
void AddBall(int x, int y, bool right, int color) const override {
diff --git a/source/code/TextManager.hpp b/source/code/TextManager.hpp
index 1e61afa..7e34fa8 100644
--- a/source/code/TextManager.hpp
+++ b/source/code/TextManager.hpp
@@ -24,12 +24,13 @@ http://www.blockattack.net
#ifndef TEXTMANAGER_HPP
#define TEXTMANAGER_HPP
+#include <string>
class TextMessage {
private:
int x = 0;
int y = 0;
- string textt;
+ std::string textt;
unsigned long int time = 0;
unsigned long int placeTime = 0; //Then the text was placed
public:
@@ -39,7 +40,7 @@ public:
//constructor:
TextMessage(int X, int Y,const char* Text,unsigned int Time) {
- placeTime = currentTime;
+ placeTime = SDL_GetTicks();
x = X;
y = Y;
textt = Text;
@@ -48,7 +49,7 @@ public:
//true if the text has expired
bool removeMe() {
- return currentTime-placeTime>time;
+ return SDL_GetTicks()-placeTime>time;
}
int getX() {
@@ -65,8 +66,8 @@ public:
}; //text popup
class TextManager {
- static const int maxNumberOfTexts = 6*12*2*2;
public:
+ static const int maxNumberOfTexts = 6*12*2*2;
TextMessage textArray[maxNumberOfTexts];
bool textUsed[maxNumberOfTexts];
@@ -76,7 +77,7 @@ public:
}
}
- int addText(int x, int y,string Text,unsigned int Time) {
+ int addText(int x, int y, const std::string& Text,unsigned int Time) {
int textNumber = 0;
while (textNumber<maxNumberOfTexts && textUsed[textNumber]) {
textNumber++;
@@ -84,14 +85,12 @@ public:
if (textNumber==maxNumberOfTexts) {
return -1;
}
- currentTime = SDL_GetTicks();
textArray[textNumber] = TextMessage(x,y,Text.c_str(),Time);
textUsed[textNumber] = true;
return 1;
} //addText
void update() {
- currentTime = SDL_GetTicks();
for (int i = 0; i<maxNumberOfTexts; i++) {
if (textUsed[i]) {
diff --git a/source/code/global.hpp b/source/code/global.hpp
index 50d54c1..9b44be0 100644
--- a/source/code/global.hpp
+++ b/source/code/global.hpp
@@ -29,6 +29,7 @@ http://www.blockattack.net
#include "sago/SagoSpriteHolder.hpp"
#include "highscore.h"
#include "sago/GameStateInterface.hpp"
+#include "TextManager.hpp"
void MainMenu();
void ResetFullscreen();
@@ -69,6 +70,8 @@ struct GlobalData {
Highscore theTopScoresEndless; //Stores highscores for endless
Highscore theTopScoresTimeTrial; //Stores highscores for timetrial
std::unique_ptr<sago::SagoSpriteHolder> spriteHolder;
+
+ TextManager theTextManager;
//The xsize and ysize are updated everytime the background is drawn
int xsize = 1024;
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 6700dd5..a957dbc 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -493,9 +493,6 @@ public:
static ExplosionManager theExplosionManager;
-#include "TextManager.hpp"
-
-static TextManager theTextManager;
//Here comes the Block Game object
#include "BlockGame.hpp"
@@ -593,14 +590,16 @@ static void DrawBalls() {
if (theExplosionManager.explosionUsed[i]) {
DrawIMG(explosion[theExplosionManager.explosionArray[i].getFrame()],globalData.screen,theExplosionManager.explosionArray[i].getX(),theExplosionManager.explosionArray[i].getY());
}
- if (theTextManager.textUsed[i]) {
- int x = theTextManager.textArray[i].getX()-12;
- int y = theTextManager.textArray[i].getY()-12;
+ } //for
+ for (int i = 0; i < globalData.theTextManager.maxNumberOfTexts; ++i) {
+ if (globalData.theTextManager.textUsed[i]) {
+ int x = globalData.theTextManager.textArray[i].getX()-12;
+ int y = globalData.theTextManager.textArray[i].getY()-12;
DrawIMG(iChainFrame,globalData.screen,x,y);
- nf_standard_small_font.draw(globalData.screen, x+12,y+7, NFont::CENTER, "%s",theTextManager.textArray[i].getText());
+ nf_standard_small_font.draw(globalData.screen, x+12,y+7, NFont::CENTER, "%s", globalData.theTextManager.textArray[i].getText());
}
- } //for
+ }
} //DrawBalls
@@ -1090,7 +1089,7 @@ int main(int argc, char* argv[]) {
InitGameControllers();
TTF_Init();
atexit(SDL_Quit); //quits SDL when the game stops for some reason (like you hit exit or Esc)
- theTextManager = TextManager();
+ globalData.theTextManager = TextManager();
//Open Audio
if (!globalData.NoSound) {
@@ -1435,7 +1434,7 @@ int runGame(Gametype gametype, int level) {
//updates the balls and explosions:g
theBallManager.update();
theExplosionManager.update();
- theTextManager.update();
+ globalData.theTextManager.update();
bool mustWriteScreenshot = false;