Android Phone as Controller

Android Phone as Controller

Postby Kalabasa » 26 Nov 2013, 15:57

Hello.

I'm new here. :)

I saw the Wii support thing. I thought, why not use Android (phones) as controller? ;)

I can program the system, however, I do not know where to start. :think: I'm new to open source too. :) Besides bug reports, I have never contributed to any project.

So, is this possible?

Thank you :D
User avatar
Kalabasa
 
Posts: 7
Joined: 26 Nov 2013, 14:20

Re: Android Phone as Controller

Postby Auria » 27 Nov 2013, 00:49

It is technically possible yes, although I am unaware of any way to do it at this time ;) touch controls are also unlikely to be fun to play with, since the game was not designed with that in mind. So it's unlikely that we will spend development time on this in the near future
Image
User avatar
Auria
STK Moderator
 
Posts: 2976
Joined: 07 Dec 2009, 03:52

Re: Android Phone as Controller

Postby hiker » 27 Nov 2013, 13:00

Auria {l Wrote}:It is technically possible yes, although I am unaware of any way to do it at this time ;) touch controls are also unlikely to be fun to play with, since the game was not designed with that in mind. So it's unlikely that we will spend development time on this in the near future

Someone already did part of it, see

youtu.be/vaT7KB-H7cc
This was linux specific (i.e. it was simulating a joystick to the OS, which STK just picked up), but it contained the functionality to connect via bluetooth or wireless internet. It would be possible to include a receiver for the latter at least in STK. But I have to admit not top priority for us main developers, but we are happy to help anyone who wants to get started.

Cheers,
Joerg
hiker
 
Posts: 1435
Joined: 07 Dec 2009, 12:15
Location: Melbourne, Australia

Re: Android Phone as Controller

Postby Kalabasa » 28 Nov 2013, 17:34

Hello. Thanks for replying.

I am now downloading the source and reading the documentation. I see the input folder, but I got lost (and confused). How does it work? From what I understand the InputManager listens for keystrokes and then calls DeviceManager? So then I have to make an AndroidManager (or NetworkInputManager so we can be generic) that listens for input from the network? Is this what WiimoteManager does? I haven't read the source yet. Thanks. :)
User avatar
Kalabasa
 
Posts: 7
Joined: 26 Nov 2013, 14:20

Re: Android Phone as Controller

Postby hiker » 29 Nov 2013, 00:47

Kalabasa {l Wrote}:I am now downloading the source and reading the documentation. I see the input folder, but I got lost (and confused). How does it work? From what I understand the InputManager listens for keystrokes and then calls DeviceManager? So then I have to make an AndroidManager (or NetworkInputManager so we can be generic) that listens for input from the network? Is this what WiimoteManager does? I haven't read the source yet. Thanks. :)

Yes, best option is to study the wiimote manager - you just have to insert the events into the irrlicht event handler (which is just what the event manager does), everything else should just work. Oh, I just realised, there is a minor change in the device manager - just search for WIIUSE in the source to find all the changes done for wiimote support.

Cheers,
Joerg
hiker
 
Posts: 1435
Joined: 07 Dec 2009, 12:15
Location: Melbourne, Australia

Re: Android Phone as Controller

Postby Auria » 29 Nov 2013, 00:51

quick description :

the inputmanager is the entry point, and the general manager of input. Device manager is responsible to list connected devices, and to be the link between the input manager and config classes. Then classes like KeyboardDevice and GamepadDevice represent one connected device (they are created by the DeviceManager). And finally, each has a configuration which contains key bindings, in KeyboardConfig and GamepadConfig,

So, I see two options for you : one, just pretend you are a special gamepad and inject gamepad events into our event handler (there is commented out debug code in our event handler to simulate hats for testing purposes). Second, create a AndroidDevice and plug it into the device manager will the other kinds of devices. The second approach is probably a bit cleaner (or it could be a subclass of GamepadDevice, perhaps)
Image
User avatar
Auria
STK Moderator
 
Posts: 2976
Joined: 07 Dec 2009, 03:52

Re: Android Phone as Controller

Postby Funto » 29 Nov 2013, 23:39

Easiest way is certainly to mimic what the wiimote manager does, which is, "emulate" a gamepad device by injecting events directly into Irrlicht and have fixed, non-configurable button assignments (that could be ok in your case if your UI/controls are designed especially for STK, IMO).
Funto
 
Posts: 459
Joined: 09 Dec 2009, 13:47
Location: Bordeaux, France

Re: Android Phone as Controller

Postby Kalabasa » 01 Dec 2013, 08:59

Built successfully :)

Executing
./supertuxkart
gives an error
[error ] StkConfig: FATAL ERROR while reading '/usr/local/share/supertuxkart/data/stk_config.xml':
[fatal ] StkConfig: Cannot find file /usr/local/share/supertuxkart/data/stk_config.xml


I have my data files at /usr/share/games/supertuxkart/data/

Using --stk-config option
./supertuxkart --stk-config /usr/share/games/supertuxkart/data/stk_config.xml
still fails
[error ] StkConfig: FATAL ERROR while reading '/usr/local/share/supertuxkart/data//usr/share/games/supertuxkart/data/stk_config.xml':
[fatal ] StkConfig: Cannot find file /usr/local/share/supertuxkart/data//usr/share/games/supertuxkart/data/stk_config.xml


