Multiplatform lightweight 2D game-engine, retro-game inspired. Uses OpenGL through GLFW3. Scripted in Lua. Aiming zero run-time dependencies.
MIT License
Welcome to Tofu Engine
!
Make yourself comfortable, and join for a ride through a mixture of old-fashioned and modern game development! :)
For the courious ones, these are the current statistics of the game-engine codebase:
Language | Files | Blank | Comment | Code |
---|---|---|---|---|
C | 80 | 3348 | 2496 | 16777 |
C/C++ Header | 88 | 698 | 2408 | 2144 |
Lua | 22 | 296 | 497 | 1708 |
GLSL | 12 | 118 | 282 | 422 |
202 | 4460 | 5683 | 21051 |
repeat
, add
, sub
, multiply
, min
, max
).Although I have been known to take pleasure in reinventing the wheel at every possible opportunity, Tofu Engine leverages some awesome libraries:
20240213
Tofu Engine is an original software, result of the experience gained from ~30 years in programming on a broad range of platforms (some concept even stems back to ancient platforms like the Amiga and the SNES, and arcane languages like AMOS and Blitz BASIC 2). However, it has also been influenced by modern similar/other software in one way or another. Here's a brief list.
The lovely game-engine logo has been designed by Blort.
In order to compile Tofu Engine
, a Linux machine in required (either physical or virtual). A Debian-based distribution is suggested, although I've been using Ubuntu during the development. One can use the following commands to install all the required dependencies:
sudo apt install build-essential
sudo apt install mingw-w64
sudo apt install xorg-dev libx11-dev libwayland-dev libxkbcommon-dev wayland-protocols mesa-common-dev libgles2-mesa-dev
sudo apt install lua5.4 liblua5.4-dev luarocks
sudo luarocks --lua-version=5.4 install argparse
sudo luarocks --lua-version=5.4 install luafilesystem
sudo luarocks --lua-version=5.4 install luacheck
sudo luarocks --lua-version=5.4 install luazen
Please note that MinGW is required only to obtain the Windows build through cross-compilation. One can simply use MinGW on Windows to build the engine binary as it is.
Of course, git
should also be installed to clone the repository.
sudo apt install git
Proceed in creating a local clone of the repository with the command
git clone https://github.com/tofuengine/tofu.git
into a suitable work directory. Move into the tofu
directory you've just created and use make
to build the executable. You can use the following command-line parameters to control the build process:
BUILD
, can be either debug
or release
with the usual meaning. If not specified, the build is assumed in debug mode.PLATFORM
, can be either linux
or windows
. If not specified, the build is assumed for Linux platform.WINDOWING
, can be x11
, wayland
, gdi
, or mesa
. If not specified, the build assumes gd1
for the Windows platform, x11
otherwise for the Linux one. Please note that mesa
is not really supported and wayland
is experimental (but should work).ARCHITECTURE
, can be x64
, x32
, arm64
or armhf
. If not specified the current host architecture is used as target.The build artifacts will be placed in the build
directory.
Alternatively, if you prefer not to tamper with your system, you can use a Docker container for the build process. For that purpose, a ready-to-use Dockerfile can be found in the
extras/docker
directory. Use themake docker-create
command to build the container andmake docker-launch
to start it in the current folder.
A note about cross-builds of the game-engine. The project has been designed with Linux as a development machine, with the distinct platform-dependent build archived through cross-compilation. As said, the Windows build is obtained thanks to MinGW, which includes all the required dependencies (i.e. development libraries). To obtain the ARM builds through cross-compilation, as well, Multiarch is to be used. The steps to add support are the following.
First and foremost the arm64
(for 64-bit ARM) and armhf
(for 32-bit ARM) architectures need to be added
sudo dpkg --add-architecture arm64
sudo dpkg --add-architecture armhf
Then, the apt
sources for this architecture need to be configured, by creating a new file /etc/apt/sources.list.d/arm64-sources.list
with this content (which mirrors the sources.list
file, minus the security sources which are not required):
echo "deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs) main restricted" | sudo tee /etc/apt/sources.list.d/arm64-sources.list > /dev/null
echo "deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-updates main restricted" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list >> /dev/null
echo "deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs) universe" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list >> /dev/null
echo "deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-updates universe" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list >> /dev/null
echo "deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs) multiverse" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list >> /dev/null
echo "deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-updates multiverse" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list >> /dev/null
echo "deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list >> /dev/null
At the same time, the current content /etc/apt/sources.list
file need to be patched so that it refers to the actual host architecture. If it isn't already configured as such you can use the following command to patch the file:
sudo sed -i "s/deb http/deb [arch=$(dpkg --print-architecture)] http/" /etc/apt/sources.list
Remember to issue a sudo apt update
command to refresh the APT database and, finally, install GCC's backends and the library dependencies we need:
sudo apt install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
sudo apt install gcc-arm-linux-gnueabihf binutils-arm-linux-gnueabihf
sudo apt install --no-install-recommends libx11-dev:arm64 libx11-dev:armhf
which will also install any required package.
Along with the game engine source, there are a bunch of (basic) demo projects. They are located in the demos
sub-directory and can be launched using make
, passing the name of the project as a target (e.g. make splash
).
If Tofu Engine appeals you and
please don't hold you back and contribute! :)
Follows a brief (and incomplete) list of additional features somewhen in the future I'd like to implement.
make bunnymark BUILD=profile
gprof ./tofu gmon.out > analysys.txt
gprof ./tofu gmon.out | ./extras/gprof2dot.py | dot -Tpng -o analysys.png