Ejemplo n.º 1
0
def build_foreach(i, ex, args, meta_args):
    """Iterate over iterable object"""
    # Set iterable
    i.iterable = hive.variable("$iterable[int]")
    i.pull_iterable = hive.pull_in(i.iterable)
    ex.iterable = hive.antenna(i.pull_iterable)

    i.do_trig = hive.triggerfunc()
    i.trig_in = hive.triggerable(i.do_trig)
    ex.start = hive.entry(i.trig_in)

    i.break_ = hive.variable('bool', False)

    i.item = hive.variable(meta_args.data_type)
    i.push_item = hive.push_out(i.item)
    ex.item = hive.output(i.push_item)

    i.index = hive.variable('int', 0)
    i.pull_index = hive.pull_out(i.index)
    ex.index = hive.output(i.pull_index)

    i.finished = hive.triggerfunc()

    i.do_break = hive.modifier(do_break)
    ex.break_ = hive.entry(i.do_break)
    ex.finished = hive.hook(i.finished)

    i.iter = hive.modifier(do_iter)
    hive.trigger(i.do_trig, i.pull_iterable)
    hive.trigger(i.do_trig, i.iter)
Ejemplo n.º 2
0
def build_keyboard(cls, i, ex, args, meta_args):
    """Listen for keyboard event"""
    if meta_args.mode == 'single key':
        ex.on_event = hive.socket(cls.add_single_listener, identifier="event.add_handler")

        args.key = hive.parameter("str.keycode", "w")
        i.key = hive.property(cls, "key", "str.keycode", args.key)

        i.push_key = hive.push_in(i.key)
        ex.key = hive.antenna(i.push_key)

        i.on_key_changed = hive.triggerable(cls.change_listener_keys)
        hive.trigger(i.push_key, i.on_key_changed)

        i.on_pressed = hive.triggerfunc()
        ex.on_pressed = hive.hook(i.on_pressed)

        i.on_released = hive.triggerfunc()
        ex.on_released = hive.hook(i.on_released)

        i.is_pressed = hive.property(cls, "is_pressed", "bool")
        i.pull_is_pressed = hive.pull_out(i.is_pressed)
        ex.is_pressed = hive.output(i.pull_is_pressed)

    else:
        ex.on_event = hive.socket(cls.add_any_listener, identifier="event.add_handler")

        i.key_pressed = hive.property(cls, 'key_pressed', data_type='str.keycode')
        i.pull_key_pressed = hive.push_out(i.key_pressed)
        ex.key_pressed = hive.output(i.pull_key_pressed)

        i.key_released = hive.property(cls, 'key_released', data_type='str.keycode')
        i.pull_key_released = hive.push_out(i.key_released)
        ex.key_released = hive.output(i.pull_key_released)
Ejemplo n.º 3
0
def build_and(i, ex, args):
    ex.a_value = hive.attribute(("bool", ), False)
    ex.b_value = hive.attribute(("bool", ), False)

    i.a = hive.pull_in(ex.a_value)
    i.b = hive.pull_in(ex.b_value)

    ex.a = hive.antenna(i.a)
    ex.b = hive.antenna(i.b)

    def on_and(h):
        h._pull_inputs()

        if h.a_value and h.b_value:
            h.trig_out()

    i.trig_out = hive.triggerfunc()
    i.trig_in = hive.modifier(on_and)

    # Update attributes before calling modifier
    i.pull_inputs = hive.triggerfunc()
    hive.trigger(i.pull_inputs, i.a, pretrigger=True)
    hive.trigger(i.pull_inputs, i.b, pretrigger=True)

    ex.trig_out = hive.hook(i.trig_out)
    ex.trig_in = hive.entry(i.trig_in)
