📜 ⬆️ ⬇️

How it is made: mobile cross-platform engine

For you, I have prepared a series of articles about mobile game development, based on the experience gained and the past rake. The first article focuses on creating your own cross-platform engine for mobile games. In truth, not only mobile, and not just games.


Content


Part 1. Mobile cross-platform engine
Part 2. Rendering UTF-8 text using an SDF font
Part 3. Rendering drops with transparency and reflections.


Do you need your own engine at all?


Every time another popular engine becomes free or open, I ask myself this question. Let's look at the pros and cons:

pros


Minuses
')

Of course, everyone will see their own pros and cons. My job is to warn. Go!

What is it made of?


We are talking primarily about the development of mobile games, so the basis will be uniquely on C ++ / OpenGL . No options! However, without secondary languages, too, can not do. Let's see what is used on each platform:
PlatformThe foundationWrapperGraphics
iOSC ++ObjectiveC or SwiftOpengl
AndroidC ++ (NDK)JavaOpengl
WindowsphoneC ++C #OpenGL via Wrapper or DirectX
tvOS (AppleTV)C ++ObjectiveC or SwiftOpengl
OsxC ++ObjectiveC or SwiftOpengl
LinuxC ++C ++Opengl
As you can see, C ++ and OpenGL are everywhere. On ObjectiveC / Java / C # you will have to write only a wrapper for working with the system of the device. The very same code of your projects will be the same - in C ++. On this note, we say: "Goodbye, painful porting!".

Opengl


I strongly recommend using OpenGL 2.0 and higher. The time of OpenGL 1.1 is long past, and the transition from 1.x to 2.x will be remembered in nightmares. However, do not rush to use the latest version of OpenGL without making sure that all target platforms support it. In most cases, OpenGL 2.0 is enough and all platforms support it.

C ++


The same situation with C ++ 11/14. If you are sure that all compilers are friends with him - super. I also have C ++ 98, so when adding a new platform - and there are plans to support consoles - I will be calm.

IDE


Xcode - for iOS, OSX, tvOS. Plugins through CocoaPods .
Android Studio - for Android. Plugins via Gradle .
Visual Studio is all under Windows.

Engine structure


First of all, the engine and projects should be carefully and logically stored on disk. As a result, I came to this structure:


Project builder


The project builder is responsible for preparing resources, formats, and packaging. Namely:
Next, the collector converts resources, encrypts, packages, and places them in [Platform] / Res.

The most important thing here is the conversion of files by extension. I use such conversions:

In this case, the collector looks at the time of the file change and converts only the changed files, which significantly speeds up its work. Specifically, my collector is written in PHP. Perhaps this is not the best choice, but it was easier for me. In addition, it can potentially be transferred to the server for teamwork.

Formats


I would recommend using these formats:

WEBP for pictures. Hardly for anyone this format will be new. And for those who hear about it for the first time - webp can store a picture without loss of quality as PNG, as well as with loss — like JPEG, but with noticeably better quality, less weight and transparency. Another advantage is the ability to scale pictures on the fly while reading a file. Libwebp is compiled for all platforms without problems.

OGG for sounds. Android natively understands the OGG format, and on iOS / OSX / tvOS I use the Tremor library (fixed-point version of the Ogg Vorbis) to decode WAV sounds and feed them to OpenAL. Attempts to use OpenAL and on Android were not crowned with success (the sounds were delayed).

Classes and modules


Let us examine in more detail what classes the engine contains and why modules are needed?
The rule “what to make in the module, and what in the engine?” Is very simple:


Following this rule, I distributed the classes as follows:

Engine



Modules



In the following articles I will focus on specific classes and modules, with examples and usefulness. I want to pay special attention to rendering the SDF fonts (Signed Distance Field) and shaders in the game from the header.

Source: https://habr.com/ru/post/282065/


All Articles