The Wayback Machine - https://web.archive.org/web/20230325060705/https://github.com/ensisoft/detonator
Skip to content

ensisoft/detonator

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

DETONATOR 2D πŸ’₯πŸ’£

An OpenGL ES based 2D game engine and editor for Linux, Windows and HTML5. Designed for simple single player games such as puzzle games, platformers, side scrollers and tile based real time strategy and tactics. οΏ½?οΏ½πŸ§©πŸ—ΊοΏ½?

Screenshot

This readme and other readme files, are for developers and cover information related to developing and building the engine itself. For end user guide see help instead.

This project would not be possible without the following οΏ½?

  • Qt, GLM, Freetype, Harfbuzz, Lua, sol3, STB, nlohmann/json, mpg123, libsndfile, Box2D, Emscripten and many others!
  • Royalty free art from https://opengameart.com

Other (subsystem) readmes:

Currently, supported major features:

  • Qt5 based WYSIWYG editor
  • Text rendering (vector and bitmap)
  • Various primitive shapes, custom polygon shapes
  • Material system with built-in materials and with custom shaders
  • Particle system with projectile and linear motion
  • Entity system with animation tracks
  • Audio engine with approx. dozen audio elements
  • Lua based scripting for entities, scenes and UIs
  • Built-in Lua script editor with code formatting and API help
  • Scene builder
  • Styleable UI system (JSON style files and material system integration)
  • Physics engine based on Box2D
  • Demo content and starter content
  • Game content packaging for native and HTML5/WASM (with Emscripten)
  • Resource archives, export and import between projects (in zip)
  • Tilemap importer, several handy dialogs for materials, fonts, colors etc.
  • Several tools for texture packing, font map packing, etc.

Currently, not yet 100% complete major features:

  • Continued work on tilemaps
    • Lua APIs for data access etc.
    • Related algorithms such as path finding
    • Compression etc. performance improvements
    • Rendering performance improvements and fixes

Planned major features not yet implemented:

  • Partial 3D support for specific objects (think objects such as coins, diamonds, player ship etc.)
  • OpenGL ES3 backend and WebGL2 support
  • Android support (TBD)
  • Mobile web + touch screen support
  • Post-processing effects such as bloom, custom render passes
  • Vector fields, fluid sims, more elaborate particle effects
  • Plenty of asset baking features
  • Acceleration structures for game subsystems such as physics and rendering

Planned minor features not yet implemented:

  • See issues for more details

Screenshot Create animated game play characters in the entity editor. Each entity can contain an arbitrary render tree of nodes with various attachments for physics, rendering, text display etc. Animation tracks allow changing the properties of the nodes and transforming the tree itself over time. Each entity type can then be associated with a Lua script where you can write your entity specific game play code.

Screenshot Create materials using the material editor by setting some properties for the provided default material shaders. Currently, supports sprite animations, textures (including text and noise), gradient and color fills out of box. Custom shaders can be used too.

Screenshot Create the game play scenes using the scene editor. The entities you create in the entity editor are available here for placing in the scene. Viewport visualization will quickly show you how much of the game world will be seen when the game plays.

Screenshot Create the game's UI in the UI editor. The UI and the widgets can be styled using a JSON based style file and then individual widgets can have their style properties fine-tuned in the editor. The style system integrates with the editor's material system too!

Screenshot Create audio graphs using the audio editor. Each audio graph can have a number of elements added to it. The graph then specifies the flow of audio PCM data from source elements to processing elements to finally to the graph output. Currently, supported audio backends are Waveout on Windows, Pulseaudio on Linux and OpenAL on HTML5/WASM. Supported formats are wav, mp3, ogg and flac.

Screenshot Use the built-in code editor to write the Lua scripts for the entities, scenes, game or UI. The editor has a built-in help system for accessing the engine side Lua API documentation as well as automatic Lua code formatting and linting.

Screenshot The particle editor allows several types of particle effects to be created conveniently by adjusting several sliders and knobs that control the particle effect.

Screenshot During the development the game is available for play in the editor. It's possible to do live edits to the game content in the editor and see the changes take place in the play window.

Build Instructions πŸ‘¨οΏ½?οΏ½οΏ½?πŸ’»

Screenshot Screenshot Screenshot Screenshot

WASM (Emscripten)

Some notes about building to WASM.

  • Building to WASM is currently supported only for the engine but not the editor.
  • The build is separated from the main engine build and is in emscripten/ folder.
    • See emscripten/CMakeLists.txt for build details.
  • Current Emscripten version is 3.0.0. Using other version will likely break things.
  • If using Windows Install Ninja from https://github.com/ninja-build/ninja/releases.
    • Drop the ninja.exe for example into the emsdk/ folder or anywhere on your PATH.
