def default_config(u_class):
    cflags = u_class.class_get_flags()
    u_class.class_set_flags(cflags | CLASS_DEFAULT_CONFIG)
    return u_class


@config('DumbConfig')
@default_config
class FooSettings(Object):

    HelloWorld = StrProperty

    FooWorld = [IntProperty]

    def __init__(self):
        self.add_property_flags('HelloWorld', CPF_CONFIG)
        self.get_uproperty('HelloWorld').set_metadata('Category',
                                                      'CategoryTest001')
        self.HelloWorld = 'Hello World 001'

        self.add_property_flags('FooWorld', CPF_CONFIG)
        self.get_uproperty('FooWorld').set_metadata('Category',
                                                    'CategoryTest002')
        self.FooWorld = [17, 22, 30]


ue.register_settings('Project', 'FooBar', 'General',
                     'General DisplayName', 'General Description',
                     ue.get_mutable_default(FooSettings))
        return u_class
    if isinstance(arg, str):
        config_name = arg
        return wrapper
    return wrapper(arg)
    
def default_config(u_class):
    cflags = u_class.class_get_flags()
    u_class.class_set_flags(cflags|CLASS_DEFAULT_CONFIG)
    return u_class

@config('DumbConfig')
@default_config
class FooSettings(Object):

    HelloWorld = StrProperty

    FooWorld = [IntProperty]

    def __init__(self):
        self.add_property_flags('HelloWorld', CPF_CONFIG)
        self.get_uproperty('HelloWorld').set_metadata('Category', 'CategoryTest001')
        self.HelloWorld = 'Hello World 001'

        self.add_property_flags('FooWorld', CPF_CONFIG)
        self.get_uproperty('FooWorld').set_metadata('Category', 'CategoryTest002')
        self.FooWorld = [17, 22, 30]


ue.register_settings('Project', 'FooBar', 'General', 'General DisplayName', 'General Description', ue.get_mutable_default(FooSettings))
Exemple #3
0
            # write back immediately
            if response:
                send_message(response, writer)
            # async calls -> do nothing here (async will handle it)

    ue.log('client {0} disconnected'.format(name))


# this spawns the server
# the try/finally trick allows for gentle shutdown of the server
async def spawn_server(host, port):
    try:
        coro = await asyncio.start_server(new_client_connected, host, port)
        ue.log('tcp server spawned on {0}:{1}'.format(host, port))
        await coro.wait_closed()
    finally:
        coro.close()
        ue.log('tcp server ended')


"""
Main Program: Get UE4 settings and start listening on port for incoming connections.
"""

settings = ue.get_mutable_default(Engine2LearnSettings)
if settings.Address and settings.Port:
    asyncio.ensure_future(spawn_server(settings.Address, settings.Port))
else:
    ue.log("No settings for either address ({}) or port ({})!".format(
        settings.Address, settings.Port))
Exemple #4
0
import unreal_engine as ue
from unreal_engine.classes import GeneralProjectSettings


def get_project_name():
    return ue.get_mutable_default(GeneralProjectSettings).ProjectName


for prop in ue.get_mutable_default(GeneralProjectSettings).properties():
    print('{0} = {1}'.format(
        prop,
        ue.get_mutable_default(GeneralProjectSettings).get_property(prop)))
Exemple #5
0
def get_project_name():
    return ue.get_mutable_default(GeneralProjectSettings).ProjectName
