Networking
This commit is contained in:
34
.exr.import
Normal file
34
.exr.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bpsjhyhlis3ov"
|
||||||
|
path="res://.godot/imported/.exr-a7725c7e971a9679cf60303f5fa7defa.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://.exr"
|
||||||
|
dest_files=["res://.godot/imported/.exr-a7725c7e971a9679cf60303f5fa7defa.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
2
Game.gd
2
Game.gd
@@ -4,8 +4,10 @@ class_name Game
|
|||||||
signal game_loaded
|
signal game_loaded
|
||||||
|
|
||||||
var init_config
|
var init_config
|
||||||
|
var weapon_config
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
weapon_config = Runtimeloader.loadConfig("weapons.cfg") as ConfigFile
|
||||||
init_config = Runtimeloader.loadConfig("init.cfg") as ConfigFile
|
init_config = Runtimeloader.loadConfig("init.cfg") as ConfigFile
|
||||||
|
|
||||||
print("Loading PCK...")
|
print("Loading PCK...")
|
||||||
|
|||||||
@@ -6,15 +6,15 @@
|
|||||||
[ext_resource type="Shader" path="res://assets/shader/crosshair.gdshader" id="3_3vnqi"]
|
[ext_resource type="Shader" path="res://assets/shader/crosshair.gdshader" id="3_3vnqi"]
|
||||||
[ext_resource type="Script" path="res://entities/PlayerSync.gd" id="5_828co"]
|
[ext_resource type="Script" path="res://entities/PlayerSync.gd" id="5_828co"]
|
||||||
|
|
||||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_8iawe"]
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_6d8kk"]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4aqh7"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ikq67"]
|
||||||
albedo_texture = ExtResource("2_mxb5i")
|
albedo_texture = ExtResource("2_mxb5i")
|
||||||
uv1_scale = Vector3(3, 2, 1)
|
uv1_scale = Vector3(3, 2, 1)
|
||||||
|
|
||||||
[sub_resource type="CylinderMesh" id="CylinderMesh_dh7aw"]
|
[sub_resource type="CylinderMesh" id="CylinderMesh_4e7dm"]
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_giw1l"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_08bwh"]
|
||||||
shader = ExtResource("3_3vnqi")
|
shader = ExtResource("3_3vnqi")
|
||||||
shader_parameter/center_enabled = null
|
shader_parameter/center_enabled = null
|
||||||
shader_parameter/legs_enabled = null
|
shader_parameter/legs_enabled = null
|
||||||
@@ -29,36 +29,36 @@ shader_parameter/len = null
|
|||||||
shader_parameter/spacing = null
|
shader_parameter/spacing = null
|
||||||
shader_parameter/spread = null
|
shader_parameter/spread = null
|
||||||
|
|
||||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_86371"]
|
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rfdcv"]
|
||||||
properties/0/path = NodePath("Body/Head:rotation")
|
properties/0/path = NodePath("Body/Head:rotation")
|
||||||
properties/0/spawn = true
|
properties/0/spawn = true
|
||||||
properties/0/sync = true
|
properties/0/sync = true
|
||||||
properties/1/path = NodePath("Body:rotation")
|
properties/1/path = NodePath("Body:rotation")
|
||||||
properties/1/spawn = true
|
properties/1/spawn = true
|
||||||
properties/1/sync = true
|
properties/1/sync = true
|
||||||
properties/2/path = NodePath("Networking:sync_velocity")
|
properties/2/path = NodePath("Networking:player_state")
|
||||||
properties/2/spawn = true
|
properties/2/spawn = false
|
||||||
properties/2/sync = true
|
properties/2/sync = true
|
||||||
properties/3/path = NodePath("Networking:sync_position")
|
properties/3/path = NodePath("Networking:sync_position")
|
||||||
properties/3/spawn = true
|
properties/3/spawn = true
|
||||||
properties/3/sync = true
|
properties/3/sync = false
|
||||||
properties/4/path = NodePath("Networking:processed_position")
|
properties/4/path = NodePath("Networking:sync_velocity")
|
||||||
properties/4/spawn = true
|
properties/4/spawn = true
|
||||||
properties/4/sync = true
|
properties/4/sync = false
|
||||||
|
|
||||||
[node name="PlayerQ3" type="CharacterBody3D"]
|
[node name="PlayerQ3" type="CharacterBody3D"]
|
||||||
script = ExtResource("1")
|
script = ExtResource("1")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
shape = SubResource("CylinderShape3D_8iawe")
|
shape = SubResource("CylinderShape3D_6d8kk")
|
||||||
|
|
||||||
[node name="Body" type="Node3D" parent="."]
|
[node name="Body" type="Node3D" parent="."]
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Body"]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="Body"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
material_override = SubResource("StandardMaterial3D_4aqh7")
|
material_override = SubResource("StandardMaterial3D_ikq67")
|
||||||
mesh = SubResource("CylinderMesh_dh7aw")
|
mesh = SubResource("CylinderMesh_4e7dm")
|
||||||
skeleton = NodePath("../../CollisionShape3D")
|
skeleton = NodePath("../../CollisionShape3D")
|
||||||
|
|
||||||
[node name="Head" type="Node3D" parent="Body"]
|
[node name="Head" type="Node3D" parent="Body"]
|
||||||
@@ -68,12 +68,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0)
|
|||||||
script = ExtResource("2_dl1i1")
|
script = ExtResource("2_dl1i1")
|
||||||
|
|
||||||
[node name="Crosshair" type="ColorRect" parent="Body/Head/Hand"]
|
[node name="Crosshair" type="ColorRect" parent="Body/Head/Hand"]
|
||||||
material = SubResource("ShaderMaterial_giw1l")
|
material = SubResource("ShaderMaterial_08bwh")
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
size_flags_horizontal = 4
|
||||||
|
size_flags_vertical = 4
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="Body/Head"]
|
[node name="Camera3D" type="Camera3D" parent="Body/Head"]
|
||||||
cull_mask = 1048573
|
cull_mask = 1048573
|
||||||
@@ -95,4 +97,4 @@ script = ExtResource("5_828co")
|
|||||||
|
|
||||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="Networking"]
|
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="Networking"]
|
||||||
root_path = NodePath("../..")
|
root_path = NodePath("../..")
|
||||||
replication_config = SubResource("SceneReplicationConfig_86371")
|
replication_config = SubResource("SceneReplicationConfig_rfdcv")
|
||||||
|
|||||||
@@ -1,5 +1,24 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
###SYNC PLAYER###
|
||||||
|
const PLAYER_STATE_SIZE = 13
|
||||||
|
var player_state:
|
||||||
|
get:
|
||||||
|
var buf = PackedByteArray()
|
||||||
|
buf.resize(PLAYER_STATE_SIZE)
|
||||||
|
buf.encode_half(0, sync_position.x)
|
||||||
|
buf.encode_half(2, sync_position.y)
|
||||||
|
buf.encode_half(4, sync_position.z)
|
||||||
|
buf.encode_half(6, sync_velocity.x)
|
||||||
|
buf.encode_half(8, sync_velocity.y)
|
||||||
|
buf.encode_half(10, sync_velocity.z)
|
||||||
|
return buf
|
||||||
|
set(value):
|
||||||
|
assert(typeof(value) == TYPE_PACKED_BYTE_ARRAY and value.size() == PLAYER_STATE_SIZE,
|
||||||
|
"Invalid `player_state` array type or size (must be TYPE_PACKED_BYTE_ARRAY of size 11).")
|
||||||
|
sync_position = Vector3(value.decode_half(0), value.decode_half(2), value.decode_half(4))
|
||||||
|
sync_velocity = Vector3(value.decode_half(6), value.decode_half(8), value.decode_half(10))
|
||||||
|
|
||||||
var sync_position : Vector3:
|
var sync_position : Vector3:
|
||||||
set(value):
|
set(value):
|
||||||
sync_position = value
|
sync_position = value
|
||||||
@@ -8,3 +27,5 @@ var sync_velocity : Vector3
|
|||||||
var sync_is_jumping : bool
|
var sync_is_jumping : bool
|
||||||
|
|
||||||
var processed_position : bool
|
var processed_position : bool
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
[gd_scene load_steps=7 format=3 uid="uid://8g7w4uv2xsck"]
|
[gd_scene load_steps=6 format=3 uid="uid://8g7w4uv2xsck"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Game.gd" id="1_71dcv"]
|
[ext_resource type="Script" path="res://Game.gd" id="1_71dcv"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dsnlwjofq6psf" path="res://scenes/GUI/Main Menu.tscn" id="2_448f8"]
|
[ext_resource type="PackedScene" uid="uid://dsnlwjofq6psf" path="res://scenes/GUI/Main Menu.tscn" id="2_448f8"]
|
||||||
[ext_resource type="Script" path="res://scenes/map/EntitySpawner.gd" id="3_i5esv"]
|
|
||||||
|
|
||||||
[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_2n8qo"]
|
[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_2n8qo"]
|
||||||
|
|
||||||
@@ -38,7 +37,3 @@ environment = SubResource("Environment_oqaam")
|
|||||||
[node name="PlayerSpawner" type="MultiplayerSpawner" parent="Networking"]
|
[node name="PlayerSpawner" type="MultiplayerSpawner" parent="Networking"]
|
||||||
_spawnable_scenes = PackedStringArray("res://entities/Player.tscn")
|
_spawnable_scenes = PackedStringArray("res://entities/Player.tscn")
|
||||||
spawn_path = NodePath("..")
|
spawn_path = NodePath("..")
|
||||||
|
|
||||||
[node name="EntitySpawner" type="MultiplayerSpawner" parent="Networking"]
|
|
||||||
spawn_path = NodePath("..")
|
|
||||||
script = ExtResource("3_i5esv")
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ func _enter_tree():
|
|||||||
if is_local_authority():
|
if is_local_authority():
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
|
func init():
|
||||||
|
$Body/Head/Hand.set_weapons()
|
||||||
|
|
||||||
func is_local_authority():
|
func is_local_authority():
|
||||||
return $Networking/MultiplayerSynchronizer.get_multiplayer_authority() == multiplayer.get_unique_id()
|
return $Networking/MultiplayerSynchronizer.get_multiplayer_authority() == multiplayer.get_unique_id()
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
const CONFIG_PATH = "weapons.cfg"
|
|
||||||
const WEAPON_SCENE = preload("res://entities/Weapon.scn")
|
const WEAPON_SCENE = preload("res://entities/Weapon.scn")
|
||||||
|
|
||||||
@onready var player_root = get_node("../../..")
|
@onready var player_root = get_node("../../..")
|
||||||
@onready var raycast = get_node("../Camera3D/AimCast") as RayCast3D
|
@onready var raycast = get_node("../Camera3D/AimCast") as RayCast3D
|
||||||
#@onready var crosshair = $Crosshair
|
#@onready var crosshair = $Crosshair
|
||||||
|
|
||||||
var ALL_WEAPONS = {}
|
var ALL_WEAPONS = []
|
||||||
var weapons = []
|
var weapons = []
|
||||||
|
|
||||||
var current_weapon_index = 0
|
var current_weapon_index = 0
|
||||||
@@ -15,28 +14,39 @@ var current_weapon = null
|
|||||||
|
|
||||||
var mouse_mov : Vector3
|
var mouse_mov : Vector3
|
||||||
var sway_lerp = 5
|
var sway_lerp = 5
|
||||||
|
@onready var game = get_node("/root/Game") as Game
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var config = Runtimeloader.loadConfig(CONFIG_PATH) as ConfigFile
|
Init_Config(game.weapon_config)
|
||||||
if(config == null):
|
if not player_root.is_local_authority():
|
||||||
|
for w_name in game.init_config.get_value("PLAYER", "starting_weapons"):
|
||||||
|
GiveWeapon(w_name)
|
||||||
|
|
||||||
|
func set_weapons():
|
||||||
|
for w_name in game.init_config.get_value("PLAYER", "starting_weapons"):
|
||||||
|
rpc("GiveWeapon",w_name)
|
||||||
|
|
||||||
|
@rpc(call_local, any_peer)
|
||||||
|
func GiveWeapon(weapon_name):
|
||||||
|
for i in ALL_WEAPONS.size():
|
||||||
|
if(ALL_WEAPONS[i].name != weapon_name):
|
||||||
|
continue
|
||||||
|
if(weapons.has(i)):
|
||||||
|
return
|
||||||
|
|
||||||
|
weapons.append(i)
|
||||||
|
if(current_weapon == null):
|
||||||
|
rpc("ChangeWeapon", ((posmod(current_weapon_index, weapons.size()))))
|
||||||
return
|
return
|
||||||
|
|
||||||
Init_Config(config)
|
@rpc(call_local, any_peer)
|
||||||
|
|
||||||
var init_config = get_node("/root/Game").init_config
|
|
||||||
for w_name in init_config.get_value("PLAYER", "starting_weapons"):
|
|
||||||
GiveWeapon(w_name)
|
|
||||||
|
|
||||||
func GiveWeapon(weapon_name):
|
|
||||||
if weapon_name in ALL_WEAPONS and not ALL_WEAPONS[weapon_name] in weapons:
|
|
||||||
weapons.append(ALL_WEAPONS[weapon_name])
|
|
||||||
ChangeWeapon((posmod(current_weapon_index, weapons.size())))
|
|
||||||
|
|
||||||
func TakeWeapon(weapon_name):
|
func TakeWeapon(weapon_name):
|
||||||
if weapon_name in ALL_WEAPONS and ALL_WEAPONS[weapon_name] in weapons:
|
for i in ALL_WEAPONS.size():
|
||||||
weapons.erase(ALL_WEAPONS[weapon_name])
|
if(ALL_WEAPONS[i].name != weapon_name):
|
||||||
ChangeWeapon((posmod(current_weapon_index, weapons.size())))
|
continue
|
||||||
|
weapons.erase(i)
|
||||||
|
if(current_weapon == ALL_WEAPONS[i]):
|
||||||
|
rpc("ChangeWeapon", ((posmod(current_weapon_index, weapons.size()))))
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if not player_root.is_local_authority():
|
if not player_root.is_local_authority():
|
||||||
@@ -46,7 +56,7 @@ func _input(event):
|
|||||||
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
|
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
|
||||||
if event is InputEventKey and event.is_pressed():
|
if event is InputEventKey and event.is_pressed():
|
||||||
if event.keycode == KEY_T:
|
if event.keycode == KEY_T:
|
||||||
GiveWeapon("CHAINSAW")
|
rpc("GiveWeapon","CHAINSAW")
|
||||||
|
|
||||||
func _unhandled_input(_event):
|
func _unhandled_input(_event):
|
||||||
if not player_root.is_local_authority():
|
if not player_root.is_local_authority():
|
||||||
@@ -56,13 +66,13 @@ func _unhandled_input(_event):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
|
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
|
||||||
ChangeWeapon(posmod((current_weapon_index + 1),weapons.size()))
|
rpc("ChangeWeapon", (posmod((current_weapon_index + 1),weapons.size())))
|
||||||
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
|
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
|
||||||
ChangeWeapon(posmod((current_weapon_index - 1),weapons.size()))
|
rpc("ChangeWeapon", (posmod((current_weapon_index - 1),weapons.size())))
|
||||||
|
|
||||||
if Input.is_action_just_pressed("reload"):
|
if Input.is_action_just_pressed("reload"):
|
||||||
current_weapon.Reload()
|
current_weapon.Reload()
|
||||||
|
@rpc(call_local, any_peer)
|
||||||
func ChangeWeapon(i):
|
func ChangeWeapon(i):
|
||||||
if(current_weapon):
|
if(current_weapon):
|
||||||
current_weapon.hide()
|
current_weapon.hide()
|
||||||
@@ -72,7 +82,8 @@ func ChangeWeapon(i):
|
|||||||
return
|
return
|
||||||
|
|
||||||
current_weapon_index = i
|
current_weapon_index = i
|
||||||
current_weapon = weapons[current_weapon_index]
|
var w_index = weapons[current_weapon_index]
|
||||||
|
current_weapon = ALL_WEAPONS[w_index]
|
||||||
current_weapon.show()
|
current_weapon.show()
|
||||||
current_weapon.init()
|
current_weapon.init()
|
||||||
raycast.target_position.z = -current_weapon.RAY_LEN
|
raycast.target_position.z = -current_weapon.RAY_LEN
|
||||||
@@ -110,7 +121,7 @@ func _process(delta):
|
|||||||
bobOscillate = sin(time * 4 * (PI) + PI/4) * 0.015
|
bobOscillate = sin(time * 4 * (PI) + PI/4) * 0.015
|
||||||
position.x = bobOscillate
|
position.x = bobOscillate
|
||||||
|
|
||||||
|
@rpc(call_local, any_peer)
|
||||||
func HitScan():
|
func HitScan():
|
||||||
if(raycast.is_colliding()):
|
if(raycast.is_colliding()):
|
||||||
var target = raycast.get_collider()
|
var target = raycast.get_collider()
|
||||||
@@ -169,4 +180,4 @@ func Init_Config(config):
|
|||||||
root.RELOAD_ANGULAR_MOMENTUM = config.get_value(weapon, "RELOAD_ANGULAR_MOMENTUM")
|
root.RELOAD_ANGULAR_MOMENTUM = config.get_value(weapon, "RELOAD_ANGULAR_MOMENTUM")
|
||||||
root.RELOAD_TIME = config.get_value(weapon, "RELOAD_TIME")
|
root.RELOAD_TIME = config.get_value(weapon, "RELOAD_TIME")
|
||||||
|
|
||||||
ALL_WEAPONS[root.name] = root
|
ALL_WEAPONS.append(root)
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ func create_player(id=1):
|
|||||||
# Add it to the "Players" node.
|
# Add it to the "Players" node.
|
||||||
# We give the new Node a name for easy retrieval, but that's not necessary.
|
# We give the new Node a name for easy retrieval, but that's not necessary.
|
||||||
p.name = str(id)
|
p.name = str(id)
|
||||||
p.set_multiplayer_authority(id)
|
#p.set_multiplayer_authority(id)
|
||||||
NetworkingRoot.add_child(p)
|
NetworkingRoot.add_child(p)
|
||||||
|
p.init()
|
||||||
|
|
||||||
func destroy_player(id):
|
func destroy_player(id):
|
||||||
# Delete this peer's node.
|
# Delete this peer's node.
|
||||||
|
|||||||
Reference in New Issue
Block a user