diff --git a/src/dawn/dawngame.c b/src/dawn/dawngame.c index 78b58c61..784ac1fd 100644 --- a/src/dawn/dawngame.c +++ b/src/dawn/dawngame.c @@ -7,9 +7,6 @@ #include "dawngame.h" -primitive_t *primitive; -float i; - game_t * gameInit(platform_t *platform) { // Create the game game_t *game = malloc(sizeof(game_t)); diff --git a/src/dawn/dawngame.h b/src/dawn/dawngame.h index 755d71a3..9e39736c 100644 --- a/src/dawn/dawngame.h +++ b/src/dawn/dawngame.h @@ -6,7 +6,6 @@ #pragma once #include #include "../engine/engine.h" - #include "../engine/file/asset.h" #include "../engine/display/shader.h" #include "../engine/display/camera.h" diff --git a/src/dawn/entity/entity.h b/src/dawn/entity/entity.h deleted file mode 100644 index 9fec6c6f..00000000 --- a/src/dawn/entity/entity.h +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) 2021 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once \ No newline at end of file diff --git a/src/dawn/world/chunk.c b/src/dawn/world/chunk.c index 863e4835..149c6cb0 100644 --- a/src/dawn/world/chunk.c +++ b/src/dawn/world/chunk.c @@ -29,7 +29,7 @@ void chunkLoad(world_t *world, chunk_t *chunk, int32_t x, int32_t y, int32_t z){ // Determine the size of our primitive. int32_t indiceCount = 0, verticeCount = 0; - for(i = 0; i < world->tileCount; i++) { + for(i = 0; i < CHUNK_TILE_COUNT; i++) { // Get the tile tile = chunk->tiles + i; @@ -80,5 +80,5 @@ void chunkUnload(world_t *world, chunk_t *chunk) { chunk->primitive = NULL; // Load chunks to zero. TODO: Necessary? - memset(chunk->tiles, TILE_NULL, world->count); + memset(chunk->tiles, TILE_NULL, CHUNK_TILE_COUNT); } \ No newline at end of file diff --git a/src/dawn/world/chunk.h b/src/dawn/world/chunk.h index f72794f0..b1d000c5 100644 --- a/src/dawn/world/chunk.h +++ b/src/dawn/world/chunk.h @@ -5,13 +5,6 @@ #include "../../engine/file/asset.h" #include "../../engine/util/string.h" -/** Width (in tiles) of chunks */ -#define CHUNK_WIDTH 16 -/** Heihgt (in tiles) of chunks */ -#define CHUNK_HEIGHT 16 -/** Depth (in tiles) of chunks */ -#define CHUNK_DEPTH 8 - /** When loading a chunk, how many chars to offset (ASCII char to byte) */ #define CHUNK_TILE_LOAD_ASCII 48 diff --git a/src/dawn/world/tile.h b/src/dawn/world/tile.h index a2c37c09..226858ad 100644 --- a/src/dawn/world/tile.h +++ b/src/dawn/world/tile.h @@ -4,12 +4,9 @@ // https://opensource.org/licenses/MIT #pragma once - #include #include - #include "worldtypes.h" - #include "../../engine/display/tileset.h" #include "../../engine/display/primitives/quad.h" #include "../../engine/display/primitives/cube.h" @@ -17,11 +14,6 @@ /** The tile id that represents a NULL tile */ #define TILE_NULL (tileid_t)0 -/** Width of a tile (in pixels) */ -#define TILE_WIDTH 16 -/** Height of a tile (in pixels) */ -#define TILE_HEIGHT 16 - /** * Creates a tilemap from a tileset. * diff --git a/src/dawn/world/world.c b/src/dawn/world/world.c index 47368fd1..4701e36f 100644 --- a/src/dawn/world/world.c +++ b/src/dawn/world/world.c @@ -27,8 +27,6 @@ world_t * worldLoad(char *assetWorldDirectory) { world = malloc(sizeof(world_t)); world->assetWorldDirectory = assetWorldDirectory; world->x = 0, world->y = 0, world->z = 0; - world->count = WORLD_WIDTH * WORLD_HEIGHT * WORLD_DEPTH; - world->tileCount = CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH; // Now begin parsing, first we need to know which version of the file format // we are using. @@ -71,10 +69,6 @@ world_t * worldLoad(char *assetWorldDirectory) { // Finished actual loading. free(worldData); - //Create chunks - world->chunks = malloc(world->count * sizeof(chunk_t)); - world->chunkList = malloc(world->count * sizeof(chunk_t *)); - // Load initial chunks, ZYX order is important here. i = 0; for(z = 0; z < WORLD_DEPTH; z++) { @@ -90,7 +84,6 @@ world_t * worldLoad(char *assetWorldDirectory) { chunk->primitive = NULL; // Init the chunk. - chunk->tiles = calloc(world->tileCount, sizeof(tile_t)); chunkLoad(world, chunk, x, y, z); i++; } @@ -109,7 +102,7 @@ void worldRender(world_t *world, shader_t *shader) { shaderUseTexture(shader, world->texture); - for(i = 0; i < world->count; i++) { + for(i = 0; i < WORLD_CHUNK_COUNT; i++) { chunk = world->chunks + i; if(chunk->primitive == NULL) continue; @@ -127,13 +120,11 @@ void worldDispose(world_t *world) { chunk_t *chunk; // Unload the chunks - for(i = 0; i < world->count; i++) { + for(i = 0; i < WORLD_CHUNK_COUNT; i++) { chunk = world->chunks + i; chunkUnload(world, chunk); - free(chunk->tiles); } - free(world->chunks); textureDispose(world->texture); tilesetDispose(world->tileset); tileMapDispose(world->tilemap); @@ -154,7 +145,7 @@ void worldShift(world_t *world, int32_t x, int32_t y, int32_t z) { wh ; chunk_t *chunk; - chunk_t **chunkList; + chunk_t *chunkList[WORLD_CHUNK_COUNT]; // Calculate the new chunklist coordinates lx = world->x + x; @@ -164,8 +155,7 @@ void worldShift(world_t *world, int32_t x, int32_t y, int32_t z) { // Precalc width * height. wh = WORLD_WIDTH * WORLD_HEIGHT; - chunkList = malloc(world->count * sizeof(chunk_t *)); - for(i = 0; i < world->count; i++) { + for(i = 0; i < WORLD_CHUNK_COUNT; i++) { chunk = world->chunkList[i]; // Calculate the new local positions for the chunk. @@ -208,7 +198,7 @@ void worldShift(world_t *world, int32_t x, int32_t y, int32_t z) { world->z = lz; // Now copy that array over. - memcpy(world->chunkList, chunkList, sizeof(chunk_t *) * world->count); + memcpy(world->chunkList, chunkList, sizeof(chunk_t *) * WORLD_CHUNK_COUNT); free(chunkList); } diff --git a/src/dawn/world/world.h b/src/dawn/world/world.h index fb59e334..7a75c158 100644 --- a/src/dawn/world/world.h +++ b/src/dawn/world/world.h @@ -17,17 +17,9 @@ #include "../../engine/util/string.h" #include "../../engine/util/math.h" -/** Width of world (in chunks) */ -#define WORLD_WIDTH 5 -/** Height of world (in chunks) */ -#define WORLD_HEIGHT WORLD_WIDTH -/** Depth of world (in chunks) */ -#define WORLD_DEPTH 2 - /** Token in the world data file to split on. */ #define WORLD_LOAD_TOKEN ";" - /** * Create a world object. * diff --git a/src/dawn/world/worldtypes.h b/src/dawn/world/worldtypes.h index f2755811..baaa2a95 100644 --- a/src/dawn/world/worldtypes.h +++ b/src/dawn/world/worldtypes.h @@ -1,20 +1,44 @@ -#pragma once +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ +#pragma once #include #include #include "../../engine/display/primitive.h" #include "../../engine/display/texture.h" #include "../../engine/display/tileset.h" +//////////////////////////////////////////////////////////////////////////////// +// Entities +//////////////////////////////////////////////////////////////////////////////// + +/** Entity ID */ +typedef uint8_t entityid_t; + +typedef struct { + float x, y, z; +} entitypos_t; + + +//////////////////////////////////////////////////////////////////////////////// +// Tiles +//////////////////////////////////////////////////////////////////////////////// + +/** Width of a tile (in pixels) */ +#define TILE_WIDTH 16 +/** Height of a tile (in pixels) */ +#define TILE_HEIGHT 16 /** Bitwise Flags from tiles. */ typedef uint8_t tileflag_t; - /** Tile ID */ typedef uint8_t tileid_t; - /** Representation of a unique tile within a chunk. */ typedef struct { /** ID of the tile */ @@ -24,7 +48,6 @@ typedef struct { int32_t indiceStart, verticeStart; } tile_t; - /** Representation of the information of a tile within a tilemap. */ typedef struct { /** Flags of the tile */ @@ -34,7 +57,6 @@ typedef struct { int32_t indiceCount, verticeCount; } tiledef_t; - /** Representation of the tile definitions within a tilemap. */ typedef struct { /** Tile definitions within the tilemap */ @@ -42,19 +64,47 @@ typedef struct { } tilemap_t; +//////////////////////////////////////////////////////////////////////////////// +// Chunks +//////////////////////////////////////////////////////////////////////////////// + +/** Width (in tiles) of chunks. */ +#define CHUNK_WIDTH 16 +/** Heihgt (in tiles) of chunks. */ +#define CHUNK_HEIGHT 16 +/** Depth (in tiles) of chunks. */ +#define CHUNK_DEPTH 8 +/** Count of tiles in the chunk. */ +#define CHUNK_TILE_COUNT CHUNK_WIDTH*CHUNK_HEIGHT*CHUNK_DEPTH + + + /** Representation of a chunk, a group of tiles that can be buffered around. */ typedef struct chunk_t { /** Position (in absolute chunk coordinates) of this chunk */ int32_t x, y, z; /** Array of tiles within the chunk */ - tile_t *tiles; + tile_t tiles[CHUNK_TILE_COUNT]; /** Ready to be rendered chunk 3d primitive */ primitive_t *primitive; } chunk_t; +//////////////////////////////////////////////////////////////////////////////// +// Worlds +//////////////////////////////////////////////////////////////////////////////// +/** Width of world (in chunks) */ +#define WORLD_WIDTH 5 +/** Height of world (in chunks) */ +#define WORLD_HEIGHT WORLD_WIDTH +/** Depth of world (in chunks) */ +#define WORLD_DEPTH 2 + +/** Count of chunks in the world */ +#define WORLD_CHUNK_COUNT WORLD_WIDTH*WORLD_HEIGHT*WORLD_DEPTH + /** Representation of the world. */ typedef struct { /** Asset subdir name */ @@ -62,25 +112,15 @@ typedef struct { /** Tileset texture */ texture_t *texture; - /** Tileset predivided */ tileset_t *tileset; - /** Tilemap of the world */ tilemap_t *tilemap; /** Current (chunk) coordinates of the first chunk in the chunk list */ int32_t x, y, z; - - /** Count of chunks within the chunk list */ - int32_t count; - - /** Count of tiles within each chunk */ - int32_t tileCount; - /** Current chunk list, ordered */ - chunk_t **chunkList; - + chunk_t *chunkList[WORLD_CHUNK_COUNT]; /** Chunk array (unordered) */ - chunk_t *chunks; + chunk_t chunks[WORLD_CHUNK_COUNT]; } world_t; \ No newline at end of file