Begin refactor.

This commit is contained in:
2021-09-18 23:13:05 -07:00
parent df53c646a2
commit 2b7446b818
143 changed files with 1706 additions and 2345 deletions

View File

@ -5,7 +5,8 @@
* https://opensource.org/licenses/MIT
*/
#include <dawn/dawn.h>
#pragma once
#include "../../libs.h"
/**
* Animation tool for converting 0-1 space into a 0-0.5 back to zero space. This

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
/**
* Returns the ease time for a given real time duration span.
* @param start At what point in time the animation started
* @param current The current point in time the animation is at.
* @param duration The total duration on the animation.
* @returns The easing time (0-1 time) that the animation is at.
*/
#define easeTimeToEase(start, current, duration) ((current-start)/duration)
// Easing Functions, most were sourced from https://gist.github.com/gre/1650294
#define easeLinear(t) t
#define easeInQuad(t) (t*t)
#define easeOutQuad(t) (t*(2-t))
#define easeInOutQuad(t) (t < .5 ? 2*t*t : -1+(4-2*t)*t)
#define easeInCubic(t) (t*t*t)
#define easeOutCubic(t) ((t-1)*(t-1)*(t-1)+1)
#define easeInOutCubic(t) (t < .5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1)
#define easeInQuart(t) (t*t*t*t)
#define easeOutQuart(t) (1 - (t-1)*(t-1)*(t-1)*(t-1))
#define easeInOutQuart(t) (t < .5 ? 8*t*t*t*t : 1-8*(t-1)*(t-1)*(t-1)*(t-1))
#define easeInQuint(t) (t*t*t*t*t)
#define easeOutQuint(t) (1 + (t-1)*(t-1)*(t-1)*(t-1)*(t-1))
#define easeInOutQuint(t) (t<.5 ? 16*t*t*t*t*t : 1+16*(t-1)*(t-1)*(t-1)*(t-1)*(t-1))

View File

