This commit is contained in:
2025-10-26 08:06:39 -05:00
parent d74226dab1
commit 3feb43fdad
34 changed files with 112 additions and 1141 deletions

View File

@@ -8,8 +8,6 @@
#include "engine/engine.h"
#include "console/console.h"
int main(int argc, char **argv) {
errorret_t ret;
ret = engineInit();

View File

@@ -7,6 +7,7 @@
#include "rpg.h"
#include "entity/entity.h"
#include "rpg/world/world.h"
#include "time/time.h"
#include "rpgcamera.h"
#include "util/memory.h"
@@ -14,8 +15,13 @@
errorret_t rpgInit(void) {
memoryZero(ENTITIES, sizeof(ENTITIES));
// Init the world.
worldInit();
// Initialize the camera
rpgCameraInit();
// TEST: Create some entities.
entity_t *ent;
ent = &ENTITIES[0];
entityInit(ent, ENTITY_TYPE_PLAYER);
@@ -27,18 +33,26 @@ errorret_t rpgInit(void) {
entityInit(ent, ENTITY_TYPE_NPC);
ent->position[0] = 6, ent->position[1] = 6;
// All Good!
errorOk();
}
void rpgUpdate(void) {
if(!TIME.fixedUpdate) return;
// TODO: Do not update if the scene is not the map scene?
// Update the world.
worldUpdate();
// Update overworld ents.
entity_t *ent = &ENTITIES[0];
do {
if(ent->type == ENTITY_TYPE_NULL) continue;
entityUpdate(ent);
} while(++ent < &ENTITIES[ENTITY_COUNT]);
// Update the camera.
rpgCameraUpdate();
}

View File

@@ -6,4 +6,5 @@
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
world.c
)

19
src/rpg/world/chunk.h Normal file
View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/world/tile.h"
#define CHUNK_WIDTH 16
#define CHUNK_HEIGHT 16
#define CHUNK_DEPTH 16
#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH)
typedef struct chunk_s {
int16_t x, y, z;
tile_t tiles[CHUNK_TILE_COUNT];
} chunk_t;

14
src/rpg/world/region.h Normal file
View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef struct {
vec2 min;
vec2 max;
} region_t;

15
src/rpg/world/tile.h Normal file
View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
#pragma pack(push, 1)
typedef struct tile_s {
uint8_t id;
} tile_t;
#pragma pack(pop)

23
src/rpg/world/world.c Normal file
View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "world.h"
#include "util/memory.h"
world_t WORLD;
void worldInit() {
memoryZero(&WORLD, sizeof(world_t));
for(uint32_t i = 0; i < WORLD_CHUNK_COUNT; i++) {
WORLD.chunkOrder[i] = &WORLD.chunks[i];
}
}
void worldUpdate() {
}

32
src/rpg/world/world.h Normal file
View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/world/chunk.h"
#define WORLD_WIDTH 4
#define WORLD_HEIGHT 4
#define WORLD_DEPTH 4
#define WORLD_CHUNK_COUNT (WORLD_WIDTH * WORLD_HEIGHT * WORLD_DEPTH)
typedef struct world_s {
chunk_t chunks[WORLD_CHUNK_COUNT];
chunk_t *chunkOrder[WORLD_CHUNK_COUNT];
int16_t x, y, z;
} world_t;
extern world_t WORLD;
/**
* Initializes the world.
*/
void worldInit();
/**
* Updates the world.
*/
void worldUpdate();

View File

@@ -17,6 +17,7 @@
#define TILE_SIZE 16
errorret_t sceneMapInit(scenedata_t *data) {
// Init the camera.
cameraInitPerspective(&data->sceneMap.camera);
data->sceneMap.camera.projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED;
data->sceneMap.camera.viewType = CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT;
@@ -36,6 +37,7 @@ errorret_t sceneMapInit(scenedata_t *data) {
}
void sceneMapUpdate(scenedata_t *data) {
}
void sceneMapRender(scenedata_t *data) {

View File

@@ -8,11 +8,12 @@
#pragma once
#include "scene/scene.h"
#include "rpg/entity/entity.h"
#include "rpg/world/world.h"
#include "display/camera.h"
typedef struct {
int32_t nothing;
camera_t camera;
world_t world;
} scenemap_t;
errorret_t sceneMapInit(scenedata_t *data);