Antkeeper  0.0.1
collection.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_SCENE_COLLECTION_HPP
21 #define ANTKEEPER_SCENE_COLLECTION_HPP
22 
23 #include <engine/scene/object.hpp>
24 #include <vector>
25 #include <unordered_map>
26 
27 namespace scene {
28 
33 {
34 public:
37 
43  void add_object(object_base& object);
44 
50  void remove_object(const object_base& object);
51 
53  void remove_objects();
54 
56  [[nodiscard]] inline const std::vector<object_base*>& get_objects() const noexcept
57  {
58  return m_objects;
59  }
60 
68  [[nodiscard]] inline const std::vector<object_base*>& get_objects(std::size_t type_id) const
69  {
70  return m_object_map[type_id];
71  }
72 
76 
82  inline void set_scale(float scale) noexcept
83  {
84  m_scale = scale;
85  }
86 
88  [[nodiscard]] inline float get_scale() const noexcept
89  {
90  return m_scale;
91  }
92 
94 
95 private:
96  std::vector<object_base*> m_objects;
97  mutable std::unordered_map<std::size_t, std::vector<object_base*>> m_object_map;
98  float m_scale{1.0f};
99 };
100 
101 } // namespace scene
102 
103 #endif // ANTKEEPER_SCENE_COLLECTION_HPP
Collection of scene objects.
Definition: collection.hpp:33
void add_object(object_base &object)
Adds an object to the collection.
Definition: collection.cpp:24
void remove_object(const object_base &object)
Removes an object from the collection.
Definition: collection.cpp:30
const std::vector< object_base * > & get_objects(std::size_t type_id) const
Returns all objects in the collection with the given type ID.
Definition: collection.hpp:68
float get_scale() const noexcept
Returns the ratio of meters to scene units.
Definition: collection.hpp:88
void remove_objects()
Removes all objects from the collection.
Definition: collection.cpp:36
void set_scale(float scale) noexcept
Sets the scale of the scene.
Definition: collection.hpp:82
const std::vector< object_base * > & get_objects() const noexcept
Returns all objects in the collection.
Definition: collection.hpp:56
Abstract base class for scene objects.
Definition: object.hpp:37
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
3D scene.
Definition: context.hpp:28