Refactoring structs Part 1
This commit is contained in:
@ -7,22 +7,13 @@
|
||||
|
||||
#include "spritebatch.h"
|
||||
|
||||
spritebatch_t * spriteBatchCreate(int32_t maxSprites) {
|
||||
spritebatch_t *batch = malloc(sizeof(spritebatch_t));
|
||||
if(batch == NULL) return NULL;
|
||||
|
||||
void spriteBatchInit(spritebatch_t *batch, int32_t maxSprites) {
|
||||
batch->maxSprites = maxSprites;
|
||||
batch->currentSprite = 0;
|
||||
|
||||
batch->primitive = primitiveCreate(
|
||||
primitiveInit(&batch->primitive,
|
||||
maxSprites*QUAD_VERTICE_COUNT, maxSprites*QUAD_INDICE_COUNT
|
||||
);
|
||||
if(batch == NULL) {
|
||||
free(batch);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return batch;
|
||||
}
|
||||
|
||||
void spriteBatchQuad(spritebatch_t *spriteBatch, int32_t index,
|
||||
@ -35,7 +26,7 @@ void spriteBatchQuad(spritebatch_t *spriteBatch, int32_t index,
|
||||
spriteBatch->currentSprite = mathMax(index, spriteBatch->currentSprite);
|
||||
}
|
||||
|
||||
quadBuffer(spriteBatch->primitive, z,
|
||||
quadBuffer(&spriteBatch->primitive, z,
|
||||
x, y, u0, v0,
|
||||
x+width, y+height, u1, v1,
|
||||
index*QUAD_VERTICE_COUNT, index*QUAD_INDICE_COUNT
|
||||
@ -48,12 +39,11 @@ void spriteBatchFlush(spritebatch_t *spriteBatch) {
|
||||
|
||||
void spriteBatchDraw(spritebatch_t *spriteBatch, int32_t index, int32_t count) {
|
||||
if(count == -1) count = spriteBatch->currentSprite;
|
||||
primitiveDraw(spriteBatch->primitive,
|
||||
primitiveDraw(&spriteBatch->primitive,
|
||||
index*QUAD_INDICE_COUNT, count*QUAD_INDICE_COUNT
|
||||
);
|
||||
}
|
||||
|
||||
void spriteBatchDispose(spritebatch_t *spriteBatch) {
|
||||
primitiveDispose(spriteBatch->primitive);
|
||||
free(spriteBatch);
|
||||
primitiveDispose(&spriteBatch->primitive);
|
||||
}
|
Reference in New Issue
Block a user