Пример #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)
Пример #2
0
def build_decompose(i, ex, args):
    """Decompose complex number into real and imaginary components"""
    i.value = hive.attribute('complex')
    i.real = hive.attribute('float')
    i.imag = hive.attribute('float')

    i.pull_imag = hive.pull_out(i.imag)
    i.pull_real = hive.pull_out(i.real)

    ex.real = hive.output(i.pull_real)
    ex.imag = hive.output(i.pull_imag)

    i.pull_value = hive.pull_in(i.value)
    ex.value = hive.antenna(i.pull_value)

    def build_value(self):
        value = self._value
        self._real = value.real
        self._imag = value.imag

    i.build_value = hive.modifier(build_value)

    hive.trigger(i.pull_imag, i.pull_value, pretrigger=True)
    hive.trigger(i.pull_real, i.pull_value, pretrigger=True)
    hive.trigger(i.pull_value, i.build_value)
Пример #3
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)
Пример #4
0
def build_buffer(i, ex, args, meta_args):
    """Store the input value and output saved value.

    In pull mode, the trigger is used to update the internal value.
    In push mode, the trigger is used to output the internal value.

    Can be used to cache changing values
    """
    args.start_value = hive.parameter(meta_args.data_type, None)
    i.cached_value = hive.attribute(meta_args.data_type, args.start_value)

    if meta_args.mode == "push":
        i.push_value = hive.push_in(i.cached_value)
        ex.value = hive.antenna(i.push_value)

        i.push_cached_value = hive.push_out(i.cached_value)
        ex.cached_value = hive.output(i.push_cached_value)

        ex.output = hive.entry(i.push_cached_value)

    elif meta_args.mode == "pull":
        i.pull_value = hive.pull_in(i.cached_value)
        ex.value = hive.antenna(i.pull_value)

        i.pull_cached_value = hive.pull_out(i.cached_value)
        ex.cached_value = hive.output(i.pull_cached_value)

        ex.update_cache = hive.entry(i.pull_value)
Пример #5
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)
Пример #6
0
def build_struct(cls, i, ex, args):
    """Interface to Struct class"""
    i.tuple = hive.variable("tuple")
    i.pack_in = hive.push_in(i.tuple)
    ex.pack = hive.antenna(i.pack_in)

    i.bytes = hive.variable("bytes")
    i.unpack_out = hive.push_out(i.bytes)
    ex.unpack = hive.output(i.unpack_out)

    i.size_out = hive.pull_out(cls.size)
    ex.size = hive.output(i.size_out)
Пример #7
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)
Пример #8
0
def build_set(i, ex, args, meta_args):
    """Perform set operation on single sets"""

    i.set_ = hive.attribute('set', set())
    i.pull_set_ = hive.pull_out(i.set_)
    ex.set_out = hive.output(i.pull_set_)

    i.push_set_ = hive.push_in(i.set_)
    ex.set_ = hive.antenna(i.push_set_)

    # Pop item
    i.popped_item = hive.attribute(meta_args.data_type)
    i.pull_pop = hive.pull_out(i.popped_item)
    ex.pop = hive.output(i.pull_pop)

    def do_pop(self):
        self._popped_item = self._set_.pop()

    i.do_pop = hive.modifier(do_pop)
    hive.trigger(i.pull_pop, i.do_pop, pretrigger=True)

    # Add item
    i.to_add = hive.attribute(meta_args.data_type)
    i.push_to_add = hive.push_in(i.to_add)
    ex.add = hive.antenna(i.push_to_add)

    def to_add(self):
        self._set_.add(self._to_add)

    i.do_add = hive.modifier(to_add)
    hive.trigger(i.push_to_add, i.do_add)

    # Remove item
    i.to_remove = hive.attribute(meta_args.data_type)
    i.push_to_remove = hive.push_in(i.to_remove)
    ex.remove = hive.antenna(i.push_to_remove)

    def do_remove(self):
        self._set_.remove(self._to_remove)

    i.do_remove = hive.modifier(do_remove)
    hive.trigger(i.push_to_remove, i.do_remove)

    def do_clear(self):
        self._set_.clear()

    i.do_clear = hive.modifier(do_clear)
    ex.clear = hive.entry(i.do_clear)
