-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HexMapCellIdRef: passing a cell id to GDScript
Had to add a class for wrapping HexMapCellId to pass to GDScript. There's a whole series of problems here. First of all, ClassDB::bind_method() can only bind methods that return a type that can be cast to a Variant. From some resources the only two viable options were Ref<T> or a pointer to an Object subclass[^1]. Pointer means we need to somehow manage memory that we've entirely passed up to GDScript. Instead we use Ref<T>. Second problem, you cannot use Object subclasses on the stack in godot-cpp[^2]. This means if we make HexMapCellId a subclass of godot::Object, we cannot use it on the stack, or easily construct it using an initializer. Insteat we'd have to use `memnew()` all over the place. So we're using a wrapper class `HexMapCellId < public godot::RefCounted`. It's a boiler-plate heavy approach, but it works for now. Did propose to godot-cpp to add a compiler flag to disable the guard-rail that keeps us from using `godot::Object` subclasses on the stack[^3]. [^1]: https://forum.godotengine.org/t/returning-custom-classes-from-c-gdextension/65920/18 [^2]: godotengine/godot-cpp#1446 (comment) [^3]: godotengine/godot-cpp#1446 (comment)
- Loading branch information
Showing
9 changed files
with
361 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
[gd_scene load_steps=2 format=4 uid="uid://bt0soj2wvavie"] | ||
[gd_scene load_steps=4 format=4 uid="uid://bt0soj2wvavie"] | ||
|
||
[ext_resource type="MeshLibrary" uid="uid://ygm46u2uobsa" path="res://tileset.tres" id="1_43pbi"] | ||
[ext_resource type="PackedScene" uid="uid://wcaukixhlbo2" path="res://RayPickerCamera/ray_picker_camera.tscn" id="1_wtynj"] | ||
|
||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_bq4b2"] | ||
|
||
[node name="Node3D" type="Node3D"] | ||
|
||
[node name="RayPickerCamera" parent="." node_paths=PackedStringArray("hex_map", "marker") instance=ExtResource("1_wtynj")] | ||
transform = Transform3D(1, 0, 0, 0, 0.5, 0.866025, 0, -0.866025, 0.5, 0, 26.0113, 10.4268) | ||
fov = 35.0 | ||
hex_map = NodePath("../HexMap") | ||
label_cells = false | ||
marker = NodePath("../GridMap/Marker") | ||
|
||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] | ||
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 66.1477, 0) | ||
shadow_enabled = true | ||
|
||
[node name="GridMap" type="GridMap" parent="."] | ||
mesh_library = ExtResource("1_43pbi") | ||
|
||
[node name="Marker" type="MeshInstance3D" parent="GridMap"] | ||
mesh = SubResource("CapsuleMesh_bq4b2") | ||
|
||
[node name="HexMap" type="HexMap" parent="."] | ||
mesh_library = ExtResource("1_43pbi") | ||
cell_size = Vector3(1.154, 1, 1.154) | ||
cell_center_y = false | ||
data = { | ||
"cells": PackedByteArray("") | ||
"cells": PackedByteArray("/P8AAP7/AAAAAP3/AAD9/wAAAAD+/wAA/P8AAAAA//8AAPz/AAAAAP7/AAD9/wAAAAD9/wAA/v8AAAAA+/8AAP//AAAAAPz/AAD//wAAAAD//wAA/f8AAAAA/v8AAP7/AAAAAPv/AAAAAAAAAAD8/wAAAAAAAAAA/f8AAP//AAAAAP7/AAD//wAAAAD//wAA/v8AAAAAAAAAAP3/AAAAAAEAAAD8/wAAAAABAAAA/f8AAAAA/f8AAAAAAAAAAP//AAD//wAAAAAAAAAA/v8AAAAAAAAAAP//AAAAAP7/AAAAAAAAAAD8/wAAAQAAAAAA/f8AAAEAAAAAAP7/AAABAAAAAAD//wAAAAAAAAAA+/8AAAEAAAAAAPv/AAD+/wAAAAD6/wAAAQAAAAAA+v8AAAAAAAAAAPv/AAD9/wAAAAD8/wAA/f8AAAAA/f8AAPz/AAAAAPr/AAD//wAAAAD8/wAA/P8AAAAA/f8AAPv/AAAAAP7/AAD7/wAAAAD//wAA+/8AAAAAAAAAAPv/AAAAAAEAAAD7/wAAAAAAAAAA/P8AAAAAAgAAAPv/AAAAAAIAAAD6/wAAAAABAAAA+v8AAAAAAAAAAPr/AAAAAP//AAD6/wAAAAD+/wAA+v8AAAAA/f8AAPr/AAAAAPz/AAD7/wAAAAD7/wAA/P8AAAAA+v8AAP7/AAAAAPn/AAAAAAAAAAD5/wAAAQAAAAAA+f8AAP7/AAAAAPr/AAD9/wAAAAD5/wAA//8AAAAAAgAAAPz/AAAAAAIAAAD9/wAAAAABAAAA/v8AAAAAAgAAAP7/AAAAAAEAAAD//wAAAAAAAAAAAAAAAAAA//8AAAEAAAAAAAYAAAD6/wAAAAAFAAAA+/8AAAAABQAAAPz/AAAAAAUAAAD9/wAAAAAFAAAA/v8AAAAABgAAAP3/AAAAAAcAAAD9/wAAAAAHAAAA/P8AAAAACAAAAPz/AAAAAAgAAAD7/wAAAAAIAAAA+v8AAAAABwAAAPr/AAAAAAYAAAD8/wAAAAAHAAAA+/8AAAAABgAAAPv/AAAAAA==") | ||
} | ||
metadata/_editor_floors_ = [0, 0, 0, 0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters