How to create a cross-platform Half-Life or "Headcrabs inside your watch"
A couple of months ago, on Hiktaimes , the news of the running Half-Life on Android Wear slipped . The article did not say a word about the developers, and then one of the habrovs asked in the comments why none of them would write here?
And now the anniversary since I started the port of the free Xash3D engine on Linux, and also, since several of my friends were still interested in the details, I decided to write this post. Who is interested in the history of the project, workarounds for various problems and my personal advice, please under the cat. I'll start with the history of the project. The engine was originally written by a programmer with the nickname Uncle Misha or g-cont. It is to him that we owe what we have now. Only in 2011, he laid out the source of the engine under the GPLv3. But he had a fatal flaw, Uncle Misha did not want to port the engine to something other than Windows. For Android port, he wanted a certain amount, and, of course, the idea failed because of our community. ')
I personally began to follow the engine from 2012, a year after the source was opened, but only in the fall of 2014, with a little C ++ programming experience, I downloaded the source code of the engine. Burning with the thought that the free game engine and cross-platform are concepts closely connected with Karmakov times, I began to port it to Linux.
At first, the port was planned using winelib, but over time, having penetrated into the architecture of the engine, I settled on SDL2, as the ubiquitous multimedia library itself. Yes, and Valve for its ports used it.
And right away my first advice to those who want to port any application unknown to him to any OS:
1) Create project files immediately and, without making a single change in the project, compile it.
Yes, your IDE may even freeze from my advice, since the compiler will generate more than one thousand errors and warnings. My compiler gave about 4000 errors.
Moving from one mistake to another, I gradually got rid of them. There was no screw code left, -Wl, - no-undefined saves a lot when porting.
And it happened - the engine was loaded. Shows its own console, and outside the window, in the meantime, it was already about the beginning of December last year. I must emphasize that before me, attempts were made and approximately on the console and ended, if not earlier. All December I went to download libraries in runtime, SDL input, sound - and here I post a screenshot on Linux.org.ru.
Several people are interested in the work done. I look back at the sources and I understand that it is impossible to work with this: in many places the code is unreadable due to macros, strange bugs appear, building outside of my localhost is very complicated. And the engine version is very old. In the comments to the thread indicate that the new versions are distributed in some other forum. As a result, I start everything from scratch, and my friend helps to bring everything into a serious look - translates the assembly to CMake, drives me with bad-smelling rags for too large commits and govnokod. Also on GitHub an organization SDLash3D is created, named after the old port. At the time of this writing, there are already five people in it, but only two are active.
Suddenly, number 2, which I have learned for myself at this time:
2) Make a header file containing only macros that will insert the necessary code for the target platform.
Also here is a tip for those who, while reading this article, write code in their studio.
3) At the expense of any suspicious and strange code, please contact Google.He will tell you that your code is compiled only under Visual Studio, which has many non-standard extensions.And less tied to WinAPI.
Meanwhile, nicknekit / Unc0nnected silently starts porting the old port to Android.
Screenshots and videos courtesy of Nikita
From February Nikita and I begin to work together on the port. He is busy with the old port, and I finish the new one and transfer the functionality associated with Android into it.
At this point, the basic operation of the port on Android is established. Now it looks like this:
In March, we create a thread at w3bsit3-dns.com, which we report on the progress of the transfer, new videos and screenshots. The first of April is version 0.1, but April 1 cannot be without a joke, so a special condition has been made in the engine, under which it closes, if pakandroid.pak is not found, in which a very fun and sufficiently high-quality G-Man mode was “sewn up” Invasion.
Since then, among the significant events for the port were:
Support touch control, made in conjunction with Beloko Games;
Release of version 0.14, which really brought success. About 20 thousand visitors in two days, judging by the statistics on GitHub;
Interface Android version for modifications made by our mittorn . Modders can independently release their game also on Android.
On this you can and finish, below the bonus in the form of individual commits and links to us on GitHub and ModDB.
Bonus number 1. Several commits related to a different understanding of code in Visual Studio and GCC. After fixing all of them, I’m sure that C support in the studio is the worst thing that happened in the field of programming:
A bug in which sound files of words were recorded one element of the array forward. Under MSVC does not manifest itself, in GCC manifests itself;
A bug in which GCC swore to go beyond the array. Under MSVC also does not appear;
And there are no links here. I just suddenly discovered for myself that all char on ARM is unsigned. That is why the NPC navigation went crazy, and the sprites didn't work in the engine. You can either insert the -fsigned-char switch, or explicitly indicate that char should be signed for this variable;
Render bug . Not really ARM problems, but OpenGL ES problem. Still not fully fixed;