DESIGNING our GAME ENGINE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey look guys my name is China welcome back to my game and in the series so last time we talked about what exactly a game engine was make sure you check out that video if you haven't already and before we begin I just want to give a huge thank you to all of the patrons that make this series possible you guys aren't supporting this series you can do so by going to patron up on 4/2 Cherno to get access to these videos like a week early as well as plenty of other cool rewards such as being involved in the planning process of these videos and finding out information about where this is going and actually influencing whether series goes as well so huge thank you to all the people involved in that so today what we're going to talk about what I thought we would talk about is actually just kind of going through some of the different things that are going to go into this game engine because we actually do need to plan what we're going to be doing right I've even got a little bit of a notepad here that I'm going to draw stuff on so that can kind of really explain to you guys where this series are going to go what we're going to do over the next few videos and how I'm going to actually structure all of this and what does this even look like so to build a game engine first of all first and foremost is not an easy task right it's actually quite difficult to build a game engine because if you take a look at just game engines kind of in the wild or game studios and how they kind of relate with game engines you know that everyone except the largest of teams really usually goes with an already made game engine and if a team does decide to build their own game engine it usually requires a lot of resources which is why it's not the best idea to kind of choose to kind of write your own game engine if all you want to do is make a game because there are other resources out there there's no real reason for you to actually do everything yourself that being said because we're not a massive team and because it's really only just me I mean I really want you guys to contribute but obviously understandably I don't think that Israel is túcume to depend on consistent contributors you know who aren't professional engineers who I'm paying so because that whole thing doesn't exist it's really up to me to build this thing and direct this thing so I have to be reasonable with my story I can't say that we've been built unreal I can't say we can build unity or anything like that that's just completely crazy right and I'm here to actually try and make a game engine that will exist maybe you know within the lifetime of the viewers who are watching this series so because of that is a bunch of compromises that I have to make and what I kind of take this slowly and kind of well by take this slowly I mean we're going to end up iterating quite rapidly over certain features and what I mean by that is we're going to focus on building up the minimal groundwork we need to actually get something working and then we'll iterate over it and improve it and add more features and have more stability and more performance and optimization and do things like that we're not going to try and write perfect 100% complete and powerful extensible code from the beginning because that would take us like a year to actually get to the point where we have an application stack like on a window and all of that because you know we'd have to do it so perfectly we're gonna can I cut that out we're gonna rapidly go over this stuff and I'll just you know probably end up just improving code over time as well as you guys will contribute and help with that as well so it's kind of a basic idea of how the series is gonna run the compromises that I'm making we can get into probably when we get to them I don't want to kind of spend today talking about you know along the entire platform of what the game engine is this is the stuff that I'm not going to have because if we start talking about that now it's going to take a while and it probably isn't going to interest to many people but I mean things like having like a level editor like the level editor is going to be built into the game engine it's going to exist in the game engine runtime I'm not going to go ahead and build an entire stay sharp WPF application that has its own kind of you know it's a full standalone like Windows application that just links in with the game engine and another live stuff because that's just that's just on the face of what's gonna take way too long it would be the kind of my recommendation for if you had a huge team I would probably do that right but because we don't have that we're going to just end up kind of building a level editor out of like I am GUI or something like that within the game and in itself and then that way be all kind of sable floss and it won't be the best solution but it will be something that is achievable by us that's an example right shade a compilation is another example like we could like ideally we'd write our own shader language and then have that compile to like you know metals method to metals shader language to like you know GLSL to hlsl to all these kind of shader languages based on the platform that you're on and that would be an amazing system that would probably take a year or two to build right so by one person so it's not something we're like we have to make compromises along the way and I just want all of you to be aware that even though I really want to build an amazing engine this series I let you like during I guess this series is to build an amazing engine I have to be realistic with what we were able to achieve now that being said there's no reason why you can't go back and then later add those features right it's just that when I'm talking about what the core technology that we're building will will entail like I have been quiet brutal maybe with kind of some of the compromises that we're going to be making because you have to remember that apart from the fact that I'm one person building a game engine I'm also I also have a full-time job building game engines for EA and also not only that but I'm not just building an engine in my spare time I'm teaching everything that goes into it I'm planning I'm doing all this kind of stuff so because of that it kind of ends up you know not being as efficient obviously if I just sat down for like you know tiles a week or like two hours a week and actually wrote code because if I did that I'd have an engine in no time since I have to teach all of this it obviously does take its toll in terms of time and efficiency anyway enough about let's actually dive in and take a look at what a game and it actually has what we're going to do and like basically plan out our roadmap for the next few videos and this series now with planning's I am going to have a major kind of design episode probably before I begin a massive new feature for example before we start building the renderer we're going to plan out exactly how the API is going to look for that look for yeah so what the API for that is going to look like how we're going to actually build that thing and just the semantics of how everything's going to work so let's dive down and take a look at in the next few videos okay so I really do want to kind of provide some kind of overview as to what our game engine which by the way does not have a name at the moment as of me recording this video maybe out maybe I would have come up with one by the time everyone sees this but I don't have a name for this engine right now so if you have a name suggestion drop it in the comments below because I'm gonna have to make a github repository pretty soon and that needs a name obviously so if you have any name suggestions for the game engine just drop a comment below and hopefully we'll come up with something pretty cool okay so game engines right um let's start off by just kind of talking about exactly what goes into them so the first point I want to kind of make is that we need like an entry point and an engine should provide some kind of entry point now an entry point is essentially when we launched our application or our game that's been made with this engine what happens right this is something that a lot of people overlook like they don't really they think okay well you've got your main function and you're done well yeah but like what happens with that like what controls where the main function is what controls the code it gets executed with the main function is that something the client controls of the game controls or is it something that the engine actually controls and maybe we kind of implement by either a macro or it gets imported somehow what happens with that when we if we break this down to primitive building blocks when we launch our game or when we launch our engine what happens right what controls what happens that's what the entry point is all about once we kind of dealt with that we have something called the application layout or at least that's kind of what I call it and the application layout is just really a section of our code that deals with application kind of life cycle and events and stuff like that so for example our run loop right what keeps the application opening and rendering frames right what keeps the time going forward what execute all of the code that our game wants to execute what about events what about things like windows being resized or like closed or input event like mouse and keyboard right all of this kind of stuff is dealt with in the application land we need a way to basically run our game or runner running our engine as an actual application on whatever platform it's going to be on that's what the application layer kind of fits in from that I kind of want to go into the window layout now this is kind of a interesting part of the engine because if you think about a window really a window is only something that exists on desktop platforms like Windows Mac Linux they have windows and as you kind of if you've done done any kind of programming before if you look at something like the OpenGL series that I have on my channel as well you know we create a window that's kind of one of the first things we do in our actual application we create a window because that's going to be the target for all of our graphics rendering as well as you know where kind of input events are gonna come from this is our entire application is that window right one of the platforms like mobile platforms it's a little bit different it's more or less kind of like a surface because the app that you've kind of given an app prompt and creating an app and console platforms kind of similar as well so I'm really kind of talking about desktop platforms when I deal with window layout stuff but because we are primarily going to be targeting desktop to begin with and we'll talk a little bit more about platform support and rendering API support and all that stuff later in this video but because we're gonna be primarily dealing with that we're gonna have a window layout and and inside that window layout we need to deal with things like input and events so input kind of gets put into events so our event manager will handle inputs what we'll handle input events that get kind of picked up by our window and our application now event managers are kind of a really important thing as well we're gonna build one that kind of funk functions on a very basic kind of messaging and broadcast system which basically just means that certain kind of layers in our application can subscribe to events and get notified when events happen by the kind of application layer stack when that happens events will get propagated to those layers and the layers can kind of choose if they want to propagate them to things like the exponent system which will also so that's kind of how events will work it's just basically a messaging system where we get interrupted when it event happened or rather not really interrupted but when an event happens we get notified because our kind of on event function essentially gets called however there's two parts to this because with input events for example yes it's really good to be notified when a case press but also sometimes we want to tip we want to check the state of an actual input device so for example where is the current Mouse position is this spacebar currently pressed right these those aren't kind of a messaging system in tomorrow less us asking the application hey is this state the case right and if so what to do something there's kind of two parts to that which again we'll discuss when we plan out the events and kind of input system from there the renderer is probably one of the biggest systems that we actually have to deal with now the renderer is what actually renders graphics on our screen we basically tell the renderer usually once the frame hey it's time for you to kind of go through your list of things that you need to draw on the screen and actually draw them right by far this is going to be the biggest system at the engine and the most complicated now I don't want to go ahead and say that the renderer is what basically the engineers because a lot of game engine series or like when people teach game engine programming they always start with the renderer there was focus on the renderer and the renderer is just this huge thing that gets kind of built immediately right and I can't really argue with that because the problem is like most likely when you're building a game the very first thing you want to see are colored pixels on the screen right you want to see graphics so of course it's going to be a good idea to kind of get that as soon as possible and for me planning this theory is this was this was a really kind of long like discussion I essentially had with myself and others about whether or not I should start with graphics or whether or not I should maybe get a lot of stuff done and the way that we're going to kind of order this stuff is we're not actually going to get the graphics immediately we are going to pretty quickly have like a basic debugging layer up and you know just the ability to basically just texts and maybe some other GUI kind of elements on the screen in kind of an application case but we're not going to go ahead and build a 3d renderer in the first like a few months probably of this series that's just not gonna happen the reason that's not gonna happen is because festival a game engine is much more than just a 3d renderer right so there's no need for us to kind of rush into that but also you're gonna see how much easier it's going to be to actually build a proper 3d renderer when we have all of the other systems kind of already operational it's just going to be an absolute breeze compared to what it would be if we have basically a raw bare-bones application and we started writing like OpenGL code or DirectX code or whatever immediately that's just that's not a good long-term strategy and we want to obviously take kind of the longest time strategy because we're trying to actually build an engine the renderer you know once we have all that this by the way isn't necessarily a list that's in order so don't think that you know we're gonna do the entry point first an application like win or later this is just kind of all the stuff that's kind of going into this so once we have the renderer I keep saying once we have the renderer as if it is ordered but we basically need some kind of render I'll say render API abstraction which basically just means that we're going to support multiple rendering api's through our engine now to begin with we're just going to deal with OpenGL the reason I've chosen are from GL at the beginning is because I already have an OpenGL stories that people can refer to and also because to be quite honest it is the simplest API out there and it's cross platform meaning that if we decide to have our code run on the Mac and Linux which I would like to get running pretty early on in this series OpenGL is gonna work out of the box if we went with something like DirectX which might have actually been mining my first choice you know it would be first of all more complicated to begin with and I would have to spend more time teaching actual DirectX than writing the code so they don't have a dedicated series for it and because it is more complicated than ours in jail instead of doing all that apart from doing all that I will also need to as soon as we have Michael because I have to implement another rendering API but because our engine will support multiple rendering API is eventually like Vulcan metal DirectX OpenGL all that kind of stuff is important to kind of design the renderer in a way with the API that you're actually using is abstract 'add meaning that when we decide to add an additional render API it's not going to be this whole nightmare rewrite because what we've already said everything up to be pretty much API agnostic obviously some things are going to have to be a yet specific it's not like we can just write a function called upload texture and then that then implement that four times for each API because the way that we want to create a renderer would be different based on the API because Vulcan might be a little bit more efficient at doing certain things if you do it this way versus like the OpenGL way so we kind of do still need to write two code paths not just like every function that OpenGL has let's create a copy of it and then that's not going to work right I mean anyone who's done kind of multiple API programming will obviously know that that is the case but we are going to design the render off from the ground up in an abstraction in an abstract kind of way so that we can deal with that I'm gonna summarize this entire section by saying basically debugging and support now this doesn't necessarily mean debugging as in I'm trying to fix my code but just really if you take the debug word out of that and you think about that what does it mean to add debugging support to your engine or to an application basically M is talking about essentially building a building with scaffolding around it right when we construct any kind of application we need good ways to actually see what's going on and debug it and solve our problems and build something so it's something like a logging system right that's something that might be really simple but it's just something that we need to have and we need to have it so that we can log any kind of data types that we have really easily and with a little bit to files and all that stuff what about performance right we've written our renderer found nasty but it's a little bit slow well where's all the time being spent well in order to work that out we need some kind of profiling system right we want to be able to basically have our application potentially run in the special mode that is outside of like visual studio settings like we want our application to actually do it itself so that we can run it on any platform and not have to worry about you know using certain tools that are available on certain platforms you know we want to essentially instrument the code which means we want to put code into our code that only runs in like debug mode or something like that which Bay three times every function and says and then you know collects it into like a nice kind of view so that maybe then we can use some kind of tool to actually look at that and see okay pull in my render function I can see the text route putting on the uniform binding is taking up the most time maybe I've written that Foley maybe I need to optimize that right that's a good that's something that's so important to have that people just kind of don't think about because of course if you're writing a simple application you might not care about that stuff but since we're adding something serious here we want to have all these systems available to us because they'll help us a lot out in the future I'm gonna kind of accelerate through this a little bit because I feel like this is videos dragging on and as we come to other features we'll deal with them but stuff like scripting you know we want to have like Lua or some kind of lead to c-sharp and - I don't really care at this point I haven't decided but want to have a scripting language kind of built in so that instead of kind of dealing with dealing with C++ code all the time we can actually write scripts and much higher level languages that even like artists or content creators can write easily without having to think about stuff like memory speaking of memory we obviously want memory systems I mean custom allocators and memory tracking because our memory systems because memory is a huge deal for performance and also a resource that we really do need to manage well and when it comes time for debug certain things as well memory usage and perhaps even like CPU time spent on memory allocation is something that we obviously want to kind of be able to inspect and minimize as much as possible an entity converting system or kind of an ECS is as well think that we need to have an opponent's system which isn't ECS this is just a way for us to be able to kind of create game objects in the world and then kind of modularize them like be able to kind of include certain components include certain systems - each kind of individual and see your game object we have in our world so they've been kind of define its behavior and what actually the engine deals with in the first episode I talked about the fact that game engines are really just Datuk transformation machines where basically we just taking data and then the engine does something with them well this kind of entity component system is a way for us to say I have this object in my world I want you to draw it as I want you to draw it this 3d model at its position right at its transform I want this script to be attached to it so that it can bounce around the room or something I want you know I want it to have kind of a physics material so that it can actually interact with physics and all that stuff I want it to play this audio you can't get a point right it's just a way for us to be able to define what actually the engine does with an entity that we have right when we launch into a world or a scene or a level or something like that we want to be able to load in all of our objects and then say well what actually happens to them how do they work you know what is the engine supposed to do with all this data that's coming in and that's kind of essentially what an ACF is speaking of physics we want some kind of physics solution will tell what that probably a lot later on I think that's about it I mean well you know obviously there's like file i/o and stuff like that and also like a VF s which is a virtual file system that we also want to talk about later and design I think that's about it I mean you know obviously we'll kind of have a build system as well and custom asset types so if we have a 3d model or a texture we have like 3d model or 3d models or textures that get authored by content creators we want to be able to convert them into a custom format that our engine that is optimized for our engine so that we don't have to waste waste time transforming that data into our data at long time so we can kind of do that offline put into that by building our asset offline and then it's really just really simple and easy to actually kind of just boot up our game and everything's in the right format and everything is the best so we definitely need that um as well as what was the other thing I was going to mention with that yeah hot-swappable assets right so we want to be able to you know change you know modern we want to have Photoshop open we want to be able to kind of draw something on our texture in Photoshop here ctrl s we want our build system to pick that up and build it and then reload that into our game while it's all running in real time so that we can kind of update stuff even like a 3d model we can just kind of tweak some of the vertices or you know modify it in some way and it should just ha swap right into our engine so the we can kind of make changes to it while the game is running that's not a really important system but again probably isn't really that worth talking about right now but it's just something some of the stuff that's kind of I'm planning to actually go into this whole kind of engine and project of a building anyway looking at the list I think that's about it I haven't covered any specifics just kind of high level systems the way that this series is going to go is next time we're just going to start a project as you know I am a full-time software engineer today so I don't have a billion years to make this series so the best way for me to actually do this is we're just gonna start writing code I'm gonna start explaining it and wherever there's wherever I write code that warrants a specific explanation I might just make a video where I kind of draw diagrams and talk about it in one detail after it's actually being done but the point is that the best way to actually write this massive engine and this overwhelming amount of work is to actually start writing it instead of spend a billion years talking about it that being said the code that I write will mostly be live I will have already written when we get to more complicated systems like logging for example I've already got I will have already have had kind of a logging solution ready to go that I will essentially just kind of write for you and explain how it works right and that kind of code it will be available on a development branch to patrons ahead way ahead of time so that's a really good kind of thing for me to do because that means that since it is available to patrons those people can kind of read through it help me out point out some flaws maybe say that all this is way too hard to use you know maybe you can simplify the API or something like that and we can find iterate over that before it actually makes it into production and into these videos which is another reason why I really need your support so that's kind of exciting and that's kind of the way the series and I go so next time we're going to make a project talking a little bit about the constraints of this series I guess or kind of the way that this is going for now we're just going to support Windows only and we're just going to spawn up in jail only I will write all the code with other platforms in mind meaning I'm not going to just write everything you know like my application dot CPP file is not going to contain a Windows code in it like win32 API code in it right because obviously the engines going to support other platforms in the future so I am still going to abstract things and make sure that I actually divide on your platform specific code or render a key a specific code to its own kind of files that will not be compiled on other platforms or if we're compiling for other or rendering API is that battle is going to be taken care of don't worry but for now we're just making the assumption that this is Windows only and we're going to be only dealing with OpenGL okay that's gonna basically hurry this up so that we can actually have an actual product an actual project like a an actual thing in our hands before we actually go ahead and start moving on to more complicated things because right iterating over this is by me the best way to actually have this done so we're also not gonna deal with like kind of pack like build systems or you know like say may for anything of that at all for now because that's gonna be that's just not really necessary once we do start talking about other platforms whenever that might be we'll deal with those things when we actually get there and I hope you guys enjoy this video if you did you can hit the like button you can all support the stories by going to patron that the channel this is such a huge like series I mean even me talking about it right now I didn't script this video or anything I just had a few nights off to the side I like this is like the by far the biggest project I've ever done in my life I'm going to need so much help from you guys but it's such an exciting thing I don't think anyone needs to actually done something this detailed and this kind of highly produced I guess quality wise so I'm really looking forward to being able to do this for you guys as always you can help support me by going into that linked pattern I hope for such the channel I can't wait to see you guys the next episode where we actually start writing for it see you guys later goodbye [Music] you [Music]
Info
Channel: The Cherno
Views: 144,696
Rating: undefined out of 5
Keywords: thecherno, thechernoproject, cherno, c++, programming, gamedev, game development, learn c++, c++ tutorial, game engine, designing our game engine
Id: etdSXlVjXss
Channel Id: undefined
Length: 26min 33sec (1593 seconds)
Published: Sun Oct 21 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.