Skip to content

Commit 0bdb75c

Browse files
authored
Improve Custom Callables and add SignalConnector (#803)
1 parent a222268 commit 0bdb75c

File tree

66 files changed

+5441
-5817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5441
-5817
lines changed

harness/tests/src/main/java/godot/tests/JavaTestClass.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
@RegisterClass
1212
public class JavaTestClass extends Node {
13-
@RegisterSignal
14-
public Signal0 testSignal = Signal0.create(this, "test_signal");
15-
16-
@RegisterSignal(parameters = {"param1", "param2"})
17-
public Signal2<String, String> testSignal2 = Signal2.create(this, "test_signal_2");
13+
//@RegisterSignal
14+
//public Signal0 testSignal = Signal0.create(this, "test_signal");
15+
//
16+
//@RegisterSignal(parameters = {"param1", "param2"})
17+
//public Signal2<String, String> testSignal2 = Signal2.create(this, "test_signal_2");
1818

1919
// The following should NOT work as we cannot extract parameter names. The compiler checks should catch that and throw a build error
2020
// @RegisterSignal
@@ -71,15 +71,15 @@ public String greeting() {
7171
@RegisterProperty
7272
public Dictionary<Float, String> dictionary = new Dictionary<>(Float.class, String.class);
7373

74-
public LambdaCallable<Void> lambdaCallable = LambdaCallable0.create(
75-
Void.class,
76-
() -> {
77-
System.out.println("Hello from Callable");
78-
return null;
79-
}
80-
);
81-
82-
public NativeCallable methodCallable = Callable.create(this, StringNames.asStringName("DummyName"));
74+
//public LambdaCallable<Void> lambdaCallable = LambdaCallable0.create(
75+
// Void.class,
76+
// () -> {
77+
// System.out.println("Hello from Callable");
78+
// return null;
79+
// }
80+
//);
81+
//
82+
//public NativeCallable methodCallable = Callable.create(this, StringNames.asStringName("DummyName"));
8383

8484
@RegisterFunction
8585
@Override
@@ -96,12 +96,12 @@ public void _ready() {
9696

9797
@RegisterFunction
9898
public void connectAndTriggerSignal() {
99-
connect(
100-
StringNames.asStringName("test_signal"),
101-
new NativeCallable(this, StringNames.asStringName("signal_callback")),
102-
(int) ConnectFlags.ONE_SHOT.getId()
103-
);
104-
emitSignal(StringNames.asStringName("test_signal"));
99+
//connect(
100+
// StringNames.asStringName("test_signal"),
101+
// new NativeCallable(this, StringNames.asStringName("signal_callback")),
102+
// (int) ConnectFlags.ONE_SHOT.getId()
103+
//);
104+
//emitSignal(StringNames.asStringName("test_signal"));
105105
}
106106

107107
@NotNull

harness/tests/src/main/kotlin/godot/tests/FuncRefTest.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import godot.annotation.RegisterFunction
66
import godot.annotation.RegisterProperty
77
import godot.annotation.RegisterSignal
88
import godot.annotation.Rpc
9+
import godot.core.callable0
10+
import godot.core.callable1
11+
import godot.core.connect
912
import godot.core.signal0
10-
import godot.extension.call
11-
import godot.extension.callDeferred
1213

1314
@RegisterClass
1415
class FuncRefTest : Node() {
@@ -51,12 +52,12 @@ class FuncRefTest : Node() {
5152

5253
@RegisterFunction
5354
fun testCallWithoutParam() {
54-
call(this::withoutParamCallback)
55+
callable0(this::withoutParamCallback).call()
5556
}
5657

5758
@RegisterFunction
5859
fun testCallDeferredWithoutParam() {
59-
callDeferred(this::withoutParamCallback)
60+
callable0(this::withoutParamCallback).callDeferred()
6061
}
6162

6263
@RegisterFunction
@@ -66,11 +67,11 @@ class FuncRefTest : Node() {
6667

6768
@RegisterFunction
6869
fun testCallWithParam() {
69-
call(this::withParamCallback, true)
70+
callable1(this::withParamCallback).call(true)
7071
}
7172

7273
@RegisterFunction
7374
fun testCallDeferredWithParam() {
74-
callDeferred(this::withParamCallback, true)
75+
callable1(this::withParamCallback).callDeferred(true)
7576
}
7677
}

harness/tests/src/main/kotlin/godot/tests/Invocation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import godot.extension.getNodeAs
4242
import godot.registration.Range
4343
import godot.tests.subpackage.OtherScript
4444
import godot.common.util.RealT
45+
import godot.core.connect
4546
import org.joda.time.DateTime
4647

4748
enum class TestEnum {

harness/tests/src/main/kotlin/godot/tests/callable/CallableMethodBindTest.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import godot.api.Node
44
import godot.annotation.RegisterClass
55
import godot.annotation.RegisterFunction
66
import godot.annotation.RegisterProperty
7-
import godot.core.NativeCallable
7+
import godot.core.MethodCallable
88
import godot.core.VariantArray
9+
import godot.core.toGodotName
910
import godot.core.variantArrayOf
1011
import godot.global.GD
1112

@@ -16,22 +17,22 @@ class CallableMethodBindTest: Node() {
1617

1718
@RegisterFunction
1819
fun callWithMethodWithAllBinds() {
19-
NativeCallable(this, CallableMethodBindTest::readySignalMethodBindTest).bind(1, 2, 3).call()
20+
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(1, 2, 3).callUnsafe()
2021
}
2122

2223
@RegisterFunction
2324
fun callWithMethodWithTwoBinds() {
24-
NativeCallable(this, CallableMethodBindTest::readySignalMethodBindTest).bind(2, 3).call(0)
25+
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(2, 3).callUnsafe(0)
2526
}
2627

2728
@RegisterFunction
2829
fun callWithMethodWithOneBind() {
29-
NativeCallable(this, CallableMethodBindTest::readySignalMethodBindTest).bind(3).call(0, 0)
30+
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(3).callUnsafe(0, 0)
3031
}
3132

3233
@RegisterFunction
3334
fun callWithMethodWithNoBind() {
34-
NativeCallable(this, CallableMethodBindTest::readySignalMethodBindTest).bind().call(0, 0, 0)
35+
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe().callUnsafe(0, 0, 0)
3536
}
3637

3738
@RegisterFunction

harness/tests/src/main/kotlin/godot/tests/coroutine/CoroutineTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ class CoroutineTest : Object() {
124124
@RegisterFunction
125125
fun asyncLoadResource() {
126126
godotCoroutine {
127-
val resource = ResourceLoader.awaitLoadAs<PackedScene>("res://Spatial.tscn") { progress ->
128-
GD.print("Resource load progress: $progress")
129-
}
127+
val resource = ResourceLoader.awaitLoadAs<PackedScene>("res://Spatial.tscn")
130128

131129
GD.print("Resource: $resource")
132130

harness/tests/test/unit/test_call_java_class.gd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func test_field_set():
2121
java_scene.free()
2222

2323

24-
func test_signal():
25-
var java_scene: JavaTestClass = load("res://java_test_scene.tscn").instantiate()
26-
get_tree().root.add_child(java_scene)
27-
await get_tree().create_timer(1).timeout
28-
java_scene.connect_and_trigger_signal()
29-
assert_true(java_scene.signal_emitted, "Signal should've been emitted in java")
24+
#func test_signal():
25+
# var java_scene: JavaTestClass = load("res://java_test_scene.tscn").instantiate()
26+
# get_tree().root.add_child(java_scene)
27+
# await get_tree().create_timer(1).timeout
28+
# java_scene.connect_and_trigger_signal()
29+
# assert_true(java_scene.signal_emitted, "Signal should've been emitted in java")

harness/tests/test/unit/test_funcref.gd

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@ extends "res://addons/gut/test.gd"
22

33

44
func test_call_without_param():
5-
var func_ref_test_script = FuncRefTest.new()
6-
func_ref_test_script.test_call_without_param()
7-
assert_true(func_ref_test_script.call_flag)
8-
func_ref_test_script.free()
5+
var func_ref_test_script = FuncRefTest.new()
6+
func_ref_test_script.test_call_without_param()
7+
assert_true(func_ref_test_script.call_flag)
8+
func_ref_test_script.free()
99

1010
func test_call_deferred_without_param():
11-
var func_ref_test_script = FuncRefTest.new()
12-
func_ref_test_script.test_call_deferred_without_param()
13-
await get_tree().create_timer(1).timeout
14-
assert_true(func_ref_test_script.call_flag)
15-
func_ref_test_script.free()
11+
var func_ref_test_script = FuncRefTest.new()
12+
func_ref_test_script.test_call_deferred_without_param()
13+
await get_tree().create_timer(1).timeout
14+
assert_true(func_ref_test_script.call_flag)
15+
func_ref_test_script.free()
1616

1717
func test_call_with_param():
18-
var func_ref_test_script = FuncRefTest.new()
19-
func_ref_test_script.test_call_with_param()
20-
assert_true(func_ref_test_script.call_with_param_flag)
21-
func_ref_test_script.free()
18+
var func_ref_test_script = FuncRefTest.new()
19+
func_ref_test_script.test_call_with_param()
20+
assert_true(func_ref_test_script.call_with_param_flag)
21+
func_ref_test_script.free()
2222

2323
func test_call_deferred_with_param():
24-
var func_ref_test_script = FuncRefTest.new()
25-
func_ref_test_script.test_call_deferred_with_param()
26-
await get_tree().create_timer(3).timeout
27-
assert_true(func_ref_test_script.call_with_param_flag)
28-
func_ref_test_script.free()
24+
var func_ref_test_script = FuncRefTest.new()
25+
func_ref_test_script.test_call_deferred_with_param()
26+
await get_tree().create_timer(3).timeout
27+
assert_true(func_ref_test_script.call_with_param_flag)
28+
func_ref_test_script.free()
2929

3030
func test_signal_call():
31-
var func_ref_test_script = FuncRefTest.new()
32-
get_tree().root.add_child(func_ref_test_script)
33-
func_ref_test_script.test_signal_call()
34-
await get_tree().create_timer(1).timeout
35-
assert_true(func_ref_test_script.signal_call_flag)
36-
get_tree().root.remove_child(func_ref_test_script)
37-
func_ref_test_script.free()
31+
var func_ref_test_script = FuncRefTest.new()
32+
get_tree().root.add_child(func_ref_test_script)
33+
func_ref_test_script.test_signal_call()
34+
await get_tree().create_timer(1).timeout
35+
assert_true(func_ref_test_script.signal_call_flag)
36+
get_tree().root.remove_child(func_ref_test_script)
37+
func_ref_test_script.free()
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
extends "res://addons/gut/test.gd"
22

33
func test_signal_connection_script_instantiation():
4-
var script = SignalTest.new()
5-
get_tree().root.add_child(script)
6-
assert_eq(script.is_connected("no_param_signal_delegate", Callable(script.other_script, "hook_no_param")), true, "signal \"no_param_signal_delegate\" should be connected to \"otherScript::hook_no_param\"")
7-
assert_eq(script.is_connected("one_param_signal_delegate", Callable(script.other_script, "hook_one_param")), true, "signal \"one_param_signal_delegate\" should be connected to \"otherScript::hook_one_param\"")
8-
assert_eq(script.is_connected("two_param_signal_delegate", Callable(script.other_script, "hook_two_param")), true, "signal \"two_param_signal_delegate\" should be connected to \"otherScript::hook_two_param\"")
4+
var script = SignalTest.new()
5+
get_tree().root.add_child(script)
6+
assert_eq(script.is_connected("no_param_signal_delegate", Callable(script.other_script, "hook_no_param")), true, "signal \"no_param_signal_delegate\" should be connected to \"otherScript::hook_no_param\"")
7+
assert_eq(script.is_connected("one_param_signal_delegate", Callable(script.other_script, "hook_one_param")), true, "signal \"one_param_signal_delegate\" should be connected to \"otherScript::hook_one_param\"")
8+
assert_eq(script.is_connected("two_param_signal_delegate", Callable(script.other_script, "hook_two_param")), true, "signal \"two_param_signal_delegate\" should be connected to \"otherScript::hook_two_param\"")
99

10-
assert_eq(script.is_connected("no_param_signal_field", Callable(script.other_script, "hook_no_param")), true, "signal \"no_param_signal_field\" should be connected to \"otherScript::hook_no_param\"")
11-
assert_eq(script.is_connected("one_param_signal_field", Callable(script.other_script, "hook_one_param")), true, "signal \"one_param_signal_field\" should be connected to \"otherScript::hook_one_param\"")
12-
assert_eq(script.is_connected("two_param_signal_field", Callable(script.other_script, "hook_two_param")), true, "signal \"two_param_signal_field\" should be connected to \"otherScript::hook_two_param\"")
10+
assert_eq(script.is_connected("no_param_signal_field", Callable(script.other_script, "hook_no_param")), true, "signal \"no_param_signal_field\" should be connected to \"otherScript::hook_no_param\"")
11+
assert_eq(script.is_connected("one_param_signal_field", Callable(script.other_script, "hook_one_param")), true, "signal \"one_param_signal_field\" should be connected to \"otherScript::hook_one_param\"")
12+
assert_eq(script.is_connected("two_param_signal_field", Callable(script.other_script, "hook_two_param")), true, "signal \"two_param_signal_field\" should be connected to \"otherScript::hook_two_param\"")
1313

14-
script.free()
14+
script.free()
1515

1616
func test_signal_connection_code():
17-
var invocation_script = load("res://Spatial.tscn").instantiate()
18-
get_tree().root.add_child(invocation_script)
19-
assert_eq(invocation_script.button.is_connected("pressed", Callable(invocation_script.invocation, "hook_no_param")), true, "signal \"pressed\" of button should be connected to \"invocation_script.invocation::hook_no_param\"")
20-
invocation_script.free()
17+
var invocation_script = load("res://Spatial.tscn").instantiate()
18+
get_tree().root.add_child(invocation_script)
19+
assert_eq(invocation_script.button.is_connected("pressed", Callable(invocation_script.invocation, "hook_no_param")), true, "signal \"pressed\" of button should be connected to \"invocation_script.invocation::hook_no_param\"")
20+
invocation_script.free()
2121

2222
func test_signal_emitted_with_multiple_targets():
23-
var script = SignalTest.new()
24-
get_tree().root.add_child(script)
25-
assert_eq(script.array.size(), 16)
26-
assert_eq(script.array[0], Vector2(0,0))
27-
assert_eq(script.array[1], Vector2(1,1))
28-
assert_eq(script.array[2], Vector2(1,2))
29-
assert_eq(script.array[3], Vector2(1,3))
30-
assert_eq(script.array[4], Vector2(1,4))
31-
assert_eq(script.array[5], Vector2(1,5))
32-
assert_eq(script.array[6], Vector2(1,6))
33-
assert_eq(script.array[7], Vector2(1,7))
34-
assert_eq(script.array[8], Vector2(1,7))
35-
assert_eq(script.array[9], Vector2(1,6))
36-
assert_eq(script.array[10], Vector2(1,5))
37-
assert_eq(script.array[11], Vector2(1,4))
38-
assert_eq(script.array[12], Vector2(1,3))
39-
assert_eq(script.array[13], Vector2(1,2))
40-
assert_eq(script.array[14], Vector2(1,1))
41-
assert_eq(script.array[15], Vector2(0,0))
42-
script.free()
23+
var script = SignalTest.new()
24+
get_tree().root.add_child(script)
25+
assert_eq(script.array.size(), 16)
26+
assert_eq(script.array[0], Vector2(0,0))
27+
assert_eq(script.array[1], Vector2(1,1))
28+
assert_eq(script.array[2], Vector2(1,2))
29+
assert_eq(script.array[3], Vector2(1,3))
30+
assert_eq(script.array[4], Vector2(1,4))
31+
assert_eq(script.array[5], Vector2(1,5))
32+
assert_eq(script.array[6], Vector2(1,6))
33+
assert_eq(script.array[7], Vector2(1,7))
34+
assert_eq(script.array[8], Vector2(1,7))
35+
assert_eq(script.array[9], Vector2(1,6))
36+
assert_eq(script.array[10], Vector2(1,5))
37+
assert_eq(script.array[11], Vector2(1,4))
38+
assert_eq(script.array[12], Vector2(1,3))
39+
assert_eq(script.array[13], Vector2(1,2))
40+
assert_eq(script.array[14], Vector2(1,1))
41+
assert_eq(script.array[15], Vector2(0,0))
42+
script.free()

install_vulkan_sdk_macos.sh

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
1+
12
#!/usr/bin/env sh
23

34
set -euo pipefail
45
IFS=$'\n\t'
6+
new_ver_full=''
7+
8+
# Check currently installed and latest available Vulkan SDK versions.
9+
if command -v jq 2>&1 >/dev/null; then
10+
curl -L "https://sdk.lunarg.com/sdk/download/latest/mac/config.json" -o /tmp/vulkan-sdk.json
11+
12+
new_ver_full=`jq -r '.version' /tmp/vulkan-sdk.json`
13+
new_ver=`echo "$new_ver_full" | awk -F. '{ printf("%d%02d%04d%02d\n", $1,$2,$3,$4); }';`
14+
15+
rm -f /tmp/vulkan-sdk.json
16+
17+
for f in $HOME/VulkanSDK/*; do
18+
if [ -d "$f" ]; then
19+
f=`echo "${f##*/}" | awk -F. '{ printf("%d%02d%04d%02d\n", $1,$2,$3,$4); }';`
20+
if [ $f -ge $new_ver ]; then
21+
echo 'Latest or newer Vulkan SDK is already installed. Skipping installation.'
22+
exit 0
23+
fi
24+
fi
25+
done
26+
else
27+
echo 'Error: Could not find 'jq' command. Is jq installed? Try running "brew install jq" or "port install jq" and rerunning this script.'
28+
exit 1
29+
fi
530

631
# Download and install the Vulkan SDK.
732
curl -L "https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.zip" -o /tmp/vulkan-sdk.zip
8-
unzip -l /tmp/vulkan-sdk.zip | grep 'InstallVulkan.*\.app' | head -n 1 | awk '{print $4}' | tr -d '/' > /tmp/install_app_name
9-
1033
unzip /tmp/vulkan-sdk.zip -d /tmp
11-
install_app_name=$(cat /tmp/install_app_name)
12-
/tmp/$install_app_name/Contents/MacOS/${install_app_name%\.app} \
13-
--accept-licenses --default-answer --confirm-command install
1434

15-
rm -rf /tmp/$install_app_name
35+
if [ -d "/tmp/vulkansdk-macOS-$new_ver_full.app" ]; then
36+
/tmp/vulkansdk-macOS-$new_ver_full.app/Contents/MacOS/vulkansdk-macOS-$new_ver_full --accept-licenses --default-answer --confirm-command install
37+
rm -rf /tmp/vulkansdk-macOS-$new_ver_full.app
38+
else
39+
echo "Couldn't install the Vulkan SDK, the unzipped contents may no longer match what this script expects."
40+
exit 1
41+
fi
42+
1643
rm -f /tmp/vulkan-sdk.zip
17-
rm -f /tmp/install_app_name
1844

19-
echo 'Vulkan SDK installed successfully! You can now build Godot by running "scons".'
45+
echo 'Vulkan SDK installed successfully! You can now build Godot by running "scons".'

0 commit comments

Comments
 (0)