feat: Update viewport calculations in renderers for consistent height handling and improve map rendering logic
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -422,23 +422,32 @@ class AsciiRenderer extends CliRendererBackend<dynamic> {
|
|||||||
final int playerColor = ColorPalette.vga32Bit[10];
|
final int playerColor = ColorPalette.vga32Bit[10];
|
||||||
final int facingColor = ColorPalette.vga32Bit[15];
|
final int facingColor = ColorPalette.vga32Bit[15];
|
||||||
|
|
||||||
if (_usesTerminalLayout) {
|
final int viewportY = 0;
|
||||||
_fillTerminalRect(
|
|
||||||
projectionOffsetX,
|
|
||||||
0,
|
|
||||||
projectionWidth,
|
|
||||||
_terminalPixelHeight,
|
|
||||||
mapBgColor,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
_fillRect(0, 0, width, height, activeTheme.solid, mapBgColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
final int viewportX = _usesTerminalLayout ? projectionOffsetX : 0;
|
final int viewportX = _usesTerminalLayout ? projectionOffsetX : 0;
|
||||||
final int viewportWidth = _usesTerminalLayout ? projectionWidth : width;
|
final int viewportWidth = _usesTerminalLayout ? projectionWidth : width;
|
||||||
final int viewportHeight = _usesTerminalLayout
|
final int viewportHeight = _usesTerminalLayout
|
||||||
? _terminalPixelHeight
|
? projectionViewHeight
|
||||||
: height;
|
: viewHeight;
|
||||||
|
|
||||||
|
if (_usesTerminalLayout) {
|
||||||
|
_fillTerminalRect(
|
||||||
|
viewportX,
|
||||||
|
viewportY,
|
||||||
|
viewportWidth,
|
||||||
|
viewportHeight,
|
||||||
|
mapBgColor,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_fillRect(
|
||||||
|
viewportX,
|
||||||
|
viewportY,
|
||||||
|
viewportWidth,
|
||||||
|
viewportHeight,
|
||||||
|
activeTheme.solid,
|
||||||
|
mapBgColor,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
final int viewportPadding = math.max(
|
final int viewportPadding = math.max(
|
||||||
3,
|
3,
|
||||||
math.min(viewportWidth, viewportHeight) ~/ 24,
|
math.min(viewportWidth, viewportHeight) ~/ 24,
|
||||||
@@ -458,7 +467,7 @@ class AsciiRenderer extends CliRendererBackend<dynamic> {
|
|||||||
final int mapPixelWidth = tileSize * 64;
|
final int mapPixelWidth = tileSize * 64;
|
||||||
final int mapPixelHeight = tileSize * 64;
|
final int mapPixelHeight = tileSize * 64;
|
||||||
final int mapStartX = viewportX + ((viewportWidth - mapPixelWidth) ~/ 2);
|
final int mapStartX = viewportX + ((viewportWidth - mapPixelWidth) ~/ 2);
|
||||||
final int mapStartY = (viewportHeight - mapPixelHeight) ~/ 2;
|
final int mapStartY = viewportY + ((viewportHeight - mapPixelHeight) ~/ 2);
|
||||||
|
|
||||||
for (int y = 0; y < 64; y++) {
|
for (int y = 0; y < 64; y++) {
|
||||||
for (int x = 0; x < 64; x++) {
|
for (int x = 0; x < 64; x++) {
|
||||||
|
|||||||
@@ -376,13 +376,14 @@ class SixelRenderer extends CliRendererBackend<String> {
|
|||||||
const int playerColor = 10;
|
const int playerColor = 10;
|
||||||
const int facingColor = 15;
|
const int facingColor = 15;
|
||||||
|
|
||||||
for (int i = 0; i < _screen.length; i++) {
|
_fillMapRect(0, 0, width, viewHeight, mapBgColor);
|
||||||
_screen[i] = mapBgColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int viewportPadding = math.max(3, math.min(width, height) ~/ 24);
|
final int viewportPadding = math.max(3, math.min(width, viewHeight) ~/ 24);
|
||||||
final int availableWidth = math.max(1, width - (viewportPadding * 2));
|
final int availableWidth = math.max(1, width - (viewportPadding * 2));
|
||||||
final int availableHeight = math.max(1, height - (viewportPadding * 2));
|
final int availableHeight = math.max(
|
||||||
|
1,
|
||||||
|
viewHeight - (viewportPadding * 2),
|
||||||
|
);
|
||||||
final int tileSize = math.max(
|
final int tileSize = math.max(
|
||||||
1,
|
1,
|
||||||
math.min(availableWidth, availableHeight) ~/ 64,
|
math.min(availableWidth, availableHeight) ~/ 64,
|
||||||
@@ -390,7 +391,7 @@ class SixelRenderer extends CliRendererBackend<String> {
|
|||||||
final int mapPixelWidth = tileSize * 64;
|
final int mapPixelWidth = tileSize * 64;
|
||||||
final int mapPixelHeight = tileSize * 64;
|
final int mapPixelHeight = tileSize * 64;
|
||||||
final int mapStartX = (width - mapPixelWidth) ~/ 2;
|
final int mapStartX = (width - mapPixelWidth) ~/ 2;
|
||||||
final int mapStartY = (height - mapPixelHeight) ~/ 2;
|
final int mapStartY = (viewHeight - mapPixelHeight) ~/ 2;
|
||||||
|
|
||||||
for (int y = 0; y < 64; y++) {
|
for (int y = 0; y < 64; y++) {
|
||||||
for (int x = 0; x < 64; x++) {
|
for (int x = 0; x < 64; x++) {
|
||||||
|
|||||||
@@ -156,11 +156,14 @@ class SoftwareRenderer extends RendererBackend<FrameBuffer> {
|
|||||||
final int playerColor = ColorPalette.vga32Bit[10];
|
final int playerColor = ColorPalette.vga32Bit[10];
|
||||||
final int facingColor = ColorPalette.vga32Bit[15];
|
final int facingColor = ColorPalette.vga32Bit[15];
|
||||||
|
|
||||||
_fillMenuPanel(0, 0, width, height, mapBgColor);
|
_fillMenuPanel(0, 0, width, viewHeight, mapBgColor);
|
||||||
|
|
||||||
final int viewportPadding = math.max(6, math.min(width, height) ~/ 24);
|
final int viewportPadding = math.max(6, math.min(width, viewHeight) ~/ 24);
|
||||||
final int availableWidth = math.max(1, width - (viewportPadding * 2));
|
final int availableWidth = math.max(1, width - (viewportPadding * 2));
|
||||||
final int availableHeight = math.max(1, height - (viewportPadding * 2));
|
final int availableHeight = math.max(
|
||||||
|
1,
|
||||||
|
viewHeight - (viewportPadding * 2),
|
||||||
|
);
|
||||||
final int tileSize = math.max(
|
final int tileSize = math.max(
|
||||||
1,
|
1,
|
||||||
math.min(availableWidth, availableHeight) ~/ 64,
|
math.min(availableWidth, availableHeight) ~/ 64,
|
||||||
@@ -168,7 +171,7 @@ class SoftwareRenderer extends RendererBackend<FrameBuffer> {
|
|||||||
final int mapPixelWidth = tileSize * 64;
|
final int mapPixelWidth = tileSize * 64;
|
||||||
final int mapPixelHeight = tileSize * 64;
|
final int mapPixelHeight = tileSize * 64;
|
||||||
final int mapStartX = (width - mapPixelWidth) ~/ 2;
|
final int mapStartX = (width - mapPixelWidth) ~/ 2;
|
||||||
final int mapStartY = (height - mapPixelHeight) ~/ 2;
|
final int mapStartY = (viewHeight - mapPixelHeight) ~/ 2;
|
||||||
|
|
||||||
for (int y = 0; y < 64; y++) {
|
for (int y = 0; y < 64; y++) {
|
||||||
for (int x = 0; x < 64; x++) {
|
for (int x = 0; x < 64; x++) {
|
||||||
|
|||||||
@@ -38,10 +38,15 @@ void main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int hudProbeX = frameMap.width ~/ 2;
|
||||||
|
final int hudProbeY = frameMap.height - 2;
|
||||||
|
final int hudProbeIndex = (hudProbeY * frameMap.width) + hudProbeX;
|
||||||
|
|
||||||
expect(changedPixels, greaterThan(mapPixels.length ~/ 5));
|
expect(changedPixels, greaterThan(mapPixels.length ~/ 5));
|
||||||
expect(mapPixels.contains(ColorPalette.vga32Bit[6]), isTrue);
|
expect(mapPixels.contains(ColorPalette.vga32Bit[6]), isTrue);
|
||||||
expect(mapPixels.contains(ColorPalette.vga32Bit[12]), isTrue);
|
expect(mapPixels.contains(ColorPalette.vga32Bit[12]), isTrue);
|
||||||
expect(mapPixels.contains(ColorPalette.vga32Bit[10]), isTrue);
|
expect(mapPixels.contains(ColorPalette.vga32Bit[10]), isTrue);
|
||||||
|
expect(mapPixels[hudProbeIndex], equals(normalPixels[hudProbeIndex]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user