Just adding more assertions.
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include "queue.h"
|
||||
|
||||
void queueInit(queue_t *queue) {
|
||||
ASSERT_NOT_NULL(queue);
|
||||
|
||||
queue->timeline = 0;
|
||||
queue->count = 0;
|
||||
queue->current = ANIMATION_QUEUE_START;
|
||||
@@ -16,6 +18,8 @@ void queueInit(queue_t *queue) {
|
||||
queueaction_t * queueNext(queue_t *queue) {
|
||||
queueaction_t *action;
|
||||
|
||||
ASSERT_NOT_NULL(queue);
|
||||
|
||||
// Is there a currently running action? If so, end it.
|
||||
if(queue->current != ANIMATION_QUEUE_START) {
|
||||
action = queue->items + queue->current;
|
||||
@@ -35,8 +39,10 @@ queueaction_t * queueNext(queue_t *queue) {
|
||||
|
||||
queueaction_t * queueAdd(queue_t *queue) {
|
||||
queueaction_t *action;
|
||||
|
||||
ASSERT_NOT_NULL(queue);
|
||||
|
||||
action = queue->items + queue->count;
|
||||
|
||||
action->index = queue->count;
|
||||
action->data = NULL;
|
||||
action->onStart = NULL;
|
||||
@@ -49,6 +55,10 @@ queueaction_t * queueAdd(queue_t *queue) {
|
||||
|
||||
void queueUpdate(queue_t *queue, float delta) {
|
||||
queueaction_t *action;
|
||||
|
||||
ASSERT_NOT_NULL(queue);
|
||||
ASSERT_GREATER_THAN(delta, 0);
|
||||
|
||||
queue->timeline += delta;
|
||||
if(queue->current >= queue->count) return;
|
||||
|
||||
@@ -60,6 +70,8 @@ void queueUpdate(queue_t *queue, float delta) {
|
||||
|
||||
void queueDispose(queue_t *queue) {
|
||||
queueaction_t *action;
|
||||
ASSERT_NOT_NULL(queue);
|
||||
|
||||
if(queue->current >= queue->count) return;
|
||||
action = queue->items + 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) {
|
||||
uint8_t i;
|
||||
ASSERT_NOT_NULL(queue);
|
||||
|
||||
// Rewind the array.
|
||||
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) {
|
||||
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;
|
||||
queueNext(queue);
|
||||
}
|
||||
|
||||
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;
|
||||
action->onUpdate = &_queueDelayUpdate;
|
||||
return action;
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
void _timelineActionDeltaUpdateStart(
|
||||
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;
|
||||
*((float *)action->data) = timeline->initials[i];
|
||||
}
|
||||
@@ -18,6 +23,12 @@ void _timelineActionDeltaUpdateDuration(
|
||||
timeline_t *timeline, timelineaction_t *action, uint8_t i
|
||||
) {
|
||||
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;
|
||||
n = timeline->easings[i](
|
||||
timelineActionGetTimeRaw(timeline, action)
|
||||
@@ -28,12 +39,19 @@ void _timelineActionDeltaUpdateDuration(
|
||||
void _timelineActionDeltaUpdateEnd(
|
||||
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;
|
||||
*((float *)action->data) = timeline->initials[i] + timeline->deltas[i];
|
||||
}
|
||||
|
||||
|
||||
void timelineInit(timeline_t *timeline) {
|
||||
ASSERT_NOT_NULL(timeline);
|
||||
|
||||
timeline->current = 0;
|
||||
timeline->diff = 0;
|
||||
timeline->previous = 0;
|
||||
@@ -46,6 +64,9 @@ void timelineUpdate(timeline_t *timeline, float delta) {
|
||||
timelineaction_t *action;
|
||||
float full;
|
||||
|
||||
ASSERT_NOT_NULL(timeline);
|
||||
ASSERT_GREATER_THAN(delta, 0);
|
||||
|
||||
timeline->diff = delta;
|
||||
timeline->previous = timeline->current;
|
||||
timeline->current = timeline->current + delta;
|
||||
@@ -80,6 +101,8 @@ bool timelineIsFinished(timeline_t *timeline) {
|
||||
uint8_t i;
|
||||
timelineaction_t *action;
|
||||
|
||||
ASSERT_NOT_NULL(timeline);
|
||||
|
||||
for(i = 0; i < timeline->actionCount; i++) {
|
||||
action = timeline->actions +i;
|
||||
if(action->start > timeline->current) return false;
|
||||
@@ -94,7 +117,12 @@ bool timelineIsFinished(timeline_t *timeline) {
|
||||
timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
|
||||
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->start = start, action->duration = duration;
|
||||
action->onStart = action->onEnd = action->onDuration = NULL;
|
||||
@@ -106,6 +134,9 @@ timelineaction_t * timelineAddDeltaAction(timeline_t *timeline,
|
||||
easefunction_t *easing, float *destination
|
||||
) {
|
||||
timelineaction_t *action;
|
||||
|
||||
ASSERT_NOT_NULL(timeline);
|
||||
|
||||
timeline->initials[timeline->actionCount] = initial;
|
||||
timeline->deltas[timeline->actionCount] = delta;
|
||||
timeline->easings[timeline->actionCount] = (
|
||||
@@ -123,19 +154,29 @@ timelineaction_t * timelineAddDeltaActionTo(timeline_t *timeline,
|
||||
float start, float duration, float initial, float end,
|
||||
easefunction_t *easing, float *destination
|
||||
) {
|
||||
ASSERT_NOT_NULL(timeline);
|
||||
|
||||
return timelineAddDeltaAction(
|
||||
timeline, start, duration, initial, end-initial, easing, destination
|
||||
);
|
||||
}
|
||||
|
||||
float timelineActionGetTimeRaw(timeline_t *timeline, timelineaction_t *action) {
|
||||
ASSERT_NOT_NULL(timeline);
|
||||
ASSERT_NOT_NULL(action);
|
||||
|
||||
return (timeline->current - action->start) / action->duration;
|
||||
}
|
||||
|
||||
float timelineActionGetTime(timeline_t *tl, timelineaction_t *at) {
|
||||
ASSERT_NOT_NULL(tl);
|
||||
ASSERT_NOT_NULL(at);
|
||||
|
||||
return mathClamp(timelineActionGetTimeRaw(tl, at), 0, 1);
|
||||
}
|
||||
|
||||
void timelineClear(timeline_t *timeline) {
|
||||
ASSERT_NOT_NULL(timeline);
|
||||
|
||||
timeline->actionCount = 0;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../assert/assert.h"
|
||||
#include "../../util/math.h"
|
||||
#include "easing.h"
|
||||
|
||||
|
||||
@@ -15,10 +15,19 @@
|
||||
|
||||
void fontInit(font_t *font, char *data) {
|
||||
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;
|
||||
|
||||
uint8_t *bitmapData = malloc(sizeof(uint8_t) * s);
|
||||
pixel_t *pixels = malloc(sizeof(pixel_t) * s);
|
||||
bitmapData = malloc(sizeof(uint8_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_BakeFontBitmap(
|
||||
@@ -41,14 +50,21 @@ void fontInit(font_t *font, char *data) {
|
||||
}
|
||||
|
||||
void fontDispose(font_t *font) {
|
||||
ASSERT_NOT_NULL(font);
|
||||
textureDispose(&font->texture);
|
||||
}
|
||||
|
||||
float fontGetScale(float fontSize) {
|
||||
ASSERT_GREATER_THAN(fontSize, 0);
|
||||
|
||||
return fontSize / FONT_SIZE_DEFAULT * FONT_GLOBAL_SCALE;
|
||||
}
|
||||
|
||||
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++;
|
||||
|
||||
if(info->lineCount >= FONT_TEXT_INFO_LINES_MAX) {
|
||||
@@ -70,8 +86,16 @@ void fontTextBuffer(
|
||||
stbtt_aligned_quad *quads;
|
||||
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
|
||||
quads = malloc(sizeof(stbtt_aligned_quad) * strlen(text));
|
||||
ASSERT_NOT_NULL(quads);
|
||||
|
||||
// Get the font scale
|
||||
scale = fontGetScale(fontSize);
|
||||
@@ -198,6 +222,11 @@ void fontTextBuffer(
|
||||
|
||||
int32_t fontGetLineCharCount(fonttextinfo_t *info,int32_t start,int32_t count) {
|
||||
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);
|
||||
|
||||
charCount = 0;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "primitive/quad.h"
|
||||
#include "../util/mem.h"
|
||||
#include "../util/math.h"
|
||||
#include "../assert/assert.h"
|
||||
|
||||
/** Which character (ASCII) to start the font from */
|
||||
#define FONT_FIRST_CHAR 32
|
||||
|
||||
@@ -12,8 +12,12 @@ void cubeBuffer(primitive_t *prim,
|
||||
float w, float h, float d,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
vertice_t *vertices = malloc(sizeof(vertice_t) * CUBE_VERTICE_COUNT);
|
||||
indice_t *indices = malloc(sizeof(indice_t) * CUBE_INDICE_COUNT);
|
||||
vertice_t vertices[CUBE_VERTICE_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].u = 0, vertices[0].v = 0;
|
||||
@@ -96,9 +100,6 @@ void cubeBuffer(primitive_t *prim,
|
||||
|
||||
primitiveBufferVertices(prim, verticeStart, CUBE_VERTICE_COUNT, vertices);
|
||||
primitiveBufferIndices(prim, indiceStart, CUBE_INDICE_COUNT, indices);
|
||||
|
||||
free(vertices);
|
||||
free(indices);
|
||||
}
|
||||
|
||||
void cubeInit(primitive_t *primitive, float w, float h, float d) {
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
void primitiveInit(primitive_t *primitive,
|
||||
int32_t verticeCount, int32_t indiceCount
|
||||
) {
|
||||
ASSERT_NOT_NULL(primitive);
|
||||
ASSERT_GREATER_THAN(verticeCount, 0);
|
||||
ASSERT_GREATER_THAN(indiceCount, 0);
|
||||
|
||||
primitive->verticeCount = verticeCount;
|
||||
primitive->indiceCount = indiceCount;
|
||||
|
||||
@@ -19,12 +23,11 @@ void primitiveInit(primitive_t *primitive,
|
||||
size_t sizeIndices = sizeof(indice_t) * indiceCount;
|
||||
|
||||
// Create some buffers, one for the vertex data, one for the indices
|
||||
GLuint *buffer = malloc(sizeof(GLuint) * 2);
|
||||
GLuint buffer[2];
|
||||
glGenBuffers(2, buffer);
|
||||
|
||||
primitive->vertexBuffer = buffer[0];
|
||||
primitive->indexBuffer = buffer[1];
|
||||
free(buffer);
|
||||
|
||||
// Buffer an empty set of data then buffer each component
|
||||
glBindBuffer(GL_ARRAY_BUFFER, primitive->vertexBuffer);
|
||||
@@ -54,6 +57,11 @@ void primitiveBufferVertices(primitive_t *primitive,
|
||||
float *positions, *coordinates;
|
||||
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
|
||||
lengthPositions = sizeof(float) * PRIMITIVE_POSITIONS_PER_VERTICE * count;
|
||||
offsetPositions = sizeof(float) * PRIMITIVE_POSITIONS_PER_VERTICE * position;
|
||||
@@ -66,7 +74,10 @@ void primitiveBufferVertices(primitive_t *primitive,
|
||||
|
||||
// Create some memory
|
||||
positions = malloc(lengthPositions);
|
||||
ASSERT_NOT_NULL(positions);
|
||||
|
||||
coordinates = malloc(lengthCoordinates);
|
||||
ASSERT_NOT_NULL(coordinates);
|
||||
|
||||
// Now copy the positions and coordinates from the vertices into the buffer
|
||||
for(i = 0; i < count; i++) {
|
||||
@@ -95,11 +106,20 @@ void primitiveBufferIndices(primitive_t *primitive,
|
||||
offset = position * 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);
|
||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, length, indices);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Re-Bind the buffers
|
||||
@@ -125,6 +145,8 @@ void primitiveDraw(primitive_t *primitive, int32_t start, int32_t count) {
|
||||
}
|
||||
|
||||
void primitiveDispose(primitive_t *primitive) {
|
||||
ASSERT_NOT_NULL(primitive);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glDeleteBuffers(1, &primitive->vertexBuffer);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../../assert/assert.h"
|
||||
|
||||
#define PRIMITIVE_POSITIONS_PER_VERTICE 3
|
||||
#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,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
vertice_t *vertices = malloc(sizeof(vertice_t) * QUAD_VERTICE_COUNT);
|
||||
indice_t *indices = malloc(sizeof(indice_t) * QUAD_INDICE_COUNT);
|
||||
vertice_t vertices[QUAD_VERTICE_COUNT];
|
||||
indice_t indices[QUAD_INDICE_COUNT];
|
||||
|
||||
vertices[0].x = x0, vertices[0].y = y0, vertices[0].z = z;
|
||||
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[5] = (indice_t)(verticeStart + 3);
|
||||
|
||||
primitiveBufferVertices(primitive,verticeStart,QUAD_VERTICE_COUNT,vertices);
|
||||
primitiveBufferIndices( primitive,indiceStart, QUAD_INDICE_COUNT, indices );
|
||||
|
||||
free(vertices);
|
||||
free(indices);
|
||||
primitiveBufferVertices(primitive, verticeStart,QUAD_VERTICE_COUNT,vertices);
|
||||
primitiveBufferIndices(primitive, indiceStart, QUAD_INDICE_COUNT, indices );
|
||||
}
|
||||
|
||||
void quadInit(primitive_t *primitive, float z,
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
#include "skywall.h"
|
||||
|
||||
void skywallInit(primitive_t *primitive) {
|
||||
primitiveInit(primitive, SKYWALL_VERTICE_COUNT, SKYWALL_INDICE_COUNT);
|
||||
|
||||
void skywallInit(primitive_t *primitive) {
|
||||
vertice_t vertices[SKYWALL_VERTICE_COUNT];
|
||||
indice_t indices[SKYWALL_INDICE_COUNT];
|
||||
int32_t n, i, j;
|
||||
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(i = 0; i < SKYWALL_SLICE_COUNT+1; i++) {
|
||||
// Get the "percentage" of the current slice, slice 0 is 0, slice n is 1
|
||||
|
||||
Reference in New Issue
Block a user