My Project
BlockWorld.h
1 #pragma once
2 #include <vector>
3 #include <array>
4 #include <map>
5 #include <unordered_set>
6 #ifdef WIN32
7 #include "stdint.h"
8 #else
9 #include <stdint.h>
10 #endif
11 #include <bitset>
12 #include "IObjectScriptingInterface.h"
13 #include "IAttributeFields.h"
14 
15 #include "util/mutex.h"
16 #include "BlockTemplate.h"
17 #include "BlockCommon.h"
18 #include "BlockChunk.h"
19 #include "RenderableChunk.h"
20 #include "BlockRenderTask.h"
21 #include "WorldInfo.h"
22 #include "BlockReadWriteLock.h"
23 
24 namespace ParaEngine
25 {
26  class BlockRegion;
27  class RenderableChunk;
28  class CBlockLightGridBase;
29  class BlockRenderTask;
30  struct BlockHeightValue;
31  struct ChunkMaxHeight;
32 
33 
36  {
37  public:
38  CBlockWorld();
39  virtual ~CBlockWorld();
40 
42  virtual int GetAttributeClassID(){ return ATTRIBUTE_CLASSID_BlockWorld; }
44  virtual const char* GetAttributeClassName(){ static const char name[] = "BlockWorld"; return name; }
46  virtual const char* GetAttributeClassDescription(){ static const char desc[] = ""; return desc; }
48  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
49 
51  virtual IAttributeFields* GetChildAttributeObject(const std::string& sName);;
53  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);;
55  virtual int GetChildAttributeColumnCount() { return 1; };
56  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
57 
58  ATTRIBUTE_METHOD1(CBlockWorld, GetBlockRenderMethod_s, int*) { *p1 = cls->GetBlockRenderMethod(); return S_OK; }
59  ATTRIBUTE_METHOD1(CBlockWorld, SetBlockRenderMethod_s, int) { cls->SetBlockRenderMethod((BlockRenderMethod)p1); return S_OK; }
60 
61  ATTRIBUTE_METHOD(CBlockWorld, ResumeLightUpdate_s) { cls->ResumeLightUpdate(); return S_OK; }
62  ATTRIBUTE_METHOD(CBlockWorld, SuspendLightUpdate_s) { cls->SuspendLightUpdate(); return S_OK; }
63 
64  ATTRIBUTE_METHOD(CBlockWorld, ResetAllLight_s) { cls->ResetAllLight(); return S_OK; }
65 
66  ATTRIBUTE_METHOD(CBlockWorld, LockWorld_s) { cls->LockWorld(); return S_OK; }
67  ATTRIBUTE_METHOD(CBlockWorld, UnlockWorld_s) { cls->UnlockWorld(); return S_OK; }
68 
69  ATTRIBUTE_METHOD1(CBlockWorld, IsLightUpdateSuspended_s, bool*) { *p1 = cls->IsLightUpdateSuspended(); return S_OK; }
70 
71  ATTRIBUTE_METHOD3(CBlockWorld, SetChunkColumnTimeStamp_s, float) { cls->SetChunkColumnTimeStamp((uint16_t)p1, (uint16_t)p2, (uint16_t)p3); return S_OK; }
72 
73  ATTRIBUTE_METHOD1(CBlockWorld, GetRenderDist_s, int*) { *p1 = cls->GetRenderDist(); return S_OK; }
74  ATTRIBUTE_METHOD1(CBlockWorld, SetRenderDist_s, int) { cls->SetRenderDist(p1); return S_OK; }
75 
76  ATTRIBUTE_METHOD1(CBlockWorld, GetDirtyColumnCount_s, int*) { *p1 = cls->GetDirtyColumnCount(); return S_OK; }
77  ATTRIBUTE_METHOD1(CBlockWorld, GetDirtyBlockCount_s, int*) { *p1 = cls->GetDirtyBlockCount(); return S_OK; }
78 
79  ATTRIBUTE_METHOD1(CBlockWorld, IsReadOnly_s, bool*) { *p1 = cls->IsReadOnly(); return S_OK; }
80  ATTRIBUTE_METHOD1(CBlockWorld, SetReadOnly_s, bool) { cls->SetReadOnly(p1); return S_OK; }
81 
82  ATTRIBUTE_METHOD1(CBlockWorld, IsRemote_s, bool*) { *p1 = cls->IsRemote(); return S_OK; }
83  ATTRIBUTE_METHOD1(CBlockWorld, SetIsRemote_s, bool) { cls->SetIsRemote(p1); return S_OK; }
84 
85  ATTRIBUTE_METHOD1(CBlockWorld, IsServerWorld_s, bool*) { *p1 = cls->IsServerWorld(); return S_OK; }
86  ATTRIBUTE_METHOD1(CBlockWorld, SetIsServerWorld_s, bool) { cls->SetIsServerWorld(p1); return S_OK; }
87 
88  ATTRIBUTE_METHOD1(CBlockWorld, IsSaveLightMap_s, bool*) { *p1 = cls->IsSaveLightMap(); return S_OK; }
89  ATTRIBUTE_METHOD1(CBlockWorld, SetSaveLightMap_s, bool) { cls->SaveLightMap(p1); return S_OK; }
90 
91  ATTRIBUTE_METHOD1(CBlockWorld, IsUseAsyncLoadWorld_s, bool*) { *p1 = cls->IsUseAsyncLoadWorld(); return S_OK; }
92  ATTRIBUTE_METHOD1(CBlockWorld, SetUseAsyncLoadWorld_s, bool) { cls->SetUseAsyncLoadWorld(p1); return S_OK; }
93 
94  ATTRIBUTE_METHOD1(CBlockWorld, GetLightCalculationStep_s, int*) { *p1 = cls->GetLightCalculationStep(); return S_OK; }
95  ATTRIBUTE_METHOD1(CBlockWorld, SetLightCalculationStep_s, int) { cls->SetLightCalculationStep(p1); return S_OK; }
96 
97  ATTRIBUTE_METHOD1(CBlockWorld, GetMaxCacheRegionCount_s, int*) { *p1 = cls->GetMaxCacheRegionCount(); return S_OK; }
98  ATTRIBUTE_METHOD1(CBlockWorld, SetMaxCacheRegionCount_s, int) { cls->SetMaxCacheRegionCount(p1); return S_OK; }
99 
100  ATTRIBUTE_METHOD1(CBlockWorld, GetNumOfLockedBlockRegion_s, int*) { *p1 = cls->GetNumOfLockedBlockRegion(); return S_OK; }
101  ATTRIBUTE_METHOD1(CBlockWorld, GetNumOfBlockRegion_s, int*) { *p1 = cls->GetNumOfBlockRegion(); return S_OK; }
102  ATTRIBUTE_METHOD1(CBlockWorld, GetTotalNumOfLoadedChunksInLockedBlockRegion_s, int*) { *p1 = cls->GetTotalNumOfLoadedChunksInLockedBlockRegion(); return S_OK; }
103 
104  ATTRIBUTE_METHOD1(CBlockWorld, IsRenderBlocks_s, bool*) { *p1 = cls->IsRenderBlocks(); return S_OK; }
105  ATTRIBUTE_METHOD1(CBlockWorld, SetRenderBlocks_s, bool) { cls->SetRenderBlocks(p1); return S_OK; }
106 
107  ATTRIBUTE_METHOD1(CBlockWorld, GetSunIntensity_s, float*) { *p1 = cls->GetSunIntensity(); return S_OK; }
108  ATTRIBUTE_METHOD1(CBlockWorld, SetSunIntensity_s, float) { cls->SetSunIntensity(p1); return S_OK; }
109 
110  ATTRIBUTE_METHOD1(CBlockWorld, GetMinWorldPos_s, Vector3*) { *p1 = Vector3((float)(cls->GetMinWorldPos().x), (float)(cls->GetMinWorldPos().y), (float)(cls->GetMinWorldPos().z)); return S_OK; }
111  ATTRIBUTE_METHOD1(CBlockWorld, SetMinWorldPos_s, Vector3) { Int32x3 v((int32)p1.x, (int32)p1.y, (int32)p1.z); cls->SetMinWorldPos(v); return S_OK; }
112 
113  ATTRIBUTE_METHOD1(CBlockWorld, GetMaxWorldPos_s, Vector3*) { *p1 = Vector3((float)(cls->GetMaxWorldPos().x), (float)(cls->GetMaxWorldPos().y), (float)(cls->GetMaxWorldPos().z)); return S_OK; }
114  ATTRIBUTE_METHOD1(CBlockWorld, SetMaxWorldPos_s, Vector3) { Int32x3 v((int32)p1.x, (int32)p1.y, (int32)p1.z); cls->SetMaxWorldPos(v); return S_OK; }
115 
116 
117  ATTRIBUTE_METHOD1(CBlockWorld, GetTotalChunksInMemory_s, int*) { *p1 = BlockChunk::GetTotalChunksInMemory(); return S_OK; }
118  ATTRIBUTE_METHOD1(CBlockWorld, GetTotalRenderableChunksInMemory_s, int*) { *p1 = RenderableChunk::GetTotalRenderableChunks(); return S_OK; }
119 
120  ATTRIBUTE_METHOD1(CBlockWorld, UseLinearTorchBrightness_s, bool) { cls->GenerateLightBrightnessTable(p1); return S_OK; }
121 
122 
123  public:
126  Type_LoadBlockRegion = 0,
127  Type_UnLoadBlockRegion,
128  Type_GeneratorScript,
129  Type_SaveRegionCallbackScript,
130  Type_BeforeLoadBlockRegion,
131  };
132  DEFINE_SCRIPT_EVENT(CBlockWorld, BeforeLoadBlockRegion);
133  DEFINE_SCRIPT_EVENT(CBlockWorld, LoadBlockRegion);
134  DEFINE_SCRIPT_EVENT(CBlockWorld, UnLoadBlockRegion);
136  DEFINE_SCRIPT_EVENT(CBlockWorld, SaveRegionCallbackScript);
137 
138  // when there is no block terrain to load from , this function will be used to generate new terrains.
139  DEFINE_SCRIPT_EVENT(CBlockWorld, GeneratorScript);
140 
142  int OnBeforeLoadBlockRegion(int x, int y);
144  int OnLoadBlockRegion(int x, int y);
146  int OnUnLoadBlockRegion(int x, int y);
148  int OnSaveBlockRegion(int x, int y);
149  public:
152 
153  virtual const std::string& GetIdentifier();
154  virtual void SetIdentifier(const std::string& sID);
155 
156  //init block world
157  virtual void EnterWorld(const string& sWorldDir, float x, float y, float z);
158 
159  //call this function when leave the block world
160  virtual void LeaveWorld();
161 
162  void ClearAllBlockTemplates();
163 
165  void SetActiveChunkRadius(int nActiveChunkRadius = 12);
166 
167  void UpdateAllActiveChunks();
168 
170  const ParaEngine::Int32x3& GetMinWorldPos() const;
171  void SetMinWorldPos(const ParaEngine::Int32x3& val);
173  const ParaEngine::Int32x3& GetMaxWorldPos() const;
174  void SetMaxWorldPos(const ParaEngine::Int32x3& val);
175 
176  uint16_t GetMaxCacheRegionCount() const;
177  void SetMaxCacheRegionCount(uint16_t val);
178 
183  virtual void SetLightCalculationStep(uint32 nTicks);
184  virtual uint32 GetLightCalculationStep();
185 
190  BlockRegion* GetRegion(uint16_t x, uint16_t y, uint16_t z, uint16_t& rs_x, uint16_t& rs_y, uint16_t& rs_z);
191  BlockRegion* GetRegion(uint16_t region_x, uint16_t region_z);
192 
193  static float GetVerticalOffset();
194 
195  static void SetVerticalOffset(float offset);
196 
197  int32_t GetActiveChunkDim();
198 
199  int32_t GetActiveChunkDimY();
200 
201  bool IsInBlockWorld();
202 
204  void SetRenderBlocks(bool bValue);
205 
207  bool IsRenderBlocks();
208 
210  bool IsUseAsyncLoadWorld() const;
211  void SetUseAsyncLoadWorld(bool val);
212 
214  void SetReadOnly(bool bValue);
215 
217  bool IsReadOnly();
218 
220  bool IsVisibleChunkDirty() const;
221  void SetVisibleChunkDirty(bool val);
222 
224  void SetIsRemote(bool bValue);
225 
227  bool IsRemote();
228 
230  void SetIsServerWorld(bool bValue);
231 
233  bool IsServerWorld();
234 
236  bool IsGroupByChunkBeforeTexture() const;
237  void SetGroupByChunkBeforeTexture(bool val);
238 
245 
250  void LockWorld();
252  void UnlockWorld();
255 
259  bool IsSaveLightMap() const;
260  void SaveLightMap(bool val);
261 
262  void SaveBlockTemplateData();
263 
264  void LoadBlockTemplateData();
265 
266  void SaveToFile(bool saveToTemp);
267 
270 
272  //template related function
273  BlockTemplate* RegisterTemplate(uint16_t id, uint32_t attFlag, uint16_t category_id);
274 
276  bool SetBlockVisible(uint16_t templateId, bool value, bool bRefreshWorld = true);
278  void RefreshBlockTemplate(uint16_t templateId);
279 
280  //set/get block id/data
281  uint32_t SetBlockId(uint16_t x, uint16_t y, uint16_t z, uint32_t nBlockID);
282  uint32_t GetBlockId(uint16_t x, uint16_t y, uint16_t z);
283  uint32_t SetBlockData(uint16_t x, uint16_t y, uint16_t z, uint32_t nBlockData);
284  uint32_t GetBlockData(uint16_t x, uint16_t y, uint16_t z);
285 
286  //do *not* hold a permanent reference of return value,underlying memory address may change
287  //@param id: template id;
288  BlockTemplate* GetBlockTemplate(uint16_t id);
289 
290  //do *not* hold a permanent reference of return value,underlying memory address may change
291  //@param x,y,z: world space block id
292  BlockTemplate* GetBlockTemplate(uint16_t x, uint16_t y, uint16_t z);
293 
294  //do *not* hold a permanent reference of return value,underlying memory address may change
295  BlockTemplate* GetBlockTemplate(Uint16x3& blockId_ws);
296 
297  //@param flag: can be one or more BlockAttrubiteFlag value.
298  bool MatchTemplateAttribute(uint16_t templateId, BlockTemplate::BlockAttrubiteFlag flag);
299 
300  void SetTemplateTexture(uint16_t id, const char* textureName);
301 
302  //get highest block, null if block not exist;
303  //@return:first is highest soiled block, second is highest transparent block,second>= first
304  ChunkMaxHeight* GetHighestBlock(uint16_t blockX_ws, uint16_t blockZ_ws);
305 
306  //get highest y values of current and neighbor blocks above terrain.
307  //return terrain height if no block above ground.
308  //@param result: int16_t[6] array contains the result height of {center,x,-x,z,-z,mask}
309  // each bit of mask indicate return value is block height or terrain height,
310  virtual void GetMaxBlockHeightWatchingSky(uint16_t blockX_ws, uint16_t blockZ_ws, ChunkMaxHeight* pResult);
311 
313  //refresh all lights in chunk column,this function will recalc all point lights in a column
314  void RefreshAllLightsInColumn(uint16_t chunkX_ws, uint16_t chunkZ_ws);
315 
316  //called when block height map changed.This function will recalc sun light of block column
317  void NotifyBlockHeightMapChanged(uint16_t blockIdX_ws, uint16_t blockIdZ_ws, ChunkMaxHeight& prevBlockHeight);
318 
320  BlockIndex GetBlockIndex(uint16_t x, uint16_t y, uint16_t z, bool bCreateIfNotExist = true);
321 
323  BlockChunk* GetChunk(uint16_t x, uint16_t y, uint16_t z, bool bCreateIfNotExist = true);
324 
326  //block manipulation function
327  void SetBlockTemplateId(float x, float y, float z, uint16_t templateId);
328 
329  void SetBlockTemplateIdByIdx(uint16_t x, uint16_t y, uint16_t z, uint16_t templateId);
330 
331  uint16_t GetBlockTemplateId(float x, float y, float z);
332 
333  uint16_t GetBlockTemplateIdByIdx(uint16_t x, uint16_t y, uint16_t z);
334 
335  void SetBlockUserData(float x, float y, float z, uint32_t data);
336 
337  void SetBlockUserDataByIdx(uint16_t x, uint16_t y, uint16_t z, uint32_t data);
338 
339  uint32_t GetBlockUserData(float x, float y, float z);
340 
341  uint32_t GetBlockUserDataByIdx(uint16_t x, uint16_t y, uint16_t z);
342 
343  bool IsObstructionBlock(uint16_t x, uint16_t y, uint16_t z);
344 
345 
346  //return null if block not exist
347  //note:do *not* hold a permanent reference of the return value,underlying
348  //block address may change after SetBlockTemplate()!
349  Block* GetBlock(uint16_t x, uint16_t y, uint16_t z);
350  Block* GetUnlockBlock(uint16_t x, uint16_t y, uint16_t z);
351 
352  //set chunk dirty will rebuild vertex buffer of the chunk
353  void SetChunkDirty(Uint16x3& chunkId_ws, bool isDirty);
354  void SetChunkLightDirty(Uint16x3& chunkId_ws);
355 
358  void SetChunkColumnTimeStamp(uint16_t x, uint16_t z, uint16_t nTimeStamp);
362  int32_t GetChunkColumnTimeStamp(uint16_t x, uint16_t z);
363 
369  bool DoChunksNearChunkExist(uint16_t x, uint16_t y, uint16_t z, uint16_t radius);
370 
375  bool CheckChunkColumnsExist(int minX, int minY, int minZ, int maxX, int maxY, int maxZ);
376 
380  bool ChunkColumnExists(uint16_t chunkX, uint16_t chunkZ);
381 
385  bool IsChunkLocked(uint32 worldX, uint32 worldZ);
386 
390  int32_t GetBlocksInRegion(Uint16x3& startChunk_ws, Uint16x3& endChunk_ws, uint32_t matchType, const luabind::adl::object& result, uint32_t verticalSectionFilter = 0);
391 
393  int GetDirtyColumnCount();
394 
396  int GetDirtyBlockCount();
397 
399  bool IsCubeModePicking();
400  void SetCubeModePicking(bool bIsCubeModePicking);
401 
403  bool Pick(const Vector3& rayOrig, const Vector3& dir, float length, PickResult& result, uint32_t filter = 0xffffffff);
404 
412  int FindFirstBlock(uint16_t x, uint16_t y, uint16_t z, uint16_t nSide = 4, uint32_t max_dist = 32, uint32_t attrFilter = 0xffffffff, int nCategoryID = -1);
413 
417  int GetFirstBlock(uint16_t x, uint16_t y, uint16_t z, int nBlockId, uint16_t nSide = 5, uint32_t max_dist = 32);
418 
421  bool RefreshChunkColumn(int16_t curChunkWX, int16_t curChunkWZ);
423  bool IsChunkColumnInActiveRange(int16_t curChunkWX, int16_t curChunkWZ);
424 
430  bool GetBlockBrightness(Uint16x3& blockId_ws, uint8_t* brightness, int nSize = 27, int nLightType = -1);
431 
435  bool GetBlockMeshBrightness(Uint16x3& blockId_ws, uint8_t* brightness, int nLightType = 2);
436 
442  float GetBlockBrightnessReal(const Vector3& vPos, float* pBrightness = NULL);
443  float GetBlockBrightnessReal(Uint16x3& blockId_ws, float* pBrightness = NULL);
444 
445 
446  //set global sun light intensity
447  //@param intensity: [0,1]
448  void SetSunIntensity(float intensity);
449 
450  float GetSunIntensity();
451 
452  //set light block dirty,called when add/remove any type of block
453  //@lightValue: >0 if block is light
454  void SetLightBlockDirty(Uint16x3& blockId_ws, bool isSunLight);
455 
457  LightData* GetLightData(uint16_t x, uint16_t y, uint16_t z, bool bCreateIfNotExist = true);
458 
459  //call this function when loading blocks from file
460  void SuspendLightUpdate();
461 
464  int GetTotalNumOfLoadedChunksInLockedBlockRegion();
465  int GetNumOfBlockRegion();
466 
467  //called when blocks loaded from file;
468  void ResumeLightUpdate();
469 
470  bool IsLightUpdateSuspended();
471 
473  float GetLightBrightnessFloat(uint8_t brightness);
474 
476  uint8_t GetLightBrightnessInt(uint8_t brightness);
477 
479  float GetLightBrightnessLinearFloat(uint8_t brightness);
480 
482  void GenerateLightBrightnessTable(bool bUseLinearBrightness = false);
483 
484  //this function should be called every time when view center or camera position changed
485  void OnViewCenterMove(float viewCenterX, float viewCenterY, float viewCenterZ);
486 
488  void SetRenderDist(int nValue);
489  int GetRenderDist();
490 
492  BlockRenderMethod GetBlockRenderMethod();
494  virtual void SetBlockRenderMethod(BlockRenderMethod method);
495 
496  void GetCurrentCenterChunkId(Int16x3& oResult);
497 
498  const Uint16x3& GetEyeBlockId();
499  void SetEyeBlockId(const Uint16x3& eyePos);
500 
501  const Uint16x3& GetEyeChunkId();
502 
503  const Int16x3 GetMinActiveChunkId();
504 
506  void OnGenerateTerrain(int nRegionX, int nRegionY, int nChunkX = -1, int nChunkZ = -1);
507 
511  void SelectBlock(uint16_t x, uint16_t y, uint16_t z, int nGroupID = 0);
512 
513  void DeselectBlock(uint16_t x, uint16_t y, uint16_t z, int nGroupID = 0);
514 
515  //add render task to render queueGe
516  virtual void AddRenderTask(BlockRenderTask* pRenderTask);
517 
521  void DeselectAllBlock(int nGroupID = -1);
522 
525  BlockRegion* CreateGetRegion(uint16_t block_x, uint16_t block_y, uint16_t block_z);
526  BlockRegion* CreateGetRegion(uint16_t region_x, uint16_t region_z);
527 
529  virtual void ClearBlockRenderCache();
530 
531  // called each frame
532  virtual void OnFrameMove();
533 
534  /* it will only return a valid chunk if input chunkPos is within current active chunk range usually around the current view center.
535  * only call this function from the main rendering thread.
536  * @return NULL is chunkPos does not exist in the current active range. or the chunk is currently dirty and can not be used.
537  */
538  RenderableChunk* GetRenderableChunk(const Int16x3& chunkPos);
539 
541  bool UnloadRegion(uint16_t block_x, uint16_t block_y, uint16_t block_z, bool bAutoSave = true);
542 
543 
544 
545  void ResetAllLight();
546  protected:
548  void UnloadRegion(BlockRegion* pRegion, bool bAutoSave = true);
549 
553  RenderableChunk& GetActiveChunk(uint16_t curChunkWX, uint16_t curChunkWY, uint16_t curChunkWZ);
554 
557  bool ReuseActiveChunk(int16_t curChunkWX, int16_t curChunkWY, int16_t curChunkWZ, BlockRegion* pRegion);
558 
559  //perform culling and fill up m_visibleChunks
560  virtual void UpdateVisibleChunks(bool bIsShadowPass = false);
561 
562  //load/unload region on center view position
563  virtual void UpdateRegionCache();
564 
565  //load/unload chunk on center view position
566  virtual void UpdateActiveChunk();
567 
568  virtual void ClearOutOfRangeActiveChunkData();
569  protected:
570  std::string m_sName;
571  int32_t m_activeChunkDim;
572  int32_t m_activeChunkDimY;
573  static float g_verticalOffset;
574 
577 
580 
583 
586 
590 
593 
596 
601 
604 
607 
608 
609  //active chunk is a toroidal 3D grid array hold render data for n chunks around eye position.
610  //we will wrap the active chunk index when eye position change.
611  //say active chunk range from [x,y,z] to [nx,nz,ny] at first when move to
612  //[x+1,y+1,z+1]~[nx+1,ny+1,nz+1] we keep all data from [x+1,y+1,z+1]~[nx,nz,ny]
613  //and fill new data in the obsolete grids to avoid full refresh
614  std::vector<RenderableChunk*> m_activeChunks;
615 
616  Int16x3 m_minActiveChunkId_ws;
617 
618 
625 
626  //current region position in world space
627  int16_t m_curRegionIdX;
628  int16_t m_curRegionIdZ;
629 
630  //current chunk position in world space
631  Int16x3 m_curChunkIdW;
632  Int16x3 m_lastChunkIdW;
633  // for checking inside UpdateRegionCache(),
634  Int16x3 m_lastChunkIdW_RegionCache;
635  Uint16x3 m_lastViewCheckIdW;
636 
637  //
638  Uint16x3 m_curCenterBlockId;
639  Uint16x3 m_curCamBlockId;
640  Uint16x3 m_curCamChunkId;
641  Uint16x3 m_selectBlockIdW;
642 
647 
648  int m_minRegionX, m_minRegionZ;
649  int m_maxRegionX, m_maxRegionZ;
650 
653 
655  BlockRenderMethod m_dwBlockRenderMethod;
656 
657  float m_sunIntensity;
658 
659  //hold all lighting info of current active region
660  CBlockLightGridBase* m_pLightGrid;
661 
662  //hold all visible chunks of current frame, weak references
663  std::vector<RenderableChunk*> m_visibleChunks;
664  std::vector<RenderableChunk*> m_tempDirtyChunks;
665 
666  // cache 4 regions at least.
667  uint16_t m_maxCacheRegionCount;
670  BlockRegionPtr* m_pRegions;
671  std::map<int, BlockRegion*> m_regionCache;
672 
673  //Block templates
674  std::map<uint16_t, BlockTemplate*> m_blockTemplates;
675  std::vector<BlockTemplate*> m_blockTemplatesArray;
676 
677  //save old data to revert
679  {
680  uint8_t torchLight;
681  int32_t lightOpyValue;
682  bool isTransparent;
683  };
684  std::map<uint16_t, BlockTemplateVisibleData> m_blockTemplateVisibleDatas;
685 
686  /* directory information about the world. */
687  CWorldInfo m_worldInfo;
688 
693  float m_lightBrightnessLinearTableFloat[17];
694 
695  std::vector<CBlockSelectGroup> m_selectedBlockMap;
696 
699 
700  friend class CMultiFrameBlockWorldRenderer;
701  };
702 }
int32_t GetBlocksInRegion(Uint16x3 &startChunk_ws, Uint16x3 &endChunk_ws, uint32_t matchType, const luabind::adl::object &result, uint32_t verticalSectionFilter=0)
Definition: BlockWorld.cpp:1322
int FindFirstBlock(uint16_t x, uint16_t y, uint16_t z, uint16_t nSide=4, uint32_t max_dist=32, uint32_t attrFilter=0xffffffff, int nCategoryID=-1)
find a block in the side direction that matched filter from block(x,y,z) this function can be used to...
Definition: BlockWorld.cpp:1672
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: BlockWorld.h:44
void SelectBlock(uint16_t x, uint16_t y, uint16_t z, int nGroupID=0)
hight light select block
Definition: BlockWorld.cpp:1994
BlockRegion * BlockRegionPtr
array of 64*64 regions.
Definition: BlockWorld.h:669
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: BlockWorld.h:42
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void SetActiveChunkRadius(int nActiveChunkRadius=12)
how many chunk
Definition: BlockWorld.cpp:269
Int32x3 m_minWorldPos
minimum world position.
Definition: BlockWorld.h:644
BlockChunk * GetChunk(uint16_t x, uint16_t y, uint16_t z, bool bCreateIfNotExist=true)
get chunk by world coordinates
Definition: BlockWorld.cpp:1793
CallBackType
script call back type
Definition: BlockWorld.h:125
void OnGenerateTerrain(int nRegionX, int nRegionY, int nChunkX=-1, int nChunkZ=-1)
this function is called when region does not have matching disk file.
Definition: BlockWorld.cpp:2042
bool CheckChunkColumnsExist(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
Checks between a min and max all the chunks in between actually exist.
Definition: BlockWorld.cpp:2155
const ParaEngine::Int32x3 & GetMinWorldPos() const
minimum world position.
Definition: BlockWorld.cpp:2329
Providing information about the current game world.
Definition: WorldInfo.h:12
void SetReadOnly(bool bValue)
whether it is readonly
Definition: BlockWorld.cpp:496
bool IsCubeModePicking()
ignore sub-block level physics during Pick() function.
Definition: BlockWorld.cpp:1351
BlockRegion * GetRegion(uint16_t x, uint16_t y, uint16_t z, uint16_t &rs_x, uint16_t &rs_y, uint16_t &rs_z)
get region object
Definition: BlockWorld.cpp:440
bool Pick(const Vector3 &rayOrig, const Vector3 &dir, float length, PickResult &result, uint32_t filter=0xffffffff)
picking in block world
Definition: BlockWorld.cpp:1356
ParaEngine::mutex m_blockworld_mutex
when some thread is accessing the block world.
Definition: BlockWorld.h:624
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: BlockChunk.h:14
virtual int GetChildAttributeColumnCount()
we support multi-dimensional child object.
Definition: BlockWorld.h:55
Int32x3 m_maxWorldPos
maximum world position.
Definition: BlockWorld.h:646
BlockRenderMethod GetBlockRenderMethod()
get how blocks are preferred to be rendered.
Definition: BlockWorld.cpp:2037
bool UnloadRegion(uint16_t block_x, uint16_t block_y, uint16_t block_z, bool bAutoSave=true)
unload region from memory.
Definition: BlockWorld.cpp:407
void SetRenderDist(int nValue)
max number of blocks to render from eye to farthest one
Definition: BlockWorld.cpp:300
basic block world coordinate
Definition: BlockCoordinate.h:72
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: BlockWorld.h:46
CBlockLightGridBase & GetLightGrid()
get light grid
Definition: BlockWorld.cpp:346
bool m_bIsServerWorld
a server world.
Definition: BlockWorld.h:585
Definition: RenderableChunk.h:17
virtual void SetBlockRenderMethod(BlockRenderMethod method)
how blocks are preferred to be rendered.
Definition: BlockWorld.cpp:351
int OnSaveBlockRegion(int x, int y)
called when block region has just saved.
Definition: BlockWorld.cpp:2095
bool ReuseActiveChunk(int16_t curChunkWX, int16_t curChunkWY, int16_t curChunkWZ, BlockRegion *pRegion)
force reusing active chunk
Definition: BlockWorld.cpp:741
bool m_isVisibleChunkDirty
if true, it will check dirty bit for all active chunks in the next the render framemove ...
Definition: BlockWorld.h:595
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
static int GetTotalRenderableChunks()
total number of renderable chunks in memory.
Definition: RenderableChunk.cpp:984
int GetFirstBlock(uint16_t x, uint16_t y, uint16_t z, int nBlockId, uint16_t nSide=5, uint32_t max_dist=32)
get the y pos of the first block of nBlockID, start searching from x, y, z in the side direction ...
Definition: BlockWorld.cpp:1732
CWorldInfo & GetWorldInfo()
return world info
Definition: BlockWorld.cpp:2114
bool IsRenderBlocks()
whether it is readonly
Definition: BlockWorld.cpp:2252
void SetRenderBlocks(bool bValue)
whether it is readonly
Definition: BlockWorld.cpp:2243
bool m_isInWorld
whether this world is active
Definition: BlockWorld.h:576
bool IsServerWorld()
whether it is server world
Definition: BlockWorld.cpp:2228
Definition: object.hpp:749
virtual void SetLightCalculationStep(uint32 nTicks)
how many lighting to calculate per tick for the lighting thread.
Definition: BlockWorld.cpp:2233
bool m_bReadOnlyWorld
if true, no auto world saving is done when user moving out of the region cache.
Definition: BlockWorld.h:579
uint8_t GetLightBrightnessInt(uint8_t brightness)
Definition: BlockWorld.cpp:246
void GenerateLightBrightnessTable(bool bUseLinearBrightness=false)
Creates the light to brightness table.
Definition: BlockWorld.cpp:1823
RenderableChunk & GetActiveChunk(uint16_t curChunkWX, uint16_t curChunkWY, uint16_t curChunkWZ)
: world chunk coordinates
Definition: BlockWorld.cpp:731
base class for an instance of block world
Definition: BlockWorld.h:35
float m_lightBrightnessTableFloat[17]
Light to brightness conversion table.
Definition: BlockWorld.h:690
void RefreshBlockTemplate(uint16_t templateId)
refresh light and other attributes for all instances of given block template.
Definition: BlockWorld.cpp:879
bool RefreshChunkColumn(int16_t curChunkWX, int16_t curChunkWZ)
this function is called, when the entire column is loaded
Definition: BlockWorld.cpp:1068
virtual void ClearBlockRenderCache()
clear block render cache
Definition: BlockWorld.cpp:2145
BlockReadWriteLock & GetReadWriteLock()
get read/write locker of this world
Definition: BlockWorld.cpp:2313
int OnBeforeLoadBlockRegion(int x, int y)
called before block region is about to be loaded.
Definition: BlockWorld.cpp:2055
bool m_is_linear_torch_brightness
if true, light value in block shader is linear.
Definition: BlockWorld.h:606
virtual int GetChildAttributeObjectCount(int nColumnIndex=0)
get the number of child objects (row count) in the given column.
Definition: BlockWorld.cpp:2438
void SetIsServerWorld(bool bValue)
whether it is a server world.
Definition: BlockWorld.cpp:2223
BlockIndex GetBlockIndex(uint16_t x, uint16_t y, uint16_t z, bool bCreateIfNotExist=true)
return the BlockChunk and the block index inside the chunk.
Definition: BlockWorld.cpp:1778
float GetBlockBrightnessReal(const Vector3 &vPos, float *pBrightness=NULL)
get the interpolated block brightness at the given position.
Definition: BlockWorld.cpp:1310
bool IsGroupByChunkBeforeTexture() const
if true, when rendering blocks, always group by chunk first and then by texture.
Definition: BlockWorld.cpp:2319
virtual IAttributeFields * GetChildAttributeObject(const std::string &sName)
get attribute by child object.
Definition: BlockWorld.cpp:2417
bool IsReadOnly()
whether it is readonly
Definition: BlockWorld.cpp:501
bool IsChunkColumnInActiveRange(int16_t curChunkWX, int16_t curChunkWZ)
is the chunk column in active chunk region.
Definition: BlockWorld.cpp:1062
bool m_bSaveLightMap
whether to save light map to disk.
Definition: BlockWorld.h:589
Definition: enum_maker.hpp:46
Chunk is a 16*16*16 inside a region.
Definition: BlockChunk.h:138
bool ChunkColumnExists(uint16_t chunkX, uint16_t chunkZ)
Returns whether a chunk exists at chunk coordinates x, y.
Definition: BlockWorld.cpp:2183
Definition: BlockIndex.h:7
block template base class.
Definition: BlockTemplate.h:15
int GetDirtyBlockCount()
get the number of remaining dirty blocks
Definition: BlockWorld.cpp:1818
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
bool m_bCubeModePicking
ignore sub-block level physics during Pick() function.
Definition: BlockWorld.h:592
bool IsChunkLocked(uint32 worldX, uint32 worldZ)
whether the chunk at the given world position is locked.
Definition: BlockWorld.cpp:2199
bool IsSaveLightMap() const
whether to save light map to disk.
Definition: BlockWorld.cpp:2119
bool IsUseAsyncLoadWorld() const
whether we will use async world loader.
Definition: BlockWorld.cpp:2257
void SetChunkColumnTimeStamp(uint16_t x, uint16_t z, uint16_t nTimeStamp)
set chunk column time stamp.
Definition: BlockWorld.cpp:1649
Block Light Data.
Definition: BlockChunk.h:110
void UnlockWorld()
Unlock mutex.
Definition: BlockWorld.cpp:2140
multiple shared readers and multiple exclusive writers it favors writers over readers.
Definition: BlockReadWriteLock.h:18
float GetLightBrightnessFloat(uint8_t brightness)
Definition: BlockWorld.cpp:241
Definition: IObjectScriptingInterface.h:6
void DeselectAllBlock(int nGroupID=-1)
Definition: BlockWorld.cpp:2021
const ParaEngine::Int32x3 & GetMaxWorldPos() const
maximum world position.
Definition: BlockWorld.cpp:2341
BlockRenderMethod m_dwBlockRenderMethod
the current block rendering method.
Definition: BlockWorld.h:655
int m_nRenderDistance
max number of blocks to render from eye to farthest one
Definition: BlockWorld.h:652
int32_t GetChunkColumnTimeStamp(uint16_t x, uint16_t z)
get the time stamp of for the given chunk column -1 means region not loaded yet, 0 means not availabl...
Definition: BlockWorld.cpp:1659
bool IsRemote()
whether it is a remote world
Definition: BlockWorld.cpp:2212
int GetNumOfLockedBlockRegion()
get the total number of locked bock regions.
Definition: BlockWorld.cpp:2275
this is used for rendering a super large block world across several frames.
Definition: MultiFrameBlockWorldRenderer.h:19
bool IsVisibleChunkDirty() const
if true, it will check dirty bit for all active chunks in the next the render framemove ...
Definition: BlockWorld.cpp:2303
Definition: BlockRenderTask.h:13
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: BlockWorld.cpp:2453
int OnLoadBlockRegion(int x, int y)
called when block region has just loaded.
Definition: BlockWorld.cpp:2069
for block or chunk location that does not has boundary check.
Definition: BlockCoordinate.h:123
float GetLightBrightnessLinearFloat(uint8_t brightness)
Definition: BlockWorld.cpp:251
cross platform mutex
Definition: mutex.h:95
int GetDirtyColumnCount()
get number of dirty chunk columns for light calculations
Definition: BlockWorld.cpp:1813
bool m_bRenderBlocks
whether to render blocks
Definition: BlockWorld.h:598
ParaEngine::mutex & GetBlockWorldMutex()
when some thread is accessing the block world.
Definition: BlockWorld.cpp:2130
512*512 region
Definition: BlockRegion.h:22
bool m_bUseAsyncLoadWorld
whether we will use async world loader.
Definition: BlockWorld.h:600
int OnUnLoadBlockRegion(int x, int y)
called when block region has just unloaded.
Definition: BlockWorld.cpp:2082
Definition: BlockCommon.h:105
uint8_t m_lightBrightnessTableInt[17]
Light to brightness conversion table.
Definition: BlockWorld.h:692
basic block world coordinate
Definition: BlockCoordinate.h:10
virtual void EnterWorld(const string &sWorldDir, float x, float y, float z)
Definition: BlockWorld.cpp:104
base class for block light grid.
Definition: BlockLightGridBase.h:37
BlockReadWriteLock m_readWriteLock
read-write lock.
Definition: BlockWorld.h:698
LightData * GetLightData(uint16_t x, uint16_t y, uint16_t z, bool bCreateIfNotExist=true)
get block light data by world coordinates
Definition: BlockWorld.cpp:1804
bool SetBlockVisible(uint16_t templateId, bool value, bool bRefreshWorld=true)
return true if refresh world is required.
Definition: BlockWorld.cpp:834
bool m_group_by_chunk_before_texture
if true, when rendering blocks, always group by chunk first and then by texture.
Definition: BlockWorld.h:603
bool GetBlockBrightness(Uint16x3 &blockId_ws, uint8_t *brightness, int nSize=27, int nLightType=-1)
get light brightness of current and 26 nearby block
Definition: BlockWorld.cpp:1255
void SetIsRemote(bool bValue)
whether it is a remote world.
Definition: BlockWorld.cpp:2217
bool GetBlockMeshBrightness(Uint16x3 &blockId_ws, uint8_t *brightness, int nLightType=2)
if the block in not solid, we will simply return the block&#39;s brightness.
Definition: BlockWorld.cpp:1260
BlockRegion * CreateGetRegion(uint16_t block_x, uint16_t block_y, uint16_t block_z)
load region at the given position.
Definition: BlockWorld.cpp:356
bool m_bIsRemote
a remote world connected to server.
Definition: BlockWorld.h:582
bool DoChunksNearChunkExist(uint16_t x, uint16_t y, uint16_t z, uint16_t radius)
Checks if any of the chunks within radius blocks of the given block exist.
Definition: BlockWorld.cpp:2150
chunk column&#39;s height map data
Definition: ChunkMaxHeight.h:6
void LockWorld()
use scoped_lock where ever possible.
Definition: BlockWorld.cpp:2135