File: IPathManager.h

package info (click to toggle)
spring 106.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,316 kB
  • sloc: cpp: 543,954; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (177 lines) | stat: -rw-r--r-- 5,794 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef I_PATH_MANAGER_H
#define I_PATH_MANAGER_H

#include <vector>
#include <cinttypes>

#include "PFSTypes.h"
#include "System/type2.h"
#include "System/float3.h"

struct MoveDef;
class CSolidObject;

class IPathManager {
public:
	static IPathManager* GetInstance(int type);
	static void FreeInstance(IPathManager*);

	virtual ~IPathManager() {}

	virtual std::int32_t GetPathFinderType() const { return NOPFS_TYPE; }
	virtual std::uint32_t GetPathCheckSum() const { return 0; }

	virtual std::int64_t Finalize() { return 0; }

	/**
	 * returns if a path was changed after RequestPath returned its pathID
	 * this can happen eg. if a PathManager reacts to TerrainChange events
	 * (by re-requesting affected paths without changing their ID's)
	 */
	virtual bool PathUpdated(unsigned int pathID) { return false; }

	virtual void RemoveCacheFiles() {}
	virtual void Update() {}
	virtual void UpdatePath(const CSolidObject* owner, unsigned int pathID) {}

	/**
	 * When a path is no longer used, call this function to release it from
	 * memory.
	 * @param pathID
	 *     The path-id returned by RequestPath.
	 */
	virtual void DeletePath(unsigned int pathID) {}

	/**
	 * Returns the next waypoint of the path.
	 *
	 * @param pathID
	 *     The path-id returned by RequestPath.
	 * @param callerPos
	 *     The current position of the user of the path.
	 *     This extra information is needed to keep the path connected to its
	 *     user.
	 * @param minDistance
	 *     Could be used to set a minimum required distance between callerPos
	 *     and the returned waypoint.
	 * @param numRetries
	 *     Dont set this, used internally
	 * @param owner
	 *     The unit the path is used for, or NULL.
	 * @param synced
	 *     Whether this evaluation has to run synced or unsynced.
	 *     If false, this call may not change any state of the path manager
	 *     that could alter paths requested in the future.
	 *     example: if (synced == false) turn of heat-mapping
	 * @return
	 *     the next waypoint of the path, or (-1,-1,-1) in case no new
	 *     waypoint could be found.
	 */
	virtual float3 NextWayPoint(
		const CSolidObject* owner,
		unsigned int pathID,
		unsigned int numRetries,
		float3 callerPos,
		float radius,
		bool synced
	) {
		return -OnesVector;
	}


	/**
	 * Returns all waypoints of a path. Different segments of a path might
	 * have different resolutions, or each segment might be represented at
	 * multiple different resolution levels. In the former case, a subset
	 * of waypoints (those belonging to i-th resolution path SEGMENTS) are
	 * stored between points[starts[i]] and points[starts[i + 1]], while in
	 * the latter case ALL waypoints (of the i-th resolution PATH) are stored
	 * between points[starts[i]] and points[starts[i + 1]]
	 *
	 * @param pathID
	 *     The path-id returned by RequestPath.
	 * @param points
	 *     The list of waypoints.
	 * @param starts
	 *     The list of starting indices for the different resolutions
	 */
	virtual void GetPathWayPoints(
		unsigned int pathID,
		std::vector<float3>& points,
		std::vector<int>& starts
	) const {
	}


	/**
	 * Generate a path from startPos to the target defined by
	 * (goalPos, goalRadius).
	 * If no complete path from startPos to goalPos could be found,
	 * then a path getting as "close" as possible to target is generated.
	 *
	 * @param moveDef
	 *     Defines the move details of the unit to use the path.
	 * @param startPos
	 *     The starting location of the requested path.
	 * @param goalPos
	 *     The center of the path goal area.
	 * @param goalRadius
	 *     Use goalRadius to define a goal area within any square that could
	 *     be accepted as path goal.
	 *     If a singular goal position is wanted, use goalRadius = 0.
	 * @param caller
	 *     The unit or feature the path will be used for.
	 * @param synced
	 *     Whether this evaluation has to run synced or unsynced.
	 *     If false, this call may not change any state of the path manager
	 *     that could alter paths requested in the future.
	 *     example: if (synced == false) turn off heat-mapping
	 * @return
	 *     a path-id >= 1 on success, 0 on failure
	 *     Failure means, no path getting "closer" to goalPos then startPos
	 *     could be found
	 */
	virtual unsigned int RequestPath(
		CSolidObject* caller,
		const MoveDef* moveDef,
		float3 startPos,
		float3 goalPos,
		float goalRadius,
		bool synced
	) {
		return 0;
	}

	/**
	 * Whenever there are any changes in the terrain
	 * (examples: explosions, new buildings, etc.)
	 * this function will be called.
	 * @param x1
	 *     First corners X-axis value, defining the rectangular area
	 *     affected by the changes.
	 * @param z1
	 *     First corners Z-axis value, defining the rectangular area
	 *     affected by the changes.
	 * @param x2
	 *     Second corners X-axis value, defining the rectangular area
	 *     affected by the changes.
	 * @param z2
	 *     Second corners Z-axis value, defining the rectangular area
	 *     affected by the changes.
	 * @param type see @TerrainChangeTypes
	 */
	virtual void TerrainChange(unsigned int x1, unsigned int z1, unsigned int x2, unsigned int z2, unsigned int type) {}

	virtual bool SetNodeExtraCosts(const float* costs, unsigned int sizex, unsigned int sizez, bool synced) { return false; }
	virtual bool SetNodeExtraCost(unsigned int x, unsigned int z, float cost, bool synced) { return false; }
	virtual float GetNodeExtraCost(unsigned int x, unsigned int z, bool synced) const { return 0.0f; }
	virtual const float* GetNodeExtraCosts(bool synced) const { return nullptr; }

	virtual int2 GetNumQueuedUpdates() const { return (int2(0, 0)); }
};

extern IPathManager* pathManager;

#endif