Beispiel #1
0
    def _add_sectors(self, textmap: Textmap):
        cycle_count = len(textmap.cycles())  # TODO memoization

        sector_list = [
            Block("sector", self._s2blocklist(s)) for s in textmap.sectors
        ]
        sector_list *= cycle_count

        return sector_list
Beispiel #2
0
    def _add_things(self, textmap: Textmap):
        # TODO multiplicity
        things = {
            t: Block("thing", [
                Assignment("x", Decimal("{0:.3f}".format(t.x))),
                Assignment("y", Decimal("{0:.3f}".format(t.y))),
                Assignment("type", t.type),
            ])
            for t in textmap.things
        }

        return list(things.values()) + self._add_vertices(textmap)
Beispiel #3
0
    def _add_vertices(self, textmap: Textmap):
        vertices = {
            v: Block("vertex", [
                Assignment("x", Decimal("{0:.3f}".format(v.x))),
                Assignment("y", Decimal("{0:.3f}".format(v.y))),
            ])
            for i, v in enumerate(
                sorted(textmap.vertices, key=lambda e: (e.y, e.x)))
        }

        vertex_list = sorted(vertices.items(), key=lambda e: (e[0].y, e[0].x))
        vertex_list = [b for _, b in vertex_list]

        return vertex_list + self._add_linedefs(textmap)
Beispiel #4
0
    def _to_sidedefs(cls, cycles_sides, linedef_list):
        cycle_to_sectorid = cls._assign_cycle_to_sectorid(
            linedef_list, cycles_sides)

        front_sector_ids = cls._ld2sdid(linedef_list, cycle_to_sectorid)

        sidefronts = [
            Block("sidedef", [
                Assignment("sector", sector_id),
                Assignment("texturemiddle", "MARBFACE"),
            ]) for sector_id in front_sector_ids
        ]

        back_sector_ids = cls._ld2sdid_back(linedef_list, cycle_to_sectorid)

        sidebacks = [
            Block("sidedef", [
                Assignment("sector", sector_id),
                Assignment("texturemiddle", "MARBFACE"),
            ]) for sector_id in back_sector_ids
        ]

        return sidefronts + sidebacks
Beispiel #5
0
    def _add_linedefs(self, textmap: Textmap):
        v2id = {
            v: i
            for i, v in enumerate(
                sorted(textmap.vertices, key=lambda e: (e.y, e.x)))
        }

        # Add v1, v2 indices
        linedefs = {(v2id[ld.v1], v2id[ld.v2], ld) for ld in textmap.linedefs}

        # Sort by v1, v2 indices
        linedefs = list(sorted(linedefs, key=lambda e: (e[0], e[1])))

        # To list of dicts
        linedefs = [(ld, dict(v1=v1, v2=v2)) for v1, v2, ld in linedefs]

        # Add sidefront indices
        for sdid, (ld, dct) in enumerate(linedefs):
            dct['sidefront'] = sdid

        # Add sideback indices
        first_sideback_index = max(dct['sidefront']
                                   for ld, dct in linedefs) + 1
        sideback_linedefs = ((ld, dct) for ld, dct in linedefs if ld.sideback)
        for sdid, (ld, dct) in enumerate(sideback_linedefs,
                                         first_sideback_index):
            dct['sideback'] = sdid

        linedefs = {(v2id[ld.v1], v2id[ld.v2],
                     Block("linedef", self._to_block(dct, ld, v2id)))
                    for ld, dct in linedefs}

        linedef_list = [
            b for _, _, b in sorted(linedefs, key=lambda e: (e[0], e[1]))
        ]

        return linedef_list + self._add_sidedefs(textmap)
Beispiel #6
0
    def ast(self) -> TranslationUnit:
        return TranslationUnit(
            Assignment("namespace", "zdoom"),
            Block("thing", [
                Assignment("x", Decimal('32.000')),
                Assignment("y", Decimal('32.000')),
                Assignment("type", 1),
            ]),

            Block("vertex", [
                Assignment("x", Decimal('0.000')),
                Assignment("y", Decimal('0.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('64.000')),
                Assignment("y", Decimal('0.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('128.000')),
                Assignment("y", Decimal('0.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('0.000')),
                Assignment("y", Decimal('64.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('64.000')),
                Assignment("y", Decimal('64.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('128.000')),
                Assignment("y", Decimal('64.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('0.000')),
                Assignment("y", Decimal('128.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('64.000')),
                Assignment("y", Decimal('128.000')),
            ]),
            Block("vertex", [
                Assignment("x", Decimal('128.000')),
                Assignment("y", Decimal('128.000')),
            ]),

            Block("linedef", [
                Assignment("v1", 0),
                Assignment("v2", 3),
                Assignment("sidefront", 0),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 1),
                Assignment("v2", 0),
                Assignment("sidefront", 1),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 2),
                Assignment("v2", 1),
                Assignment("sidefront", 2),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 3),
                Assignment("v2", 4),
                Assignment("sidefront", 3),
                Assignment("sideback", 12),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 3),
                Assignment("v2", 6),
                Assignment("sidefront", 4),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 4),
                Assignment("v2", 1),
                Assignment("sidefront", 5),
                Assignment("sideback", 13),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 4),
                Assignment("v2", 5),
                Assignment("sidefront", 6),
                Assignment("sideback", 14),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 5),
                Assignment("v2", 2),
                Assignment("sidefront", 7),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 6),
                Assignment("v2", 7),
                Assignment("sidefront", 8),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 7),
                Assignment("v2", 4),
                Assignment("sidefront", 9),
                Assignment("sideback", 15),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 7),
                Assignment("v2", 8),
                Assignment("sidefront", 10),
                Assignment("blocking", True),
            ]),
            Block("linedef", [
                Assignment("v1", 8),
                Assignment("v2", 5),
                Assignment("sidefront", 11),
                Assignment("blocking", True),
            ]),

            Block("sidedef", [
                Assignment("sector", 0),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 0),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 1),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 0),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 2),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 0),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 1),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 1),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 2),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 2),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 3),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 3),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 2),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 1),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 3),
                Assignment("texturemiddle", "MARBFACE"),
            ]),
            Block("sidedef", [
                Assignment("sector", 3),
                Assignment("texturemiddle", "MARBFACE"),
            ]),

            Block("sector", [
                Assignment("heightceiling", 128),
                Assignment("textureceiling", "CEIL3_3"),
                Assignment("texturefloor", "CEIL3_3"),
            ]),
            Block("sector", [
                Assignment("heightceiling", 128),
                Assignment("textureceiling", "CEIL3_3"),
                Assignment("texturefloor", "CEIL3_3"),
            ]),
            Block("sector", [
                Assignment("heightceiling", 128),
                Assignment("textureceiling", "CEIL3_3"),
                Assignment("texturefloor", "CEIL3_3"),
            ]),
            Block("sector", [
                Assignment("heightceiling", 128),
                Assignment("textureceiling", "CEIL3_3"),
                Assignment("texturefloor", "CEIL3_3"),
            ]),
        )