X-Git-Url: https://git.bts.cx/benzene.git/blobdiff_plain/88fe7f92d3fd592960bc2534fcdc534021c870bc..refs/heads/mainline:/src/bz/gfx/gfx.c?ds=inline diff --git a/src/bz/gfx/gfx.c b/src/bz/gfx/gfx.c index 0f26e3b..ccfdc2c 100644 --- a/src/bz/gfx/gfx.c +++ b/src/bz/gfx/gfx.c @@ -72,12 +72,23 @@ static BZMatrix globalViewMatrix = { .a = 1, .b = 0, .c = 0, .d = 1, .x = 0, .y //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; @@ -131,13 +142,19 @@ void bzGfxPrepareCanvasBuffer(BZMemoryArenaID arena, size_t width, size_t height 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) { @@ -241,8 +258,9 @@ void bzPSet(BZCoordinate x, BZCoordinate y, BZPaletteColor c) { 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; } @@ -550,11 +568,17 @@ void bzSpr(size_t n, BZCoordinate x, BZCoordinate y) { } 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) { @@ -572,7 +596,7 @@ void bzSSprExt(BZCoordinate sx, BZCoordinate sy, BZCoordinate sw, BZCoordinate s 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?? } }