Пример #9
0
def build_attr(i, ex, args, meta_args):
    """Set/get attribute on object"""
    i.name = hive.attribute("str")
    i.value = hive.attribute(meta_args.attribute_type)
    i.object_ = hive.attribute(meta_args.object_type)

    i.pull_name = hive.pull_in(i.name)
    i.pull_object = hive.pull_in(i.object_)

    ex.object_ = hive.antenna(i.pull_object)
    ex.name = hive.antenna(i.pull_name)

    if meta_args.mode == "set":
        i.push_value = hive.push_in(i.value)
        ex.value = hive.antenna(i.push_value)

        i.do_set_attr = hive.modifier(do_setattr)

        hive.trigger(i.push_value, i.pull_object)
        hive.trigger(i.pull_object, i.pull_name)
        hive.trigger(i.pull_name, i.do_set_attr)

    else:
        i.pull_value = hive.pull_out(i.value)
        ex.value = hive.output(i.pull_value)

        i.do_get_attr = hive.modifier(do_getattr)

        hive.trigger(i.pull_value, i.pull_object, pretrigger=True)
        hive.trigger(i.pull_object, i.pull_name)
        hive.trigger(i.pull_name, i.do_get_attr)
Пример #10
0
def build_convert(i, ex, args, meta_args):
    i.value_in = hive.variable(meta_args.from_data_type)
    i.value_out = hive.variable(meta_args.to_data_type)

    # For push in, push out
    if meta_args.mode == "push":
        i.ppin = hive.push_in(i.value_in)
        i.ppout = hive.push_out(i.value_out)

        hive.trigger(i.ppin, i.ppout)

    else:
        i.ppin = hive.pull_in(i.value_in)
        i.ppout = hive.pull_out(i.value_out)

        hive.trigger(i.ppout, i.ppin, pretrigger=True)

    ex.value_in = hive.antenna(i.ppin)
    ex.value_out = hive.output(i.ppout)

    # For casting (explicit conversion)
    if meta_args.conversion == "cast":
        to_base_type_name = hive.get_base_data_type(meta_args.to_data_type)
        value_cls = _type_map[to_base_type_name]

        def converter(self):
            self._value_out = value_cls(self._value_in)

        i.do_conversion = hive.modifier(converter)
        hive.trigger(i.ppout, i.do_conversion, pretrigger=True)

    # For duck typing, move value through
    else:
        i.move_value = hive.modifier(move_value)
        hive.trigger(i.ppin, i.move_value)
Пример #11
0
def build_range(i, ex, args):
    """A range iterator hive"""
    i.min_value = hive.variable("int")
    i.max_value = hive.variable("int")
    i.step = hive.variable("int")

    i.pull_min_value = hive.pull_in(i.min_value)
    i.pull_max_value = hive.pull_in(i.max_value)
    i.pull_step = hive.pull_in(i.step)

    ex.min_value = hive.antenna(i.pull_min_value)
    ex.max_value = hive.antenna(i.pull_max_value)
    ex.step = hive.antenna(i.pull_step)

    i.iterator = hive.variable("int")

    def get_range(self):
        self._iterator = range(self._min_value, self._max_value, self._step)

    i.get_range = hive.modifier(get_range)

    i.pull_iterator = hive.pull_out(i.iterator, "iterator")
    ex.iterator = hive.output(i.pull_iterator)

    hive.trigger(i.pull_iterator, i.pull_min_value, pretrigger=True)
    hive.trigger(i.pull_iterator, i.pull_max_value, pretrigger=True)
    hive.trigger(i.pull_iterator, i.pull_step, pretrigger=True)
    hive.trigger(i.pull_iterator, i.get_range, pretrigger=True)
Пример #12
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")
Пример #13
0
def build_expression(i, ex, args, meta_args):
    """Execute bound expression for provided inputs and output result"""
    ast_node = ast.parse(meta_args.expression, mode='eval')

    visitor = NodeVisitor()
    visitor.visit(ast_node)

    visited_nodes = visitor.visited_nodes

    variable_names = [x.id for x in visited_nodes if isinstance(x, ast.Name)]

    i.result = hive.attribute(meta_args.result_type)
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    for name in variable_names:
        attribute = hive.attribute()
        setattr(i, name, attribute)

        pull_in = hive.pull_in(attribute)
        setattr(ex, name, hive.antenna(pull_in))

        hive.trigger(i.pull_result, pull_in, pretrigger=True)

    func = create_func(meta_args.expression, variable_names)
    i.modifier = hive.modifier(func)
    hive.trigger(i.pull_result, i.modifier, pretrigger=True)
Пример #14
0
def build_unpack_tuple(i, ex, args, meta_args):
    """Unpack a tuple from individual inputs"""
    i.tuple_ = hive.attribute('tuple')
    i.push_tuple = hive.push_in(i.tuple_)
    ex.tuple_ = hive.antenna(i.push_tuple)

    for index, data_type in enumerate(meta_args.types):
        attr = hive.attribute(data_type)
        setattr(i, "attr_{}".format(index), attr)

        pull_out = hive.pull_out(attr)
        setattr(i, "pull_out_{}".format(index), pull_out)

        setattr(ex, "item_{}".format(index), hive.output(pull_out))

    def do_unpack_tuple(self):
        tuple_ = self._tuple_
        data_types = meta_args.types

        assert len(tuple_) == len(data_types)

        for index, item in enumerate(tuple_):
            setattr(self, "_attr_{}".format(index), item)

    i.do_unpack_tuple = hive.modifier(do_unpack_tuple)
    hive.trigger(i.push_tuple, i.do_unpack_tuple)
Пример #15
0
def build_input_handler(cls, i, ex, args):
    i.update = hive.triggerable(cls.update)
    ex.update = hive.entry(i.update)

    i.event = hive.property(cls, "event", "tuple")
    i.push_event = hive.push_out(i.event)
    ex.event = hive.output(i.push_event)
Пример #16
0
def build_item(i, ex, args, meta_args):
    """Set/get item in object"""
    i.name = hive.attribute(meta_args.index_type)
    i.value = hive.attribute(meta_args.item_type)
    i.container_ = hive.attribute(meta_args.container_type)

    i.pull_name = hive.pull_in(i.name)
    i.pull_container = hive.pull_in(i.container_)

    ex.container_ = hive.antenna(i.pull_container)
    ex.name = hive.antenna(i.pull_name)

    if meta_args.mode == "set":
        i.push_value = hive.push_in(i.value)
        ex.value = hive.antenna(i.push_value)

        i.do_set_attr = hive.modifier(do_setitem)

        hive.trigger(i.push_value, i.pull_container)
        hive.trigger(i.pull_container, i.pull_name)
        hive.trigger(i.pull_name, i.do_set_attr)

    else:
        i.pull_value = hive.pull_out(i.value)
        ex.value = hive.output(i.pull_value)

        i.do_get_attr = hive.modifier(do_getitem)

        hive.trigger(i.pull_value, i.pull_container, pretrigger=True)
        hive.trigger(i.pull_container, i.pull_name)
        hive.trigger(i.pull_name, i.do_get_attr)
Пример #17
0
def build_call(i, ex, args, meta_args):
    func = create_func(meta_args.declaration)
    spec = signature(func)

    for name, parameter in spec.parameters.items():
        if parameter.annotation is parameter.empty:
            raise ValueError("Expected annotation for parameter '{}'".format(name))

        attr = hive.attribute(parameter.annotation)
        pull_in = hive.pull_in(attr)
        antenna = hive.antenna(pull_in)

        setattr(i, name, attr)
        setattr(i, "pull_{}".format(name), pull_in)
        setattr(ex, name, antenna)

    wrapped_func = create_wrapper_func(meta_args.declaration, spec.parameters)
    i.modifier = hive.modifier(wrapped_func)

    return_type = spec.return_annotation

    if return_type is spec.empty:
        raise ValueError("Expected annotation for return parameter")

    i.result = hive.attribute(return_type)
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    hive.trigger(i.pull_result, i.modifier, pretrigger=True)
Пример #18
0
def build_set(i, ex, args):
    """Perform set operation on two sets"""
    i.a = hive.variable('set')
    i.pull_a = hive.pull_in(i.a)
    ex.a = hive.antenna(i.pull_a)

    i.b = hive.variable('set')
    i.pull_b = hive.pull_in(i.b)
    ex.b = hive.antenna(i.pull_b)

    i.result = hive.variable('set')
    for op_name, op in SET_SET_OPERATIONS.items():
        pull_op = hive.pull_out(i.result)
        setattr(i, "pull_{}".format(op_name), pull_op)
        setattr(ex, op_name, hive.output(pull_op))

        def do_operation(self):
            self._result = op(self._a, self._b)

        mod = hive.modifier(do_operation)
        setattr(i, "do_{}".format(op_name), mod)

        hive.trigger(pull_op, i.pull_a, pretrigger=True)
        hive.trigger(pull_op, mod, pretrigger=True)

    hive.trigger(i.pull_a, i.pull_b)
Пример #19
0
def build_operator(i, ex, args, meta_args):
    """HIVE interface to python mathematical operators"""
    assert meta_args.operator in operators
    op = operators[meta_args.operator]

    i.a = hive.attribute(meta_args.data_type)
    i.b = hive.attribute(meta_args.data_type)

    i.pull_a = hive.pull_in(i.a)
    ex.a = hive.antenna(i.pull_a)

    i.pull_b = hive.pull_in(i.b)
    ex.b = hive.antenna(i.pull_b)
    hive.trigger(i.pull_a, i.pull_b)

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

    def calc(self):
        self._result = op(self._a, self._b)

    i.run_operator = hive.modifier(calc)

    hive.trigger(i.pull_a, i.run_operator)
    hive.trigger(i.pull_result, i.pull_a, pretrigger=True)
Пример #20
0
def build_io(i, ex, args, meta_args):
    if meta_args.mode == 'pull':
        i.value = hive.variable()
        i.in_ = hive.pull_in(i.value)
        ex.in_ = hive.antenna(i.in_)

        hive.trigger(i.in_, )

        i.out = meta_args.out(i.value)
        ex.out = hive.output(i.out)
    else:
        i.value = hive.variable()
        i.in_ = meta_args.in_(i.value)
        ex.in_ = hive.antenna(i.in_)

        i.out = meta_args.out(i.value)
        ex.out = hive.output(i.out)
Пример #21
0
def build_random(cls, i, ex, args):
    """HIVE interface to Python random module"""
    i.push_seed = hive.push_in(cls.set_seed)
    ex.seed = hive.antenna(i.push_seed)

    i.pull_random = hive.pull_out(cls.get_rand)
    ex.random = hive.output(i.pull_random)

    i.pull_bool = hive.pull_out(cls.get_bool)
    ex.bool = hive.output(i.pull_bool)

    # Randint
    i.randint_min = hive.property(cls, "randint_min", "int")
    i.randint_max = hive.property(cls, "randint_max", "int")
    i.randint_step = hive.property(cls, "randint_step", "int")

    i.pull_randint_min = hive.pull_in(i.randint_min)
    i.pull_randint_max = hive.pull_in(i.randint_max)
    i.pull_randint_step = hive.pull_in(i.randint_step)

    ex.int_min = hive.antenna(i.pull_randint_min)
    ex.int_max = hive.antenna(i.pull_randint_max)
    ex.int_step = hive.antenna(i.pull_randint_step)

    i.pull_int = hive.pull_out(cls.get_randrange)
    ex.int = hive.output(i.pull_int)

    hive.trigger(i.pull_int, i.pull_randint_max, pretrigger=True)
    hive.trigger(i.pull_int, i.pull_randint_min, pretrigger=True)
    hive.trigger(i.pull_int, i.pull_randint_step, pretrigger=True)

    # Randrange
    i.uniform_min = hive.property(cls, "uniform_min", "float")
    i.uniform_max = hive.property(cls, "uniform_max", "float")

    i.uniform_min_in = hive.pull_in(i.uniform_min)
    i.uniform_max_in = hive.pull_in(i.uniform_max)

    ex.uniform_min = hive.antenna(i.uniform_min_in)
    ex.uniform_max = hive.antenna(i.uniform_max_in)

    i.pull_uniform = hive.pull_out(cls.get_uniform)
    ex.uniform = hive.output(i.pull_uniform)

    hive.trigger(i.pull_uniform, i.uniform_max_in, pretrigger=True)
    hive.trigger(i.pull_uniform, i.uniform_min_in, pretrigger=True)
