Lines 3D application structure (Windows Store version)

Lines 3D game is a UWP application based on “XAML App for OpenGL ES (Universal Windows)VS2015 project template (written in C++/VS2015 using OpenGL ES 2.0 and elements of OpenGL 3.0). You can install Lines 3D  from Windows Store and play for free, or at least see the game screenshots.

Main components

Game logic and OpenGL rendering engine in Lines 3D are cross-platform. Their code uses STL, OpenGL and abstract C++ interfaces for doing the following tasks:

  • Loading sounds from wav files and playing them with different speed and volume.
  • Loading textures from PNG images (this code uses Windows API, but probably it can be made cross-platform).
  • Logging game events, such as “game over” to the Windows Store. They used to collect statistics on what game levels the users play and what score they get. The possible application crashes (unhandled exceptions and memory failures) and internal errors (like file not found, etc.) are also logged to the Windows Store.
  • Accessing application installation path and application data path in the file system.

All the graphic controls, including the main windows, application bar (main menu), dialogs, message boxes and advertising are written using XAML and Windows-specific code.

Threads

There are UI thread (main thread) and the rendering thread in the application. UI thread is the thread on which the main window and all the graphic controls are created and the only thread on which the graphic control method calls are allowed.  The rendering thread is started when the application starts and the main application widow becomes visible, stops when the application is suspended and then started again when the application is resumed, it can be restarted as well at any time, for example when the user starts new game, or changes some rendering parameters such as antialiasing. Each time the rendering thread is restarted the rendering engine is completely recreated (all C++ objects are deleted and recreated, and all OpenGL shaders are recompiled). So all the graphic controls live in UI thread and the rendering engine doing the most of OpenGL calls live in the rendering thread.

Calls from the rendering thread to UI thread are marshaled using Windows-specific CoreDispatcher.RunAsync method. UI thread calls the rendering engine using the mechanism I described in article Synchronization mechanism in DirectX 11 and XAML UWP application based on the same principles as Line 3D application.

Localization

Lines 3D is translated into 9 languages with Multilingual App Toolkit that uses XLIFF standard.

Porting the application to Android and iOS

The possible solutions are “OpenGLES 2 Application (Android, iOS, Windows Universal)VS2015 project template and QT. The both alternatives have their own benefits: first – no dependency on large third party library and the ability to have a single solution file (*.sln) for all the code and easily compile it with VS2015, second – cross platform graphic controls. But anyway, the advertising and license related code is platform-specific. The other alternative is Cocos 2D or some other cross-platform game engine, for example.

On mobile device the game should look like this:

lines-2d-controlslines-3d-controls

where 1 and 2 is rotate left and rotate right buttons, 3 – step back, 4 – the score/turns/balls information block, also there should be game options button for selecting game level, save/load, mute sound, etc…

The following picture illustrates how the above pictures look from the developer perspective:

board-layout

Leave a Reply

Your email address will not be published. Required fields are marked *