r/howdidtheycodeit • u/_gts1108 • Sep 15 '21
How did they code it a game engine
I want to learn how they code a game engine but the is not allot of things in the net Can you help me? Obs: the programing language is c++
0
Upvotes
47
u/bowrilla Sep 15 '21
Well ... there's a ton of information on that out there. So ... did you even try to find some information?
https://alain.xyz/blog/game-engine-architecture
https://www.haroldserrano.com/blog/design-patterns-in-game-engine-development
https://gamedevelopment.tutsplus.com/tutorials/lets-build-a-3d-graphics-engine-points-vectors-and-basic-concepts--gamedev-8143
https://gameprogrammingpatterns.com/
There's even a whole book out there called Game Engine Architecture you sometimes find as a pdf on some university servers
Bottom line: don't write your own engine if you want to actually develop games - it'll take years and won't be even remotely as good as Unreal or Unity and those you can use for free as a hobbyist.
On top of that: if you have to ask, you don't know enough about software architecture to write a proper one. Sorry to be that blunt, but it's just the truth.
20
u/Technologenesis Sep 15 '21 edited Sep 16 '21
I did this for one of my college classes, so I will tell you the path I went down. You can take it for whatever it's worth.
A game engine essentially takes a bunch of game related libraries and wraps them up in a way that is convenient for a game developer. So, internally, the skeleton of a game engine is something like this, in rough order of importance:
You can implement these yourself, use third party libraries, or mix and match. It's up to you to decide what you're interested in diving into.
Around the skeleton goes the skin, so to speak (sorry for the gruesome metaphor but we're too far along now to change it). This is the part game developers will interact with. All these components need to be integrated into a game-developer friendly API.
A common scheme is to have the developer implement a
GameWorldobject which will containGameObjectobjects. Everything in the game will be one of theseGameObjects. Each of these things will expose methods to game developers while, under the hood, they are manipulating the internal libraries. For example, yourGameObjectmight have a method calledsetLocationwhich places it at a given location in theGameWorld. Under the hood, when this method is called somehow theGameObjectitself would have to update the position of its associated mesh in your graphics library, its collision object in your physics library, etc. But this is all abstracted away from the game developer's point of view.EDIT: For completeness, per /u/bowrilla's comment, it's worth pointing out that game engines don't just function as a library. While a library just provides functions accessible to the developer, the engine usually takes control of the program from the beginning. This usually means you, as the engine developer, will write a main function which sets up boilerplate stuff that the game developer depends on. The main function will typically launch into one or more distinct loops that handle different elements of the game. For example, a render loop might draw objects to the screen each frame; a physics loop might do physics calculations and update the game world accordingly. These are often handled in separate threads so that you can keep rendering even while you're doing physics calculations.
These loops will make regular calls to functions that you may not define; these functions are the game developer's responsibility to implement and are responsible for game functionality. For instance, your game might make regular calls to some function of your
GameWorldcalledupdate(dt)that causes the world to advance by some time stepdt. The point of all this is that the game developer is only handling code that has to do with the particularities of the game they're developing; boilerplate stuff like an event loop is handled by the engine. END EDITThis is just a very high level overview with a few starting points; you can read up on game engine architecture for some more detailed write-ups. There are varying thoughts about how to structure game worlds, objects, etc. that you might be interested in as you progress.
2
u/am0x Sep 15 '21
You should watch Jonathan blow’s twitch stream if you can catch it. He has been working on a game engine for well over a year and talks through everything as he does it.
Guy is scary smart.
2
u/create_a_new-account Oct 05 '21
go search youtube
code a game engine C++
3
u/substandardgaussian Sep 15 '21
If you want to make a game, dont code your own engine.
If you think you need to understand the innermost workings of a game engine to make a game, you don't.
If you very specifically want to make a game engine for its own sake (as in, the primary reason you want to do it is simply because you want to), then more power to you!
But it doesnt sound like you have a lot of experience, particularly with googling results, as there are tons of engine-related information and tutorials out there. They rarely go "end to end" just because the topic of the game engine is extremely vast, complex, and modular.
Do you want to make an engine because the act of making one is what excites you, or is it something else? If it's something else, dont go down the path of reinventing the wheel (making your own engine). You're unlikely to even have a wheel at the end of it, but if you just use someone else's wheel for a project you will get a lot farther.
A typical death knell for a hobbyist or even a "serious" indie game endeavor is when the team decides they must build their own engine, nothing but the absolute best customization is good enough for the game! Those engines usually end up half-finished and the game itself usually ends up basically not started.
1
u/detroitmatt Sep 15 '21
this is a really big question and there's no one clear answer
first, what do you want your engine to be capable of? An engine is just a dependency you can use to handle the Most Common Stuff your game has to do, especially stuff like 3d geometry. But if you're doing a 2d game, then your game engine doesn't need to help with 3d geometry.
1
u/Kyle_Is_On_Reddit Sep 16 '21
Cherno Project - cpp gams engine series: Hazel Engine