aboutsummaryrefslogtreecommitdiff
path: root/engines/director
diff options
context:
space:
mode:
Diffstat (limited to 'engines/director')
-rw-r--r--engines/director/director.h2
-rw-r--r--engines/director/events.cpp124
-rw-r--r--engines/director/frame.cpp16
-rw-r--r--engines/director/module.mk1
-rw-r--r--engines/director/movie.cpp3
-rw-r--r--engines/director/score.cpp92
-rw-r--r--engines/director/score.h1
-rw-r--r--engines/director/util.h2
8 files changed, 147 insertions, 94 deletions
diff --git a/engines/director/director.h b/engines/director/director.h
index 5b1e9b36eb..2f0b65288f 100644
--- a/engines/director/director.h
+++ b/engines/director/director.h
@@ -102,6 +102,8 @@ public:
Archive *createArchive();
void cleanupMainArchive();
+ void processEvents(); // evetns.cpp
+
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *getSharedDIB() const { return _sharedDIB; }
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *getSharedBMP() const { return _sharedBMP; }
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *getSharedSTXT() const { return _sharedSTXT; }
diff --git a/engines/director/events.cpp b/engines/director/events.cpp
new file mode 100644
index 0000000000..613e83c352
--- /dev/null
+++ b/engines/director/events.cpp
@@ -0,0 +1,124 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/system.h"
+#include "common/events.h"
+
+#include "director/director.h"
+#include "director/frame.h"
+#include "director/score.h"
+#include "director/sprite.h"
+#include "director/lingo/lingo.h"
+
+namespace Director {
+
+void processQuitEvent() {
+ Common::Event event;
+
+ while (g_system->getEventManager()->pollEvent(event)) {
+ if (event.type == Common::EVENT_QUIT)
+ g_director->getCurrentScore()->_stopPlay = true;
+ }
+}
+
+void DirectorEngine::processEvents() {
+ Common::Event event;
+
+ uint endTime = g_system->getMillis() + 200;
+
+ Score *sc = getCurrentScore();
+ int currentFrame = sc->getCurrentFrame();
+ uint16 spriteId = 0;
+
+ // TODO: re-instate when we know which script to run.
+ //if (currentFrame > 0)
+ // _lingo->processEvent(kEventIdle, currentFrame - 1);
+
+ while (g_system->getMillis() < endTime) {
+ while (g_system->getEventManager()->pollEvent(event)) {
+ if (event.type == Common::EVENT_QUIT)
+ sc->_stopPlay = true;
+
+ if (event.type == Common::EVENT_LBUTTONDOWN) {
+ Common::Point pos = g_system->getEventManager()->getMousePos();
+
+ // D3 doesn't have both mouse up and down.
+ // But we still want to know if the mouse is down for press effects.
+ spriteId = sc->_frames[currentFrame]->getSpriteIDFromPos(pos);
+ sc->_currentMouseDownSpriteId = spriteId;
+
+ if (getVersion() > 3) {
+ // TODO: check that this is the order of script execution!
+ _lingo->processEvent(kEventMouseDown, kCastScript, sc->_frames[currentFrame]->_sprites[spriteId]->_castId);
+ _lingo->processEvent(kEventMouseDown, kSpriteScript, sc->_frames[currentFrame]->_sprites[spriteId]->_scriptId);
+ }
+ }
+
+ if (event.type == Common::EVENT_LBUTTONUP) {
+ Common::Point pos = g_system->getEventManager()->getMousePos();
+
+ spriteId = sc->_frames[currentFrame]->getSpriteIDFromPos(pos);
+ if (getVersion() > 3) {
+ // TODO: check that this is the order of script execution!
+ _lingo->processEvent(kEventMouseUp, kCastScript, sc->_frames[currentFrame]->_sprites[spriteId]->_castId);
+ _lingo->processEvent(kEventMouseUp, kSpriteScript, sc->_frames[currentFrame]->_sprites[spriteId]->_scriptId);
+ } else {
+ // Frame script overrides sprite script
+ if (!sc->_frames[currentFrame]->_sprites[spriteId]->_scriptId)
+ _lingo->processEvent(kEventMouseUp, kSpriteScript, sc->_frames[currentFrame]->_sprites[spriteId]->_castId + 1024);
+ else
+ _lingo->processEvent(kEventMouseUp, kFrameScript, sc->_frames[currentFrame]->_sprites[spriteId]->_scriptId);
+ }
+ }
+
+ if (event.type == Common::EVENT_KEYDOWN) {
+ _keyCode = event.kbd.keycode;
+ _key = (unsigned char)(event.kbd.ascii & 0xff);
+
+ switch (_keyCode) {
+ case Common::KEYCODE_LEFT:
+ _keyCode = 123;
+ break;
+ case Common::KEYCODE_RIGHT:
+ _keyCode = 124;
+ break;
+ case Common::KEYCODE_DOWN:
+ _keyCode = 125;
+ break;
+ case Common::KEYCODE_UP:
+ _keyCode = 126;
+ break;
+ default:
+ warning("Keycode: %d", _keyCode);
+ }
+
+ // TODO: is movie script correct? Can this be elsewhere?
+ _lingo->processEvent(kEventKeyDown, kMovieScript, 0);
+ }
+ }
+
+ g_system->updateScreen();
+ g_system->delayMillis(10);
+ }
+}
+
+} // End of namespace Director
diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp
index 50627d6d16..7690a47893 100644
--- a/engines/director/frame.cpp
+++ b/engines/director/frame.cpp
@@ -415,7 +415,7 @@ void Frame::playTransition(Score *score) {
r.setHeight(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, 0, 0, r.width(), r.height());
g_system->updateScreen();
@@ -431,7 +431,7 @@ void Frame::playTransition(Score *score) {
r.setHeight(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, 0, score->_movieRect.height() - stepSize * i, r.width(), r.height());
g_system->updateScreen();
@@ -446,7 +446,7 @@ void Frame::playTransition(Score *score) {
r.setWidth(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, 0, 0, r.width(), r.height());
g_system->updateScreen();
@@ -461,7 +461,7 @@ void Frame::playTransition(Score *score) {
r.setWidth(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, score->_movieRect.width() - stepSize * i, 0, r.width(), r.height());
g_system->updateScreen();
@@ -477,7 +477,7 @@ void Frame::playTransition(Score *score) {
r.setHeight(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, score->_movieRect.width() - stepSize * i, score->_movieRect.height() - stepSize * i, r.width(), r.height());
g_system->updateScreen();
@@ -493,7 +493,7 @@ void Frame::playTransition(Score *score) {
r.setHeight(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, 0, score->_movieRect.height() - stepSize * i, r.width(), r.height());
g_system->updateScreen();
@@ -509,7 +509,7 @@ void Frame::playTransition(Score *score) {
r.setHeight(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, score->_movieRect.width() - stepSize * i, 0, r.width(), r.height());
g_system->updateScreen();
@@ -525,7 +525,7 @@ void Frame::playTransition(Score *score) {
r.setHeight(stepSize * i);
g_system->delayMillis(stepDuration);
- score->processEvents();
+ processQuitEvent();
g_system->copyRectToScreen(score->_surface->getPixels(), score->_surface->pitch, 0, 0, r.width(), r.height());
g_system->updateScreen();
diff --git a/engines/director/module.mk b/engines/director/module.mk
index 07a7a28c85..28260ea5c3 100644
--- a/engines/director/module.mk
+++ b/engines/director/module.mk
@@ -5,6 +5,7 @@ MODULE_OBJS = \
cast.o \
detection.o \
director.o \
+ events.o \
frame.o \
graphics.o \
images.o \
diff --git a/engines/director/movie.cpp b/engines/director/movie.cpp
index 5d7b60efae..561ab06145 100644
--- a/engines/director/movie.cpp
+++ b/engines/director/movie.cpp
@@ -25,6 +25,7 @@
#include "director/movie.h"
#include "director/score.h"
+#include "director/util.h"
namespace Director {
@@ -51,7 +52,7 @@ void Movie::play(Common::Point dest) {
g_system->updateScreen();
}
g_system->delayMillis(10);
- _vm->getCurrentScore()->processEvents();
+ processQuitEvent();
}
}
diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index e8e8b81452..1ba0ab4683 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -680,7 +680,7 @@ void Score::gotoLoop() {
}
}
- g_director->_skipFrameAdvance = true;
+ _vm->_skipFrameAdvance = true;
}
int Score::getCurrentLabelNumber() {
@@ -700,14 +700,14 @@ void Score::gotoNext() {
// we can just try to use the current frame and get the next label
_currentFrame = getNextLabelNumber(_currentFrame);
- g_director->_skipFrameAdvance = true;
+ _vm->_skipFrameAdvance = true;
}
void Score::gotoPrevious() {
// we actually need the frame of the label prior to the most recent label.
_currentFrame = getPreviousLabelNumber(getCurrentLabelNumber());
- g_director->_skipFrameAdvance = true;
+ _vm->_skipFrameAdvance = true;
}
int Score::getNextLabelNumber(int referenceFrame) {
@@ -891,7 +891,7 @@ void Score::startLoop() {
while (!_stopPlay && _currentFrame < _frames.size()) {
debugC(1, kDebugImages, "****************************** Current frame: %d", _currentFrame + 1);
update();
- processEvents();
+ _vm->processEvents();
}
}
@@ -930,10 +930,10 @@ void Score::update() {
}
}
- if (!g_director->_playbackPaused && !g_director->_skipFrameAdvance)
+ if (!_vm->_playbackPaused && !_vm->_skipFrameAdvance)
_currentFrame++;
- g_director->_skipFrameAdvance = false;
+ _vm->_skipFrameAdvance = false;
if (_currentFrame >= _frames.size())
return;
@@ -962,12 +962,12 @@ void Score::update() {
} else if (tempo == 135) {
// Wait for sound channel 1
while (_soundManager->isChannelActive(1)) {
- processEvents();
+ _vm->processEvents();
}
} else if (tempo == 134) {
// Wait for sound channel 2
while (_soundManager->isChannelActive(2)) {
- processEvents();
+ _vm->processEvents();
}
}
}
@@ -975,82 +975,6 @@ void Score::update() {
_nextFrameTime = g_system->getMillis() + (float)_currentFrameRate / 60 * 1000;
}
-void Score::processEvents() {
- // TODO: re-instate when we know which script to run.
- //if (_currentFrame > 0)
- // _lingo->processEvent(kEventIdle, _currentFrame - 1);
-
- Common::Event event;
-
- uint endTime = g_system->getMillis() + 200;
-
- while (g_system->getMillis() < endTime) {
- while (g_system->getEventManager()->pollEvent(event)) {
- if (event.type == Common::EVENT_QUIT)
- _stopPlay = true;
-
- if (event.type == Common::EVENT_LBUTTONDOWN) {
- Common::Point pos = g_system->getEventManager()->getMousePos();
-
- // D3 doesn't have both mouse up and down.
- // But we still want to know if the mouse is down for press effects.
- _currentMouseDownSpriteId = _frames[_currentFrame]->getSpriteIDFromPos(pos);
-
- if (_vm->getVersion() > 3) {
- // TODO: check that this is the order of script execution!
- _lingo->processEvent(kEventMouseDown, kCastScript, _frames[_currentFrame]->_sprites[_currentMouseDownSpriteId]->_castId);
- _lingo->processEvent(kEventMouseDown, kSpriteScript, _frames[_currentFrame]->_sprites[_currentMouseDownSpriteId]->_scriptId);
- }
- }
-
- if (event.type == Common::EVENT_LBUTTONUP) {
- Common::Point pos = g_system->getEventManager()->getMousePos();
-
- uint16 spriteId = _frames[_currentFrame]->getSpriteIDFromPos(pos);
- if (_vm->getVersion() > 3) {
- // TODO: check that this is the order of script execution!
- _lingo->processEvent(kEventMouseUp, kCastScript, _frames[_currentFrame]->_sprites[spriteId]->_castId);
- _lingo->processEvent(kEventMouseUp, kSpriteScript, _frames[_currentFrame]->_sprites[spriteId]->_scriptId);
- } else {
- // Frame script overrides sprite script
- if (!_frames[_currentFrame]->_sprites[spriteId]->_scriptId)
- _lingo->processEvent(kEventMouseUp, kSpriteScript, _frames[_currentFrame]->_sprites[spriteId]->_castId + 1024);
- else
- _lingo->processEvent(kEventMouseUp, kFrameScript, _frames[_currentFrame]->_sprites[spriteId]->_scriptId);
- }
- }
-
- if (event.type == Common::EVENT_KEYDOWN) {
- _vm->_keyCode = event.kbd.keycode;
- _vm->_key = (unsigned char)(event.kbd.ascii & 0xff);
-
- switch (_vm->_keyCode) {
- case Common::KEYCODE_LEFT:
- _vm->_keyCode = 123;
- break;
- case Common::KEYCODE_RIGHT:
- _vm->_keyCode = 124;
- break;
- case Common::KEYCODE_DOWN:
- _vm->_keyCode = 125;
- break;
- case Common::KEYCODE_UP:
- _vm->_keyCode = 126;
- break;
- default:
- warning("Keycode: %d", _vm->_keyCode);
- }
-
- // TODO: is movie script correct? Can this be elsewhere?
- _lingo->processEvent(kEventKeyDown, kMovieScript, 0);
- }
- }
-
- g_system->updateScreen();
- g_system->delayMillis(10);
- }
-}
-
Sprite *Score::getSpriteById(uint16 id) {
if (_currentFrame >= _frames.size() || _currentFrame < 0 || id >= _frames[_currentFrame]->_sprites.size()) {
warning("Score::getSpriteById(%d): out of bounds. frame: %d", id, _currentFrame);
diff --git a/engines/director/score.h b/engines/director/score.h
index 0a51d65a9a..3e7aa62c4f 100644
--- a/engines/director/score.h
+++ b/engines/director/score.h
@@ -67,7 +67,6 @@ public:
void gotoNext();
void gotoPrevious();
void startLoop();
- void processEvents();
Archive *getArchive() const { return _movieArchive; };
void loadConfig(Common::SeekableSubReadStreamEndian &stream);
void loadCastDataVWCR(Common::SeekableSubReadStreamEndian &stream);
diff --git a/engines/director/util.h b/engines/director/util.h
index 66f8074cfe..c31240052b 100644
--- a/engines/director/util.h
+++ b/engines/director/util.h
@@ -34,6 +34,8 @@ char *numToCastNum(int num);
Common::String *toLowercaseMac(Common::String *s);
+void processQuitEvent(); // events.cpp
+
} // End of namespace Director
#endif