Skip to content

Commit

Permalink
Add networking parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jeickhoff committed Jul 6, 2023
1 parent b52f066 commit f68f576
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Assets/Scenes/AuthoringScene/AuthoringScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ MonoBehaviour:
TerrainMaterial: {fileID: 2100000, guid: 2e01ef40587306e4c92d3d61aa003fa9, type: 2}
seed: 43
initialAreas:
x: 10
x: 4
y: 2
z: 10
z: 4
playerViewRange: 2
maxChunkSpawnsPerTick: 50
blocksPerAreaSide: 16
Expand Down Expand Up @@ -345,7 +345,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5bd6bf266b32e49ac8c5951317b6b250, type: 3}
m_Name:
m_EditorClassIdentifier:
EnableLagCompensation: 0
EnableLagCompensation: 1
ServerHistorySize: 0
ClientHistorySize: 0
ClientNonGhostWorldIndex: 0
Expand Down
26 changes: 13 additions & 13 deletions Assets/Scripts/Networking/NetCodeBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ public void CreateClientDriver(World world, ref NetworkDriverStore driverStore,
{
var driverInstance = new NetworkDriverStore.NetworkDriverInstance();
#if UNITY_EDITOR || NETCODE_DEBUG
var settings = CreateNetworkSettings(100);
driverInstance.simulatorEnabled = NetworkSimulatorSettings.Enabled;
if (NetworkSimulatorSettings.Enabled)
{
NetworkSimulatorSettings.SetSimulatorSettings(ref settings);
driverInstance.driver = NetworkDriver.Create(new UDPNetworkInterface(), settings);
DefaultDriverBuilder.CreateClientSimulatorPipelines(ref driverInstance);
}
else
{
driverInstance.driver = NetworkDriver.Create(new UDPNetworkInterface(), settings);
DefaultDriverBuilder.CreateClientPipelines(ref driverInstance);
}
var settings = CreateNetworkSettings(100);
driverInstance.simulatorEnabled = NetworkSimulatorSettings.Enabled;
if (NetworkSimulatorSettings.Enabled)
{
NetworkSimulatorSettings.SetSimulatorSettings(ref settings);
driverInstance.driver = NetworkDriver.Create(new UDPNetworkInterface(), settings);
DefaultDriverBuilder.CreateClientSimulatorPipelines(ref driverInstance);
}
else
{
driverInstance.driver = NetworkDriver.Create(new UDPNetworkInterface(), settings);
DefaultDriverBuilder.CreateClientPipelines(ref driverInstance);
}
#else
var settings = CreateNetworkSettings();
driverInstance.driver = NetworkDriver.Create(new UDPNetworkInterface(), settings);
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/Networking/NetCodeStartStreamSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Unity.NetCode;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Networking.Transport;
using Unity.Transforms;
using UnityEngine;

Expand Down Expand Up @@ -57,12 +58,23 @@ public partial struct StartGameStreamServerSystem : ISystem
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<GhostRelevancy>();
state.RequireForUpdate<GhostSendSystemData>();
state.RequireForUpdate<PlayerSpawner>();
var builder = new EntityQueryBuilder(Allocator.Temp)
.WithAll<StartGameStreamRequest>()
.WithAll<ReceiveRpcCommandRequest>();
state.RequireForUpdate(state.GetEntityQuery(builder));
networkIdFromEntity = state.GetComponentLookup<NetworkId>(true);

// Set some networking configuration parameters
var ghostSendSystemData = SystemAPI.GetSingleton<GhostSendSystemData>();
ghostSendSystemData.FirstSendImportanceMultiplier = 2;

// Component used on server to tell the ghost synchronization system to ignore certain ghosts
// for specific connections, specified through GhostRelevancySet
var ghostRelevancy = SystemAPI.GetSingleton<GhostRelevancy>();
ghostRelevancy.GhostRelevancyMode = GhostRelevancyMode.SetIsIrrelevant;
}

[BurstCompile]
Expand All @@ -75,6 +87,8 @@ public void OnUpdate(ref SystemState state)
.WithAll<StartGameStreamRequest>().WithEntityAccess())
{
commandBuffer.AddComponent<NetworkStreamInGame>(reqSrc.ValueRO.SourceConnection);
// Following line adds a per-connection component that enforces a non-standard packet size for snapshots.
//commandBuffer.AddComponent(reqSrc.ValueRO.SourceConnection, new NetworkStreamSnapshotTargetSize { Value = NetworkParameterConstants.MTU});
commandBuffer.AddComponent(reqSrc.ValueRO.SourceConnection,
new GhostConnectionPosition { Position = new float3() });
var networkId = networkIdFromEntity[reqSrc.ValueRO.SourceConnection];
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Player/PlayerMovementSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void OnCreate(ref SystemState state)
state.RequireForUpdate<Authoring.Player>();

m_MarkerGroundCheck = new ProfilerMarker("GroundCheck");
m_MarkerStep = new ProfilerMarker("Step");
m_MarkerStep = new ProfilerMarker("CollisionStep");
_terrainBlockLookup = state.GetBufferLookup<TerrainBlocks>(true);
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Terrain/Authoring/TerrainAreaAuthoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TerrainBlockBaker : Baker<TerrainAreaAuthoring>
{
public override void Bake(TerrainAreaAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
var entity = GetEntity(TransformUsageFlags.Renderable);
// Initialize with no neighbors
var terrainNeighbors = new TerrainNeighbors()
{
Expand Down

0 comments on commit f68f576

Please sign in to comment.