Many calculations in the game loop

Hello to everyone, I have a doubt and I need help.

I’m implementing some A.I. algorithms (a motion planning and reinforcement learning) in my game, so, it has grown considerably and now that I trying to add collision detection (at bounding level), it takes too much time to detected, sometimes several seconds after that the collision has occurred.

Due to the above, I will like to know if anyone could help me with some doubt that I have.

A game has to calculate several things, some calculations corresponds of what have to be render, the A.I. and others calculations corresponds to the logic of the game, so how I game can calculate all these things and keep a good fps?

Thanks for any help

P.S. I apologize for my poor English skills

P.S.S. I’m working with jme2 due to a need to continue a previous work.

For calculations such as AI pathfinding you should perform them on a background thread so they don’t block the update loop.

1 Like

Thanks Sploreg.

Now I know, I have to implement my AI algorithms on threads for a better work of the game loop.

Just a last question, is there somewhere in the jme3 tutorial or some other place where I can learn how should I structure my game? So I would not make mistakes like these, because I really don’t have a good idea of what’s the best way to code my game so it can grow nicely and don’t become a monster when I try to improve or add more functionality.

Regards and thanks again.

Well it kind of depends on what sort of game you are making: is there networking, is it an mmo, is it a block world, a FPS, RTS… Each can direct your architecture in certain ways. So there isn’t one tutorial or section of the wiki that describes how to design your game. Not that there can’t be, there just isn’t one yet.

However there are some techniques you can use across all of them: controls, threads, app states. These are all very useful building blocks for any game you will make. Some tips:

  • Don’t subclass Spatial and add variables to it (such as hitpoint, jump height, etc.). Stick things like that in Controls or other external classes that then link to the Spatial (your actual model).
  • Use as many AppStates as possible. This will help modularize your code. I have about 7 app states in my game, and I plan to have several more. They are easy to attach and detach when you need certain functionality.
1 Like

Thank you Sploreg, I will try to follow your advice.