Is anyone else getting general controller lag in the sticks and buttons? I seem to be getting about a .1 or .2 second wait before getting input in my game (even more so when two controllers are being used!). Does anyone know how to fix this?
I've also noticed a very slight lag with it on the console, but from what I've heard the Unity plugin hasn't had the input optimized yet and was sending excessive amounts of data. Not sure if that's still the case, though.
Do you know of a short term solution? I have a 4 player game for Create and I am worried that it will choke. Sorry if I am asking a silly question. Sleep dep. :)
Thanks! I will search around and see if I can set aside the time to figure it out by Wednesday. I have a laundry list of stuff I gotta hit. I can't wait till Wednesday after midnight PST to get some extended sleep. :)
I have yet another product in the works on the back burner which was native screen sharing in Unity. In the project I used pinned memory to share memory between C# and C++. I ran into lag with 3.X which will work fine in 4.X, and while troubleshooting I prepared an isolated project showing pinned memory and diving deep into DirectX 9. You can download and take a look here: http://forum.unity3d.com/threads/150847-Update-Texture2D-with-D3D-in-a-Native-Plugin-without-crashing
As it is an isolated project you should be able to find the "pinned" memory easily as it's named that.
Accessing that pinned memory from within the Java Activity has to go through JNI, either by wrapping it in a direct ByteBuffer or by providing a JNI method that accesses the pinned memory in straight C/C++. Why go through all the hassle if you can use Unity's AndroidJNI class.http://docs.unity3d.com/Documentation/ScriptReference/AndroidJNI.html
On the Android side, fill an array of floats or ints with event id/event value pairs in onKey and onGenericMotionEvent. Provide a method that returns a copy of that to the caller, use simple locked double buffering to handle threading. In C# call that method via AndroidJNI and process the events. For extra ease of use, make both the array and the method static, that way you only need to query the method via AndroidJNI without needing an object.
This will have the same performance characteristics as a pinned memory/direct buffer solution, without having to drop down to C/C++.
I'd like to avoid JNI if possible. That is the original issue any time we access JNI Unity appears to log GC stuff and slow things down. With pinned memory we can have instant access.
JNI won't produce garbage if you work with direct buffers or arrays, using critical locking for the later. As i said, you won't be able to avoid JNI. Packing things into a JSON string is pretty much the worst thing you can do in terms of GC.
i work on a different framework, and my time is limited, but maybe one of the Unity guys finds the solution above straight forward enough to implement and share.
@badlogic@tgraupmann I am willing to investigate doing doing this next week. I don't know a lick about JNI but it sounds doable. I've already invested a lot of time into poring over the Unity ODK for my own uses and will take a look when I have a chance. I just might ask you questions if I get stuck on something ungoogleable. :)
We hacked together a solution for this for Super Dungeon Bros. (I am only going to display the axis info in this post. I will post a full solution once we've created it)
Sorry apparently I don't know how to paste code in here anymore
Okay now. Did you see any unstability when calling JNI? How long can the app run before exiting? You'll see in my java calls in the OuyaSDK.cs that I pop the stack after doing a JNI call. Now I was passing a lot more data with json so it may take more time to run out of memory. With JNI as soon as your stack fills up Davik pukes and closes the app. Anyway just checking on that...
Also you may have seen that the OuyaPanel when compiling Java and the plugin calls JavaP to output a signature. That's super handy because you use those signatures in the JNI interfaces. It makes it super handy for prototyping.
That's interesting. I don't know much about any of this stuff, it was someone else on the team that did it. But we have zero instability, and it got rid of ALL input lag with four controllers and lots of action constantly. Our play sessions are small though, so we haven't played long enough sessions to see any memory stack issues.
You should probably hold on to the class and method references instead of getting them all the time (assuming you actually do this). You will run into trouble if you dettach from the thread. You'll have to attach again and fetch the references anew.
It's really simple once you find out how to do it. And yeah, we are keeping a reference to it I'm not doing that every frame, that was just an example.
Ayrik - I attempted to implement this, and it's quite clear that I am not up to speed on my Java..
I believe the relevant error that I am getting is:
[Results] elapsedTime: 0.6164112 errors: D:\AirborneDynamo\ABD_Multiplayer\Assets\Plugins\Android\src\OuyaUnityApplication.java:368: cannot find symbol
symbol : class OuyaController
location: class com.Litteratus.AirborneDynamo.OuyaUnityApplication
OuyaController c = OuyaController.getControllerByPlayer(playerNum);
^
I know the OuyaController lives in the ouya-sdk.jar, and I was pretty sure import tv.ouya.sdk.*; would cover the entire library. What could I be missing?
You are likely missing an import statement to add the OuyaSDK. Also you need to include the JAR in the classpath for the OuyaSDK. I need to make that configurable.
You are likely missing an import statement to add the OuyaSDK. Also you need to include the JAR in the classpath for the OuyaSDK. I need to make that configurable.
This only confused me more. Ok so I put import tv.ouya.console.api.OuyaController; in the OuyaUnityApplication.java. I don't know where to begin with the classpath stuff. Everything I read is specific to Eclipse, or command line..
The classpath is hardcoded in the OuyaPanel.cs right now. That's where the command line javac is generated that compiles your application java. Just make sure the JAR is included otherwise it won't find the import.
Comments
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
If you search the forums there is a faster solution floating around that could be put into a package.
They were basically taking the Java and skipping the json encoding to send direct key codes.
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
What do you mean by pinned memory?
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
Right, how can I use pinned memory?
http://forum.unity3d.com/threads/150847-Update-Texture2D-with-D3D-in-a-Native-Plugin-without-crashing
As it is an isolated project you should be able to find the "pinned" memory easily as it's named that.
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
Autogenerating JNI signatures is a future feature in (yet-another Tim plugin for Unity) in my Standalone Plugin Maker:
http://forum.unity3d.com/threads/150453-Standalone-Plugin-Maker
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
// Unity JNI reference: http://docs.unity3d.com/Documentation/ScriptReference/AndroidJNI.html
// JNI Spec: http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/jniTOC.html
// Android Plugins: http://docs.unity3d.com/Documentation/Manual/Plugins.html#AndroidPlugins
// Unity Android Plugin Guide: http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].
OUYA Inc | Android Developer
Skype: tgraupmann_prey
http://github.com/ouya/docs
http://github.com/ouya/ouya-sdk-examples
Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]
Use caution when setting [persistent wireless mode].