This commit is contained in:
Miloslav Číž 2018-09-11 14:37:54 +02:00
parent 2363c2b099
commit c3f588031f
3 changed files with 42 additions and 43 deletions

View file

@ -11,6 +11,7 @@
*/ */
// redefine some parameters // redefine some parameters
#define FPS 40
#define GRAVITY_ACCELERATION (UNITS_PER_SQUARE * 3) #define GRAVITY_ACCELERATION (UNITS_PER_SQUARE * 3)
#define PLAYER_JUMP_SPEED 700 #define PLAYER_JUMP_SPEED 700
#define CAMERA_COLL_HEIGHT_BELOW ((3 * UNITS_PER_SQUARE) / 2) #define CAMERA_COLL_HEIGHT_BELOW ((3 * UNITS_PER_SQUARE) / 2)
@ -695,14 +696,14 @@ Unit ceilingHeightAt(int16_t x, int16_t y)
Function for drawing a single pixel (like fragment shader). Bottleneck => Function for drawing a single pixel (like fragment shader). Bottleneck =>
should be as fast as possible. should be as fast as possible.
*/ */
inline void pixelFunc(PixelInfo pixel) inline void pixelFunc(PixelInfo *pixel)
{ {
if (pixel.position.y == MIDDLE_ROW) if (pixel->position.y == MIDDLE_ROW)
zBuffer[pixel.position.x] = pixel.depth; zBuffer[pixel->position.x] = pixel->depth;
uint8_t c; uint8_t c;
Unit depth = pixel.depth - UNITS_PER_SQUARE * 3; Unit depth = pixel->depth - UNITS_PER_SQUARE * 3;
depth = depth > 0 ? depth : 1; depth = depth > 0 ? depth : 1;
int intensity = 7 - (depth * 7) / (UNITS_PER_SQUARE * 5); int intensity = 7 - (depth * 7) / (UNITS_PER_SQUARE * 5);
@ -710,26 +711,26 @@ inline void pixelFunc(PixelInfo pixel)
if (intensity < 0) if (intensity < 0)
intensity = 0; intensity = 0;
if (pixel.isWall) if (pixel->isWall)
{ {
if ((pixel.hit.direction == 0 || pixel.hit.direction == 2)) if ((pixel->hit.direction == 0 || pixel->hit.direction == 2))
intensity -= 2; intensity -= 2;
if (intensity < 0) if (intensity < 0)
intensity = 0; intensity = 0;
c = sampleImage(textures[pixel.hit.type],pixel.hit.textureCoord,pixel.textureCoordY); c = sampleImage(textures[pixel->hit.type],pixel->hit.textureCoord,pixel->textureCoordY);
c = addIntensity(c,intensity - 3); c = addIntensity(c,intensity - 3);
} }
else else
c = pixel.isFloor ? c = pixel->isFloor ?
rgbToIndex(intensity/2,intensity,intensity/3) : rgbToIndex(intensity/2,intensity,intensity/3) :
rgbToIndex(intensity,intensity/2,0); rgbToIndex(intensity,intensity/2,0);
uint8_t *buf = pokitto.display.screenbuffer; uint8_t *buf = pokitto.display.screenbuffer;
buf += pixel.position.x * SUBSAMPLE; buf += pixel->position.x * SUBSAMPLE;
buf += pixel.position.y * SCREEN_WIDTH; buf += pixel->position.y * SCREEN_WIDTH;
#pragma unroll #pragma unroll
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i) for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)
@ -784,7 +785,6 @@ int main()
{ {
initGeneral(); initGeneral();
// player.setPositionSquare(4,5);
player.setPositionSquare(6,4); player.setPositionSquare(6,4);
player.mCamera.direction = 256; player.mCamera.direction = 256;

View file

@ -766,42 +766,42 @@ int8_t pixelIntensity = 0; ///< Precomputed column intensity addition.
/** /**
Function for drawing a single pixel (like fragment shader). Function for drawing a single pixel (like fragment shader).
*/ */
inline void pixelFunc(PixelInfo pixel) inline void pixelFunc(PixelInfo *pixel)
{ {
if (pixel.position.y == MIDDLE_ROW) if (pixel->position.y == MIDDLE_ROW)
zBuffer[pixel.position.x] = pixel.depth; zBuffer[pixel->position.x] = pixel->depth;
uint8_t c = 0; uint8_t c = 0;
if (!pixel.isWall) if (!pixel->isWall)
{ {
c = pixel.isFloor ? cFloor: cCeiling; c = pixel->isFloor ? cFloor: cCeiling;
} }
else else
{ {
Unit textureScroll = pixel.hit.type != 4 ? 0 : 16 * pokitto.frameCount; Unit textureScroll = pixel->hit.type != 4 ? 0 : 16 * pokitto.frameCount;
c = pixel.depth < TEXTURE_MAX_DISTANCE ? c = pixel->depth < TEXTURE_MAX_DISTANCE ?
sampleImage(textures[pixel.hit.type],pixel.hit.textureCoord + textureScroll,pixel.textureCoordY) : sampleImage(textures[pixel->hit.type],pixel->hit.textureCoord + textureScroll,pixel->textureCoordY) :
textureAverageColors[pixel.hit.type]; textureAverageColors[pixel->hit.type];
if (previousColumn == pixel.position.x) if (previousColumn == pixel->position.x)
{ {
c = addIntensity(c,pixelIntensity); c = addIntensity(c,pixelIntensity);
} }
else else
{ {
// optimization: precompute intensity for the whole column // optimization: precompute intensity for the whole column
pixelIntensity = 1 - pixel.depth / (UNITS_PER_SQUARE * 2) + (pixel.hit.direction % 2 == 0 ? 2 : 0); pixelIntensity = 1 - pixel->depth / (UNITS_PER_SQUARE * 2) + (pixel->hit.direction % 2 == 0 ? 2 : 0);
previousColumn = pixel.position.x; previousColumn = pixel->position.x;
c = addIntensity(c,pixelIntensity); c = addIntensity(c,pixelIntensity);
} }
} }
uint8_t *buf = pokitto.display.screenbuffer; uint8_t *buf = pokitto.display.screenbuffer;
buf += pixel.position.x * SUBSAMPLE; buf += pixel->position.x * SUBSAMPLE;
buf += pixel.position.y * pokitto.display.width; buf += pixel->position.y * pokitto.display.width;
#pragma unroll #pragma unroll
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i) for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)

View file

@ -194,36 +194,36 @@ uint16_t backgroundColumn = 0; ///< Precomputed background column.
/** /**
Function for drawing a single pixel (like fragment shader). Function for drawing a single pixel (like fragment shader).
*/ */
inline void pixelFunc(PixelInfo pixel) inline void pixelFunc(PixelInfo *pixel)
{ {
uint8_t c = 0; uint8_t c = 0;
int16_t intensity = 0; int16_t intensity = 0;
if (pixel.isWall) if (pixel->isWall)
{ {
c = pixel.hit.square.x != selectedSquare.x || pixel.hit.square.y != selectedSquare.y || (editing && pokitto.frameCount % 2) == 0 ? c = pixel->hit.square.x != selectedSquare.x || pixel->hit.square.y != selectedSquare.y || (editing && pokitto.frameCount % 2) == 0 ?
squareColors[pixel.hit.type] : 30; squareColors[pixel->hit.type] : 30;
intensity = pixel.depth / (UNITS_PER_SQUARE * 3); intensity = pixel->depth / (UNITS_PER_SQUARE * 3);
intensity += pixel.hit.direction % 2 == 0 ? 2 : 0; intensity += pixel->hit.direction % 2 == 0 ? 2 : 0;
} }
else if (pixel.isFloor) else if (pixel->isFloor)
{ {
c = floorColor; c = floorColor;
if (!pixel.isHorizon) if (!pixel->isHorizon)
intensity = pixel.depth / (UNITS_PER_SQUARE * 3); intensity = pixel->depth / (UNITS_PER_SQUARE * 3);
} }
else else
{ {
if (previousColumn == pixel.position.x) if (previousColumn == pixel->position.x)
{ {
c = imageBackground[2 + backgroundColumn * 22 + min(pixel.position.y,43) / 2]; c = imageBackground[2 + backgroundColumn * 22 + min(pixel->position.y,43) / 2];
} }
else else
{ {
backgroundColumn = absVal(pixel.position.x / 2 + (110 * player.mCamera.direction) / UNITS_PER_SQUARE) % 55; backgroundColumn = absVal(pixel->position.x / 2 + (110 * player.mCamera.direction) / UNITS_PER_SQUARE) % 55;
previousColumn = pixel.position.x; previousColumn = pixel->position.x;
} }
} }
@ -232,8 +232,8 @@ inline void pixelFunc(PixelInfo pixel)
uint8_t *buf = pokitto.display.screenbuffer; uint8_t *buf = pokitto.display.screenbuffer;
buf += pixel.position.x * SUBSAMPLE; buf += pixel->position.x * SUBSAMPLE;
buf += pixel.position.y * SCREEN_WIDTH; buf += pixel->position.y * SCREEN_WIDTH;
#pragma unroll #pragma unroll
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i) for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)
@ -291,7 +291,6 @@ void cameraFlyBy(uint32_t dt)
player.mCamera.position.x += step * 30; player.mCamera.position.x += step * 30;
player.mCamera.position.y += step * 15; player.mCamera.position.y += step * 15;
player.mCamera.direction = sinInt(pokitto.frameCount / 8); player.mCamera.direction = sinInt(pokitto.frameCount / 8);
} }