rename class to be more correct

This commit is contained in:
Andrew Meadows 2016-07-13 15:17:50 -07:00
parent 9f26836b43
commit 8d3f592e68
2 changed files with 28 additions and 30 deletions

View file

@ -1,5 +1,5 @@
// //
// CollisionGeometryCache.cpp // CollisionRenderMeshCache.cpp
// libraries/physcis/src // libraries/physcis/src
// //
// Created by Andrew Meadows 2016.07.13 // Created by Andrew Meadows 2016.07.13
@ -13,32 +13,32 @@
//#include <glm/gtx/norm.hpp> //#include <glm/gtx/norm.hpp>
//#include "ShapeFactory.h" //#include "ShapeFactory.h"
#include "CollisionGeometryCache.h" #include "CollisionRenderMeshCache.h"
int foo = 0; int foo = 0;
GeometryPointer createGeometryFromShape(CollisionGeometryCache::Key key) { MeshPointer createMeshFromShape(CollisionRenderMeshCache::Key key) {
return std::make_shared<int>(++foo); return std::make_shared<int>(++foo);
} }
CollisionGeometryCache::CollisionGeometryCache() { CollisionRenderMeshCache::CollisionRenderMeshCache() {
} }
CollisionGeometryCache::~CollisionGeometryCache() { CollisionRenderMeshCache::~CollisionRenderMeshCache() {
_geometryMap.clear(); _geometryMap.clear();
_pendingGarbage.clear(); _pendingGarbage.clear();
} }
GeometryPointer CollisionGeometryCache::getGeometry(CollisionGeometryCache::Key key) { MeshPointer CollisionRenderMeshCache::getMesh(CollisionRenderMeshCache::Key key) {
if (!key) { if (!key) {
return GeometryPointer(); return MeshPointer();
} }
GeometryPointer geometry = 0; MeshPointer geometry = 0;
CollisionGeometryMap::const_iterator itr = _geometryMap.find(key); CollisionMeshMap::const_iterator itr = _geometryMap.find(key);
if (itr != _geometryMap.end()) { if (itr != _geometryMap.end()) {
// make geometry and add it to map // make geometry and add it to map
geometry = createGeometryFromShape(key); geometry = createMeshFromShape(key);
if (geometry) { if (geometry) {
_geometryMap.insert(std::make_pair(key, geometry)); _geometryMap.insert(std::make_pair(key, geometry));
} }
@ -46,11 +46,11 @@ GeometryPointer CollisionGeometryCache::getGeometry(CollisionGeometryCache::Key
return geometry; return geometry;
} }
bool CollisionGeometryCache::releaseGeometry(CollisionGeometryCache::Key key) { bool CollisionRenderMeshCache::releaseMesh(CollisionRenderMeshCache::Key key) {
if (!key) { if (!key) {
return false; return false;
} }
CollisionGeometryMap::const_iterator itr = _geometryMap.find(key); CollisionMeshMap::const_iterator itr = _geometryMap.find(key);
if (itr != _geometryMap.end()) { if (itr != _geometryMap.end()) {
assert((*itr).second.use_count() != 1); assert((*itr).second.use_count() != 1);
if ((*itr).second.use_count() == 2) { if ((*itr).second.use_count() == 2) {
@ -62,11 +62,11 @@ bool CollisionGeometryCache::releaseGeometry(CollisionGeometryCache::Key key) {
return false; return false;
} }
void CollisionGeometryCache::collectGarbage() { void CollisionRenderMeshCache::collectGarbage() {
int numShapes = _pendingGarbage.size(); int numShapes = _pendingGarbage.size();
for (int i = 0; i < numShapes; ++i) { for (int i = 0; i < numShapes; ++i) {
CollisionGeometryCache::Key key = _pendingGarbage[i]; CollisionRenderMeshCache::Key key = _pendingGarbage[i];
CollisionGeometryMap::const_iterator itr = _geometryMap.find(key); CollisionMeshMap::const_iterator itr = _geometryMap.find(key);
if (itr != _geometryMap.end()) { if (itr != _geometryMap.end()) {
if ((*itr).second.use_count() == 1) { if ((*itr).second.use_count() == 1) {
// we hold the only reference // we hold the only reference

View file

@ -1,5 +1,5 @@
// //
// CollisionGeometryCache.h // CollisionRenderMeshCache.h
// libraries/physcis/src // libraries/physcis/src
// //
// Created by Andrew Meadows 2016.07.13 // Created by Andrew Meadows 2016.07.13
@ -9,19 +9,17 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_CollisionGeometryCache #ifndef hifi_CollisionRenderMeshCache_h
#define hifi_CollisionGeometryCache #define hifi_CollisionRenderMeshCache_h
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>
//#include <btBulletDynamicsCommon.h>
//#include <LinearMath/btHashMap.h>
class btCollisionShape; class btCollisionShape;
// BEGIN TEST HACK // BEGIN TEST HACK
using GeometryPointer = std::shared_ptr<int>; using MeshPointer = std::shared_ptr<int>;
// END TEST HACK // END TEST HACK
namespace std { namespace std {
@ -33,30 +31,30 @@ namespace std {
}; };
} }
class CollisionGeometryCache { class CollisionRenderMeshCache {
public: public:
using Key = btCollisionShape const *; using Key = btCollisionShape const *;
CollisionGeometryCache(); CollisionRenderMeshCache();
~CollisionGeometryCache(); ~CollisionRenderMeshCache();
/// \return pointer to geometry /// \return pointer to geometry
GeometryPointer getGeometry(Key key); MeshPointer getMesh(Key key);
/// \return true if geometry was found and released /// \return true if geometry was found and released
bool releaseGeometry(Key key); bool releaseMesh(Key key);
/// delete geometries that have zero references /// delete geometries that have zero references
void collectGarbage(); void collectGarbage();
// validation methods // validation methods
uint32_t getNumGeometries() const { return (uint32_t)_geometryMap.size(); } uint32_t getNumGeometries() const { return (uint32_t)_geometryMap.size(); }
bool hasGeometry(Key key) const { return _geometryMap.find(key) == _geometryMap.end(); } bool hasMesh(Key key) const { return _geometryMap.find(key) == _geometryMap.end(); }
private: private:
using CollisionGeometryMap = std::unordered_map<Key, GeometryPointer>; using CollisionMeshMap = std::unordered_map<Key, MeshPointer>;
CollisionGeometryMap _geometryMap; CollisionMeshMap _geometryMap;
std::vector<Key> _pendingGarbage; std::vector<Key> _pendingGarbage;
}; };
#endif // hifi_CollisionGeometryCache #endif // hifi_CollisionRenderMeshCache_h