Skip to content

Commit cbbdeb6

Browse files
authored
Merge pull request #96 from flametime/dovos-fixes
Spacetimedb 2.0 fix for V1 protocol
2 parents b078f15 + 5245982 commit cbbdeb6

31 files changed

Lines changed: 304 additions & 250 deletions

godot-client/addons/SpacetimeDB/core/spacetimedb_client.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ func _handle_parsed_message(message_resource: Resource):
324324

325325
# Emit the full transaction update signal regardless of status
326326
self.transaction_update_received.emit(tx_update)
327-
327+
elif message_resource is TransactionUpdateMessageLightmode:
328+
var tx_update: TransactionUpdateMessageLightmode = message_resource
329+
_local_db.apply_database_update(tx_update.committed_update)
328330
else:
329331
print_log("SpacetimeDBClient: Received unhandled message resource type: " + message_resource.get_class())
330332

godot-client/addons/SpacetimeDB/core_types/server_message/spacetimedb_server_message.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ static func get_resource_path(msg_type: int) -> String:
2323
SUBSCRIPTION_ERROR: return "res://addons/SpacetimeDB/core_types/server_message/subscription_error.gd" # Uses manual reader
2424
SUBSCRIBE_MULTI_APPLIED: return "res://addons/SpacetimeDB/core_types/server_message/subscribe_multi_applied.gd"
2525
UNSUBSCRIBE_MULTI_APPLIED: return "res://addons/SpacetimeDB/core_types/server_message/unsubscribe_multi_applied.gd"
26-
# TRANSACTION_UPDATE_LIGHT (0x02) is not handled yet
26+
TRANSACTION_UPDATE_LIGHT: return "res://addons/SpacetimeDB/core_types/server_message/transaction_update_lightmode.gd"
2727
_:
2828
return ""
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@tool
2+
class_name TransactionUpdateMessageLightmode extends Resource
3+
4+
@export var request_id: int #u32
5+
@export var committed_update: DatabaseUpdateData
6+
7+
func _init():
8+
set_meta("bsatn_type_request_id", "u32")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://ctcp45tdhjins

godot-client/example_code/LobbyHolder.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func on_self_update(user: MainUser):
2121

2222
func subscibe_whole_lobby(lobby_to_sub: int, user_identity: PackedByteArray):
2323
var query = [
24-
"SELECT * FROM user WHERE online == true AND lobby_id == " + str(lobby_to_sub),
24+
"SELECT * FROM user WHERE online == true AND lobby_id == " + str(lobby_to_sub),
2525
"SELECT * FROM user_data WHERE lobby_id == " + str(lobby_to_sub),
2626
]
2727
SpacetimeDB.Main.subscribe(query)

godot-client/example_code/integration_tests.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func _ready() -> void:
66
var options :SpacetimeDBConnectionOptions = SpacetimeDBConnectionOptions.new()
77

88
options.one_time_token = true # <--- anonymous-like. set to false to persist
9-
options.debug_mode = false # <--- enables lots of additional debug prints and warnings
9+
options.debug_mode = true # <--- enables lots of additional debug prints and warnings
1010
options.compression = SpacetimeDBConnection.CompressionPreference.GZIP
1111
options.threading = true
1212
# Increase buffer size. In general, you don't need this.

godot-client/example_code/lobby_holder.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func _on_user_inserted(user: MainUser) -> void:
1515
print("Set local user: ", user.identity.hex_encode())
1616
local_user = user
1717
subscibe_on_lobby(user.lobby_id)
18-
18+
1919
if users.has(user.identity):
2020
return
21-
21+
2222
print("Join: ", user.identity.hex_encode())
2323
user_join.emit(user)
2424
users[user.identity] = user
@@ -29,7 +29,7 @@ func _on_user_deleted(user: MainUser) -> void:
2929

