archivemuh
This commit is contained in:
10
archive/dusksdl2/display/overworld/CMakeLists.txt
Normal file
10
archive/dusksdl2/display/overworld/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
renderoverworld.c
|
||||
)
|
125
archive/dusksdl2/display/overworld/renderoverworld.c
Normal file
125
archive/dusksdl2/display/overworld/renderoverworld.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#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) {
|
||||
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, -1, -1);
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < ENTITY_COUNT_MAX; i++) {
|
||||
entity_t *entity = &ENTITIES[i];
|
||||
if(entity->type == ENTITY_TYPE_NULL) continue;
|
||||
|
||||
float_t x = (entity->x * TILE_WIDTH_HEIGHT) + entity->subX;
|
||||
float_t y = (entity->y * TILE_WIDTH_HEIGHT) + entity->subY;
|
||||
|
||||
// Draw the entity
|
||||
spriteBatchPush(
|
||||
NULL,
|
||||
x, y,
|
||||
x + TILE_WIDTH_HEIGHT, 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);
|
||||
}
|
||||
}
|
39
archive/dusksdl2/display/overworld/renderoverworld.h
Normal file
39
archive/dusksdl2/display/overworld/renderoverworld.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "world/chunk.h"
|
||||
#include "display/mesh/quad.h"
|
||||
|
||||
typedef struct {
|
||||
mesh_t meshBase;
|
||||
meshvertex_t verticesBase[CHUNK_TILE_COUNT * QUAD_VERTEX_COUNT];
|
||||
|
||||
mesh_t meshBaseOverlay;
|
||||
meshvertex_t verticesBaseOverlay[CHUNK_TILE_COUNT];
|
||||
} renderchunk_t;
|
||||
|
||||
typedef struct {
|
||||
renderchunk_t chunks[CHUNK_MAP_COUNT];
|
||||
} renderoverworld_t;
|
||||
|
||||
extern renderoverworld_t RENDER_OVERWORLD;
|
||||
|
||||
/**
|
||||
* Initializes the render overworld.
|
||||
*/
|
||||
void renderOverworldInit(void);
|
||||
|
||||
/**
|
||||
* Draws the render overworld.
|
||||
*/
|
||||
void renderOverworldDraw(void);
|
||||
|
||||
/**
|
||||
* Disposes of the render overworld.
|
||||
*/
|
||||
void renderOverworldDispose(void);
|
Reference in New Issue
Block a user