This commit is contained in:
Miloslav Číž 2018-09-12 07:55:04 +02:00
parent c3f588031f
commit d54399f7a3
4 changed files with 43 additions and 32 deletions

View file

@ -727,16 +727,7 @@ inline void pixelFunc(PixelInfo *pixel)
rgbToIndex(intensity/2,intensity,intensity/3) :
rgbToIndex(intensity,intensity/2,0);
uint8_t *buf = pokitto.display.screenbuffer;
buf += pixel->position.x * SUBSAMPLE;
buf += pixel->position.y * SCREEN_WIDTH;
#pragma unroll
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)
*buf++ = c;
*buf = c;
putSubsampledPixel // macro
}
void draw()
@ -777,6 +768,20 @@ void draw()
previousDepth = pos.depth;
}
// uncomment for debuggin camera
/*
pokitto.display.setColor(255);
pokitto.display.setCursor(1,1);
pokitto.display.print(player.mCamera.position.x);
pokitto.display.print(" ");
pokitto.display.print(player.mCamera.position.y);
pokitto.display.print(" ");
pokitto.display.print(player.mCamera.height);
pokitto.display.print(" ");
pokitto.display.print(player.mCamera.direction);
*/
}
bool runReleased = false; // helper for detecting switching between walk/run
@ -786,7 +791,7 @@ int main()
initGeneral();
player.setPositionSquare(6,4);
player.mCamera.direction = 256;
player.setPosition(7119,14343,5120,566);
sprites[0] = Sprite(sprite1,10,5,1,100);
sprites[1] = Sprite(sprite1,14,5,1,100);

View file

@ -798,16 +798,7 @@ inline void pixelFunc(PixelInfo *pixel)
}
}
uint8_t *buf = pokitto.display.screenbuffer;
buf += pixel->position.x * SUBSAMPLE;
buf += pixel->position.y * pokitto.display.width;
#pragma unroll
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)
*buf++ = c;
*buf = c;
putSubsampledPixel // macro
}
void draw()

View file

@ -230,16 +230,7 @@ inline void pixelFunc(PixelInfo *pixel)
if (intensity != 0)
c = addIntensity(c,intensity);
uint8_t *buf = pokitto.display.screenbuffer;
buf += pixel->position.x * SUBSAMPLE;
buf += pixel->position.y * SCREEN_WIDTH;
#pragma unroll
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)
*buf++ = c;
*buf = c;
putSubsampledPixel // macro
}
bool flyBy = true;

View file

@ -67,6 +67,22 @@ Unit zBuffer[SUBSAMPLED_WIDTH]; ///< 1D z-buffer for visibility determination.
unsigned short palette[256];
// helper macro for fast pixel drawing
#ifdef POK_SIM
#define putSubsampledPixel\
pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE,pixel->position.y,c);\
pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE + 1,pixel->position.y,c);
#else
// this code breaks the simulator
#define putSubsampledPixel\
uint8_t *buf = pokitto.display.screenbuffer;\
buf += pixel->position.x * SUBSAMPLE;\
buf += pixel->position.y * SCREEN_WIDTH;\
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)\
*buf++ = c;\
*buf = c;
#endif
/**
Gets (the index of) color by specified RGB components.
@ -250,6 +266,14 @@ public:
mCamera.position.y = y;
}
void setPosition(Unit x, Unit y, Unit z, Unit direction)
{
mCamera.position.x = x;
mCamera.position.y = y;
mCamera.height = z;
mCamera.direction = direction;
}
void setPositionSquare(int16_t squareX, int16_t squareY)
{
setPosition(
@ -295,7 +319,7 @@ public:
Unit prevHeight = mCamera.height;
moveCameraWithCollision(&mCamera,moveOffset,mVericalSpeed,
floorHeightFunction, ceilingHeightFunction, computeHeight ? 1 : 0);
floorHeightFunction, ceilingHeightFunction, computeHeight ? 1 : 0, 0);
Unit heightDiff = mCamera.height - prevHeight;