Skip to content

Commit

Permalink
feat: speed up replays
Browse files Browse the repository at this point in the history
  • Loading branch information
vasiltop committed May 22, 2024
1 parent f7793a4 commit 2305206
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 61 deletions.
27 changes: 0 additions & 27 deletions levels/bhop_end.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ use_collision = true
[node name="CSGBox3D" parent="Level" instance=ExtResource("3_utcvv")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 21.2177, -0.442081, -169.835)

[node name="CSGBox3D2" parent="Level" instance=ExtResource("3_utcvv")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 17.2008, -0.442081, -171.965)

[node name="CSGBox3D10" parent="Level" instance=ExtResource("3_utcvv")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 21.6774, -0.442081, -174.296)

[node name="CSGBox3D3" parent="Level" instance=ExtResource("3_utcvv")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 17.7144, -0.442081, -176.614)

Expand Down Expand Up @@ -137,9 +131,6 @@ transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401,
[node name="CSGBox3D11" parent="Level" instance=ExtResource("5_cj23v")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 15.3638, 0.231246, -181.149)

[node name="CSGBox3D12" parent="Level" instance=ExtResource("5_cj23v")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 13.8085, 0.231246, -184.159)

[node name="CSGBox3D13" parent="Level" instance=ExtResource("6_1j3pl")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 7.95025, 0.892944, -195.51)

Expand Down Expand Up @@ -170,21 +161,12 @@ transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401,
[node name="CSGBox3D31" parent="Level" instance=ExtResource("6_1j3pl")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 34.7209, 7.01742, -204.438)

[node name="CSGBox3D21" parent="Level" instance=ExtResource("7_1ly4d")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 16.9425, 5.02414, -221.543)

[node name="CSGBox3D16" parent="Level" instance=ExtResource("6_1j3pl")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 0.238575, 2.21934, -201.695)

[node name="CSGBox3D22" parent="Level" instance=ExtResource("2_t7i0q")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 5.95866, 3.19977, -213.535)

[node name="CSGBox3D34" parent="Level" instance=ExtResource("2_t7i0q")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 4.42573, 7.09662, -189.371)

[node name="CSGBox3D35" parent="Level" instance=ExtResource("2_t7i0q")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, -0.0710411, 7.09662, -187.047)

[node name="CSGBox3D23" parent="Level" instance=ExtResource("2_t7i0q")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 11.2103, 3.95764, -225.873)

Expand All @@ -194,15 +176,6 @@ transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401,
[node name="CSGBox3D24" parent="Level" instance=ExtResource("2_t7i0q")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 15.3205, 4.54911, -225.938)

[node name="CSGBox3D25" parent="Level" instance=ExtResource("2_t7i0q")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 20.0788, 4.76035, -223.806)

[node name="CSGBox3D19" parent="Level" instance=ExtResource("5_cj23v")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 8.28213, 3.30641, -222.726)

[node name="CSGBox3D33" parent="Level" instance=ExtResource("5_cj23v")]
transform = Transform3D(0.888401, 0, 0.459068, 0, 1, 0, -0.459068, 0, 0.888401, 17.3455, 7.05762, -197.159)

