예제 #1
0
 def architecture(self):
     yield InlineCall(self.char_set_access_unit)
     yield InlineCall(self.screen_access_unit)
     yield self.char_set_access_unit.pivot.shell.store_to_temp(
         ((0, 0, 0), Vector(*self.character_sprite_size) - Vector(1, 1, 1)))
     yield self.screen_access_unit.pivot.shell.load_from_temp(
         ((0, 0, 0), Vector(*self.character_sprite_size) - Vector(1, 1, 1)))
예제 #2
0
파일: entity_shell.py 프로젝트: bowiz2/cbac
 def load_from_temp(self, area, temp_location=(0, 0, 0)):
     """
     :param area:
     :param temp_location:
     :return:
     """
     if not isinstance(area, tuple):
         area = self.context.blockspace.get_area_of(area)
         area = absolute_area(area)
     temp_location = Vector(*temp_location)
     temp_area = [Vector(*point) + temp_location for point in area]
     return self.execute(
         self._join_command("/clone", format_area(temp_area),
                            format_realtive_location((0, 0, 0))))()
예제 #3
0
파일: test_shell.py 프로젝트: bowiz2/cbac
 def setUp(self):
     self.blockspace = BlockspaceMock((20, 20, 20))
     self.executor = CommandBlock(None)
     self.executor_location = Vector(1, 2, 3)
     self.blockspace.add_block(self.executor, self.executor_location)
     self.context = ShellContext(self.blockspace, self.executor)
     self.subject_shell.context = self.context
예제 #4
0
    def load_from_temp(self, temp_location=(0, 0, 0)):
        """
        clone  from the point of reference  area to this point.
        "Point of reference" is the location (0,0,0) in this minecraft world.
        :return: CommandSuspender
        :note: Sees use in the RAM standard unit.
        """
        # TODO: document good.
        area = self.context.get_absolute_area(self.wrapped)
        area = abs_area(area)
        temp_location = Vector(*temp_location)
        temp_area = [Vector(*point) + temp_location for point in area]

        # TODO: fix this mess.
        return self._join_command("/clone", format_area(temp_area),
                                  self.location)
예제 #5
0
파일: area.py 프로젝트: bowiz2/cbac
 def packed_blocks(self):
     """
     :return: A list of relatively packed blocks.
     """
     to_return = []
     for x, block_plane in enumerate(self.block_box.blocks):
         for y, block_row in enumerate(block_plane):
             for z, block_id in enumerate(block_row):
                 to_return.append(
                     BlockAssignment(self.block_box[x][y][z],
                                     Vector(x, y, z), None))
     return to_return
예제 #6
0
def locate_blocks(rows):
    """
    Calculate the locations of each block in the rows.
    :param rows: collection of rows.
    :return: dict of locations.
    """
    locations = {}
    # set locations for the blocks.
    for row_id, row in enumerate(rows):
        for block_id, block in enumerate(row):
            locations[block] = Vector(block_id, row_id, 0)
    return locations
예제 #7
0
    def __init__(self,
                 ratio=(1, 16, 16),
                 word_size=(8, 1, 1),
                 raw_memory=None,
                 input_address=std_logic.InputRegister):
        """
        :param ratio: The ration of words distributed in 3D space.
        :param word_size: the size of a word. by default it is a 8 bits facing east.
        :param raw_memory: This is the actual "raw" memory on which this access unit is operating.
        If no is specified, Memory block will be generated from the ratios multiplied by the word size.
        """
        ratio_product = 1
        for i in ratio:
            ratio_product *= i
        address_space_size = int(math.log(ratio_product, 2))
        word_size = Vector(*word_size)

        super(MemoryAccessUnit, self).__init__(address_space_size)
        # The address you want to access
        self.input_address = self.add_input(input_address)

        self.ratio = Vector(*ratio)
        self.word_size = word_size
        self.address_space = address_space_size

        if not raw_memory:
            # The size of the box in which the memory is stored.
            memory_box_size = (self.ratio.x * self.word_size.x,
                               self.ratio.y * self.word_size.y,
                               self.ratio.z * self.word_size.z)
            raw_memory = BlockBox(memory_box_size, FALSE_BLOCK)

        # raw memory is the actual blocks which represent the memory.
        self.raw_memory = self.add_compound(raw_memory)

        # This pivot is going to move in the memory.
        # TODO: create pivot class with generated names.
        self.pivot = Pivot()
        # ==
        self.synthesis()
