Bringing Python to Godot 01/02/2020 Emmanuel Leblond - - - PowerPoint PPT Presentation

bringing python to godot
SMART_READER_LITE
LIVE PREVIEW

Bringing Python to Godot 01/02/2020 Emmanuel Leblond - - - PowerPoint PPT Presentation

Bringing Python to Godot 01/02/2020 Emmanuel Leblond - https://github.com/touilleMan/godot-python Godot ? Open source (MIT) Full featured Linux support Demo time ! Godot: dynamic from the ground class Node2D : public Node {


slide-1
SLIDE 1

Bringing Python to Godot

01/02/2020

Emmanuel Leblond - https://github.com/touilleMan/godot-python

slide-2
SLIDE 2

Godot ?

Open source (MIT) Full featured Linux support ❤❤❤

slide-3
SLIDE 3

Demo time !

slide-4
SLIDE 4

Godot: dynamic from the ground

class Node2D : public Node { GDCLASS(Node2D, Node); void set_rot(float p_angle); float get_rot() const; ... void _bind_methods() { ClassDB::bind_method(D_METHOD("get_rot"), &Node2D::get_rot); ClassDB::bind_method(D_METHOD("set_rot", "degrees"), &Node2D::set_rot); ... } }

godot/node2d.hpp

slide-5
SLIDE 5

Godot: dynamic from the ground

class Node2D : public Node { GDCLASS(Node2D, Node); void set_rot(float p_angle); float get_rot() const; ... void _bind_methods() { ClassDB::bind_method(D_METHOD("get_rot"), &Node2D::get_rot); ClassDB::bind_method(D_METHOD("set_rot", "degrees"), &Node2D::set_rot); ... } }

godot/node2d.hpp

slide-6
SLIDE 6

Godot: dynamic from the ground

class Node2D : public Node { GDCLASS(Node2D, Node); void set_rot(float p_angle); float get_rot() const; ... void _bind_methods() { ClassDB::bind_method(D_METHOD("get_rot"), &Node2D::get_rot); ClassDB::bind_method(D_METHOD("set_rot", "degrees"), &Node2D::set_rot); ... } }

godot/node2d.hpp

# C++ static traditional way Node2D *obj = new Node2D();

  • bj->set_ret(4.2);
slide-7
SLIDE 7

Godot: dynamic from the ground

class Node2D : public Node { GDCLASS(Node2D, Node); void set_rot(float p_angle); float get_rot() const; ... void _bind_methods() { ClassDB::bind_method(D_METHOD("get_rot"), &Node2D::get_rot); ClassDB::bind_method(D_METHOD("set_rot", "degrees"), &Node2D::set_rot); ... } }

godot/node2d.hpp

# C++ static traditional way Node2D *obj = new Node2D();

  • bj->set_ret(4.2);

# C++ Dynamic way Variant obj = ClassDB::instance("Node2D"); MethodBind *mb = ClassDB::get_method("Node2D", "set_rot"); Variant args[1] = {Variant(4.2)}; Variant ret = mb->call(obj, args, ...)

slide-8
SLIDE 8

Godot: dynamic from the ground

class Node2D : public Node { GDCLASS(Node2D, Node); void set_rot(float p_angle); float get_rot() const; ... void _bind_methods() { ClassDB::bind_method(D_METHOD("get_rot"), &Node2D::get_rot); ClassDB::bind_method(D_METHOD("set_rot", "degrees"), &Node2D::set_rot); ... } }

godot/node2d.hpp

# C++ static traditional way Node2D *obj = new Node2D();

  • bj->set_ret(4.2);

# C++ Dynamic way Variant obj = ClassDB::instance("Node2D"); MethodBind *mb = ClassDB::get_method("Node2D", "set_rot"); Variant args[1] = {Variant(4.2)}; Variant ret = mb->call(obj, args, ...) # GDscript

  • bj = Node2D()
  • bj.set_ret(4.2)
slide-9
SLIDE 9

Godot: dynamic from the ground

class Node2D : public Node { GDCLASS(Node2D, Node); void set_rot(float p_angle); float get_rot() const; ... void _bind_methods() { ClassDB::bind_method(D_METHOD("get_rot"), &Node2D::get_rot); ClassDB::bind_method(D_METHOD("set_rot", "degrees"), &Node2D::set_rot); ... } }

godot/node2d.hpp

# C++ static traditional way Node2D *obj = new Node2D();

  • bj->set_ret(4.2);

# C++ Dynamic way Variant obj = ClassDB::instance("Node2D"); MethodBind *mb = ClassDB::get_method("Node2D", "set_rot"); Variant args[1] = {Variant(4.2)}; Variant ret = mb->call(obj, args, ...) # GDscript

  • bj = Node2D()
  • bj.set_ret(4.2)
