OpenClonk
C4Sky Class Reference

#include <C4Sky.h>

Collaboration diagram for C4Sky:
[legend]

Public Member Functions

 C4Sky ()
 
 ~C4Sky ()
 
void Default ()
 
bool Init (bool fSavegame, std::string names="")
 
void Clear ()
 
void SetColor (int32_t iIndex, int32_t iRed, int32_t iGreen, int32_t iBlue)
 
void SetFadePalette (int32_t *ipColors)
 
void Draw (C4TargetFacet &cgo)
 
DWORD GetSkyFadeClr (int32_t iY)
 
void Execute ()
 
bool SetModulation (DWORD dwWithClr, DWORD dwBackClr)
 
DWORD GetModulation (bool fBackClr)
 
void CompileFunc (StdCompiler *pComp)
 

Public Attributes

class C4SurfaceSurface
 
C4Shader Shader
 
C4Shader ShaderLight
 
C4Real xdir
 
C4Real ydir
 
C4Real x
 
C4Real y
 
int32_t ParX
 
int32_t ParY
 
uint32_t FadeClr1
 
uint32_t FadeClr2
 
int32_t ParallaxMode
 

Protected Attributes

int32_t Width
 
int32_t Height
 
uint32_t Modulation
 
int32_t BackClr
 
bool BackClrEnabled
 

Detailed Description

Definition at line 28 of file C4Sky.h.

Constructor & Destructor Documentation

◆ C4Sky()

C4Sky::C4Sky ( )
inline

Definition at line 31 of file C4Sky.h.

31 { Default(); }
void Default()
Definition: C4Sky.cpp:142

References Default().

Here is the call graph for this function:

◆ ~C4Sky()

C4Sky::~C4Sky ( )

Definition at line 154 of file C4Sky.cpp.

155 {
156  Clear();
157 }
void Clear()
Definition: C4Sky.cpp:159

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4Sky::Clear ( )

Definition at line 159 of file C4Sky.cpp.

160 {
161  Shader.Clear();
162  ShaderLight.Clear();
163  delete Surface; Surface=nullptr;
164  Modulation=0xffffffff;
165 }
void Clear()
Definition: C4Shader.cpp:335
class C4Surface * Surface
Definition: C4Sky.h:52
C4Shader ShaderLight
Definition: C4Sky.h:54
uint32_t Modulation
Definition: C4Sky.h:48
C4Shader Shader
Definition: C4Sky.h:53

References C4Shader::Clear(), Modulation, Shader, ShaderLight, and Surface.

Referenced by ~C4Sky().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4Sky::CompileFunc ( StdCompiler pComp)

Definition at line 237 of file C4Sky.cpp.

238 {
239  pComp->Value(mkNamingAdapt(mkCastIntAdapt(x), "X", Fix0));
240  pComp->Value(mkNamingAdapt(mkCastIntAdapt(y), "Y", Fix0));
241  pComp->Value(mkNamingAdapt(mkCastIntAdapt(xdir),"XDir", Fix0));
242  pComp->Value(mkNamingAdapt(mkCastIntAdapt(ydir),"YDir", Fix0));
243  pComp->Value(mkNamingAdapt(Modulation, "Modulation", 0xffffffffU));
244  pComp->Value(mkNamingAdapt(ParX, "ParX", 10));
245  pComp->Value(mkNamingAdapt(ParY, "ParY", 10));
246  pComp->Value(mkNamingAdapt(ParallaxMode, "ParMode", C4SkyPM_Fixed));
247  pComp->Value(mkNamingAdapt(BackClr, "BackClr", 0));
248  pComp->Value(mkNamingAdapt(BackClrEnabled, "BackClrEnabled", false));
249 }
const C4Real Fix0
Definition: C4Real.h:312
#define C4SkyPM_Fixed
Definition: C4Sky.h:25
StdCastAdapt< T, int32_t > mkCastIntAdapt(T &rValue)
Definition: StdAdaptors.h:281
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4Real y
Definition: C4Sky.h:56
bool BackClrEnabled
Definition: C4Sky.h:50
int32_t ParX
Definition: C4Sky.h:57
C4Real x
Definition: C4Sky.h:56
int32_t ParallaxMode
Definition: C4Sky.h:59
C4Real xdir
Definition: C4Sky.h:55
int32_t ParY
Definition: C4Sky.h:57
C4Real ydir
Definition: C4Sky.h:55
int32_t BackClr
Definition: C4Sky.h:49
void Value(const T &rStruct)
Definition: StdCompiler.h:161

