Cartesi Deterministic Game Engine
Project Description
The aim of the project is to bring one of the well established open source game engines to work with cartesi, which would help developers build next gen blockchain AAA games.
Problem
Current game engines are built to work in a traditional client server mode, which possess several challenges:
- Game engine dependencies and build targets are not optimally structured to create a build that works on Cartesi VM.
- Game engines are non-deterministic, where code running on different operating systems/different machines, wouldn’t produce identical results (figure 1), which would break the aim for creating deterministic results for a trustless web3 game running on cartesi machine (ex. we need to get the same results running the game on a client operating system using windows and running the same game on Cartesi VM).
Figure 1 - bullet float results between windows and linux comparison
Value proposition
Having a Cartesi compatible and deterministic game engine would aid in developing many AAA games and onboarding experienced game developers with minimum blockchain experience by providing game engine that they are used to in their web2 video games development.
How you will use Cartesi, specifically?
Demo using an Open source game engine would be provided, such that the demo would be working on Cartesi VM, as well as on other operating systems. Output from the demo running on Cartesi VM would be identical to the output from the client run.
Milestones
Milestone 1: R&D and POC (COMPLETED)
Target from R&D Phase:
- Determine pros and cons of using different game engines and determine the best engine to be used with Carteis.
- Determine the cause for non-deterministic outcomes and figure solutions that could be integrated with the game engine.
- Create a demo using a popular open source game engine that is open source, cross platform, and deterministic.
Duration: 4 months
Outcome:
Initially, unreal engine was heavily researched as it is open source and its code base is in c++. A sample game demo was developed using unreal engine and two builds of the game were executed on windows and linux. While unreal engine provides mode for making runs deterministic, it is only deterministic across builds targeted towards the same operating system. Runs on Linux and Windows failed to match which required extra investigation!
After extensive search and several code trials, it was found that the root cause for having non-deterministic results is floating-point arithmetic which game engines, specifically physics components, rely heavily on. A code sample, let’s name it AlphaTest, was developed to prove such discrepancy and a solution was searched to address this critical issue.
Two solutions had been found using fixed point arithmetic and softfloat. The code sample, AlphaTest, was first built using the GCC compiler option for using softfloat, though it failed to work (this option had limited support). Changing AlphaTest to work with fixed point arithmetic resolved the issue and produced deterministic results.
Next unreal engine code needed to be built on windows and linux machines as well as heavily investigated to determine the best approach for changing the code to use fixed point.
After successfully building unreal engine and editor on linux and windows, and going through the code base, it was deduced that it would be very challenging to continue with this approach due to the complexity of the code base, legacy code, dependency list and most importantly the demanding resources for building and running unreal engine and editor from the code base.
A search for alternatives started, which would still have a proven track record for creating AAA games and open source, with c++ code base, but lightweight.
Ogre was found to be the best option, coupled with Bullet physics engine. Tests started, and a demo was created running on both windows and linux, comparing results, which were non-deterministic. Source code was investigated and changes to bullet engine were made to use fixed point arithmetic. After 4 weeks, a version of bullet engine using fixed point was put to work, and a demo running on both linux and windows produced identical results. Major problem still existed where performance was a major bottleneck due to fixed point arithmetic. Softfloat had to be revisited again, and another approach was tried using a 3rd party softfloat library, and AlphaTest was visited again, this time using the softfloat library, and results on windows and linux were deterministic this time.
Bullet engine was adjusted to use softfloat instead of fixed point, producing close results to float numbers (figure 4), and performance was now suitable for usage (figure 2) and demo running on windows and linux is deterministic (figure 3.1 and 3.2).
This concludes milestone 1 with the creation of a deterministic POC demo that uses a popular open source game engine, ogre and bullet (figure 5), and providing code for the adjusted bullet physics engine and the demo.
Figure 2 - bullet softfloat demo
Figure 3.1 - bullet softfloat results between windows and linux comparison
Figure 3.2 - bullet softfloat results between windows and linux comparison
Figure 4 - Comparison between softfloat and float (close results)
Figure 5 - Ogre/bullet softfloat physics demo
Deliverables:
Softfloat implementation of bullet engine:
Demo using ogre and bullet:
References:
Ogre repo:
GitHub - OGRECave/ogre-next: aka ogre v2 - scene-oriented, flexible 3D C++ engine
Bullet Repo:
Softfloat library:
STandalone REproducible FLOating-Point library (brodu.net)
Milestone 2: Cartesi VM Integration
Demo created in M1 would be deployed to Cartesi VM. Complete source code and documentation would be available for the community to use and build upon.
Duration: 1 Month
Deliverables:
Complete source code for the demo deployed on Cartesi VM with documentation.
Total Funds request (USD) : $20,000 USD
About your Team
Karim, current blockchain enthusiast and evangelist, has over 20 years of experience in driving Innovation and Technology. Having attained his Master’s Degree in Technology from University of Advancing Technology, Arizona, USA, in 2006, Karim have strived to deliver cutting edge Technologies throughout his career, having worked for IBM for over 2 years, in addition to leading, inspiring and taking initiatives to deliver innovative technologies to a multitude of multinationals for over two decades. Previous work include developing a programming language and compiler for Blu-ray authoring system, sdk, advanced features and mini games for Blu-ray, developed for some of the biggest studios in the world.
Linkedin:
https://www.linkedin.com/in/ktimam/
ERC-20 Payee address
0xcb25fc71dc83a45b37dddf5e81d9a2494ef99cb1