Renderer Logic UI problem! Please help!

Problems with Canvas, OpenGL, etc...

Renderer Logic UI problem! Please help!

Postby cloudjubei » Mon Apr 25, 2011 1:53 am

I'm doing this game and I seem to have a problem in organising everything between the Renderer Logic and Ui threads. One problem is that I'm not exactly sure how the UI is supposed to be passing the user input onto the logic thread (i allow only touchscreen interaction). Atm, I have something like this:

In the UI thread:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onTouchEvent(final MotionEvent e){
  2.          return gameThread.clicked(e);    
  3.     }
Parsed in 0.012 seconds, using GeSHi

and then in the Logic thread I am using a ConcurrentLinkedQueue to store the click in it:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean clicked(MotionEvent e) {
  2.                         qClicks.offer(e);
  3.                         return true;
  4.                 }
Parsed in 0.010 seconds, using GeSHi

This is all pretty simple, so I'm wondering whether it's a good way for it to work? Because what I'm doing is every Logic frame (I go around every 16 ms (or try to) ) I look inside the queue for 1 click and if there is one I do what it says.
After that the Logic Thread proceeds with updating the position of things on the screen.
Which brings me to another question - is that how I'm supposed to be doing it? As in the logic thread goes round every 16ms (I assume the renderer is doing something similar) and updates the position of everything on the screen or should the renderer be doing this (but then the logic thread wouldn't do any logic... so i assume it's right).

So that's one thing and the other is a couple things to do with the renderer.
So 1st of all - I thought that because this game has a lot of graphics, what I will do, is have a lot of static textures binded to some objects inside the renderer (actually inside an inner static class inside the renderer), they'll get binded once the surface is created and later all my objects will be able to use this to draw stuff. Now, is this efficient? I basically have 1 texture per every single item of UI, so it's quite a lot of texture binding and creation going on and I have to wait like 10 secs before I get something to appear on screen cos of this - the question, is there a better way of doing this, or how do I crop things out of the texture, so basically I would load one bigger texture with lets say an explosion and then dependant on the coordinates I would use that part for a specific frame of the explosion (I assume this is easy, but I've no idea how to do this now).
Also, would the textures inside the class, once they would be binded (let's assume I would have all graphics I need binded this way) disappear when the game is exitted (due to some other background service interrupting it) - basically would the context get lost (like you lose it when you draw stuff with canvas) ?? Cos if so, I would have to reload everything ... which takes a lot, so again is there some better way for this?!

2nd - I have this array of renderables and the rednerer just goes over it and draws everything in it :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. renderablesLock.lock();
  2.                 for(DrawSquare square : renderables){
  3.                                 square.draw(gl);
  4.                 }
  5.                 renderablesLock.unlock();
Parsed in 0.010 seconds, using GeSHi

Now some of these squares aren't being drawn as I have this field visible in them, depending on which they are drawn as I thought that for instance, in a menu I will have a button, button pressed and button disabled image. Now all of them would be in the renderables array, but some wouldn't be drawn if they're not supposed to be visible. Question is, is it better to poll over all items of UI and draw only the ones currently there? Obviously this seems totally better as I might have loads of stuff not being drawn, whereas if I poll over all items currently on I get what I want - but the problem is that these items would have to be retrieved from my map (something like map.getMenu() which would return all objects part of the menu), so is this really better? I think it is, I will try it later, but just wanted to know whether anyone has any thoughts on this.

3rd of all, recently I've been getting some errors inside the GLThread (which I can't lookup in Eclipse cos it has no source attached) due to a nullpointerexception - what can be possibly going wrong for me to be getting this?! This happens btw, when I try to click something on the screen and move it - so that's why I also assume something with my input management must be wrong - but on the other hand, what could cause the GLThread to get this exception and crash the app?!

I would appreciate any help in answering any of these questions, especially the last one, as I can't keep on improving stuff cos of it.

Thanks in advance!!!
Posts: 8
Joined: Wed Feb 23, 2011 3:50 pm


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests