コード例 #1
0
        static Offset <FEnvironmentDescription> Serialise(FlatBufferBuilder b, EnvironmentSnapshot snapshot)
        {
            var actors_offsets = new Offset <FActor> [snapshot.Description.Actors.Values.Count];
            var j = 0;

            foreach (var actor in snapshot.Description.Actors)
            {
                var actuators_offsets = new Offset <FActuator> [actor.Value.Actuators.Values.Count];
                var i = 0;
                foreach (var actuator in actor.Value.Actuators)
                {
                    actuators_offsets[i++] = Serialise(b, actuator.Value, actuator.Key);
                }

                actors_offsets[j++] = Serialise(b,
                                                actuators_offsets,
                                                actor.Value,
                                                actor.Key);
            }

            var actors_vector_offset = FEnvironmentDescription.CreateActorsVector(b, actors_offsets);

            var configurables_offsets = new Offset <FConfigurable> [snapshot.Description.Configurables.Values.Count];
            var k = 0;

            foreach (var configurable in snapshot.Description.Configurables)
            {
                configurables_offsets[k++] = Serialise(b, configurable.Value, configurable.Key);
            }

            var configurables_vector_offset =
                FEnvironmentDescription.CreateConfigurablesVector(b, configurables_offsets);

            var objective_offset = Serialise(b, snapshot.Description);

            var sensors = new Offset <FSensor> [snapshot.Description.Sensors.Values.Count];
            var js      = 0;

            foreach (var sensor in snapshot.Description.Sensors)
            {
                sensors[js++] = Serialise(b, sensor.Key, sensor.Value);
            }

            var sensors_vector = FEnvironmentDescription.CreateSensorsVector(b, sensors);

            FEnvironmentDescription.StartFEnvironmentDescription(b);

            FEnvironmentDescription.AddObjective(b, objective_offset);
            FEnvironmentDescription.AddActors(b, actors_vector_offset);
            FEnvironmentDescription.AddConfigurables(b, configurables_vector_offset);
            FEnvironmentDescription.AddSensors(b, sensors_vector);

            return(FEnvironmentDescription.EndFEnvironmentDescription(b));
        }
コード例 #2
0
ファイル: FBSStateUtilities.cs プロジェクト: DanielLSM/droid
        static Offset <FEnvironmentDescription> build_description(FlatBufferBuilder b, EnvironmentState state)
        {
            var actors = new Offset <FActor> [state.Description.Actors.Values.Count];
            var j      = 0;

            foreach (var actor in state.Description.Actors)
            {
                var motors = new Offset <FMotor> [actor.Value.Motors.Values.Count];
                var i      = 0;
                foreach (var motor in actor.Value.Motors)
                {
                    motors[i++] = build_motor(b, motor.Value, motor.Key);
                }
                actors[j++] = build_actor(b, motors, actor.Value, actor.Key);
            }

            var actors_vector = FEnvironmentDescription.CreateActorsVector(b, actors);

            var configurables = new Offset <FConfigurable> [state.Description.Configurables.Values.Count];
            var k             = 0;

            foreach (var configurable in state.Description.Configurables)
            {
                configurables[k++] = build_configurable(b, configurable.Value, configurable.Key);
            }
            var configurables_vector = FEnvironmentDescription.CreateConfigurablesVector(b, configurables);

            var api_version_offset = b.CreateString(state.Description.APIVersion);

            var objective_offset = build_objective(b, state.Description);

            FEnvironmentDescription.StartFEnvironmentDescription(b);
            FEnvironmentDescription.AddObjective(b, objective_offset);

            FEnvironmentDescription.AddActors(b, actors_vector);
            FEnvironmentDescription.AddConfigurables(b, configurables_vector);
            FEnvironmentDescription.AddApiVersion(b, api_version_offset);
            return(FEnvironmentDescription.EndFEnvironmentDescription(b));
        }