Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: ecb8047919678e29821c54f8493ad5c99b9c9440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
   model/collisionmodel.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_MODEL_COLLISIONMODEL_H__
#define __INCLUDED_MODEL_COLLISIONMODEL_H__

#include <list>
#include <string>

#include "math/mathlib.h"
#include "model/collisionmesh.h"

namespace model
{

/**
 * @brief a container class for collision geometry
 * The CollisionModel class holds a list of references to one or more CollisionMeshes.
 * It is referenced by a single Model, and the static registry takes ownership of the 
 * CollisionModel instances. This is because a Model can be reloaded while the game is running,
 * but the CollisionMeshes are tied to bullet physics and can not be reloaded on the fly.
 * Note that the CollisionModel doesn't own its meshes either, it merely reference them.
 * CollisionMeshes are stored in the static CollisionMesh::registry() and can be referenced
 * by multiple CollisionModels.
 */
class CollisionModel
{
public:
	/**
	 * @brief type definition for the CollisionModel registry
	 * */
	typedef std::list<CollisionModel *>	Registry;
	
	/**
	 * @brief type definition for a lost of collision meshes
	 * */
	typedef std::list<CollisionMesh *>	CollisionMeshes;	
	
	/**
	 * @brief create a new collisionmodel with a give label
	 * */
	CollisionModel(const std::string  & label);
	~CollisionModel();
	
	inline const std::string &label() const {
		return collisionmodel_label;
	}
	
	/**
	 * @brief returns the number of meshes this collision model consists of
	 * */ 
	inline const size_t size() const {
		return collisionmodel_meshes.size();
	}
	
	/**
	 * @brief the collection of meshes this model consists of
	 * */
	inline CollisionMeshes & meshes() {
		return collisionmodel_meshes;
	}
	
	/**
	 * @brief add a mesh to the CollisionModel
	 * */
	void add_mesh(CollisionMesh *mesh);
	
	/**
	 * @brief initialize the CollisionModel registry
	 * init() calls clear()
	 * */
	static void init();

	/**
	 * @brief shutdown the CollisionModel registry
	 * shutdown() calls clear()
	 * */
	static void shutdown();
	
	/**
	 * @brief clear the CollisionModel registry and delete all CollisionModel instances it holds
	 * */
	static void clear();
	
	/**
	 * @brief add a CollisionModel to the registry
	 * the models label should be unique and not yet exist in the registry.
	 * */
	static void add(CollisionModel *collisionmodel);
	
	/**
	 * @brief search the registry for a model with a particular label, returns 0 if not found.
	 * */
	static CollisionModel *find(const std::string & label);
	
private:
	std::string		collisionmodel_label;
	CollisionMeshes		collisionmodel_meshes;
	
	static Registry		collisionmodel_registry;
	
}; // class CollisionModel

} // namespace model

#endif // __INCLUDED_MODEL_COLLISIONMODEL_H__