Skip to content

Commit abec500

Browse files
committed
chore: Change GraphicsObjects to use smart pointers for transitions
Use smart pointers instead of raw pointers for the BaseTransition class. This removes a small amount of resource handling code in quit().
1 parent ae3b2f8 commit abec500

File tree

5 files changed

+7
-16
lines changed

5 files changed

+7
-16
lines changed

include/framework/GraphicsObjects.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Framework {
1919
std::vector<std::unique_ptr<Image>> image_ptrs;
2020
std::vector<Spritesheet> spritesheets;
2121
std::vector<Font> fonts;
22-
std::vector<BaseTransition*> transition_ptrs;
22+
std::vector<std::unique_ptr<BaseTransition>> transition_ptrs;
2323

2424
std::vector<Button::ButtonImages> button_image_groups;
2525
};

src/framework/BaseGame.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace Framework {
145145
graphics_objects.image_ptrs = std::vector<std::unique_ptr<Framework::Image>>(GRAPHICS_OBJECTS::IMAGES::TOTAL_IMAGES);
146146
graphics_objects.spritesheets = std::vector<Framework::Spritesheet>(GRAPHICS_OBJECTS::SPRITESHEETS::TOTAL_SPRITESHEETS);
147147
graphics_objects.fonts = std::vector<Framework::Font>(GRAPHICS_OBJECTS::FONTS::TOTAL_FONTS);
148-
graphics_objects.transition_ptrs = std::vector<Framework::BaseTransition*>(GRAPHICS_OBJECTS::TRANSITIONS::TOTAL_TRANSITIONS);
148+
graphics_objects.transition_ptrs = std::vector<std::unique_ptr<Framework::BaseTransition>>(GRAPHICS_OBJECTS::TRANSITIONS::TOTAL_TRANSITIONS);
149149
graphics_objects.button_image_groups = std::vector<Framework::Button::ButtonImages>(GRAPHICS_OBJECTS::BUTTON_IMAGE_GROUPS::TOTAL_BUTTON_IMAGE_GROUPS);
150150

151151
// Load game data
@@ -158,15 +158,6 @@ namespace Framework {
158158
// Clear game data
159159
clear_data();
160160

161-
// Clear graphics objects stuff
162-
163-
// Clear transitions
164-
for (Framework::BaseTransition* transition_ptr : graphics_objects.transition_ptrs) {
165-
if (!transition_ptr) continue;
166-
delete transition_ptr;
167-
}
168-
graphics_objects.transition_ptrs.clear();
169-
170161
// Destroy renderer and window
171162
SDL_DestroyRenderer(renderer);
172163
SDL_DestroyWindow(window);

src/game/Game.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void Game::load_data() {
6060

6161

6262
// Create transitions
63-
graphics_objects.transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION] = new Framework::FadeTransition(&graphics_objects.graphics, COLOURS::BLACK, TRANSITIONS::FADE_TIME);
63+
graphics_objects.transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION] = std::make_unique<Framework::FadeTransition>(&graphics_objects.graphics, COLOURS::BLACK, TRANSITIONS::FADE_TIME);
6464
}
6565

6666
void Game::clear_data() {

src/game/GameStages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
void GameStage::start() {
66
// Set transition
7-
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION]);
7+
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION].get());
88

99
// Start transition
1010
transition->open();
@@ -52,7 +52,7 @@ void PausedStage::start() {
5252
);
5353

5454
// Set transition
55-
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION]);
55+
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION].get());
5656
}
5757

5858
bool PausedStage::update(float dt) {

src/game/MenuStages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void IntroStage::start() {
88
intro_timer.stop();
99

1010
// Start transition
11-
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION]);
11+
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION].get());
1212
transition->open();
1313
}
1414

@@ -63,7 +63,7 @@ void TitleStage::start() {
6363
);
6464

6565
// Set transition
66-
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION]);
66+
set_transition(graphics_objects->transition_ptrs[GRAPHICS_OBJECTS::TRANSITIONS::FADE_TRANSITION].get());
6767

6868
// Start transition
6969
transition->open();

0 commit comments

Comments
 (0)