How to build on Linux
  • Install Emscripten
  $ cd detonator
  $ git clone https://github.com/emscripten-core/emsdk.git
  $ cd emsdk
  $ git pull
  $ ./emsdk install latest
  $ ./emsdk activate 3.0.0
  $ source ./emsdk_env.sh
  • Check your Emscripten installation
  $ which emcc
  $ /home/user/emsdk/upstream/emscripten/emcc
  $ emcc --version
  $ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.0 (3fd52e107187b8a169bb04a02b9f982c8a075205)
  • Build the DETONATOR 2D engine into a WASM blob. Make sure that you have the emscripten tools in your path, i.e. you have sourced emsdk_env.sh in your current shell.
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ cd emscripten
  $ mkdir build
  $ cd build
  $ emcmake cmake .. -DCMAKE_BUILD_TYPE=Release
  $ make -j16 install
How to build on Windows
  • Install Emscripten
  $ cd detonator
  $ git clone https://github.com/emscripten-core/emsdk.git
  $ cd emsdk
  $ git pull
  $ emsdk.bat install latest
  $ emsdk.bat activate 3.0.0
  $ emsdk_env.bat
  • Check your Emscripten and Ninja installation
  $ where emcc
  $ C:\coding\detonator\emsdk\upstream\emscripten\emcc
  $ C:\coding\detonator\emsdk\upstream\emscripten\emcc.bat
  $ emcc --version
  $ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.0 (3fd52e107187b8a169bb04a02b9f982c8a075205)
  $ where ninja
  $ C:\coding\detonator\emsdk\ninja.exe
  $ ninja --version
  $ 1.10.2
  • Build the DETONATOR 2D engine into a WASM blob. Make sure you have emcc and ninja in your path i.e. you have ran emsdk_env.bat in your current shell.
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ cd emscripten
  $ mkdir build
  $ cd build
  $ emcmake cmake .. -DCMAKE_BUILD_TYPE=Release
  $ ninja -j16
  $ ninja -j16 install

If everything went well there should now be GameEngine.js and GameEngine.wasm files in the editor's dist folder. The .js file contains the JavaScript glue code needed to manhandle the WASM code into the browser's WASM engine when the web page loads. When a game is packaged for web these files will then be deployed (copied) into the game's output directory.

Desktop Linux

How to install dependencies

See your distro manuals for how to install the packages.

Install these packages:

  • GCC (or Clang) compiler suite
  • CMake build tool
  • Boost C++ libraries
  • Conan package manager
  • Git version control system
  • Qt5 application framework
How to build the project in RELEASE
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ mkdir build
  $ cd build
  $ conan install .. --build missing
  $ cmake -G "Unix Makefiles" .. -DCMAKE_BUILD_TYPE=Release
  $ make -j16 install
  $ ctest -j16
How to build the project in DEBUG
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ mkdir build_d
  $ cd build_d
  $ conan install .. --build missing
  $ cmake -G "Unix Makefiles" .. -DCMAKE_BUILD_TYPE=Debug
  $ make -j16 install
  $ ctest -j16
How to build the project in PROFILE
  • Build the project for profiling using valgrind / kcachegrind
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ mkdir build_profile
  $ cd build_profile
  $ conan install .. --build missing 
  $ cmake -G "Unix Makefiles" .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
  $ make -j16 install
  • Then in order to profile and analyze the output use the combination of valgrind and kcachegrind. For example:
  $ cd detonator/audio/test/
  $ valgrind --tool=cachegrind ./audio_test --graph
  $ kcaghegrind cachegrind.out.XXXXX
How to build with Ninja, Clang and Mold linker (OPTIONAL)
  • These are alternative instructions for build using Ninja, Clang and Mold linker.
  $ export CC=/usr/bin/clang
  $ export CXX=/usr/bin/clang++
  $ conan profile new detonator-clang --detect
  
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ mkdir build
  $ cd build
  $ conan install .. --build missing --profile detonator-clang
  $ cmake -G "Ninja" .. -DCMAKE_BUILD_TYPE=Release -DUSE_MOLD_LINKER=ON 
  $ ninja -j16 install
How to build Qt5 designer plugin (OPTIONAL)
  $ cd detonator/editor/gui/qt
  $ mkdir build
  $ cmake -G "Unix Makefiles" .. -DCMAKE_BUILD_TYPE=Release
  $ make -j16 
  $ sudo make install
Build troubleshooting

When you create a Conan profile with

$ conan profile new default --detect

If Conan bitches about "ERROR: invalid setting" (for example when GCC major version changes) you can try edit ~/.conan/settings.yaml. Search for the GCC versions and edit there.

Desktop Windows

These build instructions are for MSVS 2019 Community Edition and for 64bit build.

How to install dependencies
How to build the project in RELEASE
  • Open "Developer Command Prompt for VS 2019"
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ mkdir build
  $ cd build
  $ conan install .. --build missing
  $ cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release ..
  $ cmake --build   . --config Release
  $ cmake --install . --config Release
How to build the project in DEBUG

