bringing python to godot
play

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 {


  1. Bringing Python to Godot 01/02/2020 Emmanuel Leblond - https://github.com/touilleMan/godot-python

  2. Godot ? Open source (MIT) Full featured Linux support ❤❤❤

  3. Demo time !

  4. Godot: dynamic from the ground class Node2D : public Node { godot/node2d.hpp 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); ... } }

  5. Godot: dynamic from the ground class Node2D : public Node { godot/node2d.hpp 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); ... } }

  6. Godot: dynamic from the ground class Node2D : public Node { godot/node2d.hpp 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); ... } } # C++ static traditional way Node2D *obj = new Node2D(); obj->set_ret(4.2);

  7. Godot: dynamic from the ground class Node2D : public Node { godot/node2d.hpp 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); ... } } # C++ static traditional way # C++ Dynamic way Node2D *obj = new Node2D(); Variant obj = ClassDB::instance("Node2D"); obj->set_ret(4.2); MethodBind *mb = ClassDB::get_method("Node2D", "set_rot"); Variant args[1] = {Variant(4.2)}; Variant ret = mb->call(obj, args, ...)

  8. Godot: dynamic from the ground class Node2D : public Node { godot/node2d.hpp 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); ... } } # C++ static traditional way # C++ Dynamic way # GDscript Node2D *obj = new Node2D(); Variant obj = ClassDB::instance("Node2D"); obj = Node2D() obj->set_ret(4.2); MethodBind *mb = ClassDB::get_method("Node2D", "set_rot"); obj.set_ret(4.2) Variant args[1] = {Variant(4.2)}; Variant ret = mb->call(obj, args, ...)

  9. Godot: dynamic from the ground class Node2D : public Node { godot/node2d.hpp 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); ... } } # C++ static traditional way # C++ Dynamic way # GDscript Node2D *obj = new Node2D(); Variant obj = ClassDB::instance("Node2D"); obj = Node2D() obj->set_ret(4.2); MethodBind *mb = ClassDB::get_method("Node2D", "set_rot"); obj.set_ret(4.2) Variant args[1] = {Variant(4.2)}; Variant ret = mb->call(obj, args, ...)

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

  11. BUT...

  12. Python ? What for ? ● Game scripting ● Testing ● Asset pipeline with Blender ● Bring Python ecosystem to Godot ;-) Emmanuel Leblond - https://github.com/touilleMan/godot-python

  13. Bind to Python to Godot My Game project.godot godot.exe sprite.png map.tscn player.gd

  14. Bind to Python to Godot My Game project.godot godot.exe sprite.png GDNative map.tscn player.py player.gd pythonscript.so

  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();

  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);

  17. Bind to Python to Godot WHAT ? HOW ? ● Python as script language ● Godot Callbacks ● Builtins bindings ● ClassDB bindings

  18. Bind to Python to Godot WHAT ? HOW ? ● Cython ! ● Python as script language ● A looot of templates ;-) ● Godot Callbacks ● Builtins bindings ● ClassDB bindings

  19. Generate ClassDB binding godot.exe api.json 622 Classes !

  20. Generate ClassDB binding godot.exe api.json 622 Classes ! bindings.pyx 6.3 Mo

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

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

  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

  24. Roadmap ● Beta is here (we need you !) ● MacOS build :’-( ● Editor integration ● Cython in games \o/ Write a game !!! ● Godot 4.0 Emmanuel Leblond - https://github.com/touilleMan/godot-python

  25. Thank ! Q&A ? touilleMan @touilleMan Emmanuel Leblond - https://github.com/touilleMan/godot-python

  26. MicroPython :’-( \*^__^*/ ● ~90% Python ● Smaller ● No pdb ● Embedding friendly Static heap ● Customization ! ● Documentation… ● GIL is optional ●

  27. CPython + Pybind11 :’-( \*^__^*/ ● C++... ● C++ binding feels like Python ● ...with magic templates ● Autogenerate bindings with api.json Compilation time ● Output size ●

  28. CPython + CFFI :’-( \*^__^*/ ● Memory management ● You bind in Python !!!! ● Overhead ○ Closure Dynamic binding not for ● Call resolution done by Python ○ Godot release Just in time binding ○ ● Supports also Pypy

  29. CPython + Cython :’-( \*^__^*/ ● Compilation time ● C speed ● Output size ● Python clarity Allow us to write games in Cython !!!! ●

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend