idk
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
world.c
|
||||
)
|
||||
19
src/rpg/world/chunk.h
Normal file
19
src/rpg/world/chunk.h
Normal 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
14
src/rpg/world/region.h
Normal 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
15
src/rpg/world/tile.h
Normal 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
23
src/rpg/world/world.c
Normal 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
32
src/rpg/world/world.h
Normal 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();
|
||||
Reference in New Issue
Block a user