Wizard Engine
2D cross-platform game engine built around SDL2
 
Loading...
Searching...
No Matches
renderable.cpp
1/*
2 Wizard Engine
3 Copyright (C) 2023-2024 Zana Domán
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
23#define __WIZARD_ENGINE_INTERNAL__
24
26
27std::vector<wze::renderable*> wze::renderable::_instances = {};
28
29std::vector<wze::renderable*> const& wze::renderable::instances() {
30 return _instances;
31}
32
33SDL_FRect const& wze::renderable::screen_area() const {
34 return _screen_area;
35}
36
37void wze::renderable::set_screen_area(SDL_FRect const& screen_area) {
38 _screen_area = screen_area;
39}
40
41float wze::renderable::screen_angle() const {
42 return _screen_angle;
43}
44
45void wze::renderable::set_screen_angle(float screen_angle) {
46 _screen_angle = screen_angle;
47}
48
49wze::renderable::renderable() {
50 set_screen_area({0, 0, 0, 0});
51 set_screen_angle(0);
52 _instances.push_back(this);
53}
54
55wze::renderable::renderable(renderable const& other) {
56 *this = other;
57 _instances.push_back(this);
58}
59
60wze::renderable::~renderable() {
61 _instances.erase(std::find(instances().begin(), instances().end(), this));
62}
63
64wze::renderable& wze::renderable::operator=(renderable const& other) {
65 if (&other != this) {
66 set_screen_area(other.screen_area());
67 set_screen_angle(other.screen_angle());
68 }
69
70 return *this;
71}
Interface to make an object renderable.