My Project
BlockLightGridServer.h
1 #pragma once
2 
3 #include "BlockLightGridBase.h"
4 
5 namespace ParaEngine
6 {
11  {
12  public:
13  CBlockLightGridServer(CBlockWorld* pBlockWorld);
14  virtual ~CBlockLightGridServer();
15 
16  public:
17  virtual void OnEnterWorld();
18  virtual void OnLeaveWorld();
19  virtual void OnWorldMove(uint16_t centerChunkX, uint16_t centerChunkZ);
20  virtual void UpdateLighting();
21 
22  //get light brightness of current and 26 nearby block
23  // @param brightness: pointer to uint8_t blockBrightness[27];
24  // @param nSize: if 1, it will only get the center block.
25  // @param nLightType: -1 means Max light. 0 means emissive block light, 1 means sun light. 2 means both. where brightness[i] is block light and brightness[i+nSize] is sunlight
26  // @return : true if exist. false if there is no block at the position.
27  virtual bool GetBrightness(Uint16x3& blockId, uint8_t* brightness, int nSize = 27, int nLightType = -1);
28 
29  virtual void SetLightDirty(Uint16x3& blockId_ws, bool isSunLight);
30 
32  virtual void AddDirtyColumn(uint16_t chunkX_ws, uint16_t chunkZ_ws);
33 
35  virtual int GetDirtyColumnCount();
36 
37  private:
38  //this is the core function to spread light
39  void EmitLight(const Uint16x3& blockId, uint8_t brightness, bool isSunLight = false);
40 
41  //recalc light when remove light or block state changed
42  void RefreshLight(const Uint16x3& blockId);
43  void RefreshLight(const Uint16x3& blockId, bool isSunLight);
44 
46  void EmitSunLight(uint16_t blockIdX_ws, uint16_t blockIdZ_ws, bool bInitialSet = false);
47 
48  BlockIndex CalcLightDataIndex(const Uint16x3& blockId);
49 
50  LightData* GetLightData(const BlockIndex& index);
51  LightData* GetLightData(uint16_t x, uint16_t y, uint16_t z);
52  BlockChunk* GetChunk(uint16_t x, uint16_t y, uint16_t z);
53 
54  public:
60  private:
61 
62  };
63 }
different physics engine has different winding order.
Definition: EventBinding.h:32
basic block world coordinate
Definition: BlockCoordinate.h:72
base class for an instance of block world
Definition: BlockWorld.h:35
virtual void AddDirtyColumn(uint16_t chunkX_ws, uint16_t chunkZ_ws)
update all blocks in the given chunk column.
Definition: BlockLightGridServer.cpp:72
Chunk is a 16*16*16 inside a region.
Definition: BlockChunk.h:138
Definition: BlockIndex.h:7
block grid on server side.
Definition: BlockLightGridServer.h:10
Block Light Data.
Definition: BlockChunk.h:110
virtual int GetDirtyColumnCount()
get the number of remaining dirty column
Definition: BlockLightGridServer.cpp:77
int m_max_cells_per_frame
max number of cells(blocks) to calculate per frame.
Definition: BlockLightGridServer.h:56
int m_max_cells_left_per_frame
max number of cells(blocks) to left un-calculated per frame.
Definition: BlockLightGridServer.h:59
base class for block light grid.
Definition: BlockLightGridBase.h:37