Refactor
This commit is contained in:
parent
2b16ea434e
commit
c97448e9a8
4 changed files with 38 additions and 34 deletions
12
demo1.cpp
12
demo1.cpp
|
@ -1026,17 +1026,12 @@ inline void pixelFunc(RCL_PixelInfo *pixel)
|
|||
rgbToIndex(intensity/2,intensity,intensity/3) :
|
||||
rgbToIndex(intensity,intensity/2,0);
|
||||
|
||||
putSubsampledPixel // macro
|
||||
putSubsampledPixel(pixel,c);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
RCL_RayConstraints c;
|
||||
|
||||
c.maxHits = 8;
|
||||
c.maxSteps = 10;
|
||||
|
||||
RCL_render(player.mCamera,floorHeightAt,ceilingHeightAt,textureAt,c);
|
||||
RCL_render(player.mCamera,floorHeightAt,ceilingHeightAt,textureAt,defaultConstraints);
|
||||
|
||||
RCL_Unit previousDepth;
|
||||
|
||||
|
@ -1099,6 +1094,9 @@ int main()
|
|||
{
|
||||
initGeneral();
|
||||
|
||||
defaultConstraints.maxHits = 8;
|
||||
defaultConstraints.maxSteps = 10;
|
||||
|
||||
player.setPositionSquare(6,4);
|
||||
|
||||
sprites[0] = Sprite(spriteStatue,10,5,1,100);
|
||||
|
|
14
demo2.cpp
14
demo2.cpp
|
@ -961,24 +961,19 @@ inline void pixelFunc(RCL_PixelInfo *pixel)
|
|||
|
||||
}
|
||||
|
||||
putSubsampledPixel // macro
|
||||
putSubsampledPixel(pixel,c);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
RCL_RayConstraints c;
|
||||
|
||||
c.maxHits = 1;
|
||||
c.maxSteps = 20;
|
||||
|
||||
#ifdef HEAD_BOB
|
||||
player.mCamera.height += player.mHeadBob;
|
||||
#endif
|
||||
|
||||
#ifdef RENDER_PRECISE
|
||||
RCL_render(player.mCamera,floorHeightAt,0,textureAt,c);
|
||||
RCL_render(player.mCamera,floorHeightAt,0,textureAt,defaultConstraints);
|
||||
#else
|
||||
RCL_renderSimple(player.mCamera,floorHeightAt,textureAt,rollAt,c);
|
||||
RCL_renderSimple(player.mCamera,floorHeightAt,textureAt,rollAt,defaultConstraints);
|
||||
#endif
|
||||
|
||||
#ifdef HEAD_BOB
|
||||
|
@ -1001,6 +996,9 @@ int main()
|
|||
{
|
||||
initGeneral();
|
||||
|
||||
defaultConstraints.maxHits = 1;
|
||||
defaultConstraints.maxSteps = 20;
|
||||
|
||||
for (uint8_t i = 0; i < TEXTURES; ++i)
|
||||
textureAverageColors[i] = computeAverageColor(textures[i]);
|
||||
|
||||
|
|
12
demo3.cpp
12
demo3.cpp
|
@ -494,20 +494,15 @@ inline void pixelFunc(RCL_PixelInfo *pixel)
|
|||
if (intensity != 0)
|
||||
c = addIntensity(c,intensity);
|
||||
|
||||
putSubsampledPixel // macro
|
||||
putSubsampledPixel(pixel,c);
|
||||
}
|
||||
|
||||
bool flyBy = true;
|
||||
|
||||
void draw()
|
||||
{
|
||||
RCL_RayConstraints c;
|
||||
|
||||
c.maxHits = 6;
|
||||
c.maxSteps = 20;
|
||||
|
||||
player.mCamera.height += player.mHeadBob;
|
||||
RCL_render(player.mCamera,floorHeightAt,0,colorAt,c);
|
||||
RCL_render(player.mCamera,floorHeightAt,0,colorAt,defaultConstraints);
|
||||
player.mCamera.height -= player.mHeadBob;
|
||||
|
||||
if (flyBy && (pokitto.frameCount >> 3) % 3 != 0)
|
||||
|
@ -554,6 +549,9 @@ int main()
|
|||
{
|
||||
initGeneral();
|
||||
|
||||
defaultConstraints.maxHits = 6;
|
||||
defaultConstraints.maxSteps = 20;
|
||||
|
||||
floorColor = rgbToIndex(4,2,0);
|
||||
|
||||
squareColors[0] = rgbToIndex(0,0,3);
|
||||
|
|
34
general.hpp
34
general.hpp
|
@ -72,22 +72,30 @@ Pokitto::Core pokitto;
|
|||
|
||||
RCL_Unit zBuffer[SUBSAMPLED_WIDTH]; ///< 1D z-buffer for visibility determination.
|
||||
|
||||
RCL_RayConstraints defaultConstraints;
|
||||
|
||||
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);
|
||||
inline void putSubsampledPixel(RCL_PixelInfo *pixel, uint8_t color)
|
||||
{
|
||||
pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE,pixel->position.y,color);
|
||||
pokitto.display.drawPixel(pixel->position.x * SUBSAMPLE + 1,pixel->position.y,color);
|
||||
}
|
||||
#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;
|
||||
// This code breaks the simulator.
|
||||
inline void putSubsampledPixel(RCL_PixelInfo *pixel, uint8_t color)
|
||||
{
|
||||
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++ = color;
|
||||
|
||||
*buf = color;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -394,6 +402,8 @@ void initGeneral()
|
|||
pokitto.display.setFont(fontTiny);
|
||||
pokitto.display.persistence = 1;
|
||||
|
||||
RCL_initRayConstraints(&defaultConstraints);
|
||||
|
||||
initPalette();
|
||||
|
||||
for (uint8_t i = 0; i < SUBSAMPLED_WIDTH; ++i)
|
||||
|
|
Loading…
Reference in a new issue