diff --git a/TODO.txt b/TODO.txt index e566b02..4007b64 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,3 +1,9 @@ +- background sky rendering efficiently: + - first draw the solid color top and bottom + - then render the 3D scene + - then iterate over the strip that should have the sky texture and only draw + to pixels where depth buffer was not overwritten (this step can be left out + in case we have depth buffer or sky turned off) TOTAL SIZE OF TEXTURES: - 64 x 64 x 2 = 8192, 6 x floor + 2 x wall + 1 x car = 8 * 8192 = 73728 - (128 x 128 x 1) x 3 background = 49152 diff --git a/assets.h b/assets.h index f13eb9b..a002215 100644 --- a/assets.h +++ b/assets.h @@ -3,8 +3,7 @@ #include - - +#define LCR_SKY_IMAGE_SIZE 128 static const uint16_t LCR_skyImages[] = { diff --git a/game.h b/game.h index d5654f2..d2c0495 100644 --- a/game.h +++ b/game.h @@ -116,8 +116,43 @@ void LCR_gameEnd(void) { } -void LCR_drawSky() +void LCR_drawSkyStrip(int verticalOffset, uint8_t horizontalOffset) { + +#if LCR_SETTING_SKY_SIZE != 0 + + verticalOffset -= (LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE) / 2; + + int finalY = verticalOffset + LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE; + + if (finalY >= LCR_EFFECTIVE_RESOLUTION_Y) + finalY = LCR_EFFECTIVE_RESOLUTION_Y - 1; + + unsigned int skyY = 0; + + if (verticalOffset < 0) + { + skyY = -1 * verticalOffset; + verticalOffset = 0; + } + + while (verticalOffset < finalY) + { + for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i) + { + LCR_drawPixelUnsafe(x,y,10000); + } + + skyY++; + verticalOffset++; + } + +#endif + + + + +/* const uint16_t *pixel = LCR_skyImages + 256; uint8_t odd = 1; @@ -138,6 +173,7 @@ void LCR_drawSky() pixel++; } } +*/ } @@ -146,7 +182,7 @@ uint8_t LCR_gameStep(uint32_t time) for (int i = 0; i < LCR_KEYS_TOTAL; ++i) _LCR_keyStates[i] = LCR_keyPressed(i); - LCR_drawSky(); + LCR_drawSkyStrip(); return 1; } diff --git a/settings.h b/settings.h index 59c30d3..3a7c480 100644 --- a/settings.h +++ b/settings.h @@ -13,6 +13,11 @@ #define LCR_SETTING_RESOLUTION_SUBDIVIDE 1 #endif +#ifndef LCR_SETTING_SKY_SIZE + /** Size of sky texture pixel, 0 turns off sky rendering. */ + #define LCR_SETTING_SKY_SIZE 1 +#define + #ifndef LCR_SETTING_MAP_MAX_SIZE /** Maximum number of blocks a map can consist of, decreasing will save RAM but also rule out loading bigger maps. */