Ejemplo n.º 4
0
def build_server(cls, i, ex, args):
    i.local_address = hive.property(cls, "local_address", "tuple")
    i.push_bind_address = hive.push_in(i.local_address)
    ex.bind_to = hive.antenna(i.push_bind_address)

    i.do_bind = hive.triggerable(cls.do_bind)
    hive.trigger(i.push_bind_address, i.do_bind)

    # Receiving connection
    i.connected_address = hive.property(cls, "connected_address", "tuple")
    i.push_connected_address = hive.push_out(i.connected_address)
    ex.on_client_connected = hive.output(i.push_connected_address)

    # Receiving connection
    i.disconnected_address = hive.property(cls, "disconnected_address",
                                           "tuple")
    i.push_disconnected_address = hive.push_out(i.disconnected_address)
    ex.on_client_disconnected = hive.output(i.push_disconnected_address)

    # Receiving
    i.from_address = hive.property(cls, "from_address", "tuple")
    i.pull_from_address = hive.pull_out(i.from_address)
    ex.from_address = hive.output(i.pull_from_address)

    i.received_data = hive.property(cls, "received_data", "bytes")
    i.push_received = hive.push_out(i.received_data)
    ex.on_received = hive.output(i.push_received)

    # Hive callbacks
    i.on_disconnected = hive.triggerfunc()
    i.on_connected = hive.triggerfunc()
    i.on_received = hive.triggerfunc()

    hive.trigger(i.on_received, i.push_received)
    hive.trigger(i.on_connected, i.push_connected_address)
    hive.trigger(i.on_disconnected, i.push_disconnected_address)

    # Sending
    i.to_address = hive.property(cls, "to_address", "tuple")
    i.pull_to_address = hive.pull_in(i.to_address)
    ex.to_address = hive.antenna(i.pull_to_address)

    i.outgoing_data = hive.property(cls, "outgoing_data", "bytes")
    i.push_outgoing_data = hive.push_in(i.outgoing_data)
    ex.send = hive.antenna(i.push_outgoing_data)

    i.do_send_data = hive.triggerable(cls.do_send)
    hive.trigger(i.push_outgoing_data, i.pull_to_address, pretrigger=True)
    hive.trigger(i.push_outgoing_data, i.do_send_data)

    i.synchronise_data = hive.triggerable(cls.synchronise)
    i.on_tick = OnTick()
    hive.connect(i.on_tick.on_tick, i.synchronise_data)
Ejemplo n.º 5
0
def build_toggle(i, ex, args):
    """Toggle between two triggers"""
    args.start_value = hive.parameter('bool', False)
    i.toggle = hive.attribute("bool", args.start_value)

    i.modifier = hive.modifier(evaluate_toggle)
    ex.trig_in = hive.entry(i.modifier)

    i.trig_a = hive.triggerfunc()
    i.trig_b = hive.triggerfunc()

    ex.trig_a = hive.hook(i.trig_a)
    ex.trig_b = hive.hook(i.trig_b)
Ejemplo n.º 6
0
def build_keyboard(cls, i, ex, args):
    ex.on_event = hive.socket(cls.add_single_listener,
                              identifier="event.add_handler")
    i.on_tick = hive.triggerfunc()

    ex.name = hive.variable(("str", ), "<Sensor>")
    ex.key = hive.property(cls, "key", "str")
    ex.is_positive = hive.variable(("bool", ), False)

    i.positive = hive.pull_out(ex.is_positive)
    ex.positive = hive.output(i.positive)

    i.trig_out = hive.triggerfunc()
    ex.trig_out = hive.hook(i.trig_out)
Ejemplo n.º 7
0
def build_instantiator(cls, i, ex, args, meta_args):
    """Instantiates a Hive class at runtime"""
    # If this is built now, then it won't perform matchmaking, so use meta hive
    bind_meta_class = hive.meta_hive("BindEnvironment", build_bind_environment, declare_build_environment,
                                     builder_cls=BindEnvironmentClass)
    #assert bind_meta_class._hive_object_class
    i.bind_meta_class = hive.property(cls, "bind_meta_class", "class", bind_meta_class)

    i.trig_instantiate = hive.triggerfunc(cls.instantiate)
    i.do_instantiate = hive.triggerable(i.trig_instantiate)

    i.hive_class = hive.property(cls, "hive_class", "class")
    i.pull_hive_class = hive.pull_in(i.hive_class)
    ex.hive_class = hive.antenna(i.pull_hive_class)

    ex.create = hive.entry(i.do_instantiate)

    hive.trigger(i.trig_instantiate, i.pull_hive_class, pretrigger=True)

    ex.process_id = hive.property(cls, "last_created_process_id", "int.process_id")
    i.pull_process_id = hive.pull_out(ex.process_id)
    ex.last_process_id = hive.output(i.pull_process_id)

    i.push_stop_process = hive.push_in(cls.stop_hive)
    ex.stop_process = hive.antenna(i.push_stop_process)

    # Bind class plugin
    ex.bind_on_created = hive.socket(cls.add_on_created, identifier="bind.on_created", policy=hive.MultipleOptional)
    ex.add_get_plugins = hive.socket(cls.add_get_plugins, identifier="bind.get_plugins", policy=hive.MultipleOptional)
    ex.add_get_config = hive.socket(cls.add_get_config, identifier="bind.get_config", policy=hive.MultipleOptional)

    # Bind instantiator
    if meta_args.bind_process == 'child':
        # Add startup and stop callbacks
        ex.on_stopped = hive.plugin(cls.stop_all_processes, identifier="on_stopped")
