Does game programming use the method of

1) using time as the main controller to let objects interact with each other, so each step, let 1 object send messages to N objects, and the second object to any number of objects, and 3rd, 4th, until all objects done, and that's it, and display the results on screen (or think of it as just a loop that always repeat, with each iteration considered "a tick in time") (so object 1 call object 2's method, and object 2 cannot call other object's method immediately? otherwise, there can be infinite loop like (2) below. but how do you implement: "cannot call other objects until next time?" )


2) let the objects freely call other objects' methods (send messages to them), with no "Time" concept like the above

Are they both feasible solutions? But what if in (2), you have stones in a circular tube, and stone 1 pushes stone 2, and 2 pushes 3, and so forth, until stone N pushes stone 1 again, then the program will go into infinite loop and not able to do anything else (say if the program is a single process, single thread)

  • \$\begingroup\$ Both are probably used. Are you asking which one is 'better', for some value of better? \$\endgroup\$ Apr 3, 2011 at 16:02
  • \$\begingroup\$ yeah, which one better, and how to prevent infinite loop \$\endgroup\$ Apr 3, 2011 at 16:04

1 Answer 1


Usually you have some separate class that does things like collision detection (collision-solver). So instead of Object A sending a "collide" message to Object B, you have a class that holds a list of all Objects. In one step (or update), the class checks collision for all objects in that list and stops when all objects have been checked.

With this setup it can still happen that if you move an object out of the way due to a collision, it will still collide with another object. To resolve this issue you can iterate the collision-solver several times within one update loop. As long as you have a specialized class that does this, the number of iterations can easily be controlled and infinite loops can be avoided.

  • \$\begingroup\$ hm, can it be Object class having collision detection so a basket ball, grass, tree, all inherit from the Object class and have this capability? This may feel more object oriented as in the real world, atoms repel themselves, not by another class. \$\endgroup\$ Apr 3, 2011 at 16:25
  • 2
    \$\begingroup\$ While it might feel more natural to let every object handle its collision by itself it's probably not very efficient. Your objects need to be able to query the world somehow and they probably need some helper-class(es) to do that too. That means you'll have some data-structure that will allow you to query the world and you can use that for collision detection and other stuff just as well. \$\endgroup\$
    – bummzack
    Apr 3, 2011 at 16:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .