all repos — mgba @ a8921116dc40e4812682da3b214395d557800fcf

mGBA Game Boy Advance Emulator

Preprocess OBJ heights
Jeffrey Pfau jeffrey@endrift.com
Tue, 21 Jan 2014 23:41:13 -0800
commit

a8921116dc40e4812682da3b214395d557800fcf

parent

04c3b61d1c2fe4c98e484bdfde0b88c5d453b0f9

2 files changed, 41 insertions(+), 34 deletions(-)

jump to
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -5,6 +5,25 @@ #include "gba-io.h"

#include <string.h> +static const int _objSizes[32] = { + 8, 8, + 16, 16, + 32, 32, + 64, 64, + 16, 8, + 32, 8, + 32, 16, + 64, 32, + 8, 16, + 8, 32, + 16, 32, + 32, 64, + 0, 0, + 0, 0, + 0, 0, + 0, 0 +}; + static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer); static void GBAVideoSoftwareRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam);

@@ -351,6 +370,12 @@ int oamMax = 0;

for (i = 0; i < 128; ++i) { struct GBAObj* obj = &renderer->d.oam->obj[i]; if (obj->transformed || !obj->disable) { + int height = _objSizes[obj->shape * 8 + obj->size * 2 + 1]; + if (obj->transformed) { + height <<= ((struct GBATransformedObj*) obj)->doublesize; + } + renderer->sprites[oamMax].y = obj->y; + renderer->sprites[oamMax].endY = obj->y + height; renderer->sprites[oamMax].obj = *obj; ++oamMax; }

@@ -570,6 +595,8 @@ if (renderer->dispcnt.objEnable) {

if (renderer->oamDirty) { _cleanOAM(renderer); } + int mosaicV = renderer->mosaic.objV + 1; + int mosaicY = y - (y % mosaicV); for (w = 0; w < renderer->nWindows; ++w) { renderer->start = renderer->end; renderer->end = renderer->windows[w].endX;

@@ -580,11 +607,18 @@ }

int i; int drawn; for (i = 0; i < renderer->oamMax; ++i) { + int localY = y; struct GBAVideoSoftwareSprite* sprite = &renderer->sprites[i]; + if (sprite->obj.mosaic) { + localY = mosaicY; + } + if ((localY < sprite->y && (sprite->endY - 256 < 0 || localY >= sprite->endY - 256)) || localY >= sprite->endY) { + continue; + } if (sprite->obj.transformed) { - drawn = _preprocessTransformedSprite(renderer, &sprite->tobj, y); + drawn = _preprocessTransformedSprite(renderer, &sprite->tobj, localY); } else { - drawn = _preprocessSprite(renderer, &sprite->obj, y); + drawn = _preprocessSprite(renderer, &sprite->obj, localY); } spriteLayers |= drawn << sprite->obj.priority; }

@@ -1231,25 +1265,6 @@ }

} } -static const int _objSizes[32] = { - 8, 8, - 16, 16, - 32, 32, - 64, 64, - 16, 8, - 32, 8, - 32, 16, - 64, 32, - 8, 16, - 8, 32, - 16, 32, - 32, 64, - 0, 0, - 0, 0, - 0, 0, - 0, 0 -}; - #define SPRITE_NORMAL_LOOP(DEPTH, TYPE) \ SPRITE_YBASE_ ## DEPTH(inY); \ for (; outX < condition; ++outX, inX += xOffset) { \

@@ -1329,15 +1344,8 @@ renderer->row[outX] |= FLAG_OBJWIN; \

} static int _preprocessSprite(struct GBAVideoSoftwareRenderer* renderer, struct GBAObj* sprite, int y) { + int width = _objSizes[sprite->shape * 8 + sprite->size * 2]; int height = _objSizes[sprite->shape * 8 + sprite->size * 2 + 1]; - if (sprite->mosaic) { - int mosaicV = renderer->mosaic.objV + 1; - y -= y % mosaicV; - } - if ((y < sprite->y && (sprite->y + height - 256 < 0 || y >= sprite->y + height - 256)) || y >= sprite->y + height) { - return 0; - } - int width = _objSizes[sprite->shape * 8 + sprite->size * 2]; int start = renderer->start; int end = renderer->end; uint32_t flags = sprite->priority << OFFSET_PRIORITY;

@@ -1402,13 +1410,10 @@ return 1;

} static int _preprocessTransformedSprite(struct GBAVideoSoftwareRenderer* renderer, struct GBATransformedObj* sprite, int y) { + int width = _objSizes[sprite->shape * 8 + sprite->size * 2]; int height = _objSizes[sprite->shape * 8 + sprite->size * 2 + 1]; + int totalWidth = width << sprite->doublesize; int totalHeight = height << sprite->doublesize; - if ((y < sprite->y && (sprite->y + totalHeight - 256 < 0 || y >= sprite->y + totalHeight - 256)) || y >= sprite->y + totalHeight) { - return 0; - } - int width = _objSizes[sprite->shape * 8 + sprite->size * 2]; - int totalWidth = width << sprite->doublesize; int start = renderer->start; int end = renderer->end; uint32_t flags = sprite->priority << OFFSET_PRIORITY;
M src/gba/renderers/video-software.hsrc/gba/renderers/video-software.h

@@ -16,6 +16,8 @@ union {

struct GBAObj obj; struct GBATransformedObj tobj; }; + int y; + int endY; }; struct GBAVideoSoftwareBackground {