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 #include "lib/StdBuf.h"
23 
38 class C4FoWBeam
39 {
40 public:
41  C4FoWBeam(int32_t iLeftX, int32_t iLeftY, int32_t iRightX, int32_t iRightY)
42  : iLeftX(iLeftX), iLeftY(iLeftY), iRightX(iRightX), iRightY(iRightY),
43  iLeftEndY(0), iRightEndY(0),
44  iError(0),
45  fDirty(true),
46  pNext(nullptr)
47  { }
48 
49 private:
50  int32_t iLeftX, iLeftY; // left delimiter point
51  int32_t iRightX, iRightY; // right delimiter point
52  int32_t iLeftEndY, iRightEndY; // where it hit solid material.
53  int32_t iError; // How much error this beam has
54  bool fDirty; // landscape changed since it was followed?
55  C4FoWBeam *pNext;
56 
57 public:
58  bool isDirty() const { return fDirty; }
59  bool isClean() const { return !fDirty; }
60  C4FoWBeam *getNext() const { return pNext; }
61  void setNext(C4FoWBeam *next) { pNext=next; }
62 
63  // Get a point on the beam boundary.
64  inline int32_t getLeftX(int32_t y) const { return iLeftX * y / iLeftY; }
65  inline int32_t getRightX(int32_t y) const { return iRightX * y / iRightY; }
66  inline float getLeftXf(int32_t y) const { return (iLeftX * y) / float(iLeftY); }
67  inline float getRightXf(int32_t y) const { return (iRightX * y) / float(iRightY); }
68 
69  int32_t getLeftEndY() const { return iLeftEndY; }
70  int32_t getLeftEndX() const { return getLeftX(iLeftEndY); }
71  float getLeftEndXf() const { return getLeftXf(iLeftEndY); }
72  int32_t getRightEndY() const { return iRightEndY; }
73  int32_t getRightEndX() const { return getRightX(iRightEndY); }
74  float getRightEndXf() const { return getRightXf(iRightEndY); }
75 
76  StdStrBuf getDesc() const;
77 
79  bool isLeft(int32_t x, int32_t y) const {
80  return iLeftX * y > x * iLeftY;
81  }
82 
84  bool isRight(int32_t x, int32_t y) const {
85  return iRightX * y < x * iRightY;
86  }
87 
89  bool isInside(int32_t x, int32_t y) const {
90  return !isLeft(x, y) && !isRight(x, y);
91  }
92 
93  void SetLeft(int32_t x, int32_t y) { iLeftX = x; iLeftY = y; }
94  void SetRight(int32_t x, int32_t y) { iRightX = x; iRightY = y; }
95 
101  bool MergeRight(int32_t x, int32_t y);
102 
108  bool MergeLeft(int32_t x, int32_t y);
109 
113  C4FoWBeam *Split(int32_t x, int32_t y);
119  bool EliminateRight(int32_t x, int32_t y);
120 
121  void MergeDirty();
122 
124  void Clean(int32_t y);
125 
128  void Dirty(int32_t y);
129 
132  void Prune(int32_t y);
133 
134  // Serialization for debugging
135  void CompileFunc(StdCompiler *pComp);
136 
137 };
138 
139 #endif
140 
141 #endif // C4FOWBEAM
bool isRight(int32_t x, int32_t y) const
Definition: C4FoWBeam.h:84
bool EliminateRight(int32_t x, int32_t y)
Definition: C4FoWBeam.cpp:90
int32_t getLeftEndY() const
Definition: C4FoWBeam.h:69
int32_t getLeftX(int32_t y) const
Definition: C4FoWBeam.h:64
void SetLeft(int32_t x, int32_t y)
Definition: C4FoWBeam.h:93
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:65
int32_t getRightEndY() const
Definition: C4FoWBeam.h:72
int32_t getRightEndX() const
Definition: C4FoWBeam.h:73
bool isDirty() const
Definition: C4FoWBeam.h:58
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:79
StdStrBuf getDesc() const
Definition: C4FoWBeam.cpp:36
float getLeftEndXf() const
Definition: C4FoWBeam.h:71
C4FoWBeam * getNext() const
Definition: C4FoWBeam.h:60
bool isClean() const
Definition: C4FoWBeam.h:59
float getRightXf(int32_t y) const
Definition: C4FoWBeam.h:67
int32_t getLeftEndX() const
Definition: C4FoWBeam.h:70
void setNext(C4FoWBeam *next)
Definition: C4FoWBeam.h:61
C4FoWBeam(int32_t iLeftX, int32_t iLeftY, int32_t iRightX, int32_t iRightY)
Definition: C4FoWBeam.h:41
float getRightEndXf() const
Definition: C4FoWBeam.h:74
void SetRight(int32_t x, int32_t y)
Definition: C4FoWBeam.h:94
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:66
C4FoWBeam * Split(int32_t x, int32_t y)
Definition: C4FoWBeam.cpp:117
bool isInside(int32_t x, int32_t y) const
Definition: C4FoWBeam.h:89
void CompileFunc(StdCompiler *pComp)
Definition: C4FoWBeam.cpp:188