mirror of
https://github.com/overte-org/overte.git
synced 2025-04-09 02:33:19 +02:00
rename class to be more correct
This commit is contained in:
parent
9f26836b43
commit
8d3f592e68
2 changed files with 28 additions and 30 deletions
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// CollisionGeometryCache.cpp
|
||||
// CollisionRenderMeshCache.cpp
|
||||
// libraries/physcis/src
|
||||
//
|
||||
// Created by Andrew Meadows 2016.07.13
|
||||
|
@ -13,32 +13,32 @@
|
|||
//#include <glm/gtx/norm.hpp>
|
||||
|
||||
//#include "ShapeFactory.h"
|
||||
#include "CollisionGeometryCache.h"
|
||||
#include "CollisionRenderMeshCache.h"
|
||||
|
||||
int foo = 0;
|
||||
|
||||
GeometryPointer createGeometryFromShape(CollisionGeometryCache::Key key) {
|
||||
MeshPointer createMeshFromShape(CollisionRenderMeshCache::Key key) {
|
||||
return std::make_shared<int>(++foo);
|
||||
}
|
||||
|
||||
CollisionGeometryCache::CollisionGeometryCache() {
|
||||
CollisionRenderMeshCache::CollisionRenderMeshCache() {
|
||||
}
|
||||
|
||||
CollisionGeometryCache::~CollisionGeometryCache() {
|
||||
CollisionRenderMeshCache::~CollisionRenderMeshCache() {
|
||||
_geometryMap.clear();
|
||||
_pendingGarbage.clear();
|
||||
}
|
||||
|
||||
GeometryPointer CollisionGeometryCache::getGeometry(CollisionGeometryCache::Key key) {
|
||||
MeshPointer CollisionRenderMeshCache::getMesh(CollisionRenderMeshCache::Key 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()) {
|
||||
// make geometry and add it to map
|
||||
geometry = createGeometryFromShape(key);
|
||||
geometry = createMeshFromShape(key);
|
||||
if (geometry) {
|
||||
_geometryMap.insert(std::make_pair(key, geometry));
|
||||
}
|
||||
|
@ -46,11 +46,11 @@ GeometryPointer CollisionGeometryCache::getGeometry(CollisionGeometryCache::Key
|
|||
return geometry;
|
||||
}
|
||||
|
||||
bool CollisionGeometryCache::releaseGeometry(CollisionGeometryCache::Key key) {
|
||||
bool CollisionRenderMeshCache::releaseMesh(CollisionRenderMeshCache::Key key) {
|
||||
if (!key) {
|
||||
return false;
|
||||
}
|
||||
CollisionGeometryMap::const_iterator itr = _geometryMap.find(key);
|
||||
CollisionMeshMap::const_iterator itr = _geometryMap.find(key);
|
||||
if (itr != _geometryMap.end()) {
|
||||
assert((*itr).second.use_count() != 1);
|
||||
if ((*itr).second.use_count() == 2) {
|
||||
|
@ -62,11 +62,11 @@ bool CollisionGeometryCache::releaseGeometry(CollisionGeometryCache::Key key) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void CollisionGeometryCache::collectGarbage() {
|
||||
void CollisionRenderMeshCache::collectGarbage() {
|
||||
int numShapes = _pendingGarbage.size();
|
||||
for (int i = 0; i < numShapes; ++i) {
|
||||
CollisionGeometryCache::Key key = _pendingGarbage[i];
|
||||
CollisionGeometryMap::const_iterator itr = _geometryMap.find(key);
|
||||
CollisionRenderMeshCache::Key key = _pendingGarbage[i];
|
||||
CollisionMeshMap::const_iterator itr = _geometryMap.find(key);
|
||||
if (itr != _geometryMap.end()) {
|
||||
if ((*itr).second.use_count() == 1) {
|
||||
// we hold the only reference
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// CollisionGeometryCache.h
|
||||
// CollisionRenderMeshCache.h
|
||||
// libraries/physcis/src
|
||||
//
|
||||
// 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
|
||||
//
|
||||
|
||||
#ifndef hifi_CollisionGeometryCache
|
||||
#define hifi_CollisionGeometryCache
|
||||
#ifndef hifi_CollisionRenderMeshCache_h
|
||||
#define hifi_CollisionRenderMeshCache_h
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
//#include <btBulletDynamicsCommon.h>
|
||||
//#include <LinearMath/btHashMap.h>
|
||||
|
||||
class btCollisionShape;
|
||||
|
||||
// BEGIN TEST HACK
|
||||
using GeometryPointer = std::shared_ptr<int>;
|
||||
using MeshPointer = std::shared_ptr<int>;
|
||||
// END TEST HACK
|
||||
|
||||
namespace std {
|
||||
|
@ -33,30 +31,30 @@ namespace std {
|
|||
};
|
||||
}
|
||||
|
||||
class CollisionGeometryCache {
|
||||
class CollisionRenderMeshCache {
|
||||
public:
|
||||
using Key = btCollisionShape const *;
|
||||
|
||||
CollisionGeometryCache();
|
||||
~CollisionGeometryCache();
|
||||
CollisionRenderMeshCache();
|
||||
~CollisionRenderMeshCache();
|
||||
|
||||
/// \return pointer to geometry
|
||||
GeometryPointer getGeometry(Key key);
|
||||
MeshPointer getMesh(Key key);
|
||||
|
||||
/// \return true if geometry was found and released
|
||||
bool releaseGeometry(Key key);
|
||||
bool releaseMesh(Key key);
|
||||
|
||||
/// delete geometries that have zero references
|
||||
void collectGarbage();
|
||||
|
||||
// validation methods
|
||||
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:
|
||||
using CollisionGeometryMap = std::unordered_map<Key, GeometryPointer>;
|
||||
CollisionGeometryMap _geometryMap;
|
||||
using CollisionMeshMap = std::unordered_map<Key, MeshPointer>;
|
||||
CollisionMeshMap _geometryMap;
|
||||
std::vector<Key> _pendingGarbage;
|
||||
};
|
||||
|
||||
#endif // hifi_CollisionGeometryCache
|
||||
#endif // hifi_CollisionRenderMeshCache_h
|
Loading…
Reference in a new issue