예제 #8
0
파일: packer.py 프로젝트: bowiz2/cbac
def pack_areas(areas):
    """
    Takes a collection of areas and organizes them together relative to a centralized point.
    :param areas: areas you want to pack.
    :return: dict of area and the location inside the blockspace.
    """
    assignments = {}
    pivot = Vector(0, 0, 0)
    # TODO: adjust to build direction
    for area in areas:
        assignments[area] = pivot
        if area.is_isolated:
            pivot += Vector(0, 0, 1)
        else:
            prev_area_index = areas.index(area) - 1
            if prev_area_index >= 0:
                if areas[prev_area_index].is_isolated:
                    pivot += Vector(0, 0, 1)

        pivot += Vector(0, 0, area.dimensions.z + 1)

    return assignments
예제 #9
0
파일: area.py 프로젝트: bowiz2/cbac
 def packed_blocks(self):
     """
     :return: List of relatively packed blocks.
     """
     to_return = []
     for x, block_plane in enumerate(self.schematic.Blocks):
         for z, block_row in enumerate(block_plane):
             for y, block_id in enumerate(block_row):
                 to_return.append(
                     BlockAssignment(
                         Block(block_id,
                               block_data=self.schematic.Data[x][z][y]),
                         Vector(x, y, z), None))
     return to_return
예제 #10
0
파일: area.py 프로젝트: bowiz2/cbac
    def _assign(self, compound):
        corner = Vector(0, 0, 0)
        build_direction = self.start_build_direction

        packed = []

        for i, block in enumerate(compound.blocks):
            build_direction_vector = cbac.core.constants.mc_direction.vectors[
                build_direction]
            relative_location = corner + (build_direction_vector * i)
            relative_assignment = BlockAssignment(block, relative_location,
                                                  build_direction)
            packed.append(relative_assignment)

        return packed
예제 #11
0
파일: area.py 프로젝트: bowiz2/cbac
    def dimensions(self):
        """
        :return: Get the width, height and length of the area.
        """

        max_x = 0
        max_y = 0
        max_z = 0

        for block, rel_location, _ in self.packed_blocks:
            if rel_location[0] > max_x:
                max_x = rel_location[0]
            if rel_location[1] > max_y:
                max_y = rel_location[1]
            if rel_location[2] > max_z:
                max_z = rel_location[2]

        result = Vector(max_x, max_y, max_z)

        return result
예제 #12
0
파일: test_shell.py 프로젝트: bowiz2/cbac
 def setUp(self):
     super(TestLocationShell, self).setUp()
     self.blockspace.add_block(self.subject_block, Vector(2, 2, 2))
예제 #13
0
from cbac.core.utils import Vector

UP = 'up'
DOWN = 'down'
NORTH = 'north'
EAST = 'east'
SOUTH = 'south'
WEST = 'west'


def oposite(direction):
    return {
        UP: DOWN,
        DOWN: UP,
        NORTH: SOUTH,
        SOUTH: NORTH,
        EAST: WEST,
        WEST: EAST
    }[direction]


__all__ = ["UP", "DOWN", "WEST", "EAST", "SOUTH", "NORTH"]
vectors = {
    UP: Vector(0, 1, 0),
    DOWN: Vector(0, -1, 0),
    NORTH: Vector(0, 0, 1),
    EAST: Vector(1, 0, 0),
    SOUTH: Vector(0, 0, -1),
    WEST: Vector(-1, 0, 0)
}