OpenClonk
C4FoWLight.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2014-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 #ifndef C4FOWLIGHT_H
16 #define C4FOWLIGHT_H
17 
19 
20 #ifndef USE_CONSOLE
21 
22 #include "graphics/C4FacetEx.h"
23 #include "graphics/C4Surface.h"
26 #include "lib/C4Rect.h"
27 #include "object/C4Object.h"
28 
35 {
36  friend class C4FoW;
37 public:
38  C4FoWLight(C4Object *pObj);
39  ~C4FoWLight();
40 
41 private:
42  int32_t iX, iY; // center position
43  int32_t iReach; // maximum length of beams
44  int32_t iFadeout; // number of pixels over which beams fade out
45  int32_t iSize; // size of the light source. Decides smoothness of shadows
46  float gBright; // brightness of the light source. 1.0 is maximum.
47  float colorR; // red color component of the light source. 1.0 is maximum.
48  float colorG; // green color component of the light source. 1.0 is maximum.
49  float colorB; // blue color component of the light source. 1.0 is maximum.
50  float colorV; // color value. 1.0 is maximum.
51  float colorL; // color lightness. 1.0 is maximum.
52  C4FoWLight *pNext;
53  C4Object *pObj; // Associated object
54 
55  std::vector<C4FoWLightSection*> sections;
56 
57 public:
58  int32_t getX() const { return iX; }
59  int32_t getY() const { return iY; }
60  int32_t getReach() const { return iReach; }
61  int32_t getFadeout() const { return iFadeout; }
62  int32_t getTotalReach() const { return iReach + iFadeout; }
63  int32_t getSize() const { return iSize; }
64  int32_t getNormalSize() const { return iSize * 2; }
65  float getBrightness() const { return colorV * gBright; }
66  float getR() const { return colorR; }
67  float getG() const { return colorG; }
68  float getB() const { return colorB; }
69  float getValue() const { return colorV; }
70  float getLightness() const { return colorL; }
71  C4FoWLight *getNext() const { return pNext; }
72  C4Object *getObj() const { return pObj; }
73 
76  void SetReach(int32_t iReach, int32_t iFadeout);
77 
79  void SetColor(uint32_t iValue);
80 
82  void Invalidate(C4Rect r);
84  void Update(C4Rect r);
86  void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4ShaderCall& call);
87 
88  bool IsVisibleForPlayer(C4Player *player) const; // check if attached to an object that is not hostile to the given player
89 
90 private:
91  typedef std::list<class C4FoWBeamTriangle> TriangleList;
92 
94  void CalculateFanMaxed(TriangleList &triangles) const;
96  void CalculateIntermediateFadeTriangles(TriangleList &triangles) const;
97 
98  void ProjectPointOutward(float &x, float &y, float maxDistance) const;
99 
101  void DrawFan(class C4FoWDrawStrategy* pen, TriangleList &triangles) const;
103  void DrawFanMaxed(class C4FoWDrawStrategy* pen, TriangleList &triangles) const;
105  void DrawFade(C4FoWDrawStrategy* pen, TriangleList &triangles) const;
107  void DrawIntermediateFadeTriangles(C4FoWDrawStrategy* pen, TriangleList &triangles) const;
110  float GetSquaredDistanceTo(int32_t x, int32_t y) const { return (x - getX()) * (x - getX()) + (y - getY()) * (y - getY()); }
111 
112  /* Draw strategy instances. We keep them around once created, so they can
113  * reuse a VBO between individual renderings. */
114  std::unique_ptr<C4FoWDrawStrategy> OnScreenStrategy;
115  std::unique_ptr<C4FoWDrawStrategy> OffScreenStrategy;
116 };
117 
118 #endif
119 
120 #endif
int iSize
Definition: TstC4NetIO.cpp:32
Definition: C4FoW.h:102
C4FoWLight(C4Object *pObj)
Definition: C4FoWLight.cpp:29
void SetReach(int32_t iReach, int32_t iFadeout)
Definition: C4FoWLight.cpp:58
float getBrightness() const
Definition: C4FoWLight.h:65
C4Object * getObj() const
Definition: C4FoWLight.h:72
int32_t getX() const
Definition: C4FoWLight.h:58
void SetColor(uint32_t iValue)
Definition: C4FoWLight.cpp:81
void Invalidate(C4Rect r)
Definition: C4FoWLight.cpp:52
void Update(C4Rect r)
Definition: C4FoWLight.cpp:97
float getB() const
Definition: C4FoWLight.h:68
float getValue() const
Definition: C4FoWLight.h:69
int32_t getTotalReach() const
Definition: C4FoWLight.h:62
bool IsVisibleForPlayer(C4Player *player) const
Definition: C4FoWLight.cpp:364
void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4ShaderCall &call)
Definition: C4FoWLight.cpp:120
int32_t getSize() const
Definition: C4FoWLight.h:63
float getR() const
Definition: C4FoWLight.h:66
int32_t getFadeout() const
Definition: C4FoWLight.h:61
int32_t getNormalSize() const
Definition: C4FoWLight.h:64
float getLightness() const
Definition: C4FoWLight.h:70
C4FoWLight * getNext() const
Definition: C4FoWLight.h:71
int32_t getY() const
Definition: C4FoWLight.h:59
float getG() const
Definition: C4FoWLight.h:67
int32_t getReach() const
Definition: C4FoWLight.h:60
Definition: C4Rect.h:28