92 lines
2.3 KiB
C
92 lines
2.3 KiB
C
// Copyright (c) 2021 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include <malloc.h>
|
|
#include <stdint.h>
|
|
#include "tile.h"
|
|
#include "chunk.h"
|
|
#include "entity/entity.h"
|
|
#include "../display/shader.h"
|
|
#include "../display/camera.h"
|
|
#include "../display/primitive.h"
|
|
#include "../display/tileset.h"
|
|
#include "../display/texture.h"
|
|
#include "../file/asset.h"
|
|
#include "../input/input.h"
|
|
#include "../util/string.h"
|
|
#include "../util/math.h"
|
|
|
|
/** Token in the world data file to split on. */
|
|
#define WORLD_LOAD_TOKEN ";"
|
|
/** 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 world_t {
|
|
// Chunks
|
|
/** Tilemap of the world */
|
|
tilemap_t *tilemap;
|
|
/** Current (chunk) coordinates of the first chunk in the chunk list */
|
|
int32_t x, y, z;
|
|
/** Current chunk list, ordered */
|
|
chunk_t *chunkList[WORLD_CHUNK_COUNT];
|
|
/** Chunk array (unordered) */
|
|
chunk_t chunks[WORLD_CHUNK_COUNT];
|
|
|
|
entitysystem_t entities;
|
|
} world_t;
|
|
|
|
/**
|
|
* Create a world object.
|
|
*
|
|
* @returns The newly created world.
|
|
*/
|
|
world_t * worldLoad();
|
|
|
|
/**
|
|
* Render a world object to the graphics device.
|
|
*
|
|
* @param world The world to render.
|
|
* @param shader The shader to render to.
|
|
*/
|
|
void worldRender(world_t *world,
|
|
shader_t *shader, camera_t *camera,
|
|
input_t *input
|
|
);
|
|
|
|
/**
|
|
* Cleans up a previously created world.
|
|
*
|
|
* @param world World to cleanup.
|
|
*/
|
|
void worldDispose(world_t *world);
|
|
|
|
/**
|
|
* Shift the world chunk list along a set of axis (in absolute space).
|
|
*
|
|
* @param world World to shift.
|
|
* @param x X movement to shift chunk along.
|
|
* @param y Y movement to shift chunk along.
|
|
* @param z Z movement to shift chunk along.
|
|
*/
|
|
void worldShift(world_t *world, int32_t x, int32_t y, int32_t z);
|
|
|
|
/**
|
|
* Align the world chunk list (in absolute space).
|
|
*
|
|
* @param world World to align.
|
|
* @param x X movement to shift chunk along.
|
|
* @param y Y movement to shift chunk along.
|
|
* @param z Z movement to shift chunk along.
|
|
*/
|
|
void worldAlign(world_t *world, int32_t x, int32_t y, int32_t z); |