Introduction to Visual Studio: Sparky Engine (How To Make a Game Engine)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys my name is Jenna and welcome back to the Sparky Engine series in which we take a look at making a game engine from scratch in C++ and OpenGL so this episode we're going to be taking a look at Visual Studio and this should be a rough overview of how to use Visual Studio and a few things that might come in handy along our awesome journey to creating this thing in less than 40 days now it's a lot of that's coming up anyway that aside we're going to be basically taking a look at video studio so cool this is not supposed to be some massive overview a lot of the things will basically come as we go on you know with our journey so I'm not gonna pretend to cover everything here I'm just going to cover a few basics so that you can get started and so that you know basically what's going on so first of all yeah so this is what this is where we left off where we left off last time so we had this dummy little program of ours and I'm going to kind of use this to aid us to aid myself and explain things but this is Visual Studio okay if you download the theme in the description you can I think see episode 2 for information on how to actually install that theme but this is you'll get the same layout as what I've got okay and this is generally the layout I use I also use a program called visual assist okay and visual assist is a great little plugin for visual studio I'm not using it right now because it's not free so I don't really want to use anything that isn't free kind of to make this so I'm not using it I do usually use it though but no visual assist here okay so anyway you should get roughly the same panel okay or offer the same layout so let's start with exploring everything if I just close this solution so if you go file and close leisure names we can kind of start off with this and what you'll see is on the view start page this is what you'll kind of see if you if you open this up for the first time or not for the first time but you know when you're not running it when you open it so over here we can make new projects we can open projects we've got our recent hello world all this stuff you guys will probably understand but the way I open my project was I clicked on holo world okay that's what we'll be doing when we're making the engine this is really basic stuff I probably what I'll probably stop stopping now but um that's the idea okay once we're in this view we've got few different panels here that are pretty interesting first there's a solution Explorer not to be confused with team Explorer which we don't even need so I might just close that solution Explorer is essentially your directory kind of Explorer right it's supposed to show you every single file that is included in your project now the disaster comes here some files that are actually in your source directory on your hard drive will not appear here unless they're actually included in the project and this is where a lot of people get lost in Eclipse or something if you add a file to the directory you hit a 5 or whatever to refresh your navigator or package Explorer or whatever you're using you'll actually see the file here Visual Studio doesn't work that way right it has only the files that are included in your project if you want to view all files there's this button up here called show all files now show all our show all files won't be there if you've got the solution or yeah if you've got the solution selected so you can see disappears right it's here now but if I click here it all disappear so a lot of people might be like I can't see it that's probably why right if you click on your project you should be able to have this show all files button if you click show all files your view will probably change a bit and it will show you every single file so for example if I want to open my project on where is it open folder in win File Explorer right I'll see my hello my hello world directory and if I add a new file for example I should say I copy main and I call this new dot cpp right over here in my normal thing it will never appear right it won't be here if I want to include it in my project I have to click on show all files and you can see there it is it's got like a little red thing next to it if you right-click on that and hit included project it will actually be included in your project it'll be compiled since it's a CPP file and all that good stuff all right similarly you can exclude things from projects ok that's basic file management is pretty important ok any folders you create here as well will will be created on disk and if you want to actually view the hierarchy because if you see here we just have source files if I hadn't you folder or whatever it's not really going to reflect here whereas over here if I have folder you can see debug release all those folders are exactly the same as what they are on my hard drive so you probably I honestly I usually use the show all files mode when I'm just developing stuff alright and then I'll have a folder called source for example for all of my source files and that's how I'll have this set up so that's really important okay show all files is probably the most important button on here obviously there's refresh as well if you want to refresh everything and see any new files that you've added on disk anyway that's the basic idea right so we can delete this new thing and it should be deleted from disk cylinder from disk as well alright cool anyway that's the basic idea let's move on here so class view this is kind of like the outline that that uh Eclipse has visual assists like class view thing is fly a bit better but you can see that for example under in the hello world project we've got entity we've got player and the point is it kind of shows us it doesn't really show us the files classes well alright I don't even have visual assist so I can't open file anyway it just shows us generally the stuff that we've got like player and it's just a general class kind of Explorer it's kind of used for sometimes if you want to take a look so we can see what entity what player is and we can see that entity is based type fly anyway you can search here in one more class who's kind of important alright let's move on arrow lists are very important right if I make an error such as quickly just there's a touch bigger ok I forget a semicolon or something we'll get an arrow here now what's kind of important is that if I do something that isn't really an error right so I actually demonstrated this when I worked not build so adding new files by the way you can right click on project hit add new item it doesn't have to be on a project it can be on any folder right and use out a new item alright cool if I have a header file that is called do I already have a you've got um what's call this example right and I do something stupid like have a a bracket here and then over here I as I demonstrated this example last time and I include a header I'll include thing Intel you can see that this basically you get an arrow right this isn't actually an arrow if I run this role wrong file if I run this you can see we don't actually get an error right but we have an error okay that's intellisense intellisense is usually not to be trusted okay it can it is useful sometimes for diagnosing things like this but you can see these errors are basically just visual studios kind of opinion on what's wrong okay it's not actually a build failing so if you want to see only errors that are actually real errors right click here and just don't show intellisense errors and you can see that now we don't have any errors if we build we don't get any errors and of course if we had an actual error like that and we tried to build this it would actually give us a real error okay so intellisense you'll usually see that disabled especially when this project gets a bit bigger and we start doing fancy things intel says just isn't going to be able to keep up all right so that's one thing I wanted to mention here okay breakpoints we're about it we will talk about debugging in one on in this video so I'll get onto that eventually okay find symbol results um this is useful because well it I mean if it'll appear automatically but if I do something like shift f12 for example on something what it will do is it will search for definitions okay so in this case you can see it's searched a lot more than just this file alright and a few shortcuts I will get onto in the in the future but yeah essentially if I want to see where player is you this is kind of like the show all references in Eclipse if you right-click and go like work special references it will just show what it's used right so if I go right click it all you can see shift f12 is find all references okay so we'll search for everywhere player is used so if I were player and I'm like aha who's using this constructor theoretically it won't just look for the constructor unfortunately but it will find you know the usages of this for example in Maine you can see here I can't we're making an object here okay so that's important then this is what the find symbol results will kind of contain all right find results is a bit different so if I was actually searching for a string of text if I just hit ctrl shift F you'll see this find a replace dialog all right you don't have to replace that's different but when you're searching for things you can actually search in them in various like I guess search domains right so current document means just this file all open documents means all open documents entire salute and that current project will mean just the whole I world project if you've got multiple projects in your solution you can actually search the entire solution as well which is really cool so again if I wanted to see where player was defined I could search for player hit find all and you can see there will be here if you just want to see where they actually I if you just click on it once it will show you where it is all right which is pretty cool so you can see in this case it's in the include player all right cool before we go any further I'm just going to turn on line numbers here because it's a bit annoying not seeing line numbers and visually I think visual studio now by default doesn't have line numbers so if you go into tools options and then under text editor in all languages alright just on general which is just that you'll see line numbers just hit OK on that and then you'll be able to see what line of code you're on which is very useful when you're looking at error messages especially alright cool so yeah you can see that if I go through this list all yeah anyway you guys can get the drift that's just a quick interface kind of tutorial thing all right the output is pretty self-explanatory most errors in the output but pretty much all errors in the output will appear here seven with warnings so you don't really need to read this too much there are ways of course to actually log into the output when it's actually running okay well when you want your application is running and when you're debugging it so that's very useful as well in case you don't have a console will probably have an actual console there so it probably isn't too important but um that's the Apple window okay cool so a few keyboard shortcuts I don't know I'd probably don't know all of them in fact it'll assist does a lot of stuff that I probably don't know about but the basic ones I use are probably stuff like ctrl-c and ctrl-v Lowell a lot of people actually don't know how to use a keyboard when they're programming which is interesting because I I teach people privately a lot um and by the way in case you guys are interested in that it'll be a link in description to of course private tutoring but um I teach a lot of people and a lot of them are always amazed at how fast I type and how I you know navigate let's just say navigate the Seas of code well really it's just all about knowing how to use your keyboard so for example when you're navigating text instead of just using the arrow keys it's pretty much everyone knows how to do you can actually combine these with shortcuts and with buttons other buttons on your keyboard so for example if I hold down control and it's amazing how many people don't know this as well I know tons of you gonna absolutely know this so just sit tight maybe skip fast-forward a bit this is for those who don't okay if you hold down control while using the arrow keys alright specifically the left and right arrow keys you'll actually skip entire words this is something that again a lot of people don't know for some reason if I hold down control you use the up and down arrow keys it'll simply scroll but left and right it'll actually go through words so if I'm trying to replace int with a long for example you wouldn't see me go right I'll do something like ctrl + shift then the right arrow key to select the word then long okay quick tutorial for you guys right so I can select a lot of text like that really quickly alright then there's a few other buttons on your keyboard that you should get familiar with such as home and end they're really the big ones if I hit home it's going to take me to the beginning of a line if I hit home again it'll take me to the actual beginning of a line and will take me to the end of a line of code why is this useful if I'm trying to select an entire line such as result and copy it I can hit up once for example home twice then shift and then down all right that will select the line ctrl C will copy it and I can paste it as many times as I won and you can see the actual line is selected so it'll it includes the am blind character okay so that's really important okay so again get acquainted with that stuff if you want to be a bit faster and you really share anyway because it will save you time cool I need the other stuff is pretty much the same for most text editors if I am if I hold down alt while just if I hold down alt and then I'm on this particular line of code and I use the up and down arrow keys we'll just move down line up and down okay it's annoying to undo that stuff though alright so you might not want to go too crazy with that especially if you've got valuable stuff in your undo stack but that's the idea okay old and whatnot is very useful if you're just remove code and you can do it with bug with um with a selection of code as well not just one one cool um yeah I think that's pretty much it um I you know obviously you can if I want to select the line this way or whatever shift an end for example will select that just kind of get used to that stuff insert as well will override character so if I want to choose 0 to the one I can to a one I can just do that all out of that anyway that's the insert thing a lot of people probably know that um just looking at my keyboard anything else particularly useful probably not ok so that's pretty much it if I do something in this video that's weird I'll probably just cover that but that's basic text editing skills which a lot of people don't know and should so there you enjoy ok so ah what else do we have on the agenda here oK we've got a few um I was going to show you guys how to do a few things we'll say ok cool so I think what we'll do now okay one thing that's kind of annoying as well is that if you're looking at a file such as main doors EVP I'm like I want to see this on my hard drive if you right-click on this unfortunately for some weird reason there is no like find on desk or open an explorer button right it's just not here if you double click on it to open it and it appears as a tap here you can actually well eh you can hover your mouse over and it will tell you where it is but if you right-click on the actual tab you can actually open the containing folder here ok odd that it's not in here but it's it's available here so it's not too bad ok just get used to that one thing that's also really useful in the interface is this kind of scope thing so this tells me that I'm in the hello world project this tells me what scope I'm in so I'm in the global scope right and this tells me what like in a scope I'm in so for example this add function right so if I was in let's just say player right you can see that if I'm in the players kind of namespace scope thing you'll tell me that I'm in player and then that's the destructor for player so this is kind of useful as well if you're looking for something like eclipses outline and you don't want to use the class view if you just click down on this it'll show all the methods that are in here ok so you can see we've got get X that has structure and the constructor and then it works with header files the same way right cool so entity probably has a few more things not really we're looking at pretty small groups of code but there you go so that so if you drop down here you can see a quick overview of all of the functions that are actually in here all right awesome so moving on um yeah if I want to go to a definition if you literally right-click on something you'll see a bunch of shortcuts here so f12 for example if I'm going to see where player defined I hit f12 and look it takes me right to the header file so that's another release or shortcut that you could have probably figured out if you looked at this alright cool um so moving on let's talk about different projects and how we can get them to kind of interact so for example this print method that we have in header write print entity for example that's probably a bad example let's just say we have name space chana and then inside the channel namespace we have a void print and this will just take in let's just say just a string a normal C string roll a normal C string are taxed and all it will do is it will print it out so and I'll pull a print line for example since it has a newline character okay that's all I've got it's a very simple function right right now if I want to call it again I include header and then if I call it I simply type in Cherno print line and then we can say something like hello whoops all right if I run this we get the hello and everything is nice but let's just say this whole kind of setup I don't actually want it here I want it to be in a different project this will become a bit more apparent when we write a lot of code and we don't want to keep compiling it or we want to kind of modularize our entire projects right so what we want to do is we want to yeah might we basically want to have separate components for each component of our game image and we might have one for graphics well and have one for audio we might have one for like special tax reloading or something we don't want to have everything in one project okay so what we can do is we can actually kind of outsource this to another project compile it compile it into a library and then simply link it and use it as a library okay very cool so what we can do is we can right click on solution if you want to add a project and you go file new project it will probably created a new solution okay unless you actually pick add to solution that's just complicated so we can just right click on the solution here in the solution Explorer if you want to get any windows back by the way under view you'll see everything cool right click hit add and then new project you'll add it to the solution so if I call this it'll be an empty project I'll call this printer because it's going to print things under source files I'll just quickly add printer dot CPP and printer dot H so the reason I'm doing this by the way is just to show you a basic workflow between projects and also how to set up projects to use external references which is very important so printer we've got printed page so again I'll have my pragma once header god I'll have my include printed or H and then what I'll do is I'll just I'll have my I'll literally go into let's see I'll literally go into where header right and I'll just cut this code here and then under printer I'll have this right and then so we've just got this right I will probably have to include standard i/o no iostream sorry I'm thinking seal and for some reason so we've included that and then I obviously want to have this function so it's not inside a class by the way here it's just inside a namespace it's just a normal function if I I want to declare it here as a prototype so I've got println and I know that it takes in a string so this is the definition of course make sure it is inside the namespace I'll talk a bit about conventions as well you might notice that I put some things on the line some like some brackets eyes some braces I put on the newline and whatever we'll talk a bit about convention as well in a minute but we've got this print line here it's actually implemented here and it's inside these names faces everything is nice so let's go ahead and and we know that it works were tested in another thing this project let's compile it into a library so how can we do that so under printer if we hit properties you'll see this printer property pages some reason were actually already in release mode let's go back to Devo for a minute if we go to the properties let's drop in on the just general literally and you'll see the configuration type on the project defaults right if we change this to we can change this to a number of things such as static library dynamic library and a few different things so right now it compiles into an executable and that's fine for most things right if we actually wanted to have a main method or a main function and we wanted to actually run it on its own but if we want to reference it in other things yeah what we want to do is we want to actually compile it into both a static library and a dynamic library now static library is usually used for basically debugging and for actually writing code with right so this is kind of like an API thing whereas dynamic library is pretty much a binary that you provide which gets dynamically linked into an exe file for example when it actually runs so a few differences but in actual real worlds kind of scenario the static libraries I'm going to use while you're developing and then when you want to actually run the application once it's built you want to include a DLL file so we basically need both of these so if I just go to a static library here let's go to open folder in Windows Explorer one thing you'll see right now is I've never actually built it so on the printer there's no debug there's no anything there are any folders if I right click on this and hit build we'll wait for it to succeed we get a nice entry point must be defined which is just beautiful so let's go back into printer here make sure that it's set as a startup project I'll probably talk about that in a minute and then we can build it again so we're looking linking arrows which is just so much fun low so after wasting like a good minute or so I realized what the problem was the problem is we're currently in it in debug mode and if I go to properties the properties we modified when we change this to whatever was actually the release configuration so make sure you're modifying the right configuration so under the active configuration we want to change that to be a static library for example ok hit OK right click here build and it should succeed ok so again that's very silly and that's how I'm going to kind of glad that happened because I got to tell you this so make sure the configuration that you're actually modifying settings for actually matches your current configuration otherwise it just won't work or your settings basically won't affect anything so make sure so we've compiled a static library now we've hit build you'll see now on the on the printer you have a debug folder okay in this debug folder you'll see a bunch of stuff okay you won't actually see what you're looking for which is the dot Lib file for some reason it just did not decide to put it here what it does it actually puts it into your solution so under debug yeah in the holo world project so under the actual solution where we have both our hello Weldon printer things we have debug alright and here you'll see the printer dot Lib file all right this is our static library and under properties by the way you can change all this stuff you see these output directory this intermediate directory yeah you can change all these directories if you like ok that's just where it does it but if all those changes to a dynamic library hit OK right click hit build and then you'll see that we have a printer DLL and printed Lib fantastic so now we can use this printer in our other code let's figure out how we can do that for the purposes of this I'm just going to remove this project completely ok if I hit okay it'll be removed the reason I did that was just because you can see it didn't actually delete the files I just removed it for me I just want to basically complicate this list and show you that I'm not just simply referencing and I'm actually not the code isn't being compiled or anything anymore at all it's just it's just it's already been compiled into two files and that's that also I did compile it as a debug build again this is just for testing purposes not for releasing or whatever so we've got printer DLL and we've got printed out live these are our products how do we use them in hello world now so the thing is we'll actually need one more thing we basically need three things to be fully set up with this project we want we've got these sorry we've got the lib in dll we also need the header file which is printed I um and you can see it's just 94 bytes of glory so if we copy this and I'm just going to put this into here for now make a new folder called printer API right and then I'll put all these a lot of lovely files into this folder so you can actually see everything we basically need so under printer API excuse me while I just cut this for a minute and put it out into the real world under printer diapir we've got three files all right I'm gonna I'm gonna basically toss this into three directories for you we've got our includes which is printed by age yeah we've got our in fact I'm just going to put this into a Cherno folder just to because it is in Cherno namespace so we'll just we'll be nice we've got our binaries which is printer DLL and then we've got our Lib which as you can imagine is printed on Lib okay so this is typically three directories at three directories you'll see when you actually download someone else's library what we're going to do now is include these and use them in our holo world project so as you can see we don't have the print thing anymore and Hatter everything's gone let's go back to main figure out how this actually works so I'll set main back as data project of course it has been that has been done because we deleted the other project but make sure you set the right project as this data project very important you can see this currently is an error okay so what we want to do first of all is include this our head file right because that has the definitions this header file has the definitions of how we can actually call this function doesn't have the implementation or anything but it tells us how we can actually use this function so we want to include it now we could just copy it into one of these directories and include it I'm not going to do that instead I want to teach you guys how to add a new include directory so under properties for our project we've got basically two options under V C++ directories we've got our include directories we could add here in c / c++ there's also additional under general there's also additional include directory so you can add it here you can add it wherever you want okay I'm just going to add it here for no particular reason so what I'm going to do is I want to just copy this path right and then pop it in here okay you can also use macros I think they're called here yeah so you can actually use if you don't want to if you want to have a relative path you can also use a macro for example to get the current solution directory so that if someone else downloads this project file and you know they'll probably won't have a user called Sparky and whatever so you might not want an absolute path but this is just how to set it up on your computer so use macros if you like so we've included this as an additional include directory okay what that means now is we can use these angular brackets so in last in last episode's video I actually forgot to mention the difference between these if you're using quotes it means your relative to the current file so it means I'm relative to main dot CPP so if I open this containing folder I can see that I've got for example player door age I can include that because I'm in the correct directory yeah I can also for example in this case if I really wanted to go to printer API you'll see that the current directory that I'm in is hello world so I need to go back a directory then into printer API and include so I can actually do that can go back a directory like that go back into printer API include oops include Cherno and then printer page that's perfectly valid alright angular brackets are four paths or basically paths that originate in a directory that we've actually told the compiler to add as an include directory so in this case we did specify this directory right so that will be that is an additional include directory that is an include directory so when we use angular brackets it will actually search that so now we can just use that hit up Cherno and then slash printed on edge you can use backslash as a force letter some windows doesn't matter okay cool so there we go so now we've included and you can see where it is again if I just included that other directory I didn't make that sure no folder we could just do that cool if you really want you can get rid of the extension completely right and just literally on this get rid of the extension and then you'll have it you can have it kind of like a lot of the C++ libraries are so it's up to you but I like having the extension there just to remind me it's a header file but um there we go all right so there is that printable age so now you can see the arrow goes away so can we run this can we build it can we just be awesome now no we get this scary error message that a lot of people are very frightened by okay unresolved external symbol I remember back in the day I used to be scared of this one because there's a lot of out signs here and look that's just not a good time so what this means is that literally unresolved external symbol okay so it found this print line it's fine it's in the header file that we included but a lot I love how I actually went to pray why do we go to that that's very smart that one where is this ah it's cool it still thinks it's part of it that's annoying anyway we'll get all that so pretend it's not here okay um it's amazing that it did that it has the definite it has the definition of the function so it knows how to call it that's why we don't get an error here and we don't actually get a compile error we get a linking error okay hence the LNK prefix to the error code the problem is it's found the function definition it knows how to use the function but then when the linker actually tries to look for the function itself to make this Cherno print line actually do something it can't physically find it so it has a definition but it cannot find the implementation that is all this error means and in this you can see it says we've got a deckle here and then shadow print line it actually tells you what function it can't find which is nice and it tells you that's referenced in this main function alright fantastic so all we need to do is tell it where this is so how can we do that well glad you asked because back in here on the vase episode directories you'll see a library directories we want to point it to that dot Lib file or that the directory that has Lib file so again if I go to my printer API I go to Lib and then I find this I can copy this path paste it in here hit OK again you can use macros whatever to get relative paths to the current solution directory directory or whatever we've got this and then we can hit OK and it's all good isn't it no it's not we've given it the actual directory so it's like an additional include directory but when we included something we had to actually like when we added an include directory we actually had to use the include didn't we same with libraries so how do we do that well on the properties under linker because remember this isn't a compiling thing this is a linking thing now on the input there's additional dependencies over here just click on the drop down menu and edit your annemun have to do that you can just type here by the way so I can just type stuff here but I'm just doing this so that you guys can see this a bit more clearly we want to type in print ad lib okay obviously you will never find this unless you actually give it this directory which is what we did in the previous step so make sure you do that all right let's get ok okay cool there we go print result lib is now here hit OK so if we run this now if we build it my goodness it succeeded are we ready to rock and roll let's just hit it to run it and we are ok fantastic so in this case it didn't actually need a DLL so luckily right but usually if we go into for example I've got a feeling that's actually because of a few different things but if we go into our global application into sorry just into debug and we launch a low world ok great it works fantastic so it's probably actually compiled the DLL into this exit because the diello is freaking tiny but usually you would need this DLL here in our fantastic hello world application to actually run it in fact in a release mode actually do something like that ok we'll talk about that in a minute ok cool so that's essentially how you use a library it's pretty simple it's not too difficult let move on to a few different build configurations and whatnot and then I'll go through debugging and I think we'll be done so if I under properties here if I change the the build configuration to release right and I build it will probably get errors right and you'll be like what you mean I specify this include directory remember each configuration has his own set of properties so make sure you are nice this time and what you might want to do is just go to debug and copy and paste pretty much all the stuff like the include stuff so I'll just Lowell copy paste okay you might want to do all that stuff stuff involved and stuff you've changed okay well have been modified make sure you hit yes when you go between them so that's kind of nice I also like the fact that if you if you keep clicking on things like that this actually becomes wider and wider is pretty quite comical really but we also want the library directories to be included so I'll copy and paste that and then finally we want yes we want the additional include directories under general to also be in the release configuration all right cool and now if we run this it should totally work okay cool now we get errors okay this is because of the difference in configuration so for example printers will Lib iteratively by value to doesn't match value to the reasons this basically happened is because we didn't really compile our printer in release mode but don't worry okay again this was this is just a little test application one thing I want to note is that when you're doing release you might want to actually change the optimization okay so for example stuff like maximize speed will be on instead of like basically disabled which is what debug will probably have all right disabled you also might want to you know you probably want to change in line yeah there's a bunch of things you probably want to setup for example you want to obviously favor fast code and all these optimizations which actually do make a massive difference okay you can probably get your application running ten times or more faster if you set these out probably again there's a few other things like on the code generation you might want to change the floating model to be fast and the instruction set to be for example sse and there's just there's a bunch of different things you can set up here that is really important we'll be setting up a bunch of them throughout the ink engine series to make our game engine run faster and release builds but the general downside is is it becomes harder to debug all right which is why we don't really want to do this on a debug build that's why we have two different builds so there's released which in our case will probably be the one that will get distributed but debug is the one that we'll work on okay because it'll be easier to debug things let me show you the difference between the two built quickly if I go back to if we just hit OK and that so it applies this one thing you will do by the way is since run remember since debug builds we'll have sorry since each different build configuration actually has its own separate like set of properties it also has two separate folders okay so you'll see hello world has debug okay and then hello world has what we had the DLL in there I wonder if Phil's yeah it still still work without it well okay whatever I'm actually quite surprised anyway we you can see we've got release here okay didn't really succeed in building because of all these debug level measurement Mitch mismatches I'll talk but we have this release directory that I generated okay so it'll generate multiple directories so if we go up here quickly and let's just remove this printer thing because that was more of a testing if I build this now it should build successfully and we should see that our hello world release directory has this exe file which is great let's quickly do something to just see the actual difference between builds under debug if I let's just say I have an integer called two and three and then I want to add them together using the add function and when we go a B and then I'll log this see ya if I'm in a debug build all right let's build this for a minute make sure it stays cool I'm going to put a breakpoint at log okay and then I'm going to run this and we'll go through breakpoints in a minute and you'll see that when I run this it'll actually physically stop the application at that break point and we can examine our current program okay specifically things like memory and what's in there so a you can see what we'll go over this interface in a minute so we're about to you know start on the debugging side of this which is the last section in this video but you'll see that we we've put an application call nothing really looks that different in fact let's do it at C so I'll stop this and I'll rerun it okay we've good C right let's right-click and just hit go to disassembly so what you'll see here is basically the assembly equivalent of what our code has been compiled into and we can see it running here what you can see is that this is again this mode is probably not too useful to the average user because a lot of stuff you can debug here but this is actually quite useful when you just essentially don't know what the compiler is doing okay lets you verify that your compiler is actually compiling them correctly and it's not over optimizing stuff to the point where it breaks or there's just there's a lot of there's a lot of uses for this but basically it just lets you figure out what actual instructions are being sent to the CPU so in this case you can see we've got a bunch of so this is the line of code is being executed these are all the instructions that will be executed for that line of code okay so it's good if you've under viewing options and stuff like show source code which is very useful okay but and then there's also you know show symbol names which is kind of useful otherwise you don't know what it's actually doing so for example um over here you can see it's actually calling the add function fantastic and is evaluating this stuff so it's for example in this case it's actually setting a specific memory address to the value two okay and if you've done any assembly as a lot of this will look familiar but the point is we can see that it's actually you can see there's actually there's an actual function call in here now this is a very basic thing and we did I need a function call for this so if we can pilot in release mode okay and we hit f5 first of all you can see the breakpoint didn't even stop at sea right there is no see yeah which is straight away it's a bit interesting if we go to the disassembly now you'll see it looks very different first of all these lines of code are basically one thing okay because what is done is this is if apart from just simply in lining all these functions which or this add function because if there's no call to the add function the only call we have is to some other function which is probably the actual printing function to print this to our console but it's essentially combine these things evaluate the compilers actually evaluated it itself and has basically set up C and already logged it right and you can see it's pushing five and five is what two plus three is okay so you can see that the compiler is in this release build has actually gone so far as to simplify this statement and not computer runtime okay it actually figures it out while it's compiling which is beautiful and then it pushes this five and it calls the function and basically prints up and the UM the number five into our console okay so that is a good example to demonstrate the difference between configurations and what release mode will actually do it will optimize your code it's very useful and as is this disassembly window which actually showed us what it did so it again we simplify this into five whereas before of course in debug mode we had we had this did everything separately and it called the actual add function you can see call add okay and release mode did not so keep that in mind I can't actually zoom in in this by the way for some reason but keep that in mind very useful moving on so let's talk let go back to debug mode that's also an example of such a wide a bug is probably a bit more useful you can see that stuff like in ABC would all take up memory they take up four bytes each of memory to store these numbers and really smell it's like no we don't need to waste that memory will just evaluate this and literally just do that so and then that removes this all right cool anyway let's talk a bit about but that's why debug mode is important for debugging right because we don't want these variables to be removed if we're trying to diagnose what's going on with our program so very important stuff okay cool so let's let's take a quick look at the bugging because I basically want to be done I basically want to have this thing done and within an hour so so we'll do that but um debugging so breakpoints we're going to basically focus this whole debugging thing about breakpoints you'll see this massive like gray kind of Thomas green ish kind of space here between the line numbers and like this solution Explorer right there's this space right and I guess this either word depends how zoomed in you are but it's this thing right if you click once anywhere right it will pray it place this big red button thing now to someone who has no idea what it is this will destroy your life because when every time you're on your program it'll stop it'll crash and you'll be like bro what up so don't freak out it's called a breakpoint and it's incredibly useful basically when you place it at a particular line of code and you run your application your application will stop when it reaches that line of code okay so for example if I place one in a and hit run you can see our program never even stops which means a never runs so that's a kind of a useful feature we can basically instantly see does a get called anywhere in our code Lowell no it doesn't so we've got this good so we can place it anywhere and it will stop okay f9 if you're on any line f9 will place or remove a breakpoint pretty useful so when we do this it will it will pause our application and it will show us a bunch of things first of all it'll show us a few values which are important to us in the bottom here you'll see autos locals and watch these windows aren't present in the when you're not debugging right when you aren't debugging you get this different kind of view okay so under under autos it'll orders I think it I'm not sure exactly what it's when I was supposed to do I think it just kind of grabs a few variables that you it thinks will be important to you to look at right locals will just look at every local variable you've got so we've got three here and then watch allows you to basically tell it what variables to look at so if I click here and type in a it'll tell me the value eight of a right I can also click and drag variables in and stuff and it will tell me it's values so that's kind of useful as well and you can have you can see it says watch one that's because you can have like for watch windows they're not under view by the way these windows they're on the debug and windows okay so you can see this watch we can have after four watches okay there are other important things like um little modules modules the modules are kind of important when you've got a lot of projects and you not sure like for example you might not have debug symbols being loaded from some things anyway um so under debug we've got Windows you know we've got threads and whatnot and a lot of these are pretty useful but these are probably the most important ones so we'll focus on them cool so we've we've broken light right we broke on this line of code on line 41 we've got a yellow arrow there and if you if we hover our mouse over it it says this is the next statement that will be executed right this hasn't actually been executed yet technically the last thing that's been executed is like this little curly bracket right eh this int a equals two that has not actually been executed that line of code right so if we want to step forward in time one line so we want to advance our program one line we can actually do some pretty cool stuff like that so up the top here you'll see a few different things along with shortcuts right so there's the three ones were kind of interested in and there's also continue which is important which is f8 okay doesn't actually say it but it is impacted sorry it's f5 its f8 in Eclipse I think I don't know why I thought of that but f5 okay so there's step in to step over and step out they're all really useful so step over we'll simply step to the next line of code so if I hit f10 or click on step over you can see that the yellow arrow advances right and we've actually moved so we've executed this and our autos tells us the eighth actually says that it in like a red kind of font it says that a is changed into two okay the reason it's red is because it's changed since last time let me quickly see if I can actually increase the tools option increase the font of this because that is kind of annoying we'll just do it in will do and watch so let's quickly just not color let's quickly spice this up to like eighteen so I shall relaunch watch or the whole application hopefully not the whole application are you serious what does it say man hang on let's change it to fourteen watch windows I did restart that well debug window whoops okay debug windows watch fantastic did I change this right option I did great oh my goodness alright let's restart Visual Studio I guess all right sorry about that guys hopefully uh hopefully this actually works okay good um so yeah so you can see a is currently that that's just because it's undefined right it hasn't actually put anything into that memory that's just the memory address of a and a hasn't been allocated by us if we had f10 you can see thread because it's changed into that new value of to be still hasn't so if I hear that again a is now white because it hasn't changed since last time and be free so I'm simply just stepping over right that's alone doing this is fantastic because it shows you the control flow of your of your application if you're still kind of learning programming and you're not sure how for example control flow works so if Damon's for loops you know breaks and you know all everything continues whatever you're not really 100% sure about how you program actually execute code you can step through it line by line okay very very useful stuff for education and for this stuff now here I have a function right if I hit step over it will simply value 8c right so I'll just type in C now watch so we can look at it it's 5o and you that's it it'll just step over it right what if I want to actually see what the ab function does well I can okay if I hit f5 and then I go down here instead of step over I'm going to want to click step into what it will do is it'll actually step into that function okay and then if I hit f10 if I if I if this was a long function and I decided you know what I'm done with this function I can step out of it and it'll step out of the function and go back to here okay then you can see C gets set to five all right cool one more useful thing is if you're in a massive full loop or whatever and you're like man is going to take me forever to get to here you can place another breakpoint at where you want to be hit f5 and you can see it'll continue on till so f5 is continue it'll continue until it reaches that line of code which is kind of useful as well alright cool so that being said that's essentially how we can kind of breakpoint things and run through this so it's very important stuff because we see how our program actually works okay cool and then these are the three views that we want to look at so yeah the other cool thing that we can do is have conditional breakpoints so if I put something here okay and I say you know what I want to break here so if I right click on it under condition okay I can actually say C greater than 5 and when it's true okay so if I run this and sees 5 it is fine right if I change this to 6 that or whatever I change it to let's just say if I see will be 8 in this case and I run it you can see that look at that it breaks so that's also very useful if you're trying out if you're in a massive loop and you're trying to only look at certain I don't know certain iterations of that loop or you know for example if I had a massive four loop here so four in I equal zero is less than 500 I plus plus right and then I'm like and then it logged it or whatever oops and then I was like you know what I want a breakpoint here let's stop this I want a breakpoint here but a man like if I just place I in this watch as well I just keep hitting f5 or whatever and it's demand like I want to see it a duration 400 will take forever I can right click on this go condition set I greater than like 450 or whatever hit f5 and then you can see is now 4 4 451 and it's logged this a lot of times okay cool so conditional breakpoints are pretty useful you can also do other things like you can tell it what to do when hit so print message is kind of important and I can tell it to continue execution so if I do something like this and then I can say I want you to print so I equals and then if I use these curly brackets I can for example say print I yep so I will actually print the variable the value of the variable I so if I hit and you can see it's like some diamond things I'll just put a normal one here if I hit a 5 you can see over here and in my output it actually prints the value of I okay and this is this slows down the application tremendously as you can see it's like running extremely slow but you might want to do something like that okay because you want to see things so that's the idea again then of course you can set conditions for that as well so only when I is greater than 490 I want you to do that okay so if I run this again you can see we get a few things and that's it okay cool so that's some basic debugger usage very important stuff again unless it's step through our code line by line which is so useful when you're trying to debug things and you can verify things quite easily so one more kind of useful example al one more thing that you can do is whoops I forgot place a breakpoint by the way you can place break is why your application is running so if it's got a massive lube and you're like actually I do want to place a breakpoint you can do that all right so if we run this again you can also hover your mouse over values and that'll tell you what they are so you don't have to look at them in these three windows you can just solve your mouse over them and see where they are under debug windows there's also memory so under memory so you can actually view certain addresses certain addresses of memory if you want the actual hex of a value so for example a how do I get the address of that variable wall um okay new plan int P equals memory address I'll pay okay so P is that so let's P let's take this let's pump it into here hit enter that's a terrible view let's go here hopefully that didn't advance no okay so here we are so you can see what we've got here yeah man okay zero zero zero zero zero and then five okay so the five is the five right it's actually in our memory and we can look at it here okay umm pretty cool stuff and it takes up that many bits because it's that's 32 bit okay cool right so that's one more useful thing you can do again that's very seldom actually useful but I thought I'd show you anyway the main reason I want to show you this is because you can hover your mouse over variables cool one more thing and then we're done under add for example I know that this function unlike you know what I'm mining out I'm ironing out my application and this shouldn't be called anymore in fact I'm not sure why they've been called somewhere I don't know where it's ruining my application number written so much credit around where it's getting cold wrong if you run this okay and then we of course break on one a when add gets cold you'll see this thing here in New York then called call stack okay in your call stack this is basically every line of code rather every function call that has gotten you to where you are now to this breakpoint right so you can see that this is the actual breakpoint and then if I double click on this line 43 they'll say well this okay so this we can now see is what called that right so if I add another function called Lal and then this was actually in here for example in Lowell okay and then I ran this oops stays undefined let's put log in there as well so there's that old up arrow shortcut hmm Lal must return a value loss anymore and then we see here you can see that we go to Maine that calls Lowell right by the way this says this thing isn't really correct it says this is the next statement to execute so that means that this statement is currently being executed again I don't know why that didn't just do that but anyway we've got this right so we can see that this is what called Lowell Lowell calls add and then add is where we're at okay so this call sack is very useful for exactly that reason all right cool anyway thanks for watching guys if you have any questions about Visual Studio please leave a link in description I've covered very little but I've covered pretty much everything you should probably need to actually get going so again if you've got any questions just leave them in the comments below and I'll try and answer as many of them as possible I think on the weekend is what I'm actually going to start this series so I've done all the introductory videos now I really do have to get on with the series because again I want to have something bellend by 11:00 dare so I'm going to so none of these were streamed again none of these were actually streamed all these are just me recording them I will be streaming them from now on though okay so if you want to watch those streams live which you probably do make sure you go to twitch on TV for saffiano and you for either follow me there or probably more effectively or like I guess a more effective approach would be to follow me on Twitter because twitch doesn't really like unless you're on twitch all the time you probably won't know that I mean streaming it'll just send you like some email or something but on Twitter you're probably more likely to be following me on Twitter and you'll have like a phone with your Twitter feed there so you might see that so if you follow me on Twitter twitter.com 4/2 channel I'll of course announce when I'm about to stream and then I'll start streaming and will actually start this game mission so there should be some time on the weekend because I won't have time until then unfortunately so Saturday or Sunday is what I want to stream and then of course I will record that stream and post it on youtube and that'll be the official first video overriding the spiking engine where we'll start with the blank project and everything and make this awesome sparking game engine so yeah any questions leave them below it'll like it hit the like button if you enjoyed the video and I'll see you guys next time goodbye
Info
Channel: The Cherno
Views: 64,539
Rating: 4.9805589 out of 5
Keywords: thecherno, the, cherno, project, thechernoproject, game, programming, development, engine, game programming, game development, how to make a game, java, tutorial, source, code, complete, game engine, c++, c#, Java (Programming Language), C (Programming Language), sparky
Id: dDVoL9GDVCI
Channel Id: undefined
Length: 60min 25sec (3625 seconds)
Published: Thu Mar 12 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.