Just adding more assertions.
This commit is contained in:
@ -8,6 +8,8 @@
|
|||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
void queueInit(queue_t *queue) {
|
void queueInit(queue_t *queue) {
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
|
||||||
queue->timeline = 0;
|
queue->timeline = 0;
|
||||||
queue->count = 0;
|
queue->count = 0;
|
||||||
queue->current = ANIMATION_QUEUE_START;
|
queue->current = ANIMATION_QUEUE_START;
|
||||||
@ -16,6 +18,8 @@ void queueInit(queue_t *queue) {
|
|||||||
queueaction_t * queueNext(queue_t *queue) {
|
queueaction_t * queueNext(queue_t *queue) {
|
||||||
queueaction_t *action;
|
queueaction_t *action;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
|
||||||
// Is there a currently running action? If so, end it.
|
// Is there a currently running action? If so, end it.
|
||||||
if(queue->current != ANIMATION_QUEUE_START) {
|
if(queue->current != ANIMATION_QUEUE_START) {
|
||||||
action = queue->items + queue->current;
|
action = queue->items + queue->current;
|
||||||
@ -35,8 +39,10 @@ queueaction_t * queueNext(queue_t *queue) {
|
|||||||
|
|
||||||
queueaction_t * queueAdd(queue_t *queue) {
|
queueaction_t * queueAdd(queue_t *queue) {
|
||||||
queueaction_t *action;
|
queueaction_t *action;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
|
||||||
action = queue->items + queue->count;
|
action = queue->items + queue->count;
|
||||||
|
|
||||||
action->index = queue->count;
|
action->index = queue->count;
|
||||||
action->data = NULL;
|
action->data = NULL;
|
||||||
action->onStart = NULL;
|
action->onStart = NULL;
|
||||||
@ -49,6 +55,10 @@ queueaction_t * queueAdd(queue_t *queue) {
|
|||||||
|
|
||||||
void queueUpdate(queue_t *queue, float delta) {
|
void queueUpdate(queue_t *queue, float delta) {
|
||||||
queueaction_t *action;
|
queueaction_t *action;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
ASSERT_GREATER_THAN(delta, 0);
|
||||||
|
|
||||||
queue->timeline += delta;
|
queue->timeline += delta;
|
||||||
if(queue->current >= queue->count) return;
|
if(queue->current >= queue->count) return;
|
||||||
|
|
||||||
@ -60,6 +70,8 @@ void queueUpdate(queue_t *queue, float delta) {
|
|||||||
|
|
||||||
void queueDispose(queue_t *queue) {
|
void queueDispose(queue_t *queue) {
|
||||||
queueaction_t *action;
|
queueaction_t *action;
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
|
||||||
if(queue->current >= queue->count) return;
|
if(queue->current >= queue->count) return;
|
||||||
action = queue->items + queue->current;
|
action = queue->items + queue->current;
|
||||||
if(action->onEnd != NULL) action->onEnd(queue, action, queue->current);
|
if(action->onEnd != NULL) action->onEnd(queue, action, queue->current);
|
||||||
@ -67,6 +79,7 @@ void queueDispose(queue_t *queue) {
|
|||||||
|
|
||||||
void queueRestack(queue_t *queue) {
|
void queueRestack(queue_t *queue) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
|
||||||
// Rewind the array.
|
// Rewind the array.
|
||||||
arrayRewind(sizeof(queueaction_t), queue->items, ANIMATION_QUEUE_START,
|
arrayRewind(sizeof(queueaction_t), queue->items, ANIMATION_QUEUE_START,
|
||||||
@ -84,13 +97,24 @@ void queueRestack(queue_t *queue) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _queueDelayUpdate(queue_t *queue, queueaction_t *action, uint8_t i) {
|
void _queueDelayUpdate(queue_t *queue, queueaction_t *action, uint8_t i) {
|
||||||
float n = queue->timeline - queue->actionStarted;
|
float n;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
ASSERT_NOT_NULL(action);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
||||||
|
|
||||||
|
n = queue->timeline - queue->actionStarted;
|
||||||
if(n < queue->delays[i]) return;
|
if(n < queue->delays[i]) return;
|
||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
queueaction_t * queueDelay(queue_t *queue, float delay) {
|
queueaction_t * queueDelay(queue_t *queue, float delay) {
|
||||||
queueaction_t *action = queueAdd(queue);
|
queueaction_t *action;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(queue);
|
||||||
|
ASSERT_GREATER_THAN(delay, 0);
|
||||||
|
|
||||||
|
action = queueAdd(queue);
|
||||||
queue->delays[action->index] = delay;
|
queue->delays[action->index] = delay;
|
||||||
action->onUpdate = &_queueDelayUpdate;
|
action->onUpdate = &_queueDelayUpdate;
|
||||||
return action;
|
return action;
|
||||||
|
@ -10,6 +10,11 @@
|
|||||||
void _timelineActionDeltaUpdateStart(
|
void _timelineActionDeltaUpdateStart(
|
||||||
timeline_t *timeline, timelineaction_t *action, uint8_t i
|
timeline_t *timeline, timelineaction_t *action, uint8_t i
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
ASSERT_NOT_NULL(action);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
||||||
|
ASSERT_LESS_THAN(i, TIMELINE_ACTION_COUNT_MAX);
|
||||||
|
|
||||||
if(action->data == NULL) return;
|
if(action->data == NULL) return;
|
||||||
*((float *)action->data) = timeline->initials[i];
|
*((float *)action->data) = timeline->initials[i];
|
||||||
}
|
}
|
||||||
@ -18,6 +23,12 @@ void _timelineActionDeltaUpdateDuration(
|
|||||||
timeline_t *timeline, timelineaction_t *action, uint8_t i
|
timeline_t *timeline, timelineaction_t *action, uint8_t i
|
||||||
) {
|
) {
|
||||||
float n;
|
float n;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
ASSERT_NOT_NULL(action);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
||||||
|
ASSERT_LESS_THAN(i, TIMELINE_ACTION_COUNT_MAX);
|
||||||
|
|
||||||
if(action->data == NULL) return;
|
if(action->data == NULL) return;
|
||||||
n = timeline->easings[i](
|
n = timeline->easings[i](
|
||||||
timelineActionGetTimeRaw(timeline, action)
|
timelineActionGetTimeRaw(timeline, action)
|
||||||
@ -28,12 +39,19 @@ void _timelineActionDeltaUpdateDuration(
|
|||||||
void _timelineActionDeltaUpdateEnd(
|
void _timelineActionDeltaUpdateEnd(
|
||||||
timeline_t *timeline, timelineaction_t *action, uint8_t i
|
timeline_t *timeline, timelineaction_t *action, uint8_t i
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
ASSERT_NOT_NULL(action);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(i, 0);
|
||||||
|
ASSERT_LESS_THAN(i, TIMELINE_ACTION_COUNT_MAX);
|
||||||
|
|
||||||
if(action->data == NULL) return;
|
if(action->data == NULL) return;
|
||||||
*((float *)action->data) = timeline->initials[i] + timeline->deltas[i];
|
*((float *)action->data) = timeline->initials[i] + timeline->deltas[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void timelineInit(timeline_t *timeline) {
|
void timelineInit(timeline_t *timeline) {
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
|
||||||
timeline->current = 0;
|
timeline->current = 0;
|
||||||
timeline->diff = 0;
|
timeline->diff = 0;
|
||||||
timeline->previous = 0;
|
timeline->previous = 0;
|
||||||
@ -46,6 +64,9 @@ void timelineUpdate(timeline_t *timeline, float delta) {
|
|||||||
timelineaction_t *action;
|
timelineaction_t *action;
|
||||||
float full;
|
float full;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
ASSERT_GREATER_THAN(delta, 0);
|
||||||
|
|
||||||
timeline->diff = delta;
|
timeline->diff = delta;
|
||||||
timeline->previous = timeline->current;
|
timeline->previous = timeline->current;
|
||||||
timeline->current = timeline->current + delta;
|
timeline->current = timeline->current + delta;
|
||||||
@ -80,6 +101,8 @@ bool timelineIsFinished(timeline_t *timeline) {
|
|||||||
uint8_t i;
|
uint8_t i;
|
||||||
timelineaction_t *action;
|
timelineaction_t *action;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
|
||||||
for(i = 0; i < timeline->actionCount; i++) {
|
for(i = 0; i < timeline->actionCount; i++) {
|
||||||
action = timeline->actions +i;
|
action = timeline->actions +i;
|
||||||
if(action->start > timeline->current) return false;
|
if(action->start > timeline->current) return false;
|
||||||
@ -94,7 +117,12 @@ bool timelineIsFinished(timeline_t *timeline) {
|
|||||||
timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
|
timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
|
||||||
float duration
|
float duration
|
||||||
) {
|
) {
|
||||||
timelineaction_t *action = timeline->actions + (timeline->actionCount++);
|
timelineaction_t *action;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(start, 0);
|
||||||
|
|
||||||
|
action = timeline->actions + (timeline->actionCount++);
|
||||||
action->loop = false;
|
action->loop = false;
|
||||||
action->start = start, action->duration = duration;
|
action->start = start, action->duration = duration;
|
||||||
action->onStart = action->onEnd = action->onDuration = NULL;
|
action->onStart = action->onEnd = action->onDuration = NULL;
|
||||||
@ -106,6 +134,9 @@ timelineaction_t * timelineAddDeltaAction(timeline_t *timeline,
|
|||||||
easefunction_t *easing, float *destination
|
easefunction_t *easing, float *destination
|
||||||
) {
|
) {
|
||||||
timelineaction_t *action;
|
timelineaction_t *action;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
|
||||||
timeline->initials[timeline->actionCount] = initial;
|
timeline->initials[timeline->actionCount] = initial;
|
||||||
timeline->deltas[timeline->actionCount] = delta;
|
timeline->deltas[timeline->actionCount] = delta;
|
||||||
timeline->easings[timeline->actionCount] = (
|
timeline->easings[timeline->actionCount] = (
|
||||||
@ -123,19 +154,29 @@ timelineaction_t * timelineAddDeltaActionTo(timeline_t *timeline,
|
|||||||
float start, float duration, float initial, float end,
|
float start, float duration, float initial, float end,
|
||||||
easefunction_t *easing, float *destination
|
easefunction_t *easing, float *destination
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
|
||||||
return timelineAddDeltaAction(
|
return timelineAddDeltaAction(
|
||||||
timeline, start, duration, initial, end-initial, easing, destination
|
timeline, start, duration, initial, end-initial, easing, destination
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
float timelineActionGetTimeRaw(timeline_t *timeline, timelineaction_t *action) {
|
float timelineActionGetTimeRaw(timeline_t *timeline, timelineaction_t *action) {
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
ASSERT_NOT_NULL(action);
|
||||||
|
|
||||||
return (timeline->current - action->start) / action->duration;
|
return (timeline->current - action->start) / action->duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
float timelineActionGetTime(timeline_t *tl, timelineaction_t *at) {
|
float timelineActionGetTime(timeline_t *tl, timelineaction_t *at) {
|
||||||
|
ASSERT_NOT_NULL(tl);
|
||||||
|
ASSERT_NOT_NULL(at);
|
||||||
|
|
||||||
return mathClamp(timelineActionGetTimeRaw(tl, at), 0, 1);
|
return mathClamp(timelineActionGetTimeRaw(tl, at), 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timelineClear(timeline_t *timeline) {
|
void timelineClear(timeline_t *timeline) {
|
||||||
|
ASSERT_NOT_NULL(timeline);
|
||||||
|
|
||||||
timeline->actionCount = 0;
|
timeline->actionCount = 0;
|
||||||
}
|
}
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
|
#include "../../assert/assert.h"
|
||||||
#include "../../util/math.h"
|
#include "../../util/math.h"
|
||||||
#include "easing.h"
|
#include "easing.h"
|
||||||
|
|
||||||
|
@ -15,10 +15,19 @@
|
|||||||
|
|
||||||
void fontInit(font_t *font, char *data) {
|
void fontInit(font_t *font, char *data) {
|
||||||
int32_t i, s;
|
int32_t i, s;
|
||||||
|
uint8_t *bitmapData;
|
||||||
|
pixel_t *pixels;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(font);
|
||||||
|
ASSERT_NOT_NULL(data);
|
||||||
|
|
||||||
s = FONT_TEXTURE_WIDTH * FONT_TEXTURE_HEIGHT;
|
s = FONT_TEXTURE_WIDTH * FONT_TEXTURE_HEIGHT;
|
||||||
|
|
||||||
uint8_t *bitmapData = malloc(sizeof(uint8_t) * s);
|
bitmapData = malloc(sizeof(uint8_t) * s);
|
||||||
pixel_t *pixels = malloc(sizeof(pixel_t) * s);
|
ASSERT_NOT_NULL(bitmapData);
|
||||||
|
|
||||||
|
pixels = malloc(sizeof(pixel_t) * s);
|
||||||
|
ASSERT_NOT_NULL(pixels);
|
||||||
|
|
||||||
// STBTT Loads fonts as single channel values only.
|
// STBTT Loads fonts as single channel values only.
|
||||||
stbtt_BakeFontBitmap(
|
stbtt_BakeFontBitmap(
|
||||||
@ -41,14 +50,21 @@ void fontInit(font_t *font, char *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fontDispose(font_t *font) {
|
void fontDispose(font_t *font) {
|
||||||
|
ASSERT_NOT_NULL(font);
|
||||||
textureDispose(&font->texture);
|
textureDispose(&font->texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
float fontGetScale(float fontSize) {
|
float fontGetScale(float fontSize) {
|
||||||
|
ASSERT_GREATER_THAN(fontSize, 0);
|
||||||
|
|
||||||
return fontSize / FONT_SIZE_DEFAULT * FONT_GLOBAL_SCALE;
|
return fontSize / FONT_SIZE_DEFAULT * FONT_GLOBAL_SCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _fontTextBufferAddLine(fonttextinfo_t *info, int32_t start, int32_t len) {
|
bool _fontTextBufferAddLine(fonttextinfo_t *info, int32_t start, int32_t len) {
|
||||||
|
ASSERT_NOT_NULL(info);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(start, 0);
|
||||||
|
ASSERT_GREATER_THAN(len, 0);
|
||||||
|
|
||||||
info->lineCount++;
|
info->lineCount++;
|
||||||
|
|
||||||
if(info->lineCount >= FONT_TEXT_INFO_LINES_MAX) {
|
if(info->lineCount >= FONT_TEXT_INFO_LINES_MAX) {
|
||||||
@ -70,8 +86,16 @@ void fontTextBuffer(
|
|||||||
stbtt_aligned_quad *quads;
|
stbtt_aligned_quad *quads;
|
||||||
stbtt_aligned_quad *quad;
|
stbtt_aligned_quad *quad;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(font);
|
||||||
|
ASSERT_NOT_NULL(primitive);
|
||||||
|
ASSERT_NOT_NULL(info);
|
||||||
|
ASSERT_NOT_NULL(text);
|
||||||
|
ASSERT_GREATER_THAN(maxWidth, 0);
|
||||||
|
ASSERT_GREATER_THAN(fontSize, 0);
|
||||||
|
|
||||||
// Make some space
|
// Make some space
|
||||||
quads = malloc(sizeof(stbtt_aligned_quad) * strlen(text));
|
quads = malloc(sizeof(stbtt_aligned_quad) * strlen(text));
|
||||||
|
ASSERT_NOT_NULL(quads);
|
||||||
|
|
||||||
// Get the font scale
|
// Get the font scale
|
||||||
scale = fontGetScale(fontSize);
|
scale = fontGetScale(fontSize);
|
||||||
@ -198,6 +222,11 @@ void fontTextBuffer(
|
|||||||
|
|
||||||
int32_t fontGetLineCharCount(fonttextinfo_t *info,int32_t start,int32_t count) {
|
int32_t fontGetLineCharCount(fonttextinfo_t *info,int32_t start,int32_t count) {
|
||||||
int32_t charCount, i, m;
|
int32_t charCount, i, m;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(info);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(start, 0);
|
||||||
|
ASSERT_GREATER_THAN(count, 0);
|
||||||
|
|
||||||
m = mathMin(start+count, info->lineCount);
|
m = mathMin(start+count, info->lineCount);
|
||||||
|
|
||||||
charCount = 0;
|
charCount = 0;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "primitive/quad.h"
|
#include "primitive/quad.h"
|
||||||
#include "../util/mem.h"
|
#include "../util/mem.h"
|
||||||
#include "../util/math.h"
|
#include "../util/math.h"
|
||||||
|
#include "../assert/assert.h"
|
||||||
|
|
||||||
/** Which character (ASCII) to start the font from */
|
/** Which character (ASCII) to start the font from */
|
||||||
#define FONT_FIRST_CHAR 32
|
#define FONT_FIRST_CHAR 32
|
||||||
|
@ -12,8 +12,12 @@ void cubeBuffer(primitive_t *prim,
|
|||||||
float w, float h, float d,
|
float w, float h, float d,
|
||||||
int32_t verticeStart, int32_t indiceStart
|
int32_t verticeStart, int32_t indiceStart
|
||||||
) {
|
) {
|
||||||
vertice_t *vertices = malloc(sizeof(vertice_t) * CUBE_VERTICE_COUNT);
|
vertice_t vertices[CUBE_VERTICE_COUNT];
|
||||||
indice_t *indices = malloc(sizeof(indice_t) * CUBE_INDICE_COUNT);
|
indice_t indices[CUBE_INDICE_COUNT];
|
||||||
|
|
||||||
|
ASSERT_GREATER_THAN(w, 0);
|
||||||
|
ASSERT_GREATER_THAN(h, 0);
|
||||||
|
ASSERT_GREATER_THAN(d, 0);
|
||||||
|
|
||||||
vertices[0].x = x, vertices[0].y = y, vertices[0].z = z;
|
vertices[0].x = x, vertices[0].y = y, vertices[0].z = z;
|
||||||
vertices[0].u = 0, vertices[0].v = 0;
|
vertices[0].u = 0, vertices[0].v = 0;
|
||||||
@ -96,9 +100,6 @@ void cubeBuffer(primitive_t *prim,
|
|||||||
|
|
||||||
primitiveBufferVertices(prim, verticeStart, CUBE_VERTICE_COUNT, vertices);
|
primitiveBufferVertices(prim, verticeStart, CUBE_VERTICE_COUNT, vertices);
|
||||||
primitiveBufferIndices(prim, indiceStart, CUBE_INDICE_COUNT, indices);
|
primitiveBufferIndices(prim, indiceStart, CUBE_INDICE_COUNT, indices);
|
||||||
|
|
||||||
free(vertices);
|
|
||||||
free(indices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cubeInit(primitive_t *primitive, float w, float h, float d) {
|
void cubeInit(primitive_t *primitive, float w, float h, float d) {
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
void primitiveInit(primitive_t *primitive,
|
void primitiveInit(primitive_t *primitive,
|
||||||
int32_t verticeCount, int32_t indiceCount
|
int32_t verticeCount, int32_t indiceCount
|
||||||
) {
|
) {
|
||||||
|
ASSERT_NOT_NULL(primitive);
|
||||||
|
ASSERT_GREATER_THAN(verticeCount, 0);
|
||||||
|
ASSERT_GREATER_THAN(indiceCount, 0);
|
||||||
|
|
||||||
primitive->verticeCount = verticeCount;
|
primitive->verticeCount = verticeCount;
|
||||||
primitive->indiceCount = indiceCount;
|
primitive->indiceCount = indiceCount;
|
||||||
|
|
||||||
@ -19,12 +23,11 @@ void primitiveInit(primitive_t *primitive,
|
|||||||
size_t sizeIndices = sizeof(indice_t) * indiceCount;
|
size_t sizeIndices = sizeof(indice_t) * indiceCount;
|
||||||
|
|
||||||
// Create some buffers, one for the vertex data, one for the indices
|
// Create some buffers, one for the vertex data, one for the indices
|
||||||
GLuint *buffer = malloc(sizeof(GLuint) * 2);
|
GLuint buffer[2];
|
||||||
glGenBuffers(2, buffer);
|
glGenBuffers(2, buffer);
|
||||||
|
|
||||||
primitive->vertexBuffer = buffer[0];
|
primitive->vertexBuffer = buffer[0];
|
||||||
primitive->indexBuffer = buffer[1];
|
primitive->indexBuffer = buffer[1];
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
// Buffer an empty set of data then buffer each component
|
// Buffer an empty set of data then buffer each component
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, primitive->vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, primitive->vertexBuffer);
|
||||||
@ -54,6 +57,11 @@ void primitiveBufferVertices(primitive_t *primitive,
|
|||||||
float *positions, *coordinates;
|
float *positions, *coordinates;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(primitive);
|
||||||
|
ASSERT_NOT_NULL(vertices);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(position, 0);
|
||||||
|
ASSERT_GREATER_THAN(count, 0);
|
||||||
|
|
||||||
// Setup the size of the memory that the positions and coordinates will use
|
// Setup the size of the memory that the positions and coordinates will use
|
||||||
lengthPositions = sizeof(float) * PRIMITIVE_POSITIONS_PER_VERTICE * count;
|
lengthPositions = sizeof(float) * PRIMITIVE_POSITIONS_PER_VERTICE * count;
|
||||||
offsetPositions = sizeof(float) * PRIMITIVE_POSITIONS_PER_VERTICE * position;
|
offsetPositions = sizeof(float) * PRIMITIVE_POSITIONS_PER_VERTICE * position;
|
||||||
@ -66,7 +74,10 @@ void primitiveBufferVertices(primitive_t *primitive,
|
|||||||
|
|
||||||
// Create some memory
|
// Create some memory
|
||||||
positions = malloc(lengthPositions);
|
positions = malloc(lengthPositions);
|
||||||
|
ASSERT_NOT_NULL(positions);
|
||||||
|
|
||||||
coordinates = malloc(lengthCoordinates);
|
coordinates = malloc(lengthCoordinates);
|
||||||
|
ASSERT_NOT_NULL(coordinates);
|
||||||
|
|
||||||
// Now copy the positions and coordinates from the vertices into the buffer
|
// Now copy the positions and coordinates from the vertices into the buffer
|
||||||
for(i = 0; i < count; i++) {
|
for(i = 0; i < count; i++) {
|
||||||
@ -95,11 +106,20 @@ void primitiveBufferIndices(primitive_t *primitive,
|
|||||||
offset = position * sizeof(indice_t);
|
offset = position * sizeof(indice_t);
|
||||||
length = count * sizeof(indice_t);
|
length = count * sizeof(indice_t);
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(primitive);
|
||||||
|
ASSERT_NOT_NULL(indices);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(position, 0);
|
||||||
|
ASSERT_GREATER_THAN(count, 0);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, primitive->indexBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, primitive->indexBuffer);
|
||||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, length, indices);
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, length, indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count) {
|
void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count) {
|
||||||
|
ASSERT_NOT_NULL(primitive);
|
||||||
|
ASSERT_GREATER_THAN_EQUAL_TO(start, 0);
|
||||||
|
ASSERT_IF(count < 0, ASSERT_EQUAL(count, -1));
|
||||||
|
|
||||||
if(count == -1) count = primitive->indiceCount;
|
if(count == -1) count = primitive->indiceCount;
|
||||||
|
|
||||||
// Re-Bind the buffers
|
// Re-Bind the buffers
|
||||||
@ -125,6 +145,8 @@ void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void primitiveDispose(primitive_t *primitive) {
|
void primitiveDispose(primitive_t *primitive) {
|
||||||
|
ASSERT_NOT_NULL(primitive);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
glDeleteBuffers(1, &primitive->vertexBuffer);
|
glDeleteBuffers(1, &primitive->vertexBuffer);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
|
#include "../../assert/assert.h"
|
||||||
|
|
||||||
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
|
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
|
||||||
#define PRIMITIVE_COORDINATES_PER_VERTICE 2
|
#define PRIMITIVE_COORDINATES_PER_VERTICE 2
|
||||||
|
@ -12,8 +12,8 @@ void quadBuffer(primitive_t *primitive, float z,
|
|||||||
float x1, float y1, float u1, float v1,
|
float x1, float y1, float u1, float v1,
|
||||||
int32_t verticeStart, int32_t indiceStart
|
int32_t verticeStart, int32_t indiceStart
|
||||||
) {
|
) {
|
||||||
vertice_t *vertices = malloc(sizeof(vertice_t) * QUAD_VERTICE_COUNT);
|
vertice_t vertices[QUAD_VERTICE_COUNT];
|
||||||
indice_t *indices = malloc(sizeof(indice_t) * QUAD_INDICE_COUNT);
|
indice_t indices[QUAD_INDICE_COUNT];
|
||||||
|
|
||||||
vertices[0].x = x0, vertices[0].y = y0, vertices[0].z = z;
|
vertices[0].x = x0, vertices[0].y = y0, vertices[0].z = z;
|
||||||
vertices[0].u = u0, vertices[0].v = v0;
|
vertices[0].u = u0, vertices[0].v = v0;
|
||||||
@ -35,11 +35,8 @@ void quadBuffer(primitive_t *primitive, float z,
|
|||||||
indices[4] = (indice_t)(verticeStart + 2);
|
indices[4] = (indice_t)(verticeStart + 2);
|
||||||
indices[5] = (indice_t)(verticeStart + 3);
|
indices[5] = (indice_t)(verticeStart + 3);
|
||||||
|
|
||||||
primitiveBufferVertices(primitive,verticeStart,QUAD_VERTICE_COUNT,vertices);
|
primitiveBufferVertices(primitive, verticeStart,QUAD_VERTICE_COUNT,vertices);
|
||||||
primitiveBufferIndices( primitive,indiceStart, QUAD_INDICE_COUNT, indices );
|
primitiveBufferIndices(primitive, indiceStart, QUAD_INDICE_COUNT, indices );
|
||||||
|
|
||||||
free(vertices);
|
|
||||||
free(indices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void quadInit(primitive_t *primitive, float z,
|
void quadInit(primitive_t *primitive, float z,
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
|
|
||||||
#include "skywall.h"
|
#include "skywall.h"
|
||||||
|
|
||||||
void skywallInit(primitive_t *primitive) {
|
void skywallInit(primitive_t *primitive) {
|
||||||
primitiveInit(primitive, SKYWALL_VERTICE_COUNT, SKYWALL_INDICE_COUNT);
|
|
||||||
|
|
||||||
vertice_t vertices[SKYWALL_VERTICE_COUNT];
|
vertice_t vertices[SKYWALL_VERTICE_COUNT];
|
||||||
indice_t indices[SKYWALL_INDICE_COUNT];
|
indice_t indices[SKYWALL_INDICE_COUNT];
|
||||||
int32_t n, i, j;
|
int32_t n, i, j;
|
||||||
float x, y, z, p, r;
|
float x, y, z, p, r;
|
||||||
|
|
||||||
|
primitiveInit(primitive, SKYWALL_VERTICE_COUNT, SKYWALL_INDICE_COUNT);
|
||||||
|
|
||||||
// For each slice. We iterate slices+1 to do the wrapping mentioned below.
|
// For each slice. We iterate slices+1 to do the wrapping mentioned below.
|
||||||
for(i = 0; i < SKYWALL_SLICE_COUNT+1; i++) {
|
for(i = 0; i < SKYWALL_SLICE_COUNT+1; i++) {
|
||||||
// Get the "percentage" of the current slice, slice 0 is 0, slice n is 1
|
// Get the "percentage" of the current slice, slice 0 is 0, slice n is 1
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include "epoch.h"
|
#include "epoch.h"
|
||||||
|
|
||||||
void epochInit(epoch_t *epoch) {
|
void epochInit(epoch_t *epoch) {
|
||||||
|
ASSERT_NOT_NULL(epoch);
|
||||||
|
|
||||||
epoch->delta = EPOCH_FIXED_STEP;
|
epoch->delta = EPOCH_FIXED_STEP;
|
||||||
epoch->last = EPOCH_FIXED_STEP;
|
epoch->last = EPOCH_FIXED_STEP;
|
||||||
epoch->current = EPOCH_FIXED_STEP + EPOCH_FIXED_STEP;
|
epoch->current = EPOCH_FIXED_STEP + EPOCH_FIXED_STEP;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../libs.h"
|
#include "../libs.h"
|
||||||
|
#include "../assert/assert.h"
|
||||||
#include "../util/math.h"
|
#include "../util/math.h"
|
||||||
|
|
||||||
#define EPOCH_FIXED_STEP 0.016f
|
#define EPOCH_FIXED_STEP 0.016f
|
||||||
|
@ -7,25 +7,9 @@
|
|||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
#define EVENT_TEST 0x00
|
|
||||||
|
|
||||||
eventmanager_t eventManager;
|
|
||||||
|
|
||||||
bool onEventTriggered(void *user, event_t event, void *args[], int32_t argc) {
|
|
||||||
printf("Event!\n");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool gameInit(game_t *game) {
|
bool gameInit(game_t *game) {
|
||||||
ASSERT_NOT_NULL(game);
|
ASSERT_NOT_NULL(game);
|
||||||
|
|
||||||
eventManagerInit(&eventManager);
|
|
||||||
eventManagerSubscribe(&eventManager, EVENT_TEST, NULL, onEventTriggered);
|
|
||||||
eventManagerTrigger(&eventManager, EVENT_TEST, NULL, 0);
|
|
||||||
eventManagerTrigger(&eventManager, EVENT_TEST, NULL, 0);
|
|
||||||
printf("Done.\n");
|
|
||||||
|
|
||||||
|
|
||||||
// Init the engine and the rendering pipeline
|
// Init the engine and the rendering pipeline
|
||||||
engineInit(&game->engine);
|
engineInit(&game->engine);
|
||||||
|
|
||||||
|
@ -8,15 +8,19 @@
|
|||||||
#include "save.h"
|
#include "save.h"
|
||||||
|
|
||||||
void saveManagerInit(savemanager_t *man) {
|
void saveManagerInit(savemanager_t *man) {
|
||||||
|
ASSERT_NOT_NULL(man);
|
||||||
|
|
||||||
man->count = 0;
|
man->count = 0;
|
||||||
|
|
||||||
// Set up defaults
|
// Set up defaults
|
||||||
saveManagerSetUint8(man, SAVE_KEY_TEXTURE_SCALE, 0x00);
|
saveManagerSetU8(man, SAVE_KEY_TEXTURE_SCALE, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key) {
|
savevalue_t * saveManagerAddOrGet(savemanager_t *man, const char key[]) {
|
||||||
uint8_t i, j;
|
uint8_t i, j;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(man);
|
||||||
|
|
||||||
j = saveManagerGetKey(man, key);
|
j = saveManagerGetKey(man, key);
|
||||||
if(j != 0xFF) return man->values + j;
|
if(j != 0xFF) return man->values + j;
|
||||||
|
|
||||||
@ -33,17 +37,23 @@ savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key) {
|
|||||||
return man->values + man->count++;
|
return man->values + man->count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t saveManagerGetKey(savemanager_t *man, char *key) {
|
uint8_t saveManagerGetKey(savemanager_t *man, const char key[]) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(man);
|
||||||
|
|
||||||
for(i = 0; i < man->count; i++) {
|
for(i = 0; i < man->count; i++) {
|
||||||
if(strcmp(man->keys[i], key) == 0) return i;
|
if(strcmp(man->keys[i], key) == 0) return i;
|
||||||
}
|
}
|
||||||
return 0xFF;
|
return 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveManagerRemove(savemanager_t *man, char *key) {
|
void saveManagerRemove(savemanager_t *man, const char key[]) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
|
ASSERT_NOT_NULL(man);
|
||||||
|
ASSERT_NOT_NULL(key);
|
||||||
|
|
||||||
i = saveManagerGetKey(man, key);
|
i = saveManagerGetKey(man, key);
|
||||||
if(i == 0xFF) return;
|
if(i == 0xFF) return;
|
||||||
|
|
||||||
@ -52,23 +62,27 @@ void saveManagerRemove(savemanager_t *man, char *key) {
|
|||||||
|
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
savevalue_t * saveManagerSetBool(savemanager_t *man, char *key, bool val) {
|
savevalue_t * saveManagerSetBool(
|
||||||
savevalue_t * v = saveManagerAddOrGet(man, key);
|
savemanager_t *man, const char key[], bool val
|
||||||
|
) {
|
||||||
|
savevalue_t *v = saveManagerAddOrGet(man, key);
|
||||||
v->b = val;
|
v->b = val;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
savevalue_t * saveManagerSetUint8(savemanager_t *man, char *key, uint8_t val) {
|
savevalue_t * saveManagerSetU8(
|
||||||
savevalue_t * v = saveManagerAddOrGet(man, key);
|
savemanager_t *man, const char key[], uint8_t val
|
||||||
|
) {
|
||||||
|
savevalue_t *v = saveManagerAddOrGet(man, key);
|
||||||
v->u8 = val;
|
v->u8 = val;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
bool saveManagerGetBool(savemanager_t *man, char *key) {
|
bool saveManagerGetBool(savemanager_t *man, const char key[]) {
|
||||||
return saveManagerAddOrGet(man, key)->b;
|
return saveManagerAddOrGet(man, key)->b;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t saveManagerGetUint8(savemanager_t *man, char *key) {
|
uint8_t saveManagerGetU8(savemanager_t *man, const char key[]) {
|
||||||
return saveManagerAddOrGet(man, key)->u8;
|
return saveManagerAddOrGet(man, key)->u8;
|
||||||
}
|
}
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../libs.h"
|
#include "../libs.h"
|
||||||
|
#include "../assert/assert.h"
|
||||||
#include "../util/array.h"
|
#include "../util/array.h"
|
||||||
|
|
||||||
#define SAVE_VALUES_MAX 200
|
#define SAVE_VALUES_MAX 200
|
||||||
@ -14,7 +15,6 @@
|
|||||||
#define SAVE_KEY_TEXTURE_SCALE "TEXTURE_SCALE"
|
#define SAVE_KEY_TEXTURE_SCALE "TEXTURE_SCALE"
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
// char *s;
|
|
||||||
bool b;
|
bool b;
|
||||||
uint8_t u8;
|
uint8_t u8;
|
||||||
int8_t i8;
|
int8_t i8;
|
||||||
@ -23,21 +23,22 @@ typedef union {
|
|||||||
} savevalue_t;
|
} savevalue_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *keys[SAVE_VALUES_MAX];
|
const char *keys[SAVE_VALUES_MAX];
|
||||||
savevalue_t values[SAVE_VALUES_MAX];
|
savevalue_t values[SAVE_VALUES_MAX];
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
} savemanager_t;
|
} savemanager_t;
|
||||||
|
|
||||||
void saveManagerInit(savemanager_t *man);
|
void saveManagerInit(savemanager_t *man);
|
||||||
|
|
||||||
savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key);
|
savevalue_t * saveManagerAddOrGet(savemanager_t *man, const char key[]);
|
||||||
|
|
||||||
uint8_t saveManagerGetKey(savemanager_t *man, char *key);
|
uint8_t saveManagerGetKey(savemanager_t *man, const char key[]);
|
||||||
|
|
||||||
void saveManagerRemove(savemanager_t *man, char *key);
|
void saveManagerRemove(savemanager_t *man, const char key[]);
|
||||||
|
|
||||||
savevalue_t * saveManagerSetBool(savemanager_t *man, char *key, bool val);
|
savevalue_t * saveManagerSetBool(savemanager_t *man,const char key[],bool val);
|
||||||
savevalue_t * saveManagerSetUint8(savemanager_t *man, char *key, uint8_t val);
|
|
||||||
|
savevalue_t * saveManagerSetU8(savemanager_t *man,const char key[],uint8_t val);
|
||||||
|
|
||||||
bool saveManagerGetBool(savemanager_t *man, char *key);
|
bool saveManagerGetBool(savemanager_t *man, char *key);
|
||||||
uint8_t saveManagerGetUint8(savemanager_t *man, char *key);
|
uint8_t saveManagerGetU8(savemanager_t *man, char *key);
|
Reference in New Issue
Block a user