Particle Game Maker Engine  1.0.0
Enables the user to create their own particle game using a simple and coherent api in the PongChamp scripting language
QuadTree.h
Go to the documentation of this file.
1 #ifndef QUAD_TREE_H
2 #define QUAD_TREE_H
3 
4 #include "ParticleGroupHandle.h"
5 
7 struct Point
8 {
9  int x;
10  int y;
12  Point(int _x, int _y): x(_x), y(_y)
13  {
14  }
15  Point() = default;
16 };
17 
19 #define DEFAULT_COLLIDE_REST 1
20 
22 struct Node
23 {
26 
29 
32 
34  Node(Point _pos, ParticleGroupHandle* _data, int _id): pos(_pos), mGroup(_data), mid(_id)
35  {
36  }
37  Node() = default;
38 
40  int mid;
41 };
42 
44 #define QUAD_MAX 4
45 
47 #define MINQUAD_AREA 16
48 
50 class QuadTree
51 {
52 public:
53  // boundary points
56 
58  Node* nodes[QUAD_MAX] = {nullptr, nullptr, nullptr, nullptr};
59 
61  int size = 0;
62  int nextFreeNode = 0;
63 
65  bool treeHolder = false;
66 
69 
79  QuadTree(Point topL, Point botR);
80 
86  void remove(Node* n);
87 
96  void insert(Node*);
97 
99  bool inBoundary(Point);
100 
107  void shrink();
108 
109 };
110 
111 #endif
QuadTree * botLeftTree
bottom left child
Definition: QuadTree.h:75
QuadTree * topRightTree
Top right child.
Definition: QuadTree.h:73
QuadTree(Point topL, Point botR)
Construct a quadtree of bounds topL and botR.
Definition: QuadTree.cpp:7
bool treeHolder
A bool stating whether this tree is a parent of other nodes.
Definition: QuadTree.h:65
void shrink()
Definition: QuadTree.cpp:179
int nextFreeNode
Definition: QuadTree.h:62
int size
The number of particles in this QuadTree including children.
Definition: QuadTree.h:61
#define QUAD_MAX
The max number of particles that can be in a single quad tree.
Definition: QuadTree.h:44
Node * nodes[QUAD_MAX]
The particles of this Quadtree.
Definition: QuadTree.h:58
bool inBoundary(Point)
Check if current quadtree contains the point.
Definition: QuadTree.cpp:134
Point botRight
Definition: QuadTree.h:55
Point topLeft
Definition: QuadTree.h:54
QuadTree * topLeftTree
Top left child.
Definition: QuadTree.h:71
A class to represent QuadTree.
Definition: QuadTree.h:50
int mid
A unique id for this particle.
Definition: QuadTree.h:40
Node(Point _pos, ParticleGroupHandle *_data, int _id)
Constructor taking in a position group handle and unique id.
Definition: QuadTree.h:34
ParticleGroupHandle * mGroup
The handle and identifier for this particles group.
Definition: QuadTree.h:31
Definition: ParticleGroupHandle.h:29
QuadTree * botRightTree
bottom right child
Definition: QuadTree.h:77
#define DEFAULT_COLLIDE_REST
The defualt number of frames that a particle must be alive before it can collide again...
Definition: QuadTree.h:19
int canCollide
If can collide is > 0 this particle is newly spawned and cannot collide.
Definition: QuadTree.h:28
Node() = default
Point pos
The current position of this particle.
Definition: QuadTree.h:25
void insert(Node *)
Definition: QuadTree.cpp:16
objects stored in quadtree
Definition: QuadTree.h:22
Point() = default
void remove(Node *n)
Definition: QuadTree.cpp:142
Point(int _x, int _y)
constructs a point
Definition: QuadTree.h:12
int y
Definition: QuadTree.h:10
QuadTree * parent
Pointer to parent of this tree.
Definition: QuadTree.h:68
int x
x position
Definition: QuadTree.h:9
where something is in 2d space
Definition: QuadTree.h:7