/// <summary> /// /// </summary> /// <param name="b"></param> /// <param name="state"></param> /// <param name="serialise_indidual_observables"></param> /// <param name="do_serialise_unobservables"></param> /// <returns></returns> public static Offset <FState> serialise_state( FlatBufferBuilder b, EnvironmentState state, bool serialise_indidual_observables = false, bool do_serialise_unobservables = false) { var n = b.CreateString(state.EnvironmentName); var observables_vector = FState.CreateObservablesVector(b, state.Observables); var observers_vector = _null_vector_offset; if (serialise_indidual_observables) { var observations = state.Observers; var observers = new Offset <FOBS> [observations.Length]; var k = 0; foreach (var observer in observations) { observers[k++] = serialise_observer(b, observer); } observers_vector = FState.CreateObservationsVector(b, observers); } var unobservables = _null_unobservables_offset; if (do_serialise_unobservables) { var state_eunobservables = state.Unobservables; var bodies = state_eunobservables.Bodies; FUnobservables.StartBodiesVector(b, bodies.Length); foreach (var rig in bodies) { var vel = rig.Velocity; var ang = rig.AngularVelocity; FBody.CreateFBody(b, vel.x, vel.y, vel.z, ang.x, ang.y, ang.z); } var bodies_vector = b.EndVector(); var poses = state_eunobservables.Poses; FUnobservables.StartPosesVector(b, poses.Length); foreach (var tra in poses) { var pos = tra.position; var rot = tra.rotation; FQuaternionTransform.CreateFQuaternionTransform(b, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w); } var poses_vector = b.EndVector(); FUnobservables.StartFUnobservables(b); FUnobservables.AddPoses(b, poses_vector); FUnobservables.AddBodies(b, bodies_vector); unobservables = FUnobservables.EndFUnobservables(b); } var description_offset = new Offset <FEnvironmentDescription>(); if (state.Description != null) { description_offset = serialise_description(b, state); } var d = new StringOffset(); if (state.DebugMessage != "") { d = b.CreateString(state.DebugMessage); } var t = b.CreateString(state.TerminationReason); FState.StartFState(b); FState.AddEnvironmentName(b, n); FState.AddFrameNumber(b, state.FrameNumber); FState.AddObservables(b, observables_vector); if (do_serialise_unobservables) { FState.AddUnobservables(b, unobservables); } FState.AddTotalEnergySpent(b, state.TotalEnergySpentSinceReset); FState.AddSignal(b, state.Signal); FState.AddTerminated(b, state.Terminated); FState.AddTerminationReason(b, t); if (serialise_indidual_observables) { FState.AddObservations(b, observers_vector); } if (state.Description != null) { FState.AddEnvironmentDescription(b, description_offset); } if (state.DebugMessage != "") { FState.AddSerialisedMessage(b, d); } return(FState.EndFState(b)); }
/// <summary> /// /// </summary> /// <param name="b"></param> /// <param name="vel"></param> /// <param name="ang"></param> /// <returns></returns> static Offset <FRB> serialise_body_observation(FlatBufferBuilder b, Vector3 vel, Vector3 ang) { FRB.StartFRB(b); FRB.AddBody(b, FBody.CreateFBody(b, vel.x, vel.y, vel.z, ang.x, ang.y, ang.z)); return(FRB.EndFRB(b)); }