Technically rendering everything.
This commit is contained in:
@@ -6,11 +6,119 @@
|
||||
*/
|
||||
|
||||
#include "renderoverworld.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/camera/camera.h"
|
||||
#include "entity/entity.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
|
||||
renderoverworld_t RENDER_OVERWORLD;
|
||||
|
||||
void renderOverworldInit(void) {
|
||||
// Initialize overworld rendering resources here
|
||||
memoryZero(&RENDER_OVERWORLD, sizeof(RENDER_OVERWORLD));
|
||||
|
||||
for(uint8_t i = 0; i < CHUNK_MAP_COUNT; i++) {
|
||||
renderchunk_t *chunk = &RENDER_OVERWORLD.chunks[i];
|
||||
|
||||
meshInit(
|
||||
&chunk->meshBase,
|
||||
GL_TRIANGLES,
|
||||
CHUNK_TILE_COUNT * QUAD_VERTEX_COUNT,
|
||||
chunk->verticesBase
|
||||
);
|
||||
|
||||
meshInit(
|
||||
&chunk->meshBaseOverlay,
|
||||
GL_TRIANGLES,
|
||||
CHUNK_TILE_COUNT,
|
||||
chunk->verticesBaseOverlay
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void renderOverworldDraw(void) {
|
||||
cameraOverworldPush();
|
||||
|
||||
for(uint8_t i = 0; i < CHUNK_MAP_COUNT; i++) {
|
||||
renderchunk_t *chunk = &RENDER_OVERWORLD.chunks[i];
|
||||
// meshDraw(&chunk->meshBase, 0, CHUNK_TILE_COUNT * QUAD_VERTEX_COUNT);
|
||||
meshDraw(&chunk->meshBase, -1, -1);
|
||||
}
|
||||
|
||||
|
||||
for(uint8_t i = 0; i < ENTITY_COUNT_MAX; i++) {
|
||||
entity_t *entity = &ENTITIES[i];
|
||||
if(entity->type == ENTITY_TYPE_NULL) continue;
|
||||
|
||||
// Draw the entity
|
||||
spriteBatchPush(
|
||||
NULL,
|
||||
entity->x, entity->y,
|
||||
entity->x + TILE_WIDTH_HEIGHT, entity->y + TILE_WIDTH_HEIGHT,
|
||||
0xFF, 0x00, 0xFF, 0XFF,
|
||||
0.0f, 0.0f, 1.0f, 1.0f
|
||||
);
|
||||
}
|
||||
|
||||
spriteBatchFlush();
|
||||
cameraOverworldPop();
|
||||
}
|
||||
|
||||
void renderChunkUpdated(chunk_t *chunk) {
|
||||
uint8_t r, g, b;
|
||||
assertNotNull(chunk, "Chunk pointer is null");
|
||||
|
||||
int32_t chunkIndex = chunk - CHUNK_MAP.chunks;
|
||||
assertTrue(
|
||||
chunkIndex >= 0 && chunkIndex < CHUNK_MAP_COUNT,
|
||||
"Chunk index out of bounds"
|
||||
);
|
||||
|
||||
for(uint32_t i = 0; i < CHUNK_TILE_COUNT; i++) {
|
||||
tile_t base = chunk->tilesBase[i];
|
||||
tile_t overlay = chunk->tilesBaseOverlay[i];
|
||||
|
||||
float_t posX = (i % CHUNK_WIDTH) + (chunk->x * CHUNK_WIDTH);
|
||||
float_t posY = (i / CHUNK_WIDTH) + (chunk->y * CHUNK_HEIGHT);
|
||||
|
||||
switch(base) {
|
||||
case 0:
|
||||
r = 0; g = 0; b = 0; // Black for empty
|
||||
break;
|
||||
case 1:
|
||||
r = 34; g = 139; b = 34; // Forest Green
|
||||
break;
|
||||
case 2:
|
||||
r = 0; g = 191; b = 255; // Deep Sky Blue
|
||||
break;
|
||||
case 3:
|
||||
r = 139; g = 69; b = 19; // Saddle Brown
|
||||
break;
|
||||
case 4:
|
||||
r = 255; g = 255; b = 0; // Yellow
|
||||
break;
|
||||
default:
|
||||
r = 255; g = 20; b = 147; // Pink for unknown
|
||||
break;
|
||||
}
|
||||
|
||||
quadBuffer(
|
||||
&RENDER_OVERWORLD.chunks[chunkIndex].verticesBase[i * QUAD_VERTEX_COUNT],
|
||||
posX * TILE_WIDTH_HEIGHT,
|
||||
posY * TILE_WIDTH_HEIGHT,
|
||||
(posX + 1) * TILE_WIDTH_HEIGHT,
|
||||
(posY + 1) * TILE_WIDTH_HEIGHT,
|
||||
r, g, b, 255,
|
||||
0, 0, 1, 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void renderOverworldDispose(void) {
|
||||
// Clean up overworld rendering resources here
|
||||
for(uint8_t i = 0; i < CHUNK_MAP_COUNT; i++) {
|
||||
renderchunk_t *chunk = &RENDER_OVERWORLD.chunks[i];
|
||||
meshDispose(&chunk->meshBase);
|
||||
meshDispose(&chunk->meshBaseOverlay);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user