aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Node.cpp
blob: 408370a06f631448d561419c5a2326a523521f45 (plain)
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
74
75
#include "stdafx.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.level.pathfinder.h"

// 4J - added for common ctor code
// Do all the default initialisations done in the java class
void Node::_init()
{
	heapIdx = -1;

	closed = false;

	cameFrom = nullptr;
}

Node::Node(const int x, const int y, const int z) :
x(x),
y(y),
z(z),
hash(createHash(x, y, z))
{
	_init();

	//this->x = x;
	//this->y = y;
	//this->z = z;

	//hash = createHash(x, y, z);
}

int Node::createHash(const int x, const int y, const int z)
{
	return (y & 0xff) | ((x & 0x7fff) << 8) | ((z & 0x7fff) << 24) | ((x < 0) ? 0x0080000000 : 0) | ((z < 0) ? 0x0000008000 : 0);
}

float Node::distanceTo(Node *to)
{
	float xd = static_cast<float>(to->x - x);
	float yd = static_cast<float>(to->y - y);
	float zd = static_cast<float>(to->z - z);
	return Mth::sqrt(xd * xd + yd * yd + zd * zd);
}

float Node::distanceToSqr(Node *to)
{
	float xd = to->x - x;
	float yd = to->y - y;
	float zd = to->z - z;
	return xd * xd + yd * yd + zd * zd;
}

bool Node::equals(Node *o)
{
	//4J Jev, never used anything other than a node.
	//if (dynamic_cast<Node *>((Node *) o) != nullptr)
	//{
		return hash == o->hash && x == o->x && y == o->y && z == o->z;
	//}
	//return false;
}

int Node::hashCode()
{
	return hash;
}

bool Node::inOpenSet()
{
	return heapIdx >= 0;
}

wstring Node::toString()
{
	return std::to_wstring(x) + L", " + std::to_wstring(y) + L", " + std::to_wstring(z);
}