summary refs log tree commit diff
path: root/src/MapRenderer.h
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-06-16 10:35:45 +0300
committerWlodekM <[email protected]>2024-06-16 10:35:45 +0300
commitabef6da56913f1c55528103e60a50451a39628b1 (patch)
treeb3c8092471ecbb73e568cd0d336efa0e7871ee8d /src/MapRenderer.h
initial commit
Diffstat (limited to 'src/MapRenderer.h')
-rw-r--r--src/MapRenderer.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/MapRenderer.h b/src/MapRenderer.h
new file mode 100644
index 0000000..d6361c7
--- /dev/null
+++ b/src/MapRenderer.h
@@ -0,0 +1,78 @@
+#ifndef CC_MAPRENDERER_H
+#define CC_MAPRENDERER_H
+#include "Core.h"
+#include "Constants.h"
+/* Renders the blocks of the world by subdividing it into chunks.
+   Also manages the process of building/deleting chunk meshes.
+   Also sorts chunks so nearest chunks are rendered first, and calculates chunk visibility.
+   Copyright 2014-2023 ClassiCube | Licensed under BSD-3
+*/
+struct IGameComponent;
+extern struct IGameComponent MapRenderer_Component;
+
+/* Max used 1D atlases. (i.e. Atlas1D_Index(maxTextureLoc) + 1) */
+extern int MapRenderer_1DUsedCount;
+
+/* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) parts in the buffer,
+with parts for 'normal' buffer being in lower half. */
+extern struct ChunkPartInfo* MapRenderer_PartsNormal; /* TODO: THAT DESC SUCKS */
+extern struct ChunkPartInfo* MapRenderer_PartsTranslucent;
+
+/* Describes a portion of the data needed for rendering a chunk. */
+struct ChunkPartInfo {
+#ifdef CC_BUILD_GL11
+	/* 1 VB per face, another VB for sprites */
+	#define CHUNKPART_MAX_VBS (FACE_COUNT + 1)
+	GfxResourceID vbs[CHUNKPART_MAX_VBS];
+#endif
+	int offset;      /* -1 if no vertices at all */
+	int spriteCount; /* Sprite vertices count */
+	cc_uint16 counts[FACE_COUNT]; /* Counts per face */
+};
+
+/* Describes data necessary for rendering a chunk. */
+struct ChunkInfo {	
+	cc_uint16 centreX, centreY, centreZ; /* Centre coordinates of the chunk */
+
+	cc_uint8 visible : 1; /* Whether chunk is visible to the player */
+	cc_uint8 empty : 1;   /* Whether the chunk is empty of data and is known to have no data */
+	cc_uint8 dirty : 1;   /* Whether chunk is pending being rebuilt */
+	cc_uint8 allAir : 1;  /* Whether chunk is completely air */
+	cc_uint8 noData : 1;  /* Whether the chunk is currently empty of data, but may have data if built */
+	cc_uint8 : 0;         /* pad to next byte*/
+
+	cc_uint8 drawXMin : 1;
+	cc_uint8 drawXMax : 1;
+	cc_uint8 drawZMin : 1;
+	cc_uint8 drawZMax : 1;
+	cc_uint8 drawYMin : 1;
+	cc_uint8 drawYMax : 1;
+	cc_uint8 : 0;          /* pad to next byte */
+#ifdef OCCLUSION
+	public cc_bool Visited = false, Occluded = false;
+	public byte OcclusionFlags, OccludedFlags, DistanceFlags;
+#endif
+#ifndef CC_BUILD_GL11
+	GfxResourceID vb;
+#endif
+	struct ChunkPartInfo* normalParts;
+	struct ChunkPartInfo* translucentParts;
+};
+
+/* Renders the meshes of non-translucent blocks in visible chunks. */
+void MapRenderer_RenderNormal(float delta);
+/* Renders the meshes of translucent blocks in visible chunks. */
+void MapRenderer_RenderTranslucent(float delta);
+/* Potentially updates sort order of rendered chunks. */
+/* Potentially builds meshes for several nearby chunks. */
+/* NOTE: This should be called once per frame. */
+void MapRenderer_Update(float delta);
+
+/* Marks the given chunk as needing to be rebuilt/redrawn. */
+/* NOTE: Coordinates outside the map are simply ignored. */
+void MapRenderer_RefreshChunk(int cx, int cy, int cz);
+/* Called when a block is changed, to update internal state. */
+void MapRenderer_OnBlockChanged(int x, int y, int z, BlockID block);
+/* Deletes all chunks and resets internal state. */
+void MapRenderer_Refresh(void);
+#endif