3030
func subscibe_on_lobby(lobby_to_sub: int) -> void:
3131
var query := [
32-
"SELECT * FROM user WHERE online == true AND lobby_id == " + str(lobby_to_sub),
32+
"SELECT * FROM user WHERE online == true AND lobby_id == " + str(lobby_to_sub),
3333
"SELECT * FROM user_data WHERE lobby_id == " + str(lobby_to_sub),
3434
]
3535
var sub := SpacetimeDB.Main.subscribe(query)

godot-client/example_code/mouse.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func _update_player_on_row_update(_prev_value: MainUserData, user_data: MainUser
2222
func _process(delta: float) -> void:
2323
if not SpacetimeDB.Main.is_connected_db():
2424
return
25-
25+
2626
if get_meta("local") == true:
2727
if last_position != get_global_mouse_position():
2828
last_position = get_global_mouse_position()
2929
var vec_to2d := Vector3(last_position.x, last_position.y, 0)
3030
SpacetimeDB.Main.reducers.move_user(Vector2(0,0), vec_to2d)
31-
31+
3232
global_position = global_position.lerp(last_position, 10 * delta)

godot-client/example_code/player.gd

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,87 +8,87 @@ var remote_input: Vector2
88
var remote_speed: float
99

1010
func _ready() -> void:
11-
receiver.insert.connect(_initialize_player_on_insert)
12-
receiver.update.connect(_update_player_on_row_update)
13-
14-
set_process(get_meta("is_local"))
15-
set_process_input(get_meta("is_local"))
11+
receiver.insert.connect(_initialize_player_on_insert)
12+
receiver.update.connect(_update_player_on_row_update)
13+
14+
set_process(get_meta("is_local"))
15+
set_process_input(get_meta("is_local"))
1616

1717
func test_struct():
18-
var test_damage = MainDamage.create(16, SpacetimeDB.Main.get_local_identity(), [1,2,3])
19-
var test_one := MainMessage.new()
20-
test_one.int_value = 55
21-
test_one.string_value = "Hello from Godot"
22-
test_one.int_vec = [1,2,3]
23-
test_one.string_vec = ["one", "two", "three"]
24-
var option = Option.new()
25-
option.set_some(["pip", "pop"])
26-
test_one.test_option_vec = option
27-
28-
var test_option = Option.new()
29-
test_option.set_some("Single string")
30-
test_one.test_option = test_option
31-
var option_inner = Option.new()
32-
option_inner.set_some(test_damage)
33-
test_one.test_inner = option_inner
34-
35-
var res = await SpacetimeDB.Main.reducers.test_struct(test_one, func(_t):
36-
print("Result:", _t)
37-
)
18+
var test_damage = MainDamage.create(16, SpacetimeDB.Main.get_local_identity(), [1,2,3])
19+
var test_one := MainMessage.new()
20+
test_one.int_value = 55
21+
test_one.string_value = "Hello from Godot"
22+
test_one.int_vec = [1,2,3]
23+
test_one.string_vec = ["one", "two", "three"]
24+
var option = Option.new()
25+
option.set_some(["pip", "pop"])
26+
test_one.test_option_vec = option
27+
28+
var test_option = Option.new()
29+
test_option.set_some("Single string")
30+
test_one.test_option = test_option
31+
var option_inner = Option.new()
32+
option_inner.set_some(test_damage)
33+
test_one.test_inner = option_inner
34+
35+
var res = await SpacetimeDB.Main.reducers.test_struct(test_one, func(_t):
36+
print("Result:", _t)
37+
)
3838

3939
func test_option_vec(text):
40-
var opt = Option.new()
41-
opt.set_some(text)
42-
SpacetimeDB.Main.reducers.test_option_vec(opt)
43-
40+
var opt = Option.new()
41+
opt.set_some(text)
42+
SpacetimeDB.Main.reducers.test_option_vec(opt)
43+
4444
func test_option_single(text):
45-
var opt = Option.new()
46-
opt.set_some(text)
47-
SpacetimeDB.Main.reducers.test_option_single(opt)
45+
var opt = Option.new()
46+
opt.set_some(text)
47+
SpacetimeDB.Main.reducers.test_option_single(opt)
4848

4949
func _input(event: InputEvent) -> void:
50-
if event.is_action_pressed("ui_cancel"):
51-
SpacetimeDB.Main.reducers.change_color_random()
52-
53-
if event.is_action_pressed("ui_accept"):
54-
test_struct()
55-
test_option_vec(["Hello","World"])
56-
test_option_single("Welcome")
50+
if event.is_action_pressed("ui_cancel"):
51+
SpacetimeDB.Main.reducers.change_color_random()
52+
53+
if event.is_action_pressed("ui_accept"):
54+
test_struct()
55+
test_option_vec(["Hello","World"])
56+
test_option_single("Welcome")
5757

5858
func _initialize_player_on_insert(user_data: MainUserData):
59-
#Need to receive only THIS entity/table updates
60-
if get_meta("id") != user_data.identity:
61-
return
62-
63-
$MeshInstance3D.get_surface_override_material(0).albedo_color = user_data.color
64-
$Label3D.text = str(user_data.name)
65-
last_position = user_data.last_position
66-
remote_input = user_data.direction
67-
remote_speed = user_data.player_speed
68-
59+
#Need to receive only THIS entity/table updates
60+
if get_meta("id") != user_data.identity:
61+
return
62+
63+
$MeshInstance3D.get_surface_override_material(0).albedo_color = user_data.color
64+
$Label3D.text = str(user_data.name)
65+
last_position = user_data.last_position
66+
remote_input = user_data.direction
67+
remote_speed = user_data.player_speed
68+
6969
func _update_player_on_row_update(prev_value: MainUserData, user_data: MainUserData):
70-
#Need to receive only THIS entity/table updates
71-
if get_meta("id") != user_data.identity:
72-
return
70+
#Need to receive only THIS entity/table updates
71+
if get_meta("id") != user_data.identity:
72+
return
7373

74-
$MeshInstance3D.get_surface_override_material(0).albedo_color = user_data.color
75-
last_position = user_data.last_position
76-
remote_input = user_data.direction
77-
remote_speed = user_data.player_speed
74+
$MeshInstance3D.get_surface_override_material(0).albedo_color = user_data.color
75+
last_position = user_data.last_position
76+
remote_input = user_data.direction
77+
remote_speed = user_data.player_speed
7878

7979
func _process(delta: float) -> void:
80-
var input_dir: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
81-
if last_local_input == input_dir:
82-
return
83-
84-
last_local_input = input_dir
85-
SpacetimeDB.Main.reducers.move_user(input_dir, global_position)
80+
var input_dir: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
81+
if last_local_input == input_dir:
82+
return
83+
84+
last_local_input = input_dir
85+
SpacetimeDB.Main.reducers.move_user(input_dir, global_position)
8686

8787
func _physics_process(delta: float) -> void:
88-
if remote_input == Vector2.ZERO:
89-
global_position = global_position.lerp(last_position, 10 * delta)
90-
var direction := Vector3(remote_input.x, 0, remote_input.y)
91-
if direction:
92-
velocity.x = direction.x * remote_speed
93-
velocity.z = direction.z * remote_speed
94-
move_and_slide()
88+
if remote_input == Vector2.ZERO:
89+
global_position = global_position.lerp(last_position, 10 * delta)
90+
var direction := Vector3(remote_input.x, 0, remote_input.y)
91+
if direction:
92+
velocity.x = direction.x * remote_speed
93+
velocity.z = direction.z * remote_speed
94+
move_and_slide()

godot-client/example_code/players.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func spawn(user: MainUser) -> void:
1212
player.set_meta("local", user.identity == SpacetimeDB.Main.get_local_identity())
1313
player.name = user.identity.hex_encode()
1414
add_child(player)
15-
15+
1616
func despawn(user: MainUser) -> void:
1717
var player := get_node_or_null(str(user.identity.hex_encode()))
1818
if player != null:

0 commit comments

Comments
 (0)