Bringing Python to Godot game engine

Video thumbnail (Frame 0) Video thumbnail (Frame 547) Video thumbnail (Frame 1475) Video thumbnail (Frame 2884) Video thumbnail (Frame 5368) Video thumbnail (Frame 6228) Video thumbnail (Frame 6859) Video thumbnail (Frame 7895) Video thumbnail (Frame 11643) Video thumbnail (Frame 13481) Video thumbnail (Frame 15058) Video thumbnail (Frame 23675) Video thumbnail (Frame 32292) Video thumbnail (Frame 33198) Video thumbnail (Frame 35375) Video thumbnail (Frame 35924)
Video in TIB AV-Portal: Bringing Python to Godot game engine

Formal Metadata

Bringing Python to Godot game engine
Title of Series
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Bringing Python to Godot game engine [EuroPython 2017 - Talk - 2017-07-10 - PyCharm Room] [Rimini, Italy] Godot is an advanced, feature-packed, multi-platform 2D and 3D open source game engine. The project has joined the Software Freedom Conservancy project and it growing community makes it hopes to become a real alternative to Unity&GameMaker. This talk cover a year long journey of the port of Python as a scripting language for the engine, starting from a rant against Godot's Python-like proprietary language. We will have a look at Godot's internal architecture as is it itself a real interpreter with it garbage collector, dynamic typing, introspection and even builtin custom scripting language. All of this having to work next to our Python interpreter and communicate back and forth with it. Finally we will see the different approaches that have been tried to bind Python to Godot each with there own pros&cons: Using Micropython interpreter instead of CPython Using PyBind11 to statically bind to Godot C++ API Using CFFI and rely on a 3rd party C API The audience should have some basic knowledge of C level computing (static vs dynamic language, compilation & linking)
Web 2.0 Intel State of matter Multiplication sign Software Game theory Game theory
Existence Multiplication sign Closed set Lemma (mathematics) Boilerplate (text) Source code Computer programming Web 2.0 Dew point output Game theory Window God
Scripting language Electronic data interchange Demo (music) Multiplication sign 1 (number) Domain-specific language Demoscene Category of being Roundness (object) Energy level Cuboid Game theory Computing platform
Scripting language Logical constant Category of being Functional (mathematics) Formal language Exception handling
Database normalization Mapping Physicalism Bit Game theory
Scripting language Oval Personal digital assistant Multiplication sign Demo (music) Damping Aerodynamics Game theory Codierung <Programmierung> Formal language
Classical physics Bytecode Dynamical system Functional (mathematics) Server (computing) Run time (program lifecycle phase) State of matter Multiplication sign Source code Formal language Medical imaging Arrow of time Damping Aerodynamics Data structure Endliche Modelltheorie Macro (computer science) Error message Social class Scripting language Rotation Module (mathematics) Information Interface (computing) Moment (mathematics) Variable (mathematics) Compiler Category of being Interpreter (computing) Right angle Game theory Object (grammar) Modem Spacetime
Dynamical system Presentation of a group Run time (program lifecycle phase) Code State of matter Multiplication sign View (database) Execution unit 1 (number) Programmer (hardware) Cryptography Semiconductor memory Different (Kate Ryan album) Data compression God Social class Physical system Scripting language Moment (mathematics) Keyboard shortcut Staff (military) Formal language Type theory Angle Order (biology) Data conversion Reading (process) Point (geometry) Implementation Functional (mathematics) Microcontroller Mass Template (C++) Pi Goodness of fit String (computer science) Green's function Computational fluid dynamics Speicherbereinigung Energy level Software testing Metropolitan area network Compilation album Electronic data interchange Generic programming Symbol table Integrated development environment Logic Interpreter (computing) Social class Game theory Object (grammar) Library (computing)
Axiom of choice Point (geometry) Functional (mathematics) Just-in-Time-Compiler Beta function Computer file Code Multiplication sign Real number Disintegration Source code Set (mathematics) Template (C++) Revision control Goodness of fit Mathematics Roundness (object) Compiler Cuboid Software testing Endliche Modelltheorie Text editor Scripting language Module (mathematics) Forcing (mathematics) Keyboard shortcut Moment (mathematics) Projective plane Binary code Bit Lattice (order) Line (geometry) Complete metric space Demoscene Electronic signature Word Loop (music) Personal digital assistant Artistic rendering Order (biology) Game theory Data integrity
CAN bus Network topology Code Coalition Order (biology) Video game console Codierung <Programmierung> Usability
Module (mathematics) Scripting language Programming language Beta function Ferry Corsten Disintegration Infinity Computer programming Field (computer science) Spherical cap Order (biology) Game theory Text editor Traffic reporting Tuple Window Social class God Library (computing)
State of matter Projective plane Moment (mathematics) ACID Data storage device 1 (number)
NP-hard Scripting language Android (robot) INTEGRAL Linear regression Binary code Keyboard shortcut Shared memory Online help Mereology Computer programming Wave Bit rate Personal digital assistant Order (biology) output Software testing Game theory
is eminently want based web and came on state so higher among thank you for coming into this conference uh 1st let me introduce myself a I'm Emmanuel uh most of the time I'm not doing game
programming and web stuff it's kind of a hobby for me uh things kind of people you know which every 6 months I get a really great idea for a game it's what I all I have to to do that and so I started working in the game and after like 2 months on end up I realize I spend all my time making it a game giant and not the game so I get pretty disappointed and I jumping and so last time had this kind of really great ideas that appear the same I mean messed up I would just take your an existing game giant and for this 1 the personal my dear and that's how alignment goal
so let's go to good always a full feature of these just like 1 binary which get everything in the same around and just 1 pick age so there's plenty of features like a physical and gene to these with rendering you and John on this creates that you can do profiling you have at the input which is manage for you that basically you have older the hassles of boilerplates we are all already done for you would you just focus on the on the uh those are a great features about God 0 it's it's of source it's MIT license sold meaning you can basically do your own game close and sell it to you you have got to pay anything and 1 thing which was really important for me it's uh dessaline except so you don't have to go to Windows and give up game on windows because kind of boring so
now it's time for a little demo on what good looks like so this
is basically a few already according to unity Damon giants looks kind of the same so you have these these panel which is a you domain scene of the game I can do about it is that people would be too much there's my level uh so basically what you do world by building a game is you create this scene with plenty of nodes so you can see on the right side you have not for basically everything so here's kind of bonus it's kind because round platform game uh every enemy are also sorry every enemies also annulled like these that you can customize the every now the here we have plenty of people of properties uh 1 great thing about go is you can nest scenes inside scenes so what does it means is for example this enemy of right now in main seen it looks like it's just a simple nod but in fact if we look at it it's much more complex and finds all little guy he is composed of plenty of notes so it teach self-esteem and you can see that there is no heed box here for example uh there is a sprites there is animation and now we can tweak this mystical guy how we want for example I can show that the walking animation and work on applied that uh another thing I can do is to plug in scripts on any node i want to extend it so for example we can see on a
meat has a script here uh it's a it's a custom language which is called a Jedi scripts each kind of look alike by some it's inspired by Python which is not Python so there is no self keyword for example so
constants will get about it later as so with discrete so I can extend the what's the not can do I can attach new property for example I can create new function connect 2 signals except for oxygen and have so if I go back to my main
seen here so I can start to room missing a it around I can move these guys here I can change a bit to the map how it looks like an ideal inducing like that I can for example add and you and you can't here just to put the kind and if I'm good I can start running the game so here he is he didn't
crash incredible and so here it is I have my my dimen giant with all the physics already redundancy I'm really pretty poor about it and so it just work and so 1 thing about the
game and giant is a G Street is always a question that culture every time is why is it so why did said just create from scratch a new game language a new script language uh reinventing the wheel and see that just taking place on taking you out which she's is already designed for this kind of use case and to answer this question we should look at how will go to works from the inside so if we look
at that I said that the leaders that the encoder we have you seen and everything is another so if we look at a for example to do not which
is basically basically gets the nod and you add some property to move it into 2 D space so for example here you have a rotation so for the moment is really simple suppose for scum but what you do in goto is you add the server macro GT class and this function by insult and basically what you're doing by doing this is you add introspection into your class so now with these things you can do 2 things you can if you want to to create a game only using C + + 2 connecting to the C + + goto API you can do we just so the classical superstar wages just like this so using new keyword you creates an object and then use the arrows to call the function or you can go all through this so this thing which is called clears DB do something with them and using the same with and in fact you go dynamically so it's during runtime that you will ask the game engine you asked has to be to retrieve the no the the class which is named not to the to instantiated and then after that you asked to retrieve a function set rotation and to apply it to the subject and if you apply for example was the wrong function through the wrong object you won't blow up like a sec or something like that just read you end up with a uh an error object you can handle nicely you can see all around there is also violent object uh and if you think about it I mean you just like you in Python in fact in C Python you have just your C Python interpreter which has not been compiled by you and you have your or your scripts uh everything every variable in your streets is represented inside of C bison as a pi object structure and so these pi object can contain basically everything of float to an objective class from so it's just like the singer and goto you have these bargains class which contain anything so what about g disparate uh just created is looks really simple returns a dynamic interface but in fact is exactly the same thing is just coming in way to wrap this suppressed posting image API of to so putting Annals of
putting it as a way and you can see that you have on the left what is the so-called functionality of good which is so uh this violent to a class which contain basically anything and discuss the structure of the which contained all the information you can retrieve at from time about the note n on the right side you have a really simple G Street module which is basically 2 things 1 is a compiler to turn your your gold all human readable source code into buys called and and the thing is just a really tiny interpreter which state every byte code 1 by 1 and just call the equivalent called which is provided by it has to be so in the end it's and it's a really simple model it's something that is not like you're using a really big and be read the interpreter with plenty of property and functionality and so on it's just something really tiny really simple on a really uh and it's it's deeply into integrated with Godel so it works pretty well uh so there is nothing to fear about these G descriptor right 1 of the few use gaze where inventing a new language is fine but what we're here for pi
somewhat not for G descriptor and in fact I really love Python and when I start using this and and we've got of referred to discrete sorry I was always thinking about my son's he all we could do this better in Python for example I could take sees game logic outside of Xinjiang and start unit tasting we've pi test so it would be much more easier to do this thing uh I could also for example broader and the Python ecosystem into my game for example uh start using the pi torch library to user mashine learning to create a Iittle and stuff like that so all I and of realizing what I really want is I should spend a couple of week maybe amounts into trying to put my son into goto and then after that I will go back to my game and the time and I will say because now I have pi some angle with re was it and so why will recover my time invested into doing this
as so now how do we do that the 1st thing we have to do is to tell those there is a new player in the in the game which is a python and no if it finds outside he's asked to mold . I find it should come to see almost soul doing this is pretty simple there is already a generic class in goto which represent what the script languages and so we have to implement this the 2nd thing it is that uh we have to create bindings so we have to create binding fast for pies and to manipulate the object uh so there is pretty simple object like bold like mass for for example as I'm all dynamics 1 likes and all those things you before also for the node we can use a plastic in its custody API to create the binding just lazy the only ones on they needed at runtime that the only trick we have to take to make sure about it uh with those things is we must be sure to manipulate the god objects through all binding and not copies data because most of the time you get down from below you start modifying and then beat you return them to go and and good always doing stuff reading is modifying it except for an next thing is converging environment in 2 pi object so all the way total represent dynamic type into the way Python and represent any type so it really straightforward so there's no real big deal about this and the much more complex than is handled memory because now we end up with 2 different garbage collector 1 for old and wonderful pi and we have to make them work all together and most of the time what happens is you start creating an object from inside and for example you pass it to go to and so from the point to the present point of views there is not much about it about this memory so it can start to clean it to erase it and so it's called up at a time when good will start to actually read those that so we have to take care of this and now we can talk about the implementation so I said uh I was paying full something like 1 oz state to implement this uh I did man so it's been 1 year now uh so I started at the real beginning using my replies uh the reason why it's the 1st and the the guy behind those already tried to to to Python on below and this at the binding was a real pain in the ass and so it was a lot of time and the code was within read again so it didn't work out so I said OK let's try something else but the good thing about Michael price and there is a lot of customization you can do when you choose to bold it uh you can disable pay a feature that in order to have you interpreter consume less RAM and have less than eighties so maybe you can sing making a sandbox because you reduce a lot of functionality of your streets and so it's in really interesting and the trouble about it it is a micro bites and is designed to be run on microcontroller on system with which already limited you read memory which is not what you do when during game basically of a gigabyte of RAM and so there that's always uses the CPI is really a lower level that it would be with C and for example uh saw for example when you are working with strains and you're not free working restrains of most of the time the strings are all connected together and that during the compilation time like basin is looking for is a substring are reused from time to time and it does the same they're just old connect them together and so in the end you don't mind a string you just manipulate and maybe on a string so uh everything like these in my and so it makes DAPI much more difficult to work with and uh so yeah it's it was really hard to work as a dealer thing is it's not 100 per cent Python so all I said I wanted to have all the and green eyes pies ecosystem of it but uh with my Python for example you don't have the same CPI uh you don't support really dynamic staff soul and there's plenty of library that will work with Michael by some of uh 1 example is for the moment there is no support for the PD library which is in the symbol when using about it because uh micro by selling its for microcontroller and that when you run your column microphone forever you don't have access to a CNS to the out so you just don't budget with PDB but when you are working with a game it's much different you really want to be able to just put the PDB everywhere and jump in and start doing introspection and so on and so it was not to re beside uh so around this time we got the pulls them in Belgium and just after the falls them with a single was really 1st go to come so all the global programmer amid their tools will refund time to because Belgium and so you eat Freising you drink beer she's really good for programmers and so we have a lot of IDE and so on I realize my compression just won't do it and so I switch to see Python Weaver piping 11 uh pining 11 is the simplest of library which is kind of it does kind of magical tricks with C + + templates so basically you have your C + + class you wrap it with the uh hiding 11 and you immediately end up we have uh Python
module so it works really well it's really it against you you feel like your your working with Python from weavings C + + but the trouble is you ordinary static templates so you have to see this sportscaster you buy and eat and then you get it into Python but the way to go the words is much more dynamic I said you have this and you have this test DB things we when you can do introspection but you cannot use it a way if by being alignment so in the end you end up high enough for having to write a scripts uh which possible of the source code of goto in order to get boxes in the C + + API and then generate a glucose or the for force scripts before bindings so in the end it was like 100 thousand line of C + + templates everywhere generated at the completion of these was a real nightmare for something like 5 minutes just for these files uh Weaver of 5 gigabytes of RAM used and in the end you you add like you're up to 100 mega bytes of to your final binary so it was yeah it works but it follows ready and not elegant and uh re cumbersome to work with I mean every time I had to do just a simple change I have to wait more than 5 minutes just to see the recompilation uh so yeah it was kind of painful but at a time there was always a good little the go community was always there and so we had a new meeting at multi-line Paris uh we even have the the main developer of glottal which is from Argentina so we cannot see him in person normally but you when there we wife was vacation was kind of the green eyes and so we talk a lot about all the trouble then so I end up at the end there was a new feature into inside which was as they created a CPI ball on top of the C + + API and so it was a real game changer because with the CPI I could just drop everything and switch to see if if I uh which was a really good choice if you sold and confront from going on in Russia this morning so basically see if you buy user solving every problem but what you do is just you create a script in scriptures say on I want to use from into Python these function and this function you just copy-paste the the function signature then if you put your Python called to say OK I want to and that is called into my model and you end up with the defining OK I want these bison function to look like these function in to see if it goes from C send run strips and you end up with 1 c 5 you just have to combine and you get a model and the absolutely great thing about this is uh most of your binding all done now in place so it means that you have no longer to come by and you just have to comply once and given all you will most of the code despised and you just loaded dynamically and so you can change everything and any time and you don't have to recombine so compared to pioneer of and it was like a game changer and but on top of that you get pi for free which means that the combined the compatibility is here it's Ricci cheap and so yeah just having pipeline is just a really good use case for I mean gaming giant really good use case for pi pi because it's always the same loop which is round was a sense free and that as in the just-in-time compilation can really do a boost so I hope it's we make it Bruce eventually in go and so you are here and now we have a bit of which is available uh it was really is the last week in a hurry because of this conference and so I have something to show but it works pretty well and didn't but so far but but that's why we need you to find the best I'm sure there's plenty of them uh and the and the other thing is that pipeline so I said this would be a really really nice feature to have it uh the only ready the problem is for the moment I'm using a new version of a global because go is kind of really young project and he's been open-sourced in 2014 so it's been 3 years of their work a lot on its own there is plenty of new feature this new reason which is 3 point always uh you just coming out soon it will change a lot of things they're all all chances for you renderer for example you a physically based rendering have knowledge the scenes that I the change a lot a lot of things uh the thing is now the reason Alfonso I got to go to in our file I got my module which is really earlier so what I I believe it is at the top and all I'm holding with this uh pi-pi which is in beta also for pi by 3 . 5 so we have 1 out far out to beta altogether and so at end up with a big stake but it also so we have to find out and then we have to the next thing would be going to data integration because right now it's kind of wrong uh if you see a
like a set of data is very nice because everything is packed together so it's it's a really interesting but right now if I want you to
debug my straight we buy put PDB somewhere for example uh it's not like that it's but you have to go to Council and I can use of the
console and use PD like that it would
be much better to be able to use that to the bigger of a panel here in order to do this stuff has a nice things would be to be a travel to coalition forces for the cold Python code into usable tunity sure in the encoder
and last but not least I them with the most important thing would be to add a new I mean right now the CAP
API use we see if if i is not complete enough I have access to the polls in light of access to that was a class the stuff to my introspection but a doorway I register my module to go to to say OK there is a new modules for for programming language for script language on the on the program uh I'm still using C + + so what it means is that I have to read is an anterior and giant I compiled myself with this tuple of pipeline of Python sorry uh and I have to give it to you to people which is really cumbersome because I should support windows I should tuple Linux Mac OS and exit from and it's not like the the field of the of God always you have just 1 binary and then you just can't of use each the left recombined stuff and so on so the reusable infinity and going to work on used to improve the CPI in order to just be able to come go to as a shared library just a simple but Astle stuff which you can just drop on the on your a game folder and then go to see these things would load it and then you go to the present report like that uh the really good things would
be to have it and the acid stroke because you can see on go you have an acid store just like in unity uh for the moment it's a state that's of called of to discrete Scott but it would be really good you know you start your new project you go on the acid store you double click on the present and then you get to Python just like that so
that these are the final goal and I think if I think this I could go back to work in my day I too late for what what it was about by the way there are so thank you
very much have a
few say 1 more thing that I will be on the would be all this week under under your by then and I will also be on the the Sprint which all this weekend so if you interested into in the project and want to hand out to just tell me and altogether thank you they wave but sometimes for 0 questions if you have 1 please try Japan we have a microphone thank you for the talk and of course the question is what about performance on the assignment of Jesus but at there is to thing 1st is to discrete is already known to be slow I mean there is people complaining about it now we have no idea if it's because it's really all because people just composer comparing G Street to surpass fossils there need to be some test which is to be done but nobody has done that yet uh so maybe if I run benchmark right now Pisoni is faster than G Street even if there is a big binding because G Street is not optimized but I don't think it's a case uh but anyway uh I seem to improve the performance of the these bindings there is a pi pi so that's my hope that I wish for he holds that pi we make Python really fast and so the the binding layer which makes things slower but not that slow because you get a boost from pipe do you support mobile the export like I was and you mean that to support and rate with yeah we support I I I was uh desa enzyme has been used for reasons of Mr. Bean game on Android and IOS for example you can play it this free I don't share on it but the but this may be a related question but some does not currently make it easier to just be games for PC and and does he will like up like integration and high-priced make hard things sorry again this regression and you could you please speak a lower case so you know when you want to publish things that the parties and I you want to use them on a PC help and does using pi pi as part of a pipe quite will see like as part of I go again make it harder to publish things uh basically uh when you really gain is just like you you have your your folder which contain your assets in your script and you put the divine as a binary of gold just as as a program you just put it inside a folder and you get to know everything is OK everything works as there is more advanced way to do it if you want for example to to street you cold in order not having people can easily you read what it is uh down more but you can also do I sing now there are people working on supporting of the steam API to reuse game with steam uh and so on yeah there is work on it and the already game which has been shipped with so long as he it works that the thank you yeah