From 0cc8cbb2c5c3a7a4b9321ed6f1a2d42df3bbc374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 14 Sep 2018 14:01:53 +0200 Subject: [PATCH] Add settings to demo2 --- demo2.cpp | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/demo2.cpp b/demo2.cpp index afbf7e1..5af058b 100644 --- a/demo2.cpp +++ b/demo2.cpp @@ -1,8 +1,11 @@ /** Raycasting demo 2 for Pokitto. - This demo shows the simple version (only 1 intersection) of raycasting. Has - a fairly high FPS. + This demo shows a simple version (wolf3D-like) raycasting. It has a fairly + high FPS. + + There is a number of compile-time settings you can try! Look at the defines + below. Don't forget to compile with -O3! @@ -10,6 +13,31 @@ license: CC0 1.0 */ +// settings: + +//#define SUBSAMPLE 1 + /* ^ Turns high resolution in X direction on, which means twice as many rays + that will be cast. The result looks beautiful but dramatically decreases + FPS. */ + +//#define RENDER_PRECISE + /* ^ Turns on rendering using a more precise but slower algorithm. This can + be seen at less shaky head bobbing when moving. */ + +//#define NO_TEXTURES + /* ^ Turns off textures and only uses colors, which increases FPS. */ + +//#define USE_DIST_APPROX 1 + /* ^ Turns on distance approximation, which won't compute exact distances but + only approximations - this should increase performance a little, but + results in slightly distorted walls. */ + +//#define USE_COS_LUT 2 + /* ^ Turns on cos look up tables (128 items, USE_COS_LUT 1 will use only 64 + items), which should theoretically be faster, but will take additional + memory and turning can be less precise (can be seen a lot with 64 item + LUT). */ + #define FPS 60 #define HEAD_BOB_HEIGHT 200 #define HEAD_BOB_STEP 20 @@ -781,9 +809,13 @@ inline void pixelFunc(PixelInfo *pixel) { Unit textureScroll = pixel->hit.type != 4 ? 0 : 16 * pokitto.frameCount; +#ifdef NO_TEXTURES + c = textureAverageColors[pixel->hit.type]; +#else c = pixel->depth < TEXTURE_MAX_DISTANCE ? sampleImage(textures[pixel->hit.type],pixel->hit.textureCoord + textureScroll,pixel->textureCoordY) : textureAverageColors[pixel->hit.type]; +#endif if (previousColumn == pixel->position.x) { @@ -810,11 +842,12 @@ void draw() c.computeTextureCoords = 1; player.mCamera.height += player.mHeadBob; - renderSimple(player.mCamera,floorHeightAt,textureAt,pixelFunc,c); - /* this would achieve more or less the same (less shaky head bob), - for a cost of a few FPS: */ - // render(player.mCamera,floorHeightAt,0,textureAt,pixelFunc,c); +#ifdef RENDER_PRECISE + render(player.mCamera,floorHeightAt,0,textureAt,pixelFunc,c); +#else + renderSimple(player.mCamera,floorHeightAt,textureAt,pixelFunc,c); +#endif player.mCamera.height -= player.mHeadBob;