node uses shared ptr to store sdl texture
This commit is contained in:
parent
95a1e6b5b1
commit
17adaed169
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
10
src/Node.hpp
10
src/Node.hpp
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue