[pypy-svn] r62396 - pypy/trunk/pypy/lang/gameboy
cami at codespeak.net
cami at codespeak.net
Mon Mar 2 15:58:10 CET 2009
Author: cami
Date: Mon Mar 2 15:58:08 2009
New Revision: 62396
Modified:
pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
pypy/trunk/pypy/lang/gameboy/video.py
pypy/trunk/pypy/lang/gameboy/video_sprite.py
Log:
reverting the revert
Modified: pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py (original)
+++ pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py Mon Mar 2 15:58:08 2009
@@ -7,7 +7,7 @@
from pypy.lang.gameboy.timer import Clock
from pypy.lang.gameboy import constants
-use_rsdl = False
+use_rsdl = True
if use_rsdl:
from pypy.rlib.rsdl import RSDL, RSDL_helper
from pypy.rpython.lltypesystem import lltype, rffi
Modified: pypy/trunk/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video.py (original)
+++ pypy/trunk/pypy/lang/gameboy/video.py Mon Mar 2 15:58:08 2009
@@ -139,7 +139,7 @@
#XXX remove those dumb helper "objects"
self.line = [0] * (SPRITE_SIZE + GAMEBOY_SCREEN_WIDTH + SPRITE_SIZE)
- self.objects = [0] * constants.OBJECTS_PER_LINE
+ self.objects = [None] * constants.OBJECTS_PER_LINE
self.palette = [0] * 1024
self.frames = 0
@@ -555,41 +555,23 @@
count = self.scan_sprites()
lastx = SPRITE_SIZE + GAMEBOY_SCREEN_WIDTH + SPRITE_SIZE
for index in range(count):
- data = self.objects[index]
- x = (data >> 24) & 0xFF
- flags = (data >> 12) & 0xFF
- address = data & 0xFFF
+ sprite = self.objects[index]
+ x = sprite.x
if (x + SPRITE_SIZE <= lastx):
- self.draw_object_tile(x, address, flags)
+ sprite.draw(self)
else:
- self.draw_overlapped_object_tile(x, address, flags)
+ sprite.draw_overlapped(self)
lastx = x
def scan_sprites(self):
- count = 0
# search active objects
+ count = 0
for sprite in self.sprites:
- x = sprite.x
- y = sprite.y
- if sprite.hidden: continue
- tile = sprite.tile_number
- y = self.line_y - y + 2 * SPRITE_SIZE
- if self.control.big_sprite_size_selected:
- # 8x16 tile size
- tile_size = 15
- tile &= 0xFE
- else:
- # 8x8 tile size
- tile_size = 7
- if y < 0 or y > tile_size: continue
- if sprite.y_flipped:
- y = tile_size - y
- # TODO: build an object abstraction?
- self.objects[count] = (x << 24) + (count << 20) + (sprite.get_attributes_and_flags() << 12) + \
- (tile << 4) + (y << 1)
- count += 1
- if count >= constants.OBJECTS_PER_LINE:
- break
+ if not sprite.hidden and sprite.visible_on_line(self.line_y):
+ self.objects[count] = sprite
+ count += 1
+ if count >= constants.OBJECTS_PER_LINE:
+ break
self.sort_scan_sprite(count)
return count
@@ -599,8 +581,7 @@
for index in range(count):
highest = index
for right in range(index+1, count):
- if (self.objects[right] >> 20) > \
- (self.objects[highest] >> 20):
+ if self.objects[right].x > self.objects[highest].x:
highest = right
self.objects[index], self.objects[highest] = \
self.objects[highest], self.objects[index]
@@ -624,20 +605,20 @@
return self.vram[address] + (self.vram[address + 1] << 8)
- def draw_object_tile(self, x, address, flags):
- self.draw_object(set_tile_line_call_wrapper(self), x, address, flags)
+ def draw_object_tile(self, x, y, address, flags):
+ self.draw_object(set_tile_line_call_wrapper(self), x, y, address, flags)
def set_tile_line(self, pos, color, mask):
self.line[pos] |= color | mask
- def draw_overlapped_object_tile(self, x, address, flags):
+ def draw_overlapped_object_tile(self, x, y, address, flags):
self.draw_object(set_overlapped_object_line_call_wrapper(self),
- x, address, flags)
+ x, y, address, flags)
def set_overlapped_object_line(self, pos, color, mask):
self.line[pos] = (self.line[pos] & 0x0101) | color | mask
- def draw_object(self, caller, x, address, flags):
+ def draw_object(self, caller, x, y, address, flags):
pattern = self.get_pattern(address)
mask = 0
# priority
Modified: pypy/trunk/pypy/lang/gameboy/video_sprite.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_sprite.py (original)
+++ pypy/trunk/pypy/lang/gameboy/video_sprite.py Mon Mar 2 15:58:08 2009
@@ -30,27 +30,25 @@
def get_data(self):
return [self.y, self.x, self.tile_number, self.get_attributes_and_flags()]
- def set_data(self, y, x, tile_number, flags):
- """
- extracts the sprite data from an oam entry
- """
- self.extract_y_position(y)
- self.extract_x_position(x)
- self.extract_tile_number(tile_number)
- self.extract_attributes_and_flags(flags)
-
- def set_data_at(self, position, data):
- """
- extracts the sprite data from an oam entry
- """
- if position == 0:
+ def set_data_at(self, address, data):
+ actual = address % 4
+ if actual == 0:
self.extract_y_position(data)
- if position == 1:
+ if actual == 1:
self.extract_x_position(data)
- if position == 2:
+ if actual == 2:
self.extract_tile_number(data)
- if position == 3:
+ if actual == 3:
self.extract_attributes_and_flags(data)
+
+ def set_data(self, y_position, x_position, tile_number, attributes_and_flags):
+ """
+ extracts the sprite data from an oam entry
+ """
+ self.extract_y_position(y_position)
+ self.extract_x_position(x_position)
+ self.extract_tile_number(tile_number)
+ self.extract_attributes_and_flags(attributes_and_flags)
def extract_y_position(self, data):
"""
@@ -108,14 +106,18 @@
return value
def hide_check(self):
- if self.y <= 0 or self.y >= GAMEBOY_SCREEN_WIDTH:
+ if self.y <= 0 or self.y >= SPRITE_SIZE + GAMEBOY_SCREEN_HEIGHT + SPRITE_SIZE:
self.hidden = True
- elif self.x <= 0 or self.x >= GAMEBOY_SCREEN_WIDTH+SPRITE_SIZE:
+ elif self.x <= 0 or self.x >= GAMEBOY_SCREEN_WIDTH + SPRITE_SIZE:
self.hidden = True
else:
self.hidden = False
return self.hidden
+ def visible_on_line(self, line_y):
+ y = self.get_draw_y(line_y)
+ return y < 0 or y > (self.get_height() -1)
+
def get_tile_number(self):
return self.tile.id
@@ -134,11 +136,28 @@
def intersects_line(self, line):
return line >= self.y and line <= self.y + self.get_height()
- def draw(self):
- pass
-
- def draw_overlapped(self):
- pass
+ def get_draw_y(self, line_y):
+ return line_y - self.y + 2 * SPRITE_SIZE
+
+ def get_draw_address_data(self, line_y):
+ tile = self.tile_number
+ if self.big_size:
+ tile &= 0xFE
+ tile_size = self.get_height() -1
+ y = self.get_draw_y(line_y)
+ if self.y_flipped:
+ y = tile_size - y
+ return (tile << 4) + (y << 1)
+
+ def draw(self, video):
+ video.draw_object_tile(self.x, self.y, \
+ self.get_draw_address_data(video.line_y), \
+ self.get_attributes_and_flags())
+
+ def draw_overlapped(self, video):
+ video.draw_overlapped_object_tile(self.x, self.y, \
+ self.get_draw_address_data(video.line_y), \
+ self.get_attributes_and_flags())
# -----------------------------------------------------------------------------
class PaintSprite(Sprite):
More information about the Pypy-commit
mailing list