 Hello everyone, my name is Alejandro Garcia, and I'm going to talk about Python game development Here you have my Twitter and email. So if you have any question or something to ask me or whatever you want Just feel free to send me an email or Whatever, okay. And so the contents of this talk is first I'm going to talk about how Python is being used Currently in video games, and I'm going to show you my own game framework that I called it Cobra, okay, so how Python is currently used in video games And there are two ways of using Python in video games Okay, the first one is using Python as a secondary language for scripting and Here the main game is a program in another language like C++ for example And the Python interpreter is indeed inside the application, okay So the application calls that Python calls for certain actions such as what happens when two actors collide or so on but This wastes Python potential we don't use Python as much as we should and Python is designed to be extended not in bit. Okay so and some examples of game that use Python this way as a secondary language for scripting is See major civilization 4 and montan blade The other way of using Python for video games is using it as a primary language Here the pattern interpreter runs the main game loop Okay, and some buildings for improving performance can be used such as C++ or so on And we have a little slower than the previous example So some examples of game that use Python as a primary language are if online and metin 2 Next these are the most used Python libraries As a Python for primary language we have by game that is very easy and very popular You may know about it and we have cocoose 2d that is a bit more complex than pygame, but It has more features for 3d. We have blender 3d that as you may know, it's a 3d modeling tool But it also has a game engine. Okay, but don't say the blender 3d has is that is gpl So we can make commercial games for it and we have Panda 3d that is a Disney's creation framework that was used for their games such as Python's carry event. So Okay Developing games with Python. Python is very good language such as C sharp or JavaScript. Okay But The only problem is that there are very few game frameworks. C sharp is used for unity that is very popular JavaScript is used for well games, but Python is not now not currently used not because it's it's not good it's because There aren't any game frameworks and some of these frameworks are a bit limited or half an hour kitchen tour So I'm going to explain Cobra. That is my game engine It's an open source 3d game Video game framework. Okay, and it's three things dynamic Efficient and easy. Okay. So why is it dynamic? it is dynamic Because it uses an easy ECS architecture I'm going to play later what this ECS architecture is, okay So it's designed for real-world game development as you may know in the real game game development teams The game changes a lot because mainly of designers, okay? So this architecture helps us to change the game more easily and This makes Our game easily adaptable and extendable. So You may ask now. What is this entity component system? Well, it says stands for entity component system. Okay, so I'm going to show you an example Here is For example, this thing that we are working for E8 and we are developing Star Wars the new Star Wars Battlefront. So we have our game entity And from then we extend our ships and that ship can be either enemy ships or prior ships And these enemy ships can either be enemy x-wing or y-wing and the same with the players We are very happy or game Very well, and suddenly our dear game designer comes and say, hey What's up Romer? We have to change the game. So now we want a lead ship And then well, we just have to rethink again all the architecture. We have to rewrite a Lot of things and this is the new architecture that again we have with an A-seed A-seed and so on and it's very probable that Our game our game designer will come again and change our game over and over So I wonder is there a better way Well, I have the pleasure to introduce you to the entity component system It is used in modern game engines such as Unity 3d or Unreal Engine 4 and the basic concept is that the game entities that Goes on our game are just a list containing components that make up that entity. Nothing more. It's just a list Okay, so our previous example Our enemy x-wing will be a game entity that has an enemy control because it's controlled by the enemy It has a machine shooter because it shoots missiles sorry, and it has a thruster movement because it moves forward. So This component communicates with each other via messages. So here for example our Component enemy control wants to move forward. So the messages are sent to our entity components And then are consumed if needed. So the machine shooter resists forward but Because he doesn't need to know if it's moving forward then it ignores it But our thruster movement says, oh, okay, so you want to move forward. I'll do it and Our our x-wing will move forward So our architecture of of our previous example will look like this here. We have our enemy x-wing That is a game entity that has a control machine shooter at thruster movement as explained before and the only difference From the way we is that the machine shooter is replaced with blaster shooter. So making this with components we can just Reuse these components in different entities and here for example the player x-wing and the enemy Y-wing the only difference is that it's controlled with an AE and the player is controlled with keyboard control And the same goes with with y-wing So what do we achieve with this entity component system? The enemy doesn't need to know anything about the entity weapon or even if it has one He just send the message and if there is something like a missile or blast or whatever It will it will show for example if it there is nothing it will do nothing So we can quickly switch the blast with missile with the changing anything of a code making the code much more flexible to changes and Our friends the designers won't hurt us as much as As they usually do so I talk about entities. I talk about components now I'm going to talk about the systems okay, so Components don't do the hardware instead. They send commands to the systems and These commands are acute. Okay, and then later on they are Exituted in different threads this allows to use multiple cores using the full matching potential and we don't have to Because each system does a separate thing. We don't have to worry about interlocks at all. So Core is efficient. Why is it efficient? Because it has a C++ core. Okay, and it's multi core. So Here Here's Cobra uses Python and Python Communicates with C++ that has components and system. You can also program your own components in Python or C++ And your systems on C++ or Python and you may ask now, what about the gil? Who doesn't know what the gil is Who doesn't Okay The gil stands for global interpreter lock. It's a implementation feature of C Python that Doesn't allow us to run on more than one core. Okay So How do we solve this? Well, Cora is within C++ mostly. So This is how the main game loop goes. Okay for each entity in Python We update it components with Q commands to the systems and then when everything is done, we update the systems Okay, and for the update we will go to C++ and spawn a thread for each core of the system After that we update the system and we join and we can go back to Python without breaking anything of the gil This runs over and over on the game. So a Corrace is easy way CC. I tried to I was inspired by young okay to make this framework So I'm going to explain now a little example of how to make a simple project with Cobra so This is our this is a simple Cobra project. Okay, we have five files We have behaviors controller entities since and settings In the entity file we define each entity and the components you will have here for example I'm making a queue that it has three components. It has a Cartesian transform. This allows to this entity to be placed in the world of the scene and a Mesh renderer that allows us to draw a 3d model in this example I'm throwing up a cube mesh and a behavior that makes the cube to rotate so These are the most Important components that Cobra has sorry It doesn't read Okay for space transform we have a Cartesian transform that allows to as explained before it allows that entity to replace it in our world Polar transform that is just the same but instead of using a Cartesian transform is use a polar transform from the region or a screen transform that is a transformation in the screen space and this can be used for a user interface things, so These are The rendering okay, sorry for this and we have Mesh renderer that is for rendering meshes We have a mesh animator that ammage with that mesh and we have billboard renderer that Will render a billboard and a billboard is just a plane that always faces to apply Okay, so for physics have read body So body and box collides for collides for defining what kind of collisions we will have and for audio We have a audio source that is from where the audio is being played and the listener that In most the case it will be our player and there are much more components that you can use in Cobra, so and Behaviors in the behavior file we define the behaviors and Behaviors are components with for the fine messages The most important ones are stardestars or update and input in the studies it calls when When the entity is created Update calls in each tick of the game and input is when an input in the game happens, so With chorus and the messages is very easy. We just call set of components now the name of the message and here we put which Variables for output we want from that component and here in the keyword arguments. We we put the Input variables. I'm going to explain now. Okay Here's our last example Rotating behavior That just makes that that entity to rotate so here in the update that runs on a stick I'm sending a message to get the current rotation and as you can see here, I'm creating a dick That will be the output for that message and now I will have here my rotation and with speed with that speed I'm going to update it so And now I send this message set set transform with our new rotation It is also possible if you don't like to send messages to get a specific component and call a specific function on it so you can just get the transform and Call the rotation to get the current rotation and here updated just the same way as before Sorry, okay Controllers we define Mapping for different device inputs Here I'm getting the keyboard and an Xbox controller and here And I define what will be our game controller or game controller We have a fire button and x axis and here we make the Mapings saying that if this fire button is going to be a digital input that Will will map to the e key from the keyboard and the E-button to the Xbox controller So this way we will just check if the fire button is pressed And we don't have to worry if it was from the keyboard from the Xbox controller Keynet or whatever you want and the same goes with x axis This is an option input. It was just the same And design file we define the game scenes. Okay, so here I'm making oh, sorry The scenes have two important methods First they start that is called when the entity is created and then update that is called in each tick of the game Here I'm creating the previous queue Okay, and I'm calling each components to set the transform to the position 0 0 0 and in each update of the scene I'm displaying the current FPS of the game And settings dot be that it's very important It contains the game configuration and the system models that we want to use I want to explain that later And Here we set the game name in this case my name and the available resolution that our game will run Here for example this retrosolution among other settings at the one thing about this file is that here We we can set which systems will the entity component system use Here I'm using OpenGL open a L. Sorry Bullet and my own input from cobra So If if my don't want to use physics I just comment this and my game won't have physics. I don't want to use bullet. I want to use another physics library. I change it for The rendering the same if I want to use direct text So as you can see color is very extendable and you can just it's very pluggable Well And the other Okay, the current status of Cora is still in development. Okay, the the beta will be available on December And if you want to help me with this, I will be glad ready to to want to work with you And my future walls are to implement a particle system 3d Send in editor and work and support Work and support Do you know Vulkan anyone? Vulkan is the new graphics API that Chronos room will will release that will replace opengl In a short time, so I want to support it as well. And now I'm going to show you a simple Cora demo. Okay So Don't blame me. Okay. Sorry And I love Python tools for for visual studio. Don't blame me. Okay. Just run it See if it works. Well, it didn't work And This is a game like angry birds. Okay, but in 3d, we have this link shot our box and In this example is very easy. We just hold this space bar and when we release it Okay, and you can see here that I'm getting a score for the axis that are way outside And this is just So let's check the code. The code is very easy You can see here the entities that That I have I have the red box That has a partisan transform to be placed in the world mess rigid body Corridor and as an scorebox behavior this behavior. The only thing that it does is to Check if it has gone outside the the Don't know how to say it outside the The area. Yes. Thank you. Thank you Outside the area and we just At the score and we print our score. You can see it's very easy Here we have the player that's just the same But it has a very behavior and this behavior. The only thing that it does is check if the Space keys being press if so it charge up and move backwards and Then if it's released we send a message to Apply that impulse to forward you can see it's very This is all so Thank you for your attention. I hope you enjoy it any questions Yes Do you have Oculus rest support or you're planning in editing it? I don't have a clue support them Well, it would be a good idea. Yes, to the it was as well. You can just use a car transform But only moving around the X or Y axis You can use just the screen transform if you want Any more questions? Yeah Sorry So your message passing part is all in C But then it's calling back into Python to execute the the methods So what is the what for what is it just for the message passing that the Gill is released or do you have like a lot of components? written in C The components are written in C. Yes, but you can also write components in Python if you want and the systems say are Systems and the components can be programming in C or Python If I understand your question you're asking if the If all the messages are passed to all the NTPs Sorry to all the components First romance just yeah, so if you are so you're not getting you're not getting any performance benefits if your components are written in Python You only get them if you're writing them in C. Is that right? well the other performance is that the renderer is just the Ransy in C and and that's the the open GL calls that are the most expensive Right, so it's basically the rendering that is Three days everything you can just say make make a system in Python or in C just as you want Each system as I as I explained you can just In the settings it will just work Any more questions? Yes How does the framework approach the transport like problem? For example, you have a delay between client and server If I fire a bullet from client and they have a leg So is it possible with a framework to somehow approach that problem? Yes well the components are a bit bone to the To the systems, okay, so you have also to write the Components for your system if they are not compatible Any more questions? I have one. Do you support Python 3? and In the future Make it a promise Okay, do we have any more questions? Think for the talk. Where can I find the source code? The source code. I will upload it into my my GitHub I'm going to also make a web page It will be available on December if you want to or or if you want You can Tell me your email and I will send to you if you want, but it's it's still in development. There are some things that That needs a bit of work, but if you're interested I can send it to you with with the source if you want How do you see the future of? Python game development keeping in mind that There are a lot of high quality free engines out there I see it complicated. That's why I wanted to help Python to To be a thing in video game with this framework But I guess I see a bit complicated in the future So it's all code to render a mesh with what kind of shaders is that running and is it like a kind of deferred rendering engine or Customized the shaders that it rendering pipeline. It's the first rendering. Yes And can you customize the rendering pipeline? Yes. Any more questions? Okay, so I'll ask what platforms do you support? Well, I didn't try but it's it's open source so it can compile to Any platform I'm using boost push Python for the for the bindings of C++ and Well, the system is used at their own DLL and so on but a It's a bit complicated to to port right now, but it works for Windows for the moment So no Android for example. Oh for mobile I'm not planning for for being able to make games for Mobile for the moment Okay, does anybody else have a question? All right. Thank you