diff --git a/client/danmaku!/Board.tscn b/client/danmaku!/Board.tscn index 5af4920..20a1659 100644 --- a/client/danmaku!/Board.tscn +++ b/client/danmaku!/Board.tscn @@ -1,29 +1,36 @@ -[gd_scene load_steps=4 format=3 uid="uid://b1m2pclbncn68"] +[gd_scene load_steps=4 format=3 uid="uid://dsiowq0rnacln"] -[ext_resource type="Script" path="res://danmaku!/scaling.gd" id="1_mxxs1"] -[ext_resource type="PackedScene" uid="uid://cd3tqt7hr5pqs" path="res://danmaku!/player.tscn" id="2_d6n3g"] -[ext_resource type="Script" path="res://danmaku!/network_manager.gd" id="3_4fnyw"] +[ext_resource type="PackedScene" uid="uid://cd3tqt7hr5pqs" path="res://danmaku!/Player.tscn" id="1_22cjd"] +[ext_resource type="Script" path="res://danmaku!/scaling.gd" id="1_o1mqp"] +[ext_resource type="Script" path="res://danmaku!/network_manager.gd" id="2_b2dol"] -[node name="Board" type="AspectRatioContainer"] -anchors_preset = -1 -anchor_right = 0.263889 -anchor_bottom = 0.257716 -offset_right = 14.0 -offset_bottom = 27.0 -ratio = 0.5625 -script = ExtResource("1_mxxs1") -metadata/_edit_use_anchors_ = true +[node name="Board" type="Control"] +custom_minimum_size = Vector2(607.5, 1080) +layout_mode = 3 +anchors_preset = 0 +offset_right = 607.5 +offset_bottom = 1080.0 +size_flags_horizontal = 0 +size_flags_vertical = 0 +script = ExtResource("1_o1mqp") [node name="ReferenceRect" type="ReferenceRect" parent="."] -layout_mode = 2 -border_color = Color(0.995542, 0.845388, 0.421763, 1) +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +border_color = Color(1, 0.80706, 0.336228, 1) +border_width = 2.0 editor_only = false -[node name="Container" type="Node2D" parent="ReferenceRect"] -scale = Vector2(1.2125, 1.2125) +[node name="World" type="Node2D" parent="."] +unique_name_in_owner = true +scale = Vector2(6.75, 6.75) -[node name="Player" parent="ReferenceRect/Container" instance=ExtResource("2_d6n3g")] +[node name="Player" parent="World" instance=ExtResource("1_22cjd")] -[node name="NetworkManager" type="Node2D" parent="ReferenceRect/Container" node_paths=PackedStringArray("player")] -script = ExtResource("3_4fnyw") +[node name="NetworkManager" type="Node2D" parent="World" node_paths=PackedStringArray("player")] +script = ExtResource("2_b2dol") player = NodePath("../Player") diff --git a/client/danmaku!/BoardRenderer.tscn b/client/danmaku!/BoardRenderer.tscn new file mode 100644 index 0000000..c6f8004 --- /dev/null +++ b/client/danmaku!/BoardRenderer.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=5 format=3 uid="uid://b1m2pclbncn68"] + +[ext_resource type="PackedScene" uid="uid://dsiowq0rnacln" path="res://danmaku!/Board.tscn" id="2_25dpb"] + +[sub_resource type="ViewportTexture" id="ViewportTexture_0pmy2"] +viewport_path = NodePath("SubViewport") + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_foys1"] +resource_local_to_scene = true +shading_mode = 0 +albedo_texture = SubResource("ViewportTexture_0pmy2") + +[sub_resource type="QuadMesh" id="QuadMesh_txqb1"] +resource_local_to_scene = true +material = SubResource("StandardMaterial3D_foys1") +size = Vector2(0.563, 1) + +[node name="BoardRenderer" type="Node3D"] + +[node name="BoardMesh" type="MeshInstance3D" parent="."] +mesh = SubResource("QuadMesh_txqb1") +skeleton = NodePath("../SubViewport") + +[node name="SubViewport" type="SubViewport" parent="."] +handle_input_locally = false +size = Vector2i(607, 1080) + +[node name="Board" parent="SubViewport" instance=ExtResource("2_25dpb")] diff --git a/client/danmaku!/Game.tscn b/client/danmaku!/Game.tscn index 9d9e522..f39d700 100644 --- a/client/danmaku!/Game.tscn +++ b/client/danmaku!/Game.tscn @@ -1,21 +1,11 @@ [gd_scene load_steps=2 format=3 uid="uid://3a8txh83qfu5"] -[ext_resource type="PackedScene" uid="uid://b1m2pclbncn68" path="res://danmaku!/Board.tscn" id="1_pv3ov"] +[ext_resource type="PackedScene" uid="uid://b1m2pclbncn68" path="res://danmaku!/BoardRenderer.tscn" id="1_pv3ov"] -[node name="Game" type="Control"] -layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 +[node name="Game" type="Node"] -[node name="Board" parent="." instance=ExtResource("1_pv3ov")] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_right = 0.0 -offset_bottom = 0.0 -grow_horizontal = 2 -grow_vertical = 2 +[node name="BoardRenderer" parent="." instance=ExtResource("1_pv3ov")] + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.699727) +current = true diff --git a/client/danmaku!/network_manager.gd b/client/danmaku!/network_manager.gd index 5d6508d..e6ed3b8 100644 --- a/client/danmaku!/network_manager.gd +++ b/client/danmaku!/network_manager.gd @@ -12,6 +12,7 @@ var bullets = [] var current_match_id = "" func _ready() -> void: + child_exiting_tree.connect(_on_child_exiting_tree) print("Attempting auth.") await attempt_auth() print("Attempting to create debug match.") @@ -31,16 +32,14 @@ func _process(delta: float) -> void: bullet.position = interpolated_pos - #var screen_size = get_viewport().size - #bullets = bullets.filter(func(bullet): - # return bullet.position.x >= 0 and bullet.position.x <= screen_size.x and \ - # bullet.position.y >= 0 and bullet.position.y <= screen_size.y - #) + if bullet.beyond_kill_boundary(predicted_tick): + bullet.queue_free() func _on_match_state(p_state : NakamaRTAPI.MatchData): match p_state.op_code: 2: var data = JSON.parse_string(p_state.data) + # Set player position given server bounds-checking if data["forcePlayerPos"]: player.position = Vector2(float(data["playerPos"]["x"]), float(data["playerPos"]["y"])) @@ -60,7 +59,8 @@ func _on_match_state(p_state : NakamaRTAPI.MatchData): bullet.scale = Vector2(0.2, 0.2) add_child(bullet) bullets.append(bullet) - #predicted_tick = int(b["tick"]) + predicted_tick = int(b["tick"]) + delta_counter = 0 func attempt_auth() -> void: nakama_client = Nakama.create_client("defaultkey", "127.0.0.1", 7350, "http") @@ -91,11 +91,15 @@ func create_and_join_debug_match() -> void: func predict_tick_and_broadcast(delta): delta_counter += delta - # New tick, broadcast player inputs - if delta_counter >= 0.05: + # New tick (60 tick rate), broadcast player inputs + var tick_time = 0.01666666666 + if delta_counter >= tick_time: predicted_tick += 1 - delta_counter -= 0.05 + delta_counter -= tick_time var pos = get_node("../Player").position var json_string = JSON.stringify({"x": pos.x, "y": pos.y}) nakama_socket.send_match_state_async(current_match_id, 0, json_string) - bullet_lerp_factor = delta_counter / 0.05 + bullet_lerp_factor = delta_counter / tick_time + +func _on_child_exiting_tree(node: DanmakuBullet): + bullets.erase(node) diff --git a/client/danmaku!/player.tscn b/client/danmaku!/player.tscn index 4f47bee..1cdb5a6 100644 --- a/client/danmaku!/player.tscn +++ b/client/danmaku!/player.tscn @@ -1,11 +1,11 @@ [gd_scene load_steps=3 format=3 uid="uid://cd3tqt7hr5pqs"] -[ext_resource type="Script" path="res://danmaku!/player.gd" id="1_l6typ"] -[ext_resource type="Texture2D" uid="uid://bs3fntlmlqpt2" path="res://icon.svg" id="2_j7sx3"] +[ext_resource type="Script" path="res://danmaku!/player.gd" id="1_r7xhp"] +[ext_resource type="Texture2D" uid="uid://bs3fntlmlqpt2" path="res://icon.svg" id="2_04s0l"] [node name="Player" type="Node2D"] -script = ExtResource("1_l6typ") +script = ExtResource("1_r7xhp") [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.09, 0.09) -texture = ExtResource("2_j7sx3") +texture = ExtResource("2_04s0l") diff --git a/client/danmaku!/scaling.gd b/client/danmaku!/scaling.gd index 6cc98d6..41e8d8a 100644 --- a/client/danmaku!/scaling.gd +++ b/client/danmaku!/scaling.gd @@ -1,6 +1,6 @@ @tool -extends AspectRatioContainer +extends Control func _process(delta: float) -> void: - var board_screen_size = $ReferenceRect.get_rect() - $ReferenceRect/Container.scale = Vector2(board_screen_size.size.x / Globals.SERVER_SIZE.x, board_screen_size.size.y / Globals.SERVER_SIZE.y) + var board_screen_size = self.get_rect() + %World.scale = Vector2(board_screen_size.size.x / Globals.SERVER_SIZE.x, board_screen_size.size.y / Globals.SERVER_SIZE.y) diff --git a/client/project.godot b/client/project.godot index 6da05b0..06843f6 100644 --- a/client/project.godot +++ b/client/project.godot @@ -19,6 +19,11 @@ config/icon="res://icon.svg" Nakama="*res://addons/com.heroiclabs.nakama/Nakama.gd" +[display] + +window/size/viewport_width=1920 +window/size/viewport_height=1080 + [importer_defaults] animation_library={ diff --git a/server/main.go b/server/main.go index 18fc7d8..f573548 100644 --- a/server/main.go +++ b/server/main.go @@ -72,7 +72,7 @@ type BattleRoyaleMatchState struct { // Run on match start, initializes game state and sets tick rate func (m *BattleRoyaleMatch) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, params map[string]interface{}) (interface{}, int, string) { - tickRate := 20 // MatchLoop invocations per second + tickRate := 60 // MatchLoop invocations per second state := &BattleRoyaleMatchState{ tickRate: tickRate, presences: map[string]*PresenceState{}, @@ -114,7 +114,7 @@ func (m *BattleRoyaleMatch) MatchJoin(ctx context.Context, logger runtime.Logger Y: STAGE_HEIGHT - STAGE_HEIGHT*0.1, }, bullets: []*C.Bullet{}, - updatePlayerPos: false, + updatePlayerPos: true, }, } } @@ -232,9 +232,9 @@ func (m *BattleRoyaleMatch) MatchLoop(ctx context.Context, logger runtime.Logger var newBulletsToBroadcast = []map[string]interface{}{} // Test bullet spawning - if tick%1 == 0 { - velx := rand.Float64()*(STAGE_WIDTH/float64(lobbyState.tickRate)) + 1.0 - vely := rand.Float64()*(STAGE_WIDTH/float64(lobbyState.tickRate)) + 1.0 + if tick%10 == 0 { + velx := (rand.Float64() * STAGE_WIDTH) / float64(lobbyState.tickRate) + vely := (rand.Float64() * STAGE_WIDTH) / float64(lobbyState.tickRate) vel_x_sign := 2*rand.Intn(2) - 1 vel_y_sign := 2*rand.Intn(2) - 1