@ -6,8 +6,58 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../../libs.h"
#include "../../util/array.h"
#include "../../engine/engine.h"
#define ANIMATION_QUEUE_ITEM_MAX 128
#define ANIMATION_QUEUE_START 0xFF
typedef struct _queueaction_t queueaction_t;
typedef struct _queue_t queue_t;
/**
* Callback for queue events.
* @param conversation Conversation this text is attached to.
* @param text Text item that is being used in the callback
* @param i Index of the item in the queue.
*/
typedef void queuecallback_t(queue_t *queue, queueaction_t *action, uint8_t i);
typedef struct _queueaction_t {
/** Index that the action is within the queue */
uint8_t index;
/** Pointer to any custom user data */
void *data;
/** Callback to fire the moment the action is active in the queue */
queuecallback_t *onStart;
/** Callback to fire when this action has ended */
queuecallback_t *onEnd;
/** Callback to fire every update of this queue while action is active. */
queuecallback_t *onUpdate;
} queueaction_t;
typedef struct _queue_t {
/** Array of items within the queue. */
queueaction_t items[ANIMATION_QUEUE_ITEM_MAX];
uint8_t count;
/** Current index within the array of actions that is currently processing */
uint8_t current;
/** Internal timeline tracking */
float timeline;
/** Time that the current aciton started */
float actionStarted;
/** Delay Queue Item Storage */
float delays[ANIMATION_QUEUE_ITEM_MAX];
} queue_t;
/**
* Initialize the queue set.

View File

@ -4,7 +4,77 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../../libs.h"
/** Maximum number of actions a timeline can support, smaller than 0xFF */
#define TIMELINE_ACTION_COUNT_MAX 128
/** Type forwarders */
typedef struct _timeline_t timeline_t;
typedef struct _timelineaction_t timelineaction_t;
/**
* Callback for when a timeline event occurs
* @param timeline The timeline that fired this callback.
* @param action The action that this callback is attached to.
* @param i The index that this action is within the timeline.
*/
typedef void timelinecallback_t(timeline_t *timeline, timelineaction_t *action,
uint8_t i
);
typedef struct _timelineaction_t {
/** Pointer to any custom user data the timeline action wants to use. */
void *data;
/**
* The time that this action should occur within the timeline
* set to 0 or less to start immediately.
*/
float start;
/**
* The duration of the action, this will decide for how long onDuration will
* be called for, and when onEnd should be called.
* Set to a negative number to have this continue forever.
* Set to 0 to only fire the onStart.
* onStart can fire with either onDuration and onEnd on the same frame, but
* onEnd and onDuration cannot fire the same frame.
*/
float duration;
/**
* Enables animation looping. This works by forcing start to be equal to the
* current time at the point in time that onEnd is called. This will also stop
* onStart being called so ensure that your onStart and onEnd logic works.
*/
bool loop;
timelinecallback_t *onStart;
timelinecallback_t *onDuration;
timelinecallback_t *onEnd;
} timelineaction_t;
typedef struct _timeline_t {
/** The current time as far as the timeline is concerned */
float current;
/** The time of the last "frame" as far as the timeline is concerned */
float previous;
/** The frame time diff, essentially current = previous + diff */
float diff;
/** User pointer, allows you to point to some other data */
void *user;
/** Actions within the timeline */
timelineaction_t actions[TIMELINE_ACTION_COUNT_MAX];
uint8_t actionCount;
} timeline_t;
/**
* Initializes a timeline back to its default state.

View File

@ -6,8 +6,26 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "spritebatch.h"
#include "tileset.h"
/** Which is the first character within the font tilemap */
#define BITMAP_FONT_CHAR_START 33
/** Center a font along the X axis */
#define BITMAP_FONT_CENTER_X 9876543
/** Center a font along the Y axis */
#define BITMAP_FONT_CENTER_Y -BITMAP_FONT_CENTER_X
/** Align right edge of font to origin */
#define BITMAP_FONT_RIGHT_X (BITMAP_FONT_CENTER_X-1)
typedef struct {
float width, height;
int32_t lines;
} bitmapfontmeasure_t;
/**
* Get the division for a given character.

View File

@ -4,9 +4,19 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "../util/math.h"
#include "matrix.h"
/** The math for the camera is stored here. */
typedef struct {
/** View Matrix (Where the camera looks) */
matrix_t view;
/** Projection Matrix (How the camera looks) */
matrix_t projection;
} camera_t;
/**
* Make a camera look at a position in world space while itself being positioned
* within world space.

View File

@ -6,13 +6,84 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "texture.h"
#include "primitive.h"
#include "primitives/quad.h"
#include "../util/mem.h"
/** Which character (ASCII) to start the font from */
#define FONT_FIRST_CHAR 32
/** How many characters (after the first char) to generate */
#define FONT_NUM_CHARS 96
/** Width of the loaded font texture */
#define FONT_TEXTURE_WIDTH 1024
/** Height of the loaded font texture */
#define FONT_TEXTURE_HEIGHT FONT_TEXTURE_WIDTH
/** Refer to STBTT docs for OpenGL Fill Mode v d3d Fill Modes */
#define FONT_FILL_MODE 1
/** Passed to STBTT for scaling the font, essentially the font resolution */
#define FONT_TEXTURE_SIZE 64.0f
/** The global scale, just used to provide fine control of font sizes */
#define FONT_GLOBAL_SCALE 0.5f;
/** Default Font Size (on which all font scales are based) */
#define FONT_SIZE_DEFAULT 16.0f
// Chars
#define FONT_NEWLINE '\n'
#define FONT_SPACE ' '
// Heights
#define FONT_LINE_HEIGHT FONT_TEXTURE_SIZE * 0.75f
#define FONT_INITIAL_LINE FONT_LINE_HEIGHT * 0.75f
#define FONT_SPACE_SIZE FONT_TEXTURE_SIZE * 0.45f
/** Maximum number of characters a font text info can hold. */
#define FONT_TEXT_INFO_CHARS_MAX 1024
/** Maximum number of newlines that a font text info can hold. */
#define FONT_TEXT_INFO_LINES_MAX FONT_TEXT_INFO_CHARS_MAX/50
/** Representation of a font that can be used to render text */
typedef struct {
texture_t texture;
stbtt_bakedchar characterData[FONT_NUM_CHARS];
} font_t;
typedef struct {
/** What (real character) index the line starts at */
int32_t start;
/** How many (real) characters the line is in length */
int32_t length;
} fonttextinfoline_t;
typedef struct {
/** How many raw chars are in the string */
int32_t length;
/** How many real characters (non whitespace) are in the string */
int32_t realLength;
/** How many lines is the string? Trailing newlines will count */
int32_t lineCount;
/** The real character info for each line */
fonttextinfoline_t lines[FONT_TEXT_INFO_LINES_MAX];
/** Dimensions of the string */
float width, height;
/** Array of precalculated quads */
stbtt_aligned_quad quads[FONT_TEXT_INFO_CHARS_MAX];
} fonttextinfo_t;
/**
* Initializes Font from raw TTF data.
* @param font Font to initialize

View File

@ -6,8 +6,15 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "texture.h"
#include "render.h"
typedef struct {
GLuint fboId;
GLuint rboId;
texture_t texture;
} framebuffer_t;
/**
* Initializes frame buffer that can be rendered to.

View File

@ -6,7 +6,16 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
/**
* Representation for a matrix. Used as a highlevel wrapper for the math
* functions that sit underneath this API.
*/
typedef struct {
/** Internal Matrix API */
mat4 internalMatrix;
} matrix_t;
/**
* Makes matrix identity.

View File

@ -6,7 +6,34 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
#define PRIMITIVE_COORDINATES_PER_VERTICE 2
/** Structure containing information about a primitive */
typedef struct {
/** How many vertices are in the primitive */
int32_t verticeCount;
/** How many indices are in the primitive */
int32_t indiceCount;
/** Pointer to the vertex buffer on the GPU */
GLuint vertexBuffer;
/** Pointer to the index buffer on the GPU */
GLuint indexBuffer;
} primitive_t;
/** Structure containing vertice position information */
typedef struct {
/** Coordinates */
float x, y, z;
/** Texture UVs */
float u, v;
} vertice_t;
/** Indice that references a specific vertice */
typedef unsigned int indice_t;
/**
* Creates a new primitive.

View File

@ -4,13 +4,12 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../../libs.h"
#include "../primitive.h"
#define CUBE_VERTICE_COUNT 8
#define CUBE_INDICE_COUNT 36
/**
* Buffer the vertices and indices of a cube onto a primitive.
* @param primitive Primitive to buffer to.

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../../libs.h"
#include "../primitive.h"
#define QUAD_VERTICE_COUNT 4

View File

@ -4,7 +4,8 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../../libs.h"
#include "../../util/math.h"
#include "../primitive.h"
/** How many slices in each cylinder. */

