Overworld render test.

This commit is contained in:
2025-09-11 23:33:24 -05:00
parent b4d94c2cbe
commit 964a9f64f2
32 changed files with 249 additions and 1219 deletions

View File

@@ -12,14 +12,15 @@
#include "display/scene/scenemanager.h"
#include "display/mesh/quad.h"
#include "asset/assetmanager.h"
#include "assert/assert.h"
camera_t SCENE_OVERWORLD_CAMERA;
sceneoverworld_t SCENE_OVERWORLD;
asset_t *testAsset;
ref_t testAssetRef;
void sceneOverworldInit(void) {
cameraInit(&SCENE_OVERWORLD_CAMERA);
glm_vec3_copy((vec3){32.0f, 32.0f, 32.0f}, SCENE_OVERWORLD_CAMERA.lookat.position);
cameraInit(&SCENE_OVERWORLD.camera);
glm_vec3_copy((vec3){ 0.0f, 1.0f, 0.0f }, SCENE_OVERWORLD.camera.lookat.up);
scene_t *scene = &SCENE_MANAGER_SCENES[SCENE_TYPE_OVERWORLD];
scene->flags |= SCENE_FLAG_ACTIVE | SCENE_FLAG_VISIBLE;
@@ -31,24 +32,59 @@ void sceneOverworldUpdate(void) {
}
void sceneOverworldRender(void) {
cameraPushMatrix(&SCENE_OVERWORLD_CAMERA);
const float_t camOffset = 12.0f;
const float_t fbWidth = frameBufferGetWidth(FRAMEBUFFER_BOUND);
const float_t fbHeight = frameBufferGetHeight(FRAMEBUFFER_BOUND);
const float_t aspect = fbWidth / fbHeight;
const float_t pixelPerfectOffset = tanf(
(glm_rad(180) - SCENE_OVERWORLD.camera.perspective.fov) / 2.0f
) * (fbHeight/ 2.0f);
glm_vec3_copy((vec3){
-100.0f, -100.0f, 0.0f
}, SCENE_OVERWORLD.camera.lookat.target);
glm_vec3_copy((vec3){
SCENE_OVERWORLD.camera.lookat.target[0],
SCENE_OVERWORLD.camera.lookat.target[1] + camOffset,
SCENE_OVERWORLD.camera.lookat.target[2] + pixelPerfectOffset
}, SCENE_OVERWORLD.camera.lookat.position);
cameraPushMatrix(&SCENE_OVERWORLD.camera);
sceneOverworldRenderMap(&testMap);
spriteBatchFlush();
cameraPopMatrix();
}
void sceneOverworldRenderMap(const map_t *map) {
assertNotNull(map, "Map pointer cannot be NULL");
// Draw base layer
// Draw entities
entity_t *start = &map->entities[0];
entity_t *end = &map->entities[map->entityCount];
while(start < end) {
// Render entity here.
sceneOverworldRenderEntity(start);
start++;
}
// Draw overlay layer.
// renderTextDraw(0.0f, 0.0f, "Hello World", 0xFF, 0xFF, 0xFF);
}
// spriteBatchPush(
// &testAsset->paletteImage.texture,
// 0.0f, 0.0f, 12.0f, 12.0f,
// 0xFF, 0xFF, 0xFF, 0xFF,
// 0.0f, 0.0f, 1.0f, 1.0f
// );
spriteBatchFlush();
void sceneOverworldRenderEntity(const entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL");
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Invalid entity type");
assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type");
cameraPopMatrix();
// For now, just draw a placeholder quad.
spriteBatchPush(
&testAsset->paletteImage.texture,
entity->x, entity->y, entity->x + 32.0f, entity->y + 32.0f,
COLOR_WHITE, 0.0f, 0.0f, 0.125f, 0.125f
);
}
void sceneOverworldDispose(void) {

View File

@@ -7,8 +7,13 @@
#pragma once
#include "display/camera.h"
#include "rpg/world/map.h"
extern camera_t SCENE_OVERWORLD_CAMERA;
typedef struct {
camera_t camera;
} sceneoverworld_t;
extern sceneoverworld_t SCENE_OVERWORLD;
/**
* Initialize the overworld scene.
@@ -25,6 +30,20 @@ void sceneOverworldUpdate(void);
*/
void sceneOverworldRender(void);
/**
* Render a map in the overworld scene.
*
* @param map Pointer to the map to render.
*/
void sceneOverworldRenderMap(const map_t *map);
/**
* Render an entity in the overworld scene.
*
* @param entity Pointer to the entity to render.
*/
void sceneOverworldRenderEntity(const entity_t *entity);
/**
* Dispose of the overworld scene.
*/