MiataDrive: render optimizations (startWrite batching, fillRect grass/sky, DRAW_DIST 60)

This commit is contained in:
Dejvino
2026-11-12 22:40:43 +01:00
parent 008cfefc4d
commit 6eaac43050
2 changed files with 10 additions and 7 deletions
+8 -7
View File
@@ -34,7 +34,7 @@ static int scrW, scrH;
static const uint32_t FRAME_MS = 33; // ~30 fps
static const int SEG_LEN = 200; // segment length (world units)
static const int RUMBLE_SEGS = 3; // segments per rumble stripe
static const int DRAW_DIST = 90; // segments drawn ahead
static const int DRAW_DIST = 60; // segments drawn ahead
static const float ROAD_W = 1000.0f; // road half-width (world units)
static const float CAM_H = 1500.0f; // camera height above road
static const float CAM_D = 0.84f; // 1/tan(fov/2), fov ~100 deg
@@ -357,10 +357,9 @@ static void renderRoad() {
const float HORIZON_Y = scrH * 0.36f;
// sky down to just past the vanishing point
int skyBot = (int)HORIZON_Y + 14;
for (int y = 0; y < skyBot; y++) {
uint16_t c = (y < skyBot * 2 / 5) ? colSkyHi : colSkyLo;
tft.drawFastHLine(0, y, scrW, c);
}
int skySplit = skyBot * 2 / 5;
tft.fillRect(0, 0, scrW, skySplit, colSkyHi);
tft.fillRect(0, skySplit, scrW, skyBot - skySplit, colSkyLo);
float basePercent = fmodf(position_, SEG_LEN) / SEG_LEN;
int baseIdx = ((int)(position_ / SEG_LEN)) % segCount;
@@ -425,8 +424,8 @@ static void renderRoad() {
// grass band
uint16_t grass = light ? palGrassL[fog] : palGrassD[fog];
int yTop = iround(P2[n].y), yBot = iround(P1[n].y) - 1;
for (int y = yTop; y <= yBot; y++)
if (y < maxY) tft.drawFastHLine(0, y, scrW, grass);
if (yBot > (int)maxY - 1) yBot = (int)maxY - 1;
if (yTop <= yBot && yBot >= 0) tft.fillRect(0, yTop, scrW, yBot - yTop + 1, grass);
// rumble strips (wide, for speed sensation)
float r1 = P1[n].w / 6.0f, r2 = P2[n].w / 6.0f;
@@ -836,6 +835,7 @@ static void drawEndScreen(bool win) {
}
static void render() {
tft.startWrite();
switch (gameState) {
case ST_TITLE: drawTitle(); break;
case ST_SPRITES: drawSpriteTest(); break;
@@ -848,6 +848,7 @@ static void render() {
drawHUD();
break;
}
tft.endWrite();
}
// ---------------------------------------------------------------------------