Re: [android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-12 Thread Miguel Morales
Ah, I see, it might have been due to my misuse of wait() and notify(). In any case, I remember that even sleeping the thread caused decreased fps rate, (which I took as increased cpu usage.) I mentioned the pool thread, not because I implemented one, but because I avoided implementing one and

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-11 Thread Bob Kerns
No, we're not arguing semantics, we're agreeing. We were both responding to Miguel. (You did leave out being blocked in an IO call, but that's a minor detail). On Apr 10, 6:56 pm, Robert Green rbgrn@gmail.com wrote: Bob, Perhaps we're just arguing semantics.  I was simply saying that you

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-11 Thread Bob Kerns
You say: So, say I have the game loop logic in a thread like that, using the render fps average as a counter, I've noticed that the fps drops when using more than one thread, even if it's just running in an empty loop. Um, ESPECIALLY if it's running in an empty loop. The point is, you don't want

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-10 Thread Viktor Linder
I understand that this is pseudo-code, so it probably does not reflect your actual implementation, but I have two comments on this code: * Depending on how the scheduler works, the GameLogicThread or the Renderer thread may receive the lock two or more times in succession. * The renderer and the

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-10 Thread Bob Kerns
If a thread is hogging the CPU, it is *BY DEFINITION* not idle. And vice versa. An idle thread will be waiting on something. Either a synchronization lock, or an object using wait(), or some blocking IO call. This may be buried inside some other code, of course. I would suggest wondering why you

Re: [android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-10 Thread Miguel Morales
Ok, like I said I may have missed something, but say I have something like this: class MyThread extends Thread { run() { while (something) { if (something_else) //perhaps input has changed, or we have data in a socket { //do some work,

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-10 Thread Robert Green
Viktor, specifically in an Android 3D game using GLSurfaceView, the are you want to parallelize on is what happens after the lock is released by the renderer because significant time will be spent during the buffer swapping as the gl command list is flushed there and it is at that time that the

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Clankrieger
Hi, I had a lot of difficulties getting the threading and app lifecycle issues done, too. For my part, this was much more confusing than getting the actual game done. ;) The good thing is: you do not have to do too much for the render- and logic-thread separation because most of the rendering

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Eddie Ringle
I'm a bit confused. What exactly is Game.sInstance? And can you explain what the update() and render() methods do? (Well, I know what they _do_, but I do not know how they are doing it (pseudocode would work here).) My gameplay is probably going to be a bit bigger than what you have, so I don't

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Eddie Ringle
Another thought occurred to me. I'm more comfortable with the old- fashioned game loop, and I noticed I can turn off auto-rendering. I'll see if this works out instead. On Apr 9, 8:55 am, Eddie Ringle ed...@eringle.net wrote: I'm a bit confused. What exactly is Game.sInstance? And can you

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread shaun
I suggest you take a look at the open source Android game Replica Island. Chris Pruett (a Google employee and Android advocate) programmed it and I understand he uses a Thread for rendering, a Thread for game logic and a Thread for the Activity (life cycle, input etc...). He has a

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Robert Green
It's pretty easy to do this: I use a World to write to and read from for the two sides. Makes networking nice too. My World has a simple lock. Only one thing can write to it or read from it at a time. in GameLogicThread: run() { while (!done) { // wait for renderer world.getLock(); //

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Eddie Ringle
Where do you store all your attributes, like player position? Currently I just have a GLQuad class that I use to create new quads, texture them, and manage position and velocity. Do you store them in World, and then each side can access them from the world object? Also, threading is new to me, so

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Robert Green
Yeah, you're going to want to model your game like you would model the real world: class World { public Player player; public Enemy[] enemies; public int timeLeft; public int level; //etc.. } Then you update the world (usually by calls to player.update, enemy.update, etc) from your

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread shaun
I wonder how much true parallelism is happening when the game logic runs on a separate thread than the rendering (in addition to the Activity thread for a total of 3). I do not claim to be an expert in this arena, but what follows is what I think about the subject of threads in Android games.

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Eddie Ringle
One more thing question and I think I will be set. Coming from a C/C++ background, I enjoyed the use of references. I know that there is a way to pass the reference by value in Java, but am not quite clear on how. Could I, for example, create my World object, then pass that object to the renderer

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Mario Zechner
This topic is pretty interesting. I also am off the school of one thread is enough. I have to admit that I don't fully understand the benefits of a seperate logic thread. Am I right in thinking that the only reason to have a seperate logic thread is being able to use the cpu while it blocks on the

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Eddie Ringle
Is it as simple as: In GameView.java (my custom GLSurfaceView class): World _world = new World(); GameRenderer _renderer = new GameRenderer(_world); In GameRenderer.java: public World _world; public GameRenderer(World world) { _world = world; } In GameRenderer.java, _world would now have

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread shaun
Here is some more talk about threading (on Replica Island's Dev Diary/ Blog): http://replicaisland.blogspot.com/2009/10/rendering-with-two-threads.html On Apr 9, 2:58 pm, Eddie Ringle ed...@eringle.net wrote: Is it as simple as: In GameView.java (my custom GLSurfaceView class): World _world

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Robert Green
Eddie, Yes, that'll do the trick. As far as the multiple threads goes, sure you can drive your logic off of the call to onDrawFrame but there is a situation in which having a separate thread makes sense: After onDrawFrame, the rendering thread is finishing/swapping. That can actually take a

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Eddie Ringle
Robert, Silly question, but how do you get input to the logic thread? I have to get sensor and touch data from the main Activity class and somehow get it to the logic thread. Current program flow is as follows: onCreate() - GameView() - World() Renderer() GameLogic() On Apr 9, 3:24 pm, Robert

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Mario Zechner
That's what i was wondering. It makes of course a lot of sense to use the CPU idle time while the GPU is doing the heavy lifting. However, but having to put a synch around the access to the logic data in the rendering thread and the logic thread you explicitely starve one of the threads, depending

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Mario Zechner
That depends on what kind of input you need. If your game is happy with just checking the current state of the accelerometer/touch screen/ keyboard/trackball simply polling will do the trick. This means that in the UI thread, where you have your event listeners installed, you simply save the last

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Bob Kerns
Then I think this simplifies the advice we should give you. If you don't know enough about threading to know what a lock is, you should avoid threading for now. It'll be too much to learn at once, and you won't be able to do a good job of either learning about threading, or applying it. I think

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Bob Kerns
Think of it this way -- there is no such thing as pass-by-value in Java, and no such thing as references, either. Everything is equivalent to a pointer, except there is NO pointer arithmetic, and no - operator, that role being handled by '.', so it LOOKS like a reference with C++ eyes. To add to

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Eddie Ringle
Okay, I figured I could just pass the Activity through parameters, but wanted to know if a better way was possible. Thanks for all the help everyone. On Apr 9, 5:56 pm, Mario Zechner badlogicga...@gmail.com wrote: That depends on what kind of input you need. If your game is happy with just

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Lance Nanek
There are a lot of built in classes in Android and Java that you can use to avoid having to write any synchronization or lock code yourself. In my case GLSurfaceView sets up my render thread. I use HandlerThread for my game thread. The game thread sends an update object detailing all the draw

Re: [android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Miguel Morales
I may be completely wrong on this, but I've found that threads hog the CPU even when idle. The way that has worked well for me is to have the render thread, and the logic timer. (using a looper and communicating via a handler can be slow, from my experience locks are faster) To keep things

[android-developers] Re: Android OpenGL Game - App Architecture and Threading Logic

2010-04-09 Thread Robert Green
Miguel, Threads hog CPU only when _not_ idle. A thread constantly looping with no sleep is _not_ idle and is what people tend to do before they know better. This is what .wait() and .notify() were added for and using them means negligible CPU usage while waiting. The article you posted on