mirror of
https://github.com/kwsch/NHSE.git
synced 2026-03-21 17:24:30 -05:00
Minor perf improvements
Move repeat calculations from inner loop to outer loop Extract some methods for reusability
This commit is contained in:
parent
91418e9c66
commit
cf889668d3
|
|
@ -32,20 +32,26 @@ private static int[] GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, ou
|
|||
width = layer.GridWidth;
|
||||
|
||||
var bmpData = new int[width * height];
|
||||
LoadPixelsFromLayer(layer, x0, y0, width, bmpData);
|
||||
|
||||
return bmpData;
|
||||
}
|
||||
|
||||
private static void LoadPixelsFromLayer(FieldItemLayer layer, int x0, int y0, int width, int[] bmpData)
|
||||
{
|
||||
var stride = layer.GridWidth;
|
||||
|
||||
for (int x = 0; x < stride; x++)
|
||||
for (int y = 0; y < stride; y++)
|
||||
{
|
||||
for (int y = 0; y < stride; y++)
|
||||
var baseIndex = (y * width);
|
||||
for (int x = 0; x < stride; x++)
|
||||
{
|
||||
var tile = layer.GetTile(x + x0, y + y0);
|
||||
var color = FieldItemSprite.GetItemColor(tile).ToArgb();
|
||||
var i = (y * width) + x;
|
||||
bmpData[i] = color;
|
||||
var index = baseIndex + x;
|
||||
bmpData[index] = color;
|
||||
}
|
||||
}
|
||||
|
||||
return bmpData;
|
||||
}
|
||||
|
||||
public static Bitmap GetBitmapLayerAcre(FieldItemLayer layer, int x0, int y0, int scale)
|
||||
|
|
@ -99,11 +105,12 @@ private static void DrawGrid(int[] data, int w, int h, int scale)
|
|||
const int grid = -0x777778; // 0xFF888888u
|
||||
|
||||
// Horizontal Lines
|
||||
for (int x = 0; x < w; x++)
|
||||
for (int y = scale; y < h; y += scale)
|
||||
{
|
||||
for (int y = scale; y < h; y += scale)
|
||||
var baseIndex = y * w;
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
var index = (y * w) + x;
|
||||
var index = baseIndex + x;
|
||||
data[index] = grid;
|
||||
}
|
||||
}
|
||||
|
|
@ -111,9 +118,10 @@ private static void DrawGrid(int[] data, int w, int h, int scale)
|
|||
// Vertical Lines
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
var baseIndex = y * w;
|
||||
for (int x = scale; x < w; x += scale)
|
||||
{
|
||||
var index = (y * w) + x;
|
||||
var index = baseIndex + x;
|
||||
data[index] = grid;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,13 @@ public static int[] ScalePixelImage(int[] data, int scale, int w, int h, out int
|
|||
fH = scale * h;
|
||||
var scaled = new int[fW * fH];
|
||||
|
||||
ScalePixelImage(data, scaled, fW, fH, scale);
|
||||
|
||||
return scaled;
|
||||
}
|
||||
|
||||
private static void ScalePixelImage(int[] data, int[] scaled, int fW, int fH, int scale)
|
||||
{
|
||||
// For each pixel, copy to the X indexes, then block copy the row to the other rows.
|
||||
for (int y = 0, i = 0; y < fH; y += scale)
|
||||
{
|
||||
|
|
@ -85,8 +92,6 @@ public static int[] ScalePixelImage(int[] data, int scale, int w, int h, out int
|
|||
for (int y1 = 1; y1 < scale; y1++)
|
||||
Array.Copy(scaled, baseIndex, scaled, baseIndex + (y1 * fW), fW);
|
||||
}
|
||||
|
||||
return scaled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user