//uint32_t intermediateBuffer[canvasHeight][canvasWidth];
-#define SS_WIDTH 128
-#define SS_HEIGHT 128
-#define kSpriteSheetStrideShift 7
-
+//#define SS_WIDTH 128
+//#define SS_HEIGHT 128
+//#define kSpriteSheetStrideShift 7
//static uint8_t spritesheet[SS_HEIGHT][SS_WIDTH];
-static uint8_t *spritesheet = NULL;
+//static uint8_t *spritesheet = NULL;
+
+struct BZSpritesheet {
+ size_t width;
+ size_t height;
+ size_t spriteWidth;
+ size_t spriteHeight;
+ size_t spriteCount;
+ uint8_t data[];
+};
+typedef struct BZSpritesheet BZSpritesheet;
+
+static BZSpritesheet *spritesheet = NULL;
static BZFont *currentFont;
bzLog("Data: %d %d %d %d", canvasWidth, canvasMemorySize, bufferStrideShift, bufferStride);
}
-void bzGfxPrepareSpritesheet(BZMemoryArenaID arena, size_t width, size_t height, void *data) {
+void bzGfxPrepareSpritesheet(BZMemoryArenaID arena, size_t frames, size_t width, size_t height, void *data) {
uint8_t *imageData = (uint8_t *)data;
- bzLog("Preparing spritesheet %dx%d", width, height);
+ bzLog("Preparing spritesheet %dx%dx%d", frames, width, height);
- size_t spritesheetMemorySize = width * height * sizeof(uint8_t);
- spritesheet = bzMemoryAlloc(arena, spritesheetMemorySize);
- memcpy(spritesheet, data, spritesheetMemorySize);
+ size_t spritesheetDataSize = frames * width * height * sizeof(uint8_t);
+ spritesheet = bzMemoryAlloc(arena, sizeof(BZSpritesheet) + spritesheetDataSize);
+
+ spritesheet->width = width;
+ spritesheet->height = height * frames;
+ spritesheet->spriteCount = frames;
+ spritesheet->spriteWidth = width;
+ spritesheet->spriteHeight = height;
+ memcpy(&spritesheet->data, data, spritesheetDataSize);
}
void bzGfxPrepareFont(BZMemoryArenaID arena, void *font) {
BZPaletteColor bzSGet(int x, int y) {
bzAssert(spritesheet != NULL);
- if (x >= 0 && x < SS_WIDTH && y >=0 && y < SS_HEIGHT) {
- return spritesheet[(y << kSpriteSheetStrideShift) + x];
+ if (x >= 0 && x < spritesheet->width && y >=0 && y < spritesheet->height) {
+ return spritesheet->data[y * spritesheet->width + x];
+ //return spritesheet->data[(y << kSpriteSheetStrideShift) + x];
} else {
return 0;
}
}
void bzSprExt(size_t n, BZCoordinate x, BZCoordinate y, BZCoordinate w, BZCoordinate h, bool flipX, bool flipY) {
- int px = (n % 16) * 8;
- int py = (n / 16) * 8;
- int pw = w * 8;
- int ph = h * 8;
+ int px = 0;//(n % 16) * 8;
+ int py = n * spritesheet->spriteHeight;//(n / 16) * 8;
+ int pw = w * spritesheet->spriteWidth;
+ int ph = h * spritesheet->spriteHeight;
bzSSprExt(px, py, pw, ph, x, y, pw, ph, flipX, flipY);
+
+// int px = (n % 16) * 8;
+// int py = (n / 16) * 8;
+// int pw = w * 8;
+// int ph = h * 8;
+// bzSSprExt(px, py, pw, ph, x, y, pw, ph, flipX, flipY);
}
void bzSSpr(BZCoordinate sx, BZCoordinate sy, BZCoordinate sw, BZCoordinate sh, BZCoordinate dx, BZCoordinate dy) {
for (size_t y = 0; y < osh - (clipTop + clipBottom); ++y) {
for (size_t x = 0; x < osw - (clipLeft + clipRight); ++x) {
- int color = gPalettes[spritesheet[((clipTop+osy+y) << kSpriteSheetStrideShift) + clipLeft+osx+x]];
+ int color = gPalettes[spritesheet->data[(clipTop+osy+y) * spritesheet->width + clipLeft+osx+x]];
if (color > 0) bzBufferSet(currentBuffer, xMinOut+x, yMinOut+y, color); // FIXME, scaled up and 0 check removal??
}
}