Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
University of Texas at Austin CS 354R – Game Technology S. Abraham
CS 354R: Computer Game Technology
Godot Overview Fall 2019
University of Texas at Austin CS 354R – Game Technology S. Abraham
Open Source Game Engine
• Godot is open source under the MIT license that provides • Cross-platform development support • GUI editor tools • Support for 2D and 3D game development • Ability to export to multiple platforms
• Free to use and readily viewable/modifiable code
2
University of Texas at Austin CS 354R – Game Technology S. Abraham
Additional Assets
• Additional plugins and modules available in the Asset Library: • https://godotengine.org/asset-library/asset
• Can also import materials and 3D meshes from asset creation tools like Blender and Maya • Godot does not support fbx, so export as collada
• 3D models and animations can be found on https://www.turbosquid.com/ • Only some models are free • Check copyright before using
3
University of Texas at Austin CS 354R – Game Technology S. Abraham
Godot Architecture
• Godot is object-oriented • Allows both composition and aggregation
• Nodes are fundamental building blocks • Scenes are composed of nodes • Everything is built on these two hierarchies
4
5
University of Texas at Austin CS 354R – Game Technology S. Abraham
Nodes
• Nodes can: • Be named • Have editable properties • Receive callbacks • Be extended • Be a child of another node
• Nodes inherit from all their parents • Has all properties in hierarchy
6
University of Texas at Austin CS 354R – Game Technology S. Abraham
Node Functionality
• Base class for all scene objects • Some of its properties:
• name (String) • owner (Node)
• Some of its functions: • _process()• _physics_process(float delta)• _ready()
• Inherits from Object, which is base class for all classes • Servers, MainLoop, Loaders, etc
7
University of Texas at Austin CS 354R – Game Technology S. Abraham
Scenes
• Formed from a hierarchy of nodes • Have one root node • Can be saved and loaded from disk • Can be instanced
• Every game has a main scene (.tscn) • Scenes can be anything
• Levels, characters, cameras, etc • Inheritance allows for nested prefabs
• Changing parent modifies all children • Scenes can be instanced and added to other scenes
8
University of Texas at Austin CS 354R – Game Technology S. Abraham
Servers
• Used for multithreading and data separation • Implements mediator pattern to process data and push
results back to the engine • Servers can run as parallel as possible and sync only when
necessary • Used in lieu of a heavier-weight job scheduler
• Servers do not handle objects or classes • Contain references to RID (Resource ID) types • Similar to the “System” part of ECS
• Servers for physics, rendering, logic, etc
9
University of Texas at Austin CS 354R – Game Technology S. Abraham
Godot Scripting
• GDScript and VisualScript are native Godot scripting languages • Integrated into editor
• C# and C++ bindings also available • Must be developed in separate IDE
• GDNative allows C++ scripting without recompiling the engine • Can also add C++ functionality via modules but must
recompile engine
10
University of Texas at Austin CS 354R – Game Technology S. Abraham
GDScript
• Designed specifically for game development/Godot engine • Optimized for Godot • Integrated in the editor • Built-in types for linear algebra • Multithreading support • No garbage collection (uses reference counting) • Dynamically typed
• Accesses functions and properties of node that script is attached to
• Example: func _on_Button_pressed():
get_node(“Label”).text = “Hello!”
11
University of Texas at Austin CS 354R – Game Technology S. Abraham
VisualScript
• Node-based scripting language that is composed using blocks and connectors
• Intended for designers and artists • Does not make coding obsolete but makes it more
accessible • Less room for optimization
12
University of Texas at Austin CS 354R – Game Technology S. Abraham
GDNative
• Module that can run native code and load shared libraries • Connects third party libraries to Godot without
recompiling the engine • GDNative API is in C
• Requires headers (separate download from Godot source) • Has C++ bindings (separate download from Godot source
and C headers) • Can access the whole GDScript API • Allows development of scripts using C++
13
University of Texas at Austin CS 354R – Game Technology S. Abraham
Why GDNative?
• Allows for highly optimized code without modifying source to create modules
• Connects additional third-party libraries to project without modifying source
14
University of Texas at Austin CS 354R – Game Technology S. Abraham
Why are We Using GDNative?
• Generally speaking, try to develop in GDScript for general purposes/prototyping
• Using GDNative for everything ignores a lot of the power Godot provides • But this is a game technology class, so we are going to
take a lower level approach :) • “Pulls back covers” on some of the things GDScript
intentionally hides
15
University of Texas at Austin CS 354R – Game Technology S. Abraham
NativeScript Setup
• Inherit NativeScript class from node • Expected includes • Constructor/Deconstructor • Needed properties and functions
• GODOT_CLASS() macro required for internal setup
16
University of Texas at Austin CS 354R – Game Technology S. Abraham
Registering Functions and Properties
• Must expose properties and functions that are called by Godot libraries
• Use static function _register_methods()• Call register_method(“method name”, &method) for exposed methods
• Call register_property<class, type>(“property name”, property, defaultValue) for exposed properties
17
University of Texas at Austin CS 354R – Game Technology S. Abraham
Inter-node Communication?
18
University of Texas at Austin CS 354R – Game Technology S. Abraham
Signals
• Implementation of Godot’s observer pattern • Observer nodes subscribe to a subject node’s messages • Subject nodes emit messages that all observing nodes
will execute • Used for callbacks on events • Allows for decoupled nodes to communicate safely
19
University of Texas at Austin CS 354R – Game Technology S. Abraham
Connecting Signals
• Can connect through script • subject->connect(“signalname”, observer, “targetfunction”);
• Can connect through editor • Must register signal in _register_methods
• register_signal<class>((char *)”signalname”, “parameter 1”, PARAMETER_1_TYPE, “parameter 2”, PARAMETER_2_TYPE, …);
20
University of Texas at Austin CS 354R – Game Technology S. Abraham
Emitting and Receiving Signals
• By convention, Godot uses naming: _on_<subjectname>_<signalname> for target function • Must create this function in the observing node
• Can emit a signal by calling emit_signal(“signalname”, parameter1, parameter2, …);
• Many nodes have existing signals you can access: • Area nodes have area_entered(Area area)/area_exited(Area area)
• BaseButton nodes have button_down()/button_up()
21
University of Texas at Austin CS 354R – Game Technology S. Abraham
Putting it All Together
• Must create a library of all NativeScripts as a plugin • godot_gdnative_init and godot_gdnative_terminate called when plugin is loaded and unloaded
• Register all classes in the library godot_nativescript_init• godot::register_class<class>();
• Compile the plugin using SCons • Define where dynamic libraries are loaded from • Create a resource for each NativeScript for connecting to
Godot node
22
University of Texas at Austin CS 354R – Game Technology S. Abraham
Engine Extensions
• Engines usually designed to be as modular as possible • Core includes core functionality anticipated in all games • Modules contains functionality that may or may not be
used • e.g. GDScript is a module in Godot rather than a core
feature • Allows for greater extensibility and good optimizations
• Editor extensions and tools • Custom AI systems • Custom rendering systems • etc
23
University of Texas at Austin CS 354R – Game Technology S. Abraham
Creating a Module
• Create a directory and custom class within the modules folder
• If class inherits from Godot hierarchy, must use GDCLASS(ClassName, ParentClass) macro to wrap it
• To add bindings for scripting, must use _bind_methods() to use functions in callbacks
• Register new class with Godot using register_types.h/.cpp
• Add SCons file (SCsub) and config.py script for compilation
24
University of Texas at Austin CS 354R – Game Technology S. Abraham
Tutorials and Getting Started
• GDNative <https://docs.godotengine.org/en/3.1/tutorials/plugins/gdnative/index.html>
• Custom Modules in C++ <https://docs.godotengine.org/en/3.1/development/cpp/custom_modules_in_cpp.html>
• Godot API <https://docs.godotengine.org/en/3.1/classes/index.html>
• Godot Core types <https://docs.godotengine.org/en/stable/development/cpp/core_types.html>
25