Pioneer
Loading...
Searching...
No Matches
GeoSphere.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _GEOSPHERE_H
5#define _GEOSPHERE_H
6
7#include <SDL_stdinc.h>
8
9#include "BaseSphere.h"
10#include "Camera.h"
11#include "vector3.h"
12
13#include <deque>
14
15namespace Graphics {
16 class Renderer;
17 class Texture;
18}
19
20class SystemBody;
21class GeoPatch;
22class GeoPatchContext;
26
27#define NUM_PATCHES 6
28
29class GeoSphere : public BaseSphere {
30public:
31 GeoSphere(const SystemBody *body);
32 virtual ~GeoSphere();
33
34 virtual void Update() override;
35 virtual void Render(Graphics::Renderer *renderer, const matrix4x4d &modelView, vector3d campos, const float radius, const std::vector<Camera::Shadow> &shadows) override;
36
37 virtual double GetHeight(const vector3d &p) const override final
38 {
39 const double h = m_terrain->GetHeight(p);
40#ifdef DEBUG
41 // XXX don't remove this. Fix your fractals instead
42 // Fractals absolutely MUST return heights >= 0.0 (one planet radius)
43 // otherwise atmosphere and other things break.
44 if (h < 0.0) {
45 Output("GetHeight({ %f, %f, %f }) returned %f\n", p.x, p.y, p.z, h);
46 m_terrain->DebugDump();
47 assert(h >= 0.0);
48 }
49#endif /* DEBUG */
50 return h;
51 }
52
53 static void Init();
54 static void Uninit();
55 static void UpdateAllGeoSpheres();
56 static void OnChangeDetailLevel();
57 static bool OnAddQuadSplitResult(const SystemPath &path, SQuadSplitResult *res);
58 static bool OnAddSingleSplitResult(const SystemPath &path, SSingleSplitResult *res);
59 // in sbody radii
60 virtual double GetMaxFeatureHeight() const override final { return m_terrain->GetMaxHeight(); }
61
65
66 virtual void Reset() override;
67
68 inline Sint32 GetMaxDepth() const { return m_maxDepth; }
69
71
72private:
73 void BuildFirstPatches();
74 void CalculateMaxPatchDepth();
75 inline vector3d GetColor(const vector3d &p, double height, const vector3d &norm) const
76 {
77 return m_terrain->GetColor(p, height, norm);
78 }
79 void ProcessQuadSplitRequests();
80
81 std::unique_ptr<GeoPatch> m_patches[6];
82 struct TDistanceRequest {
83 TDistanceRequest(double dist, SQuadSplitRequest *pRequest, GeoPatch *pRequester) :
84 mDistance(dist),
85 mpRequest(pRequest),
86 mpRequester(pRequester) {}
87 double mDistance;
88 SQuadSplitRequest *mpRequest;
89 GeoPatch *mpRequester;
90 };
91 std::deque<TDistanceRequest> mQuadSplitRequests;
92
93 static const uint32_t MAX_SPLIT_OPERATIONS = 128;
94 std::deque<SQuadSplitResult *> mQuadSplitResults;
95 std::deque<SSingleSplitResult *> mSingleSplitResults;
96
97 bool m_hasTempCampos;
98 vector3d m_tempCampos;
99 Graphics::Frustum m_tempFrustum;
100
101 static RefCountedPtr<GeoPatchContext> s_patchContext;
102
103 virtual void SetUpMaterials() override;
104 void CreateAtmosphereMaterial();
105
108
109 enum EGSInitialisationStage {
110 eBuildFirstPatches = 0,
111 eRequestedFirstPatches,
112 eReceivedFirstPatches,
113 eDefaultUpdateState
114 };
115 EGSInitialisationStage m_initStage;
116
117 Sint32 m_maxDepth;
118};
119
120#endif /* _GEOSPHERE_H */
void Output(const char *message, Args... args)
Definition: Log.h:118
Definition: BaseSphere.h:21
RefCountedPtr< Terrain > m_terrain
Definition: BaseSphere.h:54
Definition: GeoPatchContext.h:18
Definition: GeoPatch.h:40
Definition: GeoSphere.h:29
virtual double GetHeight(const vector3d &p) const override final
Definition: GeoSphere.h:37
static bool OnAddSingleSplitResult(const SystemPath &path, SSingleSplitResult *res)
Definition: GeoSphere.cpp:113
Sint32 GetMaxDepth() const
Definition: GeoSphere.h:68
bool AddSingleSplitResult(SSingleSplitResult *res)
Definition: GeoSphere.cpp:216
virtual double GetMaxFeatureHeight() const override final
Definition: GeoSphere.h:60
bool AddQuadSplitResult(SQuadSplitResult *res)
Definition: GeoSphere.cpp:204
virtual ~GeoSphere()
Definition: GeoSphere.cpp:197
virtual void Update() override
Definition: GeoSphere.cpp:327
static bool OnAddQuadSplitResult(const SystemPath &path, SQuadSplitResult *res)
Definition: GeoSphere.cpp:95
virtual void Reset() override
Definition: GeoSphere.cpp:130
void AddQuadSplitRequest(double, SQuadSplitRequest *, GeoPatch *)
Definition: GeoSphere.cpp:361
static void Uninit()
Definition: GeoSphere.cpp:48
static void UpdateAllGeoSpheres()
Definition: GeoSphere.cpp:65
virtual void Render(Graphics::Renderer *renderer, const matrix4x4d &modelView, vector3d campos, const float radius, const std::vector< Camera::Shadow > &shadows) override
Definition: GeoSphere.cpp:377
static void Init()
Definition: GeoSphere.cpp:43
void ProcessSplitResults()
Definition: GeoSphere.cpp:228
static void OnChangeDetailLevel()
Definition: GeoSphere.cpp:74
Definition: Frustum.h:17
Definition: Renderer.h:45
Definition: RefCounted.h:36
Definition: GeoPatchJobs.h:54
Definition: GeoPatchJobs.h:170
Definition: GeoPatchJobs.h:213
Definition: SystemBody.h:137
Definition: SystemPath.h:13
Definition: Background.h:14