Using a relative path
./supertuxkart --stk-config ../../../../../usr/share/games/supertuxkart/data/stk_config.xml
does not work
[error ] StkConfig: FATAL ERROR while reading '/usr/local/share/supertuxkart/data/../../../../../usr/share/games/supertuxkart/data/stk_config.xml':
[fatal ] StkConfig: Cannot find file /usr/local/share/supertuxkart/data/../../../../../usr/share/games/supertuxkart/data/stk_config.xml


Editing io/file_manager.cpp at line 158
{l Code}: {l Select All Code}
m_root_dir = "/usr/share/games/supertuxkart/";

and then compiling
./supertuxkart
[error ] StkConfig: FATAL ERROR while reading '/usr/local/share/supertuxkart/data/stk_config.xml':
[fatal ] StkConfig: Cannot find file /usr/local/share/supertuxkart/data/stk_config.xml

Editing file_manager.cpp again
Inserting at line 169 (after the #ifdefs, before the Logs before the end of the constructor)
{l Code}: {l Select All Code}
///////////////////////////// hack /////////////////////////////////////////
m_root_dir = "/usr/share/games/supertuxkart/";
////////////////////////////////////////////////////////////////////////////

bin>./supertuxkart
Irrlicht Engine version 1.8.0
Linux 3.5.0-32-generic #53-Ubuntu SMP Wed May 29 20:22:58 UTC 2013 i686
[info ] FileManager: Data files will be fetched from: '/usr/share/games/supertuxkart/'
[info ] FileManager: User directory is '/home/lean/.config/supertuxkart/'.
[info ] FileManager: Addons files will be stored in '/home/lean/.local/share/supertuxkart/addons/'.
[info ] FileManager: Screenshots will be stored in '/home/lean/.cache/supertuxkart/screenshots/'.
[debug ] translation: Env var LANGUAGE = 'en'.
[debug ] translation: Language 'English'.
fish: Job 1, “./supertuxkart” terminated by signal SIGSEGV (Address boundary error)

Segmentation fault. :| :cry:

I don't know anymore :(
User avatar
Kalabasa
 
Posts: 7
Joined: 26 Nov 2013, 14:20

Re: Android Phone as Controller

Postby Auria » 01 Dec 2013, 17:52

Hi,

you don't need to edit the source code. To run STK without installing it system-wide, simply run it from the root. I suspect you did something like this : "cd ./cmake_build/bin; ./supertxukart". Instead, remain at the root, and issue "./cmake_build/bin/supertuxkart". Or, alternatively, you can run from the cmake_build folder with "./bin/supertuxkart". If all fails, do not edit the source code, simply "export SUPERTUXKART_DATADIR=..." where you need to replace ... with a full path
Image
User avatar
Auria
STK Moderator
 
Posts: 2976
Joined: 07 Dec 2009, 03:52

Re: Android Phone as Controller

Postby Kalabasa » 01 Dec 2013, 22:03

Thanks. It works! :D

Now, attempting to hack STK...

LONG POST! :)

I'm going for the subclass option. Make MobileDevice as a subclass of InputDevice (or should it be a subclass of GamepadDevice?).
The problem is that the input I need is from the network. (I don't know how to bluetooth :p )

Here is a general algorithm for the game. I am going to use UDP (Should I use TCP?)
1. InputManager makes a thread that will listen for incoming UDP messages.
2. Thread is listening for messages.
3. Something (probably the Android phone) sends a UDP message containing control messages and name to the host computer.
4. Thread gets the message, then calls dispatchInput(...).
5. Go to 2.

(name is for identification of the phone)

About pairing... :think:
1. User clicks "Add Android Device."
2. Game GUI shows IP address of the computer (or QR code of IP address) and waits for confirmation.
3. User enters IP address into the phone (or scans QR code on the screen).
4. Phone sends confirmation and name to the computer.
5. Game receives confirmation and makes a MobileConfig and MobileDevice for the phone.

Phone's name is stored in MobileConfig and MobileDevice.


Now about mapping the phone's messages to MobileDevice...
I have a problem. :!:
This is roughly how InputManager will receive control messages:
"lean 0 LEFT 38" <name button direction value>
"tux 0 RIGHT 4487"
"tux 0 RIGHT 22"
"lean 3 LEFT 1223"
...

Upon receiving a message, InputManager needs to call dispatchInput(...).
Parameters of dispatchInput are (Input::InputType type, int deviceID, int button, Input::AxisDirection axisDirection, int value).
I can pass button, axisDirection, value, and type; those are given.
I cannot pass deviceID. I somehow need to convert phone's name to integer.

The problem is getting id from a name then mapping that id back to the original name. InputDevice id is arbitrary.

name --?-> id (random) ----> name


Please comment. Did I get something wrong? :think:
User avatar
Kalabasa
 
Posts: 7
Joined: 26 Nov 2013, 14:20

Re: Android Phone as Controller

Postby Funto » 01 Dec 2013, 23:51

Really, I would go the simpler way of copy-pasting WiimoteManager and adapting to use networking. That way you just wouldn't have to ask yourself that kind of questions, just emulate a GamePad device by injecting the input into Irrlicht and that's it.
On the network connection, I think I would go with TCP, as you don't want to miss the user pressing a key, and network connection should be pretty fast at a close distance.

My opinion ^^.
Funto
 
Posts: 459
Joined: 09 Dec 2009, 13:47
Location: Bordeaux, France

Re: Android Phone as Controller

Postby Kalabasa » 02 Dec 2013, 09:47

Ah! I must have misunderstood the system. :oops:

I'll look again... :think:

also I just found out that enet library is already included. :D
User avatar
Kalabasa
 
Posts: 7
Joined: 26 Nov 2013, 14:20

Who is online

Users browsing this forum: No registered users and 1 guest