View File

@ -4,9 +4,18 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "framebuffer.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). Floats to allow subpixels in future. */
float width, height;
} render_t;
/**
* Initialize the renderer.
*/

View File

@ -6,7 +6,7 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "../game/game.h"
#include "framebuffer.h"
#include "primitive.h"
@ -15,6 +15,27 @@
#include "primitives/quad.h"
#include "../util/dynarray.h"
typedef struct {
framebuffer_t frame;
shader_t *shader;
} renderpass_t;
typedef struct {
framebuffer_t frame;
primitive_t quad;
dynarray_t passes;
void *user;
} renderlist_t;
typedef void renderitemcallback_t(
renderlist_t *list, renderpass_t *pass, engine_t *engine, int32_t i
);
typedef struct {
renderitemcallback_t *onRender;
} renderitem_t;
void renderListInit(renderlist_t *list, int32_t passes, int32_t width, int32_t height);
renderpass_t * renderListGetPass(renderlist_t *list, int32_t pass);
int32_t renderPassAdd(renderlist_t *list);

View File

@ -6,9 +6,46 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "camera.h"
#include "shader.h"
#include "../engine/engine.h"
/** Maximum number of items a scene can support */
#define SCENE_ITEMS_MAX 32
typedef struct _scene_t scene_t;
typedef struct _sceneitem_t sceneitem_t;
/**
* Callback for when scene events occur.
*
* @param scene The scene that is being evented.
* @param i The index of the current scene item.
* @param engine The game's engine.
*/
typedef void sceneitemcallback_t(
scene_t *scene, int32_t i, engine_t *engine
);
typedef struct _sceneitem_t {
sceneitemcallback_t *onUpdate;
sceneitemcallback_t *onRender;
sceneitemcallback_t *onDispose;
} sceneitem_t;
typedef struct _scene_t {
/** Camera that is used to render the scene */
camera_t camera;
/** Any custom user data pointer */
void *user;
/** Items within the scene */
sceneitem_t items[SCENE_ITEMS_MAX];
int32_t itemCount;
} scene_t;
void sceneInit(scene_t *scene);

