1

Topic: [TO DEVELOPERS] Porting to Android

A couple of weeks ago I bought a smartphone with Android operating system. I once heard that there is Android port of Teeworlds client. I was very disappointed when I learned that this port is abandoned and is not playable. I have some skills in both Java and C (mainly in Java) and can spend enough time to create port. Game UI will be extreamely simplified and rewritten in Java. SDL will only manage a single game session. It sounds simple, but very hard to plan things without clear understanding of source code. Of course, I can understand it myself.. After spending A LOT of time. But I think that well-designed game (which tw actually is) do not require full rewriting of source in order to create port. So I would be happy if developers respond few questions.. or just don't ignore me and guide on the right path. To begin, I need to know the answers to these questions:

- common questions -

1) What are THE MOST important classes defined in client's source?
3) What does game flow seem like?
2) Would there be any problems with separating UI and game logic?

- specific topics -

1) How does game client manage game lists and perform connection to selected game? I believe that it is possible to write 2 methods in C: one, invokable from Java code, to obtain a list and another like "connectToGame(someGameId)". Am I right or just crazy?

2) What is the easiest way to inject whole configuration data into game?

3) Is there any nonobvious dependencies between classes?

- other topics -

1) Sorry if my questions are unclear or malformed, so please provide at least any help.

2

Re: [TO DEVELOPERS] Porting to Android

Common
1) All Classes are important
3) Sry .. I don't understand the question
2) OpenGL, SDL, Wavpack, Sockets, Threads and File Access must availiable on Android for Teeworlds to work.

Specific
1) The Network stuff is found in "system.c", there are no gameids. Client connect to the IP over Sockets. Rewriting Teeworlds in Java will take years/will Be impossible.
2) Using a Folder settings and then reading the settings.VFG
3) Teeworlds Src is structured clear

I'm sure porting Teeworlds to an other System is impossible:
- Client: SDL, Wavpack and OpenGL are not supported by every os
- Server: Threaded Processes are not supported on all os

Last days I (tried) Teeworlds Wii Port:
Client ended in disaster because OpenGL is needed for the whole gfx to work and SDL-Wii does not work very good.
Server works on Wii, but as there are no libs for threaded work the Server can't handel clients. Network and File Access are working so the Server loades maps and wants to handel the clients.

3 (edited by Na_v_uho 2011-05-15 07:01:28)

Re: [TO DEVELOPERS] Porting to Android

OpenGL, SDL, Wavpack, Sockets, Threads and File Access must availiable on Android for Teeworlds to work.

I'm sure porting Teeworlds to an other System is impossible

Already working!

OpenGL, SDL

OpenGL
SDL

Wavpack

There are some attempts and Wikipedia says that at least one app exists with Wavpack support.
Anyway there will be no sound in first version of port. And it seems to be easier to convert audio to Vorbis and play music using built-in Java API.

..Sockets, Threads and File Access must availiable on Android for Teeworlds to work.

http://en.wikipedia.org/wiki/Android_(operating_system)

SDL-Wii does not work very good

But there are several SDL games succesfully ported to Android: EnviroBear, INSTEAD and few others.

So my desire to re-write some code in Java may seem strange, but it is reasonably. If you read previously mentioned post about porting, two main issues were owful (not suited for small devices) UI and low average perfomance. It seems that you did not understand me - I am going to convert to Java ONLY UI code that is menus, buttons, game lists etc. Core C code is better to leave where it is now.

Reading sources...

4

Re: [TO DEVELOPERS] Porting to Android

Na_v_uho wrote:

Already working!

You know where the link links to? I mean porting Teeworlds to another platform than Windows, Mac and Linux.


KillaBilla wrote:

SDL-Wii does not work very good

Na_v_uho wrote:

But there are several SDL games succesfully ported to Android: EnviroBear, INSTED and few others.

Na_v_uho wrote:

It seems that you did not understand me

I was talking about the SDL for Wii! It seems that you did not understand me.


Na_v_uho wrote:

So my desire to re-write some code in Java may seem strange, but it is reasonably. If you read previously mentioned post about porting, two main issues were owful (not suited for small devices) UI and low average perfomance. It seems that you did not understand me - I am going to convert to Java ONLY UI code that is menus, buttons, game lists etc. Core C code is better to leave where it is now.

I know what UI is. Why should Java have a better performance then C++? Why don't you let the whole code how it is and just port it. It is unneeded work to port a part of the game an make the C and Java parts may incompatible.


In the first post you had some questions.
I answered the questions to help you.
And now you tell me that you know everything better than me. Why do you ask if you know the best anwers? ._.

5 (edited by Na_v_uho 2011-05-15 07:04:21)

