comparison vdp.c @ 1886:183b86ba0212

Optimized sprite rendering
author Michael Pavone <pavone@retrodev.com>
date Sat, 21 Sep 2019 11:17:40 -0700
parents 4178ce857e87
children bb3edb4ec605
comparison
equal deleted inserted replaced
1885:4178ce857e87 1886:183b86ba0212
300 if (d->x_pos) { 300 if (d->x_pos) {
301 context->flags |= FLAG_CAN_MASK; 301 context->flags |= FLAG_CAN_MASK;
302 if (!(context->flags & FLAG_MASKED)) { 302 if (!(context->flags & FLAG_MASKED)) {
303 x -= 128; 303 x -= 128;
304 //printf("Draw Slot %d of %d, Rendering sprite cell from %X to x: %d\n", context->cur_slot, context->sprite_draws, d->address, x); 304 //printf("Draw Slot %d of %d, Rendering sprite cell from %X to x: %d\n", context->cur_slot, context->sprite_draws, d->address, x);
305 305 uint8_t collide = 0;
306 if (x >= 8 && x < 312) {
307 //sprite is fully visible
308 for (; address != ((context->serial_address+4) & 0xFFFF); address++) {
309 uint8_t pixel = context->vdpmem[address] >> 4;
310 if (!(context->linebuf[x] & 0xF)) {
311 context->linebuf[x] = pixel | d->pal_priority;
312 } else {
313 collide |= pixel;
314 }
315 x += dir;
316 pixel = context->vdpmem[address] & 0xF;
317 if (!(context->linebuf[x] & 0xF)) {
318 context->linebuf[x] = pixel | d->pal_priority;
319 } else {
320 collide |= pixel;
321 }
322 x += dir;
323 }
324 } else if (x > -8 && x < 327) {
325 //sprite is partially visible
306 for (; address != ((context->serial_address+4) & 0xFFFF); address++) { 326 for (; address != ((context->serial_address+4) & 0xFFFF); address++) {
307 if (x >= 0 && x < 320) { 327 if (x >= 0 && x < 320) {
328 uint8_t pixel = context->vdpmem[address] >> 4;
308 if (!(context->linebuf[x] & 0xF)) { 329 if (!(context->linebuf[x] & 0xF)) {
309 context->linebuf[x] = (context->vdpmem[address] >> 4) | d->pal_priority; 330 context->linebuf[x] = pixel | d->pal_priority;
310 } else if (context->vdpmem[address] >> 4) { 331 } else {
311 context->flags2 |= FLAG2_SPRITE_COLLIDE; 332 collide |= pixel;
312 } 333 }
313 } 334 }
314 x += dir; 335 x += dir;
315 if (x >= 0 && x < 320) { 336 if (x >= 0 && x < 320) {
337 uint8_t pixel = context->vdpmem[address] & 0xF;
316 if (!(context->linebuf[x] & 0xF)) { 338 if (!(context->linebuf[x] & 0xF)) {
317 context->linebuf[x] = (context->vdpmem[address] & 0xF) | d->pal_priority; 339 context->linebuf[x] = pixel | d->pal_priority;
318 } else if (context->vdpmem[address] & 0xF) { 340 } else {
319 context->flags2 |= FLAG2_SPRITE_COLLIDE; 341 collide |= pixel;
320 } 342 }
321 } 343 }
322 x += dir; 344 x += dir;
345 }
346 }
347 if (collide) {
348 context->flags2 |= FLAG2_SPRITE_COLLIDE;
323 } 349 }
324 } 350 }
325 } else if (context->flags & FLAG_CAN_MASK) { 351 } else if (context->flags & FLAG_CAN_MASK) {
326 context->flags |= FLAG_MASKED; 352 context->flags |= FLAG_MASKED;
327 context->flags &= ~FLAG_CAN_MASK; 353 context->flags &= ~FLAG_CAN_MASK;