using Assets.Message.Decoding; using Unity.Collections; using Unity.Jobs; using UnityEngine; namespace Assets.GAMA.net.Message.Jobs { public struct SumoMessageDecodingJob : IJob { //Inputs public NativeArray MessageBytes; //Outputs public NativeArray Headings; public NativeArray Speeds; public NativeArray Accelerations; public NativeArray HasToBeRemoved; public NativeArray Positions; public NativeArray Names; public NativeArray Species; public NativeArray AgentCount; public NativeArray ExperimentCycle; public NativeArray TimestampTicks; public void Execute() { PublishedMessage decodedMessage = Utf8Json.JsonSerializer.Deserialize(MessageBytes.ToArray()); SimulationAgentDto[] decodedAgents = decodedMessage.SimulationAgents; for (int agentIndex = 0; agentIndex < decodedAgents.Length; agentIndex++) { FixedByteString name = new FixedByteString(); FixedByteString species = new FixedByteString(); name.SetString(decodedAgents[agentIndex].Name); species.SetString(decodedAgents[agentIndex].Species); Headings[agentIndex] = float.Parse(decodedAgents[agentIndex].Properties["Heading"]); Speeds[agentIndex] = float.Parse(decodedAgents[agentIndex].Properties["Speed"]); Names[agentIndex] = name; Species[agentIndex] = species; Positions[agentIndex] = new Vector3(decodedAgents[agentIndex].Position.X, decodedAgents[agentIndex].Position.Y, decodedAgents[agentIndex].Position.Z); Accelerations[agentIndex] = float.Parse(decodedAgents[agentIndex].Properties["Acceleration"]); HasToBeRemoved[agentIndex] = decodedAgents[agentIndex].HasToBeRemoved; } TimestampTicks[0] = decodedMessage.TimestampTicks; ExperimentCycle[0] = decodedMessage.ExperimentCycle; AgentCount[0] = decodedAgents.Length; } } }