node uses shared ptr to store sdl texture

This commit is contained in:
frank 2021-06-29 17:15:47 -04:00
parent 95a1e6b5b1
commit 17adaed169
4 changed files with 10 additions and 9 deletions

View File

@ -260,8 +260,7 @@ void Game::load_sdl_context()
SDL_GetRenderDriverInfo(ii, &renderer_info);
log_renderer_info(renderer_info);
}
if ((renderer = SDL_CreateRenderer(
window, -1, SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_ACCELERATED)) == nullptr)
if ((renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_ACCELERATED)) == nullptr)
{
print_sdl_error("Could not create renderer");
flag_to_end();

View File

@ -21,12 +21,12 @@ void Node::set_parent(Node* other)
void Node::set_canvas(SDL_Texture* texture)
{
canvas = texture;
canvas = std::shared_ptr<SDL_Texture>(texture, SDL_DestroyTexture);
}
SDL_Texture* Node::get_canvas()
{
return canvas;
return canvas.get();
}
bool Node::is_active() const

View File

@ -22,10 +22,6 @@ class Node
public:
Node *parent;
SDL_Texture* canvas = nullptr;
bool active = true;
Node();
Node(Node*);
void set_parent(Node*);
@ -70,6 +66,12 @@ public:
}
}
private:
Node* parent;
std::shared_ptr<SDL_Texture> canvas;
bool active = true;
};
#endif

View File

@ -838,7 +838,7 @@ void Sprite::set_draw_children_on_frame(bool on_frame)
void Sprite::update(const std::vector<Box>& subsections)
{
if (active)
if (is_active())
{
if (step != glm::vec2(0, 0))
{