Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/collisionmodel.h')
-rw-r--r--src/model/collisionmodel.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/model/collisionmodel.h b/src/model/collisionmodel.h
new file mode 100644
index 0000000..04268d2
--- /dev/null
+++ b/src/model/collisionmodel.h
@@ -0,0 +1,111 @@
+/*
+ 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
+ * CollisionModel does not take ownership of the COllisionMesh,
+ * the mesh should be registered with the CollisionMesh::registry
+ * */
+ 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__