Ejemplo n.º 8
0
def build_watch(cls, i, ex, args, meta_args):
    """Watch value and indicate when it is changed.

    Uses a tick callback.
    """
    args.start_value = hive.parameter(meta_args.data_type, None)
    i.value = hive.property(cls, "current_value", meta_args.data_type, args.start_value)

    if meta_args.mode == 'pull':
        i.value_in = hive.pull_in(i.value)

    else:
        i.value_in = hive.push_in(i.value)

    ex.value = hive.antenna(i.value_in)

    i.on_changed = hive.triggerfunc()
    ex.on_changed = hive.hook(i.on_changed)

    if meta_args.mode == 'pull':
        ex.get_add_handler = hive.socket(cls.set_add_handler, identifier="event.add_handler")

    else:
        i.compare_values = hive.triggerable(cls.compare_values)
        hive.trigger(i.value_in, i.compare_values)
Ejemplo n.º 9
0
def test_callable_triggerfunc():
    """Trigger function will trigger associated triggerable, after first calling triggerfunc wrapped function"""
    hive_ping = hive.triggerfunc(print_ping)
    hive_pong = hive.triggerable(print_pong)
    hive.trigger(hive_ping, hive_pong)

    hive_ping()
Ejemplo n.º 10
0
def test_empty_triggerfunc():
    """Trigger function will trigger associated triggerable"""
    hive_pang = hive.triggerfunc()
    hive_pong = hive.triggerable(print_pong)
    hive.trigger(hive_pang, hive_pong)

    hive_pang()
Ejemplo n.º 11
0
def build_dog(cls, i, ex, args):
    i.call = hive.triggerfunc(cls.call)
    i.woof = hive.triggerable(cls.woof)
    hive.trigger(i.call, i.woof)

    i.bark = hive.triggerfunc()
    hive.trigger(i.bark, i.woof)

    i.woof_only = hive.triggerable(cls.woof)
    i.woofed = hive.triggerfunc()

    ex.woofs = hive.property(cls, "woofs")
    ex.woof = hive.entry(i.woof)
    ex.woof_only = hive.entry(i.woof_only)
    ex.woofed = hive.hook(i.woofed)
    ex.bark = hive.hook(i.bark)
    ex.call = hive.hook(i.call)
Ejemplo n.º 12
0
def build_dog(cls, i, ex, args):
    i.call = h.triggerfunc(cls.call)
    i.woof = h.triggerable(cls.woof)
    #h.trigger(i.call, i.woof)
    h.connect(i.call, i.woof)
    i.woof2 = h.modifier(woof2)
    i.bark = h.triggerfunc()
    h.trigger(i.bark, i.woof)
    i.woofed = h.triggerfunc()

    ex.woofs = h.property(cls, "woofs")
    ex.name = h.property(cls, "name")
    ex.woofs2 = h.variable(data_type="int", start_value=0)
    ex.woof = h.entry(i.woof)
    ex.woofed = h.hook(i.woofed)
    ex.bark = h.hook(i.bark)
    ex.call = h.hook(i.call)
Ejemplo n.º 13
0
def build_switch(i, ex, args, meta_args):
    """Redirect input trigger to true / false outputs according to boolean evaluation of switch value"""
    ex.switch = hive.attribute(meta_args.data_type)

    i.input = hive.pull_in(ex.switch)
    ex.input = hive.antenna(i.input)

    i.true = hive.triggerfunc()
    ex.true = hive.hook(i.true)

    i.false = hive.triggerfunc()
    ex.false = hive.hook(i.false)

    i.do_evaluate = hive.modifier(evaluate_switch)
    i.do_trigger = hive.triggerfunc(i.do_evaluate)
    hive.trigger(i.do_trigger, i.input, pretrigger=True)

    i.on_trigger = hive.triggerable(i.do_trigger)
    ex.trigger = hive.entry(i.on_trigger)
