示例#1
0
def gofile(self, node):
    try:
        import google.protobuf.text_format
        import gameobject_ddf_pb2
        msg = gameobject_ddf_pb2.PrototypeDesc()
        with open(node.abspath(self.env), 'rb') as in_f:
            google.protobuf.text_format.Merge(in_f.read(), msg)

        task = self.create_task('gameobject')
        task.set_inputs(node)

        embed_output_nodes = []
        for i, c in enumerate(msg.embedded_components):
            name = '%s_generated_%d.%s' % (node.name.split('.')[0], i, c.type)
            embed_node = node.parent.exclusive_build_node(name)
            embed_output_nodes.append(embed_node)

            sub_task = self.create_task(c.type)
            sub_task.set_inputs(embed_node)
            out = embed_node.change_ext('.' + c.type + 'c')
            sub_task.set_outputs(out)
            sub_task.set_run_after(task)
        out = node.change_ext('.goc')
        task.set_outputs([out] + embed_output_nodes)
    except (google.protobuf.text_format.ParseError,
            google.protobuf.message.EncodeError, Exception) as e:
        stderr_lock.acquire()
        try:
            print >> sys.stderr, '%s: %s' % (node.srcpath(self.env), str(e))
        finally:
            stderr_lock.release()
        return 1
示例#2
0
def compile_go(task):
    try:
        import google.protobuf.text_format
        import gameobject_ddf_pb2
        msg = gameobject_ddf_pb2.PrototypeDesc()
        with open(task.inputs[0].srcpath(task.env), 'rb') as in_f:
            google.protobuf.text_format.Merge(in_f.read(), msg)

        for i, c in enumerate(msg.embedded_components):
            with open(task.outputs[i + 1].bldpath(task.env), 'wb') as out_f:
                out_f.write(c.data)

            desc = msg.components.add()
            rel_path_dir = os.path.relpath(task.inputs[0].abspath(),
                                           task.generator.content_root)
            rel_path_dir = os.path.dirname(rel_path_dir)
            if c.id == '':
                raise Exception('Message is missing required field: id')
            desc.id = c.id
            desc.position.x = c.position.x
            desc.position.y = c.position.y
            desc.position.z = c.position.z
            desc.rotation.x = c.rotation.x
            desc.rotation.y = c.rotation.y
            desc.rotation.z = c.rotation.z
            desc.rotation.w = c.rotation.w

            desc.component = '/' + rel_path_dir + '/' + task.outputs[i +
                                                                     1].name

        msg = transform_gameobject(task, msg)
        while len(msg.embedded_components) > 0:
            del (msg.embedded_components[0])

        with open(task.outputs[0].bldpath(task.env), 'wb') as out_f:
            out_f.write(msg.SerializeToString())

        return 0
    except (google.protobuf.text_format.ParseError,
            google.protobuf.message.EncodeError, Exception) as e:
        stderr_lock.acquire()
        try:
            print >> sys.stderr, '%s: %s' % (task.inputs[0].srcpath(
                task.env), str(e))
        finally:
            stderr_lock.release()
        return 1
示例#3
0
def write_embedded(task):
    try:
        import google.protobuf.text_format
        import gameobject_ddf_pb2
        msg = gameobject_ddf_pb2.PrototypeDesc()
        with open(task.inputs[0].srcpath(task.env), 'rb') as in_f:
            google.protobuf.text_format.Merge(in_f.read(), msg)

        msg = transform_gameobject(task, msg)

        for i, c in enumerate(msg.embedded_components):
            with open(task.outputs[i].bldpath(task.env), 'wb') as out_f:
                out_f.write(msg.SerializeToString())

        return 0
    except (google.protobuf.text_format.ParseError, google.protobuf.message.EncodeError) as e:
        stderr_lock.acquire()
        try:
            print >>sys.stderr, '%s: %s' % (task.inputs[0].srcpath(task.env), str(e))
        finally:
            stderr_lock.release()
        return 1