diff --git a/Prefabs/Player/MultiplayPlayer.prefab b/Prefabs/Player/MultiplayPlayer.prefab index 92b8a1d..b0c7d0a 100644 --- a/Prefabs/Player/MultiplayPlayer.prefab +++ b/Prefabs/Player/MultiplayPlayer.prefab @@ -56,8 +56,11 @@ MonoBehaviour: inputJump: 0 inputPrimaryAction: 0 inputSecondaryAction: 0 + selectedItemIndex: 0 + inputThirdAction: 0 playerEntityExists: 0 playerEntityRequestSent: 0 + selectableItems: 010000000300000010000000120000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d0000000e000000 --- !u!114 &-3399718007712543476 MonoBehaviour: m_ObjectHideFlags: 0 @@ -205,6 +208,57 @@ MonoBehaviour: m_CallState: 2 m_ActionId: 52bd4c51-0503-4ffb-b405-5a778b3906fc m_ActionName: Player Controls/Exit[/Keyboard/escape] + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 207901908825964653} + m_TargetAssemblyTypeName: PolkaDOTS.Multiplay.MultiplayPlayerController, + PolkaDOTS + m_MethodName: OnLeftItem + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: beed57c0-e24f-42ba-9a6d-ef10bae29e7d + m_ActionName: Player Controls/LeftItem[/Keyboard/1] + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 207901908825964653} + m_TargetAssemblyTypeName: PolkaDOTS.Multiplay.MultiplayPlayerController, + PolkaDOTS + m_MethodName: OnRightItem + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 880b5a06-139d-40fc-bd59-67cab59e47a5 + m_ActionName: Player Controls/RightItem[/Keyboard/2] + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 207901908825964653} + m_TargetAssemblyTypeName: PolkaDOTS.Multiplay.MultiplayPlayerController, + PolkaDOTS + m_MethodName: OnThirdAction + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 4a4ddd8c-f219-4ac5-992e-b7073be2ab9a + m_ActionName: Player Controls/ThirdAction[/Keyboard/3] m_DefaultActionMap: Player Controls --- !u!20 &3141172503242693401 Camera: diff --git a/Prefabs/Player/PlayerInput.inputactions b/Prefabs/Player/PlayerInput.inputactions index 5e3e1eb..db2e0fa 100644 --- a/Prefabs/Player/PlayerInput.inputactions +++ b/Prefabs/Player/PlayerInput.inputactions @@ -67,6 +67,33 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "LeftItem", + "type": "Button", + "id": "beed57c0-e24f-42ba-9a6d-ef10bae29e7d", + "expectedControlType": "Button", + "processors": "", + "interactions": "Press", + "initialStateCheck": false + }, + { + "name": "RightItem", + "type": "Button", + "id": "880b5a06-139d-40fc-bd59-67cab59e47a5", + "expectedControlType": "Button", + "processors": "", + "interactions": "Press", + "initialStateCheck": false + }, + { + "name": "ThirdAction", + "type": "Button", + "id": "4a4ddd8c-f219-4ac5-992e-b7073be2ab9a", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -322,6 +349,39 @@ "action": "Exit", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "78e3a7a9-1ae1-4043-9f43-aa2ea4f7c665", + "path": "/1", + "interactions": "", + "processors": "", + "groups": "Keyboard And Mouse", + "action": "LeftItem", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "a47d4061-38fd-4f33-9e3e-b022e09d51ad", + "path": "/2", + "interactions": "", + "processors": "", + "groups": "Keyboard And Mouse", + "action": "RightItem", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "0725be4a-1d7f-42b8-ae5e-9073377df450", + "path": "/3", + "interactions": "", + "processors": "", + "groups": "", + "action": "ThirdAction", + "isComposite": false, + "isPartOfComposite": false } ] }, diff --git a/Runtime/Configuration/ApplicationConfig.cs b/Runtime/Configuration/ApplicationConfig.cs index c233d2b..f3f3f0d 100644 --- a/Runtime/Configuration/ApplicationConfig.cs +++ b/Runtime/Configuration/ApplicationConfig.cs @@ -17,7 +17,7 @@ public static class ApplicationConfig public static readonly CommandLineParser.FlagArgument GetRemoteConfig = new CommandLineParser.FlagArgument("-remoteConfig", false); public static readonly CommandLineParser.StringArgument DeploymentURL = new CommandLineParser.StringArgument("-deploymentURL", "127.0.0.1"); public static readonly CommandLineParser.IntArgument DeploymentPort = new CommandLineParser.IntArgument("-deploymentPort", 7980); - + // ================== NETWORKING ================== public static readonly CommandLineParser.IntArgument NetworkTickRate = new CommandLineParser.IntArgument("-networkTickRate", 60); public static readonly CommandLineParser.IntArgument SimulationTickRate = new CommandLineParser.IntArgument("-simulationTickRate", 60); @@ -25,7 +25,7 @@ public static class ApplicationConfig public static readonly CommandLineParser.IntArgument MaxSimulationStepBatchSize = new CommandLineParser.IntArgument("-maxSimulationStepBatchSize", 4); public static readonly CommandLineParser.IntArgument MaxPredictAheadTimeMS = new CommandLineParser.IntArgument("-maxPredictAheadTimeMS", 250); public static readonly CommandLineParser.FlagArgument DisablePrediction = new CommandLineParser.FlagArgument("-disablePrediction", false); - + // ================== APPLICATION ================== public static readonly CommandLineParser.FlagArgument NoGraphics = new CommandLineParser.FlagArgument("-nographics", false); public static readonly CommandLineParser.FlagArgument DebugEnabled = new CommandLineParser.FlagArgument("-debug", false); @@ -39,8 +39,8 @@ public static class ApplicationConfig public static readonly CommandLineParser.IntArgument Duration = new CommandLineParser.IntArgument("-duration", -1); public static readonly CommandLineParser.IntArgument Delay = new CommandLineParser.IntArgument("-startDelay", 0); public static readonly CommandLineParser.IntArgument UserID = new CommandLineParser.IntArgument("-userID", 0); - - + + // ================== MULTIPLAY ================== public static readonly CommandLineParser.EnumArgument MultiplayStreamingRole = new CommandLineParser.EnumArgument("-multiplayRole", MultiplayStreamingRoles.Disabled); public static readonly CommandLineParser.StringArgument SignalingUrl = new CommandLineParser.StringArgument("-signalingUrl", "ws://127.0.0.1:7981"); @@ -49,18 +49,19 @@ public static class ApplicationConfig //internal static readonly CommandLineParser.StringArrayArgument IceServerUrls = new CommandLineParser.StringArrayArgument("-iceServerUrl"); //internal static readonly CommandLineParser.StringArgument IceServerUsername = new CommandLineParser.StringArgument("-iceServerUsername"); //internal static readonly CommandLineParser.StringArgument IceServerCredential = new CommandLineParser.StringArgument("-iceServerCredential"); - + // ================== EMULATION ================== public static readonly CommandLineParser.EnumArgument EmulationType = new CommandLineParser.EnumArgument("-emulationType", Deployment.EmulationType.None); public static readonly CommandLineParser.FilePathArgument EmulationFile = new CommandLineParser.FilePathArgument("-emulationFile", Application.persistentDataPath + '\\' + "recordedInputs.inputtrace"); public static readonly CommandLineParser.IntArgument NumSimulatedPlayers = new CommandLineParser.IntArgument("-numSimulatedPlayers", 1); public static readonly CommandLineParser.IntArgument SimulatedJoinInterval = new CommandLineParser.IntArgument("-simulatedJoinInterval", 0); - + // ================== STATISTICS ================== public static readonly CommandLineParser.FlagArgument LogStats = new CommandLineParser.FlagArgument("-logStats", false); public static readonly CommandLineParser.FilePathArgument StatsFilePath = new CommandLineParser.FilePathArgument("-statsFile", Application.persistentDataPath + '\\' + "stats.csv"); - - - } + public static readonly CommandLineParser.FlagArgument ActiveLogic = new CommandLineParser.FlagArgument("-activeLogic", true); + public static readonly CommandLineParser.IntArgument CircuitX = new CommandLineParser.IntArgument("-circuitX", 1); + public static readonly CommandLineParser.IntArgument CircuitZ = new CommandLineParser.IntArgument("-circuitZ", 1); + } } \ No newline at end of file diff --git a/Runtime/Player/Multiplay/MultiplayPlayerController.cs b/Runtime/Player/Multiplay/MultiplayPlayerController.cs index 01fa70c..124e847 100644 --- a/Runtime/Player/Multiplay/MultiplayPlayerController.cs +++ b/Runtime/Player/Multiplay/MultiplayPlayerController.cs @@ -5,6 +5,8 @@ using Unity.RenderStreaming; using Unity.Serialization; using UnityEditor; +using Unity.Mathematics; +using System.Collections.Generic; /* * Gathers input from Player GameObject @@ -14,24 +16,29 @@ namespace PolkaDOTS.Multiplay // Collects input either from local devices or a remote input stream using InputActions public class MultiplayPlayerController : MonoBehaviour { - + [SerializeField] InputReceiver playerInput; [DontSerialize] public string username; - [DontSerialize]public Vector2 inputMovement; - [DontSerialize]public Vector2 inputLook; - [DontSerialize]public bool inputJump; - [DontSerialize]public bool inputPrimaryAction = false; - [DontSerialize]public bool inputSecondaryAction = false; - [DontSerialize]public bool playerEntityExists; - [DontSerialize]public bool playerEntityRequestSent; - [DontSerialize]public Entity playerEntity; + [DontSerialize] public Vector2 inputMovement; + [DontSerialize] public Vector2 inputLook; + [DontSerialize] public bool inputJump; + [DontSerialize] public bool inputPrimaryAction = false; + [DontSerialize] public bool inputSecondaryAction = false; + [DontSerialize] public int selectedItemIndex; + [DontSerialize] public bool inputThirdAction = false; + [DontSerialize] public bool playerEntityExists; + [DontSerialize] public bool playerEntityRequestSent; + [DontSerialize] public Entity playerEntity; + [DontSerialize] public List selectableItems = new List { 1, 15, 17, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; protected void Awake() { playerInput.onDeviceChange += OnDeviceChange; username = $"{ApplicationConfig.UserID.Value}"; + selectedItemIndex = 0; } + private void OnEnable() { } @@ -45,17 +52,17 @@ void OnDeviceChange(InputDevice device, InputDeviceChange change) switch (change) { case InputDeviceChange.Added: - { - playerInput.PerformPairingWithDevice(device); - CheckPairedDevices(); - return; - } + { + playerInput.PerformPairingWithDevice(device); + CheckPairedDevices(); + return; + } case InputDeviceChange.Removed: - { - playerInput.UnpairDevices(device); - CheckPairedDevices(); - return; - } + { + playerInput.UnpairDevices(device); + CheckPairedDevices(); + return; + } } } @@ -103,7 +110,7 @@ public void OnJump(InputAction.CallbackContext value) inputJump = true; } } - + public void OnPrimaryAction(InputAction.CallbackContext value) { if (value.performed) @@ -111,7 +118,7 @@ public void OnPrimaryAction(InputAction.CallbackContext value) inputPrimaryAction = true; } } - + public void OnSecondaryAction(InputAction.CallbackContext value) { if (value.performed) @@ -119,7 +126,7 @@ public void OnSecondaryAction(InputAction.CallbackContext value) inputSecondaryAction = true; } } - + public void OnEscapeAction(InputAction.CallbackContext value) { if (value.performed) @@ -133,6 +140,32 @@ public void OnEscapeAction(InputAction.CallbackContext value) #endif } } + + public void OnLeftItem(InputAction.CallbackContext value) + { + if (value.performed) + { + selectedItemIndex = math.max(selectedItemIndex - 1, 0); + Debug.Log($"Selected item: {selectedItemIndex}"); + } + } + + public void OnRightItem(InputAction.CallbackContext value) + { + if (value.performed) + { + selectedItemIndex = math.min(selectedItemIndex + 1, selectableItems.Count - 1); + Debug.Log($"Selected item: {selectedItemIndex}"); + } + } + + public void OnThirdAction(InputAction.CallbackContext value) + { + if (value.performed) + { + inputThirdAction = true; + } + } } } diff --git a/Runtime/Statistics/StatisticsWriterInstance.cs b/Runtime/Statistics/StatisticsWriterInstance.cs index 26b1334..5cd23a2 100644 --- a/Runtime/Statistics/StatisticsWriterInstance.cs +++ b/Runtime/Statistics/StatisticsWriterInstance.cs @@ -18,21 +18,23 @@ public class StatisticsWriterInstance : MonoBehaviour public static bool ready; private void Awake() { - if (!ApplicationConfig.LogStats) { + if (!ApplicationConfig.LogStats) + { return; } - if (File.Exists(ApplicationConfig.StatsFilePath)){ + if (File.Exists(ApplicationConfig.StatsFilePath)) + { // Don't overwrite existing data Debug.Log($"Stats file {ApplicationConfig.StatsFilePath.Value} already exists. Ignoring -logStats."); return; } - + Debug.Log("Creating statistics writer!"); instance = new StatisticsWriter(); ready = true; - + } private void OnDisable() @@ -40,7 +42,7 @@ private void OnDisable() if (ApplicationConfig.LogStats && ready) { // Write statistics before exit - if(!instance.written) + if (!instance.written) instance.WriteStatisticsBuffer(); } @@ -62,45 +64,63 @@ public static void WriteStatisticsBuffer() instance.WriteStatisticsBuffer(); } } - + } public class StatisticsWriter { private Dictionary recorders; - + private string metricsBuffer; - + public bool written; - + public StatisticsWriter() { recorders = new Dictionary(); written = false; // Add generic metrics - AddStatisticRecorder("Main Thread", ProfilerCategory.Internal); + AddStatisticRecorder("Main Thread", ProfilerCategory.Internal); // Total frame time AddStatisticRecorder("System Used Memory", ProfilerCategory.Memory); AddStatisticRecorder("GC Reserved Memory", ProfilerCategory.Memory); AddStatisticRecorder("Total Reserved Memory", ProfilerCategory.Memory); - - AddStatisticRecorder("NFE Snapshot Tick", ProfilerCategory.Network); - AddStatisticRecorder("NFE Snapshot Size (bits)", ProfilerCategory.Network); - AddStatisticRecorder("NFE RTT", ProfilerCategory.Network); - AddStatisticRecorder("NFE Jitter", ProfilerCategory.Network); - - AddStatisticRecorder("Multiplay FPS", ProfilerCategory.Scripts); - AddStatisticRecorder("Multiplay BitRate In", ProfilerCategory.Scripts); - AddStatisticRecorder("Multiplay BitRate Out", ProfilerCategory.Scripts); - AddStatisticRecorder("Multiplay RTT (ms)", ProfilerCategory.Scripts); - AddStatisticRecorder("Multiplay PacketLoss", ProfilerCategory.Scripts); + + //AddStatisticRecorder("NFE Snapshot Tick", ProfilerCategory.Network); + //AddStatisticRecorder("NFE Snapshot Size (bits)", ProfilerCategory.Network); + //AddStatisticRecorder("NFE RTT", ProfilerCategory.Network); + //AddStatisticRecorder("NFE Jitter", ProfilerCategory.Network); + + //AddStatisticRecorder("Multiplay FPS", ProfilerCategory.Scripts); + //AddStatisticRecorder("Multiplay BitRate In", ProfilerCategory.Scripts); + //AddStatisticRecorder("Multiplay BitRate Out", ProfilerCategory.Scripts); + //AddStatisticRecorder("Multiplay RTT (ms)", ProfilerCategory.Scripts); + //AddStatisticRecorder("Multiplay PacketLoss", ProfilerCategory.Scripts); + //AddStatisticRecorder("Number of Terrain Areas (Client)", ProfilerCategory.Scripts); //AddStatisticRecorder("Number of Terrain Areas (Server)", ProfilerCategory.Scripts); - - /*foreach (var (name, recorder) in recorders) + + // Server Related + AddStatisticRecorder("ServerFixedUpdate", ProfilerCategory.Scripts); // Total Server + AddStatisticRecorder("TerrainGeneration", ProfilerCategory.Scripts); + AddStatisticRecorder("PlayerTerrainGenCheck", ProfilerCategory.Scripts); + AddStatisticRecorder("StructureGeneration", ProfilerCategory.Scripts); + + AddStatisticRecorder("TerrainLogicSystem", ProfilerCategory.Scripts); + AddStatisticRecorder("GetUpdates", ProfilerCategory.Scripts); + AddStatisticRecorder("ReevaluatePropagateMarker", ProfilerCategory.Scripts); + AddStatisticRecorder("PropagateLogicState", ProfilerCategory.Scripts); + AddStatisticRecorder("PropInputBlocks", ProfilerCategory.Scripts); + AddStatisticRecorder("PropActiveLogicBlocks", ProfilerCategory.Scripts); + AddStatisticRecorder("CheckGateState", ProfilerCategory.Scripts); + + AddStatisticRecorder("StatisticsSystem", ProfilerCategory.Scripts); + + + foreach (var (name, recorder) in recorders) { if (!recorder.Valid) - Debug.LogWarning($"Recorder [{name}] is invalid!"); - }*/ + Debug.LogWarning($"Recorder [{name}] is invalid!"); + } } public void AddStatisticRecorder(string name, ProfilerCategory category) @@ -116,7 +136,7 @@ private byte[] HeaderToBytes() sb.Append("\n"); return Encoding.ASCII.GetBytes(sb.ToString()); } - + public void Update() { var sb = new StringBuilder($"{Time.frameCount};"); @@ -146,7 +166,7 @@ public void WriteStatisticsBuffer() file.Write(HeaderToBytes()); } } - + // Write data using (var file = File.Open(ApplicationConfig.StatsFilePath, FileMode.Append)) { @@ -157,11 +177,11 @@ public void WriteStatisticsBuffer() { Debug.LogError($"Failed to write statistics to {ApplicationConfig.StatsFilePath} with exception {e}"); } - + written = true; } - + } - + } \ No newline at end of file