Ejemplo n.º 14
0
def build_spawn(cls, i, ex, args, meta_args):
    """Spawn an entity into the scene"""
    ex.get_spawn_entity = hive.socket(cls.set_spawn_entity, "entity.spawn")

    # Associate entity with this hive so it is safely destroyed
    ex.get_register_destructor = hive.socket(cls.set_register_destructor,
                                             "entity.register_destructor")
    ex.on_entity_process_instantiated = hive.plugin(
        cls.on_entity_process_created, "bind.on_created")

    i.entity_class_id = hive.property(cls, "entity_class_id",
                                      "str.entity_class_id")
    i.pull_class_id = hive.pull_in(i.entity_class_id)
    ex.entity_class_id = hive.antenna(i.pull_class_id)

    i.entity_last_created_id = hive.property(cls, "entity_last_created_id",
                                             "int.entity_id")

    if meta_args.spawn_hive:
        i.pull_entity_id = hive.pull_out(i.entity_last_created_id)
        ex.entity_last_created_id = hive.output(i.pull_entity_id)

    else:
        i.push_entity_id = hive.push_out(i.entity_last_created_id)
        ex.created_entity_id = hive.output(i.push_entity_id)

    i.do_spawn = hive.triggerable(cls.do_spawn_entity)
    i.trigger = hive.triggerfunc(i.do_spawn)
    i.on_triggered = hive.triggerable(i.trigger)

    hive.trigger(i.trigger, i.pull_class_id, pretrigger=True)

    # Process instantiator
    if meta_args.spawn_hive:
        i.instantiator = Instantiator(forward_events='all',
                                      bind_process='child')

        # Pull entity to instantiator
        hive.connect(i.pull_entity_id, i.instantiator.entity_id)

        # Get last created
        ex.hive_class = hive.antenna(i.instantiator.hive_class)
        ex.last_process_id = hive.output(i.instantiator.last_process_id)
        ex.stop_process = hive.antenna(i.instantiator.stop_process)
        ex.pause_events = hive.antenna(i.instantiator.pause_events)
        ex.resume_events = hive.antenna(i.instantiator.resume_events)

        # Instantiate
        hive.trigger(i.trigger, i.instantiator.create)

    else:
        # Finally push out entity
        hive.trigger(i.trigger, i.push_entity_id)

    ex.spawn = hive.entry(i.on_triggered)
Ejemplo n.º 15
0
def build_listener(cls, i, ex, args, meta_args):
    """Tick event sensor, trigger on_tick every tick"""
    i.on_event = hive.triggerfunc()
    ex.on_event = hive.hook(i.on_event)

    ex.get_add_handler = hive.socket(cls.set_add_handler, "event.add_handler")

    if meta_args.mode == 'leader':
        i.after_leader = hive.property(cls, 'after_leader', 'tuple')
        i.pull_after_leader = hive.pull_out(i.after_leader)
        ex.after_leader = hive.output(i.pull_after_leader)
Ejemplo n.º 16
0
def build_while(i, ex, args):
    """Trigger output while condition is True"""
    ex.condition = hive.attribute()
    i.condition_in = hive.pull_in(ex.condition)
    ex.condition_in = hive.antenna(i.condition_in)

    i.trig = hive.triggerfunc()
    ex.trig_out = hive.hook(i.trig)

    i.trig_in = hive.modifier(do_while)
    ex.trig_in = hive.entry(i.trig_in)
