Pioneer
Loading...
Searching...
No Matches
GeoPatchJobs.h
Go to the documentation of this file.
1// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _GEOPATCHJOBS_H
5#define _GEOPATCHJOBS_H
6
7#include <SDL_stdinc.h>
8
9#include "Color.h"
10#include "GeoPatchID.h"
11#include "JobQueue.h"
12#include "vector3.h"
13#include "terrain/Terrain.h"
14
15class GeoSphere;
16
17#define BORDER_SIZE 1
18
20public:
21 SBaseRequest(const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const vector3d &cn,
22 const uint32_t depth_, const SystemPath &sysPath_, const GeoPatchID &patchID_, const int edgeLen_, const double fracStep_,
23 Terrain *pTerrain_) :
24 v0(v0_),
25 v1(v1_),
26 v2(v2_),
27 v3(v3_),
28 centroid(cn),
29 depth(depth_),
30 sysPath(sysPath_),
31 patchID(patchID_),
32 edgeLen(edgeLen_),
33 fracStep(fracStep_),
34 pTerrain(pTerrain_)
35 {
36 }
37
38 inline int NUMVERTICES(const int el) const { return el * el; }
39
40 const vector3d v0, v1, v2, v3;
42 const uint32_t depth;
45 const int edgeLen;
46 const double fracStep;
48
49protected:
50 // deliberately prevent copy constructor access
51 SBaseRequest(const SBaseRequest &r) = delete;
52};
53
55public:
56 SQuadSplitRequest(const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const vector3d &cn,
57 const uint32_t depth_, const SystemPath &sysPath_, const GeoPatchID &patchID_, const int edgeLen_, const double fracStep_,
58 Terrain *pTerrain_) :
59 SBaseRequest(v0_, v1_, v2_, v3_, cn, depth_, sysPath_, patchID_, edgeLen_, fracStep_, pTerrain_)
60 {
61 const int numVerts = NUMVERTICES(edgeLen_);
62 for (int i = 0; i < 4; ++i) {
63 heights[i] = new double[numVerts];
64 normals[i] = new vector3f[numVerts];
65 colors[i] = new Color3ub[numVerts];
66 }
67 const int numBorderedVerts = NUMVERTICES((edgeLen_ * 2) + (BORDER_SIZE * 2) - 1);
68 borderHeights.reset(new double[numBorderedVerts]);
69 borderVertexs.reset(new vector3d[numBorderedVerts]);
70 }
71
72 // Generates full-detail vertices, and also non-edge normals and colors
73 void GenerateBorderedData() const;
74
75 void GenerateSubPatchData(const int quadrantIndex,
76 const vector3d &v0, const vector3d &v1, const vector3d &v2, const vector3d &v3,
77 const int edgeLen, const int xoff, const int yoff, const int borderedEdgeLen) const;
78
79 // these are created with the request and are given to the resulting patches
82 double *heights[4];
83
84 // these are created with the request but are destroyed when the request is finished
85 std::unique_ptr<double[]> borderHeights;
86 std::unique_ptr<vector3d[]> borderVertexs;
87
88protected:
89 // deliberately prevent copy constructor access
91};
92
94public:
95 SSingleSplitRequest(const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const vector3d &cn,
96 const uint32_t depth_, const SystemPath &sysPath_, const GeoPatchID &patchID_, const int edgeLen_, const double fracStep_,
97 Terrain *pTerrain_) :
98 SBaseRequest(v0_, v1_, v2_, v3_, cn, depth_, sysPath_, patchID_, edgeLen_, fracStep_, pTerrain_)
99 {
100 const int numVerts = NUMVERTICES(edgeLen_);
101 heights = new double[numVerts];
102 normals = new vector3f[numVerts];
103 colors = new Color3ub[numVerts];
104
105 const int numBorderedVerts = NUMVERTICES(edgeLen_ + (BORDER_SIZE * 2));
106 borderHeights.reset(new double[numBorderedVerts]);
107 borderVertexs.reset(new vector3d[numBorderedVerts]);
108 }
109
110 // Generates full-detail vertices, and also non-edge normals and colors
111 void GenerateMesh() const;
112
113 // these are created with the request and are given to the resulting patches
116 double *heights;
117
118 // these are created with the request but are destroyed when the request is finished
119 std::unique_ptr<double[]> borderHeights;
120 std::unique_ptr<vector3d[]> borderVertexs;
121
122protected:
123 // deliberately prevent copy constructor access
125};
126
129 patchID(0) {}
130 SSplitResultData(double *heights_, vector3f *n_, Color3ub *c_, const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const GeoPatchID &patchID_) :
131 heights(heights_),
132 normals(n_),
133 colors(c_),
134 v0(v0_),
135 v1(v1_),
136 v2(v2_),
137 v3(v3_),
138 patchID(patchID_)
139 {}
140
141 double *heights;
146};
147
149public:
150 SBaseSplitResult(const int32_t face_, const int32_t depth_) :
151 mFace(face_),
152 mDepth(depth_) {}
153 virtual ~SBaseSplitResult() {}
154
155 inline int32_t face() const { return mFace; }
156 inline int32_t depth() const { return mDepth; }
157
158 virtual void OnCancel() = 0;
159
160protected:
161 // deliberately prevent copy constructor access
163 mFace(0),
164 mDepth(0) {}
165
166 const int32_t mFace;
167 const int32_t mDepth;
168};
169
171 static const int NUM_RESULT_DATA = 4;
172
173public:
174 SQuadSplitResult(const int32_t face_, const int32_t depth_) :
175 SBaseSplitResult(face_, depth_)
176 {
177 }
178
179 void addResult(const int kidIdx, double *h_, vector3f *n_, Color3ub *c_, const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const GeoPatchID &patchID_)
180 {
181 assert(kidIdx >= 0 && kidIdx < NUM_RESULT_DATA);
182 mData[kidIdx] = (SSplitResultData(h_, n_, c_, v0_, v1_, v2_, v3_, patchID_));
183 }
184
185 inline const SSplitResultData &data(const int32_t idx) const { return mData[idx]; }
186
187 virtual void OnCancel()
188 {
189 for (int i = 0; i < NUM_RESULT_DATA; ++i) {
190 if (mData[i].heights) {
191 delete[] mData[i].heights;
192 mData[i].heights = NULL;
193 }
194 if (mData[i].normals) {
195 delete[] mData[i].normals;
196 mData[i].normals = NULL;
197 }
198 if (mData[i].colors) {
199 delete[] mData[i].colors;
200 mData[i].colors = NULL;
201 }
202 }
203 }
204
205protected:
206 // deliberately prevent copy constructor access
208 SBaseSplitResult(r) {}
209
210 SSplitResultData mData[NUM_RESULT_DATA];
211};
212
214public:
215 SSingleSplitResult(const int32_t face_, const int32_t depth_) :
216 SBaseSplitResult(face_, depth_)
217 {
218 }
219
220 void addResult(double *h_, vector3f *n_, Color3ub *c_, const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const GeoPatchID &patchID_)
221 {
222 mData = (SSplitResultData(h_, n_, c_, v0_, v1_, v2_, v3_, patchID_));
223 }
224
225 inline const SSplitResultData &data() const { return mData; }
226
227 virtual void OnCancel()
228 {
229 {
230 if (mData.heights) {
231 delete[] mData.heights;
232 mData.heights = NULL;
233 }
234 if (mData.normals) {
235 delete[] mData.normals;
236 mData.normals = NULL;
237 }
238 if (mData.colors) {
239 delete[] mData.colors;
240 mData.colors = NULL;
241 }
242 }
243 }
244
245protected:
246 // deliberately prevent copy constructor access
248 SBaseSplitResult(r) {}
249
251};
252
253class GeoPatch;
254
255// ********************************************************************************
256// Overloaded PureJob class to handle generating the mesh for each patch
257// ********************************************************************************
258class BasePatchJob : public Job {
259public:
261 virtual void OnRun() {} // RUNS IN ANOTHER THREAD!! MUST BE THREAD SAFE!
262 virtual void OnFinish() {}
263 virtual void OnCancel() {}
264};
265
266// ********************************************************************************
267// Overloaded PureJob class to handle generating the mesh for each patch
268// ********************************************************************************
270public:
272 mData(data),
273 mpResults(NULL)
274 { /* empty */
275 }
277
278 virtual void OnRun(); // RUNS IN ANOTHER THREAD!! MUST BE THREAD SAFE!
279 virtual void OnFinish(); // runs in primary thread of the context
280
281private:
282 std::unique_ptr<SSingleSplitRequest> mData;
283 SSingleSplitResult *mpResults;
284};
285
286// ********************************************************************************
287// Overloaded PureJob class to handle generating the mesh for each patch
288// ********************************************************************************
290public:
292 mData(data),
293 mpResults(NULL)
294 { /* empty */
295 }
297
298 virtual void OnRun(); // RUNS IN ANOTHER THREAD!! MUST BE THREAD SAFE!
299 virtual void OnFinish(); // runs in primary thread of the context
300
301private:
302 std::unique_ptr<SQuadSplitRequest> mData;
303 SQuadSplitResult *mpResults;
304};
305
306#endif /* _GEOPATCHJOBS_H */
#define BORDER_SIZE
Definition GeoPatchJobs.h:17
Definition GeoPatchJobs.h:258
virtual void OnCancel()
Definition GeoPatchJobs.h:263
BasePatchJob()
Definition GeoPatchJobs.h:260
virtual void OnRun()
Definition GeoPatchJobs.h:261
virtual void OnFinish()
Definition GeoPatchJobs.h:262
Definition GeoPatchID.h:9
Definition GeoPatch.h:40
Definition GeoSphere.h:29
Definition JobQueue.h:33
Definition GeoPatchJobs.h:289
~QuadPatchJob()
Definition GeoPatchJobs.cpp:179
QuadPatchJob(SQuadSplitRequest *data)
Definition GeoPatchJobs.h:291
virtual void OnRun()
Definition GeoPatchJobs.cpp:134
virtual void OnFinish()
Definition GeoPatchJobs.cpp:127
Definition RefCounted.h:36
Definition GeoPatchJobs.h:19
const SystemPath sysPath
Definition GeoPatchJobs.h:43
const vector3d v1
Definition GeoPatchJobs.h:40
SBaseRequest(const SBaseRequest &r)=delete
const vector3d v0
Definition GeoPatchJobs.h:40
const uint32_t depth
Definition GeoPatchJobs.h:42
SBaseRequest(const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const vector3d &cn, const uint32_t depth_, const SystemPath &sysPath_, const GeoPatchID &patchID_, const int edgeLen_, const double fracStep_, Terrain *pTerrain_)
Definition GeoPatchJobs.h:21
const double fracStep
Definition GeoPatchJobs.h:46
const GeoPatchID patchID
Definition GeoPatchJobs.h:44
const vector3d v3
Definition GeoPatchJobs.h:40
const int edgeLen
Definition GeoPatchJobs.h:45
const vector3d v2
Definition GeoPatchJobs.h:40
int NUMVERTICES(const int el) const
Definition GeoPatchJobs.h:38
RefCountedPtr< Terrain > pTerrain
Definition GeoPatchJobs.h:47
const vector3d centroid
Definition GeoPatchJobs.h:41
Definition GeoPatchJobs.h:148
const int32_t mFace
Definition GeoPatchJobs.h:166
virtual ~SBaseSplitResult()
Definition GeoPatchJobs.h:153
SBaseSplitResult(const int32_t face_, const int32_t depth_)
Definition GeoPatchJobs.h:150
int32_t face() const
Definition GeoPatchJobs.h:155
virtual void OnCancel()=0
SBaseSplitResult(const SBaseSplitResult &r)
Definition GeoPatchJobs.h:162
const int32_t mDepth
Definition GeoPatchJobs.h:167
int32_t depth() const
Definition GeoPatchJobs.h:156
Definition GeoPatchJobs.h:54
Color3ub * colors[4]
Definition GeoPatchJobs.h:81
SQuadSplitRequest(const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const vector3d &cn, const uint32_t depth_, const SystemPath &sysPath_, const GeoPatchID &patchID_, const int edgeLen_, const double fracStep_, Terrain *pTerrain_)
Definition GeoPatchJobs.h:56
std::unique_ptr< vector3d[]> borderVertexs
Definition GeoPatchJobs.h:86
SQuadSplitRequest(const SQuadSplitRequest &r)=delete
void GenerateBorderedData() const
Definition GeoPatchJobs.cpp:189
double * heights[4]
Definition GeoPatchJobs.h:82
vector3f * normals[4]
Definition GeoPatchJobs.h:80
std::unique_ptr< double[]> borderHeights
Definition GeoPatchJobs.h:85
void GenerateSubPatchData(const int quadrantIndex, const vector3d &v0, const vector3d &v1, const vector3d &v2, const vector3d &v3, const int edgeLen, const int xoff, const int yoff, const int borderedEdgeLen) const
Definition GeoPatchJobs.cpp:214
Definition GeoPatchJobs.h:170
virtual void OnCancel()
Definition GeoPatchJobs.h:187
SQuadSplitResult(const SQuadSplitResult &r)
Definition GeoPatchJobs.h:207
SSplitResultData mData[NUM_RESULT_DATA]
Definition GeoPatchJobs.h:210
void addResult(const int kidIdx, double *h_, vector3f *n_, Color3ub *c_, const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const GeoPatchID &patchID_)
Definition GeoPatchJobs.h:179
const SSplitResultData & data(const int32_t idx) const
Definition GeoPatchJobs.h:185
SQuadSplitResult(const int32_t face_, const int32_t depth_)
Definition GeoPatchJobs.h:174
Definition GeoPatchJobs.h:93
SSingleSplitRequest(const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const vector3d &cn, const uint32_t depth_, const SystemPath &sysPath_, const GeoPatchID &patchID_, const int edgeLen_, const double fracStep_, Terrain *pTerrain_)
Definition GeoPatchJobs.h:95
void GenerateMesh() const
Definition GeoPatchJobs.cpp:29
double * heights
Definition GeoPatchJobs.h:116
Color3ub * colors
Definition GeoPatchJobs.h:115
SSingleSplitRequest(const SSingleSplitRequest &r)=delete
std::unique_ptr< vector3d[]> borderVertexs
Definition GeoPatchJobs.h:120
vector3f * normals
Definition GeoPatchJobs.h:114
std::unique_ptr< double[]> borderHeights
Definition GeoPatchJobs.h:119
Definition GeoPatchJobs.h:213
const SSplitResultData & data() const
Definition GeoPatchJobs.h:225
void addResult(double *h_, vector3f *n_, Color3ub *c_, const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const GeoPatchID &patchID_)
Definition GeoPatchJobs.h:220
virtual void OnCancel()
Definition GeoPatchJobs.h:227
SSplitResultData mData
Definition GeoPatchJobs.h:250
SSingleSplitResult(const SSingleSplitResult &r)
Definition GeoPatchJobs.h:247
SSingleSplitResult(const int32_t face_, const int32_t depth_)
Definition GeoPatchJobs.h:215
Definition GeoPatchJobs.h:269
SinglePatchJob(SSingleSplitRequest *data)
Definition GeoPatchJobs.h:271
~SinglePatchJob()
Definition GeoPatchJobs.cpp:115
virtual void OnRun()
Definition GeoPatchJobs.cpp:96
virtual void OnFinish()
Definition GeoPatchJobs.cpp:89
Definition SystemPath.h:13
Definition Terrain.h:25
Definition Color.h:167
Definition GeoPatchJobs.h:127
double * heights
Definition GeoPatchJobs.h:141
vector3d v1
Definition GeoPatchJobs.h:144
vector3f * normals
Definition GeoPatchJobs.h:142
Color3ub * colors
Definition GeoPatchJobs.h:143
vector3d v2
Definition GeoPatchJobs.h:144
SSplitResultData()
Definition GeoPatchJobs.h:128
vector3d v0
Definition GeoPatchJobs.h:144
SSplitResultData(double *heights_, vector3f *n_, Color3ub *c_, const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_, const GeoPatchID &patchID_)
Definition GeoPatchJobs.h:130
vector3d v3
Definition GeoPatchJobs.h:144
GeoPatchID patchID
Definition GeoPatchJobs.h:145