nonzerozen Posted January 14, 2017 Share Posted January 14, 2017 My understanding of writing a game loop is that you have to loop through all the objects who need to react and update each loop. Looping though a collection of something usually implies an order of execution. When making a sports simulation game where all the players are NPCs, who gets to move first or last can have significant tactical advantages/disadvantages. In real life we move and act independently and in real time, but with a game loop the NPCs are at the mercy of the developer and the order they choose. So my question is, how do you decide which NPC gets to move/react first? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted January 14, 2017 Share Posted January 14, 2017 Why can't you move all simultaneously? This has the added advantage of making your collision detection better too usually. Having them all act on the same state is fairly easy to achieve, you then apply all the transformations in one go at the end to update the state, reconciling any conflicts at this point. Quote Link to comment Share on other sites More sharing options...
nonzerozen Posted January 14, 2017 Author Share Posted January 14, 2017 I really don't understand. Are you saying I could add some kind of "Can I do this?" step first based on the current state, and then execute a "Let's do this" step to update the state? Please clarify because I can't really comprehend. Quote Link to comment Share on other sites More sharing options...
mattstyles Posted January 15, 2017 Share Posted January 15, 2017 Yeah, exactly, if the order of updates is causing issues then split up the processing exactly how you're thinking. When you first iterate over your list of units they all operate on the exact same state so order becomes irrelevant and when you apply the changes, again, the order becomes irrelevant. Quote Link to comment Share on other sites More sharing options...
nonzerozen Posted January 15, 2017 Author Share Posted January 15, 2017 Right. Because the NPCs are not rendered individually in individual game loops. They are all rendered in the same loop iteration. It doesn't matter which one gets to update itself based on the current state, because they will all update based on the same state, at the same iteration of the game loop. So it really isn't an issue. Obviously. Thanks. Don't know what I was thinking. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.