Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
Path.h
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#ifndef SKYFIRESERVER_PATH_H
7
#define SKYFIRESERVER_PATH_H
8
9
#include "
Common.h
"
10
#include <deque>
11
12
struct
PathNode
13
{
14
PathNode
() :
x
(0.0f),
y
(0.0f),
z
(0.0f) { }
15
PathNode
(
float
_x,
float
_y,
float
_z) :
x
(_x),
y
(_y),
z
(_z) { }
16
float
x
,
y
,
z
;
17
};
18
template
<
typename
PathElem,
typename
PathNode = PathElem>
19
20
class
Path
21
{
22
public
:
23
size_t
size
()
const
{
return
i_nodes
.size(); }
24
bool
empty
()
const
{
return
i_nodes
.empty(); }
25
void
resize
(
unsigned
int
sz) {
i_nodes
.resize(sz); }
26
void
clear
() {
i_nodes
.clear(); }
27
void
erase
(
uint32
idx) {
i_nodes
.erase(
i_nodes
.begin() + idx); }
28
void
crop
(
unsigned
int
start,
unsigned
int
end)
29
{
30
while
(start && !
i_nodes
.empty())
31
{
32
i_nodes
.pop_front();
33
--start;
34
}
35
36
while
(end && !
i_nodes
.empty())
37
{
38
i_nodes
.pop_back();
39
--end;
40
}
41
}
42
43
float
GetTotalLength
(
uint32
start,
uint32
end)
const
44
{
45
float
len = 0.0f;
46
for
(
uint32
idx = start + 1; idx < end; ++idx)
47
{
48
PathNode
const
& node =
i_nodes
[idx];
49
PathNode
const
& prev =
i_nodes
[idx - 1];
50
float
xd = node.
x
- prev.
x
;
51
float
yd = node.
y
- prev.
y
;
52
float
zd = node.
z
- prev.
z
;
53
len += sqrtf(xd * xd + yd * yd + zd * zd);
54
}
55
return
len;
56
}
57
58
float
GetTotalLength
()
const
{
return
GetTotalLength
(0,
size
()); }
59
60
float
GetPassedLength
(
uint32
curnode,
float
x,
float
y,
float
z)
const
61
{
62
float
len =
GetTotalLength
(0, curnode);
63
64
if
(curnode > 0)
65
{
66
PathNode
const
& node =
i_nodes
[curnode - 1];
67
float
xd = x - node.
x
;
68
float
yd = y - node.
y
;
69
float
zd = z - node.
z
;
70
len += sqrtf(xd * xd + yd * yd + zd * zd);
71
}
72
73
return
len;
74
}
75
76
PathNode
&
operator[]
(
size_t
idx) {
return
i_nodes
[idx]; }
77
PathNode
const
&
operator[]
(
size_t
idx)
const
{
return
i_nodes
[idx]; }
78
79
void
set
(
size_t
idx, PathElem elem) {
i_nodes
[idx] = elem; }
80
81
protected
:
82
std::deque<PathElem>
i_nodes
;
83
};
84
85
typedef
Path<PathNode>
SimplePath
;
86
87
#endif
Common.h
uint32
std::uint32_t uint32
Definition
Define.h:77
SimplePath
Path< PathNode > SimplePath
Definition
Path.h:85
Path
Definition
Path.h:21
Path::GetPassedLength
float GetPassedLength(uint32 curnode, float x, float y, float z) const
Definition
Path.h:60
Path::set
void set(size_t idx, PathElem elem)
Definition
Path.h:79
Path::erase
void erase(uint32 idx)
Definition
Path.h:27
Path< TaxiPathNodePtr, TaxiPathNodeEntry const >::i_nodes
std::deque< TaxiPathNodePtr > i_nodes
Definition
Path.h:82
Path::crop
void crop(unsigned int start, unsigned int end)
Definition
Path.h:28
Path::clear
void clear()
Definition
Path.h:26
Path::resize
void resize(unsigned int sz)
Definition
Path.h:25
Path::GetTotalLength
float GetTotalLength(uint32 start, uint32 end) const
Definition
Path.h:43
Path::size
size_t size() const
Definition
Path.h:23
Path::empty
bool empty() const
Definition
Path.h:24
Path::operator[]
PathNode & operator[](size_t idx)
Definition
Path.h:76
Path::GetTotalLength
float GetTotalLength() const
Definition
Path.h:58
Path::operator[]
PathNode const & operator[](size_t idx) const
Definition
Path.h:77
PathNode
Definition
Path.h:13
PathNode::PathNode
PathNode(float _x, float _y, float _z)
Definition
Path.h:15
PathNode::z
float z
Definition
Path.h:16
PathNode::PathNode
PathNode()
Definition
Path.h:14
PathNode::x
float x
Definition
Path.h:16
PathNode::y
float y
Definition
Path.h:16
src
server
game
Movement
Waypoints
Path.h
Generated on
for Project SkyFire Core by
1.17.0