Re: [TO DEVELOPERS] Porting to Android

Oups.. Single broken link has ruined all my efforts to explain things! Anyway sorry if my answer was too straightforward, please do not take any of my comments as a criticism - this is style of speech (and possibly result of G-translate usage). This link (works in original post now) - http://www.teeworlds.com/forum/viewtopic.php?id=6632 points to topic that reveals the same issues of pure C port without modifications as ones mentioned on many forums where people tried to play tw on Android-driven smartphones. These two issues are:

1) low usability of Teeworlds UI controls that simply were not designed for small-screen devices. These controls are used very frequently during the game (especially console is) and there is no way to make their usage more convenient except re-implementing in native (Dalvik) way. Android offers a rich suite of UI widgets, so there is no big problem with this.

2) low playability due to unsuitability of current control model on touchscreens. It think it is very ugly solution to plug usb mouse/keyboard in order to play some game on phone. The only solution I see is to create additional level of input handling, some kind of motion bot..

As for graphical performance, it is not primary problem - I hope removing all effects, background and bullets' trajectories will make it to work on my 800 MHz ARMv6 CPU.

And now you tell me that you know everything better than me. Why do you ask if you know the best anwers

I am totally novice in the C development and do not know many obvious (for Teeworlds developers) things so I was a bit embarrassed by structure and content of tw source files. I asked initial questions because I wanted to get some hints like -

"Source is separated into 3 parts: OS interface into 'base' folder, UI independent game engine in the corresponding folder and actual client implementation into 'game/client'. Сode that is executed in first place is divided between client.cpp and gameclient.cpp with lots carefully hidden references to UI code in the later one. To create the port you should create modified launcher (like one existing for Mac OS) and replace all references to code in ui.cpp and similar files by ones to your implementation"

Such things can be very obvious for current developers, but their knowledge can save few time of people interested in Teeworlds porting and hacking. It is possible that all this was previously described somewhere so links to these places are also welcome.

6 (edited by KillaBilla 2011-12-14 16:05:58)

Re: [TO DEVELOPERS] Porting to Android

Na_v_uho wrote:

"Source is separated into 3 parts: OS interface into 'base' folder, UI independent game engine in the corresponding folder and actual client implementation into 'game/client'. Сode that is executed in first place is divided between client.cpp and gameclient.cpp with lots carefully hidden references to UI code in the later one. To create the port you should create modified launcher (like one existing for Mac OS) and replace all references to code in ui.cpp and similar files by ones to your implementation"

I don't know if you have to modifie the launcher cause I have no Mac OS and I don't know what the launcher does. You mean you should put the code of 30 files in this one ui.cpp? Not a good idea: You won't be able to find any code you are looking for and all will get unclean.

There are 3 parts:
base: OS Interface + some math things
game/client: User Interface
engine: Background Processes for Client and Server e.g. Connecting or downloading a map

If you don't know much about C and C++ you can't port the main files (system.c and system.h) to Android. But this files are the only files that you really have to port to make the game run on Android. If OpenGL, SDL and Wavpack are working on Android you don't have to port any UI code. You should first port system.c to Android (Sockets/Networks, File Access, Threaded Work) and then if this port works on your Android you can start with changing the UI to make it better for the small resolution of the Android.

7

Re: [TO DEVELOPERS] Porting to Android

A nice project. It's pretty amazing how the unmodified source you linked works well.

I have an idea for the gameplay UI, if you are interested in a mockup send me a private message and I'll make you a proposal.
(I'm asking for PM because I don't read the forum regularly)

Good luck with your proj !

8

Re: [TO DEVELOPERS] Porting to Android

At least the main libarys should be availiable for android. o.O
std::sort needs at least algorithm which is availiable on nearly all systems.
If it isn' availiable on Android just write you own sort algorithm. Google for Bubblesort to  find out how it works.

9 (edited by Na_v_uho 2011-05-02 04:56:57)

Re: [TO DEVELOPERS] Porting to Android

Thanks for fast answer! :)

KillaBilla wrote:

std::sort needs at least algorithm which is availiable on nearly all systems

But full C++ support is not. According to Android NDK help "An *extremely* minimal C++ support API is available".
qsort works but I do not know how to use it with class methods like CServerBrowser::SortCompareName.
In previous versions methods used to sort games by name, type etc. were written in plain C and Pelaya (previous porter) did not have any problems. But now!!!! All such methods are class methods. I changed theit code to be useful in qsort again (eg changed logic, signatures and returned value types) but how can I pass them as params to qsort?

qsort(m_pSortedServerlist, m_NumSortedServers, sizeof(int), ???);

Or what is better I can convert these simple sorting methods to static functions (they seems not to be used anywhere else) and simply use them in qsort. But these functions now have code like this

