Пример #1
0
 def genfaceverts(self, orient):
     if orient == 0:
         return [
             ivec3(
                 self.edges[0+2+1] &0xF,
                 self.edges[4+0+1] >>4,
                 self.edges[8+2+0] >>4
             ),
             ivec3(
                 self.edges[0+0+1] &0xF,
                 self.edges[4+0+0] >>4,
                 self.edges[8+2+0] &0xF
             ),
             ivec3(
                 self.edges[0+0+0] &0xF,
                 self.edges[4+0+0] &0xF,
                 self.edges[8+0+0] &0xF
             ),
             ivec3(
                 self.edges[0+2+0] &0xF,
                 self.edges[4+0+1] &0xF,
                 self.edges[8+0+0] >>4
             )
         ]
     elif orient == 1:
         return [
             ivec3(
                 self.edges[0+2+1] >>4,
                 self.edges[4+2+1] >>4,
                 self.edges[8+2+1] >>4
             ),
             ivec3(
                 self.edges[0+2+0] >>4,
                 self.edges[4+2+1] &0xF,
                 self.edges[8+0+1] >>4
             ),
             ivec3(
                 self.edges[0+0+0] >>4,
                 self.edges[4+2+0] &0xF,
                 self.edges[8+0+1] &0xF
             ),
             ivec3(
                 self.edges[0+0+1] >>4,
                 self.edges[4+2+0] >>4,
                 self.edges[8+2+1] &0xF
             ),
         ]
     elif orient == 2:
         return [
             ivec3(
                 self.edges[0+2+0] >>4,
                 self.edges[4+2+1] &0xF,
                 self.edges[8+0+1] >>4
             ),
             ivec3(
                 self.edges[0+2+0] &0xF,
                 self.edges[4+0+1] &0xF,
                 self.edges[8+0+0] >>4
             ),
             ivec3(
                 self.edges[0+0+0] &0xF,
                 self.edges[4+0+0] &0xF,
                 self.edges[8+0+0] &0xF
             ),
             ivec3(
                 self.edges[0+0+0] >>4,
                 self.edges[4+2+0] &0xF,
                 self.edges[8+0+1] &0xF
             )
         ]
     elif orient == 3:
         return [
             ivec3(
                 self.edges[0+0+1] &0xF,
                 self.edges[4+0+0] >>4,
                 self.edges[8+2+0] &0xF
             ),
             ivec3(
                 self.edges[0+2+1] &0xF,
                 self.edges[4+0+1] >>4,
                 self.edges[8+2+0] >>4
             ),
             ivec3(
                 self.edges[0+2+1] >>4,
                 self.edges[4+2+1] >>4,
                 self.edges[8+2+1] >>4
             ),
             ivec3(
                 self.edges[0+0+1] >>4,
                 self.edges[4+2+0] >>4,
                 self.edges[8+2+1] &0xF
             )
         ]
     elif orient == 4:
         return [
             ivec3(
                 self.edges[0+0+0] &0xF,
                 self.edges[4+0+0] &0xF,
                 self.edges[8+0+0] &0xF
             ),
             ivec3(
                 self.edges[0+0+1] &0xF,
                 self.edges[4+0+0] >>4,
                 self.edges[8+2+0] &0xF
             ),
             ivec3(
                 self.edges[0+0+1] >>4,
                 self.edges[4+2+0] >>4,
                 self.edges[8+2+1] &0xF
             ),
             ivec3(
                 self.edges[0+0+0] >>4,
                 self.edges[4+2+0] &0xF,
                 self.edges[8+0+1] &0xF
             )
         ]
     elif orient == 5:
         return [
             ivec3(
                 self.edges[0+2+0] &0xF,
                 self.edges[4+0+1] &0xF,
                 self.edges[8+0+0] >>4
             ),
             ivec3(
                 self.edges[0+2+0] >>4,
                 self.edges[4+2+1] &0xF,
                 self.edges[8+0+1] >>4
             ),
             ivec3(
                 self.edges[0+2+1] >>4,
                 self.edges[4+2+1] >>4,
                 self.edges[8+2+1] >>4
             ),
             ivec3(
                 self.edges[0+2+1] &0xF,
                 self.edges[4+0+1] >>4,
                 self.edges[8+2+0] >>4
             )
         ]
     return v
Пример #2
0
    def read(self):
        with gzip.open(self.mpz, 'rb') as handle:
            self.bytes = handle.read()

        magic = self.read_str(4, null=False)
        if magic not in ('MAPZ', 'BFGZ'):
            raise Exception("Not a mapz file")


        print 'Loading map:', self.mpz
        print 'Header Magic:', magic
        print 'Header Version:'

        version = self.read_int()
        headersize = self.read_int()  # noqa
        print 'Header Size:', headersize

        meta_keys = ('worldsize', 'numents', 'numpvs',
                     'lightmaps', 'blendmap', 'numvslots',
                     'gamever', 'revision')
        #'gameident', 'numvars')
        meta_data = self.read_ints(len(meta_keys))
        meta = {}
        for (k, v) in zip(meta_keys, meta_data):
            meta[k] = v

        # char[4], null=True
        meta['gameident'] = self.read_str(3)
        meta['numvars'] = self.read_int()

        print 'Header Worldsize:', meta['worldsize']
        print 'Header Worldsize:', meta['worldsize']


        map_vars = {}
        for i in range(meta['numvars']):
            # +1 for null term string
            var_name_len = self.read_int()
            var_name = self.read_str(var_name_len)
            # print self.index, var_name
            var_type = self.read_int()

            # String
            if var_type == 2:
                var_len = self.read_int()
                var_val = self.read_str(var_len)
            elif var_type == 1:
                var_val = self.read_float()
            elif var_type == 0:
                var_val = self.read_int()
            else:
                log.error("Don't know how to handle map prop type %s", var_type)
                sys.exit()

            map_vars[var_name] = var_val

        print 'Clearing world..'

        texmru = []
        nummru = self.read_ushort()
        print 'Nummru', nummru
        for i in range(nummru):
            texmru.append(self.read_ushort())

        # Entities
        self.loadents(meta['numents'])
        print 'Header.numents', meta['numents']
        log.info("Loaded %s entities", len(self.ents))

        # Textures?
        self.loadvslots(meta['numvslots'])
        log.info("Loaded %s vslots", len(self.vslots))

        # arggghhh
        failed = False
        print "Loadchildren"
        worldroot = self.loadchildren(
            ivec3(0,0,0),
            meta['worldsize']>>1,
            failed
        )

        cube.validatec(worldroot, meta['worldsize'] >> 1)

        m = Map(magic, version, meta, map_vars)
        return m
Пример #3
0
 def __init__(self, x, y, z, type):
     self.o = ivec3(x, y, z)
     self.type = type
     self.attrs = []
     self.links = []