made Octree and Quadtree subclasses of 'Tree'

This commit is contained in:
BuildTools 2017-01-04 12:27:54 -05:00
parent affbab5d27
commit e307755656
4 changed files with 78 additions and 107 deletions

View file

@ -1,44 +1,11 @@
package regions;
public class Octree
public class Octree extends Tree
{
//STATIC
//==================================================================
public static class Node
{
public final boolean full;
public final Node[] nodes;
public Node(boolean full)
{
this.full = full;
this.nodes = new Node[0];
}
public Node(Node[] nodes)
{
this.full = false;
this.nodes = nodes;
}
}
private static class IntReference
{
int ref;
IntReference(int i)
{
this.ref = i;
}
}
private static Node parseBytes(IntReference index, byte[] bytes, int parentByte)
Node parseBytes(IntReference index, byte[] bytes, int parentByte)
{
if (parentByte == 0b00000010) return new Node(true);
if (parentByte == 0b00000001) return new Node(false);
@ -63,26 +30,11 @@ public class Octree
});
}
public static Node parseBytes(int startAtIndex, byte[] bytes)
{
return parseBytes ( new IntReference(startAtIndex), bytes, 0 );
}
public static Node parseBytes(byte[] bytes)
{
return parseBytes ( new IntReference(0), bytes, 0 );
}
//INSTANCE
//==================================================================
public final Owner owner;
public final Node root;
public Octree(Owner owner, byte[] bytes)
{
this.owner = owner;
this.root = parseBytes(bytes);
super(owner, bytes);
}
}

View file

@ -1,13 +1,15 @@
package regions;
import java.util.List;
public class Owner
{
public final String name;
public final Owner parent;
public final Owner[] children;
public final Octree[] trees;
public final String name;
public final Owner parent;
public final List<Owner> children;
public final List<Tree> trees;
public Owner(String name, Owner parent, Owner[] children, Octree[] trees)
public Owner(String name, Owner parent, List<Owner> children, List<Tree> trees)
{
this.name = name;
this.parent = parent;

View file

@ -1,44 +1,11 @@
package regions;
public class Quadtree
public class Quadtree extends Tree
{
//STATIC
//==================================================================
public static class Node
{
public final boolean full;
public final Node[] nodes;
public Node(boolean full)
{
this.full = full;
this.nodes = new Node[0];
}
public Node(Node[] nodes)
{
this.full = false;
this.nodes = nodes;
}
}
private static class IntReference
{
int ref;
IntReference(int i)
{
this.ref = i;
}
}
private static Node parseBytes(IntReference index, byte[] bytes, int parentByte)
Node parseBytes(IntReference index, byte[] bytes, int parentByte)
{
if (parentByte == 0b00000010) return new Node(true);
if (parentByte == 0b00000001) return new Node(false);
@ -57,26 +24,11 @@ public class Quadtree
});
}
public static Node parseBytes(int startAtIndex, byte[] bytes)
{
return parseBytes ( new IntReference(startAtIndex), bytes, 0 );
}
public static Node parseBytes(byte[] bytes)
{
return parseBytes ( new IntReference(0), bytes, 0 );
}
//INSTANCE
//==================================================================
public final Owner owner;
public final Node root;
public Quadtree(Owner owner, byte[] bytes)
{
this.owner = owner;
this.root = parseBytes(bytes);
super(owner, bytes);
}
}

65
src/regions/Tree.java Normal file
View file

@ -0,0 +1,65 @@
package regions;
public abstract class Tree
{
public static class Node
{
public boolean full;
public Node parent;
public Node[] children;
public Node(boolean full)
{
this.full = full;
this.children = new Node[0];
}
public Node(Node[] nodes)
{
this.full = false;
this.children = nodes;
}
}
static class IntReference
{
int ref;
IntReference(int i)
{
this.ref = i;
}
}
abstract Node parseBytes(IntReference index, byte[] bytes, int parentByte);
public Node parseBytes(int startAtIndex, byte[] bytes)
{
return parseBytes ( new IntReference(startAtIndex), bytes, 0 );
}
public Node parseBytes(byte[] bytes)
{
return parseBytes ( new IntReference(0), bytes, 0 );
}
public final Owner owner;
public final Node root;
public Tree(Owner owner, byte[] bytes)
{
this.owner = owner;
this.root = parseBytes(bytes);
}
}