int CServerBrowser::SortCompareMap(const void *Index1,const void *Index2) const
{
    CServerEntry *a = m_ppServerlist[*(const int*)Index1];
    CServerEntry *b = m_ppServerlist[*(const int*)Index2];
    return str_comp(a->m_Info.m_aMap, b->m_Info.m_aMap);
}

As you see they use local class variables, so how can I pass them pointer to my this object to resolve that dependency?

EDIT: sorry for spamming this board, problem was successfully solved by plugging stlport.

10

Re: [TO DEVELOPERS] Porting to Android

Hey, may I humbly suggest to fork my Git repository with TeeWorlds project, that already has all required libraries, and just tweak the GUI elements size? The function MENUS::render_menubar() in file game/client/components/menus.cpp is a good place to start - just modify numbers inside ui_vsplit_l() calls, and the menu buttons will become bigger.

Also, what we really need for Android port is an idea of good player controls. I've already tried moving with on-screen joystick and firing my tapping the screen where the opponent is. Later I've changed that to Gun Bros - style controls, when you have two joysticks, one for moving, another for aiming and shooting. Both methods suck. Can you propose something better, using only the phone touchscreen and the Menu button? You've mentioned some "motion bot", can you please describe in detail? (I hope that's not a plain cheaty aimbot).

BTW Wavpack included with the Teeworlds sources compiles without problems for Android, why making such fuss around it?

11

Re: [TO DEVELOPERS] Porting to Android

pelya wrote:

Hey, may I humbly suggest to fork my Git repository with TeeWorlds project, that already has all required libraries, and just tweak the GUI elements size? The function MENUS::render_menubar() in file game/client/components/menus.cpp is a good place to start - just modify numbers inside ui_vsplit_l() calls, and the menu buttons will become bigger.

I'd suggest to start from teeworlds 0.6 trunk code instead of 0.5 code

12 (edited by Na_v_uho 2011-05-15 10:42:35)

Re: [TO DEVELOPERS] Porting to Android

Hi pelya! Happy to see you here! Your work on Teeworlds porting helped me a lot with hacking game source. There were some problems with launching your tw on my pad. And your last messages on xda were full of despair... So I started my porting from scrach with last stable SDL-1.2 (actually bad decision), Teeworlds 0.6.0, and Freetype version from Android source.

It was not hard to "integrate" (polite alternative to "copy-paste") your code in the current Teeworlds source but first successfull launch revealed serious problems with fonts (maybe Freetype or video-driver bug), touchscreen calibration (maybe SDL-1.3 hack or usage of your version can help) and what is especially disappointing - with perfomance. I am sure this problems can be solved by better fonts, smaller textures and GLES-specific optimisations. But I currently have no time to work on it. Motivation is still high but exams... So do not wait anything from me until June finishes.

Post 2:

pelya wrote:

You've mentioned some "motion bot"

Idea is simple - to add control on top of game that player can drag and drop in direction he wants tee to go. Algorithm of path finding can be taken from existing pc-driven bots (some can be found on this forum). Because player spends most time running in single direction this would greatly simplify playing without adding cheat effect (player can not accidently fall but control is not so fine-graned). And gestures can be used for weapon changing. It also would be convinient to combine gesture with fire (for example drawing cross over enemy activates grenade and shoot at the same time). Such way of fast weapon switching can compensate poor accuracy in comparsion with mouse control.

Post 3:

heinrich5991 wrote:

I'd suggest to start from teeworlds 0.6 trunk code

It was not hard for me (and it would be much simpler for experienced C++ programmer) to adapt existing port to 0.6 code structure. All important code in client "graphics", "sound" and "input" files (now renamed from .c to .cpp) is still there, wrapped in C++ classes. The only thing that should be done is creating special versions of these classes and plugging them with few lines in headers.

please edit your posts instead of writing a new one, at least if it has been less than a day // m!nus

13 (edited by Lidia 2012-06-18 09:27:34)

Re: [TO DEVELOPERS] Porting to Android

pelya wrote:

Also, what we really need for Android port is an idea of good player controls. I've already tried moving with on-screen joystick and firing my tapping the screen where the opponent is. Later I've changed that to Gun Bros - style controls, when you have two joysticks, one for moving, another for aiming and shooting. Both methods suck. Can you propose something better, using only the phone touchscreen and the Menu button? You've mentioned some "motion bot", can you please describe in detail? (I hope that's not a plain cheaty aimbot).

Agree about player control. It is very inconvenient now, but I modern smarts are mainly use touchscreens. If only to develop some special removable application.

14

Re: [TO DEVELOPERS] Porting to Android

Android port is back