View File

@ -6,8 +6,49 @@
*/
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "matrix.h"
#include "camera.h"
#include "texture.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"
#define SHADER_UNI_COLR "u_Colr"
/** Representation of a shader uniform */
typedef GLuint shaderuniform_t;
/**
* 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 */
shaderuniform_t shaderVertex;
/** Pointer to an uploaded fragment shader program */
shaderuniform_t shaderFrag;
/** Pointer to an uploaded shader program linked */
shaderuniform_t shaderProgram;
/** Matrix for the view matrix */
shaderuniform_t uniView;
/** Matrix for the projection matrix */
shaderuniform_t uniProj;
/** Uniform for the current texture */
shaderuniform_t uniText;
/** Uniform for the current model world position */
shaderuniform_t uniModl;
/** Uniform for the color multiplier */
shaderuniform_t uniColr;
} shader_t;
/**
* Compiles a shader from vertex and fragment shader code.

View File

@ -4,10 +4,22 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#include "../libs.h"
#include "primitive.h"
#include "primitives/quad.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;
/**
* Creates a new Sprite Batch made of standard quads.
*

View File

@ -4,7 +4,34 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#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 {
/** Width (in pixels) of the texture */
int32_t width;
/** Height (in pixels) of the texture */
int32_t height;
/** Texture ID on the GPU */
GLuint id;
} texture_t;
/** Information about a single pixel. */
typedef struct {
/** RGBA Color values */
uint8_t r, g, b, a;
} pixel_t;
#define PIXEL_COLOR_WHITE ((pixel_t){ .r = 255, .g = 255, .b = 255, .a = 255 })
#define PIXEL_COLOR_RED ((pixel_t){ .r = 255, .g = 0, .b = 0, .a = 255 })
#define PIXEL_COLOR_GREEN ((pixel_t){ .r = 0, .g = 255, .b = 0, .a = 255 })
#define PIXEL_COLOR_BLUE ((pixel_t){ .r = 0, .g = 0, .b = 255, .a = 255 })
#define PIXEL_COLOR_BLACK ((pixel_t){ .r = 0, .g = 0, .b = 0, .a = 255 })
#define PIXEL_COLOR_TRANSPARENT ((pixel_t){ .r = 0, .g = 0, .b = 0, .a = 0 })
/**
* Initializes a texture that can be written in to.

View File

@ -4,7 +4,27 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
#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;
/** Size of each divison (in pixels) */
float divX, divY;
/** Count of divisions (unused) */
int32_t count;
/** Division information */
tilesetdiv_t *divisions;
} tileset_t;
/**
* Create a tileset. Tilesets will be pre-divided to save performance later.