git repos / blockattack-game

commit 9f7a6344

sago007 · 2018-03-30 12:05
9f7a63446cd5adf228604f082600e6fb8fa6a4ea patch · browse files
parent 34f6ec6d46de24ba62b732ef7f365077fd73c954

Use shared pointers for the cache

Changed files

M source/code/MenuSystem.cpp before
M source/code/MenuSystem.h before
M source/code/main.cpp before
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 4ecd8e1..f2b17c2 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp
@@ -52,16 +52,16 @@ void ButtonGfx::setSurfaces() {
sago::SagoTextField* ButtonGfx::getLabel(const std::string& text) {
const auto& theLabel = labels.find(text);
if (theLabel != labels.end()) {
- return labels[text];
+ return labels[text].get();
}
- sago::SagoTextField* newField = new sago::SagoTextField();
+ std::shared_ptr<sago::SagoTextField> newField = std::make_shared<sago::SagoTextField>();
newField->SetHolder(&globalData.spriteHolder->GetDataHolder());
newField->SetFont("freeserif");
newField->SetFontSize(30);
newField->SetOutline(1, {0,0,0,255});
newField->SetText(text.c_str());
labels[text] = newField;
- return labels[text];
+ return labels[text].get();
}
Button::Button() {
diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 7e595d7..a394e11 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h
@@ -44,14 +44,8 @@ struct ButtonGfx
int ysize = 0;
sago::SagoTextField* getLabel(const std::string& text);
void setSurfaces();
- ~ButtonGfx() {
- for (auto& label : labels) {
- delete label.second;
- }
- labels.clear();
- }
private:
- std::map<std::string, sago::SagoTextField*> labels;
+ std::map<std::string, std::shared_ptr<sago::SagoTextField> > labels;
};
extern ButtonGfx standardButton;
diff --git a/source/code/main.cpp b/source/code/main.cpp index f0e1f62..b6b57b5 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -387,7 +387,6 @@ void OpenScoresDisplay() {
RunGameState(d);
}
-
//Draws the balls and explosions
static void DrawBalls() {
for (size_t i = 0; i< theBallManager.ballArray.size(); i++) {