From 57c6c5db1e25a6c1b619c63a58252149057060d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 21 Sep 2018 11:14:02 +0200 Subject: [PATCH] Update tests --- make.sh | 6 ++++-- testSDL.c | 4 ++-- testTerminal.c | 44 +++++++++++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/make.sh b/make.sh index 415a5c6..f642d6c 100755 --- a/make.sh +++ b/make.sh @@ -1,3 +1,5 @@ #!/bin/bash -#clear; clear; g++ -x c -fmax-errors=5 -pedantic -Wall -Wextra -o test test.c 2>&1 >/dev/null && ./test -clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -Wall -Wextra -o testSDL testSDL.c -lSDL2 2>&1 >/dev/null && ./testSDL + +PROGRAM=testTerminal + +clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM diff --git a/testSDL.c b/testSDL.c index a587559..e61ca36 100644 --- a/testSDL.c +++ b/testSDL.c @@ -10,7 +10,7 @@ //#define RAYCAST_TINY -#define RCL_USE_DIST_APPROX 2 +//#define RCL_USE_DIST_APPROX 2 // redefine some parameters #define FPS 40 @@ -924,7 +924,7 @@ void draw() c.maxHits = 32; c.maxSteps = 32; - RCL_render(camera,floorHeightAt,ceilingHeightAt,textureAt,c); + RCL_renderComplex(camera,floorHeightAt,ceilingHeightAt,textureAt,c); RCL_Unit previousDepth; diff --git a/testTerminal.c b/testTerminal.c index 885cda7..260bc23 100644 --- a/testTerminal.c +++ b/testTerminal.c @@ -1,3 +1,15 @@ +/* + Raycasting terminal test. + + author: Miloslav Ciz + license: CC0 +*/ + +#define RCL_PIXEL_FUNCTION pixelFunc +#define RCL_COMPUTE_WALL_TEXCOORDS 0 +#define RCL_COMPUTE_FLOOR_DEPTH 0 +#define RCL_COMPUTE_CEILING_DEPTH 0 + #include #include "raycastlib.h" #include @@ -10,7 +22,7 @@ #define SCREEN_H 40 char pixels[SCREEN_W * SCREEN_H]; -Camera camera; +RCL_Camera camera; const int8_t level[LEVEL_W * LEVEL_H] = { @@ -33,17 +45,17 @@ const int8_t level[LEVEL_W * LEVEL_H] = 0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0 // 14 }; -Unit heightAt(int16_t x, int16_t y) +RCL_Unit heightAt(int16_t x, int16_t y) { int32_t index = y * LEVEL_W + x; if (index < 0 || (index >= LEVEL_W * LEVEL_H)) - return UNITS_PER_SQUARE * 2; + return RCL_UNITS_PER_SQUARE * 2; - return level[y * LEVEL_W + x] * UNITS_PER_SQUARE * 2; + return level[y * LEVEL_W + x] * RCL_UNITS_PER_SQUARE * 2; } -void pixelFunc(PixelInfo *p) +void pixelFunc(RCL_PixelInfo *p) { char c = ' '; @@ -67,17 +79,15 @@ void draw() for (int i = 0; i < 10; ++i) printf("\n"); - RayConstraints c; + RCL_RayConstraints c; - initRayConstraints(&c); + RCL_initRayConstraints(&c); c.maxHits = 1; c.maxSteps = 40; - c.computeTextureCoords = 0; - - //renderSimple(camera,heightAt,0,pixelFunc,0,c); - render(camera,heightAt,0,0,pixelFunc,c); + //RCL_renderSimple(camera,heightAt,0,0,c); + RCL_renderComplex(camera,heightAt,0,0,c); for (int j = 0; j < SCREEN_H; ++j) { @@ -95,9 +105,9 @@ int frame = 0; int main() { - initCamera(&camera); - camera.position.x = 2 * UNITS_PER_SQUARE; - camera.position.y = 2 * UNITS_PER_SQUARE; + RCL_initCamera(&camera); + camera.position.x = 2 * RCL_UNITS_PER_SQUARE; + camera.position.y = 2 * RCL_UNITS_PER_SQUARE; camera.direction = 0; camera.resolution.x = SCREEN_W; camera.resolution.y = SCREEN_H; @@ -106,8 +116,8 @@ int main() { draw(); - int squareX = divRoundDown(camera.position.x,UNITS_PER_SQUARE); - int squareY = divRoundDown(camera.position.y,UNITS_PER_SQUARE); + int squareX = RCL_divRoundDown(camera.position.x,RCL_UNITS_PER_SQUARE); + int squareY = RCL_divRoundDown(camera.position.y,RCL_UNITS_PER_SQUARE); if (rand() % 100 == 0) { @@ -127,7 +137,7 @@ int main() camera.position.y += dy * 200; camera.direction += dr * 10; - camera.height = UNITS_PER_SQUARE + sinInt(frame * 16) / 2; + camera.height = RCL_UNITS_PER_SQUARE + RCL_sinInt(frame * 16) / 2; usleep(100000);