/* 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 #include #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 Registry; /** * @brief type definition for a lost of collision meshes * */ typedef std::list 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__