Skip to content
Permalink
Browse files

DIRECTOR: Moved event processor to events.cpp

  • Loading branch information
sev- committed Mar 9, 2017
1 parent bd54615 commit 4c3f07b3e066cb6ab5d6d9b6fe4dd106a79cc530
@@ -102,6 +102,8 @@ class DirectorEngine : public ::Engine {
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; }
@@ -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
@@ -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();
@@ -5,6 +5,7 @@ MODULE_OBJS = \
cast.o \
detection.o \
director.o \
events.o \
frame.o \
graphics.o \
images.o \
@@ -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();
}
}

@@ -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,95 +962,19 @@ 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();
}
}
}

_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);
@@ -67,7 +67,6 @@ class Score {
void gotoNext();
void gotoPrevious();
void startLoop();
void processEvents();
Archive *getArchive() const { return _movieArchive; };
void loadConfig(Common::SeekableSubReadStreamEndian &stream);
void loadCastDataVWCR(Common::SeekableSubReadStreamEndian &stream);
@@ -34,6 +34,8 @@ char *numToCastNum(int num);

Common::String *toLowercaseMac(Common::String *s);

void processQuitEvent(); // events.cpp

} // End of namespace Director

#endif

0 comments on commit 4c3f07b

Please sign in to comment.
You can’t perform that action at this time.