GameTasks Confusion

After reading up on GameTasks, I'm still a bit confused. What is the difference, say, in adding an object directly to the rootNode of a gameState versus using GameTaskQueueManager to do the same thing?

This is how I understand it:



As the OpenGL thread runs (basically your game), it executes the update and render methods of your GameStates every frame in the OpenGL thread. All the content that gets executed this way needs to be loaded and added in a way that is thread-safe, or OpenGL errors will occur.



So how to add things to your game in a thread-safe way for the OpenGL thread? Well one way is using thread-safe methods - some methods can be executed from other threads without worrying about problems for OpenGL. (See incomplete list of safe and unsafe methods). However very many things can still be only done inside the OpenGL thread itself - this is where GameTaskQueueManager comes in. You can use it to insert your command into the OpenGL thread, so that it gets executed there and does not cause problems.



When you add something to the rootNode of any regular gameState without doing it through the GameTaskQueue, then the commands are probably executed in the main thread, not the game OpenGL one. I think it will be still added to your scene but when it needs to be rendered, OpenGL will probably run into problems.



All old-timers are asked to improve on whatever mistakes I made in my explanation - I want to understand this as clearly as possible also :slight_smile:




what mindgamer said was pretty much correct. is really just a thread issue that has something to do with legacy.



openGL is a single theaded operation, it requires certain calls to be in the so called GL thread. however one of java's biggest advantage is multi-threading, so theres no reason no to use this advantage in gaming. in order to update ur game logic in a multi-threaded fashion, u have to put the method calls that involve openGL excution into the original GL thread to make the old-fashioned single threaded openGL happy.



also u might wanna read more on the Callable and Runnable java api to get a better understanding.

But if you are adding only to one gamestate, lets say (just for the sake of the argument), then you probably wouldn't run into any problems if you didn't use GameTasks, right?

You will still have to make sure that all the necessary commands get executed in the OpenGL thread. If you plan to write something not very large, you might want to consider some other game implementations as well… SimpleGame for example… Everything you add there is at once in the OpenGL thread, as that is the only thread it has… it does not offer several threads out of the box as StandardGame does. And no confusion.