Game Engine Systems - Cross Platform Game Engine Development

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys welcome to the second lesson in my cross platform game engine development course um in this lesson i'm going to be showing you how we're going to be bootstrapping our projects and providing our various engine subsystems to the clients to be used using the surface locator pattern that i touched on last lesson by the end of this lesson we'll have an extensible game loop and everything we need to start rendering to the screen and as i like to say a good person always cites their sources so the entry point code is mostly taken slash inspired by the churnos game engine series entry point the service locator pattern i lifted directly out of the game programming patterns book and finally the overall architecture of the engine moving forward is informed by the game engine architecture book so links to the cherno and the books themselves are of course in the description down below so with all that out of the way let's jump into this video where we'll implement our initial systems okay so the first thing that we need is we're going to take this main function and we're actually going to take it out of our client completely so that we can control it in the future this is specifically so that for example let's say we want to uh at some point migrate to using win main instead of maine we'll be able to do that and the client will not won't have to know about it so you might notice that i've switched to sea lion instead of visual studio i'm going to work in sea lion this episode and probably move to visual studio next episode full disclosure i like c line the best i think for c make applications uh you can't really go wrong with c lion so anyways we're going to add a new uh file to our include uh folder here and we're going to hit new and we're just going to make a header file we're going to call it entry point dot h and we'll make sure to add it to git so what we're going to do is we're going to do a few things so the first thing is we are going to expose the ability to define a new application to the client what we're going to do is we're going to write our main function so we're going to write in main and into rxc and car rp now what this is going to do it's going to create the application it's going to run the application and once it's done delete the application all right so that's where where our main is going to be in now what we're going to want to do from there is in our main.cpp uh let's just take this and just to show just to get what we had before let's move that over let's actually uh put that in move these up put that inside here and move this into our main function all right and then with that done what we will go inside our main.cpp what we're going to do is we're going to include uh youtube engine slash platform slash entry point dot h now in theory that should just launch our application it builds and when we hit play we get the same window we had before so now our engine is providing a window to our client right and it's the exact same one we had before fantastic so now what we want to do is now we can bootstrap whatever we want into our main application right so what are we going to want we're going to want a application class or we can call it the engine class but let's call it game actually let's uh let's make a game right so what we're going to do is create a new class in our platform include we're going to right click new c plus class and we're going to call it game and this is what i like about the type snake case is that this is automatically going to lower case everything and what we're going to want to do from there is take our game.cpp and actually move it into our platform folder here uh once you add files and see lion i should note uh you want to right click and hit reload cmake project and what that'll do that'll make sure you'll pull in any of the includes so that you lose all the warnings and everything works properly so we have our game class here and we have our game.cbp here what we're going to want to do is we're going to want to give access to our main.cpp our our client we want them to be able to create their own games using our engine so we want them to be able to define their own game class right so what we're going to do is we're going to provide a default constructor for game just because we should and we might as well do a default d structure as well right so we are going to define as external uh function that returns a game pointer called create game now what we're going to do to make sure that this is working is we're going to go into our entry point.h uh we'll first we'll uh make a new section for headers for stuff we're going to keep we're going to include here youtube engine slash platform slash game header and just the first thing we're going to do here where it says create the application we're actually going to say create the game and we're going to say auto the game equal create game now if we build this now it's going to complain that um it might not even complain yeah it's going to complain that the game create game has not been provided so what we need to do here is go into our main.cpp and we're going to start creating our game uh in the as part of the client application so we're going to say class uh let's say youtube game [Music] and it's going to extend uh first we're going to need to include youtube engine platform game.h which actually probably didn't need to but it's good to be explicit and we're going to send game and what we're going to do is we're going to create a new constructor called youtube game it calls the base constructor and what it's going to do it's going to say hello youtube youtube game so that's going to be our base class for now we're going to extend this over time um it's probably even a good idea if you're planning on making a actually using your engine you're going to want to separate that out into its own class and stuff but for now this is good but all we're going to need to do to actually use our game runtime is we are just going to declare it here game star create game return new youtube game now if everything went as planned what's cannot cast youtube game to its private oh whoops public game there we go so if everything went as planned what's going to happen is it's going to include entry point oops let me go back let me go back to that it's going to include entry point.h which is going to be the main function the main function is going to open the window and then create the game create game is an externally defined function with that is provided inside the client here where youtube game is being returned and created so in theory we should see hello youtube game show up when we hit the run button and when we build that you'll see all the errors go away and when you hit play it didn't work why didn't it work oh that's my fault here so that didn't work because we put this after our main loop here so let's um just move all this down because we're going to be replacing that in a bit so we'll remove this hello world because that's basically what we're doing and we hit play on that now and now we should see hello youtube game all right and then we see hello youtube game now what we're going to want to do at this point is we're going to want to um have all this window logic uh abstract it out or at least not inside the main function we're going to actually make sure that it's running within our game dot h or our game class so the first thing we're going to do is create a couple of default uh a couple of constructors that we're going to want so there's going to be the base constructor which we're actually going to implement and there's also going to be uh game string and we're going to want to include string and we're going to call this a window title so those are constructors uh other than our main constructors what we're also going to want to do is have a run function and this will run we'll run the main application or run the main game and that's probably probably all we need for now in function wise anyway in our private functions we're going to want some private stuff we are going to want a void initialize services and void shutdown services so this is uh the basic structure of our game application it's going to build the application where it's going to initialize all our services and then when everything is done at the end it's going to shut down all the services so let's uh let's generate all of those lion has a has a bunch of of warnings built in which is one of the reasons i like it where it's going to tell us stuff like we should mark that explicit so that it's not automatically going to convert something to the string that you've got to have something yeah it's got to be explicit build that we'll build the run function we'll build initialize services and we'll build shutdown services all right so the reason we're overriding this base constructor is we're going to give it a default window title by calling the other constructor game uh let's say new youtube engineering game and within our other constructor what we're going to do is we're going to initialize our services now i just noticed that we're not storing the window title anywhere so what we're going to do is we're going to create a title and make this window title and we'll go back to our game header and what i like to do here i like to separate my variables from my functions so i'll just do that and then here what i'll have is i'll have an std string oops string title and what that'll do that'll make it so that when we come in here oops where did it put it oops [Music] so sea lion didn't like that since we'd since we defined our create game in this function it thought that all of our game functions belong there as well so i just moved that to the game.cbp so here again it says pass by value and use scz move and i am pretty sure that's that's what this does right so notice how earlier it said um that it should be a const reference but then uh after i i used it as an argument it said hey maybe you should use move semantics and you know what that's probably what we should do so that's what we do here do there if you're interested in move semantics and how all those work eventually i plan on making a adding that to the c plus course that i am building so uh another thing that we're going to need that i just realized is a running variable so for in order for the game to run and to know when it should stop running we're going to need a boolean here and we'll call this running and here inside our game.cpp we will running true since we wanna we want it to start running immediately so what does what is initialize services going to do what it's going to do is it's going to provide a window so it's going to create a window and provide it for us so um we made this beginnings of that last time let's look at what we did so notice how we have a provide function here uh where are we calling this we're calling it in engine youtube init right so let's go into our engine and this is what we're doing so instead of doing it here what we're going to do is we're going to copy this and we are going to go into our game.cpp initialize services and we're going to do it there now i don't like the name custom window but first let's include our service locator uh youtube engine platform service locator [Music] so i don't like the name custom window so we call it custom window here just because it was a glfw window what we're going to do we're going to rename this we're going to call it windows window or call it multi-platform that's more descriptive at least multi-platform window that's much better and in our game.cbp it should have been here so now we can include youtube engine uh not youtube engine what we will include is glfw window actually let's rename that as well so refactor rename multi platform window dot h now what this does the reason i called a multi-platform window is because in theory glfw should work on every platform so hence multi-platform but let's say for some reason we're getting we're getting problems with glfw and we want to go pure native windows window on windows this will give us the ability to do that so we'd be able to do like uh if def windows and then end if and then provide a windows window here right so but we're not going to do that we have a we're going to make a multi-platform window and we're going to uh multi-platform window.h and a new multi-platform window so we've provided a multi-platform window great that's everything we need to do inside our initialize services now inside our shutdown services um so inside our service locator dot h we've got a provide function we also want to give it we're going to say static inline void shutdown services right and then we are going to say let's just say shutdown window so in shutdown window we'll go static inline void shutdown window and all we need to do is window.reset which we'll call the windows destructor and we will just set it to null pointer so that's all we're going to do for now what that's going to do is it's going to call our window class and then call the destructor on our windows class which is window class which is not really being done so you'll notice here again last time we said virtual void virtual bull i personally like to leave it there but in c-line they'll tell you that virtual is redundant so if you wanted to because because it says override we know it's a virtual function right so we'll we'll just follow sea lions and directions there all right so what we're going to do is now inside our game.cpp uh we we can call our service locator shutdown services and that will shut down the services when we want it to so we're going to take initialized services shutdown services what we're going to do now is we're actually going to implement a destructor and let's put that in the correct spot right under the constructors where i like them to be and in here i will call shutdown services done so that those are being called those are being used and now finally what we have left to do is set up our run function so our run function is going to be very similar to what we are doing to inside our entry point so youtube engine init is no longer being used that was just uh demonstration purposes last time so we can delete that we can delete our engine.h [Music] and we can delete our engine.cpp so now that we've gotten rid of engine.h we'll delete that what we will do is move some of this stuff into our loop inside our game loop so when we run we are going to open the window and then we are going to go into the game loop now what we did before is we went into an endless loop that just that triggered only off of the um the window state right now you if you might not only be the window that wants to shut down the application so we've actually got to separate this out and that's what this running variable is for so we are going to say while running [Music] and then we're going to put an if it's going to update the window and do anything it needs to do and if the window requests to be closed we say running equal false and then we'll continue and that will exit the loop and that's how we'll have our window open so we'll open the window open the window and then run the application now you can start seeing the structure of what this is going to look like you're going to have here inside our wall running loop you're going to have a it's going to update the window then it's going to update game state then update physics and then and draw right it's going to do stuff like that and then inside initialize services it's going to like provide a window it's going to like initialize input system and it's going to initialize initialize the renderer and all that kind of stuff right so we've got a fairly a fairly extensible system now and the last thing we need to do is that in our entry point dot h we are going to call the game run and this will run run the game uh let's and then once we're done we're going to delete the game um we're just going to delete the game so what delete the game is going to do it's going to destroy it and call the destructor that we implemented which is going to then shut down all the services and shutdown services um the reason we abstract it out is to make sure that we can ensure we shut down services in the correct order usually it's going to be in the opposite order of the way you initialize them usually opposite order of initialize so yeah that's that's what we're going to do [Music] so in theory that should be everything we need so let's hit the build button see if there are any errors there are there is an error engine.cpp so if you get that error what you're going to do is right click here and hit just reload cmake project that's from the fact that i deleted the engine.h and engine.cpp but um the k the cash so i almost said cash like uh like the cherno bad influence cherno yeah just reload the project and build and that should solve that issue now if we play uh what happened so it says hello youtube game it went up it ran while running running if oh probably this uh yeah so if it requests to close then it closes so remove that and not it does fine and now we have an application running um within a scaffolded framework doing justice one thing before we actually move forward on what we're going to do what we're going to do is i'm going to show you how this is going to be extended in the future all right so what we're going to do now um to show you how this is going to be extended in the future what we're going to do is we're going to create a protected section here protected section and what we're going to do is we're going to declare a virtual void update function flow delta time there now what that's going to do is it's going to this is how our updated game loop is going to be called so and this is where you're going to hook into the rest of the engine on the game loop right so let's say um you need something to be done on the physics step you would do like a physics update right physics update all right so let's let's add those um now what we're actually going to do is we're going to make um we're going to make physics update and update um we're not going to make those pure virtual because what we want to do is uh make it optional to override them basically so with those done we're going to go into our game.cpp in our update loop and inside our game say for now we're just going to say update uh 0.0 f because we're not we haven't put a timer inside but that's how you would you would pass in delta time you would say uh calculate delta time and then you would pass in delta time here right so we have delta time and what we're going to do now is inside here we are going to say vert in our protective section virtual void update float delta time override now it's going to tell me probably that virtual is redundant yeah virtual is redundant there we go and in here we'll say stood code i'm updating now in theory that should just print i'm updating over and over again there you go you can see it happening [Music] close that everything's good now that's the basics of uh scaffolding our game engine where we you can start to see how it's all going to come together a little bit um so the if you want at this point you can actually implement a delta time here so you can actually calculate calculate your delta time here and you could do some ascii stuff inside here and you'd have technically an engine that just gives you a time between frames right and that's basically the beginnings of a game engine one more thing that we're going to do before we start doing this is we're going to extend open window here do we want to extend it there no we've got the title here yeah so so why not let's just extend our open window here to take a string but first what we're actually going to do is we're going to add a struct that we're going to extend so instead of here we're going to have class window we're also going to have a class a struct called window data [Music] which will hold a string which is the title where it's going to hold the un32t width and height let's just stick to that for now we can extend it later then we are going to pass in a window data data and then inside here we're going to override this [Music] and we're going to say data.width data.height data dot title done now in our game.cpp we can do this height equal 800. title uh width equal 600 uh this should be 800 600 and i believe which one was first i believe this is supposed to be in order but let me just title equal i um run uh title now you're gonna notice here this yells at me c plus plus requires field designators to be in the specified declaration order so um we know i know the order so it's supposed to be like this now in theory uh what that should do is it should create a engine with new youtube game engine right string is not a member oh would probably help include string [Music] will that work what is the problem now tlfw create window oh uh so cast with uh [Music] what is the problem now and this needs to be dot c string done now does that work yes that worked so now if we hit play on that new youtube engine game which is exactly what we want and finally to show it going from start to finish uh one and i'm going to take off this update um because we don't want it to keep on doing that but we are going to say youtube game and what we're going to do let's see string title and title we go and what this is it should be marked explicit let's do that and what's this oh and we want to use move semantics now youtube game exactly what we needed so there you have it um we are now from our main.cpp creating a game passing in our the game that we created and using our framework to initialize all the values and run the game loop which is seen by this update function so um that's everything for this video now hopefully you're not too disappointed that we didn't get a get too much else done when you're building something big sometimes you're not doing fun stuff so we start with this and next time we will go into um adding the very basics of vulkan where we are going to get the screen uh the window we are going to get our window um clearing to a color exciting stuff right so uh tune in next time where i'll go through that and we will get all that running well thanks for watching like subscribe all that crap see you next time
Info
Channel: Ozzadar
Views: 453
Rating: undefined out of 5
Keywords: Game Engine Systems, 2d, getting started, godot engine, game development, game dev, game engine, best game engine for solo developer, gae engine systems, game engine development, cross platform game engine, cmake, cmake game engine, engine subsystems, cpp game engine, vulkan game engine, cross platform game development, linux game dev, mac game dev, indie game dev, cpp game dev, c++ game development, c++ game engine
Id: 8jonuuVH-1c
Channel Id: undefined
Length: 32min 37sec (1957 seconds)
Published: Fri Jun 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.