Ejemplo n.º 17
0
def build_mouse(cls, i, ex, args):
    ex.on_event = hive.socket(cls.set_add_handler,
                              identifier="event.add_handler")
    i.on_tick = hive.triggerfunc()

    args.button = hive.parameter("str",
                                 "left",
                                 options={"left", "middle", "right"})
    i.button = hive.property(cls, "button", "str", args.button)

    i.push_button = hive.push_in(i.button)
    ex.button = hive.antenna(i.push_button)

    i.on_button_changed = hive.triggerable(cls.change_listener_buttons)
    hive.trigger(i.push_button, i.on_button_changed)

    i.on_pressed = hive.triggerfunc()
    ex.on_pressed = hive.hook(i.on_pressed)

    i.on_moved = hive.triggerfunc()
    ex.on_moved = hive.hook(i.on_moved)

    i.pos_x = hive.property(cls, "pos_x", "float")
    i.pull_x = hive.pull_out(i.pos_x)
    ex.x = hive.output(i.pull_x)

    i.pos_y = hive.property(cls, "pos_y", "float")
    i.pull_y = hive.pull_out(i.pos_y)
    ex.y = hive.output(i.pull_y)

    i.dx = hive.property(cls, "dx", "float")
    i.pull_dx = hive.pull_out(i.dx)
    ex.dx = hive.output(i.pull_dx)

    i.dy = hive.property(cls, "dy", "float")
    i.pull_dy = hive.pull_out(i.dy)
    ex.dy = hive.output(i.pull_dy)

    i.is_pressed = hive.property(cls, "is_pressed", "bool")
    i.pull_is_pressed = hive.pull_out(i.is_pressed)
    ex.is_pressed = hive.output(i.pull_is_pressed)
Ejemplo n.º 18
0
def build_tick(cls, i, ex, args):
    """Tick event sensor, trigger on_tick every tick"""
    i.on_tick = hive.triggerfunc()
    ex.on_tick = hive.hook(i.on_tick)

    ex.get_add_handler = hive.socket(cls.set_add_handler, "event.add_handler", policy=hive.SingleRequired)
    ex.get_remove_handler = hive.socket(cls.set_remove_handler, "event.remove_handler", policy=hive.SingleRequired)

    i.enable = hive.triggerable(cls.enable)
    ex.enable = hive.entry(i.enable)

    i.disable = hive.triggerable(cls.disable)
    ex.disable = hive.entry(i.disable)
Ejemplo n.º 19
0
def build_delay(cls, i, ex, args):
    """Delay input trigger by X ticks, where X is the value of delay_in (greater than zero)"""
    i.on_elapsed = hive.triggerfunc()
    ex.on_elapsed = hive.hook(i.on_elapsed)

    i.trigger = hive.triggerfunc(cls.on_triggered)
    i.do_trig = hive.triggerable(i.trigger)
    ex.trig_in = hive.entry(i.do_trig)

    ex.delay = hive.property(cls, "delay", "float")
    i.delay_in = hive.pull_in(ex.delay)
    ex.delay_in = hive.antenna(i.delay_in)

    i.elapsed = hive.pull_out(cls.elapsed)
    ex.elapsed = hive.output(i.elapsed)

    hive.trigger(i.trigger, i.delay_in, pretrigger=True)

    ex.get_add_handler = hive.socket(cls.set_add_handler, "event.add_handler")
    ex.get_remove_handler = hive.socket(cls.set_remove_handler, "event.remove_handler")

    ex.get_get_tick_rate = hive.socket(cls.set_get_tick_rate, "app.get_tick_rate")
Ejemplo n.º 20
0
def build_func(i, ex, args, meta_args):
    """Define callable object from expression"""
    # Get AST and parse ags
    ast_node = ast.parse(meta_args.definition, mode='exec')
    assert isinstance(ast_node, ast.Module)
    assert len(ast_node.body) == 1
    func_def_ast = ast_node.body[0]
    assert isinstance(func_def_ast, ast.FunctionDef)

    visitor = FunctionDefinitionVisitor()
    visitor.visit(ast_node)

    # Build the function itself
    user_namespace = {}
    exec(meta_args.definition, user_namespace)
    user_func = user_namespace[func_def_ast.name]

    has_return = visitor.output_type_name is not function_no_return

    # Define modifier source code (here, we will lookup the "user_func" name later)
    function_call_str = "user_func({})".format(", ".join(
        ["self._{}".format(a) for a in visitor.antennae]))
    result_body = result_str if has_return else ""
    modifier_decl = modifier_str.format(function_call_str=function_call_str,
                                        result_body=result_body)

    # Build modifier function
    namespace = {'user_func': user_func}
    exec(modifier_decl, namespace)
    modifier_func = namespace['modifier']

    # Create modifier bees
    i.modifier = hive.modifier(modifier_func)
    ex.trigger = hive.entry(i.modifier)

    i.pull_all_inputs = hive.triggerfunc()

    # Create IO pins
    for arg, (type_name, default) in visitor.antennae.items():
        attr = hive.variable(type_name, start_value=default)
        setattr(i, arg, attr)
        pull_in = hive.pull_in(attr)
        setattr(ex, arg, hive.antenna(pull_in))
        hive.trigger(i.pull_all_inputs, pull_in, pretrigger=True)

    if has_return:
        result_name = 'result'
        attr = hive.variable(visitor.output_type_name)
        setattr(i, result_name, attr)
        push_out = hive.push_out(attr)
        setattr(ex, result_name, hive.output(push_out))
