cft
Become a CreatorSign inGet Started

Creating Game Engine

I have created the Tyracorn engine in Java pretty much from scratch, only using a small number of basic libraries. If you are considering doing the same then continue reading.


user

Radek Hecl

4 months ago | 6 min read
Follow

What do you really need to do when you decide to create a game engine.

I have created the Tyracorn engine in Java pretty much from scratch, only using a small number of basic libraries. If you are considering doing the same then continue reading.

Expectations

If your goal is to publish the games quickly, then just use Unity, Unreal Engine, or another great product available. However, if you have different expectations, and time for that, then go ahead. Here are mine.

  • Learn and relax.
  • Ok to spend significant time studying and pivoting without visible progress.
  • Code is done according to the Robust Java Standards book, including many unit tests.
  • The goal is to produce decent-looking 3D games. No need to compete with AAA titles.
  • Targetting PC and Android.

Even with these, it took me more than a year to produce a reasonably complete engine (did plenty of other stuff as well, otherwise could be like 4 months).

Development Diary

Project Set-Up

I have chosen Java with Maven to be the basics. Literally started with two projects tyracorn-core and tyracorn-desktop having the following idea for the future.

  • tyracorn-code - this is the library that contains all the platform-independent code. For example, driver interfaces, data structures, rigid body engines, and other platform-independent things.
  • tyracorn-desktop - this is also the library, that has tyracorn-core as a transitive dependency. Implements the tyracorn-core interfaces for desktop.
  • Game development - add tyracorn-desktop as a dependency and write code following Tyracorn engine standards.
  • Production compilation - production compilation (e.g. for Desktop, Android) is done by a separate tool (more on that later).

Graphics 

Graphics with simple controls. Very enjoyable since progress is fast and visual. I have chosen to use OpenGL via JOGL binding library. And here are good resources to start with.

The very nice thing about the JOGL library is that it is fully available in the Maven Central repository, and works well for desktops. Just use the following dependencies.

XML1

<dependency>

2

<groupId>org.jogamp.gluegen</groupId>

3

<artifactId>gluegen-rt-main</artifactId>

4

<version>2.3.1</version>

5

</dependency>

6

<dependency>

7

<groupId>org.jogamp.jogl</groupId>

8

<artifactId>jogl-all-main</artifactId>

9

<version>2.3.1</version>

10

</dependency>

11

ā€‹

I have focused only on the desktop. Created interfaces in tyracorn-core, and implemented them in tyracorn-desktop. Also made plenty of unit tests and small POC applications, which I am maintaining even now. The result...

Android POC

Write once, run anywhere. I heard this before... And yes, I wanted to write the app on a desktop (with reasonable preconditions in mind) and be able to run it on Android phones. So I dug into an official Android OpenGL ES documentation.

Turned out, that the documentation is pretty good. So I created a project in Android Studio, included tyracorn-core as a dependency, and copied the code of sample applications over so that I can run them on my phone.

Then find out that there are slight differences in the flavors OpenGL, Java, and for example how resources are handled in those systems. So took a bit of abstraction and shuffling to be able to run the same code on both systems. Then the result is like this.

Now the POC was working. The very inconvenience was that I had to keep copying files across two projects. Life is tough );

Showpark

Remember the planned project setup? Each project is developed on a desktop by including tyracorn-desktop dependency. This allows super easy development and debugging just from IDE.

Based on this, I have started the tyracorn-showpark project and ported several test applications there.

Also implemented screen transitions so that originally independent applications are bundled into a single one and it's possible to switch them in runtime. The current version is available in the play store.

UI

This relates to the previous point. Things like screen transition, loading screens, buttons, on-screen joysticks, and so on. They are relatively small, pieces, but you won't be able to create much without them.

Toolchain

Enough of file copying like I did during Android POC. Added tyracorn-toolchain project to the suite. In summary, this project allows me to compile desktop projects into various platforms by just running a single command.

It can also deploy the dev version to the phone, or build the signed apk that can be uploaded to the play store right away. More details about how it works are in the Personal Mini Toolchains article.

Text Rendering

Find out that it's difficult to create without being able to render at least a basic text.

The greenhorn way for this is to create a tilemap from fonts (use a program like BMFont) and then render the characters as simple sprites. Although there are some problems with scaling, I took it as enough for now.

World of Actors

All top engines have a structure where there is a World managing Actor tree. And each Actor is a container for components like models, colliders, or scripts. So I wanted to define my objects like this.

Java1

Actor sphere = Actor.create(RandomStringUtils.randomAlphabetic(32)).

2

addComponent(TransformComponent.create().

3

move(Vec3.create(0, 8, 0))).

4

addComponent(ModelComponent.create().

5

setModelId(sphereModelId).

6

setTransform(Mat44.scale(1))).

7

addComponent(RigidBodyComponent.create().

8

setKinematic(false).

9

setMass(1).

10

setInertia(Inertias.sphere(1, 1)).

11

setVelocity(getRandomVelocity())).

12

addComponent(ColliderComponent.create().

13

setLayer(CollisionLayer.OBJECT).

14

setType(ColliderComponent.Type.SPHERE).

15

setRadius(1).

16

setMaterialId(objectColMatId));

17

world.actors().add(ActorId.ROOT, sphere);

18

ā€‹

Took some time to make that transition, but find this pretty powerful. It's widely used and here is a nice article about it.

Physics

Yeah, that's just a must. And it's fun to play with. I liked the articles written by Allen Chou. I have made it up to this point.

Resource Management

Loading time on mobile is an issue. At first, I just made it in a way that things work. Haven't worried about the amount of data fetched from storage, and wasn't considered necessary in-memory transformations as well. The result... 2-minute loading screen on a mobile phone. Hmmm, probably that's worth the optimization.

For that, I have created a compressed asset file type (calling them TAP files). They can hold any type of asset, and the asset is ready to be used by the engine without any further transformation. As a bonus, it supports the schema versions, so the format and data can evolve over time.

Optimizations

I found a few other pieces worth optimizing using the profiler and small test applications. The method for doing that is described in the Unit-Level Performance Testing article.

Audio

Java on the desktop has built-in functions for simple audio reading. And I wasn't able to find the same on android. So wrote a utility class, that extracts the audio tracks from files, converts them into a PCM file format, and stores them in a TAP file.

Then implemented manual sound mixer separately for desktop and android. In that way, audio works seamlessly as soon as it is loaded from the TAP file.

Maybe there is a better way, but I found this is pretty enough. Btw, here is a good article about sound mixing.

Game Attempt

Here I thought I am done. So started to code my first game. One more thing was missing. It was just too tough to do everything in code (it's possible to do, but I am lazy b**ch). So wanted to make it easier.

Editor

That was missing bit. So I created one that allows me to define prefabs, and then place them into scenes. Also, added there a way to reference the scripts so prefabs are connected with code. In order to do this, I had to significantly improve the UI. And tadaaaa.

Finally Game

Yai, now everything is ready for game creation. So go ahead and enjoy Snake. Hope I will be able to add more over time.

My Takeaway

Happy I made this experiment. I learned a lot and used the knowledge in my commercial activities (even that has nothing to do with games).

In addition, now I have my own intellectual property that is ready to evolve and grow up. That's pretty cool!

Please put me a comment about what would you like to see as a next step.

Upvote


user
Created by

Radek Hecl

Follow

Sports lover & Creator

I am addicted to sport, especially martial arts. And always looking for the technology and habits that will allow me to enjoy that more.


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles