Godot Source Code Explained by the Lead Dev #1: Core (1/2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Awesome. I was looking to contribute to the github but i didn't know where to start. This will be a good starting point

πŸ‘οΈŽ︎ 17 πŸ‘€οΈŽ︎ u/elan17x πŸ“…οΈŽ︎ Dec 21 2019 πŸ—«︎ replies

This is good

πŸ‘οΈŽ︎ 13 πŸ‘€οΈŽ︎ u/polaris343 πŸ“…οΈŽ︎ Dec 21 2019 πŸ—«︎ replies

Great I will watch this, I was thinking about adding more advanced rich text label features

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/mistrjirka πŸ“…οΈŽ︎ Dec 21 2019 πŸ—«︎ replies

So it's Go-Dot confirmed, not godough lol

πŸ‘οΈŽ︎ 6 πŸ‘€οΈŽ︎ u/TheSplashsky πŸ“…οΈŽ︎ Dec 21 2019 πŸ—«︎ replies

Godot is already crazily easy to contribute to, this is gonna make it even easier!

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/NilsIRL πŸ“…οΈŽ︎ Dec 21 2019 πŸ—«︎ replies

Greate video! I'm excited for the next one.

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/Jummit πŸ“…οΈŽ︎ Dec 21 2019 πŸ—«︎ replies

