Refator pass 1

This commit is contained in:
2025-10-06 19:14:52 -05:00
parent 85434b4edb
commit fc52afdb00
113 changed files with 96 additions and 726 deletions

View 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
map.c
)

33
archive/rpg/world/map.c Normal file
View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "map.h"
#include "util/memory.h"
#include "assert/assert.h"
void mapInit(map_t *map) {
assertNotNull(map, "Map cannot be NULL");
memoryZero(map, sizeof(map_t));
}
void mapUpdate(map_t *map) {
assertNotNull(map, "Map cannot be NULL");
entity_t *start = &map->entities[0];
entity_t *end = &map->entities[map->entityCount];
while(start < end) {
entityUpdate(start++);
}
}
entity_t * mapEntityAdd(map_t *map) {
assertNotNull(map, "Map cannot be NULL");
assertTrue(map->entityCount < MAP_ENTITY_COUNT_MAX, "Map entities full");
entity_t *entity = &map->entities[map->entityCount++];
return entity;
}

57
archive/rpg/world/map.h Normal file
View File

@@ -0,0 +1,57 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "rpg/entity/entity.h"
#define MAP_ENTITY_COUNT_MAX 32
#define MAP_WIDTH_MAX 64
#define MAP_HEIGHT_MAX 64
#define MAP_TILE_COUNT_MAX (MAP_WIDTH_MAX * MAP_HEIGHT_MAX)
#define MAP_LAYER_COUNT_MAX 2
typedef struct {
uint8_t id;
} tile_t;
typedef struct {
tile_t tiles[MAP_TILE_COUNT_MAX];
} maplayer_t;
typedef struct map_s {
entity_t entities[MAP_ENTITY_COUNT_MAX];
uint8_t entityCount;
uint8_t width, height;
maplayer_t base;
maplayer_t overlay;
} map_t;
extern map_t testMap;
/**
* Initializes a map structure.
*
* @param map Pointer to the map structure to initialize.
*/
void mapInit(map_t *map);
/**
* Updates the map and its entities.
*
* @param map Pointer to the map structure to update.
*/
void mapUpdate(map_t *map);
/**
* Adds (but does not initialize) an entity on the map.
*
* @param map Pointer to the map structure.
* @return Pointer to the added entity.
*/
entity_t * mapEntityAdd(map_t *map);

16
archive/rpg/world/tile.h Normal file
View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
typedef enum {
TILE_TYPE_NULL,
} tiletype_t;
typedef struct {
tiletype_t type;
} tile_t;