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
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#pragma once
#include "StarEither.hpp"
#include "StarNetElementSystem.hpp"
#include "StarCelestialParameters.hpp"
#include "StarSkyParameters.hpp"
#include "StarSkyRenderData.hpp"
namespace Star {
STAR_CLASS(Clock);
STAR_CLASS(AudioInstance);
STAR_CLASS(Sky);
// Sky objects, such as stars and orbiters, are given in a pseudo screen space,
// "view space", that does not take the pixel ratio into account. "viewSize"
// is the size of this space, expected to be the size of the screen *after*
// dividing by the pixel ratio.
class Sky {
public:
Sky();
Sky(SkyParameters const& skyParameters, bool inOrbit);
// Controls the space sky "flight" system
void startFlying(bool enterHyperspace, bool startInWarp, Json settings = {});
// Stops flying animation copying the new pertinant sky data from the given
// sky, as though the sky as moved to a new world.
void stopFlyingAt(Maybe<SkyParameters> SkyParameters);
void jumpTo(SkyParameters SkyParameters);
pair<ByteArray, uint64_t> writeUpdate(uint64_t fromVersion = 0, NetCompatibilityRules rules = {});
void readUpdate(ByteArray data, NetCompatibilityRules rules = {});
// handles flying and warp state transitions
void stateUpdate();
void update(double dt);
void setType(SkyType type);
SkyType type() const;
bool inSpace() const;
uint64_t seed() const;
float dayLength() const;
uint32_t day() const;
float timeOfDay() const;
// Total time since the 0th day for this world.
double epochTime() const;
void setEpochTime(double epochTime);
// Altitude is used to determine, in Atmospheric skies, the percentage of the
// atmosphere to draw and how much like space it should appear.
float altitude() const;
void setAltitude(float altitude);
// If a reference clock is set, then the epoch time is driven by the
// reference clock rather than an internal timer
void setReferenceClock(ClockConstPtr const& referenceClock);
ClockConstPtr referenceClock() const;
String ambientNoise() const;
List<AudioInstancePtr> pullSounds();
// How close is the atmosphere to space?
float spaceLevel() const;
float orbitAngle() const;
bool isDayTime() const;
// Ranges from 0.0 to 1.0 Blended periodic curve with a period of
// clock.dayLength, and the blend region size is determined by
// the variant asset "dayTransitionTime"
float dayLevel() const;
// Returns a value that cycles through the range [0.0, 4.0). 0.0 / 4.0 is
// mid-morning, 1.0 is mid-day, 2.0 is mid-evening, and 3.0 is mid-night.
// Does not cycle through evenly, the value will "stick" to mid-day and
// mid-night based on the value of the variant asset "dayTransitionTime"
float dayCycle() const;
float skyAlpha() const;
Color environmentLight() const;
Color mainSkyColor() const;
// Base sky rect colors, top and bottom, includes calculation based on day /
// night alpha
pair<Color, Color> skyRectColors() const;
Color skyFlashColor() const;
bool flying() const;
FlyingType flyingType() const;
float warpProgress() const;
WarpPhase warpPhase() const;
bool inHyperspace() const;
SkyRenderData renderData() const;
private:
// TODO: This needs to be more explicit/handled better
static constexpr float DefaultDayLength = 1000.0f;
void writeNetStates();
void readNetStates();
void enterHyperspace();
void exitHyperspace();
bool controlledMovement(JsonArray const& path, Json const& origin, float timeOffset);
Vec2F getStarOffset() const;
float getStarRotation() const;
Vec2F getWorldOffset() const;
float getWorldRotation() const;
float speedupTime() const;
float slowdownTime() const;
void skyParametersUpdated();
Json m_settings;
SkyParameters m_skyParameters;
bool m_skyParametersUpdated;
SkyType m_skyType = SkyType::Orbital;
double m_time = 0.0;
ClockConstPtr m_referenceClock;
Maybe<double> m_clockTrackingTime;
float m_altitude = 0.0f;
FlyingType m_flyingType = FlyingType::None;
FlyingType m_lastFlyingType = FlyingType::None;
double m_flyingTimer = 0.0;
bool m_enterHyperspace = false;
bool m_startInWarp = false;
WarpPhase m_warpPhase = WarpPhase::Maintain;
WarpPhase m_lastWarpPhase = WarpPhase::Maintain;
double m_flashTimer = 0.0;
// The star and world offsets and rotations must be different for two
// reasons: #1, the stars rotate over time, meaning that if they're not
// different then the world will fly off in a random direction when we leave
// #2, the stars move at a different, slower rate, controlled by JSON
// "starVelocityFactor", because they're farther away
Vec2F m_starOffset;
double m_starRotation = 0.0;
Vec2F m_starMoveOffset;
Vec2F m_worldOffset;
float m_worldRotation = 0.0f;
Vec2F m_worldMoveOffset;
// Finally, these are the offsets for the disembark and arrival paths they
// are applied to BOTH world and star offsets governed by the
// starVelocityFactor in the latter case
Vec2F m_pathOffset;
float m_pathRotation = 0.0f;
size_t m_starFrames = 0;
StringList m_starList;
StringList m_hyperStarList;
bool m_sentSFX = false;
Maybe<SkyParameters> m_destWorld;
bool m_netInit;
NetElementTopGroup m_netGroup;
NetElementBytes m_skyParametersNetState;
NetElementInt m_skyTypeNetState;
NetElementDouble m_timeNetState;
NetElementUInt m_flyingTypeNetState;
NetElementBool m_enterHyperspaceNetState;
NetElementBool m_startInWarpNetState;
NetElementInt m_warpPhaseNetState;
NetElementData<Vec2F> m_worldMoveNetState;
NetElementData<Vec2F> m_starMoveNetState;
NetElementFloat m_flyingTimerNetState;
};
}
|