TDME2  1.9.200
SceneLibrary.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 #include <memory>
5 #include <string>
6 
7 #include <tdme/tdme.h>
17 #include <tdme/math/Vector3.h>
18 #include <tdme/utilities/Console.h>
22 
23 using std::make_unique;
24 using std::remove;
25 using std::string;
26 using std::to_string;
27 using std::unique_ptr;
28 
30 
44 
45 SceneLibrary::SceneLibrary(Scene* scene)
46 {
47  this->scene = scene;
48  this->prototypeIdx = 0;
49 }
50 
52 }
53 
55 {
56  this->prototypesById.clear();
57  this->prototypes.clear();
58  this->prototypeIdx = 0;
59 }
60 
62 {
63  if (prototype->getId() == SceneLibrary::ID_ALLOCATE) prototype->setId(allocatePrototypeId());
64  auto prototypeByIdIt = prototypesById.find(prototype->getId());
65  if (prototypeByIdIt != prototypesById.end()) {
66  throw ExceptionBase("Prototype id already in use");
67  }
68  prototypes.push_back(unique_ptr<Prototype>(prototype));
69  prototypesById[prototype->getId()] = prototype;
70  if (prototype->getId() >= prototypeIdx)
71  prototypeIdx = prototype->getId() + 1;
72 
73 }
74 
76 {
77  auto prototypeByIdIt = prototypesById.find(id);
78  if (prototypeByIdIt != prototypesById.end()) {
79  auto prototype = prototypeByIdIt->second;
80  for (auto i = 0; i < prototypes.size(); i++) {
81  if (prototypes[i].get() == prototype) {
82  prototypes.erase(prototypes.begin() + i);
83  break;
84  }
85  }
86  prototypesById.erase(prototypeByIdIt);
87  }
88 }
Representation of a 3D model.
Definition: Model.h:35
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Prototype definition.
Definition: Prototype.h:55
void setId(int id)
Set Id.
Definition: Prototype.h:96
Scene prototype library definition.
Definition: SceneLibrary.h:32
vector< unique_ptr< Prototype > > prototypes
Definition: SceneLibrary.h:39
void removePrototype(int id)
Remove a prototype.
int allocatePrototypeId()
Allocata a unique prototype index.
Definition: SceneLibrary.h:61
unordered_map< int, Prototype * > prototypesById
Definition: SceneLibrary.h:38
void clear()
Clears this scene prototype library.
void addPrototype(Prototype *prototype)
Add a prototype.
static constexpr int ID_ALLOCATE
Definition: SceneLibrary.h:34
Scene definition.
Definition: Scene.h:50
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Console class.
Definition: Console.h:29
Exception base class.
Definition: ExceptionBase.h:19
Helper class to create models from physics primitive bounding volumes.
Definition: Primitives.h:33
String tools class.
Definition: StringTools.h:22