My Project
BlockTemplate.h
1 #pragma once
2 #include "BlockCommon.h"
3 #include "BlockModel.h"
4 #include "ShapeAABB.h"
5 
6 namespace ParaEngine
7 {
8  class CBlockWorld;
9  class BlockTemplate;
10  class IBlockModelProvider;
11  class Block;
12  class CShapeAABB;
13 
16  {
17  public:
18  static const uint16_t g_maxRenderPriority;
19  enum BlockAttrubiteFlag
20  {
21  batt_obstruction = 0x0000001, //physical obstruction
22  batt_breakable = 0x0000002,
23  batt_solid = 0x0000004, //light obstruction
24  batt_liquid = 0x0000008,
25  batt_blendedTexture = 0x0000010,
26  batt_light = 0x0000020,
27  batt_cubeModel = 0x0000040,
28  batt_customModel = 0x0000080,
29 
30  batt_transparent = 0x0000100,
31  batt_twoTexture = 0x0000200, //two texture blend together
32  batt_alphaTestTexture = 0x0000400, //use alpha test
33 
34  batt_singleSideTex = 0x0000800,
35  batt_threeSideTex = 0x0001000,
36  batt_fourSideTex = 0x0002000,
37  batt_sixSideTex = 0x0004000,
38  batt_climbable = 0x0008000, // whether a biped can climb up/down vertically using this block.
39  batt_blockcamera = 0x0010000, // whether the block will block camera line of sight.
40 
41  batt_framemove = 0x0020000, // whether the block has a frame move function.
42  batt_onload = 0x0040000, // whether the block has a OnBlockLoaded function.
43  batt_color_data = 0x0080000, // whether the block contains color in its block data.
44 
45  batt_invisible = 0x0100000,// whether the block is invisible.
46 
47  batt_tiling = 0x0200000,
48  };
49 
50  BlockTemplate(uint16_t id,uint32_t attFlag, uint16_t category_id);
51 
52  ~BlockTemplate();
53 
54  void Init(uint32_t attFlag, uint16_t category_id);
55 
56  inline uint16_t GetID() const
57  {
58  return m_id;
59  }
60 
61  inline uint16_t GetCategoryID() const
62  {
63  return m_category_id;
64  }
65 
66  inline uint32_t GetAttFlag() const
67  {
68  return m_attFlag;
69  }
70 
72  inline bool IsMatchAttribute(uint32_t attFlags) const
73  {
74  return ((m_attFlag & attFlags) > 0);
75  }
76 
78  inline bool IsMatchAttributes(uint32_t dwMask, uint32_t attFlags) const
79  {
80  return ((m_attFlag & dwMask) == attFlags);
81  }
82 
84  inline bool IsMatchAttributeAll(uint32_t attFlags) const
85  {
86  return ((m_attFlag & attFlags) == attFlags);
87  }
88 
89 
94  inline bool HasColorData() const
95  {
96  return ((m_attFlag & batt_color_data) == batt_color_data);
97  }
98 
104  void SetAttribute(DWORD dwAtt, bool bTurnOn = true);
105 
107  inline uint8_t GetTorchLight()
108  {
109  return m_nLightValue;
110  }
111 
113  inline uint8_t GetLightValue() {
114  return m_nLightValue;
115  };
116 
118  void SetTorchLight(uint8_t value);
119 
121  inline bool IsShadowCaster() {return m_bIsShadowCaster;};
122 
123  void SetTexture0(const char* texName, int nIndex = 0);
124 
125  void SetTexture1(const char* texName);
126 
127  void SetNormalMap(const char* texName);
128 
129  TextureEntity* GetTexture0(uint32 nUserData = 0);
130 
131  TextureEntity* GetTexture1();
132 
133  inline TextureEntity* GetNormalMap()
134  {
135  return m_pNormalMap;
136  }
137 
138  inline uint16_t GetRenderPriority()
139  {
140  return m_renderPriority;
141  }
142 
144  void LoadModel(const std::string& sModelName);
145 
147  void SetAssociatedBlock(uint16_t associated_blockid);
148 
152  BlockModel& GetBlockModel(int nIndex = 0);
153  BlockModel& CreateGetBlockModel(int nIndex = 0);
154 
155  BlockModel& GetBlockModelByData(uint32 nData);
156 
160  BlockModel& GetBlockModel(CBlockWorld* pBlockManager, uint16_t bx, uint16_t by, uint16_t bz, uint16_t nBlockData = 0, Block** neighborBlocks = NULL);
161 
163  void GetAABB(CBlockWorld* pBlockManager, uint16_t bx, uint16_t by, uint16_t bz, CShapeAABB* pOutAABB);
164 
166  void GetBoundingBoxVertices(Vector3 * pVertices, int* pNumber);
167 
169  bool IsAssociatedBlockID(uint16_t block_id);
170 
174  inline bool canProvidePower(){return m_bProvidePower;}
175 
176  void setProvidePower(bool bValue);
177 
178  bool isBlockNormalCube();
179  bool isSolidBlock();
180 
183  float GetPhysicalHeight();
184  float GetPhysicalHeight(CBlockWorld* pBlockManager, uint16_t bx, uint16_t by, uint16_t bz);
185  void SetPhysicalHeight(float fHeight);
186 
187  //transparent object will always be renderer after solid object.
188  //default value are 0 for all templates
189  //@param: priority range in [0,15] higher value get higher priority
190  inline void SetRenderPriority(uint16_t priority)
191  {
192  if(priority > g_maxRenderPriority)
193  priority = g_maxRenderPriority;
194  m_renderPriority = priority;
195  }
196 
199  inline int32_t GetLightScatterStep() {
200  return m_lightScatterStep;
201  }
202 
203  /* value between [1,15]. 1 for air which is most transparent one.
204  * 15 for solid blocks.
205  */
206  inline int32_t GetLightOpacity() {
207  return m_lightOpacity;
208  }
209  void SetLightOpacity(int32 nValue);
210 
211 
213  inline bool IsFullyOpaque() {
214  return m_lightOpacity >= 15;
215  }
216 
218  inline bool HasOpacity() {
219  return m_lightOpacity > 1;
220  }
221 
223  inline bool IsTransparent() {
224  return m_lightOpacity <= 1;
225  }
226 
228  inline bool IsAlphaTestTexture(){
229  return IsMatchAttribute(batt_alphaTestTexture);
230  }
231 
232  inline bool IsAlphaBlendedTexture(){
233  return IsMatchAttribute(batt_blendedTexture);
234  };
235 
236 
238  float GetSpeedReductionPercent() const;
239 
241  void SetSpeedReductionPercent(float val);
242 
244  void MakeCustomLinearModelProvider(int nModelCount);
245 
246  inline BlockRenderPass GetRenderPass() const { return m_renderPass; }
247  void SetRenderPass(BlockRenderPass val) { m_renderPass = val; }
248 
252  Color GetMapColor() const;
253  void SetMapColor(Color val);
254  DWORD GetBlockColor(int32_t blockData);
255  DWORD GetDiffuseColor(int32_t blockData);
256  void setUnderWaterColor(const Color & val);
257  const Color & getUnderWaterColor()const;
258  int getTileSize()const { return mTileSize; }
259  private:
261  uint16_t m_id;
263  uint16_t m_category_id;
265  uint16_t m_associated_blockid;
266 
267  uint16_t m_renderPriority;
269  BlockRenderPass m_renderPass;
270 
271  uint32_t m_attFlag;
272 
274  int32_t m_lightScatterStep;
276  int32 m_lightOpacity;
277 
278  uint32_t m_value;
279 
280  float m_fPhysicalHeight;
282  float m_fSpeedReductionPercent;
283 
284  bool m_bIsShadowCaster;
285  bool m_bProvidePower;
286 
287  std::vector<TextureEntity*> m_textures0;
288  std::vector<TextureEntity*> m_textures1;
289  TextureEntity* m_pNormalMap;
290  uint8_t m_nLightValue;
291  std::string m_secondTexName;
292  std::string m_normalMapName;
293  std::vector<BlockModel> m_block_models;
294  IBlockModelProvider* m_pBlockModelFilter;
296  Color m_dwMapColor;
297  Color m_UnderWaterColor;
298 
299  int mTileSize = 1;
300 
301  friend class IBlockModelProvider;
302  };
303 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
bool IsTransparent()
if true, it is fully transparent block.
Definition: BlockTemplate.h:223
bool IsMatchAttributeAll(uint32_t attFlags) const
if match all of the given attributes
Definition: BlockTemplate.h:84
void SetSpeedReductionPercent(float val)
[0,1] when player is walking into this block, this is the speed reduction.
Definition: BlockTemplate.cpp:501
bool HasColorData() const
whether the block contains color data.
Definition: BlockTemplate.h:94
void SetTorchLight(uint8_t value)
set torch light value
Definition: BlockTemplate.cpp:412
bool HasOpacity()
if true, it is not a fully transparent block.
Definition: BlockTemplate.h:218
different physics engine has different winding order.
Definition: EventBinding.h:32
uint8_t GetTorchLight()
torch default to 15
Definition: BlockTemplate.h:107
Definition: BlockChunk.h:14
Definition: BlockModel.h:172
Color GetMapColor() const
a single color as shown on the mini-map.
Definition: BlockTemplate.cpp:535
void GetBoundingBoxVertices(Vector3 *pVertices, int *pNumber)
get bounding box vertices
Definition: BlockTemplate.cpp:206
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
bool IsMatchAttributes(uint32_t dwMask, uint32_t attFlags) const
all attributes as specified in dwMask must match the value of attFlags
Definition: BlockTemplate.h:78
void GetAABB(CBlockWorld *pBlockManager, uint16_t bx, uint16_t by, uint16_t bz, CShapeAABB *pOutAABB)
get AABB in local space
Definition: BlockTemplate.cpp:418
bool IsFullyOpaque()
solid block without alpha blending is fully opaque
Definition: BlockTemplate.h:213
AABB-related code.
Definition: ShapeAABB.h:11
void SetAttribute(DWORD dwAtt, bool bTurnOn=true)
enable or disable a given attribute.
Definition: BlockTemplate.cpp:488
base class for an instance of block world
Definition: BlockWorld.h:35
bool IsMatchAttribute(uint32_t attFlags) const
if match any of the given attributes
Definition: BlockTemplate.h:72
void MakeCustomLinearModelProvider(int nModelCount)
make this model provider as linear for custom models.
Definition: BlockTemplate.cpp:512
BlockModel & GetBlockModel(int nIndex=0)
get the default block model.
Definition: BlockTemplate.cpp:232
float GetSpeedReductionPercent() const
[0,1] when player is walking into this block, this is the speed reduction.
Definition: BlockTemplate.cpp:496
Definition: enum_maker.hpp:46
int32_t GetLightScatterStep()
how many light to scatter between neighbor blocks.
Definition: BlockTemplate.h:199
block template base class.
Definition: BlockTemplate.h:15
interface class for filtering block models.
Definition: BlockModelProvider.h:12
float GetPhysicalHeight()
physical height of this block.
Definition: BlockTemplate.cpp:462
void SetAssociatedBlock(uint16_t associated_blockid)
set associated block
Definition: BlockTemplate.cpp:392
bool IsShadowCaster()
whether it is shadow caster.
Definition: BlockTemplate.h:121
bool IsAlphaTestTexture()
whether the block model contains no alpha tested texture.
Definition: BlockTemplate.h:228
bool canProvidePower()
Can this block provide power.
Definition: BlockTemplate.h:174
Definition: ParaColor.h:275
bool IsAssociatedBlockID(uint16_t block_id)
whether associated
Definition: BlockTemplate.cpp:397
void LoadModel(const std::string &sModelName)
load from known model name
Definition: BlockTemplate.cpp:249
uint8_t GetLightValue()
get light value.
Definition: BlockTemplate.h:113