aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorGregory Montoir2004-12-01 21:16:55 +0000
committerGregory Montoir2004-12-01 21:16:55 +0000
commitcdec823d98f37bf47a5e557371c6e5a6ce7e017f (patch)
tree489fb75183a2af34e0e1ff81b8885dd649f750fc /backends
parent8bbbbc71fb8c1fbab19bb96371c2f48d5e4ede11 (diff)
downloadscummvm-rg350-cdec823d98f37bf47a5e557371c6e5a6ce7e017f.tar.gz
scummvm-rg350-cdec823d98f37bf47a5e557371c6e5a6ce7e017f.tar.bz2
scummvm-rg350-cdec823d98f37bf47a5e557371c6e5a6ce7e017f.zip
renamed a few things to match our coding guidelines
simplified OSystem_SDL destructor and move all the SDL uninitialization stuff to the quit() method made saveScreenshot() returning false on fail svn-id: r15967
Diffstat (limited to 'backends')
-rw-r--r--backends/sdl/events.cpp184
-rw-r--r--backends/sdl/graphics.cpp179
-rw-r--r--backends/sdl/sdl-common.h68
-rw-r--r--backends/sdl/sdl.cpp99
4 files changed, 264 insertions, 266 deletions
diff --git a/backends/sdl/events.cpp b/backends/sdl/events.cpp
index ad5801a380..64da7fb9d4 100644
--- a/backends/sdl/events.cpp
+++ b/backends/sdl/events.cpp
@@ -64,8 +64,8 @@ void OSystem_SDL::fillMouseEvent(Event &event, int x, int y) {
event.mouse.y = y;
// Update the "keyboard mouse" coords
- km.x = x;
- km.y = y;
+ _km.x = x;
+ _km.y = y;
// Adjust for the screen scaling
event.mouse.x /= _scaleFactor;
@@ -76,71 +76,71 @@ void OSystem_SDL::fillMouseEvent(Event &event, int x, int y) {
event.mouse.y = aspect2Real(event.mouse.y);
}
-void OSystem_SDL::kbd_mouse() {
+void OSystem_SDL::handleKbdMouse() {
uint32 curTime = getMillis();
- if (curTime >= km.last_time + km.delay_time) {
- km.last_time = curTime;
- if (km.x_down_count == 1) {
- km.x_down_time = curTime;
- km.x_down_count = 2;
+ if (curTime >= _km.last_time + _km.delay_time) {
+ _km.last_time = curTime;
+ if (_km.x_down_count == 1) {
+ _km.x_down_time = curTime;
+ _km.x_down_count = 2;
}
- if (km.y_down_count == 1) {
- km.y_down_time = curTime;
- km.y_down_count = 2;
+ if (_km.y_down_count == 1) {
+ _km.y_down_time = curTime;
+ _km.y_down_count = 2;
}
- if (km.x_vel || km.y_vel) {
- if (km.x_down_count) {
- if (curTime > km.x_down_time + km.delay_time * 12) {
- if (km.x_vel > 0)
- km.x_vel++;
+ if (_km.x_vel || _km.y_vel) {
+ if (_km.x_down_count) {
+ if (curTime > _km.x_down_time + _km.delay_time * 12) {
+ if (_km.x_vel > 0)
+ _km.x_vel++;
else
- km.x_vel--;
- } else if (curTime > km.x_down_time + km.delay_time * 8) {
- if (km.x_vel > 0)
- km.x_vel = 5;
+ _km.x_vel--;
+ } else if (curTime > _km.x_down_time + _km.delay_time * 8) {
+ if (_km.x_vel > 0)
+ _km.x_vel = 5;
else
- km.x_vel = -5;
+ _km.x_vel = -5;
}
}
- if (km.y_down_count) {
- if (curTime > km.y_down_time + km.delay_time * 12) {
- if (km.y_vel > 0)
- km.y_vel++;
+ if (_km.y_down_count) {
+ if (curTime > _km.y_down_time + _km.delay_time * 12) {
+ if (_km.y_vel > 0)
+ _km.y_vel++;
else
- km.y_vel--;
- } else if (curTime > km.y_down_time + km.delay_time * 8) {
- if (km.y_vel > 0)
- km.y_vel = 5;
+ _km.y_vel--;
+ } else if (curTime > _km.y_down_time + _km.delay_time * 8) {
+ if (_km.y_vel > 0)
+ _km.y_vel = 5;
else
- km.y_vel = -5;
+ _km.y_vel = -5;
}
}
- km.x += km.x_vel;
- km.y += km.y_vel;
-
- if (km.x < 0) {
- km.x = 0;
- km.x_vel = -1;
- km.x_down_count = 1;
- } else if (km.x > km.x_max) {
- km.x = km.x_max;
- km.x_vel = 1;
- km.x_down_count = 1;
+ _km.x += _km.x_vel;
+ _km.y += _km.y_vel;
+
+ if (_km.x < 0) {
+ _km.x = 0;
+ _km.x_vel = -1;
+ _km.x_down_count = 1;
+ } else if (_km.x > _km.x_max) {
+ _km.x = _km.x_max;
+ _km.x_vel = 1;
+ _km.x_down_count = 1;
}
- if (km.y < 0) {
- km.y = 0;
- km.y_vel = -1;
- km.y_down_count = 1;
- } else if (km.y > km.y_max) {
- km.y = km.y_max;
- km.y_vel = 1;
- km.y_down_count = 1;
+ if (_km.y < 0) {
+ _km.y = 0;
+ _km.y_vel = -1;
+ _km.y_down_count = 1;
+ } else if (_km.y > _km.y_max) {
+ _km.y = _km.y_max;
+ _km.y_vel = 1;
+ _km.y_down_count = 1;
}
- SDL_WarpMouse(km.x, km.y);
+ SDL_WarpMouse(_km.x, _km.y);
}
}
}
@@ -150,7 +150,7 @@ bool OSystem_SDL::pollEvent(Event &event) {
int axis;
byte b = 0;
- kbd_mouse();
+ handleKbdMouse();
// If the screen mode changed, send an EVENT_SCREEN_CHANGED
if (_modeChanged) {
@@ -182,9 +182,9 @@ bool OSystem_SDL::pollEvent(Event &event) {
// Alt-Return and Alt-Enter toggle full screen mode
if (b == KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN
|| ev.key.keysym.sym == SDLK_KP_ENTER)) {
- setFullscreenMode(!_full_screen);
+ setFullscreenMode(!_fullscreen);
#ifdef USE_OSD
- if (_full_screen)
+ if (_fullscreen)
displayMessageOnOSD("Fullscreen mode");
else
displayMessageOnOSD("Windowed mode");
@@ -206,7 +206,7 @@ bool OSystem_SDL::pollEvent(Event &event) {
break;
SDL_RWclose(file);
}
- if (save_screenshot(filename))
+ if (saveScreenshot(filename))
printf("Saved '%s'\n", filename);
else
printf("Could not save screenshot!\n");
@@ -321,26 +321,26 @@ bool OSystem_SDL::pollEvent(Event &event) {
#ifdef LINUPY
// On Yopy map the End button to quit
- if ((ev.key.keysym.sym==293)) {
+ if ((ev.key.keysym.sym == 293)) {
event.event_code = EVENT_QUIT;
return true;
}
// Map menu key to f5 (scumm menu)
- if (ev.key.keysym.sym==306) {
+ if (ev.key.keysym.sym == 306) {
event.event_code = EVENT_KEYDOWN;
event.kbd.keycode = SDLK_F5;
event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
return true;
}
// Map action key to action
- if (ev.key.keysym.sym==291) {
+ if (ev.key.keysym.sym == 291) {
event.event_code = EVENT_KEYDOWN;
event.kbd.keycode = SDLK_TAB;
event.kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0);
return true;
}
// Map OK key to skip cinematic
- if (ev.key.keysym.sym==292) {
+ if (ev.key.keysym.sym == 292) {
event.event_code = EVENT_KEYDOWN;
event.kbd.keycode = SDLK_ESCAPE;
event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
@@ -390,20 +390,20 @@ bool OSystem_SDL::pollEvent(Event &event) {
switch(ev.key.keysym.sym) {
case SDLK_LEFT:
- km.x_vel = -1;
- km.x_down_count = 1;
+ _km.x_vel = -1;
+ _km.x_down_count = 1;
break;
case SDLK_RIGHT:
- km.x_vel = 1;
- km.x_down_count = 1;
+ _km.x_vel = 1;
+ _km.x_down_count = 1;
break;
case SDLK_UP:
- km.y_vel = -1;
- km.y_down_count = 1;
+ _km.y_vel = -1;
+ _km.y_down_count = 1;
break;
case SDLK_DOWN:
- km.y_vel = 1;
- km.y_down_count = 1;
+ _km.y_vel = 1;
+ _km.y_down_count = 1;
break;
default:
break;
@@ -418,27 +418,27 @@ bool OSystem_SDL::pollEvent(Event &event) {
switch(ev.key.keysym.sym) {
case SDLK_LEFT:
- if (km.x_vel < 0) {
- km.x_vel = 0;
- km.x_down_count = 0;
+ if (_km.x_vel < 0) {
+ _km.x_vel = 0;
+ _km.x_down_count = 0;
}
break;
case SDLK_RIGHT:
- if (km.x_vel > 0) {
- km.x_vel = 0;
- km.x_down_count = 0;
+ if (_km.x_vel > 0) {
+ _km.x_vel = 0;
+ _km.x_down_count = 0;
}
break;
case SDLK_UP:
- if (km.y_vel < 0) {
- km.y_vel = 0;
- km.y_down_count = 0;
+ if (_km.y_vel < 0) {
+ _km.y_vel = 0;
+ _km.y_down_count = 0;
}
break;
case SDLK_DOWN:
- if (km.y_vel > 0) {
- km.y_vel = 0;
- km.y_down_count = 0;
+ if (_km.y_vel > 0) {
+ _km.y_vel = 0;
+ _km.y_down_count = 0;
}
break;
default:
@@ -450,7 +450,7 @@ bool OSystem_SDL::pollEvent(Event &event) {
event.event_code = EVENT_MOUSEMOVE;
fillMouseEvent(event, ev.motion.x, ev.motion.y);
- set_mouse_pos(event.mouse.x, event.mouse.y);
+ setMousePos(event.mouse.x, event.mouse.y);
return true;
case SDL_MOUSEBUTTONDOWN:
@@ -551,15 +551,15 @@ bool OSystem_SDL::pollEvent(Event &event) {
if ( ev.jaxis.axis == JOY_XAXIS) {
#ifdef JOY_ANALOG
- km.x_vel = axis/2000;
- km.x_down_count = 0;
+ _km.x_vel = axis/2000;
+ _km.x_down_count = 0;
#else
if (axis != 0) {
- km.x_vel = (axis > 0) ? 1:-1;
- km.x_down_count = 1;
+ _km.x_vel = (axis > 0) ? 1:-1;
+ _km.x_down_count = 1;
} else {
- km.x_vel = 0;
- km.x_down_count = 0;
+ _km.x_vel = 0;
+ _km.x_down_count = 0;
}
#endif
@@ -568,20 +568,20 @@ bool OSystem_SDL::pollEvent(Event &event) {
axis = -axis;
#endif
#ifdef JOY_ANALOG
- km.y_vel = -axis / 2000;
- km.y_down_count = 0;
+ _km.y_vel = -axis / 2000;
+ _km.y_down_count = 0;
#else
if (axis != 0) {
- km.y_vel = (-axis > 0) ? 1: -1;
- km.y_down_count = 1;
+ _km.y_vel = (-axis > 0) ? 1: -1;
+ _km.y_down_count = 1;
} else {
- km.y_vel = 0;
- km.y_down_count = 0;
+ _km.y_vel = 0;
+ _km.y_down_count = 0;
}
#endif
}
- fillMouseEvent(event, km.x, km.y);
+ fillMouseEvent(event, _km.x, _km.y);
return true;
diff --git a/backends/sdl/graphics.cpp b/backends/sdl/graphics.cpp
index 81bd672c9a..adc8e0a9ee 100644
--- a/backends/sdl/graphics.cpp
+++ b/backends/sdl/graphics.cpp
@@ -158,7 +158,7 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
_scalerProc = newScalerProc;
if (newScaleFactor != _scaleFactor) {
_scaleFactor = newScaleFactor;
- hotswap_gfx_mode();
+ hotswapGFXMode();
}
// Determine the "scaler type", i.e. essentially an index into the
@@ -215,20 +215,20 @@ void OSystem_SDL::initSize(uint w, uint h) {
if (h != 200)
_adjustAspectRatio = false;
- CKSUM_NUM = (_screenWidth * _screenHeight / (8 * 8));
+ _cksumNum = (_screenWidth * _screenHeight / (8 * 8));
- free(_dirty_checksums);
- _dirty_checksums = (uint32 *)calloc(CKSUM_NUM * 2, sizeof(uint32));
+ free(_dirtyChecksums);
+ _dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32));
_mouseData = NULL;
- unload_gfx_mode();
- load_gfx_mode();
+ unloadGFXMode();
+ loadGFXMode();
}
-void OSystem_SDL::load_gfx_mode() {
+void OSystem_SDL::loadGFXMode() {
_forceFull = true;
- _mode_flags |= DF_UPDATE_EXPAND_1_PIXEL;
+ _modeFlags |= DF_UPDATE_EXPAND_1_PIXEL;
_tmpscreen = NULL;
@@ -244,7 +244,7 @@ void OSystem_SDL::load_gfx_mode() {
//
_hwscreen = SDL_SetVideoMode(_screenWidth * _scaleFactor, effectiveScreenHeight(), 16,
- _full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
+ _fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
);
if (_hwscreen == NULL) {
// DON'T use error(), as this tries to bring up the debug
@@ -305,13 +305,13 @@ void OSystem_SDL::load_gfx_mode() {
#endif
// keyboard cursor control, some other better place for it?
- km.x_max = _screenWidth * _scaleFactor - 1;
- km.y_max = effectiveScreenHeight() - 1;
- km.delay_time = 25;
- km.last_time = 0;
+ _km.x_max = _screenWidth * _scaleFactor - 1;
+ _km.y_max = effectiveScreenHeight() - 1;
+ _km.delay_time = 25;
+ _km.last_time = 0;
}
-void OSystem_SDL::unload_gfx_mode() {
+void OSystem_SDL::unloadGFXMode() {
if (_screen) {
SDL_FreeSurface(_screen);
_screen = NULL;
@@ -335,7 +335,7 @@ void OSystem_SDL::unload_gfx_mode() {
#endif
}
-void OSystem_SDL::hotswap_gfx_mode() {
+void OSystem_SDL::hotswapGFXMode() {
if (!_screen)
return;
@@ -353,7 +353,7 @@ void OSystem_SDL::hotswap_gfx_mode() {
#endif
// Setup the new GFX mode
- load_gfx_mode();
+ loadGFXMode();
// reset palette
SDL_SetColors(_screen, _currentPalette, 0, 256);
@@ -399,7 +399,7 @@ void OSystem_SDL::internUpdateScreen() {
}
// Make sure the mouse is drawn, if it should be drawn.
- draw_mouse();
+ drawMouse();
// Check whether the palette was changed in the meantime and update the
// screen surface accordingly.
@@ -435,25 +435,24 @@ void OSystem_SDL::internUpdateScreen() {
// Force a full redraw if requested
if (_forceFull) {
- _num_dirty_rects = 1;
-
- _dirty_rect_list[0].x = 0;
- _dirty_rect_list[0].y = 0;
- _dirty_rect_list[0].w = _screenWidth;
- _dirty_rect_list[0].h = _screenHeight;
+ _numDirtyRects = 1;
+ _dirtyRectList[0].x = 0;
+ _dirtyRectList[0].y = 0;
+ _dirtyRectList[0].w = _screenWidth;
+ _dirtyRectList[0].h = _screenHeight;
}
// Only draw anything if necessary
- if (_num_dirty_rects > 0) {
+ if (_numDirtyRects > 0) {
SDL_Rect *r;
SDL_Rect dst;
uint32 srcPitch, dstPitch;
- SDL_Rect *last_rect = _dirty_rect_list + _num_dirty_rects;
+ SDL_Rect *lastRect = _dirtyRectList + _numDirtyRects;
if (_scalerProc == Normal1x && !_adjustAspectRatio) {
SDL_Surface *target = _overlayVisible ? _tmpscreen : _screen;
- for (r = _dirty_rect_list; r != last_rect; ++r) {
+ for (r = _dirtyRectList; r != lastRect; ++r) {
dst = *r;
if (_overlayVisible) {
@@ -467,7 +466,7 @@ void OSystem_SDL::internUpdateScreen() {
}
} else {
if (!_overlayVisible) {
- for (r = _dirty_rect_list; r != last_rect; ++r) {
+ for (r = _dirtyRectList; r != lastRect; ++r) {
dst = *r;
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.
@@ -482,7 +481,7 @@ void OSystem_SDL::internUpdateScreen() {
srcPitch = _tmpscreen->pitch;
dstPitch = _hwscreen->pitch;
- for (r = _dirty_rect_list; r != last_rect; ++r) {
+ for (r = _dirtyRectList; r != lastRect; ++r) {
register int dst_y = r->y + _currentShakePos;
register int dst_h = 0;
register int orig_dst_y = 0;
@@ -518,8 +517,8 @@ void OSystem_SDL::internUpdateScreen() {
// Readjust the dirty rect list in case we are doing a full update.
// This is necessary if shaking is active.
if (_forceFull) {
- _dirty_rect_list[0].y = 0;
- _dirty_rect_list[0].h = effectiveScreenHeight();
+ _dirtyRectList[0].y = 0;
+ _dirtyRectList[0].h = effectiveScreenHeight();
}
#ifdef USE_OSD
@@ -529,19 +528,18 @@ void OSystem_SDL::internUpdateScreen() {
#endif
// Finally, blit all our changes to the screen
- SDL_UpdateRects(_hwscreen, _num_dirty_rects, _dirty_rect_list);
+ SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList);
}
- _num_dirty_rects = 0;
+ _numDirtyRects = 0;
_forceFull = false;
}
-bool OSystem_SDL::save_screenshot(const char *filename) {
+bool OSystem_SDL::saveScreenshot(const char *filename) {
assert(_hwscreen != NULL);
Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
- SDL_SaveBMP(_hwscreen, filename);
- return true;
+ return SDL_SaveBMP(_hwscreen, filename) == 0;
}
void OSystem_SDL::setFullscreenMode(bool enable) {
@@ -559,22 +557,22 @@ void OSystem_SDL::setFullscreenMode(bool enable) {
Common::StackLock lock(_graphicsMutex);
- if (_full_screen != enable) {
+ if (_fullscreen != enable) {
assert(_hwscreen != 0);
- _full_screen ^= true;
+ _fullscreen ^= true;
- undraw_mouse();
+ undrawMouse();
#if defined(MACOSX) && !SDL_VERSION_ATLEAST(1, 2, 6)
// On OS X, SDL_WM_ToggleFullScreen is currently not implemented. Worse,
// before SDL 1.2.6 it always returned -1 (which would indicate a
// successful switch). So we simply don't call it at all and use
- // hotswap_gfx_mode() directly to switch to fullscreen mode.
- hotswap_gfx_mode();
+ // hotswapGFXMode() directly to switch to fullscreen mode.
+ hotswapGFXMode();
#else
if (!SDL_WM_ToggleFullScreen(_hwscreen)) {
// if ToggleFullScreen fails, achieve the same effect with hotswap gfx mode
- hotswap_gfx_mode();
+ hotswapGFXMode();
}
#endif
@@ -604,7 +602,7 @@ void OSystem_SDL::setAspectRatioCorrection(bool enable) {
//assert(_hwscreen != 0);
_adjustAspectRatio ^= true;
- hotswap_gfx_mode();
+ hotswapGFXMode();
// Blit everything to the screen
internUpdateScreen();
@@ -638,12 +636,12 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int
Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
- if (((long)src & 3) == 0 && pitch == _screenWidth && x==0 && y==0 &&
- w==_screenWidth && h==_screenHeight && _mode_flags&DF_WANT_RECT_OPTIM) {
+ if (((long)src & 3) == 0 && pitch == _screenWidth && x == 0 && y == 0 &&
+ w == _screenWidth && h == _screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) {
/* Special, optimized case for full screen updates.
* It tries to determine what areas were actually changed,
* and just updates those, on the actual display. */
- add_dirty_rgn_auto(src);
+ addDirtyRgnAuto(src);
} else {
/* Clip the coordinates */
if (x < 0) {
@@ -669,12 +667,12 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int
if (w <= 0 || h <= 0)
return;
- cksum_valid = false;
- add_dirty_rect(x, y, w, h);
+ _cksumValid = false;
+ addDirtyRect(x, y, w, h);
}
/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
- undraw_mouse();
+ undrawMouse();
// Try to lock the screen surface
if (SDL_LockSurface(_screen) == -1)
@@ -697,17 +695,17 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int
}
-void OSystem_SDL::add_dirty_rect(int x, int y, int w, int h) {
+void OSystem_SDL::addDirtyRect(int x, int y, int w, int h) {
if (_forceFull)
return;
- if (_num_dirty_rects == NUM_DIRTY_RECT)
+ if (_numDirtyRects == NUM_DIRTY_RECT)
_forceFull = true;
else {
- SDL_Rect *r = &_dirty_rect_list[_num_dirty_rects++];
+ SDL_Rect *r = &_dirtyRectList[_numDirtyRects++];
// Extend the dirty region by 1 pixel for scalers
// that "smear" the screen, e.g. 2xSAI
- if (_mode_flags & DF_UPDATE_EXPAND_1_PIXEL) {
+ if (_modeFlags & DF_UPDATE_EXPAND_1_PIXEL) {
x--;
y--;
w+=2;
@@ -743,8 +741,8 @@ void OSystem_SDL::add_dirty_rect(int x, int y, int w, int h) {
}
-void OSystem_SDL::mk_checksums(const byte *buf) {
- uint32 *sums = _dirty_checksums;
+void OSystem_SDL::makeChecksums(const byte *buf) {
+ uint32 *sums = _dirtyChecksums;
uint x,y;
const uint last_x = (uint)_screenWidth / 8;
const uint last_y = (uint)_screenHeight / 8;
@@ -780,36 +778,36 @@ void OSystem_SDL::mk_checksums(const byte *buf) {
}
}
-void OSystem_SDL::add_dirty_rgn_auto(const byte *buf) {
+void OSystem_SDL::addDirtyRgnAuto(const byte *buf) {
assert(((long)buf & 3) == 0);
/* generate a table of the checksums */
- mk_checksums(buf);
+ makeChecksums(buf);
- if (!cksum_valid) {
+ if (!_cksumValid) {
_forceFull = true;
- cksum_valid = true;
+ _cksumValid = true;
}
/* go through the checksum list, compare it with the previous checksums,
and add all dirty rectangles to a list. try to combine small rectangles
into bigger ones in a simple way */
if (!_forceFull) {
- int x,y,w;
- uint32 *ck = _dirty_checksums;
+ int x, y, w;
+ uint32 *ck = _dirtyChecksums;
- for(y = 0; y!=_screenHeight / 8; y++) {
- for(x = 0; x!=_screenWidth / 8; x++, ck++) {
- if (ck[0] != ck[CKSUM_NUM]) {
+ for(y = 0; y != _screenHeight / 8; y++) {
+ for(x = 0; x != _screenWidth / 8; x++, ck++) {
+ if (ck[0] != ck[_cksumNum]) {
/* 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. */
w=0;
do {
- ck[w + CKSUM_NUM] = ck[w];
+ ck[w + _cksumNum] = ck[w];
w++;
- } while (x + w != _screenWidth / 8 && ck[w] != ck[w + CKSUM_NUM]);
+ } while (x + w != _screenWidth / 8 && ck[w] != ck[w + _cksumNum]);
- add_dirty_rect(x * 8, y * 8, w * 8, 8);
+ addDirtyRect(x * 8, y * 8, w * 8, 8);
if (_forceFull)
goto get_out;
@@ -819,7 +817,7 @@ void OSystem_SDL::add_dirty_rgn_auto(const byte *buf) {
} else {
get_out:;
/* Copy old checksums to new */
- memcpy(_dirty_checksums + CKSUM_NUM, _dirty_checksums, CKSUM_NUM * sizeof(uint32));
+ memcpy(_dirtyChecksums + _cksumNum, _dirtyChecksums, _cksumNum * sizeof(uint32));
}
}
@@ -864,7 +862,7 @@ void OSystem_SDL::showOverlay() {
assert (_transactionMode == kTransactionNone);
// hide the mouse
- undraw_mouse();
+ undrawMouse();
_overlayVisible = true;
clearOverlay();
@@ -874,7 +872,7 @@ void OSystem_SDL::hideOverlay() {
assert (_transactionMode == kTransactionNone);
// hide the mouse
- undraw_mouse();
+ undrawMouse();
_overlayVisible = false;
_forceFull = true;
@@ -889,7 +887,7 @@ void OSystem_SDL::clearOverlay() {
Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
// hide the mouse
- undraw_mouse();
+ undrawMouse();
// Clear the overlay by making the game screen "look through" everywhere.
SDL_Rect src, dst;
@@ -913,7 +911,7 @@ void OSystem_SDL::grabOverlay(OverlayColor *buf, int pitch) {
return;
// hide the mouse
- undraw_mouse();
+ undrawMouse();
if (SDL_LockSurface(_tmpscreen) == -1)
error("SDL_LockSurface failed: %s", SDL_GetError());
@@ -962,11 +960,11 @@ void OSystem_SDL::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, i
return;
// Mark the modified region as dirty
- cksum_valid = false;
- add_dirty_rect(x, y, w, h);
+ _cksumValid = false;
+ addDirtyRect(x, y, w, h);
/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
- undraw_mouse();
+ undrawMouse();
if (SDL_LockSurface(_tmpscreen) == -1)
error("SDL_LockSurface failed: %s", SDL_GetError());
@@ -1002,16 +1000,16 @@ bool OSystem_SDL::showMouse(bool visible) {
_mouseVisible = visible;
if (visible)
- draw_mouse();
+ drawMouse();
else
- undraw_mouse();
+ undrawMouse();
return last;
}
-void OSystem_SDL::set_mouse_pos(int x, int y) {
+void OSystem_SDL::setMousePos(int x, int y) {
if (x != _mouseCurState.x || y != _mouseCurState.y) {
- undraw_mouse();
+ undrawMouse();
_mouseCurState.x = x;
_mouseCurState.y = y;
updateScreen();
@@ -1023,19 +1021,19 @@ void OSystem_SDL::warpMouse(int x, int y) {
SDL_WarpMouse(x * _scaleFactor, y * _scaleFactor);
// SDL_WarpMouse() generates a mouse movement event, so
- // set_mouse_pos() would be called eventually. However, the
+ // setMousePos() would be called eventually. However, the
// cannon script in CoMI calls this function twice each time
// the cannon is reloaded. Unless we update the mouse position
// immediately the second call is ignored, causing the cannon
// to change its aim.
- set_mouse_pos(x, y);
+ setMousePos(x, y);
}
}
void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor) {
- undraw_mouse();
+ undrawMouse();
assert(w <= MAX_MOUSE_W);
assert(h <= MAX_MOUSE_H);
@@ -1045,10 +1043,9 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x,
_mouseHotspotX = hotspot_x;
_mouseHotspotY = hotspot_y;
- _mouseKeycolor = keycolor;
+ _mouseKeyColor = keycolor;
- if (_mouseData)
- free(_mouseData);
+ free(_mouseData);
_mouseData = (byte *)malloc(w * h);
memcpy(_mouseData, buf, w * h);
@@ -1061,7 +1058,7 @@ void OSystem_SDL::toggleMouseGrab() {
SDL_WM_GrabInput(SDL_GRAB_OFF);
}
-void OSystem_SDL::draw_mouse() {
+void OSystem_SDL::drawMouse() {
if (_mouseDrawn || !_mouseVisible)
return;
@@ -1098,7 +1095,7 @@ void OSystem_SDL::draw_mouse() {
error("SDL_LockSurface failed: %s", SDL_GetError());
// Mark as dirty
- add_dirty_rect(x, y, w, h);
+ addDirtyRect(x, y, w, h);
if (!_overlayVisible) {
byte *bak = _mouseBackup; // Surface used to backup the area obscured by the mouse
@@ -1110,7 +1107,7 @@ void OSystem_SDL::draw_mouse() {
while (width > 0) {
*bak++ = *dst;
color = *src++;
- if (color != _mouseKeycolor) // transparent, don't draw
+ if (color != _mouseKeyColor) // transparent, don't draw
*dst = color;
dst++;
width--;
@@ -1149,7 +1146,7 @@ void OSystem_SDL::draw_mouse() {
_mouseDrawn = true;
}
-void OSystem_SDL::undraw_mouse() {
+void OSystem_SDL::undrawMouse() {
assert (_transactionMode == kTransactionNone);
if (!_mouseDrawn)
@@ -1187,7 +1184,7 @@ void OSystem_SDL::undraw_mouse() {
if (!_overlayVisible) {
byte *dst, *bak = _mouseBackup;
- // No need to do clipping here, since draw_mouse() did that already
+ // No need to do clipping here, since drawMouse() did that already
dst = (byte *)_screen->pixels + old_mouse_y * _screenWidth + old_mouse_x;
for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += _screenWidth) {
for (x = 0; x < old_mouse_w; ++x) {
@@ -1200,7 +1197,7 @@ void OSystem_SDL::undraw_mouse() {
byte *dst;
uint16 *bak = (uint16 *)_mouseBackup;
- // No need to do clipping here, since draw_mouse() did that already
+ // No need to do clipping here, since drawMouse() did that already
dst = (byte *)_tmpscreen->pixels + (old_mouse_y + 1) * _tmpscreen->pitch + (old_mouse_x + 1) * 2;
for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += _tmpscreen->pitch) {
for (x = 0; x < old_mouse_w; ++x) {
@@ -1209,7 +1206,7 @@ void OSystem_SDL::undraw_mouse() {
}
}
- add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
+ addDirtyRect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
SDL_UnlockSurface(_overlayVisible ? _tmpscreen : _screen);
}
diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h
index 2175d70590..821c3cb361 100644
--- a/backends/sdl/sdl-common.h
+++ b/backends/sdl/sdl-common.h
@@ -160,7 +160,7 @@ public:
#endif
protected:
- void init_intern();
+ void initIntern();
#ifdef USE_OSD
SDL_Surface *_osdSurface;
@@ -190,8 +190,8 @@ protected:
// CD Audio
SDL_CD *_cdrom;
- int cd_track, cd_num_loops, cd_start_frame, cd_duration;
- Uint32 cd_end_time, cd_stop_time;
+ int _cdTrack, _cdNumLoops, _cdStartFrame, _cdDuration;
+ uint32 _cdEndTime, _cdStopTime;
enum {
DF_WANT_RECT_OPTIM = 1 << 0,
@@ -217,14 +217,17 @@ protected:
bool arChanged;
} _transactionDetails;
- bool _forceFull; // Force full redraw on next updateScreen
+ /** Force full redraw on next updateScreen */
+ bool _forceFull;
ScalerProc *_scalerProc;
- int _scalerType;
+ int _scalerType;
int _scaleFactor;
int _mode;
int _transactionMode;
- bool _full_screen;
- uint32 _mode_flags;
+ bool _fullscreen;
+
+ /** Current video mode flags (see DF_* constants) */
+ uint32 _modeFlags;
bool _modeChanged;
/** True if aspect ratio correction is enabled. */
@@ -238,25 +241,25 @@ protected:
MAX_SCALING = 3
};
- // Dirty rect managment
- SDL_Rect _dirty_rect_list[NUM_DIRTY_RECT];
- int _num_dirty_rects;
- uint32 *_dirty_checksums;
- bool cksum_valid;
- int CKSUM_NUM;
+ // Dirty rect management
+ SDL_Rect _dirtyRectList[NUM_DIRTY_RECT];
+ int _numDirtyRects;
+ uint32 *_dirtyChecksums;
+ bool _cksumValid;
+ int _cksumNum;
// Keyboard mouse emulation
struct KbdMouse {
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;
- } km;
+ };
struct MousePos {
int16 x, y, w, h;
- MousePos() : x(0), y(0), w(0), h(0) {}
};
// mouse
+ KbdMouse _km;
bool _mouseVisible;
bool _mouseDrawn;
byte *_mouseData;
@@ -264,7 +267,7 @@ protected:
MousePos _mouseCurState;
int16 _mouseHotspotX;
int16 _mouseHotspotY;
- byte _mouseKeycolor;
+ byte _mouseKeyColor;
// joystick
SDL_Joystick *_joystick;
@@ -284,35 +287,34 @@ protected:
MutexRef _graphicsMutex;
- void add_dirty_rgn_auto(const byte *buf);
- void mk_checksums(const byte *buf);
-
- virtual void add_dirty_rect(int x, int y, int w, int h);
+ void addDirtyRgnAuto(const byte *buf);
+ void makeChecksums(const byte *buf);
+
+ void addDirtyRect(int x, int y, int w, int h);
- void draw_mouse();
- void undraw_mouse();
+ void drawMouse();
+ void undrawMouse();
+
/** Set the position of the virtual mouse cursor. */
- void set_mouse_pos(int x, int y);
+ void setMousePos(int x, int y);
void fillMouseEvent(Event &event, int x, int y);
void toggleMouseGrab();
+ void internUpdateScreen();
- virtual void internUpdateScreen();
-
- virtual void load_gfx_mode();
- virtual void unload_gfx_mode();
- virtual void hotswap_gfx_mode();
+ void loadGFXMode();
+ void unloadGFXMode();
+ void hotswapGFXMode();
void setFullscreenMode(bool enable);
void setAspectRatioCorrection(bool enable);
- bool save_screenshot(const char *filename);
+ bool saveScreenshot(const char *filename);
- int effectiveScreenHeight() { return (_adjustAspectRatio ? 240 : _screenHeight) * _scaleFactor; }
+ int effectiveScreenHeight() const { return (_adjustAspectRatio ? 240 : _screenHeight) * _scaleFactor; }
- void setup_icon();
- void kbd_mouse();
- void init_joystick(int joystick_num) { _joystick = SDL_JoystickOpen(joystick_num); }
+ void setupIcon();
+ void handleKbdMouse();
};
#endif
diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp
index 80d9d62dfa..2b825d2327 100644
--- a/backends/sdl/sdl.cpp
+++ b/backends/sdl/sdl.cpp
@@ -35,7 +35,7 @@ OSystem *OSystem_SDL_create() {
return new OSystem_SDL();
}
-void OSystem_SDL::init_intern() {
+void OSystem_SDL::initIntern() {
int joystick_num = ConfMan.getInt("joystick_num");
uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
@@ -61,33 +61,33 @@ void OSystem_SDL::init_intern() {
// Enable unicode support if possible
SDL_EnableUNICODE(1);
- cksum_valid = false;
+ _cksumValid = false;
#ifndef _WIN32_WCE
_mode = GFX_DOUBLESIZE;
_scaleFactor = 2;
_scalerProc = Normal2x;
- _full_screen = ConfMan.getBool("fullscreen");
+ _fullscreen = ConfMan.getBool("fullscreen");
_adjustAspectRatio = ConfMan.getBool("aspect_ratio");
#else
_mode = GFX_NORMAL;
_scaleFactor = 1;
_scalerProc = Normal1x;
- _full_screen = true;
+ _fullscreen = true;
_adjustAspectRatio = false;
#endif
_scalerType = 0;
- _mode_flags = 0;
+ _modeFlags = 0;
#ifndef MACOSX // Don't set icon on OS X, as we use a nicer external icon there
// Setup the icon
- setup_icon();
+ setupIcon();
#endif
// enable joystick
if (joystick_num > -1 && SDL_NumJoysticks() > 0) {
printf("Using joystick: %s\n", SDL_JoystickName(0));
- init_joystick(joystick_num);
+ _joystick = SDL_JoystickOpen(joystick_num);
}
}
@@ -99,9 +99,10 @@ OSystem_SDL::OSystem_SDL()
_hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0),
_tmpscreen(0), _overlayVisible(false),
_samplesPerSec(0),
- _cdrom(0), _scalerProc(0), _modeChanged(false), _dirty_checksums(0),
+ _cdrom(0), _scalerProc(0), _modeChanged(false), _dirtyChecksums(0),
_mouseVisible(false), _mouseDrawn(false), _mouseData(0),
_mouseHotspotX(0), _mouseHotspotY(0),
+ _joystick(0),
_currentShakePos(0), _newShakePos(0),
_paletteDirtyStart(0), _paletteDirtyEnd(0),
_graphicsMutex(0), _transactionMode(kTransactionNone) {
@@ -113,22 +114,17 @@ OSystem_SDL::OSystem_SDL()
_mouseBackup = (byte *)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2);
// reset mouse state
- memset(&km, 0, sizeof(km));
+ memset(&_km, 0, sizeof(_km));
+ memset(&_mouseCurState, 0, sizeof(_mouseCurState));
- init_intern();
+ initIntern();
}
OSystem_SDL::~OSystem_SDL() {
-// unload_gfx_mode();
-
- if (_dirty_checksums)
- free(_dirty_checksums);
+ free(_dirtyChecksums);
free(_currentPalette);
free(_mouseBackup);
- deleteMutex(_graphicsMutex);
-
- SDL_ShowCursor(SDL_ENABLE);
- SDL_Quit();
+ free(_mouseData);
}
uint32 OSystem_SDL::getMillis() {
@@ -164,9 +160,9 @@ void OSystem_SDL::setFeatureState(Feature f, bool enable) {
break;
case kFeatureAutoComputeDirtyRects:
if (enable)
- _mode_flags |= DF_WANT_RECT_OPTIM;
+ _modeFlags |= DF_WANT_RECT_OPTIM;
else
- _mode_flags &= ~DF_WANT_RECT_OPTIM;
+ _modeFlags &= ~DF_WANT_RECT_OPTIM;
break;
default:
break;
@@ -178,30 +174,33 @@ bool OSystem_SDL::getFeatureState(Feature f) {
switch (f) {
case kFeatureFullscreenMode:
- return _full_screen;
+ return _fullscreen;
case kFeatureAspectRatioCorrection:
return _adjustAspectRatio;
case kFeatureAutoComputeDirtyRects:
- return _mode_flags & DF_WANT_RECT_OPTIM;
+ return _modeFlags & DF_WANT_RECT_OPTIM;
default:
return false;
}
}
void OSystem_SDL::quit() {
- if(_cdrom) {
+ if (_cdrom) {
SDL_CDStop(_cdrom);
SDL_CDClose(_cdrom);
}
- unload_gfx_mode();
+ unloadGFXMode();
+ deleteMutex(_graphicsMutex);
+ if (_joystick)
+ SDL_JoystickClose(_joystick);
SDL_ShowCursor(SDL_ENABLE);
SDL_Quit();
exit(0);
}
-void OSystem_SDL::setup_icon() {
+void OSystem_SDL::setupIcon() {
int w, h, ncols, nbytes, i;
unsigned int rgba[256], icon[32 * 32];
unsigned char mask[32][4];
@@ -327,9 +326,9 @@ bool OSystem_SDL::openCD(int drive) {
if (!_cdrom) {
warning("Couldn't open drive: %s", SDL_GetError());
} else {
- cd_num_loops = 0;
- cd_stop_time = 0;
- cd_end_time = 0;
+ _cdNumLoops = 0;
+ _cdStopTime = 0;
+ _cdEndTime = 0;
}
}
@@ -337,8 +336,8 @@ bool OSystem_SDL::openCD(int drive) {
}
void OSystem_SDL::stopCD() { /* Stop CD Audio in 1/10th of a second */
- cd_stop_time = SDL_GetTicks() + 100;
- cd_num_loops = 0;
+ _cdStopTime = SDL_GetTicks() + 100;
+ _cdNumLoops = 0;
}
void OSystem_SDL::playCD(int track, int num_loops, int start_frame, int duration) {
@@ -351,55 +350,55 @@ void OSystem_SDL::playCD(int track, int num_loops, int start_frame, int duration
if (duration > 0)
duration += 5;
- cd_track = track;
- cd_num_loops = num_loops;
- cd_start_frame = start_frame;
+ _cdTrack = track;
+ _cdNumLoops = num_loops;
+ _cdStartFrame = start_frame;
SDL_CDStatus(_cdrom);
if (start_frame == 0 && duration == 0)
SDL_CDPlayTracks(_cdrom, track, 0, 1, 0);
else
SDL_CDPlayTracks(_cdrom, track, start_frame, 0, duration);
- cd_duration = duration;
- cd_stop_time = 0;
- cd_end_time = SDL_GetTicks() + _cdrom->track[track].length * 1000 / CD_FPS;
+ _cdDuration = duration;
+ _cdStopTime = 0;
+ _cdEndTime = SDL_GetTicks() + _cdrom->track[track].length * 1000 / CD_FPS;
}
bool OSystem_SDL::pollCD() {
if (!_cdrom)
return false;
- return (cd_num_loops != 0 && (SDL_GetTicks() < cd_end_time || SDL_CDStatus(_cdrom) != CD_STOPPED));
+ return (_cdNumLoops != 0 && (SDL_GetTicks() < _cdEndTime || SDL_CDStatus(_cdrom) != CD_STOPPED));
}
void OSystem_SDL::updateCD() {
if (!_cdrom)
return;
- if (cd_stop_time != 0 && SDL_GetTicks() >= cd_stop_time) {
+ if (_cdStopTime != 0 && SDL_GetTicks() >= _cdStopTime) {
SDL_CDStop(_cdrom);
- cd_num_loops = 0;
- cd_stop_time = 0;
+ _cdNumLoops = 0;
+ _cdStopTime = 0;
return;
}
- if (cd_num_loops == 0 || SDL_GetTicks() < cd_end_time)
+ if (_cdNumLoops == 0 || SDL_GetTicks() < _cdEndTime)
return;
- if (cd_num_loops != 1 && SDL_CDStatus(_cdrom) != CD_STOPPED) {
+ if (_cdNumLoops != 1 && SDL_CDStatus(_cdrom) != CD_STOPPED) {
// Wait another second for it to be done
- cd_end_time += 1000;
+ _cdEndTime += 1000;
return;
}
- if (cd_num_loops > 0)
- cd_num_loops--;
+ if (_cdNumLoops > 0)
+ _cdNumLoops--;
- if (cd_num_loops != 0) {
- if (cd_start_frame == 0 && cd_duration == 0)
- SDL_CDPlayTracks(_cdrom, cd_track, 0, 1, 0);
+ if (_cdNumLoops != 0) {
+ if (_cdStartFrame == 0 && _cdDuration == 0)
+ SDL_CDPlayTracks(_cdrom, _cdTrack, 0, 1, 0);
else
- SDL_CDPlayTracks(_cdrom, cd_track, cd_start_frame, 0, cd_duration);
- cd_end_time = SDL_GetTicks() + _cdrom->track[cd_track].length * 1000 / CD_FPS;
+ SDL_CDPlayTracks(_cdrom, _cdTrack, _cdStartFrame, 0, _cdDuration);
+ _cdEndTime = SDL_GetTicks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS;
}
}