remove stubbery, make physics lib depend on model

This commit is contained in:
Andrew Meadows 2016-07-13 16:32:22 -07:00
parent 8d3f592e68
commit d59c997e64
4 changed files with 36 additions and 25 deletions

View file

@ -130,7 +130,7 @@ protected:
void evalVertexStream(); void evalVertexStream();
}; };
typedef std::shared_ptr< Mesh > MeshPointer; using MeshPointer = std::shared_ptr< Mesh >;
class Geometry { class Geometry {

View file

@ -1,5 +1,5 @@
set(TARGET_NAME physics) set(TARGET_NAME physics)
setup_hifi_library() setup_hifi_library()
link_hifi_libraries(shared fbx entities) link_hifi_libraries(shared fbx entities model)
target_bullet() target_bullet()

View file

@ -9,16 +9,31 @@
// 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
// //
#include "CollisionRenderMeshCache.h"
#include <cassert> #include <cassert>
//#include <glm/gtx/norm.hpp> //#include <glm/gtx/norm.hpp>
//#include "ShapeFactory.h" //#include "ShapeFactory.h"
#include "CollisionRenderMeshCache.h" #include <btBulletDynamicsCommon.h>
int foo = 0;
MeshPointer createMeshFromShape(CollisionRenderMeshCache::Key key) { model::MeshPointer createMeshFromShape(const btCollisionShape* shape) {
return std::make_shared<int>(++foo); if (!shape) {
return std::make_shared<model::Mesh>();
}
int32_t shapeType = shape->getShapeType();
if (shapeType == (int32_t)COMPOUND_SHAPE_PROXYTYPE) {
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
int32_t numSubShapes = compoundShape->getNumChildShapes();
for (int i = 0; i < numSubShapes; ++i) {
const btCollisionShape* childShape = compoundShape->getChildShape(i);
std::cout << "adebug " << i << " " << (void*)(childShape) << std::endl; // adebug
}
} else if (shape->isConvex()) {
std::cout << "adebug " << (void*)(shape)<< std::endl; // adebug
}
return std::make_shared<model::Mesh>();
} }
CollisionRenderMeshCache::CollisionRenderMeshCache() { CollisionRenderMeshCache::CollisionRenderMeshCache() {
@ -29,21 +44,19 @@ CollisionRenderMeshCache::~CollisionRenderMeshCache() {
_pendingGarbage.clear(); _pendingGarbage.clear();
} }
MeshPointer CollisionRenderMeshCache::getMesh(CollisionRenderMeshCache::Key key) { model::MeshPointer CollisionRenderMeshCache::getMesh(CollisionRenderMeshCache::Key key) {
if (!key) { model::MeshPointer mesh;
return MeshPointer(); if (key) {
} CollisionMeshMap::const_iterator itr = _geometryMap.find(key);
MeshPointer geometry = 0; if (itr != _geometryMap.end()) {
// make mesh and add it to map
CollisionMeshMap::const_iterator itr = _geometryMap.find(key); mesh = createMeshFromShape(key);
if (itr != _geometryMap.end()) { if (mesh) {
// make geometry and add it to map _geometryMap.insert(std::make_pair(key, mesh));
geometry = createMeshFromShape(key); }
if (geometry) {
_geometryMap.insert(std::make_pair(key, geometry));
} }
} }
return geometry; return mesh;
} }
bool CollisionRenderMeshCache::releaseMesh(CollisionRenderMeshCache::Key key) { bool CollisionRenderMeshCache::releaseMesh(CollisionRenderMeshCache::Key key) {

View file

@ -16,11 +16,9 @@
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>
class btCollisionShape; #include <model/Geometry.h>
// BEGIN TEST HACK class btCollisionShape;
using MeshPointer = std::shared_ptr<int>;
// END TEST HACK
namespace std { namespace std {
template <> template <>
@ -39,7 +37,7 @@ public:
~CollisionRenderMeshCache(); ~CollisionRenderMeshCache();
/// \return pointer to geometry /// \return pointer to geometry
MeshPointer getMesh(Key key); model::MeshPointer getMesh(Key key);
/// \return true if geometry was found and released /// \return true if geometry was found and released
bool releaseMesh(Key key); bool releaseMesh(Key key);
@ -52,7 +50,7 @@ public:
bool hasMesh(Key key) const { return _geometryMap.find(key) == _geometryMap.end(); } bool hasMesh(Key key) const { return _geometryMap.find(key) == _geometryMap.end(); }
private: private:
using CollisionMeshMap = std::unordered_map<Key, MeshPointer>; using CollisionMeshMap = std::unordered_map<Key, model::MeshPointer>;
CollisionMeshMap _geometryMap; CollisionMeshMap _geometryMap;
std::vector<Key> _pendingGarbage; std::vector<Key> _pendingGarbage;
}; };