Note that on MSVS the library interfaces change between debug/release build configs. (e.g. iterator debug levels). This means that in order to link to 3rd party libraries the debug versions of those libraries must be used.

  • Open "Developer Command Prompt for VS 2019"
  $ git clone https://github.com/ensisoft/detonator
  $ cd detonator
  $ git submodule update --init --recursive
  $ mkdir build_d
  $ cd build_d
  $ conan install .. --build missing -s build_type=Debug
  $ cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Debug ..
  $ cmake --build   . --config Debug
  $ cmake --install . --config Debug
How to build Qt5 designer plugin (OPTIONAL)
  $ cd editor\gui\qt
  $ mkdir build
  $ cmake -G "Visual Studio 16 2019" -DCMAKE-BUILD_TYPE=Release
  $ cmake --build . --config Release
  $ cmake --install . --config Release

The Boring Documentation πŸ₯±

Workflow and getting started πŸ“”

Going from a git clone to a running game is known as the "build workflow". This involves various steps involving the source tree of the engine, the source tree of the game, the runtime assets provided with the engine and the runtime assets that are part of the game. Overall this will involve several build and packaging steps.

Currently, only Lua based games are supported. There's a provided game engine that is built into a shared library and which contains all the relevant functionality for running a game. That is it will take care of rendering the scene, ticking the physics engine, handling the UI input as well as invoking the Lua scripts in order to run your game code. It's possible to also not use this provided engine but write a completely different engine. In this case the interface to implement is the "Engine" interface in engine/main/interface.h.

From source code to a running game:

  1. Build the whole project as outlined in the Build Instructions previously. You will also need to install the build targets. Installing not only copies the binaries into the right place but also copies other assets such as GLSL shader files. Without the installation step things will not work correctly!
  2. After building launch the Editor from the editor/dist folder.
  3. In the Editor: Open your game's workspace folder. This is the folder that contains the workspace.json and content.json files. In DETONATOR 2D this is essentially your "project" (It's simply a folder with those two specific files in it).
  4. In the Editor: Package your content. (Workspace|Package). Select the assets you want to package (most likely everything). When the packaging process is complete your selected output directory will contain the following:
    1. The game resources copied over, i.e. shaders, textures, font files etc.
    2. A content.json file that contains the resource descriptions for your assets that you've built in the editor
    3. A config.json file that contains the settings for the GameMain to launch the game
    4. A native "GameMain" executable and engine library. These are the default game studio binaries for running your game content after the project has been packaged.
    5. FILESYSTEM, FILESYSTEM.js, game.html GameEngine.wasm, GameEngine.js. These are the HTML5/WASM files that are needed to run the game in the browser.
  5. After packaging launch your game by running the GameMain executable in the package output directory.

Running (Unit) Tests 🫣

There's a bunch of unit tests that are built as part of the normal build process. Basically anything that begins with a "unit_test_" is a unit test.
For writing tests there's a very simple testing utility that is available in base. base/test_minimal.h

In addition to having the unit tests both the audio and graphics subsystems also have "rendering" tests, i.e. playing audio or rendering stuff on the screen. The rendering tests rely on a set of gold images a.k.a. known good images. Currently, the images are provided as part of this repository but there's the problem that because of differences in OpenGL implementations it's possible that the rendering output is not exactly the same between various vendors/implementations (such as NVIDIA, AMD, Intel etc. Fixing this is a todo for later). The audio tests, however, don't have any automated way of verifying the test output.

See this list for known Issues

On the desktop (Linux/Windows)

How to run all tests

Currently, the expectation is that all cases should pass on Linux. On Windows some tests are unfortunately broken.

  • In order to run tests after a successful build:
  $ cd detonator/build
  $ ctest -j16
How to run audio tests
  • Runs, mp3, ogg, flag and 24bit .wav tests. Use --help for more information.
  $ cd detonator/audio/test
  $ ./audio_test --mp3 --ogg --flac --24bit
  $ ...
  $ ./audio_test --help
How to run graphics tests

Any test rendering that differs from the expected gold image will stop the program for user input (press any key to continue) and will generate a Delta_ and Result_ images. The former will help visualize the pixels that were not the same between result and gold and the result will be actual rendering result.

  • Run all tests with MSAA4. Use --help for more information
  $ cd detonator/graphics/test/dist
  $ ./graphics_test --test --msaa4
  $ ...
  $ ./graphics_test --help 

On the Web (WASM+HTML5)

Currently, only some unit tests are available on the web. More tests will be enabled as needed.

How to run unit tests

The detonator/emscripten/bin folder should contain the following build artifacts:

  • unit-test.html
  • UnitTest.js
  • UnitTest.wasm

Launch a web server for serving the test HTML page.

  $ cd detonator/emscripten/bin
  $ python -m http.server

Open your web browser and navigate to http://localhost:8000/unit-test.html.

System Architecture

See this document

Coding Convention & Design πŸ’­

See this document

Tracing & Profiling πŸ’­

See this document