Answer the question
In order to leave comments, you need to log in
Is it normal that all my code is in an infinite for loop?
In general terms: I am writing a game in cities with a computer. It is essentially infinite, and therefore I stuffed the entire code of the program into a for loop without parameters. Am I doing the right thing or is there a more elegant solution?
Answer the question
In order to leave comments, you need to log in
It's okay, don't sweat it. Thus, for example, all sorts of task schedulers, web servers, etc. are arranged. The main thing is to observe two conditions:
1. Clean up unused memory at each iteration so that there is no memory leak with a large number of them.
2. Provide a condition for exiting the loop in advance. It can also be a simple shutdown of the program through some Ctrl + C in the terminal. The main thing is not to forget to clean the memory here :)
Depending on what language you are writing in, if in some bare C / C ++ - then yes, the event processing loop will have to be implemented independently. And if at a higher level, or you use some kind of engine, then most likely, this cycle is already built in there, all that remains is to receive and process the events themselves.
About the game loop - https://martalex.gitbooks.io/gameprogrammingpatter...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question