Someone who uses QtCreator! Nice

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/[deleted] πŸ“…οΈŽ︎ Dec 21 2019 πŸ—«︎ replies
Captions
hello ladies and gentlemen I'm Wanda Nancy I am the head of development of coded engine and the technical lead I'm going to work on these videos and a series of videos for while because many have straight coal that has a really large code base which makes it a bit difficult to understand and to get familiar with so the idea of these videos is to work somehow following the code base and explaining you what each bit of the code base is and what it is used for I'm not really used to streaming or to talking on a video and recording videos showing things so I hope you're patient not with me about this because again this is not something in very experience into so the audio quality note may not be the best so this is what I can do if you have any feedback on this feel free to leave in the comments below well I will start I don't really have a guide on this I only noted a few things I want to explain in which order this will be mostly improvised so is very something anything that it wasn't clear again please ask about it in the comments below what I will try to answer as best as I can so let's start if you have any doubt they use QT creator for development of code it works very well I like that you can use it exactly the same on any platform meet Windows Linux desktop or Mac OS so it's my preferred way of working with code code base I don't really use any kind of project management cutter has a sconce a sconce file you can use to build we use cons because we have two will for a very very very large amount of different platforms we have to compile for many of them at the same time usually when testing so sconce is one of the best tools for this job that said I'm not going to focus so much on the view system because there's a lot you can learn about it in the documentation I will talk about the source code mostly if at some point you really think you may need a tool in the build system I can try to do it I'm probably not the most experienced it contributor to a project regarding to it because many have been doing improv ins improvements to it so I may not be totally up to date but I can't right so let's begin let's first take a look at the directories if you download this code of source code from github you just go to github go to the engine and just on the pretty much the source code there's more two tiers for that I'm not going to cover that you can check that there's many directories here like core drivers little main miscellaneous models platforms in let's do a very quick refreshment of what every one of them is usually each of these directories depends on another there's not many cross-referencing between them the core director is core everything core is here everything else will reference core in court you have everything related to core engine all the chord types core structures everything very basic that we used to build up on from there on there is the servers after core on the servers you have like all interface is exposed like for rendering physics and everything but it's still very low-level interfaces is not really high-level interfaces after a service you have the scene this is the thing the scene has all the nodes you see when you add notes to a lot scene from the scene tree this is all in scene it only contains pretty much notes on also resources then finally you have main and from then you have the main loop that runs the engine there's some extra folders here that I will cover one is drivers which is things like for example external dependencies that are core to the engine like for example operating system stuff like POSIX windows stuff OpenGL this is core this is not something we can take away from the engine you may be compile it out to this core then you have modules which is a very large amount of formats and external libraries that you can just take out if you don't want you can when you compile scores you can see what when you can use what comes bill by default for every platform so mobiles is like dependencies are not so hard college that you cannot turn off while building and finally there is the editor you can see the editor here this contains all the code for they got that editor editor is made using colored itself everybody internals is at this point so it's really funny and there's there's a few more things like for example for the third-party libraries we bundle everything every library that God uses a third part is bundled into the view system we do this because we've used for a lot of platforms like web assembly or Android and everything and using external dependencies for all those platforms is a really really big hassle so most of the third-party liberal libraries are done inside some of them you can choose to compile out like using your party system provided ones usually this is what we do distribution versions of the libraries when you have a goal of distributed by like Debian or won't or anything else usually we use compiled out ones one we distribute from the webpage everything is bundling because it makes sure that if you will be able to run it when you don't do it especially in Windows and other operating systems who don't provide external dependencies like this so let's go to core core is the more central place everything depends on core core doesn't depend on anything else so let's begin the first thing I will discuss is the main file the main file is typed as files here is a type the file you can see this file it has very classical stuff like very basic templates defines things that make it work in every platform you have some functions for swapping things next power to is very very common and very core things this is very very core as I mentioned for more math specific things then you probably have to go to the math directory without the math functions here here are abstractions for most of the mass functions you can see all of them here nowadays we could probably use the operating system once but being that Google is pretty old and used to be compiled for consoles many times the consoles would even provide map functions you have to lend yourself or they have their own so this file will provide an abstraction for this no arises mostly just wraps around the operating system based ones except for some like for example checking if none depending on the compiler version you have to check yourself or you can use operating system provider and provided functions so this is the map functions I would say that next in importance is everything related to math you can check for example the vector 2 which is a chord type but we use everywhere it has X Y you can see an Union here the Union ensures that basically you can just use it as a size or as a position depending on whatever you want X or Y it has a lot of functions for math you can take a look at this file later like Len dot product everything sliding bouncing reflecting all the operators you have the same for vector 3 with all the the product cross product everything rated for math you can check first many of them but Ernie on drag transform something on interest maybe that we don't really use mattresses directly we use the transform structure more like the basis structure for 3d this contains two vectors so it's pretty much an orthogonal orthogonal basis meaning that it it contains a transform you don't need to really understand much about math to to follow this and worry this is just a comment about how it is organized then you have a textual transform which contains the bus is another gene point if you're working with 3d you're probably used to it if you are not working with video don't worry feel free to ignore this is fine we have the REC two and one this is basically all the math containing stuff that you will need if you use 2d or 3d so the next thing that I'm going to comment on is the OS they look T Drive free inside of core we have pretty standard OS stuff like directory access file axis you have stuff about memory we have a run a locator like for example here for creating memory we use memmio instead of new it is this mark road it's around here now we have menu so if you write good code that does something instead of using a equals new something you have to use many new something why do we do this instead of using new the reason is that this small thing you can see here we have a posting interlace and post are pretty lit pretty lit handlers here one initializing and deleting got objects you need those because it means that we can safely track why after something was initializing before this works around the limitation in C++ that you can't really tell after somebody or somebody writes an object or delete another check we can catch better when you're managing D the classes in C++ this is used every worrying about you will probably see later don't worry the only important class is OS this contains all the functions you need your for accessing the operating system abstracted because it's different on every one of them like for example you can print errors you can show dialogues with alert you can change stuff regarding to the window and the mouse in code for if you're using or reading or good for got forecast is separated you know display class from OS but since this is called 3 it's all together on and and and you can see all the functions in the OS class you can see like all the screen count and windows everything is also handled by OS operating system you can open dynamic libraries you can check the internationalized input you can kill a process you can execute a su process you can change environment variables pretty much everything you need like calendar functions time or functions delaying handling crashes spiritual keyboard mobile everything everything is handling this OS class so anything that you will typically access that is always related you can access via this class we have a wrapper for script but yeah this is basically it there's a few more things like for example the music's on the treat this or for treating this success because when Gilad was created C++ 11 didn't exist now these are provided by C++ 11 but we still have them because scripting new system of wrappers for threading so they still exist even though they probably will be used as soon as within the engine core those are file and directory access you may be wondering why we do this if operating systems provide these kind of things this basically is handles a lot of things are difficult with the operating system by unicode as an example high converting unicode patsies quite complicated not an example especially on mac OS because they are unnormalized and you have to normalize them it's complicated so it just wrap everything on for example in some platforms you don't really access the real file system so when you export a gaming code you probably have seen that is for the pc k file this is not accessible by the regular file system so you still need to use this wrapper which is file access when you export to android and reduce together everything on an APK file and you can access the file from within the APK so we use the file and directory access so we make sure everything is nicely attractive and works on every platform so you use this from your game and from the whole engine uses this also and make sure that we can access files everywhere so just if you want take a look at file access you will see pretty standard we also have some serialization and deserialization functions like for example storing inter girls getting integral storing unicode strings getting unicode strings getting a CSV when you read from a CSV file there's all those little helpers you can see that they are available for you if you need even from the scripting API for their access for directories is the same you can iterate all the files in a directory check if this is the file is it's a directory it's hidden you can get the drives on Windows you can get a lot of different things using the dheere dheere access functions you can move files rename files so these are we different on every operating system so having a nice abstraction is pretty nice so what else do we have here let me check but I think from the other side it should be okay all the way we have one more which is the main loop the main loop you should probably will probably see later again more about this the main loop is a base class that God uses it candles input events input text because when you are working with right well you have a keyboard that pops up so it gives you the whole string all at once you can initialize iterate run a needle the iteration is for the physics it'll is from one night for the graphical frames this happens at fixed time iteration and this happens and whenever it can happen it's usually synchronized to be sync if you don't have this thing is going to be cold as soon as possible and then this happens when you're finishing the aim you have this small cog for dropping files when you drag files over the screen you will get this callback now so you implement this to make your game usually you don't do this because code provides something more about which is the scene free we will see that much later but it's good to know that they always class that I showed you before like this one they was class this needs a main loop to function there is a function that is main loop and you have to provide a main loop all this is handled for you on an idealization you don't really have to do it but what is important to know is that you can't provide your own in case you really need to you probably want it to but it's good to know that you can so the same tree there's seen tree class you know when you're working with notes and you ask for the scene tree which contains all the notes this is also a main loop if you check it will inherit the main loop it's an implementation of main loop so basically if you want to make a different way of handling high level stuff singular that is not know days you want to maybe something else you can do it if you want it's probably waste of time but you can do it one of the reasons where the engine has a main loop abstraction that is so low level is that originally we also with area when we have a run company we did a lot of porting work so we would port like games and use code just as a cause cross-platform layer so we would make a custom main loop that uses the same main loop that wasn't originally written for the engine so this is not very common nowadays but it's just existent you can do it and use it so I think with OSU hyung you can get the idea what it is there's more files feel free to explore them but you won't find anything new or more interesting maybe the input event you can check later yeah well I guess when you get input you will get this structure which is input event you can get a lot of them like you can get input with modifier season after class but you can give keys you can get Mouse you can get joystick a mouse motion you can get touch controls and on the iPad or the Android tablets or cell phones or even on the web you can get well there's a lot of them you can get the pinch and zoom actions like gesture those are include events that you get you generally don't need to get them from the main loop you will probably get them from controls or input the input Kalibak easier ways to do it from within the game this is just a very low level stuff so okay that is nog from OS so let's see a bit what the containers got off has one type achill argument that we here is why does could not use a standard template library from C++ we have run templates so why is this there reason there's a few reasons for that there's not just a single one the main one is that we don't exactly use templates the same way as the exists on STL then we have a bit of different use case so the ones on a steal don't really quite cover what we need so it's easier for us to use custom ones which are actually pretty small anyway also one problem still has is that it's really really complicated it's something that is probably theoretically very correct you have like multiple levels of inheritance and templates instead of templates and everything and this is very nice that when you compile to binary the symbol size of STL stuff is huge the same bowls on STL are huge you probably have noticed when you have an error with a steal when I steal container it just shows a very huge line showing what the template is and you have see templates inside of templates inheriting templates there still is great but it just is too complicated and produces really large slimeballs the problem with the large sign buses when you compile with the bag you're the back binaries will be absolutely huge especially for something like a dot so we have really simple templates and almost when use anything complex so the sun's angles are small and they want I know you when you build or send a small build for a cell phone or HTML file is one piece so annoying because it won't be that big if you used STL it will be huge but also it's not we don't exactly use the same thing as they use one good example about this vector class still has a std vector but we don't really use that vector we use that vector for little different things usually most of the time we use that curve for just putting the stuff in an array and passing it around and we just pass around this vectors like with arrays a lot in code usually you can pass if this information like from files you can send it to servers you can just and stuff around using vectors we send a lot of stuff using them so the interesting thing is that if you copy and CD vector is just going to copy the whole thing allocate the memory it's kind of slow so since we use vectors mostly for passing data around we use this thing Coco data it contains a copy on write operators so the vector single dot are copy-on-write this means that you can pass the data around safely and it's going to share the pointers not going to reallocate anything it's just going to change your reference counter the reference counter is greater than one meaning that this vector is you soon used from any place and you try to write do it for it it prefers what is called copying right it just creates a local copy so for you you're just copying the data but internally just referencing the data unless you want to write to it in fact we make writing explicit so if you want to write to a vector let me show you it a bit difficult here you don't really going to do like my vector backdoor yeah this will fail in the you singing a lot for writing you have to write explicitly like like this right five this make sure that we don't create copies unnecessarily so passing erase is a bit more annoying because you have to explicitly write to them but the advantage of this is that we really know that we won't be making mistakes because we will only write when you actually want to write otherwise the vector will just be not not checked for copying right I mean when you read from the vector it's fine when you try to write to it you need to check the references then do copy-on-write so basically if you if we make sure that writes are explicit we can make sure we have a good control of performance so yeah that's basically it about vector let's see what else we have here well together with vector we also have a string class it's called u streamin because it's unicode string we have a run unicode string class we know again STD has a string class even a w strings for unicode but honestly we need so much more stuff from strings that what a steal provides that we don't even consider using it like for example without unicode parsing we have a lot of functions we use like for checking identifiers Val identifiers like but zeros but the similar we have so so so many functions you use for parsing and for different like for example escaping to xml escaping to http is caping to see we have way too many things that we support in or three in class like proper splitting like quick splitting because we love parsing sometimes of text winning right a lot of parsing function that they are all the string so use our own Unicode string another problem is usually that the Unicode string in Linux and some platform is 32 bits we are still using 32 bits but I think the planning goal is for is to make it UCS 16 a standard so it uses less memory for all the strings these strings also use the code data copy-on-write so strings are also copy-on-write you can pass them around and they will not really be copied it will just be referencing when you try to write one of them is going to then create a local copy so it's important to know that we also have a few more classes like set and map and hash map and well we have all those all those classical template those are much more similar to sto maybe what is different if I want you iterate them you just use very explicit pointers this is so it's just more explicit we have for vision in C++ 11 like the use of auto and these kind of things because we also always going to make the code very explicit it helps a lot to understand it when you read it and when you are reviewing code especially it also helps a lot because you don't have like the editor like this to check what a type was something is when you're on github really reviewing pull requests so having all the code very explicit it helps a lot for the contributors to review everything sent by our own computers if this is just a library you're writing on your own maybe you will feel everything we don't know that nobody will be able to understand how the library works but all this is a project that almost a thousand people contribute do so we make it very explicit to to make it readable so what's next ok one last thing this is RIT the air ADA class this is just a wrapper on around an integer this is used as an opaque reference to a resource you don't need to know anything else about this right now just that it exists there it is a type that we have in the engine it's used together with servers when I explain servers a bit more in detail you will understand what ready issues for but right now it's supposed just better hold on I think the recommended way of seeing this video is probably to stop and check the source code let's just stop the video and check the source code of what I am discussing so you understand it a better a bit better than just just unpause the video and continue so what is next I think we finally reach the object class so this is objects so objects is the base of every allocated objects on the heap I guess from God you just inherit everything all the nodes you see all the everything you see that you can access from from Jesus Creed like for example or c-sharp that is not a court type like vector or anything like that anything that is not those few chord types is derived from object so everything inherits object so this creates a custom kind of dynamic type with reflection in C++ which again we are just working around the simplest limitation so what does an object - you can check object here and has a lot of stuff let's check the public API so what object does is clearly more obvious so option has a cast to thing that you can use to cast to other types it's like dynamic cast in in C++ actually it does use dynamic cast as you can see here normally but you can compile Godot without our TT I which is what provides dynamic cast and then God will use its internal casting system which is the one you see we load that by default it's not used so some platforms like Android or html5 use the lower TTI option that means that God won't use dynamic cast and it will use its own system why does it do this well RTT ie uses a huge amount more of binary size and probably a bit more more memory and a bit more performance so not using our GT is mostly shrinks the binary like 20 percent so you can make smaller binaries so what it uses its own system for this by shrinking a lot the binary so not having our TTI is pretty cool because I mean having the option to not use it is cool because you can shrink the binary cuz us very small performant costs but you have a lot smarter binary we also can use exception single but this is something that you will see by by default I were actually before I will go back to object in a bit and show you something I forgot which is the error macros here instead of using exceptions we have this list of macros you can't just check a condition and just fail they being a lot is that you will never really throw in a section because if you throw an exception somehow it has to catch it pretty much and then has to nicely survive it this actually never happens some things just crash and when you're working with game development and you ship stuff you are probably wishing that things don't crash and just continue working so with exceptions even a smaller working crash for you so with all our handling is designed so you don't really need to catch anything we just throw an error telling you what happened and giving you a log and even if you're using the debugger is going to show you which line is coding originated the error it shows an explanation of their error or the function everything but it will try to do its best to survive so it won't fail is illegal we just provide pretty much everything and it won't crash you can probably see that if you use the editor is very difficult to crash because of the way it's designed we are very defensive with any kind of validation for arguments for any function we will try to validate them and if something is wrong with throw and run try to continue going on go we always try to survive and no matter what and it's programmed for that so let's go back to objects we're checking object two searches the error macros the file is around macros load H so let's go back to objects objects have a few things before besides the type for example you've got I will show you in code here you can for example garden object object get a glass you can get the string for the class you can use for example you can get our let me show you signals this is important of just have a list of signals you can connect a signal to do anything you want if you have learned how to use good you probably know already what signal stirring about you can even check the the the object reference you can do called deferred which is pretty important this means that all the color goes to the message queue this message queue is this one means cute message queue class this is a queue that has functions where you can push a call push a notification push push a set because you can have properties exposed in object so objects have this thing that is you can sit and get here and you can call a notification the notification is just any gnome it's just an integer every object has a different notification and then it has some macros here it has some really complex macro magic so for example I will show you like like the no that is cooler no there is no th-this isn't the scene but I will show you as an example you just inherit object you have to put this macro here which is like Gd class the type of object you are creating and the one you're inheriting this creates like if you see here it is not working you can check in the object dot H this macro is in there it's here it just creates all this in every class which allows you to set and get call notifications do a lot of different things so you can see that objects have a notification here and the protected part you can see like for example you have a right notification you can inherit another write this as many times as you want and it's not like inheritance is going to be called in every level you can use certain get if you want to wrap for setters and getters or you can use the binder system the vendor system is also overriding this you gonna write on every level it's a static override but it works kind of like a studying inheritance is pretty cool you just define this in your class and it's going to work again you can check a bit more in detail this in the documentation we have on the website I'm just doing doing more like an explanation of where everything is and what everything is so when you call bind methods which is here let me show you bind methods my methods this is static function and you call this class TV bind method so you use object together with class TV this is class TV class TV has like you combined functions and everything free and then the two reasons why you use class TV is to register like the notification the function you just kind of expose everything an option has by a class TV and then the scripting ApS can API is can make use of the object so you can see like for G star in class root three methods if you go to back to where we were you can see that node we just register all the methods here again you can check tutorials like on on this it's more explained in detail I'm just going to do an overview of what everything is and everything so class TV pretty much is what binds the engine to scripting you still need to use class TV if you want to receive a signal for example if you want to get a callback from a signal on C++ you need to bind that method by a class today because sangil's used the dynamic system that scripting use also so this is why you can also see sign ins from script and connecting them connect them from script unlike other systems that just use the C++ templates so didn't what's next I will sort these oh we just check this this file what was the name name a string name this is an another this is the G in 81 what is the class string name its quarter string name here it's in court let's go back to core core string name here so what is stringing what is the difference between string name and a regular string well string name is like a pointer to a string it's a unique pointer to a string when you create the string you can create it from a char string right your pointer or you can create it from a regular string that's one way we saw before but this will check if the string is registered in a table it has over here like this table of strings it's like a static hash table if the string already exists is going to give you a string name that contains a pointer to the existing string so these are actually unique every time you construct a string with the same string is going to be the same pointer in generally why is this useful you can use this to compare very quickly strings so instead of having to compare charter by character you just compare the pointer if you check here like operator equals just check that the pointer is the same even operator less you can check that the pointer is the same so you can use a map or a hash map with this and very quickly check the strings so when you have a string register somewhere and you just want to check very quickly like for example when you play animation you pass the name of animation you pass a string but usually it's a string name in most of the cases so God uses like for kinetic signals the animation uses Springs a lot but they are not really real strings they are actually string names they are pointers so all the comparisons are super super fast you can quickly find whatever signal animation whether you are going to use because it's just a pointer this is unfortunately not exposed in the scripting API ladies to change this for Godot for angle 4 you will be able to use spring names from scripting so you will that like I don't know whatever something to the string so you will be telling it the little string name or the compiler will detect itself because we now have select item typing but yeah spring name is just a faster way to bus drinks because they are pre saved and register and you're supposed to they're supposed to exist beforehand when you use them somehow so what is next okay next I think it should be interesting to check variant actually we could we could be barium for the next one you probably will be a bit busy with all these checking all day all these files so let's do a an overview of what we saw today we check the type test file we check the math headers we check the hours class which abstracts most of the old stuff we check the mine loop main loop is probably not something you really need to use but it's good just to know that it exists we check code templates the vector and everything we know they use copy-on-write which is the string also which is similar and it also uses copy-on-write we checked the object class which is the base for every non core typing a lot then every object or everything like from physics and notes and everything exists even the resources everything you access from the scripting API it's all objects and they have all the functions exposed by a class TV so they expose all the functions and properties and notifications and and constant these all by a class TV well we check a string name which is a wait for - having unit unit strings I'm going to show you a bit more about that before I forget so in object when you connect a signal where is the connection here you can check that it always uses a string them it never really uses raw strings it just screen name so yeah that's what's a name is for you can again just research all these topics for now so you get a better handle of them guess the next video I will describe more things like reference variants and everything but I think for for today this should be okay if there is anything you think I should be doing to make these videos easier or easier to listen more scripty or anything just let me know this is the first time I treated in this so any feedback is very appreciated well okay it's been a pleasure everybody thank you very much
Info
Channel: Juan Linietsky
Views: 26,828
Rating: undefined out of 5
Keywords:
Id: 5RIPRlCvRAk
Channel Id: undefined
Length: 37min 40sec (2260 seconds)
Published: Fri Dec 20 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.