cleaned up various variable names in the SDL backend & NewGui; also fixed a small buglet that could cause garbage to appear behind the mouse cursor when closing NewGui while inside a game

svn-id: r5029
This commit is contained in:
Max Horn 2002-09-28 16:19:28 +00:00
parent 45877ea2dc
commit 9dc5fe2a1d
6 changed files with 286 additions and 292 deletions

View file

@ -70,33 +70,33 @@ void OSystem_SDL_Common::set_timer(int timer, int (*callback)(int)) {
} }
OSystem_SDL_Common::OSystem_SDL_Common() OSystem_SDL_Common::OSystem_SDL_Common()
: sdl_screen(0), cdrom(0), SCREEN_WIDTH(0), SCREEN_HEIGHT(0), : _screen(0), _screenWidth(0), _screenHeight(0), _cdrom(0),
_dirty_checksums(0), _current_shake_pos(0), _new_shake_pos(0) _dirty_checksums(0), _currentShakePos(0), _newShakePos(0)
{ {
// allocate palette storage // allocate palette storage
_cur_pal = (SDL_Color*)calloc(sizeof(SDL_Color), 256); _currentPalette = (SDL_Color*)calloc(sizeof(SDL_Color), 256);
// allocate the dirty rect storage // allocate the dirty rect storage
_mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2); _mouseBackup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2);
} }
OSystem_SDL_Common::~OSystem_SDL_Common() OSystem_SDL_Common::~OSystem_SDL_Common()
{ {
if (_dirty_checksums) if (_dirty_checksums)
free(_dirty_checksums); free(_dirty_checksums);
free(_cur_pal); free(_currentPalette);
free(_mouse_backup); free(_mouseBackup);
} }
void OSystem_SDL_Common::init_size(uint w, uint h) { void OSystem_SDL_Common::init_size(uint w, uint h) {
// Avoid redundant res changes // Avoid redundant res changes
if ((int)w == SCREEN_WIDTH && (int)h == SCREEN_HEIGHT) if ((int)w == _screenWidth && (int)h == _screenHeight)
return; return;
SCREEN_WIDTH = w; _screenWidth = w;
SCREEN_HEIGHT = h; _screenHeight = h;
CKSUM_NUM = (SCREEN_WIDTH*SCREEN_HEIGHT/(8*8)); CKSUM_NUM = (_screenWidth*_screenHeight/(8*8));
if (_dirty_checksums) if (_dirty_checksums)
free(_dirty_checksums); free(_dirty_checksums);
_dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32)); _dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32));
@ -113,10 +113,10 @@ void OSystem_SDL_Common::init_size(uint w, uint h) {
} }
void OSystem_SDL_Common::copy_rect(const byte *buf, int pitch, int x, int y, int w, int h) { void OSystem_SDL_Common::copy_rect(const byte *buf, int pitch, int x, int y, int w, int h) {
if (sdl_screen == NULL) if (_screen == NULL)
return; return;
if (pitch == SCREEN_WIDTH && x==0 && y==0 && w==SCREEN_WIDTH && h==SCREEN_HEIGHT && _mode_flags&DF_WANT_RECT_OPTIM) { if (pitch == _screenWidth && x==0 && y==0 && w==_screenWidth && h==_screenHeight && _mode_flags&DF_WANT_RECT_OPTIM) {
/* Special, optimized case for full screen updates. /* Special, optimized case for full screen updates.
* It tries to determine what areas were actually changed, * It tries to determine what areas were actually changed,
* and just updates those, on the actual display. */ * and just updates those, on the actual display. */
@ -125,8 +125,8 @@ void OSystem_SDL_Common::copy_rect(const byte *buf, int pitch, int x, int y, int
/* Clip the coordinates */ /* Clip the coordinates */
if (x < 0) { w+=x; buf-=x; x = 0; } if (x < 0) { w+=x; buf-=x; x = 0; }
if (y < 0) { h+=y; buf-=y*pitch; y = 0; } if (y < 0) { h+=y; buf-=y*pitch; y = 0; }
if (w > SCREEN_WIDTH-x) { w = SCREEN_WIDTH - x; } if (w > _screenWidth-x) { w = _screenWidth - x; }
if (h > SCREEN_HEIGHT-y) { h = SCREEN_HEIGHT - y; } if (h > _screenHeight-y) { h = _screenHeight - y; }
if (w <= 0 || h <= 0) if (w <= 0 || h <= 0)
return; return;
@ -136,20 +136,20 @@ void OSystem_SDL_Common::copy_rect(const byte *buf, int pitch, int x, int y, int
} }
/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */ /* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
if (_mouse_drawn) if (_mouseDrawn)
undraw_mouse(); undraw_mouse();
if (SDL_LockSurface(sdl_screen) == -1) if (SDL_LockSurface(_screen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError()); error("SDL_LockSurface failed: %s.\n", SDL_GetError());
byte *dst = (byte *)sdl_screen->pixels + y * SCREEN_WIDTH + x; byte *dst = (byte *)_screen->pixels + y * _screenWidth + x;
do { do {
memcpy(dst, buf, w); memcpy(dst, buf, w);
dst += SCREEN_WIDTH; dst += _screenWidth;
buf += pitch; buf += pitch;
} while (--h); } while (--h);
SDL_UnlockSurface(sdl_screen); SDL_UnlockSurface(_screen);
} }
@ -164,25 +164,25 @@ void OSystem_SDL_Common::move_screen(int dx, int dy, int height) {
// move down // move down
// copy from bottom to top // copy from bottom to top
for (int y = height - 1; y >= dy; y--) for (int y = height - 1; y >= dy; y--)
copy_rect((byte *)sdl_screen->pixels + SCREEN_WIDTH * (y - dy), SCREEN_WIDTH, 0, y, SCREEN_WIDTH, 1); copy_rect((byte *)_screen->pixels + _screenWidth * (y - dy), _screenWidth, 0, y, _screenWidth, 1);
} else { } else {
// move up // move up
// copy from top to bottom // copy from top to bottom
for (int y = 0; y < height + dx; y++) for (int y = 0; y < height + dx; y++)
copy_rect((byte *)sdl_screen->pixels + SCREEN_WIDTH * (y - dy), SCREEN_WIDTH, 0, y, SCREEN_WIDTH, 1); copy_rect((byte *)_screen->pixels + _screenWidth * (y - dy), _screenWidth, 0, y, _screenWidth, 1);
} }
} else if (dy == 0) { } else if (dy == 0) {
// horizontal movement // horizontal movement
if (dx > 0) { if (dx > 0) {
// move right // move right
// copy from right to left // copy from right to left
for (int x = SCREEN_WIDTH - 1; x >= dx; x--) for (int x = _screenWidth - 1; x >= dx; x--)
copy_rect((byte *)sdl_screen->pixels + x - dx, SCREEN_WIDTH, x, 0, 1, height); copy_rect((byte *)_screen->pixels + x - dx, _screenWidth, x, 0, 1, height);
} else { } else {
// move left // move left
// copy from left to right // copy from left to right
for (int x = 0; x < SCREEN_WIDTH; x++) for (int x = 0; x < _screenWidth; x++)
copy_rect((byte *)sdl_screen->pixels + x - dx, SCREEN_WIDTH, x, 0, 1, height); copy_rect((byte *)_screen->pixels + x - dx, _screenWidth, x, 0, 1, height);
} }
} else { } else {
// free movement // free movement
@ -191,16 +191,16 @@ void OSystem_SDL_Common::move_screen(int dx, int dy, int height) {
} }
void OSystem_SDL_Common::add_dirty_rect(int x, int y, int w, int h) { void OSystem_SDL_Common::add_dirty_rect(int x, int y, int w, int h) {
if (force_full) if (_forceFull)
return; return;
if (num_dirty_rects == NUM_DIRTY_RECT) if (_num_dirty_rects == NUM_DIRTY_RECT)
force_full = true; _forceFull = true;
else { else {
SDL_Rect *r = &_dirty_rect_list[num_dirty_rects++]; SDL_Rect *r = &_dirty_rect_list[_num_dirty_rects++];
/* Update the dirty region by 1 pixel for graphics drivers // Extend the dirty region by 1 pixel for scalers
* that "smear" the screen */ // that "smear" the screen, e.g. 2xSAI
if (_mode_flags & DF_UPDATE_EXPAND_1_PIXEL) { if (_mode_flags & DF_UPDATE_EXPAND_1_PIXEL) {
x--; x--;
y--; y--;
@ -208,11 +208,11 @@ void OSystem_SDL_Common::add_dirty_rect(int x, int y, int w, int h) {
h+=2; h+=2;
} }
/* clip */ // clip
if (x < 0) { w+=x; x=0; } if (x < 0) { w+=x; x=0; }
if (y < 0) { h+=y; y=0; } if (y < 0) { h+=y; y=0; }
if (w > SCREEN_WIDTH-x) { w = SCREEN_WIDTH - x; } if (w > _screenWidth-x) { w = _screenWidth - x; }
if (h > SCREEN_HEIGHT-y) { h = SCREEN_HEIGHT - y; } if (h > _screenHeight-y) { h = _screenHeight - y; }
r->x = x; r->x = x;
r->y = y; r->y = y;
@ -222,16 +222,16 @@ void OSystem_SDL_Common::add_dirty_rect(int x, int y, int w, int h) {
} }
#define ROL(a,n) a = (a<<(n)) | (a>>(32-(n))) #define ROL(a,n) a = (a<<(n)) | (a>>(32-(n)))
#define DOLINE(x) a ^= ((uint32*)buf)[0+(x)*(SCREEN_WIDTH/4)]; b ^= ((uint32*)buf)[1+(x)*(SCREEN_WIDTH/4)] #define DOLINE(x) a ^= ((uint32*)buf)[0+(x)*(_screenWidth/4)]; b ^= ((uint32*)buf)[1+(x)*(_screenWidth/4)]
void OSystem_SDL_Common::mk_checksums(const byte *buf) { void OSystem_SDL_Common::mk_checksums(const byte *buf) {
uint32 *sums = _dirty_checksums; uint32 *sums = _dirty_checksums;
uint x,y; uint x,y;
const uint last_x = (uint)SCREEN_WIDTH/8; const uint last_x = (uint)_screenWidth/8;
const uint last_y = (uint)SCREEN_HEIGHT/8; const uint last_y = (uint)_screenHeight/8;
/* the 8x8 blocks in buf are enumerated starting in the top left corner and /* the 8x8 blocks in buf are enumerated starting in the top left corner and
* reading each line at a time from left to right */ * reading each line at a time from left to right */
for(y=0; y != last_y; y++, buf+=SCREEN_WIDTH*(8-1)) for(y=0; y != last_y; y++, buf+=_screenWidth*(8-1))
for(x=0; x != last_x; x++, buf+=8) { for(x=0; x != last_x; x++, buf+=8) {
uint32 a = x; uint32 a = x;
uint32 b = y; uint32 b = y;
@ -264,19 +264,19 @@ void OSystem_SDL_Common::add_dirty_rgn_auto(const byte *buf) {
mk_checksums(buf); mk_checksums(buf);
if (!cksum_valid) { if (!cksum_valid) {
force_full = true; _forceFull = true;
cksum_valid = true; cksum_valid = true;
} }
/* go through the checksum list, compare it with the previous checksums, /* go through the checksum list, compare it with the previous checksums,
and add all dirty rectangles to a list. try to combine small rectangles and add all dirty rectangles to a list. try to combine small rectangles
into bigger ones in a simple way */ into bigger ones in a simple way */
if (!force_full) { if (!_forceFull) {
int x,y,w; int x,y,w;
uint32 *ck = _dirty_checksums; uint32 *ck = _dirty_checksums;
for(y=0; y!=SCREEN_HEIGHT/8; y++) { for(y=0; y!=_screenHeight/8; y++) {
for(x=0; x!=SCREEN_WIDTH/8; x++,ck++) { for(x=0; x!=_screenWidth/8; x++,ck++) {
if (ck[0] != ck[CKSUM_NUM]) { if (ck[0] != ck[CKSUM_NUM]) {
/* found a dirty 8x8 block, now go as far to the right as possible, /* found a dirty 8x8 block, now go as far to the right as possible,
and at the same time, unmark the dirty status by setting old to new. */ and at the same time, unmark the dirty status by setting old to new. */
@ -284,11 +284,11 @@ void OSystem_SDL_Common::add_dirty_rgn_auto(const byte *buf) {
do { do {
ck[w+CKSUM_NUM] = ck[w]; ck[w+CKSUM_NUM] = ck[w];
w++; w++;
} while (x+w != SCREEN_WIDTH/8 && ck[w] != ck[w+CKSUM_NUM]); } while (x+w != _screenWidth/8 && ck[w] != ck[w+CKSUM_NUM]);
add_dirty_rect(x*8, y*8, w*8, 8); add_dirty_rect(x*8, y*8, w*8, 8);
if (force_full) if (_forceFull)
goto get_out; goto get_out;
} }
} }
@ -370,11 +370,11 @@ void OSystem_SDL_Common::kbd_mouse() {
} }
bool OSystem_SDL_Common::show_mouse(bool visible) { bool OSystem_SDL_Common::show_mouse(bool visible) {
if (_mouse_visible == visible) if (_mouseVisible == visible)
return visible; return visible;
bool last = _mouse_visible; bool last = _mouseVisible;
_mouse_visible = visible; _mouseVisible = visible;
if (visible) if (visible)
draw_mouse(); draw_mouse();
@ -396,16 +396,16 @@ void OSystem_SDL_Common::set_mouse_cursor(const byte *buf, uint w, uint h, int h
_mouse_cur_state.w = w; _mouse_cur_state.w = w;
_mouse_cur_state.h = h; _mouse_cur_state.h = h;
_mouse_hotspot_x = hotspot_x; _mouseHotspotX = hotspot_x;
_mouse_hotspot_y = hotspot_y; _mouseHotspotY = hotspot_y;
_mouse_data = (byte*)buf; _mouseData = (byte*)buf;
undraw_mouse(); undraw_mouse();
} }
void OSystem_SDL_Common::set_shake_pos(int shake_pos) { void OSystem_SDL_Common::set_shake_pos(int shake_pos) {
_new_shake_pos = shake_pos; _newShakePos = shake_pos;
} }
uint32 OSystem_SDL_Common::get_msecs() { uint32 OSystem_SDL_Common::get_msecs() {
@ -581,8 +581,8 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
km.x = event->mouse.x = ev.motion.x; km.x = event->mouse.x = ev.motion.x;
km.y = event->mouse.y = ev.motion.y; km.y = event->mouse.y = ev.motion.y;
event->mouse.x /= scaling; event->mouse.x /= _scaleFactor;
event->mouse.y /= scaling; event->mouse.y /= _scaleFactor;
return true; return true;
@ -595,8 +595,8 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
break; break;
km.x = event->mouse.x = ev.motion.x; km.x = event->mouse.x = ev.motion.x;
km.y = event->mouse.y = ev.motion.y; km.y = event->mouse.y = ev.motion.y;
event->mouse.x /= scaling; event->mouse.x /= _scaleFactor;
event->mouse.y /= scaling; event->mouse.y /= _scaleFactor;
return true; return true;
@ -609,8 +609,8 @@ bool OSystem_SDL_Common::poll_event(Event *event) {
break; break;
event->mouse.x = ev.button.x; event->mouse.x = ev.button.x;
event->mouse.y = ev.button.y; event->mouse.y = ev.button.y;
event->mouse.x /= scaling; event->mouse.x /= _scaleFactor;
event->mouse.y /= scaling; event->mouse.y /= _scaleFactor;
return true; return true;
case SDL_QUIT: case SDL_QUIT:
@ -643,12 +643,12 @@ void OSystem_SDL_Common::get_320x200_image(byte *buf) {
/* make sure the mouse is gone */ /* make sure the mouse is gone */
undraw_mouse(); undraw_mouse();
if (SDL_LockSurface(sdl_screen) == -1) if (SDL_LockSurface(_screen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError()); error("SDL_LockSurface failed: %s.\n", SDL_GetError());
memcpy(buf, sdl_screen->pixels, SCREEN_WIDTH*SCREEN_HEIGHT); memcpy(buf, _screen->pixels, _screenWidth*_screenHeight);
SDL_UnlockSurface(sdl_screen); SDL_UnlockSurface(_screen);
} }
uint32 OSystem_SDL_Common::property(int param, Property *value) { uint32 OSystem_SDL_Common::property(int param, Property *value) {
@ -663,11 +663,11 @@ uint32 OSystem_SDL_Common::property(int param, Property *value) {
case PROP_OPEN_CD: case PROP_OPEN_CD:
if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1) if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
cdrom = NULL; _cdrom = NULL;
else { else {
cdrom = SDL_CDOpen(value->cd_num); _cdrom = SDL_CDOpen(value->cd_num);
/* Did if open? Check if cdrom is NULL */ /* Did if open? Check if _cdrom is NULL */
if (!cdrom) { if (!_cdrom) {
warning("Couldn't open drive: %s\n", SDL_GetError()); warning("Couldn't open drive: %s\n", SDL_GetError());
} }
} }
@ -694,25 +694,25 @@ uint32 OSystem_SDL_Common::property(int param, Property *value) {
} }
void OSystem_SDL_Common::quit() { void OSystem_SDL_Common::quit() {
if(cdrom) { if(_cdrom) {
SDL_CDStop(cdrom); SDL_CDStop(_cdrom);
SDL_CDClose(cdrom); SDL_CDClose(_cdrom);
} }
unload_gfx_mode(); unload_gfx_mode();
exit(0); exit(0);
} }
void OSystem_SDL_Common::draw_mouse() { void OSystem_SDL_Common::draw_mouse() {
if (_mouse_drawn || !_mouse_visible) if (_mouseDrawn || !_mouseVisible)
return; return;
int x = _mouse_cur_state.x - _mouse_hotspot_x; int x = _mouse_cur_state.x - _mouseHotspotX;
int y = _mouse_cur_state.y - _mouse_hotspot_y; int y = _mouse_cur_state.y - _mouseHotspotY;
int w = _mouse_cur_state.w; int w = _mouse_cur_state.w;
int h = _mouse_cur_state.h; int h = _mouse_cur_state.h;
byte color; byte color;
byte *src = _mouse_data; // Image representing the mouse byte *src = _mouseData; // Image representing the mouse
byte *bak = _mouse_backup; // Surface used to backup the area obscured by the mouse byte *bak = _mouseBackup; // Surface used to backup the area obscured by the mouse
byte *dst; // Surface we are drawing into byte *dst; // Surface we are drawing into
// clip the mouse rect, and addjust the src pointer accordingly // clip the mouse rect, and addjust the src pointer accordingly
@ -726,10 +726,14 @@ void OSystem_SDL_Common::draw_mouse() {
src -= y * _mouse_cur_state.w; src -= y * _mouse_cur_state.w;
y = 0; y = 0;
} }
if (w > SCREEN_WIDTH - x) if (w > _screenWidth - x)
w = SCREEN_WIDTH - x; w = _screenWidth - x;
if (h > SCREEN_HEIGHT - y) if (h > _screenHeight - y)
h = SCREEN_HEIGHT - y; h = _screenHeight - y;
// Quick check to see if anything has to be drawn at all
if (w <= 0 || h <= 0)
return;
// Store the bounding box so that undraw mouse can restore the area the // Store the bounding box so that undraw mouse can restore the area the
// mouse currently covers to its original content. // mouse currently covers to its original content.
@ -738,16 +742,12 @@ void OSystem_SDL_Common::draw_mouse() {
_mouse_old_state.w = w; _mouse_old_state.w = w;
_mouse_old_state.h = h; _mouse_old_state.h = h;
// Quick check to see if anything has to be drawn at all
if (w <= 0 || h <= 0)
return;
// Draw the mouse cursor; backup the covered area in "bak" // Draw the mouse cursor; backup the covered area in "bak"
if (SDL_LockSurface(sdl_screen) == -1) if (SDL_LockSurface(_screen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError()); error("SDL_LockSurface failed: %s.\n", SDL_GetError());
dst = (byte *)sdl_screen->pixels + y * SCREEN_WIDTH + x; dst = (byte *)_screen->pixels + y * _screenWidth + x;
while (h > 0) { while (h > 0) {
int width = w; int width = w;
while (width > 0) { while (width > 0) {
@ -760,38 +760,38 @@ void OSystem_SDL_Common::draw_mouse() {
} }
src += _mouse_cur_state.w - w; src += _mouse_cur_state.w - w;
bak += MAX_MOUSE_W - w; bak += MAX_MOUSE_W - w;
dst += SCREEN_WIDTH - w; dst += _screenWidth - w;
h--; h--;
} }
SDL_UnlockSurface(sdl_screen); SDL_UnlockSurface(_screen);
// Mark as dirty // Mark as dirty
add_dirty_rect(x, y, w, h); add_dirty_rect(x, y, w, h);
// Finally, set the flag to indicate the mouse has been drawn // Finally, set the flag to indicate the mouse has been drawn
_mouse_drawn = true; _mouseDrawn = true;
} }
void OSystem_SDL_Common::undraw_mouse() { void OSystem_SDL_Common::undraw_mouse() {
if (!_mouse_drawn) if (!_mouseDrawn)
return; return;
_mouse_drawn = false; _mouseDrawn = false;
if (SDL_LockSurface(sdl_screen) == -1) if (SDL_LockSurface(_screen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError()); error("SDL_LockSurface failed: %s.\n", SDL_GetError());
byte *dst, *bak = _mouse_backup; byte *dst, *bak = _mouseBackup;
const int old_mouse_x = _mouse_old_state.x; const int old_mouse_x = _mouse_old_state.x;
const int old_mouse_y = _mouse_old_state.y; const int old_mouse_y = _mouse_old_state.y;
const int old_mouse_w = _mouse_old_state.w; const int old_mouse_w = _mouse_old_state.w;
const int old_mouse_h = _mouse_old_state.h; const int old_mouse_h = _mouse_old_state.h;
int x,y; int x, y;
// No need to do clipping here, since draw_mouse() did that already // No need to do clipping here, since draw_mouse() did that already
dst = (byte *)sdl_screen->pixels + old_mouse_y * SCREEN_WIDTH + old_mouse_x; dst = (byte *)_screen->pixels + old_mouse_y * _screenWidth + old_mouse_x;
for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += SCREEN_WIDTH) { for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += _screenWidth) {
for (x = 0; x < old_mouse_w; ++x) { for (x = 0; x < old_mouse_w; ++x) {
dst[x] = bak[x]; dst[x] = bak[x];
} }
@ -799,7 +799,7 @@ void OSystem_SDL_Common::undraw_mouse() {
add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h); add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
SDL_UnlockSurface(sdl_screen); SDL_UnlockSurface(_screen);
} }
void OSystem_SDL_Common::stop_cdrom() { /* Stop CD Audio in 1/10th of a second */ void OSystem_SDL_Common::stop_cdrom() { /* Stop CD Audio in 1/10th of a second */
@ -812,7 +812,7 @@ void OSystem_SDL_Common::play_cdrom(int track, int num_loops, int start_frame, i
if (!num_loops && !start_frame) if (!num_loops && !start_frame)
return; return;
if (!cdrom) if (!_cdrom)
return; return;
if (end_frame > 0) if (end_frame > 0)
@ -822,26 +822,26 @@ void OSystem_SDL_Common::play_cdrom(int track, int num_loops, int start_frame, i
cd_num_loops = num_loops; cd_num_loops = num_loops;
cd_start_frame = start_frame; cd_start_frame = start_frame;
SDL_CDStatus(cdrom); SDL_CDStatus(_cdrom);
SDL_CDPlayTracks(cdrom, track, start_frame, 0, end_frame); SDL_CDPlayTracks(_cdrom, track, start_frame, 0, end_frame);
cd_end_frame = end_frame; cd_end_frame = end_frame;
cd_stop_time = 0; cd_stop_time = 0;
cd_end_time = SDL_GetTicks() + cdrom->track[track].length * 1000 / CD_FPS; cd_end_time = SDL_GetTicks() + _cdrom->track[track].length * 1000 / CD_FPS;
} }
bool OSystem_SDL_Common::poll_cdrom() { bool OSystem_SDL_Common::poll_cdrom() {
if (!cdrom) if (!_cdrom)
return false; return false;
return (cd_num_loops != 0 && (SDL_GetTicks() < cd_end_time || SDL_CDStatus(cdrom) != CD_STOPPED)); return (cd_num_loops != 0 && (SDL_GetTicks() < cd_end_time || SDL_CDStatus(_cdrom) != CD_STOPPED));
} }
void OSystem_SDL_Common::update_cdrom() { void OSystem_SDL_Common::update_cdrom() {
if (!cdrom) if (!_cdrom)
return; return;
if (cd_stop_time != 0 && SDL_GetTicks() >= cd_stop_time) { if (cd_stop_time != 0 && SDL_GetTicks() >= cd_stop_time) {
SDL_CDStop(cdrom); SDL_CDStop(_cdrom);
cd_num_loops = 0; cd_num_loops = 0;
cd_stop_time = 0; cd_stop_time = 0;
return; return;
@ -850,7 +850,7 @@ void OSystem_SDL_Common::update_cdrom() {
if (cd_num_loops == 0 || SDL_GetTicks() < cd_end_time) if (cd_num_loops == 0 || SDL_GetTicks() < cd_end_time)
return; return;
if (cd_num_loops != 1 && SDL_CDStatus(cdrom) != CD_STOPPED) { if (cd_num_loops != 1 && SDL_CDStatus(_cdrom) != CD_STOPPED) {
// Wait another second for it to be done // Wait another second for it to be done
cd_end_time += 1000; cd_end_time += 1000;
return; return;
@ -860,8 +860,8 @@ void OSystem_SDL_Common::update_cdrom() {
cd_num_loops--; cd_num_loops--;
if (cd_num_loops != 0) { if (cd_num_loops != 0) {
SDL_CDPlayTracks(cdrom, cd_track, cd_start_frame, 0, cd_end_frame); SDL_CDPlayTracks(_cdrom, cd_track, cd_start_frame, 0, cd_end_frame);
cd_end_time = SDL_GetTicks() + cdrom->track[cd_track].length * 1000 / CD_FPS; cd_end_time = SDL_GetTicks() + _cdrom->track[cd_track].length * 1000 / CD_FPS;
} }
} }

View file

@ -75,17 +75,17 @@ public:
// Set function that generates samples // Set function that generates samples
bool set_sound_proc(void *param, SoundProc *proc, byte sound); bool set_sound_proc(void *param, SoundProc *proc, byte sound);
// Poll cdrom status // Poll CD status
// Returns true if cd audio is playing // Returns true if cd audio is playing
bool poll_cdrom(); bool poll_cdrom();
// Play cdrom audio track // Play CD audio track
void play_cdrom(int track, int num_loops, int start_frame, int end_frame); void play_cdrom(int track, int num_loops, int start_frame, int end_frame);
// Stop cdrom audio track // Stop CD audio track
void stop_cdrom(); void stop_cdrom();
// Update cdrom audio status // Update CD audio status
void update_cdrom(); void update_cdrom();
// Quit // Quit
@ -107,23 +107,29 @@ public:
protected: protected:
SDL_Surface *sdl_screen; // unseen game screen OSystem_SDL_Common();
SDL_CD *cdrom; virtual ~OSystem_SDL_Common();
// unseen game screen
SDL_Surface *_screen;
int _screenWidth, _screenHeight;
// CD Audio
SDL_CD *_cdrom;
int cd_track, cd_num_loops, cd_start_frame, cd_end_frame;
Uint32 cd_end_time, cd_stop_time, cd_next_second;
enum { enum {
DF_WANT_RECT_OPTIM = 1 << 0, DF_WANT_RECT_OPTIM = 1 << 0,
DF_UPDATE_EXPAND_1_PIXEL = 1 << 3 DF_UPDATE_EXPAND_1_PIXEL = 1 << 3
}; };
bool _forceFull; // Force full redraw on next update_screen
int _scaleFactor;
int _mode; int _mode;
bool _full_screen; bool _full_screen;
bool _mouse_visible;
bool _mouse_drawn;
uint32 _mode_flags; uint32 _mode_flags;
bool force_full; //Force full redraw on next update_screen
bool cksum_valid;
enum { enum {
NUM_DIRTY_RECT = 100, NUM_DIRTY_RECT = 100,
@ -132,18 +138,14 @@ protected:
MAX_SCALING = 3 MAX_SCALING = 3
}; };
int SCREEN_WIDTH, SCREEN_HEIGHT, CKSUM_NUM; // Dirty rect managment
SDL_Rect _dirty_rect_list[100]; SDL_Rect _dirty_rect_list[100];
int num_dirty_rects; int _num_dirty_rects;
uint32 *_dirty_checksums; uint32 *_dirty_checksums;
bool cksum_valid;
int CKSUM_NUM;
int scaling; // Keyboard mouse emulation
/* CD Audio */
int cd_track, cd_num_loops, cd_start_frame, cd_end_frame;
Uint32 cd_end_time, cd_stop_time, cd_next_second;
/* Keyboard mouse emulation */
struct KbdMouse { struct KbdMouse {
int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count; int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count;
uint32 last_time, delay_time, x_down_time, y_down_time; uint32 last_time, delay_time, x_down_time, y_down_time;
@ -153,20 +155,23 @@ protected:
int16 x, y, w, h; int16 x, y, w, h;
}; };
byte *_mouse_data; bool _mouseVisible;
byte *_mouse_backup; bool _mouseDrawn;
byte *_mouseData;
byte *_mouseBackup;
MousePos _mouse_cur_state; MousePos _mouse_cur_state;
MousePos _mouse_old_state; MousePos _mouse_old_state;
int16 _mouse_hotspot_x; int16 _mouseHotspotX;
int16 _mouse_hotspot_y; int16 _mouseHotspotY;
int _current_shake_pos;
int _new_shake_pos;
SDL_Color *_cur_pal;
uint _palette_changed_first, _palette_changed_last; // Shake mode
int _currentShakePos;
int _newShakePos;
// Palette data
SDL_Color *_currentPalette;
uint _paletteDirtyStart, _paletteDirtyEnd;
OSystem_SDL_Common();
virtual ~OSystem_SDL_Common();
void add_dirty_rgn_auto(const byte *buf); void add_dirty_rgn_auto(const byte *buf);
void mk_checksums(const byte *buf); void mk_checksums(const byte *buf);

View file

@ -72,7 +72,7 @@ OSystem_SDL_Common *OSystem_SDL_Common::create() {
void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) { void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) {
const byte *b = colors; const byte *b = colors;
uint i; uint i;
SDL_Color *base = _cur_pal + start; SDL_Color *base = _currentPalette + start;
for(i = 0; i < num; i++) { for(i = 0; i < num; i++) {
base[i].r = b[0]; base[i].r = b[0];
base[i].g = b[1]; base[i].g = b[1];
@ -80,11 +80,11 @@ void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) {
b += 4; b += 4;
} }
if (start < _palette_changed_first) if (start < _paletteDirtyStart)
_palette_changed_first = start; _paletteDirtyStart = start;
if (start + num > _palette_changed_last) if (start + num > _paletteDirtyEnd)
_palette_changed_last = start + num; _paletteDirtyEnd = start + num;
} }
void OSystem_SDL_Normal::draw_mouse() { void OSystem_SDL_Normal::draw_mouse() {
@ -92,17 +92,16 @@ void OSystem_SDL_Normal::draw_mouse() {
OSystem_SDL_Common::draw_mouse(); OSystem_SDL_Common::draw_mouse();
} }
if (_mouseDrawn || !_mouseVisible)
if (_mouse_drawn || !_mouse_visible)
return; return;
int x = _mouse_cur_state.x - _mouse_hotspot_x; int x = _mouse_cur_state.x - _mouseHotspotX;
int y = _mouse_cur_state.y - _mouse_hotspot_y; int y = _mouse_cur_state.y - _mouseHotspotY;
int w = _mouse_cur_state.w; int w = _mouse_cur_state.w;
int h = _mouse_cur_state.h; int h = _mouse_cur_state.h;
byte color; byte color;
byte *src = _mouse_data; // Image representing the mouse byte *src = _mouseData; // Image representing the mouse
uint16 *bak = (uint16*)_mouse_backup; // Surface used to backup the area obscured by the mouse uint16 *bak = (uint16*)_mouseBackup; // Surface used to backup the area obscured by the mouse
uint16 *dst; // Surface we are drawing into uint16 *dst; // Surface we are drawing into
// clip the mouse rect, and addjust the src pointer accordingly // clip the mouse rect, and addjust the src pointer accordingly
@ -116,14 +115,15 @@ void OSystem_SDL_Normal::draw_mouse() {
src -= y * _mouse_cur_state.w; src -= y * _mouse_cur_state.w;
y = 0; y = 0;
} }
if (w > SCREEN_WIDTH - x)
w = SCREEN_WIDTH - x;
if (h > SCREEN_HEIGHT - y)
h = SCREEN_HEIGHT - y;
// Adjust for tmp_screen offset // Quick check to see if anything has to be drawn at all
x++; if (w <= 0 || h <= 0)
y++; return;
if (w > _screenWidth - x)
w = _screenWidth - x;
if (h > _screenHeight - y)
h = _screenHeight - y;
// Store the bounding box so that undraw mouse can restore the area the // Store the bounding box so that undraw mouse can restore the area the
// mouse currently covers to its original content. // mouse currently covers to its original content.
@ -132,23 +132,19 @@ void OSystem_SDL_Normal::draw_mouse() {
_mouse_old_state.w = w; _mouse_old_state.w = w;
_mouse_old_state.h = h; _mouse_old_state.h = h;
// Quick check to see if anything has to be drawn at all
if (w <= 0 || h <= 0)
return;
// Draw the mouse cursor; backup the covered area in "bak" // Draw the mouse cursor; backup the covered area in "bak"
if (SDL_LockSurface(sdl_tmpscreen) == -1) if (SDL_LockSurface(sdl_tmpscreen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError()); error("SDL_LockSurface failed: %s.\n", SDL_GetError());
dst = (uint16 *)sdl_tmpscreen->pixels + y * TMP_SCREEN_WIDTH + x; dst = (uint16 *)sdl_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1);
while (h > 0) { while (h > 0) {
int width = w; int width = w;
while (width > 0) { while (width > 0) {
*bak++ = *dst; *bak++ = *dst;
color = *src++; color = *src++;
if (color != 0xFF) // 0xFF = transparent, don't draw if (color != 0xFF) // 0xFF = transparent, don't draw
*dst = RGB_TO_16(_cur_pal[color].r, _cur_pal[color].g, _cur_pal[color].b); *dst = RGB_TO_16(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b);
dst++; dst++;
width--; width--;
} }
@ -161,10 +157,10 @@ void OSystem_SDL_Normal::draw_mouse() {
SDL_UnlockSurface(sdl_tmpscreen); SDL_UnlockSurface(sdl_tmpscreen);
// Mark as dirty // Mark as dirty
add_dirty_rect(x-1, y-1, w, h); add_dirty_rect(x, y, w, h);
// Finally, set the flag to indicate the mouse has been drawn // Finally, set the flag to indicate the mouse has been drawn
_mouse_drawn = true; _mouseDrawn = true;
} }
void OSystem_SDL_Normal::undraw_mouse() { void OSystem_SDL_Normal::undraw_mouse() {
@ -172,65 +168,64 @@ void OSystem_SDL_Normal::undraw_mouse() {
OSystem_SDL_Common::undraw_mouse(); OSystem_SDL_Common::undraw_mouse();
} }
if (!_mouseDrawn)
if (!_mouse_drawn)
return; return;
_mouse_drawn = false; _mouseDrawn = false;
uint16 *dst, *bak = (uint16 *)_mouse_backup;
const int old_mouse_x = _mouse_old_state.x;
const int old_mouse_y = _mouse_old_state.y;
const int old_mouse_w = _mouse_old_state.w;
const int old_mouse_h = _mouse_old_state.h;
int x,y;
if (SDL_LockSurface(sdl_tmpscreen) == -1) if (SDL_LockSurface(sdl_tmpscreen) == -1)
error("SDL_LockSurface failed: %s.\n", SDL_GetError()); error("SDL_LockSurface failed: %s.\n", SDL_GetError());
uint16 *dst, *bak = (uint16 *)_mouseBackup;
const int old_mouse_x = _mouse_old_state.x;
const int old_mouse_y = _mouse_old_state.y;
const int old_mouse_w = _mouse_old_state.w;
const int old_mouse_h = _mouse_old_state.h;
int x, y;
// No need to do clipping here, since draw_mouse() did that already // No need to do clipping here, since draw_mouse() did that already
dst = (uint16 *)sdl_tmpscreen->pixels + old_mouse_y * TMP_SCREEN_WIDTH + old_mouse_x; dst = (uint16 *)sdl_tmpscreen->pixels + (old_mouse_y+1) * TMP_SCREEN_WIDTH + (old_mouse_x+1);
for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += TMP_SCREEN_WIDTH) { for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += TMP_SCREEN_WIDTH) {
for (x = 0; x < old_mouse_w; ++x) { for (x = 0; x < old_mouse_w; ++x) {
dst[x] = bak[x]; dst[x] = bak[x];
} }
} }
add_dirty_rect(old_mouse_x-1, old_mouse_y-1, old_mouse_w, old_mouse_h); add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
SDL_UnlockSurface(sdl_tmpscreen); SDL_UnlockSurface(sdl_tmpscreen);
} }
void OSystem_SDL_Normal::load_gfx_mode() { void OSystem_SDL_Normal::load_gfx_mode() {
force_full = true; _forceFull = true;
scaling = 1; _scaleFactor = 1;
_mode_flags = 0; _mode_flags = 0;
_overlay_visible = false; _overlay_visible = false;
_scaler_proc = NULL; _scaler_proc = NULL;
sdl_tmpscreen = NULL; sdl_tmpscreen = NULL;
TMP_SCREEN_WIDTH = (SCREEN_WIDTH + 3); TMP_SCREEN_WIDTH = (_screenWidth + 3);
switch(_mode) { switch(_mode) {
case GFX_2XSAI: case GFX_2XSAI:
scaling = 2; _scaleFactor = 2;
_scaler_proc = _2xSaI; _scaler_proc = _2xSaI;
break; break;
case GFX_SUPER2XSAI: case GFX_SUPER2XSAI:
scaling = 2; _scaleFactor = 2;
_scaler_proc = Super2xSaI; _scaler_proc = Super2xSaI;
break; break;
case GFX_SUPEREAGLE: case GFX_SUPEREAGLE:
scaling = 2; _scaleFactor = 2;
_scaler_proc = SuperEagle; _scaler_proc = SuperEagle;
break; break;
case GFX_ADVMAME2X: case GFX_ADVMAME2X:
scaling = 2; _scaleFactor = 2;
_scaler_proc = AdvMame2x; _scaler_proc = AdvMame2x;
break; break;
case GFX_DOUBLESIZE: case GFX_DOUBLESIZE:
scaling = 2; _scaleFactor = 2;
_scaler_proc = Normal2x; _scaler_proc = Normal2x;
break; break;
@ -239,25 +234,25 @@ void OSystem_SDL_Normal::load_gfx_mode() {
warning("full screen in useless in triplesize mode, reverting to normal mode"); warning("full screen in useless in triplesize mode, reverting to normal mode");
goto normal_mode; goto normal_mode;
} }
scaling = 3; _scaleFactor = 3;
_scaler_proc = Normal3x; _scaler_proc = Normal3x;
break; break;
case GFX_NORMAL: case GFX_NORMAL:
normal_mode:; normal_mode:;
scaling = 1; _scaleFactor = 1;
_scaler_proc = Normal1x; _scaler_proc = Normal1x;
break; break;
} }
sdl_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, 8, 0, 0, 0, 0); _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth, _screenHeight, 8, 0, 0, 0, 0);
if (sdl_screen == NULL) if (_screen == NULL)
error("sdl_screen failed failed"); error("_screen failed failed");
uint16 *tmp_screen = (uint16*)calloc(TMP_SCREEN_WIDTH*(SCREEN_HEIGHT+3),sizeof(uint16)); uint16 *tmp_screen = (uint16*)calloc(TMP_SCREEN_WIDTH*(_screenHeight+3),sizeof(uint16));
_mode_flags = DF_WANT_RECT_OPTIM | DF_UPDATE_EXPAND_1_PIXEL; _mode_flags = DF_WANT_RECT_OPTIM | DF_UPDATE_EXPAND_1_PIXEL;
sdl_hwscreen = SDL_SetVideoMode(SCREEN_WIDTH * scaling, SCREEN_HEIGHT * scaling, 16, sdl_hwscreen = SDL_SetVideoMode(_screenWidth * _scaleFactor, _screenHeight * _scaleFactor, 16,
_full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE _full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
); );
if (sdl_hwscreen == NULL) if (sdl_hwscreen == NULL)
@ -269,7 +264,7 @@ normal_mode:;
else else
Init_2xSaI(565); Init_2xSaI(565);
sdl_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen, sdl_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
TMP_SCREEN_WIDTH, SCREEN_HEIGHT + 3, 16, TMP_SCREEN_WIDTH*2, TMP_SCREEN_WIDTH, _screenHeight + 3, 16, TMP_SCREEN_WIDTH*2,
sdl_hwscreen->format->Rmask, sdl_hwscreen->format->Rmask,
sdl_hwscreen->format->Gmask, sdl_hwscreen->format->Gmask,
sdl_hwscreen->format->Bmask, sdl_hwscreen->format->Bmask,
@ -279,17 +274,17 @@ normal_mode:;
error("sdl_tmpscreen failed"); error("sdl_tmpscreen failed");
// keyboard cursor control, some other better place for it? // keyboard cursor control, some other better place for it?
km.x_max = SCREEN_WIDTH * scaling - 1; km.x_max = _screenWidth * _scaleFactor - 1;
km.y_max = SCREEN_HEIGHT * scaling - 1; km.y_max = _screenHeight * _scaleFactor - 1;
km.delay_time = 25; km.delay_time = 25;
km.last_time = 0; km.last_time = 0;
} }
void OSystem_SDL_Normal::unload_gfx_mode() { void OSystem_SDL_Normal::unload_gfx_mode() {
if (sdl_screen) { if (_screen) {
SDL_FreeSurface(sdl_screen); SDL_FreeSurface(_screen);
sdl_screen = NULL; _screen = NULL;
} }
if (sdl_hwscreen) { if (sdl_hwscreen) {
@ -314,52 +309,52 @@ void OSystem_SDL_Normal::update_screen() {
// Check whether the palette was changed in the meantime and update the // Check whether the palette was changed in the meantime and update the
// screen surface accordingly. // screen surface accordingly.
if (_palette_changed_last != 0) { if (_paletteDirtyEnd != 0) {
SDL_SetColors(sdl_screen, _cur_pal + _palette_changed_first, SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart,
_palette_changed_first, _paletteDirtyStart,
_palette_changed_last - _palette_changed_first); _paletteDirtyEnd - _paletteDirtyStart);
_palette_changed_last = 0; _paletteDirtyEnd = 0;
force_full = true; _forceFull = true;
} }
/* If the shake position changed, fill the dirty area with blackness */ /* If the shake position changed, fill the dirty area with blackness */
if (_current_shake_pos != _new_shake_pos) { if (_currentShakePos != _newShakePos) {
SDL_Rect blackrect = {0, 0, SCREEN_WIDTH*scaling, _new_shake_pos*scaling}; SDL_Rect blackrect = {0, 0, _screenWidth*_scaleFactor, _newShakePos*_scaleFactor};
SDL_FillRect(sdl_hwscreen, &blackrect, 0); SDL_FillRect(sdl_hwscreen, &blackrect, 0);
_current_shake_pos = _new_shake_pos; _currentShakePos = _newShakePos;
force_full = true; _forceFull = true;
} }
// Force a full redraw if requested // Force a full redraw if requested
if (force_full) { if (_forceFull) {
num_dirty_rects = 1; _num_dirty_rects = 1;
_dirty_rect_list[0].x = 0; _dirty_rect_list[0].x = 0;
_dirty_rect_list[0].y = 0; _dirty_rect_list[0].y = 0;
_dirty_rect_list[0].w = SCREEN_WIDTH; _dirty_rect_list[0].w = _screenWidth;
_dirty_rect_list[0].h = SCREEN_HEIGHT; _dirty_rect_list[0].h = _screenHeight;
} }
// Only draw anything if necessary // Only draw anything if necessary
if (num_dirty_rects > 0) { if (_num_dirty_rects > 0) {
SDL_Rect *r; SDL_Rect *r;
uint32 srcPitch, dstPitch; uint32 srcPitch, dstPitch;
SDL_Rect *last_rect = _dirty_rect_list + num_dirty_rects; SDL_Rect *last_rect = _dirty_rect_list + _num_dirty_rects;
// Convert appropriate parts of the 8bpp image into 16bpp // Convert appropriate parts of the 8bpp image into 16bpp
if (!_overlay_visible) { if (!_overlay_visible) {
SDL_Rect dst; SDL_Rect dst;
for(r=_dirty_rect_list; r!=last_rect; ++r) { for(r = _dirty_rect_list; r != last_rect; ++r) {
dst = *r; dst = *r;
dst.x++; // Shift rect by one since 2xSai needs to acces the data around dst.x++; // Shift rect by one since 2xSai needs to acces the data around
dst.y++; // any pixel to scale it, and we want to avoid mem access crashes. dst.y++; // any pixel to scale it, and we want to avoid mem access crashes.
if (SDL_BlitSurface(sdl_screen, r, sdl_tmpscreen, &dst) != 0) if (SDL_BlitSurface(_screen, r, sdl_tmpscreen, &dst) != 0)
error("SDL_BlitSurface failed: %s", SDL_GetError()); error("SDL_BlitSurface failed: %s", SDL_GetError());
} }
} }
@ -370,42 +365,35 @@ void OSystem_SDL_Normal::update_screen() {
srcPitch = sdl_tmpscreen->pitch; srcPitch = sdl_tmpscreen->pitch;
dstPitch = sdl_hwscreen->pitch; dstPitch = sdl_hwscreen->pitch;
for(r=_dirty_rect_list; r!=last_rect; ++r) { for(r = _dirty_rect_list; r != last_rect; ++r) {
register int dst_y = r->y + _current_shake_pos; register int dst_y = r->y + _currentShakePos;
register int dst_h = 0; register int dst_h = 0;
if (dst_y < SCREEN_HEIGHT) { if (dst_y < _screenHeight) {
dst_h = r->h; dst_h = r->h;
if (dst_h > SCREEN_HEIGHT - dst_y) if (dst_h > _screenHeight - dst_y)
dst_h = SCREEN_HEIGHT - dst_y; dst_h = _screenHeight - dst_y;
dst_y *= scaling; dst_y *= _scaleFactor;
_scaler_proc((byte*)sdl_tmpscreen->pixels + (r->x*2+2) + (r->y+1)*srcPitch, srcPitch, NULL, _scaler_proc((byte*)sdl_tmpscreen->pixels + (r->x*2+2) + (r->y+1)*srcPitch, srcPitch, NULL,
(byte*)sdl_hwscreen->pixels + r->x*2*scaling + dst_y*dstPitch, dstPitch, r->w, dst_h); (byte*)sdl_hwscreen->pixels + r->x*2*_scaleFactor + dst_y*dstPitch, dstPitch, r->w, dst_h);
} }
r->x *= scaling; r->x *= _scaleFactor;
r->y = dst_y; r->y = dst_y;
r->w *= scaling; r->w *= _scaleFactor;
r->h = dst_h * scaling; r->h = dst_h * _scaleFactor;
}
if (force_full) {
_dirty_rect_list[0].y = 0;
_dirty_rect_list[0].h = SCREEN_HEIGHT * scaling;
} }
SDL_UnlockSurface(sdl_tmpscreen); SDL_UnlockSurface(sdl_tmpscreen);
SDL_UnlockSurface(sdl_hwscreen); SDL_UnlockSurface(sdl_hwscreen);
}
// Finally, blit all our changes to the screen
if (num_dirty_rects > 0) { SDL_UpdateRects(sdl_hwscreen, _num_dirty_rects, _dirty_rect_list);
/* Finally, blit all our changes to the screen */
SDL_UpdateRects(sdl_hwscreen, num_dirty_rects, _dirty_rect_list);
} }
num_dirty_rects = 0; _num_dirty_rects = 0;
force_full = false; _forceFull = false;
} }
void OSystem_SDL_Normal::hotswap_gfx_mode() { void OSystem_SDL_Normal::hotswap_gfx_mode() {
@ -414,20 +402,20 @@ void OSystem_SDL_Normal::hotswap_gfx_mode() {
* then draw that to the new screen right after it's setup. * then draw that to the new screen right after it's setup.
*/ */
byte *bak_mem = (byte*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT); byte *bak_mem = (byte*)malloc(_screenWidth*_screenHeight);
get_320x200_image(bak_mem); get_320x200_image(bak_mem);
unload_gfx_mode(); unload_gfx_mode();
load_gfx_mode(); load_gfx_mode();
force_full = true; _forceFull = true;
// reset palette // reset palette
SDL_SetColors(sdl_screen, _cur_pal, 0, 256); SDL_SetColors(_screen, _currentPalette, 0, 256);
// blit image // blit image
OSystem_SDL_Normal::copy_rect(bak_mem, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); OSystem_SDL_Normal::copy_rect(bak_mem, _screenWidth, 0, 0, _screenWidth, _screenHeight);
free(bak_mem); free(bak_mem);
OSystem_SDL_Normal::update_screen(); OSystem_SDL_Normal::update_screen();
@ -460,8 +448,11 @@ void OSystem_SDL_Normal::show_overlay()
void OSystem_SDL_Normal::hide_overlay() void OSystem_SDL_Normal::hide_overlay()
{ {
// hide the mouse
undraw_mouse();
_overlay_visible = false; _overlay_visible = false;
force_full = true; _forceFull = true;
} }
void OSystem_SDL_Normal::clear_overlay() void OSystem_SDL_Normal::clear_overlay()
@ -476,12 +467,12 @@ void OSystem_SDL_Normal::clear_overlay()
SDL_Rect src, dst; SDL_Rect src, dst;
src.x = src.y = 0; src.x = src.y = 0;
dst.x = dst.y = 1; dst.x = dst.y = 1;
src.w = dst.w = SCREEN_WIDTH; src.w = dst.w = _screenWidth;
src.h = dst.h = SCREEN_HEIGHT; src.h = dst.h = _screenHeight;
if (SDL_BlitSurface(sdl_screen, &src, sdl_tmpscreen, &dst) != 0) if (SDL_BlitSurface(_screen, &src, sdl_tmpscreen, &dst) != 0)
error("SDL_BlitSurface failed: %s", SDL_GetError()); error("SDL_BlitSurface failed: %s", SDL_GetError());
force_full = true; _forceFull = true;
} }
void OSystem_SDL_Normal::grab_overlay(int16 *buf, int pitch) void OSystem_SDL_Normal::grab_overlay(int16 *buf, int pitch)
@ -499,9 +490,9 @@ void OSystem_SDL_Normal::grab_overlay(int16 *buf, int pitch)
error("SDL_LockSurface failed: %s.\n", SDL_GetError()); error("SDL_LockSurface failed: %s.\n", SDL_GetError());
int16 *src = (int16 *)sdl_tmpscreen->pixels + TMP_SCREEN_WIDTH + 1; int16 *src = (int16 *)sdl_tmpscreen->pixels + TMP_SCREEN_WIDTH + 1;
int h = SCREEN_HEIGHT; int h = _screenHeight;
do { do {
memcpy(buf, src, SCREEN_WIDTH*2); memcpy(buf, src, _screenWidth*2);
src += TMP_SCREEN_WIDTH; src += TMP_SCREEN_WIDTH;
buf += pitch; buf += pitch;
} while (--h); } while (--h);
@ -520,8 +511,8 @@ void OSystem_SDL_Normal::copy_rect_overlay(const int16 *buf, int pitch, int x, i
// Clip the coordinates // Clip the coordinates
if (x < 0) { w+=x; buf-=x; x = 0; } if (x < 0) { w+=x; buf-=x; x = 0; }
if (y < 0) { h+=y; buf-=y*pitch; y = 0; } if (y < 0) { h+=y; buf-=y*pitch; y = 0; }
if (w > SCREEN_WIDTH-x) { w = SCREEN_WIDTH - x; } if (w > _screenWidth-x) { w = _screenWidth - x; }
if (h > SCREEN_HEIGHT-y) { h = SCREEN_HEIGHT - y; } if (h > _screenHeight-y) { h = _screenHeight - y; }
if (w <= 0 || h <= 0) if (w <= 0 || h <= 0)
return; return;

View file

@ -75,22 +75,22 @@ void OSystem_SDL_GL::set_palette(const byte *colors, uint start, uint num) {
b += 4; b += 4;
} }
if (start < _palette_changed_first) if (start < _paletteDirtyStart)
_palette_changed_first = start; _paletteDirtyStart = start;
if (start + num > _palette_changed_last) if (start + num > _paletteDirtyEnd)
_palette_changed_last = start + num; _paletteDirtyEnd = start + num;
} }
void OSystem_SDL_GL::load_gfx_mode() { void OSystem_SDL_GL::load_gfx_mode() {
int gl_flags = FB2GL_320 | FB2GL_PITCH; int gl_flags = FB2GL_320 | FB2GL_PITCH;
force_full = true; _forceFull = true;
scaling = 2; _scaleFactor = 2;
_mode_flags = 0; _mode_flags = 0;
sdl_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, 8, 0, 0, 0, 0); _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth, _screenHeight, 8, 0, 0, 0, 0);
if (sdl_screen == NULL) if (_screen == NULL)
error("sdl_screen failed failed"); error("_screen failed failed");
_mode_flags = DF_WANT_RECT_OPTIM; _mode_flags = DF_WANT_RECT_OPTIM;
@ -111,9 +111,9 @@ void OSystem_SDL_GL::load_gfx_mode() {
} }
void OSystem_SDL_GL::unload_gfx_mode() { void OSystem_SDL_GL::unload_gfx_mode() {
if (sdl_screen) { if (_screen) {
SDL_FreeSurface(sdl_screen); SDL_FreeSurface(_screen);
sdl_screen = NULL; _screen = NULL;
} }
} }
@ -123,9 +123,9 @@ void OSystem_SDL_GL::update_screen() {
draw_mouse(); draw_mouse();
/* If the shake position changed, fill the dirty area with blackness */ /* If the shake position changed, fill the dirty area with blackness */
if (_current_shake_pos != _new_shake_pos) { if (_currentShakePos != _newShakePos) {
_current_shake_pos = _new_shake_pos; _currentShakePos = _newShakePos;
} }
@ -134,15 +134,15 @@ void OSystem_SDL_GL::update_screen() {
* "real" 8bit mode, palatte changes may be visible immediatly, * "real" 8bit mode, palatte changes may be visible immediatly,
* and we want to avoid any ugly effects. * and we want to avoid any ugly effects.
*/ */
if (_palette_changed_last != 0) { if (_paletteDirtyEnd != 0) {
fb2gl.setPalette(_palette_changed_first, fb2gl.setPalette(_paletteDirtyStart,
_palette_changed_last - _palette_changed_first); _paletteDirtyEnd - _paletteDirtyStart);
_palette_changed_last = 0; _paletteDirtyEnd = 0;
} }
// FIXME - this seems to be tied to 320x200 - what about Zak256 which needs 320x240 ? // FIXME - this seems to be tied to 320x200 - what about Zak256 which needs 320x240 ?
fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos); fb2gl.update(_screen->pixels,320,200,320,0,_currentShakePos);
} }
@ -152,7 +152,7 @@ void OSystem_SDL_GL::hotswap_gfx_mode() {
* then draw that to the new screen right after it's setup. * then draw that to the new screen right after it's setup.
*/ */
byte *bak_mem = (byte*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT); byte *bak_mem = (byte*)malloc(_screenWidth*_screenHeight);
get_320x200_image(bak_mem); get_320x200_image(bak_mem);
@ -160,10 +160,10 @@ void OSystem_SDL_GL::hotswap_gfx_mode() {
load_gfx_mode(); load_gfx_mode();
fb2gl.setPalette(0,256); fb2gl.setPalette(0,256);
fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos); fb2gl.update(_screen->pixels,320,200,320,0,_currentShakePos);
/* blit image */ /* blit image */
copy_rect(bak_mem, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); copy_rect(bak_mem, _screenWidth, 0, 0, _screenWidth, _screenHeight);
free(bak_mem); free(bak_mem);
update_screen(); update_screen();

View file

@ -75,8 +75,7 @@ static byte guifont[] = {
}; };
// Constructor // Constructor
NewGui::NewGui(OSystem *system) : _system(system), _screen(0), NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false),
_use_alpha_blending(true), _need_redraw(false),
_currentKeyDown(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0) _currentKeyDown(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0)
{ {
// Setup some default GUI colors. // Setup some default GUI colors.
@ -113,14 +112,14 @@ void NewGui::runLoop()
activeDialog->handleTickle(); activeDialog->handleTickle();
if (_need_redraw) { if (_needRedraw) {
// Restore the overlay to its initial state, then draw all dialogs. // Restore the overlay to its initial state, then draw all dialogs.
// This is necessary to get the blending right. // This is necessary to get the blending right.
_system->clear_overlay(); _system->clear_overlay();
_system->grab_overlay(_screen, _screen_pitch); _system->grab_overlay(_screen, _screenPitch);
for (i = 0; i < _dialogStack.size(); i++) for (i = 0; i < _dialogStack.size(); i++)
_dialogStack[i]->draw(); _dialogStack[i]->draw();
_need_redraw = false; _needRedraw = false;
} }
animateCursor(); animateCursor();
@ -205,10 +204,10 @@ void NewGui::saveState()
_system->show_overlay(); _system->show_overlay();
// TODO - add getHeight & getWidth methods to OSystem. // TODO - add getHeight & getWidth methods to OSystem.
_screen = new int16[320 * 240]; _screen = new int16[320 * 240];
_screen_pitch = 320; _screenPitch = 320;
// _screen = new int16[_system->get_width() * _system->get_height()]; // _screen = new int16[_system->get_width() * _system->get_height()];
// _screen_pitch = _system->get_width(); // _screenPitch = _system->get_width();
_system->grab_overlay(_screen, _screen_pitch); _system->grab_overlay(_screen, _screenPitch);
} }
void NewGui::restoreState() void NewGui::restoreState()
@ -227,7 +226,7 @@ void NewGui::restoreState()
void NewGui::openDialog(Dialog *dialog) void NewGui::openDialog(Dialog *dialog)
{ {
_dialogStack.push(dialog); _dialogStack.push(dialog);
_need_redraw = true; _needRedraw = true;
} }
void NewGui::closeTopDialog() void NewGui::closeTopDialog()
@ -238,7 +237,7 @@ void NewGui::closeTopDialog()
// Remove the dialog from the stack // Remove the dialog from the stack
_dialogStack.pop(); _dialogStack.pop();
_need_redraw = true; _needRedraw = true;
} }
@ -247,7 +246,7 @@ void NewGui::closeTopDialog()
int16 *NewGui::getBasePtr(int x, int y) int16 *NewGui::getBasePtr(int x, int y)
{ {
return _screen + x + y * _screen_pitch; return _screen + x + y * _screenPitch;
} }
void NewGui::box(int x, int y, int width, int height) void NewGui::box(int x, int y, int width, int height)
@ -282,7 +281,7 @@ void NewGui::line(int x, int y, int x2, int y2, int16 color)
/* vertical line */ /* vertical line */
while (y++ <= y2) { while (y++ <= y2) {
*ptr = color; *ptr = color;
ptr += _screen_pitch; ptr += _screenPitch;
} }
} else if (y == y2) { } else if (y == y2) {
/* horizontal line */ /* horizontal line */
@ -307,7 +306,7 @@ void NewGui::blendRect(int x, int y, int w, int h, int16 color)
(GREEN_FROM_16(ptr[i])+g)/4, (GREEN_FROM_16(ptr[i])+g)/4,
(BLUE_FROM_16(ptr[i])+b)/4); (BLUE_FROM_16(ptr[i])+b)/4);
} }
ptr += _screen_pitch; ptr += _screenPitch;
} }
} }
@ -322,7 +321,7 @@ void NewGui::fillRect(int x, int y, int w, int h, int16 color)
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
ptr[i] = color; ptr[i] = color;
} }
ptr += _screen_pitch; ptr += _screenPitch;
} }
} }
@ -338,7 +337,7 @@ void NewGui::checkerRect(int x, int y, int w, int h, int16 color)
if ((h ^ i) & 1) if ((h ^ i) & 1)
ptr[i] = color; ptr[i] = color;
} }
ptr += _screen_pitch; ptr += _screenPitch;
} }
} }
@ -353,12 +352,12 @@ void NewGui::frameRect(int x, int y, int w, int h, int16 color)
for (i = 0; i < w; i++, ptr++) for (i = 0; i < w; i++, ptr++)
*ptr = color; *ptr = color;
ptr--; ptr--;
for (i = 0; i < h; i++, ptr += _screen_pitch) for (i = 0; i < h; i++, ptr += _screenPitch)
*ptr = color; *ptr = color;
ptr = basePtr; ptr = basePtr;
for (i = 0; i < h; i++, ptr += _screen_pitch) for (i = 0; i < h; i++, ptr += _screenPitch)
*ptr = color; *ptr = color;
ptr -= _screen_pitch; ptr -= _screenPitch;
for (i = 0; i < w; i++, ptr++) for (i = 0; i < w; i++, ptr++)
*ptr = color; *ptr = color;
} }
@ -369,7 +368,7 @@ void NewGui::addDirtyRect(int x, int y, int w, int h)
// blit the affected area directly to the overlay. At least for our current // blit the affected area directly to the overlay. At least for our current
// GUI/widget/dialog code that is just fine. // GUI/widget/dialog code that is just fine.
int16 *buf = getBasePtr(x, y); int16 *buf = getBasePtr(x, y);
_system->copy_rect_overlay(buf, _screen_pitch, x, y, w, h); _system->copy_rect_overlay(buf, _screenPitch, x, y, w, h);
} }
void NewGui::drawChar(const char chr, int xx, int yy, int16 color) void NewGui::drawChar(const char chr, int xx, int yy, int16 color)
@ -394,7 +393,7 @@ void NewGui::drawChar(const char chr, int xx, int yy, int16 color)
if (c) if (c)
ptr[x] = color; ptr[x] = color;
} }
ptr += _screen_pitch; ptr += _screenPitch;
} }
} }
@ -442,7 +441,7 @@ void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, int16 color)
ptr[x2] = color; ptr[x2] = color;
mask >>= 4; mask >>= 4;
} }
ptr += _screen_pitch; ptr += _screenPitch;
} }
} }

View file

@ -81,10 +81,9 @@ public:
protected: protected:
OSystem *_system; OSystem *_system;
int16 *_screen; int16 *_screen;
int _screen_pitch; int _screenPitch;
bool _use_alpha_blending; bool _needRedraw;
bool _need_redraw;
DialogStack _dialogStack; DialogStack _dialogStack;
// for continuous events (keyDown) // for continuous events (keyDown)