(screen.c) Faster drawing of pixel
This commit is contained in:
parent
a44dbd9696
commit
d043ce633d
|
@ -23,24 +23,25 @@ static Uint8 blending[4][16] = {
|
||||||
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
|
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
screen_write(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
|
screen_pixel(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
|
||||||
{
|
{
|
||||||
if(x < p->width && y < p->height) {
|
if(x >= p->width || y >= p->height)
|
||||||
Uint32 i = x + y * p->width;
|
return;
|
||||||
if(color != layer->pixels[i]) {
|
layer->pixels[x + y * p->width] = color;
|
||||||
layer->pixels[i] = color;
|
|
||||||
layer->changed = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
screen_fill(UxnScreen *p, Layer *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color)
|
screen_fill(UxnScreen *p, Layer *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color)
|
||||||
{
|
{
|
||||||
int v, h;
|
int x, y;
|
||||||
for(v = y1; v < y2; v++)
|
if(x2 >= p->width) x2 = p->width;
|
||||||
for(h = x1; h < x2; h++)
|
if(y2 >= p->height) y2 = p->height;
|
||||||
screen_write(p, layer, h, v, color);
|
if(x1 >= x2 || y1 >= y2)
|
||||||
|
return;
|
||||||
|
for(y = y1; y < y2; y++)
|
||||||
|
for(x = x1; x < x2; x++)
|
||||||
|
layer->pixels[x + y * p->width] = color;
|
||||||
|
layer->changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -52,13 +53,14 @@ screen_blit(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8
|
||||||
for(h = 7; h >= 0; --h, c >>= 1) {
|
for(h = 7; h >= 0; --h, c >>= 1) {
|
||||||
Uint8 ch = (c & 1) | ((c >> 7) & 2);
|
Uint8 ch = (c & 1) | ((c >> 7) & 2);
|
||||||
if(opaque || ch)
|
if(opaque || ch)
|
||||||
screen_write(p,
|
screen_pixel(p,
|
||||||
layer,
|
layer,
|
||||||
x + (flipx ? 7 - h : h),
|
x + (flipx ? 7 - h : h),
|
||||||
y + (flipy ? 7 - v : v),
|
y + (flipy ? 7 - v : v),
|
||||||
blending[ch][color]);
|
blending[ch][color]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
layer->changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -137,7 +139,8 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
||||||
Uint8 xflip = d[0xe] & 0x10, yflip = d[0xe] & 0x20;
|
Uint8 xflip = d[0xe] & 0x10, yflip = d[0xe] & 0x20;
|
||||||
screen_fill(&uxn_screen, layer, xflip ? 0 : x, yflip ? 0 : y, xflip ? x : uxn_screen.width, yflip ? y : uxn_screen.height, d[0xe] & 0x3);
|
screen_fill(&uxn_screen, layer, xflip ? 0 : x, yflip ? 0 : y, xflip ? x : uxn_screen.width, yflip ? y : uxn_screen.height, d[0xe] & 0x3);
|
||||||
} else {
|
} else {
|
||||||
screen_write(&uxn_screen, layer, x, y, d[0xe] & 0x3);
|
screen_pixel(&uxn_screen, layer, x, y, d[0xe] & 0x3);
|
||||||
|
layer->changed = 1;
|
||||||
if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */
|
if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */
|
||||||
if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */
|
if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue