コード例 #1
0
ファイル: item.py プロジェクト: BlenderCN-Org/hive2
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)
コード例 #2
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)
コード例 #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)
コード例 #4
0
ファイル: range_.py プロジェクト: agoose77/hive2
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)
コード例 #5
0
ファイル: immutable.py プロジェクト: agoose77/hive2
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)
コード例 #6
0
ファイル: math_.py プロジェクト: BlenderCN-Org/hive2
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)
コード例 #7
0
def build_move(cls, i, ex, args, meta_args):
    """Apply a position delta to an entity"""
    coordinate_system = meta_args.coordinate_system

    i.displacement = hive.property(cls, "displacement", "vector")
    i.pull_displacement = hive.pull_in(i.displacement)
    ex.displacement = hive.antenna(i.pull_displacement)

    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.pull_displacement, i.do_get_entity_id)

    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.pull_displacement, i.pull_entity_id)

    if coordinate_system == 'absolute':
        ex.get_set_position = hive.socket(
            cls.set_set_position, identifier="entity.position.set.absolute")
        ex.get_get_position = hive.socket(
            cls.set_get_position, identifier="entity.position.get.absolute")

        i.do_set_position = hive.triggerable(cls.do_move_absolute)

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

        hive.trigger(i.pull_displacement, i.pull_other_entity_id)

        ex.get_set_position = hive.socket(
            cls.set_set_position, identifier="entity.position.set.relative")
        ex.get_get_position = hive.socket(
            cls.set_get_position, identifier="entity.position.get.relative")

        i.do_set_position = hive.triggerable(cls.do_move_relative)

    hive.trigger(i.pull_displacement, i.do_set_position)

    ex.trig = hive.entry(i.pull_displacement)
コード例 #8
0
ファイル: call.py プロジェクト: BlenderCN-Org/hive2
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)
コード例 #9
0
ファイル: convert.py プロジェクト: agoose77/hive2
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)
コード例 #10
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)
コード例 #11
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")
コード例 #12
0
def build_bind(cls, i, ex, args, meta_args):
    bind_mode = meta_args.bind_entity

    if bind_mode == 'bound':
        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)
コード例 #13
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)
コード例 #14
0
ファイル: expression.py プロジェクト: BlenderCN-Org/hive2
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)
コード例 #15
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)
コード例 #16
0
ファイル: decompose.py プロジェクト: BlenderCN-Org/hive2
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)
コード例 #17
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)
コード例 #18
0
def build_cross(i, ex, args):
    """Calculate the cross product between two vectors"""
    i.a = hive.attribute("vector")
    i.b = hive.attribute("vector")

    pull_a = hive.pull_in(i.a)
    pull_b = hive.pull_in(i.b)

    ex.a = hive.antenna(pull_a)
    ex.b = hive.antenna(pull_b)

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

    calculate = hive.modifier(cross_modifier)
    hive.trigger(i.pull_result, calculate, pretrigger=True)
コード例 #19
0
def build_dispatch(cls, i, ex, args):
    i.event = hive.property(cls, "event", "tuple.event")
    i.pull_event = hive.pull_in(i.event)
    ex.event = hive.antenna(i.pull_event)

    ex.get_read_event = hive.socket(cls.set_read_event, identifier="event.process")

    i.dispatch = hive.triggerable(cls.dispatch)
    ex.trig = hive.entry(i.dispatch)
コード例 #20
0
def build_add_head(i, ex, args):
    """Add header to event tuple"""
    i.do_add_head = hive.modifier(do_add_head)

    i.head = hive.variable("str")
    i.pull_head = hive.pull_in(i.head)
    ex.head = hive.antenna(i.pull_head)

    i.leader = hive.variable("tuple.event")
    i.pull_leader = hive.pull_in(i.leader)
    ex.leader = hive.antenna(i.pull_leader)

    i.event = hive.variable("tuple.event")
    i.pull_event = hive.pull_out(i.event)
    ex.event = hive.output(i.pull_event)

    hive.trigger(i.pull_event, i.pull_head, pretrigger=True)
    hive.trigger(i.pull_head, i.pull_leader)
    hive.trigger(i.pull_leader, i.do_add_head)
コード例 #21
0
ファイル: animation.py プロジェクト: agoose77/hive2
def build_animation(cls, i, ex, args, meta_args):
    """Play animation for actor"""
    i.do_start = hive.triggerable(cls.start)
    i.do_stop = hive.triggerable(cls.stop)

    ex.start = hive.entry(i.do_start)
    ex.stop = hive.entry(i.do_stop)

    i.current_frame = hive.property(cls, "current_frame", "int")
    i.end_frame = hive.property(cls, "end_frame", "int")
    i.start_frame = hive.property(cls, "start_frame", "int")

    i.pull_current_frame = hive.pull_out(i.current_frame)
    i.pull_end_frame = hive.pull_in(i.end_frame)
    i.pull_start_frame = hive.pull_in(i.start_frame)

    ex.current_frame = hive.output(i.pull_current_frame)
    ex.start_frame = hive.antenna(i.pull_start_frame)
    ex.end_frame = hive.antenna(i.pull_end_frame)
コード例 #22
0
ファイル: spawn.py プロジェクト: agoose77/hive2
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)
コード例 #23
0
ファイル: while_.py プロジェクト: BlenderCN-Org/hive2
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)
コード例 #24
0
ファイル: dot.py プロジェクト: agoose77/hive2
def build_dot(i, ex, args):
    """Calculate the dot product between two vectors"""
    i.a = hive.variable("vector")
    i.b = hive.variable("vector")

    i.pull_a = hive.pull_in(i.a)
    i.pull_b = hive.pull_in(i.b)

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

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

    i.calculate = hive.modifier(dot_modifier)

    hive.trigger(i.pull_result, i.pull_a, pretrigger=True)
    hive.trigger(i.pull_a, i.pull_b)
    hive.trigger(i.pull_b, i.calculate)
コード例 #25
0
def build_endswith(i, ex, args):
    """Check if string ends with a substring"""
    i.string = hive.attribute('str')
    i.substring = hive.attribute('str')

    i.pull_string = hive.pull_in(i.string)
    i.pull_substring = hive.pull_in(i.substring)

    ex.string = hive.antenna(i.pull_string)
    ex.substring = hive.antenna(i.pull_substring)

    i.endswith = hive.attribute('bool')
    i.pull_endswith = hive.pull_out(i.endswith)
    ex.endswith = hive.output(i.pull_endswith)

    i.do_find_substr = hive.modifier(do_endswith)

    hive.trigger(i.pull_endswith, i.pull_string, pretrigger=True)
    hive.trigger(i.pull_string, i.pull_substring)
    hive.trigger(i.pull_substring, i.do_find_substr)
コード例 #26
0
ファイル: tag.py プロジェクト: agoose77/hive2
def build_tag(cls, i, ex, args, meta_args):
    """Access to entity tag API"""
    if meta_args.bound:
        ex.get_bound = hive.socket(cls.set_get_entity_id, identifier="entity.get_bound")
        i.do_get_bound_entity_id = hive.triggerable(cls.get_entity_id)

    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)
        i.do_get_bound_entity_id = hive.triggerable(i.pull_entity_id)

    i.tag_name = hive.property(cls, "tag_name", "str")
    i.tag_value = hive.property(cls, "tag_value", meta_args.data_type)

    i.pull_tag_name = hive.pull_in(i.tag_name)
    ex.name = hive.antenna(i.pull_tag_name)

    if meta_args.mode == 'get':
        ex.get_get_tag = hive.socket(cls.set_get_tag, identifier="entity.tag.get")

        i.pull_tag_value = hive.pull_out(i.tag_value)
        ex.value = hive.output(i.pull_tag_value)

        i.do_get_tag = hive.triggerable(cls.get_tag)

        hive.trigger(i.pull_tag_value, i.do_get_bound_entity_id)
        hive.trigger(i.pull_tag_value, i.pull_tag_name)
        hive.trigger(i.pull_tag_value, i.do_get_tag)

    else:
        ex.get_set_tag = hive.socket(cls.set_set_tag, identifier="entity.tag.set")

        i.push_tag_value = hive.push_in(i.tag_value)
        ex.value = hive.antenna(i.push_tag_value)

        i.do_get_tag = hive.triggerable(cls.get_tag)

        hive.trigger(i.push_tag_value, i.do_get_bound_entity_id)
        hive.trigger(i.push_tag_value, i.pull_tag_name)
        hive.trigger(i.push_tag_value, i.do_get_tag)
コード例 #27
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)
コード例 #28
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)
コード例 #29
0
ファイル: normalise.py プロジェクト: agoose77/hive2
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)
コード例 #30
0
ファイル: server.py プロジェクト: agoose77/hive2
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)