From d4734bd4f2963168f794691a618869ba4e558aaa Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 4 Oct 2003 11:50:21 +0000 Subject: use namespace Common a bit more; don't zero the RNG in scumm (else the seed gets reset); remove obsolete 256 color blending code svn-id: r10592 --- backends/sdl/sdl-common.cpp | 6 +-- backends/sdl/sdl.cpp | 6 +-- backends/sdl/sdl_gl.cpp | 6 +-- common/timer.cpp | 8 ++-- common/util.cpp | 95 ++++++--------------------------------------- common/util.h | 16 ++++---- scumm/script_v5.cpp | 2 +- scumm/scumm.h | 2 +- scumm/scummvm.cpp | 1 - simon/simon.h | 2 +- sky/logic.h | 2 +- sound/mixer.cpp | 38 +++++++++--------- sound/mpu401.cpp | 2 +- sword2/driver/d_sound.cpp | 16 ++++---- 14 files changed, 65 insertions(+), 137 deletions(-) diff --git a/backends/sdl/sdl-common.cpp b/backends/sdl/sdl-common.cpp index cb4e49966f..ee28922e7e 100644 --- a/backends/sdl/sdl-common.cpp +++ b/backends/sdl/sdl-common.cpp @@ -150,7 +150,7 @@ void OSystem_SDL_Common::copy_rect(const byte *src, int pitch, int x, int y, int if (_screen == NULL) return; - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // 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) { @@ -218,7 +218,7 @@ void OSystem_SDL_Common::move_screen(int dx, int dy, int height) { if ((dx == 0 && dy == 0) || height <= 0) return; - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends byte *src, *dst; int x, y; @@ -1295,7 +1295,7 @@ void OSystem_SDL_Common::clear_overlay() { if (!_overlayVisible) return; - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends // hide the mouse undraw_mouse(); diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp index ad1c0d813c..93f8fb2a26 100644 --- a/backends/sdl/sdl.cpp +++ b/backends/sdl/sdl.cpp @@ -239,7 +239,7 @@ void OSystem_SDL::hotswap_gfx_mode() { void OSystem_SDL::update_screen() { assert(_hwscreen != NULL); - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends // If the shake position changed, fill the dirty area with blackness if (_currentShakePos != _newShakePos) { @@ -369,7 +369,7 @@ void OSystem_SDL::update_screen() { uint32 OSystem_SDL::property(int param, Property *value) { - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends if (param == PROP_TOGGLE_FULLSCREEN) { assert(_hwscreen != 0); @@ -408,7 +408,7 @@ uint32 OSystem_SDL::property(int param, Property *value) { bool OSystem_SDL::save_screenshot(const char *filename) { assert(_hwscreen != NULL); - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends SDL_SaveBMP(_hwscreen, filename); return true; } diff --git a/backends/sdl/sdl_gl.cpp b/backends/sdl/sdl_gl.cpp index 4fab4f0f5a..7177a9ceeb 100644 --- a/backends/sdl/sdl_gl.cpp +++ b/backends/sdl/sdl_gl.cpp @@ -359,7 +359,7 @@ void OSystem_SDL_OpenGL::hotswap_gfx_mode() { void OSystem_SDL_OpenGL::update_screen() { - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends // If the shake position changed, fill the dirty area with blackness if (_currentShakePos != _newShakePos) { @@ -563,7 +563,7 @@ bool OSystem_SDL_OpenGL::poll_event(Event *event) { uint32 OSystem_SDL_OpenGL::property(int param, Property *value) { - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends if (param == PROP_TOGGLE_FULLSCREEN) { if (!_usingOpenGL) @@ -686,7 +686,7 @@ bool OSystem_SDL_OpenGL::save_screenshot(const char *filename) { if (_usingOpenGL) return false; - StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends + Common::StackLock lock(_graphicsMutex, this); // Lock the mutex until this function ends assert(_hwscreen != NULL); SDL_SaveBMP(_hwscreen, filename); diff --git a/common/timer.cpp b/common/timer.cpp index cc8bf00efc..c6a139bd54 100644 --- a/common/timer.cpp +++ b/common/timer.cpp @@ -54,7 +54,7 @@ Timer::~Timer() { _system->set_timer(0, 0); { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); for (int i = 0; i < MAX_TIMERS; i++) { _timerSlots[i].procedure = NULL; _timerSlots[i].interval = 0; @@ -81,7 +81,7 @@ int Timer::timer_handler(int t) { } int Timer::handler(int t) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); uint32 interval, l; _lastTime = _thisTime; @@ -102,7 +102,7 @@ int Timer::handler(int t) { } bool Timer::installProcedure(TimerProc procedure, int32 interval, void *refCon) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); int32 l; bool found = false; @@ -124,7 +124,7 @@ bool Timer::installProcedure(TimerProc procedure, int32 interval, void *refCon) } void Timer::releaseProcedure(TimerProc procedure) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); int32 l; for (l = 0; l < MAX_TIMERS; l++) { diff --git a/common/util.cpp b/common/util.cpp index 7732372dbb..5c85e74c70 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -22,106 +22,34 @@ #include "base/engine.h" #include "common/util.h" -// -// 8-bit alpha blending routines -// -#ifndef NEWGUI_256 -static int BlendCache[256][256]; -#endif -// -// Find the entry in the given palette which matches the color defined by -// the tripel (r,b,g) most closely. -// -int RGBMatch(byte *palette, int r, int g, int b) { - int i, bestidx = 0, besterr = 0xFFFFFF; - int error = 0; - - for (i = 0;i < 256;i++) { - byte *pal = palette + (i * 3); - int r_diff = r - (int)*pal++; - int g_diff = g - (int)*pal++; - int b_diff = b - (int)*pal++; - r_diff *= r_diff; g_diff *= g_diff; b_diff *= b_diff; - - error = r_diff + g_diff + b_diff; - if (error < besterr) { - besterr = error; - bestidx = i; - } - } - return bestidx; -} - -// -// Blend two 8 bit colors into a third, all colors being defined by palette indices. -// -int Blend(int src, int dst, byte *palette) { -#ifndef NEWGUI_256 - int r, g, b; - int alpha = 128; // Level of transparency [0-256] - byte *srcpal = palette + (dst * 3); - byte *dstpal = palette + (src * 3); - - if (BlendCache[dst][src] > -1) - return BlendCache[dst][src]; - - r = (*srcpal++ * alpha); - r += (*dstpal++ * (256 - alpha)); - r /= 256; - - g = (*srcpal++ * alpha); - g += (*dstpal++ * (256 - alpha)); - g /= 256; - - b = (*srcpal++ * alpha); - b += (*dstpal++ * (256 - alpha)); - b /= 256; - - return (BlendCache[dst][src] = RGBMatch(palette, r , g , b )); -#else - return 0; -#endif -} - -// -// Reset the blending cache -// -void ClearBlendCache() { -#ifndef NEWGUI_256 - for (int i = 0; i < 256; i++) - for (int j = 0 ; j < 256 ; j++) -// BlendCache[i][j] = i; // No alphablending -// BlendCache[i][j] = j; // 100% translucent - BlendCache[i][j] = -1; // Enable alphablending -#endif -} +namespace Common { // // Print hexdump of the data passed in // -void hexdump(const byte * data, int len, int bytes_per_line) { - assert(1 <= bytes_per_line && bytes_per_line <= 32); +void hexdump(const byte * data, int len, int bytesPerLine) { + assert(1 <= bytesPerLine && bytesPerLine <= 32); int i; byte c; int offset = 0; - while (len >= bytes_per_line) { + while (len >= bytesPerLine) { printf("%06x: ", offset); - for (i = 0; i < bytes_per_line; i++) { + for (i = 0; i < bytesPerLine; i++) { printf("%02x ", data[i]); if (i % 4 == 3) printf(" "); } printf(" |"); - for (i = 0; i < bytes_per_line; i++) { + for (i = 0; i < bytesPerLine; i++) { c = data[i]; if (c < 32 || c >= 127) c = '.'; printf("%c", c); } printf("|\n"); - data += bytes_per_line; - len -= bytes_per_line; - offset += bytes_per_line; + data += bytesPerLine; + len -= bytesPerLine; + offset += bytesPerLine; } if (len <= 0) @@ -133,7 +61,7 @@ void hexdump(const byte * data, int len, int bytes_per_line) { if (i % 4 == 3) printf(" "); } - for (; i < bytes_per_line; i++) + for (; i < bytesPerLine; i++) printf(" "); printf(" |"); for (i = 0; i < len; i++) { @@ -142,7 +70,7 @@ void hexdump(const byte * data, int len, int bytes_per_line) { c = '.'; printf("%c", c); } - for (; i < bytes_per_line; i++) + for (; i < bytesPerLine; i++) printf(" "); printf("|\n"); } @@ -187,3 +115,4 @@ void StackLock::unlock() { _syst->unlock_mutex(_mutex); } +} // End of namespace Common diff --git a/common/util.h b/common/util.h index 14ab36f4b0..a62511d6da 100644 --- a/common/util.h +++ b/common/util.h @@ -35,22 +35,20 @@ template inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; } #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0]))) -int RGBMatch(byte *palette, int r, int g, int b); -int Blend(int src, int dst, byte *palette); -void ClearBlendCache(); +namespace Common { /** - * Print a hexdump of the data passed in. The number of bytes per line - * is customizable. + * Print a hexdump of the data passed in. The number of bytes per line is + * customizable. * @param data the data to be dumped * @param len the lenght of that data * @param bytes_per_line number of bytes to print per line (default: 16) */ -void hexdump(const byte * data, int len, int bytes_per_line = 16); +void hexdump(const byte * data, int len, int bytesPerLine = 16); /** - * A simple random number generator. Although it is definitely not suitable - * for cryptographic purposes, it serves our purposes just fine. + * Simple random number generator. Although it is definitely not suitable for + * cryptographic purposes, it serves our purposes just fine. */ class RandomSource { private: @@ -88,6 +86,8 @@ public: ~StackLock(); }; +} // End of namespace Common + #if defined(__GNUC__) diff --git a/scumm/script_v5.cpp b/scumm/script_v5.cpp index b06830ce08..857883cfa2 100644 --- a/scumm/script_v5.cpp +++ b/scumm/script_v5.cpp @@ -907,7 +907,7 @@ void ScummEngine_v5::saveVars() { void ScummEngine_v5::loadVars() { int a, b; - hexdump(_scriptPointer, 64); +// Common::hexdump(_scriptPointer, 64); while ((_opcode = fetchScriptByte()) != 0) { switch (_opcode & 0x1F) { case 0x01: // read a range of variables diff --git a/scumm/scumm.h b/scumm/scumm.h index 56fded1b2b..d6664263e9 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -362,7 +362,7 @@ protected: public: /* Random number generation */ - RandomSource _rnd; + Common::RandomSource _rnd; /* Core variable definitions */ byte _gameId; diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 9a23af9d6d..9bf268886c 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -296,7 +296,6 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst) _confirmExitDialog = NULL; _debuggerDialog = NULL; _fastMode = 0; - memset(&_rnd, 0, sizeof(RandomSource)); _gameId = 0; memset(&gdi, 0, sizeof(Gdi)); _actors = NULL; diff --git a/simon/simon.h b/simon/simon.h index e9a4ce92c0..c5f47671f2 100644 --- a/simon/simon.h +++ b/simon/simon.h @@ -347,7 +347,7 @@ protected: byte *_sdl_buf; byte *_sdl_buf_attached; - RandomSource _rnd; + Common::RandomSource _rnd; byte *_vc_10_base_ptr_old; byte _hebrew_char_widths[32]; diff --git a/sky/logic.h b/sky/logic.h index 52dfa4bb04..8b0859591b 100644 --- a/sky/logic.h +++ b/sky/logic.h @@ -255,7 +255,7 @@ protected: uint32 _currentSection; - RandomSource _rnd; + Common::RandomSource _rnd; SkyScreen *_skyScreen; SkyDisk *_skyDisk; diff --git a/sound/mixer.cpp b/sound/mixer.cpp index a8d611588f..a46ad18db7 100644 --- a/sound/mixer.cpp +++ b/sound/mixer.cpp @@ -161,18 +161,18 @@ bool SoundMixer::bindToSystem(OSystem *syst) { } void SoundMixer::setupPremix(PremixProc *proc, void *param) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); _premixParam = param; _premixProc = proc; } int SoundMixer::newStream(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, uint32 buffer_size, byte volume, int8 pan) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); return insertChannel(handle, new ChannelStream(this, handle, sound, size, rate, flags, buffer_size, volume, pan)); } void SoundMixer::appendStream(PlayingSoundHandle handle, void *sound, uint32 size) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (handle == 0) return; @@ -198,7 +198,7 @@ void SoundMixer::appendStream(PlayingSoundHandle handle, void *sound, uint32 siz } void SoundMixer::endStream(PlayingSoundHandle handle) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); // Simply ignore stop requests for handles of sounds that already terminated if (handle == 0) @@ -245,7 +245,7 @@ int SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) { } int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, byte volume, int8 pan, uint32 loopStart, uint32 loopEnd) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); // Prevent duplicate sounds if (id != -1) { @@ -259,24 +259,24 @@ int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, ui #ifdef USE_MAD int SoundMixer::playMP3(PlayingSoundHandle *handle, File *file, uint32 size, byte volume, int8 pan) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); return insertChannel(handle, new ChannelMP3(this, handle, file, size, volume, pan)); } int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration, byte volume, int8 pan) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); return insertChannel(handle, new ChannelMP3CDMusic(this, handle, file, duration, volume, pan)); } #endif #ifdef USE_VORBIS int SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track, byte volume, int8 pan) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); return insertChannel(handle, new ChannelVorbis(this, handle, ov_file, duration, is_cd_track, volume, pan)); } #endif void SoundMixer::mix(int16 *buf, uint len) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (_premixProc && !_paused) { _premixProc(_premixParam, buf, len); @@ -302,7 +302,7 @@ void SoundMixer::mixCallback(void *s, byte *samples, int len) { } void SoundMixer::stopAll() { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) if (_channels[i]) _channels[i]->destroy(); @@ -314,13 +314,13 @@ void SoundMixer::stopChannel(int index) { return; } - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (_channels[index]) _channels[index]->destroy(); } void SoundMixer::stopID(int id) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) { if (_channels[i] != NULL && _channels[i]->_id == id) { _channels[i]->destroy(); @@ -330,7 +330,7 @@ void SoundMixer::stopID(int id) { } void SoundMixer::stopHandle(PlayingSoundHandle handle) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); // Simply ignore stop requests for handles of sounds that already terminated if (handle == 0) @@ -348,7 +348,7 @@ void SoundMixer::stopHandle(PlayingSoundHandle handle) { } void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (handle == 0) return; @@ -365,7 +365,7 @@ void SoundMixer::setChannelVolume(PlayingSoundHandle handle, byte volume) { } void SoundMixer::setChannelPan(PlayingSoundHandle handle, int8 pan) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (handle == 0) return; @@ -391,13 +391,13 @@ void SoundMixer::pauseChannel(int index, bool paused) { return; } - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (_channels[index]) _channels[index]->pause(paused); } void SoundMixer::pauseID(int id, bool paused) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) { if (_channels[i] != NULL && _channels[i]->_id == id) { _channels[i]->pause(paused); @@ -407,7 +407,7 @@ void SoundMixer::pauseID(int id, bool paused) { } void SoundMixer::pauseHandle(PlayingSoundHandle handle, bool paused) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); // Simply ignore pause/unpause requests for handles of sound that alreayd terminated if (handle == 0) @@ -429,7 +429,7 @@ bool SoundMixer::hasActiveSFXChannel() { // (and maybe also voice) here to work properly in iMuseDigital // games. In the past that was achieve using the _beginSlots hack. // Since we don't have that anymore, it's not that simple anymore. - StackLock lock(_mutex); + Common::StackLock lock(_mutex); for (int i = 0; i != NUM_CHANNELS; i++) if (_channels[i] && !_channels[i]->isMusicChannel()) return true; diff --git a/sound/mpu401.cpp b/sound/mpu401.cpp index aa798005ad..e6391016c7 100644 --- a/sound/mpu401.cpp +++ b/sound/mpu401.cpp @@ -126,7 +126,7 @@ MidiChannel *MidiDriver_MPU401::allocateChannel() { return NULL; } -void MidiDriver_MPU401::setTimerCallback (void *timer_param, TimerProc timer_proc) { +void MidiDriver_MPU401::setTimerCallback(void *timer_param, TimerProc timer_proc) { if (!_timer_proc || !timer_proc) { if (_timer_proc) g_timer->releaseProcedure(_timer_proc); diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index eb160b7e27..856cddf8c6 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -180,7 +180,7 @@ void Sound::reverseStereo(void) { // after the credits. void Sound::saveMusicState() { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); int saveStream; @@ -203,7 +203,7 @@ void Sound::saveMusicState() { } void Sound::restoreMusicState() { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); int restoreStream; @@ -272,7 +272,7 @@ int32 Sound::isFxOpen(int32 id) { } void Sound::fxServer(int16 *data, uint len) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (!_soundOn) return; @@ -899,7 +899,7 @@ uint8 Sound::isFxMute(void) { */ int32 Sound::streamCompMusic(const char *filename, uint32 musicId, bool looping) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); uint32 len; int32 primaryStream = -1; @@ -1062,7 +1062,7 @@ int32 Sound::dipMusic() { */ int32 Sound::musicTimeRemaining() { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); for (int i = 0; i < MAXMUS; i++) { if (_music[i]._streaming && !_music[i]._fading) @@ -1077,7 +1077,7 @@ int32 Sound::musicTimeRemaining() { */ void Sound::stopMusic(void) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); for (int i = 0; i < MAXMUS; i++) { if (_music[i]._streaming) @@ -1092,7 +1092,7 @@ void Sound::stopMusic(void) { */ void Sound::pauseMusic(void) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (_soundOn) { for (int i = 0; i < MAXMUS; i++) { @@ -1110,7 +1110,7 @@ void Sound::pauseMusic(void) { */ void Sound::unpauseMusic(void) { - StackLock lock(_mutex); + Common::StackLock lock(_mutex); if (_soundOn) { for (int i = 0; i < MAXMUS; i++) -- cgit v1.2.3