aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2011-05-14 14:10:05 +0200
committerBastien Bouclet2011-05-14 14:10:45 +0200
commit7cc82487d368fb94fc4e9e9ad16a80eb4536beda (patch)
tree111444d8108a3520831c206a6e2ccf07e1f898c1
parentcd54d761e10f5c8f24c5508ae22381ed71018abc (diff)
downloadscummvm-rg350-7cc82487d368fb94fc4e9e9ad16a80eb4536beda.tar.gz
scummvm-rg350-7cc82487d368fb94fc4e9e9ad16a80eb4536beda.tar.bz2
scummvm-rg350-7cc82487d368fb94fc4e9e9ad16a80eb4536beda.zip
MOHAWK: When running scripts in Myst, add delays when necessary between draws to mimic older hardware.
-rw-r--r--engines/mohawk/graphics.cpp43
-rw-r--r--engines/mohawk/graphics.h7
-rw-r--r--engines/mohawk/myst_scripts.cpp7
-rw-r--r--engines/mohawk/myst_stacks/channelwood.cpp4
-rw-r--r--engines/mohawk/myst_stacks/myst.cpp2
5 files changed, 58 insertions, 5 deletions
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp
index 9e02e70a22..b3653b1fdf 100644
--- a/engines/mohawk/graphics.cpp
+++ b/engines/mohawk/graphics.cpp
@@ -293,6 +293,9 @@ MystGraphics::MystGraphics(MohawkEngine_Myst* vm) : GraphicsManager(), _vm(vm) {
// Initialize our buffer
_backBuffer = new Graphics::Surface();
_backBuffer->create(_vm->_system->getWidth(), _vm->_system->getHeight(), _pixelFormat);
+
+ _nextAllowedDrawTime = _vm->_system->getMillis();
+ _enableDrawingTimeSimulation = 0;
}
MystGraphics::~MystGraphics() {
@@ -444,6 +447,8 @@ void MystGraphics::copyImageSectionToScreen(uint16 image, Common::Rect src, Comm
debug(3, "\twidth: %d", width);
debug(3, "\theight: %d", height);
+ simulatePreviousDrawDelay(dest);
+
_vm->_system->copyRectToScreen((byte *)surface->getBasePtr(src.left, top), surface->pitch, dest.left, dest.top, width, height);
}
@@ -499,10 +504,18 @@ void MystGraphics::copyImageToBackBuffer(uint16 image, Common::Rect dest) {
void MystGraphics::copyBackBufferToScreen(Common::Rect r) {
r.clip(_viewport);
+
+ simulatePreviousDrawDelay(r);
+
_vm->_system->copyRectToScreen((byte *)_backBuffer->getBasePtr(r.left, r.top), _backBuffer->pitch, r.left, r.top, r.width(), r.height());
}
void MystGraphics::runTransition(uint16 type, Common::Rect rect, uint16 steps, uint16 delay) {
+
+ // Do not artificially delay during transitions
+ int oldEnableDrawingTimeSimulation = _enableDrawingTimeSimulation;
+ _enableDrawingTimeSimulation = 0;
+
switch (type) {
case 0: {
debugC(kDebugScript, "Left to Right");
@@ -604,6 +617,8 @@ void MystGraphics::runTransition(uint16 type, Common::Rect rect, uint16 steps, u
_vm->_system->updateScreen();
break;
}
+
+ _enableDrawingTimeSimulation = oldEnableDrawingTimeSimulation;
}
void MystGraphics::drawRect(Common::Rect rect, RectState state) {
@@ -629,6 +644,34 @@ void MystGraphics::drawLine(const Common::Point &p1, const Common::Point &p2, ui
_backBuffer->drawLine(p1.x, p1.y, p2.x, p2.y, color);
}
+void MystGraphics::enableDrawingTimeSimulation(bool enable) {
+ if (enable)
+ _enableDrawingTimeSimulation++;
+ else
+ _enableDrawingTimeSimulation--;
+
+ if (_enableDrawingTimeSimulation < 0)
+ _enableDrawingTimeSimulation = 0;
+}
+
+void MystGraphics::simulatePreviousDrawDelay(const Common::Rect &dest) {
+ uint32 time = 0;
+
+ if (_enableDrawingTimeSimulation) {
+ time = _vm->_system->getMillis();
+
+ // Do not draw anything new too quickly after the previous draw call
+ // so that images stay at least a little while on screen
+ // This is enabled only for scripted draw calls
+ if (time < _nextAllowedDrawTime)
+ _vm->_system->delayMillis(_nextAllowedDrawTime - time);
+ }
+
+ // Next draw call allowed at DELAY + AERA * COEFF milliseconds from now
+ time = _vm->_system->getMillis();
+ _nextAllowedDrawTime = time + _constantDrawDelay + dest.height() * dest.width() / _proportionalDrawDelay;
+}
+
#endif // ENABLE_MYST
#ifdef ENABLE_RIVEN
diff --git a/engines/mohawk/graphics.h b/engines/mohawk/graphics.h
index e1f0b50078..d7057f48cf 100644
--- a/engines/mohawk/graphics.h
+++ b/engines/mohawk/graphics.h
@@ -128,10 +128,12 @@ public:
void runTransition(uint16 type, Common::Rect rect, uint16 steps, uint16 delay);
void drawRect(Common::Rect rect, RectState state);
void drawLine(const Common::Point &p1, const Common::Point &p2, uint32 color);
+ void enableDrawingTimeSimulation(bool enable);
protected:
MohawkSurface *decodeImage(uint16 id);
MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
+ void simulatePreviousDrawDelay(const Common::Rect &dest);
private:
MohawkEngine_Myst *_vm;
@@ -156,6 +158,11 @@ private:
Graphics::Surface *_backBuffer;
Graphics::PixelFormat _pixelFormat;
Common::Rect _viewport;
+
+ int _enableDrawingTimeSimulation;
+ uint32 _nextAllowedDrawTime;
+ static const uint _constantDrawDelay = 10; // ms
+ static const uint _proportionalDrawDelay = 500; // pixels per ms
};
#endif // ENABLE_MYST
diff --git a/engines/mohawk/myst_scripts.cpp b/engines/mohawk/myst_scripts.cpp
index 6148c48c60..a6351449b0 100644
--- a/engines/mohawk/myst_scripts.cpp
+++ b/engines/mohawk/myst_scripts.cpp
@@ -154,6 +154,11 @@ void MystScriptParser::setupCommonOpcodes() {
void MystScriptParser::runScript(MystScript script, MystResource *invokingResource) {
debugC(kDebugScript, "Script Size: %d", script->size());
+
+ // Scripted drawing takes more time to simulate older hardware
+ // This way opcodes can't overwrite what the previous ones drew too quickly
+ _vm->_gfx->enableDrawingTimeSimulation(true);
+
for (uint16 i = 0; i < script->size(); i++) {
MystScriptEntry &entry = script->operator[](i);
debugC(kDebugScript, "\tOpcode %d: %d", i, entry.opcode);
@@ -165,6 +170,8 @@ void MystScriptParser::runScript(MystScript script, MystResource *invokingResour
runOpcode(entry.opcode, entry.var, entry.argc, entry.argv);
}
+
+ _vm->_gfx->enableDrawingTimeSimulation(false);
}
void MystScriptParser::runOpcode(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
diff --git a/engines/mohawk/myst_stacks/channelwood.cpp b/engines/mohawk/myst_stacks/channelwood.cpp
index 2ed651fb9c..0dd69a673a 100644
--- a/engines/mohawk/myst_stacks/channelwood.cpp
+++ b/engines/mohawk/myst_stacks/channelwood.cpp
@@ -330,7 +330,7 @@ void Channelwood::o_drawImageChangeCardAndVolume(uint16 op, uint16 var, uint16 a
_vm->_gfx->copyImageToScreen(imageId, Common::Rect(0, 0, 544, 333));
_vm->_system->updateScreen();
- _vm->_system->delayMillis(10);
+
_vm->changeToCard(cardId, true);
if (argc == 3) {
@@ -348,7 +348,6 @@ void Channelwood::o_waterTankValveOpen(uint16 op, uint16 var, uint16 argc, uint1
for (uint16 imageId = 3601; imageId >= 3595; imageId--) {
_vm->_gfx->copyImageToScreen(imageId, rect);
_vm->_system->updateScreen();
- _vm->_system->delayMillis(5);
}
pipeChangeValve(true, 0x80);
@@ -663,7 +662,6 @@ void Channelwood::o_waterTankValveClose(uint16 op, uint16 var, uint16 argc, uint
for (uint16 imageId = 3595; imageId <= 3601; imageId++) {
_vm->_gfx->copyImageToScreen(imageId, rect);
_vm->_system->updateScreen();
- _vm->_system->delayMillis(5);
}
pipeChangeValve(false, 0x80);
diff --git a/engines/mohawk/myst_stacks/myst.cpp b/engines/mohawk/myst_stacks/myst.cpp
index 43cbdc85e4..f77ae753d9 100644
--- a/engines/mohawk/myst_stacks/myst.cpp
+++ b/engines/mohawk/myst_stacks/myst.cpp
@@ -859,7 +859,6 @@ void Myst::o_fireplaceToggleButton(uint16 op, uint16 var, uint16 argc, uint16 *a
for (uint i = 4795; i >= 4779; i--) {
_vm->_gfx->copyImageToScreen(i, _invokingResource->getRect());
_vm->_system->updateScreen();
- _vm->_system->delayMillis(1);
}
_fireplaceLines[var - 17] &= ~bitmask;
} else {
@@ -867,7 +866,6 @@ void Myst::o_fireplaceToggleButton(uint16 op, uint16 var, uint16 argc, uint16 *a
for (uint i = 4779; i <= 4795; i++) {
_vm->_gfx->copyImageToScreen(i, _invokingResource->getRect());
_vm->_system->updateScreen();
- _vm->_system->delayMillis(1);
}
_fireplaceLines[var - 17] |= bitmask;
}