2 #include "BlockWorld.h" 3 #include "effect_file.h" 10 struct BlockHeightValue;
12 class CMultiFrameBlockWorldRenderer;
39 ATTRIBUTE_METHOD1(
BlockWorldClient, GetBlockLightColor_s,
Vector3*) {*p1 = cls->GetBlockLightColor().ToVector3();
return S_OK;}
42 ATTRIBUTE_METHOD1(
BlockWorldClient, SetPostProcessingScript_s,
const char*) {cls->SetPostProcessingScript(p1);
return S_OK;}
44 ATTRIBUTE_METHOD1(
BlockWorldClient, SetPostProcessingAlphaScript_s,
const char*) { cls->SetPostProcessingAlphaScript(p1);
return S_OK; }
46 ATTRIBUTE_METHOD1(
BlockWorldClient, GetUseSunlightShadowMap_s,
bool*) {*p1 = cls->GetUseSunlightShadowMap();
return S_OK;}
47 ATTRIBUTE_METHOD1(
BlockWorldClient, SetUseSunlightShadowMap_s,
bool) {cls->SetUseSunlightShadowMap((BlockRenderMethod)p1);
return S_OK;}
49 ATTRIBUTE_METHOD1(
BlockWorldClient, HasSunlightShadowMap_s,
bool*) { *p1 = cls->HasSunlightShadowMap();
return S_OK; }
52 ATTRIBUTE_METHOD1(
BlockWorldClient, GetUseWaterReflection_s,
bool*) {*p1 = cls->GetUseWaterReflection();
return S_OK;}
53 ATTRIBUTE_METHOD1(
BlockWorldClient, SetUseWaterReflection_s,
bool) {cls->SetUseWaterReflection((BlockRenderMethod)p1);
return S_OK;}
55 ATTRIBUTE_METHOD1(
BlockWorldClient, CanUseAdvancedShading_s,
bool*) {*p1 = cls->CanUseAdvancedShading();
return S_OK;}
57 ATTRIBUTE_METHOD1(
BlockWorldClient, IsMovieOutputMode_s,
bool*) { *p1 = cls->IsMovieOutputMode();
return S_OK; }
58 ATTRIBUTE_METHOD1(
BlockWorldClient, EnableMovieOutputMode_s,
bool) { cls->EnableMovieOutputMode((BlockRenderMethod)p1);
return S_OK; }
60 ATTRIBUTE_METHOD1(
BlockWorldClient, GetVertexBufferSizeLimit_s,
int*) { *p1 = cls->GetVertexBufferSizeLimit();
return S_OK; }
61 ATTRIBUTE_METHOD1(
BlockWorldClient, SetVertexBufferSizeLimit_s,
int) { cls->SetVertexBufferSizeLimit(p1);
return S_OK; }
63 ATTRIBUTE_METHOD1(
BlockWorldClient, IsAsyncChunkMode_s,
bool*) { *p1 = cls->IsAsyncChunkMode();
return S_OK; }
64 ATTRIBUTE_METHOD1(
BlockWorldClient, SetAsyncChunkMode_s,
bool) { cls->SetAsyncChunkMode(p1);
return S_OK; }
67 ATTRIBUTE_METHOD1(
BlockWorldClient, GetAlwaysInVertexBufferChunkRadius_s,
int*) { *p1 = cls->GetAlwaysInVertexBufferChunkRadius();
return S_OK; }
68 ATTRIBUTE_METHOD1(
BlockWorldClient, SetAlwaysInVertexBufferChunkRadius_s,
int) { cls->SetAlwaysInVertexBufferChunkRadius(p1);
return S_OK; }
70 ATTRIBUTE_METHOD1(
BlockWorldClient, GetMaxVisibleVertexBufferBytes_s,
int*) { *p1 = cls->GetMaxVisibleVertexBufferBytes();
return S_OK; }
71 ATTRIBUTE_METHOD1(
BlockWorldClient, SetMaxVisibleVertexBufferBytes_s,
int) { cls->SetMaxVisibleVertexBufferBytes(p1);
return S_OK; }
74 ATTRIBUTE_METHOD1(
BlockWorldClient, GetNearCameraChunkDist_s,
int*) { *p1 = cls->GetNearCameraChunkDist();
return S_OK; }
75 ATTRIBUTE_METHOD1(
BlockWorldClient, SetNearCameraChunkDist_s,
int) { cls->SetNearCameraChunkDist(p1);
return S_OK; }
77 ATTRIBUTE_METHOD1(
BlockWorldClient, GetMaxBufferRebuildPerTick_s,
int*) { *p1 = cls->GetMaxBufferRebuildPerTick();
return S_OK; }
78 ATTRIBUTE_METHOD1(
BlockWorldClient, SetMaxBufferRebuildPerTick_s,
int) { cls->SetMaxBufferRebuildPerTick(p1);
return S_OK; }
80 ATTRIBUTE_METHOD1(
BlockWorldClient, GetMaxBufferRebuildPerTick_FarChunk_s,
int*) { *p1 = cls->GetMaxBufferRebuildPerTick_FarChunk();
return S_OK; }
81 ATTRIBUTE_METHOD1(
BlockWorldClient, SetMaxBufferRebuildPerTick_FarChunk_s,
int) { cls->SetMaxBufferRebuildPerTick_FarChunk(p1);
return S_OK; }
83 ATTRIBUTE_METHOD1(
BlockWorldClient, GetUsePointTextureFiltering_s,
bool*) { *p1 = cls->GetUsePointTextureFiltering();
return S_OK; }
84 ATTRIBUTE_METHOD1(
BlockWorldClient, SetUsePointTextureFiltering_s,
bool) { cls->SetUsePointTextureFiltering(p1);
return S_OK; }
98 virtual void EnterWorld(
const string& sWorldDir,
float x,
float y,
float z);
101 virtual void LeaveWorld();
104 virtual void UpdateVisibleChunks(
bool bIsShadowPass =
false);
109 void DeleteAllBlocks();
119 void PreRender(
bool bIsShadowPass =
false);
121 void CheckRebuildVisibleChunks(
bool bAsyncMode =
true,
bool bIsShadowPass =
false);
128 void Render(BlockRenderPass nRenderPass = BlockRenderPass_Opaque, std::vector<BlockRenderTask*>* pCurRenderQueue = NULL,
int nRenderMethod = -1);
133 std::vector<BlockRenderTask*>* GetRenderQueueByPass(BlockRenderPass nRenderPass);
142 void SetDamagedBlock(uint16_t wx,uint16_t wy,uint16_t wz);
144 void SetDamagedBlockDegree(
float degree);
163 std::string GetSelectionTexture();
167 std::string GetDamageTexture();
174 float GetWaterLevel(
float x,
float y,
float z,
int nRayLength=2);
178 void RestoreDeviceObjects();
183 void RendererRecreated();
188 void RestoreNormalShader();
203 void SetPostProcessingAlphaScript(
const char* sCallbackScript);
210 bool GetUseSunlightShadowMap();
215 bool GetUseWaterReflection();
227 virtual void GetMaxBlockHeightWatchingSky(uint16_t blockX_ws, uint16_t blockZ_ws,
ChunkMaxHeight* pResult);
233 void EnableMovieOutputMode(
bool val);
237 void SetVertexBufferSizeLimit(
int val);
241 void SetAlwaysInVertexBufferChunkRadius(
int val);
245 void SetMaxVisibleVertexBufferBytes(
int val);
250 void SetAsyncChunkMode(
bool val);
254 void SetNearCameraChunkDist(
int val);
260 void SetMaxBufferRebuildPerTick(
int val);
266 void SetMaxBufferRebuildPerTick_FarChunk(
int val);
273 void SetUsePointTextureFiltering(
bool bUse);
275 virtual void UpdateActiveChunk();
279 IndexBufferDevicePtr_type GetIndexBuffer();
283 void BuildSelectionBlockBuffer();
285 void RenderSelectionBlock(
int nSelectionIndex = BLOCK_GROUP_ID_HIGHLIGHT,
float fScaledBlockSize = 1.01f,
LinearColor* pColor = NULL, BOOL bColorAnimate = TRUE);
287 void RenderWireFrameBlock(
int nSelectionIndex = BLOCK_GROUP_ID_WIREFRAME,
float fScaledBlockSize = 1.01f,
LinearColor* pLineColor = NULL);
289 void RenderDamagedBlock();
291 int FillSelectBlockVertice(std::map<int64_t, Uint16x3>* pSelectedBlockMap, uint16_t x, uint16_t y, uint16_t z,
SelectBlockVertex* blockModel,
const Vector3& vOffset,
const float fBlockSize,
float fUV_Y_Offset = 0.f,
float fUV_Y_Size = 1.f);
293 int FillSelectBlockInvert(std::map<int64_t, Uint16x3>& selectedBlockMap, uint16_t x, uint16_t y, uint16_t z,
SelectBlockVertex* blockModel,
const Vector3& vOffset,
const float fBlockSize,
float fUV_Y_Offset = 0.f,
float fUV_Y_Size = 1.f);
295 bool HasSunlightShadowMap();
297 void AddToVisibleChunk(
RenderableChunk &chunk,
int nViewDist,
int nRenderFrameCount);
298 int ClearActiveChunksToMemLimit(
bool bIsShadowPass =
false);
300 void ClearVisibleChunksToByteLimit(
bool bIsShadowPass);
305 static int32_t g_TexPass;
306 static int32_t g_twoTexPass;
307 static int32_t g_TexNormalMapPass;
308 static int32_t g_twoTexNormalMapPass;
309 static int32_t g_transparentBlockPass;
310 static int32_t g_waterBlockPass;
311 static int32_t g_selectBlockPass;
312 static int32_t g_bumpyBlockPass;
315 bool m_isUnderLiquid;
320 std::vector<BlockRenderTask*> m_solidRenderTasks;
321 std::vector<BlockRenderTask*> m_alphaTestRenderTasks;
322 std::vector<BlockRenderTask*> m_alphaBlendRenderTasks;
323 std::vector<BlockRenderTask*> m_reflectedWaterRenderTasks;
326 std::vector<float> m_selectBlockInstData;
327 int32_t m_maxSelectBlockPerBatch;
329 asset_ptr<TextureEntity> m_highLightTextures[BLOCK_GROUP_ID_MAX];
330 std::vector<SelectBlockVertex> m_select_block_vertices;
331 std::vector<uint16_t> m_select_block_indices;
335 #ifdef USE_DIRECTX_RENDERER 337 asset_ptr<TextureEntity> m_render_target_color;
339 asset_ptr<TextureEntity> m_render_target_color_hdr;
341 asset_ptr<TextureEntity> m_render_target_block_info;
342 LPDIRECT3DSURFACE9 m_render_target_block_info_surface;
344 asset_ptr<TextureEntity> m_render_target_depth_tex;
345 LPDIRECT3DSURFACE9 m_render_target_depth_tex_surface;
347 asset_ptr<TextureEntity> m_render_target_normal;
348 LPDIRECT3DSURFACE9 m_render_target_normal_surface;
350 LPDIRECT3DSURFACE9 m_pDepthStencilSurface;
351 LPDIRECT3DSURFACE9 m_pOldRenderTarget;
352 LPDIRECT3DSURFACE9 m_pOldZBuffer;
355 asset_ptr<CEffectFile> m_block_effect_fancy;
356 asset_ptr<CEffectFile> m_normal_mesh_effect_fancy;
357 asset_ptr<CEffectFile> m_bmax_model_effect_fancy;
358 asset_ptr<CEffectFile> m_terrain_fancy;
361 asset_ptr<CEffectFile> m_lightgeometry_effects[3];
366 asset_ptr<TextureEntity> m_damangeTexture;
367 float m_damageDegree;
371 std::string m_sPostProcessorCallbackScript;
373 std::string m_sPostProcessorAlphaCallbackScript;
375 int m_nMaxBufferRebuildPerTick;
376 int m_nNearCameraChunkDist;
377 int m_nMaxBufferRebuildPerTick_FarChunk;
380 int m_nVertexBufferSizeLimit;
382 int m_nAlwaysInVertexBufferChunkRadius;
384 int m_nMaxVisibleVertexBufferBytes;
387 int m_nBufferRebuildCountThisTick;
390 bool m_bUseSunlightShadowMap;
393 bool m_bUseWaterReflection;
398 bool m_bMovieOutputMode;
402 bool m_bAsyncChunkMode;
405 bool m_bUsePointTextureFiltering;
void PrepareShadowCasters(CShadowMap *pShadowMap)
prepare shadow casters
Definition: BlockWorldClient.cpp:2413
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: BlockWorldClient.h:23
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void DoPostRenderingProcessing(BlockRenderPass nRenderPass=BlockRenderPass_Opaque)
do post rendering processing
Definition: BlockWorldClient.cpp:2204
Definition: BlockModel.h:163
bool CanUseAdvancedShading()
check device capabilities for deferred shading.
Definition: BlockWorldClient.cpp:2365
different physics engine has different winding order.
Definition: EventBinding.h:32
int GetMaxBufferRebuildPerTick_FarChunk() const
how many chunks to upload to video memory for far aways chunks per tick.
Definition: BlockWorldClient.cpp:3098
virtual void SetBlockRenderMethod(BlockRenderMethod method)
how blocks are preferred to be rendered.
Definition: BlockWorldClient.cpp:2022
virtual void ClearBlockRenderCache()
clear block render cache
Definition: BlockWorldClient.cpp:2109
int GetMaxBufferRebuildPerTick() const
how many chunks to upload to video memory per tick for near camera chunks.
Definition: BlockWorldClient.cpp:3078
basic block world coordinate
Definition: BlockCoordinate.h:72
virtual int GetChildAttributeColumnCount()
we support multi-dimensional child object.
Definition: BlockWorldClient.cpp:3013
Definition: RenderableChunk.h:17
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
virtual IAttributeFields * GetChildAttributeObject(const std::string &sName)
get attribute by child object.
Definition: BlockWorldClient.cpp:2995
bool IsAsyncChunkMode() const
if true, if we want to use a separate thread to fill the chunk buffer.
Definition: BlockWorldClient.cpp:3061
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: BlockWorldClient.cpp:3183
void RenderDeferredLights()
render light geometry.
Definition: BlockWorldClient.cpp:3116
void SetDamageTexture(const char *textureName)
used to render damaged texture.
Definition: BlockWorldClient.cpp:1932
int GetAlwaysInVertexBufferChunkRadius() const
we will ensure all chunks in this buffer range are also in memory, and not counted in m_nVertexBuffer...
Definition: BlockWorldClient.cpp:3041
int GetVertexBufferSizeLimit() const
for 32 bits version, we need to set the vertex buffer size limit to something like 700MB to prevent r...
Definition: BlockWorldClient.cpp:2985
base class for an instance of block world
Definition: BlockWorld.h:35
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: BlockWorldClient.h:19
bool GetUsePointTextureFiltering()
whether to use point texture filtering for all ui images rendered.
Definition: BlockWorldClient.cpp:2146
int GetNearCameraChunkDist() const
near camera chunk is always rendered and cached in vertex buffer.
Definition: BlockWorldClient.cpp:3088
vertex element
Definition: VertexDeclarationOpenGL.h:21
in OpenGL, there is no different between vertex and index buffer.
Definition: ParaVertexBuffer.h:78
bool PrepareAllRenderTargets(bool bSetRenderTarget=true)
call this function to set up all render targets for fancy graphics if any.
Definition: BlockWorldClient.cpp:2225
A common interface for all classes implementing IAttributeFields By implementing this class's virtual...
Definition: IAttributeFields.h:59
virtual int GetChildAttributeObjectCount(int nColumnIndex=0)
get the number of child objects (row count) in the given column.
Definition: BlockWorldClient.cpp:3032
bool IsMovieOutputMode() const
whenever in movie output mode, we will cache all terrain and lighting information.
Definition: BlockWorldClient.cpp:2930
void SetUseSunlightShadowMap(bool bEnable)
whether to use sun light shadow map
Definition: BlockWorldClient.cpp:2378
void SetUseWaterReflection(bool bEnable)
whether to use sun light shadow map
Definition: BlockWorldClient.cpp:2403
void InvalidateDeviceObjects()
must call this function when device is invalid.
Definition: BlockWorldClient.cpp:2166
int GetMaxVisibleVertexBufferBytes() const
we will only draw when there are less than this number of vertex visible at the current frame...
Definition: BlockWorldClient.cpp:3051
some functions about shadow map
Definition: ShadowMap.h:8
bool DrawMultiFrameBlockWorldOnSky()
render the image to the screen, with z test enabled and z-write disabled.
Definition: BlockWorldClient.cpp:3110
float GetWaterLevel(float x, float y, float z, int nRayLength=2)
get the water block level just nRayLength blocks under the given positions it will also check global ...
Definition: BlockWorldClient.cpp:1983
this is a singleton client side block world instance.
Definition: BlockWorldClient.h:15
void RenderDynamicBlocks()
render selection and damaged blocks
Definition: BlockWorldClient.cpp:2431
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object's name
Definition: BlockWorldClient.h:21
this is used for rendering a super large block world across several frames.
Definition: MultiFrameBlockWorldRenderer.h:19
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
Definition: BlockRenderTask.h:13
void RenderShadowMap()
render shadow map pass
Definition: BlockWorldClient.cpp:259
void SetBlockLightColor(const LinearColor &color)
default block emissive light color.
Definition: BlockWorldClient.cpp:2131
void DeleteDeviceObjects()
must call this function when device is lost.
Definition: BlockWorldClient.cpp:1860
bool DrawMultiFrameBlockWorld()
render multi frame block world is enabled.
Definition: BlockWorldClient.cpp:2348
LinearColor GetBlockLightColor()
default block emissive light color.
Definition: BlockWorldClient.cpp:2136
void SetPostProcessingScript(const char *sCallbackScript)
this is usually set for fancy graphics' composite shader in deferred shading.
Definition: BlockWorldClient.cpp:2355
bool IsPointUnderWater(const Vector3 &vPos)
check whether a specified point is under the water surface.
Definition: BlockWorldClient.cpp:1953
void Render(BlockRenderPass nRenderPass=BlockRenderPass_Opaque, std::vector< BlockRenderTask *> *pCurRenderQueue=NULL, int nRenderMethod=-1)
render all blocks in render queue using the given pass
Definition: BlockWorldClient.cpp:440
void InitDeviceObjects()
this function currently does nothing
Definition: BlockWorldClient.cpp:2156
chunk column's height map data
Definition: ChunkMaxHeight.h:6
void SetSelectionTexture(const char *textureName)
used to render selection texture.
Definition: BlockWorldClient.cpp:1898