1
Fork 0

Increase performance of Tick by partially unrolling Calc* functions.

This commit is contained in:
Marisa the Magician 2023-10-09 16:21:59 +02:00
commit 605798b51b
2 changed files with 102 additions and 28 deletions

View file

@ -232,8 +232,8 @@ class FireTexture
// prepare the lut // prepare the lut
for ( int i=0; i<256; i++ ) for ( int i=0; i<256; i++ )
{ {
double x = pal[i].r+((pal[i].g/16)*256)%4096; double x = pal[i].r+((pal[i].g>>4)<<8)&4095;
double y = (pal[i].g/16)+(pal[i].b*16); double y = (pal[i].g>>4)+(pal[i].b<<4);
blitterlut[i] = (x,y)/4096.+(1.,1.)/8192.; blitterlut[i] = (x,y)/4096.+(1.,1.)/8192.;
} }
} }

View file

@ -13,6 +13,7 @@ extend class FireTexture
private int renderheat; // overall intensity private int renderheat; // overall intensity
// direct pixel access wrapper functions // direct pixel access wrapper functions
// not used by the Calc code, would reduce performance
private uint GetPixel( uint x, uint y ) private uint GetPixel( uint x, uint y )
{ {
// ensure coords are wrapped // ensure coords are wrapped
@ -27,33 +28,74 @@ extend class FireTexture
y &= vmask; y &= vmask;
pixels[x+y*width] = c; pixels[x+y*width] = c;
} }
private Color GetPixelRGB( uint x, uint y )
{
// ensure coords are wrapped
x &= umask;
y &= vmask;
return pal[pixels[x+y*width]];
}
private uint LookupFiretable( uint a, uint b, uint c, uint d )
{
return firetable[min(a+b+c+d,1023)];
}
// heat propagation with bRising (triangle shifted two pixels down) // heat propagation with bRising (triangle shifted two pixels down)
private void CalcWrapFire() private void CalcWrapFire()
{ {
uint mid, left, right, up; uint mid, left, right, up;
for ( uint y=0; y<height; y++ ) uint y;
for ( y=0; y<height-2; y++ )
{ {
for ( uint x=0; x<width; x++ ) mid = pixels[(y+1)*width];
left = pixels[(width-1)+(y+1)*width];
right = pixels[1+(y+1)*width];
up = pixels[(y+2)*width];
pixels[y*width] = firetable[mid+left+right+up];
for ( uint x=1; x<width-1; x++ )
{ {
mid = GetPixel(x,y+1); mid = pixels[x+(y+1)*width];
left = GetPixel(x-1,y+1); left = pixels[(x-1)+(y+1)*width];
right = GetPixel(x+1,y+1); right = pixels[(x+1)+(y+1)*width];
up = GetPixel(x,y+2); up = pixels[x+(y+2)*width];
PutPixel(x,y,LookupFiretable(mid,left,right,up)); pixels[x+y*width] = firetable[mid+left+right+up];
} }
mid = pixels[(width-1)+(y+1)*width];
left = pixels[(width-2)+(y+1)*width];
right = pixels[(y+1)*width];
up = pixels[(width-1)+(y+2)*width];
pixels[(width-1)+y*width] = firetable[mid+left+right+up];
}
y = height-2;
{
mid = pixels[(y+1)*width];
left = pixels[(width-1)+(y+1)*width];
right = pixels[1+(y+1)*width];
up = pixels[0];
pixels[y*width] = firetable[mid+left+right+up];
for ( uint x=1; x<width-1; x++ )
{
mid = pixels[x+(y+1)*width];
left = pixels[(x-1)+(y+1)*width];
right = pixels[(x+1)+(y+1)*width];
up = pixels[x];
pixels[x+y*width] = firetable[mid+left+right+up];
}
mid = pixels[(width-1)+(y+1)*width];
left = pixels[(width-2)+(y+1)*width];
right = pixels[(y+1)*width];
up = pixels[(width-1)];
pixels[(width-1)+y*width] = firetable[mid+left+right+up];
}
y = height-1;
{
mid = pixels[width];
left = pixels[(width-1)];
right = pixels[1];
up = pixels[2*width];
pixels[y*width] = firetable[mid+left+right+up];
for ( uint x=1; x<width-1; x++ )
{
mid = pixels[x+width];
left = pixels[(x-1)+width];
right = pixels[(x+1)+width];
up = pixels[x+2*width];
pixels[x+y*width] = firetable[mid+left+right+up];
}
mid = pixels[(width-1)+width];
left = pixels[(width-2)+width];
right = pixels[width];
up = pixels[(width-1)+2*width];
pixels[(width-1)+y*width] = firetable[mid+left+right+up];
} }
} }
// ... without bRising (triangle shifted one pixel down) // ... without bRising (triangle shifted one pixel down)
@ -64,16 +106,48 @@ extend class FireTexture
uint temp[256]; uint temp[256];
for ( uint i=0; i<width; i++ ) temp[i] = pixels[i]; for ( uint i=0; i<width; i++ ) temp[i] = pixels[i];
uint mid, left, right, up; uint mid, left, right, up;
for ( uint y=0; y<height; y++ ) uint y;
for ( y=0; y<height-1; y++ )
{ {
for ( uint x=0; x<width; x++ ) mid = pixels[y*width];
left = pixels[(width-1)+y*width];
right = pixels[1+y*width];
up = pixels[(y+1)*width];
pixels[y*width] = firetable[mid+left+right+up];
for ( uint x=1; x<width-1; x++ )
{ {
mid = GetPixel(x,y); mid = pixels[x+y*width];
left = GetPixel(x-1,y); left = pixels[(x-1)+y*width];
right = GetPixel(x+1,y); right = pixels[(x+1)+y*width];
up = (y==height-1)?temp[x&255]:GetPixel(x,y+1); up = pixels[x+(y+1)*width];
PutPixel(x,y,LookupFiretable(mid,left,right,up)); pixels[x+y*width] = firetable[mid+left+right+up];
} }
mid = pixels[(width-1)+y*width];
left = pixels[(width-2)+y*width];
right = pixels[y*width];
up = pixels[(width-1)+(y+1)*width];
pixels[(width-1)+y*width] = firetable[mid+left+right+up];
}
y = height-1;
{
mid = pixels[y*width];
left = pixels[(width-1)+y*width];
right = pixels[1+y*width];
up = temp[0];
pixels[y*width] = firetable[mid+left+right+up];
for ( uint x=1; x<width-1; x++ )
{
mid = pixels[x+y*width];
left = pixels[(x-1)+y*width];
right = pixels[(x+1)+y*width];
up = temp[x];
pixels[x+y*width] = firetable[mid+left+right+up];
}
mid = pixels[(width-1)+y*width];
left = pixels[(width-2)+y*width];
right = pixels[y*width];
up = temp[width-1];
pixels[(width-1)+y*width] = firetable[mid+left+right+up];
} }
} }
} }