Hey there, I'm new around these parts, and to the subject of game development itself
Over the summer I'm going to spend some time, trying to write a very basic game engine, using C++. My plan was to build it in such a way, that you have a application class, which contains everything about the game (such as game logic, objects and so on), and an engine class which takes a application object, does stuff with it.
However no matter how I try to organize it, I seem to keep running into the problem, that everything needs to have everything else passed to it. Being a mathematical engineering undergrad, most programming I have done, has been aimed at very narrow tasks, so I'm not sure how to have handle this problem. I won't hide, that learning some OOP along the way is also a major goal of this project. Anyway an example of the problem:
The engine class which are responsible for the main loop, is meant to use a fixed time step. It has a “time” class member object, responsible for keeping track of time, both between frames, and between updates. However even though the update uses a fixed step size, I still have to pass that step size into the update / render function, in order for it to be used by the game logic / physics / whatever. These in turn will have to pass it again, to all the components etc etc. This might seem trivial, but it to me it looks like its going to be a a recurring problem, as there will probably be more things than just time, which most things will need to know. As far as I can see, it can be handled in one of the following ways;
- Pass the variable everywhere. This is what I don't want to have to do, as I expect this approach will quickly get out of hand, as the project expands.
- Hard code the time step into everything, which seems obviously bad.
- Use a namespace for “time”, rather then a class. This is bad OOP practice, as far as I can find online.
- Use a singleton, which again the internet says is bad.
- Pass a reference to the Time class or a shared pointer to everything, which will bloat all the classes, and still not avoid having to pass it in some capacity, which also seems bad.
So how do I handle this in a good way? Keep in mind I do not have any grand plans for this project. My hope is to make something somewhat flexible and simple, but the main goal is to learn. If you have courses to recommend, or books on C++ / game design, those would be appreciated as well. However I typically learn the most by doing, so while its probably not the most efficient way, it is the way I will actually learn something, whether then nothing.
DISCLAIMER: English is not my native language. If I'm miss using terms, or explaining something inadequately, feel free to correct me.