Ejemplo n.º 21
0
def build_house(cls, i, ex, args):
    i.brutus_ = DogHive("Brutus")
    i.fifi = DogHive("Fifi")

    i.dog_appeared = hive.triggerable(cls.dog_appeared)
    hive.trigger(i.brutus_.call, i.dog_appeared)

    i.mail_arrived = hive.triggerfunc(cls.mail_arrived)
    hive.trigger(i.mail_arrived, i.fifi.woof)

    ex.brutus = i.brutus_
    ex.fifi = i.fifi
    ex.mail_arrived = hive.hook(i.mail_arrived)
    ex.dog_appeared = hive.entry(i.dog_appeared)
Ejemplo n.º 22
0
def build_house(cls, i, ex, args):
    i.brutus = dog("Brutus")
    i.fifi = dog("Fifi")

    i.dog_comes = h.triggerable(cls.dog_comes)
    h.trigger(i.brutus.call, i.dog_comes)

    i.mail = h.triggerfunc(cls.mail)
    h.trigger(i.mail, i.fifi.woof)

    ex.brutus = i.brutus
    ex.fifi = i.fifi
    ex.mail = h.hook(i.mail)
    ex.dog_comes = h.entry(i.dog_comes)
Ejemplo n.º 23
0
def build_server(cls, i, ex, args):
    i.connect_address = hive.property(cls, "server_address", "tuple")
    i.push_connect = hive.push_in(i.connect_address)
    ex.connect_to = hive.antenna(i.push_connect)

    i.do_connect = hive.triggerable(cls.do_connect)
    hive.trigger(i.push_connect, i.do_connect)

    # Hive callbacks
    i.on_disconnected = hive.triggerfunc()
    i.on_connected = hive.triggerfunc()
    i.on_received = hive.triggerfunc()

    # Receiving connection
    ex.on_connected = hive.hook(i.on_connected)

    # Lost connection
    ex.on_disconnected = hive.hook(i.on_disconnected)

    # Receiving
    i.received_data = hive.property(cls, "received_data", "bytes")
    i.push_received = hive.push_out(i.received_data)
    ex.on_received = hive.output(i.push_received)

    hive.trigger(i.on_received, i.push_received)

    # Sending
    i.outgoing_data = hive.property(cls, "outgoing_data", "bytes")
    i.push_outgoing_data = hive.push_in(i.outgoing_data)
    ex.send = hive.antenna(i.push_outgoing_data)

    i.do_send_data = hive.triggerable(cls.do_send)
    hive.trigger(i.push_outgoing_data, i.do_send_data)

    i.synchronise_data = hive.triggerable(cls.synchronise)
    i.on_tick = OnTick()
    hive.connect(i.on_tick.on_tick, i.synchronise_data)
Ejemplo n.º 24
0
def build_always(i, ex, args):
    ex.name = hive.variable(("str", ), "<Sensor>")
    ex.is_positive = hive.variable(("bool", ), True)

    i.positive = hive.pull_out(ex.is_positive)
    ex.positive = hive.output(i.positive)

    def trigger(h):
        h.trig_out()

    i.trig_in = hive.modifier(trigger)
    ex.trig_in = hive.entry(i.trig_in)

    i.trig_out = hive.triggerfunc()
    ex.trig_out = hive.hook(i.trig_out)
Ejemplo n.º 25
0
def build_next(i, ex, args, meta_args):
    """Iterate over generator object, output new value when pulled"""
    i.iterator = hive.attribute("iterator")
    i.iterator_in = hive.pull_in(i.iterator)
    ex.iterator = hive.antenna(i.iterator_in)

    i.pull_iterator = hive.triggerfunc()
    hive.trigger(i.pull_iterator, i.iterator_in)

    i.result = hive.attribute(meta_args.data_type)
    i.pull_value = hive.pull_out(i.result)
    ex.value = hive.output(i.pull_value)

    i.do_next = hive.modifier(next_modifier)

    hive.trigger(i.pull_value, i.do_next, pretrigger=True)
