OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4FoWBeam.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 
16 #ifndef C4FOWBEAM_H
17 #define C4FOWBEAM_H
18 
20 
21 #ifndef USE_CONSOLE
22 
37 class C4FoWBeam
38 {
39 public:
40  C4FoWBeam(int32_t iLeftX, int32_t iLeftY, int32_t iRightX, int32_t iRightY)
41  : iLeftX(iLeftX), iLeftY(iLeftY), iRightX(iRightX), iRightY(iRightY),
42  iLeftEndY(0), iRightEndY(0),
43  iError(0),
44  fDirty(true),
45  pNext(nullptr)
46  { }
47 
48 private:
49  int32_t iLeftX, iLeftY; // left delimiter point
50  int32_t iRightX, iRightY; // right delimiter point
51  int32_t iLeftEndY, iRightEndY; // where it hit solid material.
52  int32_t iError; // How much error this beam has
53  bool fDirty; // landscape changed since it was followed?
54  C4FoWBeam *pNext;
55 
56 public:
57  bool isDirty() const { return fDirty; }
58  bool isClean() const { return !fDirty; }
59  C4FoWBeam *getNext() const { return pNext; }
60  void setNext(C4FoWBeam *next) { pNext=next; }
61 
62  // Get a point on the beam boundary.
63  inline int32_t getLeftX(int32_t y) const { return iLeftX * y / iLeftY; }
64  inline int32_t getRightX(int32_t y) const { return iRightX * y / iRightY; }
65  inline float getLeftXf(int32_t y) const { return (iLeftX * y) / float(iLeftY); }
66  inline float getRightXf(int32_t y) const { return (iRightX * y) / float(iRightY); }
67 
68  int32_t getLeftEndY() const { return iLeftEndY; }
69  int32_t getLeftEndX() const { return getLeftX(iLeftEndY); }
70  float getLeftEndXf() const { return getLeftXf(iLeftEndY); }
71  int32_t getRightEndY() const { return iRightEndY; }
72  int32_t getRightEndX() const { return getRightX(iRightEndY); }
73  float getRightEndXf() const { return getRightXf(iRightEndY); }
74 
75  StdStrBuf getDesc() const;
76 
78  bool isLeft(int32_t x, int32_t y) const {
79  return iLeftX * y > x * iLeftY;
80  }
81 
83  bool isRight(int32_t x, int32_t y) const {
84  return iRightX * y < x * iRightY;
85  }
86 
88  bool isInside(int32_t x, int32_t y) const {
89  return !isLeft(x, y) && !isRight(x, y);
90  }
91 
92  void SetLeft(int32_t x, int32_t y) { iLeftX = x; iLeftY = y; }
93  void SetRight(int32_t x, int32_t y) { iRightX = x; iRightY = y; }
94 
100  bool MergeRight(int32_t x, int32_t y);
101 
107  bool MergeLeft(int32_t x, int32_t y);
108 
112  C4FoWBeam *Split(int32_t x, int32_t y);
118  bool EliminateRight(int32_t x, int32_t y);
119 
120  void MergeDirty();
121 
123  void Clean(int32_t y);
124 
127  void Dirty(int32_t y);
128 
131  void Prune(int32_t y);
132 
133  // Serialization for debugging
134  void CompileFunc(StdCompiler *pComp);
135 
136 };
137 
138 #endif
139 
140 #endif // C4FOWBEAM
bool isRight(int32_t x, int32_t y) const
Definition: C4FoWBeam.h:83
bool EliminateRight(int32_t x, int32_t y)
Definition: C4FoWBeam.cpp:90
int32_t getLeftEndY() const
Definition: C4FoWBeam.h:68
int32_t getLeftX(int32_t y) const
Definition: C4FoWBeam.h:63
void SetLeft(int32_t x, int32_t y)
Definition: C4FoWBeam.h:92
void Dirty(int32_t y)
Definition: C4FoWBeam.cpp:165
void MergeDirty()
Definition: C4FoWBeam.cpp:136
int32_t getRightX(int32_t y) const
Definition: C4FoWBeam.h:64
int32_t getRightEndY() const
Definition: C4FoWBeam.h:71
int32_t getRightEndX() const
Definition: C4FoWBeam.h:72
bool isDirty() const
Definition: C4FoWBeam.h:57
void Prune(int32_t y)
Definition: C4FoWBeam.cpp:173
void Clean(int32_t y)
Definition: C4FoWBeam.cpp:157
bool isLeft(int32_t x, int32_t y) const
Definition: C4FoWBeam.h:78
StdStrBuf getDesc() const
Definition: C4FoWBeam.cpp:36
float getLeftEndXf() const
Definition: C4FoWBeam.h:70
C4FoWBeam * getNext() const
Definition: C4FoWBeam.h:59
bool isClean() const
Definition: C4FoWBeam.h:58
float getRightXf(int32_t y) const
Definition: C4FoWBeam.h:66
int32_t getLeftEndX() const
Definition: C4FoWBeam.h:69
void setNext(C4FoWBeam *next)
Definition: C4FoWBeam.h:60
C4FoWBeam(int32_t iLeftX, int32_t iLeftY, int32_t iRightX, int32_t iRightY)
Definition: C4FoWBeam.h:40
float getRightEndXf() const
Definition: C4FoWBeam.h:73
void SetRight(int32_t x, int32_t y)
Definition: C4FoWBeam.h:93
bool MergeLeft(int32_t x, int32_t y)
Definition: C4FoWBeam.cpp:70
bool MergeRight(int32_t x, int32_t y)
Definition: C4FoWBeam.cpp:45
float getLeftXf(int32_t y) const
Definition: C4FoWBeam.h:65
C4FoWBeam * Split(int32_t x, int32_t y)
Definition: C4FoWBeam.cpp:117
bool isInside(int32_t x, int32_t y) const
Definition: C4FoWBeam.h:88
void CompileFunc(StdCompiler *pComp)
Definition: C4FoWBeam.cpp:188