Sign in to follow this  

game loop

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I think this depends on your type of game? Are you looking at something with a Large AI? (unlikely, we're talking needing a long loop) or are you looking at "if the guy is there and I can shoot, shoot) Likely just make a quick function that has all the enemy possiblities, tests and though patterns?

Share this post


Link to post
Share on other sites
Since we are at the topic of the game loop. .....
There is a rule for us programmers ( eerr.. actually YOU programmers! ) not to have our functions longer than the size of our window and be able to see them without scolling our window. But in a game loop there are many thing to do, so you know that the loop ( not even the function ) will be longer than what the screen can show. Should we care?

thanks...

Share this post


Link to post
Share on other sites
Quote:
Original post by valla2
Since we are at the topic of the game loop. .....
There is a rule for us programmers ( eerr.. actually YOU programmers! ) not to have our functions longer than the size of our window and be able to see them without scolling our window. But in a game loop there are many thing to do, so you know that the loop ( not even the function ) will be longer than what the screen can show. Should we care?

thanks...


Well it's not a "rule" but it's good practice to keep your functions relatively short (maybe less than 50 lines). You can always call other functions within the function to reduce the size of it.

Share this post


Link to post
Share on other sites
Quote:
Original post by valla2
Since we are at the topic of the game loop. .....
There is a rule for us programmers ( eerr.. actually YOU programmers! ) not to have our functions longer than the size of our window and be able to see them without scolling our window. But in a game loop there are many thing to do, so you know that the loop ( not even the function ) will be longer than what the screen can show. Should we care?
You delegate responsibility for those things out to sub-functions. One clear job per function keeps thing nice and simple.

Share this post


Link to post
Share on other sites
Quote:
Original post by valla2
yes.. and the game loop prevents the programmer from doing so...


No, it doesn't. We call our functions from within the loop. We can even have additional loops within the game loop.

Share this post


Link to post
Share on other sites
Ahem.

General rule is, have as many functions as possible. Function is good if you can describe it in one short sentence.

But that produces many function calls and that costs one memory cycle each (a lot of wasted CPU cycles).

I suggest putting "inline" infront most of your functions you know you'll call many many many times in very short periods and give compiler a hint that can really speed up some loops or iterations. Search through web or MSDN for "inline" keyword explanation.

To exclude myself from flaming (again), anyone please correct me if I'm wrong, cause I use inlines often with such designing pattern when doing speed-critical software, ie. games.

Share this post


Link to post
Share on other sites
Quote:
Original post by dark_696
General rule is, have as many functions as possible.


No. Have as many functions as required. You could produce code with a ridiculous amount of functions if you really wanted, but that would be neither efficient or readable.

Quote:
Original post by dark_696
Function is good if you can describe it in one short sentence.


This however, is generally very good advice. It's best if each function performs one specific task, which will generally lend itself well to a single, short sentence description. If you've named your functions well, this should lead to code that is nice and easy to read, as well as very functional.

Quote:
Original post by dark_696
But that produces many function calls and that costs one memory cycle each (a lot of wasted CPU cycles).


You should (almost) never need to optimise on this sort of level. If you do need to, you're probably using bad algorithms and/or data structures. As Knuth said: "Premature optimization is the root of all evil". First, write good, clean, readable code, that does performs the required task. Then, see if you can write it more efficiently. Profile your code, and optimise where there are bottlenecks - usually this will mean a better algorithm for some task. Remember that modern compilers will make many optimisations for you.

Share this post


Link to post
Share on other sites

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this