Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?" )

Or,

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)

share|improve this question
    
Both are probably used. Are you asking which one is 'better', for some value of better? –  The Communist Duck Apr 3 '11 at 16:02
    
yeah, which one better, and how to prevent infinite loop –  動靜能量 Apr 3 '11 at 16:04
add comment

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
    
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. –  動靜能量 Apr 3 '11 at 16:25
2  
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. –  bummzack Apr 3 '11 at 16:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.