mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 19:26:43 +01:00
optimize blitSprite
This commit is contained in:
Binary file not shown.
@@ -353,11 +353,23 @@ export fn line(x1: f32, y1: f32, x2: f32, y2: f32, col: i32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export fn blitSprite(sprite: i32, size: i32, x: i32, y: i32, control: i32) {
|
export fn blitSprite(sprite: i32, size: i32, x: i32, y: i32, control: i32) {
|
||||||
let width = size & 65535;
|
let lazy width = size & 65535;
|
||||||
let height = select(size >> 16, size >> 16, width);
|
let lazy height = select(size >> 16, size >> 16, width);
|
||||||
|
|
||||||
|
let lazy x0 = select(x < 0, -x, 0);
|
||||||
|
let lazy x1 = select(x + width > 320, 320 - x, width);
|
||||||
|
let lazy y0 = select(y < 0, -y, 0);
|
||||||
|
let lazy y1 = select(y + height > 240, 240 - y, height);
|
||||||
|
|
||||||
|
let lazy numRows = y1 - y0;
|
||||||
|
let lazy numCols = x1 - x0;
|
||||||
|
if numRows <= 0 | numCols <= 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let trans = (control & 511) - 256;
|
let trans = (control & 511) - 256;
|
||||||
let flip_x = 1 - ((control >> 8) & 2);
|
let lazy flip_x = 1 - ((control >> 8) & 2);
|
||||||
let flip_y = 1 - ((control >> 9) & 2);
|
let lazy flip_y = 1 - ((control >> 9) & 2);
|
||||||
if flip_x < 0 {
|
if flip_x < 0 {
|
||||||
sprite += width - 1;
|
sprite += width - 1;
|
||||||
}
|
}
|
||||||
@@ -365,17 +377,21 @@ export fn blitSprite(sprite: i32, size: i32, x: i32, y: i32, control: i32) {
|
|||||||
sprite += (height - 1) * width;
|
sprite += (height - 1) * width;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ly = 0;
|
let srcRow = sprite + x0 * flip_x + y0 * flip_y * width;
|
||||||
|
let dstRow = x + x0 + (y + y0) * 320;
|
||||||
|
|
||||||
loop yloop {
|
loop yloop {
|
||||||
let lx = 0;
|
let lx = 0;
|
||||||
loop xloop {
|
loop xloop {
|
||||||
let col = (sprite + lx * flip_x + ly * flip_y * height)?0;
|
let lazy col = (srcRow + lx * flip_x)?0;
|
||||||
if col != trans {
|
if col != trans {
|
||||||
setPixel(x + lx, y + ly, col);
|
(dstRow + lx)?120 = col;
|
||||||
}
|
}
|
||||||
branch_if (lx +:= 1) < width: xloop;
|
branch_if (lx +:= 1) < numCols: xloop;
|
||||||
}
|
}
|
||||||
branch_if (ly +:= 1) < height: yloop;
|
srcRow += width * flip_y;
|
||||||
|
dstRow += 320;
|
||||||
|
branch_if numRows -:= 1: yloop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user