Browse Source

Use page allocator for BVH

reduz 4 years ago
parent
commit
2e66e5d599
3 changed files with 7 additions and 5 deletions
  1. 2 2
      core/math/dynamic_bvh.cpp
  2. 2 0
      core/math/dynamic_bvh.h
  3. 3 3
      core/templates/paged_allocator.h

+ 2 - 2
core/math/dynamic_bvh.cpp

@@ -31,7 +31,7 @@
 #include "dynamic_bvh.h"
 #include "dynamic_bvh.h"
 
 
 void DynamicBVH::_delete_node(Node *p_node) {
 void DynamicBVH::_delete_node(Node *p_node) {
-	memdelete(p_node);
+	node_allocator.free(p_node);
 }
 }
 
 
 void DynamicBVH::_recurse_delete_node(Node *p_node) {
 void DynamicBVH::_recurse_delete_node(Node *p_node) {
@@ -46,7 +46,7 @@ void DynamicBVH::_recurse_delete_node(Node *p_node) {
 }
 }
 
 
 DynamicBVH::Node *DynamicBVH::_create_node(Node *p_parent, void *p_data) {
 DynamicBVH::Node *DynamicBVH::_create_node(Node *p_parent, void *p_data) {
-	Node *node = memnew(Node);
+	Node *node = node_allocator.alloc();
 	node->parent = p_parent;
 	node->parent = p_parent;
 	node->data = p_data;
 	node->data = p_data;
 	return (node);
 	return (node);

+ 2 - 0
core/math/dynamic_bvh.h

@@ -34,6 +34,7 @@
 #include "core/math/aabb.h"
 #include "core/math/aabb.h"
 #include "core/templates/list.h"
 #include "core/templates/list.h"
 #include "core/templates/local_vector.h"
 #include "core/templates/local_vector.h"
+#include "core/templates/paged_allocator.h"
 #include "core/typedefs.h"
 #include "core/typedefs.h"
 
 
 // Based on bullet Dbvh
 // Based on bullet Dbvh
@@ -217,6 +218,7 @@ private:
 		}
 		}
 	};
 	};
 
 
+	PagedAllocator<Node> node_allocator;
 	// Fields
 	// Fields
 	Node *bvh_root = nullptr;
 	Node *bvh_root = nullptr;
 	int lkhd = -1;
 	int lkhd = -1;

+ 3 - 3
core/templates/paged_allocator.h

@@ -108,7 +108,7 @@ public:
 		return page_size > 0;
 		return page_size > 0;
 	}
 	}
 
 
-	void configure(uint32_t p_page_size, bool p_thread_safe) {
+	void configure(uint32_t p_page_size) {
 		ERR_FAIL_COND(page_pool != nullptr); //sanity check
 		ERR_FAIL_COND(page_pool != nullptr); //sanity check
 		ERR_FAIL_COND(p_page_size == 0);
 		ERR_FAIL_COND(p_page_size == 0);
 		page_size = nearest_power_of_2_templated(p_page_size);
 		page_size = nearest_power_of_2_templated(p_page_size);
@@ -116,8 +116,8 @@ public:
 		page_shift = get_shift_from_power_of_2(page_size);
 		page_shift = get_shift_from_power_of_2(page_size);
 	}
 	}
 
 
-	PagedAllocator(uint32_t p_page_size = 4096, bool p_thread_safe = false) { // power of 2 recommended because of alignment with OS page sizes. Even if element is bigger, its still a multiple and get rounded amount of pages
-		configure(p_page_size, false);
+	PagedAllocator(uint32_t p_page_size = 4096) { // power of 2 recommended because of alignment with OS page sizes. Even if element is bigger, its still a multiple and get rounded amount of pages
+		configure(p_page_size);
 	}
 	}
 
 
 	~PagedAllocator() {
 	~PagedAllocator() {