1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-21 20:29:59 +01:00
raycastlib/README.md

120 lines
6.3 KiB
Markdown
Raw Normal View History

2018-09-21 20:00:08 +02:00
# raycastlib
2019-07-01 18:42:00 +02:00
Public domain ray casting library for (not only) resource-limited computers.
2018-09-21 20:00:08 +02:00
2019-07-13 19:39:43 +02:00
If you like this, you may also like my similar project: [small3dlib](https://gitlab.com/drummyfish/small3dlib). These two libraries can very easily be combined together -- here is a proof-of-concept gif (environment rendered with raycastlib, cubes with small3dlib):
2020-11-22 17:12:11 +01:00
I've made a complete game with this library: [Anarch](https://gitlab.com/drummyfish/sucklessfps).
2020-06-21 17:40:17 +02:00
2019-07-13 19:39:43 +02:00
![](https://gitlab.com/drummyfish/small3dlib/raw/master/media/rcl_plus_s3l.gif)
2019-06-22 00:04:54 +02:00
2018-09-29 20:30:07 +02:00
eye-candy previews
------------------
2018-09-21 20:00:08 +02:00
2019-06-24 18:20:16 +02:00
Pokitto (32bit embedded console, 48 MHz, 36 kB RAM):
2018-09-21 20:00:08 +02:00
2021-06-18 09:26:07 +02:00
![](media/pokitto1.gif)
![](media/pokitto2.gif)
![](media/pokitto3.gif)
2018-09-21 20:00:08 +02:00
2019-06-24 18:20:16 +02:00
SDL (PC):
2018-09-21 20:00:08 +02:00
2021-06-18 09:26:07 +02:00
![](media/sdl.gif)
2018-09-21 20:00:08 +02:00
2019-06-24 18:20:16 +02:00
Arduboy (8bit Arduino console, 16 MHz, 2.5 kB RAM):
2018-09-21 20:00:08 +02:00
2021-06-18 09:26:07 +02:00
![](media/arduboy.gif)
![](media/arduboy2.gif)
2018-09-21 20:00:08 +02:00
terminal:
2021-06-18 09:26:07 +02:00
![](media/terminal.gif)
2018-09-21 20:00:08 +02:00
2019-06-24 18:20:16 +02:00
Gamebuino META (Arduino 32bit console, 48 MHz, 32 kB RAM):
2018-10-23 08:28:36 +02:00
2021-06-18 09:26:07 +02:00
![](media/gamebuino.gif)
2018-10-23 08:28:36 +02:00
2018-09-29 20:30:07 +02:00
features
--------
2019-06-25 17:08:18 +02:00
- Very **fast, small and efficient**.
- Uses **only integer math** (32bit). The tiny version should only require 16bit, but isn't completed.
- **No dependencies** (uses only stdint standard library), extremely portable.
2019-08-26 13:55:43 +02:00
- **Single header**, KISS, suckless.
2022-02-23 14:47:46 +01:00
- **No dynamic heap allocation**.
2019-06-25 17:08:18 +02:00
- Advanced rendering of **variable height floor and ceiling**.
- **Textured walls and floor**.
- **Depth information** (e.g. for fog or z-buffer rendering).
- **Camera shearing** (looking up/down).
- Camera movement with **collisions**.
- Partial support for **opening door**.
- **Pure C99**, tested to run as C++ as well.
- Optional framework **functions that handle the whole rendering**.
- Still **flexible** -- pixels are left for you to draw in any way you want.
2020-06-21 12:02:37 +02:00
- **Tested on many platforms**:
2020-06-21 11:39:52 +02:00
- PC (little endian, 64bit GNU)
2020-06-21 12:17:43 +02:00
- PowerPC emulator (big endian)
- compilers: gcc, clang, emscripten (web browser, JavaScript transpile)
2020-06-21 12:02:37 +02:00
- Arduboy (only experimental)
- Pokitto (32bit resource-limited embedded ARM)
- Gamebuino META (32bit resource-limited embedded ARM)
2020-06-21 12:18:45 +02:00
- TODO:
2020-06-21 11:39:52 +02:00
- Android
- Windows
2019-06-25 17:08:18 +02:00
- **Many compile-time options** to tune the performance vs quality.
2020-06-21 12:02:37 +02:00
- **Well commented** and formatted code, with examples. Automatic documentation (comments + provided Doxyfile).
2019-06-25 17:08:18 +02:00
- Completely **free of legal restrictions**, do literally anything you want.
2018-09-29 20:30:07 +02:00
2018-09-30 12:23:07 +02:00
**NOTE**: Backwards compatibility isn't a goal of this libraray. It is meant to
be an as-is set of tools that the users is welcome to adjust for their
specific project. So new features will be preferred to keeping the same
interface.
2018-12-21 08:28:06 +01:00
how to use
----------
2019-06-25 17:22:42 +02:00
**Don't forget to compile with -O3!** This drastically improves performance.
2020-06-21 19:28:22 +02:00
For start take a look at the [helloWorld.c](programs/helloWorld.c) program and other examples.
2020-06-21 12:02:37 +02:00
For more examples see my [Pokitto demos](https://gitlab.com/drummyfish/Pokitto-Raycasting) repository.
2018-12-21 08:28:06 +01:00
2019-06-26 21:11:21 +02:00
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.
2018-12-21 08:28:06 +01:00
The basic philosophy is:
2020-06-21 12:02:37 +02:00
- The library implements only a **rendering back-end**, it doesn't perform any drawing to the actual screen,
2019-06-02 01:37:50 +02:00
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.
2018-12-21 08:28:06 +01:00
- Before including the header, define `RCL_PIXEL_FUNCTION` to the name of a function you will use to
draw pixels. It is basically a fragment/pixel shader function that the library will call. You will
be passed info about the pixel and can decide what to do with it, so you can process it, discard it,
or simply write it to the screen.
- Call `RCL_renderSimple` or `RCL_renderComplex` to perform the frame rendering. This will cause the
2019-06-02 01:37:50 +02:00
library to start calling the `RCL_PIXEL_FUNCTION` in order to draw the frame. You can optionally write
a similar function of your own using the more low-level functions which are also provided.
2018-12-21 08:28:06 +01:00
- The library gets info about the world (such as floor or ceiling height) via *array* functions
(`RCL_ArrayFunction` type) -- functions that take *x* and *y* coordinates of a square and return given
2019-06-02 01:37:50 +02:00
information. This way you are free to not only fetch the map data from an array, but also generate
the world procedurally if that is what you want.
2018-12-21 08:28:06 +01:00
- Fixed point arithmetics is used as a principle, but there is no abstraction above it, everything is simply
an integer (`RCL_Unit` type). The space is considered to be a dense grid, where each world square
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`.
2018-09-21 20:00:08 +02:00
license
-------
2019-07-04 00:39:15 +02:00
Everything is CC0 1.0 (public domain, https://creativecommons.org/publicdomain/zero/1.0/) + a waiver of all other IP rights (including patents).
2020-06-21 12:20:37 +02:00
I've written all code completely myself from scratch, the art used in demos is either my own released under CC0 or someone else's released under CC0.
2019-06-25 16:52:54 +02:00
2020-06-21 12:20:37 +02:00
This is not a mandatory condition, but please consider supporting free software and free culture by using free licenses and/or waivers.
2019-06-25 16:52:54 +02:00
2019-06-26 21:42:50 +02:00
If you'd like to support me or just read something about me and my projects, visit my site: [www.tastyfish.cz](http://www.tastyfish.cz/).
2022-09-20 17:07:25 +02:00
You can also choose to use this under the following waiver which is here to just ensure more legal safety and waiving of additional IP such as patents:
The intent of this waiver is to ensure that this work will never be encumbered by any exclusive intellectual property rights and will always be in the public domain world-wide, i.e. not putting any restrictions on its use.
Each contributor to this work agrees that they waive any exclusive rights, including but not limited to copyright, patents, trademark, trade dress, industrial design, plant varieties and trade secrets, to any and all ideas, concepts, processes, discoveries, improvements and inventions conceived, discovered, made, designed, researched or developed by the contributor either solely or jointly with others, which relate to this work or result from this work. Should any waiver of such right be judged legally invalid or ineffective under applicable law, the contributor hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to this right.