OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 "object/C4Object.h"
23 #include "graphics/C4Surface.h"
24 #include "graphics/C4FacetEx.h"
27 #include "lib/C4Rect.h"
28 
29 #include <vector>
30 
37 {
38  friend class C4FoW;
39 public:
40  C4FoWLight(C4Object *pObj);
41  ~C4FoWLight();
42 
43 private:
44  int32_t iX, iY; // center position
45  int32_t iReach; // maximum length of beams
46  int32_t iFadeout; // number of pixels over which beams fade out
47  int32_t iSize; // size of the light source. Decides smoothness of shadows
48  float gBright; // brightness of the light source. 1.0 is maximum.
49  float colorR; // red color component of the light source. 1.0 is maximum.
50  float colorG; // green color component of the light source. 1.0 is maximum.
51  float colorB; // blue color component of the light source. 1.0 is maximum.
52  float colorV; // color value. 1.0 is maximum.
53  float colorL; // color lightness. 1.0 is maximum.
54  C4FoWLight *pNext;
55  C4Object *pObj; // Associated object
56 
57  std::vector<C4FoWLightSection*> sections;
58 
59 public:
60  int32_t getX() const { return iX; }
61  int32_t getY() const { return iY; }
62  int32_t getReach() const { return iReach; }
63  int32_t getFadeout() const { return iFadeout; }
64  int32_t getTotalReach() const { return iReach + iFadeout; }
65  int32_t getSize() const { return iSize; }
66  int32_t getNormalSize() const { return iSize * 2; }
67  float getBrightness() const { return colorV * gBright; }
68  float getR() const { return colorR; }
69  float getG() const { return colorG; }
70  float getB() const { return colorB; }
71  float getValue() const { return colorV; }
72  float getLightness() const { return colorL; }
73  C4FoWLight *getNext() const { return pNext; }
74  C4Object *getObj() const { return pObj; }
75 
78  void SetReach(int32_t iReach, int32_t iFadeout);
79 
81  void SetColor(uint32_t iValue);
82 
84  void Invalidate(C4Rect r);
86  void Update(C4Rect r);
88  void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4ShaderCall& call);
89 
90  bool IsVisibleForPlayer(C4Player *player) const; // check if attached to an object that is not hostile to the given player
91 
92 private:
93  typedef std::list<class C4FoWBeamTriangle> TriangleList;
94 
96  void CalculateFanMaxed(TriangleList &triangles) const;
98  void CalculateIntermediateFadeTriangles(TriangleList &triangles) const;
99 
100  void ProjectPointOutward(float &x, float &y, float maxDistance) const;
101 
103  void DrawFan(class C4FoWDrawStrategy* pen, TriangleList &triangles) const;
105  void DrawFanMaxed(class C4FoWDrawStrategy* pen, TriangleList &triangles) const;
107  void DrawFade(C4FoWDrawStrategy* pen, TriangleList &triangles) const;
109  void DrawIntermediateFadeTriangles(C4FoWDrawStrategy* pen, TriangleList &triangles) const;
112  float GetSquaredDistanceTo(int32_t x, int32_t y) const { return (x - getX()) * (x - getX()) + (y - getY()) * (y - getY()); }
113 
114  /* Draw strategy instances. We keep them around once created, so they can
115  * reuse a VBO between individual renderings. */
116  std::unique_ptr<C4FoWDrawStrategy> OnScreenStrategy;
117  std::unique_ptr<C4FoWDrawStrategy> OffScreenStrategy;
118 };
119 
120 #endif
121 
122 #endif
float getBrightness() const
Definition: C4FoWLight.h:67
void SetColor(uint32_t iValue)
Definition: C4FoWLight.cpp:83
C4Object * getObj() const
Definition: C4FoWLight.h:74
float getR() const
Definition: C4FoWLight.h:68
int32_t getY() const
Definition: C4FoWLight.h:61
int32_t getFadeout() const
Definition: C4FoWLight.h:63
float getB() const
Definition: C4FoWLight.h:70
void Update(C4Rect r)
Definition: C4FoWLight.cpp:99
void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen, C4ShaderCall &call)
Definition: C4FoWLight.cpp:122
Definition: C4Rect.h:29
void Invalidate(C4Rect r)
Definition: C4FoWLight.cpp:54
int32_t getX() const
Definition: C4FoWLight.h:60
C4FoWLight * getNext() const
Definition: C4FoWLight.h:73
int32_t getSize() const
Definition: C4FoWLight.h:65
int32_t getTotalReach() const
Definition: C4FoWLight.h:64
float getLightness() const
Definition: C4FoWLight.h:72
float getValue() const
Definition: C4FoWLight.h:71
Definition: C4FoW.h:101
int32_t getNormalSize() const
Definition: C4FoWLight.h:66
float getG() const
Definition: C4FoWLight.h:69
int32_t getReach() const
Definition: C4FoWLight.h:62
C4FoWLight(C4Object *pObj)
Definition: C4FoWLight.cpp:31
bool IsVisibleForPlayer(C4Player *player) const
Definition: C4FoWLight.cpp:370
void SetReach(int32_t iReach, int32_t iFadeout)
Definition: C4FoWLight.cpp:60
int iSize
Definition: TstC4NetIO.cpp:35