slide-10
SLIDE 10

GDscript ? Why ?

Variant Godot builtin int, float ... register API my_game.gd Godot Node ClassDB Compiler bytecode Interpreter Godot core GDscript

slide-11
SLIDE 11

BUT...

slide-12
SLIDE 12

Python ? What for ?

  • Game scripting
  • Testing
  • Asset pipeline with Blender
  • Bring Python ecosystem to Godot ;-)

Emmanuel Leblond - https://github.com/touilleMan/godot-python

slide-13
SLIDE 13

My Game

Bind to Python to Godot

godot.exe player.gd sprite.png map.tscn project.godot

slide-14
SLIDE 14

My Game

Bind to Python to Godot

godot.exe player.gd sprite.png map.tscn project.godot player.py pythonscript.so GDNative

slide-15
SLIDE 15

Control Godot from C with GDNative

# C++ static traditional way Node2D *obj = new Node2D(); Vector2 new_pos = obj->translate(Vector2(1.1, 2.2)); # GDNative C godot_class_constructor constructor = gdapi10.godot_get_class_constructor("Node2D"); godot_object *obj = constructor();

slide-16
SLIDE 16

Control Godot from C with GDNative

# C++ static traditional way Node2D *obj = new Node2D(); Vector2 new_pos = obj->translate(Vector2(1.1, 2.2)); # GDNative C godot_class_constructor constructor = gdapi10.godot_get_class_constructor("Node2D"); godot_object *obj = constructor(); godot_method_bind meth = gdapi10.godot_method_bind_get_method("Node2D", "translate"); godot_vector2 arg0; godot_vector2_new(&arg0, 1.1, 2.2); void *args[1] = {&arg0}; godot_vector2 ret; gdapi10.godot_method_bind_ptrcall(meth, p_obj, args, &ret);

slide-17
SLIDE 17

WHAT ?

  • Python as script language
  • Godot Callbacks
  • Builtins bindings
  • ClassDB bindings

Bind to Python to Godot

HOW ?

slide-18
SLIDE 18

WHAT ?

  • Python as script language
  • Godot Callbacks
  • Builtins bindings
  • ClassDB bindings

Bind to Python to Godot

HOW ?

  • Cython !
  • A looot of templates ;-)
slide-19
SLIDE 19

Generate ClassDB binding

godot.exe api.json 622 Classes !

slide-20
SLIDE 20

Generate ClassDB binding

godot.exe api.json bindings.pyx 6.3 Mo 622 Classes !

slide-21
SLIDE 21

Generate ClassDB binding

godot.exe api.json bindings.pyx bindings.c 6.3 Mo 87 Mo 60s 622 Classes !

slide-22
SLIDE 22

Generate ClassDB binding

godot.exe api.json bindings.pyx bindings.c bindings.so 6.3 Mo 87 Mo 12 Mo 200s 60s 622 Classes !

slide-23
SLIDE 23

Roadmap

  • Beta is here (we need you !)
  • MacOS build :’-(
  • Editor integration
  • Cython in games \o/
  • Godot 4.0

Emmanuel Leblond - https://github.com/touilleMan/godot-python

slide-24
SLIDE 24

Roadmap

  • Beta is here (we need you !)
  • MacOS build :’-(
  • Editor integration
  • Cython in games \o/
  • Godot 4.0

Emmanuel Leblond - https://github.com/touilleMan/godot-python

Write a game !!!

slide-25
SLIDE 25

Thank ! Q&A ?

@touilleMan touilleMan

Emmanuel Leblond - https://github.com/touilleMan/godot-python

slide-26
SLIDE 26

MicroPython

:’-(

  • ~90% Python
  • No pdb
  • Static heap
  • Documentation…

\*^__^*/

  • Smaller
  • Embedding friendly
  • Customization !
  • GIL is optional
slide-27
SLIDE 27

CPython + Pybind11

:’-(

  • C++...
  • ...with magic templates
  • Compilation time
  • Output size

\*^__^*/

  • C++ binding feels like Python
  • Autogenerate bindings with api.json
slide-28
SLIDE 28

CPython + CFFI

:’-(

  • Memory management
  • Overhead
  • Dynamic binding not for

Godot release \*^__^*/

  • You bind in Python !!!!

○ Closure ○ Call resolution done by Python ○ Just in time binding

  • Supports also Pypy
slide-29
SLIDE 29

CPython + Cython

:’-(

  • Compilation time
  • Output size

\*^__^*/

  • C speed
  • Python clarity
  • Allow us to write games in Cython !!!!