def test_message_int32():
    val = 1337
    msg_out = OutgoingMessage()
    msg_out.write_int32(val)

    msg_in = IncomingMessage(msg_out.buffer)
    read_val = msg_in.read_int32()
    assert val == read_val
 def set_float_parameter(self, key: str, value: float) -> None:
     """
     Sets a float environment parameter in the Unity Environment.
     :param key: The string identifier of the parameter.
     :param value: The float value of the parameter.
     """
     msg = OutgoingMessage()
     msg.write_string(key)
     msg.write_int32(self.EnvironmentDataTypes.FLOAT)
     msg.write_float32(value)
     super().queue_message_to_send(msg)
Exemple #3
0
def test_message_int32():
    val = 1337
    msg_out = OutgoingMessage()
    msg_out.write_int32(val)

    msg_in = IncomingMessage(msg_out.buffer)
    read_val = msg_in.read_int32()
    assert val == read_val

    # Test reading with defaults
    assert 0 == msg_in.read_int32()
    assert val == msg_in.read_int32(default_value=val)
 def set_configuration_parameters(
     self,
     width: int = 80,
     height: int = 80,
     quality_level: int = 1,
     time_scale: float = 20.0,
     target_frame_rate: int = -1,
 ) -> None:
     """
     Sets the engine configuration. Takes as input the configurations of the
     engine.
     :param width: Defines the width of the display. Default 80.
     :param height: Defines the height of the display. Default 80.
     :param quality_level: Defines the quality level of the simulation.
     Default 1.
     :param time_scale: Defines the multiplier for the deltatime in the
     simulation. If set to a higher value, time will pass faster in the
     simulation but the physics might break. Default 20.
     :param target_frame_rate: Instructs simulation to try to render at a
     specified frame rate. Default -1.
     """
     msg = OutgoingMessage()
     msg.write_int32(width)
     msg.write_int32(height)
     msg.write_int32(quality_level)
     msg.write_float32(time_scale)
     msg.write_int32(target_frame_rate)
     super().queue_message_to_send(msg)
Exemple #5
0
def test_stats_channel():
    receiver = StatsSideChannel()
    message = OutgoingMessage()
    message.write_string("stats-1")
    message.write_float32(42.0)
    message.write_int32(1)  # corresponds to StatsAggregationMethod.MOST_RECENT

    receiver.on_message_received(IncomingMessage(message.buffer))

    stats = receiver.get_and_reset_stats()

    assert len(stats) == 1
    val, method = stats["stats-1"][0]
    assert val - 42.0 < 1e-8
    assert method == StatsAggregationMethod.MOST_RECENT
 def set_gaussian_sampler_parameters(self, key: str, mean: float,
                                     st_dev: float, seed: int) -> None:
     """
     Sets a gaussian environment parameter sampler.
     :param key: The string identifier of the parameter.
     :param mean: The mean of the sampling distribution.
     :param st_dev: The standard deviation of the sampling distribution.
     :param seed: The random seed to initialize the sampler.
     """
     msg = OutgoingMessage()
     msg.write_string(key)
     msg.write_int32(self.EnvironmentDataTypes.SAMPLER)
     msg.write_int32(seed)
     msg.write_int32(self.SamplerTypes.GAUSSIAN)
     msg.write_float32(mean)
     msg.write_float32(st_dev)
     super().queue_message_to_send(msg)
 def set_uniform_sampler_parameters(self, key: str, min_value: float,
                                    max_value: float, seed: int) -> None:
     """
     Sets a uniform environment parameter sampler.
     :param key: The string identifier of the parameter.
     :param min_value: The minimum of the sampling distribution.
     :param max_value: The maximum of the sampling distribution.
     :param seed: The random seed to initialize the sampler.
     """
     msg = OutgoingMessage()
     msg.write_string(key)
     msg.write_int32(self.EnvironmentDataTypes.SAMPLER)
     msg.write_int32(seed)
     msg.write_int32(self.SamplerTypes.UNIFORM)
     msg.write_float32(min_value)
     msg.write_float32(max_value)
     super().queue_message_to_send(msg)
 def set_multirangeuniform_sampler_parameters(self, key: str,
                                              intervals: List[Tuple[float,
                                                                    float]],
                                              seed: int) -> None:
     """
     Sets a multirangeuniform environment parameter sampler.
     :param key: The string identifier of the parameter.
     :param intervals: The lists of min and max that define each uniform distribution.
     :param seed: The random seed to initialize the sampler.
     """
     msg = OutgoingMessage()
     msg.write_string(key)
     msg.write_int32(self.EnvironmentDataTypes.SAMPLER)
     msg.write_int32(seed)
     msg.write_int32(self.SamplerTypes.MULTIRANGEUNIFORM)
     flattened_intervals = [
         value for interval in intervals for value in interval
     ]
     msg.write_float32_list(flattened_intervals)
     super().queue_message_to_send(msg)
Exemple #9
0
 def send_int(self, value):
     msg = OutgoingMessage()
     msg.write_int32(value)
     super().queue_message_to_send(msg)
Exemple #10
0
    def set_configuration_parameters(
        self,
        width: Optional[int] = None,
        height: Optional[int] = None,
        quality_level: Optional[int] = None,
        time_scale: Optional[float] = None,
        target_frame_rate: Optional[int] = None,
        capture_frame_rate: Optional[int] = None,
    ) -> None:
        """
        Sets the engine configuration. Takes as input the configurations of the
        engine.
        :param width: Defines the width of the display. (Must be set alongside height)
        :param height: Defines the height of the display. (Must be set alongside width)
        :param quality_level: Defines the quality level of the simulation.
        :param time_scale: Defines the multiplier for the deltatime in the
        simulation. If set to a higher value, time will pass faster in the
        simulation but the physics might break.
        :param target_frame_rate: Instructs simulation to try to render at a
        specified frame rate.
        :param capture_frame_rate: Instructs the simulation to consider time between
        updates to always be constant, regardless of the actual frame rate.
        """

        if (width is None and height is not None) or (width is not None
                                                      and height is None):
            raise UnitySideChannelException(
                "You cannot set the width/height of the screen resolution without also setting the height/width"
            )

        if width is not None and height is not None:
            screen_msg = OutgoingMessage()
            screen_msg.write_int32(self.ConfigurationType.SCREEN_RESOLUTION)
            screen_msg.write_int32(width)
            screen_msg.write_int32(height)
            super().queue_message_to_send(screen_msg)

        if quality_level is not None:
            quality_level_msg = OutgoingMessage()
            quality_level_msg.write_int32(self.ConfigurationType.QUALITY_LEVEL)
            quality_level_msg.write_int32(quality_level)
            super().queue_message_to_send(quality_level_msg)

        if time_scale is not None:
            time_scale_msg = OutgoingMessage()
            time_scale_msg.write_int32(self.ConfigurationType.TIME_SCALE)
            time_scale_msg.write_float32(time_scale)
            super().queue_message_to_send(time_scale_msg)

        if target_frame_rate is not None:
            target_frame_rate_msg = OutgoingMessage()
            target_frame_rate_msg.write_int32(
                self.ConfigurationType.TARGET_FRAME_RATE)
            target_frame_rate_msg.write_int32(target_frame_rate)
            super().queue_message_to_send(target_frame_rate_msg)

        if capture_frame_rate is not None:
            capture_frame_rate_msg = OutgoingMessage()
            capture_frame_rate_msg.write_int32(
                self.ConfigurationType.CAPTURE_FRAME_RATE)
            capture_frame_rate_msg.write_int32(capture_frame_rate)
            super().queue_message_to_send(capture_frame_rate_msg)