Skip to content

Commit

Permalink
CMDS
Browse files Browse the repository at this point in the history
  • Loading branch information
MayKoder committed May 10, 2020
1 parent e1e3d8b commit c35f5ec
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
24 changes: 19 additions & 5 deletions full_code/Space_Partitioning_Engine/Core/AABBTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct AABBNode
AABBNode();
~AABBNode();

//Initialize node data
void Init(AABBTree*, AABBNode*, int, int, int, int);

//Min and Max node positions that construct the rect
Expand All @@ -67,21 +68,28 @@ struct AABBNode

void SetRect(int, int, int, int);

//Returns the node rect
Rect GetRect()
{
return {minPos.x, minPos.y, maxPos.x - minPos.x, maxPos.y - minPos.y};
}

//Returns a pointer to the node data list
std::list<Entity*>* GetData()
{
return &data;
}

//Returns a copy of the node data list
std::list<Entity*> GetDataValue()
{
return data;
}

//Updates the node points (min and max) with the data elements
//Updates the node min and max positions
void UpdateNode();

//Creates a node subdivision and distributes the old node data
static void SubDivide(AABBNode&);
};

Expand All @@ -99,19 +107,25 @@ class AABBTree
//Display variable, debug info won't be rendered if this is false
bool displayTree;


//Initialize tree data
void Init(int, int, int, int);
//Adds a unit to the tree and manages subdivisions

//Adds a unit to the tree by positions and manages subdivisions
void AddUnitToTree(Entity&);

//Updates all tree nodes with recursivity
void UpdateAllNodes(AABBNode& node);

//Returns a pointer to the lowest node inside a point
AABBNode* FindLowestNodeInPoint(AABBNode*, const Point);

//Loads all the leaves in a list
void LoadLeavesToList(AABBNode*, std::list<AABBNode*>&);
void LoadLeafNodesInsideRect(AABBNode*, std::vector<AABBNode*>&, Rect& collider);

void DeleteDataElement(AABBNode&, Entity*);
//Loads all leaves inside the rect
void LoadLeafNodesInsideRect(AABBNode*, std::vector<AABBNode*>&, Rect& collider);

//Deletes the tree if it’s a pointer
void Clear();

};
Expand Down
16 changes: 16 additions & 0 deletions full_code/Space_Partitioning_Engine/Core/MaykMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ struct Point
{
int x = 0, y = 0;

//Overrides the operator* to allow dot product between Points
float operator*(Point const &b)
{
return (x * b.x) + (y * b.y);
}

//Returns the Manhattan distance between two points
float DistanceManhattan(const Point& v) const
{
return ABS(v.x - x) + ABS(v.y - y);
}

//Returns true if X and Y are equal to 0
bool IsZero()
{
return (x == 0 && y == 0);
Expand All @@ -55,6 +58,7 @@ struct Rect
{
int x = 0, y = 0, w = 0, h = 0;

//Returns the rect’s central point
Point GetCentralPoint()
{
return {x + w / 2, y + h / 2};
Expand Down Expand Up @@ -83,13 +87,25 @@ struct Vector4

namespace MaykMath
{
//Calculate a vector from two points and invert the Y (we need this for OA detection)
Point NegatedYVectorFromPoints(Point, Point);

//Calculate and return the area of any triangle
float GetTriangleArea(Point, Point, Point);

//Returns true if the Point is inside an OA rectangle
bool IsPointInsideOffAxisRectangle(Point, Point, Point, Point, Point);

//Returns true is the point is inside the AA rectangle
bool IsPointInsideAxisAlignedRectangle(Rect, Point);

//Returns true if the input rects are overlaping
bool CheckRectCollision(const Rect&, const Rect&);

//Returns a Point with the minimum values of the two input Points
Point GetMinPoint(Point, Point);

//Returns a Point with the maximum values of the two input Points
Point GetMaxPoint(Point, Point);
}

Expand Down
16 changes: 15 additions & 1 deletion full_code/Space_Partitioning_Engine/Core/QuadTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct QuadNode
QuadNode();
~QuadNode();

//Initialize node data
void Init(QuadTree*, QuadNode*, int, int, int, int);

//Positions
Expand All @@ -58,11 +59,16 @@ struct QuadNode
//Data
std::list<Entity*> data;

//Sets the rect info
void SetRect(int&, int&, int&, int&);

//Returns the node rect
Rect GetRect() { return {x, y, w, h}; };

//Return a pointer to the data list
const std::list<Entity*>* GetContent() { return &data; }

//Subdivides the tree X number of times
static void SubDivide(QuadNode&, int);
};

Expand All @@ -73,6 +79,7 @@ class QuadTree
QuadTree();
~QuadTree();

//Initialize tree data
void Init(TreeType, int, int, int, int);

QuadNode baseNode;
Expand All @@ -85,15 +92,22 @@ class QuadTree
int lowest_height = 0;
QuadNode* lowestNode = nullptr;

//Adds an entity to the tree by positions and manages subdivisions
void AddEntityToNode(Entity&, Point);

//Loads all nodes overlaping with the point in a list
void LoadNodesToList(std::list<QuadNode*>*, QuadNode*, Point, Point);

//Finds the leaf inside a point
void FindLowestNodeInPoint(QuadNode*, const Point&);

//Checks off axis rect overlap
static bool CheckNodeOverLap(Rect, Rect);

//Transforms input to isometric space
static Point CoordsToIsometricInt(Point, Point);

//Delete and free all the tree memory
//Deletes the tree if it’s a pointer
void Clear();

};
Expand Down

0 comments on commit c35f5ec

Please sign in to comment.