[node name="CSGBox3D17" parent="Level" instance=ExtResource("3_utcvv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.47007, -2.66858, -7.55735)
size = Vector3(2, 5.97367, 2)
Expand Down
10 changes: 8 additions & 2 deletions levels/level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func _ready():
end_zone.get_node("Area3D").body_entered.connect(player_finished)
map_name = get_tree().current_scene.name
get_leaderboard_request.request_completed.connect(handle_leaderboard)
get_leaderboard()
post_leaderboard_request.request_completed.connect(test)

if SceneManager.replay_when_level_started:
Expand All @@ -54,6 +53,9 @@ func _ready():
func test(result, response_code, headers, body):
var json = body.get_string_from_utf8()

print(body)
print(response_code)

func get_leaderboard():

var body = JSON.stringify({
Expand Down Expand Up @@ -88,19 +90,23 @@ func player_finished(col):
completed = true
Notify.info("Map completed! Press %s to view a replay." % Save.get_action_string("replay"))
recorder.stop()
thread.start(save_and_publish_run)
#thread.start(save_and_publish_run)
save_and_publish_run()

func save_and_publish_run():
var r = recorder.save(floor(timer * 1000))
var time = Save.data[map_name]['pr']
Save.previous_run_replay = r
print("here")
if time == null or timer < time:

Save.data[map_name]['pr'] = snapped(timer, 0.001)
Save.data[map_name]['replay'] = Array(r.to_bytes())
Save.save_data()
var body = r.to_bytes()
var headers = ["Content-Type: application/json", "password: " + Settings.password, "auth_ticket: " + SteamClient.auth_ticket_hex]
post_leaderboard_request.request_raw(url + "publish", headers, HTTPClient.METHOD_POST, body)
print("sending")

func update_timer_label():
timer_label.text = str(snapped(timer, 0.001)) + " s"
Expand Down
16 changes: 4 additions & 12 deletions levels/recorder.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,9 @@ func replay_run():
player.position.y = front.get_position().get_y()
player.position.z = front.get_position().get_z()

player.rotation.x = front.get_playerRotation().get_x()
player.rotation.y = front.get_playerRotation().get_y()
player.rotation.z = front.get_playerRotation().get_z()
player.rotation.y = front.get_playerRotation()
player.get_node("Camera3D").rotation.x = front.get_cameraRotation()

player.get_node("Camera3D").rotation.x = front.get_cameraRotation().get_x()
player.get_node("Camera3D").rotation.y = front.get_cameraRotation().get_y()
player.get_node("Camera3D").rotation.z = front.get_cameraRotation().get_z()

replay_index += 1

func _physics_process(delta):
Expand All @@ -76,13 +71,10 @@ func record_run():
var frame: run.Frame = current_run.add_frames()

var position = frame.new_position()
var player_rotation = frame.new_playerRotation()
var camera_rotation = frame.new_cameraRotation()
frame.set_playerRotation(player.rotation.y)
frame.set_cameraRotation(camera.rotation.x)

var pos = player.position
position.set_x(pos.x)
position.set_y(pos.y)
position.set_z(pos.z)

player_rotation.set_y(player.rotation.y)
camera_rotation.set_x(camera.rotation.x)
1 change: 0 additions & 1 deletion player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func check_for_landing():
audio_player.stream = landing
audio_player.play()
jumped = false
print(snapped(global_position.y, 0.01), snapped(last_jump_pos.y, 0.01))
if time_since_landing > 0.6 and snapped(global_position.y, 0.01) == snapped(last_jump_pos.y, 0.01) and longjump_counts:
last_jump = last_jump_pos.distance_to(global_position)
last_jump_label.text = str(snapped(last_jump, 0.001)) + " u"
Expand Down
4 changes: 2 additions & 2 deletions protobuf/run.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ message Vec3 {

message Frame {
Vec3 position = 1;
Vec3 playerRotation = 2;
Vec3 cameraRotation = 3;
float playerRotation = 2;
float cameraRotation = 3;
float delta = 4;
}

Expand Down
30 changes: 13 additions & 17 deletions run.gd
Original file line number Diff line number Diff line change
Expand Up @@ -740,16 +740,14 @@ class Frame:
service.func_ref = Callable(self, "new_position")
data[__position.tag] = service

__playerRotation = PBField.new("playerRotation", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 2, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE])
__playerRotation = PBField.new("playerRotation", PB_DATA_TYPE.FLOAT, PB_RULE.OPTIONAL, 2, true, DEFAULT_VALUES_3[PB_DATA_TYPE.FLOAT])
service = PBServiceField.new()
service.field = __playerRotation
service.func_ref = Callable(self, "new_playerRotation")
data[__playerRotation.tag] = service

__cameraRotation = PBField.new("cameraRotation", PB_DATA_TYPE.MESSAGE, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE])
__cameraRotation = PBField.new("cameraRotation", PB_DATA_TYPE.FLOAT, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.FLOAT])
service = PBServiceField.new()
service.field = __cameraRotation
service.func_ref = Callable(self, "new_cameraRotation")
data[__cameraRotation.tag] = service

__delta = PBField.new("delta", PB_DATA_TYPE.FLOAT, PB_RULE.OPTIONAL, 4, true, DEFAULT_VALUES_3[PB_DATA_TYPE.FLOAT])
Expand All @@ -770,24 +768,22 @@ class Frame:
return __position.value

var __playerRotation: PBField
func get_playerRotation() -> Vec3:
func get_playerRotation() -> float:
return __playerRotation.value
func clear_playerRotation() -> void:
data[2].state = PB_SERVICE_STATE.UNFILLED
__playerRotation.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]
func new_playerRotation() -> Vec3:
__playerRotation.value = Vec3.new()
return __playerRotation.value
__playerRotation.value = DEFAULT_VALUES_3[PB_DATA_TYPE.FLOAT]
func set_playerRotation(value : float) -> void:
__playerRotation.value = value

var __cameraRotation: PBField
func get_cameraRotation() -> Vec3:
func get_cameraRotation() -> float:
return __cameraRotation.value
func clear_cameraRotation() -> void:
data[3].state = PB_SERVICE_STATE.UNFILLED
__cameraRotation.value = DEFAULT_VALUES_3[PB_DATA_TYPE.MESSAGE]
func new_cameraRotation() -> Vec3:
__cameraRotation.value = Vec3.new()
return __cameraRotation.value
__cameraRotation.value = DEFAULT_VALUES_3[PB_DATA_TYPE.FLOAT]
func set_cameraRotation(value : float) -> void:
__cameraRotation.value = value

var __delta: PBField
func get_delta() -> float:
Expand Down Expand Up @@ -835,7 +831,7 @@ class Run:
service.field = __steam_id
data[__steam_id.tag] = service

__value = PBField.new("value", PB_DATA_TYPE.INT64, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.INT64])
__value = PBField.new("value", PB_DATA_TYPE.INT32, PB_RULE.OPTIONAL, 3, true, DEFAULT_VALUES_3[PB_DATA_TYPE.INT32])
service = PBServiceField.new()
service.field = __value
data[__value.tag] = service
Expand All @@ -853,7 +849,7 @@ class Run:
var data = {}

var __frames: PBField
func get_frames() -> Array:
func get_frames() -> Array[Frame]:
return __frames.value
func clear_frames() -> void:
data[1].state = PB_SERVICE_STATE.UNFILLED
Expand All @@ -877,7 +873,7 @@ class Run:
return __value.value
func clear_value() -> void:
data[3].state = PB_SERVICE_STATE.UNFILLED
__value.value = DEFAULT_VALUES_3[PB_DATA_TYPE.INT64]
__value.value = DEFAULT_VALUES_3[PB_DATA_TYPE.INT32]
func set_value(value : int) -> void:
__value.value = value

Expand Down

0 comments on commit 2305206

Please sign in to comment.