Refactored.
This commit is contained in:
29
include/dawn/dawn.h
Normal file
29
include/dawn/dawn.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "libs.h"
|
||||
|
||||
#include "display/camera.h"
|
||||
#include "display/primitive.h"
|
||||
#include "display/render.h"
|
||||
#include "display/shader.h"
|
||||
#include "display/spritebatch.h"
|
||||
#include "display/texture.h"
|
||||
#include "display/tileset.h"
|
||||
|
||||
#include "file/asset.h"
|
||||
|
||||
#include "game/game.h"
|
||||
|
||||
#include "input/input.h"
|
||||
|
||||
#include "util/list.h"
|
||||
|
||||
#include "world/entity/entity.h"
|
||||
#include "world/map/chunk.h"
|
||||
#include "world/map/map.h"
|
||||
#include "world/map/tile.h"
|
||||
#include "world/world.h"
|
18
include/dawn/display/camera.h
Normal file
18
include/dawn/display/camera.h
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Msters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/** The math for the camera is stored here. */
|
||||
typedef struct {
|
||||
/** View Matrix (Where the camera looks) */
|
||||
mat4 view;
|
||||
|
||||
/** Projection Matrix (How the camera looks) */
|
||||
mat4 projection;
|
||||
} camera_t;
|
30
include/dawn/display/primitive.h
Normal file
30
include/dawn/display/primitive.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
|
||||
#define PRIMITIVE_COORDINATES_PER_VERTICE 2
|
||||
|
||||
/** Structure containing information about a primitive */
|
||||
typedef struct {
|
||||
int32_t verticeCount;
|
||||
int32_t indiceCount;
|
||||
|
||||
GLuint vertexBuffer;
|
||||
GLuint indexBuffer;
|
||||
} primitive_t;
|
||||
|
||||
/** Structure containing vertice position information */
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
float u, v;
|
||||
} vertice_t;
|
||||
|
||||
/** Indice that references a specific vertice */
|
||||
typedef unsigned int indice_t;
|
19
include/dawn/display/render.h
Normal file
19
include/dawn/display/render.h
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Contains information about the current render state, can be used for querying
|
||||
* how the renderer is currently set up.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Resolution (in pixels) */
|
||||
int32_t width, height;
|
||||
} render_t;
|
||||
|
||||
/** Current render state */
|
||||
extern render_t RENDER_STATE;
|
41
include/dawn/display/shader.h
Normal file
41
include/dawn/display/shader.h
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Msters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
#define SHADER_UNI_VIEW "u_View"
|
||||
#define SHADER_UNI_PROJ "u_Proj"
|
||||
#define SHADER_UNI_TEXT "u_Text"
|
||||
#define SHADER_UNI_MODL "u_Modl"
|
||||
|
||||
/**
|
||||
* Structure containing information about an OpenGL Shader. For simplicity sake
|
||||
* we demand certain uninforms to be present on the shader target.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Pointer to an uploaded vertex shader program */
|
||||
GLuint shaderVertex;
|
||||
|
||||
/** Pointer to an uploaded fragment shader program */
|
||||
GLuint shaderFrag;
|
||||
|
||||
/** Pointer to an uploaded shader program linked */
|
||||
GLuint shaderProgram;
|
||||
|
||||
/** Matrix for the view matrix */
|
||||
GLint uniView;
|
||||
|
||||
/** Matrix for the projection matrix */
|
||||
GLint uniProj;
|
||||
|
||||
/** Uniform for the current texture */
|
||||
GLint uniText;
|
||||
|
||||
/** Uniform for the current model world position */
|
||||
GLint uniModl;
|
||||
} shader_t;
|
21
include/dawn/display/spritebatch.h
Normal file
21
include/dawn/display/spritebatch.h
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/** Definition of a Sprite Batch. */
|
||||
typedef struct {
|
||||
/** Maximum sprites the batch can hold. */
|
||||
int32_t maxSprites;
|
||||
|
||||
/** The current/next sprite index. */
|
||||
int32_t currentSprite;
|
||||
|
||||
/** Internal primitive */
|
||||
primitive_t *primitive;
|
||||
} spritebatch_t;
|
23
include/dawn/display/texture.h
Normal file
23
include/dawn/display/texture.h
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Structure detailing information about a texture.
|
||||
* Because we plan to upload the pixels of a texture into the GPU, we don't
|
||||
* store the pixels in memory because we don't need to!
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
GLuint id;
|
||||
} texture_t;
|
||||
|
||||
/** Information about a single pixel. */
|
||||
typedef struct {
|
||||
uint8_t r, g, b, a ;
|
||||
} pixel_t;
|
24
include/dawn/display/tileset.h
Normal file
24
include/dawn/display/tileset.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/** Division of a texture */
|
||||
typedef struct {
|
||||
float x0, y0, x1, y1;
|
||||
} tilesetdiv_t;
|
||||
|
||||
/** Definition of a Tileset */
|
||||
typedef struct {
|
||||
/** Count of X/Y divisions */
|
||||
int32_t columns, rows;
|
||||
|
||||
/** Count of divisions (unused) */
|
||||
int32_t count;
|
||||
|
||||
/** Division information */
|
||||
tilesetdiv_t *divisions;
|
||||
} tileset_t;
|
9
include/dawn/file/asset.h
Normal file
9
include/dawn/file/asset.h
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
/** Prefix of all asset load methods, may be customizable in future. */
|
||||
#define ASSET_PREFIX "../assets/"
|
25
include/dawn/game/game.h
Normal file
25
include/dawn/game/game.h
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../display/shader.h"
|
||||
#include "../display/camera.h"
|
||||
|
||||
/** Name of the current game */
|
||||
#define GAME_NAME "Dawn"
|
||||
|
||||
/** Describes the current game */
|
||||
typedef struct {
|
||||
/** Describes the name of a specific game. */
|
||||
char *name;
|
||||
|
||||
/** World Rendering stuff. */
|
||||
shader_t *shaderWorld;
|
||||
camera_t cameraWorld;
|
||||
} game_t;
|
||||
|
||||
/** The current running game state. */
|
||||
extern game_t GAME_STATE;
|
69
include/dawn/input/input.h
Normal file
69
include/dawn/input/input.h
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../util/list.h"
|
||||
|
||||
|
||||
/** Inputs */
|
||||
#define GAME_INPUT_UP (inputbind_t)0x01
|
||||
#define GAME_INPUT_DOWN (inputbind_t)0x02
|
||||
#define GAME_INPUT_LEFT (inputbind_t)0x03
|
||||
#define GAME_INPUT_RIGHT (inputbind_t)0x04
|
||||
|
||||
#define INPUT_NULL (inputbind_t)0x00
|
||||
#define INPUT_BIND_COUNT 128
|
||||
#define INPUT_SOURCE_COUNT 4096
|
||||
|
||||
/**
|
||||
* Input Bind, a specific action bind reference for the game engine to use.
|
||||
* e.g. "Jump" or "Walk Forward".
|
||||
*/
|
||||
typedef uint8_t inputbind_t;
|
||||
|
||||
/**
|
||||
* Input source identifier. It's up to the platform itself to decide what the
|
||||
* hell this number refers to. For most platforms it will be an input, such as a
|
||||
* keyboard scancode or a (pad number * button count) + button.
|
||||
*/
|
||||
typedef uint32_t inputsource_t;
|
||||
|
||||
/**
|
||||
* Value that represents the state of an input. Defined as 0-1 where 0 is set
|
||||
* to be completely off / netural state, and 1 is completely on / full state.
|
||||
*/
|
||||
typedef float inputval_t;
|
||||
|
||||
/**
|
||||
* Structure for the entire input mapping.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Float of the input between 0 and 1. */
|
||||
inputval_t inputsA[INPUT_BIND_COUNT];
|
||||
/** Float of the input between 0 and 1. */
|
||||
inputval_t inputsB[INPUT_BIND_COUNT];
|
||||
|
||||
/** Flippable state */
|
||||
inputval_t *current, *previous;
|
||||
|
||||
/**
|
||||
* Binding Map, Array of lists where index = binding and entry is a list of
|
||||
* input sources.
|
||||
*/
|
||||
list_t *bindMap[INPUT_BIND_COUNT];
|
||||
|
||||
/**
|
||||
* Input buffer array. Keeps track of raw values from the inputs.
|
||||
* The engine will read from the buffer when necessary.
|
||||
*/
|
||||
inputval_t buffer[INPUT_SOURCE_COUNT];
|
||||
|
||||
/** Float of the GameTime that the input was actuated last. */
|
||||
float times[INPUT_BIND_COUNT];
|
||||
} input_t;
|
||||
|
||||
/** The current input state */
|
||||
extern input_t INPUT_STATE;
|
21
include/dawn/libs.h
Normal file
21
include/dawn/libs.h
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
// Static Libs
|
||||
#include <cglm/cglm.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
// Standard Libs
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <string.h>
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# define strtok_r strtok_s
|
||||
#endif
|
31
include/dawn/util/list.h
Normal file
31
include/dawn/util/list.h
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
/**
|
||||
* Entry within a given linked list.
|
||||
* @param data* The pointer to the data that is within the entry.
|
||||
* @param prev* Pointer to the previous entry in the list.
|
||||
* @param next* Pointer to the next entry in the list.
|
||||
*/
|
||||
typedef struct listentry_t {
|
||||
void *data;
|
||||
struct listentry_t *prev;
|
||||
struct listentry_t *next;
|
||||
} listentry_t;
|
||||
|
||||
/**
|
||||
* Linked List of elements, Doubly Linked.
|
||||
* @param size The count of elements currently within the list
|
||||
* @param start* First element within the list.
|
||||
* @param end* Last element within the list.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t size;
|
||||
listentry_t *start;
|
||||
listentry_t *end;
|
||||
} list_t;
|
23
include/dawn/world/entity/entity.h
Normal file
23
include/dawn/world/entity/entity.h
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
|
||||
#define ENTITY_COUNT 64
|
||||
|
||||
typedef struct {
|
||||
int32_t gridX, gridY, gridZ;
|
||||
int32_t oldGridX, oldGridY, oldGridZ;
|
||||
float positionX, positionY, positionZ;
|
||||
} entity_t;
|
||||
|
||||
typedef struct {
|
||||
entity_t entities[ENTITY_COUNT]
|
||||
} entitystate_t;
|
||||
|
||||
extern entitystate_t ENTITY_STATE;
|
33
include/dawn/world/map/chunk.h
Normal file
33
include/dawn/world/map/chunk.h
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../display/primitive.h"
|
||||
#include "tile.h"
|
||||
|
||||
/** When loading a chunk, how many chars to offset (ASCII char to byte) */
|
||||
#define CHUNK_TILE_LOAD_ASCII 48
|
||||
|
||||
/** Width (in tiles) of chunks. */
|
||||
#define CHUNK_WIDTH 16
|
||||
/** Height (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 {
|
||||
/** Position (in absolute chunk coordinates) of this chunk */
|
||||
int32_t x, y, z;
|
||||
|
||||
/** Array of tiles within the chunk */
|
||||
tileid_t tiles[CHUNK_TILE_COUNT];
|
||||
|
||||
/** Ready to be rendered chunk 3d primitive */
|
||||
primitive_t *primitive;
|
||||
} chunk_t;
|
46
include/dawn/world/map/map.h
Normal file
46
include/dawn/world/map/map.h
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "tile.h"
|
||||
#include "chunk.h"
|
||||
#include "../../display/texture.h"
|
||||
#include "../../display/tileset.h"
|
||||
|
||||
/** Width of map (in chunks) */
|
||||
#define MAP_WIDTH 3
|
||||
/** Height of map (in chunks) */
|
||||
#define MAP_HEIGHT MAP_WIDTH
|
||||
/** Depth of map (in chunks) */
|
||||
#define MAP_DEPTH 2
|
||||
/** Count of chunks in the world */
|
||||
#define MAP_CHUNK_COUNT MAP_WIDTH * MAP_HEIGHT * MAP_DEPTH
|
||||
|
||||
#define MAP_ASSET_TEXTURE "world/tileset.png"
|
||||
|
||||
typedef struct {
|
||||
/** Tile definitions */
|
||||
tiledef_t *tileDefinitions;
|
||||
|
||||
/** Tileset predivided */
|
||||
tileset_t *tileset;
|
||||
|
||||
/** Texture of the tileset */
|
||||
texture_t *texture;
|
||||
|
||||
/** Current (chunk) coordinates of the first chunk in the chunk list */
|
||||
int32_t x, y, z;
|
||||
|
||||
/** Current chunk list, ordered */
|
||||
chunk_t *chunkList[MAP_CHUNK_COUNT];
|
||||
|
||||
/** Chunk array, unordered */
|
||||
chunk_t chunks[MAP_CHUNK_COUNT];
|
||||
} map_t;
|
||||
|
||||
extern map_t MAP_STATE;
|
29
include/dawn/world/map/tile.h
Normal file
29
include/dawn/world/map/tile.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
|
||||
/** Width of a tile (in pixels) */
|
||||
#define TILE_WIDTH 16
|
||||
/** Height of a tile (in pixels) */
|
||||
#define TILE_HEIGHT 16
|
||||
/** What a NULL tile is represented as. */
|
||||
#define TILE_NULL 0x00
|
||||
|
||||
/** Bitwise Flags from tiles. */
|
||||
typedef uint8_t tileflag_t;
|
||||
|
||||
/** Tile ID */
|
||||
typedef uint8_t tileid_t;
|
||||
|
||||
/** Representation of the information of a tile within a tilemap. */
|
||||
typedef struct {
|
||||
/** Flags of the tile */
|
||||
tileflag_t flags;
|
||||
|
||||
/** How many indices and vertices a tile with this definition has. */
|
||||
int32_t indiceCount, verticeCount;
|
||||
} tiledef_t;
|
9
include/dawn/world/world.h
Normal file
9
include/dawn/world/world.h
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "map/chunk.h"
|
||||
#include "map/map.h"
|
Reference in New Issue
Block a user