References BackClr, BackClrEnabled, C4SkyPM_Fixed, Fix0, mkCastIntAdapt(), mkNamingAdapt(), Modulation, ParallaxMode, ParX, ParY, StdCompiler::Value(), x, xdir, y, and ydir.

Here is the call graph for this function:

◆ Default()

void C4Sky::Default ( )

Definition at line 142 of file C4Sky.cpp.

143 {
144  Width=Height=0;
145  Surface=nullptr;
146  x=y=xdir=ydir=0;
147  Modulation=0xffffffff;
148  ParX=ParY=10;
150  BackClr=0;
151  BackClrEnabled=false;
152 }
int32_t Height
Definition: C4Sky.h:47
int32_t Width
Definition: C4Sky.h:47

References BackClr, BackClrEnabled, C4SkyPM_Fixed, Height, Modulation, ParallaxMode, ParX, ParY, Surface, Width, x, xdir, y, and ydir.

Referenced by C4Sky().

Here is the caller graph for this function:

◆ Draw()

void C4Sky::Draw ( C4TargetFacet cgo)

Definition at line 180 of file C4Sky.cpp.

181 {
182  // background color?
183  if (BackClrEnabled) pDraw->DrawBoxDw(cgo.Surface, cgo.X, cgo.Y, cgo.X+cgo.Wdt, cgo.Y+cgo.Hgt, BackClr);
184  // sky surface?
185  if (Modulation != 0xffffffff) pDraw->ActivateBlitModulation(Modulation);
186  C4ShaderCall call(pDraw->GetFoW() ? &ShaderLight : &Shader); // call is started in C4Draw
187  if (Surface)
188  {
189  // blit parallax sky
190  float zoom = cgo.Zoom;
191  float targetx = cgo.TargetX; float targety = cgo.TargetY;
192 
193  float parx = 10.0f / ParX; float pary = 10.0f / ParY;
194  float par = parx; //todo: pary?
195 
196  // Step 1: project to landscape coordinates
197  float resultzoom = 1.0 / (1.0 - (par - par/zoom));
198 
199  float rx = ((1 - parx) * targetx) * resultzoom + fixtof(x) / (parx + zoom - parx * zoom);
200  float ry = ((1 - pary) * targety) * resultzoom + fixtof(y) / (pary + zoom - pary * zoom);
201 
202  // Step 2: convert to screen coordinates
203  float resultx = (rx - targetx) * zoom / resultzoom;
204  float resulty = (ry - targety) * zoom / resultzoom;
205 
206  ZoomDataStackItem zdsi(resultzoom);
207 
208  pDraw->BlitSurfaceTile(Surface, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt * zoom / resultzoom, cgo.Hgt * zoom / resultzoom, -resultx, -resulty, &call);
209  }
210  else
211  {
212  // no sky surface: blit sky fade
213  DWORD dwClr1=GetSkyFadeClr(cgo.TargetY);
214  DWORD dwClr2=GetSkyFadeClr(cgo.TargetY+cgo.Hgt);
215  pDraw->DrawBoxFade(cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt, dwClr1, dwClr1, dwClr2, dwClr2, &call);
216  }
217  if (Modulation != 0xffffffff) pDraw->DeactivateBlitModulation();
218  // done
219 }
C4Draw * pDraw
Definition: C4Draw.cpp:42
float fixtof(const C4Fixed &x)
Definition: C4Real.h:257
uint32_t DWORD
const C4FoWRegion * GetFoW() const
Definition: C4Draw.h:194
void DrawBoxFade(C4Surface *sfcDest, float iX, float iY, float iWdt, float iHgt, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:824
void DeactivateBlitModulation()
Definition: C4Draw.h:189
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:840
void ActivateBlitModulation(DWORD dwWithClr)
Definition: C4Draw.h:188
bool BlitSurfaceTile(C4Surface *sfcSurface, C4Surface *sfcTarget, float iToX, float iToY, float iToWdt, float iToHgt, float iOffsetX, float iOffsetY, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:529
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
float Wdt
Definition: C4Facet.h:118
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
DWORD GetSkyFadeClr(int32_t iY)
Definition: C4Sky.cpp:221
float TargetY
Definition: C4Facet.h:165
float TargetX
Definition: C4Facet.h:165
float Zoom
Definition: C4Facet.h:165

References C4Draw::ActivateBlitModulation(), BackClr, BackClrEnabled, C4Draw::BlitSurfaceTile(), C4Draw::DeactivateBlitModulation(), C4Draw::DrawBoxDw(), C4Draw::DrawBoxFade(), fixtof(), C4Draw::GetFoW(), GetSkyFadeClr(), C4Facet::Hgt, Modulation, ParX, ParY, pDraw, Shader, ShaderLight, C4Facet::Surface, Surface, C4TargetFacet::TargetX, C4TargetFacet::TargetY, C4Facet::Wdt, C4Facet::X, x, C4Facet::Y, y, and C4TargetFacet::Zoom.

Referenced by C4Viewport::Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Execute()

void C4Sky::Execute ( )

Definition at line 167 of file C4Sky.cpp.

168 {
169  // surface exists?
170  if (!Surface) return;
171  // advance pos
172  x+=xdir; y+=ydir;
173  // clip by bounds
174  if (x>=itofix(Width)) x-=itofix(Width);
175  if (y>=itofix(Height)) y-=itofix(Height);
176  // update speed
178 }
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4Real C4REAL100(int x)
Definition: C4Real.h:267
#define C4SkyPM_Wind
Definition: C4Sky.h:26
C4Weather Weather
Definition: C4Weather.cpp:206
int32_t Wind
Definition: C4Weather.h:31

References C4REAL100(), C4SkyPM_Wind, Height, itofix(), ParallaxMode, Surface, Weather, Width, C4Weather::Wind, x, xdir, y, and ydir.

Here is the call graph for this function:

◆ GetModulation()

DWORD C4Sky::GetModulation ( bool  fBackClr)
inline

Definition at line 43 of file C4Sky.h.

44  { return fBackClr ? BackClr : Modulation; }

References BackClr, and Modulation.

◆ GetSkyFadeClr()

DWORD C4Sky::GetSkyFadeClr ( int32_t  iY)

Definition at line 221 of file C4Sky.cpp.

222 {
223  int32_t iPos2=(iY*256)/::Landscape.GetHeight(); int32_t iPos1=256-iPos2;
224  return (((((FadeClr1&0xff00ff)*iPos1 + (FadeClr2&0xff00ff)*iPos2) & 0xff00ff00)
225  | (((FadeClr1&0x00ff00)*iPos1 + (FadeClr2&0x00ff00)*iPos2) & 0x00ff0000))>>8)
226  | (FadeClr1 & 0xff000000);
227 }
C4Landscape Landscape
int32_t GetHeight() const
uint32_t FadeClr1
Definition: C4Sky.h:58
uint32_t FadeClr2
Definition: C4Sky.h:58

References FadeClr1, FadeClr2, C4Landscape::GetHeight(), and Landscape.

Referenced by Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

bool C4Sky::Init ( bool  fSavegame,
std::string  names = "" 
)

Definition at line 46 of file C4Sky.cpp.

47 {
48  // reset scrolling pos+speed
49  // not in savegame, because it will have been loaded from game data there
50  if (!fSavegame)
51  {
52  x=y=xdir=ydir=0; ParX=ParY=10; ParallaxMode=0;
53  }
54 
55  // Check for sky bitmap in scenario file
56  Surface = new C4Surface();
57  bool loaded = false;
58  if (names.empty())
59  {
61  }
62 
63  // Else, evaluate scenario core landscape sky default list
64  if (!loaded)
65  {
66  if (names.empty()) names = Game.C4S.Landscape.SkyDef;
67  static std::regex separator(R"([,;\s]+)");
68  std::vector<std::string> parts;
69  std::copy(
70  std::sregex_token_iterator(names.begin(), names.end(), separator, -1),
71  std::sregex_token_iterator(),
72  std::back_inserter(parts));
73 
74  auto name = parts.at(SeededRandom(Game.RandomSeed, parts.size()));
75  // Sky tile specified, try load
76  if (name != "Default")
77  {
78  // Check for sky tile in scenario file
79  loaded = !!Surface->LoadAny(Game.ScenarioFile, name.c_str(), true, true, C4SF_Tileable | C4SF_MipMap);
80  if (!loaded)
81  {
82  loaded = !!Surface->LoadAny(::GraphicsResource.Files, name.c_str(), true, false, C4SF_Tileable | C4SF_MipMap);
83  }
84  }
85  }
86 
87  if (loaded)
88  {
89  // surface loaded, store first color index
90  FadeClr1=FadeClr2=0xffffffff;
91 
92  // set parallax scroll mode
94  {
95  case 0: // default: no scrolling
96  break;
97  case 1: // go with the wind in xdir, and do some parallax scrolling in ydir
99  ParY=20;
100  break;
101  case 2: // parallax in both directions
102  ParX=ParY=20;
103  break;
104  }
105 
106  }
107 
108 
109  // Else, try creating default Surface
110  if (!loaded)
111  {
113  delete Surface;
114  Surface = nullptr;
115  }
116 
117  // Load sky shaders: regular sprite shaders with OC_SKY define
118  const char* const SkyDefines[] = { "OC_SKY", nullptr };
119  if (!pDraw->PrepareSpriteShader(Shader, "Sky", Surface ? C4SSC_BASE : 0, &::GraphicsResource.Files, SkyDefines, nullptr))
120  return false;
121  if (!pDraw->PrepareSpriteShader(ShaderLight, "SkyLight", (Surface ? C4SSC_BASE : 0) | C4SSC_LIGHT, &::GraphicsResource.Files, SkyDefines, nullptr))
122  return false;
123 
124  // no sky - using fade in newgfx
125  if (!Surface)
126  return true;
127 
128  // Store size
129  if (Surface)
130  {
131  int iWdt,iHgt;
132  if (Surface->GetSurfaceSize(iWdt, iHgt))
133  {
134  Width = iWdt; Height = iHgt;
135  }
136  }
137 
138  // Success
139  return true;
140 }
#define C4CFN_Sky
Definition: C4Components.h:65
C4Game Game
Definition: C4Globals.cpp:52
C4GraphicsResource GraphicsResource
uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange)
Definition: C4Random.cpp:69
const int C4SF_MipMap
Definition: C4Surface.h:50
const int C4SF_Tileable
Definition: C4Surface.h:49
virtual bool PrepareSpriteShader(C4Shader &shader, const char *name, int ssc, C4GroupSet *pGroups, const char *const *additionalDefines, const char *const *additionalSlices)=0
C4Scenario C4S
Definition: C4Game.h:74
int32_t RandomSeed
Definition: C4Game.h:135
C4Group ScenarioFile
Definition: C4Game.h:86
int32_t SkyDefFade[6]
Definition: C4Scenario.h:174
int32_t SkyScrollMode
Definition: C4Scenario.h:186
std::string SkyDef
Definition: C4Scenario.h:173
C4SLandscape Landscape
Definition: C4Scenario.h:236
void SetFadePalette(int32_t *ipColors)
Definition: C4Sky.cpp:30
bool LoadAny(C4Group &hGroup, const char *szFilename, bool fOwnPal, bool fNoErrIfNotFound, int iFlags)
bool GetSurfaceSize(int &irX, int &irY)
Definition: C4Surface.cpp:444

References C4CFN_Sky, C4Game::C4S, C4SF_MipMap, C4SF_Tileable, C4SkyPM_Wind, FadeClr1, FadeClr2, C4GraphicsResource::Files, Game, GraphicsResource, C4Scenario::Landscape, C4Surface::LoadAny(), ParallaxMode, ParX, ParY, pDraw, C4Draw::PrepareSpriteShader(), C4Game::RandomSeed, C4Game::ScenarioFile, SeededRandom(), SetFadePalette(), Shader, C4SLandscape::SkyDef, C4SLandscape::SkyDefFade, C4SLandscape::SkyScrollMode, Surface, x, xdir, y, and ydir.

Here is the call graph for this function:

◆ SetColor()

void C4Sky::SetColor ( int32_t  iIndex,
int32_t  iRed,
int32_t  iGreen,
int32_t  iBlue 
)

◆ SetFadePalette()

void C4Sky::SetFadePalette ( int32_t *  ipColors)

Definition at line 30 of file C4Sky.cpp.

31 {
32  // If colors all zero, use game palette default blue
33  if (ipColors[0]+ipColors[1]+ipColors[2]+ipColors[3]+ipColors[4]+ipColors[5]==0)
34  {
35  FadeClr1=C4RGB(0x1c, 0x40, 0x99);
36  FadeClr2=C4RGB(0xc2, 0xc6, 0xff);
37  }
38  else
39  {
40  // set colors
41  FadeClr1=C4RGB(ipColors[0], ipColors[1], ipColors[2]);
42  FadeClr2=C4RGB(ipColors[3], ipColors[4], ipColors[5]);
43  }
44 }
#define C4RGB(r, g, b)
Definition: StdColors.h:26

References C4RGB, FadeClr1, and FadeClr2.

Referenced by Init().

Here is the caller graph for this function:

◆ SetModulation()

bool C4Sky::SetModulation ( DWORD  dwWithClr,
DWORD  dwBackClr 
)

Definition at line 229 of file C4Sky.cpp.

230 {
231  Modulation=dwWithClr;
232  BackClr=dwBackClr;
233  BackClrEnabled=(Modulation>>24 != 0xff) ? true : false;
234  return true;
235 }

References BackClr, BackClrEnabled, and Modulation.

Member Data Documentation

◆ BackClr

int32_t C4Sky::BackClr
protected

Definition at line 49 of file C4Sky.h.

Referenced by CompileFunc(), Default(), Draw(), GetModulation(), and SetModulation().

◆ BackClrEnabled

bool C4Sky::BackClrEnabled
protected

Definition at line 50 of file C4Sky.h.

Referenced by CompileFunc(), Default(), Draw(), and SetModulation().

◆ FadeClr1

uint32_t C4Sky::FadeClr1

Definition at line 58 of file C4Sky.h.

Referenced by GetSkyFadeClr(), Init(), and SetFadePalette().

◆ FadeClr2

uint32_t C4Sky::FadeClr2

Definition at line 58 of file C4Sky.h.

Referenced by GetSkyFadeClr(), Init(), and SetFadePalette().

◆ Height

int32_t C4Sky::Height
protected

Definition at line 47 of file C4Sky.h.

Referenced by Default(), and Execute().

◆ Modulation

uint32_t C4Sky::Modulation
protected

Definition at line 48 of file C4Sky.h.

Referenced by Clear(), CompileFunc(), Default(), Draw(), GetModulation(), and SetModulation().

◆ ParallaxMode

int32_t C4Sky::ParallaxMode

Definition at line 59 of file C4Sky.h.

Referenced by CompileFunc(), Default(), Execute(), and Init().

◆ ParX

int32_t C4Sky::ParX

Definition at line 57 of file C4Sky.h.

Referenced by CompileFunc(), Default(), C4GraphicsSystem::DoSaveScreenshot(), Draw(), and Init().

◆ ParY

int32_t C4Sky::ParY

Definition at line 57 of file C4Sky.h.

Referenced by CompileFunc(), Default(), C4GraphicsSystem::DoSaveScreenshot(), Draw(), and Init().

◆ Shader

C4Shader C4Sky::Shader

Definition at line 53 of file C4Sky.h.

Referenced by Clear(), Draw(), and Init().

◆ ShaderLight

C4Shader C4Sky::ShaderLight

Definition at line 54 of file C4Sky.h.

Referenced by Clear(), and Draw().

◆ Surface

class C4Surface* C4Sky::Surface

Definition at line 52 of file C4Sky.h.

Referenced by Clear(), Default(), Draw(), Execute(), and Init().

◆ Width

int32_t C4Sky::Width
protected

Definition at line 47 of file C4Sky.h.

Referenced by Default(), and Execute().

◆ x

C4Real C4Sky::x

Definition at line 56 of file C4Sky.h.

Referenced by CompileFunc(), Default(), Draw(), Execute(), and Init().

◆ xdir

C4Real C4Sky::xdir

Definition at line 55 of file C4Sky.h.

Referenced by CompileFunc(), Default(), Execute(), and Init().

◆ y

C4Real C4Sky::y

Definition at line 56 of file C4Sky.h.

Referenced by CompileFunc(), Default(), Draw(), Execute(), and Init().

◆ ydir

C4Real C4Sky::ydir

Definition at line 55 of file C4Sky.h.

Referenced by CompileFunc(), Default(), Execute(), and Init().


The documentation for this class was generated from the following files: