[Scummvm-git-logs] scummvm master -> 43fb9ebb1b188578e272885a318bc57abed42de9
grechnik
diamondaz at yandex.ru
Tue Oct 16 00:04:12 CEST 2018
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
43fb9ebb1b LASTEXPRESS: drop sound thread
Commit: 43fb9ebb1b188578e272885a318bc57abed42de9
https://github.com/scummvm/scummvm/commit/43fb9ebb1b188578e272885a318bc57abed42de9
Author: Evgeny Grechnikov (diamondaz at yandex.ru)
Date: 2018-10-16T01:03:55+03:00
Commit Message:
LASTEXPRESS: drop sound thread
The backend runs its own sound thread anyway,
with the corresponding bookkeeping that we use.
We don't need yet another sound thread,
and it is always nice to not have something
that could change our structures from underneath us.
Changed paths:
engines/lastexpress/helpers.h
engines/lastexpress/lastexpress.cpp
engines/lastexpress/lastexpress.h
engines/lastexpress/sound/queue.cpp
engines/lastexpress/sound/queue.h
diff --git a/engines/lastexpress/helpers.h b/engines/lastexpress/helpers.h
index 6f94cf2..2331f2b 100644
--- a/engines/lastexpress/helpers.h
+++ b/engines/lastexpress/helpers.h
@@ -57,7 +57,6 @@
#define setGlobalTimer(timer) getLogic()->getGameState()->setTimer(timer)
#define setCoords(coords) getLogic()->getGameState()->setCoordinates(coords)
#define getCoords() getLogic()->getGameState()->getCoordinates()
-#define setFrameCount(count) _engine->setFrameCounter(count)
#define getFrameCount() _engine->getFrameCounter()
// Scenes
diff --git a/engines/lastexpress/lastexpress.cpp b/engines/lastexpress/lastexpress.cpp
index 91f8a6a..688d084 100644
--- a/engines/lastexpress/lastexpress.cpp
+++ b/engines/lastexpress/lastexpress.cpp
@@ -42,7 +42,6 @@
#include "common/debug-channels.h"
#include "common/error.h"
#include "common/fs.h"
-#include "common/timer.h"
#include "engines/util.h"
@@ -57,7 +56,7 @@ LastExpressEngine::LastExpressEngine(OSystem *syst, const ADGameDescription *gd)
Engine(syst), _gameDescription(gd),
_debugger(NULL), _random("lastexpress"), _cursor(NULL),
_font(NULL), _logic(NULL), _menu(NULL),
- _frameCounter(0), _lastFrameCount(0),
+ _lastFrameCount(0),
_graphicsMan(NULL), _resMan(NULL),
_sceneMan(NULL), _soundMan(NULL),
_eventMouse(NULL), _eventTick(NULL),
@@ -84,8 +83,6 @@ LastExpressEngine::LastExpressEngine(OSystem *syst, const ADGameDescription *gd)
}
LastExpressEngine::~LastExpressEngine() {
- _timer->removeTimerProc(&soundTimer);
-
// Delete the remaining objects
SAFE_DELETE(_cursor);
SAFE_DELETE(_font);
@@ -144,9 +141,8 @@ Common::Error LastExpressEngine::run() {
// Game logic
_logic = new Logic(this);
- // Start sound manager and setup timer
+ // Sound manager
_soundMan = new SoundManager(this);
- _timer->installTimerProc(&soundTimer, 17000, this, "lastexpressSound");
// Menu
_menu = new Menu(this);
@@ -163,6 +159,11 @@ Common::Error LastExpressEngine::run() {
return Common::kNoError;
}
+uint32 LastExpressEngine::getFrameCounter() const {
+ // the original game has a timer running at 60Hz incrementing a dedicated variable
+ return (uint64)_system->getMillis() * 60 / 1000;
+}
+
void LastExpressEngine::pollEvents() {
Common::Event ev;
if (!_eventMan->pollEvent(ev))
@@ -222,10 +223,13 @@ bool LastExpressEngine::handleEvents() {
getGameLogic()->getGameState()->getGameFlags()->mouseLeftClick = true;
getGameLogic()->getGameState()->getGameFlags()->mouseLeftPressed = (ev.type == Common::EVENT_LBUTTONDOWN) ? true : false;
- // Adjust frameInterval flag
- if (_frameCounter < _lastFrameCount + 30)
- getGameLogic()->getGameState()->getGameFlags()->frameInterval = true;
- _lastFrameCount = _frameCounter;
+ {
+ // Adjust frameInterval flag
+ uint32 frameCounter = getFrameCounter();
+ if (frameCounter < _lastFrameCount + 30)
+ getGameLogic()->getGameState()->getGameFlags()->frameInterval = true;
+ _lastFrameCount = frameCounter;
+ }
if (_eventMouse && _eventMouse->isValid())
(*_eventMouse)(ev);
@@ -273,21 +277,6 @@ bool LastExpressEngine::handleEvents() {
}
///////////////////////////////////////////////////////////////////////////////////
-/// Timer
-///////////////////////////////////////////////////////////////////////////////////
-void LastExpressEngine::soundTimer(void *refCon) {
- ((LastExpressEngine *)refCon)->handleSoundTimer();
-}
-
-void LastExpressEngine::handleSoundTimer() {
- if (_frameCounter & 1)
- if (_soundMan)
- _soundMan->getQueue()->handleTimer();
-
- _frameCounter++;
-}
-
-///////////////////////////////////////////////////////////////////////////////////
/// Event Handling
///////////////////////////////////////////////////////////////////////////////////
void LastExpressEngine::backupEventHandlers() {
diff --git a/engines/lastexpress/lastexpress.h b/engines/lastexpress/lastexpress.h
index b33784b..11fa8c7 100644
--- a/engines/lastexpress/lastexpress.h
+++ b/engines/lastexpress/lastexpress.h
@@ -104,13 +104,8 @@ public:
bool isDemo() const;
// Frame Counter
- uint32 getFrameCounter() { return _frameCounter; }
- void setFrameCounter(uint32 count) { _frameCounter = count; }
-
-protected:
- // Sound Timer
- static void soundTimer(void *ptr);
- void handleSoundTimer();
+ // TODO: all callers could use _system->getMillis() directly without extra conversions
+ uint32 getFrameCounter() const;
private:
const ADGameDescription *_gameDescription;
@@ -127,7 +122,6 @@ private:
Menu *_menu;
// Frame counter
- uint32 _frameCounter;
uint32 _lastFrameCount;
// Managers
diff --git a/engines/lastexpress/sound/queue.cpp b/engines/lastexpress/sound/queue.cpp
index 84b6e69..ce71536 100644
--- a/engines/lastexpress/sound/queue.cpp
+++ b/engines/lastexpress/sound/queue.cpp
@@ -60,30 +60,6 @@ SoundQueue::~SoundQueue() {
}
//////////////////////////////////////////////////////////////////////////
-// Timer
-//////////////////////////////////////////////////////////////////////////
-void SoundQueue::handleTimer() {
- Common::StackLock locker(_mutex);
-
- for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
- SoundEntry *entry = (*i);
- if (entry == NULL)
- error("[SoundQueue::handleTimer] Invalid entry found in sound queue");
-
- // When the entry has stopped playing, we remove his buffer
- if (entry->isFinished()) {
- entry->close();
- SAFE_DELETE(entry);
- i = _soundList.reverse_erase(i);
- continue;
- }
-
- // Queue the entry data, applying filtering
- entry->play();
- }
-}
-
-//////////////////////////////////////////////////////////////////////////
// Sound queue management
//////////////////////////////////////////////////////////////////////////
void SoundQueue::addToQueue(SoundEntry *entry) {
@@ -91,24 +67,18 @@ void SoundQueue::addToQueue(SoundEntry *entry) {
}
void SoundQueue::removeFromQueue(EntityIndex entity) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(entity);
if (entry)
entry->reset();
}
void SoundQueue::removeFromQueue(Common::String filename) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(filename);
if (entry)
entry->reset();
}
void SoundQueue::updateQueue() {
- Common::StackLock locker(_mutex);
-
++_flag;
if (getSoundState() & kSoundState1) {
@@ -136,7 +106,19 @@ void SoundQueue::updateQueue() {
entry->close();
SAFE_DELETE(entry);
it = _soundList.reverse_erase(it);
+ continue;
}
+
+ // When the entry has stopped playing, we remove his buffer
+ if (entry->isFinished()) {
+ entry->close();
+ SAFE_DELETE(entry);
+ it = _soundList.reverse_erase(it);
+ continue;
+ }
+
+ // Queue the entry data, applying filtering
+ entry->play();
}
// Original update the current entry, loading another set of samples to be decoded
@@ -147,8 +129,6 @@ void SoundQueue::updateQueue() {
}
void SoundQueue::resetQueue() {
- Common::StackLock locker(_mutex);
-
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
if ((*i)->getType() == kSoundType1) {
(*i)->reset();
@@ -168,8 +148,6 @@ void SoundQueue::resetQueue(SoundType type1, SoundType type2) {
if (!type2)
type2 = type1;
- Common::StackLock locker(_mutex);
-
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
if ((*i)->getType() != type1 && (*i)->getType() != type2)
(*i)->reset();
@@ -177,8 +155,6 @@ void SoundQueue::resetQueue(SoundType type1, SoundType type2) {
}
void SoundQueue::clearQueue() {
- Common::StackLock locker(_mutex);
-
_flag |= 8;
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
@@ -200,8 +176,6 @@ void SoundQueue::clearQueue() {
// State
//////////////////////////////////////////////////////////////////////////
void SoundQueue::clearStatus() {
- Common::StackLock locker(_mutex);
-
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
(*i)->setStatus((*i)->getStatus() | kSoundFlagCloseRequested);
}
@@ -210,16 +184,12 @@ void SoundQueue::clearStatus() {
// Entry management
//////////////////////////////////////////////////////////////////////////
void SoundQueue::setupEntry(SoundType type, EntityIndex index) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(type);
if (entry)
entry->setEntity(index);
}
void SoundQueue::processEntry(EntityIndex entity) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(entity);
if (entry) {
entry->update(0);
@@ -228,16 +198,12 @@ void SoundQueue::processEntry(EntityIndex entity) {
}
void SoundQueue::processEntry(SoundType type) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(type);
if (entry)
entry->update(0);
}
void SoundQueue::processEntry(Common::String filename) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(filename);
if (entry) {
entry->update(0);
@@ -283,8 +249,6 @@ SoundEntry *SoundQueue::getEntry(SoundType type) {
}
uint32 SoundQueue::getEntryTime(EntityIndex index) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(index);
if (entry)
return entry->getTime();
@@ -293,14 +257,10 @@ uint32 SoundQueue::getEntryTime(EntityIndex index) {
}
bool SoundQueue::isBuffered(EntityIndex entity) {
- Common::StackLock locker(_mutex);
-
return (getEntry(entity) != NULL);
}
bool SoundQueue::isBuffered(Common::String filename, bool testForEntity) {
- Common::StackLock locker(_mutex);
-
SoundEntry *entry = getEntry(filename);
if (testForEntity)
@@ -313,8 +273,6 @@ bool SoundQueue::isBuffered(Common::String filename, bool testForEntity) {
// Subtitles
//////////////////////////////////////////////////////////////////////////
void SoundQueue::updateSubtitles() {
- Common::StackLock locker(_mutex);
-
uint32 index = 0;
SubtitleEntry *subtitle = NULL;
@@ -363,8 +321,6 @@ void SoundQueue::updateSubtitles() {
// Savegame
//////////////////////////////////////////////////////////////////////////
void SoundQueue::saveLoadWithSerializer(Common::Serializer &s) {
- Common::StackLock locker(_mutex);
-
s.syncAsUint32LE(_state);
s.syncAsUint32LE(_currentType);
@@ -391,12 +347,7 @@ void SoundQueue::saveLoadWithSerializer(Common::Serializer &s) {
}
-// FIXME: We probably need another mutex here to protect during the whole savegame process
-// as we could have removed an entry between the time we check the count and the time we
-// save the entries
uint32 SoundQueue::count() {
- Common::StackLock locker(_mutex);
-
uint32 numEntries = 0;
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
if ((*i)->getName2().matchString("NISSND?"))
@@ -409,8 +360,6 @@ uint32 SoundQueue::count() {
// Debug
//////////////////////////////////////////////////////////////////////////
void SoundQueue::stopAllSound() {
- Common::StackLock locker(_mutex);
-
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
(*i)->getSoundStream()->stop();
}
diff --git a/engines/lastexpress/sound/queue.h b/engines/lastexpress/sound/queue.h
index 60c4475..1c73f57 100644
--- a/engines/lastexpress/sound/queue.h
+++ b/engines/lastexpress/sound/queue.h
@@ -40,9 +40,6 @@ public:
SoundQueue(LastExpressEngine *engine);
~SoundQueue();
- // Timer
- void handleTimer();
-
// Queue
void addToQueue(SoundEntry *entry);
void removeFromQueue(Common::String filename);
@@ -96,8 +93,6 @@ protected:
private:
LastExpressEngine *_engine;
- Common::Mutex _mutex;
-
// State & shared data
int _state;
SoundType _currentType;
More information about the Scummvm-git-logs
mailing list