TDME2 1.9.121
MeshManager.cpp
Go to the documentation of this file.
2
3#include <string>
4#include <unordered_map>
5
6#include <tdme/tdme.h>
10
11using std::string;
12using std::unordered_map;
13
18
19MeshManager::MeshManager()
20{
21}
22
24 for (auto it = meshes.begin(); it != meshes.end(); ++it) {
25 delete it->second;
26 }
27}
28
30{
31 // check if we already manage this mesh
32 auto meshManagedIt = meshes.find(meshId);
33 if (meshManagedIt != meshes.end()) {
34 auto meshManaged = meshManagedIt->second;
35 meshManaged->incrementReferenceCounter();
36 return meshManaged->getMesh();
37 }
38 // otherwise no mesh
39 return nullptr;
40}
41
42void MeshManager::addMesh(const string& meshId, Object3DNodeMesh* mesh)
43{
44 // create managed texture
45 auto meshManaged = new MeshManager_MeshManaged(meshId, mesh);
46 meshManaged->incrementReferenceCounter();
47 // add it to our textures
48 meshes[meshManaged->getId()] = meshManaged;
49}
50
51void MeshManager::removeMesh(const string& meshId)
52{
53 auto meshManagedIt = meshes.find(meshId);
54 if (meshManagedIt != meshes.end()) {
55 auto meshManaged = meshManagedIt->second;
56 if (meshManaged->decrementReferenceCounter()) {
57 // remove from our list
58 meshes.erase(meshManagedIt);
59 delete meshManaged;
60 }
61 return;
62 }
63 Console::println(string("Warning: mesh not managed by mesh manager: " + meshId));
64}
unordered_map< string, MeshManager_MeshManaged * > meshes
Definition: MeshManager.h:25
void removeMesh(const string &meshId)
Removes a mesh from manager.
Definition: MeshManager.cpp:51
Object3DNodeMesh * getMesh(const string &meshId)
Get mesh from managed meshes.
Definition: MeshManager.cpp:29
void addMesh(const string &meshId, Object3DNodeMesh *mesh)
Adds a mesh to manager.
Definition: MeshManager.cpp:42
Object 3D node mesh specifically for rendering.
Console class.
Definition: Console.h:26