Exemple #6
0
def get_spec():
    """
    Returns the observation_space (observers) and action_space (action- and axis-mappings) of the Game as a dict with
    keys: `observation_space` and `action_space`
    """
    playing_world = get_playing_world()

    # build the action_space descriptor
    action_space_desc = {}
    input_ = ue.get_mutable_default(InputSettings)
    # go through all action mappings
    # TODO: FOR NOW: ignore all non-keyboard mappings for simplicity.
    # TODO: Later, we will have to create a tick box to specify which actions should be sent to ML
    for action in input_.ActionMappings:
        if re.search(r'Gamepad|Mouse|Thumbstick', action.Key.KeyName):
            continue
        if action.ActionName not in action_space_desc:
            action_space_desc[action.ActionName] = {
                "type": "action",
                "keys": [action.Key.KeyName]
            }
        else:
            action_space_desc[action.ActionName]["keys"].append(
                action.Key.KeyName)
    for axis in input_.AxisMappings:
        if re.search(r'Gamepad|Mouse|Thumbstick', axis.Key.KeyName):
            continue
        if axis.AxisName not in action_space_desc:
            action_space_desc[axis.AxisName] = {
                "type": "axis",
                "keys": [(axis.Key.KeyName, axis.Scale)]
            }
        else:
            action_space_desc[axis.AxisName]["keys"].append(
                (axis.Key.KeyName, axis.Scale))
    ue.log("action_space_desc: {}".format(action_space_desc))

    # DEBUG
    #pydevd.settrace("localhost", port=20023, stdoutToServer=True, stderrToServer=True)  # DEBUG
    # END: DEBUG

    # build the observation_space descriptor
    observation_space_desc = {}
    for observer in MLObserver.GetRegisteredObservers():
        owner, obs_name = sanity_check_observer(observer, playing_world)
        #ue.log("obs={} name={} owner={} enabled={} gray={} type={}".
        #       format(observer, obs_name, owner, observer.bEnabled, observer.bGrayscale, observer.ObserverType))
        # ignore reward observer (ObserverType=1) and is-terminal observer (ObserverType=2)
        if not owner or observer.ObserverType > 0:
            continue

        # ue.log("DEBUG: get_spec observer {}".format(obs_name))

        # this observer returns a camera image
        if observer.bScreenCapture:
            try:
                _, texture = get_scene_capture_and_texture(owner, observer)
            except RuntimeError as e:
                return {"status": "error", "message": "{}".format(e)}
            observation_space_desc[obs_name + "/camera"] = {
                "type":
                "IntBox",
                "shape":
                (texture.SizeX, texture.SizeY) if observer.bGrayscale else
                (texture.SizeX, texture.SizeY, 3),
                "min":
                0,
                "max":
                255
            }

        # go through non-camera/capture properties that need to be observed by this Observer
        for observed_prop in observer.ObservedProperties:
            if not observed_prop.bEnabled:
                continue
            prop_name = observed_prop.PropName
            if not owner.has_property(prop_name):
                continue

            type_ = type(owner.get_property(prop_name))
            if type_ == ue.FVector or type_ == ue.FRotator:
                desc = {
                    "type": "Continuous",
                    "shape": (3, )
                }  # no min/max -> will be derived from samples
            elif type_ == ue.UObject:
                desc = {"type": "str"}
            elif type_ == bool:
                desc = {"type": "Bool"}
            elif type_ == float:
                desc = {"type": "Continuous", "shape": (1, )}
            elif type_ == int:
                desc = {"type": "IntBox", "shape": (1, )}
            else:
                return {
                    "status":
                    "error",
                    "message":
                    "Observed property {} has an unsupported type ({})".format(
                        prop_name, type_)
                }

            observation_space_desc[obs_name + "/" + prop_name] = desc

    ue.log("observation_space_desc: {}".format(observation_space_desc))

    return {
        "status": "ok",
        "game_name": get_project_name(),
        "action_space_desc": action_space_desc,
        "observation_space_desc": observation_space_desc
    }
