5 class VidException(Exception):
12 # Stuff from I_* in the C code.
13 def SetPalette(self, data):
15 for i in range (0, 768, 3):
16 rgb = [ord(x) for x in data[i:i+3]]
17 self.palette.append(rgb)
18 self.screen.set_palette(self.palette)
23 # Stuff from V_* in the C code.
24 def __blitRaw (self, data, w, h):
25 screen = pygame.surfarray.pixels2d (self.screen)
27 for x in range (0, w):
28 screen[x,y] = ord (data[y * w + x])
30 def __blitPatch(self, data, x, y, trans = lambda x: x):
31 (width, height) = struct.unpack_from ('<hh', data, 0)
32 (left_offset, top_offset) = struct.unpack_from('<hh', data, 4)
33 column_offsets = struct.unpack_from('<8i', data, 8)
39 # Crazy column/patch thing to buffer
40 screen = pygame.surfarray.pixels2d (self.screen)
41 for x_ofs in range (0, width):
42 col_ofs = struct.unpack_from ('<i', data, 8 + 4 * x_ofs)[0]
43 topdelta = ord (data[col_ofs + 0])
44 # Step through the posts in a column
45 while topdelta != 255:
46 length = ord (data[col_ofs + 1])
47 source_ofs = col_ofs + 3
48 for y_ofs in range (0, length):
49 screen[x + x_ofs, topdelta + y_ofs] = trans(ord (data[source_ofs + y_ofs]))
50 col_ofs = col_ofs + length + 4
51 topdelta = ord (data[col_ofs + 0])
55 self.window = pygame.display.set_mode ((320,200), 0, 8)
56 pygame.display.set_caption('PyHexen')
57 self.screen = pygame.display.get_surface()
59 def DrawRawScreen(self, lump):
60 # Horribly inefficent for now.
61 self.__blitRaw (lump, 320, 200)
63 def DrawPatch(self, x, y, lump):
64 # Horribly inefficent for now.
65 self.__blitPatch (lump, x, y)
67 def DrawFuzzPatch(self, x, y, lump):
69 self.DrawPatch(x,y,lump)
71 def DrawShadowedPatch(self,x,y,lump):
73 self.DrawPatch(x,y,lump)