Entry Point | Game Engine Series

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys my name is trying to welcome back to my game engine series of the hazel engine series as I guess I can call it now last time we talked about setting up a basic visual studio project and solution all that and actually having kind of a hazel library link against the sandbox application if you guys haven't seen that episode make sure you check it out because that was the first episode in which we wrote any code in this episode we're going to continue on with writing code we kind of just wrote more of a test last time that really just showed kind of how we could interact I guess between that static library or the dynamic library that we built which was our hazel engine and then also the actual sandbox application that we have but it was really rough and today we're gonna set it up a little bit more properly and specifically we're gonna actually start by creating an entry point so let's talk a little bit about what that actually means so when we talk about kind of writing applications I guess there's always an entry point to that application unless it's like some kind of static library like even dynamic libraries have entry points and we can kind of talk about that I think a little bit later in this series as well but essentially our application needs to start somewhere right what is what happens when we launch our application well we know certain code will essentially run and then from there we probably want to somewhat take control and say well okay all of this kind of engine startup code needs to actually happen now there's many different ways that we could do it for example because our and our engine is a dll file DLL files also have kind of a main function so basically we're allowed to call certain code when either we attach that dll process or when we detach it so in other words if for the if our application loads the DLL or unloads the DLL we can kind of hook into those events and just say I want to run this code and that's fine but because we are building kind of an engine that is essentially an application engine as climene sure it's a game engine but what is a game engine right a game engine is a real-time kind of application engine it doesn't just have to apply to games and certainly hazel is not necessarily I probably might not even brand it necessarily as a game engine because it's capable of so much more than that and it will be capable of so much more than that so because we kind of it's an engine on which we can build applications it's kind of important for us essentially to just be able to say okay well I'm going to provide a way for hazel applications to actually create their entry point we could just write a main function in our application in fact if we look over at the code that we currently have we have this application or CBP file which is inside sandbox and that just has many I'll just make this a bit bigger we just have that main function void main and that calls hazel print and all that stuff's fine basically what I'm saying is I don't want this to be here because this means that this kind of how the main function is defined is up to the application whereas this is something that I would like to take control of from the engine side so that's what we're gonna talk about today it's gonna be kind of a simple set up I don't think it will take too long and just as a short kind of disclaimer with everything in the series this series obviously I'm writing as I go and as far as any kind of software engineering project is done this is subject to change in the future so if I decide that actually like let's do it a bit differently like this is not final code in any sense we're running a game engine together I haven't got a game engine written and then I'm just showing you step-by-step how I bought that end product no we're writing an engine together here so obviously things may change over time anyway without further ado let's just jump in and start programming and I'm just gonna show you guys how to make an entry point we're also gonna make an application class that will essentially be a way for us to actually like launch our obligation and define an application inside our sandbox project and we're also probably going to need to get that decals decals spec DLL import and export functions into a macro so that we can actually you know reuse header files and not do what we've done here which is essentially having to manually kind of import this void print thing manually have this function declaration here with the DLL M import and then over here as you can see we had that export so anyway the first thing that I want to do is inside sauce I'm going to add a new folder called hazel and everything's kind of going to go into here so this is going to be kind of the hazel core library this test stuff I'm just gonna flat out delete because I don't care about any of that and then inside hazel I'm going to make a few new items I really want to make something called well I'm gonna make something called core build age which for now I'm calling a quarter age this will have some basic mappers to begin with and I also want to make my kind of application I can probably make a simple plus class called application and then hopefully it will create a header file for me and a CPP file let's just hit OK that's pretty basic it saves a bit of typing if I offer over here you can see we've got some definitions as well so I'll start by taking this application class and putting it into the hazel namespace the hazel namespace is we didn't talk too much about naming or anything like that but essentially everything is going to be in the hazel namespace and for macros they will most likely be shortened to Hz like that instead of kind of making an HSN namespace like this which you could do that's quite a popular approach so now at least well whatever for this hazel engine I decided to kind of go with the actual full word like that and if we switch over to the CPP file I'm going to do the exact same thing name space hazel and we're going to wrap it like that I'm going to write a void run here which is basically just going to run our application and for now this is going to be incredibly simple I'm literally just gonna stick a while true loop in here like that just so that we can kind of just have an infinitely running application that won't close for now the other thing that's really important to do is make this destructor virtual because this class will actually be inherited worldsuck last by our actual sandbox application because the way that we're going to write this as you see in a minute is essentially we're going to make our application which inherits from hazel application okay cool that's looking pretty good to me we have the big problem here of having to actually decals spec DLL export and import depending on where it's kind of written this actual application like this okay so in order to actually use this class inside sandbox because this is a DLL we need to export it from that hazel DLL so when we build this has hazel DLL this needs to be DLL export and then when we include application of age inside application or CPP in our sandbox project this actually needs to be DLL import the same way that we had with our print function except here is with the entire class so to do this and to make it a lot easier for ourselves we're actually going to go to that core header file that we made by the way application should be inside that hazel um thinks I'm just gonna move it into there inside core I'm just going to find a macro that is either either DLL import or export depending on whether or not we're building this DLL file so the way we're going to do that is very simple first of all do explore deco spec do export and import is a Windows only thing I want to say if def H said platform Windows okay so this only applies to Windows one one more level deep I'll say if def H said build DLL which means we're trying to build this DLL min which will this macro will be defined for this actual hazel project but not for sandbox we're gonna say define hazel API as in deco spec DLL export end it or other else we're going to define it as input okay and I mean we could just put like a simple kind of else you know error there's or only supports windows because that's all we support for now okay just so that this basically will trigger an error and one build if if no platforms are defined which for now I guess is just this so we're going to grab this we're going to right-click on hazel go to properties inside hazel property pages for all configurations and for our x64 platform under C C++ preprocessor we're going to define a couple of macros so first of all we'll put a couple of definitions in a step platform windows will be something that I'll put in here of course and this actually also needs to go into sandbox so I look on sandbox and put a shared platform windows ok making sure that we have a semicolon and then additionally in hazel I'm going to put a macro called hazel build vol I call the macros their religious definitions or defines but there we go so hazel build DLL okay so that's what we've got in here which means that that this kind of export should be active when we build the hazel library but for sandbox this import should be active so if we go to application or H I'll include portal H and then we'll just say class hazel API application just like that ok so now that we've done that what essentially that means is that if we go into our application or safety which is in sandbox this is becoming a little bit confusing because both of these files are called application bill CBP so I'm actually going to rename this file to sandbox does TVP or maybe sandbox app del CBP just so that we kind of get rid of that confusion now what I want to do is I don't really want to in my son box application have to do stuff like include you know hazel slash application but sippy that's kind of hard to use right what I actually want to be able to do essentially is just say I want to include hazel dot H like that okay and that should sort out everything for me so what I'm going to do is first of all inside source over here I'm going to add a new item called hazel - and this will kind of be like a header file that is only intended intended to be included by client applications so hazel will never include this you can see it's actually outside of hazel this is just kind of for used by applications so this is for use by hazel vocations okay and inside here we're going to include hazel stuff so include hazel application maybe hazel core whatever we don't really need to include for but you kind of get the point we're just going to put everything that we need kind of into here and then this will be included here so to make this kind of work we're going to right click on sandbox hit properties we're gonna go to C C++ general and as an additional include directory I'm going to say solution directory and then hazel and then backslash source like that so we're adding this source folder as an include directory in sandbox so that we can actually either you know do that or doesn't really matter if we use angular brackets or not but the point is we can kind of use a compiler include path even like this or like this to actually include hazel and we don't have to use relative plots okay cool so that's it that's done let's think about writing actual application now so we can say class sandbox is public hazel application okay we can do a number of things here let's maybe just have a basic constructor and destructor which for now we'll do the nothing and then I mean we only need to do much here but basically the idea is we kind of have a skeleton class which is a hazel location and the idea now is that we kind of want to run it maybe by doing something like sandbox sandbox equals new sandbox we're gonna allocate it on the heap like this for now making sure to delete it later and then we'll do something like sandbox run that's what we basically want to do okay I don't want to do this inside sandbox app dot cpp because this should be somewhat handled this would this should basically be handled by the engine and not by the application where heap allocated it because sandbox can tend to be very large and we do want to control the lifetime of this explicitly because it is our literally our entire like application so this does like I definitely want to be explicit with memory when it comes to this but if we run this it should actually work and hopefully just bring up okay well in this case actually get a an arrow which is fantastic so what does it say here okay inconsistent DLL linkage okay so it's not happy with our DLL linkage and in fact yeah so there's something wrong with the hazel API macro probably I should say what we actually defined that as because it should be hazel Bill Doyle okay I see so we used Hz build DLL here and hazel build DLL here so let's just get rid of hazel will just say a chesed build dll like that and here okay so now it should actually export that properly let's build this hazel project and then we'll build at the sandbox okay and I don't know why this is void it clearly should be int I'm not sure what I wrote last time but let's run this code and see what happens now if we run this we're going to get an entry point out found error the basic reason for this is because of course we we're not updating our DLL which now has other stuff in it so we need to copy that hazel dll to our sound box and replace the old one because we've built it now this really should be a post build step from hazel or like a virtual staff from sandbox really that does this for us but you can see that now we get an application that runs kind of infinitely right it's not going to do anything because we've just got a while true loop there it is kind of loading in the hazel application okay so now that we've done that we've actually kind of done the majority of the work here we've created all these macros that actually either export or import our symbols and we've written a basic entry point now what I want to do is actually inside hazel make a header file called entry point which will basically define that main function for us so entry point don't H and then this is just going to be a header file which will probably just say if def I imagined this entry fun will change based on platform so we'll say if def page said platform windows and we might just stick our our arrow up not really required we could stick this in here just like that every time that we do that but of course if we have it at least once especially in a file like court or age it should just not build if if hazel only supports windows Kay make sure there's no typos all right so basically what this will do is fairly simple it's just going to be this int main function like that that's going to create our hazel application for us now this I will fill out with oxy and RV we most likely want this to be win main on windows because we might want to retain certain information about how the program was run just for kind of Windows like when 32 API purposes but we won't worry about that for now now what we actually need though is some way to create an application now sandbox we don't know it's gonna be sandbox and I don't want to set up some weird like macros or anything like that so all I'm going to do is say that somewhere we're going to have a something that returns the hazel application pointer so extern hazel application like that and we'll say something like hazel create application I think that that would be okay so basically what this is is a function that we will define somewhere else which will actually return that application for us so create application is something that we will implement in the client so this is all going to make sense Minnis we're actually gonna end up defining this well declaring this function inside application or H so over here I'm just going to write a function which is essentially application create application that's what we call for now and this is something that is should be defined in client okay which means that inside our sandbox app which I'll just pin over here we need to actually say basically instead of this main entry point we need to basically say that hazal application create application is going to return in our case a new sandbox class instance right which is our actual application that we've built okay and that's it so if we go back to entry point just to see kind of how this will look like don't worry about any of the arrows at all but this is basically what we end up with this is an extern that will be found somewhere else in in our case inside sandbox app and all that this is going to do is upon main you know will actually didn't type any code that's great but basically up on main and we can just order this order app equals hazel create application just like that and then we're gonna do a run and then I'm going to delete app ok so this will basically just create our application for us by calling this function and then it will call the run function on side application which will do our while true loop and then at the end it will kind of delete it okay so that is how that works now we need to include this entry point inside hazel and just to make it kind of really obvious I might say something like entry point just to kind of make it I guess obvious that this is where it is and I'm just going to include hazel slash entry point okay and then hopefully we will be able to not have not have to have a main function in the at all if I right click and hit build we get a linking error the carbocation is an unresolved external and the reason that has happened here is because of course this needs to be a hazel trait application so we will right click and build that and then you can see we get no errors at all and if I run this code we kind of get the same result okay so the difference I guess is that we've actually moved this entry point into being inside the hazel engine right and I could even say something like printf you know hazel engine or something I don't know just for the meantime and if I run that I might need to actually include something so let's just include stdio.h far on this you can see that we get hazel engine printing so essentially everything is kind of fine I'll get rid of about these two things for now because that was the test and we've essentially kind of moved the pain of creating this kind of main function and doing everything properly to the actual engine side so if we look at our client side all we need to do is include hazel create our kind of sandbox class and just write a function which essentially returns this you could automate this even further if you wanted to but I quite like this base it's very simple we can do extra code here if we really need to upon kind of creating our application but it's just really really simple really clean and you can see that we've basically set up and and effectively like an antenna entry point for our entire engine and game so that's pretty cool okay so that's our entry point done we now have a basic entry point into our our actual application and our engine which is very important because that's where everything kind of goes from that entry point it's not defined that it's but it's very simple for us to actually start kind of building applications or at least having an entry point into the applications that we build using the hazel engine now you just saw me try and print have something and I like I mean I couldn't really and this kind of brings me - what's gonna happen in the next episode and our next kind of big task which is going to be to actually add a logging support to the engine because logging is one of the most important things that we can do like at all we need some kind of feedback on what's actually going on and just you know all the startup information just everything really so next episode we're actually going to use a logging library to start being able to log events or log any kind of information that we need into the console and possibly into files as well so that's what we're going to move onto next time I just wanted to kind of define a basic entry point because I think that this in general is something that people just forget all the time just being able to actually say I'm writing an application that uses the hazel engine how on earth does that application start what am I meant to do and we've kind of defined that right now which is pretty exciting now before we leave it at this today I do want actually push this code to github and I'll kind of show you guys how I do that just for fun so I showed the creation of this Haslett repository last time in fact it's already got 108 stars on github which is quite interesting because I haven't actually even released that video yet but here we have our Haslett repository let's actually push all the code that we've done today it's that repository so I'm going to go to this dev hazal directory which is the directory of this solution I'm going to open a command prompt window over here and I'm going to type in a get status just to make sure that were that everything is kind of fine now the biggest thing that I don't want is obviously this dot vs directory I do not want that to be kind of included at all so what I'm going to do is actually set up a gear ignore so I'm going to just open vs code here and I'll make a new file called git ignore inside this hazal directory you can see here it is and all I'm going to do is I just had a nice comment it just says kind of directories and I'm going to include I want to ignore a couple directories here so the first thing is going to be dot vs and then with bin and bin ends I'm going to ignore them for now we will probably commit binaries in some form in the future so this is somewhat temporary but now if I run that same get status you should see that we don't actually have vs or be an indoor bin in here which means I can just simply and get an asterisk and we don't on to get status you can see we have basically everything we want dot user is also something I do not want to commit so files and we'll say dot B user and if we go back here just to get rid of all of these files that we've just added to get we'll just do get ring set and just dot and if you're on a status again you'll see that we don't have anything so if we do a git add asterisk again and do a status you should see that we actually still have user because I need to add an asterisk at the front there so let's do that whole process again get reset get add get status you can see we no longer have those files here at all and that looks really good for everything that I actually want to commit I'm gonna say git commit and I'll just basically say set up set up basic application and entry points and then I'm just going to do a git push origin master and then it would actually push it but I'm not actually going to do this until the episode goes live for everyone because I kind of like to keep the repository actually synchronized with the video release days ok so there we go I hope you guys enjoyed this video if you did you can hit that like button you can also help support this series by going over to patreon icon for slash the Cherno huge thank you as always to all the patrons that make this series possible the next episode of this game engine series is actually already up for patrons if you're watching this live on youtube you can watch the next episode right now if you just go over to patron icon flash the Turner and help support this series also all of this code that I've written I've actually already written it it's in a private kind of development branch that patrons have access to so if you would like access to basically the future of this series and like met probably 10 to 20 episodes ahead like where I've already got the logging library implemented and all of that kind of stuff and you potentially want to help contribute to that kind of series development branch then you can also help slow the series and as a reward you'll have access to all of that because into this video as always I'll see you next time goodbye [Music] [Music]
Info
Channel: The Cherno
Views: 133,354
Rating: undefined out of 5
Keywords: thecherno, thechernoproject, cherno, c++, programming, gamedev, game development, learn c++, c++ tutorial, game engine, how to make a game engine, game engine series, hazel, hazel engine
Id: meARMOmTLgE
Channel Id: undefined
Length: 24min 45sec (1485 seconds)
Published: Sun Nov 04 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.