StandardGame newbie question

Hey,

I understand that the game loop is all about two functions:



1- update: update all subnode locations, textures etc …

2- render: draw the rootNode



the loop ends when the game shuts down, right?



well im very confused when i see in some jme examples that node creations are being done in update injections… does this mean that we create a new node on every game update? It doesnt make any sense to me at all



can anyone please clarify that point ?

As the header comments in StandardGame say, the purpose of StandardGame is to provide a better solution to jME's SimpleGame class – and it does this very well – and yes the game loop is all about update (game data) and render (drawing to screen) per tick/frame. 



What examples are you talking about specifically in regard to "node creations are being done in update injections"?  A bit of context would help…

thanks for your reply

well one of the cases is this http://www.jmonkeyengine.com/wiki/doku.php/simplegame_to_standardgame

where



    Future<Camera> future = GameTaskQueueManager.getManager().update(new Callable<Camera>() {
      public Camera call() throws Exception {
        DisplaySystem display = DisplaySystem.getDisplaySystem();
        int width = display.getWidth();
        int height = display.getHeight();
        Camera camera = display.getRenderer().createCamera(width, height);
        camera.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
        return camera;
      }
    });
    Camera myCamera = future.get();  



doesn't that mean a camera s being created on every update?

No, since the camera is being implemented as a Future object it means that the program is going to wait until it is finished being created (in the OpenGL thread) – otherwise, if it wasn't built as a Future object the noted error would occur.



A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be retrieved using method get when the computation has completed, blocking if necessary until it is ready. Cancellation is performed by the cancel method. Additional methods are provided to determine if the task completed normally or was cancelled. Once a computation has completed, the computation cannot be cancelled. If you would like to use a Future for the sake of cancellability but not provide a usable result, you can declare types of the form Future<?> and return null as a result of the underlying task.



See j2ee.me - This website is for sale! - Java software Resources and Information. for more.

Things you put in the Callable in:


GameTaskQueueManager.getManager().update(Callable c)



is run in the OpenGL thread.
Certain things need to be run there since OpenGL is single threaded.
Mostly things that change things about the rendered world, like attaching children to the root node and adding render states (not actually sure which things really have to go in there, but for some things you may get strange glitches or NullPointerExceptions if you don't inject them into the OpenGL thread as above).

You only need to use get() on the returned Future object if you need something returned from your call() method.

Yeh ok, well thanks … I made some tests and came up to this conclusion, injecting to render()/update() will run in the next render()/update() in the OpenGL thread only once … right?

Correct!