1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-22 20:39:57 +01:00
This commit is contained in:
Miloslav Číž 2020-06-21 12:02:37 +02:00
parent 74af704656
commit 0005f40264
5 changed files with 40 additions and 29 deletions

View file

@ -48,18 +48,19 @@ features
- **Pure C99**, tested to run as C++ as well. - **Pure C99**, tested to run as C++ as well.
- Optional framework **functions that handle the whole rendering**. - Optional framework **functions that handle the whole rendering**.
- Still **flexible** -- pixels are left for you to draw in any way you want. - Still **flexible** -- pixels are left for you to draw in any way you want.
- **Tested on multiple platforms**: - **Tested on many platforms**:
- PC (little endian, 64bit GNU) - PC (little endian, 64bit GNU)
- compilers: gcc, clang
- Emscripten (web browser, JavaScript transpile) - Emscripten (web browser, JavaScript transpile)
- Arduboy - Arduboy (only experimental)
- Pokitto - Pokitto (32bit resource-limited embedded ARM)
- Gamebuino META - Gamebuino META (32bit resource-limited embedded ARM)
- TODO: - TODO:
- PowerPC emulator (big endian) - PowerPC emulator (big endian)
- Android - Android
- Windows - Windows
- **Many compile-time options** to tune the performance vs quality. - **Many compile-time options** to tune the performance vs quality.
- **Well commented** and formatted code. Automatic documentation (comments + provided Doxyfile). - **Well commented** and formatted code, with examples. Automatic documentation (comments + provided Doxyfile).
- Completely **free of legal restrictions**, do literally anything you want. - Completely **free of legal restrictions**, do literally anything you want.
**NOTE**: Backwards compatibility isn't a goal of this libraray. It is meant to **NOTE**: Backwards compatibility isn't a goal of this libraray. It is meant to
@ -72,17 +73,14 @@ how to use
**Don't forget to compile with -O3!** This drastically improves performance. **Don't forget to compile with -O3!** This drastically improves performance.
For start take a look at the [testTerminal.c](https://gitlab.com/drummyfish/raycastlib/blob/master/programs/testTerminal.c) program. For start take a look at the [helloWorld.c](https://gitlab.com/drummyfish/raycastlib/blob/master/programs/helloWorld.c) program and other examples.
It is only a little bit more complex than a simple hello world. For more examples see my [Pokitto demos](https://gitlab.com/drummyfish/Pokitto-Raycasting) repository.
For more examples see the other files, plus my [Pokitto demos](https://gitlab.com/drummyfish/Pokitto-Raycasting) repository,
which contains some better documented example code, including a [very simple hello world](https://gitlab.com/drummyfish/Pokitto-Raycasting/blob/master/helloRay.cpp).
Also see **the library code itself**, it is meant to be self-documenting -- you'll find the description of a lot of things at the start of the file. Also see **the library code itself**, it is meant to be self-documenting -- you'll find the description of a lot of things at the start of the file.
The basic philosophy is: The basic philosophy is:
- The library implements only a rendering back-end, it doesn't perform any drawing to the actual screen, - The library implements only a **rendering back-end**, it doesn't perform any drawing to the actual screen,
hence there is no dependency on any library such as OpenGL or SDL. It just calls your front-end function hence there is no dependency on any library such as OpenGL or SDL. It just calls your front-end function
and tells you which pixels you should write. How you do it is up to you. and tells you which pixels you should write. How you do it is up to you.
- Before including the header, define `RCL_PIXEL_FUNCTION` to the name of a function you will use to - Before including the header, define `RCL_PIXEL_FUNCTION` to the name of a function you will use to
@ -101,15 +99,6 @@ The basic philosophy is:
has a side length of `RCL_UNITS_PER_SQUARE` units. Numbers are normalized by this constant, so e.g. has a side length of `RCL_UNITS_PER_SQUARE` units. Numbers are normalized by this constant, so e.g.
the sin function returns a value from `-RCL_UNITS_PER_SQUARE` to `RCL_UNITS_PER_SQUARE`. the sin function returns a value from `-RCL_UNITS_PER_SQUARE` to `RCL_UNITS_PER_SQUARE`.
TODO
----
- Transparency (conditional ray passing through).
- Doors in the middle of squares.
- Rolling doors for `RCL_renderComplex`.
- Possibly merge all rendering functions into one.
- Fix rendering bug that happens at the boundary of positive and negative square coords.
license license
------- -------

View file

@ -1,8 +1,27 @@
#!/bin/bash #!/bin/bash
# Make script for raycastlib programs.
# by drummyfish
# released under CC0 1.0, public domain
if [ "$#" -ne 1 ]; then if [ "$#" -ne 1 ]; then
echo "ERROR: expecting one argument, the name of program without extension (e.g. \"helloWorld\")" echo "ERROR: expecting one argument, the name of program without extension (e.g. \"helloWorld\")"
exit 0 exit 0
fi fi
clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -Wall -Wextra -o $1 $1.c -lSDL2 2>&1 >/dev/null && ./$1 link=""
if [ "$1" = "testSDL" ]; then
link="-lSDL2"
fi
clear
clear
flags="-x c -g -O3 -pedantic -Wall -Wextra -o $1 $1.c ${link}"
compiler=gcc
#compiler=clang
echo "making:" ${compiler} ${flags}
${compiler} ${flags} > /dev/null 2>&1 && ./$1

View file

@ -1,5 +1,6 @@
/** /**
Tests for raycastlib. General tests for raycastlib, use to test new version, different platforms
etc.
license: CC0 license: CC0
*/ */
@ -477,7 +478,7 @@ int main()
RCL_Unit scaled = RCL_perspectiveScaleHorizontal(size,distance); RCL_Unit scaled = RCL_perspectiveScaleHorizontal(size,distance);
RCL_Unit distance2 = RCL_perspectiveScaleHorizontalInverse(size,scaled); RCL_Unit distance2 = RCL_perspectiveScaleHorizontalInverse(size,scaled);
if (RCL_absVal(distance - distance2 > 2)) if (RCL_abs(distance - distance2 > 2))
printf("ERROR: distance: %d, distance inverse: %d\n",distance,distance2); printf("ERROR: distance: %d, distance inverse: %d\n",distance,distance2);
} }
@ -552,9 +553,6 @@ int main()
t = measureTime(benchmarkRender); t = measureTime(benchmarkRender);
printf("render 100 times: %ld ms\n",t); printf("render 100 times: %ld ms\n",t);
printf("\n");
printProfile();
printf("\n===== all OK =====\n"); printf("\n===== all OK =====\n");
return 0; return 0;

View file

@ -1,5 +1,6 @@
/* /*
Raycasting terminal test. Raycasting terminal test. Renders a raycasted animation in the terminal as
ASCII.
author: Miloslav Ciz author: Miloslav Ciz
license: CC0 1.0, public domain license: CC0 1.0, public domain
@ -79,8 +80,7 @@ void pixelFunc(RCL_PixelInfo *p)
switch (p->hit.direction) switch (p->hit.direction)
{ {
case 0: shade += 2; case 0: shade += 2;
case 1: shade += p->texCoords.y / 512; case 1: c = asciiShades[shade];
c = asciiShades[shade];
break; break;
case 2: c = 'o'; break; case 2: c = 'o'; break;
case 3: case 3:

5
todo.txt Normal file
View file

@ -0,0 +1,5 @@
- Transparency (conditional ray passing through).
- Doors in the middle of squares.
- Rolling doors for `RCL_renderComplex`. Or perhaps remove rolling doors (KISS)
- Possibly merge all rendering functions into one.
- Fix rendering bug that happens at the boundary of positive and negative square coords.