/* ***************************************** * Methods * ***************************************** */ /// <summary> /// Adds new octree and creates first initial node at given origing /// </summary> /// <returns></returns> static private void _AddOctree( ) { BoundingOctreeAddNodeSystem.Nodes octree = new BoundingOctreeAddNodeSystem.Nodes(); //octree.NUM_ENTITIES_ALLOWED = 0 ; octree.NUM_ENTITIES_ALLOWED = 1; octree.f_minNodeSize = 1f; int i_nodeArrayAllocationSize = 1000000; // 800 ; // dispose on manager exit octree.a_bounds = new NativeArray <Bounds> (i_nodeArrayAllocationSize, Allocator.Persistent); octree.a_rootNodeIndex = new NativeArray <int> (i_nodeArrayAllocationSize, Allocator.Persistent); octree.a_childrenNodeIndex = new NativeArray <int> (i_nodeArrayAllocationSize * 8, Allocator.Persistent); octree.a_childrenNodesCount = new NativeArray <byte> (i_nodeArrayAllocationSize, Allocator.Persistent); octree.a_entitiesInNodeCount = new NativeArray <byte> (i_nodeArrayAllocationSize * octree.NUM_ENTITIES_ALLOWED, Allocator.Persistent); octree.a_entitiesInNodes = new NativeArray <EntityInstance> (i_nodeArrayAllocationSize * octree.NUM_ENTITIES_ALLOWED, Allocator.Persistent); // kep buffer bigger than node capcity octree.a_baseLength = new NativeArray <float> (i_nodeArrayAllocationSize, Allocator.Persistent); octree.a_actualLength = new NativeArray <float> (i_nodeArrayAllocationSize, Allocator.Persistent); octree.f_looseness = 1.0f; // range 1 to 2. Shuld be clamped // range 1.0f to 2.0f // where 1 is no loosness (ordinary octree) octree.f_initialSize = 1; octree.i_lastNodeIndex = 0; octree.i_objectsCount = 0; octree.i_rootNodeIndex = 0; // octree = _SetValues ( octree, 0, octree.f_minNodeSize, new float3 (1,1,1) ) ; octree.a_baseLength [0] = octree.f_initialSize; octree.a_actualLength [0] = octree.f_initialSize; octree.a_bounds [0] = new Bounds() { f3_center = new float3(1, 1, 1) * 0.5f, f_size = octree.f_initialSize }; Debug.Log("Add initial new node to new octree"); int i_initialNodeIndex = 0; // EntityInstance initialEntityInstance = new EntityInstance () { f3_position = new float3 (1,1,1) * 0, entity = new Entity () } ; // _AddNode ( 0, i_initialNodeIndex, initialEntityInstance ) ; Debug.Log("Add new octree to the list"); Debug.Log("Review octree id structure, as it do not considers, when octree group is deleted from the list."); // Add octree l_octrees.Add(octree); OctreeTag octreeTag = new OctreeTag() { i_octreeID = l_octrees.Count }; Entity newEntity = entityManager.CreateEntity(archetype); entityManager.SetComponentData <OctreeTag> (newEntity, octreeTag); // Add initial node with index, at origin position 0,0,0 // _AddNodeNow ( octree ) ; }
protected override void OnDestroyManager( ) { BoundingOctreeAddNodeSystem.Nodes octree = l_octrees [0]; octree.a_bounds.Dispose(); octree.a_rootNodeIndex.Dispose(); octree.a_childrenNodeIndex.Dispose(); octree.a_childrenNodesCount.Dispose(); octree.a_entitiesInNodeCount.Dispose(); octree.a_entitiesInNodes.Dispose(); octree.a_baseLength.Dispose(); octree.a_actualLength.Dispose(); base.OnDestroyManager( ); }