Physic Thread

Hi, I am trying to combine StandardGame with jme-physic2 in a seperate thread:

I may have many questions!

Thread updateT = new Thread(new Runnable() {
  public void run() {
      while (!isTerminated()) {
        results = PhysicsWorld.getInstance().update(tpf);
        getCollisionQueue().addAll( results );
  } });

first  the update method does return anything... so what is the result? and I d'ont either see a getCollisionQueue()... has it disapeard in Physics2 or am I not looking to the right place?

then it is about tpf the timer it is private in StandardGame so i first just put tpf at -1 in the update but it was not working at all then I just copy paste the StandardGame and put the timer as protected and used it... it works better but only if the physic Thread has a better priority the the openGl thread... sound logic but according to DarkProphet it was better to give the physic thread a MIN_PRIORITY

My question is: is there a reason for the timer to be private? and if yes can I acces to it with Timer.getInstance() even if it has been initiated with a nanoTimer??

and to finish it is about the timeUntilNextUpdate is there any value that should fit well? or can i just apply a value according on how precise i want the simulation to be?

thanks for reading this up to the end, Thomas

I can't tell you anything about StandardGame - I did neither use it nor did I even have a closer look at it. Same goes for getCollisionQueue() - no idea where this comes from.

But collisions are most comfortably handled with input handlers in jME Physics 2. Which can also decouple threads. Have a look into the tutorial lesson about collision events.

Well, you very well might want to run physics in the same graphical thread (which I would consider perfectly reasonable, but there are other valid options as well that will work with StandardGame).  You might simply consider creating your GameState for physics and adding a Controller to the rootNode (BasicGame has an accessible rootNode) that updates physics (this would give you access to the tpf directly).

Otherwise you can define your own update thread that determines tpf itself (which really is pretty simple).


I am considering using a GameState for physics but I still want to have the physic engine in a seperate thread… a gameState doesn't seems to create et new thread is it true? so what i should do is to create a PhysicGameState, with my physic thread in it or that implements Runnable with a field tpf and each time update(float tpf) is called i just update the field tpf…

am i right?

Pretty close. :wink:

Play around with it and I'm sure you'll figure it out.  StandardGame is pretty straight-forward so feel free to steal code as necessary. :slight_smile:

Ok thanks a lot I already try to implement what I said and it seems to work well