def get_spec():
    """
    Returns the observation_space (observers) and action_space (action- and axis-mappings) of the Game as a dict with keys:
    `observation_space` and `action_space`
    """
    # auto_texture_size = (84, 84)  # the default size of SceneCapture2D components automatically added to a camera

    playing_world = get_playing_world()

    # build the action_space descriptor
    action_space_desc = {}
    input_ = ue.get_mutable_default(InputSettings)
    # go through all action mappings
    for action in input_.ActionMappings:
        if action.ActionName not in action_space_desc:
            action_space_desc[action.ActionName] = {
                "type": "action",
                "keys": [action.Key.KeyName]
            }
        else:
            action_space_desc[action.ActionName]["keys"].append(
                action.Key.KeyName)
    for axis in input_.AxisMappings:
        if axis.AxisName not in action_space_desc:
            action_space_desc[axis.AxisName] = {
                "type": "axis",
                "keys": [(axis.Key.KeyName, axis.Scale)]
            }
        else:
            action_space_desc[axis.AxisName]["keys"].append(
                (axis.Key.KeyName, axis.Scale))
    ue.log("action_space_desc: {}".format(action_space_desc))

    # DEBUG
    #pydevd.settrace("localhost", port=20023, stdoutToServer=True, stderrToServer=True)  # DEBUG
    # END: DEBUG

    # build the observation_space descriptor
    observation_space_desc = {}
    for observer in E2LObserver.GetRegisteredObservers():
        parent, obs_name = sanity_check_observer(observer, playing_world)
        if not parent:
            continue

        ue.log("DEBUG: get_spec observer {}".format(obs_name))

        # this observer returns a camera image
        if observer.bScreenCapture:
            try:
                _, texture = get_scene_capture_and_texture(parent, obs_name)
            except RuntimeError as e:
                return {"status": "error", "message": "{}".format(e)}
            observation_space_desc[obs_name + ":camera"] = {
                "type": "IntBox",
                "shape": (texture.SizeX, texture.SizeY, 3),
                "min": 0,
                "max": 255
            }

        # go through non-camera/capture properties that need to be observed by this Observer
        for observed_prop in observer.ObservedProperties:
            if not observed_prop.bEnabled:
                continue
            prop_name = observed_prop.PropName
            if not parent.has_property(prop_name):
                continue

            type_ = type(parent.get_property(prop_name))
            if type_ == ue.FVector or type_ == ue.FRotator:
                desc = {
                    "type": "Continuous",
                    "shape": (3, )
                }  # no min/max -> will be derived from samples
            elif type_ == ue.UObject:
                desc = {"type": "str"}
            elif type_ == bool:
                desc = {"type": "Bool"}
            elif type_ == float:
                desc = {"type": "Continuous", "shape": (1, )}
            elif type_ == int:
                desc = {"type": "IntBox", "shape": (1, )}
            else:
                return {
                    "status":
                    "error",
                    "message":
                    "Observed property {} has an unsupported type ({})".format(
                        prop_name, type_)
                }

            observation_space_desc[obs_name + ":" + prop_name] = desc

    ue.log("observation_space_desc: {}".format(observation_space_desc))

    return {
        "status": "ok",
        "action_space_desc": action_space_desc,
        "observation_space_desc": observation_space_desc
    }
Exemple #8
0
    try:
        ue.log("Trying to start listen server on {0}:{1}.".format(host, port))
        co_routine = await asyncio.start_server(new_client_connected, host, port)
        ue.log("Server spawned.")
        await co_routine.wait_closed()
    finally:
        if co_routine:
            co_routine.close()
        ue.log("TCP server ended")

    
"""
Main Program: Get UE4 settings and start listening on port for incoming connections.
"""

# the number to add to our listen port (in case we have many remote-game-envs in one network
port_add = 0
if "MARLENE_PORT_ADD" in os.environ:
    port_add = int(os.environ["MARLENE_PORT_ADD"])

settings = ue.get_mutable_default(MaRLEnESettings)
if not settings.Port:
    settings.Port = 6025
    ue.log("No port set: Using default of {}.".format(settings.Port))
if not settings.Address:
    settings.Address = "localhost"
    ue.log("No address set: Using default of {}.".format(settings.Address))

ue.log("Address={} Port={}.".format(settings.Address, settings.Port))
asyncio.ensure_future(spawn_server(settings.Address, settings.Port + port_add))
import unreal_engine as ue
from unreal_engine.classes import DucanduSettings

settings = ue.get_mutable_default(DucanduSettings)
for prop in settings.properties():
    print('{0}={1}'.format(prop, settings.get_property(prop)))
        return u_class
    if isinstance(arg, str):
        config_name = arg
        return wrapper
    return wrapper(arg)
    
def default_config(u_class):
    cflags = u_class.class_get_flags()
    u_class.class_set_flags(cflags|CLASS_DEFAULT_CONFIG)
    return u_class

@config('DumbConfig')
@default_config
class FooSettings(Object):

    HelloWorld = StrProperty

    FooWorld = [IntProperty]

    def __init__(self):
        self.add_property_flags('HelloWorld', CPF_CONFIG)
        self.get_fproperty('HelloWorld').set_metadata('Category', 'CategoryTest001')
        self.HelloWorld = 'Hello World 001'

        self.add_property_flags('FooWorld', CPF_CONFIG)
        self.get_fproperty('FooWorld').set_metadata('Category', 'CategoryTest002')
        self.FooWorld = [17, 22, 30]


ue.register_settings('Project', 'FooBar', 'General', 'General DisplayName', 'General Description', ue.get_mutable_default(FooSettings))