Пример #22
0
def build_define(i, ex, args, meta_args):
    """Define callable object from expression"""
    # Check body is valid
    ast_node = ast.parse(meta_args.definition, mode='exec')

    func = create_func(meta_args.definition)
    i.result = hive.attribute(("object", "callable"), func)
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)
Пример #23
0
def build_this(cls, i, ex, args):
    """Access to current bound entity"""
    ex.get_bound_entity = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound")

    i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
    i.pull_entity_id = hive.pull_out(i.entity_id)
    ex.entity_id = hive.output(i.pull_entity_id)

    i.do_get_entity_id = hive.triggerable(cls.get_entity_id)
    hive.trigger(i.pull_entity_id, i.do_get_entity_id, pretrigger=True)
Пример #24
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)
Пример #25
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)
Пример #26
0
def build_determinant(i, ex, args):
    """Calculate the determinant (length) of a vector"""
    i.vector = hive.variable("vector")
    i.pull_vector = hive.pull_in(i.vector)
    ex.vector = hive.antenna(i.pull_vector)

    i.result = hive.variable("float")
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    i.calculate = hive.modifier(length_modifier)
    hive.trigger(i.pull_result, i.calculate, pretrigger=True)
Пример #27
0
def build_transistor(i, ex, args, meta_args):
    """Convert a pull output into a push output, using a trigger input"""
    i.value = hive.variable(meta_args.data_type)
    i.pull_value = hive.pull_in(i.value)
    ex.value = hive.antenna(i.pull_value)

    i.push_value = hive.push_out(i.value)
    ex.result = hive.output(i.push_value)

    ex.trigger = hive.entry(i.pull_value)

    hive.trigger(i.pull_value, i.push_value)
Пример #28
0
def build_normalise(i, ex, args):
    """Find the unit vector for a given vector"""
    i.vector = hive.variable("vector")
    i.pull_vector = hive.pull_in(i.vector)
    ex.vector = hive.antenna(i.pull_vector)

    i.result = hive.variable("vector")
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    i.calculate = hive.modifier(normalise_modifier)
    hive.trigger(i.pull_result, i.calculate, pretrigger=True)
Пример #29
0
def time_builder(cls, i, ex, args):
    """Access to Python time module"""
    i.elapsed = hive.property(cls, 'elapsed', 'float')
    i.elapsed_out = hive.pull_out(i.elapsed)
    ex.elapsed_out = hive.output(i.elapsed_out)

    ex.get_add_handler = hive.socket(cls.set_add_handler, "event.add_handler")
    ex.on_started = hive.plugin(cls.on_started,
                                "on_started",
                                policy=hive.SingleRequired)
    ex.get_get_tick_rate = hive.socket(cls.set_get_tick_rate,
                                       "app.get_tick_rate")
Пример #30
0
def build_count(i, ex, args):
    """Simple integer counter"""
    args.start_value = hive.parameter("int", 0)
    ex.count = hive.attribute("int", args.start_value)

    i.do_count_up = hive.modifier(do_count_up)
    ex.increment = hive.entry(i.do_count_up)

    i.do_count_down = hive.modifier(do_count_down)
    ex.decrement = hive.entry(i.do_count_down)

    i.count_out = hive.push_out(ex.count)
    ex.count_out = hive.output(i.count_out)