From bbaebdf680179dca103b0ed635e791aa602d610d Mon Sep 17 00:00:00 2001 From: Marisa-Chan Date: Sat, 5 Jul 2014 17:27:08 +0000 Subject: ZVISION: Process events for controls similar to original engine, fix some errors. --- engines/zvision/core/events.cpp | 24 +++++--------------- engines/zvision/scripting/script_manager.cpp | 33 ++++++++++++++++++++++++++++ engines/zvision/scripting/script_manager.h | 6 +++++ engines/zvision/zvision.h | 2 -- 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp index 943f8ff279..c977125f55 100644 --- a/engines/zvision/core/events.cpp +++ b/engines/zvision/core/events.cpp @@ -46,13 +46,15 @@ void ZVision::processEvents() { case Common::EVENT_LBUTTONDOWN: _cursorManager->cursorDown(true); _scriptManager->setStateValue(StateKey_LMouse, 1); - onMouseDown(_event.mouse); + _menu->onMouseDown(_event.mouse); + _scriptManager->addEvent(_event); break; case Common::EVENT_LBUTTONUP: _cursorManager->cursorDown(false); _scriptManager->setStateValue(StateKey_LMouse, 0); - onMouseUp(_event.mouse); + _menu->onMouseUp(_event.mouse); + _scriptManager->addEvent(_event); break; case Common::EVENT_RBUTTONDOWN: @@ -87,10 +89,10 @@ void ZVision::processEvents() { break; } - _scriptManager->onKeyDown(_event.kbd); + _scriptManager->addEvent(_event); break; case Common::EVENT_KEYUP: - _scriptManager->onKeyUp(_event.kbd); + _scriptManager->addEvent(_event); break; default: break; @@ -98,20 +100,6 @@ void ZVision::processEvents() { } } -void ZVision::onMouseDown(const Common::Point &pos) { - _menu->onMouseDown(pos); - - Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); - _scriptManager->onMouseDown(pos, imageCoord); -} - -void ZVision::onMouseUp(const Common::Point &pos) { - _menu->onMouseUp(pos); - - Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); - _scriptManager->onMouseUp(pos, imageCoord); -} - void ZVision::onMouseMove(const Common::Point &pos) { _menu->onMouseMove(pos); Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); diff --git a/engines/zvision/scripting/script_manager.cpp b/engines/zvision/scripting/script_manager.cpp index fc765f0bfb..7c124b6eca 100644 --- a/engines/zvision/scripting/script_manager.cpp +++ b/engines/zvision/scripting/script_manager.cpp @@ -51,6 +51,7 @@ ScriptManager::~ScriptManager() { cleanScriptScope(world); cleanScriptScope(room); cleanScriptScope(nodeview); + _controlEvents.clear(); } void ScriptManager::initialize() { @@ -66,6 +67,8 @@ void ScriptManager::initialize() { parseScrFile("universe.scr", universe); changeLocation('g', 'a', 'r', 'y', 0); + + _controlEvents.clear(); } void ScriptManager::update(uint deltaTimeMillis) { @@ -151,6 +154,32 @@ void ScriptManager::updateNodes(uint deltaTimeMillis) { void ScriptManager::updateControls(uint deltaTimeMillis) { if (!_activeControls) return; + + // Process only one event + if (!_controlEvents.empty()) { + Common::Event _event = _controlEvents.front(); + Common::Point imageCoord; + switch (_event.type) { + case Common::EVENT_LBUTTONDOWN: + imageCoord = _engine->getRenderManager()->screenSpaceToImageSpace(_event.mouse); + onMouseDown(_event.mouse, imageCoord); + break; + case Common::EVENT_LBUTTONUP: + imageCoord = _engine->getRenderManager()->screenSpaceToImageSpace(_event.mouse); + onMouseUp(_event.mouse, imageCoord); + break; + case Common::EVENT_KEYDOWN: + onKeyDown(_event.kbd); + break; + case Common::EVENT_KEYUP: + onKeyUp(_event.kbd); + break; + default: + break; + } + _controlEvents.pop_front(); + } + for (ControlList::iterator iter = _activeControls->begin(); iter != _activeControls->end(); iter++) (*iter)->process(deltaTimeMillis); } @@ -693,6 +722,10 @@ Location ScriptManager::getCurrentLocation() const { return location; } +void ScriptManager::addEvent(Common::Event event) { + _controlEvents.push_back(event); +} + ValueSlot::ValueSlot(ScriptManager *sc_man, const char *slot_val): _sc_man(sc_man) { value = 0; diff --git a/engines/zvision/scripting/script_manager.h b/engines/zvision/scripting/script_manager.h index 8ec364b35f..316b50ab26 100644 --- a/engines/zvision/scripting/script_manager.h +++ b/engines/zvision/scripting/script_manager.h @@ -29,6 +29,7 @@ #include "common/hashmap.h" #include "common/queue.h" +#include "common/events.h" namespace Common { @@ -111,6 +112,7 @@ typedef Common::Queue PuzzleQueue; typedef Common::List ControlList; typedef Common::HashMap StateMap; typedef Common::List SideFXList; +typedef Common::List EventList; class ScriptManager { public: @@ -152,6 +154,8 @@ private: /** Holds the currently active controls */ ControlList *_activeControls; + EventList _controlEvents; + script_scope universe; script_scope world; script_scope room; @@ -192,6 +196,8 @@ public: void killSideFx(uint32 key); void killSideFxType(SideFX::SideFXType type); + void addEvent(Common::Event); + /** * Called when LeftMouse is pushed. * diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index db2c646fda..57e7339da6 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -179,8 +179,6 @@ private: /** Called every frame from ZVision::run() to process any events from EventMan */ void processEvents(); - void onMouseDown(const Common::Point &pos); - void onMouseUp(const Common::Point &pos); void onMouseMove(const Common::Point &pos); void updateRotation(); }; -- cgit v1.2.3