diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-07 18:25:37 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-01-07 18:26:38 -0300 |
commit | 2ab83e1abbf5ee6d00e16056a9e9394114026f28 (patch) | |
tree | 7efbb375cc4d00d8e8589fcf1b6a1303bec5df2d /core/math | |
parent | 2a38a5eaa844043b846e03d6655f84caf8a31e74 (diff) |
Memory pool vectors (DVector) have been enormously simplified in code, and renamed to PoolVector
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/a_star.cpp | 28 | ||||
-rw-r--r-- | core/math/a_star.h | 4 | ||||
-rw-r--r-- | core/math/bsp_tree.cpp | 14 | ||||
-rw-r--r-- | core/math/bsp_tree.h | 2 | ||||
-rw-r--r-- | core/math/geometry.cpp | 44 | ||||
-rw-r--r-- | core/math/geometry.h | 14 | ||||
-rw-r--r-- | core/math/triangle_mesh.cpp | 48 | ||||
-rw-r--r-- | core/math/triangle_mesh.h | 10 |
8 files changed, 82 insertions, 82 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 29f61834b4..0d6997183f 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -295,10 +295,10 @@ bool AStar::_solve(Point* begin_point, Point* end_point) { } -DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { +PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { - ERR_FAIL_COND_V(!points.has(p_from_id),DVector<Vector3>()); - ERR_FAIL_COND_V(!points.has(p_to_id),DVector<Vector3>()); + ERR_FAIL_COND_V(!points.has(p_from_id),PoolVector<Vector3>()); + ERR_FAIL_COND_V(!points.has(p_to_id),PoolVector<Vector3>()); pass++; @@ -307,7 +307,7 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { Point* b = points[p_to_id]; if (a==b) { - DVector<Vector3> ret; + PoolVector<Vector3> ret; ret.push_back(a->pos); return ret; } @@ -319,7 +319,7 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { bool found_route=_solve(begin_point,end_point); if (!found_route) - return DVector<Vector3>(); + return PoolVector<Vector3>(); //midpoints Point *p=end_point; @@ -329,11 +329,11 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { p=p->prev_point; } - DVector<Vector3> path; + PoolVector<Vector3> path; path.resize(pc); { - DVector<Vector3>::Write w = path.write(); + PoolVector<Vector3>::Write w = path.write(); Point *p=end_point; int idx=pc-1; @@ -351,10 +351,10 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) { } -DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) { +PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) { - ERR_FAIL_COND_V(!points.has(p_from_id),DVector<int>()); - ERR_FAIL_COND_V(!points.has(p_to_id),DVector<int>()); + ERR_FAIL_COND_V(!points.has(p_from_id),PoolVector<int>()); + ERR_FAIL_COND_V(!points.has(p_to_id),PoolVector<int>()); pass++; @@ -363,7 +363,7 @@ DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) { Point* b = points[p_to_id]; if (a==b) { - DVector<int> ret; + PoolVector<int> ret; ret.push_back(a->id); return ret; } @@ -375,7 +375,7 @@ DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) { bool found_route=_solve(begin_point,end_point); if (!found_route) - return DVector<int>(); + return PoolVector<int>(); //midpoints Point *p=end_point; @@ -385,11 +385,11 @@ DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) { p=p->prev_point; } - DVector<int> path; + PoolVector<int> path; path.resize(pc); { - DVector<int>::Write w = path.write(); + PoolVector<int>::Write w = path.write(); p=end_point; int idx=pc-1; diff --git a/core/math/a_star.h b/core/math/a_star.h index 66a983a6ce..35e6ead226 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -113,8 +113,8 @@ public: int get_closest_point(const Vector3& p_point) const; Vector3 get_closest_pos_in_segment(const Vector3& p_point) const; - DVector<Vector3> get_point_path(int p_from_id, int p_to_id); - DVector<int> get_id_path(int p_from_id, int p_to_id); + PoolVector<Vector3> get_point_path(int p_from_id, int p_to_id); + PoolVector<int> get_id_path(int p_from_id, int p_to_id); AStar(); ~AStar(); diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index 5242abfa3b..b7194d7ffb 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -484,7 +484,7 @@ BSP_Tree::operator Variant() const { d["planes"]=plane_values; - DVector<int> dst_nodes; + PoolVector<int> dst_nodes; dst_nodes.resize(nodes.size()*3); for(int i=0;i<nodes.size();i++) { @@ -514,19 +514,19 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) { ERR_FAIL_COND(!d.has("aabb")); ERR_FAIL_COND(!d.has("error_radius")); - DVector<int> src_nodes = d["nodes"]; + PoolVector<int> src_nodes = d["nodes"]; ERR_FAIL_COND(src_nodes.size()%3); if (d["planes"].get_type()==Variant::REAL_ARRAY) { - DVector<float> src_planes=d["planes"]; + PoolVector<float> src_planes=d["planes"]; int plane_count=src_planes.size(); ERR_FAIL_COND(plane_count%4); planes.resize(plane_count/4); if (plane_count) { - DVector<float>::Read r = src_planes.read(); + PoolVector<float>::Read r = src_planes.read(); for(int i=0;i<plane_count/4;i++) { planes[i].normal.x=r[i*4+0]; @@ -549,7 +549,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) { // int node_count = src_nodes.size(); nodes.resize(src_nodes.size()/3); - DVector<int>::Read r = src_nodes.read(); + PoolVector<int>::Read r = src_nodes.read(); for(int i=0;i<nodes.size();i++) { @@ -560,12 +560,12 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) { } -BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) { +BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) { // compute aabb int face_count=p_faces.size(); - DVector<Face3>::Read faces_r=p_faces.read(); + PoolVector<Face3>::Read faces_r=p_faces.read(); const Face3 *facesptr = faces_r.ptr(); diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index 3913e3d34a..236b6e5ac2 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -91,7 +91,7 @@ public: BSP_Tree(); BSP_Tree(const Variant& p_variant); - BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius=0); + BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius=0); BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius=0); ~BSP_Tree(); diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 91f7cf179a..3232d36262 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -204,21 +204,21 @@ static bool _group_face(_FaceClassify *p_faces, int len, int p_index,int p_group } -DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array ) { +PoolVector< PoolVector< Face3 > > Geometry::separate_objects( PoolVector< Face3 > p_array ) { - DVector< DVector< Face3 > > objects; + PoolVector< PoolVector< Face3 > > objects; int len = p_array.size(); - DVector<Face3>::Read r=p_array.read(); + PoolVector<Face3>::Read r=p_array.read(); const Face3* arrayptr = r.ptr(); - DVector< _FaceClassify> fc; + PoolVector< _FaceClassify> fc; fc.resize( len ); - DVector< _FaceClassify >::Write fcw=fc.write(); + PoolVector< _FaceClassify >::Write fcw=fc.write(); _FaceClassify * _fcptr = fcw.ptr(); @@ -231,7 +231,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array if (error) { - ERR_FAIL_COND_V(error, DVector< DVector< Face3 > >() ); // invalid geometry + ERR_FAIL_COND_V(error, PoolVector< PoolVector< Face3 > >() ); // invalid geometry } /* group connected faces in separate objects */ @@ -257,8 +257,8 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array if (group>=0) { objects.resize(group); - DVector< DVector<Face3> >::Write obw=objects.write(); - DVector< Face3 > *group_faces = obw.ptr(); + PoolVector< PoolVector<Face3> >::Write obw=objects.write(); + PoolVector< Face3 > *group_faces = obw.ptr(); for (int i=0;i<len;i++) { if (!_fcptr[i].valid) @@ -487,7 +487,7 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int } } -static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,DVector<Face3>& p_faces) { +static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,PoolVector<Face3>& p_faces) { ERR_FAIL_INDEX(x,len_x); ERR_FAIL_INDEX(y,len_y); @@ -580,13 +580,13 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l } -DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_error ) { +PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,float *p_error ) { #define _MIN_SIZE 1.0 #define _MAX_LENGTH 20 int face_count=p_array.size(); - DVector<Face3>::Read facesr=p_array.read(); + PoolVector<Face3>::Read facesr=p_array.read(); const Face3 *faces = facesr.ptr(); AABB global_aabb; @@ -696,7 +696,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro //print_line("Wrapper (3/6): Building Faces"); - DVector<Face3> wrapped_faces; + PoolVector<Face3> wrapped_faces; for (int i=0;i<div_x;i++) { @@ -714,7 +714,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro // transform face vertices to global coords int wrapped_faces_count=wrapped_faces.size(); - DVector<Face3>::Write wrapped_facesw=wrapped_faces.write(); + PoolVector<Face3>::Write wrapped_facesw=wrapped_faces.write(); Face3* wrapped_faces_ptr=wrapped_facesw.ptr(); for(int i=0;i<wrapped_faces_count;i++) { @@ -748,7 +748,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro return wrapped_faces; } -Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) { +Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes) { MeshData mesh; @@ -896,9 +896,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) { } -DVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) { +PoolVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) { - DVector<Plane> planes; + PoolVector<Plane> planes; planes.push_back( Plane( Vector3(1,0,0), p_extents.x ) ); planes.push_back( Plane( Vector3(-1,0,0), p_extents.x ) ); @@ -910,9 +910,9 @@ DVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) { return planes; } -DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) { +PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) { - DVector<Plane> planes; + PoolVector<Plane> planes; for (int i=0;i<p_sides;i++) { @@ -933,10 +933,10 @@ DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, i } -DVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) { +PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) { - DVector<Plane> planes; + PoolVector<Plane> planes; Vector3 axis; axis[p_axis]=1.0; @@ -969,9 +969,9 @@ DVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lo } -DVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { +PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { - DVector<Plane> planes; + PoolVector<Plane> planes; Vector3 axis; axis[p_axis]=1.0; diff --git a/core/math/geometry.h b/core/math/geometry.h index dae556cd09..9800e5513c 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -808,9 +808,9 @@ public: } - static DVector< DVector< Face3 > > separate_objects( DVector< Face3 > p_array ); + static PoolVector< PoolVector< Face3 > > separate_objects( PoolVector< Face3 > p_array ); - static DVector< Face3 > wrap_geometry( DVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry + static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry struct MeshData { @@ -919,11 +919,11 @@ public: return H; } - static MeshData build_convex_mesh(const DVector<Plane> &p_planes); - static DVector<Plane> build_sphere_planes(float p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z); - static DVector<Plane> build_box_planes(const Vector3& p_extents); - static DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z); - static DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z); + static MeshData build_convex_mesh(const PoolVector<Plane> &p_planes); + static PoolVector<Plane> build_sphere_planes(float p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z); + static PoolVector<Plane> build_box_planes(const Vector3& p_extents); + static PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z); + static PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z); static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size); diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index b3daee0c7e..101e164eae 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -94,7 +94,7 @@ int TriangleMesh::_create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_d } -void TriangleMesh::create(const DVector<Vector3>& p_faces) { +void TriangleMesh::create(const PoolVector<Vector3>& p_faces) { valid=false; @@ -104,7 +104,7 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) { triangles.resize(fc); bvh.resize(fc*3); //will never be larger than this (todo make better) - DVector<BVH>::Write bw = bvh.write(); + PoolVector<BVH>::Write bw = bvh.write(); { @@ -112,8 +112,8 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) { //except for the Set for repeated triangles, everything //goes in-place. - DVector<Vector3>::Read r = p_faces.read(); - DVector<Triangle>::Write w = triangles.write(); + PoolVector<Vector3>::Read r = p_faces.read(); + PoolVector<Triangle>::Write w = triangles.write(); Map<Vector3,int> db; for(int i=0;i<fc;i++) { @@ -149,16 +149,16 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) { } vertices.resize(db.size()); - DVector<Vector3>::Write vw = vertices.write(); + PoolVector<Vector3>::Write vw = vertices.write(); for (Map<Vector3,int>::Element *E=db.front();E;E=E->next()) { vw[E->get()]=E->key(); } } - DVector<BVH*> bwptrs; + PoolVector<BVH*> bwptrs; bwptrs.resize(fc); - DVector<BVH*>::Write bwp = bwptrs.write(); + PoolVector<BVH*>::Write bwp = bwptrs.write(); for(int i=0;i<fc;i++) { bwp[i]=&bw[i]; @@ -168,7 +168,7 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) { int max_alloc=fc; int max=_create_bvh(bw.ptr(),bwp.ptr(),0,fc,1,max_depth,max_alloc); - bw=DVector<BVH>::Write(); //clearup + bw=PoolVector<BVH>::Write(); //clearup bvh.resize(max_alloc); //resize back valid=true; @@ -197,9 +197,9 @@ Vector3 TriangleMesh::get_area_normal(const AABB& p_aabb) const { int level=0; - DVector<Triangle>::Read trianglesr = triangles.read(); - DVector<Vector3>::Read verticesr=vertices.read(); - DVector<BVH>::Read bvhr=bvh.read(); + PoolVector<Triangle>::Read trianglesr = triangles.read(); + PoolVector<Vector3>::Read verticesr=vertices.read(); + PoolVector<BVH>::Read bvhr=bvh.read(); const Triangle *triangleptr=trianglesr.ptr(); int pos=bvh.size()-1; @@ -299,9 +299,9 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end int level=0; - DVector<Triangle>::Read trianglesr = triangles.read(); - DVector<Vector3>::Read verticesr=vertices.read(); - DVector<BVH>::Read bvhr=bvh.read(); + PoolVector<Triangle>::Read trianglesr = triangles.read(); + PoolVector<Vector3>::Read verticesr=vertices.read(); + PoolVector<BVH>::Read bvhr=bvh.read(); const Triangle *triangleptr=trianglesr.ptr(); const Vector3 *vertexptr=verticesr.ptr(); @@ -422,9 +422,9 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec int level=0; - DVector<Triangle>::Read trianglesr = triangles.read(); - DVector<Vector3>::Read verticesr=vertices.read(); - DVector<BVH>::Read bvhr=bvh.read(); + PoolVector<Triangle>::Read trianglesr = triangles.read(); + PoolVector<Vector3>::Read verticesr=vertices.read(); + PoolVector<BVH>::Read bvhr=bvh.read(); const Triangle *triangleptr=trianglesr.ptr(); const Vector3 *vertexptr=verticesr.ptr(); @@ -524,18 +524,18 @@ bool TriangleMesh::is_valid() const { return valid; } -DVector<Face3> TriangleMesh::get_faces() const { +PoolVector<Face3> TriangleMesh::get_faces() const { if (!valid) - return DVector<Face3>(); + return PoolVector<Face3>(); - DVector<Face3> faces; + PoolVector<Face3> faces; int ts = triangles.size(); faces.resize(triangles.size()); - DVector<Face3>::Write w=faces.write(); - DVector<Triangle>::Read r = triangles.read(); - DVector<Vector3>::Read rv = vertices.read(); + PoolVector<Face3>::Write w=faces.write(); + PoolVector<Triangle>::Read r = triangles.read(); + PoolVector<Vector3>::Read rv = vertices.read(); for(int i=0;i<ts;i++) { for(int j=0;j<3;j++) { @@ -543,7 +543,7 @@ DVector<Face3> TriangleMesh::get_faces() const { } } - w = DVector<Face3>::Write(); + w = PoolVector<Face3>::Write(); return faces; } diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index d42f9c8dde..37d32bd7ec 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -41,8 +41,8 @@ class TriangleMesh : public Reference { int indices[3]; }; - DVector<Triangle> triangles; - DVector<Vector3> vertices; + PoolVector<Triangle> triangles; + PoolVector<Vector3> vertices; struct BVH { @@ -79,7 +79,7 @@ class TriangleMesh : public Reference { int _create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_depth,int&max_depth,int&max_alloc); - DVector<BVH> bvh; + PoolVector<BVH> bvh; int max_depth; bool valid; @@ -89,10 +89,10 @@ public: bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const; bool intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vector3 &r_point, Vector3 &r_normal) const; Vector3 get_area_normal(const AABB& p_aabb) const; - DVector<Face3> get_faces() const; + PoolVector<Face3> get_faces() const; - void create(const DVector<Vector3>& p_faces); + void create(const PoolVector<Vector3>& p_faces); TriangleMesh(); }; |