Ejemplo n.º 26
0
def build_mainloop(cls, i, ex, args):
    """Blocking fixed-timestep trigger generator"""
    i.tick = hive.triggerfunc()
    i.stop = hive.triggerable(cls.stop)
    i.run = hive.triggerable(cls.run)

    ex.tick = hive.hook(i.tick)
    ex.run = hive.entry(i.run)
    ex.stop = hive.entry(i.stop)

    i.tick_rate = hive.property(cls, "tick_rate", 'int')
    i.pull_tick_rate = hive.pull_out(i.tick_rate)
    ex.tick_rate = hive.output(i.pull_tick_rate)

    ex.get_tick_rate = hive.plugin(cls.get_tick_rate,
                                   identifier="app.get_tick_rate")
    ex.quit = hive.plugin(cls.stop, identifier="app.quit")
Ejemplo n.º 27
0
def build_variable(i, ex, args, meta_args):
    """Simple value-holding hive"""
    args.start_value = hive.parameter(meta_args.data_type)
    ex.value = hive.variable(meta_args.data_type, args.start_value)

    i.pull_value = hive.pull_out(ex.value)
    ex.value_out = hive.output(i.pull_value)

    i.push_value = hive.push_in(ex.value)
    ex.value_in = hive.antenna(i.push_value)

    if meta_args.advanced:
        i.pre_output = hive.triggerfunc()
        ex.pre_output = hive.hook(i.pre_output)

        i.do_pre_output = hive.triggerable(i.pre_output)
        hive.trigger(i.pull_value, i.do_pre_output, pretrigger=True)
Ejemplo n.º 28
0
def build_physics_manager(cls, i, ex, args):
    i.tick_rate = hive.property(cls, "tick_rate", 'int')
    i.pull_tick_rate = hive.pull_in(i.tick_rate)
    ex.tick_rate = hive.antenna(i.pull_tick_rate)

    i.do_update = hive.triggerfunc(cls.update)
    hive.trigger(i.do_update, i.pull_tick_rate, pretrigger=True)

    i.on_tick = hive.triggerable(i.do_update)
    ex.tick = hive.entry(i.on_tick)

    ex.on_entity_destroyed = hive.plugin(cls.on_entity_destroyed, "entity.on_destroyed", policy=hive.SingleRequired)
    ex.on_entity_created = hive.plugin(cls.on_entity_created, "entity.on_created", policy=hive.SingleRequired)

    ex.get_angular_velocity = hive.plugin(cls.get_angular_velocity, "entity.angular_velocity.get",
                                          export_to_parent=True)
    ex.set_angular_velocity = hive.plugin(cls.set_angular_velocity, "entity.angular_velocity.set",
                                          export_to_parent=True)

    ex.get_linear_velocity = hive.plugin(cls.get_linear_velocity, "entity.angular_velocity.get", export_to_parent=True)
    ex.set_linear_velocity = hive.plugin(cls.set_linear_velocity, "entity.angular_velocity.set", export_to_parent=True)
Ejemplo n.º 29
0
def build_timer(i, ex, args):
    i.dt = hive.variable("float", 0.0)
    ex.step = hive.variable("float", 1 / 60)

    def start(self):
        last = clock()
        while True:
            now = clock()
            self._dt += now - last

            if self._dt > self.step:
                self._dt -= self.step
                self.tick()

            last = now

    i.start = hive.modifier(start)
    ex.start = hive.entry(i.start)

    i.tick = hive.triggerfunc()
    ex.tick = hive.hook(i.tick)
Ejemplo n.º 30
0
def build_destroy(cls, i, ex, args, meta_args):
    """Destroy an entity"""
    i.trig_destroy = hive.triggerfunc(cls.destroy)
    i.do_destroy = hive.triggerable(i.trig_destroy)
    ex.destroy = hive.entry(i.do_destroy)

    if meta_args.bound:
        ex.get_bound = hive.socket(cls.set_get_entity_id,
                                   identifier="entity.get_bound")
        i.do_get_entity_id = hive.triggerable(cls.do_get_entity_id)

        hive.trigger(i.trig_destroy, i.do_get_entity_id, pretrigger=True)

    else:
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.pull_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.pull_entity_id)

        hive.trigger(i.trig_destroy, i.pull_entity_id, pretrigger=True)

    ex.get_destroy_entity = hive.socket(cls.set_destroy_entity,
                                        identifier="entity.destroy")