-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactor_tree.h
More file actions
73 lines (58 loc) · 1.74 KB
/
actor_tree.h
File metadata and controls
73 lines (58 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef ACTOR_TREE_INCLUDED
#define ACTOR_TREE_INCLUDED
#include <algorithm>
#include "SM64DS_PI.h"
class ActorTreeNode
{
const unsigned uniqueID;
Actor& actor;
unsigned height = 1;
ActorTreeNode* left = nullptr;
ActorTreeNode* right = nullptr;
ActorTreeNode(const ActorTreeNode&) = delete;
ActorTreeNode(ActorTreeNode&&) = delete;
ActorTreeNode& operator=(const ActorTreeNode&) = delete;
ActorTreeNode& operator=(ActorTreeNode&&) = delete;
[[gnu::target("thumb")]]
static unsigned Getheight(const ActorTreeNode* node)
{
if (node)
return node->height;
else
return 0;
}
[[gnu::target("thumb")]]
void UpdateHeight()
{
height = std::max(Getheight(left), Getheight(right)) + 1;
}
[[gnu::target("thumb")]]
int GetHeightDiff() const
{
return Getheight(left) - Getheight(right);
}
ActorTreeNode* Rotate(ActorTreeNode* ActorTreeNode::* from, ActorTreeNode* ActorTreeNode::* to);
[[gnu::target("thumb")]]
static void RotateLeft(ActorTreeNode*& pivot)
{
pivot = pivot->Rotate(&ActorTreeNode::left, &ActorTreeNode::right);
}
[[gnu::target("thumb")]]
static void RotateRight(ActorTreeNode*& pivot)
{
pivot = pivot->Rotate(&ActorTreeNode::right, &ActorTreeNode::left);
}
static void Insert(ActorTreeNode*& root, ActorTreeNode& newNode);
static void Remove(ActorTreeNode*& root, unsigned uniqueID);
static void RestoreBalance(ActorTreeNode*& node);
static ActorTreeNode* root;
public:
[[gnu::target("thumb")]]
ActorTreeNode(Actor& actor) : uniqueID(actor.uniqueID), actor(actor) { Insert(root, *this); }
[[gnu::target("thumb")]]
~ActorTreeNode() { Remove(root, uniqueID); }
static Actor* Find(unsigned uniqueID);
Actor& GetActor() { return actor; }
const Actor& GetActor() const { return actor; }
};
#endif