From e821fd789ce8da9e9012dd527487b34d59b1a702 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 3 Jun 2016 21:58:25 +0200 Subject: MACVENTURE: Add initial game files --- engines/macventure/configure.engine | 3 +++ engines/macventure/detection.cpp | 29 +++++++++++++++++++++++++++++ engines/macventure/macventure.cpp | 21 +++++++++++++++++++++ engines/macventure/macventure.h | 21 +++++++++++++++++++++ engines/macventure/module.mk | 16 ++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 engines/macventure/configure.engine create mode 100644 engines/macventure/detection.cpp create mode 100644 engines/macventure/macventure.cpp create mode 100644 engines/macventure/macventure.h create mode 100644 engines/macventure/module.mk diff --git a/engines/macventure/configure.engine b/engines/macventure/configure.engine new file mode 100644 index 0000000000..bb4eb6ceb5 --- /dev/null +++ b/engines/macventure/configure.engine @@ -0,0 +1,3 @@ +# This file is included from the main "configure" script +# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] +add_engine macventure "MACVENTURE" no diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp new file mode 100644 index 0000000000..ac4a6e5817 --- /dev/null +++ b/engines/macventure/detection.cpp @@ -0,0 +1,29 @@ +/* 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 "base/plugins.h" + + namespace MacVenture { + + + + } // End of namespace MacVenture diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp new file mode 100644 index 0000000000..ae926f0a5c --- /dev/null +++ b/engines/macventure/macventure.cpp @@ -0,0 +1,21 @@ +/* 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. + * + */ diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h new file mode 100644 index 0000000000..ae926f0a5c --- /dev/null +++ b/engines/macventure/macventure.h @@ -0,0 +1,21 @@ +/* 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. + * + */ diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk new file mode 100644 index 0000000000..4c04159b3e --- /dev/null +++ b/engines/macventure/module.mk @@ -0,0 +1,16 @@ +MODULE := engines/macventure + +MODULE_OBJS := \ + detection.o \ + macventure.o + +MODULE_DIRS += \ + engines/macventure + +# This module can be built as a plugin +ifeq ($(ENABLE_WAGE), DYNAMIC_PLUGIN) +PLUGIN := 1 +endif + +# Include common rules +include $(srcdir)/rules.mk -- cgit v1.2.3 From 52d53c25515a93b9f129f0f7aa1d16918f6490d5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 4 Jun 2016 20:53:01 +0200 Subject: MACVENTURE: Add game detection for Shadowgate --- engines/macventure/detection.cpp | 52 +++++++++++++++++++++++++++++++++-- engines/macventure/detection_tables.h | 33 ++++++++++++++++++++++ engines/macventure/macventure.cpp | 21 ++++++++++++++ engines/macventure/macventure.h | 25 +++++++++++++++++ engines/macventure/module.mk | 2 +- 5 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 engines/macventure/detection_tables.h diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index ac4a6e5817..8fa5fab57d 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -20,10 +20,56 @@ * */ - #include "base/plugins.h" +#include "base/plugins.h" - namespace MacVenture { +#include "engines/advancedDetector.h" +#include "common/system.h" +#include "macventure/macventure.h" +namespace MacVenture { - } // End of namespace MacVenture +#include "macventure/detection_tables.h" + +static const PlainGameDescriptor macventureGames[] = { + { "Shadowgate", "Shadowgate" }, + { 0, 0 } +}; + +class MacVentureMetaEngine : public AdvancedMetaEngine { +public: + MacVentureMetaEngine() : AdvancedMetaEngine(MacVenture::gameDescriptions, sizeof(ADGameDescription), macventureGames) { + _guiOptions = GUIO0(); + _md5Bytes = 5000000; // TODO: Upper limit, adjust it once all games are added + } + + virtual const char * getName() const override { + return "MacVenture"; + } + virtual const char * getOriginalCopyright() const override { + return "(C) ICOM Simulations"; + } + + virtual bool createInstance(OSystem * syst, Engine ** engine, const ADGameDescription * desc) const; + virtual bool hasFeature(MetaEngineFeature f) const; +}; + +bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { + return false; +} + +bool MacVentureMetaEngine::createInstance(OSystem * syst, Engine ** engine, const ADGameDescription *game) const { + if (game) { + *engine = new MacVentureEngine(syst, game); + } + return game != 0; +} + + +} // End of namespace MacVenture + +#if PLUGIN_ENABLED_DYNAMIC(MACVENTURE) + REGISTER_PLUGIN_DYNAMIC(MACVENTURE, PLUGIN_TYPE_ENGINE, MacVenture::MacVentureMetaEngine); +#else + REGISTER_PLUGIN_STATIC(MACVENTURE, PLUGIN_TYPE_ENGINE, MacVenture::MacVentureMetaEngine); +#endif diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h new file mode 100644 index 0000000000..9aa9536c09 --- /dev/null +++ b/engines/macventure/detection_tables.h @@ -0,0 +1,33 @@ +/* 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. +* +*/ + +namespace MacVenture { + +#define ADGF_DEFAULT (ADGF_DROPLANGUAGE|ADGF_DROPPLATFORM) + +#define BASEGAME(n, v, f, md5, s) {n, v, AD_ENTRY1s(f, md5, s), Common::EN_ANY, Common::kPlatformMacintosh, ADGF_DEFAULT, GUIO0()} + +static const ADGameDescription gameDescriptions[] = { + BASEGAME("Shadowgate", "Zojoi Rerelease", "Shadowgate.dsk", "4e03e9ef1cd5f65ce1de14d512510537", 839680), // Zojoi Rerelease + AD_TABLE_END_MARKER +}; +} // End of namespace MacVenture diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index ae926f0a5c..06325f5eba 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -19,3 +19,24 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ + +#include "common/error.h" + +#include "engines/engine.h" + +#include "macventure/macventure.h" + +namespace MacVenture { + +MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst) { + _gameDescription = gameDesc; +} + +MacVentureEngine::~MacVentureEngine() { +} + +Common::Error MacVentureEngine::run() { + return Common::Error(); +} + +} // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index ae926f0a5c..d4ead54457 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -19,3 +19,28 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ + +#ifndef MACVENTURE_H +#define MACVENTURE_H + +#include "engines/engine.h" + +struct ADGameDescription; + +namespace MacVenture { + +class MacVentureEngine : public Engine { + +public: + MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc); + ~MacVentureEngine(); + + virtual Common::Error run(); + +private: + const ADGameDescription *_gameDescription; + +}; +} // End of namespace MacVenture + +#endif \ No newline at end of file diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 4c04159b3e..839cbb4587 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -8,7 +8,7 @@ MODULE_DIRS += \ engines/macventure # This module can be built as a plugin -ifeq ($(ENABLE_WAGE), DYNAMIC_PLUGIN) +ifeq ($(ENABLE_MACVENTURE), DYNAMIC_PLUGIN) PLUGIN := 1 endif -- cgit v1.2.3 From 6815b0546708fd2154e799f89d65c8724da7250b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 5 Jun 2016 20:44:26 +0200 Subject: MACVENTURE: Fix detection problem --- engines/macventure/detection.cpp | 2 +- engines/macventure/detection_tables.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 8fa5fab57d..feaf60d7c2 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -32,7 +32,7 @@ namespace MacVenture { #include "macventure/detection_tables.h" static const PlainGameDescriptor macventureGames[] = { - { "Shadowgate", "Shadowgate" }, + { "shadowgate", "Shadowgate" }, { 0, 0 } }; diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h index 9aa9536c09..9c9b91f696 100644 --- a/engines/macventure/detection_tables.h +++ b/engines/macventure/detection_tables.h @@ -27,7 +27,7 @@ namespace MacVenture { #define BASEGAME(n, v, f, md5, s) {n, v, AD_ENTRY1s(f, md5, s), Common::EN_ANY, Common::kPlatformMacintosh, ADGF_DEFAULT, GUIO0()} static const ADGameDescription gameDescriptions[] = { - BASEGAME("Shadowgate", "Zojoi Rerelease", "Shadowgate.dsk", "4e03e9ef1cd5f65ce1de14d512510537", 839680), // Zojoi Rerelease + BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.dsk", "4e03e9ef1cd5f65ce1de14d512510537", 839680), // Zojoi Rerelease AD_TABLE_END_MARKER }; } // End of namespace MacVenture -- cgit v1.2.3 From c6070c0d99215d2e0207feeffd8fdb9013af6bed Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 5 Jun 2016 20:45:14 +0200 Subject: MACVENTURE: Add empty engine --- engines/macventure/configure.engine | 2 +- engines/macventure/macventure.cpp | 37 +++++++++++++++++++++++++++++++++++-- engines/macventure/macventure.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/engines/macventure/configure.engine b/engines/macventure/configure.engine index bb4eb6ceb5..dc7cf7912c 100644 --- a/engines/macventure/configure.engine +++ b/engines/macventure/configure.engine @@ -1,3 +1,3 @@ # This file is included from the main "configure" script # add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] -add_engine macventure "MACVENTURE" no +add_engine macventure "MacVenture" no diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 06325f5eba..a031513f3d 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -20,9 +20,13 @@ * */ +#include "common/scummsys.h" + +#include "common/debug-channels.h" +#include "common/debug.h" #include "common/error.h" -#include "engines/engine.h" +#include "engines/util.h" #include "macventure/macventure.h" @@ -30,13 +34,42 @@ namespace MacVenture { MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst) { _gameDescription = gameDesc; + _rnd = new Common::RandomSource("macventure"); + + _debugger= NULL; + + debug("MacVenture::MacVentureEngine()"); } MacVentureEngine::~MacVentureEngine() { + debug("MacVenture::~MacVentureEngine()"); + + DebugMan.clearAllDebugChannels(); + delete _rnd; + delete _debugger; } Common::Error MacVentureEngine::run() { - return Common::Error(); + debug("MacVenture::MacVentureEngine::init()"); + + initGraphics(kScreenWidth, kScreenHeight, true); + + //_screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); + + //_wm = new Graphics::MacWindowManager(); + //_wm->setScreen(&_screen); + + // Create debugger console. It requires GFX to be initialized + _debugger = new Console(this); + + // Additional setup. + debug("MacVentureEngine::init"); + + // Your main even loop should be (invoked from) here. + debug("MacVentureEngine::go: Hello, World!"); + + + return Common::kNoError; } } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index d4ead54457..39574943c7 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -23,12 +23,34 @@ #ifndef MACVENTURE_H #define MACVENTURE_H +#include "common/debug.h" +#include "common/random.h" + #include "engines/engine.h" +#include "graphics/managed_surface.h" +#include "graphics/macgui/macwindowmanager.h" + +#include "gui/debugger.h" + struct ADGameDescription; namespace MacVenture { +class Console; + +enum { + kScreenWidth = 512, + kScreenHeight = 342 +}; + +enum { + kMacVentureDebugExample = 1 << 0, + kMacVentureDebugExample2 = 1 << 1 + // next new level must be 1 << 2 (4) + // the current limitation is 32 debug levels (1 << 31 is the last one) +}; + class MacVentureEngine : public Engine { public: @@ -39,7 +61,20 @@ public: private: const ADGameDescription *_gameDescription; + Common::RandomSource *_rnd; + + Console *_debugger; + + Graphics::MacWindowManager *_wm; + + Graphics::ManagedSurface _screen; +}; + +class Console : public GUI::Debugger { +public: + Console(MacVentureEngine *vm) {} + virtual ~Console(void) {} }; } // End of namespace MacVenture -- cgit v1.2.3 From d56f5a3bc43dd978244d17902e993704da8ace5e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 5 Jun 2016 20:55:29 +0200 Subject: MACVENTURE: Add empty event loop --- engines/macventure/macventure.cpp | 40 ++++++++++++++++++++++++++++++--------- engines/macventure/macventure.h | 6 +++++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index a031513f3d..8cf6ba01cd 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -20,8 +20,7 @@ * */ -#include "common/scummsys.h" - +#include "common/system.h" #include "common/debug-channels.h" #include "common/debug.h" #include "common/error.h" @@ -52,24 +51,47 @@ MacVentureEngine::~MacVentureEngine() { Common::Error MacVentureEngine::run() { debug("MacVenture::MacVentureEngine::init()"); - initGraphics(kScreenWidth, kScreenHeight, true); - - //_screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); - - //_wm = new Graphics::MacWindowManager(); - //_wm->setScreen(&_screen); + initGraphics(kScreenWidth, kScreenHeight, true); - // Create debugger console. It requires GFX to be initialized _debugger = new Console(this); // Additional setup. debug("MacVentureEngine::init"); + _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); + + _wm = new Graphics::MacWindowManager(); + _wm->setScreen(&_screen); + + // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); + _shouldQuit = false; + while (!_shouldQuit) { + processEvents(); + + debug("Ping"); + + g_system->updateScreen(); + g_system->delayMillis(50); + } return Common::kNoError; } +void MacVentureEngine::processEvents() { + Common::Event event; + + while (_eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_QUIT: + _shouldQuit = true; + break; + default: + break; + } + } +} + } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 39574943c7..ab29eedea7 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -59,6 +59,9 @@ public: virtual Common::Error run(); +private: + void processEvents(); + private: const ADGameDescription *_gameDescription; Common::RandomSource *_rnd; @@ -66,8 +69,9 @@ private: Console *_debugger; Graphics::MacWindowManager *_wm; - Graphics::ManagedSurface _screen; + + bool _shouldQuit; }; -- cgit v1.2.3 From 6f5997fec6a7fcf1f3a9875218f82a7fda73ac31 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 5 Jun 2016 21:20:13 +0200 Subject: MACVENTURE: Add naked window for tests --- engines/macventure/macventure.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 8cf6ba01cd..67efbc8e31 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -63,6 +63,10 @@ Common::Error MacVentureEngine::run() { _wm = new Graphics::MacWindowManager(); _wm->setScreen(&_screen); + _screen.fillRect(Common::Rect(0, 0, _screen.w, _screen.h), Graphics::kColorWhite); + + Graphics::MacWindow *w = _wm->addWindow(false, true, true); + w->setDimensions(Common::Rect(100, 100)); // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); @@ -71,7 +75,7 @@ Common::Error MacVentureEngine::run() { while (!_shouldQuit) { processEvents(); - debug("Ping"); + _wm->draw(); g_system->updateScreen(); g_system->delayMillis(50); -- cgit v1.2.3 From 322836699a87fb7ce334d1d99ed5df00e5ebac8b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 5 Jun 2016 21:34:23 +0200 Subject: MACVENTURE: Border Loading code --- engines/macventure/macventure.cpp | 56 +++++++++++++++++++++++++++++++++------ engines/macventure/macventure.h | 3 +++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 67efbc8e31..be949ec00a 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -25,6 +25,10 @@ #include "common/debug.h" #include "common/error.h" +// For border loading, should be gone later +#include "common/file.h" +#include "image/bmp.h" + #include "engines/util.h" #include "macventure/macventure.h" @@ -60,14 +64,8 @@ Common::Error MacVentureEngine::run() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); - _wm = new Graphics::MacWindowManager(); - _wm->setScreen(&_screen); - - _screen.fillRect(Common::Rect(0, 0, _screen.w, _screen.h), Graphics::kColorWhite); - - Graphics::MacWindow *w = _wm->addWindow(false, true, true); - w->setDimensions(Common::Rect(100, 100)); - + initGUI(); + // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); @@ -98,4 +96,46 @@ void MacVentureEngine::processEvents() { } } +void MacVentureEngine::initGUI() { + _wm = new Graphics::MacWindowManager(); + _wm->setScreen(&_screen); + Graphics::MacWindow *w = _wm->addWindow(false, true, true); + w->setDimensions(Common::Rect(100, 100)); + w->setActive(false); + + loadBorder(w, "border_inac.bmp", false); + +} + +void MacVentureEngine::loadBorder(Graphics::MacWindow *target, Common::String filename, bool active) { + Common::File borderfile; + + if (!borderfile.open(filename)) { + debug(1, "Cannot open border file"); + return; + } + + Image::BitmapDecoder bmpDecoder; + Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size()); + Graphics::Surface source; + Graphics::TransparentSurface *surface = new Graphics::TransparentSurface(); + + if (stream) { + debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename); + bmpDecoder.loadStream(*stream); + source = *(bmpDecoder.getSurface()); + + source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette()); + surface->create(source.w, source.h, source.format); + surface->copyFrom(source); + surface->applyColorKey(255, 0, 255, false); + + target->setBorder(*surface, active); + + borderfile.close(); + + delete stream; + } +} + } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index ab29eedea7..cdf50b7e91 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -62,6 +62,9 @@ public: private: void processEvents(); + void initGUI(); + void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + private: const ADGameDescription *_gameDescription; Common::RandomSource *_rnd; -- cgit v1.2.3 From f095c4a958af62d5f696f61243aca7a2c48f6ba7 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 8 Jun 2016 11:02:21 +0200 Subject: MACVENTURE: Extract GUI code --- engines/macventure/detection.cpp | 4 ++- engines/macventure/gui.cpp | 62 +++++++++++++++++++++++++++++++++++++++ engines/macventure/gui.h | 56 +++++++++++++++++++++++++++++++++++ engines/macventure/macventure.cpp | 58 ++++-------------------------------- engines/macventure/macventure.h | 10 +++---- engines/macventure/module.mk | 1 + 6 files changed, 131 insertions(+), 60 deletions(-) create mode 100644 engines/macventure/gui.cpp create mode 100644 engines/macventure/gui.h diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index feaf60d7c2..ade07a0853 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -27,6 +27,8 @@ #include "macventure/macventure.h" +#include "macventure.h" + namespace MacVenture { #include "macventure/detection_tables.h" @@ -37,7 +39,7 @@ static const PlainGameDescriptor macventureGames[] = { }; class MacVentureMetaEngine : public AdvancedMetaEngine { -public: +public: MacVentureMetaEngine() : AdvancedMetaEngine(MacVenture::gameDescriptions, sizeof(ADGameDescription), macventureGames) { _guiOptions = GUIO0(); _md5Bytes = 5000000; // TODO: Upper limit, adjust it once all games are added diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp new file mode 100644 index 0000000000..22e0faa515 --- /dev/null +++ b/engines/macventure/gui.cpp @@ -0,0 +1,62 @@ + +#include "macventure/macventure.h" + +#include "common/file.h" +#include "image/bmp.h" + +namespace MacVenture { + +Gui::Gui() { + initGUI(); +} + +Gui::~Gui() { + +} + +void Gui::draw() { + _wm.draw(); +} + +void Gui::initGUI() { + _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); + _wm.setScreen(&_screen); + Graphics::MacWindow *w = _wm.addWindow(false, true, true); + w->setDimensions(Common::Rect(100, 100)); + w->setActive(false); + + loadBorder(w, "border_inac.bmp", false); +} + +void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { + Common::File borderfile; + + if (!borderfile.open(filename)) { + debug(1, "Cannot open border file"); + return; + } + + Image::BitmapDecoder bmpDecoder; + Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size()); + Graphics::Surface source; + Graphics::TransparentSurface *surface = new Graphics::TransparentSurface(); + + if (stream) { + debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename); + bmpDecoder.loadStream(*stream); + source = *(bmpDecoder.getSurface()); + + source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette()); + surface->create(source.w, source.h, source.format); + surface->copyFrom(source); + surface->applyColorKey(255, 0, 255, false); + + target->setBorder(*surface, active); + + borderfile.close(); + + delete stream; + } +} + +} // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h new file mode 100644 index 0000000000..0cfb835d38 --- /dev/null +++ b/engines/macventure/gui.h @@ -0,0 +1,56 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_GUI_H +#define MACVENTURE_GUI_H + +#include "graphics/macgui/macwindowmanager.h" + +#include "macventure/macventure.h" + +namespace MacVenture { + +using namespace Graphics::MacGUIConstants; + +class Gui { + +public: + Gui(); + ~Gui(); + + void draw(); + +private: // Attributes + + Graphics::ManagedSurface _screen; + Graphics::MacWindowManager _wm; + +private: // Methods + + void initGUI(); + void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index be949ec00a..ef47d93f1a 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -25,10 +25,6 @@ #include "common/debug.h" #include "common/error.h" -// For border loading, should be gone later -#include "common/file.h" -#include "image/bmp.h" - #include "engines/util.h" #include "macventure/macventure.h" @@ -50,22 +46,21 @@ MacVentureEngine::~MacVentureEngine() { DebugMan.clearAllDebugChannels(); delete _rnd; delete _debugger; + delete _gui; } Common::Error MacVentureEngine::run() { debug("MacVenture::MacVentureEngine::init()"); - initGraphics(kScreenWidth, kScreenHeight, true); + initGraphics(kScreenWidth, kScreenHeight, true); _debugger = new Console(this); // Additional setup. debug("MacVentureEngine::init"); - _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); + _gui = new Gui(); - initGUI(); - // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); @@ -73,7 +68,7 @@ Common::Error MacVentureEngine::run() { while (!_shouldQuit) { processEvents(); - _wm->draw(); + _gui->draw(); g_system->updateScreen(); g_system->delayMillis(50); @@ -90,52 +85,9 @@ void MacVentureEngine::processEvents() { case Common::EVENT_QUIT: _shouldQuit = true; break; - default: + default: break; } } } - -void MacVentureEngine::initGUI() { - _wm = new Graphics::MacWindowManager(); - _wm->setScreen(&_screen); - Graphics::MacWindow *w = _wm->addWindow(false, true, true); - w->setDimensions(Common::Rect(100, 100)); - w->setActive(false); - - loadBorder(w, "border_inac.bmp", false); - -} - -void MacVentureEngine::loadBorder(Graphics::MacWindow *target, Common::String filename, bool active) { - Common::File borderfile; - - if (!borderfile.open(filename)) { - debug(1, "Cannot open border file"); - return; - } - - Image::BitmapDecoder bmpDecoder; - Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size()); - Graphics::Surface source; - Graphics::TransparentSurface *surface = new Graphics::TransparentSurface(); - - if (stream) { - debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename); - bmpDecoder.loadStream(*stream); - source = *(bmpDecoder.getSurface()); - - source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette()); - surface->create(source.w, source.h, source.format); - surface->copyFrom(source); - surface->applyColorKey(255, 0, 255, false); - - target->setBorder(*surface, active); - - borderfile.close(); - - delete stream; - } -} - } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index cdf50b7e91..5f655b9e59 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -33,6 +33,8 @@ #include "gui/debugger.h" +#include "macventure/gui.h" + struct ADGameDescription; namespace MacVenture { @@ -61,18 +63,14 @@ public: private: void processEvents(); - - void initGUI(); - void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); - + private: const ADGameDescription *_gameDescription; Common::RandomSource *_rnd; Console *_debugger; - Graphics::MacWindowManager *_wm; - Graphics::ManagedSurface _screen; + Gui *_gui; bool _shouldQuit; }; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 839cbb4587..3f11d15856 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -2,6 +2,7 @@ MODULE := engines/macventure MODULE_OBJS := \ detection.o \ + gui.o \ macventure.o MODULE_DIRS += \ -- cgit v1.2.3 From d15e3a03c73da1d5a0bbc372970936eedfa1108d Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 8 Jun 2016 11:17:56 +0200 Subject: MACVENTURE: Add game file manager --- engines/macventure/detection.cpp | 10 +++++++++- engines/macventure/macventure.cpp | 6 ++++++ engines/macventure/macventure.h | 16 ++++++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index ade07a0853..88fb85d650 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -27,7 +27,13 @@ #include "macventure/macventure.h" -#include "macventure.h" +namespace MacVenture { + + const char *MacVentureEngine::getGameFileName() const { + return _gameDescription->filesDescriptions[0].fileName; + } + +} namespace MacVenture { @@ -68,6 +74,8 @@ bool MacVentureMetaEngine::createInstance(OSystem * syst, Engine ** engine, cons } + + } // End of namespace MacVenture #if PLUGIN_ENABLED_DYNAMIC(MACVENTURE) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index ef47d93f1a..3f576373e0 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -64,6 +64,10 @@ Common::Error MacVentureEngine::run() { // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); + _resourceManager = new Common::MacResManager(); + if (!_resourceManager->open(getGameFileName())) + error("Could not open %s as a resource fork", getGameFileName()); + _shouldQuit = false; while (!_shouldQuit) { processEvents(); @@ -90,4 +94,6 @@ void MacVentureEngine::processEvents() { } } } + + } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 5f655b9e59..9be560c46e 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -23,14 +23,11 @@ #ifndef MACVENTURE_H #define MACVENTURE_H +#include "engines/engine.h" #include "common/debug.h" #include "common/random.h" +#include "common/macresman.h" -#include "engines/engine.h" - -#include "graphics/managed_surface.h" -#include "graphics/macgui/macwindowmanager.h" - #include "gui/debugger.h" #include "macventure/gui.h" @@ -64,15 +61,22 @@ public: private: void processEvents(); -private: +private: // Attributes + const ADGameDescription *_gameDescription; Common::RandomSource *_rnd; + + Common::MacResManager *_resourceManager; Console *_debugger; Gui *_gui; bool _shouldQuit; + +private: // Methods + + const char* getGameFileName() const; }; -- cgit v1.2.3 From 2fd43c24d01e7b532deeddeab87d34e5ef0bd039 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 8 Jun 2016 13:18:50 +0200 Subject: MACVENTURE: Small fix in detection --- engines/macventure/detection_tables.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h index 9c9b91f696..4667561ea8 100644 --- a/engines/macventure/detection_tables.h +++ b/engines/macventure/detection_tables.h @@ -27,7 +27,7 @@ namespace MacVenture { #define BASEGAME(n, v, f, md5, s) {n, v, AD_ENTRY1s(f, md5, s), Common::EN_ANY, Common::kPlatformMacintosh, ADGF_DEFAULT, GUIO0()} static const ADGameDescription gameDescriptions[] = { - BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.dsk", "4e03e9ef1cd5f65ce1de14d512510537", 839680), // Zojoi Rerelease + BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "054db22bdc6db3ccb89a23cd840f858e", 70528), // Zojoi Rerelease AD_TABLE_END_MARKER }; } // End of namespace MacVenture -- cgit v1.2.3 From dd072a39de77f410c41604bcbcc1581606422f67 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 8 Jun 2016 16:07:53 +0200 Subject: MACVENTURE: Add basic menu loading --- engines/macventure/gui.cpp | 31 ++++++++++++++++++--- engines/macventure/gui.h | 12 ++++++--- engines/macventure/macventure.cpp | 57 ++++++++++++++++++++++++++++++++++++--- engines/macventure/macventure.h | 9 +++++++ 4 files changed, 98 insertions(+), 11 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 22e0faa515..38a633673c 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1,12 +1,23 @@ - -#include "macventure/macventure.h" - #include "common/file.h" #include "image/bmp.h" +#include "macventure/macventure.h" +#include "macventure/gui.h" + namespace MacVenture { -Gui::Gui() { +/* priority, name, action, shortcut, enabled*/ +#define MV_MENU5(p, n, a, s, e) Graphics::MenuData{p, n, a, s, e} +#define MV_MENU4(p, n, a, s) Graphics::MenuData{p, n, a, s, false} +#define MV_MENUtop(n, a, s) Graphics::MenuData{-1, n, a, s, true} + +static const Graphics::MenuData menuSubItems[] = { + { -1, "Hello World", 0, 0, false }, + { 0, "How yo duin", 0, 0, false }, +}; + +Gui::Gui(MacVentureEngine *engine) { + _engine = engine; initGUI(); } @@ -25,6 +36,12 @@ void Gui::initGUI() { w->setDimensions(Common::Rect(100, 100)); w->setActive(false); + _menu = _wm.addMenu(); + + loadMenus(); + + _menu->calcDimensions(); + loadBorder(w, "border_inac.bmp", false); } @@ -59,4 +76,10 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool } } +void Gui::loadMenus() { + Graphics::MenuData data; + Common::Array::const_iterator iter; + _menu->addStaticMenus(_engine->getMenuData()); +} + } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 0cfb835d38..c6aae15303 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -24,29 +24,35 @@ #define MACVENTURE_GUI_H #include "graphics/macgui/macwindowmanager.h" - -#include "macventure/macventure.h" +#include "graphics/macgui/macwindow.h" +#include "graphics/macgui/macmenu.h" namespace MacVenture { using namespace Graphics::MacGUIConstants; +class MacVentureEngine; class Gui { public: - Gui(); + Gui(MacVentureEngine *engine); ~Gui(); void draw(); private: // Attributes + MacVentureEngine *_engine; + Graphics::ManagedSurface _screen; Graphics::MacWindowManager _wm; + Graphics::Menu *_menu; + private: // Methods void initGUI(); + void loadMenus(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); }; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 3f576373e0..5eefde51f3 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -24,13 +24,19 @@ #include "common/debug-channels.h" #include "common/debug.h" #include "common/error.h" - #include "engines/util.h" #include "macventure/macventure.h" +// To move +#include "common/file.h" + namespace MacVenture { +enum { + kMaxMenuTitleLength = 30 +}; + MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst) { _gameDescription = gameDesc; _rnd = new Common::RandomSource("macventure"); @@ -57,9 +63,7 @@ Common::Error MacVentureEngine::run() { _debugger = new Console(this); // Additional setup. - debug("MacVentureEngine::init"); - - _gui = new Gui(); + debug("MacVentureEngine::init"); // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); @@ -68,6 +72,11 @@ Common::Error MacVentureEngine::run() { if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); + if (!loadMenuData()) + error("Could not load menu data from %s", getGameFileName()); + + _gui = new Gui(this); + _shouldQuit = false; while (!_shouldQuit) { processEvents(); @@ -95,5 +104,45 @@ void MacVentureEngine::processEvents() { } } +bool MacVentureEngine::loadMenuData() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + Common::MacResIDArray::const_iterator iter; + + if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0) + return false; + + _menuData = new Graphics::MenuData[resArray.size()]; + int i = 0; + + for (iter = resArray.begin(); iter != resArray.end(); ++iter) { + res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); + + Graphics::MenuData data; + int menunum = -1; + for (int i = 0; i < 5; i++) { + res->readUint16BE(); + // Skip menuID, width, height, resourceID, placeholder + } + bool enabled = res->readUint32BE(); + uint8 titleLength = res->readByte(); + char* title = new char[titleLength+1]; + res->read(title, titleLength); + title[titleLength] = '\0'; + + _menuData[i] = { menunum, title, 0, 0, enabled}; + i++; + } + + // Override last value (end-of-menu) with our end-of-menu + _menuData[resArray.size() - 1] = { 0, 0, 0, 0, false }; + + return true; +} + +Graphics::MenuData* MacVentureEngine::getMenuData() { + return _menuData; +} + } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 9be560c46e..254f162d54 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -58,8 +58,12 @@ public: virtual Common::Error run(); + Graphics::MenuData *getMenuData(); + private: void processEvents(); + + bool loadMenuData(); private: // Attributes @@ -77,6 +81,11 @@ private: // Attributes private: // Methods const char* getGameFileName() const; + +private: //To move + + Graphics::MenuData *_menuData; + }; -- cgit v1.2.3 From 4611429959b2fdc8608b6c972997b4e0b5ca05e7 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 8 Jun 2016 17:13:02 +0200 Subject: MACVENTURE: Add submenu loading --- engines/macventure/gui.cpp | 80 ++++++++++++++++++++++++++++++++++++--- engines/macventure/gui.h | 6 ++- engines/macventure/macventure.cpp | 60 +++++------------------------ engines/macventure/macventure.h | 8 ---- engines/macventure/menu.cpp | 53 ++++++++++++++++++++++++++ engines/macventure/menu.h | 56 +++++++++++++++++++++++++++ 6 files changed, 197 insertions(+), 66 deletions(-) create mode 100644 engines/macventure/menu.cpp create mode 100644 engines/macventure/menu.h diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 38a633673c..10901e952e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1,3 +1,25 @@ +/* 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/file.h" #include "image/bmp.h" @@ -16,8 +38,9 @@ static const Graphics::MenuData menuSubItems[] = { { 0, "How yo duin", 0, 0, false }, }; -Gui::Gui(MacVentureEngine *engine) { +Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _engine = engine; + _resourceManager = resman; initGUI(); } @@ -29,6 +52,10 @@ void Gui::draw() { _wm.draw(); } +bool Gui::processEvent(Common::Event &event) { + return _wm.processEvent(event); +} + void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); @@ -38,7 +65,8 @@ void Gui::initGUI() { _menu = _wm.addMenu(); - loadMenus(); + if (!loadMenus()) + error("Could not load menus"); _menu->calcDimensions(); @@ -76,10 +104,50 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool } } -void Gui::loadMenus() { - Graphics::MenuData data; - Common::Array::const_iterator iter; - _menu->addStaticMenus(_engine->getMenuData()); +bool Gui::loadMenus() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + Common::MacResIDArray::const_iterator iter; + + if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0) + return false; + + _menu->addMenuItem("(c)"); + _menu->addMenuSubItem(0, "Hello", 0, 0, 'K', true); + + int i = 1; + for (iter = resArray.begin(); iter != resArray.end(); ++iter) { + res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); + + Graphics::MenuData data; + int menunum = -1; // High level menus have level -1 + /* Skip menuID, width, height, resourceID, placeholder */ + for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } + bool enabled = res->readUint32BE(); + uint8 titleLength = res->readByte(); + char* title = new char[titleLength + 1]; + res->read(title, titleLength); + title[titleLength] = '\0'; + + if (titleLength > 2) { + _menu->addMenuItem(title); + + // Read submenu items + while (titleLength = res->readByte()) { + title = new char[titleLength + 1]; + res->read(title, titleLength); + title[titleLength] = '\0'; + // Skip icon, key, mark, style + for (int skip = 0; skip < 4; skip++) { res->readUint16BE(); } + _menu->addMenuSubItem(i, title, 0); + } + } + + i++; + } + + return true; + } } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index c6aae15303..96f2380ca0 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -35,14 +35,16 @@ class MacVentureEngine; class Gui { public: - Gui(MacVentureEngine *engine); + Gui(MacVentureEngine *engine, Common::MacResManager *resman); ~Gui(); void draw(); + bool processEvent(Common::Event &event); private: // Attributes MacVentureEngine *_engine; + Common::MacResManager *_resourceManager; Graphics::ManagedSurface _screen; Graphics::MacWindowManager _wm; @@ -52,7 +54,7 @@ private: // Attributes private: // Methods void initGUI(); - void loadMenus(); + bool loadMenus(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); }; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 5eefde51f3..5660fde16c 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -63,7 +63,7 @@ Common::Error MacVentureEngine::run() { _debugger = new Console(this); // Additional setup. - debug("MacVentureEngine::init"); + debug("MacVentureEngine::init"); // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); @@ -72,10 +72,7 @@ Common::Error MacVentureEngine::run() { if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); - if (!loadMenuData()) - error("Could not load menu data from %s", getGameFileName()); - - _gui = new Gui(this); + _gui = new Gui(this, _resourceManager); _shouldQuit = false; while (!_shouldQuit) { @@ -94,55 +91,18 @@ void MacVentureEngine::processEvents() { Common::Event event; while (_eventMan->pollEvent(event)) { + if (_gui->processEvent(event)) + continue; + switch (event.type) { - case Common::EVENT_QUIT: - _shouldQuit = true; - break; - default: - break; + case Common::EVENT_QUIT: + _shouldQuit = true; + break; + default: + break; } } } -bool MacVentureEngine::loadMenuData() { - Common::MacResIDArray resArray; - Common::SeekableReadStream *res; - Common::MacResIDArray::const_iterator iter; - - if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0) - return false; - - _menuData = new Graphics::MenuData[resArray.size()]; - int i = 0; - - for (iter = resArray.begin(); iter != resArray.end(); ++iter) { - res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); - - Graphics::MenuData data; - int menunum = -1; - for (int i = 0; i < 5; i++) { - res->readUint16BE(); - // Skip menuID, width, height, resourceID, placeholder - } - bool enabled = res->readUint32BE(); - uint8 titleLength = res->readByte(); - char* title = new char[titleLength+1]; - res->read(title, titleLength); - title[titleLength] = '\0'; - - _menuData[i] = { menunum, title, 0, 0, enabled}; - i++; - } - - // Override last value (end-of-menu) with our end-of-menu - _menuData[resArray.size() - 1] = { 0, 0, 0, 0, false }; - - return true; -} - -Graphics::MenuData* MacVentureEngine::getMenuData() { - return _menuData; -} - } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 254f162d54..771588fde1 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -58,12 +58,8 @@ public: virtual Common::Error run(); - Graphics::MenuData *getMenuData(); - private: void processEvents(); - - bool loadMenuData(); private: // Attributes @@ -82,10 +78,6 @@ private: // Methods const char* getGameFileName() const; -private: //To move - - Graphics::MenuData *_menuData; - }; diff --git a/engines/macventure/menu.cpp b/engines/macventure/menu.cpp new file mode 100644 index 0000000000..dd3c495e10 --- /dev/null +++ b/engines/macventure/menu.cpp @@ -0,0 +1,53 @@ +/* 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 "macventure/menu.h" +#include "macventure/macventure.h" + +#include "common/file.h" +#include "graphics/macgui/macwindowmanager.h" + +namespace MacVenture { + +Menu::Menu(MacVentureEngine *engine, Graphics::MacWindowManager *wm) { + + _engine = engine; + _wm = wm; + + _menu = _wm->addMenu(); + + if (!loadMenuData()) + error("Could not load menu data from %s", _engine->getGameFileName()); +} + +Menu::~Menu() { + delete _ +} + +void Menu::draw() { + +} + +bool Menu::loadMenuData() { + +} + +} // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/menu.h b/engines/macventure/menu.h new file mode 100644 index 0000000000..dab6369e15 --- /dev/null +++ b/engines/macventure/menu.h @@ -0,0 +1,56 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_MENU_H +#define MACVENTURE_MENU_H + +namespace MacVenture { + +class MacVentureEngine; + +class Graphics::MacWindowManager; + +class Menu { + +public: + Menu(MacVentureEngine *engine, Graphics::MacWindowManager *wm); + ~Menu(); + + void draw(); + +private: // Attributes + + MacVentureEngine *_engine; + Graphics::MacWindowManager *_wm; + Graphics::Menu *_menu; + +private: // Methods + + void init(); + bool loadMenuData(); + +}; + +} // End of namespace MacVenture + +#endif + -- cgit v1.2.3 From 88949eddce470ff0d329296eb1b3b8c72b07823b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 8 Jun 2016 19:02:15 +0200 Subject: MACVENTURE: Add menu display --- engines/macventure/gui.cpp | 29 ++++++++++++++++++----------- engines/macventure/gui.h | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 10901e952e..eb1abe00e0 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -59,9 +59,9 @@ bool Gui::processEvent(Common::Event &event) { void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); - Graphics::MacWindow *w = _wm.addWindow(false, true, true); - w->setDimensions(Common::Rect(100, 100)); - w->setActive(false); + _outConsoleWindow = _wm.addWindow(false, true, true); + _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); + _outConsoleWindow->setActive(false); _menu = _wm.addMenu(); @@ -70,7 +70,7 @@ void Gui::initGUI() { _menu->calcDimensions(); - loadBorder(w, "border_inac.bmp", false); + loadBorder(_outConsoleWindow, "border_inac.bmp", false); } void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { @@ -113,19 +113,23 @@ bool Gui::loadMenus() { return false; _menu->addMenuItem("(c)"); - _menu->addMenuSubItem(0, "Hello", 0, 0, 'K', true); + _menu->addMenuSubItem(0, "Hello", 0, 0, 'K', false); int i = 1; for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); + bool enabled; + uint16 key; + uint8 titleLength; + char* title; Graphics::MenuData data; int menunum = -1; // High level menus have level -1 /* Skip menuID, width, height, resourceID, placeholder */ for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } - bool enabled = res->readUint32BE(); - uint8 titleLength = res->readByte(); - char* title = new char[titleLength + 1]; + enabled = res->readUint32BE(); + titleLength = res->readByte(); + title = new char[titleLength + 1]; res->read(title, titleLength); title[titleLength] = '\0'; @@ -137,9 +141,12 @@ bool Gui::loadMenus() { title = new char[titleLength + 1]; res->read(title, titleLength); title[titleLength] = '\0'; - // Skip icon, key, mark, style - for (int skip = 0; skip < 4; skip++) { res->readUint16BE(); } - _menu->addMenuSubItem(i, title, 0); + // Skip icon + res->readUint16BE(); + key = res->readUint16BE(); + // Skip key, mark, style + for (int skip = 0; skip < 2; skip++) { res->readUint16BE(); } + _menu->addMenuSubItem(i, title, 0, 0, key, false); } } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 96f2380ca0..810779363b 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -49,6 +49,7 @@ private: // Attributes Graphics::ManagedSurface _screen; Graphics::MacWindowManager _wm; + Graphics::MacWindow *_outConsoleWindow; Graphics::Menu *_menu; private: // Methods -- cgit v1.2.3 From 7991b3ede73e8545bb64795706d26ace7a711f9b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 9 Jun 2016 11:31:19 +0200 Subject: MACVENTURE: Add static menus --- engines/macventure/gui.cpp | 148 ++++++++++++++++++++++++++++++++++++++------- engines/macventure/gui.h | 24 +++++++- 2 files changed, 149 insertions(+), 23 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index eb1abe00e0..9e0b37760a 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -28,16 +28,49 @@ namespace MacVenture { -/* priority, name, action, shortcut, enabled*/ -#define MV_MENU5(p, n, a, s, e) Graphics::MenuData{p, n, a, s, e} -#define MV_MENU4(p, n, a, s) Graphics::MenuData{p, n, a, s, false} -#define MV_MENUtop(n, a, s) Graphics::MenuData{-1, n, a, s, true} +enum MenuAction; + +enum { + kMenuHighLevel = -1, + kMenuAbout = 0, + kMenuFile = 1, + kMenuEdit = 2, + kMenuSpecial = 3 +}; static const Graphics::MenuData menuSubItems[] = { - { -1, "Hello World", 0, 0, false }, - { 0, "How yo duin", 0, 0, false }, + { kMenuHighLevel, "File", 0, 0, false }, + { kMenuHighLevel, "Edit", 0, 0, false }, + { kMenuHighLevel, "Special", 0, 0, false }, + { kMenuHighLevel, "Font", 0, 0, false }, + { kMenuHighLevel, "FontSize", 0, 0, false }, + + //{ kMenuAbout, "About", kMenuActionAbout, 0, true}, + + { kMenuFile, "New", kMenuActionNew, 0, true }, + { kMenuFile, NULL, 0, 0, false }, + { kMenuFile, "Open...", kMenuActionOpen, 0, true }, + { kMenuFile, "Save", kMenuActionSave, 0, true }, + { kMenuFile, "Save as...", kMenuActionSaveAs, 0, true }, + { kMenuFile, NULL, 0, 0, false }, + { kMenuFile, "Quit", kMenuActionQuit, 0, true }, + + { kMenuEdit, "Undo", kMenuActionUndo, 'Z', true }, + { kMenuEdit, NULL, 0, 0, false }, + { kMenuEdit, "Cut", kMenuActionCut, 'K', true }, + { kMenuEdit, "Copy", kMenuActionCopy, 'C', true }, + { kMenuEdit, "Paste", kMenuActionPaste, 'V', true }, + { kMenuEdit, "Clear", kMenuActionClear, 'B', true }, + + { kMenuSpecial, "Clean Up", kMenuActionCleanUp, 0, true }, + { kMenuSpecial, "Mess Up", kMenuActionMessUp, 0, true }, + + { 0, NULL, 0, 0, false } }; +bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); +void menuCommandsCallback(int action, Common::String &text, void *data); + Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _engine = engine; _resourceManager = resman; @@ -59,18 +92,20 @@ bool Gui::processEvent(Common::Event &event) { void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); - _outConsoleWindow = _wm.addWindow(false, true, true); - _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); - _outConsoleWindow->setActive(false); + // Menu _menu = _wm.addMenu(); - if (!loadMenus()) error("Could not load menus"); - + _menu->setCommandsCallback(menuCommandsCallback, this); _menu->calcDimensions(); - loadBorder(_outConsoleWindow, "border_inac.bmp", false); + // In-game Output Console + _outConsoleWindow = _wm.addWindow(false, true, true); + _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); + _outConsoleWindow->setActive(false); + _outConsoleWindow->setCallback(outConsoleWindowCallback, this); + loadBorder(_outConsoleWindow, "border_inac.bmp", false); } void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { @@ -105,25 +140,31 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool } bool Gui::loadMenus() { + + // We assume that, if there are static menus, we don't need dynamic ones + if (menuSubItems) { + _menu->addStaticMenus(menuSubItems); + return true; + } + Common::MacResIDArray resArray; Common::SeekableReadStream *res; Common::MacResIDArray::const_iterator iter; if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0) - return false; + return false; - _menu->addMenuItem("(c)"); - _menu->addMenuSubItem(0, "Hello", 0, 0, 'K', false); + _menu->addMenuSubItem(0, "Abb", kMenuActionAbout, 0, 'A', true); int i = 1; for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); bool enabled; uint16 key; + uint16 style; uint8 titleLength; char* title; - Graphics::MenuData data; int menunum = -1; // High level menus have level -1 /* Skip menuID, width, height, resourceID, placeholder */ for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } @@ -133,7 +174,7 @@ bool Gui::loadMenus() { res->read(title, titleLength); title[titleLength] = '\0'; - if (titleLength > 2) { + if (titleLength > 1) { _menu->addMenuItem(title); // Read submenu items @@ -143,18 +184,81 @@ bool Gui::loadMenus() { title[titleLength] = '\0'; // Skip icon res->readUint16BE(); + // Read key key = res->readUint16BE(); - // Skip key, mark, style - for (int skip = 0; skip < 2; skip++) { res->readUint16BE(); } - _menu->addMenuSubItem(i, title, 0, 0, key, false); + // Skip mark + res->readUint16BE(); + // Read style + style = res->readUint16BE(); + _menu->addMenuSubItem(i, title, 0, style, key, false); } } i++; - } + } + return true; +} + +/* CALLBACKS */ +bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui) { return true; - +} + +void menuCommandsCallback(int action, Common::String &text, void *data) { + Gui *g = (Gui *)data; + + g->handleMenuAction((MenuAction)action); +} + +/* HANDLERS */ +void Gui::handleMenuAction(MenuAction action) { + switch (action) { + case MacVenture::kMenuActionAbout: + debug("MacVenture Menu Action: About"); + break; + case MacVenture::kMenuActionNew: + debug("MacVenture Menu Action: New"); + break; + case MacVenture::kMenuActionOpen: + debug("MacVenture Menu Action: Open"); + break; + case MacVenture::kMenuActionSave: + debug("MacVenture Menu Action: Save"); + break; + case MacVenture::kMenuActionSaveAs: + debug("MacVenture Menu Action: Save As"); + break; + case MacVenture::kMenuActionQuit: + debug("MacVenture Menu Action: Quit"); + break; + case MacVenture::kMenuActionUndo: + debug("MacVenture Menu Action: Undo"); + break; + case MacVenture::kMenuActionCut: + debug("MacVenture Menu Action: Cut"); + break; + case MacVenture::kMenuActionCopy: + debug("MacVenture Menu Action: Copy"); + break; + case MacVenture::kMenuActionPaste: + debug("MacVenture Menu Action: Paste"); + break; + case MacVenture::kMenuActionClear: + debug("MacVenture Menu Action: Clear"); + break; + case MacVenture::kMenuActionCleanUp: + debug("MacVenture Menu Action: Clean Up"); + break; + case MacVenture::kMenuActionMessUp: + debug("MacVenture Menu Action: Mess Up"); + break; + case MacVenture::kMenuActionCommand: + debug("MacVenture Menu Action: GENERIC"); + break; + default: + break; + } } } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 810779363b..eb5197bd8d 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -30,8 +30,29 @@ namespace MacVenture { using namespace Graphics::MacGUIConstants; +using namespace Graphics::MacWindowConstants; class MacVentureEngine; +//namespace MacVentureMenuActions { +enum MenuAction { + kMenuActionAbout, + kMenuActionNew, + kMenuActionOpen, + kMenuActionSave, + kMenuActionSaveAs, + kMenuActionQuit, + kMenuActionUndo, + kMenuActionCut, + kMenuActionCopy, + kMenuActionPaste, + kMenuActionClear, + kMenuActionCleanUp, + kMenuActionMessUp, + + kMenuActionCommand +}; +//} using namespace MacVentureMenuActions; + class Gui { public: @@ -40,6 +61,7 @@ public: void draw(); bool processEvent(Common::Event &event); + void handleMenuAction(MenuAction action); private: // Attributes @@ -56,7 +78,7 @@ private: // Methods void initGUI(); bool loadMenus(); - void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); }; -- cgit v1.2.3 From c09e74b6a736f1970f2c75411dba6e2cefe1e76b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 11 Jun 2016 23:25:42 +0200 Subject: MACVENTURE: Add commnad window text render --- engines/macventure/gui.cpp | 38 ++++++++++++++++++++++++++++++----- engines/macventure/gui.h | 50 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 9e0b37760a..6bb54d8b79 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -40,7 +40,7 @@ enum { static const Graphics::MenuData menuSubItems[] = { { kMenuHighLevel, "File", 0, 0, false }, - { kMenuHighLevel, "Edit", 0, 0, false }, + { kMenuHighLevel, "Edit", 0, 0, false }, { kMenuHighLevel, "Special", 0, 0, false }, { kMenuHighLevel, "Font", 0, 0, false }, { kMenuHighLevel, "FontSize", 0, 0, false }, @@ -83,6 +83,12 @@ Gui::~Gui() { void Gui::draw() { _wm.draw(); + Common::List::const_iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + CommandButton button = *it; + if (button.getData().refcon != kControlExitBox) + button.draw(*_controlsWindow->getSurface()); + } } bool Gui::processEvent(Common::Event &event) { @@ -100,12 +106,34 @@ void Gui::initGUI() { _menu->setCommandsCallback(menuCommandsCallback, this); _menu->calcDimensions(); + if (!loadWindows()) + error("Could not load windows"); + + initWindows(); + + if (!loadControls()) + error("Could not load controls"); + + draw(); + +} + +void Gui::initWindows() { + // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - loadBorder(_outConsoleWindow, "border_inac.bmp", false); + loadBorder(_outConsoleWindow, "border_command.bmp", false); + + // Game Controls Window + _controlsWindow = _wm.addWindow(false, false, false); + _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); + _controlsWindow->setActive(false); + _controlsWindow->setCallback(controlsWindowCallback, this); + loadBorder(_controlsWindow, "border_command.bmp", false); + } void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { @@ -152,7 +180,7 @@ bool Gui::loadMenus() { Common::MacResIDArray::const_iterator iter; if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0) - return false; + return false; _menu->addMenuSubItem(0, "Abb", kMenuActionAbout, 0, 'A', true); @@ -192,12 +220,12 @@ bool Gui::loadMenus() { style = res->readUint16BE(); _menu->addMenuSubItem(i, title, 0, style, key, false); } - } + } i++; } - return true; + return true; } /* CALLBACKS */ diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index eb5197bd8d..d63f7fcb18 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -53,7 +53,7 @@ enum MenuAction { }; //} using namespace MacVentureMenuActions; -class Gui { +class Gui { public: Gui(MacVentureEngine *engine, Common::MacResManager *resman); @@ -78,10 +78,56 @@ private: // Methods void initGUI(); bool loadMenus(); - void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); }; +class CommandButton { + +enum { + kCommandsLeftPadding = 0, + kCommandsTopPadding = 0 +}; + +public: + CommandButton(ControlData data, Gui *g) { + _data = data; + _gui = g; + } + ~CommandButton() {} + + void draw(Graphics::ManagedSurface &surface) { + + + surface.fillRect(_data.bounds, kColorWhite); + surface.frameRect(_data.bounds, kColorBlack); + + const Graphics::Font &font = _gui->getCurrentFont(); + Common::String title(_data.title); + font.drawString( + &surface, + title, + _data.bounds.left, + _data.bounds.top, + _data.bounds.right - _data.bounds.left, + kColorBlack, + Graphics::kTextAlignCenter); + + } + + bool isInsideBounds(Common::Point point) { + return _data.bounds.contains(point); + } + + const ControlData& getData() { + return _data; + } + +private: + ControlData _data; + Gui *_gui; +}; + } // End of namespace MacVenture #endif -- cgit v1.2.3 From 63e4fe8fc7d99d858f5302a7c3321e1d73296904 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 11 Jun 2016 23:57:35 +0200 Subject: MACVENTURE: Add command callback --- engines/macventure/gui.cpp | 31 +++++++++++++++++++++++++++++-- engines/macventure/gui.h | 7 ++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 6bb54d8b79..887f9c2b65 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -82,13 +82,15 @@ Gui::~Gui() { } void Gui::draw() { - _wm.draw(); + Common::List::const_iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { CommandButton button = *it; if (button.getData().refcon != kControlExitBox) button.draw(*_controlsWindow->getSurface()); } + + _wm.draw(); } bool Gui::processEvent(Common::Event &event) { @@ -133,6 +135,7 @@ void Gui::initWindows() { _controlsWindow->setActive(false); _controlsWindow->setCallback(controlsWindowCallback, this); loadBorder(_controlsWindow, "border_command.bmp", false); + loadBorder(_controlsWindow, "border_command.bmp", true); } @@ -229,10 +232,16 @@ bool Gui::loadMenus() { } /* CALLBACKS */ -bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui) { +bool outConsoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { return true; } +bool controlsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return g->processCommandEvents(click, event); +} + void menuCommandsCallback(int action, Common::String &text, void *data) { Gui *g = (Gui *)data; @@ -289,4 +298,22 @@ void Gui::handleMenuAction(MenuAction action) { } } + +bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { + if (event.type == Common::EVENT_LBUTTONUP) { + Common::Point position( + event.mouse.x - _controlsWindow->getDimensions().left, + event.mouse.y - _controlsWindow->getDimensions().top); + //debug("Click at: %d, %d", p) + Common::List::const_iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + const CommandButton &data = *it; + if (data.isInsideBounds(position)) { + debug("Command active: %s", data.getData().title); + } + } + } + return false; +} + } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index d63f7fcb18..c6446cec29 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -62,6 +62,7 @@ public: void draw(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); + bool processCommandEvents(WindowClick click, Common::Event &event); private: // Attributes @@ -96,7 +97,7 @@ public: } ~CommandButton() {} - void draw(Graphics::ManagedSurface &surface) { + void draw(Graphics::ManagedSurface &surface) const { surface.fillRect(_data.bounds, kColorWhite); @@ -115,11 +116,11 @@ public: } - bool isInsideBounds(Common::Point point) { + bool isInsideBounds(const Common::Point point) const { return _data.bounds.contains(point); } - const ControlData& getData() { + const ControlData& getData() const { return _data; } -- cgit v1.2.3 From 1d5cbee3a820c34af2ecdc2221e38290ab33c82f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 12 Jun 2016 20:22:01 +0200 Subject: MACVENTURE: Fix small border bug --- engines/macventure/gui.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++- engines/macventure/gui.h | 62 ++++++++++++++++++++++- 2 files changed, 181 insertions(+), 2 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 887f9c2b65..caf6eb1789 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -231,6 +231,91 @@ bool Gui::loadMenus() { return true; } +bool Gui::loadWindows() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + Common::MacResIDArray::const_iterator iter; + + _windowData = new Common::List(); + + if ((resArray = _resourceManager->getResIDArray(MKTAG('W', 'I', 'N', 'D'))).size() == 0) + return false; + + uint32 id = kCommandsWindow; + for (iter = resArray.begin(); iter != resArray.end(); ++iter) { + res = _resourceManager->getResource(MKTAG('W', 'I', 'N', 'D'), *iter); + WindowData data; + uint16 top, left, bottom, right; + uint16 borderSize; + top = res->readUint16BE(); + left = res->readUint16BE(); + bottom = res->readUint16BE(); + right = res->readUint16BE(); + data.type = (MVWindowType)res->readUint16BE(); + data.bounds = Common::Rect( + left, + top, + right + borderThickness(data.type), + bottom + borderThickness(data.type)); + data.visible = res->readUint16BE(); + data.hasCloseBox = res->readUint16BE(); + data.refcon = (WindowReference)id; id++; + res->readUint32BE(); // Skip the true id. For some reason it's reading 0 + data.titleLength = res->readByte(); + if (data.titleLength) { + data.title = new char[data.titleLength + 1]; + res->read(data.title, data.titleLength); + data.title[data.titleLength] = '\0'; + } + + _windowData->push_back(data); + } + + return true; +} + +bool Gui::loadControls() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + Common::MacResIDArray::const_iterator iter; + + _controlData = new Common::List(); + + if ((resArray = _resourceManager->getResIDArray(MKTAG('C', 'N', 'T', 'L'))).size() == 0) + return false; + + uint32 id = kControlExitBox; + for (iter = resArray.begin(); iter != resArray.end(); ++iter) { + res = _resourceManager->getResource(MKTAG('C', 'N', 'T', 'L'), *iter); + ControlData data; + uint16 top, left, bottom, right; + top = res->readUint16BE(); + left = res->readUint16BE(); + bottom = res->readUint16BE(); + right = res->readUint16BE(); + Common::Rect bounds(left, top, right, bottom); // For some reason, if I remove this it segfaults + data.bounds = Common::Rect(left, top, right, bottom); + data.scrollValue = res->readUint16BE(); + data.visible = res->readByte(); + res->readByte(); // Unused + data.scrollMax = res->readUint16BE(); + data.scrollMin = res->readUint16BE(); + data.cdef = res->readUint16BE(); + data.refcon = (ControlReference)id; id++; + res->readUint32BE(); + data.titleLength = res->readByte(); + if (data.titleLength) { + data.title = new char[data.titleLength + 1]; + res->read(data.title, data.titleLength); + data.title[data.titleLength] = '\0'; + } + + i++; + } + + return true; +} + /* CALLBACKS */ bool outConsoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { return true; @@ -304,7 +389,6 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { Common::Point position( event.mouse.x - _controlsWindow->getDimensions().left, event.mouse.y - _controlsWindow->getDimensions().top); - //debug("Click at: %d, %d", p) Common::List::const_iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { const CommandButton &data = *it; @@ -316,4 +400,39 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { return false; } +/* Ugly switches */ + +uint16 Gui::borderThickness(MVWindowType type) { + switch (type) { + case MacVenture::kDocument: + break; + case MacVenture::kDBox: + break; + case MacVenture::kPlainDBox: + return 6; + case MacVenture::kAltBox: + break; + case MacVenture::kNoGrowDoc: + break; + case MacVenture::kMovableDBox: + break; + case MacVenture::kZoomDoc: + break; + case MacVenture::kZoomNoGrow: + break; + case MacVenture::kRDoc16: + break; + case MacVenture::kRDoc4: + break; + case MacVenture::kRDoc6: + break; + case MacVenture::kRDoc10: + break; + default: + break; + } + + return 0; +} + } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index c6446cec29..983dc10f74 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -53,6 +53,65 @@ enum MenuAction { }; //} using namespace MacVentureMenuActions; +enum WindowReference { + kCommandsWindow = 0x80, + kMainGameWindow = 0x81, + kOutConsoleWindow = 0x82, + kSelfWindow = 0x83, + kExitsWindow = 0x84, + kDiplomaWindow = 0x85 +}; + +enum MVWindowType { + kDocument = 0x00, + kDBox = 0x01, + kPlainDBox = 0x02, + kAltBox = 0x03, + kNoGrowDoc = 0x04, + kMovableDBox = 0x05, + kZoomDoc = 0x08, + kZoomNoGrow = 0x0c, + kRDoc16 = 0x10, + kRDoc4 = 0x12, + kRDoc6 = 0x14, + kRDoc10 = 0x16 +}; + +struct WindowData { + Common::Rect bounds; + MVWindowType type; + uint16 visible; + uint16 hasCloseBox; + WindowReference refcon; + uint8 titleLength; + char* title; +}; + +enum ControlReference { + kControlExitBox = 0, + kControlExamine = 1, + kControlOpen = 2, + kControlClose = 3, + kControlSpeak = 4, + kControlOperate = 5, + kControlGo = 6, + kControlHit = 7, + kControlConsume = 8 +}; + +struct ControlData { + Common::Rect bounds; + uint16 scrollValue; + uint8 visible; + uint16 scrollMax; + uint16 scrollMin; + uint16 cdef; + uint32 refcon; + uint8 titleLength; + char* title; +}; + + class Gui { public: @@ -81,6 +140,8 @@ private: // Methods bool loadMenus(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + uint16 borderThickness(MVWindowType type); + }; class CommandButton { @@ -113,7 +174,6 @@ public: _data.bounds.right - _data.bounds.left, kColorBlack, Graphics::kTextAlignCenter); - } bool isInsideBounds(const Common::Point point) const { -- cgit v1.2.3 From ec40b4ec441dd1e3af4cdf1fb670d44efc19f7f4 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 12 Jun 2016 22:09:06 +0200 Subject: MACVENTURE: Fix border offsets --- engines/macventure/gui.cpp | 85 ++++++++++++++++++++++++++------------- engines/macventure/gui.h | 25 +++++++++++- engines/macventure/macventure.cpp | 18 +++++++++ engines/macventure/macventure.h | 13 ++++-- 4 files changed, 109 insertions(+), 32 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index caf6eb1789..8f922d3dd2 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -83,12 +83,7 @@ Gui::~Gui() { void Gui::draw() { - Common::List::const_iterator it = _controlData->begin(); - for (; it != _controlData->end(); ++it) { - CommandButton button = *it; - if (button.getData().refcon != kControlExitBox) - button.draw(*_controlsWindow->getSurface()); - } + drawCommandsWindow(); _wm.draw(); } @@ -122,13 +117,6 @@ void Gui::initGUI() { void Gui::initWindows() { - // In-game Output Console - _outConsoleWindow = _wm.addWindow(false, true, true); - _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); - _outConsoleWindow->setActive(false); - _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - loadBorder(_outConsoleWindow, "border_command.bmp", false); - // Game Controls Window _controlsWindow = _wm.addWindow(false, false, false); _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); @@ -137,6 +125,15 @@ void Gui::initWindows() { loadBorder(_controlsWindow, "border_command.bmp", false); loadBorder(_controlsWindow, "border_command.bmp", true); + // Main Game Window + + // In-game Output Console + _outConsoleWindow = _wm.addWindow(false, true, true); + _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); + _outConsoleWindow->setActive(false); + _outConsoleWindow->setCallback(outConsoleWindowCallback, this); + loadBorder(_outConsoleWindow, "border_command.bmp", false); + } void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { @@ -253,10 +250,10 @@ bool Gui::loadWindows() { right = res->readUint16BE(); data.type = (MVWindowType)res->readUint16BE(); data.bounds = Common::Rect( - left, - top, - right + borderThickness(data.type), - bottom + borderThickness(data.type)); + left - borderThickness(data.type), + top - borderThickness(data.type), + right + borderThickness(data.type) * 2, + bottom + borderThickness(data.type) * 2); data.visible = res->readUint16BE(); data.hasCloseBox = res->readUint16BE(); data.refcon = (WindowReference)id; id++; @@ -284,6 +281,7 @@ bool Gui::loadControls() { if ((resArray = _resourceManager->getResIDArray(MKTAG('C', 'N', 'T', 'L'))).size() == 0) return false; + uint16 commandsBorder = borderThickness(kPlainDBox); uint32 id = kControlExitBox; for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('C', 'N', 'T', 'L'), *iter); @@ -293,8 +291,6 @@ bool Gui::loadControls() { left = res->readUint16BE(); bottom = res->readUint16BE(); right = res->readUint16BE(); - Common::Rect bounds(left, top, right, bottom); // For some reason, if I remove this it segfaults - data.bounds = Common::Rect(left, top, right, bottom); data.scrollValue = res->readUint16BE(); data.visible = res->readByte(); res->readByte(); // Unused @@ -309,6 +305,11 @@ bool Gui::loadControls() { res->read(data.title, data.titleLength); data.title[data.titleLength] = '\0'; } + if (data.refcon != kControlExitBox) + data.border = commandsBorder; + + Common::Rect bounds(left, top, right, bottom); // For some reason, if I remove this it segfaults + data.bounds = Common::Rect(left + data.border, top + data.border, right + data.border, bottom + data.border); i++; } @@ -316,6 +317,32 @@ bool Gui::loadControls() { return true; } +void Gui::drawCommandsWindow() { + if (_engine->isPaused()) { + Graphics::ManagedSurface *srf = _controlsWindow->getSurface(); + WindowData data = getWindowData(kCommandsWindow); + uint16 border = borderThickness(data.type); + srf->fillRect(Common::Rect(border * 2, border * 2, srf->w - (border * 3), srf->h - (border * 3)), kColorWhite); + getCurrentFont().drawString( + srf, + _engine->getCommandsPausedString(), + 0, + (srf->h / 2) - getCurrentFont().getFontHeight(), + data.bounds.right - data.bounds.left, + kColorBlack, + Graphics::kTextAlignCenter); + } + else { + Common::List::const_iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + CommandButton button = *it; + if (button.getData().refcon != kControlExitBox) + button.draw(*_controlsWindow->getSurface()); + } + } +} + + /* CALLBACKS */ bool outConsoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { return true; @@ -386,14 +413,18 @@ void Gui::handleMenuAction(MenuAction action) { bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { - Common::Point position( - event.mouse.x - _controlsWindow->getDimensions().left, - event.mouse.y - _controlsWindow->getDimensions().top); - Common::List::const_iterator it = _controlData->begin(); - for (; it != _controlData->end(); ++it) { - const CommandButton &data = *it; - if (data.isInsideBounds(position)) { - debug("Command active: %s", data.getData().title); + if (_engine->isPaused()) { + _engine->requestUnpause(); + } else { + Common::Point position( + event.mouse.x - _controlsWindow->getDimensions().left, + event.mouse.y - _controlsWindow->getDimensions().top); + Common::List::const_iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + const CommandButton &data = *it; + if (data.isInsideBounds(position)) { + debug("Command active: %s", data.getData().title); + } } } } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 983dc10f74..9316f91fd3 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -109,6 +109,7 @@ struct ControlData { uint32 refcon; uint8 titleLength; char* title; + uint16 border; }; @@ -123,6 +124,13 @@ public: void handleMenuAction(MenuAction action); bool processCommandEvents(WindowClick click, Common::Event &event); + const WindowData& getWindowData(WindowReference reference); + + const Graphics::Font& getCurrentFont(); + + // Ugly switches + uint16 borderThickness(MVWindowType type); + private: // Attributes MacVentureEngine *_engine; @@ -131,16 +139,30 @@ private: // Attributes Graphics::ManagedSurface _screen; Graphics::MacWindowManager _wm; + Common::List *_windowData; + Common::List *_controlData; + + Graphics::MacWindow *_controlsWindow; + Graphics::MacWindow *_mainGameWindow; Graphics::MacWindow *_outConsoleWindow; + Graphics::MacWindow *_selfWindow; + Graphics::MacWindow *_exitsWindow; + Graphics::MacWindow *_diplomaWindow; Graphics::Menu *_menu; private: // Methods + + // Initializers void initGUI(); + void initWindows(); + + // Loaders bool loadMenus(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); - uint16 borderThickness(MVWindowType type); + // Drawers + void drawCommandsWindow(); }; @@ -160,7 +182,6 @@ public: void draw(Graphics::ManagedSurface &surface) const { - surface.fillRect(_data.bounds, kColorWhite); surface.frameRect(_data.bounds, kColorBlack); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 5660fde16c..19021278cb 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -87,6 +87,24 @@ Common::Error MacVentureEngine::run() { return Common::kNoError; } +void MacVentureEngine::requestQuit() { + _shouldQuit = true; +} + +void MacVentureEngine::requestUnpause() { + _paused = false; +} + +// Data retrieval + +bool MacVentureEngine::isPaused() { + return _paused; +} + +Common::String MacVentureEngine::getCommandsPausedString() { + return Common::String("Click to continue"); +} + void MacVentureEngine::processEvents() { Common::Event event; diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 771588fde1..b8d065b876 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -58,16 +58,23 @@ public: virtual Common::Error run(); + void requestQuit(); + void requestUnpause(); + + // Data retrieval + bool isPaused(); + Common::String getCommandsPausedString(); + private: void processEvents(); - + private: // Attributes const ADGameDescription *_gameDescription; Common::RandomSource *_rnd; Common::MacResManager *_resourceManager; - + Console *_debugger; Gui *_gui; @@ -88,4 +95,4 @@ public: }; } // End of namespace MacVenture -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From 61134cf570b711b61bef8034db2b167a3a6f4ef3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 12 Jun 2016 22:27:23 +0200 Subject: MACVENTURE: Add the rest of the windows --- engines/macventure/gui.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++- engines/macventure/gui.h | 7 ++- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 8f922d3dd2..3aac7e1ada 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -68,7 +68,14 @@ static const Graphics::MenuData menuSubItems[] = { { 0, NULL, 0, 0, false } }; +bool controlsWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); +bool mainGameWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); +bool selfWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); +bool exitsWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); +bool diplomaWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); +bool inventoryWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); + void menuCommandsCallback(int action, Common::String &text, void *data); Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { @@ -92,6 +99,24 @@ bool Gui::processEvent(Common::Event &event) { return _wm.processEvent(event); } +const WindowData& Gui::getWindowData(WindowReference reference) { + assert(_windowData); + + Common::List::const_iterator iter = _windowData->begin(); + while (iter->refcon != reference && iter != _windowData->end()) { + iter++; + } + + if (iter->refcon == reference) + return *iter; + + error("Could not locate the desired window data"); +} + +const Graphics::Font& Gui::getCurrentFont() { + return *_wm.getFont("Chicago-12", Graphics::FontManager::kBigGUIFont); +} + void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); @@ -126,6 +151,12 @@ void Gui::initWindows() { loadBorder(_controlsWindow, "border_command.bmp", true); // Main Game Window + _mainGameWindow = _wm.addWindow(false, false, false); + _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); + _mainGameWindow->setActive(false); + _mainGameWindow->setCallback(mainGameWindowCallback, this); + loadBorder(_mainGameWindow, "border_command.bmp", false); + loadBorder(_mainGameWindow, "border_command.bmp", true); // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); @@ -134,6 +165,36 @@ void Gui::initWindows() { _outConsoleWindow->setCallback(outConsoleWindowCallback, this); loadBorder(_outConsoleWindow, "border_command.bmp", false); + // Self Window + _selfWindow = _wm.addWindow(false, true, true); + _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); + _selfWindow->setActive(false); + _selfWindow->setCallback(selfWindowCallback, this); + loadBorder(_selfWindow, "border_command.bmp", false); + + // Exits Window + _exitsWindow = _wm.addWindow(false, true, true); + _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); + _exitsWindow->setActive(false); + _exitsWindow->setCallback(exitsWindowCallback, this); + loadBorder(_exitsWindow, "border_command.bmp", false); + + // Diploma Window + _diplomaWindow = _wm.addWindow(false, true, true); + _diplomaWindow->setDimensions(getWindowData(kDiplomaWindow).bounds); + _diplomaWindow->setActive(false); + _diplomaWindow->setCallback(diplomaWindowCallback, this); + loadBorder(_diplomaWindow, "border_command.bmp", false); + // Render invisible for now + _diplomaWindow->getSurface()->fillRect(_diplomaWindow->getSurface()->getBounds(), kColorGreen2); + + // Inventory Window + _inventoryWindow = _wm.addWindow(false, true, true); + _inventoryWindow->setDimensions(getWindowData(kInventoryWindow).bounds); + _inventoryWindow->setActive(false); + _inventoryWindow->setCallback(inventoryWindowCallback, this); + loadBorder(_inventoryWindow, "border_command.bmp", false); + } void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { @@ -265,12 +326,28 @@ bool Gui::loadWindows() { data.title[data.titleLength] = '\0'; } + debug(5, "Window loaded: %s", data.title); + _windowData->push_back(data); } + loadInventoryWindow(); + return true; } +void Gui::loadInventoryWindow() { + WindowData data; + data.bounds = Common::Rect(5, 30, 125, 190); + data.title = "Inventory"; + data.visible = true; + data.hasCloseBox = false; + data.refcon = kInventoryWindow; + data.titleLength = 10; + + _windowData->push_back(data); +} + bool Gui::loadControls() { Common::MacResIDArray resArray; Common::SeekableReadStream *res; @@ -344,14 +421,45 @@ void Gui::drawCommandsWindow() { /* CALLBACKS */ + +bool controlsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return g->processCommandEvents(click, event); +} + +bool mainGameWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return true; +} + bool outConsoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { return true; } -bool controlsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { +bool selfWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - return g->processCommandEvents(click, event); + return true; +} + +bool exitsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return true; +} + +bool diplomaWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return true; +} + +bool inventoryWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return true; } void menuCommandsCallback(int action, Common::String &text, void *data) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 9316f91fd3..7ffe199344 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -59,7 +59,8 @@ enum WindowReference { kOutConsoleWindow = 0x82, kSelfWindow = 0x83, kExitsWindow = 0x84, - kDiplomaWindow = 0x85 + kDiplomaWindow = 0x85, + kInventoryWindow = 0x90 // Not in the files, but here for convenience }; enum MVWindowType { @@ -148,6 +149,7 @@ private: // Attributes Graphics::MacWindow *_selfWindow; Graphics::MacWindow *_exitsWindow; Graphics::MacWindow *_diplomaWindow; + Graphics::MacWindow *_inventoryWindow; Graphics::Menu *_menu; private: // Methods @@ -159,6 +161,9 @@ private: // Methods // Loaders bool loadMenus(); + bool loadWindows(); + void loadInventoryWindow(); + bool loadControls(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); // Drawers -- cgit v1.2.3 From c676bb99237a1d2eeb9965aae4fe78503cea9b46 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 12 Jun 2016 23:08:24 +0200 Subject: MACVENTURE: Load general settings --- engines/macventure/macventure.cpp | 57 ++++++++++++++++++++++++++++++++++++--- engines/macventure/macventure.h | 28 ++++++++++++++++++- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 19021278cb..6e2d7edaab 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -37,6 +37,12 @@ enum { kMaxMenuTitleLength = 30 }; +enum { + kGlobalSettingsID = 0x80, + kDiplomaGeometryID = 0x81, + kTextHuffmanTableID = 0x83 +}; + MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst) { _gameDescription = gameDesc; _rnd = new Common::RandomSource("macventure"); @@ -65,13 +71,13 @@ Common::Error MacVentureEngine::run() { // Additional setup. debug("MacVentureEngine::init"); - // Your main even loop should be (invoked from) here. - debug("MacVentureEngine::go: Hello, World!"); - _resourceManager = new Common::MacResManager(); if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); + if (!loadGlobalSettings()) + error("Could not load the engine settings"); + _gui = new Gui(this, _resourceManager); _shouldQuit = false; @@ -87,6 +93,51 @@ Common::Error MacVentureEngine::run() { return Common::kNoError; } +bool MacVentureEngine::loadGlobalSettings() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + + if ((resArray = _resourceManager->getResIDArray(MKTAG('G', 'N', 'R', 'L'))).size() == 0) + return false; + + res = _resourceManager->getResource(MKTAG('G', 'N', 'R', 'L'), kGlobalSettingsID); + if (res) { + _globalSettings.numObjects = res->readUint16BE(); + _globalSettings.numGlobals = res->readUint16BE(); + _globalSettings.numCommands = res->readUint16BE(); + _globalSettings.numAttributes = res->readUint16BE(); + _globalSettings.numGroups = res->readUint16BE(); + res->readUint16BE(); // unknown + _globalSettings.invTop = res->readUint16BE(); + _globalSettings.invLeft = res->readUint16BE(); + _globalSettings.invWidth = res->readUint16BE(); + _globalSettings.invHeight = res->readUint16BE(); + _globalSettings.invOffsetY = res->readUint16BE(); + _globalSettings.invOffsetX = res->readSint16BE(); + _globalSettings.defaultFont = res->readUint16BE(); + _globalSettings.defaultSize = res->readUint16BE(); + + _globalSettings.attrIndices = new uint8[_globalSettings.numAttributes]; + res->read(_globalSettings.attrIndices, _globalSettings.numAttributes); + + _globalSettings.attrMasks = new uint16[_globalSettings.numAttributes]; + for (int i = 0; i < _globalSettings.numAttributes; i++) + _globalSettings.attrMasks[i] = res->readUint16BE(); + + _globalSettings.attrShifts = new uint8[_globalSettings.numAttributes]; + res->read(_globalSettings.attrShifts, _globalSettings.numAttributes); + + _globalSettings.cmdArgCnts = new uint8[_globalSettings.numCommands]; + res->read(_globalSettings.cmdArgCnts, _globalSettings.numCommands); + + + + return true; + } + + return false; +} + void MacVentureEngine::requestQuit() { _shouldQuit = true; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index b8d065b876..ffc1c2a9f2 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -50,6 +50,27 @@ enum { // the current limitation is 32 debug levels (1 << 31 is the last one) }; +struct GlobalSettings { + uint16 numObjects; // number of game objects defined + uint16 numGlobals; // number of globals defined + uint16 numCommands; // number of commands defined + uint16 numAttributes; // number of attributes + uint16 numGroups; // number of object groups + uint16 invTop; // inventory window bounds + uint16 invLeft; + uint16 invHeight; + uint16 invWidth; + uint16 invOffsetY; // positioning offset for + uint16 invOffsetX; // new inventory windows + uint16 defaultFont; // default font + uint16 defaultSize; // default font size + uint8 *attrIndices; // attribute indices into attribute table + uint16 *attrMasks; // attribute masks + uint8 *attrShifts; // attribute bit shifts + uint8 *cmdArgCnts; // command argument counts + uint8 *commands; // command buttons +}; + class MacVentureEngine : public Engine { public: @@ -61,6 +82,9 @@ public: void requestQuit(); void requestUnpause(); + // Data loading + bool loadGlobalSettings(); + // Data retrieval bool isPaused(); Common::String getCommandsPausedString(); @@ -76,10 +100,12 @@ private: // Attributes Common::MacResManager *_resourceManager; Console *_debugger; - Gui *_gui; + // Engine state + GlobalSettings _globalSettings; bool _shouldQuit; + bool _paused; private: // Methods -- cgit v1.2.3 From 5368aa979bca198c9337410cd5908c151052f2b6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 12 Jun 2016 23:13:55 +0200 Subject: MACVENTURE: Change inventory to use the general settings --- engines/macventure/gui.cpp | 7 +++- engines/macventure/macventure.cpp | 79 +++++++++++++++++++++------------------ engines/macventure/macventure.h | 7 ++-- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 3aac7e1ada..7b6c7e3486 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -338,7 +338,12 @@ bool Gui::loadWindows() { void Gui::loadInventoryWindow() { WindowData data; - data.bounds = Common::Rect(5, 30, 125, 190); + GlobalSettings settings = _engine->getGlobalSettings(); + data.bounds = Common::Rect( + settings.invLeft, + settings.invTop, + settings.invLeft + settings.invWidth, + settings.invTop + settings.invHeight); data.title = "Inventory"; data.visible = true; data.hasCloseBox = false; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 6e2d7edaab..5827ecc370 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -93,6 +93,47 @@ Common::Error MacVentureEngine::run() { return Common::kNoError; } +void MacVentureEngine::requestQuit() { + _shouldQuit = true; +} + +void MacVentureEngine::requestUnpause() { + _paused = false; +} + +const GlobalSettings& MacVentureEngine::getGlobalSettings() { + return _globalSettings; +} + +// Data retrieval + +bool MacVentureEngine::isPaused() { + return _paused; +} + +Common::String MacVentureEngine::getCommandsPausedString() { + return Common::String("Click to continue"); +} + +void MacVentureEngine::processEvents() { + Common::Event event; + + while (_eventMan->pollEvent(event)) { + if (_gui->processEvent(event)) + continue; + + switch (event.type) { + case Common::EVENT_QUIT: + _shouldQuit = true; + break; + default: + break; + } + } +} + +// Data loading + bool MacVentureEngine::loadGlobalSettings() { Common::MacResIDArray resArray; Common::SeekableReadStream *res; @@ -130,7 +171,8 @@ bool MacVentureEngine::loadGlobalSettings() { _globalSettings.cmdArgCnts = new uint8[_globalSettings.numCommands]; res->read(_globalSettings.cmdArgCnts, _globalSettings.numCommands); - + _globalSettings.commands = new uint8[_globalSettings.numCommands]; + res->read(_globalSettings.commands, _globalSettings.numCommands); return true; } @@ -138,40 +180,5 @@ bool MacVentureEngine::loadGlobalSettings() { return false; } -void MacVentureEngine::requestQuit() { - _shouldQuit = true; -} - -void MacVentureEngine::requestUnpause() { - _paused = false; -} - -// Data retrieval - -bool MacVentureEngine::isPaused() { - return _paused; -} - -Common::String MacVentureEngine::getCommandsPausedString() { - return Common::String("Click to continue"); -} - -void MacVentureEngine::processEvents() { - Common::Event event; - - while (_eventMan->pollEvent(event)) { - if (_gui->processEvent(event)) - continue; - - switch (event.type) { - case Common::EVENT_QUIT: - _shouldQuit = true; - break; - default: - break; - } - } -} - } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index ffc1c2a9f2..da1f66a277 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -82,16 +82,17 @@ public: void requestQuit(); void requestUnpause(); - // Data loading - bool loadGlobalSettings(); - // Data retrieval bool isPaused(); Common::String getCommandsPausedString(); + const GlobalSettings& getGlobalSettings(); private: void processEvents(); + // Data loading + bool loadGlobalSettings(); + private: // Attributes const ADGameDescription *_gameDescription; -- cgit v1.2.3 From d43523010b71b24dd29dafae3f965695e9d920d7 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 12 Jun 2016 23:23:10 +0200 Subject: MACVENTURE: Add callbacks for all windows --- engines/macventure/gui.cpp | 37 ++++++++++++++++++++++++++++++++----- engines/macventure/gui.h | 7 +++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 7b6c7e3486..3a19d6c2fd 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -429,6 +429,7 @@ void Gui::drawCommandsWindow() { bool controlsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; + return g->processCommandEvents(click, event); } @@ -436,29 +437,31 @@ bool controlsWindowCallback(Graphics::WindowClick click, Common::Event &event, v bool mainGameWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - return true; + return g->processMainGameEvents(click, event); } bool outConsoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - return true; + Gui *g = (Gui*)gui; + + return g->processOutConsoleEvents(click, event); } bool selfWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - return true; + return g->processSelfEvents(click, event); } bool exitsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - return true; + return g->processExitsEvents(click, event); } bool diplomaWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - return true; + return g->processDiplomaEvents(click, event); } bool inventoryWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { @@ -544,6 +547,30 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { return false; } +bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & event) { + debug(6, "Processing event in Main Game Window"); + return getWindowData(kMainGameWindow).visible; +} +bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & event) { + debug(6, "Processing event in Out Console Window"); + return getWindowData(kOutConsoleWindow).visible; +} + +bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event) { + debug(6, "Processing event in Self Window"); + return getWindowData(kSelfWindow).visible; +} + +bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & event) { + debug(6, "Processing event in Exits Window"); + return getWindowData(kExitsWindow).visible; +} + +bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & event) { + debug(6, "Processing event in Diploma Window"); + return getWindowData(kDiplomaWindow).visible; +} + /* Ugly switches */ uint16 Gui::borderThickness(MVWindowType type) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 7ffe199344..a1c31eeb76 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -123,7 +123,14 @@ public: void draw(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); + + // Event processors bool processCommandEvents(WindowClick click, Common::Event &event); + bool processMainGameEvents(WindowClick click, Common::Event &event); + bool processOutConsoleEvents(WindowClick click, Common::Event &event); + bool processSelfEvents(WindowClick click, Common::Event &event); + bool processExitsEvents(WindowClick click, Common::Event &event); + bool processDiplomaEvents(WindowClick click, Common::Event &event); const WindowData& getWindowData(WindowReference reference); -- cgit v1.2.3 From 88e6f9257e14b08ea15f24b60823aaa969502ad3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 13 Jun 2016 00:01:39 +0200 Subject: MACVENTURE: Add appropriate border bounding boxes --- engines/macventure/gui.cpp | 39 +++++++++++++++++++++------------------ engines/macventure/gui.h | 11 ++++++++++- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 3a19d6c2fd..849dca50e6 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -177,9 +177,11 @@ void Gui::initWindows() { _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); - loadBorder(_exitsWindow, "border_command.bmp", false); + loadBorder(_exitsWindow, "border_title_inac.bmp", false); + loadBorder(_exitsWindow, "border_title_inac.bmp", true); - // Diploma Window + // Diploma Window (we can go without it for now) + /* _diplomaWindow = _wm.addWindow(false, true, true); _diplomaWindow->setDimensions(getWindowData(kDiplomaWindow).bounds); _diplomaWindow->setActive(false); @@ -187,6 +189,7 @@ void Gui::initWindows() { loadBorder(_diplomaWindow, "border_command.bmp", false); // Render invisible for now _diplomaWindow->getSurface()->fillRect(_diplomaWindow->getSurface()->getBounds(), kColorGreen2); + */ // Inventory Window _inventoryWindow = _wm.addWindow(false, true, true); @@ -311,10 +314,10 @@ bool Gui::loadWindows() { right = res->readUint16BE(); data.type = (MVWindowType)res->readUint16BE(); data.bounds = Common::Rect( - left - borderThickness(data.type), - top - borderThickness(data.type), - right + borderThickness(data.type) * 2, - bottom + borderThickness(data.type) * 2); + left - borderBounds(data.type).leftOffset, + top - borderBounds(data.type).topOffset, + right + borderBounds(data.type).rightOffset * 2, + bottom + borderBounds(data.type).bottomOffset * 2); data.visible = res->readUint16BE(); data.hasCloseBox = res->readUint16BE(); data.refcon = (WindowReference)id; id++; @@ -340,9 +343,9 @@ void Gui::loadInventoryWindow() { WindowData data; GlobalSettings settings = _engine->getGlobalSettings(); data.bounds = Common::Rect( - settings.invLeft, - settings.invTop, - settings.invLeft + settings.invWidth, + settings.invLeft, + settings.invTop, + settings.invLeft + settings.invWidth, settings.invTop + settings.invHeight); data.title = "Inventory"; data.visible = true; @@ -363,7 +366,7 @@ bool Gui::loadControls() { if ((resArray = _resourceManager->getResIDArray(MKTAG('C', 'N', 'T', 'L'))).size() == 0) return false; - uint16 commandsBorder = borderThickness(kPlainDBox); + uint16 commandsBorder = borderBounds(kPlainDBox).topOffset; uint32 id = kControlExitBox; for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('C', 'N', 'T', 'L'), *iter); @@ -403,7 +406,7 @@ void Gui::drawCommandsWindow() { if (_engine->isPaused()) { Graphics::ManagedSurface *srf = _controlsWindow->getSurface(); WindowData data = getWindowData(kCommandsWindow); - uint16 border = borderThickness(data.type); + uint16 border = borderBounds(data.type).topOffset; srf->fillRect(Common::Rect(border * 2, border * 2, srf->w - (border * 3), srf->h - (border * 3)), kColorWhite); getCurrentFont().drawString( srf, @@ -429,7 +432,7 @@ void Gui::drawCommandsWindow() { bool controlsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - + return g->processCommandEvents(click, event); } @@ -573,28 +576,28 @@ bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & ev /* Ugly switches */ -uint16 Gui::borderThickness(MVWindowType type) { +BorderBounds Gui::borderBounds(MVWindowType type) { switch (type) { case MacVenture::kDocument: break; case MacVenture::kDBox: break; case MacVenture::kPlainDBox: - return 6; + return BorderBounds(6, 6, 6, 6); case MacVenture::kAltBox: break; case MacVenture::kNoGrowDoc: - break; + return BorderBounds(1, 17, 1, 1); case MacVenture::kMovableDBox: break; case MacVenture::kZoomDoc: - break; + return BorderBounds(1, 19, 16, 1); case MacVenture::kZoomNoGrow: break; case MacVenture::kRDoc16: break; case MacVenture::kRDoc4: - break; + return BorderBounds(1, 19, 1, 1); case MacVenture::kRDoc6: break; case MacVenture::kRDoc10: @@ -603,7 +606,7 @@ uint16 Gui::borderThickness(MVWindowType type) { break; } - return 0; + return BorderBounds(0, 0, 0, 0); } } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index a1c31eeb76..a8dc7a755e 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -113,6 +113,15 @@ struct ControlData { uint16 border; }; +struct BorderBounds { + uint16 leftOffset; + uint16 topOffset; + uint16 rightOffset; + uint16 bottomOffset; + + BorderBounds(uint16 l, uint16 t, uint16 r, uint16 b) : leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} +}; + class Gui { @@ -137,7 +146,7 @@ public: const Graphics::Font& getCurrentFont(); // Ugly switches - uint16 borderThickness(MVWindowType type); + BorderBounds borderBounds(MVWindowType type); private: // Attributes -- cgit v1.2.3 From 9564866ec360dbab39973a5b982b748f6c060637 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 13 Jun 2016 00:36:24 +0200 Subject: MACVENTURE: Add image to self window --- engines/macventure/gui.cpp | 39 ++++++++++++++++++++++++++++++++++++--- engines/macventure/gui.h | 3 +++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 849dca50e6..3aa9c5de33 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -89,8 +89,7 @@ Gui::~Gui() { } void Gui::draw() { - - drawCommandsWindow(); + drawWindows(); _wm.draw(); } @@ -170,7 +169,8 @@ void Gui::initWindows() { _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - loadBorder(_selfWindow, "border_command.bmp", false); + loadBorder(_selfWindow, "border_self_inac.bmp", false); + loadBorder(_selfWindow, "border_self_act.bmp", true); // Exits Window _exitsWindow = _wm.addWindow(false, true, true); @@ -402,6 +402,14 @@ bool Gui::loadControls() { return true; } +void Gui::drawWindows() { + + drawCommandsWindow(); + drawMainGameWindow(); + + drawSelfWindow(); +} + void Gui::drawCommandsWindow() { if (_engine->isPaused()) { Graphics::ManagedSurface *srf = _controlsWindow->getSurface(); @@ -427,6 +435,30 @@ void Gui::drawCommandsWindow() { } } +void Gui::drawMainGameWindow() { + Graphics::ManagedSurface *srf = _mainGameWindow->getSurface(); + BorderBounds border = borderBounds(getWindowData(kMainGameWindow).type); + srf->fillRect( + Common::Rect( + border.leftOffset * 2, + border.topOffset * 2, + srf->w - (border.rightOffset * 3), + srf->h - (border.bottomOffset * 3)), + kColorWhite); + getCurrentFont().drawString( + srf, + Common::String("Main Game Window"), + 0, + (srf->h / 2) - getCurrentFont().getFontHeight(), + srf->w, + kColorBlack, + Graphics::kTextAlignCenter); +} + +void Gui::drawSelfWindow() { + +} + /* CALLBACKS */ @@ -585,6 +617,7 @@ BorderBounds Gui::borderBounds(MVWindowType type) { case MacVenture::kPlainDBox: return BorderBounds(6, 6, 6, 6); case MacVenture::kAltBox: + //return BorderBounds(8, 9, 11, 10); // For now, I'll stick to the original bmp, it's gorgeous break; case MacVenture::kNoGrowDoc: return BorderBounds(1, 17, 1, 1); diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index a8dc7a755e..1eba4d231b 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -183,7 +183,10 @@ private: // Methods void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); // Drawers + void drawWindows(); void drawCommandsWindow(); + void drawMainGameWindow(); + void drawSelfWindow(); }; -- cgit v1.2.3 From 5719ea30760c85113b4536f7b70295422e95ae9e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 13 Jun 2016 20:29:08 +0200 Subject: MACVENTURE: Add save game loading --- engines/macventure/macventure.cpp | 7 +-- engines/macventure/macventure.h | 16 +++++++ engines/macventure/module.mk | 4 +- engines/macventure/object.cpp | 30 ++++++++++++ engines/macventure/object.h | 54 +++++++++++++++++++++ engines/macventure/world.cpp | 98 +++++++++++++++++++++++++++++++++++++++ engines/macventure/world.h | 73 +++++++++++++++++++++++++++++ 7 files changed, 275 insertions(+), 7 deletions(-) create mode 100644 engines/macventure/object.cpp create mode 100644 engines/macventure/object.h create mode 100644 engines/macventure/world.cpp create mode 100644 engines/macventure/world.h diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 5827ecc370..92ae709b5e 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -37,12 +37,6 @@ enum { kMaxMenuTitleLength = 30 }; -enum { - kGlobalSettingsID = 0x80, - kDiplomaGeometryID = 0x81, - kTextHuffmanTableID = 0x83 -}; - MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst) { _gameDescription = gameDesc; _rnd = new Common::RandomSource("macventure"); @@ -79,6 +73,7 @@ Common::Error MacVentureEngine::run() { error("Could not load the engine settings"); _gui = new Gui(this, _resourceManager); + _world = new World(this, _resourceManager); _shouldQuit = false; while (!_shouldQuit) { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index da1f66a277..3a20bbe2a8 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -31,12 +31,14 @@ #include "gui/debugger.h" #include "macventure/gui.h" +#include "macventure/world.h" struct ADGameDescription; namespace MacVenture { class Console; +class World; enum { kScreenWidth = 512, @@ -50,6 +52,19 @@ enum { // the current limitation is 32 debug levels (1 << 31 is the last one) }; +enum { + kGlobalSettingsID = 0x80, + kDiplomaGeometryID = 0x81, + kTextHuffmanTableID = 0x83 +}; + +enum { + kSaveGameStrID = 0x82, + kDiplomaFilenameID = 0x83, + kClickToContinueTextID = 0x84, + kStartGameFilenameID = 0x85 +}; + struct GlobalSettings { uint16 numObjects; // number of game objects defined uint16 numGlobals; // number of globals defined @@ -102,6 +117,7 @@ private: // Attributes Console *_debugger; Gui *_gui; + World *_world; // Engine state GlobalSettings _globalSettings; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 3f11d15856..2fac1b5347 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -3,7 +3,9 @@ MODULE := engines/macventure MODULE_OBJS := \ detection.o \ gui.o \ - macventure.o + object.o \ + macventure.o \ + world.o \ MODULE_DIRS += \ engines/macventure diff --git a/engines/macventure/object.cpp b/engines/macventure/object.cpp new file mode 100644 index 0000000000..18a734ccd1 --- /dev/null +++ b/engines/macventure/object.cpp @@ -0,0 +1,30 @@ +/* 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 "macventure/object.h" + +namespace MacVenture { + +Object::Object() {} +Object::~Object() {} + +} // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/object.h b/engines/macventure/object.h new file mode 100644 index 0000000000..ebd64ad14f --- /dev/null +++ b/engines/macventure/object.h @@ -0,0 +1,54 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_OBJECT_H +#define MACVENTURE_OBJECT_H + +#include "macventure/macventure.h" + +namespace MacVenture { + +struct ContainerHeader { + uint32 header; +}; + +struct ObjectGroup { + uint32 bitOffset; // Actually uint24, but we don't have that + uint32 offset; +}; + +struct ContainerSubHeader { + uint16 numObjects; + uint16 *huff; + uint8 *lengths; + ObjectGroup *groups; +}; + +class Object { +public: + Object(); + ~Object(); +}; + +} // End of namespace MacVenture + +#endif \ No newline at end of file diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp new file mode 100644 index 0000000000..223541d152 --- /dev/null +++ b/engines/macventure/world.cpp @@ -0,0 +1,98 @@ +#include "macventure/world.h" + +#include "common/file.h" + +namespace MacVenture { + +World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { + _resourceManager = resMan; + _engine = engine; + + if (!loadStartGameFileName()) + error("Could not load initial game configuration"); + + Common::File saveGameFile; + if (!saveGameFile.open(_startGameFileName)) + error("Could not load initial game configuration"); + + Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); + + _saveGame = new SaveGame(_engine, saveGameRes); + + delete saveGameRes; + saveGameFile.close(); +} + + +World::~World() { + + if (_saveGame) + delete _saveGame; +} + +bool World::loadStartGameFileName() { + Common::SeekableReadStream *res; + + res = _resourceManager->getResource(MKTAG('S', 'T', 'R', ' '), kStartGameFilenameID); + if (!res) + return false; + + byte length = res->readByte(); + char *fileName = new char[length + 1]; + res->read(fileName, length); + fileName[length] = '\0'; + _startGameFileName = Common::String(fileName, length); + _startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".TXT"); + + return true; +} + +// SaveGame +SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { + _groups = Common::Array(); + loadGroups(engine, res); + _globals = Common::Array(); + loadGlobals(engine, res); + _text = Common::String(); + loadText(engine, res); +} + +SaveGame::~SaveGame() { +} + +const Common::Array& MacVenture::SaveGame::getGroups() { + return _groups; +} + +const Common::Array& MacVenture::SaveGame::getGlobals() { + return _globals; +} + +const Common::String & MacVenture::SaveGame::getText() { + return _text; +} + +void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) { + GlobalSettings settings = engine->getGlobalSettings(); + for (int i = 0; i < settings.numGroups; ++i) { + AttributeGroup g; + for (int j = 0; j < settings.numObjects; ++j) + g.push_back(res->readUint16BE()); + + _groups.push_back(g); + } +} + +void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream * res) { + GlobalSettings settings = engine->getGlobalSettings(); + for (int i = 0; i < settings.numGlobals; ++i) { + _globals.push_back(res->readUint16BE()); + } +} + +void SaveGame::loadText(MacVentureEngine *engine, Common::SeekableReadStream * res) { + _text = "Placeholder Console Text"; +} + + +} // End of namespace MacVenture diff --git a/engines/macventure/world.h b/engines/macventure/world.h new file mode 100644 index 0000000000..0a7eb25526 --- /dev/null +++ b/engines/macventure/world.h @@ -0,0 +1,73 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_WORLD_H +#define MACVENTURE_WORLD_H + +#include "macventure/macventure.h" + +namespace MacVenture { + +typedef Common::Array AttributeGroup; + +class SaveGame { +public: + SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res); + ~SaveGame(); + + const Common::Array &getGroups(); + const Common::Array &getGlobals(); + const Common::String &getText(); + +private: + void loadGroups(MacVentureEngine *engine, Common::SeekableReadStream *res); + void loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream *res); + void loadText(MacVentureEngine *engine, Common::SeekableReadStream *res); + +private: + Common::Array _groups; + Common::Array _globals; + Common::String _text; +}; + +class World { +public: + World(MacVentureEngine *engine, Common::MacResManager *resMan); + ~World(); + +private: + bool loadStartGameFileName(); + +private: + MacVentureEngine *_engine; + Common::MacResManager *_resourceManager; + + Common::String _startGameFileName; + + SaveGame *_saveGame; + +}; + +} // End of namespace MacVenture + +#endif + -- cgit v1.2.3 From b3be60273fdaf88470798230810393f5806dd69a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 14 Jun 2016 00:16:02 +0200 Subject: MACVENTURE: Add generic container --- engines/macventure/container.h | 203 +++++++++++++++++++++++++++++++++++++++++ engines/macventure/object.h | 16 ---- engines/macventure/world.cpp | 7 +- engines/macventure/world.h | 2 + 4 files changed, 211 insertions(+), 17 deletions(-) create mode 100644 engines/macventure/container.h diff --git a/engines/macventure/container.h b/engines/macventure/container.h new file mode 100644 index 0000000000..fc350735d2 --- /dev/null +++ b/engines/macventure/container.h @@ -0,0 +1,203 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_CONTAINER_H +#define MACVENTURE_CONTAINER_H + +#include "macventure/macventure.h" + +#include "common/file.h" + +namespace MacVenture { + + +struct ItemGroup { + uint32 bitOffset; //It's really uint24 + uint32 offset; //It's really uint24 + uint32 lengths[64]; +}; + +typedef uint32 ContainerHeader; + +template +class Container { + +public: + Container(char *filename) { + if (!_file.open(filename)) + error("Could not open %s", filename); + + _res = _file.readStream(_file.size()); + _header = _res->readUint32BE(); + + if (!(_header & 0x80000000)) { + // Is simplified container + int dataLen = _res->size() - sizeof(_header); + _lenObjs = _header; + _numObjs = dataLen / _lenObjs; + } + else { + ContainerHeader subHead = _header & 0x7fffffff; + _res->seek(subHead, SEEK_SET); + _numObjs = _res->readUint16BE(); + + for (int i = 0; i < 15; ++i) + _huff[i] = _res->readUint16BE(); + + for (int i = 0; i < 16; ++i) + _lens[i] = _res->readByte(); + + ItemGroup group; + for (int i = 0; i < _numObjs; ++i) { + uint32 bits; + if ((i & 0x37) == 0) { // It's the start of a group + // Place myself in the correct position to read group + _res->seek(subHead + (i >> 6) * 6 + 0x30, SEEK_SET); + _res->read(&bits, 3); + bits >>= 4; + _res->read(&group.offset, 3); // Read 3 bytes + group.offset >>= 4; + bits &= 7; + group.bitOffset = bits; + _res->seek(subHead + (bits >> 3), SEEK_SET); + } + + // Workaround to implement peek + // Read the value in 32 bits + uint32 v = (_res->readUint32BE() >> (16 - bits)) & 0xffff; + // Go back + _res->seek(-4, SEEK_CUR); + + // Look in the Huffman table + int x; + for (x = 0; x<16; x++) + if (_huff[x] > v) break; + + // Bits that we need to read from the length table + uint8 bitsToRead = _lens[x]; + + bits += (bitsToRead & 0xf); + if (bits & 0x10) { + bits &= 0xf; + _res->seek(2, SEEK_CUR); + } + + // We already have in bits the first 4 bits (97) + bitsToRead = bitsToRead >> 4; + + // The actual length of the object + uint32 len = 0; + if (bitsToRead) { + // Peek 4 bytes + len = _res->readUint32BE(); + _res->seek(-4, SEEK_CUR); + + bitsToRead--; + + if (bitsToRead == 0) len = 0; + else len >>= (32 - bitsToRead) - bits; + + len &= (1 << bitsToRead) - 1; + len |= 1 << bitsToRead; + + if (bits & 0x10) { + bits &= 0xf; + _res->seek(2, SEEK_CUR); + } + + } + + group.lengths[(i & 0x3f)] = len; + + if ((i & 0x37) == 0) { + _groups.push_back(group); + } + } + } + } + + ~Container() { + + if (_file.isOpen()) + _file.close(); + + if (_res) + delete _res; + } + +public: + T getItem(uint32 id) { + T item; + if (!(_header & 0x80000000)) { + _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); + _res->read(&item, _lenObjs); + } else { + ContainerHeader subHead = _header & 0x7fffffff; + uint32 groupID = (id >> 6); + uint32 objectIndex = id & 0x3f; // Index within the group + + _res->seek(subHead + (groupID * 6), SEEK_SET); + + uint32 offset = 0; + for (int i = 0; i < objectIndex; i++) { + offset += _groups[groupID].lengths[i]; + } + + _res->seek(offset, SEEK_CUR); + + _res->read(&item, _groups[groupID].lengths[objectIndex]); + } + return item; + } + +protected: + + uint _lenObjs; + uint _numObjs; + + ContainerHeader _header; + + uint16 _huff[15]; // huffman masks + uint8 _lens[16]; // huffman lengths + Common::Array _groups; + + Common::File _file; + Common::SeekableReadStream *_res; + +}; + +/* +template +class PersistentContainer : public Container { +public: + PersistentContainer(Common::String filename) : + Container(filename) { + // Load + } + +private: + +};*/ + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/object.h b/engines/macventure/object.h index ebd64ad14f..1712ec6c17 100644 --- a/engines/macventure/object.h +++ b/engines/macventure/object.h @@ -27,22 +27,6 @@ namespace MacVenture { -struct ContainerHeader { - uint32 header; -}; - -struct ObjectGroup { - uint32 bitOffset; // Actually uint24, but we don't have that - uint32 offset; -}; - -struct ContainerSubHeader { - uint16 numObjects; - uint16 *huff; - uint8 *lengths; - ObjectGroup *groups; -}; - class Object { public: Object(); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 223541d152..835d53ae10 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -4,7 +4,7 @@ namespace MacVenture { -World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { +World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _resourceManager = resMan; _engine = engine; @@ -19,6 +19,8 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _saveGame = new SaveGame(_engine, saveGameRes); + _objectConstants = new Container("Shadowgate II/Shadow Object.TXT"); + delete saveGameRes; saveGameFile.close(); } @@ -28,6 +30,9 @@ World::~World() { if (_saveGame) delete _saveGame; + + if (_objectConstants) + delete _objectConstants; } bool World::loadStartGameFileName() { diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 0a7eb25526..41f6ddccaa 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -24,6 +24,7 @@ #define MACVENTURE_WORLD_H #include "macventure/macventure.h" +#include "macventure/container.h" namespace MacVenture { @@ -64,6 +65,7 @@ private: Common::String _startGameFileName; SaveGame *_saveGame; + Container *_objectConstants; }; -- cgit v1.2.3 From 9fc9e3398186f1405ac36497f53fe9a95839c257 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 15 Jun 2016 00:21:26 +0200 Subject: MACVENTURE: Fix detection --- engines/macventure/detection_tables.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h index 4667561ea8..08093da57d 100644 --- a/engines/macventure/detection_tables.h +++ b/engines/macventure/detection_tables.h @@ -27,7 +27,7 @@ namespace MacVenture { #define BASEGAME(n, v, f, md5, s) {n, v, AD_ENTRY1s(f, md5, s), Common::EN_ANY, Common::kPlatformMacintosh, ADGF_DEFAULT, GUIO0()} static const ADGameDescription gameDescriptions[] = { - BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "054db22bdc6db3ccb89a23cd840f858e", 70528), // Zojoi Rerelease + BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "dea09e16829b99278feb84c121066576", 70528), // Zojoi Rerelease AD_TABLE_END_MARKER }; } // End of namespace MacVenture -- cgit v1.2.3 From 56e8ac873b05f68fc9dfa1aa09f136974c71d353 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 15 Jun 2016 00:21:57 +0200 Subject: MACVENTURE: Add generic non-persistent container loading --- engines/macventure/container.h | 128 ++++++++++++++++++++--------------------- engines/macventure/world.cpp | 4 +- 2 files changed, 64 insertions(+), 68 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index fc350735d2..c2b558f6d3 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -26,6 +26,7 @@ #include "macventure/macventure.h" #include "common/file.h" +#include "common/bitstream.h" namespace MacVenture { @@ -56,8 +57,8 @@ public: _numObjs = dataLen / _lenObjs; } else { - ContainerHeader subHead = _header & 0x7fffffff; - _res->seek(subHead, SEEK_SET); + _header &= 0x7fffffff; + _res->seek(_header, SEEK_SET); _numObjs = _res->readUint16BE(); for (int i = 0; i < 15; ++i) @@ -66,71 +67,50 @@ public: for (int i = 0; i < 16; ++i) _lens[i] = _res->readByte(); - ItemGroup group; - for (int i = 0; i < _numObjs; ++i) { - uint32 bits; - if ((i & 0x37) == 0) { // It's the start of a group - // Place myself in the correct position to read group - _res->seek(subHead + (i >> 6) * 6 + 0x30, SEEK_SET); - _res->read(&bits, 3); - bits >>= 4; - _res->read(&group.offset, 3); // Read 3 bytes - group.offset >>= 4; - bits &= 7; - group.bitOffset = bits; - _res->seek(subHead + (bits >> 3), SEEK_SET); - } - - // Workaround to implement peek - // Read the value in 32 bits - uint32 v = (_res->readUint32BE() >> (16 - bits)) & 0xffff; - // Go back - _res->seek(-4, SEEK_CUR); - - // Look in the Huffman table - int x; - for (x = 0; x<16; x++) - if (_huff[x] > v) break; - - // Bits that we need to read from the length table - uint8 bitsToRead = _lens[x]; - - bits += (bitsToRead & 0xf); - if (bits & 0x10) { - bits &= 0xf; - _res->seek(2, SEEK_CUR); - } - - // We already have in bits the first 4 bits (97) - bitsToRead = bitsToRead >> 4; - - // The actual length of the object - uint32 len = 0; - if (bitsToRead) { - // Peek 4 bytes - len = _res->readUint32BE(); - _res->seek(-4, SEEK_CUR); - - bitsToRead--; - - if (bitsToRead == 0) len = 0; - else len >>= (32 - bitsToRead) - bits; - - len &= (1 << bitsToRead) - 1; - len |= 1 << bitsToRead; - - if (bits & 0x10) { - bits &= 0xf; - _res->seek(2, SEEK_CUR); - } - - } - - group.lengths[(i & 0x3f)] = len; - - if ((i & 0x37) == 0) { - _groups.push_back(group); + // Read groups + uint numGroups = _numObjs / 64; + if ((_numObjs % 64) > 0) + numGroups++; + + for (uint i = 0; i < numGroups; ++i) { + ItemGroup group; + + // Place myself in the correct position to read group + _res->seek(_header + (i * 6) + 0x30, SEEK_SET); + byte b1, b2, b3; + b1 = _res->readByte(); + b2 = _res->readByte(); + b3 = _res->readByte(); + group.bitOffset = (b1 << 16) + (b2 << 8) + (b3 << 0); + + b1 = _res->readByte(); + b2 = _res->readByte(); + b3 = _res->readByte(); + group.offset = (b1 << 16) + (b2 << 8) + (b3 << 0); + + // Place the bit reader in the correct position + // group.bitOffset indicates the offset from the start of the subHeader + _res->seek(_header + (group.bitOffset >> 3), SEEK_SET); + + Common::BitStream32BEMSB bitStream(_res); + // Skip the last 3 bits that we couldn't skip with seek + bitStream.skip(group.bitOffset & 7); + for (uint j = 0; j < 64; ++j) { + uint32 length = 0; + uint32 mask = bitStream.peekBits(16); + // Look in the Huffman table + int x; + for (x = 0; x<16; x++) + if (_huff[x] > mask) break; + // OK UNTIL HERE + // There may be a bug from this point forward, as the + // lengths do not seem to coincide + length = bitStream.getBits(_lens[x]); + + group.lengths[j] = length; } + + _groups.push_back(group); } } } @@ -169,6 +149,19 @@ public: return item; } + /* + void seekBits(uint32 bitNum) { + uint bytes = bits / 8; + _remainderOffset = bits % 8; + _res->seek(bytes, SEEK_SET); + } + + void readBits((void*)target, uint32 bitNum) { + // Skip the first _remainderOffset bits, read bitNum from that point + byte offset = 0xFF << _remainderOffset; + + }*/ + protected: uint _lenObjs; @@ -183,6 +176,9 @@ protected: Common::File _file; Common::SeekableReadStream *_res; + // To be moved + //byte _remainderOffset; + }; /* diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 835d53ae10..dccf63ad2e 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -19,7 +19,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _saveGame = new SaveGame(_engine, saveGameRes); - _objectConstants = new Container("Shadowgate II/Shadow Object.TXT"); + _objectConstants = new Container("Shadowgate II/Shadow Graphic"); delete saveGameRes; saveGameFile.close(); @@ -47,7 +47,7 @@ bool World::loadStartGameFileName() { res->read(fileName, length); fileName[length] = '\0'; _startGameFileName = Common::String(fileName, length); - _startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".TXT"); + _startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".bin"); return true; } -- cgit v1.2.3 From b6a5040e35d93ae32ac892653c131a30c2123d6e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 01:08:57 +0200 Subject: MACVENTURE: Test and fix object loading --- engines/macventure/container.h | 99 +++++++++++++++++++++++++++--------------- engines/macventure/world.cpp | 6 ++- engines/macventure/world.h | 2 +- 3 files changed, 71 insertions(+), 36 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index c2b558f6d3..a0028eecb3 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -39,7 +39,6 @@ struct ItemGroup { typedef uint32 ContainerHeader; -template class Container { public: @@ -49,9 +48,11 @@ public: _res = _file.readStream(_file.size()); _header = _res->readUint32BE(); + _simplified = false; if (!(_header & 0x80000000)) { // Is simplified container + _simplified = true; int dataLen = _res->size() - sizeof(_header); _lenObjs = _header; _numObjs = dataLen / _lenObjs; @@ -90,24 +91,51 @@ public: // Place the bit reader in the correct position // group.bitOffset indicates the offset from the start of the subHeader - _res->seek(_header + (group.bitOffset >> 3), SEEK_SET); + _res->seek(_header + (group.bitOffset >> 3), SEEK_SET); + uint32 bits = group.bitOffset & 7; - Common::BitStream32BEMSB bitStream(_res); - // Skip the last 3 bits that we couldn't skip with seek - bitStream.skip(group.bitOffset & 7); - for (uint j = 0; j < 64; ++j) { + for (uint j = 0; j < 64; ++j) { uint32 length = 0; - uint32 mask = bitStream.peekBits(16); + //debug("reading mask from address %x", _res->pos()); + uint32 mask = _res->readUint32BE(); + mask >>= (16 - bits); + mask &= 0xFFFF; + debug(11, "Load mask of object &%d:%d is %x", i, j, mask); + _res->seek(-4, SEEK_CUR); // Look in the Huffman table - int x; - for (x = 0; x<16; x++) + int x = 0; + for (x = 0; x < 16; x++) { if (_huff[x] > mask) break; - // OK UNTIL HERE - // There may be a bug from this point forward, as the - // lengths do not seem to coincide - length = bitStream.getBits(_lens[x]); + } + + // I will opt to copy the code from webventure, + // But according to the docs, this call should suffice: + // length = bitStream.getBits(_lens[x]); + // The problem is that _lens[] usually contains values larger + // Than 32, so we have to read them with the method below + + //This code below, taken from the implementation, seems to give the same results. + + uint32 bitSize = _lens[x]; + bits += bitSize & 0xF; + if (bits & 0x10) { + bits &= 0xf; + _res->seek(2, SEEK_CUR); + } + bitSize >>= 4; + if (bitSize) { + length = _res->readUint32BE(); + _res->seek(-4, SEEK_CUR); + bitSize--; + if (bitSize == 0) length = 0; + else length >>= (32 - bitSize) - bits; + length &= (1 << bitSize) - 1; + length |= 1 << bitSize; + bits += bitSize; + } group.lengths[j] = length; + debug(11, "Load legth of object %d:%d is %d", i, j, length); } _groups.push_back(group); @@ -125,11 +153,26 @@ public: } public: - T getItem(uint32 id) { - T item; - if (!(_header & 0x80000000)) { + /** + * Must be called before retrieving an object. + */ + uint32 getItemByteSize(uint32 id) { + if (_simplified) { + return _lenObjs; + } else { + uint32 groupID = (id >> 6); + uint32 objectIndex = id & 0x3f; // Index within the group + return _groups[groupID].lengths[objectIndex]; + } + } + + /** + * Assumes storage is initialized. + */ + void getItem(uint32 id, void* storage) { + if (_simplified) { _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); - _res->read(&item, _lenObjs); + _res->read(storage, _lenObjs); } else { ContainerHeader subHead = _header & 0x7fffffff; uint32 groupID = (id >> 6); @@ -144,27 +187,15 @@ public: _res->seek(offset, SEEK_CUR); - _res->read(&item, _groups[groupID].lengths[objectIndex]); + _res->read(storage, _groups[groupID].lengths[objectIndex]); } - return item; } - - /* - void seekBits(uint32 bitNum) { - uint bytes = bits / 8; - _remainderOffset = bits % 8; - _res->seek(bytes, SEEK_SET); - } - - void readBits((void*)target, uint32 bitNum) { - // Skip the first _remainderOffset bits, read bitNum from that point - byte offset = 0xFF << _remainderOffset; - - }*/ - + protected: + + bool _simplified; - uint _lenObjs; + uint _lenObjs; // In the case of simple container, lenght of an object uint _numObjs; ContainerHeader _header; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index dccf63ad2e..68faa0a5d1 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -19,7 +19,11 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _saveGame = new SaveGame(_engine, saveGameRes); - _objectConstants = new Container("Shadowgate II/Shadow Graphic"); + _objectConstants = new Container("Shadowgate II/Shadow Graphic"); + + uint32 size = _objectConstants->getItemByteSize(2); + char * ob1 = new char[size]; + _objectConstants->getItem(2, ob1); delete saveGameRes; saveGameFile.close(); diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 41f6ddccaa..38eb4bbc9d 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -65,7 +65,7 @@ private: Common::String _startGameFileName; SaveGame *_saveGame; - Container *_objectConstants; + Container *_objectConstants; }; -- cgit v1.2.3 From 22db262d57b919a73dea71a353951cc9b0d63d53 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 17:50:32 +0200 Subject: MACVENTURE: Add string tables --- engines/macventure/stringtable.h | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 engines/macventure/stringtable.h diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h new file mode 100644 index 0000000000..87ec9775cb --- /dev/null +++ b/engines/macventure/stringtable.h @@ -0,0 +1,99 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_STRINGTABLE_H +#define MACVENTURE_STRINGTABLE_H + +#include "macventure/macventure.h" + +#include "common/file.h" + +namespace MacVenture { + +enum StringTableID { + kErrorStringTableID = 0x80, + kFilenamesStringTableID = 0x81, + kCommonArticlesStringTableID = 0x82, + kNamingArticlesStringTableID = 0x83, + kIndirectArticlesStringTableID = 0x84 +}; + +class StringTable { +public: + StringTable(MacVentureEngine *engine, Common::MacResManager *resMan, StringTableID id) { + _engine = engine; + _resourceManager = resMan; + _id = id; + + if (!loadStrings()) + error("Could not load string table %x", id); + } + + ~StringTable() { + + } + + const Common::Array *getStrings() { + return &_strings; + } + +private: + + bool loadStrings() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + + if ((resArray = _resourceManager->getResIDArray(MKTAG('S', 'T', 'R', '#'))).size() == 0) + return false; + + res = _resourceManager->getResource(MKTAG('S', 'T', 'R', '#'), _id); + + _strings.push_back("dummy"); // String tables are 1-indexed + uint16 numStrings = res->readUint16BE(); + uint8 strLength = 0; + for (uint i = 0; i < numStrings; ++i) { + strLength = res->readByte(); + char* str = new char[strLength + 1]; + res->read(str, strLength); + str[strLength] = '\0'; + debug(11, "Loaded string %s", str); + _strings.push_back(Common::String(str)); + delete[] str; + } + + return true; + } + +private: + + MacVentureEngine *_engine; + Common::MacResManager *_resourceManager; + + StringTableID _id; + + Common::Array _strings; +}; + +} // End of namespace MacVenture + +#endif + -- cgit v1.2.3 From b024a24821eac6f3b0e4513c853ca845d608c198 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 17:54:58 +0200 Subject: MACVENTURE: Change container to return a stream --- engines/macventure/container.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index a0028eecb3..e960ddb9c3 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -62,10 +62,10 @@ public: _res->seek(_header, SEEK_SET); _numObjs = _res->readUint16BE(); - for (int i = 0; i < 15; ++i) + for (uint i = 0; i < 15; ++i) _huff[i] = _res->readUint16BE(); - for (int i = 0; i < 16; ++i) + for (uint i = 0; i < 16; ++i) _lens[i] = _res->readByte(); // Read groups @@ -167,12 +167,12 @@ public: } /** - * Assumes storage is initialized. + * getItemByteSize should be called before this one */ - void getItem(uint32 id, void* storage) { + Common::SeekableReadStream *getItem(uint32 id) { if (_simplified) { _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); - _res->read(storage, _lenObjs); + return _res; } else { ContainerHeader subHead = _header & 0x7fffffff; uint32 groupID = (id >> 6); @@ -181,13 +181,13 @@ public: _res->seek(subHead + (groupID * 6), SEEK_SET); uint32 offset = 0; - for (int i = 0; i < objectIndex; i++) { + for (uint i = 0; i < objectIndex; i++) { offset += _groups[groupID].lengths[i]; } _res->seek(offset, SEEK_CUR); - _res->read(storage, _groups[groupID].lengths[objectIndex]); + return _res; } } -- cgit v1.2.3 From b209c52ed980db3fed608b2743eec2556869c1bb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 18:17:45 +0200 Subject: MACVENTURE: Add filepath retrieval --- engines/macventure/container.h | 2 +- engines/macventure/macventure.cpp | 21 +++++++++++++++++++-- engines/macventure/macventure.h | 19 +++++++++++++++++-- engines/macventure/world.cpp | 8 ++------ engines/macventure/world.h | 1 + 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index e960ddb9c3..0c6a41ee17 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -42,7 +42,7 @@ typedef uint32 ContainerHeader; class Container { public: - Container(char *filename) { + Container(const char *filename) { if (!_file.open(filename)) error("Could not open %s", filename); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 92ae709b5e..821a786924 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -53,6 +53,10 @@ MacVentureEngine::~MacVentureEngine() { delete _rnd; delete _debugger; delete _gui; + + if (_filenames) { + delete _filenames; + } } Common::Error MacVentureEngine::run() { @@ -72,6 +76,10 @@ Common::Error MacVentureEngine::run() { if (!loadGlobalSettings()) error("Could not load the engine settings"); + // Engine-wide loading + _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); + + // Big class instantiation _gui = new Gui(this, _resourceManager); _world = new World(this, _resourceManager); @@ -96,7 +104,7 @@ void MacVentureEngine::requestUnpause() { _paused = false; } -const GlobalSettings& MacVentureEngine::getGlobalSettings() { +const GlobalSettings& MacVentureEngine::getGlobalSettings() const { return _globalSettings; } @@ -106,7 +114,7 @@ bool MacVentureEngine::isPaused() { return _paused; } -Common::String MacVentureEngine::getCommandsPausedString() { +Common::String MacVentureEngine::getCommandsPausedString() const { return Common::String("Click to continue"); } @@ -127,6 +135,15 @@ void MacVentureEngine::processEvents() { } } +Common::String MacVentureEngine::getFilePath(FilePathID id) const { + const Common::Array *names = _filenames->getStrings(); + if (id <= 3) { // We don't want a file in the subdirectory + return Common::String((*names)[id]); + } else { // We want a game file + return Common::String((*names)[3] + "/" + (*names)[id]); + } +} + // Data loading bool MacVentureEngine::loadGlobalSettings() { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 3a20bbe2a8..d4f1a33fb9 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -32,6 +32,7 @@ #include "macventure/gui.h" #include "macventure/world.h" +#include "macventure/stringtable.h" struct ADGameDescription; @@ -65,6 +66,18 @@ enum { kStartGameFilenameID = 0x85 }; +enum FilePathID { + kMCVID = 1, + kTitlePathID = 2, + kSubdirPathID = 3, + kObjectPathID = 4, + kFilterPathID = 5, + kTextPathID = 6, + kGraphicPathID = 7, + kSoundPathID = 8 +}; + + struct GlobalSettings { uint16 numObjects; // number of game objects defined uint16 numGlobals; // number of globals defined @@ -99,8 +112,9 @@ public: // Data retrieval bool isPaused(); - Common::String getCommandsPausedString(); - const GlobalSettings& getGlobalSettings(); + Common::String getCommandsPausedString() const; + const GlobalSettings& getGlobalSettings() const; + Common::String getFilePath(FilePathID id) const; private: void processEvents(); @@ -121,6 +135,7 @@ private: // Attributes // Engine state GlobalSettings _globalSettings; + StringTable *_filenames; bool _shouldQuit; bool _paused; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 68faa0a5d1..cdc0e1682e 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -19,12 +19,8 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _saveGame = new SaveGame(_engine, saveGameRes); - _objectConstants = new Container("Shadowgate II/Shadow Graphic"); - - uint32 size = _objectConstants->getItemByteSize(2); - char * ob1 = new char[size]; - _objectConstants->getItem(2, ob1); - + _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); + delete saveGameRes; saveGameFile.close(); } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 38eb4bbc9d..eed7b50363 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -66,6 +66,7 @@ private: SaveGame *_saveGame; Container *_objectConstants; + Container *_gameText; }; -- cgit v1.2.3 From bc435b398e0c6ad0afb48f1d30721d3d4588d6c6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 19:02:14 +0200 Subject: MACVENTURE: Add text huffman loading --- engines/macventure/image.h | 40 ++++++++++++++++++++++++++++++++++++ engines/macventure/macventure.cpp | 43 +++++++++++++++++++++++++++++++++++---- engines/macventure/macventure.h | 4 ++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 engines/macventure/image.h diff --git a/engines/macventure/image.h b/engines/macventure/image.h new file mode 100644 index 0000000000..5bf6ccf7ac --- /dev/null +++ b/engines/macventure/image.h @@ -0,0 +1,40 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_IMAGE_H +#define MACVENTURE_IMAGE_H + +#include "macventure/macventure.h" + +namespace MacVenture { + +class Image { +public: + Image(); + ~Image(); + + void blit(Graphics::ManagedSurface *target); +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 821a786924..0e3e5a5e5b 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -54,9 +54,11 @@ MacVentureEngine::~MacVentureEngine() { delete _debugger; delete _gui; - if (_filenames) { + if (_filenames) delete _filenames; - } + + if (_textHuffman) + delete _textHuffman; } Common::Error MacVentureEngine::run() { @@ -73,12 +75,14 @@ Common::Error MacVentureEngine::run() { if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); + // Engine-wide loading if (!loadGlobalSettings()) error("Could not load the engine settings"); - // Engine-wide loading + _oldTextEncoding = !loadTextHuffman(); + _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); - + // Big class instantiation _gui = new Gui(this, _resourceManager); _world = new World(this, _resourceManager); @@ -192,5 +196,36 @@ bool MacVentureEngine::loadGlobalSettings() { return false; } +bool MacVentureEngine::loadTextHuffman() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + + if ((resArray = _resourceManager->getResIDArray(MKTAG('G', 'N', 'R', 'L'))).size() == 0) + return false; + + res = _resourceManager->getResource(MKTAG('G', 'N', 'R', 'L'), kTextHuffmanTableID); + if (res) { + uint32 numEntries = res->readUint16BE(); + res->readUint16BE(); // Skip + + uint32 *masks = new uint32[numEntries]; + for (uint i = 0; i < numEntries - 1; i++) + // For some reason there are one lass mask than entries + masks[i] = res->readUint16BE(); + + uint8 *lengths = new uint8[numEntries]; + for (uint i = 0; i < numEntries; i++) + lengths[i] = res->readByte(); + + uint32 *values = new uint32[numEntries]; + for (uint i = 0; i < numEntries; i++) + values[i] = res->readByte(); + + _textHuffman = new Common::Huffman(0, numEntries, masks, lengths, values); + + return true; + } + return false; +} } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index d4f1a33fb9..8e11612870 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -27,6 +27,7 @@ #include "common/debug.h" #include "common/random.h" #include "common/macresman.h" +#include "common/huffman.h" #include "gui/debugger.h" @@ -121,6 +122,7 @@ private: // Data loading bool loadGlobalSettings(); + bool loadTextHuffman(); private: // Attributes @@ -136,6 +138,8 @@ private: // Attributes // Engine state GlobalSettings _globalSettings; StringTable *_filenames; + Common::Huffman *_textHuffman; + bool _oldTextEncoding; bool _shouldQuit; bool _paused; -- cgit v1.2.3 From a112cdcb9dd8349390a54b8c5cd2c0c8bc3ad66a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 20:33:02 +0200 Subject: MACVENTURE: Add object attribute retrieval --- engines/macventure/macventure.cpp | 14 +++++++++----- engines/macventure/macventure.h | 10 ++++++++++ engines/macventure/world.cpp | 21 +++++++++++++++++++++ engines/macventure/world.h | 3 ++- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 0e3e5a5e5b..383832b80e 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -88,9 +88,9 @@ Common::Error MacVentureEngine::run() { _world = new World(this, _resourceManager); _shouldQuit = false; - while (!_shouldQuit) { + while (!(_gameState == kGameStateQuitting)) { processEvents(); - + _gui->draw(); g_system->updateScreen(); @@ -102,10 +102,12 @@ Common::Error MacVentureEngine::run() { void MacVentureEngine::requestQuit() { _shouldQuit = true; + _gameState = kGameStateQuitting; } void MacVentureEngine::requestUnpause() { _paused = false; + _gameState = kGameStatePlaying; } const GlobalSettings& MacVentureEngine::getGlobalSettings() const { @@ -130,8 +132,8 @@ void MacVentureEngine::processEvents() { continue; switch (event.type) { - case Common::EVENT_QUIT: - _shouldQuit = true; + case Common::EVENT_QUIT: + _gameState = kGameStateQuitting; break; default: break; @@ -222,10 +224,12 @@ bool MacVentureEngine::loadTextHuffman() { values[i] = res->readByte(); _textHuffman = new Common::Huffman(0, numEntries, masks, lengths, values); - + debug(5, "Text is huffman-encoded"); return true; } return false; } + + } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 8e11612870..e4cda4e11b 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -100,6 +100,15 @@ struct GlobalSettings { uint8 *commands; // command buttons }; +enum GameState { + kGameStateInit, + kGameStatePlaying, + kGameStateWinnig, + kGameStateLosing, + kGameStateQuitting +}; + + class MacVentureEngine : public Engine { public: @@ -136,6 +145,7 @@ private: // Attributes World *_world; // Engine state + GameState _gameState; GlobalSettings _globalSettings; StringTable *_filenames; Common::Huffman *_textHuffman; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index cdc0e1682e..209b3c1096 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -19,6 +19,9 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _saveGame = new SaveGame(_engine, saveGameRes); + debug("%x", _saveGame->getGroups()[0][1]); + debug(11, "Parent of player is %d", getObjAttr(1, 0)); + _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); delete saveGameRes; @@ -35,6 +38,24 @@ World::~World() { delete _objectConstants; } + +uint32 World::getObjAttr(uint32 objID, uint32 attrID) { + uint32 res; + uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; + if (!(index & 0x80)) { // It's not a constant + res = _saveGame->getGroups()[attrID][objID]; + } else { + Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); + index &= 0x7F; + objStream->skip((index * 2) - 1); + res = objStream->readUint16BE(); + } + res &= _engine->getGlobalSettings().attrMasks[attrID]; + res >>= _engine->getGlobalSettings().attrShifts[attrID]; + debug(11, "Attribute %x from object %x is %x", attrID, objID, res); + return res; +} + bool World::loadStartGameFileName() { Common::SeekableReadStream *res; diff --git a/engines/macventure/world.h b/engines/macventure/world.h index eed7b50363..9a74e5ce3e 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -55,6 +55,8 @@ public: World(MacVentureEngine *engine, Common::MacResManager *resMan); ~World(); + uint32 getObjAttr(uint32 objID, uint32 attrID); + private: bool loadStartGameFileName(); @@ -67,7 +69,6 @@ private: SaveGame *_saveGame; Container *_objectConstants; Container *_gameText; - }; } // End of namespace MacVenture -- cgit v1.2.3 From ef5a1525149b8f9cfc6806fdb46217d912025195 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 16 Jun 2016 23:04:10 +0200 Subject: MACVENTURE: Add main loop --- engines/macventure/macventure.cpp | 157 +++++++++++++++++++++++++++++++++----- engines/macventure/macventure.h | 53 ++++++++++++- engines/macventure/script.h | 72 +++++++++++++++++ engines/macventure/world.cpp | 12 +-- engines/macventure/world.h | 30 +++++++- 5 files changed, 294 insertions(+), 30 deletions(-) create mode 100644 engines/macventure/script.h diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 383832b80e..8466c1bf2d 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -53,10 +53,11 @@ MacVentureEngine::~MacVentureEngine() { delete _rnd; delete _debugger; delete _gui; + delete _scriptEngine; - if (_filenames) + if (_filenames) delete _filenames; - + if (_textHuffman) delete _textHuffman; } @@ -80,18 +81,42 @@ Common::Error MacVentureEngine::run() { error("Could not load the engine settings"); _oldTextEncoding = !loadTextHuffman(); - + _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); - + // Big class instantiation _gui = new Gui(this, _resourceManager); _world = new World(this, _resourceManager); + _scriptEngine = new ScriptEngine(); - _shouldQuit = false; + _paused = false; + _halted = true; + _cmdReady = false; + _haltedAtEnd = false; + _haltedInSelection = false; while (!(_gameState == kGameStateQuitting)) { processEvents(); - - _gui->draw(); + + if (!_halted) { + _gui->draw(); + } + + if (_cmdReady || _halted) { + _halted = false; + if (runScriptEngine()) { + _halted = true; + _paused = true; + } else { + _paused = false; + if (!updateState()) { + updateControls(); + } + } + } + + if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { + endGame(); + } g_system->updateScreen(); g_system->delayMillis(50); @@ -101,29 +126,34 @@ Common::Error MacVentureEngine::run() { } void MacVentureEngine::requestQuit() { - _shouldQuit = true; + // TODO: Display save game dialog and such _gameState = kGameStateQuitting; } void MacVentureEngine::requestUnpause() { _paused = false; - _gameState = kGameStatePlaying; + _gameState = kGameStatePlaying; } -const GlobalSettings& MacVentureEngine::getGlobalSettings() const { - return _globalSettings; +void MacVentureEngine::enqueueObject(ObjID id) { + QueuedObject obj; + obj.parent = _world->getObjAttr(id, kAttrParentObject); + obj.x = _world->getObjAttr(id, kAttrPosX); + obj.y = _world->getObjAttr(id, kAttrPosY); + obj.exitx = _world->getObjAttr(id, kAttrExitX); + obj.exity = _world->getObjAttr(id, kAttrExitY); + obj.hidden = _world->getObjAttr(id, kAttrHiddenExit); + obj.offsecreen = _world->getObjAttr(id, kAttrInvisible); + obj.invisible = _world->getObjAttr(id, kAttrUnclickable); + _objQueue.push_back(obj); } -// Data retrieval - -bool MacVentureEngine::isPaused() { - return _paused; +const GlobalSettings& MacVentureEngine::getGlobalSettings() const { + return _globalSettings; } -Common::String MacVentureEngine::getCommandsPausedString() const { - return Common::String("Click to continue"); -} +// Private engine methods void MacVentureEngine::processEvents() { Common::Event event; @@ -132,7 +162,7 @@ void MacVentureEngine::processEvents() { continue; switch (event.type) { - case Common::EVENT_QUIT: + case Common::EVENT_QUIT: _gameState = kGameStateQuitting; break; default: @@ -141,6 +171,91 @@ void MacVentureEngine::processEvents() { } } +bool MacVenture::MacVentureEngine::runScriptEngine() { + debug(5, "MAIN: Running script engine"); + if (_haltedAtEnd) { + _haltedAtEnd = false; + if (_scriptEngine->resume()) { + _haltedAtEnd = true; + return true; + } + return false; + } + + if (_haltedInSelection) { + _haltedInSelection = false; + if (_scriptEngine->resume()) { + _haltedInSelection = true; + return true; + } + if (updateState()) + return true; + } + + while (!_currentSelection.empty()) { + ObjID obj = _currentSelection.front(); + _currentSelection.pop_front(); + if ((_gameState == kGameStateInit || _gameState == kGameStatePlaying) && _world->isObjActive(obj)) { + if (_scriptEngine->runControl(_selectedControl, obj, _destObject, _deltaPoint)) { + _haltedInSelection = true; + return true; + } + if (updateState()) { + return true; + } + } + } + if (_selectedControl == 1) + _gameChanged = false; + + else if (_gameState == kGameStateInit || _gameState == kGameStatePlaying){ + if (_scriptEngine->runControl(kTick, _selectedControl, _destObject, _deltaPoint)) { + _haltedAtEnd = true; + return true; + } + } + return false; +} + +void MacVentureEngine::endGame() { + requestQuit(); +} + +bool MacVentureEngine::updateState() { + runObjQueue(); + return true; +} + +void MacVentureEngine::runObjQueue() { + +} + +void MacVentureEngine::updateControls() { + if (_activeControl) + _activeControl = kNoCommand; + // toggleExits(); + // resetVars(); +} + +void MacVentureEngine::resetVars() { + _selectedControl = kNoCommand; + _activeControl = kNoCommand; + _currentSelection.clear(); + _destObject = 0; + _deltaPoint = Common::Point(0, 0); + _cmdReady = false; +} + +// Data retrieval + +bool MacVentureEngine::isPaused() { + return _paused; +} + +Common::String MacVentureEngine::getCommandsPausedString() const { + return Common::String("Click to continue"); +} + Common::String MacVentureEngine::getFilePath(FilePathID id) const { const Common::Array *names = _filenames->getStrings(); if (id <= 3) { // We don't want a file in the subdirectory @@ -226,8 +341,8 @@ bool MacVentureEngine::loadTextHuffman() { _textHuffman = new Common::Huffman(0, numEntries, masks, lengths, values); debug(5, "Text is huffman-encoded"); return true; - } - return false; + } + return false; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index e4cda4e11b..e1a147c28a 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -34,6 +34,7 @@ #include "macventure/gui.h" #include "macventure/world.h" #include "macventure/stringtable.h" +#include "macventure/script.h" struct ADGameDescription; @@ -41,6 +42,9 @@ namespace MacVenture { class Console; class World; +class ScriptEngine; + +typedef uint32 ObjID; enum { kScreenWidth = 512, @@ -108,6 +112,29 @@ enum GameState { kGameStateQuitting }; +enum ObjectQueueID { + kFocusWindow = 2, + kOpenWindow = 3, + kCloseWindow = 4, + kUpdateObject = 7, + kUpdateWindow = 8, + kSetToPlayerParent = 12, + kHightlightExits = 13, + kAnimateBack = 14 +}; + +struct QueuedObject { + ObjectQueueID id; + ObjID object; + ObjID parent; + uint x; + uint y; + uint exitx; + uint exity; + bool hidden; + bool offsecreen; + bool invisible; +}; class MacVentureEngine : public Engine { @@ -120,6 +147,8 @@ public: void requestQuit(); void requestUnpause(); + void enqueueObject(ObjID id); + // Data retrieval bool isPaused(); Common::String getCommandsPausedString() const; @@ -129,6 +158,13 @@ public: private: void processEvents(); + bool runScriptEngine(); + void endGame(); + bool updateState(); + void runObjQueue(); + void updateControls(); + void resetVars(); + // Data loading bool loadGlobalSettings(); bool loadTextHuffman(); @@ -143,6 +179,7 @@ private: // Attributes Console *_debugger; Gui *_gui; World *_world; + ScriptEngine *_scriptEngine; // Engine state GameState _gameState; @@ -150,8 +187,20 @@ private: // Attributes StringTable *_filenames; Common::Huffman *_textHuffman; bool _oldTextEncoding; - bool _shouldQuit; - bool _paused; + bool _paused, _halted, _cmdReady; + bool _haltedAtEnd, _haltedInSelection; + bool _gameChanged; + + Common::List _objQueue; + Common::List _soundQueue; + Common::List _textQueue; + + // Selections + ObjID _destObject; + ControlAction _selectedControl; + ControlAction _activeControl; + Common::List _currentSelection; + Common::Point _deltaPoint; private: // Methods diff --git a/engines/macventure/script.h b/engines/macventure/script.h new file mode 100644 index 0000000000..66376924b0 --- /dev/null +++ b/engines/macventure/script.h @@ -0,0 +1,72 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_SCRIPT_H +#define MACVENTURE_SCRIPT_H + +#include "macventure/macventure.h" + +namespace MacVenture { + +enum ControlAction { + kNoCommand = 0, + kStartOrResume = 1, + kClose = 2, + kTick = 3, + kActivateObject = 4, + kMoveObject = 5, + kConsume = 6, + kExamine = 7, + kGo = 8, + kHit = 9, + kOpen = 10, + kOperate = 11, + kSpeak = 12, + kBabble = 13, + kTargetName = 14, + kDebugObject = 15 +}; + +typedef uint32 ObjID; + +class ScriptEngine { +public: + ScriptEngine() {} + ~ScriptEngine() {} + + bool runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta) { + debug(7, "SCRIPT: Running control %d from obj %d into obj %d, at delta (%d, %d)", + action, source, destination, delta.x, delta.y); + + return false; + } + + bool resume() { + debug(7, "SCRIPT: Resume"); + + return false; + } +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 209b3c1096..d8fd9b4e39 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -17,11 +17,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); - _saveGame = new SaveGame(_engine, saveGameRes); - - debug("%x", _saveGame->getGroups()[0][1]); - debug(11, "Parent of player is %d", getObjAttr(1, 0)); - + _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); delete saveGameRes; @@ -39,7 +35,7 @@ World::~World() { } -uint32 World::getObjAttr(uint32 objID, uint32 attrID) { +uint32 World::getObjAttr(ObjID objID, uint32 attrID) { uint32 res; uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; if (!(index & 0x80)) { // It's not a constant @@ -56,6 +52,10 @@ uint32 World::getObjAttr(uint32 objID, uint32 attrID) { return res; } +bool MacVenture::World::isObjActive(ObjID obj) { + return false; +} + bool World::loadStartGameFileName() { Common::SeekableReadStream *res; diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 9a74e5ce3e..e5c728ef58 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -28,8 +28,35 @@ namespace MacVenture { +typedef uint32 ObjID; typedef Common::Array AttributeGroup; +enum ObjectAttributeID { + kAttrParentObject = 0, + kAttrPosX = 1, + kAttrPosY = 2, + kAttrInvisible = 3, + kAttrUnclickable = 4, + kAttrUndraggable = 5, + kAttrContainerOpen = 6, + kAttrPrefixes = 7, + kAttrIsExit = 8, + kAttrExitX = 9, + kAttrExitY = 10, + kAttrHiddenExit = 11, + kAttrOtherDoor = 12, + kAttrIsOpen = 13, + kAttrIsLocked = 14, + kAttrWeight = 16, + kAttrSize = 17, + kAttrHasDescription = 19, + kAttrIsDoor = 20, + kAttrIsContainer = 22, + kAttrIsOperable = 23, + kAttrIsEnterable = 24, + kAttrIsEdible = 25 +}; + class SaveGame { public: SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res); @@ -55,7 +82,8 @@ public: World(MacVentureEngine *engine, Common::MacResManager *resMan); ~World(); - uint32 getObjAttr(uint32 objID, uint32 attrID); + uint32 getObjAttr(ObjID objID, uint32 attrID); + bool isObjActive(ObjID obj); private: bool loadStartGameFileName(); -- cgit v1.2.3 From 79496ea5c07cf3da9fef845e53b6df2c36a6a8e7 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 12:44:52 +0200 Subject: MACVENTURE: Add command activation --- engines/macventure/gui.cpp | 37 +++++++++++++++++++++-------------- engines/macventure/gui.h | 5 +++++ engines/macventure/macventure.cpp | 41 +++++++++++++++++++++++++++++++++++++++ engines/macventure/macventure.h | 5 +++++ 4 files changed, 73 insertions(+), 15 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 3aa9c5de33..aeca8df1c9 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -68,7 +68,7 @@ static const Graphics::MenuData menuSubItems[] = { { 0, NULL, 0, 0, false } }; -bool controlsWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); +bool commandsWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool mainGameWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool selfWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); @@ -145,7 +145,7 @@ void Gui::initWindows() { _controlsWindow = _wm.addWindow(false, false, false); _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); _controlsWindow->setActive(false); - _controlsWindow->setCallback(controlsWindowCallback, this); + _controlsWindow->setCallback(commandsWindowCallback, this); loadBorder(_controlsWindow, "border_command.bmp", false); loadBorder(_controlsWindow, "border_command.bmp", true); @@ -462,7 +462,7 @@ void Gui::drawSelfWindow() { /* CALLBACKS */ -bool controlsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { +bool commandsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; @@ -564,20 +564,27 @@ void Gui::handleMenuAction(MenuAction action) { bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { - if (_engine->isPaused()) { - _engine->requestUnpause(); - } else { - Common::Point position( - event.mouse.x - _controlsWindow->getDimensions().left, - event.mouse.y - _controlsWindow->getDimensions().top); - Common::List::const_iterator it = _controlData->begin(); - for (; it != _controlData->end(); ++it) { - const CommandButton &data = *it; - if (data.isInsideBounds(position)) { - debug("Command active: %s", data.getData().title); - } + if (_engine->isPaused()) + return true; + + Common::Point position( + event.mouse.x - _controlsWindow->getDimensions().left, + event.mouse.y - _controlsWindow->getDimensions().top); + + CommandButton data; + Common::List::const_iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + if (it->isInsideBounds(position)) { + debug("Command active: %s", it->getData().title); + data = *it; } } + + _engine->selectControl((ControlReference)data.getData().refcon); + _engine->activateCommand((ControlReference)data.getData().refcon); + + // Run main + } return false; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 1eba4d231b..4d760e8382 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -198,6 +198,11 @@ enum { }; public: + + CommandButton() { + _gui = nullptr; + } + CommandButton(ControlData data, Gui *g) { _data = data; _gui = g; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 8466c1bf2d..27a2aad1fc 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -135,6 +135,22 @@ void MacVentureEngine::requestUnpause() { _gameState = kGameStatePlaying; } +void MacVentureEngine::selectControl(ControlReference id) { + ControlAction action = referenceToAction(id); + debug(7, "Select control %x", action); + _selectedControl = action; +} + +void MacVentureEngine::activateCommand(ControlReference id) { + ControlAction action = referenceToAction(id); + if (action != _activeControl) { + if (_activeControl) + _activeControl = kNoCommand; + _activeControl = action; + } + debug(7, "Activating Command %x... Command %x is active", action, _activeControl); +} + void MacVentureEngine::enqueueObject(ObjID id) { QueuedObject obj; obj.parent = _world->getObjAttr(id, kAttrParentObject); @@ -246,6 +262,31 @@ void MacVentureEngine::resetVars() { _cmdReady = false; } +ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlReference id) { + switch (id) { + case MacVenture::kControlExitBox: + return kActivateObject;//?? + case MacVenture::kControlExamine: + return kExamine; + case MacVenture::kControlOpen: + return kOpen; + case MacVenture::kControlClose: + return kClose; + case MacVenture::kControlSpeak: + return kSpeak; + case MacVenture::kControlOperate: + return kOperate; + case MacVenture::kControlGo: + return kGo; + case MacVenture::kControlHit: + return kHit; + case MacVenture::kControlConsume: + return kConsume; + default: + return kNoCommand; + } +} + // Data retrieval bool MacVentureEngine::isPaused() { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index e1a147c28a..8fe5792e7c 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -146,6 +146,8 @@ public: void requestQuit(); void requestUnpause(); + void selectControl(ControlReference id); + void activateCommand(ControlReference id); void enqueueObject(ObjID id); @@ -169,6 +171,9 @@ private: bool loadGlobalSettings(); bool loadTextHuffman(); + // Utils + ControlAction referenceToAction(ControlReference id); + private: // Attributes const ADGameDescription *_gameDescription; -- cgit v1.2.3 From ec768fbec167321914326a54a7efc2032e03c3e3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 12:53:32 +0200 Subject: MACVENTURE: Test and complete main loop --- engines/macventure/gui.cpp | 5 ++-- engines/macventure/macventure.cpp | 61 +++++++++++++++++++++++++++++---------- engines/macventure/macventure.h | 5 +++- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index aeca8df1c9..4ca3de70b3 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -582,9 +582,8 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { _engine->selectControl((ControlReference)data.getData().refcon); _engine->activateCommand((ControlReference)data.getData().refcon); - - // Run main - + _engine->refreshReady(); + _engine->preparedToRun(); } return false; } diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 27a2aad1fc..3b453563a6 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -94,28 +94,34 @@ Common::Error MacVentureEngine::run() { _cmdReady = false; _haltedAtEnd = false; _haltedInSelection = false; + _prepared = true; while (!(_gameState == kGameStateQuitting)) { processEvents(); - if (!_halted) { - _gui->draw(); - } + if (_prepared) { + _prepared = false; + + if (!_halted) { + _gui->draw(); + } - if (_cmdReady || _halted) { - _halted = false; - if (runScriptEngine()) { - _halted = true; - _paused = true; - } else { - _paused = false; - if (!updateState()) { - updateControls(); + if (_cmdReady || _halted) { + _halted = false; + if (runScriptEngine()) { + _halted = true; + _paused = true; + } + else { + _paused = false; + if (!updateState()) { + updateControls(); + } } } - } - if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { - endGame(); + if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { + endGame(); + } } g_system->updateScreen(); @@ -144,13 +150,32 @@ void MacVentureEngine::selectControl(ControlReference id) { void MacVentureEngine::activateCommand(ControlReference id) { ControlAction action = referenceToAction(id); if (action != _activeControl) { - if (_activeControl) + if (_activeControl) _activeControl = kNoCommand; _activeControl = action; } debug(7, "Activating Command %x... Command %x is active", action, _activeControl); } +void MacVentureEngine::refreshReady() { + switch (objectsToApplyCommand()) { + case 0: // No selected object + _cmdReady = true; + break; + case 1: // We have some selected object + _cmdReady = _currentSelection.size() != 0; + break; + case 2: + if (_destObject > 0) // We have a destination seleted + _cmdReady = true; + break; + } +} + +void MacVentureEngine::preparedToRun() { + _prepared = true; +} + void MacVentureEngine::enqueueObject(ObjID id) { QueuedObject obj; obj.parent = _world->getObjAttr(id, kAttrParentObject); @@ -287,6 +312,10 @@ ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlReference i } } +uint MacVentureEngine::objectsToApplyCommand() { + return uint(); +} + // Data retrieval bool MacVentureEngine::isPaused() { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 8fe5792e7c..16d4d8de63 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -148,6 +148,8 @@ public: void requestUnpause(); void selectControl(ControlReference id); void activateCommand(ControlReference id); + void refreshReady(); + void preparedToRun(); void enqueueObject(ObjID id); @@ -173,6 +175,7 @@ private: // Utils ControlAction referenceToAction(ControlReference id); + uint objectsToApplyCommand(); private: // Attributes @@ -192,7 +195,7 @@ private: // Attributes StringTable *_filenames; Common::Huffman *_textHuffman; bool _oldTextEncoding; - bool _paused, _halted, _cmdReady; + bool _paused, _halted, _cmdReady, _prepared; bool _haltedAtEnd, _haltedInSelection; bool _gameChanged; -- cgit v1.2.3 From da174b708c74b051d297fb23e61b70faf96448d4 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 14:16:35 +0200 Subject: MACVENTURE: Fix small retrieval bug --- engines/macventure/container.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 0c6a41ee17..3573ddabeb 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -56,8 +56,7 @@ public: int dataLen = _res->size() - sizeof(_header); _lenObjs = _header; _numObjs = dataLen / _lenObjs; - } - else { + } else { _header &= 0x7fffffff; _res->seek(_header, SEEK_SET); _numObjs = _res->readUint16BE(); @@ -178,7 +177,7 @@ public: uint32 groupID = (id >> 6); uint32 objectIndex = id & 0x3f; // Index within the group - _res->seek(subHead + (groupID * 6), SEEK_SET); + _res->seek((groupID * 6), SEEK_SET); uint32 offset = 0; for (uint i = 0; i < objectIndex; i++) { -- cgit v1.2.3 From c42451bf22d22f10c73013aec169689fad26ded6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 14:21:03 +0200 Subject: MACVENTURE: Fix (another) small retrieval bug --- engines/macventure/container.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 3573ddabeb..9cfa013c82 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -177,7 +177,7 @@ public: uint32 groupID = (id >> 6); uint32 objectIndex = id & 0x3f; // Index within the group - _res->seek((groupID * 6), SEEK_SET); + _res->seek(4 + (groupID * 6), SEEK_SET); uint32 offset = 0; for (uint i = 0; i < objectIndex; i++) { -- cgit v1.2.3 From aae8378afdc8372ba788363587d0b919b9d96d93 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 15:54:55 +0200 Subject: MACVENTURE: Remove unused variables --- engines/macventure/container.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 9cfa013c82..bd88f663b8 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -30,7 +30,6 @@ namespace MacVenture { - struct ItemGroup { uint32 bitOffset; //It's really uint24 uint32 offset; //It's really uint24 @@ -173,7 +172,6 @@ public: _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); return _res; } else { - ContainerHeader subHead = _header & 0x7fffffff; uint32 groupID = (id >> 6); uint32 objectIndex = id & 0x3f; // Index within the group -- cgit v1.2.3 From 9c10b431ce3a59588571fbb77d8ae861f2de4c50 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 15:55:23 +0200 Subject: MACVENTURE: Add text decoding (without composite) --- engines/macventure/hufflists.h | 57 +++++++++++++++ engines/macventure/macventure.cpp | 21 ++++-- engines/macventure/macventure.h | 5 +- engines/macventure/module.mk | 1 + engines/macventure/text.cpp | 146 ++++++++++++++++++++++++++++++++++++++ engines/macventure/text.h | 56 +++++++++++++++ engines/macventure/world.cpp | 7 +- engines/macventure/world.h | 2 + 8 files changed, 287 insertions(+), 8 deletions(-) create mode 100644 engines/macventure/hufflists.h create mode 100644 engines/macventure/text.cpp create mode 100644 engines/macventure/text.h diff --git a/engines/macventure/hufflists.h b/engines/macventure/hufflists.h new file mode 100644 index 0000000000..1ea4f21535 --- /dev/null +++ b/engines/macventure/hufflists.h @@ -0,0 +1,57 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_HUFFLIST_H +#define MACVENTURE_HUFFLIST_H + +namespace MacVenture { + +// The engine uses a <= comparison instead of ==, so I can't use Common::Huffman +class HuffmanLists { +public: + HuffmanLists() { + _numEntries = 0; + } + HuffmanLists(uint32 num, uint32 *lens, uint32 *masks, uint32 *symbols) { + _numEntries = num; + _lens = Common::Array(lens, num); + _masks = Common::Array(masks, num); + _symbols = Common::Array(symbols, num); + } + ~HuffmanLists() {} + + + uint32 getNumEntries() const { return _numEntries; } + uint32 getLength(uint32 index) const { return _lens[index]; } + uint32 getMask(uint32 index) const { return _masks[index]; } + uint32 getSymbol(uint32 index) const { return _symbols[index]; } + +private: + uint32 _numEntries; + Common::Array _lens; + Common::Array _masks; + Common::Array _symbols; +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 3b453563a6..2054c5eab6 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -42,6 +42,7 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD _rnd = new Common::RandomSource("macventure"); _debugger= NULL; + _gui = NULL; debug("MacVenture::MacVentureEngine()"); } @@ -143,7 +144,7 @@ void MacVentureEngine::requestUnpause() { void MacVentureEngine::selectControl(ControlReference id) { ControlAction action = referenceToAction(id); - debug(7, "Select control %x", action); + debug(4, "Select control %x", action); _selectedControl = action; } @@ -154,7 +155,7 @@ void MacVentureEngine::activateCommand(ControlReference id) { _activeControl = kNoCommand; _activeControl = action; } - debug(7, "Activating Command %x... Command %x is active", action, _activeControl); + debug(4, "Activating Command %x... Command %x is active", action, _activeControl); } void MacVentureEngine::refreshReady() { @@ -213,7 +214,7 @@ void MacVentureEngine::processEvents() { } bool MacVenture::MacVentureEngine::runScriptEngine() { - debug(5, "MAIN: Running script engine"); + debug(4, "MAIN: Running script engine"); if (_haltedAtEnd) { _haltedAtEnd = false; if (_scriptEngine->resume()) { @@ -335,6 +336,14 @@ Common::String MacVentureEngine::getFilePath(FilePathID id) const { } } +bool MacVentureEngine::isOldText() const { + return _oldTextEncoding; +} + +const HuffmanLists * MacVentureEngine::getDecodingHuffman() const { + return _textHuffman; +} + // Data loading bool MacVentureEngine::loadGlobalSettings() { @@ -400,7 +409,7 @@ bool MacVentureEngine::loadTextHuffman() { // For some reason there are one lass mask than entries masks[i] = res->readUint16BE(); - uint8 *lengths = new uint8[numEntries]; + uint32 *lengths = new uint32[numEntries]; for (uint i = 0; i < numEntries; i++) lengths[i] = res->readByte(); @@ -408,8 +417,8 @@ bool MacVentureEngine::loadTextHuffman() { for (uint i = 0; i < numEntries; i++) values[i] = res->readByte(); - _textHuffman = new Common::Huffman(0, numEntries, masks, lengths, values); - debug(5, "Text is huffman-encoded"); + _textHuffman = new HuffmanLists(numEntries, lengths, masks, values); + debug(4, "Text is huffman-encoded"); return true; } return false; diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 16d4d8de63..656aeaf2b6 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -33,6 +33,7 @@ #include "macventure/gui.h" #include "macventure/world.h" +#include "macventure/hufflists.h" #include "macventure/stringtable.h" #include "macventure/script.h" @@ -158,6 +159,8 @@ public: Common::String getCommandsPausedString() const; const GlobalSettings& getGlobalSettings() const; Common::String getFilePath(FilePathID id) const; + bool isOldText() const; + const HuffmanLists *getDecodingHuffman() const; private: void processEvents(); @@ -193,7 +196,7 @@ private: // Attributes GameState _gameState; GlobalSettings _globalSettings; StringTable *_filenames; - Common::Huffman *_textHuffman; + HuffmanLists *_textHuffman; bool _oldTextEncoding; bool _paused, _halted, _cmdReady, _prepared; bool _haltedAtEnd, _haltedInSelection; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 2fac1b5347..47e0c702e4 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ detection.o \ gui.o \ object.o \ + text.o \ macventure.o \ world.o \ diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp new file mode 100644 index 0000000000..adac94bdd2 --- /dev/null +++ b/engines/macventure/text.cpp @@ -0,0 +1,146 @@ +/* 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 "macventure/text.h" + +namespace MacVenture { +TextAsset::TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman) { + _id = objid; + _container = container; + _huffman = huffman; + + if (isOld) { + decodeOld(); + } + else { + decodeHuffman(); + } +} + +void TextAsset::decodeOld() { + Common::SeekableReadStream *res = _container->getItem(_id); + uint16 strLen = res->readUint16BE(); + Common::BitStream32BELSB stream(res); + char* str = new char[strLen + 1]; + bool lowercase = false; + char c; + for (uint16 i = 0; i < strLen; i++) { + char val = stream.getBits(5); + if (val == 0x0) { // Space + c = ' '; + } + else if (val >= 0x1 && val <= 0x1A) { + if (lowercase) { // Ascii a-z + c = val + 0x60; + } + else { // Ascii A-Z + c = val + 0x40; + } + lowercase = true; + } + else if (val == 0x1B) { + if (lowercase) { + c = '.'; + } + else { + c = ','; + } + lowercase = true; + } + else if (val == 0x1C) { + if (lowercase) { + c = 0x27; // Ascii ' + } + else { + c = 0x22; // Ascii '"' + } + lowercase = true; + } + else if (val == 0x1D) { // Composite + warning("Composite strings not implemented"); + stream.getBits(16); + lowercase = true; + } + else if (val == 0x1E) { + c = stream.getBits(8); + lowercase = true; + } + else if (val == 0x1F) { + lowercase = !lowercase; + } + else { + warning("Unrecognized char in old text %d, pos %d", _id, i); + } + str[i] = c; + } + + str[strLen] = '\0'; + debug(7, "Decoded %d string (old): %s", _id, str); + _decoded = Common::String(str); +} + +void TextAsset::decodeHuffman() { + _decoded = Common::String("Huffman string"); + Common::SeekableReadStream *res = _container->getItem(_id); + Common::BitStream32BEMSB stream(res); + uint16 strLen = 0; + if (stream.getBit()) { + strLen = stream.getBits(15); + } + else { + strLen = stream.getBits(7); + } + + char* str = new char[strLen + 1]; + uint32 mask = 0; + uint32 symbol = 0; + char c; + for (uint16 i = 0; i < strLen; i++) { + mask = stream.peekBits(16); // The mask is OK, so it means that I don't know how to use the huffman + uint32 entry; + // Find the length index + for (entry = 0; entry < _huffman->getNumEntries(); entry++) { + if (mask < _huffman->getMask(entry)) break; + } + + stream.skip(_huffman->getLength(entry)); + + symbol = _huffman->getSymbol(entry); + + if (symbol == 1) { // 7-bit ascii + c = stream.getBits(7); + } + else if (symbol == 2) { // Composite + warning("Composite huffman strings not implemented"); + } + else { // Plain ascii + c = symbol & 0xFF; + } + + str[i] = c; + } + + str[strLen] = '\0'; + debug(7, "Decoded %d'th string (new): %s", _id, str); + _decoded = Common::String(str); +} +} // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/text.h b/engines/macventure/text.h new file mode 100644 index 0000000000..3b3af926be --- /dev/null +++ b/engines/macventure/text.h @@ -0,0 +1,56 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_TEXT_H +#define MACVENTURE_TEXT_H + +#include "macventure/macventure.h" +#include "macventure/hufflists.h" + +namespace MacVenture { +typedef uint32 ObjID; + +class TextAsset { +public: + TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman); + ~TextAsset() {} + + const Common::String *decode() { + return &_decoded; + } + +private: + void decodeOld(); + void decodeHuffman(); + +private: + Container *_container; + ObjID _id; + const HuffmanLists *_huffman; + + Common::String _decoded; + +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index d8fd9b4e39..d919a1a639 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -19,7 +19,12 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); - + //_gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); + _gameText = new Container("Shadowgate II/Shadow Text"); + + ObjID tid = (ObjID)1; + TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); + delete saveGameRes; saveGameFile.close(); } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index e5c728ef58..6931996100 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -25,11 +25,13 @@ #include "macventure/macventure.h" #include "macventure/container.h" +#include "macventure/text.h" namespace MacVenture { typedef uint32 ObjID; typedef Common::Array AttributeGroup; +class TextAsset; enum ObjectAttributeID { kAttrParentObject = 0, -- cgit v1.2.3 From d7d03baba9534e1d94e7642c685addedbb9e2238 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 20:45:43 +0200 Subject: MACVENTURE: Fix small bug in save reading --- engines/macventure/world.cpp | 27 ++++++++++++++++++++++++--- engines/macventure/world.h | 7 ++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index d919a1a639..abb0c55c04 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -15,11 +15,13 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { if (!saveGameFile.open(_startGameFileName)) error("Could not load initial game configuration"); + debug("Loading save game state from %s", _startGameFileName.c_str()); Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); - //_gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); + calculateObjectRelations(); + _gameText = new Container("Shadowgate II/Shadow Text"); ObjID tid = (ObjID)1; @@ -73,11 +75,25 @@ bool World::loadStartGameFileName() { res->read(fileName, length); fileName[length] = '\0'; _startGameFileName = Common::String(fileName, length); - _startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".bin"); return true; } +void World::calculateObjectRelations() { + ObjID val, next; + uint32 numObjs = _engine->getGlobalSettings().numObjects; + const AttributeGroup &parents = *_saveGame->getGroup(0); + for (uint i = 0; i < numObjs * 2; i++) { + _relations.push_back(0); + } + for (uint i = numObjs - 1; i > 0; i--) { + val = parents[i]; + next = _relations[val * 2]; + if (next) { _relations[i * 2 + 1] = next; } + _relations[val * 2] = i; + } +} + // SaveGame SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { _groups = Common::Array(); @@ -95,6 +111,11 @@ const Common::Array& MacVenture::SaveGame::getGroups() { return _groups; } +const AttributeGroup * SaveGame::getGroup(uint32 groupID) { + assert(groupID < _groups.size()); + return &(_groups[groupID]); +} + const Common::Array& MacVenture::SaveGame::getGlobals() { return _globals; } @@ -107,7 +128,7 @@ void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * GlobalSettings settings = engine->getGlobalSettings(); for (int i = 0; i < settings.numGroups; ++i) { AttributeGroup g; - for (int j = 0; j < settings.numObjects; ++j) + for (int j = 0; j < settings.numObjects; ++j) g.push_back(res->readUint16BE()); _groups.push_back(g); diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 6931996100..fe93ef1395 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -30,7 +30,8 @@ namespace MacVenture { typedef uint32 ObjID; -typedef Common::Array AttributeGroup; +typedef uint16 Attribute; +typedef Common::Array AttributeGroup; class TextAsset; enum ObjectAttributeID { @@ -65,6 +66,7 @@ public: ~SaveGame(); const Common::Array &getGroups(); + const AttributeGroup *getGroup(uint32 groupID); const Common::Array &getGlobals(); const Common::String &getText(); @@ -89,6 +91,7 @@ public: private: bool loadStartGameFileName(); + void calculateObjectRelations(); private: MacVentureEngine *_engine; @@ -99,6 +102,8 @@ private: SaveGame *_saveGame; Container *_objectConstants; Container *_gameText; + + Common::Array _relations; // Parent-child relations, stored in Williams Heap format }; } // End of namespace MacVenture -- cgit v1.2.3 From 0fc3e909749f3d1af3e617fbcbc83c3f7819c392 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 20:46:22 +0200 Subject: MACVENTURE: Small fixed --- engines/macventure/image.h | 19 +++++++++++++++---- engines/macventure/macventure.cpp | 4 ++++ engines/macventure/macventure.h | 5 ++++- engines/macventure/script.h | 24 +++++++++++++++++++++++- engines/macventure/text.cpp | 23 ++++++++++++++--------- engines/macventure/text.h | 1 + 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 5bf6ccf7ac..4cc40f1ed0 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -27,12 +27,23 @@ namespace MacVenture { -class Image { +class ImageAsset { public: - Image(); - ~Image(); + ImageAsset(ObjID id, Container *container) { + _id = id; + _container = container; + } + ~ImageAsset() { - void blit(Graphics::ManagedSurface *target); + } + + void blit(Graphics::ManagedSurface *target) { + debug("Blitting image %x ", _id); + } + +private: + ObjID _id; + Container *_container; }; } // End of namespace MacVenture diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 2054c5eab6..da192628fe 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -59,6 +59,9 @@ MacVentureEngine::~MacVentureEngine() { if (_filenames) delete _filenames; + if (_decodingArticles) + delete _decodingArticles; + if (_textHuffman) delete _textHuffman; } @@ -84,6 +87,7 @@ Common::Error MacVentureEngine::run() { _oldTextEncoding = !loadTextHuffman(); _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); + _decodingArticles = new StringTable(this, _resourceManager, kCommonArticlesStringTableID); // Big class instantiation _gui = new Gui(this, _resourceManager); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 656aeaf2b6..a4340bf2bc 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -192,10 +192,13 @@ private: // Attributes World *_world; ScriptEngine *_scriptEngine; + // String tables + StringTable *_filenames; + StringTable *_decodingArticles; + // Engine state GameState _gameState; GlobalSettings _globalSettings; - StringTable *_filenames; HuffmanLists *_textHuffman; bool _oldTextEncoding; bool _paused, _halted, _cmdReady, _prepared; diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 66376924b0..9814c01ad4 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -24,6 +24,7 @@ #define MACVENTURE_SCRIPT_H #include "macventure/macventure.h" +#include "macventure/container.h" namespace MacVenture { @@ -47,7 +48,28 @@ enum ControlAction { }; typedef uint32 ObjID; - + +class ScriptAsset { +public: + ScriptAsset(ObjID id, Container *container, MacVentureEngine *engine) { + _id = id; + _container = container; + _engine = engine; + } + ~ScriptAsset() { + + } + + void execute() { + debug("SCRIPT: Executing script %x ", _id); + } + +private: + ObjID _id; + Container *_container; + MacVentureEngine *_engine; +}; + class ScriptEngine { public: ScriptEngine() {} diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index adac94bdd2..49df7ed9a0 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -27,8 +27,9 @@ TextAsset::TextAsset(ObjID objid, Container *container, bool isOld, const Huffma _id = objid; _container = container; _huffman = huffman; + _isOld = isOld; - if (isOld) { + if (_isOld) { decodeOld(); } else { @@ -99,7 +100,7 @@ void TextAsset::decodeOld() { } void TextAsset::decodeHuffman() { - _decoded = Common::String("Huffman string"); + _decoded = Common::String(""); Common::SeekableReadStream *res = _container->getItem(_id); Common::BitStream32BEMSB stream(res); uint16 strLen = 0; @@ -110,7 +111,6 @@ void TextAsset::decodeHuffman() { strLen = stream.getBits(7); } - char* str = new char[strLen + 1]; uint32 mask = 0; uint32 symbol = 0; char c; @@ -130,17 +130,22 @@ void TextAsset::decodeHuffman() { c = stream.getBits(7); } else if (symbol == 2) { // Composite - warning("Composite huffman strings not implemented"); + warning("Composite huffman strings not tested"); + if (stream.getBit()) { // TextID + ObjID embedId = stream.getBits(15); + TextAsset embedded(embedId, _container, _isOld, _huffman); + _decoded += *embedded.decode(); + } else { //Composite obj string + _decoded += Common::String("Unimplemented"); + } } else { // Plain ascii c = symbol & 0xFF; } - str[i] = c; + _decoded += c; } - - str[strLen] = '\0'; - debug(7, "Decoded %d'th string (new): %s", _id, str); - _decoded = Common::String(str); + _decoded += '\0'; + debug(7, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); } } // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/text.h b/engines/macventure/text.h index 3b3af926be..cfe76d6e11 100644 --- a/engines/macventure/text.h +++ b/engines/macventure/text.h @@ -46,6 +46,7 @@ private: Container *_container; ObjID _id; const HuffmanLists *_huffman; + bool _isOld; Common::String _decoded; -- cgit v1.2.3 From e8725ae068a51fb6ccdfd9f7d2bd4e8e7a12f40a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 21:47:40 +0200 Subject: MACVENTURE: Add attribute set function --- engines/macventure/macventure.cpp | 12 +++++++++ engines/macventure/macventure.h | 1 + engines/macventure/world.cpp | 52 ++++++++++++++++++++++++++++++++++++++- engines/macventure/world.h | 5 ++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index da192628fe..75f2c33711 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -99,6 +99,14 @@ Common::Error MacVentureEngine::run() { _cmdReady = false; _haltedAtEnd = false; _haltedInSelection = false; + + //if !savegame + _cmdReady = true; + _selectedControl = kStartOrResume; + ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); + _currentSelection.push_back(playerParent);// Push the parent of the player + _world->setObjAttr(playerParent, 6, 1); + _prepared = true; while (!(_gameState == kGameStateQuitting)) { processEvents(); @@ -181,6 +189,10 @@ void MacVentureEngine::preparedToRun() { _prepared = true; } +void MacVentureEngine::gameChanged() { + _gameChanged = true; +} + void MacVentureEngine::enqueueObject(ObjID id) { QueuedObject obj; obj.parent = _world->getObjAttr(id, kAttrParentObject); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index a4340bf2bc..457d685992 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -151,6 +151,7 @@ public: void activateCommand(ControlReference id); void refreshReady(); void preparedToRun(); + void gameChanged(); void enqueueObject(ObjID id); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index abb0c55c04..feb8c0b7be 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -46,7 +46,7 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { uint32 res; uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; if (!(index & 0x80)) { // It's not a constant - res = _saveGame->getGroups()[attrID][objID]; + res = _saveGame->getAttr(objID, index); } else { Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); index &= 0x7F; @@ -59,6 +59,25 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { return res; } +void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) { + if (attrID == kAttrPosX || attrID == kAttrPosY) {} + // Round to scale + + if (attrID == kAttrParentObject) + setParent(objID, value); + + if (attrID < kAttrOtherDoor) + _engine->enqueueObject(objID); + + uint32 idx = _engine->getGlobalSettings().attrIndices[attrID]; + value <<= _engine->getGlobalSettings().attrShifts[attrID]; + value &= _engine->getGlobalSettings().attrMasks[attrID]; + Attribute oldVal = _saveGame->getAttr(objID, idx); + oldVal &= ~_engine->getGlobalSettings().attrMasks[attrID]; + _saveGame->setAttr(idx, objID, (value | oldVal)); + _engine->gameChanged(); +} + bool MacVenture::World::isObjActive(ObjID obj) { return false; } @@ -94,6 +113,28 @@ void World::calculateObjectRelations() { } } +void World::setParent(ObjID child, ObjID newParent) { + ObjID old = _saveGame->getAttr(child, kAttrParentObject); + if (newParent == child) + return; + + ObjID oldNdx = old * 2; + old = _relations[oldNdx]; + while (old != child) { + oldNdx = (old * 2) + 1; + old = _relations[oldNdx]; + } + _relations[oldNdx] = _relations[(old * 2) + 1]; + oldNdx = newParent * 2; + old = _relations[oldNdx]; + while (old && old <= child) { + oldNdx = (old * 2) + 1; + old = _relations[oldNdx]; + } + _relations[child * 2 + 1] = old; + _relations[oldNdx] = child; +} + // SaveGame SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { _groups = Common::Array(); @@ -107,6 +148,15 @@ SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { SaveGame::~SaveGame() { } + +Attribute SaveGame::getAttr(ObjID objID, uint32 attrID) { + return _groups[attrID][objID]; +} + +void SaveGame::setAttr(uint32 attrID, ObjID objID, Attribute value) { + _groups[attrID][objID] = value; +} + const Common::Array& MacVenture::SaveGame::getGroups() { return _groups; } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index fe93ef1395..58e9fc5ce5 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -65,6 +65,9 @@ public: SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res); ~SaveGame(); + Attribute getAttr(ObjID objID, uint32 attrID); + void setAttr(uint32 attrID, ObjID objID, Attribute value); + const Common::Array &getGroups(); const AttributeGroup *getGroup(uint32 groupID); const Common::Array &getGlobals(); @@ -87,11 +90,13 @@ public: ~World(); uint32 getObjAttr(ObjID objID, uint32 attrID); + void setObjAttr(ObjID objID, uint32 attrID, Attribute value); bool isObjActive(ObjID obj); private: bool loadStartGameFileName(); void calculateObjectRelations(); + void setParent(ObjID child, ObjID newParent); private: MacVentureEngine *_engine; -- cgit v1.2.3 From 9b052d0a973971a50b4f0df918489e0fc6dd9fdb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 18 Jun 2016 00:27:35 +0200 Subject: MACVENTURE: Add untested script engine --- engines/macventure/macventure.cpp | 6 +- engines/macventure/module.mk | 3 +- engines/macventure/script.cpp | 174 ++++++++++++++++++++++++++++++++++++++ engines/macventure/script.h | 77 +++++++++++------ engines/macventure/world.cpp | 20 +++++ engines/macventure/world.h | 3 +- 6 files changed, 254 insertions(+), 29 deletions(-) create mode 100644 engines/macventure/script.cpp diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 75f2c33711..78884cf1bf 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -92,7 +92,7 @@ Common::Error MacVentureEngine::run() { // Big class instantiation _gui = new Gui(this, _resourceManager); _world = new World(this, _resourceManager); - _scriptEngine = new ScriptEngine(); + _scriptEngine = new ScriptEngine(_world); _paused = false; _halted = true; @@ -233,7 +233,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { debug(4, "MAIN: Running script engine"); if (_haltedAtEnd) { _haltedAtEnd = false; - if (_scriptEngine->resume()) { + if (_scriptEngine->resume(false)) { _haltedAtEnd = true; return true; } @@ -242,7 +242,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { if (_haltedInSelection) { _haltedInSelection = false; - if (_scriptEngine->resume()) { + if (_scriptEngine->resume(false)) { _haltedInSelection = true; return true; } diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 47e0c702e4..c0dc818d96 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -5,8 +5,9 @@ MODULE_OBJS := \ gui.o \ object.o \ text.o \ - macventure.o \ world.o \ + script.o \ + macventure.o MODULE_DIRS += \ engines/macventure diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp new file mode 100644 index 0000000000..7e594f5a11 --- /dev/null +++ b/engines/macventure/script.cpp @@ -0,0 +1,174 @@ +/* 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 "macventure/macventure.h" +#include "macventure/script.h" +#include "macventure/world.h" +#include "macventure/container.h" + +namespace MacVenture { + +ScriptEngine::ScriptEngine(World * world) { + _world = world; + _scripts = new Container("Shadowgate II/Shadow Filter"); +} + +ScriptEngine::~ScriptEngine() { + if (_scripts) + delete _scripts; +} + +bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta) { + //debug(7, "SCRIPT: Running control %d from obj %d into obj %d, at delta (%d, %d)", + // action, source, destination, delta.x, delta.y); + + EngineFrame frame; + frame.action = action; + frame.src = source; + frame.dest = destination; + frame.x = delta.x; + frame.y = delta.y; + frame.haltedInSaves = false; + frame.haltedInFirst = false; + frame.haltedInFamily = false; + _frames.push_back(frame); + debug(7, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); + + return resume(true); +} + +bool ScriptEngine::resume(bool execAll) { + debug(7, "SCRIPT: Resume"); + while (_frames.size()) { + bool fail = execFrame(execAll); + if (fail) return true; + } + return false; +} + +void ScriptEngine::reset() { + _frames.clear(); +} + +bool ScriptEngine::execFrame(bool execAll) { + bool doFirst = execAll; + bool doFamily = false; + bool fail; + + EngineFrame *frame = &_frames.front(); + + // Do first dispatch script (script 0) + if (frame->haltedInFirst || doFirst) { // We were stuck or it's the first time + frame->haltedInFirst = false; + if (doFirst) { fail = loadScript(frame, 0); } + else { fail = resumeFunc(frame); } + if (fail) { + frame->haltedInFirst = true; + return true; + } + doFamily = true; + frame->familyIdx = 0; + } + + // Do scripts in the family of player (ObjID 1) + if (frame->haltedInFamily || doFamily) { // We have to do the family or we were stuck here + frame->haltedInFamily = false; + Common::Array family = _world->getFamily(_world->getObjAttr(1, kAttrParentObject), false); + uint32 i = frame->familyIdx; + for (; i < family.size(); i++) { + if (doFamily) { fail = loadScript(frame, family[i]); } + else { fail = resumeFunc(frame); } + if (fail) { // We are stuck, so we don't shift the frame + frame->haltedInFamily = true; + frame->familyIdx = i; + return true; + } + doFamily = true; + } + } + + //Handle saves + /* + + uint highest; + uint high; + if (frame->haltedInSaves) { + frame->haltedInSaves = false; + } + + + do { + highest = 0; + for (uint i = 0; i < frame->haltedInSaves.size) + } + */ + + _frames.remove_at(0); + return false; +} + +bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { + frame->scripts.push_back(ScriptAsset(scriptID, _scripts)); + return false; +} + +bool ScriptEngine::resumeFunc(EngineFrame * frame) { + bool fail = runFunc(); + if (fail) return fail; + frame->scripts.remove_at(0); + if (frame->scripts.size()) + return resumeFunc(frame); + return false; +} + +bool ScriptEngine::runFunc() { + debug(7, "SCRIPT: I'm running the function"); + return false; +} + +ScriptAsset::ScriptAsset(ObjID id, Container * container) { + _id = id; + _container = container; + _ip = 0x0; +} + +void ScriptAsset::reset() { + _ip = 0x0; +} + +uint8 ScriptAsset::fecth() { + uint8 ins = _instructions[_ip]; + _ip++; + return ins; +} + +void ScriptAsset::loadInstructions() { + uint32 amount = _container->getItemByteSize(_id); + Common::SeekableReadStream *res = _container->getItem(_id); + for (uint i = 0; i < amount; i++) { + _instructions.push_back(res->readByte()); + } + debug(7, "SCRIPT: Load %d instructions for script %d", amount, _id); +} + +} // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 9814c01ad4..d66a867eca 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -23,10 +23,13 @@ #ifndef MACVENTURE_SCRIPT_H #define MACVENTURE_SCRIPT_H -#include "macventure/macventure.h" #include "macventure/container.h" +#include "macventure/world.h" namespace MacVenture { + +class Container; +class World; enum ControlAction { kNoCommand = 0, @@ -51,42 +54,68 @@ typedef uint32 ObjID; class ScriptAsset { public: - ScriptAsset(ObjID id, Container *container, MacVentureEngine *engine) { - _id = id; - _container = container; - _engine = engine; - } - ~ScriptAsset() { + ScriptAsset(ObjID id, Container *container); + ~ScriptAsset() {} - } + void reset(); + uint8 fecth(); - void execute() { - debug("SCRIPT: Executing script %x ", _id); - } +private: + + void loadInstructions(); private: ObjID _id; Container *_container; - MacVentureEngine *_engine; + + Common::Array _instructions; + uint32 _ip; // Instruction pointer +}; + +struct EngineState { + uint8 stack[0x80]; + uint8 sp; + + EngineState() { + sp = 0x80; + } +}; + +struct EngineFrame { + ControlAction action; + ObjID src; + ObjID dest; + int x; + int y; + EngineState state; + Common::Array scripts; + uint32 familyIdx; + + bool haltedInFirst; + bool haltedInFamily; + bool haltedInSaves; }; class ScriptEngine { public: - ScriptEngine() {} - ~ScriptEngine() {} + ScriptEngine(World *world); + ~ScriptEngine(); - bool runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta) { - debug(7, "SCRIPT: Running control %d from obj %d into obj %d, at delta (%d, %d)", - action, source, destination, delta.x, delta.y); - - return false; - } +public: + bool runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta); + bool resume(bool execAll); + void reset(); - bool resume() { - debug(7, "SCRIPT: Resume"); +private: + bool execFrame(bool execAll); + bool loadScript(EngineFrame * frame, uint32 scriptID); + bool resumeFunc(EngineFrame * frame); + bool runFunc(); - return false; - } +private: + World *_world; + Common::Array _frames; + Container *_scripts; }; } // End of namespace MacVenture diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index feb8c0b7be..2cd50ff82a 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -1,4 +1,5 @@ #include "macventure/world.h" +#include "macventure/macventure.h" #include "common/file.h" @@ -82,6 +83,25 @@ bool MacVenture::World::isObjActive(ObjID obj) { return false; } +Common::Array World::getFamily(ObjID objID, bool recursive) { + Common::Array res; + res.push_back(objID); + res.push_back(getChildren(objID, recursive)); + return res; +} + +Common::Array World::getChildren(ObjID objID, bool recursive) { + Common::Array res; + ObjID child = _relations[objID * 2]; + while (child) { + res.push_back(child); + if (!recursive) + res.push_back(getChildren(child, false)); + child = _relations[child * 2 + 1]; + } + return Common::Array(); +} + bool World::loadStartGameFileName() { Common::SeekableReadStream *res; diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 58e9fc5ce5..3893aca445 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -23,7 +23,6 @@ #ifndef MACVENTURE_WORLD_H #define MACVENTURE_WORLD_H -#include "macventure/macventure.h" #include "macventure/container.h" #include "macventure/text.h" @@ -92,6 +91,8 @@ public: uint32 getObjAttr(ObjID objID, uint32 attrID); void setObjAttr(ObjID objID, uint32 attrID, Attribute value); bool isObjActive(ObjID obj); + Common::Array getFamily(ObjID objID, bool recursive); + Common::Array getChildren(ObjID objID, bool recursive); private: bool loadStartGameFileName(); -- cgit v1.2.3 From 96f9910c79849c980a09ff733f4710ba9d414dc9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 18 Jun 2016 23:14:17 +0200 Subject: MACVENTURE: Add opcodes for script engine --- engines/macventure/macventure.cpp | 24 +- engines/macventure/macventure.h | 24 +- engines/macventure/script.cpp | 994 +++++++++++++++++++++++++++++++++++++- engines/macventure/script.h | 188 ++++++- engines/macventure/world.cpp | 54 +++ engines/macventure/world.h | 17 +- 6 files changed, 1281 insertions(+), 20 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 78884cf1bf..f2a2f43f51 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -92,7 +92,7 @@ Common::Error MacVentureEngine::run() { // Big class instantiation _gui = new Gui(this, _resourceManager); _world = new World(this, _resourceManager); - _scriptEngine = new ScriptEngine(_world); + _scriptEngine = new ScriptEngine(this, _world); _paused = false; _halted = true; @@ -193,6 +193,14 @@ void MacVentureEngine::gameChanged() { _gameChanged = true; } +void MacVentureEngine::winGame() { + _gameState = kGameStateWinnig; +} + +void MacVentureEngine::loseGame() { + _gameState = kGameStateLosing; +} + void MacVentureEngine::enqueueObject(ObjID id) { QueuedObject obj; obj.parent = _world->getObjAttr(id, kAttrParentObject); @@ -206,6 +214,13 @@ void MacVentureEngine::enqueueObject(ObjID id) { _objQueue.push_back(obj); } +void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text) { +} + +void MacVentureEngine::printTexts() { + debug("Printing texts.."); +} + const GlobalSettings& MacVentureEngine::getGlobalSettings() const { return _globalSettings; } @@ -284,6 +299,9 @@ bool MacVentureEngine::updateState() { return true; } +void MacVentureEngine::revert() { +} + void MacVentureEngine::runObjQueue() { } @@ -360,6 +378,10 @@ const HuffmanLists * MacVentureEngine::getDecodingHuffman() const { return _textHuffman; } +uint32 MacVentureEngine::randBetween(uint32 min, uint32 max) { + return _rnd->getRandomNumber(max - min) + min; +} + // Data loading bool MacVentureEngine::loadGlobalSettings() { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 457d685992..3ae195aef0 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -124,6 +124,12 @@ enum ObjectQueueID { kAnimateBack = 14 }; +enum TextQueueID { + kTextNumber = 1, + kTextNewLine = 2, + kTextPlain = 3 +}; + struct QueuedObject { ObjectQueueID id; ObjID object; @@ -152,8 +158,17 @@ public: void refreshReady(); void preparedToRun(); void gameChanged(); + void winGame(); + void loseGame(); + + bool updateState(); + void revert(); void enqueueObject(ObjID id); + void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text); + + void runObjQueue(); + void printTexts(); // Data retrieval bool isPaused(); @@ -162,14 +177,13 @@ public: Common::String getFilePath(FilePathID id) const; bool isOldText() const; const HuffmanLists *getDecodingHuffman() const; + uint32 randBetween(uint32 min, uint32 max); private: void processEvents(); bool runScriptEngine(); void endGame(); - bool updateState(); - void runObjQueue(); void updateControls(); void resetVars(); @@ -181,6 +195,8 @@ private: ControlAction referenceToAction(ControlReference id); uint objectsToApplyCommand(); + const char* getGameFileName() const; + private: // Attributes const ADGameDescription *_gameDescription; @@ -217,10 +233,6 @@ private: // Attributes Common::List _currentSelection; Common::Point _deltaPoint; -private: // Methods - - const char* getGameFileName() const; - }; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 7e594f5a11..b0d5ef0011 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -20,6 +20,8 @@ * */ +#include "common/system.h" + #include "macventure/macventure.h" #include "macventure/script.h" #include "macventure/world.h" @@ -27,7 +29,8 @@ namespace MacVenture { -ScriptEngine::ScriptEngine(World * world) { +ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { + _engine = engine; _world = world; _scripts = new Container("Shadowgate II/Shadow Filter"); } @@ -133,7 +136,7 @@ bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { } bool ScriptEngine::resumeFunc(EngineFrame * frame) { - bool fail = runFunc(); + bool fail = runFunc(frame); if (fail) return fail; frame->scripts.remove_at(0); if (frame->scripts.size()) @@ -141,11 +144,986 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { return false; } -bool ScriptEngine::runFunc() { +bool ScriptEngine::runFunc(EngineFrame *frame) { debug(7, "SCRIPT: I'm running the function"); + ScriptAsset &script = frame->scripts.front(); + EngineState *state = &frame->state; + byte op; + while (script.hasNext()) { + op = script.fetch(); + if (!(op & 0x80)) { + state->push(op); + } else { + switch (op) { + case 0x80: //get attribute + op80GATT(state, frame); + break; + case 0x81: //set attribute + op81SATT(state, frame); + break; + case 0x82: //sum children attribute + op82SUCH(state, frame); + break; + case 0x83: //push selected control + op83PUCT(state, frame); + break; + case 0x84: //push selected object + op84PUOB(state, frame); + break; + case 0x85: //push target + op85PUTA(state, frame); + break; + case 0x86: //push deltax + op86PUDX(state, frame); + break; + case 0x87: //push deltay + op87PUDY(state, frame); + break; + case 0x88: //push immediate.b + op88PUIB(state, frame, &script); + break; + case 0x89: //push immediate + op89PUI(state, frame, &script); + break; + case 0x8a: //get global + op8aGGLO(state, frame); + break; + case 0x8b: //set global + op8bSGLO(state, frame); + break; + case 0x8c: //random + op8cRAND(state, frame); + break; + case 0x8d: //copy + op8dCOPY(state, frame); + break; + case 0x8e: //copyn + op8eCOPYN(state, frame); + break; + case 0x8f: //swap + op8fSWAP(state, frame); + break; + case 0x90: //swapn + op90SWAPN(state, frame); + break; + case 0x91: //pop + op91POP(state, frame); + break; + case 0x92: //copy+1 + op92COPYP(state, frame); + break; + case 0x93: //copy+n + op93COPYPN(state, frame); + break; + case 0x94: //shuffle + op94SHUFF(state, frame); + break; + case 0x95: //sort + op95SORT(state, frame); + break; + case 0x96: //clear stack + op96CLEAR(state, frame); + break; + case 0x97: //get stack size + op97SIZE(state, frame); + break; + case 0x98: //add + op98ADD(state, frame); + break; + case 0x99: //subtract + op99SUB(state, frame); + break; + case 0x9a: //multiply + op9aMUL(state, frame); + break; + case 0x9b: //divide + op9bDIV(state, frame); + break; + case 0x9c: //mod + op9cMOD(state, frame); + break; + case 0x9d: //divmod + op9dDMOD(state, frame); + break; + case 0x9e: //abs + op9eABS(state, frame); + break; + case 0x9f: //neg + op9fNEG(state, frame); + break; + case 0xa0: //and + opa0AND(state, frame); + break; + case 0xa1: //or + opa1OR(state, frame); + break; + case 0xa2: //xor + opa2XOR(state, frame); + break; + case 0xa3: //not + opa3NOT(state, frame); + break; + case 0xa4: //logical and + opa4LAND(state, frame); + break; + case 0xa5: //logical or + opa5LOR(state, frame); + break; + case 0xa6: //logical xor + opa6LXOR(state, frame); + break; + case 0xa7: //logical not + opa7LNOT(state, frame); + break; + case 0xa8: //gt? unsigned + opa8GTU(state, frame); + break; + case 0xa9: //lt? unsigned + opa9LTU(state, frame); + break; + case 0xaa: //gt? signed + opaaGTS(state, frame); + break; + case 0xab: //lt? signed + opabLTS(state, frame); + break; + case 0xac: //eq? + opacEQ(state, frame); + break; + case 0xad: //eq string? + opadEQS(state, frame); + break; + case 0xae: //contains + opaeCONT(state, frame); + break; + case 0xaf: //contains word + opafCONTW(state, frame); + break; + case 0xb0: //bra + opb0BRA(state, frame, &script); + break; + case 0xb1: //bra.b + opb1BRAB(state, frame, &script); + break; + case 0xb2: //beq + opb2BEQ(state, frame, &script); + break; + case 0xb3: //beq.b + opb3BEQB(state, frame, &script); + break; + case 0xb4: //bne + opb4BNE(state, frame, &script); + break; + case 0xb5: //bne.b + opb5BNEB(state, frame, &script); + break; + case 0xb6: //call later + opb6CLAT(state, frame); + break; + case 0xb7: //cancel call + opb7CCA(state, frame); + break; + case 0xb8: //cancel low priority + opb8CLOW(state, frame); + break; + case 0xb9: //cancel high priority + opb9CHI(state, frame); + break; + case 0xba: //cancel priority range + opbaCRAN(state, frame); + break; + case 0xbb: //fork + opbbFORK(state, frame); + break; + case 0xbc: //call + opbcCALL(state, frame, &script); + break; + case 0xbd: //focus object + opbdFOOB(state, frame); + break; + case 0xbe: //swap objects + opbeSWOB(state, frame); + break; + case 0xbf: //snap object + opbfSNOB(state, frame); + break; + case 0xc0: //toggle exits + opc0TEXI(state, frame); + break; + case 0xc1: //print text + opc1PTXT(state, frame); + break; + case 0xc2: //print newline + opc2PNEW(state, frame); + break; + case 0xc3: //print text+nl + opc3PTNE(state, frame); + break; + case 0xc4: //print nl+text+nl + opc4PNTN(state, frame); + break; + case 0xc5: //print number + opc5PNUM(state, frame); + break; + case 0xc6: //push 2 + opc6P2(state, frame); + break; + case 0xc7: //play sound in background + opc7PLBG(state, frame); + break; + case 0xc8: //play sound and wait + opc8PLAW(state, frame); + break; + case 0xc9: //wait for sound to finish? + opc9WAIT(state, frame); + break; + case 0xca: //get current time + opcaTIME(state, frame); + break; + case 0xcb: //get current day + opcbDAY(state, frame); + break; + case 0xcc: //get children + opccCHLD(state, frame); + break; + case 0xcd: //get num children + opcdNCHLD(state, frame); + break; + case 0xce: //get engine version + opceVERS(state, frame); + break; + case 0xcf: //push scenario number + opcfPSCE(state, frame); + break; + case 0xd0: //push 1 + opd0P1(state, frame); + break; + case 0xd1: //get object dimensions + opd1GOBD(state, frame); + break; + case 0xd2: //get overlap percent + opd2GOVP(state, frame); + break; + case 0xd3: //capture children + opd3CAPC(state, frame); + break; + case 0xd4: //release children + opd4RELC(state, frame); + break; + case 0xd5: //show speech dialog + opd5DLOG(state, frame); + return true; + case 0xd6: //activate command + opd6ACMD(state, frame); + break; + case 0xd7: //lose game + opd7LOSE(state, frame); + break; + case 0xd8: //win game + opd8WIN(state, frame); + break; + case 0xd9: //sleep + opd9SLEEP(state, frame); + return true; + case 0xda: //click to continue + opdaCLICK(state, frame); + return true; + case 0xdb: //run queue + opdbROBQ(state, frame); + break; + case 0xdc: //run sound queue + opdcRSQ(state, frame); + break; + case 0xdd: //run text queue + opddRTQ(state, frame); + break; + case 0xde: //update screen + opdeUPSC(state, frame); + break; + case 0xdf: //flash main window + opdfFMAI(state, frame); + return true; + case 0xe0: //cache graphic and object + ope0CHGR(state, frame); + break; + case 0xe1: //cache sound + ope1CHSO(state, frame); + break; + case 0xe2: //muldiv + ope2MDIV(state, frame); + break; + case 0xe3: //update object + ope3UPOB(state, frame); + break; + case 0xe4: //currently playing event? + ope4PLEV(state, frame); + break; + case 0xe5: //wait for event to finish + ope5WEV(state, frame); + break; + case 0xe6: //get fibonacci (joke) + ope6GFIB(state, frame); + break; + case 0xe7: //calc fibonacci + ope7CFIB(state, frame); + break; + default: + op00NOOP(op); + } + } + } return false; } +word ScriptEngine::neg16(word val) { + if (val & 0x8000) + val = -((val ^ 0xFFFF) + 1); + return val; +} + +word ScriptEngine::neg8(word val) { + if (val & 0x80) + val = -((val ^ 0xff) + 1); + return val; +} + +word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { + word sum = 0; + Common::Array children = _world->getChildren(obj, recursive); + for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { + sum += _world->getObjAttr(*it, attr); + } + return sum; +} + +void MacVenture::ScriptEngine::op80GATT(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + word attr = state->pop(); + state->push(_world->getObjAttr(obj, attr)); +} + +void ScriptEngine::op81SATT(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + word attr = state->pop(); + word val = neg16(state->pop()); + _world->setObjAttr(obj, attr, val); +} + +void ScriptEngine::op82SUCH(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + word attr = state->pop(); + word recursive = neg16(state->pop()); + state->push(sumChildrenAttr(obj, attr, recursive)); +} + +void ScriptEngine::op83PUCT(EngineState * state, EngineFrame * frame) { + state->push(frame->action); +} + +void ScriptEngine::op84PUOB(EngineState * state, EngineFrame * frame) { + state->push(frame->src); +} + +void ScriptEngine::op85PUTA(EngineState * state, EngineFrame * frame) { + state->push(frame->dest); +} + +void ScriptEngine::op86PUDX(EngineState * state, EngineFrame * frame) { + state->push(frame->x); +} + +void ScriptEngine::op87PUDY(EngineState * state, EngineFrame * frame) { + state->push(frame->y); +} + +void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + state->push(asset->fetch()); +} + +void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + state->push(val); +} + +void ScriptEngine::op8aGGLO(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + state->push(_world->getGlobal(idx)); +} + +void ScriptEngine::op8bSGLO(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + word val = neg16(state->pop()); + _world->setGlobal(idx, val); + _engine->gameChanged(); +} + +void ScriptEngine::op8cRAND(EngineState * state, EngineFrame * frame) { + word max = state->pop(); + state->push(_engine->randBetween(0, max)); +} + +void ScriptEngine::op8dCOPY(EngineState * state, EngineFrame * frame) { + word val = state->pop(); + state->push(val); + state->push(val); +} + +void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { + word n = state->pop(); + word offs = n - 1; + word val; + while (n) { + val = state->peek(offs); + state->push(val); + } +} + +void ScriptEngine::op8fSWAP(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(b); + state->push(a); +} + +void ScriptEngine::op90SWAPN(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + word a = state->peek(idx); + word b = state->peek(0); + state->poke(idx, b); + state->poke(0, a); +} + +void ScriptEngine::op91POP(EngineState * state, EngineFrame * frame) { + state->pop(); +} + +void ScriptEngine::op92COPYP(EngineState * state, EngineFrame * frame) { + word val = state->peek(1); + state->push(val); +} + +void ScriptEngine::op93COPYPN(EngineState * state, EngineFrame * frame) { + word idx = state->pop(); + word val = state->peek(idx); + state->push(val); +} + +void ScriptEngine::op94SHUFF(EngineState * state, EngineFrame * frame) { + word a = state->pop(); + word b = state->pop(); + word c = state->pop(); + state->push(a); + state->push(c); + state->push(b); +} + +void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { + word step = neg16(state->pop()); + word num = neg16(state->pop()); + step %= num; + if (step<0) step += num; + word end = 0; + word start = 0; + for (word i = 1;i= num) start -= num; + if (start == end) + { + end++; + start = end; + } + else + { + word a = state->peek(end); + word b = state->peek(start); + state->poke(end, b); + state->poke(start, a); + } + } +} + +void ScriptEngine::op96CLEAR(EngineState * state, EngineFrame * frame) { + state->clear(); +} + +void ScriptEngine::op97SIZE(EngineState * state, EngineFrame * frame) { + state->push(state->size()); +} + +void ScriptEngine::op98ADD(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a + b); +} + +void ScriptEngine::op99SUB(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a - b); +} + +void ScriptEngine::op9aMUL(EngineState * state, EngineFrame * frame) { + int16 b = state->pop(); + int16 a = state->pop(); + state->push(a * b); +} + +void ScriptEngine::op9bDIV(EngineState * state, EngineFrame * frame) { + int16 b = state->pop(); + int16 a = state->pop(); + state->push((a / b) | 0); +} + +void ScriptEngine::op9cMOD(EngineState * state, EngineFrame * frame) { + int16 b = state->pop(); + int16 a = state->pop(); + state->push(a % b); +} + +void ScriptEngine::op9dDMOD(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a % b); + state->push((a / b) | 0); +} + +void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { + word val = neg16(state->pop()); + if (val<0) val = -val; + state->push(val); +} + +void ScriptEngine::op9fNEG(EngineState * state, EngineFrame * frame) { + word val = -neg16(state->pop()); + state->push(val); +} + +void ScriptEngine::opa0AND(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a & b); +} + +void ScriptEngine::opa1OR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a | b); +} + +void ScriptEngine::opa2XOR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(a ^ b); +} + +void ScriptEngine::opa3NOT(EngineState * state, EngineFrame * frame) { + word a = state->pop(); + state->push(a ^ 0xFFFF); +} + +void ScriptEngine::opa4LAND(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a && b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa5LOR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a || b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa6LXOR(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((!a != !b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa7LNOT(EngineState * state, EngineFrame * frame) { + word a = state->pop(); + state->push((a == 0) ? 0xFFFF : 0); +} + +void ScriptEngine::opa8GTU(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a > b) ? 0xFFFF : 0); +} + +void ScriptEngine::opa9LTU(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push((a < b) ? 0xFFFF : 0); +} + +void ScriptEngine::opaaGTS(EngineState * state, EngineFrame * frame) { + word b = neg16(state->pop()); + word a = neg16(state->pop()); + state->push((a > b) ? 0xFFFF : 0); +} + +void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { + word b = neg16(state->pop()); + word a = neg16(state->pop()); + state->push((a < b) ? 0xFFFF : 0); +} + +void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { + word b = neg16(state->pop()); + word a = neg16(state->pop()); + state->push((a == b) ? 0xFFFF : 0); +} + +void ScriptEngine::opadEQS(EngineState * state, EngineFrame * frame) { + Common::String b = _world->getText(state->pop()); + Common::String a = _world->getText(state->pop()); + state->push((a == b) ? 1 : 0); +} + +void ScriptEngine::opaeCONT(EngineState * state, EngineFrame * frame) { + Common::String needle = _world->getText(state->pop()); + Common::String haystack = _world->getText(state->pop()); + haystack.toLowercase(); + state->push(haystack.contains(needle) ? 1 : 0); +} + +void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { + Common::String needle = _world->getText(state->pop()); + Common::String haystack = _world->getText(state->pop()); + haystack.toLowercase(); + state->push(haystack.contains(needle) ? 1 : 0); +} + +void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + val = neg16(val); + asset->branch(val); +} + +void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val = neg8(val); + asset->branch(val); +} + +void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + val = neg16(val); + word b = state->pop(); + if (b != 0) asset->branch(val); +} + +void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val = neg8(val); + word b = state->pop(); + if (b != 0) asset->branch(val); +} + +void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val <<= 8; + val = val | asset->fetch(); + val = neg16(val); + word b = state->pop(); + if (b == 0) asset->branch(val); +} + +void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { + word val = asset->fetch(); + val = neg8(val); + word b = state->pop(); + if (b == 0) asset->branch(val); +} + +void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { + word rank = state->pop(); + word func = state->pop(); + frame->saves.push_back(FunCall(rank, func)); +} + +void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { + word func = state->pop(); + for (int i = 0; i < frame->saves.size(); i++) { + if (frame->saves[i].func == func) + frame->saves[i].rank = 0; + } +} + +void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { + word hi = state->pop(); + for (int i = 0;isaves.size();i++) + if (frame->saves[i].rank <= hi) + frame->saves[i].rank = 0; +} + +void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { + word lo = state->pop(); + for (int i = 0;isaves.size();i++) + if (frame->saves[i].rank >= lo) + frame->saves[i].rank = 0; +} + +void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { + word hi = state->pop(); + word lo = state->pop(); + for (int i = 0;isaves.size();i++) + if (frame->saves[i].rank >= lo && + frame->saves[i].rank <= hi) + frame->saves[i].rank = 0; +} + +void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { + EngineFrame newframe; + newframe.action = (ControlAction)state->pop(); + newframe.src = state->pop(); + newframe.dest = state->pop(); + newframe.x = state->pop(); + newframe.y = state->pop(); + _frames.push_back(newframe); +} + +void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word id = state->pop(); + ScriptAsset newfun = ScriptAsset(id, _scripts); + frame->scripts.remove_at(0); + frame->scripts.insert_at(0, newfun); + script = &frame->scripts.front(); +} + +void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _engine->enqueueObject(obj); +} + +void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { + op00NOOP(0xbe); +} + +void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { + op00NOOP(0xbf); +} + +void ScriptEngine::opc0TEXI(EngineState * state, EngineFrame * frame) { + op00NOOP(0xc0); +} + +void ScriptEngine::opc1PTXT(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); +} + +void ScriptEngine::opc2PNEW(EngineState * state, EngineFrame * frame) { + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); +} + +void ScriptEngine::opc3PTNE(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); +} + +void ScriptEngine::opc4PNTN(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); + _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); + _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); +} + +void ScriptEngine::opc5PNUM(EngineState * state, EngineFrame * frame) { + word tid = state->pop(); + _engine->enqueueText(kTextNumber, frame->dest, frame->src, tid); +} + +void ScriptEngine::opc6P2(EngineState * state, EngineFrame * frame) { + state->push(2); +} + +void ScriptEngine::opc7PLBG(EngineState * state, EngineFrame * frame) { + state->pop(); + op00NOOP(0xc7); +} + +void ScriptEngine::opc8PLAW(EngineState * state, EngineFrame * frame) { + state->pop(); + op00NOOP(0xc8); +} + +void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { + op00NOOP(0xc9); +} + +void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { + for (int i = 0; i < 6; i++) // Dummy + state->push(0x00); + op00NOOP(0xca); +} + +void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { + state->push(9); +} + +void ScriptEngine::opccCHLD(EngineState * state, EngineFrame * frame) { + bool recursive = state->pop() != 0; + word obj = state->pop(); + Common::Array children = _world->getChildren(obj, recursive); + for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { + state->push(*it); + } + state->push(children.size()); +} + +void ScriptEngine::opcdNCHLD(EngineState * state, EngineFrame * frame) { + bool recursive = state->pop() != 0; + word obj = state->pop(); + Common::Array children = _world->getChildren(obj, recursive); + state->push(children.size()); +} + +void ScriptEngine::opceVERS(EngineState * state, EngineFrame * frame) { + state->push(86); +} + +void ScriptEngine::opcfPSCE(EngineState * state, EngineFrame * frame) { + state->push(0); //Not release +} + +void ScriptEngine::opd0P1(EngineState * state, EngineFrame * frame) { + state->push(1); +} + +void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + Common::Rect bounds(0, 0, 1, 1); //= _world->getObjBounds(obj); + state->push(bounds.width()); + state->push(bounds.height()); +} + +void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + state->push(0);//_world->getOverlapPercent(b, a)); +} + +void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _world->captureChildren(obj); +} + +void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _world->releaseChildren(obj); +} + +void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { + word txt = state->pop(); + op00NOOP(0xd5); +} + +void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { + _engine->activateCommand((ControlReference)state->pop()); +} + +void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { + _engine->loseGame(); +} + +void ScriptEngine::opd8WIN(EngineState * state, EngineFrame * frame) { + _engine->winGame(); +} + +void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { + word ticks = state->pop(); + g_system->delayMillis((ticks / 60) * 1000); + _engine->preparedToRun(); +} + +void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { + //_engine->updateScreen(false); + //clickToContinue(); + op00NOOP(0xda); +} + +void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { + _engine->runObjQueue(); +} + +void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { + op00NOOP(0xdc); +} + +void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { + _engine->printTexts(); +} + +void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { + //_engine->updateScreen(false); + op00NOOP(0xde); +} + +void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { + word ticks = state->pop(); + g_system->delayMillis((ticks / 60) * 1000); + _engine->revert(); +} + +void ScriptEngine::ope0CHGR(EngineState * state, EngineFrame * frame) { + word txt = state->pop(); + op00NOOP(0xe0); +} + +void ScriptEngine::ope1CHSO(EngineState * state, EngineFrame * frame) { + word txt = state->pop(); + op00NOOP(0xe1); +} + +void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { + word b = state->pop(); + word a = state->pop(); + a *= b; + word c = state->pop(); + a /= c; + state->push(a | 0); +} + +void ScriptEngine::ope3UPOB(EngineState * state, EngineFrame * frame) { + word obj = state->pop(); + _world->updateObj(obj); +} + +void ScriptEngine::ope4PLEV(EngineState * state, EngineFrame * frame) { + state->push(0); + op00NOOP(0xe4); +} + +void ScriptEngine::ope5WEV(EngineState * state, EngineFrame * frame) { + op00NOOP(0xe5); +} + +void ScriptEngine::ope6GFIB(EngineState * state, EngineFrame * frame) { + state->push(0); + op00NOOP(0xe6); +} + +void ScriptEngine::ope7CFIB(EngineState * state, EngineFrame * frame) { + state->pop(); + op00NOOP(0xe7); +} + +void ScriptEngine::op00NOOP(byte op) { + debug("SCRIPT: Opcode not implemented => %x", op); +} + + + + ScriptAsset::ScriptAsset(ObjID id, Container * container) { _id = id; _container = container; @@ -156,12 +1134,20 @@ void ScriptAsset::reset() { _ip = 0x0; } -uint8 ScriptAsset::fecth() { +uint8 ScriptAsset::fetch() { uint8 ins = _instructions[_ip]; _ip++; return ins; } +bool ScriptAsset::hasNext() { + return _ip < _instructions.size(); +} + +void ScriptAsset::branch(word amount) { + _ip += amount; +} + void ScriptAsset::loadInstructions() { uint32 amount = _container->getItemByteSize(_id); Common::SeekableReadStream *res = _container->getItem(_id); diff --git a/engines/macventure/script.h b/engines/macventure/script.h index d66a867eca..e56c6e7440 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -51,6 +51,7 @@ enum ControlAction { }; typedef uint32 ObjID; +typedef int16 word; class ScriptAsset { public: @@ -58,7 +59,9 @@ public: ~ScriptAsset() {} void reset(); - uint8 fecth(); + uint8 fetch(); + bool hasNext(); + void branch(word amount); private: @@ -72,13 +75,61 @@ private: uint32 _ip; // Instruction pointer }; -struct EngineState { - uint8 stack[0x80]; - uint8 sp; - +class EngineState { +public: EngineState() { + clear(); + } + + void push(word data) { + stack[sp] = unneg16(data); + sp--; + } + + word pop() { + byte v = stack[sp]; + sp++; + return v; + } + + word peek(word off) { + return stack[sp + off]; + } + + void poke(word off, word val) { + stack[sp + off] = unneg16(val); + } + + void clear() { sp = 0x80; } + + word size() { + return 0x80 - sp; + } + +private: + word unneg16(word data) { + if (data < 0) + data = ((-data) ^ 0xFFFF) + 1; + + return data; + } + +private: + + word stack[0x80]; + word sp; +}; + +struct FunCall { + word func; + word rank; + + FunCall(word f, word r) { + func = f; + rank = r; + } }; struct EngineFrame { @@ -89,6 +140,7 @@ struct EngineFrame { int y; EngineState state; Common::Array scripts; + Common::Array saves; uint32 familyIdx; bool haltedInFirst; @@ -98,7 +150,7 @@ struct EngineFrame { class ScriptEngine { public: - ScriptEngine(World *world); + ScriptEngine(MacVentureEngine *engine, World *world); ~ScriptEngine(); public: @@ -110,9 +162,131 @@ private: bool execFrame(bool execAll); bool loadScript(EngineFrame * frame, uint32 scriptID); bool resumeFunc(EngineFrame * frame); - bool runFunc(); + bool runFunc(EngineFrame * frame); + +private: + + // Aux + word neg16(word val); + word neg8(word val); + word sumChildrenAttr(word obj, word attr, bool recursive); + + // Opcodes + void op80GATT(EngineState *state, EngineFrame *frame); //get attribute + void op81SATT(EngineState *state, EngineFrame *frame); //set attribute + void op82SUCH(EngineState *state, EngineFrame *frame); //sum children attribute + void op83PUCT(EngineState *state, EngineFrame *frame); //push selected control + void op84PUOB(EngineState *state, EngineFrame *frame); //push selected object + void op85PUTA(EngineState *state, EngineFrame *frame); //push target + void op86PUDX(EngineState *state, EngineFrame *frame); //push deltax + void op87PUDY(EngineState *state, EngineFrame *frame); //push deltay + void op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset *asset);//push immediate.b + void op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *asset);//push immediate + void op8aGGLO(EngineState *state, EngineFrame *frame); //get global + void op8bSGLO(EngineState *state, EngineFrame *frame); //set global + void op8cRAND(EngineState *state, EngineFrame *frame); //random + void op8dCOPY(EngineState *state, EngineFrame *frame); //copy + void op8eCOPYN(EngineState *state, EngineFrame *frame); //copyn + void op8fSWAP(EngineState *state, EngineFrame *frame); //swap + + void op90SWAPN(EngineState *state, EngineFrame *frame); //swapn + void op91POP(EngineState *state, EngineFrame *frame); //pop + void op92COPYP(EngineState *state, EngineFrame *frame); //copy+1 + void op93COPYPN(EngineState *state, EngineFrame *frame);//copy+n + void op94SHUFF(EngineState *state, EngineFrame *frame); //shuffle + void op95SORT(EngineState *state, EngineFrame *frame); //sort + void op96CLEAR(EngineState *state, EngineFrame *frame); //clear stack + void op97SIZE(EngineState *state, EngineFrame *frame); //get stack size + void op98ADD(EngineState *state, EngineFrame *frame); //add + void op99SUB(EngineState *state, EngineFrame *frame); //subtract + void op9aMUL(EngineState *state, EngineFrame *frame); //multiply + void op9bDIV(EngineState *state, EngineFrame *frame); //divide + void op9cMOD(EngineState *state, EngineFrame *frame); //mod + void op9dDMOD(EngineState *state, EngineFrame *frame); //divmod + void op9eABS(EngineState *state, EngineFrame *frame); //abs + void op9fNEG(EngineState *state, EngineFrame *frame); //neg + + void opa0AND(EngineState *state, EngineFrame *frame); //and + void opa1OR(EngineState *state, EngineFrame *frame); //or + void opa2XOR(EngineState *state, EngineFrame *frame); //xor + void opa3NOT(EngineState *state, EngineFrame *frame); //not + void opa4LAND(EngineState *state, EngineFrame *frame); //logical and + void opa5LOR(EngineState *state, EngineFrame *frame); //logical or + void opa6LXOR(EngineState *state, EngineFrame *frame); //logical xor + void opa7LNOT(EngineState *state, EngineFrame *frame); //logical not + void opa8GTU(EngineState *state, EngineFrame *frame); //gt? unsigned + void opa9LTU(EngineState *state, EngineFrame *frame); //lt? unsigned + void opaaGTS(EngineState *state, EngineFrame *frame); //gt? signed + void opabLTS(EngineState *state, EngineFrame *frame); //lt? signed + void opacEQ(EngineState *state, EngineFrame *frame); //eq? + void opadEQS(EngineState *state, EngineFrame *frame); //eq string? + void opaeCONT(EngineState *state, EngineFrame *frame); //contains + void opafCONTW(EngineState *state, EngineFrame *frame); //contains word + + void opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bra + void opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bra.b + void opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //beq + void opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //beq.b + void opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bne + void opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bne.b + void opb6CLAT(EngineState *state, EngineFrame *frame); //call later + void opb7CCA(EngineState *state, EngineFrame *frame); //cancel call + void opb8CLOW(EngineState *state, EngineFrame *frame); //cancel low priority + void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority + void opbaCRAN(EngineState *state, EngineFrame *frame); //cancel priority range + void opbbFORK(EngineState *state, EngineFrame *frame); //fork + void opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset *script); //call + void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object + void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects + void opbfSNOB(EngineState *state, EngineFrame *frame); //snap object + + void opc0TEXI(EngineState *state, EngineFrame *frame); //toggle exits + void opc1PTXT(EngineState *state, EngineFrame *frame); //print text + void opc2PNEW(EngineState *state, EngineFrame *frame); //print newline + void opc3PTNE(EngineState *state, EngineFrame *frame); //print text+nl + void opc4PNTN(EngineState *state, EngineFrame *frame); //print nl+text+nl + void opc5PNUM(EngineState *state, EngineFrame *frame); //print number + void opc6P2(EngineState *state, EngineFrame *frame); //push 2 + void opc7PLBG(EngineState *state, EngineFrame *frame); //play sound in background + void opc8PLAW(EngineState *state, EngineFrame *frame); //play sound and wait + void opc9WAIT(EngineState *state, EngineFrame *frame); //wait for sound to finish? + void opcaTIME(EngineState *state, EngineFrame *frame); //get current time + void opcbDAY(EngineState *state, EngineFrame *frame); //get current day + void opccCHLD(EngineState *state, EngineFrame *frame); //get children + void opcdNCHLD(EngineState *state, EngineFrame *frame); //get num children + void opceVERS(EngineState *state, EngineFrame *frame); //get engine version + void opcfPSCE(EngineState *state, EngineFrame *frame); //push scenario number + + void opd0P1(EngineState *state, EngineFrame *frame); //push 1 + void opd1GOBD(EngineState *state, EngineFrame *frame); //get object dimensions + void opd2GOVP(EngineState *state, EngineFrame *frame); //get overlap percent + void opd3CAPC(EngineState *state, EngineFrame *frame); //capture children + void opd4RELC(EngineState *state, EngineFrame *frame); //release children + void opd5DLOG(EngineState *state, EngineFrame *frame); //show speech dialog + void opd6ACMD(EngineState *state, EngineFrame *frame); //activate command + void opd7LOSE(EngineState *state, EngineFrame *frame); //lose game + void opd8WIN(EngineState *state, EngineFrame *frame); //win game + void opd9SLEEP(EngineState *state, EngineFrame *frame); //sleep + void opdaCLICK(EngineState *state, EngineFrame *frame); //click to continue + void opdbROBQ(EngineState *state, EngineFrame *frame); //run queue + void opdcRSQ(EngineState *state, EngineFrame *frame); //run sound queue + void opddRTQ(EngineState *state, EngineFrame *frame); //run text queue + void opdeUPSC(EngineState *state, EngineFrame *frame); //update screen + void opdfFMAI(EngineState *state, EngineFrame *frame); //flash main window + + void ope0CHGR(EngineState *state, EngineFrame *frame); //cache graphic and object + void ope1CHSO(EngineState *state, EngineFrame *frame); //cache sound + void ope2MDIV(EngineState *state, EngineFrame *frame); //muldiv + void ope3UPOB(EngineState *state, EngineFrame *frame); //update object + void ope4PLEV(EngineState *state, EngineFrame *frame); //currently playing event? + void ope5WEV(EngineState *state, EngineFrame *frame); //wait for event to finish + void ope6GFIB(EngineState *state, EngineFrame *frame); //get fibonacci (joke) + void ope7CFIB(EngineState *state, EngineFrame *frame); //calc fibonacci + + void op00NOOP(byte op); private: + MacVentureEngine *_engine; World *_world; Common::Array _frames; Container *_scripts; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 2cd50ff82a..2f603c5ddc 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -102,6 +102,56 @@ Common::Array World::getChildren(ObjID objID, bool recursive) { return Common::Array(); } +WindowReference World::getObjWindow(ObjID objID) { + switch (objID) { + case 0xfffc: return kExitsWindow; + case 0xfffd: return kSelfWindow; + case 0xfffe: return kOutConsoleWindow; + case 0xffff: return kCommandsWindow; + } + + return findObjWindow(objID); +} + +WindowReference World::findObjWindow(ObjID objID) { + return kMainGameWindow; +} + +Attribute World::getGlobal(uint32 attrID) { + return _saveGame->getGlobals()[attrID]; +} + +void World::setGlobal(uint32 attrID, Attribute value) { + _saveGame->setGlobal(attrID, value); +} + +void World::updateObj(ObjID objID) { + WindowReference win; + if (getObjAttr(1, kAttrParentObject) == objID) { + win = kMainGameWindow; + } else { + win = getObjWindow(objID); + } + if (win) { + //focusObjWin(objID); + _engine->runObjQueue(); + //_engine->updateWindow(win); + } +} + +void World::captureChildren(ObjID objID) { +} + +void World::releaseChildren(ObjID objID) { +} + +Common::String World::getText(ObjID objID) { + TextAsset text = TextAsset(objID, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); + + return *text.decode(); +} + + bool World::loadStartGameFileName() { Common::SeekableReadStream *res; @@ -186,6 +236,10 @@ const AttributeGroup * SaveGame::getGroup(uint32 groupID) { return &(_groups[groupID]); } +void SaveGame::setGlobal(uint32 attrID, Attribute value) { + _globals[attrID] = value; +} + const Common::Array& MacVenture::SaveGame::getGlobals() { return _globals; } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 3893aca445..370582665b 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -67,9 +67,11 @@ public: Attribute getAttr(ObjID objID, uint32 attrID); void setAttr(uint32 attrID, ObjID objID, Attribute value); + void setGlobal(uint32 attrID, Attribute value); + const Common::Array &getGlobals(); + const Common::Array &getGroups(); const AttributeGroup *getGroup(uint32 groupID); - const Common::Array &getGlobals(); const Common::String &getText(); private: @@ -88,11 +90,22 @@ public: World(MacVentureEngine *engine, Common::MacResManager *resMan); ~World(); - uint32 getObjAttr(ObjID objID, uint32 attrID); + void setObjAttr(ObjID objID, uint32 attrID, Attribute value); + void setGlobal(uint32 attrID, Attribute value); + void updateObj(ObjID objID); + void captureChildren(ObjID objID); + void releaseChildren(ObjID objID); + + uint32 getObjAttr(ObjID objID, uint32 attrID); + Attribute getGlobal(uint32 attrID); + Common::String getText(ObjID objID); + bool isObjActive(ObjID obj); Common::Array getFamily(ObjID objID, bool recursive); Common::Array getChildren(ObjID objID, bool recursive); + WindowReference getObjWindow(ObjID objID); + WindowReference findObjWindow(ObjID objID); private: bool loadStartGameFileName(); -- cgit v1.2.3 From 60d5ef5c5b875269f29cd817481de7e162f4966a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 20 Jun 2016 01:30:39 +0200 Subject: MACVENTURE: Begin implementing object queue --- engines/macventure/gui.cpp | 144 +++++++++++++++++++++++++----------- engines/macventure/gui.h | 21 ++++-- engines/macventure/macventure.cpp | 149 ++++++++++++++++++++++++++++++++++---- engines/macventure/macventure.h | 25 +++++-- engines/macventure/script.cpp | 3 +- engines/macventure/world.cpp | 54 +++++++++----- engines/macventure/world.h | 11 ++- 7 files changed, 315 insertions(+), 92 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 4ca3de70b3..1a468eb93c 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -99,23 +99,44 @@ bool Gui::processEvent(Common::Event &event) { } const WindowData& Gui::getWindowData(WindowReference reference) { - assert(_windowData); - - Common::List::const_iterator iter = _windowData->begin(); - while (iter->refcon != reference && iter != _windowData->end()) { - iter++; - } - - if (iter->refcon == reference) - return *iter; - - error("Could not locate the desired window data"); + return findWindowData(reference); } const Graphics::Font& Gui::getCurrentFont() { return *_wm.getFont("Chicago-12", Graphics::FontManager::kBigGUIFont); } +void Gui::bringToFront(WindowReference winID) { + // FIXME: There has to be a better way to do this, maybe with the _wm + switch (winID) { + case MacVenture::kCommandsWindow: + _controlsWindow->setActive(true); + break; + case MacVenture::kMainGameWindow: + _mainGameWindow->setActive(true); + break; + case MacVenture::kOutConsoleWindow: + _outConsoleWindow->setActive(true); + break; + case MacVenture::kSelfWindow: + _selfWindow->setActive(true); + break; + case MacVenture::kExitsWindow: + _exitsWindow->setActive(true); + break; + case MacVenture::kDiplomaWindow: + _diplomaWindow->setActive(true); + break; + default: + break; + } +} + +void Gui::setWindowTitle(WindowReference winID, Common::String string) { + findWindowData(winID).title = string; + findWindowData(winID).titleLength = string.size(); +} + void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); @@ -191,13 +212,6 @@ void Gui::initWindows() { _diplomaWindow->getSurface()->fillRect(_diplomaWindow->getSurface()->getBounds(), kColorGreen2); */ - // Inventory Window - _inventoryWindow = _wm.addWindow(false, true, true); - _inventoryWindow->setDimensions(getWindowData(kInventoryWindow).bounds); - _inventoryWindow->setActive(false); - _inventoryWindow->setCallback(inventoryWindowCallback, this); - loadBorder(_inventoryWindow, "border_command.bmp", false); - } void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { @@ -324,9 +338,10 @@ bool Gui::loadWindows() { res->readUint32BE(); // Skip the true id. For some reason it's reading 0 data.titleLength = res->readByte(); if (data.titleLength) { - data.title = new char[data.titleLength + 1]; - res->read(data.title, data.titleLength); - data.title[data.titleLength] = '\0'; + char* newTitle = new char[data.titleLength + 1]; + res->read(newTitle, data.titleLength); + newTitle[data.titleLength] = '\0'; + data.title = Common::String(newTitle); } debug(5, "Window loaded: %s", data.title); @@ -334,28 +349,9 @@ bool Gui::loadWindows() { _windowData->push_back(data); } - loadInventoryWindow(); - return true; } -void Gui::loadInventoryWindow() { - WindowData data; - GlobalSettings settings = _engine->getGlobalSettings(); - data.bounds = Common::Rect( - settings.invLeft, - settings.invTop, - settings.invLeft + settings.invWidth, - settings.invTop + settings.invHeight); - data.title = "Inventory"; - data.visible = true; - data.hasCloseBox = false; - data.refcon = kInventoryWindow; - data.titleLength = 10; - - _windowData->push_back(data); -} - bool Gui::loadControls() { Common::MacResIDArray resArray; Common::SeekableReadStream *res; @@ -456,7 +452,21 @@ void Gui::drawMainGameWindow() { } void Gui::drawSelfWindow() { + warning("drawSelfWindow: Unimplemented"); +} + +WindowData & Gui::findWindowData(WindowReference reference) { + assert(_windowData); + + Common::List::iterator iter = _windowData->begin(); + while (iter->refcon != reference && iter != _windowData->end()) { + iter++; + } + + if (iter->refcon == reference) + return *iter; + error("Could not locate the desired window data"); } @@ -561,12 +571,60 @@ void Gui::handleMenuAction(MenuAction action) { } } +void Gui::updateWindow(WindowReference winID, bool containerOpen) { + if (winID > 0x90) return; + if (winID == kSelfWindow || containerOpen) { + if (winID == kMainGameWindow) { + warning("Unimplemented: draw main game window"); + } else { + warning("Unimplemented: fill window with background"); + } + WindowData &data = findWindowData(winID); + Common::Array children = data.children; + for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { + warning("Unimplemented: draw object %x", *it); + } + if (data.type == kZoomDoc && data.updateScroll) { + warning("Unimplemented: update scroll"); + } + } +} + +WindowReference Gui::createInventoryWindow() { + Graphics::MacWindow *newWindow = _wm.addWindow(true, true, true); + WindowData newData; + GlobalSettings settings = _engine->getGlobalSettings(); + newData.refcon = (WindowReference)ABS(_inventoryWindows.size()); // This is a hack + + if (_windowData->back().refcon < 0x80) { // There is already another inventory window + newData.bounds = _windowData->back().bounds; // Inventory windows are always last + newData.bounds.translate(newData.bounds.left + settings.invOffsetX, newData.bounds.top + settings.invOffsetY); + } else { + newData.bounds = Common::Rect( + settings.invLeft, + settings.invTop, + settings.invLeft + settings.invWidth, + settings.invTop + settings.invHeight); + } + newData.type = kZoomDoc; + newData.hasCloseBox = true; + newData.visible = true; + _windowData->push_back(newData); + + newWindow->setDimensions(newData.bounds); + newWindow->setCallback(inventoryWindowCallback, this); + loadBorder(newWindow, "border_self_inac.bmp", false); + loadBorder(newWindow, "border_self_act.bmp", true); + _inventoryWindows.push_back(newWindow); + return newData.refcon; +} + bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { - if (_engine->isPaused()) + if (_engine->isPaused()) return true; - + Common::Point position( event.mouse.x - _controlsWindow->getDimensions().left, event.mouse.y - _controlsWindow->getDimensions().top); @@ -583,7 +641,7 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { _engine->selectControl((ControlReference)data.getData().refcon); _engine->activateCommand((ControlReference)data.getData().refcon); _engine->refreshReady(); - _engine->preparedToRun(); + _engine->preparedToRun(); } return false; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 4d760e8382..b107b1584f 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -32,6 +32,7 @@ namespace MacVenture { using namespace Graphics::MacGUIConstants; using namespace Graphics::MacWindowConstants; class MacVentureEngine; +typedef uint32 ObjID; //namespace MacVentureMenuActions { enum MenuAction { @@ -59,8 +60,7 @@ enum WindowReference { kOutConsoleWindow = 0x82, kSelfWindow = 0x83, kExitsWindow = 0x84, - kDiplomaWindow = 0x85, - kInventoryWindow = 0x90 // Not in the files, but here for convenience + kDiplomaWindow = 0x85 }; enum MVWindowType { @@ -85,7 +85,9 @@ struct WindowData { uint16 hasCloseBox; WindowReference refcon; uint8 titleLength; - char* title; + Common::String title; + Common::Array children; + bool updateScroll; }; enum ControlReference { @@ -132,6 +134,9 @@ public: void draw(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); + void updateWindow(WindowReference winID, bool containerOpen); + + WindowReference createInventoryWindow(); // Event processors bool processCommandEvents(WindowClick click, Common::Event &event); @@ -145,6 +150,10 @@ public: const Graphics::Font& getCurrentFont(); + // Modifiers + void bringToFront(WindowReference window); + void setWindowTitle(WindowReference winID, Common::String string); + // Ugly switches BorderBounds borderBounds(MVWindowType type); @@ -165,7 +174,7 @@ private: // Attributes Graphics::MacWindow *_selfWindow; Graphics::MacWindow *_exitsWindow; Graphics::MacWindow *_diplomaWindow; - Graphics::MacWindow *_inventoryWindow; + Common::Array _inventoryWindows; Graphics::Menu *_menu; private: // Methods @@ -178,7 +187,6 @@ private: // Methods // Loaders bool loadMenus(); bool loadWindows(); - void loadInventoryWindow(); bool loadControls(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); @@ -188,6 +196,9 @@ private: // Methods void drawMainGameWindow(); void drawSelfWindow(); + // Finders + WindowData& findWindowData(WindowReference reference); + }; class CommandButton { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index f2a2f43f51..6e477d4b05 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -171,7 +171,7 @@ void MacVentureEngine::activateCommand(ControlReference id) { } void MacVentureEngine::refreshReady() { - switch (objectsToApplyCommand()) { + switch (getInvolvedObjects()) { case 0: // No selected object _cmdReady = true; break; @@ -201,16 +201,18 @@ void MacVentureEngine::loseGame() { _gameState = kGameStateLosing; } -void MacVentureEngine::enqueueObject(ObjID id) { +void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID) { QueuedObject obj; - obj.parent = _world->getObjAttr(id, kAttrParentObject); - obj.x = _world->getObjAttr(id, kAttrPosX); - obj.y = _world->getObjAttr(id, kAttrPosY); - obj.exitx = _world->getObjAttr(id, kAttrExitX); - obj.exity = _world->getObjAttr(id, kAttrExitY); - obj.hidden = _world->getObjAttr(id, kAttrHiddenExit); - obj.offsecreen = _world->getObjAttr(id, kAttrInvisible); - obj.invisible = _world->getObjAttr(id, kAttrUnclickable); + obj.id = type; + obj.object = objID; + obj.parent = _world->getObjAttr(objID, kAttrParentObject); + obj.x = _world->getObjAttr(objID, kAttrPosX); + obj.y = _world->getObjAttr(objID, kAttrPosY); + obj.exitx = _world->getObjAttr(objID, kAttrExitX); + obj.exity = _world->getObjAttr(objID, kAttrExitY); + obj.hidden = _world->getObjAttr(objID, kAttrHiddenExit); + obj.offsecreen = _world->getObjAttr(objID, kAttrInvisible); + obj.invisible = _world->getObjAttr(objID, kAttrUnclickable); _objQueue.push_back(obj); } @@ -300,16 +302,58 @@ bool MacVentureEngine::updateState() { } void MacVentureEngine::revert() { + warning("revert: unimplemented"); } void MacVentureEngine::runObjQueue() { - + warning("runObjQueue: not fully implemented"); + while (!_objQueue.empty()) { + uint32 biggest = 0; + uint32 index = 0; + uint32 temp; + for (uint i = 0; i < _objQueue.size(); i++) { + temp = _objQueue[i].id; + if (temp > biggest) { + biggest = temp; + index = i; + } + } + QueuedObject obj = _objQueue[index]; + _objQueue.remove_at(index); + switch (obj.id) { + case 0x2: + focusObjectWindow(obj.object); + break; + case 0x3: + openObject(obj.object); + break; + case 0x4: + closeObject(obj.object); + break; + case 0x7: + checkObject(obj.object); + break; + case 0x8: + reflectSwap(obj.object); + break; + case 0xc: + _world->setObjAttr(_gui->getWindowData(kMainGameWindow).refcon, kAttrContainerOpen, 0); + _world->setObjAttr(_world->getObjAttr(1, kAttrParentObject), kAttrContainerOpen, 1); + break; + case 0xd: + toggleExits(); + break; + case 0xe: + zoomObject(obj.object); + break; + } + } } void MacVentureEngine::updateControls() { if (_activeControl) _activeControl = kNoCommand; - // toggleExits(); + toggleExits(); // resetVars(); } @@ -322,6 +366,52 @@ void MacVentureEngine::resetVars() { _cmdReady = false; } +void MacVentureEngine::focusObjectWindow(ObjID objID) { + if (objID) { + WindowReference win = getObjWindow(objID); + if (win) + _gui->bringToFront(win); + } +} + +void MacVentureEngine::openObject(ObjID objID) { + if (getObjWindow(objID)) return; + if (objID == _world->getObjAttr(1, kAttrParentObject)) { + //_gui->setRefcon(objID, kMainGameWindow); // FIXME: Find better name + _gui->updateWindow(kMainGameWindow, _world->getObjAttr(objID, kAttrContainerOpen)); + //_gui->drawExits(); + _gui->setWindowTitle(kMainGameWindow, _world->getText(objID)); + } else { // Open inventory window + Common::Point p(_world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); + //getParentWin(obj).localToGlobal(p); + //globalToDesktop(p); + WindowReference invID = _gui->createInventoryWindow(); + _gui->setWindowTitle(invID, _world->getText(objID)); + //_gui->setRefCon(objID, invID); + _gui->updateWindow(invID, _world->getObjAttr(objID, kAttrContainerOpen)); + } +} + +void MacVentureEngine::closeObject(ObjID objID) { + warning("closeObject: unimplemented"); +} + +void MacVentureEngine::checkObject(ObjID objID) { + warning("checkObject: unimplemented"); +} + +void MacVentureEngine::reflectSwap(ObjID objID) { + warning("reflectSwap: unimplemented"); +} + +void MacVentureEngine::toggleExits() { + warning("toggleExits: unimplemented"); +} + +void MacVentureEngine::zoomObject(ObjID objID) { + warning("zoomObject: unimplemented"); +} + ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlReference id) { switch (id) { case MacVenture::kControlExitBox: @@ -347,10 +437,6 @@ ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlReference i } } -uint MacVentureEngine::objectsToApplyCommand() { - return uint(); -} - // Data retrieval bool MacVentureEngine::isPaused() { @@ -382,6 +468,37 @@ uint32 MacVentureEngine::randBetween(uint32 min, uint32 max) { return _rnd->getRandomNumber(max - min) + min; } +uint32 MacVentureEngine::getInvolvedObjects() { + return (_selectedControl ? _globalSettings.cmdArgCnts[_selectedControl - 1] : 3000); +} + +WindowReference MacVentureEngine::getObjWindow(ObjID objID) { + switch (objID) { + case 0xfffc: return kExitsWindow; + case 0xfffd: return kSelfWindow; + case 0xfffe: return kOutConsoleWindow; + case 0xffff: return kCommandsWindow; + } + + return findObjWindow(objID); +} + +WindowReference MacVentureEngine::findObjWindow(ObjID objID) { + return kMainGameWindow; +} + +Common::Point MacVentureEngine::getDeltaPoint() { + return _deltaPoint; +} + +ObjID MacVentureEngine::getDestObject() { + return _destObject; +} + +ControlAction MacVentureEngine::getSelectedControl() { + return _selectedControl; +} + // Data loading bool MacVentureEngine::loadGlobalSettings() { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 3ae195aef0..aabcdcb8ac 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -164,7 +164,7 @@ public: bool updateState(); void revert(); - void enqueueObject(ObjID id); + void enqueueObject(ObjectQueueID type, ObjID objID); void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text); void runObjQueue(); @@ -178,6 +178,13 @@ public: bool isOldText() const; const HuffmanLists *getDecodingHuffman() const; uint32 randBetween(uint32 min, uint32 max); + uint32 getInvolvedObjects(); + WindowReference getObjWindow(ObjID objID); + WindowReference findObjWindow(ObjID objID); + + Common::Point getDeltaPoint(); + ObjID getDestObject(); + ControlAction getSelectedControl(); private: void processEvents(); @@ -187,13 +194,21 @@ private: void updateControls(); void resetVars(); + // Object queue methods + void focusObjectWindow(ObjID objID); + void openObject(ObjID objID); + void closeObject(ObjID objID); + void checkObject(ObjID objID); + void reflectSwap(ObjID objID); + void toggleExits(); + void zoomObject(ObjID objID); + // Data loading bool loadGlobalSettings(); bool loadTextHuffman(); // Utils ControlAction referenceToAction(ControlReference id); - uint objectsToApplyCommand(); const char* getGameFileName() const; @@ -222,9 +237,9 @@ private: // Attributes bool _haltedAtEnd, _haltedInSelection; bool _gameChanged; - Common::List _objQueue; - Common::List _soundQueue; - Common::List _textQueue; + Common::Array _objQueue; + Common::Array _soundQueue; + Common::Array _textQueue; // Selections ObjID _destObject; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index b0d5ef0011..5702c9f1ad 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -151,6 +151,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { byte op; while (script.hasNext()) { op = script.fetch(); + debug(8, "SCRIPT: I'm running operation %x", op); if (!(op & 0x80)) { state->push(op); } else { @@ -900,7 +901,7 @@ void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { word obj = state->pop(); - _engine->enqueueObject(obj); + _engine->enqueueObject(kFocusWindow, obj); } void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 2f603c5ddc..c7b103efd7 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -68,7 +68,7 @@ void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) { setParent(objID, value); if (attrID < kAttrOtherDoor) - _engine->enqueueObject(objID); + _engine->enqueueObject(kUpdateObject, objID); uint32 idx = _engine->getGlobalSettings().attrIndices[attrID]; value <<= _engine->getGlobalSettings().attrShifts[attrID]; @@ -80,7 +80,29 @@ void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) { } bool MacVenture::World::isObjActive(ObjID obj) { - return false; + ObjID destObj = _engine->getDestObject(); + Common::Point p = _engine->getDeltaPoint(); + ControlAction selectedControl = _engine->getSelectedControl(); + if (!getAncestor(obj)) return false; // If our ancestor is the garbage (obj 0), we're inactive + if (_engine->getInvolvedObjects() >= 2 && // If (we need > 1 objs for the command) && + destObj > 0 && // we have a destination object && + !getAncestor(destObj)) // but that destination object is in the garbage + return false; + if (selectedControl != kMoveObject) return true; // We only need one + // Handle move object + if (!isObjDraggable(obj)) return false; // We can't move it + if (getObjAttr(1, kAttrParentObject) != destObj) return true; // if the target is not the player's parent, we can go + Common::Rect rect(kScreenWidth, kScreenHeight); + rect.top -= getObjAttr(obj, kAttrPosY) + p.y; + rect.left -= getObjAttr(obj, kAttrPosX) + p.x; + return intersects(obj, rect); +} + +ObjID World::getAncestor(ObjID objID) { + ObjID root = getObjAttr(1, kAttrParentObject); + while (objID != 0 && objID != 1 && objID != root) + objID = getObjAttr(objID, kAttrParentObject); + return objID; } Common::Array World::getFamily(ObjID objID, bool recursive) { @@ -102,21 +124,6 @@ Common::Array World::getChildren(ObjID objID, bool recursive) { return Common::Array(); } -WindowReference World::getObjWindow(ObjID objID) { - switch (objID) { - case 0xfffc: return kExitsWindow; - case 0xfffd: return kSelfWindow; - case 0xfffe: return kOutConsoleWindow; - case 0xffff: return kCommandsWindow; - } - - return findObjWindow(objID); -} - -WindowReference World::findObjWindow(ObjID objID) { - return kMainGameWindow; -} - Attribute World::getGlobal(uint32 attrID) { return _saveGame->getGlobals()[attrID]; } @@ -130,7 +137,7 @@ void World::updateObj(ObjID objID) { if (getObjAttr(1, kAttrParentObject) == objID) { win = kMainGameWindow; } else { - win = getObjWindow(objID); + win = _engine->getObjWindow(objID); } if (win) { //focusObjWin(objID); @@ -152,6 +159,17 @@ Common::String World::getText(ObjID objID) { } +bool World::isObjDraggable(ObjID objID) { + return (getObjAttr(objID, kAttrInvisible) == 0 && + getObjAttr(objID, kAttrUnclickable) == 0 && + getObjAttr(objID, kAttrUndraggable) == 0); +} + +bool World::intersects(ObjID objID, Common::Rect rect) { + warning("Intersects: unimplemented"); + return true; +} + bool World::loadStartGameFileName() { Common::SeekableReadStream *res; diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 370582665b..fe45508623 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -101,13 +101,16 @@ public: Attribute getGlobal(uint32 attrID); Common::String getText(ObjID objID); - bool isObjActive(ObjID obj); + bool isObjActive(ObjID objID); + + ObjID getAncestor(ObjID objID); Common::Array getFamily(ObjID objID, bool recursive); - Common::Array getChildren(ObjID objID, bool recursive); - WindowReference getObjWindow(ObjID objID); - WindowReference findObjWindow(ObjID objID); + Common::Array getChildren(ObjID objID, bool recursive); private: + bool isObjDraggable(ObjID objID); + bool intersects(ObjID objID, Common::Rect rect); + bool loadStartGameFileName(); void calculateObjectRelations(); void setParent(ObjID child, ObjID newParent); -- cgit v1.2.3 From 2fbff0e6782759770048c9b9442832e525d001b6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 20 Jun 2016 08:59:53 +0200 Subject: MACVENTURE: Fix some minor warnings --- engines/macventure/gui.cpp | 14 +++++--- engines/macventure/gui.h | 2 ++ engines/macventure/macventure.cpp | 1 + engines/macventure/script.cpp | 70 ++++++++++++++++++++------------------- engines/macventure/script.h | 18 +++++----- 5 files changed, 58 insertions(+), 47 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 1a468eb93c..c5c6df30cb 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -94,6 +94,10 @@ void Gui::draw() { _wm.draw(); } +void Gui::drawMenu() { + _menu->draw(&_screen); +} + bool Gui::processEvent(Common::Event &event) { return _wm.processEvent(event); } @@ -271,7 +275,6 @@ bool Gui::loadMenus() { uint8 titleLength; char* title; - int menunum = -1; // High level menus have level -1 /* Skip menuID, width, height, resourceID, placeholder */ for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } enabled = res->readUint32BE(); @@ -320,8 +323,7 @@ bool Gui::loadWindows() { for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('W', 'I', 'N', 'D'), *iter); WindowData data; - uint16 top, left, bottom, right; - uint16 borderSize; + uint16 top, left, bottom, right; top = res->readUint16BE(); left = res->readUint16BE(); bottom = res->readUint16BE(); @@ -512,7 +514,7 @@ bool diplomaWindowCallback(Graphics::WindowClick click, Common::Event &event, vo bool inventoryWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - return true; + return g->processInventoryEvents(click, event); } void menuCommandsCallback(int action, Common::String &text, void *data) { @@ -670,6 +672,10 @@ bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & ev return getWindowData(kDiplomaWindow).visible; } +bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { + return false; +} + /* Ugly switches */ BorderBounds Gui::borderBounds(MVWindowType type) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index b107b1584f..dc08a77cec 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -132,6 +132,7 @@ public: ~Gui(); void draw(); + void drawMenu(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); void updateWindow(WindowReference winID, bool containerOpen); @@ -145,6 +146,7 @@ public: bool processSelfEvents(WindowClick click, Common::Event &event); bool processExitsEvents(WindowClick click, Common::Event &event); bool processDiplomaEvents(WindowClick click, Common::Event &event); + bool processInventoryEvents(WindowClick click, Common::Event &event); const WindowData& getWindowData(WindowReference reference); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 6e477d4b05..23425d976f 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -137,6 +137,7 @@ Common::Error MacVentureEngine::run() { } } + _gui->drawMenu(); g_system->updateScreen(); g_system->delayMillis(50); } diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5702c9f1ad..715249ca6d 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -337,7 +337,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opbbFORK(state, frame); break; case 0xbc: //call - opbcCALL(state, frame, &script); + opbcCALL(state, frame, script); break; case 0xbd: //focus object opbdFOOB(state, frame); @@ -537,14 +537,14 @@ void ScriptEngine::op87PUDY(EngineState * state, EngineFrame * frame) { state->push(frame->y); } -void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - state->push(asset->fetch()); +void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + state->push(script->fetch()); } -void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * asset) { - word val = asset->fetch(); +void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); state->push(val); } @@ -798,50 +798,50 @@ void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { state->push(haystack.contains(needle) ? 1 : 0); } -void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); val = neg16(val); - asset->branch(val); + script->branch(val); } -void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val = neg8(val); - asset->branch(val); + script->branch(val); } -void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b != 0) asset->branch(val); + if (b != 0) script->branch(val); } -void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b != 0) asset->branch(val); + if (b != 0) script->branch(val); } -void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val <<= 8; - val = val | asset->fetch(); + val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b == 0) asset->branch(val); + if (b == 0) script->branch(val); } -void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *asset) { - word val = asset->fetch(); +void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { + word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b == 0) asset->branch(val); + if (b == 0) script->branch(val); } void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { @@ -852,7 +852,7 @@ void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { word func = state->pop(); - for (int i = 0; i < frame->saves.size(); i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].func == func) frame->saves[i].rank = 0; } @@ -860,14 +860,14 @@ void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { word hi = state->pop(); - for (int i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) if (frame->saves[i].rank <= hi) frame->saves[i].rank = 0; } void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { word lo = state->pop(); - for (int i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) if (frame->saves[i].rank >= lo) frame->saves[i].rank = 0; } @@ -875,7 +875,7 @@ void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { word hi = state->pop(); word lo = state->pop(); - for (int i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) if (frame->saves[i].rank >= lo && frame->saves[i].rank <= hi) frame->saves[i].rank = 0; @@ -891,12 +891,12 @@ void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { _frames.push_back(newframe); } -void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); frame->scripts.remove_at(0); frame->scripts.insert_at(0, newfun); - script = &frame->scripts.front(); + script = frame->scripts.front(); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -962,7 +962,7 @@ void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { - for (int i = 0; i < 6; i++) // Dummy + for (uint i = 0; i < 6; i++) // Dummy state->push(0x00); op00NOOP(0xca); } @@ -1005,12 +1005,14 @@ void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { Common::Rect bounds(0, 0, 1, 1); //= _world->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); + op00NOOP(0xd1); } void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { word b = state->pop(); word a = state->pop(); state->push(0);//_world->getOverlapPercent(b, a)); + op00NOOP(0xd2); } void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/script.h b/engines/macventure/script.h index e56c6e7440..178e054e05 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -180,8 +180,8 @@ private: void op85PUTA(EngineState *state, EngineFrame *frame); //push target void op86PUDX(EngineState *state, EngineFrame *frame); //push deltax void op87PUDY(EngineState *state, EngineFrame *frame); //push deltay - void op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset *asset);//push immediate.b - void op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *asset);//push immediate + void op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset *script);//push immediate.b + void op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *script);//push immediate void op8aGGLO(EngineState *state, EngineFrame *frame); //get global void op8bSGLO(EngineState *state, EngineFrame *frame); //set global void op8cRAND(EngineState *state, EngineFrame *frame); //random @@ -223,19 +223,19 @@ private: void opaeCONT(EngineState *state, EngineFrame *frame); //contains void opafCONTW(EngineState *state, EngineFrame *frame); //contains word - void opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bra - void opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bra.b - void opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //beq - void opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //beq.b - void opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bne - void opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *asset); //bne.b + void opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *script); //bra + void opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *script); //bra.b + void opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *script); //beq + void opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *script); //beq.b + void opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *script); //bne + void opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *script); //bne.b void opb6CLAT(EngineState *state, EngineFrame *frame); //call later void opb7CCA(EngineState *state, EngineFrame *frame); //cancel call void opb8CLOW(EngineState *state, EngineFrame *frame); //cancel low priority void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority void opbaCRAN(EngineState *state, EngineFrame *frame); //cancel priority range void opbbFORK(EngineState *state, EngineFrame *frame); //fork - void opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset *script); //call + void opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script); //call void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects void opbfSNOB(EngineState *state, EngineFrame *frame); //snap object -- cgit v1.2.3 From bbf0c62f14326818d135a75bc6f9e58ad59346a1 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 20 Jun 2016 09:09:10 +0200 Subject: MACVENTURE: Add enqueue text --- engines/macventure/macventure.cpp | 16 +++++++++------- engines/macventure/macventure.h | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 23425d976f..5c8f6b4051 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -112,11 +112,7 @@ Common::Error MacVentureEngine::run() { processEvents(); if (_prepared) { - _prepared = false; - - if (!_halted) { - _gui->draw(); - } + _prepared = false; if (_cmdReady || _halted) { _halted = false; @@ -137,7 +133,7 @@ Common::Error MacVentureEngine::run() { } } - _gui->drawMenu(); + _gui->draw(); g_system->updateScreen(); g_system->delayMillis(50); } @@ -218,10 +214,16 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID) { } void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text) { + QueuedText newText; + newText.id = type; + newText.destination = target; + newText.source = source; + newText.asset = text; + _textQueue.push_back(newText); } void MacVentureEngine::printTexts() { - debug("Printing texts.."); + warning("printTexts: unimplemented"); } const GlobalSettings& MacVentureEngine::getGlobalSettings() const { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index aabcdcb8ac..bb4eec83f5 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -124,12 +124,6 @@ enum ObjectQueueID { kAnimateBack = 14 }; -enum TextQueueID { - kTextNumber = 1, - kTextNewLine = 2, - kTextPlain = 3 -}; - struct QueuedObject { ObjectQueueID id; ObjID object; @@ -143,6 +137,19 @@ struct QueuedObject { bool invisible; }; +enum TextQueueID { + kTextNumber = 1, + kTextNewLine = 2, + kTextPlain = 3 +}; + +struct QueuedText { + TextQueueID id; + ObjID source; + ObjID destination; + ObjID asset; +}; + class MacVentureEngine : public Engine { public: @@ -239,7 +246,7 @@ private: // Attributes Common::Array _objQueue; Common::Array _soundQueue; - Common::Array _textQueue; + Common::Array _textQueue; // Selections ObjID _destObject; -- cgit v1.2.3 From ccc76f2119dcd3b802604294fc1f7bccad645374 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 21 Jun 2016 03:02:14 +0200 Subject: MACVENTURE: Add PPIC0, 1 and 2 decoding --- engines/macventure/container.h | 14 ++- engines/macventure/gui.cpp | 77 ++++++++++-- engines/macventure/gui.h | 6 + engines/macventure/image.cpp | 256 ++++++++++++++++++++++++++++++++++++++ engines/macventure/image.h | 51 ++++++-- engines/macventure/macventure.cpp | 84 ++++++++++++- engines/macventure/macventure.h | 7 ++ engines/macventure/module.mk | 1 + engines/macventure/script.cpp | 10 +- engines/macventure/world.cpp | 10 +- engines/macventure/world.h | 2 + 11 files changed, 477 insertions(+), 41 deletions(-) create mode 100644 engines/macventure/image.cpp diff --git a/engines/macventure/container.h b/engines/macventure/container.h index bd88f663b8..4dc5172fd7 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -117,7 +117,7 @@ public: uint32 bitSize = _lens[x]; bits += bitSize & 0xF; if (bits & 0x10) { - bits &= 0xf; + bits &= 0xF; _res->seek(2, SEEK_CUR); } bitSize >>= 4; @@ -129,7 +129,11 @@ public: else length >>= (32 - bitSize) - bits; length &= (1 << bitSize) - 1; length |= 1 << bitSize; - bits += bitSize; + bits += bitSize; + if (bits & 0x10) { + bits &= 0xF; + _res->seek(2, SEEK_CUR); + } } group.lengths[j] = length; @@ -173,16 +177,14 @@ public: return _res; } else { uint32 groupID = (id >> 6); - uint32 objectIndex = id & 0x3f; // Index within the group - - _res->seek(4 + (groupID * 6), SEEK_SET); + uint32 objectIndex = id & 0x3f; // Index within the group uint32 offset = 0; for (uint i = 0; i < objectIndex; i++) { offset += _groups[groupID].lengths[i]; } - _res->seek(offset, SEEK_CUR); + _res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); return _res; } diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index c5c6df30cb..725ce38268 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -99,7 +99,11 @@ void Gui::drawMenu() { } bool Gui::processEvent(Common::Event &event) { - return _wm.processEvent(event); + bool processed = false; + if (event.type == Common::EVENT_LBUTTONDOWN) { + debug("Click on the ui"); + } + return (processed || _wm.processEvent(event)); } const WindowData& Gui::getWindowData(WindowReference reference) { @@ -141,6 +145,27 @@ void Gui::setWindowTitle(WindowReference winID, Common::String string) { findWindowData(winID).titleLength = string.size(); } +void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array &children) { + WindowData &data = findWindowData(ref); + data.children.clear(); + uint32 originx = 0x7fff; + uint32 originy = 0x7fff; + for (uint i = 0; i < children.size(); i++) { + if (children[i] != 1) { + ObjID child = children[i]; + if (ref != kMainGameWindow) { + Common::Point childPos = _engine->getObjPosition(child); + originx = originx > childPos.x ? childPos.x : originx; + originy = originy > childPos.y ? childPos.y : originy; + } + data.children.push_back(child); + } + } + if (originx != 0x7fff) data.bounds.left = originx; + if (originy != 0x7fff) data.bounds.top = originy; + if (ref != kMainGameWindow) data.updateScroll = true; +} + void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); @@ -160,6 +185,7 @@ void Gui::initGUI() { if (!loadControls()) error("Could not load controls"); + draw(); } @@ -323,7 +349,7 @@ bool Gui::loadWindows() { for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('W', 'I', 'N', 'D'), *iter); WindowData data; - uint16 top, left, bottom, right; + uint16 top, left, bottom, right; top = res->readUint16BE(); left = res->readUint16BE(); bottom = res->readUint16BE(); @@ -346,7 +372,7 @@ bool Gui::loadWindows() { data.title = Common::String(newTitle); } - debug(5, "Window loaded: %s", data.title); + debug(4, "Window loaded: %s", data.title); _windowData->push_back(data); } @@ -451,10 +477,30 @@ void Gui::drawMainGameWindow() { srf->w, kColorBlack, Graphics::kTextAlignCenter); + + WindowData &data = findWindowData(kMainGameWindow); + for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { + Common::Point pos = _engine->getObjPosition(*it); + srf->fillRect( + Common::Rect( + border.leftOffset * 2 + pos.x, + border.topOffset * 2 + pos.y, + 5, + 5), + kColorBlack); + } } void Gui::drawSelfWindow() { - warning("drawSelfWindow: Unimplemented"); + Graphics::ManagedSurface *srf = _selfWindow->getSurface(); + BorderBounds border = borderBounds(getWindowData(kSelfWindow).type); + srf->fillRect( + Common::Rect( + border.leftOffset * 2, + border.topOffset * 2, + srf->w - (border.rightOffset * 3), + srf->h - (border.bottomOffset * 3)), + kColorWhite); } WindowData & Gui::findWindowData(WindowReference reference) { @@ -477,7 +523,6 @@ WindowData & Gui::findWindowData(WindowReference reference) { bool commandsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { Gui *g = (Gui*)gui; - return g->processCommandEvents(click, event); } @@ -577,7 +622,7 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { if (winID > 0x90) return; if (winID == kSelfWindow || containerOpen) { if (winID == kMainGameWindow) { - warning("Unimplemented: draw main game window"); + drawMainGameWindow(); } else { warning("Unimplemented: fill window with background"); } @@ -618,9 +663,22 @@ WindowReference Gui::createInventoryWindow() { loadBorder(newWindow, "border_self_inac.bmp", false); loadBorder(newWindow, "border_self_act.bmp", true); _inventoryWindows.push_back(newWindow); + + debug(3, "Create new inventory window. Reference: %d", newData.refcon); return newData.refcon; } +bool Gui::tryCloseWindow(WindowReference winID) { + WindowData data = findWindowData(winID); + Graphics::MacWindow *wind; + if (winID < 0x80) { // Inventory window + warning("Window closing not implemented"); + } else { + warning("Window closing not implemented"); + } + return true; +} + bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { @@ -635,7 +693,7 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { Common::List::const_iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { if (it->isInsideBounds(position)) { - debug("Command active: %s", it->getData().title); + debug(4, "Command active: %s", it->getData().title); data = *it; } } @@ -649,26 +707,21 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { } bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & event) { - debug(6, "Processing event in Main Game Window"); return getWindowData(kMainGameWindow).visible; } bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & event) { - debug(6, "Processing event in Out Console Window"); return getWindowData(kOutConsoleWindow).visible; } bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event) { - debug(6, "Processing event in Self Window"); return getWindowData(kSelfWindow).visible; } bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & event) { - debug(6, "Processing event in Exits Window"); return getWindowData(kExitsWindow).visible; } bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & event) { - debug(6, "Processing event in Diploma Window"); return getWindowData(kDiplomaWindow).visible; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index dc08a77cec..8c964aea93 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -27,6 +27,10 @@ #include "graphics/macgui/macwindow.h" #include "graphics/macgui/macmenu.h" +#include "graphics/font.h" + +#include "macventure/image.h" + namespace MacVenture { using namespace Graphics::MacGUIConstants; @@ -138,6 +142,7 @@ public: void updateWindow(WindowReference winID, bool containerOpen); WindowReference createInventoryWindow(); + bool tryCloseWindow(WindowReference winID); // Event processors bool processCommandEvents(WindowClick click, Common::Event &event); @@ -155,6 +160,7 @@ public: // Modifiers void bringToFront(WindowReference window); void setWindowTitle(WindowReference winID, Common::String string); + void updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array &children); // Ugly switches BorderBounds borderBounds(MVWindowType type); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp new file mode 100644 index 0000000000..33f8ce8848 --- /dev/null +++ b/engines/macventure/image.cpp @@ -0,0 +1,256 @@ +/* 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 "macventure/image.h" + +namespace MacVenture { + +PPICHuff PPIC1Huff = { + // Masks + { 0x0000,0x2000,0x4000,0x5000,0x6000,0x7000,0x8000,0x9000,0xa000, + 0xb000,0xc000,0xd000,0xd800,0xe000,0xe800,0xf000,0xf800 }, + // Lens + { 3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5 }, + // Symbols + { 0x00,0x0f,0x03,0x05,0x06,0x07,0x08,0x09,0x0a,0x0c,0xff,0x01, + 0x02,0x04,0x0b,0x0d,0xe } +}; + +PPICHuff PPIC2Huff = { + // Masks + { 0x0000,0x4000,0x8000,0xc000,0xc800,0xd000,0xd800,0xe000,0xe800, + 0xf000,0xf400,0xf600,0xf800,0xfa00,0xfc00,0xfe00,0xff00 }, + // Lens + { 2,2,2,5,5,5,5,5,5,6,7,7,7,7,7,8,8 }, + // Symbols + { 0xff,0x00,0x0f,0x01,0x03,0x07,0x0e,0x0c,0x08,0x06,0x02,0x04, + 0x09,0x0d,0x0b,0x0a,0x05 } +}; + +ImageAsset::ImageAsset(ObjID id, Container * container) { + _id = id; + _container = container; + + decodePPIC(); +} + +ImageAsset::~ImageAsset() { + delete _surface; + delete _mask; + delete[] _data; +} + +void ImageAsset::blit(Graphics::ManagedSurface * target) { + debug("Blitting image %x ", _id); +} + +void ImageAsset::decodePPIC() { + ObjID realID = _id; + uint32 size = _container->getItemByteSize(_id); + if (size == 2 || size == 0) { + realID = _container->getItem(_id)->readUint16BE(); + } + Common::BitStream32BEMSB stream(_container->getItem(realID)); + + uint8 mode = stream.getBits(3); + int w, h; + if (stream.getBit()) h = stream.getBits(10); + else h = stream.getBits(6); + + if (stream.getBit()) w = stream.getBits(10); + else w = stream.getBits(6); + + _rowBytes = ((w + 0xF) >> 3) & 0xFFFE; + _bitWidth = w; + _bitHeight = h; + + _surface = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); + _mask = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); + _data = new byte[_surface->w * _surface->h]; + + switch (mode) + { + case MacVenture::kPPIC0: + decodePPIC0(stream); + break; + case MacVenture::kPPIC1: + decodePPIC1(stream); + break; + case MacVenture::kPPIC2: + decodePPIC2(stream); + break; + case MacVenture::kPPIC3: + decodePPIC3(stream); + break; + } +} + +void ImageAsset::decodePPIC0(Common::BitStream & stream) { + for (uint y = 0; y < _surface->h; y++) + for (uint x = 0; x < _surface->w; x++) + *(byte*)_surface->getBasePtr(x, y) = (byte)stream.getBits(8); +} + +void ImageAsset::decodePPIC1(Common::BitStream & stream) { + decodeHuffGraphic(PPIC1Huff, stream); +} + +void ImageAsset::decodePPIC2(Common::BitStream & stream) { + decodeHuffGraphic(PPIC2Huff, stream); +} + +void ImageAsset::decodePPIC3(Common::BitStream & stream) { + +} + +void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream) { + byte flags = 0; + _walkRepeat = 0; + _walkLast = 0; + if (_bitWidth & 3) + flags = stream.getBits(5); + else + flags = stream.getBits(4) << 1; + + byte odd = 0; + byte blank = _bitWidth & 0xf; + if (blank) { + blank >>= 2; + odd = blank & 1; + blank = 2 - (blank >> 1); + } + + uint pos = 0; + for (uint y = 0; y < _bitHeight; y++) { + uint x = 0; + for (; x < _bitWidth >> 3; x++) { + byte hi = walkHuff(huff, stream) << 4; + _data[pos++] = walkHuff(huff, stream) | hi; + } + if (odd) { + _data[pos] = walkHuff(huff, stream) << 4; + } + pos += blank; + } + uint16 edge = _bitWidth & 3; + uint16 bits = 0; + uint16 val = 0; + uint16 v; + if (edge) { + pos = _rowBytes - blank; + for (uint y = 0; y < _bitHeight; y++) { + if (flags & 1) { + if (bits < edge) { + v = walkHuff(huff, stream) << 4; + val |= v >> bits; + bits += 4; + } + bits -= edge; + v = val; + val <<= edge; + val &= 0xFF; + } else { + v = stream.getBits(edge); + v <<= 8 - edge; + } + if (odd) + v >>= 4; + + _data[pos] |= v & 0xff; + pos += _rowBytes; + } + } + if (flags & 8) { + pos = 0; + for (uint y = 0; y < _bitHeight; y++) { + if (flags & 2) { + for (uint x = 0; x < _rowBytes; x++) + { + _data[pos] ^= v; + v = _data[pos]; + pos++; + } + } + else { + for (uint x = 0; x < _rowBytes; x++) { + val = _data[pos] ^ v; + val ^= (val >> 4) & 0xf; + _data[pos] = val; + pos++; + v = (val << 4) & 0xff; + } + } + } + } + if (flags & 4) { + uint16 delta = _rowBytes * 4; + if (flags & 2) delta *= 2; + pos = 0; + uint q = delta; + for (uint i = 0;i < _surface->h * _rowBytes - delta;i++) { + _data[q] ^= _data[pos]; + q++; + pos++; + } + } +} + +byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { + if (_walkRepeat) { + _walkRepeat--; + _walkLast = ((_walkLast << 8) & 0xFF00) | (_walkLast >> 8); + return _walkLast & 0xFF; + } + uint16 dw = stream.peekBits(16); + uint16 i = 0; + for (;i < 16; i++) { + if (huff.masks[i + 1] > dw) + break; + } + stream.skip(huff.lens[i]); + uint8 val = huff.symbols[i]; + if (val == 0xFF) { + if (!stream.getBit()) { + _walkLast &= 0xFF; + _walkLast |= _walkLast << 8; + } + _walkRepeat = stream.getBits(3); + if (_walkRepeat < 3) { + _walkRepeat <<= 4; + _walkRepeat |= stream.getBits(4); + if (_walkRepeat < 8) { + _walkRepeat <<= 8; + _walkRepeat |= stream.getBits(8); + } + } + _walkRepeat -= 2; + _walkLast = ((_walkLast << 8) & 0xFF00) | (_walkLast >> 8); + return _walkLast & 0xFF; + } else { + _walkLast <<= 8; + _walkLast |= val; + _walkLast &= 0xFFFF; + } + return val; +} + +} // End of namespace MacVenture diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 4cc40f1ed0..847b757788 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -24,26 +24,59 @@ #define MACVENTURE_IMAGE_H #include "macventure/macventure.h" +#include "macventure/container.h" namespace MacVenture { +typedef uint32 ObjID; +class Container; + +enum GraphicsEncoding { + kPPIC0 = 0, + kPPIC1 = 1, + kPPIC2 = 2, + kPPIC3 = 3 +}; + +struct PPICHuff { + uint16 masks[17]; + uint16 lens[17]; + uint8 symbols[17]; +}; + class ImageAsset { public: - ImageAsset(ObjID id, Container *container) { - _id = id; - _container = container; - } - ~ImageAsset() { + ImageAsset(ObjID id, Container *container); + ~ImageAsset(); + + void blit(Graphics::ManagedSurface *target); - } +private: + void decodePPIC(); + + void decodePPIC0(Common::BitStream &stream); + void decodePPIC1(Common::BitStream &stream); + void decodePPIC2(Common::BitStream &stream); + void decodePPIC3(Common::BitStream &stream); - void blit(Graphics::ManagedSurface *target) { - debug("Blitting image %x ", _id); - } + void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream); + byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); private: ObjID _id; Container *_container; + + uint16 _walkRepeat; + uint16 _walkLast; + + uint16 _rowBytes; + uint16 _bitWidth; + uint16 _bitHeight; + + byte* _data; + + Graphics::ManagedSurface *_surface; + Graphics::ManagedSurface *_mask; }; } // End of namespace MacVenture diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 5c8f6b4051..f277d242cf 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -224,6 +224,29 @@ void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, void MacVentureEngine::printTexts() { warning("printTexts: unimplemented"); + for (uint i = 0; i < _textQueue.size(); i++) { + QueuedText text = _textQueue.front(); + _textQueue.remove_at(0); + switch (text.id) { + case kTextNumber: + debug("Print Number: %d", text.asset); + break; + case kTextNewLine: + debug("Print Newline: "); + break; + case kTextPlain: + debug("Print Plain Text: %s", _world->getText(text.asset).c_str()); + break; + } + } +} + +void MacVentureEngine::focusObjWin(ObjID objID) { + _gui->bringToFront(getObjWindow(objID)); +} + +void MacVentureEngine::updateWindow(WindowReference winID) { + _gui->updateWindow(winID, true); } const GlobalSettings& MacVentureEngine::getGlobalSettings() const { @@ -356,8 +379,8 @@ void MacVentureEngine::runObjQueue() { void MacVentureEngine::updateControls() { if (_activeControl) _activeControl = kNoCommand; - toggleExits(); - // resetVars(); + toggleExits(); + resetVars(); } void MacVentureEngine::resetVars() { @@ -378,9 +401,11 @@ void MacVentureEngine::focusObjectWindow(ObjID objID) { } void MacVentureEngine::openObject(ObjID objID) { + + debug("openObject: %d", objID); if (getObjWindow(objID)) return; if (objID == _world->getObjAttr(1, kAttrParentObject)) { - //_gui->setRefcon(objID, kMainGameWindow); // FIXME: Find better name + _gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true)); // FIXME: Find better name _gui->updateWindow(kMainGameWindow, _world->getObjAttr(objID, kAttrContainerOpen)); //_gui->drawExits(); _gui->setWindowTitle(kMainGameWindow, _world->getText(objID)); @@ -390,17 +415,54 @@ void MacVentureEngine::openObject(ObjID objID) { //globalToDesktop(p); WindowReference invID = _gui->createInventoryWindow(); _gui->setWindowTitle(invID, _world->getText(objID)); - //_gui->setRefCon(objID, invID); + _gui->updateWindowInfo(invID, objID, _world->getChildren(objID, true)); _gui->updateWindow(invID, _world->getObjAttr(objID, kAttrContainerOpen)); } } void MacVentureEngine::closeObject(ObjID objID) { - warning("closeObject: unimplemented"); + warning("closeObject: not fully implemented"); + bool success = _gui->tryCloseWindow(getObjWindow(objID)); + return; } void MacVentureEngine::checkObject(ObjID objID) { - warning("checkObject: unimplemented"); + //warning("checkObject: unimplemented"); + bool hasChanged = false; + debug("Check Object[%d] parent[%d] x[%d] y[%d]", + objID, + _world->getObjAttr(objID, kAttrParentObject), + _world->getObjAttr(objID, kAttrPosX), + _world->getObjAttr(objID, kAttrPosY)); + //bool incoming = isIncomingObj(objID); + //if (incoming) removeIncoming(objID); + if (objID == 1) { + if (_world->getObjAttr(objID, kAttrParentObject) != 0) { + enqueueObject(kSetToPlayerParent, objID); + } + } + _gui->updateWindow(findParentWindow(objID), true); + + WindowReference win = getObjWindow(objID); + ObjID parent = objID; + ObjID root = _world->getObjAttr(1, kAttrParentObject); + while (parent != root) { + if (parent == 0 || !_world->getObjAttr(parent, kAttrContainerOpen)) break; + parent = _world->getObjAttr(parent, kAttrParentObject); + } + if (parent == root) { + if (win) return; + enqueueObject(kOpenWindow, objID); + } else { + if (!win) return; + enqueueObject(kCloseWindow, objID); + } + + // Update children + Common::Array children = _world->getChildren(objID, true); + for (uint i = 0; i < children.size(); i++) { + enqueueObject(kUpdateObject, children[i]); + } } void MacVentureEngine::reflectSwap(ObjID objID) { @@ -475,6 +537,10 @@ uint32 MacVentureEngine::getInvolvedObjects() { return (_selectedControl ? _globalSettings.cmdArgCnts[_selectedControl - 1] : 3000); } +Common::Point MacVentureEngine::getObjPosition(ObjID objID) { + return Common::Point(_world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); +} + WindowReference MacVentureEngine::getObjWindow(ObjID objID) { switch (objID) { case 0xfffc: return kExitsWindow; @@ -490,6 +556,12 @@ WindowReference MacVentureEngine::findObjWindow(ObjID objID) { return kMainGameWindow; } +WindowReference MacVentureEngine::findParentWindow(ObjID objID) { + if (objID == 1) return kSelfWindow; + ObjID parent = _world->getObjAttr(objID, kAttrParentObject); + return getObjWindow(parent); +} + Common::Point MacVentureEngine::getDeltaPoint() { return _deltaPoint; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index bb4eec83f5..a23dbecd30 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -177,6 +177,9 @@ public: void runObjQueue(); void printTexts(); + void focusObjWin(ObjID objID); + void updateWindow(WindowReference winID); + // Data retrieval bool isPaused(); Common::String getCommandsPausedString() const; @@ -186,8 +189,12 @@ public: const HuffmanLists *getDecodingHuffman() const; uint32 randBetween(uint32 min, uint32 max); uint32 getInvolvedObjects(); + + Common::Point getObjPosition(ObjID objID); + WindowReference getObjWindow(ObjID objID); WindowReference findObjWindow(ObjID objID); + WindowReference findParentWindow(ObjID objID); Common::Point getDeltaPoint(); ObjID getDestObject(); diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index c0dc818d96..efd5a693be 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -7,6 +7,7 @@ MODULE_OBJS := \ text.o \ world.o \ script.o \ + image.o \ macventure.o MODULE_DIRS += \ diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 715249ca6d..64f94af16d 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -54,14 +54,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(7, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(7, "SCRIPT: Resume"); + debug(3, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -145,13 +145,13 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { } bool ScriptEngine::runFunc(EngineFrame *frame) { - debug(7, "SCRIPT: I'm running the function"); + debug(3, "SCRIPT: I'm running the function"); ScriptAsset &script = frame->scripts.front(); EngineState *state = &frame->state; byte op; while (script.hasNext()) { op = script.fetch(); - debug(8, "SCRIPT: I'm running operation %x", op); + debug(3, "SCRIPT: I'm running operation %x", op); if (!(op & 0x80)) { state->push(op); } else { @@ -1157,7 +1157,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } - debug(7, "SCRIPT: Load %d instructions for script %d", amount, _id); + debug(3, "SCRIPT: Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index c7b103efd7..36e9e21158 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -23,11 +23,15 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); calculateObjectRelations(); - _gameText = new Container("Shadowgate II/Shadow Text"); + warning("Test functions about to happen"); + _gameGraphics = new Container("Shadowgate II/Shadow Graphic"); + _gameText = new Container("Shadowgate II/Shadow Text"); ObjID tid = (ObjID)1; TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); + ImageAsset testImg(((428 * 2) + 1), _gameGraphics); + delete saveGameRes; saveGameFile.close(); } @@ -140,9 +144,9 @@ void World::updateObj(ObjID objID) { win = _engine->getObjWindow(objID); } if (win) { - //focusObjWin(objID); + _engine->focusObjWin(objID); _engine->runObjQueue(); - //_engine->updateWindow(win); + _engine->updateWindow(win); } } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index fe45508623..8afa75c83c 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -122,8 +122,10 @@ private: Common::String _startGameFileName; SaveGame *_saveGame; + Container *_objectConstants; Container *_gameText; + Container *_gameGraphics; Common::Array _relations; // Parent-child relations, stored in Williams Heap format }; -- cgit v1.2.3 From 1cee6caf13fdc44cacd50c7382bb7e967589f683 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 21 Jun 2016 11:10:37 +0200 Subject: MACVENTURE: Test PPIC1 and 2 decoding --- engines/macventure/image.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 33f8ce8848..c1fb7d0ef6 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -151,12 +151,13 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st } pos += blank; } - uint16 edge = _bitWidth & 3; - uint16 bits = 0; - uint16 val = 0; - uint16 v; + + uint16 edge = _bitWidth & 3; if (edge) { pos = _rowBytes - blank; + uint16 bits = 0; + uint16 val = 0; + uint16 v; for (uint y = 0; y < _bitHeight; y++) { if (flags & 1) { if (bits < edge) { @@ -182,6 +183,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (flags & 8) { pos = 0; for (uint y = 0; y < _bitHeight; y++) { + uint16 v = 0; if (flags & 2) { for (uint x = 0; x < _rowBytes; x++) { @@ -192,7 +194,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st } else { for (uint x = 0; x < _rowBytes; x++) { - val = _data[pos] ^ v; + uint16 val = _data[pos] ^ v; val ^= (val >> 4) & 0xf; _data[pos] = val; pos++; -- cgit v1.2.3 From 15de1a2e604be9f6c6eb4100cf656deef1afe028 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 21 Jun 2016 13:22:56 +0200 Subject: MACVENTURE: Add graphics blitting --- engines/macventure/gui.cpp | 10 ++- engines/macventure/gui.h | 4 ++ engines/macventure/image.cpp | 154 ++++++++++++++++++++++++++++++++----------- engines/macventure/image.h | 33 ++++++---- engines/macventure/world.cpp | 5 +- engines/macventure/world.h | 1 - 6 files changed, 149 insertions(+), 58 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 725ce38268..77e28bac4e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -177,6 +177,8 @@ void Gui::initGUI() { _menu->setCommandsCallback(menuCommandsCallback, this); _menu->calcDimensions(); + loadGraphics(); + if (!loadWindows()) error("Could not load windows"); @@ -275,6 +277,10 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool } } +void Gui::loadGraphics() { + _graphics = new Container("Shadowgate II/Shadow Graphic"); +} + bool Gui::loadMenus() { // We assume that, if there are static menus, we don't need dynamic ones @@ -488,7 +494,9 @@ void Gui::drawMainGameWindow() { 5, 5), kColorBlack); - } + } + ImageAsset testImg(428, _graphics); + testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC); } void Gui::drawSelfWindow() { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 8c964aea93..3236d3bdb2 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -29,6 +29,7 @@ #include "graphics/font.h" +#include "macventure/container.h" #include "macventure/image.h" namespace MacVenture { @@ -185,6 +186,8 @@ private: // Attributes Common::Array _inventoryWindows; Graphics::Menu *_menu; + Container *_graphics; + private: // Methods @@ -197,6 +200,7 @@ private: // Methods bool loadWindows(); bool loadControls(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + void loadGraphics(); // Drawers void drawWindows(); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index c1fb7d0ef6..4a3064ded6 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -46,28 +46,32 @@ PPICHuff PPIC2Huff = { 0x09,0x0d,0x0b,0x0a,0x05 } }; -ImageAsset::ImageAsset(ObjID id, Container * container) { - _id = id; - _container = container; +ImageAsset::ImageAsset(ObjID original, Container * container) { + _id = (original * 2); + _mask = (original * 2) + 1; - decodePPIC(); + _container = container; + + //_imgData = nullptr; + //_maskData = nullptr; + + decodePPIC(_id, _imgData); + decodePPIC(_mask, _maskData); } ImageAsset::~ImageAsset() { - delete _surface; - delete _mask; - delete[] _data; -} + //if (_imgData) + // delete[] _imgData; -void ImageAsset::blit(Graphics::ManagedSurface * target) { - debug("Blitting image %x ", _id); + //if (_maskData) + // delete[] _maskData; } -void ImageAsset::decodePPIC() { - ObjID realID = _id; - uint32 size = _container->getItemByteSize(_id); +void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { + ObjID realID = id; + uint32 size = _container->getItemByteSize(id); if (size == 2 || size == 0) { - realID = _container->getItem(_id)->readUint16BE(); + realID = _container->getItem(id)->readUint16BE(); } Common::BitStream32BEMSB stream(_container->getItem(realID)); @@ -83,46 +87,48 @@ void ImageAsset::decodePPIC() { _bitWidth = w; _bitHeight = h; - _surface = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); - _mask = new Graphics::ManagedSurface(_rowBytes, h, Graphics::PixelFormat::createFormatCLUT8()); - _data = new byte[_surface->w * _surface->h]; + for (uint i = 0; i < _rowBytes * h; i++) { + data.push_back(0); + } switch (mode) { case MacVenture::kPPIC0: - decodePPIC0(stream); + decodePPIC0(stream, data); break; case MacVenture::kPPIC1: - decodePPIC1(stream); + decodePPIC1(stream, data); break; case MacVenture::kPPIC2: - decodePPIC2(stream); + decodePPIC2(stream, data); break; case MacVenture::kPPIC3: - decodePPIC3(stream); + decodePPIC3(stream, data); break; } } -void ImageAsset::decodePPIC0(Common::BitStream & stream) { - for (uint y = 0; y < _surface->h; y++) - for (uint x = 0; x < _surface->w; x++) - *(byte*)_surface->getBasePtr(x, y) = (byte)stream.getBits(8); +void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &data) { + warning("Untested loading function: decode PPIC0"); + uint words = _bitWidth >> 4; + for (uint y = 0; y <_bitHeight; y++) + for (uint x = 0; x < words; x++) + data[y * words + x] = (byte)stream.getBits(8); } -void ImageAsset::decodePPIC1(Common::BitStream & stream) { - decodeHuffGraphic(PPIC1Huff, stream); +void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array &data) { + decodeHuffGraphic(PPIC1Huff, stream, data); } -void ImageAsset::decodePPIC2(Common::BitStream & stream) { - decodeHuffGraphic(PPIC2Huff, stream); +void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array &data) { + decodeHuffGraphic(PPIC2Huff, stream, data); } -void ImageAsset::decodePPIC3(Common::BitStream & stream) { +void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &data) { } -void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream) { +void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream, Common::Array &data) { byte flags = 0; _walkRepeat = 0; _walkLast = 0; @@ -144,10 +150,10 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st uint x = 0; for (; x < _bitWidth >> 3; x++) { byte hi = walkHuff(huff, stream) << 4; - _data[pos++] = walkHuff(huff, stream) | hi; + data[pos++] = walkHuff(huff, stream) | hi; } if (odd) { - _data[pos] = walkHuff(huff, stream) << 4; + data[pos] = walkHuff(huff, stream) << 4; } pos += blank; } @@ -176,7 +182,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (odd) v >>= 4; - _data[pos] |= v & 0xff; + data[pos] |= v & 0xff; pos += _rowBytes; } } @@ -187,16 +193,16 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (flags & 2) { for (uint x = 0; x < _rowBytes; x++) { - _data[pos] ^= v; - v = _data[pos]; + data[pos] ^= v; + v = data[pos]; pos++; } } else { for (uint x = 0; x < _rowBytes; x++) { - uint16 val = _data[pos] ^ v; + uint16 val = data[pos] ^ v; val ^= (val >> 4) & 0xf; - _data[pos] = val; + data[pos] = val; pos++; v = (val << 4) & 0xff; } @@ -208,8 +214,8 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (flags & 2) delta *= 2; pos = 0; uint q = delta; - for (uint i = 0;i < _surface->h * _rowBytes - delta;i++) { - _data[q] ^= _data[pos]; + for (uint i = 0;i < _bitHeight * _rowBytes - delta;i++) { + data[q] ^= data[pos]; q++; pos++; } @@ -255,4 +261,72 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { return val; } +void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { + debug("Blitting image %x ", _id); + if (_container->getItemByteSize(_mask)) { // Has mask + switch (mode) { + case MacVenture::kBlitBIC: + blitBIC(target, x, y, _maskData); + break; + case MacVenture::kBlitOR: + blitOR(target, x, y, _maskData); + break; + } + } + else if (_container->getItemByteSize(_id)) { + switch (mode) { + case MacVenture::kBlitBIC: + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorWhite); + break; + case MacVenture::kBlitOR: + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorBlack); + break; + } + } + if (_container->getItemByteSize(_id) && mode > 0) { + blitXOR(target, x, y, _maskData); + } +} + +void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + for (uint y = 0;y < _bitHeight; y++) { + uint bmpofs = y * _rowBytes; + byte pix = 0; + for (uint x = 0; x < _bitWidth; x++) { + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + + if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; + } + } +} + +void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + for (uint y = 0;y < _bitHeight; y++) { + uint bmpofs = y * _rowBytes; + byte pix = 0; + for (uint x = 0; x < _bitWidth; x++) { + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + + if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorBlack; + } + } +} + +void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + for (uint y = 0;y < _bitHeight; y++) { + uint bmpofs = y * _rowBytes; + byte pix = 0; + for (uint x = 0; x < _bitWidth; x++) { + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + + if (pix) { // We need to xor + byte p = *((byte *)target->getBasePtr(ox + x, oy + y)); + if (p == kColorWhite) p = kColorBlack; + else p = kColorWhite; + *((byte *)target->getBasePtr(ox + x, oy + y)) = p; + } + } + } +} + } // End of namespace MacVenture diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 847b757788..f7ecab354c 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -44,26 +44,37 @@ struct PPICHuff { uint8 symbols[17]; }; +enum BlitMode { + kBlitBIC = 1, + kBlitOR = 2, + kBlitXOR = 3 +}; + class ImageAsset { public: - ImageAsset(ObjID id, Container *container); + ImageAsset(ObjID original, Container *container); ~ImageAsset(); - void blit(Graphics::ManagedSurface *target); + void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode); private: - void decodePPIC(); + void decodePPIC(ObjID id, Common::Array &data); - void decodePPIC0(Common::BitStream &stream); - void decodePPIC1(Common::BitStream &stream); - void decodePPIC2(Common::BitStream &stream); - void decodePPIC3(Common::BitStream &stream); + void decodePPIC0(Common::BitStream &stream, Common::Array &data); + void decodePPIC1(Common::BitStream &stream, Common::Array &data); + void decodePPIC2(Common::BitStream &stream, Common::Array &data); + void decodePPIC3(Common::BitStream &stream, Common::Array &data); - void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream); + void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array &data); byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); + void blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); + void blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); + void blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); + private: ObjID _id; + ObjID _mask; Container *_container; uint16 _walkRepeat; @@ -73,10 +84,8 @@ private: uint16 _bitWidth; uint16 _bitHeight; - byte* _data; - - Graphics::ManagedSurface *_surface; - Graphics::ManagedSurface *_mask; + Common::Array _imgData; + Common::Array _maskData; }; } // End of namespace MacVenture diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 36e9e21158..7a93773386 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -24,14 +24,11 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { calculateObjectRelations(); warning("Test functions about to happen"); - _gameGraphics = new Container("Shadowgate II/Shadow Graphic"); _gameText = new Container("Shadowgate II/Shadow Text"); ObjID tid = (ObjID)1; TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); - - ImageAsset testImg(((428 * 2) + 1), _gameGraphics); - + delete saveGameRes; saveGameFile.close(); } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index 8afa75c83c..f42dd3a816 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -125,7 +125,6 @@ private: Container *_objectConstants; Container *_gameText; - Container *_gameGraphics; Common::Array _relations; // Parent-child relations, stored in Williams Heap format }; -- cgit v1.2.3 From 27ecdea89169bf9fd2a1c0870a17c93592ff299e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 21 Jun 2016 19:17:38 +0200 Subject: MACVENTURE: Add & test PPIC3 Huffman loading --- engines/macventure/gui.cpp | 13 ++++++- engines/macventure/gui.h | 1 + engines/macventure/image.cpp | 71 +++++++++++++++++++++++++++++++++++++++ engines/macventure/image.h | 2 ++ engines/macventure/macventure.cpp | 1 + 5 files changed, 87 insertions(+), 1 deletion(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 77e28bac4e..f0dd82d43e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -92,12 +92,18 @@ void Gui::draw() { drawWindows(); _wm.draw(); + + drawTitle(); } void Gui::drawMenu() { _menu->draw(&_screen); } +void Gui::drawTitle() { + warning("drawTitle hasn't been tested yet"); +} + bool Gui::processEvent(Common::Event &event) { bool processed = false; if (event.type == Common::EVENT_LBUTTONDOWN) { @@ -494,7 +500,12 @@ void Gui::drawMainGameWindow() { 5, 5), kColorBlack); - } + } + + // Tests + ImageAsset testBg(3, _graphics); + testBg.blitInto(srf, border.leftOffset * 2, border.topOffset * 2, kBlitDirect); + ImageAsset testImg(428, _graphics); testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 3236d3bdb2..404c18e808 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -138,6 +138,7 @@ public: void draw(); void drawMenu(); + void drawTitle(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); void updateWindow(WindowReference winID, bool containerOpen); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 4a3064ded6..960c18dfc4 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -46,6 +46,20 @@ PPICHuff PPIC2Huff = { 0x09,0x0d,0x0b,0x0a,0x05 } }; +// Used to load the huffman table in PPIC3 decoding +byte loadBits[] = { + 0x08, 0x0f, 0x02, 0xff, 0x00, + 0x04, 0xff, 0x01, + 0x07, 0x09, 0x08, 0xff, 0x03, + 0x04, 0xff, 0x04, + 0x0a, 0x07, 0x0a, 0x0b, 0x06, 0xff, 0x05, + 0x06, 0x06, 0x0b, 0xff, 0x07, + 0x03, 0xff, 0x09, + 0x04, 0x03, 0x0e, 0xff, 0x0c, + 0x02, 0xff, 0x0d, + 0x01, 0xff, 0x0f, + 0xff }; + ImageAsset::ImageAsset(ObjID original, Container * container) { _id = (original * 2); _mask = (original * 2) + 1; @@ -125,7 +139,47 @@ void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array &da } void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &data) { + // We need to load the huffman from the PPIC itself + PPICHuff huff; + uint16 v, bits; + uint16 load = 0; + while ((bits = loadBits[load++]) != 0xFF) { + v = stream.getBits(bits); + while ((bits = loadBits[load++]) != 0xFF) { + huff.symbols[loadBits[load++]] = v % bits; + v = (v / bits) | 0; + } + huff.symbols[loadBits[load++]] = v; + } + huff.symbols[0x10] = 0; + for (uint i = 0x10; i > 0; i--) + for (uint j = i; j <= 0x10; j++) + if (huff.symbols[j] >= huff.symbols[i - 1]) + huff.symbols[j]++; + + for (uint i = 0x10; i >= 0; i--) { + if (huff.symbols[i] == 0x10) { + huff.symbols[i] = 0xff; + break; + } + } + + bits = stream.getBits(2) + 1; + uint16 mask = 0; + for (uint i = 0; i < 0xf; i++) { + if (i) + while (!stream.getBit()) bits++; + huff.lens[i] = bits; + huff.masks[i] = mask; + mask += 1 << (16 - bits); + } + huff.masks[0xf] = mask; + while (mask&(1 << (16 - bits))) bits++; + huff.masks[0x10] = mask | (1 << (16 - bits)); + huff.lens[0xf] = bits; + huff.lens[0x10] = bits; + decodeHuffGraphic(huff, stream, data); } void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream, Common::Array &data) { @@ -263,6 +317,10 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { debug("Blitting image %x ", _id); + if (mode == kBlitDirect) { + blitDirect(target, x, y, _imgData); + } + if (_container->getItemByteSize(_mask)) { // Has mask switch (mode) { case MacVenture::kBlitBIC: @@ -288,6 +346,19 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, } } +void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { + for (uint y = 0;y < _bitHeight; y++) { + uint bmpofs = y * _rowBytes; + byte pix = 0; + for (uint x = 0; x < _bitWidth; x++) { + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + + pix = pix ? kColorWhite : kColorBlack; + *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; + } + } +} + void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { for (uint y = 0;y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; diff --git a/engines/macventure/image.h b/engines/macventure/image.h index f7ecab354c..21e544a76e 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -45,6 +45,7 @@ struct PPICHuff { }; enum BlitMode { + kBlitDirect = 0, kBlitBIC = 1, kBlitOR = 2, kBlitXOR = 3 @@ -68,6 +69,7 @@ private: void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array &data); byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); + void blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); void blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); void blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); void blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index f277d242cf..e68f7d2b7a 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -76,6 +76,7 @@ Common::Error MacVentureEngine::run() { // Additional setup. debug("MacVentureEngine::init"); + _resourceManager = new Common::MacResManager(); if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); -- cgit v1.2.3 From 4d8f8fd36bdb9b1f807f4da04c9e3e4c3438dbfa Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 21 Jun 2016 20:30:41 +0200 Subject: MACVENTURE: Complete ppic blitting --- engines/macventure/gui.cpp | 15 ++++----------- engines/macventure/image.cpp | 9 +++++---- engines/macventure/macventure.cpp | 3 ++- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index f0dd82d43e..90d57aafc2 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -480,15 +480,7 @@ void Gui::drawMainGameWindow() { border.topOffset * 2, srf->w - (border.rightOffset * 3), srf->h - (border.bottomOffset * 3)), - kColorWhite); - getCurrentFont().drawString( - srf, - Common::String("Main Game Window"), - 0, - (srf->h / 2) - getCurrentFont().getFontHeight(), - srf->w, - kColorBlack, - Graphics::kTextAlignCenter); + kColorBlack); WindowData &data = findWindowData(kMainGameWindow); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { @@ -506,8 +498,9 @@ void Gui::drawMainGameWindow() { ImageAsset testBg(3, _graphics); testBg.blitInto(srf, border.leftOffset * 2, border.topOffset * 2, kBlitDirect); - ImageAsset testImg(428, _graphics); - testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC); + //ImageAsset testImg(428, _graphics); + //testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC); + } void Gui::drawSelfWindow() { diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 960c18dfc4..46d440c957 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -70,7 +70,9 @@ ImageAsset::ImageAsset(ObjID original, Container * container) { //_maskData = nullptr; decodePPIC(_id, _imgData); - decodePPIC(_mask, _maskData); + + if (_container->getItemByteSize(_mask)) // Has mask + decodePPIC(_mask, _maskData); } ImageAsset::~ImageAsset() { @@ -352,9 +354,8 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 byte pix = 0; for (uint x = 0; x < _bitWidth; x++) { pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); - - pix = pix ? kColorWhite : kColorBlack; - *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; + pix = pix ? kColorBlack : kColorWhite; + if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; } } } diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index e68f7d2b7a..9bdb99d12f 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -132,9 +132,10 @@ Common::Error MacVentureEngine::run() { if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { endGame(); } + + _gui->draw(); } - _gui->draw(); g_system->updateScreen(); g_system->delayMillis(50); } -- cgit v1.2.3 From 0743e9531b5ef871e17cd7ca88966ea2c07b7147 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 22 Jun 2016 00:47:53 +0200 Subject: MACVENTURE: Implemente dynamic object drawing --- engines/macventure/gui.cpp | 108 +++++++++++++++++++++++++----------- engines/macventure/gui.h | 25 ++++++++- engines/macventure/image.cpp | 4 +- engines/macventure/image.h | 15 ++--- engines/macventure/macventure.cpp | 113 +++++++++++++++++++++++++++----------- engines/macventure/macventure.h | 11 +++- engines/macventure/module.mk | 2 +- engines/macventure/world.cpp | 2 +- 8 files changed, 199 insertions(+), 81 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 90d57aafc2..e202b82d3e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -86,6 +86,16 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { Gui::~Gui() { + if (_windowData) + delete _windowData; + + if (_controlData) + delete _controlData; + + Common::HashMap::const_iterator it = _assets.begin(); + for (; it != _assets.end(); it++) { + delete it->_value; + } } void Gui::draw() { @@ -104,6 +114,10 @@ void Gui::drawTitle() { warning("drawTitle hasn't been tested yet"); } +void Gui::drawExit(ObjID id) { + warning("Unimplemented method: drawExit"); +} + bool Gui::processEvent(Common::Event &event) { bool processed = false; if (event.type == Common::EVENT_LBUTTONDOWN) { @@ -164,7 +178,7 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array originx = originx > childPos.x ? childPos.x : originx; originy = originy > childPos.y ? childPos.y : originy; } - data.children.push_back(child); + data.children.push_back(DrawableObject(child, kBlitDirect)); } } if (originx != 0x7fff) data.bounds.left = originx; @@ -172,6 +186,20 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array if (ref != kMainGameWindow) data.updateScroll = true; } +void Gui::addChild(WindowReference target, ObjID child) { + findWindowData(target).children.push_back(DrawableObject(child, kBlitDirect)); +} + +void Gui::removeChild(WindowReference target, ObjID child) { + WindowData data = findWindowData(target); + uint index = 0; + for (;index < data.children.size(); index++) { + if (data.children[index].obj == child) break; + } + + data.children.remove_at(index); +} + void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); @@ -230,6 +258,7 @@ void Gui::initWindows() { _selfWindow->setCallback(selfWindowCallback, this); loadBorder(_selfWindow, "border_self_inac.bmp", false); loadBorder(_selfWindow, "border_self_act.bmp", true); + findWindowData(kSelfWindow).children.push_back(DrawableObject(1, kBlitDirect)); // Exits Window _exitsWindow = _wm.addWindow(false, true, true); @@ -443,7 +472,6 @@ void Gui::drawWindows() { drawCommandsWindow(); drawMainGameWindow(); - drawSelfWindow(); } void Gui::drawCommandsWindow() { @@ -460,8 +488,7 @@ void Gui::drawCommandsWindow() { data.bounds.right - data.bounds.left, kColorBlack, Graphics::kTextAlignCenter); - } - else { + } else { Common::List::const_iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { CommandButton button = *it; @@ -474,32 +501,15 @@ void Gui::drawCommandsWindow() { void Gui::drawMainGameWindow() { Graphics::ManagedSurface *srf = _mainGameWindow->getSurface(); BorderBounds border = borderBounds(getWindowData(kMainGameWindow).type); - srf->fillRect( - Common::Rect( - border.leftOffset * 2, - border.topOffset * 2, - srf->w - (border.rightOffset * 3), - srf->h - (border.bottomOffset * 3)), - kColorBlack); - - WindowData &data = findWindowData(kMainGameWindow); - for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { - Common::Point pos = _engine->getObjPosition(*it); - srf->fillRect( - Common::Rect( - border.leftOffset * 2 + pos.x, - border.topOffset * 2 + pos.y, - 5, - 5), - kColorBlack); - } - // Tests - ImageAsset testBg(3, _graphics); - testBg.blitInto(srf, border.leftOffset * 2, border.topOffset * 2, kBlitDirect); + ImageAsset bg(3, _graphics); + bg.blitInto( + _mainGameWindow->getSurface(), + border.leftOffset * 2, + border.topOffset * 2, + kBlitDirect); - //ImageAsset testImg(428, _graphics); - //testImg.blitInto(srf, border.leftOffset * 2 + 10,border.topOffset * 2 + 10, kBlitBIC); + drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); } @@ -515,6 +525,27 @@ void Gui::drawSelfWindow() { kColorWhite); } +void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { + WindowData &data = findWindowData(kMainGameWindow); + BorderBounds border = borderBounds(data.type); + Common::Point pos; + ObjID child; + BlitMode mode; + for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { + child = (*it).obj; + mode = (BlitMode)(*it).mode; + pos = _engine->getObjPosition(child); + if (!_assets.contains(child)) { + _assets[child] = new ImageAsset(child, _graphics); + } + _assets[child]->blitInto( + surface, + border.leftOffset * 2 + pos.x, + border.topOffset * 2 + pos.y, + mode); + } +} + WindowData & Gui::findWindowData(WindowReference reference) { assert(_windowData); @@ -631,7 +662,7 @@ void Gui::handleMenuAction(MenuAction action) { } void Gui::updateWindow(WindowReference winID, bool containerOpen) { - if (winID > 0x90) return; + if (winID > 0x90 || winID == kNoWindow) return; if (winID == kSelfWindow || containerOpen) { if (winID == kMainGameWindow) { drawMainGameWindow(); @@ -639,9 +670,21 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { warning("Unimplemented: fill window with background"); } WindowData &data = findWindowData(winID); - Common::Array children = data.children; - for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { - warning("Unimplemented: draw object %x", *it); + Common::Array &children = data.children; + for (uint i = 0; i < children.size(); i++) { + uint flag = 0; + ObjID child = children[i].obj; + BlitMode mode; + bool off = _engine->isObjVisible(child); + if (!off || _engine->isObjClickable(child)) { + mode = kBlitBIC; + if (_engine->isObjSelected(child)) { + mode = kBlitOR; + } else if (off || flag) { + mode = kBlitXOR; + } + children[i] = DrawableObject(child, mode); + } } if (data.type == kZoomDoc && data.updateScroll) { warning("Unimplemented: update scroll"); @@ -682,7 +725,6 @@ WindowReference Gui::createInventoryWindow() { bool Gui::tryCloseWindow(WindowReference winID) { WindowData data = findWindowData(winID); - Graphics::MacWindow *wind; if (winID < 0x80) { // Inventory window warning("Window closing not implemented"); } else { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 404c18e808..2e8b6e20a2 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -39,7 +39,9 @@ using namespace Graphics::MacWindowConstants; class MacVentureEngine; typedef uint32 ObjID; -//namespace MacVentureMenuActions { +class CommandButton; +class ImageAsset; + enum MenuAction { kMenuActionAbout, kMenuActionNew, @@ -60,6 +62,7 @@ enum MenuAction { //} using namespace MacVentureMenuActions; enum WindowReference { + kNoWindow = 0, kCommandsWindow = 0x80, kMainGameWindow = 0x81, kOutConsoleWindow = 0x82, @@ -83,6 +86,16 @@ enum MVWindowType { kRDoc10 = 0x16 }; + +struct DrawableObject { + ObjID obj; + byte mode; + DrawableObject(ObjID id, byte md) { + obj = id; + mode = md; + } +}; + struct WindowData { Common::Rect bounds; MVWindowType type; @@ -91,7 +104,7 @@ struct WindowData { WindowReference refcon; uint8 titleLength; Common::String title; - Common::Array children; + Common::Array children; bool updateScroll; }; @@ -139,6 +152,7 @@ public: void draw(); void drawMenu(); void drawTitle(); + void drawExit(ObjID id); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); void updateWindow(WindowReference winID, bool containerOpen); @@ -164,6 +178,9 @@ public: void setWindowTitle(WindowReference winID, Common::String string); void updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array &children); + void addChild(WindowReference target, ObjID child); + void removeChild(WindowReference target, ObjID child); + // Ugly switches BorderBounds borderBounds(MVWindowType type); @@ -188,10 +205,10 @@ private: // Attributes Graphics::Menu *_menu; Container *_graphics; + Common::HashMap _assets; private: // Methods - // Initializers void initGUI(); void initWindows(); @@ -209,6 +226,8 @@ private: // Methods void drawMainGameWindow(); void drawSelfWindow(); + void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface); + // Finders WindowData& findWindowData(WindowReference reference); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 46d440c957..47b755a829 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -318,9 +318,9 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { } void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { - debug("Blitting image %x ", _id); if (mode == kBlitDirect) { blitDirect(target, x, y, _imgData); + return; } if (_container->getItemByteSize(_mask)) { // Has mask @@ -344,7 +344,7 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, } } if (_container->getItemByteSize(_id) && mode > 0) { - blitXOR(target, x, y, _maskData); + blitXOR(target, x, y, _imgData); } } diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 21e544a76e..eb52da83ad 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -31,6 +31,14 @@ namespace MacVenture { typedef uint32 ObjID; class Container; + +enum BlitMode { + kBlitDirect = 0, + kBlitBIC = 1, + kBlitOR = 2, + kBlitXOR = 3 +}; + enum GraphicsEncoding { kPPIC0 = 0, kPPIC1 = 1, @@ -44,13 +52,6 @@ struct PPICHuff { uint8 symbols[17]; }; -enum BlitMode { - kBlitDirect = 0, - kBlitBIC = 1, - kBlitOR = 2, - kBlitXOR = 3 -}; - class ImageAsset { public: ImageAsset(ObjID original, Container *container); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 9bdb99d12f..87b5d51327 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -115,13 +115,15 @@ Common::Error MacVentureEngine::run() { if (_prepared) { _prepared = false; + if (!_halted) + updateState(); + if (_cmdReady || _halted) { _halted = false; if (runScriptEngine()) { _halted = true; _paused = true; - } - else { + } else { _paused = false; if (!updateState()) { updateControls(); @@ -131,10 +133,9 @@ Common::Error MacVentureEngine::run() { if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { endGame(); - } - - _gui->draw(); + } } + _gui->draw(); g_system->updateScreen(); g_system->delayMillis(50); @@ -210,7 +211,7 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID) { obj.exitx = _world->getObjAttr(objID, kAttrExitX); obj.exity = _world->getObjAttr(objID, kAttrExitY); obj.hidden = _world->getObjAttr(objID, kAttrHiddenExit); - obj.offsecreen = _world->getObjAttr(objID, kAttrInvisible); + obj.offscreen = _world->getObjAttr(objID, kAttrInvisible); obj.invisible = _world->getObjAttr(objID, kAttrUnclickable); _objQueue.push_back(obj); } @@ -224,7 +225,7 @@ void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, _textQueue.push_back(newText); } -void MacVentureEngine::printTexts() { +bool MacVentureEngine::printTexts() { warning("printTexts: unimplemented"); for (uint i = 0; i < _textQueue.size(); i++) { QueuedText text = _textQueue.front(); @@ -232,12 +233,15 @@ void MacVentureEngine::printTexts() { switch (text.id) { case kTextNumber: debug("Print Number: %d", text.asset); + gameChanged(); break; case kTextNewLine: debug("Print Newline: "); + gameChanged(); break; case kTextPlain: debug("Print Plain Text: %s", _world->getText(text.asset).c_str()); + gameChanged(); break; } } @@ -326,7 +330,8 @@ void MacVentureEngine::endGame() { bool MacVentureEngine::updateState() { runObjQueue(); - return true; + bool wait = printTexts(); + return wait; } void MacVentureEngine::revert() { @@ -359,7 +364,7 @@ void MacVentureEngine::runObjQueue() { closeObject(obj.object); break; case 0x7: - checkObject(obj.object); + checkObject(obj); break; case 0x8: reflectSwap(obj.object); @@ -428,40 +433,68 @@ void MacVentureEngine::closeObject(ObjID objID) { return; } -void MacVentureEngine::checkObject(ObjID objID) { +void MacVentureEngine::checkObject(QueuedObject old) { //warning("checkObject: unimplemented"); bool hasChanged = false; debug("Check Object[%d] parent[%d] x[%d] y[%d]", - objID, - _world->getObjAttr(objID, kAttrParentObject), - _world->getObjAttr(objID, kAttrPosX), - _world->getObjAttr(objID, kAttrPosY)); + old.object, + _world->getObjAttr(old.object, kAttrParentObject), + _world->getObjAttr(old.object, kAttrPosX), + _world->getObjAttr(old.object, kAttrPosY)); //bool incoming = isIncomingObj(objID); //if (incoming) removeIncoming(objID); - if (objID == 1) { - if (_world->getObjAttr(objID, kAttrParentObject) != 0) { - enqueueObject(kSetToPlayerParent, objID); - } - } - _gui->updateWindow(findParentWindow(objID), true); - - WindowReference win = getObjWindow(objID); - ObjID parent = objID; + ObjID id = old.object; + if (id == 1) { + if (old.parent != _world->getObjAttr(id, kAttrParentObject)) { + enqueueObject(kSetToPlayerParent, id); + } + if (old.offscreen != _world->getObjAttr(id, kAttrInvisible) || + old.invisible != _world->getObjAttr(id, kAttrUnclickable)) { + updateWindow(findParentWindow(id)); + } + } else if (old.parent != _world->getObjAttr(id, kAttrParentObject) || + old.x != _world->getObjAttr(id, kAttrPosX) || + old.y != _world->getObjAttr(id, kAttrPosY)) { + WindowReference oldWin = getObjWindow(old.parent); + if (oldWin) { + _gui->removeChild(oldWin, id); + hasChanged = true; + } + + WindowReference newWin = getObjWindow(id); + if (newWin) { + _gui->addChild(newWin, id); + hasChanged = true; + } + } else if (old.offscreen != _world->getObjAttr(id, kAttrInvisible) || + old.invisible != _world->getObjAttr(id, kAttrUnclickable)) { + updateWindow(findParentWindow(id)); + } + + if (_world->getObjAttr(id, kAttrIsExit)) { + if (hasChanged || + old.hidden != _world->getObjAttr(id, kAttrHiddenExit) || + old.exitx != _world->getObjAttr(id, kAttrExitX) || + old.exity != _world->getObjAttr(id, kAttrExitY)) + _gui->drawExit(id); + } + WindowReference win = getObjWindow(id); + ObjID cur = id; ObjID root = _world->getObjAttr(1, kAttrParentObject); - while (parent != root) { - if (parent == 0 || !_world->getObjAttr(parent, kAttrContainerOpen)) break; - parent = _world->getObjAttr(parent, kAttrParentObject); + while (cur != root) { + if (cur == 0 || !_world->getObjAttr(cur, kAttrContainerOpen)) break; + cur = _world->getObjAttr(cur, kAttrParentObject); } - if (parent == root) { + if (cur == root) { if (win) return; - enqueueObject(kOpenWindow, objID); + enqueueObject(kOpenWindow, id); //open } else { if (!win) return; - enqueueObject(kCloseWindow, objID); + enqueueObject(kCloseWindow, id); //close } // Update children - Common::Array children = _world->getChildren(objID, true); + Common::Array children = _world->getChildren(id, true); for (uint i = 0; i < children.size(); i++) { enqueueObject(kUpdateObject, children[i]); } @@ -543,6 +576,19 @@ Common::Point MacVentureEngine::getObjPosition(ObjID objID) { return Common::Point(_world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); } +bool MacVentureEngine::isObjVisible(ObjID objID) { + return _world->getObjAttr(objID, kAttrInvisible) == 0; +} + +bool MacVentureEngine::isObjClickable(ObjID objID) { + return _world->getObjAttr(objID, kAttrUnclickable) == 0; +} + +bool MacVentureEngine::isObjSelected(ObjID objID) { + warning("Unimplemented: isObjSelected"); + return false; +} + WindowReference MacVentureEngine::getObjWindow(ObjID objID) { switch (objID) { case 0xfffc: return kExitsWindow; @@ -555,7 +601,12 @@ WindowReference MacVentureEngine::getObjWindow(ObjID objID) { } WindowReference MacVentureEngine::findObjWindow(ObjID objID) { - return kMainGameWindow; + // This is a bit of a hack, we take advantage of the consecutive nature of references + for (uint i = kCommandsWindow; i <= kDiplomaWindow; i++) { + const WindowData &data = _gui->getWindowData((WindowReference)i); + if (data.refcon == objID) { return data.refcon; } + } + return kNoWindow; } WindowReference MacVentureEngine::findParentWindow(ObjID objID) { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index a23dbecd30..7e6f362a8c 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -133,7 +133,7 @@ struct QueuedObject { uint exitx; uint exity; bool hidden; - bool offsecreen; + bool offscreen; bool invisible; }; @@ -175,7 +175,7 @@ public: void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text); void runObjQueue(); - void printTexts(); + bool printTexts(); void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); @@ -190,7 +190,11 @@ public: uint32 randBetween(uint32 min, uint32 max); uint32 getInvolvedObjects(); + // Attributes consult Common::Point getObjPosition(ObjID objID); + bool isObjVisible(ObjID objID); + bool isObjClickable(ObjID objID); + bool isObjSelected(ObjID objID); WindowReference getObjWindow(ObjID objID); WindowReference findObjWindow(ObjID objID); @@ -212,7 +216,7 @@ private: void focusObjectWindow(ObjID objID); void openObject(ObjID objID); void closeObject(ObjID objID); - void checkObject(ObjID objID); + void checkObject(QueuedObject objID); void reflectSwap(ObjID objID); void toggleExits(); void zoomObject(ObjID objID); @@ -252,6 +256,7 @@ private: // Attributes bool _gameChanged; Common::Array _objQueue; + Common::Array _inQueue; Common::Array _soundQueue; Common::Array _textQueue; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index efd5a693be..022b8d7c32 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -1,13 +1,13 @@ MODULE := engines/macventure MODULE_OBJS := \ + image.o \ detection.o \ gui.o \ object.o \ text.o \ world.o \ script.o \ - image.o \ macventure.o MODULE_DIRS += \ diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 7a93773386..2ee7bae92f 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -122,7 +122,7 @@ Common::Array World::getChildren(ObjID objID, bool recursive) { res.push_back(getChildren(child, false)); child = _relations[child * 2 + 1]; } - return Common::Array(); + return res; } Attribute World::getGlobal(uint32 attrID) { -- cgit v1.2.3 From 1540674f7720f520bdb585999e24ceb653c9bda3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 22 Jun 2016 21:48:14 +0200 Subject: MACVENTURE: Fix dymanic object drawing --- engines/macventure/gui.cpp | 49 ++++++++++++++++++++++--------------- engines/macventure/image.cpp | 58 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 26 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index e202b82d3e..5c1747cb18 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -26,6 +26,9 @@ #include "macventure/macventure.h" #include "macventure/gui.h" +//Test +#include "common/system.h" + namespace MacVenture { enum MenuAction; @@ -99,11 +102,12 @@ Gui::~Gui() { } void Gui::draw() { - drawWindows(); - _wm.draw(); + drawWindows(); drawTitle(); + + _wm.draw(); } void Gui::drawMenu() { @@ -178,7 +182,7 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array originx = originx > childPos.x ? childPos.x : originx; originy = originy > childPos.y ? childPos.y : originy; } - data.children.push_back(DrawableObject(child, kBlitDirect)); + data.children.push_back(DrawableObject(child, kBlitBIC)); } } if (originx != 0x7fff) data.bounds.left = originx; @@ -187,7 +191,7 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array } void Gui::addChild(WindowReference target, ObjID child) { - findWindowData(target).children.push_back(DrawableObject(child, kBlitDirect)); + findWindowData(target).children.push_back(DrawableObject(child, kBlitBIC)); } void Gui::removeChild(WindowReference target, ObjID child) { @@ -502,8 +506,11 @@ void Gui::drawMainGameWindow() { Graphics::ManagedSurface *srf = _mainGameWindow->getSurface(); BorderBounds border = borderBounds(getWindowData(kMainGameWindow).type); - ImageAsset bg(3, _graphics); - bg.blitInto( + if (!_assets.contains(3)) { + _assets[3] = new ImageAsset(3, _graphics); + } + + _assets[3]->blitInto( _mainGameWindow->getSurface(), border.leftOffset * 2, border.topOffset * 2, @@ -511,18 +518,16 @@ void Gui::drawMainGameWindow() { drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); + // To be deleted + _wm.draw(); + + g_system->updateScreen(); + } void Gui::drawSelfWindow() { Graphics::ManagedSurface *srf = _selfWindow->getSurface(); BorderBounds border = borderBounds(getWindowData(kSelfWindow).type); - srf->fillRect( - Common::Rect( - border.leftOffset * 2, - border.topOffset * 2, - srf->w - (border.rightOffset * 3), - srf->h - (border.bottomOffset * 3)), - kColorWhite); } void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { @@ -543,6 +548,12 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * border.leftOffset * 2 + pos.x, border.topOffset * 2 + pos.y, mode); + + // To be deleted + _wm.draw(); + + g_system->updateScreen(); + } } @@ -674,14 +685,14 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { for (uint i = 0; i < children.size(); i++) { uint flag = 0; ObjID child = children[i].obj; - BlitMode mode; - bool off = _engine->isObjVisible(child); - if (!off || _engine->isObjClickable(child)) { + BlitMode mode = kBlitDirect; + bool off = !_engine->isObjVisible(child); + if (flag || !off || !_engine->isObjClickable(child)) { mode = kBlitBIC; - if (_engine->isObjSelected(child)) { - mode = kBlitOR; - } else if (off || flag) { + if (off || flag) { mode = kBlitXOR; + } else if (_engine->isObjSelected(child)) { + mode = kBlitOR; } children[i] = DrawableObject(child, mode); } diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 47b755a829..60f491cf55 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -332,8 +332,7 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, blitOR(target, x, y, _maskData); break; } - } - else if (_container->getItemByteSize(_id)) { + } else if (_container->getItemByteSize(_id)) { switch (mode) { case MacVenture::kBlitBIC: target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorWhite); @@ -343,12 +342,24 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, break; } } + if (_container->getItemByteSize(_id) && mode > 0) { blitXOR(target, x, y, _imgData); } } void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { + if (_bitWidth == 0 || _bitHeight == 0) return; + uint w = _bitWidth; + uint h = _bitHeight; + uint sx = 0; + uint sy = 0; + if (ox<0) { sx = -ox; ox = 0; } + if (oy<0) { sy = -oy; oy = 0; } + if (w + ox >= target->w) w = target->w - ox; + if (h + oy >= target->h) h = target->h - oy; + if (w == 0 || h == 0) return; + for (uint y = 0;y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; @@ -361,10 +372,21 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 } void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { - for (uint y = 0;y < _bitHeight; y++) { + if (_bitWidth == 0 || _bitHeight == 0) return; + uint w = _bitWidth; + uint h = _bitHeight; + uint sx = 0; + uint sy = 0; + if (ox<0) { sx = -ox; ox = 0; } + if (oy<0) { sy = -oy; oy = 0; } + if (w + ox >= target->w) w = target->w - ox; + if (h + oy >= target->h) h = target->h - oy; + if (w == 0 || h == 0) return; + + for (uint y = 0;y < h; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; - for (uint x = 0; x < _bitWidth; x++) { + for (uint x = 0; x < w; x++) { pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; @@ -373,6 +395,17 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy } void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + if (_bitWidth == 0 || _bitHeight == 0) return; + uint w = _bitWidth; + uint h = _bitHeight; + uint sx = 0; + uint sy = 0; + if (ox<0) { sx = -ox; ox = 0; } + if (oy<0) { sy = -oy; oy = 0; } + if (w + ox >= target->w) w = target->w - ox; + if (h + oy >= target->h) h = target->h - oy; + if (w == 0 || h == 0) return; + for (uint y = 0;y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; @@ -385,6 +418,17 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, } void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + if (_bitWidth == 0 || _bitHeight == 0) return; + uint w = _bitWidth; + uint h = _bitHeight; + uint sx = 0; + uint sy = 0; + if (ox<0) { sx = -ox; ox = 0; } + if (oy<0) { sy = -oy; oy = 0; } + if (w + ox >= target->w) w = target->w - ox; + if (h + oy >= target->h) h = target->h - oy; + if (w == 0 || h == 0) return; + for (uint y = 0;y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; @@ -393,9 +437,9 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy if (pix) { // We need to xor byte p = *((byte *)target->getBasePtr(ox + x, oy + y)); - if (p == kColorWhite) p = kColorBlack; - else p = kColorWhite; - *((byte *)target->getBasePtr(ox + x, oy + y)) = p; + + *((byte *)target->getBasePtr(ox + x, oy + y)) = + (p == kColorWhite) ? kColorBlack : kColorWhite; } } } -- cgit v1.2.3 From 0fb344dfeda53e81a70e89be45bda6d5c0614e7e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 22 Jun 2016 22:09:10 +0200 Subject: MACVENTURE: Hack for dynamic object drawing --- engines/macventure/gui.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 5c1747cb18..1ac1d0b0f8 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -26,9 +26,6 @@ #include "macventure/macventure.h" #include "macventure/gui.h" -//Test -#include "common/system.h" - namespace MacVenture { enum MenuAction; @@ -103,8 +100,10 @@ Gui::~Gui() { void Gui::draw() { - drawWindows(); + // Will be performance-improved after the milestone + _wm.setFullRefresh(true); + drawWindows(); drawTitle(); _wm.draw(); @@ -225,7 +224,6 @@ void Gui::initGUI() { if (!loadControls()) error("Could not load controls"); - draw(); } @@ -506,6 +504,8 @@ void Gui::drawMainGameWindow() { Graphics::ManagedSurface *srf = _mainGameWindow->getSurface(); BorderBounds border = borderBounds(getWindowData(kMainGameWindow).type); + _mainGameWindow->setDirty(true); + if (!_assets.contains(3)) { _assets[3] = new ImageAsset(3, _graphics); } @@ -518,11 +518,6 @@ void Gui::drawMainGameWindow() { drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); - // To be deleted - _wm.draw(); - - g_system->updateScreen(); - } void Gui::drawSelfWindow() { @@ -549,11 +544,8 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * border.topOffset * 2 + pos.y, mode); - // To be deleted + // To be deleted, this is a big hack, but it doesn't work without it. _wm.draw(); - - g_system->updateScreen(); - } } -- cgit v1.2.3 From ec7eb7cb5bec5174f7fd3446824280ab44050f5e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 23 Jun 2016 00:24:39 +0200 Subject: MACVENTURE: Game window object selection and some more opcodes --- engines/macventure/gui.cpp | 36 +++++++++++++++++++++++---------- engines/macventure/image.cpp | 14 +++++-------- engines/macventure/image.h | 2 ++ engines/macventure/macventure.cpp | 42 +++++++++++++++++++++++++++++---------- engines/macventure/macventure.h | 4 +++- engines/macventure/script.cpp | 21 ++++++++++++-------- 6 files changed, 81 insertions(+), 38 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 1ac1d0b0f8..f1eb8b63e6 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -104,7 +104,6 @@ void Gui::draw() { _wm.setFullRefresh(true); drawWindows(); - drawTitle(); _wm.draw(); } @@ -121,14 +120,6 @@ void Gui::drawExit(ObjID id) { warning("Unimplemented method: drawExit"); } -bool Gui::processEvent(Common::Event &event) { - bool processed = false; - if (event.type == Common::EVENT_LBUTTONDOWN) { - debug("Click on the ui"); - } - return (processed || _wm.processEvent(event)); -} - const WindowData& Gui::getWindowData(WindowReference reference) { return findWindowData(reference); } @@ -736,6 +727,13 @@ bool Gui::tryCloseWindow(WindowReference winID) { return true; } +bool Gui::processEvent(Common::Event &event) { + bool processed = false; + if (event.type == Common::EVENT_LBUTTONDOWN) { + debug("Click on the ui"); + } + return (processed || _wm.processEvent(event)); +} bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { @@ -764,7 +762,25 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { } bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & event) { - return getWindowData(kMainGameWindow).visible; + if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) { + WindowData &data = findWindowData(kMainGameWindow); + ObjID child; + BlitMode mode; + Common::Point pos; + for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { + child = (*it).obj; + mode = (BlitMode)(*it).mode; + pos = _engine->getObjPosition(child); + pos.x += data.bounds.left; + pos.y += data.bounds.top; + if (_assets[child]->isPointInside(pos, event.mouse)) { + // select the first object clicked + _engine->selectObject(child); + return true; + } + } + } + return false; } bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & event) { return getWindowData(kOutConsoleWindow).visible; diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 60f491cf55..de4e3ba12e 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -65,10 +65,6 @@ ImageAsset::ImageAsset(ObjID original, Container * container) { _mask = (original * 2) + 1; _container = container; - - //_imgData = nullptr; - //_maskData = nullptr; - decodePPIC(_id, _imgData); if (_container->getItemByteSize(_mask)) // Has mask @@ -76,11 +72,6 @@ ImageAsset::ImageAsset(ObjID original, Container * container) { } ImageAsset::~ImageAsset() { - //if (_imgData) - // delete[] _imgData; - - //if (_maskData) - // delete[] _maskData; } void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { @@ -348,6 +339,11 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, } } +bool ImageAsset::isPointInside(Common::Point myPos, Common::Point click) { + Common::Rect bounds(myPos.x, myPos.y, myPos.x + _bitWidth, myPos.y + _bitHeight); + return bounds.contains(click); +} + void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { if (_bitWidth == 0 || _bitHeight == 0) return; uint w = _bitWidth; diff --git a/engines/macventure/image.h b/engines/macventure/image.h index eb52da83ad..0a3ea50ef1 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -59,6 +59,8 @@ public: void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode); + bool isPointInside(Common::Point myPos, Common::Point click); + private: void decodePPIC(ObjID id, Common::Array &data); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 87b5d51327..8d367c7174 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -204,15 +204,17 @@ void MacVentureEngine::loseGame() { void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID) { QueuedObject obj; obj.id = type; - obj.object = objID; - obj.parent = _world->getObjAttr(objID, kAttrParentObject); - obj.x = _world->getObjAttr(objID, kAttrPosX); - obj.y = _world->getObjAttr(objID, kAttrPosY); - obj.exitx = _world->getObjAttr(objID, kAttrExitX); - obj.exity = _world->getObjAttr(objID, kAttrExitY); - obj.hidden = _world->getObjAttr(objID, kAttrHiddenExit); - obj.offscreen = _world->getObjAttr(objID, kAttrInvisible); - obj.invisible = _world->getObjAttr(objID, kAttrUnclickable); + if (type != kHightlightExits) { + obj.object = objID; + obj.parent = _world->getObjAttr(objID, kAttrParentObject); + obj.x = _world->getObjAttr(objID, kAttrPosX); + obj.y = _world->getObjAttr(objID, kAttrPosY); + obj.exitx = _world->getObjAttr(objID, kAttrExitX); + obj.exity = _world->getObjAttr(objID, kAttrExitY); + obj.hidden = _world->getObjAttr(objID, kAttrHiddenExit); + obj.offscreen = _world->getObjAttr(objID, kAttrInvisible); + obj.invisible = _world->getObjAttr(objID, kAttrUnclickable); + } _objQueue.push_back(obj); } @@ -247,6 +249,26 @@ bool MacVentureEngine::printTexts() { } } +void MacVentureEngine::selectObject(ObjID objID) { + bool found = false; + uint i = 0; + while (i < _currentSelection.size() && !found) { + if (_currentSelection[i] == objID) found = true; + else i++; + } + + if (!found) _currentSelection.push_back(objID); + + found = false; + i = 0; + while (i < _selectedObjs.size() && !found) { + if (_selectedObjs[i] == objID) found = true; + else i++; + } + + if (!found) _selectedObjs.push_back(objID); +} + void MacVentureEngine::focusObjWin(ObjID objID) { _gui->bringToFront(getObjWindow(objID)); } @@ -301,7 +323,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { while (!_currentSelection.empty()) { ObjID obj = _currentSelection.front(); - _currentSelection.pop_front(); + _currentSelection.remove_at(0); if ((_gameState == kGameStateInit || _gameState == kGameStatePlaying) && _world->isObjActive(obj)) { if (_scriptEngine->runControl(_selectedControl, obj, _destObject, _deltaPoint)) { _haltedInSelection = true; diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 7e6f362a8c..c45069c06c 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -177,6 +177,7 @@ public: void runObjQueue(); bool printTexts(); + void selectObject(ObjID objID); void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); @@ -264,7 +265,8 @@ private: // Attributes ObjID _destObject; ControlAction _selectedControl; ControlAction _activeControl; - Common::List _currentSelection; + Common::Array _currentSelection; + Common::Array _selectedObjs; Common::Point _deltaPoint; }; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 64f94af16d..f7550360c8 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -905,15 +905,22 @@ void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { - op00NOOP(0xbe); + ObjID from = state->pop(); + ObjID to = state->pop(); + _engine->enqueueObject(kUpdateWindow, to); + _world->setObjAttr(to, kAttrContainerOpen, _world->getObjAttr(from, 6)); + _world->setObjAttr(from, kAttrContainerOpen, 0); + Common::Array children = _world->getChildren(from, true); + for (uint i = 0; i < children.size(); i++) + _world->setObjAttr(children[i], 0, to); } void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { - op00NOOP(0xbf); + _engine->enqueueObject(kAnimateBack, frame->src); } void ScriptEngine::opc0TEXI(EngineState * state, EngineFrame * frame) { - op00NOOP(0xc0); + _engine->enqueueObject(kHightlightExits, 0); } void ScriptEngine::opc1PTXT(EngineState * state, EngineFrame * frame) { @@ -1049,9 +1056,8 @@ void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { - //_engine->updateScreen(false); - //clickToContinue(); - op00NOOP(0xda); + _engine->updateState(); + //_engine->clickToContinue(); } void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { @@ -1067,8 +1073,7 @@ void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { - //_engine->updateScreen(false); - op00NOOP(0xde); + _engine->updateState(); } void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From ba5ed7fc88a69da782f3df18698837a67a59eb6b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 23 Jun 2016 23:21:24 +0200 Subject: MACVENTURE: Major push in functionality and rendering --- engines/macventure/gui.cpp | 401 +++++++++++++++++++++++++------------- engines/macventure/gui.h | 30 ++- engines/macventure/image.cpp | 84 ++++---- engines/macventure/image.h | 2 +- engines/macventure/macventure.cpp | 132 +++++++++---- engines/macventure/macventure.h | 9 +- engines/macventure/script.cpp | 55 +++--- 7 files changed, 478 insertions(+), 235 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index f1eb8b63e6..d4fd337557 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -106,6 +106,8 @@ void Gui::draw() { drawWindows(); _wm.draw(); + + //drawWindowTitle(kMainGameWindow, _mainGameWindow->getSurface()); } void Gui::drawMenu() { @@ -117,7 +119,17 @@ void Gui::drawTitle() { } void Gui::drawExit(ObjID id) { - warning("Unimplemented method: drawExit"); + findWindowData(kExitsWindow).children.push_back(DrawableObject(id, kBlitDirect)); +} + +void Gui::clearControls() { + if (!_controlData) + return; + + Common::List::iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + it->unselect(); + } } const WindowData& Gui::getWindowData(WindowReference reference) { @@ -234,44 +246,65 @@ void Gui::initWindows() { _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); - loadBorder(_mainGameWindow, "border_command.bmp", false); - loadBorder(_mainGameWindow, "border_command.bmp", true); + loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - loadBorder(_outConsoleWindow, "border_command.bmp", false); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); // Self Window _selfWindow = _wm.addWindow(false, true, true); _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - loadBorder(_selfWindow, "border_self_inac.bmp", false); - loadBorder(_selfWindow, "border_self_act.bmp", true); - findWindowData(kSelfWindow).children.push_back(DrawableObject(1, kBlitDirect)); + loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); // Exits Window _exitsWindow = _wm.addWindow(false, true, true); _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); - loadBorder(_exitsWindow, "border_title_inac.bmp", false); - loadBorder(_exitsWindow, "border_title_inac.bmp", true); + loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); + +} + +WindowReference Gui::createInventoryWindow() { + Graphics::MacWindow *newWindow = _wm.addWindow(true, true, true); + WindowData newData; + GlobalSettings settings = _engine->getGlobalSettings(); + newData.refcon = (WindowReference)ABS(_inventoryWindows.size()); // This is a hack + + if (_windowData->back().refcon < 0x80) { // There is already another inventory window + newData.bounds = _windowData->back().bounds; // Inventory windows are always last + newData.bounds.translate(newData.bounds.left + settings.invOffsetX, newData.bounds.top + settings.invOffsetY); + } + else { + newData.bounds = Common::Rect( + settings.invLeft, + settings.invTop, + settings.invLeft + settings.invWidth, + settings.invTop + settings.invHeight); + } + newData.type = kZoomDoc; + newData.hasCloseBox = true; + newData.visible = true; + _windowData->push_back(newData); - // Diploma Window (we can go without it for now) - /* - _diplomaWindow = _wm.addWindow(false, true, true); - _diplomaWindow->setDimensions(getWindowData(kDiplomaWindow).bounds); - _diplomaWindow->setActive(false); - _diplomaWindow->setCallback(diplomaWindowCallback, this); - loadBorder(_diplomaWindow, "border_command.bmp", false); - // Render invisible for now - _diplomaWindow->getSurface()->fillRect(_diplomaWindow->getSurface()->getBounds(), kColorGreen2); - */ + newWindow->setDimensions(newData.bounds); + newWindow->setCallback(inventoryWindowCallback, this); + loadBorder(newWindow, "border_no_scroll_inac.bmp", false); + loadBorder(newWindow, "border_no_scroll_act.bmp", true); + _inventoryWindows.push_back(newWindow); + debug("Create new inventory window. Reference: %d", newData.refcon); + return newData.refcon; } void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { @@ -464,11 +497,14 @@ void Gui::drawWindows() { drawCommandsWindow(); drawMainGameWindow(); + drawSelfWindow(); + drawInventories(); + drawExitsWindow(); } void Gui::drawCommandsWindow() { - if (_engine->isPaused()) { + if (_engine->needsClickToContinue()) { Graphics::ManagedSurface *srf = _controlsWindow->getSurface(); WindowData data = getWindowData(kCommandsWindow); uint16 border = borderBounds(data.type).topOffset; @@ -493,51 +529,113 @@ void Gui::drawCommandsWindow() { void Gui::drawMainGameWindow() { Graphics::ManagedSurface *srf = _mainGameWindow->getSurface(); - BorderBounds border = borderBounds(getWindowData(kMainGameWindow).type); + const WindowData &data = getWindowData(kMainGameWindow); + BorderBounds border = borderBounds(data.type); _mainGameWindow->setDirty(true); + //if (data.titleLength > 0) + // drawWindowTitle(kMainGameWindow, srf); + if (!_assets.contains(3)) { _assets[3] = new ImageAsset(3, _graphics); } _assets[3]->blitInto( _mainGameWindow->getSurface(), - border.leftOffset * 2, - border.topOffset * 2, + border.leftOffset, + border.topOffset, kBlitDirect); drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); - } void Gui::drawSelfWindow() { - Graphics::ManagedSurface *srf = _selfWindow->getSurface(); - BorderBounds border = borderBounds(getWindowData(kSelfWindow).type); + drawObjectsInWindow(kSelfWindow, _selfWindow->getSurface()); + if (_engine->isObjSelected(1)) invertWindowColors(kSelfWindow); +} + +void Gui::drawInventories() { + Common::List::const_iterator it = _windowData->begin(); + while (it != _windowData->end() && (*it).refcon >= 0x80) { + it++; + } + Graphics::ManagedSurface *srf; + while (it != _windowData->end()) { + srf = _inventoryWindows[(*it).refcon]->getSurface(); + BorderBounds border = borderBounds((*it).type); + srf->fillRect(Common::Rect( + border.leftOffset, + border.topOffset, + srf->w + border.rightOffset, + srf->h + border.bottomOffset), kColorWhite); + drawObjectsInWindow((*it).refcon, _inventoryWindows[(*it).refcon]->getSurface()); + it++; + } +} + +void Gui::drawExitsWindow() { + WindowData &data = findWindowData(kExitsWindow); + BorderBounds border = borderBounds(data.type); + Graphics::ManagedSurface *srf = _exitsWindow->getSurface(); + srf->fillRect(Common::Rect( + border.leftOffset, + border.topOffset, + srf->w + border.rightOffset, + srf->h + border.bottomOffset), kColorWhite); + + drawObjectsInWindow(kExitsWindow, _exitsWindow->getSurface()); } void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { - WindowData &data = findWindowData(kMainGameWindow); + WindowData &data = findWindowData(target); BorderBounds border = borderBounds(data.type); Common::Point pos; ObjID child; BlitMode mode; - for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { - child = (*it).obj; - mode = (BlitMode)(*it).mode; + + if (data.children.size() == 0) return; + + Common::Point forbidden(0, 0); + for (uint i = 0; i < data.children.size(); i++) { + child = data.children[i].obj; + mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); - if (!_assets.contains(child)) { - _assets[child] = new ImageAsset(child, _graphics); + + if (pos != forbidden || child < 600) { // Small HACK until I figre out where the last garbage child in main game window comes from + if (!_assets.contains(child)) { + _assets[child] = new ImageAsset(child, _graphics); + } + + _assets[child]->blitInto( + surface, + border.leftOffset + pos.x, + border.topOffset + pos.y, + mode); } - _assets[child]->blitInto( - surface, - border.leftOffset * 2 + pos.x, - border.topOffset * 2 + pos.y, - mode); - - // To be deleted, this is a big hack, but it doesn't work without it. - _wm.draw(); + } + + findWindow(data.refcon)->setDirty(true); + +} + +void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { + WindowData &data = findWindowData(target); + BorderBounds border = borderBounds(data.type); + + uint left = 10;//getCurrentFont().getStringWidth(data.title) - 10; + uint right = 30;//getCurrentFont().getStringWidth(data.title) + 10; + + surface->fillRect(Common::Rect(left, 0, right, border.topOffset - 1), kColorGray); + getCurrentFont().drawString( + surface, + data.title, + 0, + right, + right - left, + kColorBlack, + Graphics::kTextAlignCenter); } WindowData & Gui::findWindowData(WindowReference reference) { @@ -554,56 +652,29 @@ WindowData & Gui::findWindowData(WindowReference reference) { error("Could not locate the desired window data"); } - -/* CALLBACKS */ - -bool commandsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - Gui *g = (Gui*)gui; - - return g->processCommandEvents(click, event); -} - -bool mainGameWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - Gui *g = (Gui*)gui; - - return g->processMainGameEvents(click, event); -} - -bool outConsoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - Gui *g = (Gui*)gui; - - return g->processOutConsoleEvents(click, event); -} - -bool selfWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - Gui *g = (Gui*)gui; - - return g->processSelfEvents(click, event); -} - -bool exitsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - Gui *g = (Gui*)gui; - - return g->processExitsEvents(click, event); -} - -bool diplomaWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - Gui *g = (Gui*)gui; - - return g->processDiplomaEvents(click, event); -} - -bool inventoryWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { - Gui *g = (Gui*)gui; - - return g->processInventoryEvents(click, event); +Graphics::MacWindow * Gui::findWindow(WindowReference reference) { + if (reference < 0x80) { // It's an inventory window + return _inventoryWindows[reference]; + } + switch (reference) { + case MacVenture::kNoWindow: + return nullptr; + case MacVenture::kCommandsWindow: + return _controlsWindow; + case MacVenture::kMainGameWindow: + return _mainGameWindow; + case MacVenture::kOutConsoleWindow: + return _outConsoleWindow; + case MacVenture::kSelfWindow: + return _selfWindow; + case MacVenture::kExitsWindow: + return _exitsWindow; + case MacVenture::kDiplomaWindow: + return _diplomaWindow; + } + return nullptr; } -void menuCommandsCallback(int action, Common::String &text, void *data) { - Gui *g = (Gui *)data; - - g->handleMenuAction((MenuAction)action); -} /* HANDLERS */ void Gui::handleMenuAction(MenuAction action) { @@ -655,15 +726,66 @@ void Gui::handleMenuAction(MenuAction action) { } } +/* CALLBACKS */ + +bool commandsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + return g->processCommandEvents(click, event); +} + +bool mainGameWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + return g->processMainGameEvents(click, event); +} + +bool outConsoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + return g->processOutConsoleEvents(click, event); +} + +bool selfWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return g->processSelfEvents(click, event); +} + +bool exitsWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return g->processExitsEvents(click, event); +} + +bool diplomaWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return g->processDiplomaEvents(click, event); +} + +bool inventoryWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui) { + Gui *g = (Gui*)gui; + + return g->processInventoryEvents(click, event); +} + +void menuCommandsCallback(int action, Common::String &text, void *data) { + Gui *g = (Gui *)data; + + g->handleMenuAction((MenuAction)action); +} + void Gui::updateWindow(WindowReference winID, bool containerOpen) { - if (winID > 0x90 || winID == kNoWindow) return; + if (winID == kNoWindow) return; if (winID == kSelfWindow || containerOpen) { - if (winID == kMainGameWindow) { - drawMainGameWindow(); + WindowData &data = findWindowData(winID); + if (winID == kCommandsWindow) { + Common::List::iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + it->unselect(); + } } else { - warning("Unimplemented: fill window with background"); + Graphics::MacWindow *winRef = findWindow(winID); + winRef->getSurface()->fillRect(data.bounds, kColorGray); } - WindowData &data = findWindowData(winID); Common::Array &children = data.children; for (uint i = 0; i < children.size(); i++) { uint flag = 0; @@ -680,41 +802,24 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { children[i] = DrawableObject(child, mode); } } + if (winID == kMainGameWindow) { + drawMainGameWindow(); + } if (data.type == kZoomDoc && data.updateScroll) { warning("Unimplemented: update scroll"); } } } -WindowReference Gui::createInventoryWindow() { - Graphics::MacWindow *newWindow = _wm.addWindow(true, true, true); - WindowData newData; - GlobalSettings settings = _engine->getGlobalSettings(); - newData.refcon = (WindowReference)ABS(_inventoryWindows.size()); // This is a hack - - if (_windowData->back().refcon < 0x80) { // There is already another inventory window - newData.bounds = _windowData->back().bounds; // Inventory windows are always last - newData.bounds.translate(newData.bounds.left + settings.invOffsetX, newData.bounds.top + settings.invOffsetY); - } else { - newData.bounds = Common::Rect( - settings.invLeft, - settings.invTop, - settings.invLeft + settings.invWidth, - settings.invTop + settings.invHeight); +void Gui::invertWindowColors(WindowReference winID) { + Graphics::ManagedSurface *srf = findWindow(winID)->getSurface(); + for (uint y = 0; y < srf->h; y++) { + for (uint x = 0; x < srf->w; x++) { + byte p = *(byte *)srf->getBasePtr(x, y); + *(byte *)srf->getBasePtr(x, y) = + (p == kColorWhite) ? kColorBlack : kColorGray; + } } - newData.type = kZoomDoc; - newData.hasCloseBox = true; - newData.visible = true; - _windowData->push_back(newData); - - newWindow->setDimensions(newData.bounds); - newWindow->setCallback(inventoryWindowCallback, this); - loadBorder(newWindow, "border_self_inac.bmp", false); - loadBorder(newWindow, "border_self_act.bmp", true); - _inventoryWindows.push_back(newWindow); - - debug(3, "Create new inventory window. Reference: %d", newData.refcon); - return newData.refcon; } bool Gui::tryCloseWindow(WindowReference winID) { @@ -729,30 +834,41 @@ bool Gui::tryCloseWindow(WindowReference winID) { bool Gui::processEvent(Common::Event &event) { bool processed = false; - if (event.type == Common::EVENT_LBUTTONDOWN) { - debug("Click on the ui"); + if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP) { + _engine->updateDelta(event.mouse); + processed = true; } - return (processed || _wm.processEvent(event)); + processed |= _wm.processEvent(event); + return (processed); } bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { - if (_engine->isPaused()) + if (_engine->needsClickToContinue()) { + _engine->activateCommand(kControlClickToContinue); return true; + } Common::Point position( event.mouse.x - _controlsWindow->getDimensions().left, event.mouse.y - _controlsWindow->getDimensions().top); CommandButton data; - Common::List::const_iterator it = _controlData->begin(); + if (!_controlData) + return false; + + Common::List::iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { if (it->isInsideBounds(position)) { - debug(4, "Command active: %s", it->getData().title); + it->select(); data = *it; } + else { + it->unselect(); + } } + _engine->selectControl((ControlReference)data.getData().refcon); _engine->activateCommand((ControlReference)data.getData().refcon); _engine->refreshReady(); @@ -762,6 +878,9 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { } bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & event) { + if (_engine->needsClickToContinue()) + return true; + if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) { WindowData &data = findWindowData(kMainGameWindow); ObjID child; @@ -769,36 +888,52 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e Common::Point pos; for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; - mode = (BlitMode)(*it).mode; pos = _engine->getObjPosition(child); - pos.x += data.bounds.left; - pos.y += data.bounds.top; - if (_assets[child]->isPointInside(pos, event.mouse)) { + pos.x += _mainGameWindow->getDimensions().left; + pos.y += _mainGameWindow->getDimensions().top; + pos = event.mouse - pos; + if (_assets.contains(child) && _assets[child]->isPointInside(pos)) { // select the first object clicked _engine->selectObject(child); - return true; } } } return false; } bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & event) { + if (_engine->needsClickToContinue()) + return true; + return getWindowData(kOutConsoleWindow).visible; } bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event) { - return getWindowData(kSelfWindow).visible; + if (_engine->needsClickToContinue()) + return true; + + if (event.type == Common::EVENT_LBUTTONUP) { + _engine->selectObject(1); + } + return true; } bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & event) { + if (_engine->needsClickToContinue()) + return true; return getWindowData(kExitsWindow).visible; } bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & event) { + if (_engine->needsClickToContinue()) + return true; + return getWindowData(kDiplomaWindow).visible; } bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { + if (_engine->needsClickToContinue()) + return true; + return false; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 2e8b6e20a2..b7d5d52b83 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -117,7 +117,8 @@ enum ControlReference { kControlOperate = 5, kControlGo = 6, kControlHit = 7, - kControlConsume = 8 + kControlConsume = 8, + kControlClickToContinue = 9 }; struct ControlData { @@ -153,9 +154,11 @@ public: void drawMenu(); void drawTitle(); void drawExit(ObjID id); + void clearControls(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); void updateWindow(WindowReference winID, bool containerOpen); + void invertWindowColors(WindowReference winID); WindowReference createInventoryWindow(); bool tryCloseWindow(WindowReference winID); @@ -225,11 +228,15 @@ private: // Methods void drawCommandsWindow(); void drawMainGameWindow(); void drawSelfWindow(); + void drawInventories(); + void drawExitsWindow(); void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface); + void drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface); // Finders WindowData& findWindowData(WindowReference reference); + Graphics::MacWindow *findWindow(WindowReference reference); }; @@ -249,12 +256,16 @@ public: CommandButton(ControlData data, Gui *g) { _data = data; _gui = g; + _selected = false; } ~CommandButton() {} void draw(Graphics::ManagedSurface &surface) const { - surface.fillRect(_data.bounds, kColorWhite); + uint colorFill = _selected ? kColorBlack : kColorWhite; + uint colorText = _selected ? kColorWhite : kColorBlack; + + surface.fillRect(_data.bounds, colorFill); surface.frameRect(_data.bounds, kColorBlack); const Graphics::Font &font = _gui->getCurrentFont(); @@ -265,7 +276,7 @@ public: _data.bounds.left, _data.bounds.top, _data.bounds.right - _data.bounds.left, - kColorBlack, + colorText, Graphics::kTextAlignCenter); } @@ -277,7 +288,20 @@ public: return _data; } + void select() { + _selected = true; + } + + void unselect() { + _selected = false; + } + + bool isSelected() { + return _selected; + } + private: + bool _selected; ControlData _data; Gui *_gui; }; diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index de4e3ba12e..54d19c9fd2 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -311,40 +311,47 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { if (mode == kBlitDirect) { blitDirect(target, x, y, _imgData); - return; - } - - if (_container->getItemByteSize(_mask)) { // Has mask - switch (mode) { - case MacVenture::kBlitBIC: - blitBIC(target, x, y, _maskData); - break; - case MacVenture::kBlitOR: - blitOR(target, x, y, _maskData); - break; - } - } else if (_container->getItemByteSize(_id)) { - switch (mode) { - case MacVenture::kBlitBIC: - target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorWhite); - break; - case MacVenture::kBlitOR: - target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorBlack); - break; + } else if (mode < kBlitXOR){ + if (_container->getItemByteSize(_mask)) { // Has mask + switch (mode) { + case MacVenture::kBlitBIC: + blitBIC(target, x, y, _maskData); + break; + case MacVenture::kBlitOR: + blitOR(target, x, y, _maskData); + break; + default: + break; + } + } else if (_container->getItemByteSize(_id)) { + switch (mode) { + case MacVenture::kBlitBIC: + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorWhite); + break; + case MacVenture::kBlitOR: + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorBlack); + break; + default: + break; + } } - } - if (_container->getItemByteSize(_id) && mode > 0) { - blitXOR(target, x, y, _imgData); - } + if (_container->getItemByteSize(_id) && mode > 0) { + blitXOR(target, x, y, _imgData); + } + } } -bool ImageAsset::isPointInside(Common::Point myPos, Common::Point click) { - Common::Rect bounds(myPos.x, myPos.y, myPos.x + _bitWidth, myPos.y + _bitHeight); - return bounds.contains(click); +bool ImageAsset::isPointInside(Common::Point point) { + if (point.x >= _bitWidth || point.y >= _bitHeight) return false; + if (_maskData.empty()) return false; + // We see if the point lands on the mask. + uint pix = _maskData[(point.y * _rowBytes) + (point.x >> 3)] & (1 << (7 - (point.x & 7))); + return pix != 0; } void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { + /* if (_bitWidth == 0 || _bitHeight == 0) return; uint w = _bitWidth; uint h = _bitHeight; @@ -355,19 +362,21 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; + */ - for (uint y = 0;y < _bitHeight; y++) { + for (uint y = 0; y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; for (uint x = 0; x < _bitWidth; x++) { pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); pix = pix ? kColorBlack : kColorWhite; - if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; + *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; } } } void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + /* if (_bitWidth == 0 || _bitHeight == 0) return; uint w = _bitWidth; uint h = _bitHeight; @@ -378,19 +387,19 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; - - for (uint y = 0;y < h; y++) { + */ + for (uint y = 0; y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; - for (uint x = 0; x < w; x++) { - pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); - + for (uint x = 0; x < _bitWidth; x++) { + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; } } } void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + /* if (_bitWidth == 0 || _bitHeight == 0) return; uint w = _bitWidth; uint h = _bitHeight; @@ -401,8 +410,8 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; - - for (uint y = 0;y < _bitHeight; y++) { + */ + for (uint y = 0; y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; for (uint x = 0; x < _bitWidth; x++) { @@ -414,6 +423,7 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, } void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { + /* if (_bitWidth == 0 || _bitHeight == 0) return; uint w = _bitWidth; uint h = _bitHeight; @@ -424,7 +434,7 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; - + */ for (uint y = 0;y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 0a3ea50ef1..adce9a54a2 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -59,7 +59,7 @@ public: void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode); - bool isPointInside(Common::Point myPos, Common::Point click); + bool isPointInside(Common::Point point); private: void decodePPIC(ObjID id, Common::Array &data); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 8d367c7174..572677a7f6 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -100,45 +100,55 @@ Common::Error MacVentureEngine::run() { _cmdReady = false; _haltedAtEnd = false; _haltedInSelection = false; + _clickToContinue = true; + _gameState = kGameStateInit; + _destObject = 0; + _prepared = true; //if !savegame _cmdReady = true; _selectedControl = kStartOrResume; ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); _currentSelection.push_back(playerParent);// Push the parent of the player - _world->setObjAttr(playerParent, 6, 1); + _world->setObjAttr(playerParent, kAttrContainerOpen, 1); - _prepared = true; - while (!(_gameState == kGameStateQuitting)) { + _gui->addChild(kSelfWindow, 1); + _gui->updateWindow(kSelfWindow, false); + + while (_gameState != kGameStateQuitting) { processEvents(); - if (_prepared) { - _prepared = false; - - if (!_halted) - updateState(); - - if (_cmdReady || _halted) { - _halted = false; - if (runScriptEngine()) { - _halted = true; - _paused = true; - } else { - _paused = false; - if (!updateState()) { - updateControls(); + if (_gameState != kGameStateQuitting) { + + if (_prepared) { + _prepared = false; + + if (!_halted) + updateState(); + + if (_cmdReady || _halted) { + _halted = false; + if (runScriptEngine()) { + _halted = true; + _paused = true; } + else { + _paused = false; + if (!updateState()) { + updateControls(); + } + } + } + + if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { + endGame(); } } + _gui->draw(); - if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { - endGame(); - } + g_system->updateScreen(); + g_system->delayMillis(50); } - _gui->draw(); - - g_system->updateScreen(); - g_system->delayMillis(50); } return Common::kNoError; @@ -161,6 +171,11 @@ void MacVentureEngine::selectControl(ControlReference id) { } void MacVentureEngine::activateCommand(ControlReference id) { + if (id == kControlClickToContinue) { + _clickToContinue = false; + _paused = true; + return; + } ControlAction action = referenceToAction(id); if (action != _activeControl) { if (_activeControl) @@ -168,6 +183,7 @@ void MacVentureEngine::activateCommand(ControlReference id) { _activeControl = action; } debug(4, "Activating Command %x... Command %x is active", action, _activeControl); + refreshReady(); } void MacVentureEngine::refreshReady() { @@ -201,9 +217,16 @@ void MacVentureEngine::loseGame() { _gameState = kGameStateLosing; } -void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID) { +void MacVentureEngine::clickToContinue() { + _clickToContinue = true; +} + +void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID target) { QueuedObject obj; obj.id = type; + + if (type == kUpdateWindow) { obj.target = target; } + if (type != kHightlightExits) { obj.object = objID; obj.parent = _world->getObjAttr(objID, kAttrParentObject); @@ -257,7 +280,12 @@ void MacVentureEngine::selectObject(ObjID objID) { else i++; } - if (!found) _currentSelection.push_back(objID); + if (!found) { + _currentSelection.push_back(objID); + debug("Object %d selected", objID); + } else { + debug("Object %d already selected", objID); + } found = false; i = 0; @@ -266,7 +294,15 @@ void MacVentureEngine::selectObject(ObjID objID) { else i++; } - if (!found) _selectedObjs.push_back(objID); + if (!found) _selectedObjs.push_back(objID); +} + +void MacVentureEngine::updateDelta(Common::Point newPos) { + Common::Point newDelta = newPos - _deltaPoint; + debug(4, "Update delta: Old(%d, %d), New(%d, %d)", + _deltaPoint.x, _deltaPoint.y, + newDelta.x, newDelta.y); + _deltaPoint = newDelta; } void MacVentureEngine::focusObjWin(ObjID objID) { @@ -357,11 +393,11 @@ bool MacVentureEngine::updateState() { } void MacVentureEngine::revert() { - warning("revert: unimplemented"); + _gui->invertWindowColors(kMainGameWindow); + preparedToRun(); } void MacVentureEngine::runObjQueue() { - warning("runObjQueue: not fully implemented"); while (!_objQueue.empty()) { uint32 biggest = 0; uint32 index = 0; @@ -389,7 +425,7 @@ void MacVentureEngine::runObjQueue() { checkObject(obj); break; case 0x8: - reflectSwap(obj.object); + reflectSwap(obj.object, obj.target); break; case 0xc: _world->setObjAttr(_gui->getWindowData(kMainGameWindow).refcon, kAttrContainerOpen, 0); @@ -408,6 +444,7 @@ void MacVentureEngine::runObjQueue() { void MacVentureEngine::updateControls() { if (_activeControl) _activeControl = kNoCommand; + _gui->clearControls(); toggleExits(); resetVars(); } @@ -434,7 +471,7 @@ void MacVentureEngine::openObject(ObjID objID) { debug("openObject: %d", objID); if (getObjWindow(objID)) return; if (objID == _world->getObjAttr(1, kAttrParentObject)) { - _gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true)); // FIXME: Find better name + _gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true)); _gui->updateWindow(kMainGameWindow, _world->getObjAttr(objID, kAttrContainerOpen)); //_gui->drawExits(); _gui->setWindowTitle(kMainGameWindow, _world->getText(objID)); @@ -522,12 +559,30 @@ void MacVentureEngine::checkObject(QueuedObject old) { } } -void MacVentureEngine::reflectSwap(ObjID objID) { - warning("reflectSwap: unimplemented"); +void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { + warning("reflectSwap: untested"); + WindowReference from = getObjWindow(fromID); + WindowReference to = getObjWindow(toID); + WindowReference tmp = to; + if (!to) { + tmp = from; + } + if (tmp) { + Common::String newTitle = _world->getText(toID); + _gui->setWindowTitle(tmp, newTitle); + _gui->updateWindowInfo(tmp, toID, _world->getChildren(toID, true)); + updateWindow(tmp); + } } void MacVentureEngine::toggleExits() { warning("toggleExits: unimplemented"); + while (!_selectedObjs.empty()) { + ObjID obj = _selectedObjs.front(); + _selectedObjs.remove_at(0); + // Todo: highlight exit + updateWindow(findParentWindow(obj)); + } } void MacVentureEngine::zoomObject(ObjID objID) { @@ -565,6 +620,10 @@ bool MacVentureEngine::isPaused() { return _paused; } +bool MacVentureEngine::needsClickToContinue() { + return _clickToContinue; +} + Common::String MacVentureEngine::getCommandsPausedString() const { return Common::String("Click to continue"); } @@ -607,7 +666,10 @@ bool MacVentureEngine::isObjClickable(ObjID objID) { } bool MacVentureEngine::isObjSelected(ObjID objID) { - warning("Unimplemented: isObjSelected"); + Common::Array::const_iterator it; + for (it = _currentSelection.begin(); it != _currentSelection.end(); it++) { + if (*it == objID) return true; + } return false; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index c45069c06c..c19021d4c5 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -135,6 +135,7 @@ struct QueuedObject { bool hidden; bool offscreen; bool invisible; + ObjID target; // For swapping }; enum TextQueueID { @@ -167,22 +168,25 @@ public: void gameChanged(); void winGame(); void loseGame(); + void clickToContinue(); bool updateState(); void revert(); - void enqueueObject(ObjectQueueID type, ObjID objID); + void enqueueObject(ObjectQueueID type, ObjID objID, ObjID target = 0); void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text); void runObjQueue(); bool printTexts(); void selectObject(ObjID objID); + void updateDelta(Common::Point newPos); void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); // Data retrieval bool isPaused(); + bool needsClickToContinue(); Common::String getCommandsPausedString() const; const GlobalSettings& getGlobalSettings() const; Common::String getFilePath(FilePathID id) const; @@ -218,7 +222,7 @@ private: void openObject(ObjID objID); void closeObject(ObjID objID); void checkObject(QueuedObject objID); - void reflectSwap(ObjID objID); + void reflectSwap(ObjID fromID, ObjID toID); void toggleExits(); void zoomObject(ObjID objID); @@ -255,6 +259,7 @@ private: // Attributes bool _paused, _halted, _cmdReady, _prepared; bool _haltedAtEnd, _haltedInSelection; bool _gameChanged; + bool _clickToContinue; Common::Array _objQueue; Common::Array _inQueue; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index f7550360c8..bf9339fe76 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -41,9 +41,6 @@ ScriptEngine::~ScriptEngine() { } bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta) { - //debug(7, "SCRIPT: Running control %d from obj %d into obj %d, at delta (%d, %d)", - // action, source, destination, delta.x, delta.y); - EngineFrame frame; frame.action = action; frame.src = source; @@ -108,24 +105,37 @@ bool ScriptEngine::execFrame(bool execAll) { } doFamily = true; } - } - - //Handle saves - /* + } - uint highest; - uint high; + // Halted in saves if (frame->haltedInSaves) { - frame->haltedInSaves = false; - } - - - do { - highest = 0; - for (uint i = 0; i < frame->haltedInSaves.size) + frame->haltedInSaves = false; + if (resumeFunc(frame)) { + frame->haltedInSaves = true; + return true; + } } - */ + uint highest = 0; + uint localHigh = 0; + do { // Saved function calls + highest = 0; + for (uint i = 0; i saves.size(); i++) + { + if (highest < frame->saves[i].rank) { + highest = frame->saves[i].rank; + localHigh = i; + } + } + if (highest) { + frame->saves[localHigh].rank = 0; + if (loadScript(frame, frame->saves[localHigh].func)) { + frame->haltedInSaves = true; + return true; + } + } + } while (highest); + _frames.remove_at(0); return false; } @@ -907,7 +917,7 @@ void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { ObjID from = state->pop(); ObjID to = state->pop(); - _engine->enqueueObject(kUpdateWindow, to); + _engine->enqueueObject(kUpdateWindow, from, to); _world->setObjAttr(to, kAttrContainerOpen, _world->getObjAttr(from, 6)); _world->setObjAttr(from, kAttrContainerOpen, 0); Common::Array children = _world->getChildren(from, true); @@ -1057,7 +1067,7 @@ void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { _engine->updateState(); - //_engine->clickToContinue(); + _engine->clickToContinue(); } void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { @@ -1083,13 +1093,11 @@ void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { } void ScriptEngine::ope0CHGR(EngineState * state, EngineFrame * frame) { - word txt = state->pop(); - op00NOOP(0xe0); + state->pop(); } void ScriptEngine::ope1CHSO(EngineState * state, EngineFrame * frame) { - word txt = state->pop(); - op00NOOP(0xe1); + state->pop(); } void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { @@ -1108,7 +1116,6 @@ void ScriptEngine::ope3UPOB(EngineState * state, EngineFrame * frame) { void ScriptEngine::ope4PLEV(EngineState * state, EngineFrame * frame) { state->push(0); - op00NOOP(0xe4); } void ScriptEngine::ope5WEV(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 499ebc0b54c79e89f4ee38628cea1f64cdf40bf2 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 24 Jun 2016 21:00:06 +0200 Subject: MACVENTURE: Script engine fixes --- engines/macventure/gui.cpp | 36 ++++++-- engines/macventure/gui.h | 8 +- engines/macventure/image.cpp | 8 ++ engines/macventure/image.h | 3 + engines/macventure/macventure.cpp | 183 +++++++++++++++++++++++++++++++------- engines/macventure/macventure.h | 14 ++- engines/macventure/script.cpp | 35 +++++--- engines/macventure/script.h | 13 ++- 8 files changed, 239 insertions(+), 61 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d4fd337557..d43be9b269 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -248,6 +248,7 @@ void Gui::initWindows() { _mainGameWindow->setCallback(mainGameWindowCallback, this); loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); + findWindowData(kMainGameWindow).objRef = 3; // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); @@ -264,6 +265,7 @@ void Gui::initWindows() { _selfWindow->setCallback(selfWindowCallback, this); loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); + findWindowData(kMainGameWindow).objRef = 0; // Exits Window _exitsWindow = _wm.addWindow(false, true, true); @@ -273,9 +275,10 @@ void Gui::initWindows() { loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); + } -WindowReference Gui::createInventoryWindow() { +WindowReference Gui::createInventoryWindow(ObjID objRef) { Graphics::MacWindow *newWindow = _wm.addWindow(true, true, true); WindowData newData; GlobalSettings settings = _engine->getGlobalSettings(); @@ -295,6 +298,7 @@ WindowReference Gui::createInventoryWindow() { newData.type = kZoomDoc; newData.hasCloseBox = true; newData.visible = true; + newData.objRef = objRef; _windowData->push_back(newData); newWindow->setDimensions(newData.bounds); @@ -528,7 +532,6 @@ void Gui::drawCommandsWindow() { } void Gui::drawMainGameWindow() { - Graphics::ManagedSurface *srf = _mainGameWindow->getSurface(); const WindowData &data = getWindowData(kMainGameWindow); BorderBounds border = borderBounds(data.type); @@ -612,12 +615,18 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * border.leftOffset + pos.x, border.topOffset + pos.y, mode); + + if (_engine->isObjSelected(child)) + _assets[child]->blitInto( + surface, + border.leftOffset + pos.x, + border.topOffset + pos.y, + kBlitOR); } } findWindow(data.refcon)->setDirty(true); - } void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { @@ -782,6 +791,9 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { for (; it != _controlData->end(); ++it) { it->unselect(); } + } + if (winID == kMainGameWindow) { + drawMainGameWindow(); } else { Graphics::MacWindow *winRef = findWindow(winID); winRef->getSurface()->fillRect(data.bounds, kColorGray); @@ -802,9 +814,6 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { children[i] = DrawableObject(child, mode); } } - if (winID == kMainGameWindow) { - drawMainGameWindow(); - } if (data.type == kZoomDoc && data.updateScroll) { warning("Unimplemented: update scroll"); } @@ -832,6 +841,16 @@ bool Gui::tryCloseWindow(WindowReference winID) { return true; } +uint Gui::getObjWidth(ObjID obj) { + if (!_assets.contains(obj)) return 0; + return _assets[obj]->getWidth(); +} + +uint Gui::getObjHeight(ObjID obj) { + if (!_assets.contains(obj)) return 0; + return _assets[obj]->getHeight(); +} + bool Gui::processEvent(Common::Event &event) { bool processed = false; if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP) { @@ -884,7 +903,6 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) { WindowData &data = findWindowData(kMainGameWindow); ObjID child; - BlitMode mode; Common::Point pos; for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; @@ -894,7 +912,7 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e pos = event.mouse - pos; if (_assets.contains(child) && _assets[child]->isPointInside(pos)) { // select the first object clicked - _engine->selectObject(child); + _engine->handleObjectSelect(child, kMainGameWindow, event); } } } @@ -912,7 +930,7 @@ bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event return true; if (event.type == Common::EVENT_LBUTTONUP) { - _engine->selectObject(1); + _engine->handleObjectSelect(1, kSelfWindow, event); } return true; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index b7d5d52b83..1da1b103dd 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -99,6 +99,7 @@ struct DrawableObject { struct WindowData { Common::Rect bounds; MVWindowType type; + ObjID objRef; uint16 visible; uint16 hasCloseBox; WindowReference refcon; @@ -160,9 +161,12 @@ public: void updateWindow(WindowReference winID, bool containerOpen); void invertWindowColors(WindowReference winID); - WindowReference createInventoryWindow(); + WindowReference createInventoryWindow(ObjID objRef); bool tryCloseWindow(WindowReference winID); + uint getObjWidth(ObjID obj); + uint getObjHeight(ObjID obj); + // Event processors bool processCommandEvents(WindowClick click, Common::Event &event); bool processMainGameEvents(WindowClick click, Common::Event &event); @@ -172,6 +176,8 @@ public: bool processDiplomaEvents(WindowClick click, Common::Event &event); bool processInventoryEvents(WindowClick click, Common::Event &event); + //bool processClickObject(ObjID obj, WindowReference win, Common::Event event, bool canDrag); + const WindowData& getWindowData(WindowReference reference); const Graphics::Font& getCurrentFont(); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 54d19c9fd2..323b8a1089 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -350,6 +350,14 @@ bool ImageAsset::isPointInside(Common::Point point) { return pix != 0; } +uint ImageAsset::getWidth() { + return _bitWidth; +} + +uint ImageAsset::getHeight() { + return _bitWidth; +} + void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { /* if (_bitWidth == 0 || _bitHeight == 0) return; diff --git a/engines/macventure/image.h b/engines/macventure/image.h index adce9a54a2..52f0dfa591 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -61,6 +61,9 @@ public: bool isPointInside(Common::Point point); + uint getWidth(); + uint getHeight(); + private: void decodePPIC(ObjID id, Common::Array &data); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 572677a7f6..21496cd8b2 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -41,7 +41,7 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD _gameDescription = gameDesc; _rnd = new Common::RandomSource("macventure"); - _debugger= NULL; + _debugger = NULL; _gui = NULL; debug("MacVenture::MacVentureEngine()"); @@ -96,7 +96,7 @@ Common::Error MacVentureEngine::run() { _scriptEngine = new ScriptEngine(this, _world); _paused = false; - _halted = true; + _halted = false; _cmdReady = false; _haltedAtEnd = false; _haltedInSelection = false; @@ -114,7 +114,7 @@ Common::Error MacVentureEngine::run() { _gui->addChild(kSelfWindow, 1); _gui->updateWindow(kSelfWindow, false); - + while (_gameState != kGameStateQuitting) { processEvents(); @@ -227,7 +227,7 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID targ if (type == kUpdateWindow) { obj.target = target; } - if (type != kHightlightExits) { + if (type != kHightlightExits) { obj.object = objID; obj.parent = _world->getObjAttr(objID, kAttrParentObject); obj.x = _world->getObjAttr(objID, kAttrPosX); @@ -267,34 +267,62 @@ bool MacVentureEngine::printTexts() { case kTextPlain: debug("Print Plain Text: %s", _world->getText(text.asset).c_str()); gameChanged(); - break; + break; } } + return false; } -void MacVentureEngine::selectObject(ObjID objID) { - bool found = false; - uint i = 0; - while (i < _currentSelection.size() && !found) { - if (_currentSelection[i] == objID) found = true; - else i++; - } - - if (!found) { - _currentSelection.push_back(objID); - debug("Object %d selected", objID); - } else { - debug("Object %d already selected", objID); +void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Common::Event event) { + if (win == kExitsWindow) { + win = kMainGameWindow; } - found = false; - i = 0; - while (i < _selectedObjs.size() && !found) { - if (_selectedObjs[i] == objID) found = true; - else i++; - } + bool canDrag = (objID && !_world->getObjAttr(objID, kAttrInvisible)); + + const WindowData &windata = _gui->getWindowData(win); - if (!found) _selectedObjs.push_back(objID); + if (event.kbd.flags & Common::KBD_SHIFT) { + // Do shift ;) + } + else { + if (_selectedControl && _currentSelection.size() > 0 && getInvolvedObjects() > 1) { + if (objID == 0) + selectPrimaryObject(windata.objRef); + else + selectPrimaryObject(objID); + preparedToRun(); + } + else { + if (objID == 0) { + unselectAll(); + //if (windata.type == kAnimateBack) { + //doLasso(win, event, canDrag); + //} + //else { + objID = win; + //} + } + if (objID > 0) { + int i = findObjectInArray(objID, _currentSelection); + + /*if (event.type == Common::EVENT isDoubleClick(event)) { // no double click for now + if (!found) + unSelectAll(); + selectObj(obj); + doubleClickObject(obj, win, event, canDrag); + } else {*/ + if (i >= 0) + unselectAll(); + selectObject(objID); + if (getInvolvedObjects() == 1) + _cmdReady = true; + preparedToRun(); + //singleClickObject(objID, win, event, canDrag); + //} + } + } + } } void MacVentureEngine::updateDelta(Common::Point newPos) { @@ -373,7 +401,11 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { if (_selectedControl == 1) _gameChanged = false; +<<<<<<< HEAD else if (_gameState == kGameStateInit || _gameState == kGameStatePlaying){ +======= + else if (_gameState == kGameStateInit || _gameState == kGameStatePlaying) { +>>>>>>> 088fc4d... MACVENTURE: Script engine fixes if (_scriptEngine->runControl(kTick, _selectedControl, _destObject, _deltaPoint)) { _haltedAtEnd = true; return true; @@ -445,7 +477,7 @@ void MacVentureEngine::updateControls() { if (_activeControl) _activeControl = kNoCommand; _gui->clearControls(); - toggleExits(); + toggleExits(); resetVars(); } @@ -458,6 +490,70 @@ void MacVentureEngine::resetVars() { _cmdReady = false; } +void MacVentureEngine::unselectAll() { + while (!_currentSelection.empty()) { + unselectObject(_currentSelection.front()); + //_currentSelection.remove_at(0); + } +} + +void MacVentureEngine::selectObject(ObjID objID) { + if (!_currentSelection.empty()) { + if (findParentWindow(objID) != findParentWindow(_currentSelection[0])) + unselectAll(); + } + if (findObjectInArray(objID, _currentSelection) == -1) + _currentSelection.push_back(objID); + if (findObjectInArray(objID, _selectedObjs) == -1) { + _selectedObjs.push_back(objID); + highlightExit(objID); + } +} + +void MacVentureEngine::unselectObject(ObjID objID) { + int idxCur = findObjectInArray(objID, _currentSelection); + int idxSel = findObjectInArray(objID, _selectedObjs); + if (idxCur != -1) _currentSelection.remove_at(idxCur); + if (idxSel != -1) { + _selectedObjs.remove_at(idxSel); + highlightExit(objID); + } +} + +int MacVentureEngine::findObjectInArray(ObjID objID, const Common::Array &list) { + // Find the object in the current selection + bool found = false; + uint i = 0; + while (i < list.size() && !found) { + if (list[i] == objID) found = true; + else i++; + } + // HACK, should use iterator + return found ? i : -1; +} + +void MacVentureEngine::highlightExit(ObjID objID) { + warning("highlightExit: unimplemented"); +} + +void MacVentureEngine::selectPrimaryObject(ObjID objID) { + if (objID == _destObject) return; + int idx; + if (_destObject > 0 && + (idx = findObjectInArray(_destObject, _selectedObjs)) != -1 && + findObjectInArray(_destObject, _currentSelection) == -1) + { + _selectedObjs.remove_at(idx); + highlightExit(_destObject); + } + _destObject = objID; + if (findObjectInArray(_destObject, _selectedObjs) == -1) { + _selectedObjs.push_back(_destObject); + highlightExit(_destObject); + } + _cmdReady = true; +} + void MacVentureEngine::focusObjectWindow(ObjID objID) { if (objID) { WindowReference win = getObjWindow(objID); @@ -479,7 +575,7 @@ void MacVentureEngine::openObject(ObjID objID) { Common::Point p(_world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); //getParentWin(obj).localToGlobal(p); //globalToDesktop(p); - WindowReference invID = _gui->createInventoryWindow(); + WindowReference invID = _gui->createInventoryWindow(objID); _gui->setWindowTitle(invID, _world->getText(objID)); _gui->updateWindowInfo(invID, objID, _world->getChildren(objID, true)); _gui->updateWindow(invID, _world->getObjAttr(objID, kAttrContainerOpen)); @@ -576,11 +672,10 @@ void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { } void MacVentureEngine::toggleExits() { - warning("toggleExits: unimplemented"); while (!_selectedObjs.empty()) { ObjID obj = _selectedObjs.front(); _selectedObjs.remove_at(0); - // Todo: highlight exit + highlightExit(obj); updateWindow(findParentWindow(obj)); } } @@ -666,11 +761,33 @@ bool MacVentureEngine::isObjClickable(ObjID objID) { } bool MacVentureEngine::isObjSelected(ObjID objID) { - Common::Array::const_iterator it; - for (it = _currentSelection.begin(); it != _currentSelection.end(); it++) { - if (*it == objID) return true; + int idx = findObjectInArray(objID, _currentSelection); + return idx != -1; +} + +Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { + Common::Point pos = getObjPosition(objID); + uint w = _gui->getObjWidth(objID); // This shouldn't go here + uint h = _gui->getObjHeight(objID); + return Common::Rect(pos.x, pos.y, pos.x + w, pos.y + h); +} + +uint MacVentureEngine::getOverlapPercent(ObjID one, ObjID other) { + //not the same parent? 0 overlap + if (_world->getObjAttr(one, kAttrParentObject) != + _world->getObjAttr(other, kAttrParentObject)) + return 0; + + Common::Rect oneBounds = getObjBounds(one); + Common::Rect otherBounds = getObjBounds(other); + if (otherBounds.intersects(oneBounds) || + oneBounds.intersects(otherBounds)) + { + uint areaOne = oneBounds.width() * oneBounds.height(); + uint areaOther = otherBounds.width() * otherBounds.height(); + return (areaOther * 100 / areaOne) | 0; } - return false; + return 0; } WindowReference MacVentureEngine::getObjWindow(ObjID objID) { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index c19021d4c5..4671c2a881 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -179,7 +179,7 @@ public: void runObjQueue(); bool printTexts(); - void selectObject(ObjID objID); + void handleObjectSelect(ObjID objID, WindowReference win, Common::Event event); void updateDelta(Common::Point newPos); void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); @@ -201,6 +201,10 @@ public: bool isObjClickable(ObjID objID); bool isObjSelected(ObjID objID); + // Encapsulation HACK + Common::Rect getObjBounds(ObjID objID); + uint getOverlapPercent(ObjID one, ObjID other); + WindowReference getObjWindow(ObjID objID); WindowReference findObjWindow(ObjID objID); WindowReference findParentWindow(ObjID objID); @@ -217,6 +221,14 @@ private: void updateControls(); void resetVars(); + void unselectAll(); + void selectObject(ObjID objID); + void unselectObject(ObjID objID); + int findObjectInArray(ObjID objID, const Common::Array &list); + void highlightExit(ObjID objID); + void selectPrimaryObject(ObjID objID); + + // Object queue methods void focusObjectWindow(ObjID objID); void openObject(ObjID objID); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index bf9339fe76..4c00054bb6 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -136,32 +136,37 @@ bool ScriptEngine::execFrame(bool execAll) { } } while (highest); - _frames.remove_at(0); + _frames.pop_front(); return false; } bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { - frame->scripts.push_back(ScriptAsset(scriptID, _scripts)); + if (_scripts->getItemByteSize(scriptID) > 0) { + debug(3, "SCRIPT: Loading function %d", scriptID); + // Insert the new script at the front + frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); + return runFunc(frame); + } return false; } bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool fail = runFunc(frame); if (fail) return fail; - frame->scripts.remove_at(0); + frame->scripts.pop_front(); if (frame->scripts.size()) return resumeFunc(frame); return false; } bool ScriptEngine::runFunc(EngineFrame *frame) { - debug(3, "SCRIPT: I'm running the function"); ScriptAsset &script = frame->scripts.front(); + debug(3, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; byte op; while (script.hasNext()) { op = script.fetch(); - debug(3, "SCRIPT: I'm running operation %x", op); + debug(3, "SCRIPT: I'm running operation %d", op); if (!(op & 0x80)) { state->push(op); } else { @@ -857,7 +862,7 @@ void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsse void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { word rank = state->pop(); word func = state->pop(); - frame->saves.push_back(FunCall(rank, func)); + frame->saves.push_back(FunCall(func, rank)); } void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { @@ -904,9 +909,11 @@ void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); - frame->scripts.remove_at(0); - frame->scripts.insert_at(0, newfun); + ScriptAsset current = script; + loadScript(frame, id); + frame->scripts.pop_front(); script = frame->scripts.front(); + debug(3, "SCRIPT: Return from fuction %d", id); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1019,17 +1026,15 @@ void ScriptEngine::opd0P1(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { word obj = state->pop(); - Common::Rect bounds(0, 0, 1, 1); //= _world->getObjBounds(obj); + Common::Rect bounds = _engine->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); - op00NOOP(0xd1); } void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { word b = state->pop(); word a = state->pop(); - state->push(0);//_world->getOverlapPercent(b, a)); - op00NOOP(0xd2); + state->push(_engine->getOverlapPercent(b, a)); } void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { @@ -1138,11 +1143,11 @@ void ScriptEngine::op00NOOP(byte op) { - ScriptAsset::ScriptAsset(ObjID id, Container * container) { _id = id; _container = container; _ip = 0x0; + loadInstructions(); } void ScriptAsset::reset() { @@ -1163,6 +1168,10 @@ void ScriptAsset::branch(word amount) { _ip += amount; } +ObjID ScriptAsset::getId() { + return _id; +} + void ScriptAsset::loadInstructions() { uint32 amount = _container->getItemByteSize(_id); Common::SeekableReadStream *res = _container->getItem(_id); diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 178e054e05..1a143cffd0 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -63,6 +63,8 @@ public: bool hasNext(); void branch(word amount); + ObjID getId(); + private: void loadInstructions(); @@ -82,12 +84,12 @@ public: } void push(word data) { + sp--; stack[sp] = unneg16(data); - sp--; } word pop() { - byte v = stack[sp]; + word v = stack[sp]; sp++; return v; } @@ -102,6 +104,9 @@ public: void clear() { sp = 0x80; + for (int i = 0; i < sp; i++) { + stack[i] = 0; + } } word size() { @@ -139,7 +144,7 @@ struct EngineFrame { int x; int y; EngineState state; - Common::Array scripts; + Common::List scripts; Common::Array saves; uint32 familyIdx; @@ -288,7 +293,7 @@ private: private: MacVentureEngine *_engine; World *_world; - Common::Array _frames; + Common::List _frames; Container *_scripts; }; -- cgit v1.2.3 From 8dd52b6cce3835950f255f48d13f3d09a7dbe0ff Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 17:38:15 +0200 Subject: MACVENTURE: Complete text decoding --- engines/macventure/gui.cpp | 54 ++++++++++++++---------- engines/macventure/gui.h | 1 + engines/macventure/image.h | 1 + engines/macventure/macventure.cpp | 54 ++++++++++++++++-------- engines/macventure/macventure.h | 9 +++- engines/macventure/script.cpp | 12 +++--- engines/macventure/text.cpp | 89 +++++++++++++++++++++++++++++++-------- engines/macventure/text.h | 8 +++- engines/macventure/world.cpp | 7 +-- engines/macventure/world.h | 2 +- 10 files changed, 165 insertions(+), 72 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d43be9b269..e0fcc5d691 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -174,6 +174,7 @@ void Gui::setWindowTitle(WindowReference winID, Common::String string) { void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array &children) { WindowData &data = findWindowData(ref); data.children.clear(); + data.objRef = objID; uint32 originx = 0x7fff; uint32 originy = 0x7fff; for (uint i = 0; i < children.size(); i++) { @@ -224,6 +225,8 @@ void Gui::initGUI() { initWindows(); + assignObjReferences(); + if (!loadControls()) error("Could not load controls"); @@ -238,43 +241,47 @@ void Gui::initWindows() { _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); _controlsWindow->setActive(false); _controlsWindow->setCallback(commandsWindowCallback, this); - loadBorder(_controlsWindow, "border_command.bmp", false); - loadBorder(_controlsWindow, "border_command.bmp", true); + //loadBorder(_controlsWindow, "border_command.bmp", false); + //loadBorder(_controlsWindow, "border_command.bmp", true); // Main Game Window _mainGameWindow = _wm.addWindow(false, false, false); _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); - loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); - findWindowData(kMainGameWindow).objRef = 3; + //loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); + //loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); + //loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); + //loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); // Self Window _selfWindow = _wm.addWindow(false, true, true); _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); - findWindowData(kMainGameWindow).objRef = 0; + //loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); + //loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); // Exits Window _exitsWindow = _wm.addWindow(false, true, true); _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); - loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); + //loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); + //loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); + + +} +void Gui::assignObjReferences() { + + findWindowData(kSelfWindow).objRef = 0; } @@ -282,7 +289,7 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { Graphics::MacWindow *newWindow = _wm.addWindow(true, true, true); WindowData newData; GlobalSettings settings = _engine->getGlobalSettings(); - newData.refcon = (WindowReference)ABS(_inventoryWindows.size()); // This is a hack + newData.refcon = (WindowReference)ABS(_inventoryWindows.size()); // This is a HACK if (_windowData->back().refcon < 0x80) { // There is already another inventory window newData.bounds = _windowData->back().bounds; // Inventory windows are always last @@ -303,8 +310,8 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); - loadBorder(newWindow, "border_no_scroll_inac.bmp", false); - loadBorder(newWindow, "border_no_scroll_act.bmp", true); + //loadBorder(newWindow, "border_no_scroll_inac.bmp", false); + //loadBorder(newWindow, "border_no_scroll_act.bmp", true); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); @@ -587,7 +594,7 @@ void Gui::drawExitsWindow() { srf->w + border.rightOffset, srf->h + border.bottomOffset), kColorWhite); - drawObjectsInWindow(kExitsWindow, _exitsWindow->getSurface()); + drawObjectsInWindow(kMainGameWindow, _exitsWindow->getSurface()); } void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { @@ -792,12 +799,6 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { it->unselect(); } } - if (winID == kMainGameWindow) { - drawMainGameWindow(); - } else { - Graphics::MacWindow *winRef = findWindow(winID); - winRef->getSurface()->fillRect(data.bounds, kColorGray); - } Common::Array &children = data.children; for (uint i = 0; i < children.size(); i++) { uint flag = 0; @@ -812,8 +813,17 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { mode = kBlitOR; } children[i] = DrawableObject(child, mode); + } else { + children[i] = DrawableObject(child, kBlitXOR); } } + if (winID == kMainGameWindow) { + drawMainGameWindow(); + } + else { + Graphics::MacWindow *winRef = findWindow(winID); + winRef->getSurface()->fillRect(data.bounds, kColorGray); + } if (data.type == kZoomDoc && data.updateScroll) { warning("Unimplemented: update scroll"); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 1da1b103dd..3569df7bbe 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -221,6 +221,7 @@ private: // Methods // Initializers void initGUI(); void initWindows(); + void assignObjReferences(); // Mainly guesswork // Loaders bool loadMenus(); diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 52f0dfa591..9538d0cbb6 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -37,6 +37,7 @@ enum BlitMode { kBlitBIC = 1, kBlitOR = 2, kBlitXOR = 3 + //kBlitNONE = 4, }; enum GraphicsEncoding { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 21496cd8b2..3187b39709 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -59,8 +59,14 @@ MacVentureEngine::~MacVentureEngine() { if (_filenames) delete _filenames; - if (_decodingArticles) - delete _decodingArticles; + if (_decodingDirectArticles) + delete _decodingDirectArticles; + + if (_decodingNamingArticles) + delete _decodingNamingArticles; + + if (_decodingIndirectArticles) + delete _decodingIndirectArticles; if (_textHuffman) delete _textHuffman; @@ -88,7 +94,9 @@ Common::Error MacVentureEngine::run() { _oldTextEncoding = !loadTextHuffman(); _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); - _decodingArticles = new StringTable(this, _resourceManager, kCommonArticlesStringTableID); + _decodingDirectArticles = new StringTable(this, _resourceManager, kCommonArticlesStringTableID); + _decodingNamingArticles = new StringTable(this, _resourceManager, kNamingArticlesStringTableID); + _decodingDirectArticles = new StringTable(this, _resourceManager, kIndirectArticlesStringTableID); // Big class instantiation _gui = new Gui(this, _resourceManager); @@ -251,7 +259,6 @@ void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, } bool MacVentureEngine::printTexts() { - warning("printTexts: unimplemented"); for (uint i = 0; i < _textQueue.size(); i++) { QueuedText text = _textQueue.front(); _textQueue.remove_at(0); @@ -265,7 +272,7 @@ bool MacVentureEngine::printTexts() { gameChanged(); break; case kTextPlain: - debug("Print Plain Text: %s", _world->getText(text.asset).c_str()); + debug("Print Plain Text: %s", _world->getText(text.asset, text.source, text.destination).c_str()); gameChanged(); break; } @@ -401,11 +408,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { if (_selectedControl == 1) _gameChanged = false; -<<<<<<< HEAD - else if (_gameState == kGameStateInit || _gameState == kGameStatePlaying){ -======= else if (_gameState == kGameStateInit || _gameState == kGameStatePlaying) { ->>>>>>> 088fc4d... MACVENTURE: Script engine fixes if (_scriptEngine->runControl(kTick, _selectedControl, _destObject, _deltaPoint)) { _haltedAtEnd = true; return true; @@ -493,7 +496,6 @@ void MacVentureEngine::resetVars() { void MacVentureEngine::unselectAll() { while (!_currentSelection.empty()) { unselectObject(_currentSelection.front()); - //_currentSelection.remove_at(0); } } @@ -532,6 +534,22 @@ int MacVentureEngine::findObjectInArray(ObjID objID, const Common::Array return found ? i : -1; } +uint MacVentureEngine::getPrefixNdx(ObjID obj) { + return _world->getObjAttr(obj, kAttrPrefixes); +} + +Common::String MacVentureEngine::getPrefixString(uint flag, ObjID obj) { + uint ndx = _world->getObjAttr(obj, kAttrPrefixes); // HACK should check the type of that one + ndx = ((ndx) >> flag) & 3; + if (ndx) { + return (*_decodingNamingArticles->getStrings())[ndx]; + } +} + +Common::String MacVentureEngine::getNoun(ObjID ndx) { + return (*_decodingIndirectArticles->getStrings())[ndx]; +} + void MacVentureEngine::highlightExit(ObjID objID) { warning("highlightExit: unimplemented"); } @@ -541,7 +559,7 @@ void MacVentureEngine::selectPrimaryObject(ObjID objID) { int idx; if (_destObject > 0 && (idx = findObjectInArray(_destObject, _selectedObjs)) != -1 && - findObjectInArray(_destObject, _currentSelection) == -1) + findObjectInArray(_destObject, _currentSelection) == -1) { _selectedObjs.remove_at(idx); highlightExit(_destObject); @@ -570,13 +588,13 @@ void MacVentureEngine::openObject(ObjID objID) { _gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true)); _gui->updateWindow(kMainGameWindow, _world->getObjAttr(objID, kAttrContainerOpen)); //_gui->drawExits(); - _gui->setWindowTitle(kMainGameWindow, _world->getText(objID)); + _gui->setWindowTitle(kMainGameWindow, _world->getText(objID, objID, objID)); // it ignores source and target in the original } else { // Open inventory window Common::Point p(_world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); //getParentWin(obj).localToGlobal(p); //globalToDesktop(p); WindowReference invID = _gui->createInventoryWindow(objID); - _gui->setWindowTitle(invID, _world->getText(objID)); + _gui->setWindowTitle(invID, _world->getText(objID, objID, objID)); _gui->updateWindowInfo(invID, objID, _world->getChildren(objID, true)); _gui->updateWindow(invID, _world->getObjAttr(objID, kAttrContainerOpen)); } @@ -664,7 +682,7 @@ void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { tmp = from; } if (tmp) { - Common::String newTitle = _world->getText(toID); + Common::String newTitle = _world->getText(toID, 0, 0); // Ignores src and targ in the original _gui->setWindowTitle(tmp, newTitle); _gui->updateWindowInfo(tmp, toID, _world->getChildren(toID, true)); updateWindow(tmp); @@ -677,7 +695,7 @@ void MacVentureEngine::toggleExits() { _selectedObjs.remove_at(0); highlightExit(obj); updateWindow(findParentWindow(obj)); - } + } } void MacVentureEngine::zoomObject(ObjID objID) { @@ -775,13 +793,13 @@ Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { uint MacVentureEngine::getOverlapPercent(ObjID one, ObjID other) { //not the same parent? 0 overlap if (_world->getObjAttr(one, kAttrParentObject) != - _world->getObjAttr(other, kAttrParentObject)) + _world->getObjAttr(other, kAttrParentObject)) return 0; Common::Rect oneBounds = getObjBounds(one); Common::Rect otherBounds = getObjBounds(other); if (otherBounds.intersects(oneBounds) || - oneBounds.intersects(otherBounds)) + oneBounds.intersects(otherBounds)) { uint areaOne = oneBounds.width() * oneBounds.height(); uint areaOther = otherBounds.width() * otherBounds.height(); @@ -805,7 +823,7 @@ WindowReference MacVentureEngine::findObjWindow(ObjID objID) { // This is a bit of a hack, we take advantage of the consecutive nature of references for (uint i = kCommandsWindow; i <= kDiplomaWindow; i++) { const WindowData &data = _gui->getWindowData((WindowReference)i); - if (data.refcon == objID) { return data.refcon; } + if (data.objRef == objID) { return data.refcon; } } return kNoWindow; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 4671c2a881..891fdb5ad6 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -194,6 +194,10 @@ public: const HuffmanLists *getDecodingHuffman() const; uint32 randBetween(uint32 min, uint32 max); uint32 getInvolvedObjects(); + int findObjectInArray(ObjID objID, const Common::Array &list); + uint getPrefixNdx(ObjID obj); + Common::String getPrefixString(uint flag, ObjID obj); + Common::String getNoun(ObjID ndx); // Attributes consult Common::Point getObjPosition(ObjID objID); @@ -224,7 +228,6 @@ private: void unselectAll(); void selectObject(ObjID objID); void unselectObject(ObjID objID); - int findObjectInArray(ObjID objID, const Common::Array &list); void highlightExit(ObjID objID); void selectPrimaryObject(ObjID objID); @@ -261,7 +264,9 @@ private: // Attributes // String tables StringTable *_filenames; - StringTable *_decodingArticles; + StringTable *_decodingDirectArticles; + StringTable *_decodingNamingArticles; + StringTable *_decodingIndirectArticles; // Engine state GameState _gameState; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 4c00054bb6..2e283e4c15 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -794,21 +794,21 @@ void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opadEQS(EngineState * state, EngineFrame * frame) { - Common::String b = _world->getText(state->pop()); - Common::String a = _world->getText(state->pop()); + Common::String b = _world->getText(state->pop(), 0, 0); // HACK, these destinations might be wrong + Common::String a = _world->getText(state->pop(), 0, 0); state->push((a == b) ? 1 : 0); } void ScriptEngine::opaeCONT(EngineState * state, EngineFrame * frame) { - Common::String needle = _world->getText(state->pop()); - Common::String haystack = _world->getText(state->pop()); + Common::String needle = _world->getText(state->pop(), 0, 0); + Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { - Common::String needle = _world->getText(state->pop()); - Common::String haystack = _world->getText(state->pop()); + Common::String needle = _world->getText(state->pop(), 0, 0); + Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 49df7ed9a0..79c3200146 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -23,11 +23,14 @@ #include "macventure/text.h" namespace MacVenture { -TextAsset::TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman) { +TextAsset::TextAsset(MacVentureEngine *engine, ObjID objid, ObjID source, ObjID target, Container *container, bool isOld, const HuffmanLists *huffman) { _id = objid; + _sourceObj = source; + _targetObj = target; _container = container; _huffman = huffman; _isOld = isOld; + _engine = engine; if (_isOld) { decodeOld(); @@ -77,8 +80,20 @@ void TextAsset::decodeOld() { lowercase = true; } else if (val == 0x1D) { // Composite - warning("Composite strings not implemented"); - stream.getBits(16); + ObjID subval = stream.getBits(16); + Common::String child; + if (subval & 0x8000) { + // Composite object id + subval ^= 0xFFFF; + child = getNoun(subval); + } else { + // Just another id + // HACK, see below in getNoun() + child = *TextAsset(_engine, subval, _sourceObj, _targetObj, _container, _isOld, _huffman).decode(); + } + if (child.size() > 0) { + c = '?'; // HACK Will fix later, should append + } lowercase = true; } else if (val == 0x1E) { @@ -102,7 +117,7 @@ void TextAsset::decodeOld() { void TextAsset::decodeHuffman() { _decoded = Common::String(""); Common::SeekableReadStream *res = _container->getItem(_id); - Common::BitStream32BEMSB stream(res); + Common::BitStream8MSB stream(res); uint16 strLen = 0; if (stream.getBit()) { strLen = stream.getBits(15); @@ -110,12 +125,13 @@ void TextAsset::decodeHuffman() { else { strLen = stream.getBits(7); } - + // OK up to here uint32 mask = 0; uint32 symbol = 0; char c; for (uint16 i = 0; i < strLen; i++) { - mask = stream.peekBits(16); // The mask is OK, so it means that I don't know how to use the huffman + mask = stream.peekBits(16); // The mask is OK + uint32 entry; // Find the length index for (entry = 0; entry < _huffman->getNumEntries(); entry++) { @@ -128,24 +144,63 @@ void TextAsset::decodeHuffman() { if (symbol == 1) { // 7-bit ascii c = stream.getBits(7); - } - else if (symbol == 2) { // Composite - warning("Composite huffman strings not tested"); + _decoded += c; + } else if (symbol == 2) { // Composite if (stream.getBit()) { // TextID ObjID embedId = stream.getBits(15); - TextAsset embedded(embedId, _container, _isOld, _huffman); - _decoded += *embedded.decode(); + uint pos = stream.pos(); // HACK, part 1 + TextAsset embedded(_engine, embedId, _sourceObj, _targetObj, _container, _isOld, _huffman); + stream.rewind();// HACK, part 2 + stream.skip(pos); + + _decoded.replace(_decoded.end(), _decoded.end(), *embedded.decode()); + + // Another HACK, to get around that EOS char I insert at the end + _decoded.replace(_decoded.end() - 1, _decoded.end(), ""); } else { //Composite obj string - _decoded += Common::String("Unimplemented"); + ObjID embedId = stream.getBits(8); + _decoded.replace(_decoded.end(), _decoded.end(), getNoun(embedId)); + // Another HACK, to get around that EOS char I insert at the end + _decoded.replace(_decoded.end() - 1, _decoded.end(), ""); } - } - else { // Plain ascii + } else { // Plain ascii c = symbol & 0xFF; - } - - _decoded += c; + _decoded.replace(_decoded.end(), _decoded.end(), Common::String(c)); + } } _decoded += '\0'; debug(7, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); } +Common::String TextAsset::getNoun(ObjID subval) { + ObjID obj; + Common::String name; + if (subval & 8) + obj = _targetObj; + else + obj = _sourceObj; + if ((subval & 3) == 1) + { + uint idx = _engine->getPrefixNdx(obj); + idx = ((idx >> 4) & 3) + 1; + name = _engine->getNoun(idx); + } + else + { + // HACK, there should be a pool of assets or something like in the GUI + name = *TextAsset(_engine, obj, _sourceObj, _targetObj, _container, _isOld, _huffman).decode(); + switch (subval & 3) + { + case 2: + name = _engine->getPrefixString(0, obj) + name; + break; + case 3: + name = _engine->getPrefixString(2, obj) + name; + break; + } + } + if (name.size() && (subval & 4)) + name.toUppercase(); // HACK, should only capitalize first char? + return name; +} + } // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/text.h b/engines/macventure/text.h index cfe76d6e11..2389454042 100644 --- a/engines/macventure/text.h +++ b/engines/macventure/text.h @@ -31,7 +31,7 @@ typedef uint32 ObjID; class TextAsset { public: - TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman); + TextAsset(MacVentureEngine *engine, ObjID objid, ObjID source, ObjID target, Container *container, bool isOld, const HuffmanLists *huffman); ~TextAsset() {} const Common::String *decode() { @@ -42,9 +42,15 @@ private: void decodeOld(); void decodeHuffman(); + Common::String getNoun(ObjID id); + private: + MacVentureEngine *_engine; + Container *_container; ObjID _id; + ObjID _targetObj; + ObjID _sourceObj; const HuffmanLists *_huffman; bool _isOld; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 2ee7bae92f..02d388ab5f 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -25,9 +25,6 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { warning("Test functions about to happen"); _gameText = new Container("Shadowgate II/Shadow Text"); - - ObjID tid = (ObjID)1; - TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); delete saveGameRes; saveGameFile.close(); @@ -153,8 +150,8 @@ void World::captureChildren(ObjID objID) { void World::releaseChildren(ObjID objID) { } -Common::String World::getText(ObjID objID) { - TextAsset text = TextAsset(objID, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); +Common::String World::getText(ObjID objID, ObjID source, ObjID target) { + TextAsset text = TextAsset(_engine, objID, source, target, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); return *text.decode(); } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index f42dd3a816..c023c70ec6 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -99,7 +99,7 @@ public: uint32 getObjAttr(ObjID objID, uint32 attrID); Attribute getGlobal(uint32 attrID); - Common::String getText(ObjID objID); + Common::String getText(ObjID objID, ObjID source, ObjID target); bool isObjActive(ObjID objID); -- cgit v1.2.3 From 25f086e63b2b007ba03a47dcdab2426369edf01f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 18:05:47 +0200 Subject: MACVENTURE: Add a small hack for decoding --- engines/macventure/text.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 79c3200146..d3fc956b93 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -159,7 +159,12 @@ void TextAsset::decodeHuffman() { _decoded.replace(_decoded.end() - 1, _decoded.end(), ""); } else { //Composite obj string ObjID embedId = stream.getBits(8); + uint pos = stream.pos(); // HACK, part 1 + _decoded.replace(_decoded.end(), _decoded.end(), getNoun(embedId)); + stream.rewind();// HACK, part 2 + stream.skip(pos); + // Another HACK, to get around that EOS char I insert at the end _decoded.replace(_decoded.end() - 1, _decoded.end(), ""); } -- cgit v1.2.3 From 4837b7750a5494f7002f8f7c5d47ba44621dd425 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 20:45:53 +0200 Subject: MACVENTURE: Add rect collission for main game window --- engines/macventure/container.h | 31 +++++++++++-------------------- engines/macventure/gui.cpp | 39 +++++++++++++++++++++++++++++++-------- engines/macventure/image.cpp | 12 ++++++++++++ engines/macventure/image.h | 1 + 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 4dc5172fd7..440c0cb977 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -42,6 +42,8 @@ class Container { public: Container(const char *filename) { + _filename = Common::String(filename); + if (!_file.open(filename)) error("Could not open %s", filename); @@ -172,9 +174,11 @@ public: * getItemByteSize should be called before this one */ Common::SeekableReadStream *getItem(uint32 id) { + _res->seek(0); + Common::SeekableReadStream *res = _res->readStream(_res->size()); if (_simplified) { - _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); - return _res; + res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); + return res; } else { uint32 groupID = (id >> 6); uint32 objectIndex = id & 0x3f; // Index within the group @@ -184,9 +188,9 @@ public: offset += _groups[groupID].lengths[i]; } - _res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); + res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); - return _res; + return res; } } @@ -202,27 +206,14 @@ protected: uint16 _huff[15]; // huffman masks uint8 _lens[16]; // huffman lengths Common::Array _groups; - + + Common::String _filename; Common::File _file; Common::SeekableReadStream *_res; - - // To be moved - //byte _remainderOffset; + }; -/* -template -class PersistentContainer : public Container { -public: - PersistentContainer(Common::String filename) : - Container(filename) { - // Load - } - -private: - -};*/ } // End of namespace MacVenture diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index e0fcc5d691..529d0444de 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -26,10 +26,18 @@ #include "macventure/macventure.h" #include "macventure/gui.h" +// TBDeleted +#include "common/system.h" + namespace MacVenture { enum MenuAction; +enum { + kCursorWidth = 4, // HACK Arbitrary width to test + kCursorHeight = 4 +}; + enum { kMenuHighLevel = -1, kMenuAbout = 0, @@ -250,7 +258,7 @@ void Gui::initWindows() { _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); //loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); + loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); @@ -558,6 +566,17 @@ void Gui::drawMainGameWindow() { kBlitDirect); drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); + + // To be deleted + /* + g_system->copyRectToScreen( + _mainGameWindow->getSurface()->getPixels(), + _mainGameWindow->getSurface()->pitch, + 0, 0, + _mainGameWindow->getSurface()->w, + _mainGameWindow->getSurface()->h); + */ + g_system->updateScreen(); } void Gui::drawSelfWindow() { @@ -914,15 +933,19 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e WindowData &data = findWindowData(kMainGameWindow); ObjID child; Common::Point pos; + // Click rect to local coordinates. We assume the click is inside the window ^ + int left = event.mouse.x - _mainGameWindow->getDimensions().left; + int top = event.mouse.y - _mainGameWindow->getDimensions().top; + Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; - pos = _engine->getObjPosition(child); - pos.x += _mainGameWindow->getDimensions().left; - pos.y += _mainGameWindow->getDimensions().top; - pos = event.mouse - pos; - if (_assets.contains(child) && _assets[child]->isPointInside(pos)) { - // select the first object clicked - _engine->handleObjectSelect(child, kMainGameWindow, event); + Common::Rect intersection = clickRect.findIntersectingRect(_engine->getObjBounds(child)); + intersection = Common::Rect(0, 0, intersection.width(), intersection.height()); + if (_assets.contains(child) && _engine->isObjClickable(child)) { + if (_assets[child]->isRectInside(intersection)) { + // select the first object clicked + _engine->handleObjectSelect(child, kMainGameWindow, event); + } } } } diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 323b8a1089..1a50a4ffbc 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -350,6 +350,18 @@ bool ImageAsset::isPointInside(Common::Point point) { return pix != 0; } +bool ImageAsset::isRectInside(Common::Rect rect) { + for (uint y = rect.top; y < rect.top + rect.height(); y++) { + uint bmpofs = y * _rowBytes; + byte pix; + for (uint x = rect.left; x < rect.left + rect.width(); x++) { + pix = _maskData[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + if (pix) return true; + } + } + return false; +} + uint ImageAsset::getWidth() { return _bitWidth; } diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 9538d0cbb6..5cbe146055 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -61,6 +61,7 @@ public: void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode); bool isPointInside(Common::Point point); + bool isRectInside(Common::Rect rect); uint getWidth(); uint getHeight(); -- cgit v1.2.3 From 45a2aa94b9e79bfe1e384d1240018abdc8df8f84 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 22:21:26 +0200 Subject: MACVENTURE: Fix rect collission --- engines/macventure/gui.cpp | 104 ++++++++++++++++++++++++-------------- engines/macventure/image.cpp | 4 +- engines/macventure/macventure.cpp | 12 ++++- engines/macventure/macventure.h | 2 + 4 files changed, 80 insertions(+), 42 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 529d0444de..e1fb0beca3 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -38,6 +38,11 @@ enum { kCursorHeight = 4 }; +enum { + kExitButtonWidth = 10, // HACK Arbitrary width to test + kExitButtonHeight = 10 +}; + enum { kMenuHighLevel = -1, kMenuAbout = 0, @@ -212,7 +217,8 @@ void Gui::removeChild(WindowReference target, ObjID child) { if (data.children[index].obj == child) break; } - data.children.remove_at(index); + if (index < data.children.size()) + data.children.remove_at(index); } void Gui::initGUI() { @@ -249,15 +255,15 @@ void Gui::initWindows() { _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); _controlsWindow->setActive(false); _controlsWindow->setCallback(commandsWindowCallback, this); - //loadBorder(_controlsWindow, "border_command.bmp", false); - //loadBorder(_controlsWindow, "border_command.bmp", true); + loadBorder(_controlsWindow, "border_command.bmp", false); + loadBorder(_controlsWindow, "border_command.bmp", true); // Main Game Window _mainGameWindow = _wm.addWindow(false, false, false); _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); - //loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); // In-game Output Console @@ -265,24 +271,24 @@ void Gui::initWindows() { _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - //loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); - //loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); // Self Window _selfWindow = _wm.addWindow(false, true, true); _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - //loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); + loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); // Exits Window _exitsWindow = _wm.addWindow(false, true, true); _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); - //loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); + loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); } @@ -318,8 +324,8 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); - //loadBorder(newWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(newWindow, "border_no_scroll_act.bmp", true); + loadBorder(newWindow, "border_no_scroll_inac.bmp", false); + loadBorder(newWindow, "border_no_scroll_act.bmp", true); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); @@ -340,21 +346,12 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool Graphics::TransparentSurface *surface = new Graphics::TransparentSurface(); if (stream) { - debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename); - bmpDecoder.loadStream(*stream); - source = *(bmpDecoder.getSurface()); - - source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette()); - surface->create(source.w, source.h, source.format); - surface->copyFrom(source); - surface->applyColorKey(255, 0, 255, false); - - target->setBorder(*surface, active); - - borderfile.close(); + debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename.c_str()); + target->loadBorder(*stream, active); delete stream; } + borderfile.close(); } void Gui::loadGraphics() { @@ -567,21 +564,13 @@ void Gui::drawMainGameWindow() { drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); - // To be deleted - /* - g_system->copyRectToScreen( - _mainGameWindow->getSurface()->getPixels(), - _mainGameWindow->getSurface()->pitch, - 0, 0, - _mainGameWindow->getSurface()->w, - _mainGameWindow->getSurface()->h); - */ - g_system->updateScreen(); + findWindow(kMainGameWindow)->setDirty(true); } void Gui::drawSelfWindow() { drawObjectsInWindow(kSelfWindow, _selfWindow->getSurface()); if (_engine->isObjSelected(1)) invertWindowColors(kSelfWindow); + findWindow(kSelfWindow)->setDirty(true); } void Gui::drawInventories() { @@ -600,7 +589,10 @@ void Gui::drawInventories() { srf->h + border.bottomOffset), kColorWhite); drawObjectsInWindow((*it).refcon, _inventoryWindows[(*it).refcon]->getSurface()); it++; + + findWindow((*it).refcon)->setDirty(true); } + } void Gui::drawExitsWindow() { @@ -613,7 +605,32 @@ void Gui::drawExitsWindow() { srf->w + border.rightOffset, srf->h + border.bottomOffset), kColorWhite); - drawObjectsInWindow(kMainGameWindow, _exitsWindow->getSurface()); + // For each obj in the main window, if it is an exit, we draw it + WindowData &objData = findWindowData(kMainGameWindow); + Common::Point pos; + ObjID child; + BlitMode mode; + Common::Rect exit; + for (uint i = 0; i < objData.children.size(); i++) { + child = objData.children[i].obj; + mode = (BlitMode)objData.children[i].mode; + pos = _engine->getObjExitPosition(child); + pos.x += border.leftOffset; + pos.y += border.topOffset; + exit = Common::Rect(pos.x, pos.y, pos.x + kExitButtonWidth, pos.y + kExitButtonHeight); + if (_engine->isObjExit(child)) { + if (_engine->isObjSelected(child)) + srf->fillRect(exit, kColorGreen); + + srf->fillRect(exit, kColorGreen); + } + } + + findWindow(kExitsWindow)->setDirty(true); + + // To be deleted + //g_system->copyRectToScreen(srf->getPixels(), srf->pitch, 0, 0, srf->w, srf->h); + //g_system->updateScreen(); } void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { @@ -652,7 +669,6 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * } - findWindow(data.refcon)->setDirty(true); } void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { @@ -939,9 +955,19 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; - Common::Rect intersection = clickRect.findIntersectingRect(_engine->getObjBounds(child)); - intersection = Common::Rect(0, 0, intersection.width(), intersection.height()); - if (_assets.contains(child) && _engine->isObjClickable(child)) { + if (_assets.contains(child) && + _engine->isObjClickable(child) && + _engine->isObjVisible(child)) { + Common::Rect bounds = _engine->getObjBounds(child); + Common::Rect intersection = bounds.findIntersectingRect(clickRect); + // We translate it to the image's coord system + intersection = Common::Rect( + intersection.left - bounds.left, + intersection.top - bounds.top, + intersection.left - bounds.left + intersection.width(), + intersection.top - bounds.top + intersection.height()); + + if (_assets[child]->isRectInside(intersection)) { // select the first object clicked _engine->handleObjectSelect(child, kMainGameWindow, event); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 1a50a4ffbc..e70a82154f 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -80,7 +80,7 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { if (size == 2 || size == 0) { realID = _container->getItem(id)->readUint16BE(); } - Common::BitStream32BEMSB stream(_container->getItem(realID)); + Common::BitStream32BEMSB stream(_container->getItem(realID), true); uint8 mode = stream.getBits(3); int w, h; @@ -367,7 +367,7 @@ uint ImageAsset::getWidth() { } uint ImageAsset::getHeight() { - return _bitWidth; + return _bitHeight; } void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 3187b39709..012c9a7341 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -96,7 +96,7 @@ Common::Error MacVentureEngine::run() { _filenames = new StringTable(this, _resourceManager, kFilenamesStringTableID); _decodingDirectArticles = new StringTable(this, _resourceManager, kCommonArticlesStringTableID); _decodingNamingArticles = new StringTable(this, _resourceManager, kNamingArticlesStringTableID); - _decodingDirectArticles = new StringTable(this, _resourceManager, kIndirectArticlesStringTableID); + _decodingIndirectArticles = new StringTable(this, _resourceManager, kIndirectArticlesStringTableID); // Big class instantiation _gui = new Gui(this, _resourceManager); @@ -783,6 +783,16 @@ bool MacVentureEngine::isObjSelected(ObjID objID) { return idx != -1; } +bool MacVentureEngine::isObjExit(ObjID objID) { + return _world->getObjAttr(objID, kAttrIsExit); +} + +Common::Point MacVentureEngine::getObjExitPosition(ObjID objID) { + uint x = _world->getObjAttr(objID, kAttrExitX); + uint y = _world->getObjAttr(objID, kAttrExitY); + return Common::Point(x, y); +} + Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { Common::Point pos = getObjPosition(objID); uint w = _gui->getObjWidth(objID); // This shouldn't go here diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 891fdb5ad6..c63864de20 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -204,6 +204,8 @@ public: bool isObjVisible(ObjID objID); bool isObjClickable(ObjID objID); bool isObjSelected(ObjID objID); + bool isObjExit(ObjID objID); + Common::Point getObjExitPosition(ObjID objID); // Encapsulation HACK Common::Rect getObjBounds(ObjID objID); -- cgit v1.2.3 From 8bee2a7b1c467a2b442cd0d8a35487ac9e963de9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 22:53:11 +0200 Subject: MACVENTURE: Add inventory callback --- engines/macventure/gui.cpp | 67 ++++++++++++++++++++++++++++----------- engines/macventure/gui.h | 3 ++ engines/macventure/macventure.cpp | 6 ++-- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index e1fb0beca3..04cc390546 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -726,6 +726,27 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { return nullptr; } +bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { + if (_assets.contains(obj) && + _engine->isObjClickable(obj) && + _engine->isObjVisible(obj)) { + Common::Rect bounds = _engine->getObjBounds(obj); + Common::Rect intersection = bounds.findIntersectingRect(target); + // We translate it to the image's coord system + intersection = Common::Rect( + intersection.left - bounds.left, + intersection.top - bounds.top, + intersection.left - bounds.left + intersection.width(), + intersection.top - bounds.top + intersection.height()); + + + if (_assets[obj]->isRectInside(intersection)) { + return true; + } + } + return false; +} + /* HANDLERS */ void Gui::handleMenuAction(MenuAction action) { @@ -955,23 +976,8 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; - if (_assets.contains(child) && - _engine->isObjClickable(child) && - _engine->isObjVisible(child)) { - Common::Rect bounds = _engine->getObjBounds(child); - Common::Rect intersection = bounds.findIntersectingRect(clickRect); - // We translate it to the image's coord system - intersection = Common::Rect( - intersection.left - bounds.left, - intersection.top - bounds.top, - intersection.left - bounds.left + intersection.width(), - intersection.top - bounds.top + intersection.height()); - - - if (_assets[child]->isRectInside(intersection)) { - // select the first object clicked - _engine->handleObjectSelect(child, kMainGameWindow, event); - } + if (isRectInsideObject(clickRect, child)) { + _engine->handleObjectSelect(child, kMainGameWindow, event); } } } @@ -1011,7 +1017,32 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (_engine->needsClickToContinue()) return true; - return false; + if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) { + + // Find the appropriate window + uint ref = 0; + uint i; + for (uint i = 0; i < _inventoryWindows.size(); i++) { + if (_inventoryWindows[i]->hasAllFocus()) { // HACK + ref = i; + } + } + + WindowData &data = findWindowData((WindowReference) ref); + ObjID child; + Common::Point pos; + // Click rect to local coordinates. We assume the click is inside the window ^ + int left = event.mouse.x - _inventoryWindows[i]->getDimensions().left; + int top = event.mouse.y - _inventoryWindows[i]->getDimensions().top; + Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight); + for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { + child = (*it).obj; + if (isRectInsideObject(clickRect, child)) { + _engine->handleObjectSelect(child, (WindowReference)ref, event); + } + } + } + return true; } /* Ugly switches */ diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 3569df7bbe..cd6fda7f72 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -245,6 +245,9 @@ private: // Methods WindowData& findWindowData(WindowReference reference); Graphics::MacWindow *findWindow(WindowReference reference); + // Utils + bool isRectInsideObject(Common::Rect target, ObjID obj); + }; class CommandButton { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 012c9a7341..a87da312dd 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -291,16 +291,14 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Comm if (event.kbd.flags & Common::KBD_SHIFT) { // Do shift ;) - } - else { + } else { if (_selectedControl && _currentSelection.size() > 0 && getInvolvedObjects() > 1) { if (objID == 0) selectPrimaryObject(windata.objRef); else selectPrimaryObject(objID); preparedToRun(); - } - else { + } else { if (objID == 0) { unselectAll(); //if (windata.type == kAnimateBack) { -- cgit v1.2.3 From 764d0ad0fed0dd4e65bd9f6b090fbb803666ba45 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 25 Jun 2016 23:20:28 +0200 Subject: MACVENTURE: Fix small script bug --- engines/macventure/gui.cpp | 4 ++-- engines/macventure/script.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 04cc390546..6f3680b321 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -34,8 +34,8 @@ namespace MacVenture { enum MenuAction; enum { - kCursorWidth = 4, // HACK Arbitrary width to test - kCursorHeight = 4 + kCursorWidth = 10, // HACK Arbitrary width to test + kCursorHeight = 10 }; enum { diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 2e283e4c15..cca144e2d8 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -593,6 +593,7 @@ void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { while (n) { val = state->peek(offs); state->push(val); + n--; } } -- cgit v1.2.3 From 08588eb6f914fc77aa443f3844681787bde02949 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 27 Jun 2016 19:10:49 +0200 Subject: MACVENTURE: Add first drag implementation --- engines/macventure/gui.cpp | 66 +++++++++++++++++++++++++++++++++++++++++----- engines/macventure/gui.h | 11 ++++++++ 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 6f3680b321..0b13923cb0 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -26,7 +26,7 @@ #include "macventure/macventure.h" #include "macventure/gui.h" -// TBDeleted +// For the dragged object #include "common/system.h" namespace MacVenture { @@ -94,6 +94,11 @@ void menuCommandsCallback(int action, Common::String &text, void *data); Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _engine = engine; _resourceManager = resman; + _windowData = nullptr; + _controlData = nullptr; + _draggedObj.id = 0; + _draggedObj.pos = Common::Point(0, 0); + initGUI(); } @@ -120,6 +125,8 @@ void Gui::draw() { _wm.draw(); + drawDraggedObject(); + //drawWindowTitle(kMainGameWindow, _mainGameWindow->getSurface()); } @@ -648,7 +655,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); - if (pos != forbidden || child < 600) { // Small HACK until I figre out where the last garbage child in main game window comes from + if (pos != forbidden && child < 600 && child != _draggedObj.id) { // Small HACK until I figre out where the last garbage child in main game window comes from if (!_assets.contains(child)) { _assets[child] = new ImageAsset(child, _graphics); } @@ -689,6 +696,30 @@ void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * sur Graphics::kTextAlignCenter); } +void Gui::drawDraggedObject() { + if (_draggedObj.id != 0) { + if (!_assets.contains(_draggedObj.id)) + _assets[_draggedObj.id] = new ImageAsset(_draggedObj.id, _graphics); + + ImageAsset *asset = _assets[_draggedObj.id]; + + _draggedSurface.create(asset->getWidth(), asset->getHeight(), _screen.format); + _screen.copyRectToSurface(_draggedSurface, _draggedObj.pos.x, _draggedObj.pos.y, + Common::Rect(asset->getWidth() - 1, asset->getHeight() - 1)); + + asset->blitInto(&_draggedSurface, 0, 0, kBlitOR); + + g_system->copyRectToScreen( + _draggedSurface.getPixels(), + _draggedSurface.pitch, + _draggedObj.pos.x, + _draggedObj.pos.y, + _draggedSurface.w, + _draggedSurface.h); + + } +} + WindowData & Gui::findWindowData(WindowReference reference) { assert(_windowData); @@ -747,6 +778,18 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { return false; } +void Gui::selectDraggable(ObjID child, Common::Point pos) { + if (_engine->isObjClickable(child)) { + _draggedObj.id = child; + _draggedObj.pos = pos; + } +} + +void Gui::handleDragRelease(Common::Point pos) { + _draggedObj.id = 0; + _engine->updateDelta(pos); +} + /* HANDLERS */ void Gui::handleMenuAction(MenuAction action) { @@ -919,10 +962,19 @@ uint Gui::getObjHeight(ObjID obj) { bool Gui::processEvent(Common::Event &event) { bool processed = false; - if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP) { - _engine->updateDelta(event.mouse); + if (event.type == Common::EVENT_MOUSEMOVE) { + if (_draggedObj.id != 0) { + _draggedObj.pos = event.mouse; + } processed = true; } + else if (event.type == Common::EVENT_LBUTTONUP) { + if (_draggedObj.id != 0) { + handleDragRelease(event.mouse); + } + processed = true; + } + processed |= _wm.processEvent(event); return (processed); } @@ -966,7 +1018,7 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e if (_engine->needsClickToContinue()) return true; - if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) { + if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { WindowData &data = findWindowData(kMainGameWindow); ObjID child; Common::Point pos; @@ -977,6 +1029,7 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; if (isRectInsideObject(clickRect, child)) { + selectDraggable(child, event.mouse); _engine->handleObjectSelect(child, kMainGameWindow, event); } } @@ -1017,7 +1070,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (_engine->needsClickToContinue()) return true; - if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) { + if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { // Find the appropriate window uint ref = 0; @@ -1038,6 +1091,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; if (isRectInsideObject(clickRect, child)) { + selectDraggable(child, event.mouse); _engine->handleObjectSelect(child, (WindowReference)ref, event); } } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index cd6fda7f72..9d48d6320b 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -144,6 +144,11 @@ struct BorderBounds { BorderBounds(uint16 l, uint16 t, uint16 r, uint16 b) : leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} }; +struct DraggedObj { + ObjID id; + Common::Point pos; +}; + class Gui { @@ -216,6 +221,9 @@ private: // Attributes Container *_graphics; Common::HashMap _assets; + Graphics::ManagedSurface _draggedSurface; + DraggedObj _draggedObj; + private: // Methods // Initializers @@ -238,6 +246,7 @@ private: // Methods void drawInventories(); void drawExitsWindow(); + void drawDraggedObject(); void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface); void drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface); @@ -247,6 +256,8 @@ private: // Methods // Utils bool isRectInsideObject(Common::Rect target, ObjID obj); + void selectDraggable(ObjID child, Common::Point pos); + void handleDragRelease(Common::Point pos); }; -- cgit v1.2.3 From 0485483254e9ce94acfd4750122a466984227904 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 28 Jun 2016 20:56:55 +0200 Subject: MACVENTURE: Minor fixes and skull rising --- engines/macventure/container.h | 13 ++++++------- engines/macventure/gui.cpp | 37 +++++++++++++++++++++++-------------- engines/macventure/gui.h | 1 + engines/macventure/image.cpp | 4 ++-- engines/macventure/macventure.cpp | 14 ++++++++------ engines/macventure/macventure.h | 2 +- engines/macventure/script.cpp | 27 ++++++++++++++++++++++----- engines/macventure/script.h | 2 +- engines/macventure/stringtable.h | 9 +++++++-- engines/macventure/world.cpp | 3 +-- 10 files changed, 72 insertions(+), 40 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 440c0cb977..f0094a786b 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -173,12 +173,9 @@ public: /** * getItemByteSize should be called before this one */ - Common::SeekableReadStream *getItem(uint32 id) { - _res->seek(0); - Common::SeekableReadStream *res = _res->readStream(_res->size()); + Common::SeekableReadStream *getItem(uint32 id) { if (_simplified) { - res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); - return res; + _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); } else { uint32 groupID = (id >> 6); uint32 objectIndex = id & 0x3f; // Index within the group @@ -188,10 +185,12 @@ public: offset += _groups[groupID].lengths[i]; } - res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); + _res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); - return res; } + + Common::SeekableReadStream *res = _res->readStream(getItemByteSize(id) * 2); + return res; } protected: diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 0b13923cb0..c8f6b3bf62 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -34,8 +34,8 @@ namespace MacVenture { enum MenuAction; enum { - kCursorWidth = 10, // HACK Arbitrary width to test - kCursorHeight = 10 + kCursorWidth = 2, // HACK Arbitrary width to test + kCursorHeight = 2 }; enum { @@ -126,7 +126,7 @@ void Gui::draw() { _wm.draw(); drawDraggedObject(); - + //drawWindowTitle(kMainGameWindow, _mainGameWindow->getSurface()); } @@ -202,8 +202,8 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array ObjID child = children[i]; if (ref != kMainGameWindow) { Common::Point childPos = _engine->getObjPosition(child); - originx = originx > childPos.x ? childPos.x : originx; - originy = originy > childPos.y ? childPos.y : originy; + originx = originx > (uint)childPos.x ? (uint)childPos.x : originx; + originy = originy > (uint)childPos.y ? (uint)childPos.y : originy; } data.children.push_back(DrawableObject(child, kBlitBIC)); } @@ -362,7 +362,7 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool } void Gui::loadGraphics() { - _graphics = new Container("Shadowgate II/Shadow Graphic"); + _graphics = new Container(_engine->getFilePath(kGraphicPathID).c_str()); } bool Gui::loadMenus() { @@ -616,11 +616,11 @@ void Gui::drawExitsWindow() { WindowData &objData = findWindowData(kMainGameWindow); Common::Point pos; ObjID child; - BlitMode mode; + //BlitMode mode; Common::Rect exit; for (uint i = 0; i < objData.children.size(); i++) { child = objData.children[i].obj; - mode = (BlitMode)objData.children[i].mode; + //mode = (BlitMode)objData.children[i].mode; pos = _engine->getObjExitPosition(child); pos.x += border.leftOffset; pos.y += border.topOffset; @@ -788,6 +788,13 @@ void Gui::selectDraggable(ObjID child, Common::Point pos) { void Gui::handleDragRelease(Common::Point pos) { _draggedObj.id = 0; _engine->updateDelta(pos); + _engine->preparedToRun(); +} + +Common::Rect Gui::calculateClickRect(Common::Point clickPos, Common::Rect windowBounds) { + int left = clickPos.x - windowBounds.left; + int top = clickPos.y - windowBounds.top; + return Common::Rect(left - kCursorWidth, top - kCursorHeight, left + kCursorWidth, top + kCursorHeight); } @@ -967,6 +974,12 @@ bool Gui::processEvent(Common::Event &event) { _draggedObj.pos = event.mouse; } processed = true; + + // TEST + Common::Rect mr = calculateClickRect(event.mouse, _screen.getBounds()); + _screen.fillRect(mr, kColorGreen); + g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h); + g_system->updateScreen(); } else if (event.type == Common::EVENT_LBUTTONUP) { if (_draggedObj.id != 0) { @@ -1023,9 +1036,7 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e ObjID child; Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ - int left = event.mouse.x - _mainGameWindow->getDimensions().left; - int top = event.mouse.y - _mainGameWindow->getDimensions().top; - Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight); + Common::Rect clickRect = calculateClickRect(event.mouse, _mainGameWindow->getDimensions()); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; if (isRectInsideObject(clickRect, child)) { @@ -1085,9 +1096,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { ObjID child; Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ - int left = event.mouse.x - _inventoryWindows[i]->getDimensions().left; - int top = event.mouse.y - _inventoryWindows[i]->getDimensions().top; - Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight); + Common::Rect clickRect = calculateClickRect(event.mouse, _inventoryWindows[i]->getDimensions()); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; if (isRectInsideObject(clickRect, child)) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 9d48d6320b..73c4318408 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -258,6 +258,7 @@ private: // Methods bool isRectInsideObject(Common::Rect target, ObjID obj); void selectDraggable(ObjID child, Common::Point pos); void handleDragRelease(Common::Point pos); + Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); }; diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index e70a82154f..d880e142bb 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -192,9 +192,9 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st blank = 2 - (blank >> 1); } - uint pos = 0; + uint16 pos = 0; for (uint y = 0; y < _bitHeight; y++) { - uint x = 0; + uint16 x = 0; for (; x < _bitWidth >> 3; x++) { byte hi = walkHuff(huff, stream) << 4; data[pos++] = walkHuff(huff, stream) | hi; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index a87da312dd..8624159a95 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -537,15 +537,17 @@ uint MacVentureEngine::getPrefixNdx(ObjID obj) { } Common::String MacVentureEngine::getPrefixString(uint flag, ObjID obj) { - uint ndx = _world->getObjAttr(obj, kAttrPrefixes); // HACK should check the type of that one + uint ndx = getPrefixNdx(obj); ndx = ((ndx) >> flag) & 3; if (ndx) { - return (*_decodingNamingArticles->getStrings())[ndx]; + return _decodingNamingArticles->getString(ndx); + } else { + return Common::String("missigno "); } } Common::String MacVentureEngine::getNoun(ObjID ndx) { - return (*_decodingIndirectArticles->getStrings())[ndx]; + return _decodingIndirectArticles->getString(ndx); } void MacVentureEngine::highlightExit(ObjID objID) { @@ -740,11 +742,11 @@ Common::String MacVentureEngine::getCommandsPausedString() const { } Common::String MacVentureEngine::getFilePath(FilePathID id) const { - const Common::Array *names = _filenames->getStrings(); + const Common::Array &names = _filenames->getStrings(); if (id <= 3) { // We don't want a file in the subdirectory - return Common::String((*names)[id]); + return Common::String(names[id]); } else { // We want a game file - return Common::String((*names)[3] + "/" + (*names)[id]); + return Common::String(names[3] + "/" + names[id]); } } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index c63864de20..28c3bf9ad3 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -175,7 +175,7 @@ public: void enqueueObject(ObjectQueueID type, ObjID objID, ObjID target = 0); void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text); - + void runObjQueue(); bool printTexts(); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index cca144e2d8..cc9474e6d4 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -84,6 +84,7 @@ bool ScriptEngine::execFrame(bool execAll) { else { fail = resumeFunc(frame); } if (fail) { frame->haltedInFirst = true; + _engine->preparedToRun(); return true; } doFamily = true; @@ -101,6 +102,7 @@ bool ScriptEngine::execFrame(bool execAll) { if (fail) { // We are stuck, so we don't shift the frame frame->haltedInFamily = true; frame->familyIdx = i; + _engine->preparedToRun(); return true; } doFamily = true; @@ -112,6 +114,7 @@ bool ScriptEngine::execFrame(bool execAll) { frame->haltedInSaves = false; if (resumeFunc(frame)) { frame->haltedInSaves = true; + _engine->preparedToRun(); return true; } } @@ -131,6 +134,7 @@ bool ScriptEngine::execFrame(bool execAll) { frame->saves[localHigh].rank = 0; if (loadScript(frame, frame->saves[localHigh].func)) { frame->haltedInSaves = true; + _engine->preparedToRun(); return true; } } @@ -352,7 +356,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opbbFORK(state, frame); break; case 0xbc: //call - opbcCALL(state, frame, script); + if (opbcCALL(state, frame, script)) + return true; break; case 0xbd: //focus object opbdFOOB(state, frame); @@ -907,11 +912,12 @@ void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { _frames.push_back(newframe); } -void ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { +bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; - loadScript(frame, id); + if (loadScript(frame, id)) + return true; frame->scripts.pop_front(); script = frame->scripts.front(); debug(3, "SCRIPT: Return from fuction %d", id); @@ -987,12 +993,23 @@ void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { - for (uint i = 0; i < 6; i++) // Dummy + for (uint i = 0; i < 3; i++) // We skip year, month and date state->push(0x00); - op00NOOP(0xca); + + uint32 totalPlayTime = _engine->getTotalPlayTime() / 1000; // In seconds + word hours = totalPlayTime / 3600; + totalPlayTime %= 3600; + state->push(hours); + word minutes = totalPlayTime / 60; + totalPlayTime %= 60; + state->push(minutes); + state->push(totalPlayTime); + debug("Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); + } void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { + // Probaby irrelevant, so we push Day [9] state->push(9); } diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 1a143cffd0..acbffcd315 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -240,7 +240,7 @@ private: void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority void opbaCRAN(EngineState *state, EngineFrame *frame); //cancel priority range void opbbFORK(EngineState *state, EngineFrame *frame); //fork - void opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script); //call + bool opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script); //call void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects void opbfSNOB(EngineState *state, EngineFrame *frame); //snap object diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index 87ec9775cb..ffb9d375ab 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -52,8 +52,13 @@ public: } - const Common::Array *getStrings() { - return &_strings; + const Common::Array &getStrings() { + return _strings; + } + + Common::String getString(uint ndx) { + assert(ndx < _strings.size()); + return _strings[ndx]; } private: diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 02d388ab5f..8e83f91057 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -23,8 +23,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); calculateObjectRelations(); - warning("Test functions about to happen"); - _gameText = new Container("Shadowgate II/Shadow Text"); + _gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); delete saveGameRes; saveGameFile.close(); -- cgit v1.2.3 From 680790acaa8dca81e66e21da58d91054f983e8ec Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 28 Jun 2016 21:03:24 +0200 Subject: MACVENTURE: Add proper capitalization --- engines/macventure/text.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index d3fc956b93..cf7402822d 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -203,8 +203,12 @@ Common::String TextAsset::getNoun(ObjID subval) { break; } } - if (name.size() && (subval & 4)) - name.toUppercase(); // HACK, should only capitalize first char? + if (name.size() && (subval & 4)) { + Common::String tmp = name; + name.toUppercase(); + name.replace(1, name.size() - 1, tmp, 1, tmp.size() - 1); + } + return name; } -- cgit v1.2.3 From 246fec28f55ca646a77985cd7b95a33b2cae994d Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 28 Jun 2016 21:10:12 +0200 Subject: MACVENTURE: Fix minor object drawing bug --- engines/macventure/gui.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index c8f6b3bf62..7cae246ab1 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -126,7 +126,7 @@ void Gui::draw() { _wm.draw(); drawDraggedObject(); - + //drawWindowTitle(kMainGameWindow, _mainGameWindow->getSurface()); } @@ -649,13 +649,12 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * if (data.children.size() == 0) return; - Common::Point forbidden(0, 0); for (uint i = 0; i < data.children.size(); i++) { child = data.children[i].obj; mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); - if (pos != forbidden && child < 600 && child != _draggedObj.id) { // Small HACK until I figre out where the last garbage child in main game window comes from + if (child < 600 && child != _draggedObj.id) { // Small HACK until I figre out where the last garbage child in main game window comes from if (!_assets.contains(child)) { _assets[child] = new ImageAsset(child, _graphics); } -- cgit v1.2.3 From 517aceefcb397ccda476dc7e2b02d6da5595e4fd Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 30 Jun 2016 08:41:25 +0200 Subject: MACVENTURE: Add scene transition --- engines/macventure/gui.cpp | 280 +++++++++++++++++++++++--------------- engines/macventure/gui.h | 32 +++-- engines/macventure/image.cpp | 8 +- engines/macventure/macventure.cpp | 44 +++++- engines/macventure/macventure.h | 5 +- engines/macventure/world.cpp | 14 +- 6 files changed, 246 insertions(+), 137 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 7cae246ab1..15d573b6a8 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -110,12 +110,42 @@ Gui::~Gui() { if (_controlData) delete _controlData; + if (_exitsData) + delete _exitsData; + Common::HashMap::const_iterator it = _assets.begin(); for (; it != _assets.end(); it++) { delete it->_value; } } +void Gui::initGUI() { + _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); + _wm.setScreen(&_screen); + + // Menu + _menu = _wm.addMenu(); + if (!loadMenus()) + error("Could not load menus"); + _menu->setCommandsCallback(menuCommandsCallback, this); + _menu->calcDimensions(); + + loadGraphics(); + + if (!loadWindows()) + error("Could not load windows"); + + initWindows(); + + assignObjReferences(); + + if (!loadControls()) + error("Could not load controls"); + + draw(); + +} + void Gui::draw() { // Will be performance-improved after the milestone @@ -138,15 +168,11 @@ void Gui::drawTitle() { warning("drawTitle hasn't been tested yet"); } -void Gui::drawExit(ObjID id) { - findWindowData(kExitsWindow).children.push_back(DrawableObject(id, kBlitDirect)); -} - void Gui::clearControls() { if (!_controlData) return; - Common::List::iterator it = _controlData->begin(); + Common::Array::iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { it->unselect(); } @@ -228,33 +254,6 @@ void Gui::removeChild(WindowReference target, ObjID child) { data.children.remove_at(index); } -void Gui::initGUI() { - _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); - _wm.setScreen(&_screen); - - // Menu - _menu = _wm.addMenu(); - if (!loadMenus()) - error("Could not load menus"); - _menu->setCommandsCallback(menuCommandsCallback, this); - _menu->calcDimensions(); - - loadGraphics(); - - if (!loadWindows()) - error("Could not load windows"); - - initWindows(); - - assignObjReferences(); - - if (!loadControls()) - error("Could not load controls"); - - draw(); - -} - void Gui::initWindows() { // Game Controls Window @@ -282,7 +281,7 @@ void Gui::initWindows() { loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); // Self Window - _selfWindow = _wm.addWindow(false, true, true); + _selfWindow = _wm.addWindow(false, true, false); _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); @@ -290,7 +289,7 @@ void Gui::initWindows() { loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); // Exits Window - _exitsWindow = _wm.addWindow(false, true, true); + _exitsWindow = _wm.addWindow(false, false, false); _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); @@ -475,7 +474,8 @@ bool Gui::loadControls() { Common::SeekableReadStream *res; Common::MacResIDArray::const_iterator iter; - _controlData = new Common::List(); + _controlData = new Common::Array(); + _exitsData = new Common::Array(); if ((resArray = _resourceManager->getResIDArray(MKTAG('C', 'N', 'T', 'L'))).size() == 0) return false; @@ -541,7 +541,7 @@ void Gui::drawCommandsWindow() { kColorBlack, Graphics::kTextAlignCenter); } else { - Common::List::const_iterator it = _controlData->begin(); + Common::Array::const_iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { CommandButton button = *it; if (button.getData().refcon != kControlExitBox) @@ -553,22 +553,22 @@ void Gui::drawCommandsWindow() { void Gui::drawMainGameWindow() { const WindowData &data = getWindowData(kMainGameWindow); BorderBounds border = borderBounds(data.type); + ObjID objRef = data.objRef; _mainGameWindow->setDirty(true); - //if (data.titleLength > 0) - // drawWindowTitle(kMainGameWindow, srf); - - if (!_assets.contains(3)) { - _assets[3] = new ImageAsset(3, _graphics); - } + if (data.objRef > 0 && data.objRef < 2000) { + if (!_assets.contains(objRef)) { + _assets[objRef] = new ImageAsset(objRef, _graphics); + } - _assets[3]->blitInto( - _mainGameWindow->getSurface(), - border.leftOffset, - border.topOffset, - kBlitDirect); + _assets[objRef]->blitInto( + _mainGameWindow->getSurface(), + border.leftOffset, + border.topOffset, + kBlitDirect); + } drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); findWindow(kMainGameWindow)->setDirty(true); @@ -603,34 +603,20 @@ void Gui::drawInventories() { } void Gui::drawExitsWindow() { - WindowData &data = findWindowData(kExitsWindow); - BorderBounds border = borderBounds(data.type); + Graphics::ManagedSurface *srf = _exitsWindow->getSurface(); + BorderBounds border = borderBounds(getWindowData(kExitsWindow).type); + srf->fillRect(Common::Rect( border.leftOffset, border.topOffset, srf->w + border.rightOffset, srf->h + border.bottomOffset), kColorWhite); - // For each obj in the main window, if it is an exit, we draw it - WindowData &objData = findWindowData(kMainGameWindow); - Common::Point pos; - ObjID child; - //BlitMode mode; - Common::Rect exit; - for (uint i = 0; i < objData.children.size(); i++) { - child = objData.children[i].obj; - //mode = (BlitMode)objData.children[i].mode; - pos = _engine->getObjExitPosition(child); - pos.x += border.leftOffset; - pos.y += border.topOffset; - exit = Common::Rect(pos.x, pos.y, pos.x + kExitButtonWidth, pos.y + kExitButtonHeight); - if (_engine->isObjExit(child)) { - if (_engine->isObjSelected(child)) - srf->fillRect(exit, kColorGreen); - - srf->fillRect(exit, kColorGreen); - } + Common::Array::const_iterator it = _exitsData->begin(); + for (; it != _exitsData->end(); ++it) { + CommandButton button = *it; + button.draw(*_exitsWindow->getSurface()); } findWindow(kExitsWindow)->setDirty(true); @@ -719,6 +705,92 @@ void Gui::drawDraggedObject() { } } + +void Gui::updateWindow(WindowReference winID, bool containerOpen) { + if (winID == kSelfWindow || containerOpen) { + WindowData &data = findWindowData(winID); + if (winID == kCommandsWindow) { + Common::Array::iterator it = _controlData->begin(); + for (; it != _controlData->end(); ++it) { + it->unselect(); + } + } + Common::Array &children = data.children; + for (uint i = 0; i < children.size(); i++) { + uint flag = 0; + ObjID child = children[i].obj; + BlitMode mode = kBlitDirect; + bool off = !_engine->isObjVisible(child); + if (flag || !off || !_engine->isObjClickable(child)) { + mode = kBlitBIC; + if (off || flag) { + mode = kBlitXOR; + } + else if (_engine->isObjSelected(child)) { + mode = kBlitOR; + } + children[i] = DrawableObject(child, mode); + } + else { + children[i] = DrawableObject(child, kBlitXOR); + } + } + if (winID == kMainGameWindow) { + drawMainGameWindow(); + } + else { + Graphics::MacWindow *winRef = findWindow(winID); + winRef->getSurface()->fillRect(data.bounds, kColorGray); + } + if (data.type == kZoomDoc && data.updateScroll) { + warning("Unimplemented: update scroll"); + } + } +} + +void Gui::unselectExits() { + Common::Array::const_iterator it = _exitsData->begin(); + for (; it != _exitsData->end(); ++it) { + CommandButton button = *it; + button.unselect(); + } +} + +void Gui::updateExit(ObjID obj) { + if (!_engine->isObjExit(obj)) return; + + BorderBounds border = borderBounds(getWindowData(kExitsWindow).type); + + int ctl = -1; + int i = 0; + Common::Array::const_iterator it = _exitsData->begin(); + for (;it != _exitsData->end(); it++) { + if (it->getData().refcon == obj) + ctl = i; + else + i++; + } + + if (ctl != -1) + _exitsData->remove_at(ctl); + + if (!_engine->isHiddenExit(obj) && + _engine->getParent(obj) == _engine->getParent(1)) + { + ControlData data; + data.titleLength = 0; + data.refcon = obj; + Common::Point pos = _engine->getObjExitPosition(obj); + pos.x = border.leftOffset; + pos.y = border.topOffset; + data.bounds = Common::Rect(pos.x, pos.y, pos.x + kExitButtonWidth, pos.y + kExitButtonHeight); + data.visible = true; + + _exitsData->push_back(CommandButton(data, this)); + } +} + + WindowData & Gui::findWindowData(WindowReference reference) { assert(_windowData); @@ -894,46 +966,6 @@ void menuCommandsCallback(int action, Common::String &text, void *data) { g->handleMenuAction((MenuAction)action); } -void Gui::updateWindow(WindowReference winID, bool containerOpen) { - if (winID == kNoWindow) return; - if (winID == kSelfWindow || containerOpen) { - WindowData &data = findWindowData(winID); - if (winID == kCommandsWindow) { - Common::List::iterator it = _controlData->begin(); - for (; it != _controlData->end(); ++it) { - it->unselect(); - } - } - Common::Array &children = data.children; - for (uint i = 0; i < children.size(); i++) { - uint flag = 0; - ObjID child = children[i].obj; - BlitMode mode = kBlitDirect; - bool off = !_engine->isObjVisible(child); - if (flag || !off || !_engine->isObjClickable(child)) { - mode = kBlitBIC; - if (off || flag) { - mode = kBlitXOR; - } else if (_engine->isObjSelected(child)) { - mode = kBlitOR; - } - children[i] = DrawableObject(child, mode); - } else { - children[i] = DrawableObject(child, kBlitXOR); - } - } - if (winID == kMainGameWindow) { - drawMainGameWindow(); - } - else { - Graphics::MacWindow *winRef = findWindow(winID); - winRef->getSurface()->fillRect(data.bounds, kColorGray); - } - if (data.type == kZoomDoc && data.updateScroll) { - warning("Unimplemented: update scroll"); - } - } -} void Gui::invertWindowColors(WindowReference winID) { Graphics::ManagedSurface *srf = findWindow(winID)->getSurface(); @@ -1006,7 +1038,7 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (!_controlData) return false; - Common::List::iterator it = _controlData->begin(); + Common::Array::iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { if (it->isInsideBounds(position)) { it->select(); @@ -1064,8 +1096,32 @@ bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event } bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & event) { - if (_engine->needsClickToContinue()) - return true; + if (event.type == Common::EVENT_LBUTTONUP) { + if (_engine->needsClickToContinue()) { + return true; + } + + Common::Point position( + event.mouse.x - _exitsWindow->getDimensions().left, + event.mouse.y - _exitsWindow->getDimensions().top); + + CommandButton data; + if (!_exitsData) + return false; + + Common::Array::iterator it = _exitsData->begin(); + for (; it != _exitsData->end(); ++it) { + if (it->isInsideBounds(position)) { + it->select(); + data = *it; + } + else { + it->unselect(); + } + } + + _engine->handleObjectSelect(data.getData().refcon, kExitsWindow, event); + } return getWindowData(kExitsWindow).visible; } @@ -1118,7 +1174,7 @@ BorderBounds Gui::borderBounds(MVWindowType type) { case MacVenture::kPlainDBox: return BorderBounds(6, 6, 6, 6); case MacVenture::kAltBox: - //return BorderBounds(8, 9, 11, 10); // For now, I'll stick to the original bmp, it's gorgeous + return BorderBounds(8, 9, 11, 10); // For now, I'll stick to the original bmp, it's gorgeous break; case MacVenture::kNoGrowDoc: return BorderBounds(1, 17, 1, 1); diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 73c4318408..dd08173d3c 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -129,7 +129,7 @@ struct ControlData { uint16 scrollMax; uint16 scrollMin; uint16 cdef; - uint32 refcon; + uint32 refcon; // If exits window, then the obj id. Otherwise, the control type uint8 titleLength; char* title; uint16 border; @@ -159,7 +159,7 @@ public: void draw(); void drawMenu(); void drawTitle(); - void drawExit(ObjID id); + void clearControls(); bool processEvent(Common::Event &event); void handleMenuAction(MenuAction action); @@ -195,6 +195,9 @@ public: void addChild(WindowReference target, ObjID child); void removeChild(WindowReference target, ObjID child); + void unselectExits(); + void updateExit(ObjID id); + // Ugly switches BorderBounds borderBounds(MVWindowType type); @@ -207,7 +210,8 @@ private: // Attributes Graphics::MacWindowManager _wm; Common::List *_windowData; - Common::List *_controlData; + Common::Array *_controlData; + Common::Array *_exitsData; Graphics::MacWindow *_controlsWindow; Graphics::MacWindow *_mainGameWindow; @@ -290,16 +294,18 @@ public: surface.fillRect(_data.bounds, colorFill); surface.frameRect(_data.bounds, kColorBlack); - const Graphics::Font &font = _gui->getCurrentFont(); - Common::String title(_data.title); - font.drawString( - &surface, - title, - _data.bounds.left, - _data.bounds.top, - _data.bounds.right - _data.bounds.left, - colorText, - Graphics::kTextAlignCenter); + if (_data.titleLength > 0) { + const Graphics::Font &font = _gui->getCurrentFont(); + Common::String title(_data.title); + font.drawString( + &surface, + title, + _data.bounds.left, + _data.bounds.top, + _data.bounds.right - _data.bounds.left, + colorText, + Graphics::kTextAlignCenter); + } } bool isInsideBounds(const Common::Point point) const { diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index d880e142bb..1aae1727ef 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -77,7 +77,13 @@ ImageAsset::~ImageAsset() { void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { ObjID realID = id; uint32 size = _container->getItemByteSize(id); - if (size == 2 || size == 0) { + if (size < 2) { + _rowBytes = 0; + _bitHeight = 0; + _bitHeight = 0; + return; + } + if (size == 2) { realID = _container->getItem(id)->readUint16BE(); } Common::BitStream32BEMSB stream(_container->getItem(realID), true); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 8624159a95..08b5ec90c1 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -174,7 +174,7 @@ void MacVentureEngine::requestUnpause() { void MacVentureEngine::selectControl(ControlReference id) { ControlAction action = referenceToAction(id); - debug(4, "Select control %x", action); + debug(2, "Select control %x", action); _selectedControl = action; } @@ -190,7 +190,7 @@ void MacVentureEngine::activateCommand(ControlReference id) { _activeControl = kNoCommand; _activeControl = action; } - debug(4, "Activating Command %x... Command %x is active", action, _activeControl); + debug(2, "Activating Command %x... Command %x is active", action, _activeControl); refreshReady(); } @@ -520,6 +520,17 @@ void MacVentureEngine::unselectObject(ObjID objID) { } } + +void MacVentureEngine::updateExits() { + // exitWin.killControls(); + _gui->unselectExits(); + + Common::Array exits = _world->getChildren(_world->getObjAttr(1, kAttrParentObject), true); + for (uint i = 0; i < exits.size(); i++) + _gui->updateExit(exits[i]); + +} + int MacVentureEngine::findObjectInArray(ObjID objID, const Common::Array &list) { // Find the object in the current selection bool found = false; @@ -542,7 +553,7 @@ Common::String MacVentureEngine::getPrefixString(uint flag, ObjID obj) { if (ndx) { return _decodingNamingArticles->getString(ndx); } else { - return Common::String("missigno "); + return Common::String("m1551gn0 "); } } @@ -551,7 +562,20 @@ Common::String MacVentureEngine::getNoun(ObjID ndx) { } void MacVentureEngine::highlightExit(ObjID objID) { - warning("highlightExit: unimplemented"); + //ObjID ctl = _gui->getWinChild(obj); + /*if (ctl) { + if (findObjectInArray(obj, _selectedObjs) != -1) + _gui->selectExit(ctl); + else + _gui->unselectExit(ctl); + } + if (obj == _world->getObjAttr(1, kAttrParentObject)) { + if (findObjectInArray(obj, _selectedObjs) != -1) + _gui->selectExit(obj); + else + _gui->unselectExit(obj); + }*/ + //updateWindow(findParentWindow(obj)); } void MacVentureEngine::selectPrimaryObject(ObjID objID) { @@ -587,7 +611,7 @@ void MacVentureEngine::openObject(ObjID objID) { if (objID == _world->getObjAttr(1, kAttrParentObject)) { _gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true)); _gui->updateWindow(kMainGameWindow, _world->getObjAttr(objID, kAttrContainerOpen)); - //_gui->drawExits(); + updateExits(); _gui->setWindowTitle(kMainGameWindow, _world->getText(objID, objID, objID)); // it ignores source and target in the original } else { // Open inventory window Common::Point p(_world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); @@ -649,7 +673,7 @@ void MacVentureEngine::checkObject(QueuedObject old) { old.hidden != _world->getObjAttr(id, kAttrHiddenExit) || old.exitx != _world->getObjAttr(id, kAttrExitX) || old.exity != _world->getObjAttr(id, kAttrExitY)) - _gui->drawExit(id); + _gui->updateExit(id); } WindowReference win = getObjWindow(id); ObjID cur = id; @@ -787,12 +811,20 @@ bool MacVentureEngine::isObjExit(ObjID objID) { return _world->getObjAttr(objID, kAttrIsExit); } +bool MacVentureEngine::isHiddenExit(ObjID objID) { + return _world->getObjAttr(objID, kAttrHiddenExit); +} + Common::Point MacVentureEngine::getObjExitPosition(ObjID objID) { uint x = _world->getObjAttr(objID, kAttrExitX); uint y = _world->getObjAttr(objID, kAttrExitY); return Common::Point(x, y); } +ObjID MacVentureEngine::getParent(ObjID objID) { + return _world->getObjAttr(objID, kAttrParentObject); +} + Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { Common::Point pos = getObjPosition(objID); uint w = _gui->getObjWidth(objID); // This shouldn't go here diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 28c3bf9ad3..9ecfbc0fd7 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -205,7 +205,10 @@ public: bool isObjClickable(ObjID objID); bool isObjSelected(ObjID objID); bool isObjExit(ObjID objID); + bool isHiddenExit(ObjID objID); Common::Point getObjExitPosition(ObjID objID); + ObjID getParent(ObjID objID); + // Encapsulation HACK Common::Rect getObjBounds(ObjID objID); @@ -232,7 +235,7 @@ private: void unselectObject(ObjID objID); void highlightExit(ObjID objID); void selectPrimaryObject(ObjID objID); - + void updateExits(); // Object queue methods void focusObjectWindow(ObjID objID); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 8e83f91057..670f39902c 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -43,17 +43,23 @@ World::~World() { uint32 World::getObjAttr(ObjID objID, uint32 attrID) { uint32 res; uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; + // HACK, but if I try to initialize it in the else clause, it goes out of scope and segfaults + Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); if (!(index & 0x80)) { // It's not a constant res = _saveGame->getAttr(objID, index); } else { - Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); index &= 0x7F; - objStream->skip((index * 2) - 1); - res = objStream->readUint16BE(); + if (objStream->size() == 0) return 0; + // Look for the right attribute inside the object + objStream->skip(index * 2); + res = objStream->readByte() << 8; + res |= objStream->readByte(); } res &= _engine->getGlobalSettings().attrMasks[attrID]; res >>= _engine->getGlobalSettings().attrShifts[attrID]; - debug(11, "Attribute %x from object %x is %x", attrID, objID, res); + if (res & 0x8000) + res = -((res ^ 0xffff) + 1); + debug(3, "Attribute %x from object %x is %x", attrID, objID, res); return res; } -- cgit v1.2.3 From 03a9ad4899f19de262a9eed6c9c50219ba44d466 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 30 Jun 2016 09:36:04 +0200 Subject: MACVENTURE: Fix game detection --- engines/macventure/detection_tables.h | 4 ++-- engines/macventure/gui.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h index 08093da57d..e2e94261bb 100644 --- a/engines/macventure/detection_tables.h +++ b/engines/macventure/detection_tables.h @@ -22,12 +22,12 @@ namespace MacVenture { -#define ADGF_DEFAULT (ADGF_DROPLANGUAGE|ADGF_DROPPLATFORM) +#define ADGF_DEFAULT (ADGF_DROPLANGUAGE|ADGF_DROPPLATFORM|ADGF_MACRESFORK) #define BASEGAME(n, v, f, md5, s) {n, v, AD_ENTRY1s(f, md5, s), Common::EN_ANY, Common::kPlatformMacintosh, ADGF_DEFAULT, GUIO0()} static const ADGameDescription gameDescriptions[] = { - BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "dea09e16829b99278feb84c121066576", 70528), // Zojoi Rerelease + BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "ebbfbcbf93938bd2900cb0c0213b19ad", 68974), // Zojoi Rerelease AD_TABLE_END_MARKER }; } // End of namespace MacVenture diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 15d573b6a8..3d38be508b 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1174,7 +1174,7 @@ BorderBounds Gui::borderBounds(MVWindowType type) { case MacVenture::kPlainDBox: return BorderBounds(6, 6, 6, 6); case MacVenture::kAltBox: - return BorderBounds(8, 9, 11, 10); // For now, I'll stick to the original bmp, it's gorgeous + return BorderBounds(8, 9, 11, 10); break; case MacVenture::kNoGrowDoc: return BorderBounds(1, 17, 1, 1); -- cgit v1.2.3 From 9403ef720a40ce47688b1957d1a64bc91c87df0a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 30 Jun 2016 16:57:14 +0200 Subject: MACVENTURE: Fix clicks and dragging offset --- engines/macventure/gui.cpp | 50 ++++++++++++++++++++++++++------------- engines/macventure/gui.h | 5 +++- engines/macventure/macventure.cpp | 5 +++- engines/macventure/macventure.h | 2 +- engines/macventure/world.cpp | 2 +- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 3d38be508b..8f8acda6dd 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -639,6 +639,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * child = data.children[i].obj; mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); + pos += Common::Point(border.leftOffset, border.topOffset); if (child < 600 && child != _draggedObj.id) { // Small HACK until I figre out where the last garbage child in main game window comes from if (!_assets.contains(child)) { @@ -647,16 +648,20 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * _assets[child]->blitInto( surface, - border.leftOffset + pos.x, - border.topOffset + pos.y, + pos.x, + pos.y, mode); if (_engine->isObjSelected(child)) _assets[child]->blitInto( - surface, - border.leftOffset + pos.x, - border.topOffset + pos.y, - kBlitOR); + surface, pos.x, pos.y, kBlitOR); + + // For test + surface->frameRect(Common::Rect( + pos.x, + pos.y, + pos.x + _assets[child]->getWidth(), + pos.y + _assets[child]->getHeight()), kColorGreen); } } @@ -791,6 +796,12 @@ void Gui::updateExit(ObjID obj) { } +Common::Point Gui::getWindowSurfacePos(WindowReference reference) { + const WindowData &data = getWindowData(reference); + BorderBounds border = borderBounds(data.type); + return Common::Point(data.bounds.left + border.leftOffset, data.bounds.top + border.topOffset); +} + WindowData & Gui::findWindowData(WindowReference reference) { assert(_windowData); @@ -830,8 +841,9 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { if (_assets.contains(obj) && - _engine->isObjClickable(obj) && - _engine->isObjVisible(obj)) { + //_engine->isObjClickable(obj) && + _engine->isObjVisible(obj)) + { Common::Rect bounds = _engine->getObjBounds(obj); Common::Rect intersection = bounds.findIntersectingRect(target); // We translate it to the image's coord system @@ -849,16 +861,20 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { return false; } -void Gui::selectDraggable(ObjID child, Common::Point pos) { +void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point startPos) { if (_engine->isObjClickable(child)) { _draggedObj.id = child; - _draggedObj.pos = pos; + _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - startPos; + _draggedObj.pos = startPos + _draggedObj.mouseOffset; } } void Gui::handleDragRelease(Common::Point pos) { _draggedObj.id = 0; _engine->updateDelta(pos); + _engine->selectControl(kControlOperate); + _engine->activateCommand(kControlOperate); + _engine->refreshReady(); _engine->preparedToRun(); } @@ -1002,7 +1018,7 @@ bool Gui::processEvent(Common::Event &event) { bool processed = false; if (event.type == Common::EVENT_MOUSEMOVE) { if (_draggedObj.id != 0) { - _draggedObj.pos = event.mouse; + _draggedObj.pos = event.mouse + _draggedObj.mouseOffset; } processed = true; @@ -1071,8 +1087,8 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; if (isRectInsideObject(clickRect, child)) { - selectDraggable(child, event.mouse); - _engine->handleObjectSelect(child, kMainGameWindow, event); + selectDraggable(child, kMainGameWindow, event.mouse); + _engine->handleObjectSelect(child, kMainGameWindow, event, false); } } } @@ -1090,7 +1106,7 @@ bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event return true; if (event.type == Common::EVENT_LBUTTONUP) { - _engine->handleObjectSelect(1, kSelfWindow, event); + _engine->handleObjectSelect(1, kSelfWindow, event, false); } return true; } @@ -1120,7 +1136,7 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even } } - _engine->handleObjectSelect(data.getData().refcon, kExitsWindow, event); + _engine->handleObjectSelect(data.getData().refcon, kExitsWindow, event, false); } return getWindowData(kExitsWindow).visible; } @@ -1155,8 +1171,8 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; if (isRectInsideObject(clickRect, child)) { - selectDraggable(child, event.mouse); - _engine->handleObjectSelect(child, (WindowReference)ref, event); + selectDraggable(child, data.refcon, event.mouse); + _engine->handleObjectSelect(child, (WindowReference)ref, event, false); } } } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index dd08173d3c..d71ee6680b 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -147,6 +147,8 @@ struct BorderBounds { struct DraggedObj { ObjID id; Common::Point pos; + Common::Point mouseOffset; + bool hasMoved; }; @@ -255,12 +257,13 @@ private: // Methods void drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface); // Finders + Common::Point getWindowSurfacePos(WindowReference reference); WindowData& findWindowData(WindowReference reference); Graphics::MacWindow *findWindow(WindowReference reference); // Utils bool isRectInsideObject(Common::Rect target, ObjID obj); - void selectDraggable(ObjID child, Common::Point pos); + void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); void handleDragRelease(Common::Point pos); Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 08b5ec90c1..b26250a5bf 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -280,7 +280,7 @@ bool MacVentureEngine::printTexts() { return false; } -void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Common::Event event) { +void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Common::Event event, bool isDoubleClick) { if (win == kExitsWindow) { win = kMainGameWindow; } @@ -826,7 +826,10 @@ ObjID MacVentureEngine::getParent(ObjID objID) { } Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { + BorderBounds bounds = _gui->borderBounds(_gui->getWindowData(findParentWindow(objID)).type); // HACK Common::Point pos = getObjPosition(objID); + pos.x += bounds.leftOffset; + pos.y += bounds.topOffset; uint w = _gui->getObjWidth(objID); // This shouldn't go here uint h = _gui->getObjHeight(objID); return Common::Rect(pos.x, pos.y, pos.x + w, pos.y + h); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 9ecfbc0fd7..cdf9a94a5a 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -179,7 +179,7 @@ public: void runObjQueue(); bool printTexts(); - void handleObjectSelect(ObjID objID, WindowReference win, Common::Event event); + void handleObjectSelect(ObjID objID, WindowReference win, Common::Event event, bool isDoubleClick); void updateDelta(Common::Point newPos); void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 670f39902c..15e3c2a531 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -59,7 +59,7 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { res >>= _engine->getGlobalSettings().attrShifts[attrID]; if (res & 0x8000) res = -((res ^ 0xffff) + 1); - debug(3, "Attribute %x from object %x is %x", attrID, objID, res); + debug(6, "Attribute %x from object %x is %x", attrID, objID, res); return res; } -- cgit v1.2.3 From a6e1202a0c95c8124536504cf1dee81970ae74bb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 1 Jul 2016 10:40:13 +0200 Subject: MACVENTURE: Fix object selection fallthrough --- engines/macventure/gui.cpp | 26 +++++++++++++++----------- engines/macventure/gui.h | 1 + engines/macventure/script.cpp | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 8f8acda6dd..f07b914d26 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -641,7 +641,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * pos = _engine->getObjPosition(child); pos += Common::Point(border.leftOffset, border.topOffset); - if (child < 600 && child != _draggedObj.id) { // Small HACK until I figre out where the last garbage child in main game window comes from + if (child < 600) { // Small HACK until I figre out where the last garbage child in main game window comes from if (!_assets.contains(child)) { _assets[child] = new ImageAsset(child, _graphics); } @@ -654,7 +654,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * if (_engine->isObjSelected(child)) _assets[child]->blitInto( - surface, pos.x, pos.y, kBlitOR); + surface, pos.x, pos.y, kBlitXOR); // For test surface->frameRect(Common::Rect( @@ -697,7 +697,7 @@ void Gui::drawDraggedObject() { _screen.copyRectToSurface(_draggedSurface, _draggedObj.pos.x, _draggedObj.pos.y, Common::Rect(asset->getWidth() - 1, asset->getHeight() - 1)); - asset->blitInto(&_draggedSurface, 0, 0, kBlitOR); + asset->blitInto(&_draggedSurface, 0, 0, kBlitBIC); g_system->copyRectToScreen( _draggedSurface.getPixels(), @@ -839,6 +839,16 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { return nullptr; } +void Gui::checkSelect(ObjID obj, const Common::Event &event, const Common::Rect & clickRect, WindowReference ref) { + if (_engine->isObjVisible(obj) && + _engine->isObjClickable(obj) && + isRectInsideObject(clickRect, obj)) + { + selectDraggable(obj, ref, event.mouse); + _engine->handleObjectSelect(obj, (WindowReference)ref, event, false); + } +} + bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { if (_assets.contains(obj) && //_engine->isObjClickable(obj) && @@ -1086,10 +1096,7 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e Common::Rect clickRect = calculateClickRect(event.mouse, _mainGameWindow->getDimensions()); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; - if (isRectInsideObject(clickRect, child)) { - selectDraggable(child, kMainGameWindow, event.mouse); - _engine->handleObjectSelect(child, kMainGameWindow, event, false); - } + checkSelect(child, event, clickRect, kMainGameWindow); } } return false; @@ -1170,10 +1177,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { Common::Rect clickRect = calculateClickRect(event.mouse, _inventoryWindows[i]->getDimensions()); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; - if (isRectInsideObject(clickRect, child)) { - selectDraggable(child, data.refcon, event.mouse); - _engine->handleObjectSelect(child, (WindowReference)ref, event, false); - } + checkSelect(child, event, clickRect, (WindowReference)ref); } } return true; diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index d71ee6680b..f93e8db42b 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -262,6 +262,7 @@ private: // Methods Graphics::MacWindow *findWindow(WindowReference reference); // Utils + void checkSelect(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); bool isRectInsideObject(Common::Rect target, ObjID obj); void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); void handleDragRelease(Common::Point pos); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index cc9474e6d4..cbc47a9148 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -794,8 +794,8 @@ void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { - word b = neg16(state->pop()); - word a = neg16(state->pop()); + word b = state->pop(); + word a = state->pop(); state->push((a == b) ? 0xFFFF : 0); } -- cgit v1.2.3 From 541702206889519515f20c42dd10aaba70630db1 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 2 Jul 2016 17:11:42 +0200 Subject: MACVENTURE: Add double click support --- engines/macventure/gui.cpp | 76 ++++++++++++++++++++------ engines/macventure/gui.h | 110 +++++++++++++++++++++++++++++++++++++- engines/macventure/macventure.cpp | 55 +++++++++++++------ engines/macventure/macventure.h | 3 +- 4 files changed, 209 insertions(+), 35 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index f07b914d26..dc0c4afb09 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -26,7 +26,7 @@ #include "macventure/macventure.h" #include "macventure/gui.h" -// For the dragged object +#include "common/timer.h" #include "common/system.h" namespace MacVenture { @@ -81,6 +81,12 @@ static const Graphics::MenuData menuSubItems[] = { { 0, NULL, 0, 0, false } }; + +static void cursorTimerHandler(void *refCon) { + Gui *gui = (Gui *)refCon; + gui->processCursorTick(); +} + bool commandsWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool mainGameWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); @@ -99,6 +105,9 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _draggedObj.id = 0; _draggedObj.pos = Common::Point(0, 0); + _cursor = new Cursor(this); + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 1000000, this, "macVentureCursor"); + initGUI(); } @@ -113,6 +122,9 @@ Gui::~Gui() { if (_exitsData) delete _exitsData; + if (_cursor) + delete _cursor; + Common::HashMap::const_iterator it = _assets.begin(); for (; it != _assets.end(); it++) { delete it->_value; @@ -654,7 +666,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * if (_engine->isObjSelected(child)) _assets[child]->blitInto( - surface, pos.x, pos.y, kBlitXOR); + surface, pos.x, pos.y, kBlitOR); // For test surface->frameRect(Common::Rect( @@ -796,6 +808,16 @@ void Gui::updateExit(ObjID obj) { } +WindowReference Gui::findWindowAtPoint(Common::Point point) { + Common::List::iterator it; + for (it = _windowData->begin(); it != _windowData->end(); it++) { + if (it->bounds.contains(point) && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered + return it->refcon; + } + } + return kNoWindow; +} + Common::Point Gui::getWindowSurfacePos(WindowReference reference) { const WindowData &data = getWindowData(reference); BorderBounds border = borderBounds(data.type); @@ -845,7 +867,6 @@ void Gui::checkSelect(ObjID obj, const Common::Event &event, const Common::Rect isRectInsideObject(clickRect, obj)) { selectDraggable(obj, ref, event.mouse); - _engine->handleObjectSelect(obj, (WindowReference)ref, event, false); } } @@ -873,19 +894,22 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point startPos) { if (_engine->isObjClickable(child)) { + _draggedObj.hasMoved = false; _draggedObj.id = child; _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - startPos; _draggedObj.pos = startPos + _draggedObj.mouseOffset; } } -void Gui::handleDragRelease(Common::Point pos) { +void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) { + WindowReference destinationWindow = findWindowAtPoint(pos); + if (_draggedObj.hasMoved) { + ObjID destObject = getWindowData(destinationWindow).objRef; + _engine->handleObjectDrop(_draggedObj.id, pos, destObject); //change pos to validate + } else { + _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); + } _draggedObj.id = 0; - _engine->updateDelta(pos); - _engine->selectControl(kControlOperate); - _engine->activateCommand(kControlOperate); - _engine->refreshReady(); - _engine->preparedToRun(); } Common::Rect Gui::calculateClickRect(Common::Point clickPos, Common::Rect windowBounds) { @@ -1026,9 +1050,13 @@ uint Gui::getObjHeight(ObjID obj) { bool Gui::processEvent(Common::Event &event) { bool processed = false; + + processed |= _cursor->processEvent(event); + if (event.type == Common::EVENT_MOUSEMOVE) { if (_draggedObj.id != 0) { _draggedObj.pos = event.mouse + _draggedObj.mouseOffset; + _draggedObj.hasMoved = true; } processed = true; @@ -1038,12 +1066,6 @@ bool Gui::processEvent(Common::Event &event) { g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h); g_system->updateScreen(); } - else if (event.type == Common::EVENT_LBUTTONUP) { - if (_draggedObj.id != 0) { - handleDragRelease(event.mouse); - } - processed = true; - } processed |= _wm.processEvent(event); return (processed); @@ -1113,7 +1135,7 @@ bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event return true; if (event.type == Common::EVENT_LBUTTONUP) { - _engine->handleObjectSelect(1, kSelfWindow, event, false); + _engine->handleObjectSelect(1, kSelfWindow, false, false); } return true; } @@ -1143,7 +1165,7 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even } } - _engine->handleObjectSelect(data.getData().refcon, kExitsWindow, event, false); + _engine->handleObjectSelect(data.getData().refcon, kExitsWindow, false, false); } return getWindowData(kExitsWindow).visible; } @@ -1183,6 +1205,26 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { return true; } +void Gui::processCursorTick() { + _cursor->tick(); + + + + + + handleDragRelease(_draggedObj.pos, false, true); + +} + +void Gui::handleSingleClick(Common::Point pos) { + //handleDragRelease(_draggedObj.pos, false, false); + debug("Single Click"); +} + +void Gui::handleDoubleClick(Common::Point pos) { + debug("Double Click"); +} + /* Ugly switches */ BorderBounds Gui::borderBounds(MVWindowType type) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index f93e8db42b..75bb1e64a5 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -39,6 +39,7 @@ using namespace Graphics::MacWindowConstants; class MacVentureEngine; typedef uint32 ObjID; +class Cursor; class CommandButton; class ImageAsset; @@ -151,6 +152,14 @@ struct DraggedObj { bool hasMoved; }; +enum CursorState { + // HACK, I should define a proper FSM for this + kCursorIdle, + kCursorSingleClick, // Triggered when mouse goes up + kCursorSingleClickAwait, // Triggered when we are in single click and mouse goes down + kCursorSingleClickTrap, // Trap state, for when we are in await, and the timer goes off + kCursorDoubleClick +}; class Gui { @@ -183,12 +192,18 @@ public: bool processDiplomaEvents(WindowClick click, Common::Event &event); bool processInventoryEvents(WindowClick click, Common::Event &event); + void processCursorTick(); + //bool processClickObject(ObjID obj, WindowReference win, Common::Event event, bool canDrag); const WindowData& getWindowData(WindowReference reference); const Graphics::Font& getCurrentFont(); + // Clicks + void handleSingleClick(Common::Point pos); + void handleDoubleClick(Common::Point pos); + // Modifiers void bringToFront(WindowReference window); void setWindowTitle(WindowReference winID, Common::String string); @@ -230,6 +245,8 @@ private: // Attributes Graphics::ManagedSurface _draggedSurface; DraggedObj _draggedObj; + Cursor *_cursor; + private: // Methods // Initializers @@ -257,6 +274,7 @@ private: // Methods void drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface); // Finders + WindowReference findWindowAtPoint(Common::Point point); Common::Point getWindowSurfacePos(WindowReference reference); WindowData& findWindowData(WindowReference reference); Graphics::MacWindow *findWindow(WindowReference reference); @@ -265,11 +283,101 @@ private: // Methods void checkSelect(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); bool isRectInsideObject(Common::Rect target, ObjID obj); void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); - void handleDragRelease(Common::Point pos); + void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); }; +class Cursor { +enum ClickState { + kCursorIdle = 0, + kCursorSC = 1, + kCursorNoTick = 2, + kCursorSCTrans = 3, + kCursorExecSC = 4, + kCursorExecDC = 5, + kCursorStateCount +}; + +enum CursorInput { // Columns for the FSM transition table + kTickCol = 0, + kButtonDownCol = 1, + kButtonUpCol = 2, + kCursorInputCount +}; + + +ClickState _transitionTable[kCursorStateCount][kCursorInputCount] = { + /* kCursorIdle */ {kCursorIdle, kCursorIdle, kCursorSC }, + /* kCursorSC */ {kCursorExecSC, kCursorSCTrans, kCursorExecDC }, + /* IgnoreTick */ {kCursorNoTick, kCursorNoTick, kCursorExecSC }, + /* SC Transition */ {kCursorNoTick, kCursorNoTick, kCursorExecDC }, + /* Exec SC */ {kCursorIdle, kCursorExecSC, kCursorExecSC }, // Trap state + /* Exec DC */ {kCursorIdle, kCursorExecDC, kCursorExecDC } // Trap state +}; + +public: + Cursor(Gui *gui) { + _gui = gui; + _state = kCursorIdle; + } + + ~Cursor() {} + + void tick() { + executeState(); + changeState(kTickCol); + } + + bool processEvent(const Common::Event &event) { + executeState(); + + if (event.type == Common::EVENT_MOUSEMOVE) { + _pos = event.mouse; + return true; + } + if (event.type == Common::EVENT_LBUTTONDOWN) { + changeState(kButtonDownCol); + return true; + } + if (event.type == Common::EVENT_LBUTTONUP) { + changeState(kButtonUpCol); + return true; + } + + return false; + } + + Common::Point getPos() { + return _pos; + } + +private: + + void changeState(CursorInput input) { + debug("Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); + _state = _transitionTable[_state][input]; + } + + void executeState() { + if (_state == kCursorExecSC) { + _gui->handleSingleClick(_pos); + changeState(kTickCol); + } else if (_state == kCursorExecDC) { + _gui->handleDoubleClick(_pos); + changeState(kTickCol); + } + } + + +private: + Gui *_gui; + + Common::Point _pos; + ClickState _state; + +}; + class CommandButton { enum { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index b26250a5bf..1578c57011 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -280,7 +280,7 @@ bool MacVentureEngine::printTexts() { return false; } -void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Common::Event event, bool isDoubleClick) { +void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick) { if (win == kExitsWindow) { win = kMainGameWindow; } @@ -289,7 +289,7 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Comm const WindowData &windata = _gui->getWindowData(win); - if (event.kbd.flags & Common::KBD_SHIFT) { + if (shiftPressed) { // Do shift ;) } else { if (_selectedControl && _currentSelection.size() > 0 && getInvolvedObjects() > 1) { @@ -311,25 +311,47 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Comm if (objID > 0) { int i = findObjectInArray(objID, _currentSelection); - /*if (event.type == Common::EVENT isDoubleClick(event)) { // no double click for now - if (!found) - unSelectAll(); - selectObj(obj); - doubleClickObject(obj, win, event, canDrag); - } else {*/ - if (i >= 0) - unselectAll(); - selectObject(objID); - if (getInvolvedObjects() == 1) - _cmdReady = true; - preparedToRun(); - //singleClickObject(objID, win, event, canDrag); - //} + if (isDoubleClick) { // no double click for now + if (i >= 0) + unselectAll(); + selectObject(objID); + if (!_cmdReady) + { + selectPrimaryObject(objID); + if (_selectedControl == kNoCommand) { + _selectedControl = kActivateObject; + if (_activeControl) + _activeControl = kNoCommand; + _activeControl = kActivateObject; + _cmdReady = true; + } + } + preparedToRun(); + //doubleClickObject(objID, win, event, canDrag); + debug("Double click"); + } else { + if (i >= 0) + unselectAll(); + selectObject(objID); + if (getInvolvedObjects() == 1) + _cmdReady = true; + preparedToRun(); + //singleClickObject(objID, win, event, canDrag); + } } } } } +void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent) { + _destObject = newParent; + updateDelta(delta); + selectControl(kControlOperate); + activateCommand(kControlOperate); + refreshReady(); + preparedToRun(); +} + void MacVentureEngine::updateDelta(Common::Point newPos) { Common::Point newDelta = newPos - _deltaPoint; debug(4, "Update delta: Old(%d, %d), New(%d, %d)", @@ -508,6 +530,7 @@ void MacVentureEngine::selectObject(ObjID objID) { _selectedObjs.push_back(objID); highlightExit(objID); } + _deltaPoint = getObjPosition(objID); } void MacVentureEngine::unselectObject(ObjID objID) { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index cdf9a94a5a..ad13d122f1 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -179,7 +179,8 @@ public: void runObjQueue(); bool printTexts(); - void handleObjectSelect(ObjID objID, WindowReference win, Common::Event event, bool isDoubleClick); + void handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick); + void handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent); void updateDelta(Common::Point newPos); void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); -- cgit v1.2.3 From 46a85f02d6086bb14a6635a6af77ba85520a7e39 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 4 Jul 2016 11:45:47 +0200 Subject: MACVENTURE: Add initial text rendering --- engines/macventure/gui.cpp | 80 +++++++++++++++++++++++++-------------- engines/macventure/gui.h | 65 +++++++++++++++++++++++++++++-- engines/macventure/macventure.cpp | 39 ++++++++----------- engines/macventure/macventure.h | 11 +++--- engines/macventure/script.cpp | 2 +- 5 files changed, 135 insertions(+), 62 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index dc0c4afb09..7ad5eb0d41 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -51,6 +51,14 @@ enum { kMenuSpecial = 3 }; +enum { + kCommandNum = 8 +}; + +enum { + kDragThreshold = 5 +}; + static const Graphics::MenuData menuSubItems[] = { { kMenuHighLevel, "File", 0, 0, false }, { kMenuHighLevel, "Edit", 0, 0, false }, @@ -106,7 +114,9 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _draggedObj.pos = Common::Point(0, 0); _cursor = new Cursor(this); - g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 1000000, this, "macVentureCursor"); + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 500000, this, "macVentureCursor"); + + _consoleText = new ConsoleText(this); initGUI(); } @@ -125,6 +135,9 @@ Gui::~Gui() { if (_cursor) delete _cursor; + if (_consoleText) + delete _consoleText; + Common::HashMap::const_iterator it = _assets.begin(); for (; it != _assets.end(); it++) { delete it->_value; @@ -297,8 +310,8 @@ void Gui::initWindows() { _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true); + loadBorder(_selfWindow, "border_none.bmp", false); + loadBorder(_selfWindow, "border_none.bmp", true); // Exits Window _exitsWindow = _wm.addWindow(false, false, false); @@ -508,7 +521,7 @@ bool Gui::loadControls() { data.scrollMax = res->readUint16BE(); data.scrollMin = res->readUint16BE(); data.cdef = res->readUint16BE(); - data.refcon = (ControlReference)id; id++; + data.refcon = (ControlType)id; id++; res->readUint32BE(); data.titleLength = res->readByte(); if (data.titleLength) { @@ -535,6 +548,7 @@ void Gui::drawWindows() { drawSelfWindow(); drawInventories(); drawExitsWindow(); + drawConsoleWindow(); } @@ -579,7 +593,6 @@ void Gui::drawMainGameWindow() { border.leftOffset, border.topOffset, kBlitDirect); - } drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); @@ -638,6 +651,13 @@ void Gui::drawExitsWindow() { //g_system->updateScreen(); } +void Gui::drawConsoleWindow() { + + Graphics::ManagedSurface *srf = _outConsoleWindow->getSurface(); + BorderBounds bounds = borderBounds(getWindowData(kOutConsoleWindow).type); + _consoleText->renderInto(srf, bounds.leftOffset); +} + void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { WindowData &data = findWindowData(target); BorderBounds border = borderBounds(data.type); @@ -796,7 +816,7 @@ void Gui::updateExit(ObjID obj) { { ControlData data; data.titleLength = 0; - data.refcon = obj; + data.objref = obj; Common::Point pos = _engine->getObjExitPosition(obj); pos.x = border.leftOffset; pos.y = border.topOffset; @@ -807,6 +827,11 @@ void Gui::updateExit(ObjID obj) { } } +void Gui::printText(const Common::String & text) { + debug("Print Text: %s", text); + _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); +} + WindowReference Gui::findWindowAtPoint(Common::Point point) { Common::List::iterator it; @@ -893,7 +918,7 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { } void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point startPos) { - if (_engine->isObjClickable(child)) { + if (_engine->isObjClickable(child) && _draggedObj.id == 0) { _draggedObj.hasMoved = false; _draggedObj.id = child; _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - startPos; @@ -903,12 +928,14 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point sta void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) { WindowReference destinationWindow = findWindowAtPoint(pos); - if (_draggedObj.hasMoved) { + if (_draggedObj.id != 0 && _draggedObj.hasMoved) { ObjID destObject = getWindowData(destinationWindow).objRef; - _engine->handleObjectDrop(_draggedObj.id, pos, destObject); //change pos to validate - } else { - _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); + debug("drop the object at obj %d", destObject); + _engine->handleObjectDrop(_draggedObj.id, pos, destObject); } + _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); + + _draggedObj.id = 0; } @@ -1055,16 +1082,17 @@ bool Gui::processEvent(Common::Event &event) { if (event.type == Common::EVENT_MOUSEMOVE) { if (_draggedObj.id != 0) { - _draggedObj.pos = event.mouse + _draggedObj.mouseOffset; - _draggedObj.hasMoved = true; + Common::Point newPos = event.mouse + _draggedObj.mouseOffset; + _draggedObj.hasMoved = newPos.sqrDist(_draggedObj.pos) >= kDragThreshold; + _draggedObj.pos = newPos; } processed = true; // TEST - Common::Rect mr = calculateClickRect(event.mouse, _screen.getBounds()); - _screen.fillRect(mr, kColorGreen); - g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h); - g_system->updateScreen(); + //Common::Rect mr = calculateClickRect(event.mouse, _screen.getBounds()); + //_screen.fillRect(mr, kColorGreen); + //g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h); + //g_system->updateScreen(); } processed |= _wm.processEvent(event); @@ -1098,8 +1126,8 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { } - _engine->selectControl((ControlReference)data.getData().refcon); - _engine->activateCommand((ControlReference)data.getData().refcon); + _engine->selectControl(_engine->referenceToAction(data.getData().refcon)); + _engine->activateCommand(data.getData().refcon); _engine->refreshReady(); _engine->preparedToRun(); } @@ -1207,22 +1235,16 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { void Gui::processCursorTick() { _cursor->tick(); - - - - - - handleDragRelease(_draggedObj.pos, false, true); - } void Gui::handleSingleClick(Common::Point pos) { - //handleDragRelease(_draggedObj.pos, false, false); debug("Single Click"); + handleDragRelease(_draggedObj.pos, false, false); } void Gui::handleDoubleClick(Common::Point pos) { debug("Double Click"); + handleDragRelease(_draggedObj.pos, false, true); } /* Ugly switches */ @@ -1236,7 +1258,7 @@ BorderBounds Gui::borderBounds(MVWindowType type) { case MacVenture::kPlainDBox: return BorderBounds(6, 6, 6, 6); case MacVenture::kAltBox: - return BorderBounds(8, 9, 11, 10); + return BorderBounds(4, 4, 4, 4); // Hand-tested break; case MacVenture::kNoGrowDoc: return BorderBounds(1, 17, 1, 1); @@ -1249,7 +1271,7 @@ BorderBounds Gui::borderBounds(MVWindowType type) { case MacVenture::kRDoc16: break; case MacVenture::kRDoc4: - return BorderBounds(1, 19, 1, 1); + return BorderBounds(0, 19, 1, 1); case MacVenture::kRDoc6: break; case MacVenture::kRDoc10: diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 75bb1e64a5..6dd22f568c 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -40,6 +40,7 @@ class MacVentureEngine; typedef uint32 ObjID; class Cursor; +class ConsoleText; class CommandButton; class ImageAsset; @@ -110,7 +111,7 @@ struct WindowData { bool updateScroll; }; -enum ControlReference { +enum ControlType { kControlExitBox = 0, kControlExamine = 1, kControlOpen = 2, @@ -130,7 +131,8 @@ struct ControlData { uint16 scrollMax; uint16 scrollMin; uint16 cdef; - uint32 refcon; // If exits window, then the obj id. Otherwise, the control type + ObjID objref; + ControlType refcon; // If exits window, then the obj id. Otherwise, the control type uint8 titleLength; char* title; uint16 border; @@ -215,6 +217,8 @@ public: void unselectExits(); void updateExit(ObjID id); + void printText(const Common::String &text); + // Ugly switches BorderBounds borderBounds(MVWindowType type); @@ -244,9 +248,11 @@ private: // Attributes Graphics::ManagedSurface _draggedSurface; DraggedObj _draggedObj; - + Cursor *_cursor; + ConsoleText *_consoleText; + private: // Methods // Initializers @@ -268,6 +274,7 @@ private: // Methods void drawSelfWindow(); void drawInventories(); void drawExitsWindow(); + void drawConsoleWindow(); void drawDraggedObject(); void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface); @@ -446,6 +453,58 @@ private: Gui *_gui; }; +class ConsoleText { + +public: + + ConsoleText(Gui *gui) { + _gui = gui; + _lines.push_back(""); + } + + ~ConsoleText() { + + } + + void printLine(const Common::String &str, int maxW) { + Common::StringArray wrappedLines; + int textW = maxW; + const Graphics::Font *font = &_gui->getCurrentFont(); + + font->wordWrapText(str, textW, wrappedLines); + + if (wrappedLines.empty()) // Sometimes we have empty lines + _lines.push_back(""); + + for (Common::StringArray::const_iterator j = wrappedLines.begin(); j != wrappedLines.end(); ++j) + _lines.push_back(*j); + + updateScroll(); + } + + void renderInto(Graphics::ManagedSurface *target, uint leftOffset) { + target->fillRect(target->getBounds(), kColorWhite); + const Graphics::Font *font = &_gui->getCurrentFont(); + // HACK print the last lines visible (no scroll) + uint y = target->h - font->getFontHeight(); + for (uint i = _lines.size() - 1; i != 0; i--) { + font->drawString(target, _lines[i], leftOffset, y, font->getStringWidth(_lines[i]), kColorBlack); + y -= font->getFontHeight(); + } + } + + void updateScroll() { + // TODO implemebt + } + +private: + + Gui *_gui; + + Common::StringArray _lines; + +}; + } // End of namespace MacVenture #endif diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 1578c57011..6a9f82f468 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -172,13 +172,12 @@ void MacVentureEngine::requestUnpause() { _gameState = kGameStatePlaying; } -void MacVentureEngine::selectControl(ControlReference id) { - ControlAction action = referenceToAction(id); - debug(2, "Select control %x", action); - _selectedControl = action; +void MacVentureEngine::selectControl(ControlAction id) { + debug(2, "Select control %x", id); + _selectedControl = id; } -void MacVentureEngine::activateCommand(ControlReference id) { +void MacVentureEngine::activateCommand(ControlType id) { if (id == kControlClickToContinue) { _clickToContinue = false; _paused = true; @@ -264,15 +263,15 @@ bool MacVentureEngine::printTexts() { _textQueue.remove_at(0); switch (text.id) { case kTextNumber: - debug("Print Number: %d", text.asset); + _gui->printText(Common::String(text.asset)); gameChanged(); break; case kTextNewLine: - debug("Print Newline: "); + _gui->printText(Common::String("\n")); gameChanged(); break; case kTextPlain: - debug("Print Plain Text: %s", _world->getText(text.asset, text.source, text.destination).c_str()); + _gui->printText(_world->getText(text.asset, text.source, text.destination)); gameChanged(); break; } @@ -311,24 +310,19 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool if (objID > 0) { int i = findObjectInArray(objID, _currentSelection); - if (isDoubleClick) { // no double click for now + if (isDoubleClick) { if (i >= 0) unselectAll(); selectObject(objID); if (!_cmdReady) { - selectPrimaryObject(objID); - if (_selectedControl == kNoCommand) { - _selectedControl = kActivateObject; - if (_activeControl) - _activeControl = kNoCommand; - _activeControl = kActivateObject; - _cmdReady = true; - } + selectObject(objID); + + selectControl(kActivateObject); + _activeControl = kActivateObject; + _cmdReady = true; } preparedToRun(); - //doubleClickObject(objID, win, event, canDrag); - debug("Double click"); } else { if (i >= 0) unselectAll(); @@ -336,7 +330,6 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool if (getInvolvedObjects() == 1) _cmdReady = true; preparedToRun(); - //singleClickObject(objID, win, event, canDrag); } } } @@ -346,7 +339,7 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent) { _destObject = newParent; updateDelta(delta); - selectControl(kControlOperate); + selectControl(kOperate); activateCommand(kControlOperate); refreshReady(); preparedToRun(); @@ -354,7 +347,7 @@ void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID void MacVentureEngine::updateDelta(Common::Point newPos) { Common::Point newDelta = newPos - _deltaPoint; - debug(4, "Update delta: Old(%d, %d), New(%d, %d)", + debug("Update delta: Old(%d, %d), New(%d, %d)", _deltaPoint.x, _deltaPoint.y, newDelta.x, newDelta.y); _deltaPoint = newDelta; @@ -749,7 +742,7 @@ void MacVentureEngine::zoomObject(ObjID objID) { warning("zoomObject: unimplemented"); } -ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlReference id) { +ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlType id) { switch (id) { case MacVenture::kControlExitBox: return kActivateObject;//?? diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index ad13d122f1..a1f570ed98 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -161,8 +161,8 @@ public: void requestQuit(); void requestUnpause(); - void selectControl(ControlReference id); - void activateCommand(ControlReference id); + void selectControl(ControlAction action); + void activateCommand(ControlType id); void refreshReady(); void preparedToRun(); void gameChanged(); @@ -210,6 +210,8 @@ public: Common::Point getObjExitPosition(ObjID objID); ObjID getParent(ObjID objID); + // Utils + ControlAction referenceToAction(ControlType id); // Encapsulation HACK Common::Rect getObjBounds(ObjID objID); @@ -250,10 +252,7 @@ private: // Data loading bool loadGlobalSettings(); bool loadTextHuffman(); - - // Utils - ControlAction referenceToAction(ControlReference id); - + const char* getGameFileName() const; private: // Attributes diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index cbc47a9148..230198bc6c 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1071,7 +1071,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { - _engine->activateCommand((ControlReference)state->pop()); + _engine->activateCommand((ControlType)state->pop()); } void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From b4609642840917fe08d675960ce9f0e4567bd6c9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 5 Jul 2016 13:06:51 +0200 Subject: MACVENTURE: Add double click --- engines/macventure/gui.cpp | 25 +++++++++++++++++-------- engines/macventure/gui.h | 28 ++++++++++++++++++++++++---- engines/macventure/macventure.cpp | 24 +++++++++++------------- engines/macventure/macventure.h | 23 ++++++++++++++++++++++- engines/macventure/script.cpp | 15 +++++++++++---- engines/macventure/script.h | 20 +------------------- 6 files changed, 86 insertions(+), 49 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 7ad5eb0d41..fb6f46ba03 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -521,15 +521,15 @@ bool Gui::loadControls() { data.scrollMax = res->readUint16BE(); data.scrollMin = res->readUint16BE(); data.cdef = res->readUint16BE(); - data.refcon = (ControlType)id; id++; - res->readUint32BE(); + data.refcon = (ControlAction)res->readUint32BE();//(ControlType)id; id++; + data.type = (ControlType)id; id++; data.titleLength = res->readByte(); if (data.titleLength) { data.title = new char[data.titleLength + 1]; res->read(data.title, data.titleLength); data.title[data.titleLength] = '\0'; } - if (data.refcon != kControlExitBox) + if (data.type != kControlExitBox) data.border = commandsBorder; Common::Rect bounds(left, top, right, bottom); // For some reason, if I remove this it segfaults @@ -570,7 +570,7 @@ void Gui::drawCommandsWindow() { Common::Array::const_iterator it = _controlData->begin(); for (; it != _controlData->end(); ++it) { CommandButton button = *it; - if (button.getData().refcon != kControlExitBox) + if (button.getData().type != kControlExitBox) button.draw(*_controlsWindow->getSurface()); } } @@ -816,7 +816,7 @@ void Gui::updateExit(ObjID obj) { { ControlData data; data.titleLength = 0; - data.objref = obj; + data.refcon = (ControlAction)obj; // Objects can be exits (actions) Common::Point pos = _engine->getObjExitPosition(obj); pos.x = border.leftOffset; pos.y = border.topOffset; @@ -935,7 +935,6 @@ void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleC } _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); - _draggedObj.id = 0; } @@ -1102,7 +1101,7 @@ bool Gui::processEvent(Common::Event &event) { bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { if (_engine->needsClickToContinue()) { - _engine->activateCommand(kControlClickToContinue); + _engine->activateCommand(kClickToContinue); return true; } @@ -1126,7 +1125,7 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { } - _engine->selectControl(_engine->referenceToAction(data.getData().refcon)); + _engine->selectControl(data.getData().refcon); _engine->activateCommand(data.getData().refcon); _engine->refreshReady(); _engine->preparedToRun(); @@ -1240,11 +1239,21 @@ void Gui::processCursorTick() { void Gui::handleSingleClick(Common::Point pos) { debug("Single Click"); handleDragRelease(_draggedObj.pos, false, false); + + // HACK For test, please delete me + //WindowReference destinationWindow = findWindowAtPoint(pos); + //_engine->handleObjectSelect(_draggedObj.id, destinationWindow, false, false); + //_draggedObj.id = 0; } void Gui::handleDoubleClick(Common::Point pos) { debug("Double Click"); handleDragRelease(_draggedObj.pos, false, true); + + // HACK For test, please delete me + //WindowReference destinationWindow = findWindowAtPoint(pos); + //_engine->handleObjectSelect(_draggedObj.id, destinationWindow, false, true); + //_draggedObj.id = 0; } /* Ugly switches */ diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 6dd22f568c..4e4eda7092 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -111,7 +111,7 @@ struct WindowData { bool updateScroll; }; -enum ControlType { +enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc) kControlExitBox = 0, kControlExamine = 1, kControlOpen = 2, @@ -124,6 +124,26 @@ enum ControlType { kControlClickToContinue = 9 }; +enum ControlAction { // HACK, figure out a way to put it in engine + kNoCommand = 0, + kStartOrResume = 1, + kClose = 2, + kTick = 3, + kActivateObject = 4, + kMoveObject = 5, + kConsume = 6, + kExamine = 7, + kGo = 8, + kHit = 9, + kOpen = 10, + kOperate = 11, + kSpeak = 12, + kBabble = 13, + kTargetName = 14, + kDebugObject = 15, + kClickToContinue = 16 +}; + struct ControlData { Common::Rect bounds; uint16 scrollValue; @@ -131,8 +151,8 @@ struct ControlData { uint16 scrollMax; uint16 scrollMin; uint16 cdef; - ObjID objref; - ControlType refcon; // If exits window, then the obj id. Otherwise, the control type + ControlAction refcon; + ControlType type; uint8 titleLength; char* title; uint16 border; @@ -362,7 +382,7 @@ public: private: void changeState(CursorInput input) { - debug("Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); + debug(4, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); _state = _transitionTable[_state][input]; } diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 6a9f82f468..42829d97cd 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -177,19 +177,18 @@ void MacVentureEngine::selectControl(ControlAction id) { _selectedControl = id; } -void MacVentureEngine::activateCommand(ControlType id) { - if (id == kControlClickToContinue) { +void MacVentureEngine::activateCommand(ControlAction id) { + if (id == kClickToContinue) { _clickToContinue = false; _paused = true; return; - } - ControlAction action = referenceToAction(id); - if (action != _activeControl) { + } + if (id != _activeControl) { if (_activeControl) _activeControl = kNoCommand; - _activeControl = action; + _activeControl = id; } - debug(2, "Activating Command %x... Command %x is active", action, _activeControl); + debug(2, "Activating Command %x... Command %x is active", id, _activeControl); refreshReady(); } @@ -267,7 +266,7 @@ bool MacVentureEngine::printTexts() { gameChanged(); break; case kTextNewLine: - _gui->printText(Common::String("\n")); + _gui->printText(Common::String("")); gameChanged(); break; case kTextPlain: @@ -314,10 +313,9 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool if (i >= 0) unselectAll(); selectObject(objID); - if (!_cmdReady) - { - selectObject(objID); - + _destObject = objID; + _deltaPoint = Common::Point(0, 0); + if (!_cmdReady) { selectControl(kActivateObject); _activeControl = kActivateObject; _cmdReady = true; @@ -340,7 +338,7 @@ void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID _destObject = newParent; updateDelta(delta); selectControl(kOperate); - activateCommand(kControlOperate); + activateCommand(kOperate); refreshReady(); preparedToRun(); } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index a1f570ed98..6dab558a0d 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -71,6 +71,27 @@ enum { kClickToContinueTextID = 0x84, kStartGameFilenameID = 0x85 }; +/* +enum ControlAction { + kNoCommand = 0, + kStartOrResume = 1, + kClose = 2, + kTick = 3, + kActivateObject = 4, + kMoveObject = 5, + kConsume = 6, + kExamine = 7, + kGo = 8, + kHit = 9, + kOpen = 10, + kOperate = 11, + kSpeak = 12, + kBabble = 13, + kTargetName = 14, + kDebugObject = 15, + kClickToContinue = 16 +}; +*/ enum FilePathID { kMCVID = 1, @@ -162,7 +183,7 @@ public: void requestQuit(); void requestUnpause(); void selectControl(ControlAction action); - void activateCommand(ControlType id); + void activateCommand(ControlAction id); void refreshReady(); void preparedToRun(); void gameChanged(); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 230198bc6c..a86347ba4c 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -353,7 +353,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opbaCRAN(state, frame); break; case 0xbb: //fork - opbbFORK(state, frame); + if (opbbFORK(state, frame)) + return true; break; case 0xbc: //call if (opbcCALL(state, frame, script)) @@ -902,14 +903,20 @@ void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { frame->saves[i].rank = 0; } -void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { +bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { EngineFrame newframe; newframe.action = (ControlAction)state->pop(); newframe.src = state->pop(); newframe.dest = state->pop(); newframe.x = state->pop(); newframe.y = state->pop(); - _frames.push_back(newframe); + newframe.haltedInFamily = false; + newframe.haltedInFirst = false; + newframe.haltedInSaves = false; + _frames.push_front(newframe); + if (execFrame(true)) { + return true; + } } bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { @@ -1071,7 +1078,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { - _engine->activateCommand((ControlType)state->pop()); + _engine->activateCommand((ControlAction)state->pop()); } void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/script.h b/engines/macventure/script.h index acbffcd315..8aee88fd66 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -31,24 +31,6 @@ namespace MacVenture { class Container; class World; -enum ControlAction { - kNoCommand = 0, - kStartOrResume = 1, - kClose = 2, - kTick = 3, - kActivateObject = 4, - kMoveObject = 5, - kConsume = 6, - kExamine = 7, - kGo = 8, - kHit = 9, - kOpen = 10, - kOperate = 11, - kSpeak = 12, - kBabble = 13, - kTargetName = 14, - kDebugObject = 15 -}; typedef uint32 ObjID; typedef int16 word; @@ -239,7 +221,7 @@ private: void opb8CLOW(EngineState *state, EngineFrame *frame); //cancel low priority void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority void opbaCRAN(EngineState *state, EngineFrame *frame); //cancel priority range - void opbbFORK(EngineState *state, EngineFrame *frame); //fork + bool opbbFORK(EngineState *state, EngineFrame *frame); //fork bool opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script); //call void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects -- cgit v1.2.3 From 9905cd24d3335c6dab612b5a8c0e3682856020d9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 7 Jul 2016 15:06:40 +0200 Subject: MACVENTURE: Tidy up Inventory window system --- engines/macventure/gui.cpp | 78 ++++++++++++++++++++++++--------------- engines/macventure/gui.h | 7 +++- engines/macventure/macventure.cpp | 33 +++++++++++++---- engines/macventure/macventure.h | 2 + engines/macventure/script.cpp | 12 +++--- 5 files changed, 87 insertions(+), 45 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index fb6f46ba03..0012335584 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -56,7 +56,7 @@ enum { }; enum { - kDragThreshold = 5 + kDragThreshold = 1 }; static const Graphics::MenuData menuSubItems[] = { @@ -320,21 +320,17 @@ void Gui::initWindows() { _exitsWindow->setCallback(exitsWindowCallback, this); loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); - - } void Gui::assignObjReferences() { - findWindowData(kSelfWindow).objRef = 0; - } WindowReference Gui::createInventoryWindow(ObjID objRef) { Graphics::MacWindow *newWindow = _wm.addWindow(true, true, true); WindowData newData; GlobalSettings settings = _engine->getGlobalSettings(); - newData.refcon = (WindowReference)ABS(_inventoryWindows.size()); // This is a HACK + newData.refcon = (WindowReference)ABS(_inventoryWindows.size() + kInventoryStart); // This is a HACK if (_windowData->back().refcon < 0x80) { // There is already another inventory window newData.bounds = _windowData->back().bounds; // Inventory windows are always last @@ -606,23 +602,21 @@ void Gui::drawSelfWindow() { } void Gui::drawInventories() { - Common::List::const_iterator it = _windowData->begin(); - while (it != _windowData->end() && (*it).refcon >= 0x80) { - it++; - } + + Graphics::ManagedSurface *srf; - while (it != _windowData->end()) { - srf = _inventoryWindows[(*it).refcon]->getSurface(); - BorderBounds border = borderBounds((*it).type); + for (uint i = 0; i < _inventoryWindows.size(); i++) { + const WindowData &data = getWindowData((WindowReference)(kInventoryStart + i)); + srf = findWindow(data.refcon)->getSurface(); // HACK + BorderBounds border = borderBounds(data.type); srf->fillRect(Common::Rect( border.leftOffset, border.topOffset, srf->w + border.rightOffset, srf->h + border.bottomOffset), kColorWhite); - drawObjectsInWindow((*it).refcon, _inventoryWindows[(*it).refcon]->getSurface()); - it++; + drawObjectsInWindow(data.refcon, srf); - findWindow((*it).refcon)->setDirty(true); + findWindow(data.refcon)->setDirty(true); } } @@ -864,8 +858,8 @@ WindowData & Gui::findWindowData(WindowReference reference) { } Graphics::MacWindow * Gui::findWindow(WindowReference reference) { - if (reference < 0x80) { // It's an inventory window - return _inventoryWindows[reference]; + if (reference < 0x80 && reference >= kInventoryStart) { // It's an inventory window + return _inventoryWindows[reference - kInventoryStart]; } switch (reference) { case MacVenture::kNoWindow: @@ -921,6 +915,8 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point sta if (_engine->isObjClickable(child) && _draggedObj.id == 0) { _draggedObj.hasMoved = false; _draggedObj.id = child; + _draggedObj.startPos = startPos; + _draggedObj.startWin = origin; _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - startPos; _draggedObj.pos = startPos + _draggedObj.mouseOffset; } @@ -928,14 +924,19 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point sta void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) { WindowReference destinationWindow = findWindowAtPoint(pos); - if (_draggedObj.id != 0 && _draggedObj.hasMoved) { - ObjID destObject = getWindowData(destinationWindow).objRef; - debug("drop the object at obj %d", destObject); - _engine->handleObjectDrop(_draggedObj.id, pos, destObject); - } - _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); + if (_draggedObj.id != 0) { + if (_draggedObj.hasMoved) { + ObjID destObject = getWindowData(destinationWindow).objRef; + pos -= _draggedObj.startPos; + pos = localize(pos, _draggedObj.startWin, destinationWindow); + debug("drop the object at obj %d, pos (%d, %d)", destObject, pos.x, pos.y); - _draggedObj.id = 0; + _engine->handleObjectDrop(_draggedObj.id, pos, destObject); + } + _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); + _draggedObj.id = 0; + _draggedObj.hasMoved = false; + } } Common::Rect Gui::calculateClickRect(Common::Point clickPos, Common::Rect windowBounds) { @@ -944,6 +945,22 @@ Common::Rect Gui::calculateClickRect(Common::Point clickPos, Common::Rect window return Common::Rect(left - kCursorWidth, top - kCursorHeight, left + kCursorWidth, top + kCursorHeight); } +Common::Point Gui::localize(Common::Point point, WindowReference origin, WindowReference target) { + Graphics::MacWindow *oriWin = findWindow(origin); + Graphics::MacWindow *destWin = findWindow(target); + if (origin != target) { + // ori.local to global + point.x += oriWin->getDimensions().left; + point.y += oriWin->getDimensions().top; + if (destWin) { + // dest.globalToLocal + point.x -= destWin->getDimensions().left; + point.y -= destWin->getDimensions().top; + } + } + return point; +} + /* HANDLERS */ void Gui::handleMenuAction(MenuAction action) { @@ -1177,7 +1194,7 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even event.mouse.x - _exitsWindow->getDimensions().left, event.mouse.y - _exitsWindow->getDimensions().top); - CommandButton data; + CommandButton button; if (!_exitsData) return false; @@ -1185,14 +1202,15 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even for (; it != _exitsData->end(); ++it) { if (it->isInsideBounds(position)) { it->select(); - data = *it; + button = *it; + _engine->handleObjectSelect(button.getData().refcon, kExitsWindow, false, false); + return true; } else { it->unselect(); } } - _engine->handleObjectSelect(data.getData().refcon, kExitsWindow, false, false); } return getWindowData(kExitsWindow).visible; } @@ -1238,7 +1256,7 @@ void Gui::processCursorTick() { void Gui::handleSingleClick(Common::Point pos) { debug("Single Click"); - handleDragRelease(_draggedObj.pos, false, false); + handleDragRelease(pos, false, false); // HACK For test, please delete me //WindowReference destinationWindow = findWindowAtPoint(pos); @@ -1248,7 +1266,7 @@ void Gui::handleSingleClick(Common::Point pos) { void Gui::handleDoubleClick(Common::Point pos) { debug("Double Click"); - handleDragRelease(_draggedObj.pos, false, true); + handleDragRelease(pos, false, true); // HACK For test, please delete me //WindowReference destinationWindow = findWindowAtPoint(pos); diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 4e4eda7092..54e7b66945 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -65,6 +65,7 @@ enum MenuAction { enum WindowReference { kNoWindow = 0, + kInventoryStart = 1, kCommandsWindow = 0x80, kMainGameWindow = 0x81, kOutConsoleWindow = 0x82, @@ -171,6 +172,8 @@ struct DraggedObj { ObjID id; Common::Point pos; Common::Point mouseOffset; + Common::Point startPos; + WindowReference startWin; bool hasMoved; }; @@ -312,6 +315,7 @@ private: // Methods void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); + Common::Point localize(Common::Point point, WindowReference origin, WindowReference target); }; @@ -352,12 +356,11 @@ public: ~Cursor() {} void tick() { - executeState(); + executeState(); changeState(kTickCol); } bool processEvent(const Common::Event &event) { - executeState(); if (event.type == Common::EVENT_MOUSEMOVE) { _pos = event.mouse; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 42829d97cd..b9c46da8e4 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -231,6 +231,10 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID targ QueuedObject obj; obj.id = type; + if (type == kUpdateObject && isObjEnqueued(objID)) { + return; + } + if (type == kUpdateWindow) { obj.target = target; } if (type != kHightlightExits) { @@ -247,6 +251,14 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID targ _objQueue.push_back(obj); } +bool MacVentureEngine::isObjEnqueued(ObjID objID) { + Common::Array::const_iterator it; + for (it = _objQueue.begin(); it != _objQueue.end(); it++) { + if ((*it).object == objID) return true; + } + return false; +} + void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text) { QueuedText newText; newText.id = type; @@ -337,18 +349,17 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent) { _destObject = newParent; updateDelta(delta); - selectControl(kOperate); - activateCommand(kOperate); + selectControl(kMoveObject); + activateCommand(kMoveObject); refreshReady(); preparedToRun(); } void MacVentureEngine::updateDelta(Common::Point newPos) { - Common::Point newDelta = newPos - _deltaPoint; debug("Update delta: Old(%d, %d), New(%d, %d)", _deltaPoint.x, _deltaPoint.y, - newDelta.x, newDelta.y); - _deltaPoint = newDelta; + newPos.x, newPos.y); + _deltaPoint = newPos; } void MacVentureEngine::focusObjWin(ObjID objID) { @@ -620,7 +631,12 @@ void MacVentureEngine::focusObjectWindow(ObjID objID) { void MacVentureEngine::openObject(ObjID objID) { - debug("openObject: %d", objID); + debug("Open Object[%d] parent[%d] x[%d] y[%d]", + objID, + _world->getObjAttr(objID, kAttrParentObject), + _world->getObjAttr(objID, kAttrPosX), + _world->getObjAttr(objID, kAttrPosY)); + if (getObjWindow(objID)) return; if (objID == _world->getObjAttr(1, kAttrParentObject)) { _gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true)); @@ -712,10 +728,13 @@ void MacVentureEngine::checkObject(QueuedObject old) { } void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { - warning("reflectSwap: untested"); + //warning("reflectSwap: untested"); WindowReference from = getObjWindow(fromID); WindowReference to = getObjWindow(toID); WindowReference tmp = to; + debug("Swap Object[%d] to Object[%d], from win[%d] to win[%d] ", + fromID, toID, from, to); + if (!to) { tmp = from; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 6dab558a0d..043218c8a0 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -270,6 +270,8 @@ private: void toggleExits(); void zoomObject(ObjID objID); + bool isObjEnqueued(ObjID obj); + // Data loading bool loadGlobalSettings(); bool loadTextHuffman(); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index a86347ba4c..5e8bcd69a2 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -51,14 +51,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debug(2, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(3, "SCRIPT: Resume"); + debug(2, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -146,7 +146,7 @@ bool ScriptEngine::execFrame(bool execAll) { bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { - debug(3, "SCRIPT: Loading function %d", scriptID); + debug(2, "SCRIPT: Loading function %d", scriptID); // Insert the new script at the front frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); return runFunc(frame); @@ -165,7 +165,7 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool ScriptEngine::runFunc(EngineFrame *frame) { ScriptAsset &script = frame->scripts.front(); - debug(3, "SCRIPT: Executing function %d", script.getId()); + debug(2, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; byte op; while (script.hasNext()) { @@ -927,7 +927,7 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse return true; frame->scripts.pop_front(); script = frame->scripts.front(); - debug(3, "SCRIPT: Return from fuction %d", id); + debug(2, "SCRIPT: Return from fuction %d", id); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1203,7 +1203,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } - debug(3, "SCRIPT: Load %d instructions for script %d", amount, _id); + debug(2, "SCRIPT: Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture \ No newline at end of file -- cgit v1.2.3 From 528283fbe1abb33e61131f7372cda6e2192dbf70 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 7 Jul 2016 19:50:30 +0200 Subject: MACVENTURE: First version of working drag --- engines/macventure/gui.cpp | 31 +++++++++++++++++++++++++++++-- engines/macventure/gui.h | 3 +++ engines/macventure/macventure.cpp | 29 ++++++----------------------- engines/macventure/macventure.h | 5 ++--- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 0012335584..9671dc0f5f 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -243,6 +243,7 @@ void Gui::setWindowTitle(WindowReference winID, Common::String string) { } void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array &children) { + if (ref == kNoWindow) return; WindowData &data = findWindowData(ref); data.children.clear(); data.objRef = objID; @@ -603,7 +604,6 @@ void Gui::drawSelfWindow() { void Gui::drawInventories() { - Graphics::ManagedSurface *srf; for (uint i = 0; i < _inventoryWindows.size(); i++) { const WindowData &data = getWindowData((WindowReference)(kInventoryStart + i)); @@ -667,7 +667,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * pos = _engine->getObjPosition(child); pos += Common::Point(border.leftOffset, border.topOffset); - if (child < 600) { // Small HACK until I figre out where the last garbage child in main game window comes from + if (child < 650) { // Small HACK until I figre out where the last garbage child in main game window comes from if (!_assets.contains(child)) { _assets[child] = new ImageAsset(child, _graphics); } @@ -738,6 +738,7 @@ void Gui::drawDraggedObject() { void Gui::updateWindow(WindowReference winID, bool containerOpen) { + if (winID == kNoWindow) return; if (winID == kSelfWindow || containerOpen) { WindowData &data = findWindowData(winID); if (winID == kCommandsWindow) { @@ -880,6 +881,32 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { return nullptr; } +WindowReference Gui::getObjWindow(ObjID objID) { + switch (objID) { + case 0xfffc: return kExitsWindow; + case 0xfffd: return kSelfWindow; + case 0xfffe: return kOutConsoleWindow; + case 0xffff: return kCommandsWindow; + } + + return findObjWindow(objID); +} + +WindowReference Gui::findObjWindow(ObjID objID) { + // This is a bit of a HACK, we take advantage of the consecutive nature of references + for (uint i = kCommandsWindow; i <= kDiplomaWindow; i++) { + const WindowData &data = getWindowData((WindowReference)i); + if (data.objRef == objID) { return data.refcon; } + } + + for (uint i = kInventoryStart; i < _inventoryWindows.size() + kInventoryStart; i++) { + const WindowData &data = getWindowData((WindowReference)i); + if (data.objRef == objID) { return data.refcon; } + } + + return kNoWindow; +} + void Gui::checkSelect(ObjID obj, const Common::Event &event, const Common::Rect & clickRect, WindowReference ref) { if (_engine->isObjVisible(obj) && _engine->isObjClickable(obj) && diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 54e7b66945..cd0799d66d 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -208,6 +208,9 @@ public: uint getObjWidth(ObjID obj); uint getObjHeight(ObjID obj); + WindowReference getObjWindow(ObjID objID); + WindowReference findObjWindow(ObjID objID); + // Event processors bool processCommandEvents(WindowClick click, Common::Event &event); bool processMainGameEvents(WindowClick click, Common::Event &event); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index b9c46da8e4..061438207b 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -665,11 +665,9 @@ void MacVentureEngine::checkObject(QueuedObject old) { bool hasChanged = false; debug("Check Object[%d] parent[%d] x[%d] y[%d]", old.object, - _world->getObjAttr(old.object, kAttrParentObject), - _world->getObjAttr(old.object, kAttrPosX), - _world->getObjAttr(old.object, kAttrPosY)); - //bool incoming = isIncomingObj(objID); - //if (incoming) removeIncoming(objID); + old.parent, + old.x, + old.y); ObjID id = old.object; if (id == 1) { if (old.parent != _world->getObjAttr(id, kAttrParentObject)) { @@ -688,7 +686,7 @@ void MacVentureEngine::checkObject(QueuedObject old) { hasChanged = true; } - WindowReference newWin = getObjWindow(id); + WindowReference newWin = findParentWindow(id); if (newWin) { _gui->addChild(newWin, id); hasChanged = true; @@ -887,28 +885,13 @@ uint MacVentureEngine::getOverlapPercent(ObjID one, ObjID other) { } WindowReference MacVentureEngine::getObjWindow(ObjID objID) { - switch (objID) { - case 0xfffc: return kExitsWindow; - case 0xfffd: return kSelfWindow; - case 0xfffe: return kOutConsoleWindow; - case 0xffff: return kCommandsWindow; - } - - return findObjWindow(objID); -} - -WindowReference MacVentureEngine::findObjWindow(ObjID objID) { - // This is a bit of a hack, we take advantage of the consecutive nature of references - for (uint i = kCommandsWindow; i <= kDiplomaWindow; i++) { - const WindowData &data = _gui->getWindowData((WindowReference)i); - if (data.objRef == objID) { return data.refcon; } - } - return kNoWindow; + return _gui->getObjWindow(objID); } WindowReference MacVentureEngine::findParentWindow(ObjID objID) { if (objID == 1) return kSelfWindow; ObjID parent = _world->getObjAttr(objID, kAttrParentObject); + if (parent == 0) return kNoWindow; return getObjWindow(parent); } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 043218c8a0..735dda51cc 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -196,7 +196,7 @@ public: void enqueueObject(ObjectQueueID type, ObjID objID, ObjID target = 0); void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text); - + void runObjQueue(); bool printTexts(); @@ -239,7 +239,6 @@ public: uint getOverlapPercent(ObjID one, ObjID other); WindowReference getObjWindow(ObjID objID); - WindowReference findObjWindow(ObjID objID); WindowReference findParentWindow(ObjID objID); Common::Point getDeltaPoint(); @@ -275,7 +274,7 @@ private: // Data loading bool loadGlobalSettings(); bool loadTextHuffman(); - + const char* getGameFileName() const; private: // Attributes -- cgit v1.2.3 From 87540eaa8f2b6664ff916605bd8bc57a7658cec3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 8 Jul 2016 12:05:07 +0200 Subject: MACVENTURE: Fix error with second scene --- engines/macventure/gui.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 9671dc0f5f..1c626fef81 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -683,11 +683,14 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface, pos.x, pos.y, kBlitOR); // For test + /* surface->frameRect(Common::Rect( pos.x, pos.y, - pos.x + _assets[child]->getWidth(), - pos.y + _assets[child]->getHeight()), kColorGreen); + pos.x + _assets[child]->getWidth() + 1, + pos.y + _assets[child]->getHeight() + 1), kColorGreen); + */ + } } @@ -736,7 +739,6 @@ void Gui::drawDraggedObject() { } } - void Gui::updateWindow(WindowReference winID, bool containerOpen) { if (winID == kNoWindow) return; if (winID == kSelfWindow || containerOpen) { -- cgit v1.2.3 From 6da240a6e75d9e79d6254a338b905fbb2568d0e0 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 8 Jul 2016 12:32:42 +0200 Subject: MACVENTURE: Fix object selection in inventory --- engines/macventure/gui.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 1c626fef81..43dfe71883 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -683,18 +683,14 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface, pos.x, pos.y, kBlitOR); // For test - /* - surface->frameRect(Common::Rect( + /*surface->frameRect(Common::Rect( pos.x, pos.y, pos.x + _assets[child]->getWidth() + 1, pos.y + _assets[child]->getHeight() + 1), kColorGreen); */ - } - } - } void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { @@ -1258,19 +1254,13 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { // Find the appropriate window - uint ref = 0; - uint i; - for (uint i = 0; i < _inventoryWindows.size(); i++) { - if (_inventoryWindows[i]->hasAllFocus()) { // HACK - ref = i; - } - } - + WindowReference ref = findWindowAtPoint(event.mouse); + Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); ObjID child; Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ - Common::Rect clickRect = calculateClickRect(event.mouse, _inventoryWindows[i]->getDimensions()); + Common::Rect clickRect = calculateClickRect(event.mouse, win->getDimensions()); for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { child = (*it).obj; checkSelect(child, event, clickRect, (WindowReference)ref); -- cgit v1.2.3 From 4662642bc3f8ac2e680d48e9bf34c703991c8652 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 8 Jul 2016 12:41:44 +0200 Subject: MACVENTURE: Adjust drag selection to account for window movement --- engines/macventure/gui.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 43dfe71883..f8430e1efa 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -827,6 +827,7 @@ void Gui::printText(const Common::String & text) { WindowReference Gui::findWindowAtPoint(Common::Point point) { + // HACK, MIGHT NEED TO LOOK INTO THE Graphcis::MacWindow dimensions to account for window movement Common::List::iterator it; for (it = _windowData->begin(); it != _windowData->end(); it++) { if (it->bounds.contains(point) && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered @@ -839,7 +840,8 @@ WindowReference Gui::findWindowAtPoint(Common::Point point) { Common::Point Gui::getWindowSurfacePos(WindowReference reference) { const WindowData &data = getWindowData(reference); BorderBounds border = borderBounds(data.type); - return Common::Point(data.bounds.left + border.leftOffset, data.bounds.top + border.topOffset); + Graphics::MacWindow *win = findWindow(reference); + return Common::Point(win->getDimensions().left + border.leftOffset, win->getDimensions().top + border.topOffset); } WindowData & Gui::findWindowData(WindowReference reference) { @@ -1251,7 +1253,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (_engine->needsClickToContinue()) return true; - if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { + if (event.type == Common::EVENT_LBUTTONDOWN) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); -- cgit v1.2.3 From 8aec5e1cdb1e35a8a3dd03fd58cad493c303f434 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 9 Jul 2016 12:54:26 +0200 Subject: MACVENTURE: Fix inventory --- engines/macventure/macventure.cpp | 9 ++++----- engines/macventure/world.cpp | 35 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 061438207b..bd3374e894 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -182,7 +182,7 @@ void MacVentureEngine::activateCommand(ControlAction id) { _clickToContinue = false; _paused = true; return; - } + } if (id != _activeControl) { if (_activeControl) _activeControl = kNoCommand; @@ -327,10 +327,10 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool selectObject(objID); _destObject = objID; _deltaPoint = Common::Point(0, 0); - if (!_cmdReady) { + if (!_cmdReady) { selectControl(kActivateObject); _activeControl = kActivateObject; - _cmdReady = true; + _cmdReady = true; } preparedToRun(); } else { @@ -532,7 +532,6 @@ void MacVentureEngine::selectObject(ObjID objID) { _selectedObjs.push_back(objID); highlightExit(objID); } - _deltaPoint = getObjPosition(objID); } void MacVentureEngine::unselectObject(ObjID objID) { @@ -548,7 +547,7 @@ void MacVentureEngine::unselectObject(ObjID objID) { void MacVentureEngine::updateExits() { // exitWin.killControls(); - _gui->unselectExits(); + _gui->unselectExits(); Common::Array exits = _world->getChildren(_world->getObjAttr(1, kAttrParentObject), true); for (uint i = 0; i < exits.size(); i++) diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 15e3c2a531..ec20ba6b20 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -6,32 +6,32 @@ namespace MacVenture { World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { - _resourceManager = resMan; + _resourceManager = resMan; _engine = engine; if (!loadStartGameFileName()) error("Could not load initial game configuration"); Common::File saveGameFile; - if (!saveGameFile.open(_startGameFileName)) + if (!saveGameFile.open(_startGameFileName)) error("Could not load initial game configuration"); debug("Loading save game state from %s", _startGameFileName.c_str()); Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); - _saveGame = new SaveGame(_engine, saveGameRes); + _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); calculateObjectRelations(); - - _gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); - + + _gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); + delete saveGameRes; - saveGameFile.close(); + saveGameFile.close(); } World::~World() { - + if (_saveGame) delete _saveGame; @@ -66,10 +66,10 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) { if (attrID == kAttrPosX || attrID == kAttrPosY) {} // Round to scale - - if (attrID == kAttrParentObject) + + if (attrID == kAttrParentObject) setParent(objID, value); - + if (attrID < kAttrOtherDoor) _engine->enqueueObject(kUpdateObject, objID); @@ -87,17 +87,17 @@ bool MacVenture::World::isObjActive(ObjID obj) { Common::Point p = _engine->getDeltaPoint(); ControlAction selectedControl = _engine->getSelectedControl(); if (!getAncestor(obj)) return false; // If our ancestor is the garbage (obj 0), we're inactive - if (_engine->getInvolvedObjects() >= 2 && // If (we need > 1 objs for the command) && + if (_engine->getInvolvedObjects() >= 2 && // If (we need > 1 objs for the command) && destObj > 0 && // we have a destination object && !getAncestor(destObj)) // but that destination object is in the garbage return false; - if (selectedControl != kMoveObject) return true; // We only need one + if (selectedControl != kMoveObject) return true; // We only need one // Handle move object if (!isObjDraggable(obj)) return false; // We can't move it if (getObjAttr(1, kAttrParentObject) != destObj) return true; // if the target is not the player's parent, we can go Common::Rect rect(kScreenWidth, kScreenHeight); rect.top -= getObjAttr(obj, kAttrPosY) + p.y; - rect.left -= getObjAttr(obj, kAttrPosX) + p.x; + rect.left -= getObjAttr(obj, kAttrPosX) + p.x; return intersects(obj, rect); } @@ -157,7 +157,7 @@ void World::releaseChildren(ObjID objID) { Common::String World::getText(ObjID objID, ObjID source, ObjID target) { TextAsset text = TextAsset(_engine, objID, source, target, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); - + return *text.decode(); } @@ -169,8 +169,7 @@ bool World::isObjDraggable(ObjID objID) { } bool World::intersects(ObjID objID, Common::Rect rect) { - warning("Intersects: unimplemented"); - return true; + return _engine->getObjBounds(objID).intersects(rect); } bool World::loadStartGameFileName() { @@ -275,7 +274,7 @@ void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * AttributeGroup g; for (int j = 0; j < settings.numObjects; ++j) g.push_back(res->readUint16BE()); - + _groups.push_back(g); } } -- cgit v1.2.3 From b35ef40895989d7d64e0f2dd7d0a055082b59569 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 9 Jul 2016 13:09:11 +0200 Subject: MACVENTURE: Fix temporal window reallocation --- engines/macventure/macventure.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index bd3374e894..9994df2c73 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -856,10 +856,14 @@ ObjID MacVentureEngine::getParent(ObjID objID) { } Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { - BorderBounds bounds = _gui->borderBounds(_gui->getWindowData(findParentWindow(objID)).type); // HACK Common::Point pos = getObjPosition(objID); - pos.x += bounds.leftOffset; - pos.y += bounds.topOffset; + + WindowReference win = findParentWindow(objID); + if (win != kNoWindow) { // If it's not in a window YET, we don't really care about the border + BorderBounds bounds = _gui->borderBounds(_gui->getWindowData(win).type); // HACK + pos.x += bounds.leftOffset; + pos.y += bounds.topOffset; + } uint w = _gui->getObjWidth(objID); // This shouldn't go here uint h = _gui->getObjHeight(objID); return Common::Rect(pos.x, pos.y, pos.x + w, pos.y + h); -- cgit v1.2.3 From 9ac125392587aa02f1e874fd5bf095cb56da9564 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 9 Jul 2016 13:49:28 +0200 Subject: MACVENTURE: Fix the removal of objects in window --- engines/macventure/gui.cpp | 55 +++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index f8430e1efa..05c479be83 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -270,7 +270,7 @@ void Gui::addChild(WindowReference target, ObjID child) { } void Gui::removeChild(WindowReference target, ObjID child) { - WindowData data = findWindowData(target); + WindowData &data = findWindowData(target); uint index = 0; for (;index < data.children.size(); index++) { if (data.children[index].obj == child) break; @@ -388,8 +388,8 @@ void Gui::loadGraphics() { bool Gui::loadMenus() { - // We assume that, if there are static menus, we don't need dynamic ones - if (menuSubItems) { + if (kLoadStaticMenus) { + // We assume that, if there are static menus, we don't need dynamic ones _menu->addStaticMenus(menuSubItems); return true; } @@ -667,29 +667,27 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * pos = _engine->getObjPosition(child); pos += Common::Point(border.leftOffset, border.topOffset); - if (child < 650) { // Small HACK until I figre out where the last garbage child in main game window comes from - if (!_assets.contains(child)) { - _assets[child] = new ImageAsset(child, _graphics); - } + if (!_assets.contains(child)) { + _assets[child] = new ImageAsset(child, _graphics); + } + _assets[child]->blitInto( + surface, + pos.x, + pos.y, + mode); + + if (_engine->isObjSelected(child)) _assets[child]->blitInto( - surface, - pos.x, - pos.y, - mode); - - if (_engine->isObjSelected(child)) - _assets[child]->blitInto( - surface, pos.x, pos.y, kBlitOR); - - // For test - /*surface->frameRect(Common::Rect( - pos.x, - pos.y, - pos.x + _assets[child]->getWidth() + 1, - pos.y + _assets[child]->getHeight() + 1), kColorGreen); - */ - } + surface, pos.x, pos.y, kBlitOR); + + // For test + /*surface->frameRect(Common::Rect( + pos.x, + pos.y, + pos.x + _assets[child]->getWidth() + 1, + pos.y + _assets[child]->getHeight() + 1), kColorGreen); + */ } } @@ -755,20 +753,17 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { mode = kBlitBIC; if (off || flag) { mode = kBlitXOR; - } - else if (_engine->isObjSelected(child)) { + } else if (!off && _engine->isObjSelected(child)) { mode = kBlitOR; } children[i] = DrawableObject(child, mode); - } - else { + } else { children[i] = DrawableObject(child, kBlitXOR); } } if (winID == kMainGameWindow) { drawMainGameWindow(); - } - else { + } else { Graphics::MacWindow *winRef = findWindow(winID); winRef->getSurface()->fillRect(data.bounds, kColorGray); } -- cgit v1.2.3 From fdd949bb00d5d3b5bda54ef85f8fde3682dc2c27 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 9 Jul 2016 19:46:10 +0200 Subject: MACVENTURE: Fix exits drawing --- engines/macventure/gui.cpp | 12 ++++++++---- engines/macventure/gui.h | 9 +++++---- engines/macventure/macventure.cpp | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 05c479be83..5a26482e9d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -717,8 +717,8 @@ void Gui::drawDraggedObject() { ImageAsset *asset = _assets[_draggedObj.id]; _draggedSurface.create(asset->getWidth(), asset->getHeight(), _screen.format); - _screen.copyRectToSurface(_draggedSurface, _draggedObj.pos.x, _draggedObj.pos.y, - Common::Rect(asset->getWidth() - 1, asset->getHeight() - 1)); + //_screen.copyRectToSurface(_draggedSurface, _draggedObj.pos.x, _draggedObj.pos.y, + // Common::Rect(asset->getWidth() - 1, asset->getHeight() - 1)); asset->blitInto(&_draggedSurface, 0, 0, kBlitBIC); @@ -773,6 +773,10 @@ void Gui::updateWindow(WindowReference winID, bool containerOpen) { } } +void Gui::clearExits() { + _exitsData->clear(); +} + void Gui::unselectExits() { Common::Array::const_iterator it = _exitsData->begin(); for (; it != _exitsData->end(); ++it) { @@ -806,8 +810,8 @@ void Gui::updateExit(ObjID obj) { data.titleLength = 0; data.refcon = (ControlAction)obj; // Objects can be exits (actions) Common::Point pos = _engine->getObjExitPosition(obj); - pos.x = border.leftOffset; - pos.y = border.topOffset; + pos.x += border.leftOffset; + pos.y += border.topOffset; data.bounds = Common::Rect(pos.x, pos.y, pos.x + kExitButtonWidth, pos.y + kExitButtonHeight); data.visible = true; diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index cd0799d66d..55dd180029 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -112,7 +112,7 @@ struct WindowData { bool updateScroll; }; -enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc) +enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc) kControlExitBox = 0, kControlExamine = 1, kControlOpen = 2, @@ -152,7 +152,7 @@ struct ControlData { uint16 scrollMax; uint16 scrollMin; uint16 cdef; - ControlAction refcon; + ControlAction refcon; ControlType type; uint8 titleLength; char* title; @@ -240,6 +240,7 @@ public: void addChild(WindowReference target, ObjID child); void removeChild(WindowReference target, ObjID child); + void clearExits(); void unselectExits(); void updateExit(ObjID id); @@ -274,7 +275,7 @@ private: // Attributes Graphics::ManagedSurface _draggedSurface; DraggedObj _draggedObj; - + Cursor *_cursor; ConsoleText *_consoleText; @@ -359,7 +360,7 @@ public: ~Cursor() {} void tick() { - executeState(); + executeState(); changeState(kTickCol); } diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 9994df2c73..28bfa65a98 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -546,7 +546,7 @@ void MacVentureEngine::unselectObject(ObjID objID) { void MacVentureEngine::updateExits() { - // exitWin.killControls(); + _gui->clearExits(); _gui->unselectExits(); Common::Array exits = _world->getChildren(_world->getObjAttr(1, kAttrParentObject), true); -- cgit v1.2.3 From b6acfe868ce4b614bfdc9d510e10e35923a7fed6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 10 Jul 2016 18:56:05 +0200 Subject: MACVENTURE: Fix click-through and refactor --- engines/macventure/gui.cpp | 32 +++++++++++++++++--------------- engines/macventure/gui.h | 3 ++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 5a26482e9d..880ec286d0 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -906,13 +906,20 @@ WindowReference Gui::findObjWindow(ObjID objID) { return kNoWindow; } -void Gui::checkSelect(ObjID obj, const Common::Event &event, const Common::Rect & clickRect, WindowReference ref) { - if (_engine->isObjVisible(obj) && - _engine->isObjClickable(obj) && - isRectInsideObject(clickRect, obj)) - { - selectDraggable(obj, ref, event.mouse); +bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { + return (_engine->isObjVisible(obj) && + _engine->isObjClickable(obj) && + isRectInsideObject(clickRect, obj)); +} + +void Gui::checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { + ObjID child; + for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { + if (canBeSelected((*it).obj, event, clickRect, ref)) { + child = (*it).obj; + } } + if (child != 0) selectDraggable(child, ref, event.mouse); } bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { @@ -1182,14 +1189,11 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { WindowData &data = findWindowData(kMainGameWindow); - ObjID child; + ObjID child = 0; Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ Common::Rect clickRect = calculateClickRect(event.mouse, _mainGameWindow->getDimensions()); - for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { - child = (*it).obj; - checkSelect(child, event, clickRect, kMainGameWindow); - } + checkSelect(data, event, clickRect, kMainGameWindow); } return false; } @@ -1262,10 +1266,8 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ Common::Rect clickRect = calculateClickRect(event.mouse, win->getDimensions()); - for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { - child = (*it).obj; - checkSelect(child, event, clickRect, (WindowReference)ref); - } + checkSelect(data, event, clickRect, (WindowReference)ref); + } return true; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 55dd180029..cd8c162a1d 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -314,7 +314,8 @@ private: // Methods Graphics::MacWindow *findWindow(WindowReference reference); // Utils - void checkSelect(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); + bool canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); + void checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); bool isRectInsideObject(Common::Rect target, ObjID obj); void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); -- cgit v1.2.3 From a5a094b6bdf1dd61f270e60068c42d9f62b8c447 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 10 Jul 2016 23:03:26 +0200 Subject: MACVENTURE: Begin fixing second inventory problem --- engines/macventure/gui.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 880ec286d0..1f07e7c7c4 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -830,7 +830,8 @@ WindowReference Gui::findWindowAtPoint(Common::Point point) { Common::List::iterator it; for (it = _windowData->begin(); it != _windowData->end(); it++) { if (it->bounds.contains(point) && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered - return it->refcon; + if (findWindow(it->refcon)->isActive()) + return it->refcon; } } return kNoWindow; @@ -957,6 +958,7 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point sta void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) { WindowReference destinationWindow = findWindowAtPoint(pos); + if (destinationWindow == kNoWindow) return; if (_draggedObj.id != 0) { if (_draggedObj.hasMoved) { ObjID destObject = getWindowData(destinationWindow).objRef; @@ -1260,6 +1262,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); + if (ref == kNoWindow) return false; Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); ObjID child; -- cgit v1.2.3 From 19d732186760bb13be49fb8d5ca4c45de0f77d86 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 12 Jul 2016 11:49:05 +0200 Subject: MACVENTURE: Fix torch drawing problem --- engines/macventure/gui.cpp | 15 +++++++-------- engines/macventure/gui.h | 3 +-- engines/macventure/macventure.cpp | 5 +++-- engines/macventure/script.cpp | 25 ++++++++++++------------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 1f07e7c7c4..b4fada64b8 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1116,14 +1116,13 @@ bool Gui::tryCloseWindow(WindowReference winID) { return true; } -uint Gui::getObjWidth(ObjID obj) { - if (!_assets.contains(obj)) return 0; - return _assets[obj]->getWidth(); -} - -uint Gui::getObjHeight(ObjID obj) { - if (!_assets.contains(obj)) return 0; - return _assets[obj]->getHeight(); +Common::Point Gui::getObjMeasures(ObjID obj) { + if (!_assets.contains(obj)) { + _assets[obj] = new ImageAsset(obj, _graphics); + } + uint w = _assets[obj]->getWidth(); + uint h = _assets[obj]->getHeight(); + return Common::Point(w, h); } bool Gui::processEvent(Common::Event &event) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index cd8c162a1d..2c4ef3fd2a 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -205,8 +205,7 @@ public: WindowReference createInventoryWindow(ObjID objRef); bool tryCloseWindow(WindowReference winID); - uint getObjWidth(ObjID obj); - uint getObjHeight(ObjID obj); + Common::Point getObjMeasures(ObjID obj); WindowReference getObjWindow(ObjID objID); WindowReference findObjWindow(ObjID objID); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 28bfa65a98..211ba43971 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -864,8 +864,9 @@ Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { pos.x += bounds.leftOffset; pos.y += bounds.topOffset; } - uint w = _gui->getObjWidth(objID); // This shouldn't go here - uint h = _gui->getObjHeight(objID); + Common::Point measures = _gui->getObjMeasures(objID); + uint w = measures.x; + uint h = measures.y; return Common::Rect(pos.x, pos.y, pos.x + w, pos.y + h); } diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5e8bcd69a2..5b86c31e84 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -27,8 +27,8 @@ #include "macventure/world.h" #include "macventure/container.h" -namespace MacVenture { - +namespace MacVenture { + ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; @@ -57,13 +57,13 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat return resume(true); } -bool ScriptEngine::resume(bool execAll) { +bool ScriptEngine::resume(bool execAll) { debug(2, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; } - return false; + return false; } void ScriptEngine::reset() { @@ -107,7 +107,7 @@ bool ScriptEngine::execFrame(bool execAll) { } doFamily = true; } - } + } // Halted in saves if (frame->haltedInSaves) { @@ -139,7 +139,7 @@ bool ScriptEngine::execFrame(bool execAll) { } } } while (highest); - + _frames.pop_front(); return false; } @@ -167,7 +167,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { ScriptAsset &script = frame->scripts.front(); debug(2, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; - byte op; + byte op; while (script.hasNext()) { op = script.fetch(); debug(3, "SCRIPT: I'm running operation %d", op); @@ -352,7 +352,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { case 0xba: //cancel priority range opbaCRAN(state, frame); break; - case 0xbb: //fork + case 0xbb: //fork if (opbbFORK(state, frame)) return true; break; @@ -1012,7 +1012,6 @@ void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { state->push(minutes); state->push(totalPlayTime); debug("Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); - } void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { @@ -1056,7 +1055,7 @@ void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { state->push(bounds.height()); } -void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { word b = state->pop(); word a = state->pop(); state->push(_engine->getOverlapPercent(b, a)); @@ -1168,10 +1167,10 @@ void ScriptEngine::op00NOOP(byte op) { -ScriptAsset::ScriptAsset(ObjID id, Container * container) { +ScriptAsset::ScriptAsset(ObjID id, Container * container) { _id = id; _container = container; - _ip = 0x0; + _ip = 0x0; loadInstructions(); } @@ -1206,4 +1205,4 @@ void ScriptAsset::loadInstructions() { debug(2, "SCRIPT: Load %d instructions for script %d", amount, _id); } -} // End of namespace MacVenture \ No newline at end of file +} // End of namespace MacVenture -- cgit v1.2.3 From bc29c37f3273ca98fa813349dd1bd66a7af09e80 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 12 Jul 2016 22:02:32 +0200 Subject: MACVENUTRE: Fix PPIC0 Drawing --- engines/macventure/image.cpp | 56 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 1aae1727ef..c964ce4341 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -64,7 +64,7 @@ ImageAsset::ImageAsset(ObjID original, Container * container) { _id = (original * 2); _mask = (original * 2) + 1; - _container = container; + _container = container; decodePPIC(_id, _imgData); if (_container->getItemByteSize(_mask)) // Has mask @@ -124,9 +124,40 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &data) { warning("Untested loading function: decode PPIC0"); uint words = _bitWidth >> 4; - for (uint y = 0; y <_bitHeight; y++) - for (uint x = 0; x < words; x++) - data[y * words + x] = (byte)stream.getBits(8); + uint bytes = _bitWidth & 0xF; + uint v = 0; + uint p = 0; + for (uint y = 0; y <_bitHeight; y++) { + for (uint x = 0; x < words; x++) { + v = stream.peekBits(32); + stream.skip(16); + v >>= 16 - (stream.pos() % 8); + data[p] = (v >> 8) & 0xff; p++; + data[p] = v & 0xff; p++; + } + if (bytes) { + v = stream.getBits(bytes); + v <<= 16 - bytes; + data[p] = (v >> 8) & 0xff; p++; + data[p] = v & 0xff; p++; + } + } + /* + for (var i=0;i>>=16-ppic.bit; + bitmap.data[p++]=(v>>8)&0xff; + bitmap.data[p++]=v&0xff; + } + if (bytes) + { + v=ppic.bits(bytes); + v<<=16-bytes; + bitmap.data[p++]=(v>>8)&0xff; + bitmap.data[p++]=v&0xff; + } + */ } void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array &data) { @@ -211,7 +242,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st pos += blank; } - uint16 edge = _bitWidth & 3; + uint16 edge = _bitWidth & 3; if (edge) { pos = _rowBytes - blank; uint16 bits = 0; @@ -332,10 +363,10 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, } else if (_container->getItemByteSize(_id)) { switch (mode) { case MacVenture::kBlitBIC: - target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorWhite); + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight), kColorWhite); break; case MacVenture::kBlitOR: - target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight * 2), kColorBlack); + target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight), kColorBlack); break; default: break; @@ -345,7 +376,7 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, if (_container->getItemByteSize(_id) && mode > 0) { blitXOR(target, x, y, _imgData); } - } + } } bool ImageAsset::isPointInside(Common::Point point) { @@ -357,6 +388,9 @@ bool ImageAsset::isPointInside(Common::Point point) { } bool ImageAsset::isRectInside(Common::Rect rect) { + // HACK is it &&, or ||? + if (_maskData.empty()) return (rect.width() > 0 && rect.height() > 0); + for (uint y = rect.top; y < rect.top + rect.height(); y++) { uint bmpofs = y * _rowBytes; byte pix; @@ -389,7 +423,7 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; */ - + for (uint y = 0; y < _bitHeight; y++) { uint bmpofs = y * _rowBytes; byte pix = 0; @@ -418,7 +452,7 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy uint bmpofs = y * _rowBytes; byte pix = 0; for (uint x = 0; x < _bitWidth; x++) { - pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; } } @@ -470,7 +504,7 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy if (pix) { // We need to xor byte p = *((byte *)target->getBasePtr(ox + x, oy + y)); - *((byte *)target->getBasePtr(ox + x, oy + y)) = + *((byte *)target->getBasePtr(ox + x, oy + y)) = (p == kColorWhite) ? kColorBlack : kColorWhite; } } -- cgit v1.2.3 From d826fcb18b84f3e3eb3e4cad293122c9a44b9871 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 13:40:00 +0200 Subject: MACVENTURE: Fix drag screen overflow problem --- engines/macventure/gui.cpp | 114 +++++++++++++++++++++++++++------------------ engines/macventure/gui.h | 2 + 2 files changed, 70 insertions(+), 46 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index b4fada64b8..79df822eb0 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -203,6 +203,48 @@ void Gui::clearControls() { } } +void Gui::initWindows() { + // Game Controls Window + _controlsWindow = _wm.addWindow(false, false, false); + _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); + _controlsWindow->setActive(false); + _controlsWindow->setCallback(commandsWindowCallback, this); + loadBorder(_controlsWindow, "border_command.bmp", false); + loadBorder(_controlsWindow, "border_command.bmp", true); + + // Main Game Window + _mainGameWindow = _wm.addWindow(false, false, false); + _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); + _mainGameWindow->setActive(false); + _mainGameWindow->setCallback(mainGameWindowCallback, this); + loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); + + // In-game Output Console + _outConsoleWindow = _wm.addWindow(false, true, true); + _outConsoleWindow->setDimensions(getWindowData(kOutConsoleWindow).bounds); + _outConsoleWindow->setActive(false); + _outConsoleWindow->setCallback(outConsoleWindowCallback, this); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); + + // Self Window + _selfWindow = _wm.addWindow(false, true, false); + _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); + _selfWindow->setActive(false); + _selfWindow->setCallback(selfWindowCallback, this); + loadBorder(_selfWindow, "border_none.bmp", false); + loadBorder(_selfWindow, "border_none.bmp", true); + + // Exits Window + _exitsWindow = _wm.addWindow(false, false, false); + _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); + _exitsWindow->setActive(false); + _exitsWindow->setCallback(exitsWindowCallback, this); + loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); + loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); +} + const WindowData& Gui::getWindowData(WindowReference reference) { return findWindowData(reference); } @@ -280,49 +322,6 @@ void Gui::removeChild(WindowReference target, ObjID child) { data.children.remove_at(index); } -void Gui::initWindows() { - - // Game Controls Window - _controlsWindow = _wm.addWindow(false, false, false); - _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); - _controlsWindow->setActive(false); - _controlsWindow->setCallback(commandsWindowCallback, this); - loadBorder(_controlsWindow, "border_command.bmp", false); - loadBorder(_controlsWindow, "border_command.bmp", true); - - // Main Game Window - _mainGameWindow = _wm.addWindow(false, false, false); - _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); - _mainGameWindow->setActive(false); - _mainGameWindow->setCallback(mainGameWindowCallback, this); - loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); - - // In-game Output Console - _outConsoleWindow = _wm.addWindow(false, true, true); - _outConsoleWindow->setDimensions(Common::Rect(20, 20, 120, 120)); - _outConsoleWindow->setActive(false); - _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); - - // Self Window - _selfWindow = _wm.addWindow(false, true, false); - _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); - _selfWindow->setActive(false); - _selfWindow->setCallback(selfWindowCallback, this); - loadBorder(_selfWindow, "border_none.bmp", false); - loadBorder(_selfWindow, "border_none.bmp", true); - - // Exits Window - _exitsWindow = _wm.addWindow(false, false, false); - _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); - _exitsWindow->setActive(false); - _exitsWindow->setCallback(exitsWindowCallback, this); - loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); -} - void Gui::assignObjReferences() { findWindowData(kSelfWindow).objRef = 0; } @@ -824,6 +823,31 @@ void Gui::printText(const Common::String & text) { _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } +void Gui::moveDraggedObject(Common::Point target) { + Common::Point newPos = target + _draggedObj.mouseOffset; + bool movement = false; + // If we overflow, move the mouseOffset, not the position. + if (newPos.x < 0 || newPos.x + _assets[_draggedObj.id]->getWidth() >= kScreenWidth) { + _draggedObj.mouseOffset.x = _draggedObj.pos.x - target.x; + } else { + _draggedObj.pos.x = newPos.x; + movement = true; + } + + if (newPos.y < 0 || newPos.y + _assets[_draggedObj.id]->getHeight() >= kScreenHeight) { + _draggedObj.mouseOffset.y = _draggedObj.pos.y - target.y; + } else { + _draggedObj.pos.y = newPos.y; + movement = true; + } + + // TODO establish an absolute distance, such as _draggedObj.pos.sqrDist(_draggedObj.startPos); + _draggedObj.hasMoved |= movement && (newPos.sqrDist(_draggedObj.pos) >= kDragThreshold); + + // TODO DELETE MEEE + debug("Dragged obj position: (%d, %d), mouse offset: (%d, %d)", + _draggedObj.pos.x, _draggedObj.pos.y, _draggedObj.mouseOffset.x, _draggedObj.mouseOffset.y); +} WindowReference Gui::findWindowAtPoint(Common::Point point) { // HACK, MIGHT NEED TO LOOK INTO THE Graphcis::MacWindow dimensions to account for window movement @@ -1132,9 +1156,7 @@ bool Gui::processEvent(Common::Event &event) { if (event.type == Common::EVENT_MOUSEMOVE) { if (_draggedObj.id != 0) { - Common::Point newPos = event.mouse + _draggedObj.mouseOffset; - _draggedObj.hasMoved = newPos.sqrDist(_draggedObj.pos) >= kDragThreshold; - _draggedObj.pos = newPos; + moveDraggedObject(event.mouse); } processed = true; diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 2c4ef3fd2a..65f2ec5fdb 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -306,6 +306,8 @@ private: // Methods void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface); void drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface); + void moveDraggedObject(Common::Point target); + // Finders WindowReference findWindowAtPoint(Common::Point point); Common::Point getWindowSurfacePos(WindowReference reference); -- cgit v1.2.3 From 31a32963b4047e54fa1af93e4bf28c99a72ed580 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 14:39:56 +0200 Subject: MACVENTURE: Fix dragged object move recognition --- engines/macventure/gui.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 79df822eb0..7eccb16a95 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -56,7 +56,7 @@ enum { }; enum { - kDragThreshold = 1 + kDragThreshold = 5 }; static const Graphics::MenuData menuSubItems[] = { @@ -841,12 +841,17 @@ void Gui::moveDraggedObject(Common::Point target) { movement = true; } - // TODO establish an absolute distance, such as _draggedObj.pos.sqrDist(_draggedObj.startPos); - _draggedObj.hasMoved |= movement && (newPos.sqrDist(_draggedObj.pos) >= kDragThreshold); + // TODO FInd more elegant way of making pow2 + _draggedObj.hasMoved = movement && (_draggedObj.startPos.sqrDist(_draggedObj.pos) >= (kDragThreshold * kDragThreshold)); + + debug(4, "Dragged obj position: (%d, %d), mouse offset: (%d, %d), hasMoved: %d, dist: %d, threshold: %d", + _draggedObj.pos.x, _draggedObj.pos.y, + _draggedObj.mouseOffset.x, _draggedObj.mouseOffset.y, + _draggedObj.hasMoved, + _draggedObj.startPos.sqrDist(_draggedObj.pos), + kDragThreshold * kDragThreshold + ); - // TODO DELETE MEEE - debug("Dragged obj position: (%d, %d), mouse offset: (%d, %d)", - _draggedObj.pos.x, _draggedObj.pos.y, _draggedObj.mouseOffset.x, _draggedObj.mouseOffset.y); } WindowReference Gui::findWindowAtPoint(Common::Point point) { @@ -969,14 +974,14 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { return false; } -void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point startPos) { +void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point click) { if (_engine->isObjClickable(child) && _draggedObj.id == 0) { _draggedObj.hasMoved = false; _draggedObj.id = child; - _draggedObj.startPos = startPos; _draggedObj.startWin = origin; - _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - startPos; - _draggedObj.pos = startPos + _draggedObj.mouseOffset; + _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - click; + _draggedObj.pos = click + _draggedObj.mouseOffset; + _draggedObj.startPos = _draggedObj.pos; } } -- cgit v1.2.3 From 777923be660749e792d993be9f8f2c08fb801dc4 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 14:47:32 +0200 Subject: MACVENTURE: Correct object drop position --- engines/macventure/gui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 7eccb16a95..71a7d0c132 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -681,12 +681,12 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface, pos.x, pos.y, kBlitOR); // For test - /*surface->frameRect(Common::Rect( + surface->frameRect(Common::Rect( pos.x, pos.y, pos.x + _assets[child]->getWidth() + 1, pos.y + _assets[child]->getHeight() + 1), kColorGreen); - */ + } } @@ -991,7 +991,7 @@ void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleC if (_draggedObj.id != 0) { if (_draggedObj.hasMoved) { ObjID destObject = getWindowData(destinationWindow).objRef; - pos -= _draggedObj.startPos; + pos -= (_draggedObj.startPos - _draggedObj.mouseOffset); pos = localize(pos, _draggedObj.startWin, destinationWindow); debug("drop the object at obj %d, pos (%d, %d)", destObject, pos.x, pos.y); -- cgit v1.2.3 From 2ba8b1ca8c418e3c3b3f5d90155e1a76eb95f16e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 15:31:07 +0200 Subject: MACVENTURE: FIx pesky random drag selection --- engines/macventure/gui.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 71a7d0c132..a056e1ba23 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -716,8 +716,8 @@ void Gui::drawDraggedObject() { ImageAsset *asset = _assets[_draggedObj.id]; _draggedSurface.create(asset->getWidth(), asset->getHeight(), _screen.format); - //_screen.copyRectToSurface(_draggedSurface, _draggedObj.pos.x, _draggedObj.pos.y, - // Common::Rect(asset->getWidth() - 1, asset->getHeight() - 1)); + _screen.copyRectToSurface(_draggedSurface, _draggedObj.pos.x, _draggedObj.pos.y, + Common::Rect(asset->getWidth() - 1, asset->getHeight() - 1)); asset->blitInto(&_draggedSurface, 0, 0, kBlitBIC); @@ -936,14 +936,8 @@ WindowReference Gui::findObjWindow(ObjID objID) { return kNoWindow; } -bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { - return (_engine->isObjVisible(obj) && - _engine->isObjClickable(obj) && - isRectInsideObject(clickRect, obj)); -} - void Gui::checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { - ObjID child; + ObjID child = 0; for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { if (canBeSelected((*it).obj, event, clickRect, ref)) { child = (*it).obj; @@ -952,6 +946,12 @@ void Gui::checkSelect(const WindowData &data, const Common::Event &event, const if (child != 0) selectDraggable(child, ref, event.mouse); } +bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { + return (_engine->isObjVisible(obj) && + _engine->isObjClickable(obj) && + isRectInsideObject(clickRect, obj)); +} + bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { if (_assets.contains(obj) && //_engine->isObjClickable(obj) && @@ -993,7 +993,7 @@ void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleC ObjID destObject = getWindowData(destinationWindow).objRef; pos -= (_draggedObj.startPos - _draggedObj.mouseOffset); pos = localize(pos, _draggedObj.startWin, destinationWindow); - debug("drop the object at obj %d, pos (%d, %d)", destObject, pos.x, pos.y); + debug("drop the object %d at obj %d, pos (%d, %d)", _draggedObj.id, destObject, pos.x, pos.y); _engine->handleObjectDrop(_draggedObj.id, pos, destObject); } -- cgit v1.2.3 From c36f8c429fd213aa9b3fbe58c894036a1dc26473 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 18:48:50 +0200 Subject: MACVENTURE: Soften conditions for object selection --- engines/macventure/gui.cpp | 14 ++++++-------- engines/macventure/image.cpp | 1 - 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index a056e1ba23..0b7606ce51 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -308,6 +308,9 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array } void Gui::addChild(WindowReference target, ObjID child) { + // HACK WRONG!! Please delete me when you are done testing! + if (child == 92) return; // Avoid adding the stones in the waterfall + findWindowData(target).children.push_back(DrawableObject(child, kBlitBIC)); } @@ -819,7 +822,7 @@ void Gui::updateExit(ObjID obj) { } void Gui::printText(const Common::String & text) { - debug("Print Text: %s", text); + debug(1, "Print Text: %s", text.c_str()); _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } @@ -947,16 +950,12 @@ void Gui::checkSelect(const WindowData &data, const Common::Event &event, const } bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { - return (_engine->isObjVisible(obj) && - _engine->isObjClickable(obj) && + return (_engine->isObjClickable(obj) && isRectInsideObject(clickRect, obj)); } bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { - if (_assets.contains(obj) && - //_engine->isObjClickable(obj) && - _engine->isObjVisible(obj)) - { + if (_assets.contains(obj)) { Common::Rect bounds = _engine->getObjBounds(obj); Common::Rect intersection = bounds.findIntersectingRect(target); // We translate it to the image's coord system @@ -966,7 +965,6 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { intersection.left - bounds.left + intersection.width(), intersection.top - bounds.top + intersection.height()); - if (_assets[obj]->isRectInside(intersection)) { return true; } diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index c964ce4341..21986e382c 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -122,7 +122,6 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { } void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &data) { - warning("Untested loading function: decode PPIC0"); uint words = _bitWidth >> 4; uint bytes = _bitWidth & 0xF; uint v = 0; -- cgit v1.2.3 From f8efc58a59bd94579dd58f46bbcaeb059f691995 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 19:09:14 +0200 Subject: MACVENTURE: Fix inventory window selection --- engines/macventure/gui.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 0b7606ce51..415e02e35b 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -308,9 +308,6 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array } void Gui::addChild(WindowReference target, ObjID child) { - // HACK WRONG!! Please delete me when you are done testing! - if (child == 92) return; // Avoid adding the stones in the waterfall - findWindowData(target).children.push_back(DrawableObject(child, kBlitBIC)); } @@ -609,7 +606,7 @@ void Gui::drawInventories() { Graphics::ManagedSurface *srf; for (uint i = 0; i < _inventoryWindows.size(); i++) { const WindowData &data = getWindowData((WindowReference)(kInventoryStart + i)); - srf = findWindow(data.refcon)->getSurface(); // HACK + srf = findWindow(data.refcon)->getSurface(); BorderBounds border = borderBounds(data.type); srf->fillRect(Common::Rect( border.leftOffset, @@ -858,11 +855,12 @@ void Gui::moveDraggedObject(Common::Point target) { } WindowReference Gui::findWindowAtPoint(Common::Point point) { - // HACK, MIGHT NEED TO LOOK INTO THE Graphcis::MacWindow dimensions to account for window movement Common::List::iterator it; + Graphics::MacWindow *win; for (it = _windowData->begin(); it != _windowData->end(); it++) { - if (it->bounds.contains(point) && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered - if (findWindow(it->refcon)->isActive()) + win = findWindow(it->refcon); + if (win && win->getDimensions().contains(point) && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered + if (win->isActive()) return it->refcon; } } @@ -1286,6 +1284,8 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); + // TODO DELETE MEEEE! + debug("WindowFound: %d", ref); if (ref == kNoWindow) return false; Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); @@ -1306,21 +1306,11 @@ void Gui::processCursorTick() { void Gui::handleSingleClick(Common::Point pos) { debug("Single Click"); handleDragRelease(pos, false, false); - - // HACK For test, please delete me - //WindowReference destinationWindow = findWindowAtPoint(pos); - //_engine->handleObjectSelect(_draggedObj.id, destinationWindow, false, false); - //_draggedObj.id = 0; } void Gui::handleDoubleClick(Common::Point pos) { debug("Double Click"); handleDragRelease(pos, false, true); - - // HACK For test, please delete me - //WindowReference destinationWindow = findWindowAtPoint(pos); - //_engine->handleObjectSelect(_draggedObj.id, destinationWindow, false, true); - //_draggedObj.id = 0; } /* Ugly switches */ -- cgit v1.2.3 From e32c126348df69d8ec15ef3b67d6250935325860 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 19:17:25 +0200 Subject: MACVENTURE: Refactor asset load checking --- engines/macventure/gui.cpp | 49 ++++++++++++++++++++-------------------------- engines/macventure/gui.h | 2 ++ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 415e02e35b..a313e3e94d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -580,9 +580,7 @@ void Gui::drawMainGameWindow() { _mainGameWindow->setDirty(true); if (data.objRef > 0 && data.objRef < 2000) { - if (!_assets.contains(objRef)) { - _assets[objRef] = new ImageAsset(objRef, _graphics); - } + ensureAssetLoaded(objRef); _assets[objRef]->blitInto( _mainGameWindow->getSurface(), @@ -665,10 +663,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); pos += Common::Point(border.leftOffset, border.topOffset); - - if (!_assets.contains(child)) { - _assets[child] = new ImageAsset(child, _graphics); - } + ensureAssetLoaded(child); _assets[child]->blitInto( surface, @@ -710,9 +705,7 @@ void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * sur void Gui::drawDraggedObject() { if (_draggedObj.id != 0) { - if (!_assets.contains(_draggedObj.id)) - _assets[_draggedObj.id] = new ImageAsset(_draggedObj.id, _graphics); - + ensureAssetLoaded(_draggedObj.id); ImageAsset *asset = _assets[_draggedObj.id]; _draggedSurface.create(asset->getWidth(), asset->getHeight(), _screen.format); @@ -953,21 +946,17 @@ bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rec } bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { - if (_assets.contains(obj)) { - Common::Rect bounds = _engine->getObjBounds(obj); - Common::Rect intersection = bounds.findIntersectingRect(target); - // We translate it to the image's coord system - intersection = Common::Rect( - intersection.left - bounds.left, - intersection.top - bounds.top, - intersection.left - bounds.left + intersection.width(), - intersection.top - bounds.top + intersection.height()); - - if (_assets[obj]->isRectInside(intersection)) { - return true; - } - } - return false; + ensureAssetLoaded(obj); + Common::Rect bounds = _engine->getObjBounds(obj); + Common::Rect intersection = bounds.findIntersectingRect(target); + // We translate it to the image's coord system + intersection = Common::Rect( + intersection.left - bounds.left, + intersection.top - bounds.top, + intersection.left - bounds.left + intersection.width(), + intersection.top - bounds.top + intersection.height()); + + return _assets[obj]->isRectInside(intersection); } void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point click) { @@ -1142,9 +1131,7 @@ bool Gui::tryCloseWindow(WindowReference winID) { } Common::Point Gui::getObjMeasures(ObjID obj) { - if (!_assets.contains(obj)) { - _assets[obj] = new ImageAsset(obj, _graphics); - } + ensureAssetLoaded(obj); uint w = _assets[obj]->getWidth(); uint h = _assets[obj]->getHeight(); return Common::Point(w, h); @@ -1313,6 +1300,12 @@ void Gui::handleDoubleClick(Common::Point pos) { handleDragRelease(pos, false, true); } +void Gui::ensureAssetLoaded(ObjID obj) { + if (!_assets.contains(obj)) { + _assets[obj] = new ImageAsset(obj, _graphics); + } +} + /* Ugly switches */ BorderBounds Gui::borderBounds(MVWindowType type) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 65f2ec5fdb..a44813511c 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -323,6 +323,8 @@ private: // Methods Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); Common::Point localize(Common::Point point, WindowReference origin, WindowReference target); + void ensureAssetLoaded(ObjID obj); + }; class Cursor { -- cgit v1.2.3 From dad1edcef0e5b95b0d4b09e97c2045a3b5ba61f3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 19:22:11 +0200 Subject: MACVENTURE: Remove unnecesary window code --- engines/macventure/gui.cpp | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index a313e3e94d..91df455318 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -254,29 +254,7 @@ const Graphics::Font& Gui::getCurrentFont() { } void Gui::bringToFront(WindowReference winID) { - // FIXME: There has to be a better way to do this, maybe with the _wm - switch (winID) { - case MacVenture::kCommandsWindow: - _controlsWindow->setActive(true); - break; - case MacVenture::kMainGameWindow: - _mainGameWindow->setActive(true); - break; - case MacVenture::kOutConsoleWindow: - _outConsoleWindow->setActive(true); - break; - case MacVenture::kSelfWindow: - _selfWindow->setActive(true); - break; - case MacVenture::kExitsWindow: - _exitsWindow->setActive(true); - break; - case MacVenture::kDiplomaWindow: - _diplomaWindow->setActive(true); - break; - default: - break; - } + findWindow(winID)->setActive(true); } void Gui::setWindowTitle(WindowReference winID, Common::String string) { -- cgit v1.2.3 From 8162483026ec52476a1106e72259c84e5476fd2d Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 14 Jul 2016 00:18:08 +0200 Subject: MACVENTURE: Add text input logic --- engines/macventure/gui.cpp | 5 +---- engines/macventure/macventure.cpp | 12 +++++++++++- engines/macventure/macventure.h | 25 ++++--------------------- engines/macventure/script.cpp | 6 +++++- engines/macventure/script.h | 21 ++++++++++----------- engines/macventure/world.cpp | 5 ++++- 6 files changed, 35 insertions(+), 39 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 91df455318..02f603659e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -460,7 +460,7 @@ bool Gui::loadWindows() { data.title = Common::String(newTitle); } - debug(4, "Window loaded: %s", data.title); + debug(4, "Window loaded: %s", data.title.c_str()); _windowData->push_back(data); } @@ -1163,7 +1163,6 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { } } - _engine->selectControl(data.getData().refcon); _engine->activateCommand(data.getData().refcon); _engine->refreshReady(); @@ -1178,7 +1177,6 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { WindowData &data = findWindowData(kMainGameWindow); - ObjID child = 0; Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ Common::Rect clickRect = calculateClickRect(event.mouse, _mainGameWindow->getDimensions()); @@ -1254,7 +1252,6 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (ref == kNoWindow) return false; Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); - ObjID child; Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ Common::Rect clickRect = calculateClickRect(event.mouse, win->getDimensions()); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 211ba43971..b6db45c93a 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -370,11 +370,17 @@ void MacVentureEngine::updateWindow(WindowReference winID) { _gui->updateWindow(winID, true); } +bool MacVentureEngine::showTextEntry(ObjID text, ObjID srcObj, ObjID destObj) { + debug("Showing speech dialog, asset %d from %d to %d", text, srcObj, destObj); + _userInput = Common::String("epor"); + warning("Show text entry: not fully implemented"); + return true; +} + const GlobalSettings& MacVentureEngine::getGlobalSettings() const { return _globalSettings; } - // Private engine methods void MacVentureEngine::processEvents() { Common::Event event; @@ -585,6 +591,10 @@ Common::String MacVentureEngine::getNoun(ObjID ndx) { return _decodingIndirectArticles->getString(ndx); } +Common::String MacVentureEngine::getUserInput() { + return _userInput; +} + void MacVentureEngine::highlightExit(ObjID objID) { //ObjID ctl = _gui->getWinChild(obj); /*if (ctl) { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 735dda51cc..71c3cbea8b 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -71,27 +71,6 @@ enum { kClickToContinueTextID = 0x84, kStartGameFilenameID = 0x85 }; -/* -enum ControlAction { - kNoCommand = 0, - kStartOrResume = 1, - kClose = 2, - kTick = 3, - kActivateObject = 4, - kMoveObject = 5, - kConsume = 6, - kExamine = 7, - kGo = 8, - kHit = 9, - kOpen = 10, - kOperate = 11, - kSpeak = 12, - kBabble = 13, - kTargetName = 14, - kDebugObject = 15, - kClickToContinue = 16 -}; -*/ enum FilePathID { kMCVID = 1, @@ -206,6 +185,8 @@ public: void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); + bool showTextEntry(ObjID text, ObjID srcObj, ObjID destObj); + // Data retrieval bool isPaused(); bool needsClickToContinue(); @@ -220,6 +201,7 @@ public: uint getPrefixNdx(ObjID obj); Common::String getPrefixString(uint flag, ObjID obj); Common::String getNoun(ObjID ndx); + Common::String getUserInput(); // Attributes consult Common::Point getObjPosition(ObjID objID); @@ -317,6 +299,7 @@ private: // Attributes Common::Array _currentSelection; Common::Array _selectedObjs; Common::Point _deltaPoint; + Common::String _userInput; }; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5b86c31e84..794bbdde60 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1073,7 +1073,11 @@ void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { word txt = state->pop(); - op00NOOP(0xd5); + if (_engine->showTextEntry(txt, frame->src, frame->dest)) { + state->push(0xFFFF); + } else { + state->push(0x0000); + } } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 8aee88fd66..49b69874e6 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -27,21 +27,20 @@ #include "macventure/world.h" namespace MacVenture { - + class Container; class World; - typedef uint32 ObjID; typedef int16 word; class ScriptAsset { public: - ScriptAsset(ObjID id, Container *container); + ScriptAsset(ObjID id, Container *container); ~ScriptAsset() {} void reset(); - uint8 fetch(); + uint8 fetch(); bool hasNext(); void branch(word amount); @@ -66,7 +65,7 @@ public: } void push(word data) { - sp--; + sp--; stack[sp] = unneg16(data); } @@ -97,7 +96,7 @@ public: private: word unneg16(word data) { - if (data < 0) + if (data < 0) data = ((-data) ^ 0xFFFF) + 1; return data; @@ -141,17 +140,17 @@ public: ~ScriptEngine(); public: - bool runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta); - bool resume(bool execAll); + bool runControl(ControlAction action, ObjID source, ObjID destination, Common::Point delta); + bool resume(bool execAll); void reset(); private: bool execFrame(bool execAll); bool loadScript(EngineFrame * frame, uint32 scriptID); - bool resumeFunc(EngineFrame * frame); + bool resumeFunc(EngineFrame * frame); bool runFunc(EngineFrame * frame); -private: +private: // Aux word neg16(word val); @@ -208,7 +207,7 @@ private: void opacEQ(EngineState *state, EngineFrame *frame); //eq? void opadEQS(EngineState *state, EngineFrame *frame); //eq string? void opaeCONT(EngineState *state, EngineFrame *frame); //contains - void opafCONTW(EngineState *state, EngineFrame *frame); //contains word + void opafCONTW(EngineState *state, EngineFrame *frame); //contains word void opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *script); //bra void opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *script); //bra.b diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index ec20ba6b20..e247404eb6 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -156,6 +156,9 @@ void World::releaseChildren(ObjID objID) { } Common::String World::getText(ObjID objID, ObjID source, ObjID target) { + if (objID & 0x8000){ + return _engine->getUserInput(); + } TextAsset text = TextAsset(_engine, objID, source, target, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); return *text.decode(); @@ -169,7 +172,7 @@ bool World::isObjDraggable(ObjID objID) { } bool World::intersects(ObjID objID, Common::Rect rect) { - return _engine->getObjBounds(objID).intersects(rect); + return _engine->getObjBounds(objID).intersects(rect); } bool World::loadStartGameFileName() { -- cgit v1.2.3 From 2a521bb22df9c5e5d477deb32ebc8b6a54e91fde Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 15 Jul 2016 12:47:27 +0200 Subject: MACVENTURE: Add dialog system --- engines/macventure/dialog.cpp | 254 ++++++++++++++++++++++++++++++++++++++++++ engines/macventure/dialog.h | 146 ++++++++++++++++++++++++ engines/macventure/gui.cpp | 24 +++- engines/macventure/gui.h | 5 + engines/macventure/image.cpp | 27 +---- engines/macventure/module.mk | 3 +- 6 files changed, 434 insertions(+), 25 deletions(-) create mode 100644 engines/macventure/dialog.cpp create mode 100644 engines/macventure/dialog.h diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp new file mode 100644 index 0000000000..78fb942db1 --- /dev/null +++ b/engines/macventure/dialog.cpp @@ -0,0 +1,254 @@ +/* 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 "macventure/dialog.h" + +namespace MacVenture { + +// Prebuilt dialogs + +enum { + // HACK + kMaxPrebuiltDialogElements = 10 +}; + +struct PrebuiltDialog { + Common::Rect bounds; + PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; +}; + +PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { + + {/* kSaveAsDialog */ + Common::Rect(0, 146, 456, 254), + { {kDEButton, "YES", kDANone, Common::Point(24, 68), 120, 22}, + {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, + {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, + {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0}} + } + +}; + +Dialog::Dialog(Gui *gui, Common::Point pos, uint width, uint height) : + _gui(gui), _bounds(Common::Rect(pos.x, pos.y, pos.x + width, pos.y + height)) {} + +Dialog::Dialog(Gui *gui, PrebuiltDialogs prebuilt) { + _gui = gui; + const PrebuiltDialog &dialog = prebuiltDialogs[prebuilt]; + _bounds = dialog.bounds; + for (int i = 0; dialog.elements[i].type != kDEEnd; i++) { + addPrebuiltElement(dialog.elements[i]); + } +} + +Dialog::~Dialog() { + for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { + delete *it; + } +} + +void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { + switch(action) { + case kDACloseDialog: + _gui->closeDialog(); + break; + } +} + +const Graphics::Font& Dialog::getFont() { + return _gui->getCurrentFont(); +} + +bool Dialog::processEvent(Common::Event event) { + for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { + if ((*it)->processEvent(this, event)) return true; + } +} + +void Dialog::addButton(Common::String title, MacVenture::DialogAction action, Common::Point position, uint width, uint height) { + _elements.push_back(new DialogButton(this, title, action, position, width, height)); +} + +void Dialog::addText(Common::String content, Common::Point position) { + _elements.push_back(new DialogPlainText(this, content, position)); +} + +void Dialog::addTextInput(Common::Point position, int width, int height) { + _elements.push_back(new DialogTextInput(this, position, width, height)); +} + +void Dialog::draw() { + Graphics::ManagedSurface compose; + // Compose the surface + compose.create(_bounds.width(), _bounds.height()); + Common::Rect base(0, 0, _bounds.width(), _bounds.height()); + compose.fillRect(base, kColorWhite); + compose.frameRect(base, kColorBlack); + for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { + (*it)->draw(this, compose); + } + + g_system->copyRectToScreen(compose.getPixels(), compose.pitch, + _bounds.left, _bounds.top, _bounds.width(), _bounds.height()); +} + +void Dialog::localize(Common::Point &point) { + point.x -= _bounds.left; + point.y -= _bounds.top; +} + +void Dialog::setUserInput(Common::String content) { + _userInput = content; + debug(2, "Set user input: %s", _userInput.c_str()); +} + +void Dialog::addPrebuiltElement(const MacVenture::PrebuiltDialogElement &element) { + switch(element.type) { + case kDEButton: + addButton(element.title, element.action, element.position, element.width, element.height); + break; + case kDEPlainText: + addText(element.title, element.position); + break; + case kDETextInput: + addTextInput(element.position, element.width, element.height); + break; + } +} + +// Dialog Element + +DialogElement::DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width, uint height) : + _text(title), _action(action) { + if (width == 0) { + width = dialog->getFont().getStringWidth(title); + } + if (height == 0) { + height = dialog->getFont().getFontHeight(); + } + _bounds = Common::Rect(position.x, position.y, position.x + width, position.y + height); + } + +bool DialogElement::processEvent(MacVenture::Dialog *dialog, Common::Event event) { + // HACK for test, please delete me + Common::Point mouse = event.mouse; + dialog->localize(mouse); + if (_bounds.contains(mouse)) debug(1, "Hovering over: %s", _text.c_str()); + + return doProcessEvent(dialog, event); +} + +void DialogElement::draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { + doDraw(dialog, target); +} + +const Common::String& DialogElement::getText() { + return doGetText(); +} + +const Common::String& DialogElement::doGetText() { + return _text; +} + +// CONCRETE DIALOG ELEMENTS + +DialogButton::DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width, uint height): + DialogElement(dialog, title, action, position, width, height) {} + +bool DialogButton::doProcessEvent(MacVenture::Dialog *dialog, Common::Event event) { + Common::Point mouse = event.mouse; + if (event.type == Common::EVENT_LBUTTONDOWN) { + dialog->localize(mouse); + if (_bounds.contains(mouse)) { + debug(1, "Click! Button: %s", _text.c_str()); + dialog->handleDialogAction(this, _action); + return true; + } + } + return false; +} + +void DialogButton::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { + target.fillRect(_bounds, kColorWhite); + target.frameRect(_bounds, kColorBlack); + // Draw title + dialog->getFont().drawString( + &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); +} + +DialogPlainText::DialogPlainText(Dialog *dialog, Common::String content, Common::Point position) : + DialogElement(dialog, content, kDANone, position, 0, 0) { } + +DialogPlainText::~DialogPlainText() {} + +bool DialogPlainText::doProcessEvent(MacVenture::Dialog *dialog, Common::Event event) { + return false; +} + +void DialogPlainText::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { + // Draw contents + dialog->getFont().drawString( + &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack); + +} + +DialogTextInput::DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height) : + DialogElement(dialog, "", kDANone, position, width, height) {} +DialogTextInput::~DialogTextInput() {} + +bool DialogTextInput::doProcessEvent(Dialog *dialog, Common::Event event) { + if (event.type == Common::EVENT_KEYDOWN) { + switch (event.kbd.keycode) { + case Common::KEYCODE_BACKSPACE: + if (!_text.empty()) { + _text.deleteLastChar(); + dialog->setUserInput(_text); + return true; + } + break; + + default: + if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) { + _text += (char)event.kbd.ascii; + dialog->setUserInput(_text); + return true; + } + + break; + } + } + return false; +} +void DialogTextInput::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { + target.fillRect(_bounds, kColorWhite); + target.frameRect(_bounds, kColorBlack); + dialog->getFont().drawString( + &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack); +} + + + +} // End of namespace MacVenture diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h new file mode 100644 index 0000000000..fa17432018 --- /dev/null +++ b/engines/macventure/dialog.h @@ -0,0 +1,146 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_DIALOG_H +#define MACVENTURE_DIALOG_H + +#include "graphics/macgui/macwindowmanager.h" + +#include "macventure/macventure.h" +#include "macventure/gui.h" + +namespace MacVenture { + +using namespace Graphics::MacGUIConstants; +class Gui; + +class DialogElement; + +enum DialogAction { + kDANone, + kDACloseDialog +}; + +enum PrebuiltDialogs { + kSaveAsDialog = 0, + kPrebuiltDialogCount +}; + +enum PrebuiltElementType { + kDEPlainText, + kDEButton, + kDETextInput, + kDEEnd +}; + +struct PrebuiltDialogElement { + PrebuiltElementType type; + Common::String title; + DialogAction action; + Common::Point position; + uint width; + uint height; +}; + +class Dialog { +public: + Dialog(Gui *gui, Common::Point pos, uint width, uint height); + Dialog(Gui *gui, PrebuiltDialogs prebuilt); + + ~Dialog(); + + bool processEvent(Common::Event event); + void draw(); + void localize(Common::Point &point); + void handleDialogAction(DialogElement *trigger, DialogAction action); + + const Graphics::Font& getFont(); + + void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); + void addText(Common::String content, Common::Point position); + void addTextInput(Common::Point position, int width, int height); + + void setUserInput(Common::String content); + +private: + void addPrebuiltElement(const PrebuiltDialogElement &element); + +private: + Gui *_gui; + + Common::String _userInput; + Common::Array _elements; + Common::Rect _bounds; +}; + +class DialogElement { +public: + DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); + virtual ~DialogElement() {} + + bool processEvent(Dialog *dialog, Common::Event event); + void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); + const Common::String& getText(); + +private: + virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0; + virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0; + virtual const Common::String& doGetText(); + +protected: + Common::String _text; + Common::Rect _bounds; + DialogAction _action; +}; + +// Dialog elements +class DialogButton : public DialogElement { +public: + DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); + ~DialogButton() {} + +private: + bool doProcessEvent(Dialog *dialog, Common::Event event); + void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); +}; + +class DialogPlainText : public DialogElement { +public: + DialogPlainText(Dialog *dialog, Common::String content, Common::Point position); + ~DialogPlainText(); +private: + bool doProcessEvent(Dialog *dialog, Common::Event event); + void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); +}; + +class DialogTextInput : public DialogElement { +public: + DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height); + ~DialogTextInput(); +private: + bool doProcessEvent(Dialog *dialog, Common::Event event); + void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 02f603659e..4b01f8bca9 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -112,6 +112,7 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _controlData = nullptr; _draggedObj.id = 0; _draggedObj.pos = Common::Point(0, 0); + _dialog = nullptr; _cursor = new Cursor(this); g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 500000, this, "macVentureCursor"); @@ -138,6 +139,9 @@ Gui::~Gui() { if (_consoleText) delete _consoleText; + if (_dialog) + delete _dialog; + Common::HashMap::const_iterator it = _assets.begin(); for (; it != _assets.end(); it++) { delete it->_value; @@ -181,7 +185,7 @@ void Gui::draw() { _wm.draw(); drawDraggedObject(); - + drawDialog(); //drawWindowTitle(kMainGameWindow, _mainGameWindow->getSurface()); } @@ -703,6 +707,10 @@ void Gui::drawDraggedObject() { } } +void Gui::drawDialog() { + if (_dialog) _dialog->draw(); +} + void Gui::updateWindow(WindowReference winID, bool containerOpen) { if (winID == kNoWindow) return; if (winID == kSelfWindow || containerOpen) { @@ -794,6 +802,11 @@ void Gui::printText(const Common::String & text) { _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } +void Gui::closeDialog() { + delete _dialog; + _dialog = nullptr; +} + void Gui::moveDraggedObject(Common::Point target) { Common::Point newPos = target + _draggedObj.mouseOffset; bool movement = false; @@ -1006,6 +1019,8 @@ void Gui::handleMenuAction(MenuAction action) { break; case MacVenture::kMenuActionSaveAs: debug("MacVenture Menu Action: Save As"); + // HACK this should be wrapped in a function + _dialog = new Dialog(this, kSaveAsDialog); break; case MacVenture::kMenuActionQuit: debug("MacVenture Menu Action: Quit"); @@ -1120,6 +1135,8 @@ bool Gui::processEvent(Common::Event &event) { processed |= _cursor->processEvent(event); + if (_dialog && _dialog->processEvent(event)) return true; + if (event.type == Common::EVENT_MOUSEMOVE) { if (_draggedObj.id != 0) { moveDraggedObject(event.mouse); @@ -1247,8 +1264,6 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); - // TODO DELETE MEEEE! - debug("WindowFound: %d", ref); if (ref == kNoWindow) return false; Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); @@ -1267,11 +1282,14 @@ void Gui::processCursorTick() { void Gui::handleSingleClick(Common::Point pos) { debug("Single Click"); + // HACK + if (_dialog) return; handleDragRelease(pos, false, false); } void Gui::handleDoubleClick(Common::Point pos) { debug("Double Click"); + if (_dialog) return; handleDragRelease(pos, false, true); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index a44813511c..046e7e516c 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -31,6 +31,7 @@ #include "macventure/container.h" #include "macventure/image.h" +#include "macventure/dialog.h" namespace MacVenture { @@ -43,6 +44,7 @@ class Cursor; class ConsoleText; class CommandButton; class ImageAsset; +class Dialog; enum MenuAction { kMenuActionAbout, @@ -244,6 +246,7 @@ public: void updateExit(ObjID id); void printText(const Common::String &text); + void closeDialog(); // Ugly switches BorderBounds borderBounds(MVWindowType type); @@ -268,6 +271,7 @@ private: // Attributes Graphics::MacWindow *_diplomaWindow; Common::Array _inventoryWindows; Graphics::Menu *_menu; + Dialog *_dialog; Container *_graphics; Common::HashMap _assets; @@ -305,6 +309,7 @@ private: // Methods void drawDraggedObject(); void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface); void drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface); + void drawDialog(); void moveDraggedObject(Common::Point target); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 21986e382c..cbe3cc910d 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -100,7 +100,7 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { _bitWidth = w; _bitHeight = h; - for (uint i = 0; i < _rowBytes * h; i++) { + for (int i = 0; i < _rowBytes * h; i++) { data.push_back(0); } @@ -141,22 +141,7 @@ void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &da data[p] = v & 0xff; p++; } } - /* - for (var i=0;i>>=16-ppic.bit; - bitmap.data[p++]=(v>>8)&0xff; - bitmap.data[p++]=v&0xff; - } - if (bytes) - { - v=ppic.bits(bytes); - v<<=16-bytes; - bitmap.data[p++]=(v>>8)&0xff; - bitmap.data[p++]=v&0xff; - } - */ + } void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array &data) { @@ -186,7 +171,7 @@ void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &da if (huff.symbols[j] >= huff.symbols[i - 1]) huff.symbols[j]++; - for (uint i = 0x10; i >= 0; i--) { + for (int i = 0x10; i >= 0; i--) { if (huff.symbols[i] == 0x10) { huff.symbols[i] = 0xff; break; @@ -297,7 +282,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (flags & 2) delta *= 2; pos = 0; uint q = delta; - for (uint i = 0;i < _bitHeight * _rowBytes - delta;i++) { + for (int i = 0; i < _bitHeight * _rowBytes - delta; i++) { data[q] ^= data[pos]; q++; pos++; @@ -390,10 +375,10 @@ bool ImageAsset::isRectInside(Common::Rect rect) { // HACK is it &&, or ||? if (_maskData.empty()) return (rect.width() > 0 && rect.height() > 0); - for (uint y = rect.top; y < rect.top + rect.height(); y++) { + for (int y = rect.top; y < rect.top + rect.height(); y++) { uint bmpofs = y * _rowBytes; byte pix; - for (uint x = rect.left; x < rect.left + rect.width(); x++) { + for (int x = rect.left; x < rect.left + rect.width(); x++) { pix = _maskData[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); if (pix) return true; } diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 022b8d7c32..813677c33c 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -8,7 +8,8 @@ MODULE_OBJS := \ text.o \ world.o \ script.o \ - macventure.o + macventure.o \ + dialog.o MODULE_DIRS += \ engines/macventure -- cgit v1.2.3 From 734b453c86bb20b2cb52c4f695f8a770b97be459 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 15 Jul 2016 23:02:37 +0200 Subject: MACVENTURE: Add text input dialog --- engines/macventure/dialog.cpp | 34 +++++++++++++++++++++++++--------- engines/macventure/dialog.h | 4 +++- engines/macventure/gui.cpp | 32 +++++++++++++++++++++++--------- engines/macventure/gui.h | 3 +++ engines/macventure/macventure.cpp | 22 ++++++++++++++++------ engines/macventure/macventure.h | 3 ++- engines/macventure/script.cpp | 1 + 7 files changed, 73 insertions(+), 26 deletions(-) diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 78fb942db1..3a09feffd5 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -41,13 +41,26 @@ struct PrebuiltDialog { PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { {/* kSaveAsDialog */ - Common::Rect(0, 146, 456, 254), - { {kDEButton, "YES", kDANone, Common::Point(24, 68), 120, 22}, - {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, - {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, - {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0}} + Common::Rect(0, 146, 456, 254), + { + {kDEButton, "YES", kDANone, Common::Point(24, 68), 120, 22}, + {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, + {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, + {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + }, + + { /* kSpeakDialog */ + Common::Rect(20, 92, 400, 200), + { + {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, + {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, + {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } } }; @@ -75,6 +88,10 @@ void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { case kDACloseDialog: _gui->closeDialog(); break; + case kDASubmit: + _gui->setTextInput(_userInput); + _gui->closeDialog(); + break; } } @@ -122,7 +139,6 @@ void Dialog::localize(Common::Point &point) { void Dialog::setUserInput(Common::String content) { _userInput = content; - debug(2, "Set user input: %s", _userInput.c_str()); } void Dialog::addPrebuiltElement(const MacVenture::PrebuiltDialogElement &element) { @@ -211,7 +227,7 @@ bool DialogPlainText::doProcessEvent(MacVenture::Dialog *dialog, Common::Event e void DialogPlainText::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { // Draw contents dialog->getFont().drawString( - &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack); + &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); } diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index fa17432018..1dbebf77f2 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -37,11 +37,13 @@ class DialogElement; enum DialogAction { kDANone, - kDACloseDialog + kDACloseDialog, + kDASubmit }; enum PrebuiltDialogs { kSaveAsDialog = 0, + kSpeakDialog = 1, kPrebuiltDialogCount }; diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 4b01f8bca9..d8deb4b568 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -31,6 +31,8 @@ namespace MacVenture { +#define MACVENTURE_DEBUG_GUI true + enum MenuAction; enum { @@ -333,8 +335,8 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); - loadBorder(newWindow, "border_no_scroll_inac.bmp", false); - loadBorder(newWindow, "border_no_scroll_act.bmp", true); + //loadBorder(newWindow, "border_no_scroll_inac.bmp", false); + //loadBorder(newWindow, "border_no_scroll_act.bmp", true); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); @@ -658,11 +660,9 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface, pos.x, pos.y, kBlitOR); // For test - surface->frameRect(Common::Rect( - pos.x, - pos.y, - pos.x + _assets[child]->getWidth() + 1, - pos.y + _assets[child]->getHeight() + 1), kColorGreen); + if (MACVENTURE_DEBUG_GUI) { + surface->frameRect(_engine->getObjBounds(child), kColorGreen); + } } } @@ -802,11 +802,25 @@ void Gui::printText(const Common::String & text) { _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } +void Gui::setTextInput(Common::String str) { + _engine->setTextInput(str); +} + void Gui::closeDialog() { delete _dialog; _dialog = nullptr; } +void Gui::getTextFromUser() { + if (_dialog) { + delete _dialog; + } + _dialog = new Dialog(this, kSpeakDialog); + // Hack to pause the engine + _engine->clickToContinue(); +} + + void Gui::moveDraggedObject(Common::Point target) { Common::Point newPos = target + _draggedObj.mouseOffset; bool movement = false; @@ -1125,8 +1139,8 @@ bool Gui::tryCloseWindow(WindowReference winID) { Common::Point Gui::getObjMeasures(ObjID obj) { ensureAssetLoaded(obj); - uint w = _assets[obj]->getWidth(); - uint h = _assets[obj]->getHeight(); + int w = MAX(0, (int)_assets[obj]->getWidth()); + int h = MAX(0, (int)_assets[obj]->getHeight()); return Common::Point(w, h); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 046e7e516c..f800aeb835 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -246,6 +246,9 @@ public: void updateExit(ObjID id); void printText(const Common::String &text); + + void getTextFromUser(); + void setTextInput(Common::String str); void closeDialog(); // Ugly switches diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index b6db45c93a..1fca4288e8 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -372,11 +372,25 @@ void MacVentureEngine::updateWindow(WindowReference winID) { bool MacVentureEngine::showTextEntry(ObjID text, ObjID srcObj, ObjID destObj) { debug("Showing speech dialog, asset %d from %d to %d", text, srcObj, destObj); - _userInput = Common::String("epor"); - warning("Show text entry: not fully implemented"); + _gui->getTextFromUser(); + + // HACK WITH FLAGS + _prepared = false; + warning("Show text entry: not fully tested"); return true; } +void MacVentureEngine::setTextInput(Common::String content) { + // HACK WITH FLAGS + _prepared = true; + _userInput = content; + _clickToContinue = false; +} + +Common::String MacVentureEngine::getUserInput() { + return _userInput; +} + const GlobalSettings& MacVentureEngine::getGlobalSettings() const { return _globalSettings; } @@ -591,10 +605,6 @@ Common::String MacVentureEngine::getNoun(ObjID ndx) { return _decodingIndirectArticles->getString(ndx); } -Common::String MacVentureEngine::getUserInput() { - return _userInput; -} - void MacVentureEngine::highlightExit(ObjID objID) { //ObjID ctl = _gui->getWinChild(obj); /*if (ctl) { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 71c3cbea8b..f6a3ea66af 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -186,6 +186,8 @@ public: void updateWindow(WindowReference winID); bool showTextEntry(ObjID text, ObjID srcObj, ObjID destObj); + void setTextInput(Common::String content); + Common::String getUserInput(); // Data retrieval bool isPaused(); @@ -201,7 +203,6 @@ public: uint getPrefixNdx(ObjID obj); Common::String getPrefixString(uint flag, ObjID obj); Common::String getNoun(ObjID ndx); - Common::String getUserInput(); // Attributes consult Common::Point getObjPosition(ObjID objID); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 794bbdde60..fdb470ca48 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -32,6 +32,7 @@ namespace MacVenture { ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; + // HACK _scripts = new Container("Shadowgate II/Shadow Filter"); } -- cgit v1.2.3 From a06f291280e0897beed18e63e269938dfa45ccef Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 16 Jul 2016 19:57:36 +0200 Subject: MACVENTURE: Add basic game save/load feature --- engines/macventure/dialog.cpp | 11 ++++---- engines/macventure/dialog.h | 3 ++- engines/macventure/gui.cpp | 38 ++++++++++++++++++--------- engines/macventure/gui.h | 4 +++ engines/macventure/image.cpp | 4 +-- engines/macventure/macventure.cpp | 52 ++++++++++++++++++++++++++++++++++-- engines/macventure/macventure.h | 13 +++++++++ engines/macventure/world.cpp | 55 +++++++++++++++++++++++++-------------- engines/macventure/world.h | 12 +++++---- 9 files changed, 144 insertions(+), 48 deletions(-) diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 3a09feffd5..ba489d4bad 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -43,7 +43,7 @@ PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { {/* kSaveAsDialog */ Common::Rect(0, 146, 456, 254), { - {kDEButton, "YES", kDANone, Common::Point(24, 68), 120, 22}, + {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, @@ -92,6 +92,10 @@ void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { _gui->setTextInput(_userInput); _gui->closeDialog(); break; + case kDASaveAs: + _gui->saveInto(0); + _gui->closeDialog(); + break; } } @@ -169,11 +173,6 @@ DialogElement::DialogElement(Dialog *dialog, Common::String title, DialogAction } bool DialogElement::processEvent(MacVenture::Dialog *dialog, Common::Event event) { - // HACK for test, please delete me - Common::Point mouse = event.mouse; - dialog->localize(mouse); - if (_bounds.contains(mouse)) debug(1, "Hovering over: %s", _text.c_str()); - return doProcessEvent(dialog, event); } diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index 1dbebf77f2..e773956b09 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -38,7 +38,8 @@ class DialogElement; enum DialogAction { kDANone, kDACloseDialog, - kDASubmit + kDASubmit, + kDASaveAs }; enum PrebuiltDialogs { diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d8deb4b568..6c9ccf6a2f 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -335,8 +335,8 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); - //loadBorder(newWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(newWindow, "border_no_scroll_act.bmp", true); + loadBorder(newWindow, "border_no_scroll_inac.bmp", false); + loadBorder(newWindow, "border_no_scroll_act.bmp", true); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); @@ -686,13 +686,12 @@ void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * sur } void Gui::drawDraggedObject() { - if (_draggedObj.id != 0) { + if (_draggedObj.id != 0 && + _engine->isObjVisible(_draggedObj.id)) { ensureAssetLoaded(_draggedObj.id); ImageAsset *asset = _assets[_draggedObj.id]; _draggedSurface.create(asset->getWidth(), asset->getHeight(), _screen.format); - _screen.copyRectToSurface(_draggedSurface, _draggedObj.pos.x, _draggedObj.pos.y, - Common::Rect(asset->getWidth() - 1, asset->getHeight() - 1)); asset->blitInto(&_draggedSurface, 0, 0, kBlitBIC); @@ -820,6 +819,14 @@ void Gui::getTextFromUser() { _engine->clickToContinue(); } +void Gui::loadGame(int slot) { + _engine->loadGameState(slot); +} + +void Gui::saveInto(int slot) { + _engine->saveGameState(slot, "desc"); + _engine->preparedToRun(); +} void Gui::moveDraggedObject(Common::Point target) { Common::Point newPos = target + _draggedObj.mouseOffset; @@ -857,9 +864,11 @@ WindowReference Gui::findWindowAtPoint(Common::Point point) { Graphics::MacWindow *win; for (it = _windowData->begin(); it != _windowData->end(); it++) { win = findWindow(it->refcon); - if (win && win->getDimensions().contains(point) && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered - if (win->isActive()) - return it->refcon; + if (win && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered + if (win->getDimensions().contains(point)) { + if (win->isActive()) + return it->refcon; + } } } return kNoWindow; @@ -869,6 +878,7 @@ Common::Point Gui::getWindowSurfacePos(WindowReference reference) { const WindowData &data = getWindowData(reference); BorderBounds border = borderBounds(data.type); Graphics::MacWindow *win = findWindow(reference); + if (!win) return Common::Point(0, 0); return Common::Point(win->getDimensions().left + border.leftOffset, win->getDimensions().top + border.topOffset); } @@ -976,9 +986,9 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point cli } void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) { - WindowReference destinationWindow = findWindowAtPoint(pos); - if (destinationWindow == kNoWindow) return; if (_draggedObj.id != 0) { + WindowReference destinationWindow = findWindowAtPoint(pos); + if (destinationWindow == kNoWindow) return; if (_draggedObj.hasMoved) { ObjID destObject = getWindowData(destinationWindow).objRef; pos -= (_draggedObj.startPos - _draggedObj.mouseOffset); @@ -1027,9 +1037,11 @@ void Gui::handleMenuAction(MenuAction action) { break; case MacVenture::kMenuActionOpen: debug("MacVenture Menu Action: Open"); + loadGame(0); break; case MacVenture::kMenuActionSave: debug("MacVenture Menu Action: Save"); + saveInto(0); break; case MacVenture::kMenuActionSaveAs: debug("MacVenture Menu Action: Save As"); @@ -1139,8 +1151,8 @@ bool Gui::tryCloseWindow(WindowReference winID) { Common::Point Gui::getObjMeasures(ObjID obj) { ensureAssetLoaded(obj); - int w = MAX(0, (int)_assets[obj]->getWidth()); - int h = MAX(0, (int)_assets[obj]->getHeight()); + int w = _assets[obj]->getWidth(); + int h = _assets[obj]->getHeight(); return Common::Point(w, h); } @@ -1296,7 +1308,7 @@ void Gui::processCursorTick() { void Gui::handleSingleClick(Common::Point pos) { debug("Single Click"); - // HACK + // HACK THERE HAS TO BE A MORE ELEGANT WAY if (_dialog) return; handleDragRelease(pos, false, false); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index f800aeb835..b03ca2afe9 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -247,10 +247,14 @@ public: void printText(const Common::String &text); + //Dialog interactions void getTextFromUser(); void setTextInput(Common::String str); void closeDialog(); + void loadGame(int slot); + void saveInto(int slot); + // Ugly switches BorderBounds borderBounds(MVWindowType type); diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index cbe3cc910d..fa281eb19a 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -387,11 +387,11 @@ bool ImageAsset::isRectInside(Common::Rect rect) { } uint ImageAsset::getWidth() { - return _bitWidth; + return MAX(0, (int)_bitWidth); } uint ImageAsset::getHeight() { - return _bitHeight; + return MAX(0, (int)_bitHeight); } void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 1fca4288e8..9b764d9856 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -82,7 +82,6 @@ Common::Error MacVentureEngine::run() { // Additional setup. debug("MacVentureEngine::init"); - _resourceManager = new Common::MacResManager(); if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); @@ -113,7 +112,6 @@ Common::Error MacVentureEngine::run() { _destObject = 0; _prepared = true; - //if !savegame _cmdReady = true; _selectedControl = kStartOrResume; ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); @@ -162,6 +160,42 @@ Common::Error MacVentureEngine::run() { return Common::kNoError; } +Common::Error MacVentureEngine::loadGameState(int slot) { + Common::InSaveFile *file = getSaveFileManager()->openForLoading("Shadowgate.1"); + _world->loadGameFrom(file); + reset(); + return Common::kNoError; +} + +Common::Error MacVentureEngine::saveGameState(int slot, const Common::String &desc) { + Common::SaveFileManager *manager = getSaveFileManager(); + // HACK Get a real name! + Common::OutSaveFile *file = manager->openForSaving("Shadowgate.1"); + _world->saveGameInto(file); + delete file; +} + +void MacVentureEngine::reset() { + resetInternals(); + resetGui(); +} + +void MacVentureEngine::resetInternals() { + _scriptEngine->reset(); + _currentSelection.clear(); + _selectedObjs.clear(); + _objQueue.clear(); + _textQueue.clear(); +} + +void MacVentureEngine::resetGui() { + _gui->updateWindowInfo(kMainGameWindow, getParent(1), _world->getChildren(getParent(1), true)); + // HACK! should update all inventories + _gui->updateWindowInfo(kInventoryStart, 1, _world->getChildren(1, true)); + _gui->updateWindowInfo(kExitsWindow, getParent(1), _world->getChildren(getParent(1), true)); +} + + void MacVentureEngine::requestQuit() { // TODO: Display save game dialog and such _gameState = kGameStateQuitting; @@ -391,6 +425,20 @@ Common::String MacVentureEngine::getUserInput() { return _userInput; } + +Common::String MacVentureEngine::getStartGameFileName() { + Common::SeekableReadStream *res; + res = _resourceManager->getResource(MKTAG('S', 'T', 'R', ' '), kStartGameFilenameID); + if (!res) + return ""; + + byte length = res->readByte(); + char *fileName = new char[length + 1]; + res->read(fileName, length); + fileName[length] = '\0'; + return Common::String(fileName, length); +} + const GlobalSettings& MacVentureEngine::getGlobalSettings() const { return _globalSettings; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index f6a3ea66af..167abcc351 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -24,10 +24,13 @@ #define MACVENTURE_H #include "engines/engine.h" +#include "common/scummsys.h" +#include "common/system.h" #include "common/debug.h" #include "common/random.h" #include "common/macresman.h" #include "common/huffman.h" +#include "common/savefile.h" #include "gui/debugger.h" @@ -41,6 +44,8 @@ struct ADGameDescription; namespace MacVenture { +class SaveFileManager; + class Console; class World; class ScriptEngine; @@ -158,6 +163,12 @@ public: ~MacVentureEngine(); virtual Common::Error run(); + virtual Common::Error loadGameState(int slot); + virtual Common::Error saveGameState(int slot, const Common::String &desc); + + void reset(); + void resetInternals(); + void resetGui(); void requestQuit(); void requestUnpause(); @@ -189,7 +200,9 @@ public: void setTextInput(Common::String content); Common::String getUserInput(); + // Data retrieval + Common::String getStartGameFileName(); bool isPaused(); bool needsClickToContinue(); Common::String getCommandsPausedString() const; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index e247404eb6..cf13b78e48 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -9,7 +9,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _resourceManager = resMan; _engine = engine; - if (!loadStartGameFileName()) + if ((_startGameFileName = _engine->getStartGameFileName()) == "") error("Could not load initial game configuration"); Common::File saveGameFile; @@ -150,9 +150,11 @@ void World::updateObj(ObjID objID) { } void World::captureChildren(ObjID objID) { + warning("Capture children unimplemented!"); } void World::releaseChildren(ObjID objID) { + warning("Release children unimplemented!"); } Common::String World::getText(ObjID objID, ObjID source, ObjID target) { @@ -175,23 +177,8 @@ bool World::intersects(ObjID objID, Common::Rect rect) { return _engine->getObjBounds(objID).intersects(rect); } -bool World::loadStartGameFileName() { - Common::SeekableReadStream *res; - - res = _resourceManager->getResource(MKTAG('S', 'T', 'R', ' '), kStartGameFilenameID); - if (!res) - return false; - - byte length = res->readByte(); - char *fileName = new char[length + 1]; - res->read(fileName, length); - fileName[length] = '\0'; - _startGameFileName = Common::String(fileName, length); - - return true; -} - void World::calculateObjectRelations() { + _relations.clear(); ObjID val, next; uint32 numObjs = _engine->getGlobalSettings().numObjects; const AttributeGroup &parents = *_saveGame->getGroup(0); @@ -228,6 +215,16 @@ void World::setParent(ObjID child, ObjID newParent) { _relations[oldNdx] = child; } +void World::loadGameFrom(Common::InSaveFile *file) { + if (_saveGame) delete _saveGame; + _saveGame = new SaveGame(_engine, file); + calculateObjectRelations(); +} + +void World::saveGameInto(Common::OutSaveFile *file) { + _saveGame->saveInto(file); +} + // SaveGame SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { _groups = Common::Array(); @@ -263,14 +260,34 @@ void SaveGame::setGlobal(uint32 attrID, Attribute value) { _globals[attrID] = value; } -const Common::Array& MacVenture::SaveGame::getGlobals() { +const Common::Array& SaveGame::getGlobals() { return _globals; } -const Common::String & MacVenture::SaveGame::getText() { +const Common::String & SaveGame::getText() { return _text; } +void SaveGame::saveInto(Common::OutSaveFile *file) { + warning("Saving the game not yet tested!"); + // Save attibutes + Common::Array::const_iterator itg; + for(itg = _groups.begin(); itg != _groups.end(); itg++) { + Common::Array::const_iterator ita; + for (ita = itg->begin(); ita != itg->end(); ita++) { + file->writeUint16BE((*ita)); + } + } + // Save globals + Common::Array::const_iterator global; + for (global = _globals.begin(); global != _globals.end(); global++) { + file->writeUint16BE((*global)); + } + // Save text + _text = "Hello"; + file->write(_text.c_str(), _text.size()); +} + void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) { GlobalSettings settings = engine->getGlobalSettings(); for (int i = 0; i < settings.numGroups; ++i) { diff --git a/engines/macventure/world.h b/engines/macventure/world.h index c023c70ec6..f3933c5f7e 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -74,6 +74,8 @@ public: const AttributeGroup *getGroup(uint32 groupID); const Common::String &getText(); + void saveInto(Common::OutSaveFile *file); + private: void loadGroups(MacVentureEngine *engine, Common::SeekableReadStream *res); void loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream *res); @@ -90,7 +92,6 @@ public: World(MacVentureEngine *engine, Common::MacResManager *resMan); ~World(); - void setObjAttr(ObjID objID, uint32 attrID, Attribute value); void setGlobal(uint32 attrID, Attribute value); void updateObj(ObjID objID); @@ -105,13 +106,15 @@ public: ObjID getAncestor(ObjID objID); Common::Array getFamily(ObjID objID, bool recursive); - Common::Array getChildren(ObjID objID, bool recursive); + Common::Array getChildren(ObjID objID, bool recursive); + + void loadGameFrom(Common::InSaveFile *file); + void saveGameInto(Common::OutSaveFile *file); private: bool isObjDraggable(ObjID objID); bool intersects(ObjID objID, Common::Rect rect); - bool loadStartGameFileName(); void calculateObjectRelations(); void setParent(ObjID child, ObjID newParent); @@ -119,7 +122,7 @@ private: MacVentureEngine *_engine; Common::MacResManager *_resourceManager; - Common::String _startGameFileName; + Common::String _startGameFileName; SaveGame *_saveGame; @@ -132,4 +135,3 @@ private: } // End of namespace MacVenture #endif - -- cgit v1.2.3 From 33ed84ff74fabac68d0900223e82c2717927ef2f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 17 Jul 2016 02:06:35 +0200 Subject: MACVENTURE: Fix small render error --- engines/macventure/image.cpp | 6 ++++-- engines/macventure/image.h | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index fa281eb19a..feb4d2e78b 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -386,11 +386,13 @@ bool ImageAsset::isRectInside(Common::Rect rect) { return false; } -uint ImageAsset::getWidth() { +int ImageAsset::getWidth() { + if (_imgData.size() == 0) return 0; return MAX(0, (int)_bitWidth); } -uint ImageAsset::getHeight() { +int ImageAsset::getHeight() { + if (_imgData.size() == 0) return 0; return MAX(0, (int)_bitHeight); } diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 5cbe146055..b529109442 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -55,7 +55,7 @@ struct PPICHuff { class ImageAsset { public: - ImageAsset(ObjID original, Container *container); + ImageAsset(ObjID original, Container *container); ~ImageAsset(); void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode); @@ -63,8 +63,8 @@ public: bool isPointInside(Common::Point point); bool isRectInside(Common::Rect rect); - uint getWidth(); - uint getHeight(); + int getWidth(); + int getHeight(); private: void decodePPIC(ObjID id, Common::Array &data); -- cgit v1.2.3 From 886330770ff7b9b1c9bb8c9374628f7b0aef4785 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 17 Jul 2016 13:34:21 +0200 Subject: MACVENTURE: Fix exits loading from savegame --- engines/macventure/macventure.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 9b764d9856..9d437612f0 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -192,7 +192,8 @@ void MacVentureEngine::resetGui() { _gui->updateWindowInfo(kMainGameWindow, getParent(1), _world->getChildren(getParent(1), true)); // HACK! should update all inventories _gui->updateWindowInfo(kInventoryStart, 1, _world->getChildren(1, true)); - _gui->updateWindowInfo(kExitsWindow, getParent(1), _world->getChildren(getParent(1), true)); + updateControls(); + updateExits(); } -- cgit v1.2.3 From 014d1b7dcbb27b9db35a02be99338d3525e72349 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 18 Jul 2016 15:26:06 +0200 Subject: MACVENTURE: Fix sign issue --- engines/macventure/script.cpp | 16 +++++++++------- engines/macventure/world.cpp | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index fdb470ca48..36aabae3ed 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -52,14 +52,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(2, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(2, "SCRIPT: Resume"); + debug(3, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -166,7 +166,6 @@ bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool ScriptEngine::runFunc(EngineFrame *frame) { ScriptAsset &script = frame->scripts.front(); - debug(2, "SCRIPT: Executing function %d", script.getId()); EngineState *state = &frame->state; byte op; while (script.hasNext()) { @@ -772,24 +771,26 @@ void ScriptEngine::opa7LNOT(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opa8GTU(EngineState * state, EngineFrame * frame) { - word b = state->pop(); - word a = state->pop(); + uint16 b = state->pop(); + uint16 a = state->pop(); state->push((a > b) ? 0xFFFF : 0); } void ScriptEngine::opa9LTU(EngineState * state, EngineFrame * frame) { - word b = state->pop(); - word a = state->pop(); + uint16 b = state->pop(); + uint16 a = state->pop(); state->push((a < b) ? 0xFFFF : 0); } void ScriptEngine::opaaGTS(EngineState * state, EngineFrame * frame) { + // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a > b) ? 0xFFFF : 0); } void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { + // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a < b) ? 0xFFFF : 0); @@ -924,6 +925,7 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; + debug(2, "SCRIPT: Call function: %d", id); if (loadScript(frame, id)) return true; frame->scripts.pop_front(); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index cf13b78e48..ab35226aa0 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -41,7 +41,7 @@ World::~World() { uint32 World::getObjAttr(ObjID objID, uint32 attrID) { - uint32 res; + int res; uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; // HACK, but if I try to initialize it in the else clause, it goes out of scope and segfaults Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); -- cgit v1.2.3 From 09a4a4ac39f0cdaf7f8f78eb35ccadcb2cf1b467 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 18 Jul 2016 19:16:13 +0200 Subject: MACVENTURE: Fix image to allow mask attributes --- engines/macventure/image.cpp | 191 +++++++++++++++++++++++-------------------- engines/macventure/image.h | 31 +++---- engines/macventure/world.cpp | 2 +- 3 files changed, 119 insertions(+), 105 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index feb4d2e78b..a4db46ecd4 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -64,23 +64,37 @@ ImageAsset::ImageAsset(ObjID original, Container * container) { _id = (original * 2); _mask = (original * 2) + 1; + uint imgRowBytes = 0; + uint imgBitWidth = 0; + uint imgBitHeight = 0; + uint maskRowBytes = 0; + uint maskBitWidth = 0; + uint maskBitHeight = 0; + _container = container; - decodePPIC(_id, _imgData); + decodePPIC(_id, _imgData, imgBitHeight, imgBitWidth, imgRowBytes); + _imgRowBytes = imgRowBytes; + _imgBitWidth = imgBitWidth; + _imgBitHeight = imgBitHeight; - if (_container->getItemByteSize(_mask)) // Has mask - decodePPIC(_mask, _maskData); + if (_container->getItemByteSize(_mask)) { + decodePPIC(_mask, _maskData, maskBitHeight, maskBitWidth, maskRowBytes); + } + _maskRowBytes = maskRowBytes; + _maskBitWidth = maskBitWidth; + _maskBitHeight = maskBitHeight; } ImageAsset::~ImageAsset() { } -void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { +void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight, uint &bitWidth, uint &rowBytes) { ObjID realID = id; uint32 size = _container->getItemByteSize(id); if (size < 2) { - _rowBytes = 0; - _bitHeight = 0; - _bitHeight = 0; + rowBytes = 0; + bitHeight = 0; + bitWidth = 0; return; } if (size == 2) { @@ -96,37 +110,37 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data) { if (stream.getBit()) w = stream.getBits(10); else w = stream.getBits(6); - _rowBytes = ((w + 0xF) >> 3) & 0xFFFE; - _bitWidth = w; - _bitHeight = h; + rowBytes = ((w + 0xF) >> 3) & 0xFFFE; + bitWidth = w; + bitHeight = h; - for (int i = 0; i < _rowBytes * h; i++) { + for (int i = 0; i < rowBytes * h; i++) { data.push_back(0); } switch (mode) { case MacVenture::kPPIC0: - decodePPIC0(stream, data); + decodePPIC0(stream, data, bitHeight, bitWidth, rowBytes); break; case MacVenture::kPPIC1: - decodePPIC1(stream, data); + decodePPIC1(stream, data, bitHeight, bitWidth, rowBytes); break; case MacVenture::kPPIC2: - decodePPIC2(stream, data); + decodePPIC2(stream, data, bitHeight, bitWidth, rowBytes); break; case MacVenture::kPPIC3: - decodePPIC3(stream, data); + decodePPIC3(stream, data, bitHeight, bitWidth, rowBytes); break; } } -void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &data) { - uint words = _bitWidth >> 4; - uint bytes = _bitWidth & 0xF; +void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { + uint words = bitWidth >> 4; + uint bytes = bitWidth & 0xF; uint v = 0; uint p = 0; - for (uint y = 0; y <_bitHeight; y++) { + for (uint y = 0; y < bitHeight; y++) { for (uint x = 0; x < words; x++) { v = stream.peekBits(32); stream.skip(16); @@ -144,15 +158,15 @@ void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &da } -void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array &data) { - decodeHuffGraphic(PPIC1Huff, stream, data); +void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { + decodeHuffGraphic(PPIC1Huff, stream, data, bitHeight, bitWidth, rowBytes); } -void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array &data) { - decodeHuffGraphic(PPIC2Huff, stream, data); +void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { + decodeHuffGraphic(PPIC2Huff, stream, data, bitHeight, bitWidth, rowBytes); } -void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &data) { +void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { // We need to load the huffman from the PPIC itself PPICHuff huff; uint16 v, bits; @@ -193,20 +207,20 @@ void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &da huff.lens[0xf] = bits; huff.lens[0x10] = bits; - decodeHuffGraphic(huff, stream, data); + decodeHuffGraphic(huff, stream, data, bitHeight, bitWidth, rowBytes); } -void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream, Common::Array &data) { +void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { byte flags = 0; _walkRepeat = 0; _walkLast = 0; - if (_bitWidth & 3) + if (bitWidth & 3) flags = stream.getBits(5); else flags = stream.getBits(4) << 1; byte odd = 0; - byte blank = _bitWidth & 0xf; + byte blank = bitWidth & 0xf; if (blank) { blank >>= 2; odd = blank & 1; @@ -214,9 +228,9 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st } uint16 pos = 0; - for (uint y = 0; y < _bitHeight; y++) { + for (uint y = 0; y < bitHeight; y++) { uint16 x = 0; - for (; x < _bitWidth >> 3; x++) { + for (; x < bitWidth >> 3; x++) { byte hi = walkHuff(huff, stream) << 4; data[pos++] = walkHuff(huff, stream) | hi; } @@ -226,13 +240,13 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st pos += blank; } - uint16 edge = _bitWidth & 3; + uint16 edge = bitWidth & 3; if (edge) { - pos = _rowBytes - blank; + pos = rowBytes - blank; uint16 bits = 0; uint16 val = 0; uint16 v; - for (uint y = 0; y < _bitHeight; y++) { + for (uint y = 0; y < bitHeight; y++) { if (flags & 1) { if (bits < edge) { v = walkHuff(huff, stream) << 4; @@ -251,15 +265,15 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st v >>= 4; data[pos] |= v & 0xff; - pos += _rowBytes; + pos += rowBytes; } } if (flags & 8) { pos = 0; - for (uint y = 0; y < _bitHeight; y++) { + for (uint y = 0; y < bitHeight; y++) { uint16 v = 0; if (flags & 2) { - for (uint x = 0; x < _rowBytes; x++) + for (uint x = 0; x < rowBytes; x++) { data[pos] ^= v; v = data[pos]; @@ -267,7 +281,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st } } else { - for (uint x = 0; x < _rowBytes; x++) { + for (uint x = 0; x < rowBytes; x++) { uint16 val = data[pos] ^ v; val ^= (val >> 4) & 0xf; data[pos] = val; @@ -278,11 +292,11 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st } } if (flags & 4) { - uint16 delta = _rowBytes * 4; + uint16 delta = rowBytes * 4; if (flags & 2) delta *= 2; pos = 0; uint q = delta; - for (int i = 0; i < _bitHeight * _rowBytes - delta; i++) { + for (int i = 0; i < bitHeight * rowBytes - delta; i++) { data[q] ^= data[pos]; q++; pos++; @@ -331,15 +345,15 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { if (mode == kBlitDirect) { - blitDirect(target, x, y, _imgData); + blitDirect(target, x, y, _imgData, _imgBitHeight, _imgBitWidth, _imgRowBytes); } else if (mode < kBlitXOR){ if (_container->getItemByteSize(_mask)) { // Has mask switch (mode) { case MacVenture::kBlitBIC: - blitBIC(target, x, y, _maskData); + blitBIC(target, x, y, _maskData, _maskBitHeight, _maskBitWidth, _maskRowBytes); break; case MacVenture::kBlitOR: - blitOR(target, x, y, _maskData); + blitOR(target, x, y, _maskData, _maskBitHeight, _maskBitWidth, _maskRowBytes); break; default: break; @@ -347,10 +361,10 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, } else if (_container->getItemByteSize(_id)) { switch (mode) { case MacVenture::kBlitBIC: - target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight), kColorWhite); + target->fillRect(Common::Rect(x, y, x + _imgBitWidth, y + _imgBitHeight), kColorWhite); break; case MacVenture::kBlitOR: - target->fillRect(Common::Rect(x, y, x + _bitWidth, y + _bitHeight), kColorBlack); + target->fillRect(Common::Rect(x, y, x + _imgBitWidth, y + _imgBitHeight), kColorBlack); break; default: break; @@ -358,16 +372,16 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, } if (_container->getItemByteSize(_id) && mode > 0) { - blitXOR(target, x, y, _imgData); + blitXOR(target, x, y, _imgData, _imgBitHeight, _imgBitWidth, _imgRowBytes); } } } bool ImageAsset::isPointInside(Common::Point point) { - if (point.x >= _bitWidth || point.y >= _bitHeight) return false; + if (point.x >= _maskBitWidth || point.y >= _maskBitHeight) return false; if (_maskData.empty()) return false; // We see if the point lands on the mask. - uint pix = _maskData[(point.y * _rowBytes) + (point.x >> 3)] & (1 << (7 - (point.x & 7))); + uint pix = _maskData[(point.y * _maskRowBytes) + (point.x >> 3)] & (1 << (7 - (point.x & 7))); return pix != 0; } @@ -376,7 +390,7 @@ bool ImageAsset::isRectInside(Common::Rect rect) { if (_maskData.empty()) return (rect.width() > 0 && rect.height() > 0); for (int y = rect.top; y < rect.top + rect.height(); y++) { - uint bmpofs = y * _rowBytes; + uint bmpofs = y * _maskRowBytes; byte pix; for (int x = rect.left; x < rect.left + rect.width(); x++) { pix = _maskData[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); @@ -388,19 +402,20 @@ bool ImageAsset::isRectInside(Common::Rect rect) { int ImageAsset::getWidth() { if (_imgData.size() == 0) return 0; - return MAX(0, (int)_bitWidth); + return MAX(0, (int)_imgBitWidth); } int ImageAsset::getHeight() { if (_imgData.size() == 0) return 0; - return MAX(0, (int)_bitHeight); + return MAX(0, (int)_imgBitHeight); } -void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data) { - /* - if (_bitWidth == 0 || _bitHeight == 0) return; - uint w = _bitWidth; - uint h = _bitHeight; +void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data, uint bitHeight, uint bitWidth, uint rowBytes) { + +/* + if (bitWidth == 0 || bitHeight == 0) return; + uint w = bitWidth; + uint h = bitHeight; uint sx = 0; uint sy = 0; if (ox<0) { sx = -ox; ox = 0; } @@ -408,12 +423,11 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; - */ - - for (uint y = 0; y < _bitHeight; y++) { - uint bmpofs = y * _rowBytes; +*/ + for (uint y = 0; y < bitHeight; y++) { + uint bmpofs = y * rowBytes; byte pix = 0; - for (uint x = 0; x < _bitWidth; x++) { + for (uint x = 0; x < bitWidth; x++) { pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); pix = pix ? kColorBlack : kColorWhite; *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; @@ -421,11 +435,11 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 } } -void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { - /* - if (_bitWidth == 0 || _bitHeight == 0) return; - uint w = _bitWidth; - uint h = _bitHeight; +void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +/* + if (bitWidth == 0 || bitHeight == 0) return; + uint w = bitWidth; + uint h = bitHeight; uint sx = 0; uint sy = 0; if (ox<0) { sx = -ox; ox = 0; } @@ -433,22 +447,22 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; - */ - for (uint y = 0; y < _bitHeight; y++) { - uint bmpofs = y * _rowBytes; +*/ + for (uint y = 0; y < bitHeight; y++) { + uint bmpofs = y * rowBytes; byte pix = 0; - for (uint x = 0; x < _bitWidth; x++) { + for (uint x = 0; x < bitWidth; x++) { pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; } } } -void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { - /* - if (_bitWidth == 0 || _bitHeight == 0) return; - uint w = _bitWidth; - uint h = _bitHeight; +void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +/* + if (bitWidth == 0 || bitHeight == 0) return; + uint w = bitWidth; + uint h = bitHeight; uint sx = 0; uint sy = 0; if (ox<0) { sx = -ox; ox = 0; } @@ -456,23 +470,22 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; - */ - for (uint y = 0; y < _bitHeight; y++) { - uint bmpofs = y * _rowBytes; +*/ + for (uint y = 0; y < bitHeight; y++) { + uint bmpofs = y * rowBytes; byte pix = 0; - for (uint x = 0; x < _bitWidth; x++) { + for (uint x = 0; x < bitWidth; x++) { pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); - if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorBlack; } } } -void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data) { - /* - if (_bitWidth == 0 || _bitHeight == 0) return; - uint w = _bitWidth; - uint h = _bitHeight; +void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +/* + if (bitWidth == 0 || bitHeight == 0) return; + uint w = bitWidth; + uint h = bitHeight; uint sx = 0; uint sy = 0; if (ox<0) { sx = -ox; ox = 0; } @@ -480,16 +493,14 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy if (w + ox >= target->w) w = target->w - ox; if (h + oy >= target->h) h = target->h - oy; if (w == 0 || h == 0) return; - */ - for (uint y = 0;y < _bitHeight; y++) { - uint bmpofs = y * _rowBytes; +*/ + for (uint y = 0; y < bitHeight; y++) { + uint bmpofs = y * rowBytes; byte pix = 0; - for (uint x = 0; x < _bitWidth; x++) { + for (uint x = 0; x < bitWidth; x++) { pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); - if (pix) { // We need to xor byte p = *((byte *)target->getBasePtr(ox + x, oy + y)); - *((byte *)target->getBasePtr(ox + x, oy + y)) = (p == kColorWhite) ? kColorBlack : kColorWhite; } diff --git a/engines/macventure/image.h b/engines/macventure/image.h index b529109442..e6b2515f5c 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -67,20 +67,20 @@ public: int getHeight(); private: - void decodePPIC(ObjID id, Common::Array &data); + void decodePPIC(ObjID id, Common::Array &data, uint &bitHeight, uint &bitWidth, uint &rowBytes); - void decodePPIC0(Common::BitStream &stream, Common::Array &data); - void decodePPIC1(Common::BitStream &stream, Common::Array &data); - void decodePPIC2(Common::BitStream &stream, Common::Array &data); - void decodePPIC3(Common::BitStream &stream, Common::Array &data); + void decodePPIC0(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void decodePPIC1(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void decodePPIC2(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void decodePPIC3(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array &data); + void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); - void blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); - void blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); - void blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); - void blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data); + void blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); private: ObjID _id; @@ -90,12 +90,15 @@ private: uint16 _walkRepeat; uint16 _walkLast; - uint16 _rowBytes; - uint16 _bitWidth; - uint16 _bitHeight; - Common::Array _imgData; + uint16 _imgRowBytes; + uint16 _imgBitWidth; + uint16 _imgBitHeight; + Common::Array _maskData; + uint16 _maskRowBytes; + uint16 _maskBitWidth; + uint16 _maskBitHeight; }; } // End of namespace MacVenture diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index ab35226aa0..e6efeb5598 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -41,7 +41,7 @@ World::~World() { uint32 World::getObjAttr(ObjID objID, uint32 attrID) { - int res; + uint res; uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; // HACK, but if I try to initialize it in the else clause, it goes out of scope and segfaults Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); -- cgit v1.2.3 From 49a2efe408575dbbbdd4e7fc060df843dd8ecd1f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 19 Jul 2016 13:10:31 +0200 Subject: MACVENTURE: Shadowgate Winnable --- engines/macventure/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 6c9ccf6a2f..c1582988cf 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -219,7 +219,7 @@ void Gui::initWindows() { loadBorder(_controlsWindow, "border_command.bmp", true); // Main Game Window - _mainGameWindow = _wm.addWindow(false, false, false); + _mainGameWindow = _wm.addWindow(true, true, true); _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); -- cgit v1.2.3 From 91493aaeb860edbdc991bca679ad6cf8a9d513eb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 19 Jul 2016 17:57:30 +0200 Subject: MACVENTURE: Add closeable inventory windows --- engines/macventure/gui.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index c1582988cf..d38a7a5c3d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -223,8 +223,8 @@ void Gui::initWindows() { _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); - loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); + //loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); + //loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); @@ -335,8 +335,9 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); - loadBorder(newWindow, "border_no_scroll_inac.bmp", false); - loadBorder(newWindow, "border_no_scroll_act.bmp", true); + newWindow->setCloseable(true); + //loadBorder(newWindow, "border_no_scroll_inac.bmp", false); + //loadBorder(newWindow, "border_no_scroll_act.bmp", true); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); @@ -1283,14 +1284,32 @@ bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & ev } bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { + if (event.type == Common::EVENT_LBUTTONDOWN && click == kBorderCloseButton) { + WindowReference ref = findWindowAtPoint(event.mouse); + if (ref == kNoWindow) return false; + + if (click == kBorderCloseButton) { + _inventoryWindows.remove_at(ref - kInventoryStart); + bool found = false; + Common::List::iterator it; + for (it = _windowData->begin(); it != _windowData->end() && !found; it++) { + if (it->refcon == ref) { + _windowData->erase(it); + found = true; + } + } + return true; + } + } + if (_engine->needsClickToContinue()) return true; if (event.type == Common::EVENT_LBUTTONDOWN) { - // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); if (ref == kNoWindow) return false; + Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); Common::Point pos; -- cgit v1.2.3 From 53a5fb6c546bee103526fe444ece0c2cda52d624 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 21 Jul 2016 15:25:43 +0200 Subject: MACVENTURE: Refactor dialogs and controls --- engines/macventure/controls.cpp | 77 +++++++++++++++++++++ engines/macventure/controls.h | 105 ++++++++++++++++++++++++++++ engines/macventure/dialog.cpp | 39 ----------- engines/macventure/dialog.h | 33 +-------- engines/macventure/gui.cpp | 30 +++++--- engines/macventure/gui.h | 124 ++-------------------------------- engines/macventure/macventure.cpp | 3 +- engines/macventure/macventure.h | 1 + engines/macventure/module.mk | 5 +- engines/macventure/prebuilt_dialogs.h | 97 ++++++++++++++++++++++++++ engines/macventure/script.h | 2 + engines/macventure/text.h | 3 +- 12 files changed, 316 insertions(+), 203 deletions(-) create mode 100644 engines/macventure/controls.cpp create mode 100644 engines/macventure/controls.h create mode 100644 engines/macventure/prebuilt_dialogs.h diff --git a/engines/macventure/controls.cpp b/engines/macventure/controls.cpp new file mode 100644 index 0000000000..f467d72de6 --- /dev/null +++ b/engines/macventure/controls.cpp @@ -0,0 +1,77 @@ +/* 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 "macventure/gui.h" + +namespace MacVenture { +CommandButton::CommandButton() { + _gui = nullptr; +} + +CommandButton::CommandButton(ControlData data, Gui *g) { + _data = data; + _gui = g; + _selected = false; +} + +void CommandButton::draw(Graphics::ManagedSurface &surface) const { + + uint colorFill = _selected ? kColorBlack : kColorWhite; + uint colorText = _selected ? kColorWhite : kColorBlack; + + surface.fillRect(_data.bounds, colorFill); + surface.frameRect(_data.bounds, kColorBlack); + + if (_data.titleLength > 0) { + const Graphics::Font &font = _gui->getCurrentFont(); + Common::String title(_data.title); + font.drawString( + &surface, + title, + _data.bounds.left, + _data.bounds.top, + _data.bounds.right - _data.bounds.left, + colorText, + Graphics::kTextAlignCenter); + } +} + +bool CommandButton::isInsideBounds(const Common::Point point) const { + return _data.bounds.contains(point); +} + +const ControlData& CommandButton::getData() const { + return _data; +} + +void CommandButton::select() { + _selected = true; +} + +void CommandButton::unselect() { + _selected = false; +} + +bool CommandButton::isSelected() { + return _selected; +} +} diff --git a/engines/macventure/controls.h b/engines/macventure/controls.h new file mode 100644 index 0000000000..a780f6328b --- /dev/null +++ b/engines/macventure/controls.h @@ -0,0 +1,105 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_CONTROLS_H +#define MACVENTURE_CONTROLS_H + +namespace MacVenture { + +class Gui; + +enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc) + kControlExitBox = 0, + kControlExamine = 1, + kControlOpen = 2, + kControlClose = 3, + kControlSpeak = 4, + kControlOperate = 5, + kControlGo = 6, + kControlHit = 7, + kControlConsume = 8, + kControlClickToContinue = 9 +}; + +enum ControlAction { // HACK, figure out a way to put it in engine + kNoCommand = 0, + kStartOrResume = 1, + kClose = 2, + kTick = 3, + kActivateObject = 4, + kMoveObject = 5, + kConsume = 6, + kExamine = 7, + kGo = 8, + kHit = 9, + kOpen = 10, + kOperate = 11, + kSpeak = 12, + kBabble = 13, + kTargetName = 14, + kDebugObject = 15, + kClickToContinue = 16 +}; +struct ControlData { + Common::Rect bounds; + uint16 scrollValue; + uint8 visible; + uint16 scrollMax; + uint16 scrollMin; + uint16 cdef; + ControlAction refcon; + ControlType type; + uint8 titleLength; + char* title; + uint16 border; +}; + +class CommandButton { + +enum { + kCommandsLeftPadding = 0, + kCommandsTopPadding = 0 +}; + +public: + + CommandButton(); + + CommandButton(ControlData data, Gui *g); + ~CommandButton() {} + + void draw(Graphics::ManagedSurface &surface) const; + bool isInsideBounds(const Common::Point point) const; + const ControlData& getData() const; + void select(); + void unselect(); + bool isSelected(); + +private: + bool _selected; + ControlData _data; + Gui *_gui; +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index ba489d4bad..a6c1e78a6f 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -23,47 +23,8 @@ #include "common/system.h" #include "macventure/dialog.h" - namespace MacVenture { -// Prebuilt dialogs - -enum { - // HACK - kMaxPrebuiltDialogElements = 10 -}; - -struct PrebuiltDialog { - Common::Rect bounds; - PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; -}; - -PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { - - {/* kSaveAsDialog */ - Common::Rect(0, 146, 456, 254), - { - {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, - {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, - {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, - {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - }, - - { /* kSpeakDialog */ - Common::Rect(20, 92, 400, 200), - { - {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, - {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, - {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - } - -}; Dialog::Dialog(Gui *gui, Common::Point pos, uint width, uint height) : _gui(gui), _bounds(Common::Rect(pos.x, pos.y, pos.x + width, pos.y + height)) {} diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index e773956b09..66d68e358e 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -26,44 +26,13 @@ #include "graphics/macgui/macwindowmanager.h" #include "macventure/macventure.h" -#include "macventure/gui.h" - +#include "macventure/prebuilt_dialogs.h" namespace MacVenture { using namespace Graphics::MacGUIConstants; class Gui; - class DialogElement; -enum DialogAction { - kDANone, - kDACloseDialog, - kDASubmit, - kDASaveAs -}; - -enum PrebuiltDialogs { - kSaveAsDialog = 0, - kSpeakDialog = 1, - kPrebuiltDialogCount -}; - -enum PrebuiltElementType { - kDEPlainText, - kDEButton, - kDETextInput, - kDEEnd -}; - -struct PrebuiltDialogElement { - PrebuiltElementType type; - Common::String title; - DialogAction action; - Common::Point position; - uint width; - uint height; -}; - class Dialog { public: Dialog(Gui *gui, Common::Point pos, uint width, uint height); diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d38a7a5c3d..d8db6656e5 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -20,14 +20,14 @@ * */ + #include "common/file.h" +#include "common/timer.h" +#include "common/system.h" #include "image/bmp.h" -#include "macventure/macventure.h" #include "macventure/gui.h" - -#include "common/timer.h" -#include "common/system.h" +#include "macventure/dialog.h" namespace MacVenture { @@ -36,12 +36,12 @@ namespace MacVenture { enum MenuAction; enum { - kCursorWidth = 2, // HACK Arbitrary width to test + kCursorWidth = 2, kCursorHeight = 2 }; enum { - kExitButtonWidth = 10, // HACK Arbitrary width to test + kExitButtonWidth = 10, kExitButtonHeight = 10 }; @@ -802,10 +802,20 @@ void Gui::printText(const Common::String & text) { _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } +void Gui::showPrebuiltDialog(PrebuiltDialogs type) { + closeDialog(); + _dialog = new Dialog(this, type); +} + +bool Gui::isDialogOpen() { + return _dialog != nullptr; +} + void Gui::setTextInput(Common::String str) { _engine->setTextInput(str); } + void Gui::closeDialog() { delete _dialog; _dialog = nullptr; @@ -815,9 +825,7 @@ void Gui::getTextFromUser() { if (_dialog) { delete _dialog; } - _dialog = new Dialog(this, kSpeakDialog); - // Hack to pause the engine - _engine->clickToContinue(); + showPrebuiltDialog(kSpeakDialog); } void Gui::loadGame(int slot) { @@ -1046,8 +1054,7 @@ void Gui::handleMenuAction(MenuAction action) { break; case MacVenture::kMenuActionSaveAs: debug("MacVenture Menu Action: Save As"); - // HACK this should be wrapped in a function - _dialog = new Dialog(this, kSaveAsDialog); + showPrebuiltDialog(kSaveAsDialog); break; case MacVenture::kMenuActionQuit: debug("MacVenture Menu Action: Quit"); @@ -1140,6 +1147,7 @@ void Gui::invertWindowColors(WindowReference winID) { } } + bool Gui::tryCloseWindow(WindowReference winID) { WindowData data = findWindowData(winID); if (winID < 0x80) { // Inventory window diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index b03ca2afe9..eb929cfcdd 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -29,9 +29,12 @@ #include "graphics/font.h" +#include "macventure/macventure.h" #include "macventure/container.h" #include "macventure/image.h" +#include "macventure/prebuilt_dialogs.h" #include "macventure/dialog.h" +#include "macventure/controls.h" namespace MacVenture { @@ -114,53 +117,6 @@ struct WindowData { bool updateScroll; }; -enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc) - kControlExitBox = 0, - kControlExamine = 1, - kControlOpen = 2, - kControlClose = 3, - kControlSpeak = 4, - kControlOperate = 5, - kControlGo = 6, - kControlHit = 7, - kControlConsume = 8, - kControlClickToContinue = 9 -}; - -enum ControlAction { // HACK, figure out a way to put it in engine - kNoCommand = 0, - kStartOrResume = 1, - kClose = 2, - kTick = 3, - kActivateObject = 4, - kMoveObject = 5, - kConsume = 6, - kExamine = 7, - kGo = 8, - kHit = 9, - kOpen = 10, - kOperate = 11, - kSpeak = 12, - kBabble = 13, - kTargetName = 14, - kDebugObject = 15, - kClickToContinue = 16 -}; - -struct ControlData { - Common::Rect bounds; - uint16 scrollValue; - uint8 visible; - uint16 scrollMax; - uint16 scrollMin; - uint16 cdef; - ControlAction refcon; - ControlType type; - uint8 titleLength; - char* title; - uint16 border; -}; - struct BorderBounds { uint16 leftOffset; uint16 topOffset; @@ -204,6 +160,7 @@ public: void updateWindow(WindowReference winID, bool containerOpen); void invertWindowColors(WindowReference winID); + WindowReference createInventoryWindow(ObjID objRef); bool tryCloseWindow(WindowReference winID); @@ -223,8 +180,6 @@ public: void processCursorTick(); - //bool processClickObject(ObjID obj, WindowReference win, Common::Event event, bool canDrag); - const WindowData& getWindowData(WindowReference reference); const Graphics::Font& getCurrentFont(); @@ -248,6 +203,9 @@ public: void printText(const Common::String &text); //Dialog interactions + void showPrebuiltDialog(PrebuiltDialogs type); + bool isDialogOpen(); + void getTextFromUser(); void setTextInput(Common::String str); void closeDialog(); @@ -428,74 +386,6 @@ private: }; -class CommandButton { - -enum { - kCommandsLeftPadding = 0, - kCommandsTopPadding = 0 -}; - -public: - - CommandButton() { - _gui = nullptr; - } - - CommandButton(ControlData data, Gui *g) { - _data = data; - _gui = g; - _selected = false; - } - ~CommandButton() {} - - void draw(Graphics::ManagedSurface &surface) const { - - uint colorFill = _selected ? kColorBlack : kColorWhite; - uint colorText = _selected ? kColorWhite : kColorBlack; - - surface.fillRect(_data.bounds, colorFill); - surface.frameRect(_data.bounds, kColorBlack); - - if (_data.titleLength > 0) { - const Graphics::Font &font = _gui->getCurrentFont(); - Common::String title(_data.title); - font.drawString( - &surface, - title, - _data.bounds.left, - _data.bounds.top, - _data.bounds.right - _data.bounds.left, - colorText, - Graphics::kTextAlignCenter); - } - } - - bool isInsideBounds(const Common::Point point) const { - return _data.bounds.contains(point); - } - - const ControlData& getData() const { - return _data; - } - - void select() { - _selected = true; - } - - void unselect() { - _selected = false; - } - - bool isSelected() { - return _selected; - } - -private: - bool _selected; - ControlData _data; - Gui *_gui; -}; - class ConsoleText { public: diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 9d437612f0..6cb6db5d42 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -126,7 +126,7 @@ Common::Error MacVentureEngine::run() { if (_gameState != kGameStateQuitting) { - if (_prepared) { + if (_prepared && !_gui->isDialogOpen()) { _prepared = false; if (!_halted) @@ -148,6 +148,7 @@ Common::Error MacVentureEngine::run() { if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { endGame(); + return Common::kNoError; } } _gui->draw(); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 167abcc351..9d1677dd6b 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -39,6 +39,7 @@ #include "macventure/hufflists.h" #include "macventure/stringtable.h" #include "macventure/script.h" +#include "controls.h" struct ADGameDescription; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 813677c33c..66039d4c9f 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -3,13 +3,14 @@ MODULE := engines/macventure MODULE_OBJS := \ image.o \ detection.o \ - gui.o \ object.o \ text.o \ world.o \ script.o \ macventure.o \ - dialog.o + gui.o \ + dialog.o \ + controls.o MODULE_DIRS += \ engines/macventure diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h new file mode 100644 index 0000000000..34df91e51b --- /dev/null +++ b/engines/macventure/prebuilt_dialogs.h @@ -0,0 +1,97 @@ + +/* 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. +* +*/ + +#ifndef MACVENTURE_PREBUIT_DIALOGS_H +#define MACVENTURE_PREBUIT_DIALOGS_H + +namespace MacVenture { +enum DialogAction { + kDANone, + kDACloseDialog, + kDASubmit, + kDASaveAs +}; + +enum PrebuiltDialogs { + kSaveAsDialog = 0, + kSpeakDialog = 1, + kPrebuiltDialogCount +}; + +enum PrebuiltElementType { + kDEPlainText, + kDEButton, + kDETextInput, + kDEEnd +}; + +struct PrebuiltDialogElement { + PrebuiltElementType type; + Common::String title; + DialogAction action; + Common::Point position; + uint width; + uint height; +}; + + +// Prebuilt dialogs +enum { + // HACK + kMaxPrebuiltDialogElements = 10 +}; + +struct PrebuiltDialog { + Common::Rect bounds; + PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; +}; + +PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { + + {/* kSaveAsDialog */ + Common::Rect(0, 146, 456, 254), + { + {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, + {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, + {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, + {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + }, + + { /* kSpeakDialog */ + Common::Rect(20, 92, 400, 200), + { + {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, + {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, + {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + } + +}; +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 49b69874e6..5760a31e8a 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -25,6 +25,8 @@ #include "macventure/container.h" #include "macventure/world.h" +#include "macventure/macventure.h" +#include "macventure/controls.h" namespace MacVenture { diff --git a/engines/macventure/text.h b/engines/macventure/text.h index 2389454042..88dd112681 100644 --- a/engines/macventure/text.h +++ b/engines/macventure/text.h @@ -28,6 +28,7 @@ namespace MacVenture { typedef uint32 ObjID; +class MacVentureEngine; class TextAsset { public: @@ -53,7 +54,7 @@ private: ObjID _sourceObj; const HuffmanLists *_huffman; bool _isOld; - + Common::String _decoded; }; -- cgit v1.2.3 From 2dfbfdbaba780ec4598556299af967f7eb0abf63 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 21 Jul 2016 17:38:28 +0200 Subject: MACVENTURE: Implement in-engine window closing --- engines/macventure/dialog.h | 3 ++ engines/macventure/gui.cpp | 72 +++++++++----------------- engines/macventure/gui.h | 65 ++--------------------- engines/macventure/macventure.cpp | 2 +- engines/macventure/macventure.h | 3 +- engines/macventure/module.mk | 5 +- engines/macventure/prebuilt_dialogs.cpp | 53 +++++++++++++++++++ engines/macventure/prebuilt_dialogs.h | 32 ++---------- engines/macventure/windows.cpp | 60 ++++++++++++++++++++++ engines/macventure/windows.h | 91 +++++++++++++++++++++++++++++++++ 10 files changed, 245 insertions(+), 141 deletions(-) create mode 100644 engines/macventure/prebuilt_dialogs.cpp create mode 100644 engines/macventure/windows.cpp create mode 100644 engines/macventure/windows.h diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index 66d68e358e..d40639a2d3 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -27,11 +27,14 @@ #include "macventure/macventure.h" #include "macventure/prebuilt_dialogs.h" + namespace MacVenture { using namespace Graphics::MacGUIConstants; class Gui; class DialogElement; +extern PrebuiltDialog prebuiltDialogs[]; + class Dialog { public: diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d8db6656e5..6fcd48c9fc 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -598,6 +598,12 @@ void Gui::drawInventories() { srf->h + border.bottomOffset), kColorWhite); drawObjectsInWindow(data.refcon, srf); + if (MACVENTURE_DEBUG_GUI) { + Common::Rect innerDims = findWindow(data.refcon)->getInnerDimensions(); + innerDims = Common::Rect(17, 17, innerDims.width() + 17, innerDims.height() + 17); + srf->frameRect(innerDims, kColorGreen); + } + findWindow(data.refcon)->setDirty(true); } @@ -1034,6 +1040,18 @@ Common::Point Gui::localize(Common::Point point, WindowReference origin, WindowR return point; } +void Gui::removeInventoryWindow(WindowReference ref) { + _inventoryWindows.remove_at(ref - kInventoryStart); + bool found = false; + Common::List::iterator it; + for (it = _windowData->begin(); it != _windowData->end() && !found; it++) { + if (it->refcon == ref) { + _windowData->erase(it); + found = true; + } + } +} + /* HANDLERS */ void Gui::handleMenuAction(MenuAction action) { @@ -1147,13 +1165,12 @@ void Gui::invertWindowColors(WindowReference winID) { } } - bool Gui::tryCloseWindow(WindowReference winID) { WindowData data = findWindowData(winID); - if (winID < 0x80) { // Inventory window - warning("Window closing not implemented"); - } else { - warning("Window closing not implemented"); + Graphics::MacWindow *win = findWindow(winID); + _wm.removeWindow(win); + if (winID < 0x80) { + removeInventoryWindow(winID); } return true; } @@ -1297,15 +1314,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (ref == kNoWindow) return false; if (click == kBorderCloseButton) { - _inventoryWindows.remove_at(ref - kInventoryStart); - bool found = false; - Common::List::iterator it; - for (it = _windowData->begin(); it != _windowData->end() && !found; it++) { - if (it->refcon == ref) { - _windowData->erase(it); - found = true; - } - } + removeInventoryWindow(ref); return true; } } @@ -1352,40 +1361,5 @@ void Gui::ensureAssetLoaded(ObjID obj) { } } -/* Ugly switches */ - -BorderBounds Gui::borderBounds(MVWindowType type) { - switch (type) { - case MacVenture::kDocument: - break; - case MacVenture::kDBox: - break; - case MacVenture::kPlainDBox: - return BorderBounds(6, 6, 6, 6); - case MacVenture::kAltBox: - return BorderBounds(4, 4, 4, 4); // Hand-tested - break; - case MacVenture::kNoGrowDoc: - return BorderBounds(1, 17, 1, 1); - case MacVenture::kMovableDBox: - break; - case MacVenture::kZoomDoc: - return BorderBounds(1, 19, 16, 1); - case MacVenture::kZoomNoGrow: - break; - case MacVenture::kRDoc16: - break; - case MacVenture::kRDoc4: - return BorderBounds(0, 19, 1, 1); - case MacVenture::kRDoc6: - break; - case MacVenture::kRDoc10: - break; - default: - break; - } - - return BorderBounds(0, 0, 0, 0); -} } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index eb929cfcdd..95e1480762 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -35,6 +35,7 @@ #include "macventure/prebuilt_dialogs.h" #include "macventure/dialog.h" #include "macventure/controls.h" +#include "macventure/windows.h" namespace MacVenture { @@ -49,6 +50,9 @@ class CommandButton; class ImageAsset; class Dialog; +BorderBounds borderBounds(MVWindowType type); +extern PrebuiltDialog prebuiltDialogs[]; + enum MenuAction { kMenuActionAbout, kMenuActionNew, @@ -68,64 +72,6 @@ enum MenuAction { }; //} using namespace MacVentureMenuActions; -enum WindowReference { - kNoWindow = 0, - kInventoryStart = 1, - kCommandsWindow = 0x80, - kMainGameWindow = 0x81, - kOutConsoleWindow = 0x82, - kSelfWindow = 0x83, - kExitsWindow = 0x84, - kDiplomaWindow = 0x85 -}; - -enum MVWindowType { - kDocument = 0x00, - kDBox = 0x01, - kPlainDBox = 0x02, - kAltBox = 0x03, - kNoGrowDoc = 0x04, - kMovableDBox = 0x05, - kZoomDoc = 0x08, - kZoomNoGrow = 0x0c, - kRDoc16 = 0x10, - kRDoc4 = 0x12, - kRDoc6 = 0x14, - kRDoc10 = 0x16 -}; - - -struct DrawableObject { - ObjID obj; - byte mode; - DrawableObject(ObjID id, byte md) { - obj = id; - mode = md; - } -}; - -struct WindowData { - Common::Rect bounds; - MVWindowType type; - ObjID objRef; - uint16 visible; - uint16 hasCloseBox; - WindowReference refcon; - uint8 titleLength; - Common::String title; - Common::Array children; - bool updateScroll; -}; - -struct BorderBounds { - uint16 leftOffset; - uint16 topOffset; - uint16 rightOffset; - uint16 bottomOffset; - - BorderBounds(uint16 l, uint16 t, uint16 r, uint16 b) : leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} -}; - struct DraggedObj { ObjID id; Common::Point pos; @@ -213,8 +159,6 @@ public: void loadGame(int slot); void saveInto(int slot); - // Ugly switches - BorderBounds borderBounds(MVWindowType type); private: // Attributes @@ -292,6 +236,7 @@ private: // Methods void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); Common::Point localize(Common::Point point, WindowReference origin, WindowReference target); + void removeInventoryWindow(WindowReference ref); void ensureAssetLoaded(ObjID obj); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 6cb6db5d42..ff4072dba3 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -930,7 +930,7 @@ Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { WindowReference win = findParentWindow(objID); if (win != kNoWindow) { // If it's not in a window YET, we don't really care about the border - BorderBounds bounds = _gui->borderBounds(_gui->getWindowData(win).type); // HACK + BorderBounds bounds = borderBounds(_gui->getWindowData(win).type); // HACK pos.x += bounds.leftOffset; pos.y += bounds.topOffset; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 9d1677dd6b..b228a34713 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -39,7 +39,8 @@ #include "macventure/hufflists.h" #include "macventure/stringtable.h" #include "macventure/script.h" -#include "controls.h" +#include "macventure/controls.h" +#include "macventure/windows.h" struct ADGameDescription; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 66039d4c9f..48c8930520 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -10,7 +10,10 @@ MODULE_OBJS := \ macventure.o \ gui.o \ dialog.o \ - controls.o + controls.o \ + prebuilt_dialogs.o \ + windows.o + MODULE_DIRS += \ engines/macventure diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp new file mode 100644 index 0000000000..13d2d446bf --- /dev/null +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -0,0 +1,53 @@ +/* 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 "macventure/prebuilt_dialogs.h" + +namespace MacVenture { + +PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { + + {/* kSaveAsDialog */ + Common::Rect(0, 146, 456, 254), + { + {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, + {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, + {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, + {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + }, + + { /* kSpeakDialog */ + Common::Rect(20, 92, 400, 200), + { + {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, + {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, + {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + } + +}; +} // End of namespace MacVenture diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 34df91e51b..1e708dbb67 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -1,4 +1,3 @@ - /* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names @@ -24,7 +23,10 @@ #ifndef MACVENTURE_PREBUIT_DIALOGS_H #define MACVENTURE_PREBUIT_DIALOGS_H +#include "common/rect.h" + namespace MacVenture { + enum DialogAction { kDANone, kDACloseDialog, @@ -54,7 +56,6 @@ struct PrebuiltDialogElement { uint height; }; - // Prebuilt dialogs enum { // HACK @@ -65,33 +66,6 @@ struct PrebuiltDialog { Common::Rect bounds; PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; }; - -PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { - - {/* kSaveAsDialog */ - Common::Rect(0, 146, 456, 254), - { - {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, - {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, - {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, - {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - }, - - { /* kSpeakDialog */ - Common::Rect(20, 92, 400, 200), - { - {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, - {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, - {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - } - -}; } // End of namespace MacVenture #endif diff --git a/engines/macventure/windows.cpp b/engines/macventure/windows.cpp new file mode 100644 index 0000000000..33a63709d2 --- /dev/null +++ b/engines/macventure/windows.cpp @@ -0,0 +1,60 @@ +/* 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 "macventure/windows.h" + +namespace MacVenture { + +BorderBounds borderBounds(MVWindowType type) { + switch (type) { + case MacVenture::kDocument: + break; + case MacVenture::kDBox: + break; + case MacVenture::kPlainDBox: + return BorderBounds(6, 6, 6, 6); + case MacVenture::kAltBox: + return BorderBounds(4, 4, 4, 4); // Hand-tested + break; + case MacVenture::kNoGrowDoc: + return BorderBounds(1, 17, 1, 1); + case MacVenture::kMovableDBox: + break; + case MacVenture::kZoomDoc: + return BorderBounds(1, 19, 16, 1); + case MacVenture::kZoomNoGrow: + break; + case MacVenture::kRDoc16: + break; + case MacVenture::kRDoc4: + return BorderBounds(0, 19, 1, 1); + case MacVenture::kRDoc6: + break; + case MacVenture::kRDoc10: + break; + default: + break; + } + + return BorderBounds(0, 0, 0, 0); +} +} // End of namespace MacVenture diff --git a/engines/macventure/windows.h b/engines/macventure/windows.h new file mode 100644 index 0000000000..70af446817 --- /dev/null +++ b/engines/macventure/windows.h @@ -0,0 +1,91 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_WINDOWS_H +#define MACVENTURE_WINDOWS_H + +#include "common/rect.h" +#include "common/array.h" + +namespace MacVenture { + // massive HACK +typedef uint32 ObjID; + +enum WindowReference { + kNoWindow = 0, + kInventoryStart = 1, + kCommandsWindow = 0x80, + kMainGameWindow = 0x81, + kOutConsoleWindow = 0x82, + kSelfWindow = 0x83, + kExitsWindow = 0x84, + kDiplomaWindow = 0x85 +}; + +enum MVWindowType { + kDocument = 0x00, + kDBox = 0x01, + kPlainDBox = 0x02, + kAltBox = 0x03, + kNoGrowDoc = 0x04, + kMovableDBox = 0x05, + kZoomDoc = 0x08, + kZoomNoGrow = 0x0c, + kRDoc16 = 0x10, + kRDoc4 = 0x12, + kRDoc6 = 0x14, + kRDoc10 = 0x16 +}; + +struct DrawableObject { + ObjID obj; + byte mode; + DrawableObject(ObjID id, byte md) { + obj = id; + mode = md; + } +}; + +struct WindowData { + Common::Rect bounds; + MVWindowType type; + ObjID objRef; + uint16 visible; + uint16 hasCloseBox; + WindowReference refcon; + uint8 titleLength; + Common::String title; + Common::Array children; + bool updateScroll; +}; + +struct BorderBounds { + uint16 leftOffset; + uint16 topOffset; + uint16 rightOffset; + uint16 bottomOffset; + + BorderBounds(uint16 l, uint16 t, uint16 r, uint16 b) : + leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} +}; +} +#endif -- cgit v1.2.3 From 87c6265582f6efa31f6a8dcc77ffe509c3720010 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 22 Jul 2016 12:45:54 +0200 Subject: MACVENTURE: Fix window borders --- engines/macventure/gui.cpp | 47 +++++++++++++++++++++++++++--------------- engines/macventure/gui.h | 2 +- engines/macventure/windows.cpp | 2 +- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 6fcd48c9fc..37aef21110 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -215,40 +215,40 @@ void Gui::initWindows() { _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); _controlsWindow->setActive(false); _controlsWindow->setCallback(commandsWindowCallback, this); - loadBorder(_controlsWindow, "border_command.bmp", false); - loadBorder(_controlsWindow, "border_command.bmp", true); + loadBorder(_controlsWindow, "border_command.bmp", false, findWindowData(kCommandsWindow).type); + loadBorder(_controlsWindow, "border_command.bmp", true, findWindowData(kCommandsWindow).type); // Main Game Window _mainGameWindow = _wm.addWindow(true, true, true); _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); - //loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true); + loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false, findWindowData(kMainGameWindow).type); + loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true, findWindowData(kMainGameWindow).type); // In-game Output Console _outConsoleWindow = _wm.addWindow(false, true, true); _outConsoleWindow->setDimensions(getWindowData(kOutConsoleWindow).bounds); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false, findWindowData(kOutConsoleWindow).type); + loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true, findWindowData(kOutConsoleWindow).type); // Self Window _selfWindow = _wm.addWindow(false, true, false); _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - loadBorder(_selfWindow, "border_none.bmp", false); - loadBorder(_selfWindow, "border_none.bmp", true); + loadBorder(_selfWindow, "border_none.bmp", false, findWindowData(kSelfWindow).type); + loadBorder(_selfWindow, "border_none.bmp", true, findWindowData(kSelfWindow).type); // Exits Window _exitsWindow = _wm.addWindow(false, false, false); _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); - loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false); - loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true); + loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false, findWindowData(kExitsWindow).type); + loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true, findWindowData(kExitsWindow).type); } const WindowData& Gui::getWindowData(WindowReference reference) { @@ -336,15 +336,15 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); newWindow->setCloseable(true); - //loadBorder(newWindow, "border_no_scroll_inac.bmp", false); - //loadBorder(newWindow, "border_no_scroll_act.bmp", true); + loadBorder(newWindow, "border_both_scroll_inac.bmp", false, newData.type); + loadBorder(newWindow, "border_both_scroll_inac.bmp", true, newData.type); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); return newData.refcon; } -void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool active) { +void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool active, MVWindowType type) { Common::File borderfile; if (!borderfile.open(filename)) { @@ -358,8 +358,9 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool Graphics::TransparentSurface *surface = new Graphics::TransparentSurface(); if (stream) { + BorderBounds bbs = borderBounds(type); debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename.c_str()); - target->loadBorder(*stream, active); + target->loadBorder(*stream, active, bbs.leftOffset, bbs.rightOffset, bbs.topOffset, bbs.bottomOffset); delete stream; } @@ -575,6 +576,15 @@ void Gui::drawMainGameWindow() { } drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); + if (MACVENTURE_DEBUG_GUI) { + Graphics::MacWindow *win = findWindow(data.refcon); + Common::Rect innerDims = win->getInnerDimensions(); + int x = win->getDimensions().left; + int y = win->getDimensions().top; + innerDims.translate(-x, -y); + win->getSurface()->frameRect(innerDims, kColorGreen); + } + findWindow(kMainGameWindow)->setDirty(true); } @@ -599,8 +609,11 @@ void Gui::drawInventories() { drawObjectsInWindow(data.refcon, srf); if (MACVENTURE_DEBUG_GUI) { - Common::Rect innerDims = findWindow(data.refcon)->getInnerDimensions(); - innerDims = Common::Rect(17, 17, innerDims.width() + 17, innerDims.height() + 17); + Graphics::MacWindow *win = findWindow(data.refcon); + Common::Rect innerDims = win->getInnerDimensions(); + int x = win->getDimensions().left; + int y = win->getDimensions().top; + innerDims.translate(-x, -y); srf->frameRect(innerDims, kColorGreen); } @@ -1322,7 +1335,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (_engine->needsClickToContinue()) return true; - if (event.type == Common::EVENT_LBUTTONDOWN) { + if (event.type == Common::EVENT_LBUTTONDOWN && click == kBorderInner) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); if (ref == kNoWindow) return false; diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 95e1480762..90f2f42991 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -203,7 +203,7 @@ private: // Methods bool loadMenus(); bool loadWindows(); bool loadControls(); - void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); + void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active, MVWindowType type); void loadGraphics(); // Drawers diff --git a/engines/macventure/windows.cpp b/engines/macventure/windows.cpp index 33a63709d2..c89fa9397c 100644 --- a/engines/macventure/windows.cpp +++ b/engines/macventure/windows.cpp @@ -40,7 +40,7 @@ BorderBounds borderBounds(MVWindowType type) { case MacVenture::kMovableDBox: break; case MacVenture::kZoomDoc: - return BorderBounds(1, 19, 16, 1); + return BorderBounds(1, 19, 16, 16); case MacVenture::kZoomNoGrow: break; case MacVenture::kRDoc16: -- cgit v1.2.3 From fb180a8cdbf7e75c28502a8f3531d78cc5224535 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 24 Jul 2016 17:39:03 +0200 Subject: MACVENTURE: Fix gui --- engines/macventure/gui.cpp | 6 +++--- engines/macventure/windows.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 37aef21110..13f0a9d692 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -232,7 +232,7 @@ void Gui::initWindows() { _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false, findWindowData(kOutConsoleWindow).type); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", true, findWindowData(kOutConsoleWindow).type); + loadBorder(_outConsoleWindow, "border_left_scroll_act.bmp", true, findWindowData(kOutConsoleWindow).type); // Self Window _selfWindow = _wm.addWindow(false, true, false); @@ -337,7 +337,7 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setCallback(inventoryWindowCallback, this); newWindow->setCloseable(true); loadBorder(newWindow, "border_both_scroll_inac.bmp", false, newData.type); - loadBorder(newWindow, "border_both_scroll_inac.bmp", true, newData.type); + loadBorder(newWindow, "border_both_scroll_act.bmp", true, newData.type); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); @@ -539,7 +539,7 @@ void Gui::drawCommandsWindow() { Graphics::ManagedSurface *srf = _controlsWindow->getSurface(); WindowData data = getWindowData(kCommandsWindow); uint16 border = borderBounds(data.type).topOffset; - srf->fillRect(Common::Rect(border * 2, border * 2, srf->w - (border * 3), srf->h - (border * 3)), kColorWhite); + srf->fillRect(Common::Rect(0, 0, srf->w, srf->h), kColorWhite); getCurrentFont().drawString( srf, _engine->getCommandsPausedString(), diff --git a/engines/macventure/windows.cpp b/engines/macventure/windows.cpp index c89fa9397c..9825349641 100644 --- a/engines/macventure/windows.cpp +++ b/engines/macventure/windows.cpp @@ -31,22 +31,22 @@ BorderBounds borderBounds(MVWindowType type) { case MacVenture::kDBox: break; case MacVenture::kPlainDBox: - return BorderBounds(6, 6, 6, 6); + return BorderBounds(1, 1, 1, 2); case MacVenture::kAltBox: - return BorderBounds(4, 4, 4, 4); // Hand-tested + return BorderBounds(0, 0, 0, 0); // Hand-tested break; case MacVenture::kNoGrowDoc: return BorderBounds(1, 17, 1, 1); case MacVenture::kMovableDBox: break; case MacVenture::kZoomDoc: - return BorderBounds(1, 19, 16, 16); + return BorderBounds(1, 19, 17, 17); case MacVenture::kZoomNoGrow: break; case MacVenture::kRDoc16: break; case MacVenture::kRDoc4: - return BorderBounds(0, 19, 1, 1); + return BorderBounds(1, 19, 1, 1); case MacVenture::kRDoc6: break; case MacVenture::kRDoc10: -- cgit v1.2.3 From a7f2cea37d7ec5101d4b2235168e2b660993258a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 25 Jul 2016 16:43:20 +0200 Subject: MACVENTURE: Add scroll to console window --- engines/macventure/gui.cpp | 6 ++++++ engines/macventure/gui.h | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 13f0a9d692..6a30985b74 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1270,6 +1270,12 @@ bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & if (_engine->needsClickToContinue()) return true; + debug("OutConsoleEvent: %d", click); + if (click == kBorderScrollUp) { + _consoleText->scrollUp(); + return true; + } + return getWindowData(kOutConsoleWindow).visible; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 90f2f42991..aea6733d2f 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -363,7 +363,6 @@ public: void renderInto(Graphics::ManagedSurface *target, uint leftOffset) { target->fillRect(target->getBounds(), kColorWhite); const Graphics::Font *font = &_gui->getCurrentFont(); - // HACK print the last lines visible (no scroll) uint y = target->h - font->getFontHeight(); for (uint i = _lines.size() - 1; i != 0; i--) { font->drawString(target, _lines[i], leftOffset, y, font->getStringWidth(_lines[i]), kColorBlack); @@ -372,14 +371,25 @@ public: } void updateScroll() { - // TODO implemebt + _scrollPos = _lines.size() - 1; } + void scrollDown() { + if (_scrollPos < _lines.size() - 1) _scrollPos++; + } + + void scrollUp() { + debug("scroll up"); + if (_scrollPos > 0) _scrollPos--; + } + + private: Gui *_gui; Common::StringArray _lines; + int _scrollPos; }; -- cgit v1.2.3 From e25fb16a3739696fbf85d7666bf013abb40bec24 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 26 Jul 2016 10:43:02 +0200 Subject: MACVENTURE: Add scroll to console window --- engines/macventure/gui.cpp | 10 +++++++--- engines/macventure/gui.h | 2 +- engines/macventure/macventure.cpp | 2 -- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 6a30985b74..8045c27a51 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -227,7 +227,7 @@ void Gui::initWindows() { loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true, findWindowData(kMainGameWindow).type); // In-game Output Console - _outConsoleWindow = _wm.addWindow(false, true, true); + _outConsoleWindow = _wm.addWindow(true, true, false); _outConsoleWindow->setDimensions(getWindowData(kOutConsoleWindow).bounds); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); @@ -1266,15 +1266,19 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e } return false; } + bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & event) { if (_engine->needsClickToContinue()) return true; - debug("OutConsoleEvent: %d", click); - if (click == kBorderScrollUp) { + if (click == kBorderScrollUp && event.type == Common::EVENT_LBUTTONDOWN) { _consoleText->scrollUp(); return true; } + if (click == kBorderScrollDown && event.type == Common::EVENT_LBUTTONDOWN) { + _consoleText->scrollDown(); + return true; + } return getWindowData(kOutConsoleWindow).visible; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index aea6733d2f..902aa8c142 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -364,7 +364,7 @@ public: target->fillRect(target->getBounds(), kColorWhite); const Graphics::Font *font = &_gui->getCurrentFont(); uint y = target->h - font->getFontHeight(); - for (uint i = _lines.size() - 1; i != 0; i--) { + for (uint i = _scrollPos; i != 0; i--) { font->drawString(target, _lines[i], leftOffset, y, font->getStringWidth(_lines[i]), kColorBlack); y -= font->getFontHeight(); } diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index ff4072dba3..871b10428e 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -714,8 +714,6 @@ void MacVentureEngine::openObject(ObjID objID) { _gui->setWindowTitle(kMainGameWindow, _world->getText(objID, objID, objID)); // it ignores source and target in the original } else { // Open inventory window Common::Point p(_world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); - //getParentWin(obj).localToGlobal(p); - //globalToDesktop(p); WindowReference invID = _gui->createInventoryWindow(objID); _gui->setWindowTitle(invID, _world->getText(objID, objID, objID)); _gui->updateWindowInfo(invID, objID, _world->getChildren(objID, true)); -- cgit v1.2.3 From b02185432716e9a6a9d163318a0ebf817750a167 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 26 Jul 2016 11:06:41 +0200 Subject: MACVENTURE: Add scroll to inventory windows --- engines/macventure/gui.cpp | 27 ++++++++++++++++++++++----- engines/macventure/windows.h | 5 +++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 8045c27a51..ed9bad6720 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -467,6 +467,7 @@ bool Gui::loadWindows() { newTitle[data.titleLength] = '\0'; data.title = Common::String(newTitle); } + data.scrollPos = Common::Point(0, 0); debug(4, "Window loaded: %s", data.title.c_str()); @@ -667,6 +668,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); pos += Common::Point(border.leftOffset, border.topOffset); + pos -= data.scrollPos; ensureAssetLoaded(child); _assets[child]->blitInto( @@ -1345,18 +1347,33 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (_engine->needsClickToContinue()) return true; - if (event.type == Common::EVENT_LBUTTONDOWN && click == kBorderInner) { + if (event.type == Common::EVENT_LBUTTONDOWN) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); if (ref == kNoWindow) return false; Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); - Common::Point pos; - // Click rect to local coordinates. We assume the click is inside the window ^ - Common::Rect clickRect = calculateClickRect(event.mouse, win->getDimensions()); - checkSelect(data, event, clickRect, (WindowReference)ref); + if (click == kBorderScrollUp) { + data.scrollPos.y = MAX(0, data.scrollPos.y - kScrollAmount); + } + if (click == kBorderScrollDown) { + data.scrollPos.y += kScrollAmount; + } + if (click == kBorderScrollLeft) { + data.scrollPos.x = MAX(0, data.scrollPos.x - kScrollAmount); + } + if (click == kBorderScrollRight) { + data.scrollPos.x += kScrollAmount; + } + + if (click == kBorderInner) { + Common::Point pos; + // Click rect to local coordinates. We assume the click is inside the window ^ + Common::Rect clickRect = calculateClickRect(event.mouse, win->getDimensions()); + checkSelect(data, event, clickRect, (WindowReference)ref); + } } return true; } diff --git a/engines/macventure/windows.h b/engines/macventure/windows.h index 70af446817..79b2798a2b 100644 --- a/engines/macventure/windows.h +++ b/engines/macventure/windows.h @@ -65,6 +65,10 @@ struct DrawableObject { } }; +enum { + kScrollAmount = 10 +}; + struct WindowData { Common::Rect bounds; MVWindowType type; @@ -76,6 +80,7 @@ struct WindowData { Common::String title; Common::Array children; bool updateScroll; + Common::Point scrollPos; }; struct BorderBounds { -- cgit v1.2.3 From 518d336e5a5e266c2b443a9cacfa88abd541fe28 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 26 Jul 2016 11:42:58 +0200 Subject: MACVENTURE: Fix item selection on scroll --- engines/macventure/gui.cpp | 14 ++++++++------ engines/macventure/gui.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index ed9bad6720..738ea900af 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -683,7 +683,9 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * // For test if (MACVENTURE_DEBUG_GUI) { - surface->frameRect(_engine->getObjBounds(child), kColorGreen); + Common::Rect testBounds = _engine->getObjBounds(child); + testBounds.translate(-data.scrollPos.x, -data.scrollPos.y); + surface->frameRect(testBounds, kColorGreen); } } @@ -982,7 +984,7 @@ void Gui::checkSelect(const WindowData &data, const Common::Event &event, const child = (*it).obj; } } - if (child != 0) selectDraggable(child, ref, event.mouse); + if (child != 0) selectDraggable(child, ref, event.mouse, data.scrollPos); } bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { @@ -1004,12 +1006,12 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { return _assets[obj]->isRectInside(intersection); } -void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point click) { +void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point click, Common::Point scroll) { if (_engine->isObjClickable(child) && _draggedObj.id == 0) { _draggedObj.hasMoved = false; _draggedObj.id = child; _draggedObj.startWin = origin; - _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - click; + _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - click - scroll; _draggedObj.pos = click + _draggedObj.mouseOffset; _draggedObj.startPos = _draggedObj.pos; } @@ -1263,7 +1265,7 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e WindowData &data = findWindowData(kMainGameWindow); Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ - Common::Rect clickRect = calculateClickRect(event.mouse, _mainGameWindow->getDimensions()); + Common::Rect clickRect = calculateClickRect(event.mouse + data.scrollPos, _mainGameWindow->getDimensions()); checkSelect(data, event, clickRect, kMainGameWindow); } return false; @@ -1371,7 +1373,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (click == kBorderInner) { Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ - Common::Rect clickRect = calculateClickRect(event.mouse, win->getDimensions()); + Common::Rect clickRect = calculateClickRect(event.mouse + data.scrollPos, win->getDimensions()); checkSelect(data, event, clickRect, (WindowReference)ref); } } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 902aa8c142..8b0cbc6a6b 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -232,7 +232,7 @@ private: // Methods bool canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); void checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); bool isRectInsideObject(Common::Rect target, ObjID obj); - void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); + void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos, Common::Point scroll); void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); Common::Point localize(Common::Point point, WindowReference origin, WindowReference target); -- cgit v1.2.3 From f58435a2bcf41153b5a0c0e61548dd350e24cad9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 27 Jul 2016 21:08:33 +0200 Subject: MACVENTURE: Add dejavu --- engines/macventure/container.h | 52 +++++++++++++++++++---------------- engines/macventure/detection.cpp | 1 + engines/macventure/detection_tables.h | 1 + engines/macventure/gui.cpp | 2 +- engines/macventure/script.cpp | 2 +- engines/macventure/world.cpp | 4 +-- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index f0094a786b..a909122874 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -26,6 +26,7 @@ #include "macventure/macventure.h" #include "common/file.h" +#include "common/fs.h" #include "common/bitstream.h" namespace MacVenture { @@ -38,20 +39,23 @@ struct ItemGroup { typedef uint32 ContainerHeader; -class Container { +class Container { public: - Container(const char *filename) { - _filename = Common::String(filename); + Container(Common::String filename) { + _filename = filename; - if (!_file.open(filename)) - error("Could not open %s", filename); + FSNode node = FSDirectory("."); + debug(node.getDisplayName().c_str()); + + if (!_file.open(_filename)) + error("Could not open %s", _filename.c_str()); _res = _file.readStream(_file.size()); _header = _res->readUint32BE(); _simplified = false; - - if (!(_header & 0x80000000)) { + + if (!(_header & 0x80000000)) { // Is simplified container _simplified = true; int dataLen = _res->size() - sizeof(_header); @@ -75,7 +79,7 @@ public: for (uint i = 0; i < numGroups; ++i) { ItemGroup group; - + // Place myself in the correct position to read group _res->seek(_header + (i * 6) + 0x30, SEEK_SET); byte b1, b2, b3; @@ -91,10 +95,10 @@ public: // Place the bit reader in the correct position // group.bitOffset indicates the offset from the start of the subHeader - _res->seek(_header + (group.bitOffset >> 3), SEEK_SET); + _res->seek(_header + (group.bitOffset >> 3), SEEK_SET); uint32 bits = group.bitOffset & 7; - for (uint j = 0; j < 64; ++j) { + for (uint j = 0; j < 64; ++j) { uint32 length = 0; //debug("reading mask from address %x", _res->pos()); uint32 mask = _res->readUint32BE(); @@ -107,8 +111,8 @@ public: for (x = 0; x < 16; x++) { if (_huff[x] > mask) break; } - - // I will opt to copy the code from webventure, + + // I will opt to copy the code from webventure, // But according to the docs, this call should suffice: // length = bitStream.getBits(_lens[x]); // The problem is that _lens[] usually contains values larger @@ -131,19 +135,19 @@ public: else length >>= (32 - bitSize) - bits; length &= (1 << bitSize) - 1; length |= 1 << bitSize; - bits += bitSize; + bits += bitSize; if (bits & 0x10) { bits &= 0xF; _res->seek(2, SEEK_CUR); } - } + } group.lengths[j] = length; debug(11, "Load legth of object %d:%d is %d", i, j, length); } - - _groups.push_back(group); - } + + _groups.push_back(group); + } } } @@ -173,12 +177,12 @@ public: /** * getItemByteSize should be called before this one */ - Common::SeekableReadStream *getItem(uint32 id) { + Common::SeekableReadStream *getItem(uint32 id) { if (_simplified) { _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); } else { uint32 groupID = (id >> 6); - uint32 objectIndex = id & 0x3f; // Index within the group + uint32 objectIndex = id & 0x3f; // Index within the group uint32 offset = 0; for (uint i = 0; i < objectIndex; i++) { @@ -192,24 +196,24 @@ public: Common::SeekableReadStream *res = _res->readStream(getItemByteSize(id) * 2); return res; } - + protected: bool _simplified; - + uint _lenObjs; // In the case of simple container, lenght of an object uint _numObjs; ContainerHeader _header; - + uint16 _huff[15]; // huffman masks uint8 _lens[16]; // huffman lengths Common::Array _groups; - + Common::String _filename; Common::File _file; Common::SeekableReadStream *_res; - + }; diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 88fb85d650..597f859cee 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -41,6 +41,7 @@ namespace MacVenture { static const PlainGameDescriptor macventureGames[] = { { "shadowgate", "Shadowgate" }, + { "deja_vu", "Deja Vu"}, { 0, 0 } }; diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h index e2e94261bb..ebcf35f8b6 100644 --- a/engines/macventure/detection_tables.h +++ b/engines/macventure/detection_tables.h @@ -28,6 +28,7 @@ namespace MacVenture { static const ADGameDescription gameDescriptions[] = { BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "ebbfbcbf93938bd2900cb0c0213b19ad", 68974), // Zojoi Rerelease + BASEGAME("deja_vu", "Zojoi Rerelease", "Déjà Vu.bin", "5e9f5a8e3c8eb29ed02b34ae5937354f", 69034), // Zojoi Rerelease AD_TABLE_END_MARKER }; } // End of namespace MacVenture diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 738ea900af..7691b56697 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -368,7 +368,7 @@ void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool } void Gui::loadGraphics() { - _graphics = new Container(_engine->getFilePath(kGraphicPathID).c_str()); + _graphics = new Container(_engine->getFilePath(kGraphicPathID)); } bool Gui::loadMenus() { diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 36aabae3ed..51bfa3382b 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -33,7 +33,7 @@ ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; // HACK - _scripts = new Container("Shadowgate II/Shadow Filter"); + _scripts = new Container(_engine->getFilePath(kFilterPathID)); } ScriptEngine::~ScriptEngine() { diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index e6efeb5598..f5af029f8f 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -20,10 +20,10 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); _saveGame = new SaveGame(_engine, saveGameRes); - _objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str()); + _objectConstants = new Container(_engine->getFilePath(kObjectPathID)); calculateObjectRelations(); - _gameText = new Container(_engine->getFilePath(kTextPathID).c_str()); + _gameText = new Container(_engine->getFilePath(kTextPathID)); delete saveGameRes; saveGameFile.close(); -- cgit v1.2.3 From 5781b738be5b7821982ee966743696c83492dbd3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 28 Jul 2016 12:50:37 +0200 Subject: MACVENTURE: Deja Vu playable --- engines/macventure/container.h | 4 ++-- engines/macventure/detection_tables.h | 2 +- engines/macventure/macventure.cpp | 15 ++++++++++++++- engines/macventure/macventure.h | 3 +++ engines/macventure/stringtable.h | 12 ++++++++---- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index a909122874..21fdc6c529 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -45,8 +45,8 @@ public: Container(Common::String filename) { _filename = filename; - FSNode node = FSDirectory("."); - debug(node.getDisplayName().c_str()); + //FSNode node = FSDirectory("."); + //debug(node.getDisplayName().c_str()); if (!_file.open(_filename)) error("Could not open %s", _filename.c_str()); diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h index ebcf35f8b6..0b55d03dd5 100644 --- a/engines/macventure/detection_tables.h +++ b/engines/macventure/detection_tables.h @@ -28,7 +28,7 @@ namespace MacVenture { static const ADGameDescription gameDescriptions[] = { BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "ebbfbcbf93938bd2900cb0c0213b19ad", 68974), // Zojoi Rerelease - BASEGAME("deja_vu", "Zojoi Rerelease", "Déjà Vu.bin", "5e9f5a8e3c8eb29ed02b34ae5937354f", 69034), // Zojoi Rerelease + BASEGAME("deja_vu", "Zojoi Rerelease", "Deja Vu.bin", "5e9f5a8e3c8eb29ed02b34ae5937354f", 69034), // Zojoi Rerelease AD_TABLE_END_MARKER }; } // End of namespace MacVenture diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 871b10428e..9cba0502ce 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -33,6 +33,16 @@ namespace MacVenture { +// HACK, see below +void toASCII(Common::String &str) { + debug("toASCII: %s", str.c_str()); + Common::String::iterator it = str.begin(); + for (; it != str.end(); it++) { + if (*it == '\216') { str.replace(it, it + 1, "e"); } + if (*it == '\210') { str.replace(it, it + 1, "a"); } + } +} + enum { kMaxMenuTitleLength = 30 }; @@ -438,7 +448,10 @@ Common::String MacVentureEngine::getStartGameFileName() { char *fileName = new char[length + 1]; res->read(fileName, length); fileName[length] = '\0'; - return Common::String(fileName, length); + Common::String result = Common::String(fileName, length); + // HACK, see definition of toASCII + toASCII(result); + return result; } const GlobalSettings& MacVentureEngine::getGlobalSettings() const { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index b228a34713..6baaa31ac1 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -54,6 +54,9 @@ class ScriptEngine; typedef uint32 ObjID; +// HACK, until I find a way to translate correctly +extern void toASCII(Common::String &str); + enum { kScreenWidth = 512, kScreenHeight = 342 diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index ffb9d375ab..ff9eddc040 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -29,6 +29,8 @@ namespace MacVenture { +extern void toASCII(Common::String &str); + enum StringTableID { kErrorStringTableID = 0x80, kFilenamesStringTableID = 0x81, @@ -39,11 +41,11 @@ enum StringTableID { class StringTable { public: - StringTable(MacVentureEngine *engine, Common::MacResManager *resMan, StringTableID id) { + StringTable(MacVentureEngine *engine, Common::MacResManager *resMan, StringTableID id) { _engine = engine; _resourceManager = resMan; _id = id; - + if (!loadStrings()) error("Could not load string table %x", id); } @@ -80,8 +82,11 @@ private: char* str = new char[strLength + 1]; res->read(str, strLength); str[strLength] = '\0'; + // HACK until a proper special char implementation is found, this will have to do. + Common::String result = Common::String(str); + toASCII(result); debug(11, "Loaded string %s", str); - _strings.push_back(Common::String(str)); + _strings.push_back(Common::String(result)); delete[] str; } @@ -101,4 +106,3 @@ private: } // End of namespace MacVenture #endif - -- cgit v1.2.3 From 74ea29d0fa489f2fe903c06bdb935bf5f78eb69b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 28 Jul 2016 13:07:50 +0200 Subject: MACVENTURE: Add detection for Deja Vu II --- engines/macventure/detection.cpp | 1 + engines/macventure/detection_tables.h | 1 + 2 files changed, 2 insertions(+) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 597f859cee..85cbb11cae 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -42,6 +42,7 @@ namespace MacVenture { static const PlainGameDescriptor macventureGames[] = { { "shadowgate", "Shadowgate" }, { "deja_vu", "Deja Vu"}, + { "deja_vu2", "Deja Vu II"}, { 0, 0 } }; diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h index 0b55d03dd5..6ba51e0086 100644 --- a/engines/macventure/detection_tables.h +++ b/engines/macventure/detection_tables.h @@ -29,6 +29,7 @@ namespace MacVenture { static const ADGameDescription gameDescriptions[] = { BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "ebbfbcbf93938bd2900cb0c0213b19ad", 68974), // Zojoi Rerelease BASEGAME("deja_vu", "Zojoi Rerelease", "Deja Vu.bin", "5e9f5a8e3c8eb29ed02b34ae5937354f", 69034), // Zojoi Rerelease + BASEGAME("deja_vu2", "Zojoi Rerelease", "Lost in Las Vegas.bin", "8f8e1d8d41f577ee0fbc03847969af0d", 66520), // Zojoi Rerelease AD_TABLE_END_MARKER }; } // End of namespace MacVenture -- cgit v1.2.3 From b64622744f480b04dab9603fe0c09fb76e8e25b3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 12:21:35 +0200 Subject: MACVENTURE: Add infrastructure to support sound system --- engines/macventure/macventure.cpp | 82 ++++++++++++++++++++++++--------- engines/macventure/macventure.h | 21 ++++++++- engines/macventure/module.mk | 3 +- engines/macventure/script.cpp | 11 +++-- engines/macventure/sound.cpp | 95 +++++++++++++++++++++++++++++++++++++++ engines/macventure/sound.h | 85 +++++++++++++++++++++++++++++++++++ 6 files changed, 268 insertions(+), 29 deletions(-) create mode 100644 engines/macventure/sound.cpp create mode 100644 engines/macventure/sound.h diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 9cba0502ce..5d9d6f9938 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -54,6 +54,8 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD _debugger = NULL; _gui = NULL; + _soundManager = NULL; + debug("MacVenture::MacVentureEngine()"); } @@ -80,6 +82,9 @@ MacVentureEngine::~MacVentureEngine() { if (_textHuffman) delete _textHuffman; + + if (_soundManager) + delete _soundManager; } Common::Error MacVentureEngine::run() { @@ -112,6 +117,8 @@ Common::Error MacVentureEngine::run() { _world = new World(this, _resourceManager); _scriptEngine = new ScriptEngine(this, _world); + _soundManager = new SoundManager(this); + _paused = false; _halted = false; _cmdReady = false; @@ -314,26 +321,11 @@ void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, _textQueue.push_back(newText); } -bool MacVentureEngine::printTexts() { - for (uint i = 0; i < _textQueue.size(); i++) { - QueuedText text = _textQueue.front(); - _textQueue.remove_at(0); - switch (text.id) { - case kTextNumber: - _gui->printText(Common::String(text.asset)); - gameChanged(); - break; - case kTextNewLine: - _gui->printText(Common::String("")); - gameChanged(); - break; - case kTextPlain: - _gui->printText(_world->getText(text.asset, text.source, text.destination)); - gameChanged(); - break; - } - } - return false; +void MacVentureEngine::enqueueSound(SoundQueueID type, ObjID target) { + QueuedSound newSound; + newSound.id = type; + newSound.reference = target; + _soundQueue.push_back(newSound); } void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick) { @@ -529,6 +521,8 @@ void MacVentureEngine::endGame() { bool MacVentureEngine::updateState() { runObjQueue(); bool wait = printTexts(); + // HACK playSounds should accept a bool passed to updateState + wait |= playSounds(true); return wait; } @@ -581,6 +575,54 @@ void MacVentureEngine::runObjQueue() { } } +bool MacVentureEngine::printTexts() { + for (uint i = 0; i < _textQueue.size(); i++) { + QueuedText text = _textQueue.front(); + _textQueue.remove_at(0); + switch (text.id) { + case kTextNumber: + _gui->printText(Common::String(text.asset)); + gameChanged(); + break; + case kTextNewLine: + _gui->printText(Common::String("")); + gameChanged(); + break; + case kTextPlain: + _gui->printText(_world->getText(text.asset, text.source, text.destination)); + gameChanged(); + break; + } + } + return false; +} + +bool MacVentureEngine::playSounds(bool pause) { + int delay=0; + while (!_soundQueue.empty()) { + QueuedSound item = _soundQueue.front(); + _soundQueue.remove_at(0); + switch (item.id) { + case kSoundPlay: + _soundManager->playSound(item.reference); + break; + case kSoundPlayAndWait: + delay = _soundManager->playSound(item.reference); + break; + case kSoundWait: + //wait for sound to finish? + break; + } + } + if (pause && delay > 0) { + warning("Sound pausing not yet tested. Pausing for %d", delay * 1000); + g_system->delayMillis(delay * 1000); + preparedToRun(); + return true; + } + return false; +} + void MacVentureEngine::updateControls() { if (_activeControl) _activeControl = kNoCommand; diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 6baaa31ac1..28eb8e42ff 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -41,6 +41,7 @@ #include "macventure/script.h" #include "macventure/controls.h" #include "macventure/windows.h" +#include "macventure/sound.h" struct ADGameDescription; @@ -52,6 +53,8 @@ class Console; class World; class ScriptEngine; +class SoundManager; + typedef uint32 ObjID; // HACK, until I find a way to translate correctly @@ -161,6 +164,17 @@ struct QueuedText { ObjID asset; }; +enum SoundQueueID { + kSoundPlay = 1, + kSoundPlayAndWait = 2, + kSoundWait = 3 +}; + +struct QueuedSound { + SoundQueueID id; + ObjID reference; +}; + class MacVentureEngine : public Engine { public: @@ -191,9 +205,11 @@ public: void enqueueObject(ObjectQueueID type, ObjID objID, ObjID target = 0); void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text); + void enqueueSound(SoundQueueID type, ObjID target); void runObjQueue(); bool printTexts(); + bool playSounds(bool pause); void handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick); void handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent); @@ -205,7 +221,6 @@ public: void setTextInput(Common::String content); Common::String getUserInput(); - // Data retrieval Common::String getStartGameFileName(); bool isPaused(); @@ -296,6 +311,8 @@ private: // Attributes StringTable *_decodingNamingArticles; StringTable *_decodingIndirectArticles; + SoundManager *_soundManager; + // Engine state GameState _gameState; GlobalSettings _globalSettings; @@ -308,7 +325,7 @@ private: // Attributes Common::Array _objQueue; Common::Array _inQueue; - Common::Array _soundQueue; + Common::Array _soundQueue; Common::Array _textQueue; // Selections diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 48c8930520..a1e2f5ef71 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -12,7 +12,8 @@ MODULE_OBJS := \ dialog.o \ controls.o \ prebuilt_dialogs.o \ - windows.o + windows.o \ + sound.o MODULE_DIRS += \ diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 51bfa3382b..55bb4063bd 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -32,7 +32,6 @@ namespace MacVenture { ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { _engine = engine; _world = world; - // HACK _scripts = new Container(_engine->getFilePath(kFilterPathID)); } @@ -989,17 +988,17 @@ void ScriptEngine::opc6P2(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opc7PLBG(EngineState * state, EngineFrame * frame) { - state->pop(); - op00NOOP(0xc7); + word target = state->pop(); + _engine->enqueueSound(kSoundPlay, target); } void ScriptEngine::opc8PLAW(EngineState * state, EngineFrame * frame) { - state->pop(); - op00NOOP(0xc8); + word target = state->pop(); + _engine->enqueueSound(kSoundPlayAndWait, target); } void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { - op00NOOP(0xc9); + _engine->enqueueSound(kSoundWait, 0); } void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp new file mode 100644 index 0000000000..2addb1932b --- /dev/null +++ b/engines/macventure/sound.cpp @@ -0,0 +1,95 @@ +/* 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 "macventure/sound.h" + +namespace MacVenture { + +SoundAsset::SoundAsset(Container *container, ObjID id) : + _container(container), _id(id) { + + //TODO Decode the sound + if (_container->getItemByteSize(_id) == 0) + warning("Trying to load an empty sound asset."); + + Common::SeekableReadStream *stream = _container->getItem(_id); + + stream->seek(5, SEEK_SET); + SoundType type = (SoundType)stream->readByte(); + + switch(type) { + case kSound10: + decode10(stream); + break; + default: + warning("Unrecognized sound type: %x", type); + } + + delete stream; +} + +SoundAsset::~SoundAsset() {} + +void SoundAsset::play() { + //TODO: Play song + warning("SoundAsset::play() not yet implemented"); +} + +uint32 SoundAsset::getPlayLength() { + return _length / _frequency; +} + +void SoundAsset::decode10(Common::SeekableReadStream *stream) { + //TODO: Decode 10 + debug("Decoding sound type 10"); +} + +// SoundManager +SoundManager::SoundManager(MacVentureEngine *engine) { + _container = nullptr; + Common::String filename = engine->getFilePath(kSoundPathID); + _container = new Container(filename); + debug("Created sound manager with file %s", filename.c_str()); +} + +SoundManager::~SoundManager(){ + if (_container) + delete _container; + + Common::HashMap::iterator it; + for (it = _assets.begin(); it != _assets.end(); it++) { + delete it->_value; + } +} + +uint32 SoundManager::playSound(ObjID sound) { + ensureLoaded(sound); + _assets[sound]->play(); + return _assets[sound]->getPlayLength(); +} + +void SoundManager::ensureLoaded(ObjID sound) { + if (!_assets.contains(sound)) + _assets[sound] = new SoundAsset(_container, sound); +} + +} //End of namespace MacVenture diff --git a/engines/macventure/sound.h b/engines/macventure/sound.h new file mode 100644 index 0000000000..3c7a68fc2b --- /dev/null +++ b/engines/macventure/sound.h @@ -0,0 +1,85 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_SOUND_H +#define MACVENTURE_SOUND_H + +#include "macventure/macventure.h" +#include "macventure/container.h" + +#include "common/file.h" +#include "common/hashmap.h" + +namespace MacVenture { + +enum SoundType { + kSound10 = 0x10, + kSound12 = 0x12, + kSound18 = 0x18, + kSound1a = 0x1a, + kSound44 = 0x44, + kSound78 = 0x78, + kSound7e = 0x7e +}; + +class SoundAsset { + +public: + SoundAsset(Container *container, ObjID id); + ~SoundAsset(); + + void play(); + uint32 getPlayLength(); + +private: + + void decode10(Common::SeekableReadStream *stream); + +private: + + Container *_container; + ObjID _id; + + Common::Array _data; + uint32 _length; + uint32 _frequency; +}; + +class SoundManager { +public: + SoundManager(MacVentureEngine *engine); + ~SoundManager(); + + uint32 playSound(ObjID sound); + +private: + void ensureLoaded(ObjID sound); + +private: + + Container *_container; + Common::HashMap _assets; + +}; +} // End of namespace MacVenture + +#endif -- cgit v1.2.3 From 2ff5dad423efd34085876dd8acb6b68046751aed Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 12:53:31 +0200 Subject: MACVENTURE: Add decoding for 0x10 and 0x7e sounds --- engines/macventure/sound.cpp | 44 ++++++++++++++++++++++++++++++++++++++++---- engines/macventure/sound.h | 1 + 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 2addb1932b..fe4637e703 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -35,11 +35,14 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : stream->seek(5, SEEK_SET); SoundType type = (SoundType)stream->readByte(); - + debug(2, "Decoding sound of type %x", type); switch(type) { case kSound10: decode10(stream); break; + case kSound7e: + decode7e(stream); + break; default: warning("Unrecognized sound type: %x", type); } @@ -59,8 +62,41 @@ uint32 SoundAsset::getPlayLength() { } void SoundAsset::decode10(Common::SeekableReadStream *stream) { - //TODO: Decode 10 - debug("Decoding sound type 10"); + Common::Array wavtable; + stream->seek(0x198, SEEK_SET); + for (int i = 0; i < 16; i++) { + wavtable.push_back(stream->readByte()); + } + _length = stream->readUint32BE() * 2; + //Unused + stream->readUint16BE(); + _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + byte ch = 0; + for (int i = 0; i < _length; i++) { + if (i & 1) ch >>= 4; + else ch = stream->readByte(); + _data.push_back(wavtable[ch & 0xf]); + } +} + +void SoundAsset::decode7e(Common::SeekableReadStream *stream) { + Common::Array wavtable; + stream->seek(0xc2, SEEK_SET); + for (int i = 0; i < 16; i++) { + wavtable.push_back(stream->readByte()); + } + //Unused + stream->readUint32BE(); + _length = stream->readUint32BE(); + _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + uint32 last=0x80; + byte ch = 0; + for (int i = 0; i < _length; i++) { + if (i & 1) ch <<= 4; + else ch = stream->readByte(); + last += wavtable[(ch >> 4) & 0xf]; + _data.push_back(last & 0xff); + } } // SoundManager @@ -68,7 +104,7 @@ SoundManager::SoundManager(MacVentureEngine *engine) { _container = nullptr; Common::String filename = engine->getFilePath(kSoundPathID); _container = new Container(filename); - debug("Created sound manager with file %s", filename.c_str()); + debug(1, "Created sound manager with file %s", filename.c_str()); } SoundManager::~SoundManager(){ diff --git a/engines/macventure/sound.h b/engines/macventure/sound.h index 3c7a68fc2b..d3fb1360a3 100644 --- a/engines/macventure/sound.h +++ b/engines/macventure/sound.h @@ -53,6 +53,7 @@ public: private: void decode10(Common::SeekableReadStream *stream); + void decode7e(Common::SeekableReadStream *stream); private: -- cgit v1.2.3 From f5338f4beb5069ebfbab1d09e8a839e65eeaf8a7 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 13:40:30 +0200 Subject: MACVENTURE: Add decoding for the rest of the sounds --- engines/macventure/sound.cpp | 130 +++++++++++++++++++++++++++++++++++++++++-- engines/macventure/sound.h | 5 ++ 2 files changed, 131 insertions(+), 4 deletions(-) diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index fe4637e703..f7fb0b5a17 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -40,6 +40,21 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : case kSound10: decode10(stream); break; + case kSound12: + decode12(stream); + break; + case kSound18: + decode18(stream); + break; + case kSound1a: + decode1a(stream); + break; + case kSound44: + decode44(stream); + break; + case kSound78: + decode78(stream); + break; case kSound7e: decode7e(stream); break; @@ -62,9 +77,68 @@ uint32 SoundAsset::getPlayLength() { } void SoundAsset::decode10(Common::SeekableReadStream *stream) { + warning("Decode sound 0x10 untested"); Common::Array wavtable; stream->seek(0x198, SEEK_SET); - for (int i = 0; i < 16; i++) { + for (uint i = 0; i < 16; i++) { + wavtable.push_back(stream->readByte()); + } + _length = stream->readUint32BE() * 2; + //Unused + stream->readUint16BE(); + _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + byte ch = 0; + for (uint i = 0; i < _length; i++) { + if (i & 1) ch >>= 4; + else ch = stream->readByte(); + _data.push_back(wavtable[ch & 0xf]); + } +} + +void SoundAsset::decode12(Common::SeekableReadStream *stream) { + warning("Decode sound 0x12 untested"); + stream->seek(0xc, SEEK_SET); + uint32 repeat = stream->readUint16BE(); + stream->seek(0x34, SEEK_SET); + uint32 base = stream->readUint16BE() + 0x34; + stream->seek(base, SEEK_SET); + _length = stream->readUint32BE() - 6; + stream->readUint16BE(); + _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + stream->seek(0xe2, SEEK_SET); + // TODO: Possible source of bugs, the original just assigns the seek to the scales + uint32 scales = stream->pos() + 0xe2; + for (uint i = 0; i < repeat; i++) { + stream->seek(scales + i * 2, SEEK_SET); + uint32 scale = stream->readUint16BE(); + stream->seek(base + 0xa, SEEK_SET); + for (uint j = 0; j < _length; j++) { + byte ch = stream->readByte(); + if (ch & 0x80) { + ch -= 0x80; + uint32 env= ch * scale; + ch = (env >> 8) & 0xff; + if (ch & 0x80) ch = 0x7f; + ch += 0x80; + } else { + ch = (ch ^ 0xff) + 1; + ch -= 0x80; + uint32 env = ch * scale; + ch = (env >> 8) & 0xff; + if (ch & 0x80) ch = 0x7f; + ch += 0x80; + ch = (ch ^ 0xff) + 1; + } + _data.push_back(ch); + } + } +} + +void SoundAsset::decode18(Common::SeekableReadStream *stream) { + warning("Decode sound 0x18 untested"); + Common::Array wavtable; + stream->seek(0x252, SEEK_SET); + for (uint i = 0; i < 16; i++) { wavtable.push_back(stream->readByte()); } _length = stream->readUint32BE() * 2; @@ -72,17 +146,65 @@ void SoundAsset::decode10(Common::SeekableReadStream *stream) { stream->readUint16BE(); _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; byte ch = 0; - for (int i = 0; i < _length; i++) { + for (uint i = 0; i < _length; i++) { + if (i & 1) ch >>= 4; + else ch = stream->readByte(); + _data.push_back(wavtable[ch & 0xf]); + } +} + +void SoundAsset::decode1a(Common::SeekableReadStream *stream) { + warning("Decode sound 0x1a untested"); + Common::Array wavtable; + stream->seek(0x220, SEEK_SET); + for (uint i = 0; i < 16; i++) { + wavtable.push_back(stream->readByte()); + } + _length = stream->readUint32BE(); + //Unused + stream->readUint16BE(); + _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + byte ch = 0; + for (uint i = 0; i < _length; i++) { if (i & 1) ch >>= 4; else ch = stream->readByte(); _data.push_back(wavtable[ch & 0xf]); } } +void SoundAsset::decode44(Common::SeekableReadStream *stream) { + warning("Decode sound 0x44 untested"); + stream->seek(0x5e, SEEK_SET); + _length = stream->readUint32BE(); + _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + for (uint i = 0; i < _length; i++) { + _data.push_back(stream->readByte()); + } +} + +void SoundAsset::decode78(Common::SeekableReadStream *stream) { + warning("Decode sound 0x78 untested"); + Common::Array wavtable; + stream->seek(0xba, SEEK_SET); + for (uint i = 0; i < 16; i++) { + wavtable.push_back(stream->readByte()); + } + //Unused + stream->readUint32BE(); + _length = stream->readUint32BE(); + _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + byte ch = 0; + for (uint i = 0; i < _length; i++) { + if (i & 1) ch <<= 4; + else ch = stream->readByte(); + _data.push_back(wavtable[(ch >> 4) & 0xf]); + } +} + void SoundAsset::decode7e(Common::SeekableReadStream *stream) { Common::Array wavtable; stream->seek(0xc2, SEEK_SET); - for (int i = 0; i < 16; i++) { + for (uint i = 0; i < 16; i++) { wavtable.push_back(stream->readByte()); } //Unused @@ -91,7 +213,7 @@ void SoundAsset::decode7e(Common::SeekableReadStream *stream) { _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; uint32 last=0x80; byte ch = 0; - for (int i = 0; i < _length; i++) { + for (uint i = 0; i < _length; i++) { if (i & 1) ch <<= 4; else ch = stream->readByte(); last += wavtable[(ch >> 4) & 0xf]; diff --git a/engines/macventure/sound.h b/engines/macventure/sound.h index d3fb1360a3..58fc650b00 100644 --- a/engines/macventure/sound.h +++ b/engines/macventure/sound.h @@ -53,6 +53,11 @@ public: private: void decode10(Common::SeekableReadStream *stream); + void decode12(Common::SeekableReadStream *stream); + void decode18(Common::SeekableReadStream *stream); + void decode1a(Common::SeekableReadStream *stream); + void decode44(Common::SeekableReadStream *stream); + void decode78(Common::SeekableReadStream *stream); void decode7e(Common::SeekableReadStream *stream); private: -- cgit v1.2.3 From 842bff03e0fd949bcac1b3fd4c281d3fc5547ca5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 13:43:35 +0200 Subject: MACVENTURE: Implement missing instruction --- engines/macventure/script.cpp | 7 ++++--- engines/macventure/script.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 55bb4063bd..6f0a7820b3 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -453,7 +453,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opdbROBQ(state, frame); break; case 0xdc: //run sound queue - opdcRSQ(state, frame); + if (opdcRSQ(state, frame)) + return true; break; case 0xdd: //run text queue opddRTQ(state, frame); @@ -1109,8 +1110,8 @@ void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { _engine->runObjQueue(); } -void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { - op00NOOP(0xdc); +bool ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { + return _engine->playSounds(true); } void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 5760a31e8a..7c4b77df75 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -257,7 +257,7 @@ private: void opd9SLEEP(EngineState *state, EngineFrame *frame); //sleep void opdaCLICK(EngineState *state, EngineFrame *frame); //click to continue void opdbROBQ(EngineState *state, EngineFrame *frame); //run queue - void opdcRSQ(EngineState *state, EngineFrame *frame); //run sound queue + bool opdcRSQ(EngineState *state, EngineFrame *frame); //run sound queue void opddRTQ(EngineState *state, EngineFrame *frame); //run text queue void opdeUPSC(EngineState *state, EngineFrame *frame); //update screen void opdfFMAI(EngineState *state, EngineFrame *frame); //flash main window -- cgit v1.2.3 From dd2908fe42d54037436e7b3a05bc275d11822a93 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 17:19:29 +0200 Subject: MACVENTURE: Add basic audio playback --- engines/macventure/macventure.cpp | 2 +- engines/macventure/sound.cpp | 70 +++++++++++++++++++++------------------ engines/macventure/sound.h | 8 +++-- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 5d9d6f9938..21d98b1601 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -117,7 +117,7 @@ Common::Error MacVentureEngine::run() { _world = new World(this, _resourceManager); _scriptEngine = new ScriptEngine(this, _world); - _soundManager = new SoundManager(this); + _soundManager = new SoundManager(this, _mixer); _paused = false; _halted = false; diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index f7fb0b5a17..7eca8b4e8a 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -22,12 +22,45 @@ #include "macventure/sound.h" +#include "audio/mixer.h" +#include "audio/audiostream.h" +#include "audio/decoders/raw.h" + namespace MacVenture { +// SoundManager +SoundManager::SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer) { + _container = nullptr; + Common::String filename = engine->getFilePath(kSoundPathID); + _container = new Container(filename); + _mixer = mixer; + debug(1, "Created sound manager with file %s", filename.c_str()); +} + +SoundManager::~SoundManager(){ + if (_container) + delete _container; + + Common::HashMap::iterator it; + for (it = _assets.begin(); it != _assets.end(); it++) { + delete it->_value; + } +} + +uint32 SoundManager::playSound(ObjID sound) { + ensureLoaded(sound); + _assets[sound]->play(_mixer, &_handle); + return _assets[sound]->getPlayLength(); +} + +void SoundManager::ensureLoaded(ObjID sound) { + if (!_assets.contains(sound)) + _assets[sound] = new SoundAsset(_container, sound); +} + SoundAsset::SoundAsset(Container *container, ObjID id) : _container(container), _id(id) { - //TODO Decode the sound if (_container->getItemByteSize(_id) == 0) warning("Trying to load an empty sound asset."); @@ -67,9 +100,9 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : SoundAsset::~SoundAsset() {} -void SoundAsset::play() { - //TODO: Play song - warning("SoundAsset::play() not yet implemented"); +void SoundAsset::play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle) { + Audio::AudioStream *sound = Audio::makeRawStream(&_data.front(), _length, _frequency, Audio::FLAG_UNSIGNED); + mixer->playStream(Audio::Mixer::kPlainSoundType, soundHandle, sound); } uint32 SoundAsset::getPlayLength() { @@ -221,33 +254,4 @@ void SoundAsset::decode7e(Common::SeekableReadStream *stream) { } } -// SoundManager -SoundManager::SoundManager(MacVentureEngine *engine) { - _container = nullptr; - Common::String filename = engine->getFilePath(kSoundPathID); - _container = new Container(filename); - debug(1, "Created sound manager with file %s", filename.c_str()); -} - -SoundManager::~SoundManager(){ - if (_container) - delete _container; - - Common::HashMap::iterator it; - for (it = _assets.begin(); it != _assets.end(); it++) { - delete it->_value; - } -} - -uint32 SoundManager::playSound(ObjID sound) { - ensureLoaded(sound); - _assets[sound]->play(); - return _assets[sound]->getPlayLength(); -} - -void SoundManager::ensureLoaded(ObjID sound) { - if (!_assets.contains(sound)) - _assets[sound] = new SoundAsset(_container, sound); -} - } //End of namespace MacVenture diff --git a/engines/macventure/sound.h b/engines/macventure/sound.h index 58fc650b00..d1b1bb8a37 100644 --- a/engines/macventure/sound.h +++ b/engines/macventure/sound.h @@ -29,6 +29,8 @@ #include "common/file.h" #include "common/hashmap.h" +#include "audio/mixer.h" + namespace MacVenture { enum SoundType { @@ -47,7 +49,7 @@ public: SoundAsset(Container *container, ObjID id); ~SoundAsset(); - void play(); + void play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle); uint32 getPlayLength(); private: @@ -72,7 +74,7 @@ private: class SoundManager { public: - SoundManager(MacVentureEngine *engine); + SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer); ~SoundManager(); uint32 playSound(ObjID sound); @@ -84,6 +86,8 @@ private: Container *_container; Common::HashMap _assets; + Audio::SoundHandle _handle; + Audio::Mixer *_mixer; }; } // End of namespace MacVenture -- cgit v1.2.3 From 90b022c07834d13c0ceacadad09d35ff0ea193b3 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 1 Aug 2016 18:10:17 +0200 Subject: MACVENTURE: Test some sound decodings --- engines/macventure/sound.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 7eca8b4e8a..97fe3c6132 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -206,7 +206,6 @@ void SoundAsset::decode1a(Common::SeekableReadStream *stream) { } void SoundAsset::decode44(Common::SeekableReadStream *stream) { - warning("Decode sound 0x44 untested"); stream->seek(0x5e, SEEK_SET); _length = stream->readUint32BE(); _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; @@ -216,7 +215,6 @@ void SoundAsset::decode44(Common::SeekableReadStream *stream) { } void SoundAsset::decode78(Common::SeekableReadStream *stream) { - warning("Decode sound 0x78 untested"); Common::Array wavtable; stream->seek(0xba, SEEK_SET); for (uint i = 0; i < 16; i++) { -- cgit v1.2.3 From b7b4862e4c93898e5a315c672e52df0ea1894cc6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 2 Aug 2016 12:00:07 +0200 Subject: MACVENTURE: Add metadata to savegames --- engines/macventure/detection.cpp | 56 +++++++++++++++++++++--- engines/macventure/macventure.cpp | 15 ------- engines/macventure/module.mk | 3 +- engines/macventure/saveload.cpp | 89 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 21 deletions(-) create mode 100644 engines/macventure/saveload.cpp diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 85cbb11cae..64a7923f04 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -29,10 +29,9 @@ namespace MacVenture { - const char *MacVentureEngine::getGameFileName() const { - return _gameDescription->filesDescriptions[0].fileName; - } - +const char *MacVentureEngine::getGameFileName() const { + return _gameDescription->filesDescriptions[0].fileName; +} } namespace MacVenture { @@ -46,6 +45,8 @@ static const PlainGameDescriptor macventureGames[] = { { 0, 0 } }; +SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot); + class MacVentureMetaEngine : public AdvancedMetaEngine { public: MacVentureMetaEngine() : AdvancedMetaEngine(MacVenture::gameDescriptions, sizeof(ADGameDescription), macventureGames) { @@ -62,12 +63,57 @@ public: virtual bool createInstance(OSystem * syst, Engine ** engine, const ADGameDescription * desc) const; virtual bool hasFeature(MetaEngineFeature f) const; + virtual SaveStateList listSaves(const char *target) const; + virtual int getMaximumSaveSlot() const; }; bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { - return false; + return + (f == kSupportsListSaves) || + (f == kSupportsLoadingDuringStartup); } +SaveStateList MacVentureMetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".###"; + + filenames = saveFileMan->listSavefiles(pattern); + + SaveStateList saveList; + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + int slotNum = atoi(file->c_str() + file->size() - 3); + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); + + SaveStateDescriptor desc; + // Do not allow save slot 0 (used for auto-saving) to be deleted or + // overwritten. + desc.setDeletableFlag(slotNum != 0); + desc.setWriteProtectedFlag(slotNum == 0); + + if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) { + Common::InSaveFile *in = saveFileMan->openForLoading(*file); + if (in) { + SaveStateDescriptor desc = loadMetaData(in, slotNum); + if (desc.getSaveSlot() != slotNum) { + // invalid + delete in; + continue; + } + saveList.push_back(desc); + delete in; + } + } + } + + // Sort saves based on slot number. + Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); + return saveList; +} + +int MacVentureMetaEngine::getMaximumSaveSlot() const { return 999; } + bool MacVentureMetaEngine::createInstance(OSystem * syst, Engine ** engine, const ADGameDescription *game) const { if (game) { *engine = new MacVentureEngine(syst, game); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 21d98b1601..6a7c1474a8 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -178,21 +178,6 @@ Common::Error MacVentureEngine::run() { return Common::kNoError; } -Common::Error MacVentureEngine::loadGameState(int slot) { - Common::InSaveFile *file = getSaveFileManager()->openForLoading("Shadowgate.1"); - _world->loadGameFrom(file); - reset(); - return Common::kNoError; -} - -Common::Error MacVentureEngine::saveGameState(int slot, const Common::String &desc) { - Common::SaveFileManager *manager = getSaveFileManager(); - // HACK Get a real name! - Common::OutSaveFile *file = manager->openForSaving("Shadowgate.1"); - _world->saveGameInto(file); - delete file; -} - void MacVentureEngine::reset() { resetInternals(); resetGui(); diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index a1e2f5ef71..244401b4a6 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -13,7 +13,8 @@ MODULE_OBJS := \ controls.o \ prebuilt_dialogs.o \ windows.o \ - sound.o + sound.o \ + saveload.o MODULE_DIRS += \ diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp new file mode 100644 index 0000000000..a256713b24 --- /dev/null +++ b/engines/macventure/saveload.cpp @@ -0,0 +1,89 @@ +/* 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 "macventure/macventure.h" + +#include "common/error.h" +#include "common/savefile.h" +#include "engines/savestate.h" + +namespace MacVenture { + +#define MACVENTURE_SAVE_HEADER MKTAG('M', 'V', 'S', 'S') // (M)ac(V)enture (S)cummVM (S)ave (0x4d565353, uint32) +#define MACVENTURE_SAVE_VERSION 1 //1 BYTE +#define MACVENTURE_DESC_LENGTH 1 //1 BYTE for the description length + +SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { + // Metadata is stored at the end of the file + // |DESCRIPTION | + // |HEADER |VERSION|DESCLEN| + s->seek(-(5 + MACVENTURE_DESC_LENGTH), SEEK_END); + uint32 sig = s->readUint32BE(); + byte version = s->readByte(); + + SaveStateDescriptor desc(-1, ""); // init to an invalid save slot + + if (sig != MACVENTURE_SAVE_HEADER || version > MACVENTURE_SAVE_VERSION) + return desc; + + // Save is valid, set its slot number + desc.setSaveSlot(slot); + + // Load the description + Common::String name; + // Depends on MACVENTURE_DESC_LENGTH + byte descSize = s->readByte(); + s->seek(-(5 + MACVENTURE_DESC_LENGTH + descSize), SEEK_END); + for (int i = 0; i < descSize; ++i) + name += s->readByte(); + desc.setDescription(name); + + return desc; +} + +void writeMetaData(Common::OutSaveFile *file, Common::String desc) { + if (desc.size() >= (1 << (MACVENTURE_DESC_LENGTH * 4))) { + desc.erase((1 << (MACVENTURE_DESC_LENGTH * 4)) - 1); + } + file->writeString(desc); + file->writeUint32BE(MACVENTURE_SAVE_HEADER); + file->writeByte(MACVENTURE_SAVE_VERSION); + file->writeByte(desc.size()); +} + +Common::Error MacVentureEngine::loadGameState(int slot) { + Common::InSaveFile *file = getSaveFileManager()->openForLoading("shadowgate.001"); + _world->loadGameFrom(file); + reset(); + return Common::kNoError; +} + +Common::Error MacVentureEngine::saveGameState(int slot, const Common::String &desc) { + Common::SaveFileManager *manager = getSaveFileManager(); + // HACK Get a real name! + Common::OutSaveFile *file = manager->openForSaving(desc); + _world->saveGameInto(file); + writeMetaData(file, desc); + delete file; +} + +} // End of namespace MacVenture -- cgit v1.2.3 From 9ab6ce04a11de0bf5f56a7866a4837c7431cefbe Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 2 Aug 2016 13:01:35 +0200 Subject: MACVENTURE: Change GUI to accept ScummVM dialogs --- engines/macventure/detection.cpp | 17 +++++++++------ engines/macventure/dialog.h | 2 +- engines/macventure/gui.cpp | 6 ++--- engines/macventure/gui.h | 2 ++ engines/macventure/macventure.h | 4 ++++ engines/macventure/prebuilt_dialogs.h | 2 +- engines/macventure/saveload.cpp | 41 +++++++++++++++++++++++++++++++++-- 7 files changed, 60 insertions(+), 14 deletions(-) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 64a7923f04..082a8acc65 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -32,9 +32,7 @@ namespace MacVenture { const char *MacVentureEngine::getGameFileName() const { return _gameDescription->filesDescriptions[0].fileName; } -} - -namespace MacVenture { +} // End of namespace MacVenture #include "macventure/detection_tables.h" @@ -45,6 +43,8 @@ static const PlainGameDescriptor macventureGames[] = { { 0, 0 } }; +namespace MacVenture { + SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot); class MacVentureMetaEngine : public AdvancedMetaEngine { @@ -73,6 +73,12 @@ bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { (f == kSupportsLoadingDuringStartup); } +bool MacVentureEngine::hasFeature(EngineFeature f) const { + return + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); +} + SaveStateList MacVentureMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; @@ -116,14 +122,11 @@ int MacVentureMetaEngine::getMaximumSaveSlot() const { return 999; } bool MacVentureMetaEngine::createInstance(OSystem * syst, Engine ** engine, const ADGameDescription *game) const { if (game) { - *engine = new MacVentureEngine(syst, game); + *engine = new MacVenture::MacVentureEngine(syst, game); } return game != 0; } - - - } // End of namespace MacVenture #if PLUGIN_ENABLED_DYNAMIC(MACVENTURE) diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index d40639a2d3..a01011f2b8 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -39,7 +39,7 @@ extern PrebuiltDialog prebuiltDialogs[]; class Dialog { public: Dialog(Gui *gui, Common::Point pos, uint width, uint height); - Dialog(Gui *gui, PrebuiltDialogs prebuilt); + Dialog(Gui *gui, PrebuiltDialogs prebuilt); ~Dialog(); diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 7691b56697..d615493b60 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1081,15 +1081,15 @@ void Gui::handleMenuAction(MenuAction action) { break; case MacVenture::kMenuActionOpen: debug("MacVenture Menu Action: Open"); - loadGame(0); + _engine->scummVMSaveLoadDialog(false); break; case MacVenture::kMenuActionSave: debug("MacVenture Menu Action: Save"); - saveInto(0); + _engine->scummVMSaveLoadDialog(true); break; case MacVenture::kMenuActionSaveAs: debug("MacVenture Menu Action: Save As"); - showPrebuiltDialog(kSaveAsDialog); + _engine->scummVMSaveLoadDialog(true); break; case MacVenture::kMenuActionQuit: debug("MacVenture Menu Action: Quit"); diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 8b0cbc6a6b..31cacd76ef 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -156,6 +156,8 @@ public: void setTextInput(Common::String str); void closeDialog(); + + // TODO: Currently unused, we are using ScummVM dialogs instead. void loadGame(int slot); void saveInto(int slot); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 28eb8e42ff..3e6f7c02ce 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -181,7 +181,11 @@ public: MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc); ~MacVentureEngine(); + virtual bool hasFeature(EngineFeature f) const; + virtual Common::Error run(); + + bool scummVMSaveLoadDialog(bool isSave); virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 1e708dbb67..58e8f0b823 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -35,7 +35,7 @@ enum DialogAction { }; enum PrebuiltDialogs { - kSaveAsDialog = 0, + kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead. kSpeakDialog = 1, kPrebuiltDialogCount }; diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index a256713b24..e1b6227851 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -25,6 +25,7 @@ #include "common/error.h" #include "common/savefile.h" #include "engines/savestate.h" +#include "gui/saveload.h" namespace MacVenture { @@ -71,19 +72,55 @@ void writeMetaData(Common::OutSaveFile *file, Common::String desc) { } Common::Error MacVentureEngine::loadGameState(int slot) { - Common::InSaveFile *file = getSaveFileManager()->openForLoading("shadowgate.001"); + Common::String saveFileName = Common::String::format("%s.%03d", _targetName.c_str(), slot); + Common::InSaveFile *file; + if(!(file = getSaveFileManager()->openForLoading(saveFileName))) { + error("missing savegame file %s", saveFileName.c_str()); + } _world->loadGameFrom(file); reset(); return Common::kNoError; } Common::Error MacVentureEngine::saveGameState(int slot, const Common::String &desc) { + Common::String saveFileName = Common::String::format("%s.%03d", _targetName.c_str(), slot); Common::SaveFileManager *manager = getSaveFileManager(); // HACK Get a real name! - Common::OutSaveFile *file = manager->openForSaving(desc); + Common::OutSaveFile *file = manager->openForSaving(saveFileName); _world->saveGameInto(file); writeMetaData(file, desc); delete file; } +bool MacVentureEngine::scummVMSaveLoadDialog(bool isSave) { + if (!isSave) { + // do loading + GUI::SaveLoadChooser dialog = GUI::SaveLoadChooser(Common::String("Load game:"), Common::String("Load"), false); + int slot = dialog.runModalWithCurrentTarget(); + + if (slot < 0) + return true; + + return loadGameState(slot).getCode() == Common::kNoError; + } + + // do saving + GUI::SaveLoadChooser dialog = GUI::SaveLoadChooser(Common::String("Save game:"), Common::String("Save"), true); + int slot = dialog.runModalWithCurrentTarget(); + Common::String desc = dialog.getResultString(); + + if (desc.empty()) { + // create our own description for the saved game, the user didnt enter it + desc = dialog.createDefaultSaveDescription(slot); + } + + if (desc.size() > (1 << MACVENTURE_DESC_LENGTH * 4) - 1) + desc = Common::String(desc.c_str(), (1 << MACVENTURE_DESC_LENGTH * 4) - 1); + + if (slot < 0) + return true; + + return saveGameState(slot, desc).getCode() == Common::kNoError; +} + } // End of namespace MacVenture -- cgit v1.2.3 From 0acdf0c459eaf96c0b181cd3a6a94ba58a97475b Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 2 Aug 2016 13:15:43 +0200 Subject: MACVENTURE: Implement savefile deletion --- engines/macventure/detection.cpp | 8 +++++++- engines/macventure/saveload.cpp | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 082a8acc65..f4edaefa40 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -65,12 +65,14 @@ public: virtual bool hasFeature(MetaEngineFeature f) const; virtual SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; + virtual void removeSaveState(const char *target, int slot) const; }; bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { return (f == kSupportsListSaves) || - (f == kSupportsLoadingDuringStartup); + (f == kSupportsLoadingDuringStartup) || + (f == kSupportsDeleteSave); } bool MacVentureEngine::hasFeature(EngineFeature f) const { @@ -127,6 +129,10 @@ bool MacVentureMetaEngine::createInstance(OSystem * syst, Engine ** engine, cons return game != 0; } +void MacVentureMetaEngine::removeSaveState(const char *target, int slot) const { + g_system->getSavefileManager()->removeSavefile(Common::String::format("%s.%03d", target, slot)); +} + } // End of namespace MacVenture #if PLUGIN_ENABLED_DYNAMIC(MACVENTURE) diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index e1b6227851..1322a43510 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -89,6 +89,11 @@ Common::Error MacVentureEngine::saveGameState(int slot, const Common::String &de Common::OutSaveFile *file = manager->openForSaving(saveFileName); _world->saveGameInto(file); writeMetaData(file, desc); + + file->finalize(); + if (file->err()) { + warning("Could not save '%s' correctly.", saveFileName.c_str()); + } delete file; } -- cgit v1.2.3 From f0dde375c13a262d5d71cdf74114b64754fa0755 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 2 Aug 2016 13:29:23 +0200 Subject: MACVENTURE: Add missing methods for runtime load --- engines/macventure/detection.cpp | 1 + engines/macventure/macventure.h | 2 ++ engines/macventure/saveload.cpp | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index f4edaefa40..9bf94cfdd4 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -77,6 +77,7 @@ bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { bool MacVentureEngine::hasFeature(EngineFeature f) const { return + (f == kSupportsRTL) || (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime); } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 3e6f7c02ce..b4f8192ed7 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -186,6 +186,8 @@ public: virtual Common::Error run(); bool scummVMSaveLoadDialog(bool isSave); + bool canLoadGameStateCurrently(); + bool canSaveGameStateCurrently(); virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index 1322a43510..95d290d87b 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -128,4 +128,12 @@ bool MacVentureEngine::scummVMSaveLoadDialog(bool isSave) { return saveGameState(slot, desc).getCode() == Common::kNoError; } +bool MacVentureEngine::canLoadGameStateCurrently() { + return true; +} + +bool MacVentureEngine::canSaveGameStateCurrently() { + return true; +} + } // End of namespace MacVenture -- cgit v1.2.3 From d1a31ff5dbb3fb9cd7a3cda2945ee7f9183a6497 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 2 Aug 2016 13:58:16 +0200 Subject: MACVENTURE: Fix startup loading bug --- engines/macventure/gui.cpp | 7 +++++++ engines/macventure/gui.h | 2 +- engines/macventure/macventure.cpp | 17 +++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d615493b60..b3f282f4c9 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -951,6 +951,13 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { return nullptr; } +void Gui::ensureInventoryOpen(WindowReference reference, ObjID id) { + assert(reference < 0x80 && reference >= kInventoryStart); + if (reference - kInventoryStart == _inventoryWindows.size()) { + createInventoryWindow(id); + } +} + WindowReference Gui::getObjWindow(ObjID objID) { switch (objID) { case 0xfffc: return kExitsWindow; diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 31cacd76ef..18be9b93e2 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -106,7 +106,6 @@ public: void updateWindow(WindowReference winID, bool containerOpen); void invertWindowColors(WindowReference winID); - WindowReference createInventoryWindow(ObjID objRef); bool tryCloseWindow(WindowReference winID); @@ -138,6 +137,7 @@ public: void bringToFront(WindowReference window); void setWindowTitle(WindowReference winID, Common::String string); void updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array &children); + void ensureInventoryOpen(WindowReference reference, ObjID id); void addChild(WindowReference target, ObjID child); void removeChild(WindowReference target, ObjID child); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 6a7c1474a8..b52379d6ed 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -24,6 +24,7 @@ #include "common/debug-channels.h" #include "common/debug.h" #include "common/error.h" +#include "common/config-manager.h" #include "engines/util.h" #include "macventure/macventure.h" @@ -129,11 +130,18 @@ Common::Error MacVentureEngine::run() { _destObject = 0; _prepared = true; - _cmdReady = true; + int directSaveSlotLoading = ConfMan.getInt("save_slot"); + if (directSaveSlotLoading >= 0) { + if (loadGameState(directSaveSlotLoading).getCode() != Common::kNoError) { + error("Could not load game from slot '%d'", directSaveSlotLoading); + } + } else { + _cmdReady = true; + ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); + _currentSelection.push_back(playerParent);// Push the parent of the player + _world->setObjAttr(playerParent, kAttrContainerOpen, 1); + } _selectedControl = kStartOrResume; - ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); - _currentSelection.push_back(playerParent);// Push the parent of the player - _world->setObjAttr(playerParent, kAttrContainerOpen, 1); _gui->addChild(kSelfWindow, 1); _gui->updateWindow(kSelfWindow, false); @@ -194,6 +202,7 @@ void MacVentureEngine::resetInternals() { void MacVentureEngine::resetGui() { _gui->updateWindowInfo(kMainGameWindow, getParent(1), _world->getChildren(getParent(1), true)); // HACK! should update all inventories + _gui->ensureInventoryOpen(kInventoryStart, 1); _gui->updateWindowInfo(kInventoryStart, 1, _world->getChildren(1, true)); updateControls(); updateExits(); -- cgit v1.2.3 From 5c43e3049936c28b57147c2062e1f7724a9165ce Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 2 Aug 2016 18:45:23 +0200 Subject: MACVENTURE: Implement loading borders from zip --- engines/macventure/datafiles.cpp | 83 +++++++++++++++++++++++++++++++++++++++ engines/macventure/gui.cpp | 36 ++++++----------- engines/macventure/gui.h | 4 +- engines/macventure/macventure.cpp | 5 +++ engines/macventure/macventure.h | 6 +++ engines/macventure/module.mk | 3 +- 6 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 engines/macventure/datafiles.cpp diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp new file mode 100644 index 0000000000..71407a7557 --- /dev/null +++ b/engines/macventure/datafiles.cpp @@ -0,0 +1,83 @@ +/* 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. + * + */ + +#ifndef MACVENTURE_DATAFILES_H +#define MACVENTURE_DATAFILES_H + +#include "macventure/macventure.h" +#include "macventure/windows.h" + +#include "common/unzip.h" + +namespace MacVenture { + +#define MACVENTURE_DATA_BUNDLE Common::String("macventure.zip") + +Common::String windowTypeName(MVWindowType windowType) { + switch (windowType) { + case kDocument: + return "Document"; + case kDBox: + return "DBox"; + case kPlainDBox: + return "PlainDBox"; + case kAltBox: + return "AltBox"; + case kNoGrowDoc: + return "NoGrowDoc"; + case kMovableDBox: + return "MovableDBox"; + case kZoomDoc: + return "ZoomDoc"; + case kZoomNoGrow: + return "ZoomNoGrow"; + case kRDoc16: + return "RDoc16"; + case kRDoc4: + return "RDoc4"; + case kRDoc6: + return "RDoc6"; + case kRDoc10: + return "RDoc10"; + } +} + +void MacVentureEngine::loadDataBundle() { + _dataBundle = Common::makeZipArchive(MACVENTURE_DATA_BUNDLE); + if (!_dataBundle) + error("Couldn't load data bundle '%s'.", MACVENTURE_DATA_BUNDLE.c_str()); +} + +Common::SeekableReadStream *MacVentureEngine::getBorderFile(MVWindowType windowType, bool isActive) { + Common::String filename = windowTypeName(windowType); + filename += (isActive ? "_act.bmp" : "_inac.bmp"); + if (!_dataBundle->hasFile(filename)) { + warning("Missing border file '%s' in data bundle", filename.c_str()); + return nullptr; + } + + return _dataBundle->createReadStreamForMember(filename); +} + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index b3f282f4c9..4f11478c21 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -215,40 +215,35 @@ void Gui::initWindows() { _controlsWindow->setDimensions(getWindowData(kCommandsWindow).bounds); _controlsWindow->setActive(false); _controlsWindow->setCallback(commandsWindowCallback, this); - loadBorder(_controlsWindow, "border_command.bmp", false, findWindowData(kCommandsWindow).type); - loadBorder(_controlsWindow, "border_command.bmp", true, findWindowData(kCommandsWindow).type); + loadBorders(_controlsWindow, findWindowData(kCommandsWindow).type); // Main Game Window _mainGameWindow = _wm.addWindow(true, true, true); _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); - loadBorder(_mainGameWindow, "border_no_scroll_inac.bmp", false, findWindowData(kMainGameWindow).type); - loadBorder(_mainGameWindow, "border_no_scroll_act.bmp", true, findWindowData(kMainGameWindow).type); + loadBorders(_mainGameWindow, findWindowData(kMainGameWindow).type); // In-game Output Console _outConsoleWindow = _wm.addWindow(true, true, false); _outConsoleWindow->setDimensions(getWindowData(kOutConsoleWindow).bounds); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); - loadBorder(_outConsoleWindow, "border_left_scroll_inac.bmp", false, findWindowData(kOutConsoleWindow).type); - loadBorder(_outConsoleWindow, "border_left_scroll_act.bmp", true, findWindowData(kOutConsoleWindow).type); + loadBorders(_outConsoleWindow, findWindowData(kOutConsoleWindow).type); // Self Window _selfWindow = _wm.addWindow(false, true, false); _selfWindow->setDimensions(getWindowData(kSelfWindow).bounds); _selfWindow->setActive(false); _selfWindow->setCallback(selfWindowCallback, this); - loadBorder(_selfWindow, "border_none.bmp", false, findWindowData(kSelfWindow).type); - loadBorder(_selfWindow, "border_none.bmp", true, findWindowData(kSelfWindow).type); + loadBorders(_selfWindow, findWindowData(kSelfWindow).type); // Exits Window _exitsWindow = _wm.addWindow(false, false, false); _exitsWindow->setDimensions(getWindowData(kExitsWindow).bounds); _exitsWindow->setActive(false); _exitsWindow->setCallback(exitsWindowCallback, this); - loadBorder(_exitsWindow, "border_no_scroll_inac.bmp", false, findWindowData(kExitsWindow).type); - loadBorder(_exitsWindow, "border_no_scroll_act.bmp", true, findWindowData(kExitsWindow).type); + loadBorders(_exitsWindow, findWindowData(kExitsWindow).type); } const WindowData& Gui::getWindowData(WindowReference reference) { @@ -336,35 +331,28 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { newWindow->setDimensions(newData.bounds); newWindow->setCallback(inventoryWindowCallback, this); newWindow->setCloseable(true); - loadBorder(newWindow, "border_both_scroll_inac.bmp", false, newData.type); - loadBorder(newWindow, "border_both_scroll_act.bmp", true, newData.type); + loadBorders(newWindow, newData.type); _inventoryWindows.push_back(newWindow); debug("Create new inventory window. Reference: %d", newData.refcon); return newData.refcon; } -void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool active, MVWindowType type) { - Common::File borderfile; +void Gui::loadBorders(Graphics::MacWindow * target, MVWindowType type) { + loadBorder(target, type, false); + loadBorder(target, type, true); +} - if (!borderfile.open(filename)) { - debug(1, "Cannot open border file"); - return; - } +void Gui::loadBorder(Graphics::MacWindow * target, MVWindowType type, bool active) { - Image::BitmapDecoder bmpDecoder; - Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size()); - Graphics::Surface source; - Graphics::TransparentSurface *surface = new Graphics::TransparentSurface(); + Common::SeekableReadStream *stream = _engine->getBorderFile(type, active); if (stream) { BorderBounds bbs = borderBounds(type); - debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename.c_str()); target->loadBorder(*stream, active, bbs.leftOffset, bbs.rightOffset, bbs.topOffset, bbs.bottomOffset); delete stream; } - borderfile.close(); } void Gui::loadGraphics() { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 18be9b93e2..fb9bccf8a5 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -156,7 +156,6 @@ public: void setTextInput(Common::String str); void closeDialog(); - // TODO: Currently unused, we are using ScummVM dialogs instead. void loadGame(int slot); void saveInto(int slot); @@ -205,7 +204,8 @@ private: // Methods bool loadMenus(); bool loadWindows(); bool loadControls(); - void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active, MVWindowType type); + void loadBorders(Graphics::MacWindow *target, MVWindowType type); + void loadBorder(Graphics::MacWindow *target, MVWindowType type, bool active); void loadGraphics(); // Drawers diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index b52379d6ed..ac9ae8e3f7 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -86,6 +86,9 @@ MacVentureEngine::~MacVentureEngine() { if (_soundManager) delete _soundManager; + + if (_dataBundle) + delete _dataBundle; } Common::Error MacVentureEngine::run() { @@ -113,6 +116,8 @@ Common::Error MacVentureEngine::run() { _decodingNamingArticles = new StringTable(this, _resourceManager, kNamingArticlesStringTableID); _decodingIndirectArticles = new StringTable(this, _resourceManager, kIndirectArticlesStringTableID); + loadDataBundle(); + // Big class instantiation _gui = new Gui(this, _resourceManager); _world = new World(this, _resourceManager); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index b4f8192ed7..6953b61904 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -191,6 +191,10 @@ public: virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); + // datafiles.cpp + void loadDataBundle(); + Common::SeekableReadStream *getBorderFile(MVWindowType windowType, bool isActive); + void reset(); void resetInternals(); void resetGui(); @@ -319,6 +323,8 @@ private: // Attributes SoundManager *_soundManager; + Common::Archive *_dataBundle; + // Engine state GameState _gameState; GlobalSettings _globalSettings; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 244401b4a6..7b81018394 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -14,7 +14,8 @@ MODULE_OBJS := \ prebuilt_dialogs.o \ windows.o \ sound.o \ - saveload.o + saveload.o \ + datafiles.o MODULE_DIRS += \ -- cgit v1.2.3 From 06d9e188dfbe465c3adcc3e35d9547213c759d65 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 2 Aug 2016 18:55:18 +0200 Subject: MACVENTURE: Fix scroll in GUI --- engines/macventure/gui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index fb9bccf8a5..a44e394eaf 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -340,6 +340,7 @@ public: ConsoleText(Gui *gui) { _gui = gui; _lines.push_back(""); + updateScroll(); } ~ConsoleText() { @@ -377,11 +378,10 @@ public: } void scrollDown() { - if (_scrollPos < _lines.size() - 1) _scrollPos++; + if (_scrollPos < (int)(_lines.size() - 1)) _scrollPos++; } void scrollUp() { - debug("scroll up"); if (_scrollPos > 0) _scrollPos--; } -- cgit v1.2.3 From 427d69535f87c7a4ba4e82eedc3cae845f454535 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 09:50:29 +0200 Subject: MACVENTURE: Fix object overflow --- engines/macventure/image.cpp | 110 ++++++++++++++++--------------------------- engines/macventure/image.h | 10 ++-- 2 files changed, 47 insertions(+), 73 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index a4db46ecd4..05ec68c2a0 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -410,95 +410,58 @@ int ImageAsset::getHeight() { return MAX(0, (int)_imgBitHeight); } -void ImageAsset::blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array& data, uint bitHeight, uint bitWidth, uint rowBytes) { - -/* - if (bitWidth == 0 || bitHeight == 0) return; - uint w = bitWidth; - uint h = bitHeight; - uint sx = 0; - uint sy = 0; - if (ox<0) { sx = -ox; ox = 0; } - if (oy<0) { sy = -oy; oy = 0; } - if (w + ox >= target->w) w = target->w - ox; - if (h + oy >= target->h) h = target->h - oy; - if (w == 0 || h == 0) return; -*/ - for (uint y = 0; y < bitHeight; y++) { - uint bmpofs = y * rowBytes; +void ImageAsset::blitDirect(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array& data, uint bitHeight, uint bitWidth, uint rowBytes) { + uint sx, sy, w, h; + calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + + for (uint y = 0; y < h; y++) { + uint bmpofs = (y + sy) * rowBytes; byte pix = 0; - for (uint x = 0; x < bitWidth; x++) { - pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + for (uint x = 0; x < w; x++) { + pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); pix = pix ? kColorBlack : kColorWhite; *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; } } } -void ImageAsset::blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { -/* - if (bitWidth == 0 || bitHeight == 0) return; - uint w = bitWidth; - uint h = bitHeight; - uint sx = 0; - uint sy = 0; - if (ox<0) { sx = -ox; ox = 0; } - if (oy<0) { sy = -oy; oy = 0; } - if (w + ox >= target->w) w = target->w - ox; - if (h + oy >= target->h) h = target->h - oy; - if (w == 0 || h == 0) return; -*/ - for (uint y = 0; y < bitHeight; y++) { - uint bmpofs = y * rowBytes; +void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { + uint sx, sy, w, h; + calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + + for (uint y = 0; y < h; y++) { + uint bmpofs = (y + sy) * rowBytes; byte pix = 0; - for (uint x = 0; x < bitWidth; x++) { - pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + for (uint x = sx; x < w; x++) { + pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; } } } -void ImageAsset::blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { -/* - if (bitWidth == 0 || bitHeight == 0) return; - uint w = bitWidth; - uint h = bitHeight; - uint sx = 0; - uint sy = 0; - if (ox<0) { sx = -ox; ox = 0; } - if (oy<0) { sy = -oy; oy = 0; } - if (w + ox >= target->w) w = target->w - ox; - if (h + oy >= target->h) h = target->h - oy; - if (w == 0 || h == 0) return; -*/ - for (uint y = 0; y < bitHeight; y++) { - uint bmpofs = y * rowBytes; +void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { + uint sx, sy, w, h; + calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + + for (uint y = 0; y < h; y++) { + uint bmpofs = (y + sy) * rowBytes; byte pix = 0; - for (uint x = 0; x < bitWidth; x++) { - pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + for (uint x = 0; x < w; x++) { + pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorBlack; } } } -void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { -/* - if (bitWidth == 0 || bitHeight == 0) return; - uint w = bitWidth; - uint h = bitHeight; - uint sx = 0; - uint sy = 0; - if (ox<0) { sx = -ox; ox = 0; } - if (oy<0) { sy = -oy; oy = 0; } - if (w + ox >= target->w) w = target->w - ox; - if (h + oy >= target->h) h = target->h - oy; - if (w == 0 || h == 0) return; -*/ - for (uint y = 0; y < bitHeight; y++) { - uint bmpofs = y * rowBytes; +void ImageAsset::blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { + uint sx, sy, w, h; + calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + + for (uint y = 0; y < h; y++) { + uint bmpofs = (y + sy) * rowBytes; byte pix = 0; - for (uint x = 0; x < bitWidth; x++) { - pix = data[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); + for (uint x = 0; x < w; x++) { + pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); if (pix) { // We need to xor byte p = *((byte *)target->getBasePtr(ox + x, oy + y)); *((byte *)target->getBasePtr(ox + x, oy + y)) = @@ -508,4 +471,13 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy } } +void ImageAsset::calculateSubsection(int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h) { + sx = (ox < 0) ? -ox : 0; + sy = (oy < 0) ? -oy : 0; + ox = (ox < 0) ? 0 : ox; + oy = (oy < 0) ? 0 : oy; + w = MAX((int)(bitWidth - sx), 0); + h = MAX((int)(bitHeight - sy), 0); +} + } // End of namespace MacVenture diff --git a/engines/macventure/image.h b/engines/macventure/image.h index e6b2515f5c..3520f8182e 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -77,10 +77,12 @@ private: void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); - void blitDirect(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void blitBIC(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void blitOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void blitXOR(Graphics::ManagedSurface * target, uint32 ox, uint32 oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitDirect(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitBIC(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + + void calculateSubsection(int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h); private: ObjID _id; -- cgit v1.2.3 From 0202ff9c508ad8d510014a7c5581d57385d2acd2 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 10:04:58 +0200 Subject: MACVENTURE: Fix exit highlighting --- engines/macventure/macventure.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index ac9ae8e3f7..6ed11eb9c7 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -172,6 +172,7 @@ Common::Error MacVentureEngine::run() { _paused = false; if (!updateState()) { updateControls(); + updateExits(); } } } -- cgit v1.2.3 From 5b63e29d5e2ff4710cf4d417474b607d84317dee Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 10:56:51 +0200 Subject: MACVENTURE: Clean up updateState function --- engines/macventure/macventure.cpp | 34 ++++++++++++---------------------- engines/macventure/macventure.h | 6 +++--- engines/macventure/script.cpp | 11 +++++------ engines/macventure/script.h | 2 +- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 6ed11eb9c7..867504b427 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -160,20 +160,18 @@ Common::Error MacVentureEngine::run() { _prepared = false; if (!_halted) - updateState(); + updateState(false); if (_cmdReady || _halted) { _halted = false; if (runScriptEngine()) { _halted = true; _paused = true; - } - else { + } else { _paused = false; - if (!updateState()) { - updateControls(); - updateExits(); - } + updateState(true); + updateControls(); + updateExits(); } } @@ -485,8 +483,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { _haltedInSelection = true; return true; } - if (updateState()) - return true; + updateState(true); } while (!_currentSelection.empty()) { @@ -497,9 +494,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { _haltedInSelection = true; return true; } - if (updateState()) { - return true; - } + updateState(true); } } if (_selectedControl == 1) @@ -518,12 +513,10 @@ void MacVentureEngine::endGame() { requestQuit(); } -bool MacVentureEngine::updateState() { +void MacVentureEngine::updateState(bool pause) { runObjQueue(); - bool wait = printTexts(); - // HACK playSounds should accept a bool passed to updateState - wait |= playSounds(true); - return wait; + printTexts(); + playSounds(pause); } void MacVentureEngine::revert() { @@ -575,7 +568,7 @@ void MacVentureEngine::runObjQueue() { } } -bool MacVentureEngine::printTexts() { +void MacVentureEngine::printTexts() { for (uint i = 0; i < _textQueue.size(); i++) { QueuedText text = _textQueue.front(); _textQueue.remove_at(0); @@ -594,10 +587,9 @@ bool MacVentureEngine::printTexts() { break; } } - return false; } -bool MacVentureEngine::playSounds(bool pause) { +void MacVentureEngine::playSounds(bool pause) { int delay=0; while (!_soundQueue.empty()) { QueuedSound item = _soundQueue.front(); @@ -618,9 +610,7 @@ bool MacVentureEngine::playSounds(bool pause) { warning("Sound pausing not yet tested. Pausing for %d", delay * 1000); g_system->delayMillis(delay * 1000); preparedToRun(); - return true; } - return false; } void MacVentureEngine::updateControls() { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 6953b61904..275a7ac1a7 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -210,7 +210,7 @@ public: void loseGame(); void clickToContinue(); - bool updateState(); + void updateState(bool pause); void revert(); void enqueueObject(ObjectQueueID type, ObjID objID, ObjID target = 0); @@ -218,8 +218,8 @@ public: void enqueueSound(SoundQueueID type, ObjID target); void runObjQueue(); - bool printTexts(); - bool playSounds(bool pause); + void printTexts(); + void playSounds(bool pause); void handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick); void handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 6f0a7820b3..ef1d36cbae 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -453,8 +453,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { opdbROBQ(state, frame); break; case 0xdc: //run sound queue - if (opdcRSQ(state, frame)) - return true; + opdcRSQ(state, frame); break; case 0xdd: //run text queue opddRTQ(state, frame); @@ -1102,7 +1101,7 @@ void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { - _engine->updateState(); + _engine->updateState(false); _engine->clickToContinue(); } @@ -1110,8 +1109,8 @@ void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { _engine->runObjQueue(); } -bool ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { - return _engine->playSounds(true); +void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { + _engine->playSounds(true); } void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { @@ -1119,7 +1118,7 @@ void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { - _engine->updateState(); + _engine->updateState(true); } void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 7c4b77df75..5760a31e8a 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -257,7 +257,7 @@ private: void opd9SLEEP(EngineState *state, EngineFrame *frame); //sleep void opdaCLICK(EngineState *state, EngineFrame *frame); //click to continue void opdbROBQ(EngineState *state, EngineFrame *frame); //run queue - bool opdcRSQ(EngineState *state, EngineFrame *frame); //run sound queue + void opdcRSQ(EngineState *state, EngineFrame *frame); //run sound queue void opddRTQ(EngineState *state, EngineFrame *frame); //run text queue void opdeUPSC(EngineState *state, EngineFrame *frame); //update screen void opdfFMAI(EngineState *state, EngineFrame *frame); //flash main window -- cgit v1.2.3 From 0aef29a8c5f364e53f6bef57fee890005bcda129 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 13:54:21 +0200 Subject: MACVENTURE: Revamp double click detection --- engines/macventure/gui.cpp | 20 +++-------- engines/macventure/gui.h | 88 +++++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 40 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 4f11478c21..327a2e8b7f 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -20,9 +20,7 @@ * */ - #include "common/file.h" -#include "common/timer.h" #include "common/system.h" #include "image/bmp.h" @@ -92,11 +90,6 @@ static const Graphics::MenuData menuSubItems[] = { }; -static void cursorTimerHandler(void *refCon) { - Gui *gui = (Gui *)refCon; - gui->processCursorTick(); -} - bool commandsWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool mainGameWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); bool outConsoleWindowCallback(Graphics::WindowClick, Common::Event &event, void *gui); @@ -117,7 +110,6 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _dialog = nullptr; _cursor = new Cursor(this); - g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 500000, this, "macVentureCursor"); _consoleText = new ConsoleText(this); @@ -886,8 +878,7 @@ WindowReference Gui::findWindowAtPoint(Common::Point point) { win = findWindow(it->refcon); if (win && it->refcon != kDiplomaWindow) { //HACK, diploma should be cosnidered if (win->getDimensions().contains(point)) { - if (win->isActive()) - return it->refcon; + return it->refcon; } } } @@ -979,7 +970,10 @@ void Gui::checkSelect(const WindowData &data, const Common::Event &event, const child = (*it).obj; } } - if (child != 0) selectDraggable(child, ref, event.mouse, data.scrollPos); + if (child != 0) { + selectDraggable(child, ref, event.mouse, data.scrollPos); + bringToFront(ref); + } } bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { @@ -1375,10 +1369,6 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { return true; } -void Gui::processCursorTick() { - _cursor->tick(); -} - void Gui::handleSingleClick(Common::Point pos) { debug("Single Click"); // HACK THERE HAS TO BE A MORE ELEGANT WAY diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index a44e394eaf..bc9ca14643 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -29,6 +29,8 @@ #include "graphics/font.h" +#include "common/timer.h" + #include "macventure/macventure.h" #include "macventure/container.h" #include "macventure/image.h" @@ -123,8 +125,6 @@ public: bool processDiplomaEvents(WindowClick click, Common::Event &event); bool processInventoryEvents(WindowClick click, Common::Event &event); - void processCursorTick(); - const WindowData& getWindowData(WindowReference reference); const Graphics::Font& getCurrentFont(); @@ -244,32 +244,35 @@ private: // Methods }; +static void cursorTimerHandler(void *refCon); + class Cursor { enum ClickState { kCursorIdle = 0, - kCursorSC = 1, - kCursorNoTick = 2, - kCursorSCTrans = 3, - kCursorExecSC = 4, - kCursorExecDC = 5, + kCursorSCStart = 1, + kCursorSCDrag = 2, + kCursorDCStart = 3, + kCursorDCDo = 4, + kCursorSCSink = 5, kCursorStateCount }; enum CursorInput { // Columns for the FSM transition table - kTickCol = 0, - kButtonDownCol = 1, - kButtonUpCol = 2, + kButtonDownCol = 0, + kButtonUpCol = 1, + kTickCol = 2, kCursorInputCount }; ClickState _transitionTable[kCursorStateCount][kCursorInputCount] = { - /* kCursorIdle */ {kCursorIdle, kCursorIdle, kCursorSC }, - /* kCursorSC */ {kCursorExecSC, kCursorSCTrans, kCursorExecDC }, - /* IgnoreTick */ {kCursorNoTick, kCursorNoTick, kCursorExecSC }, - /* SC Transition */ {kCursorNoTick, kCursorNoTick, kCursorExecDC }, - /* Exec SC */ {kCursorIdle, kCursorExecSC, kCursorExecSC }, // Trap state - /* Exec DC */ {kCursorIdle, kCursorExecDC, kCursorExecDC } // Trap state + /* Button down, Button Up, Tick */ + /* Idle */ {kCursorSCStart, kCursorIdle, kCursorIdle }, + /* SC Start */ {kCursorSCStart, kCursorDCStart, kCursorSCDrag}, + /* SC Do */ {kCursorSCDrag, kCursorIdle, kCursorSCDrag}, + /* DC Start */ {kCursorDCDo, kCursorDCStart, kCursorSCSink}, + /* DC Do */ {kCursorDCDo, kCursorIdle, kCursorDCDo }, + /* SC Sink */ {kCursorIdle, kCursorIdle, kCursorIdle }, }; public: @@ -281,12 +284,10 @@ public: ~Cursor() {} void tick() { - executeState(); changeState(kTickCol); } bool processEvent(const Common::Event &event) { - if (event.type == Common::EVENT_MOUSEMOVE) { _pos = event.mouse; return true; @@ -310,17 +311,49 @@ public: private: void changeState(CursorInput input) { - debug(4, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); - _state = _transitionTable[_state][input]; + debug(1, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); + if (_state != _transitionTable[_state][input]) { + executeStateOut(); + _state = _transitionTable[_state][input]; + executeStateIn(); + } } - void executeState() { - if (_state == kCursorExecSC) { + void executeStateIn() { + switch (_state) { + case kCursorSCStart: + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); + break; + case kCursorDCStart: + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); + break; + case kCursorSCSink: _gui->handleSingleClick(_pos); changeState(kTickCol); - } else if (_state == kCursorExecDC) { + break; + default: + break; + } + } + + void executeStateOut() { + switch (_state) { + case kCursorIdle: + break; + case kCursorSCStart: + g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); + break; + case kCursorSCDrag: + _gui->handleSingleClick(_pos); + break; + case kCursorDCStart: + g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); + break; + case kCursorDCDo: _gui->handleDoubleClick(_pos); - changeState(kTickCol); + break; + default: + break; } } @@ -330,9 +363,14 @@ private: Common::Point _pos; ClickState _state; - }; +static void cursorTimerHandler(void *refCon) { + Cursor *cursor = (Cursor *)refCon; + cursor->tick(); +} + + class ConsoleText { public: -- cgit v1.2.3 From 409a665867d5c310bf335436d05bf728c26c2f4a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 16:02:51 +0200 Subject: MACVENTURE: Adapt dragging to new click detection --- engines/macventure/gui.cpp | 39 ++++++++++++++++++--------------------- engines/macventure/gui.h | 10 ++++++++-- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 327a2e8b7f..24f7031629 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -963,22 +963,22 @@ WindowReference Gui::findObjWindow(ObjID objID) { return kNoWindow; } -void Gui::checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { +void Gui::checkSelect(const WindowData &data, Common::Point pos, const Common::Rect &clickRect, WindowReference ref) { ObjID child = 0; for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { - if (canBeSelected((*it).obj, event, clickRect, ref)) { + if (canBeSelected((*it).obj, clickRect, ref)) { child = (*it).obj; } } if (child != 0) { - selectDraggable(child, ref, event.mouse, data.scrollPos); + selectDraggable(child, ref, pos, data.scrollPos); bringToFront(ref); } } -bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { +bool Gui::canBeSelected(ObjID obj, const Common::Rect &clickRect, WindowReference ref) { return (_engine->isObjClickable(obj) && - isRectInsideObject(clickRect, obj)); + isRectInsideObject(clickRect, obj)); } bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { @@ -1007,6 +1007,7 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point cli } void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) { + if (_draggedObj.id != 0) { WindowReference destinationWindow = findWindowAtPoint(pos); if (destinationWindow == kNoWindow) return; @@ -1250,13 +1251,6 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e if (_engine->needsClickToContinue()) return true; - if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { - WindowData &data = findWindowData(kMainGameWindow); - Common::Point pos; - // Click rect to local coordinates. We assume the click is inside the window ^ - Common::Rect clickRect = calculateClickRect(event.mouse + data.scrollPos, _mainGameWindow->getDimensions()); - checkSelect(data, event, clickRect, kMainGameWindow); - } return false; } @@ -1342,8 +1336,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); if (ref == kNoWindow) return false; - - Graphics::MacWindow *win = findWindow(ref); + WindowData &data = findWindowData((WindowReference) ref); if (click == kBorderScrollUp) { @@ -1358,17 +1351,21 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (click == kBorderScrollRight) { data.scrollPos.x += kScrollAmount; } - - if (click == kBorderInner) { - Common::Point pos; - // Click rect to local coordinates. We assume the click is inside the window ^ - Common::Rect clickRect = calculateClickRect(event.mouse + data.scrollPos, win->getDimensions()); - checkSelect(data, event, clickRect, (WindowReference)ref); - } } return true; } +void Gui::selectForDrag(Common::Point pos) { + WindowReference ref = findWindowAtPoint(pos); + if (ref == kNoWindow) return; + + Graphics::MacWindow *win = findWindow(ref); + WindowData &data = findWindowData((WindowReference) ref); + + Common::Rect clickRect = calculateClickRect(pos + data.scrollPos, win->getDimensions()); + checkSelect(data, pos, clickRect, (WindowReference)ref); +} + void Gui::handleSingleClick(Common::Point pos) { debug("Single Click"); // HACK THERE HAS TO BE A MORE ELEGANT WAY diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index bc9ca14643..8155fb50d1 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -130,6 +130,7 @@ public: const Graphics::Font& getCurrentFont(); // Clicks + void selectForDrag(Common::Point pos); void handleSingleClick(Common::Point pos); void handleDoubleClick(Common::Point pos); @@ -231,8 +232,8 @@ private: // Methods Graphics::MacWindow *findWindow(WindowReference reference); // Utils - bool canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); - void checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); + void checkSelect(const WindowData &data, Common::Point pos, const Common::Rect &clickRect, WindowReference ref); + bool canBeSelected(ObjID obj, const Common::Rect &clickRect, WindowReference ref); bool isRectInsideObject(Common::Rect target, ObjID obj); void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos, Common::Point scroll); void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); @@ -308,6 +309,10 @@ public: return _pos; } + bool canSelectDraggable() { + return _state == kCursorSCDrag; + } + private: void changeState(CursorInput input) { @@ -323,6 +328,7 @@ private: switch (_state) { case kCursorSCStart: g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); + _gui->selectForDrag(_pos); break; case kCursorDCStart: g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); -- cgit v1.2.3 From cb4650247fa10f530cc1ac5d2e4c312b055c988d Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 16:48:33 +0200 Subject: MACVENTURE: Fix segfault when saving --- engines/macventure/saveload.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index 95d290d87b..54009a1127 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -95,6 +95,7 @@ Common::Error MacVentureEngine::saveGameState(int slot, const Common::String &de warning("Could not save '%s' correctly.", saveFileName.c_str()); } delete file; + return Common::kNoError; } bool MacVentureEngine::scummVMSaveLoadDialog(bool isSave) { -- cgit v1.2.3 From d925d2c2cec380ff5422a6c737a8f7ee49085fd7 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 17:11:13 +0200 Subject: MACVENTURE: Fix segfault with death sound --- engines/macventure/sound.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 97fe3c6132..0f9ea43afe 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -59,7 +59,7 @@ void SoundManager::ensureLoaded(ObjID sound) { } SoundAsset::SoundAsset(Container *container, ObjID id) : - _container(container), _id(id) { + _container(container), _id(id), _length(0), _frequency(1) { if (_container->getItemByteSize(_id) == 0) warning("Trying to load an empty sound asset."); @@ -93,6 +93,7 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : break; default: warning("Unrecognized sound type: %x", type); + break; } delete stream; @@ -101,11 +102,13 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : SoundAsset::~SoundAsset() {} void SoundAsset::play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle) { + if (_data.size() == 0) return; Audio::AudioStream *sound = Audio::makeRawStream(&_data.front(), _length, _frequency, Audio::FLAG_UNSIGNED); mixer->playStream(Audio::Mixer::kPlainSoundType, soundHandle, sound); } uint32 SoundAsset::getPlayLength() { + return _length / _frequency; } -- cgit v1.2.3 From d1a249bc9e35ffb141f52e50b07f542a64978383 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 4 Aug 2016 17:30:00 +0200 Subject: MACVENTURE: Fix selected object drawing --- engines/macventure/gui.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 24f7031629..b449855fc0 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -657,9 +657,14 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * pos.y, mode); - if (_engine->isObjSelected(child)) - _assets[child]->blitInto( - surface, pos.x, pos.y, kBlitOR); + if (_engine->isObjVisible(child)) { + if (_engine->isObjSelected(child) || + child == _draggedObj.id) { + + _assets[child]->blitInto( + surface, pos.x, pos.y, kBlitOR); + } + } // For test if (MACVENTURE_DEBUG_GUI) { @@ -1336,7 +1341,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); if (ref == kNoWindow) return false; - + WindowData &data = findWindowData((WindowReference) ref); if (click == kBorderScrollUp) { -- cgit v1.2.3 From 0c0be43a3e1e4d012eb6742a88aaa2e398360f2c Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 5 Aug 2016 10:46:58 +0200 Subject: MACVENTURE: Fix corner case drawing overflow --- engines/macventure/gui.cpp | 48 +++++++++++++++++++++----------------------- engines/macventure/image.cpp | 14 +++++++------ engines/macventure/image.h | 2 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index b449855fc0..6833de7dfc 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -696,22 +696,34 @@ void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * sur void Gui::drawDraggedObject() { if (_draggedObj.id != 0 && - _engine->isObjVisible(_draggedObj.id)) { + _engine->isObjVisible(_draggedObj.id)) { ensureAssetLoaded(_draggedObj.id); ImageAsset *asset = _assets[_draggedObj.id]; - _draggedSurface.create(asset->getWidth(), asset->getHeight(), _screen.format); + // In case of overflow from the right/top + uint w = asset->getWidth() + MIN((int16)0, _draggedObj.pos.x); + uint h = asset->getHeight() + MIN((int16)0, _draggedObj.pos.y); - asset->blitInto(&_draggedSurface, 0, 0, kBlitBIC); + // In case of overflow from the bottom/left + if (_draggedObj.pos.x > 0 && _draggedObj.pos.x + w > kScreenWidth) { w = kScreenWidth - _draggedObj.pos.x; } + if (_draggedObj.pos.y > 0 && _draggedObj.pos.y + h > kScreenHeight) { h = kScreenHeight - _draggedObj.pos.y; } + + _draggedSurface.create(w, h, _screen.format); + + asset->blitInto(&_draggedSurface, MIN((int16)0, _draggedObj.pos.x), MIN((int16)0, _draggedObj.pos.y), kBlitBIC); + + Common::Point target = _draggedObj.pos; + if (target.x < 0) { target.x = 0; } + if (target.y < 0) { target.y = 0; } g_system->copyRectToScreen( - _draggedSurface.getPixels(), + _draggedSurface.getBasePtr(0, 0), _draggedSurface.pitch, - _draggedObj.pos.x, - _draggedObj.pos.y, + target.x, + target.y, _draggedSurface.w, - _draggedSurface.h); - + _draggedSurface.h + ); } } @@ -846,25 +858,11 @@ void Gui::saveInto(int slot) { } void Gui::moveDraggedObject(Common::Point target) { - Common::Point newPos = target + _draggedObj.mouseOffset; - bool movement = false; - // If we overflow, move the mouseOffset, not the position. - if (newPos.x < 0 || newPos.x + _assets[_draggedObj.id]->getWidth() >= kScreenWidth) { - _draggedObj.mouseOffset.x = _draggedObj.pos.x - target.x; - } else { - _draggedObj.pos.x = newPos.x; - movement = true; - } - - if (newPos.y < 0 || newPos.y + _assets[_draggedObj.id]->getHeight() >= kScreenHeight) { - _draggedObj.mouseOffset.y = _draggedObj.pos.y - target.y; - } else { - _draggedObj.pos.y = newPos.y; - movement = true; - } + ensureAssetLoaded(_draggedObj.id); + _draggedObj.pos = target + _draggedObj.mouseOffset; // TODO FInd more elegant way of making pow2 - _draggedObj.hasMoved = movement && (_draggedObj.startPos.sqrDist(_draggedObj.pos) >= (kDragThreshold * kDragThreshold)); + _draggedObj.hasMoved = (_draggedObj.startPos.sqrDist(_draggedObj.pos) >= (kDragThreshold * kDragThreshold)); debug(4, "Dragged obj position: (%d, %d), mouse offset: (%d, %d), hasMoved: %d, dist: %d, threshold: %d", _draggedObj.pos.x, _draggedObj.pos.y, diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 05ec68c2a0..a89eae94be 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -412,7 +412,7 @@ int ImageAsset::getHeight() { void ImageAsset::blitDirect(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array& data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; @@ -427,12 +427,12 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, int ox, int oy, c void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; byte pix = 0; - for (uint x = sx; x < w; x++) { + for (uint x = 0; x < w; x++) { pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; } @@ -441,7 +441,7 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, cons void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; @@ -455,7 +455,7 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const void ImageAsset::blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; @@ -471,13 +471,15 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, int ox, int oy, cons } } -void ImageAsset::calculateSubsection(int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h) { +void ImageAsset::calculateSubsection(Graphics::ManagedSurface *target, int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h) { sx = (ox < 0) ? -ox : 0; sy = (oy < 0) ? -oy : 0; ox = (ox < 0) ? 0 : ox; oy = (oy < 0) ? 0 : oy; w = MAX((int)(bitWidth - sx), 0); h = MAX((int)(bitHeight - sy), 0); + w = w > target->w ? target->w : w; + h = h > target->h ? target->h : h; } } // End of namespace MacVenture diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 3520f8182e..3910f83fa8 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -82,7 +82,7 @@ private: void blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); void blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void calculateSubsection(int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h); + void calculateSubsection(Graphics::ManagedSurface *target, int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h); private: ObjID _id; -- cgit v1.2.3 From 47916aca622f42fe210e7d4738c91f3aca3e9fb2 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 5 Aug 2016 10:53:07 +0200 Subject: MACVENTURE: Fix dragged object drawing --- engines/macventure/gui.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 6833de7dfc..0f5a264d61 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -708,14 +708,21 @@ void Gui::drawDraggedObject() { if (_draggedObj.pos.x > 0 && _draggedObj.pos.x + w > kScreenWidth) { w = kScreenWidth - _draggedObj.pos.x; } if (_draggedObj.pos.y > 0 && _draggedObj.pos.y + h > kScreenHeight) { h = kScreenHeight - _draggedObj.pos.y; } - _draggedSurface.create(w, h, _screen.format); - - asset->blitInto(&_draggedSurface, MIN((int16)0, _draggedObj.pos.x), MIN((int16)0, _draggedObj.pos.y), kBlitBIC); - Common::Point target = _draggedObj.pos; if (target.x < 0) { target.x = 0; } if (target.y < 0) { target.y = 0; } + _draggedSurface.create(w, h, _screen.format); + _draggedSurface.blitFrom( + _screen, + Common::Rect( + target.x, + target.y, + target.x + _draggedSurface.w, + target.y + _draggedSurface.h), + Common::Point(0, 0)); + asset->blitInto(&_draggedSurface, MIN((int16)0, _draggedObj.pos.x), MIN((int16)0, _draggedObj.pos.y), kBlitBIC); + g_system->copyRectToScreen( _draggedSurface.getBasePtr(0, 0), _draggedSurface.pitch, -- cgit v1.2.3 From 28bf4f11683eb165805e6f94e32ccf07819ed44c Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 5 Aug 2016 18:15:20 +0200 Subject: MACVENTURE: Fix some of the offsets --- engines/macventure/datafiles.cpp | 2 ++ engines/macventure/gui.cpp | 37 +++++++++++++++++++++++-------------- engines/macventure/windows.cpp | 11 ++++++----- engines/macventure/windows.h | 2 ++ 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp index 71407a7557..77ecaee626 100644 --- a/engines/macventure/datafiles.cpp +++ b/engines/macventure/datafiles.cpp @@ -50,6 +50,8 @@ Common::String windowTypeName(MVWindowType windowType) { return "ZoomDoc"; case kZoomNoGrow: return "ZoomNoGrow"; + case kInvWindow: + return "InvWindow"; case kRDoc16: return "RDoc16"; case kRDoc4: diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 0f5a264d61..4c69923672 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -218,7 +218,11 @@ void Gui::initWindows() { // In-game Output Console _outConsoleWindow = _wm.addWindow(true, true, false); - _outConsoleWindow->setDimensions(getWindowData(kOutConsoleWindow).bounds); + // HACK We have to hand-create the dimensions, otherwise they don't fit + const WindowData &wd = getWindowData(kOutConsoleWindow); + Common::Rect dimensions = wd.bounds; + dimensions.setWidth(dimensions.width() - borderBounds(wd.type).rightOffset); + _outConsoleWindow->setDimensions(dimensions); _outConsoleWindow->setActive(false); _outConsoleWindow->setCallback(outConsoleWindowCallback, this); loadBorders(_outConsoleWindow, findWindowData(kOutConsoleWindow).type); @@ -306,15 +310,15 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { if (_windowData->back().refcon < 0x80) { // There is already another inventory window newData.bounds = _windowData->back().bounds; // Inventory windows are always last newData.bounds.translate(newData.bounds.left + settings.invOffsetX, newData.bounds.top + settings.invOffsetY); - } - else { + } else { + BorderBounds bbs = borderBounds(kInvWindow); newData.bounds = Common::Rect( - settings.invLeft, - settings.invTop, + settings.invLeft - bbs.leftOffset, + settings.invTop - bbs.topOffset, settings.invLeft + settings.invWidth, settings.invTop + settings.invHeight); } - newData.type = kZoomDoc; + newData.type = kInvWindow; newData.hasCloseBox = true; newData.visible = true; newData.objRef = objRef; @@ -431,11 +435,13 @@ bool Gui::loadWindows() { bottom = res->readUint16BE(); right = res->readUint16BE(); data.type = (MVWindowType)res->readUint16BE(); + BorderBounds bbs = borderBounds(data.type); data.bounds = Common::Rect( - left - borderBounds(data.type).leftOffset, - top - borderBounds(data.type).topOffset, - right + borderBounds(data.type).rightOffset * 2, - bottom + borderBounds(data.type).bottomOffset * 2); + left - bbs.leftOffset, + top - bbs.topOffset, + right + bbs.rightOffset, + bottom + bbs.bottomOffset); + data.visible = res->readUint16BE(); data.hasCloseBox = res->readUint16BE(); data.refcon = (WindowReference)id; id++; @@ -492,11 +498,14 @@ bool Gui::loadControls() { res->read(data.title, data.titleLength); data.title[data.titleLength] = '\0'; } - if (data.type != kControlExitBox) - data.border = commandsBorder; + if (data.type != kControlExitBox) { + BorderBounds bbs = borderBounds(getWindowData(kCommandsWindow).type); + // We just want to move the button, not change it's size + data.bounds = Common::Rect(left + bbs.leftOffset, top + bbs.topOffset, right + bbs.leftOffset, bottom + bbs.topOffset); + } else { + data.bounds = Common::Rect(left, top, right, bottom); + } - Common::Rect bounds(left, top, right, bottom); // For some reason, if I remove this it segfaults - data.bounds = Common::Rect(left + data.border, top + data.border, right + data.border, bottom + data.border); i++; } diff --git a/engines/macventure/windows.cpp b/engines/macventure/windows.cpp index 9825349641..b3d544924f 100644 --- a/engines/macventure/windows.cpp +++ b/engines/macventure/windows.cpp @@ -31,22 +31,23 @@ BorderBounds borderBounds(MVWindowType type) { case MacVenture::kDBox: break; case MacVenture::kPlainDBox: - return BorderBounds(1, 1, 1, 2); + return BorderBounds(3, 3, 3, 3); case MacVenture::kAltBox: return BorderBounds(0, 0, 0, 0); // Hand-tested - break; case MacVenture::kNoGrowDoc: - return BorderBounds(1, 17, 1, 1); + return BorderBounds(1, 20, 1, 1); case MacVenture::kMovableDBox: break; case MacVenture::kZoomDoc: - return BorderBounds(1, 19, 17, 17); + return BorderBounds(1, 20, 17, 1); case MacVenture::kZoomNoGrow: break; + case MacVenture::kInvWindow: + return BorderBounds(1, 20, 17, 17); case MacVenture::kRDoc16: break; case MacVenture::kRDoc4: - return BorderBounds(1, 19, 1, 1); + return BorderBounds(1, 20, 1, 1); case MacVenture::kRDoc6: break; case MacVenture::kRDoc10: diff --git a/engines/macventure/windows.h b/engines/macventure/windows.h index 79b2798a2b..fe3f9275d0 100644 --- a/engines/macventure/windows.h +++ b/engines/macventure/windows.h @@ -50,6 +50,8 @@ enum MVWindowType { kMovableDBox = 0x05, kZoomDoc = 0x08, kZoomNoGrow = 0x0c, + // WebVenture assigns arbitrary kinds post-loading + kInvWindow = 0x0e, kRDoc16 = 0x10, kRDoc4 = 0x12, kRDoc6 = 0x14, -- cgit v1.2.3 From 5fade27a0cbac0ac8014bfff9a14d112baf3f7cd Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 5 Aug 2016 18:30:58 +0200 Subject: MACVENTURE: Fix indentation in controls.cpp --- engines/macventure/controls.cpp | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/engines/macventure/controls.cpp b/engines/macventure/controls.cpp index f467d72de6..26807a3308 100644 --- a/engines/macventure/controls.cpp +++ b/engines/macventure/controls.cpp @@ -24,47 +24,47 @@ namespace MacVenture { CommandButton::CommandButton() { - _gui = nullptr; + _gui = nullptr; } CommandButton::CommandButton(ControlData data, Gui *g) { - _data = data; - _gui = g; - _selected = false; + _data = data; + _gui = g; + _selected = false; } void CommandButton::draw(Graphics::ManagedSurface &surface) const { - uint colorFill = _selected ? kColorBlack : kColorWhite; - uint colorText = _selected ? kColorWhite : kColorBlack; + uint colorFill = _selected ? kColorBlack : kColorWhite; + uint colorText = _selected ? kColorWhite : kColorBlack; - surface.fillRect(_data.bounds, colorFill); - surface.frameRect(_data.bounds, kColorBlack); + surface.fillRect(_data.bounds, colorFill); + surface.frameRect(_data.bounds, kColorBlack); - if (_data.titleLength > 0) { - const Graphics::Font &font = _gui->getCurrentFont(); - Common::String title(_data.title); - font.drawString( - &surface, - title, - _data.bounds.left, - _data.bounds.top, - _data.bounds.right - _data.bounds.left, - colorText, - Graphics::kTextAlignCenter); - } + if (_data.titleLength > 0) { + const Graphics::Font &font = _gui->getCurrentFont(); + Common::String title(_data.title); + font.drawString( + &surface, + title, + _data.bounds.left, + _data.bounds.top, + _data.bounds.right - _data.bounds.left, + colorText, + Graphics::kTextAlignCenter); + } } bool CommandButton::isInsideBounds(const Common::Point point) const { - return _data.bounds.contains(point); + return _data.bounds.contains(point); } const ControlData& CommandButton::getData() const { - return _data; + return _data; } void CommandButton::select() { - _selected = true; + _selected = true; } void CommandButton::unselect() { @@ -72,6 +72,6 @@ void CommandButton::unselect() { } bool CommandButton::isSelected() { - return _selected; + return _selected; } } -- cgit v1.2.3 From 0b36a77af42868edaab4434215bbae5d8c3a5e2f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 7 Aug 2016 14:08:29 +0200 Subject: MACVENTURE: Refactor dragging code --- engines/macventure/gui.cpp | 57 +++++++++++++++++++++++----------------------- engines/macventure/gui.h | 20 ++++++++-------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 4c69923672..17d31d824d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -904,12 +904,14 @@ WindowReference Gui::findWindowAtPoint(Common::Point point) { return kNoWindow; } -Common::Point Gui::getWindowSurfacePos(WindowReference reference) { +Common::Point Gui::getGlobalScrolledSurfacePosition(WindowReference reference) { const WindowData &data = getWindowData(reference); BorderBounds border = borderBounds(data.type); Graphics::MacWindow *win = findWindow(reference); if (!win) return Common::Point(0, 0); - return Common::Point(win->getDimensions().left + border.leftOffset, win->getDimensions().top + border.topOffset); + return Common::Point( + win->getDimensions().left + border.leftOffset - data.scrollPos.x, + win->getDimensions().top + border.topOffset - data.scrollPos.y); } WindowData & Gui::findWindowData(WindowReference reference) { @@ -990,7 +992,7 @@ void Gui::checkSelect(const WindowData &data, Common::Point pos, const Common::R } } if (child != 0) { - selectDraggable(child, ref, pos, data.scrollPos); + selectDraggable(child, ref, pos); bringToFront(ref); } } @@ -1014,29 +1016,30 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { return _assets[obj]->isRectInside(intersection); } -void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point click, Common::Point scroll) { +void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point click) { if (_engine->isObjClickable(child) && _draggedObj.id == 0) { _draggedObj.hasMoved = false; _draggedObj.id = child; _draggedObj.startWin = origin; - _draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - click - scroll; + Common::Point localizedClick = click - getGlobalScrolledSurfacePosition(origin); + _draggedObj.mouseOffset = _engine->getObjPosition(child) - localizedClick; _draggedObj.pos = click + _draggedObj.mouseOffset; _draggedObj.startPos = _draggedObj.pos; } } -void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) { - +void Gui::handleDragRelease(bool shiftPressed, bool isDoubleClick) { if (_draggedObj.id != 0) { - WindowReference destinationWindow = findWindowAtPoint(pos); + WindowReference destinationWindow = findWindowAtPoint(_draggedObj.pos); if (destinationWindow == kNoWindow) return; if (_draggedObj.hasMoved) { - ObjID destObject = getWindowData(destinationWindow).objRef; - pos -= (_draggedObj.startPos - _draggedObj.mouseOffset); - pos = localize(pos, _draggedObj.startWin, destinationWindow); - debug("drop the object %d at obj %d, pos (%d, %d)", _draggedObj.id, destObject, pos.x, pos.y); + const WindowData &destinationWindowData = getWindowData(destinationWindow); + ObjID destObject = destinationWindowData.objRef; + Common::Point dropPosition = _draggedObj.pos - _draggedObj.startPos; + dropPosition = localizeTravelledDistance(dropPosition, _draggedObj.startWin, destinationWindow); + debug(3, "drop the object %d at obj %d, pos (%d, %d)", _draggedObj.id, destObject, dropPosition.x, dropPosition.y); - _engine->handleObjectDrop(_draggedObj.id, pos, destObject); + _engine->handleObjectDrop(_draggedObj.id, dropPosition, destObject); } _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); _draggedObj.id = 0; @@ -1050,17 +1053,13 @@ Common::Rect Gui::calculateClickRect(Common::Point clickPos, Common::Rect window return Common::Rect(left - kCursorWidth, top - kCursorHeight, left + kCursorWidth, top + kCursorHeight); } -Common::Point Gui::localize(Common::Point point, WindowReference origin, WindowReference target) { - Graphics::MacWindow *oriWin = findWindow(origin); - Graphics::MacWindow *destWin = findWindow(target); +Common::Point Gui::localizeTravelledDistance(Common::Point point, WindowReference origin, WindowReference target) { if (origin != target) { // ori.local to global - point.x += oriWin->getDimensions().left; - point.y += oriWin->getDimensions().top; - if (destWin) { + point += getGlobalScrolledSurfacePosition(origin); + if (findWindow(target)) { // dest.globalToLocal - point.x -= destWin->getDimensions().left; - point.y -= destWin->getDimensions().top; + point -= getGlobalScrolledSurfacePosition(target); } } return point; @@ -1374,28 +1373,28 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { return true; } -void Gui::selectForDrag(Common::Point pos) { - WindowReference ref = findWindowAtPoint(pos); +void Gui::selectForDrag(Common::Point cursorPosition) { + WindowReference ref = findWindowAtPoint(cursorPosition); if (ref == kNoWindow) return; Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); - Common::Rect clickRect = calculateClickRect(pos + data.scrollPos, win->getDimensions()); - checkSelect(data, pos, clickRect, (WindowReference)ref); + Common::Rect clickRect = calculateClickRect(cursorPosition + data.scrollPos, win->getDimensions()); + checkSelect(data, cursorPosition, clickRect, (WindowReference)ref); } -void Gui::handleSingleClick(Common::Point pos) { +void Gui::handleSingleClick() { debug("Single Click"); // HACK THERE HAS TO BE A MORE ELEGANT WAY if (_dialog) return; - handleDragRelease(pos, false, false); + handleDragRelease(false, false); } -void Gui::handleDoubleClick(Common::Point pos) { +void Gui::handleDoubleClick() { debug("Double Click"); if (_dialog) return; - handleDragRelease(pos, false, true); + handleDragRelease(false, true); } void Gui::ensureAssetLoaded(ObjID obj) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 8155fb50d1..c7fb1c74ac 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -130,9 +130,9 @@ public: const Graphics::Font& getCurrentFont(); // Clicks - void selectForDrag(Common::Point pos); - void handleSingleClick(Common::Point pos); - void handleDoubleClick(Common::Point pos); + void selectForDrag(Common::Point cursorPosition); + void handleSingleClick(); + void handleDoubleClick(); // Modifiers void bringToFront(WindowReference window); @@ -227,7 +227,7 @@ private: // Methods // Finders WindowReference findWindowAtPoint(Common::Point point); - Common::Point getWindowSurfacePos(WindowReference reference); + Common::Point getGlobalScrolledSurfacePosition(WindowReference reference); WindowData& findWindowData(WindowReference reference); Graphics::MacWindow *findWindow(WindowReference reference); @@ -235,10 +235,10 @@ private: // Methods void checkSelect(const WindowData &data, Common::Point pos, const Common::Rect &clickRect, WindowReference ref); bool canBeSelected(ObjID obj, const Common::Rect &clickRect, WindowReference ref); bool isRectInsideObject(Common::Rect target, ObjID obj); - void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos, Common::Point scroll); - void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); + void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); + void handleDragRelease(bool shiftPressed, bool isDoubleClick); Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); - Common::Point localize(Common::Point point, WindowReference origin, WindowReference target); + Common::Point localizeTravelledDistance(Common::Point point, WindowReference origin, WindowReference target); void removeInventoryWindow(WindowReference ref); void ensureAssetLoaded(ObjID obj); @@ -334,7 +334,7 @@ private: g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); break; case kCursorSCSink: - _gui->handleSingleClick(_pos); + _gui->handleSingleClick(); changeState(kTickCol); break; default: @@ -350,13 +350,13 @@ private: g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); break; case kCursorSCDrag: - _gui->handleSingleClick(_pos); + _gui->handleSingleClick(); break; case kCursorDCStart: g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); break; case kCursorDCDo: - _gui->handleDoubleClick(_pos); + _gui->handleDoubleClick(); break; default: break; -- cgit v1.2.3 From 8608776768e9926d5be09904232647bff39d7e72 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 7 Aug 2016 17:15:01 +0200 Subject: MACVENTURE: Add debug channels --- engines/macventure/container.h | 9 ++------- engines/macventure/debug.h | 39 +++++++++++++++++++++++++++++++++++++++ engines/macventure/dialog.cpp | 2 +- engines/macventure/gui.cpp | 37 +++++++++++++++++-------------------- engines/macventure/gui.h | 2 +- engines/macventure/macventure.cpp | 33 +++++++++++++++++++++++---------- engines/macventure/macventure.h | 10 +++------- engines/macventure/script.cpp | 18 +++++++++--------- engines/macventure/sound.cpp | 4 ++-- engines/macventure/stringtable.h | 2 +- engines/macventure/text.cpp | 14 +++++++------- engines/macventure/world.cpp | 2 +- 12 files changed, 106 insertions(+), 66 deletions(-) create mode 100644 engines/macventure/debug.h diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 21fdc6c529..013a11dafc 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -45,9 +45,6 @@ public: Container(Common::String filename) { _filename = filename; - //FSNode node = FSDirectory("."); - //debug(node.getDisplayName().c_str()); - if (!_file.open(_filename)) error("Could not open %s", _filename.c_str()); @@ -100,11 +97,10 @@ public: for (uint j = 0; j < 64; ++j) { uint32 length = 0; - //debug("reading mask from address %x", _res->pos()); uint32 mask = _res->readUint32BE(); mask >>= (16 - bits); mask &= 0xFFFF; - debug(11, "Load mask of object &%d:%d is %x", i, j, mask); + debugC(11, kMVDebugContainer, "Load mask of object &%d:%d is %x", i, j, mask); _res->seek(-4, SEEK_CUR); // Look in the Huffman table int x = 0; @@ -143,7 +139,7 @@ public: } group.lengths[j] = length; - debug(11, "Load legth of object %d:%d is %d", i, j, length); + debugC(11, kMVDebugContainer, "Load legth of object %d:%d is %d", i, j, length); } _groups.push_back(group); @@ -214,7 +210,6 @@ protected: Common::File _file; Common::SeekableReadStream *_res; - }; diff --git a/engines/macventure/debug.h b/engines/macventure/debug.h new file mode 100644 index 0000000000..8ee9ebe008 --- /dev/null +++ b/engines/macventure/debug.h @@ -0,0 +1,39 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_DEBUG_H +#define MACVENTURE_DEBUG_H + +namespace MacVenture { +enum MacVentureDebugChannel { + kMVDebugMain = 1 << 0, + kMVDebugGUI = 1 << 1, + kMVDebugImage = 1 << 2, + kMVDebugText = 1 << 3, + kMVDebugScript = 1 << 4, + kMVDebugSound = 1 << 5, + kMVDebugContainer = 1 << 6, + kMVDebugTests = 1 << 31 +}; +} // End namespace MacVenture + +#endif diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index a6c1e78a6f..fe01d8fd8a 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -159,7 +159,7 @@ bool DialogButton::doProcessEvent(MacVenture::Dialog *dialog, Common::Event even if (event.type == Common::EVENT_LBUTTONDOWN) { dialog->localize(mouse); if (_bounds.contains(mouse)) { - debug(1, "Click! Button: %s", _text.c_str()); + debugC(1, kMVDebugGUI, "Click! Button: %s", _text.c_str()); dialog->handleDialogAction(this, _action); return true; } diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 17d31d824d..5fa746ce3d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -330,7 +330,7 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { loadBorders(newWindow, newData.type); _inventoryWindows.push_back(newWindow); - debug("Create new inventory window. Reference: %d", newData.refcon); + debugC(1, kMVDebugGUI, "Create new inventory window. Reference: %d", newData.refcon); return newData.refcon; } @@ -455,7 +455,7 @@ bool Gui::loadWindows() { } data.scrollPos = Common::Point(0, 0); - debug(4, "Window loaded: %s", data.title.c_str()); + debugC(4, kMVDebugGUI, "Window loaded: %s", data.title.c_str()); _windowData->push_back(data); } @@ -834,7 +834,7 @@ void Gui::updateExit(ObjID obj) { } void Gui::printText(const Common::String & text) { - debug(1, "Print Text: %s", text.c_str()); + debugC(1, kMVDebugGUI, "Print Text: %s", text.c_str()); _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } @@ -880,7 +880,7 @@ void Gui::moveDraggedObject(Common::Point target) { // TODO FInd more elegant way of making pow2 _draggedObj.hasMoved = (_draggedObj.startPos.sqrDist(_draggedObj.pos) >= (kDragThreshold * kDragThreshold)); - debug(4, "Dragged obj position: (%d, %d), mouse offset: (%d, %d), hasMoved: %d, dist: %d, threshold: %d", + debugC(4, kMVDebugGUI, "Dragged obj position: (%d, %d), mouse offset: (%d, %d), hasMoved: %d, dist: %d, threshold: %d", _draggedObj.pos.x, _draggedObj.pos.y, _draggedObj.mouseOffset.x, _draggedObj.mouseOffset.y, _draggedObj.hasMoved, @@ -1037,7 +1037,7 @@ void Gui::handleDragRelease(bool shiftPressed, bool isDoubleClick) { ObjID destObject = destinationWindowData.objRef; Common::Point dropPosition = _draggedObj.pos - _draggedObj.startPos; dropPosition = localizeTravelledDistance(dropPosition, _draggedObj.startWin, destinationWindow); - debug(3, "drop the object %d at obj %d, pos (%d, %d)", _draggedObj.id, destObject, dropPosition.x, dropPosition.y); + debugC(3, kMVDebugGUI, "Drop the object %d at obj %d, pos (%d, %d)", _draggedObj.id, destObject, dropPosition.x, dropPosition.y); _engine->handleObjectDrop(_draggedObj.id, dropPosition, destObject); } @@ -1082,49 +1082,46 @@ void Gui::removeInventoryWindow(WindowReference ref) { void Gui::handleMenuAction(MenuAction action) { switch (action) { case MacVenture::kMenuActionAbout: - debug("MacVenture Menu Action: About"); + warning("Unimplemented MacVenture Menu Action: About"); break; case MacVenture::kMenuActionNew: - debug("MacVenture Menu Action: New"); + warning("Unimplemented MacVenture Menu Action: New"); break; case MacVenture::kMenuActionOpen: - debug("MacVenture Menu Action: Open"); _engine->scummVMSaveLoadDialog(false); break; case MacVenture::kMenuActionSave: - debug("MacVenture Menu Action: Save"); _engine->scummVMSaveLoadDialog(true); break; case MacVenture::kMenuActionSaveAs: - debug("MacVenture Menu Action: Save As"); _engine->scummVMSaveLoadDialog(true); break; case MacVenture::kMenuActionQuit: debug("MacVenture Menu Action: Quit"); break; case MacVenture::kMenuActionUndo: - debug("MacVenture Menu Action: Undo"); + warning("Unimplemented MacVenture Menu Action: Undo"); break; case MacVenture::kMenuActionCut: - debug("MacVenture Menu Action: Cut"); + warning("Unimplemented MacVenture Menu Action: Cut"); break; case MacVenture::kMenuActionCopy: - debug("MacVenture Menu Action: Copy"); + warning("Unimplemented MacVenture Menu Action: Copy"); break; case MacVenture::kMenuActionPaste: - debug("MacVenture Menu Action: Paste"); + warning("Unimplemented MacVenture Menu Action: Paste"); break; case MacVenture::kMenuActionClear: - debug("MacVenture Menu Action: Clear"); + warning("Unimplemented MacVenture Menu Action: Clear"); break; case MacVenture::kMenuActionCleanUp: - debug("MacVenture Menu Action: Clean Up"); + warning("Unimplemented MacVenture Menu Action: Clean Up"); break; case MacVenture::kMenuActionMessUp: - debug("MacVenture Menu Action: Mess Up"); + warning("Unimplemented MacVenture Menu Action: Mess Up"); break; case MacVenture::kMenuActionCommand: - debug("MacVenture Menu Action: GENERIC"); + warning("Unimplemented MacVenture Menu Action: GENERIC"); break; default: break; @@ -1385,14 +1382,14 @@ void Gui::selectForDrag(Common::Point cursorPosition) { } void Gui::handleSingleClick() { - debug("Single Click"); + debugC(2, kMVDebugGUI, "Registered Single Click"); // HACK THERE HAS TO BE A MORE ELEGANT WAY if (_dialog) return; handleDragRelease(false, false); } void Gui::handleDoubleClick() { - debug("Double Click"); + debugC(2, kMVDebugGUI, "Registered Double Click"); if (_dialog) return; handleDragRelease(false, true); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index c7fb1c74ac..a62264cb6f 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -316,7 +316,7 @@ public: private: void changeState(CursorInput input) { - debug(1, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); + debugC(3, kMVDebugGUI, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); if (_state != _transitionTable[_state][input]) { executeStateOut(); _state = _transitionTable[_state][input]; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 867504b427..e1d1febd57 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -36,7 +36,7 @@ namespace MacVenture { // HACK, see below void toASCII(Common::String &str) { - debug("toASCII: %s", str.c_str()); + debugC(1, kMVDebugMain, "toASCII: %s", str.c_str()); Common::String::iterator it = str.begin(); for (; it != str.end(); it++) { if (*it == '\216') { str.replace(it, it + 1, "e"); } @@ -52,11 +52,14 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD _gameDescription = gameDesc; _rnd = new Common::RandomSource("macventure"); + initDebugChannels(); + _debugger = NULL; _gui = NULL; _soundManager = NULL; + debug("MacVenture::MacVentureEngine()"); } @@ -91,6 +94,16 @@ MacVentureEngine::~MacVentureEngine() { delete _dataBundle; } +void MacVentureEngine::initDebugChannels() { + DebugMan.addDebugChannel(kMVDebugMain, "main", "Engine state"); + DebugMan.addDebugChannel(kMVDebugGUI, "gui", "Gui"); + DebugMan.addDebugChannel(kMVDebugText, "text", "Text decoders and printers"); + DebugMan.addDebugChannel(kMVDebugImage, "image", "Image decoders and renderers"); + DebugMan.addDebugChannel(kMVDebugScript, "script", "Script engine"); + DebugMan.addDebugChannel(kMVDebugSound, "sound", "Sound decoders"); + DebugMan.addDebugChannel(kMVDebugContainer, "container", "Containers"); +} + Common::Error MacVentureEngine::run() { debug("MacVenture::MacVentureEngine::init()"); @@ -224,7 +237,7 @@ void MacVentureEngine::requestUnpause() { } void MacVentureEngine::selectControl(ControlAction id) { - debug(2, "Select control %x", id); + debugC(2, kMVDebugMain, "Select control %x", id); _selectedControl = id; } @@ -239,7 +252,7 @@ void MacVentureEngine::activateCommand(ControlAction id) { _activeControl = kNoCommand; _activeControl = id; } - debug(2, "Activating Command %x... Command %x is active", id, _activeControl); + debugC(2, kMVDebugMain, "Activating Command %x... Command %x is active", id, _activeControl); refreshReady(); } @@ -392,7 +405,7 @@ void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID } void MacVentureEngine::updateDelta(Common::Point newPos) { - debug("Update delta: Old(%d, %d), New(%d, %d)", + debugC(4, kMVDebugMain, "Update delta: Old(%d, %d), New(%d, %d)", _deltaPoint.x, _deltaPoint.y, newPos.x, newPos.y); _deltaPoint = newPos; @@ -407,7 +420,7 @@ void MacVentureEngine::updateWindow(WindowReference winID) { } bool MacVentureEngine::showTextEntry(ObjID text, ObjID srcObj, ObjID destObj) { - debug("Showing speech dialog, asset %d from %d to %d", text, srcObj, destObj); + debugC(3, kMVDebugMain, "Showing speech dialog, asset %d from %d to %d", text, srcObj, destObj); _gui->getTextFromUser(); // HACK WITH FLAGS @@ -467,7 +480,7 @@ void MacVentureEngine::processEvents() { } bool MacVenture::MacVentureEngine::runScriptEngine() { - debug(4, "MAIN: Running script engine"); + debugC(4, kMVDebugMain, "MAIN: Running script engine"); if (_haltedAtEnd) { _haltedAtEnd = false; if (_scriptEngine->resume(false)) { @@ -745,7 +758,7 @@ void MacVentureEngine::focusObjectWindow(ObjID objID) { void MacVentureEngine::openObject(ObjID objID) { - debug("Open Object[%d] parent[%d] x[%d] y[%d]", + debugC(1, kMVDebugMain, "Open Object[%d] parent[%d] x[%d] y[%d]", objID, _world->getObjAttr(objID, kAttrParentObject), _world->getObjAttr(objID, kAttrPosX), @@ -775,7 +788,7 @@ void MacVentureEngine::closeObject(ObjID objID) { void MacVentureEngine::checkObject(QueuedObject old) { //warning("checkObject: unimplemented"); bool hasChanged = false; - debug("Check Object[%d] parent[%d] x[%d] y[%d]", + debugC(1, kMVDebugMain, "Check Object[%d] parent[%d] x[%d] y[%d]", old.object, old.parent, old.x, @@ -842,7 +855,7 @@ void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { WindowReference from = getObjWindow(fromID); WindowReference to = getObjWindow(toID); WindowReference tmp = to; - debug("Swap Object[%d] to Object[%d], from win[%d] to win[%d] ", + debugC(1, kMVDebugMain, "Swap Object[%d] to Object[%d], from win[%d] to win[%d] ", fromID, toID, from, to); if (!to) { @@ -1098,7 +1111,7 @@ bool MacVentureEngine::loadTextHuffman() { values[i] = res->readByte(); _textHuffman = new HuffmanLists(numEntries, lengths, masks, values); - debug(4, "Text is huffman-encoded"); + debugC(4, kMVDebugMain, "Text is huffman-encoded"); return true; } return false; diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 275a7ac1a7..e9d4e12bfc 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -34,6 +34,7 @@ #include "gui/debugger.h" +#include "macventure/debug.h" #include "macventure/gui.h" #include "macventure/world.h" #include "macventure/hufflists.h" @@ -65,13 +66,6 @@ enum { kScreenHeight = 342 }; -enum { - kMacVentureDebugExample = 1 << 0, - kMacVentureDebugExample2 = 1 << 1 - // next new level must be 1 << 2 (4) - // the current limitation is 32 debug levels (1 << 31 is the last one) -}; - enum { kGlobalSettingsID = 0x80, kDiplomaGeometryID = 0x81, @@ -191,6 +185,8 @@ public: virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); + void initDebugChannels(); + // datafiles.cpp void loadDataBundle(); Common::SeekableReadStream *getBorderFile(MVWindowType windowType, bool isActive); diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index ef1d36cbae..d191cefa12 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -51,14 +51,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debug(3, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debugC(3, kMVDebugScript, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debug(3, "SCRIPT: Resume"); + debugC(3, kMVDebugScript, "SCRIPT: Resume"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -146,7 +146,7 @@ bool ScriptEngine::execFrame(bool execAll) { bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { - debug(2, "SCRIPT: Loading function %d", scriptID); + debugC(2, kMVDebugScript, "SCRIPT: Loading function %d", scriptID); // Insert the new script at the front frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); return runFunc(frame); @@ -169,7 +169,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { byte op; while (script.hasNext()) { op = script.fetch(); - debug(3, "SCRIPT: I'm running operation %d", op); + debugC(3, kMVDebugScript, "SCRIPT: I'm running operation %d", op); if (!(op & 0x80)) { state->push(op); } else { @@ -924,12 +924,12 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; - debug(2, "SCRIPT: Call function: %d", id); + debugC(2, kMVDebugScript, "SCRIPT: Call function: %d", id); if (loadScript(frame, id)) return true; frame->scripts.pop_front(); script = frame->scripts.front(); - debug(2, "SCRIPT: Return from fuction %d", id); + debugC(2, kMVDebugScript, "SCRIPT: Return from fuction %d", id); } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1013,7 +1013,7 @@ void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { totalPlayTime %= 60; state->push(minutes); state->push(totalPlayTime); - debug("Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); + debugC(2, kMVDebugScript, "Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); } void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { @@ -1168,7 +1168,7 @@ void ScriptEngine::ope7CFIB(EngineState * state, EngineFrame * frame) { } void ScriptEngine::op00NOOP(byte op) { - debug("SCRIPT: Opcode not implemented => %x", op); + warning("SCRIPT: Opcode not implemented => %x", op); } @@ -1208,7 +1208,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } - debug(2, "SCRIPT: Load %d instructions for script %d", amount, _id); + debugC(2, kMVDebugScript, "SCRIPT: Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 0f9ea43afe..785c83ee0b 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -34,7 +34,7 @@ SoundManager::SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer) { Common::String filename = engine->getFilePath(kSoundPathID); _container = new Container(filename); _mixer = mixer; - debug(1, "Created sound manager with file %s", filename.c_str()); + debugC(1, kMVDebugSound, "Created sound manager with file %s", filename.c_str()); } SoundManager::~SoundManager(){ @@ -68,7 +68,7 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : stream->seek(5, SEEK_SET); SoundType type = (SoundType)stream->readByte(); - debug(2, "Decoding sound of type %x", type); + debugC(2, kMVDebugSound, "Decoding sound of type %x", type); switch(type) { case kSound10: decode10(stream); diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index ff9eddc040..f05b793ced 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -85,7 +85,7 @@ private: // HACK until a proper special char implementation is found, this will have to do. Common::String result = Common::String(str); toASCII(result); - debug(11, "Loaded string %s", str); + debugC(5, kMVDebugText, "Loaded string %s", str); _strings.push_back(Common::String(result)); delete[] str; } diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index cf7402822d..74b5685e7f 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -37,7 +37,7 @@ TextAsset::TextAsset(MacVentureEngine *engine, ObjID objid, ObjID source, ObjID } else { decodeHuffman(); - } + } } void TextAsset::decodeOld() { @@ -110,7 +110,7 @@ void TextAsset::decodeOld() { } str[strLen] = '\0'; - debug(7, "Decoded %d string (old): %s", _id, str); + debugC(3, kMVDebugText, "Decoded %d string (old): %s", _id, str); _decoded = Common::String(str); } @@ -136,7 +136,7 @@ void TextAsset::decodeHuffman() { // Find the length index for (entry = 0; entry < _huffman->getNumEntries(); entry++) { if (mask < _huffman->getMask(entry)) break; - } + } stream.skip(_huffman->getLength(entry)); @@ -171,10 +171,10 @@ void TextAsset::decodeHuffman() { } else { // Plain ascii c = symbol & 0xFF; _decoded.replace(_decoded.end(), _decoded.end(), Common::String(c)); - } + } } _decoded += '\0'; - debug(7, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); + debugC(4, kMVDebugText, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); } Common::String TextAsset::getNoun(ObjID subval) { ObjID obj; @@ -208,8 +208,8 @@ Common::String TextAsset::getNoun(ObjID subval) { name.toUppercase(); name.replace(1, name.size() - 1, tmp, 1, tmp.size() - 1); } - + return name; } -} // End of namespace MacVenture \ No newline at end of file +} // End of namespace MacVenture diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index f5af029f8f..012e872272 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -59,7 +59,7 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { res >>= _engine->getGlobalSettings().attrShifts[attrID]; if (res & 0x8000) res = -((res ^ 0xffff) + 1); - debug(6, "Attribute %x from object %x is %x", attrID, objID, res); + debugC(5, kMVDebugMain, "Attribute %x from object %x is %x", attrID, objID, res); return res; } -- cgit v1.2.3 From dd3527517690c3fdd065dfaacfef936666f139e0 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 7 Aug 2016 17:33:36 +0200 Subject: MACVENTURE: Add conditionals to engine destructors --- engines/macventure/debug.h | 3 +-- engines/macventure/macventure.cpp | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/engines/macventure/debug.h b/engines/macventure/debug.h index 8ee9ebe008..c223d01fe4 100644 --- a/engines/macventure/debug.h +++ b/engines/macventure/debug.h @@ -31,8 +31,7 @@ enum MacVentureDebugChannel { kMVDebugText = 1 << 3, kMVDebugScript = 1 << 4, kMVDebugSound = 1 << 5, - kMVDebugContainer = 1 << 6, - kMVDebugTests = 1 << 31 + kMVDebugContainer = 1 << 6 }; } // End namespace MacVenture diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index e1d1febd57..37a57ca423 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -56,9 +56,17 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD _debugger = NULL; _gui = NULL; + _scriptEngine = NULL; + _filenames = NULL; + + _decodingDirectArticles = NULL; + _decodingNamingArticles = NULL; + _decodingIndirectArticles = NULL; + _textHuffman = NULL; _soundManager = NULL; + _dataBundle = NULL; debug("MacVenture::MacVentureEngine()"); } @@ -67,10 +75,18 @@ MacVentureEngine::~MacVentureEngine() { debug("MacVenture::~MacVentureEngine()"); DebugMan.clearAllDebugChannels(); - delete _rnd; - delete _debugger; - delete _gui; - delete _scriptEngine; + + if (_rnd) + delete _rnd; + + if (_debugger) + delete _debugger; + + if (_gui) + delete _gui; + + if (_scriptEngine) + delete _scriptEngine; if (_filenames) delete _filenames; @@ -106,7 +122,6 @@ void MacVentureEngine::initDebugChannels() { Common::Error MacVentureEngine::run() { debug("MacVenture::MacVentureEngine::init()"); - initGraphics(kScreenWidth, kScreenHeight, true); _debugger = new Console(this); -- cgit v1.2.3 From 9676b6f7fe2c9f6ec94ebcce17da5f78c362b3ac Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 8 Aug 2016 17:54:13 +0200 Subject: MACVENTURE: Fix window resizing bug --- engines/macventure/gui.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 5fa746ce3d..66288d0906 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -589,13 +589,11 @@ void Gui::drawInventories() { Graphics::ManagedSurface *srf; for (uint i = 0; i < _inventoryWindows.size(); i++) { const WindowData &data = getWindowData((WindowReference)(kInventoryStart + i)); - srf = findWindow(data.refcon)->getSurface(); + Graphics::MacWindow *win = findWindow(data.refcon); + srf = win->getSurface(); + srf->clear(kColorGreen); BorderBounds border = borderBounds(data.type); - srf->fillRect(Common::Rect( - border.leftOffset, - border.topOffset, - srf->w + border.rightOffset, - srf->h + border.bottomOffset), kColorWhite); + srf->fillRect(srf->getBounds(), kColorWhite); drawObjectsInWindow(data.refcon, srf); if (MACVENTURE_DEBUG_GUI) { @@ -643,7 +641,7 @@ void Gui::drawConsoleWindow() { _consoleText->renderInto(srf, bounds.leftOffset); } -void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) { +void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface) { WindowData &data = findWindowData(target); BorderBounds border = borderBounds(data.type); Common::Point pos; @@ -652,16 +650,22 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * if (data.children.size() == 0) return; + Graphics::ManagedSurface *composeSurface = new Graphics::ManagedSurface(); + composeSurface->create( + surface->w - border.leftOffset - border.rightOffset, + surface->h - border.topOffset - border.bottomOffset, + surface->format); + composeSurface->clear(kColorGreen); + for (uint i = 0; i < data.children.size(); i++) { child = data.children[i].obj; mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); - pos += Common::Point(border.leftOffset, border.topOffset); pos -= data.scrollPos; ensureAssetLoaded(child); _assets[child]->blitInto( - surface, + composeSurface, pos.x, pos.y, mode); @@ -671,7 +675,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * child == _draggedObj.id) { _assets[child]->blitInto( - surface, pos.x, pos.y, kBlitOR); + composeSurface, pos.x, pos.y, kBlitOR); } } @@ -681,8 +685,10 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * testBounds.translate(-data.scrollPos.x, -data.scrollPos.y); surface->frameRect(testBounds, kColorGreen); } - } + Common::Point composePosition = Common::Point(border.leftOffset, border.topOffset); + surface->transBlitFrom(*composeSurface, composePosition, kColorGreen); + delete composeSurface; } void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { -- cgit v1.2.3 From 4f6609f704edf2ee38582cb2d2f17a7017d79732 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 8 Aug 2016 18:06:29 +0200 Subject: MACVENTURE: Refactor object drawing --- engines/macventure/gui.cpp | 24 ++++++++++++------------ engines/macventure/gui.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 66288d0906..caa756f755 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -564,7 +564,8 @@ void Gui::drawMainGameWindow() { border.topOffset, kBlitDirect); } - drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface()); + + drawObjectsInWindow(data, _mainGameWindow->getSurface()); if (MACVENTURE_DEBUG_GUI) { Graphics::MacWindow *win = findWindow(data.refcon); @@ -579,7 +580,7 @@ void Gui::drawMainGameWindow() { } void Gui::drawSelfWindow() { - drawObjectsInWindow(kSelfWindow, _selfWindow->getSurface()); + drawObjectsInWindow(getWindowData(kSelfWindow), _selfWindow->getSurface()); if (_engine->isObjSelected(1)) invertWindowColors(kSelfWindow); findWindow(kSelfWindow)->setDirty(true); } @@ -594,7 +595,7 @@ void Gui::drawInventories() { srf->clear(kColorGreen); BorderBounds border = borderBounds(data.type); srf->fillRect(srf->getBounds(), kColorWhite); - drawObjectsInWindow(data.refcon, srf); + drawObjectsInWindow(data, srf); if (MACVENTURE_DEBUG_GUI) { Graphics::MacWindow *win = findWindow(data.refcon); @@ -641,14 +642,13 @@ void Gui::drawConsoleWindow() { _consoleText->renderInto(srf, bounds.leftOffset); } -void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface) { - WindowData &data = findWindowData(target); - BorderBounds border = borderBounds(data.type); +void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSurface *surface) { + BorderBounds border = borderBounds(targetData.type); Common::Point pos; ObjID child; BlitMode mode; - if (data.children.size() == 0) return; + if (targetData.children.size() == 0) return; Graphics::ManagedSurface *composeSurface = new Graphics::ManagedSurface(); composeSurface->create( @@ -657,11 +657,11 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface->format); composeSurface->clear(kColorGreen); - for (uint i = 0; i < data.children.size(); i++) { - child = data.children[i].obj; - mode = (BlitMode)data.children[i].mode; + for (uint i = 0; i < targetData.children.size(); i++) { + child = targetData.children[i].obj; + mode = (BlitMode)targetData.children[i].mode; pos = _engine->getObjPosition(child); - pos -= data.scrollPos; + pos -= targetData.scrollPos; ensureAssetLoaded(child); _assets[child]->blitInto( @@ -682,7 +682,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * // For test if (MACVENTURE_DEBUG_GUI) { Common::Rect testBounds = _engine->getObjBounds(child); - testBounds.translate(-data.scrollPos.x, -data.scrollPos.y); + testBounds.translate(-targetData.scrollPos.x, -targetData.scrollPos.y); surface->frameRect(testBounds, kColorGreen); } } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index a62264cb6f..12b499ad30 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -219,7 +219,7 @@ private: // Methods void drawConsoleWindow(); void drawDraggedObject(); - void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface); + void drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSurface *surface); void drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface); void drawDialog(); -- cgit v1.2.3 From 560185903cf13dbb91ce916dc7347cec6f968c12 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 8 Aug 2016 18:36:51 +0200 Subject: MACVENTURE: Fix console drawing bug --- engines/macventure/gui.cpp | 14 +++++++++----- engines/macventure/gui.h | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index caa756f755..deb4a09a77 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -639,7 +639,7 @@ void Gui::drawConsoleWindow() { Graphics::ManagedSurface *srf = _outConsoleWindow->getSurface(); BorderBounds bounds = borderBounds(getWindowData(kOutConsoleWindow).type); - _consoleText->renderInto(srf, bounds.leftOffset); + _consoleText->renderInto(srf, bounds, kConsoleLeftOffset); } void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSurface *surface) { @@ -651,10 +651,7 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur if (targetData.children.size() == 0) return; Graphics::ManagedSurface *composeSurface = new Graphics::ManagedSurface(); - composeSurface->create( - surface->w - border.leftOffset - border.rightOffset, - surface->h - border.topOffset - border.bottomOffset, - surface->format); + createInnerSurface(composeSurface, surface, border); composeSurface->clear(kColorGreen); for (uint i = 0; i < targetData.children.size(); i++) { @@ -879,6 +876,13 @@ void Gui::saveInto(int slot) { _engine->preparedToRun(); } +void Gui::createInnerSurface(Graphics::ManagedSurface *innerSurface, Graphics::ManagedSurface *outerSurface, const BorderBounds &borders) { + innerSurface->create( + outerSurface->w - borders.leftOffset - borders.rightOffset, + outerSurface->h - borders.topOffset - borders.bottomOffset, + outerSurface->format); +} + void Gui::moveDraggedObject(Common::Point target) { ensureAssetLoaded(_draggedObj.id); _draggedObj.pos = target + _draggedObj.mouseOffset; diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 12b499ad30..7d1a08aa5b 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -161,6 +161,8 @@ public: void loadGame(int slot); void saveInto(int slot); + void createInnerSurface(Graphics::ManagedSurface *innerSurface, Graphics::ManagedSurface *outerSurface, const BorderBounds &borders); + private: // Attributes @@ -377,6 +379,10 @@ static void cursorTimerHandler(void *refCon) { } +enum { + kConsoleLeftOffset = 2 +}; + class ConsoleText { public: @@ -407,14 +413,23 @@ public: updateScroll(); } - void renderInto(Graphics::ManagedSurface *target, uint leftOffset) { + void renderInto(Graphics::ManagedSurface *target, const BorderBounds borders, int textOffset) { target->fillRect(target->getBounds(), kColorWhite); + + Graphics::ManagedSurface *composeSurface = new Graphics::ManagedSurface(); + _gui->createInnerSurface(composeSurface, target, borders); + composeSurface->clear(kColorGreen); + const Graphics::Font *font = &_gui->getCurrentFont(); uint y = target->h - font->getFontHeight(); for (uint i = _scrollPos; i != 0; i--) { - font->drawString(target, _lines[i], leftOffset, y, font->getStringWidth(_lines[i]), kColorBlack); + font->drawString(target, _lines[i], textOffset, y, font->getStringWidth(_lines[i]), kColorBlack); y -= font->getFontHeight(); } + + Common::Point composePosition = Common::Point(borders.leftOffset, borders.topOffset); + target->transBlitFrom(*composeSurface, composePosition, kColorGreen); + delete composeSurface; } void updateScroll() { -- cgit v1.2.3 From fd601f016f952f0a1b7fb4170fa05293813e7da5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 9 Aug 2016 13:06:42 +0200 Subject: MACVENTURE: Fix small if --- engines/macventure/macventure.cpp | 3 +-- engines/macventure/sound.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 37a57ca423..8b947d5790 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -205,7 +205,6 @@ Common::Error MacVentureEngine::run() { if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { endGame(); - return Common::kNoError; } } _gui->draw(); @@ -240,7 +239,6 @@ void MacVentureEngine::resetGui() { updateExits(); } - void MacVentureEngine::requestQuit() { // TODO: Display save game dialog and such _gameState = kGameStateQuitting; @@ -542,6 +540,7 @@ void MacVentureEngine::endGame() { } void MacVentureEngine::updateState(bool pause) { + _prepared = false; runObjQueue(); printTexts(); playSounds(pause); diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 785c83ee0b..ea3b2d94ee 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -39,7 +39,7 @@ SoundManager::SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer) { SoundManager::~SoundManager(){ if (_container) - delete _container; + delete _container; Common::HashMap::iterator it; for (it = _assets.begin(); it != _assets.end(); it++) { -- cgit v1.2.3 From 7f533ff7df2e54efc01a44a838cd8f67ddf551b0 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 9 Aug 2016 15:36:21 +0200 Subject: MACVENTURE: Fix double free on sound --- engines/macventure/macventure.cpp | 4 ++-- engines/macventure/sound.cpp | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 8b947d5790..beee71aae5 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -634,8 +634,8 @@ void MacVentureEngine::playSounds(bool pause) { } } if (pause && delay > 0) { - warning("Sound pausing not yet tested. Pausing for %d", delay * 1000); - g_system->delayMillis(delay * 1000); + warning("Sound pausing not yet tested. Pausing for %d", delay); + g_system->delayMillis(delay); preparedToRun(); } } diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index ea3b2d94ee..f05c88fcd6 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -42,7 +42,8 @@ SoundManager::~SoundManager(){ delete _container; Common::HashMap::iterator it; - for (it = _assets.begin(); it != _assets.end(); it++) { + Common::HashMap::iterator end = _assets.end(); + for (it = _assets.begin(); it != end; it++) { delete it->_value; } } @@ -60,7 +61,7 @@ void SoundManager::ensureLoaded(ObjID sound) { SoundAsset::SoundAsset(Container *container, ObjID id) : _container(container), _id(id), _length(0), _frequency(1) { - + debug("SoundAsset::SoundAsset(%d)", _id); if (_container->getItemByteSize(_id) == 0) warning("Trying to load an empty sound asset."); @@ -99,17 +100,19 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : delete stream; } -SoundAsset::~SoundAsset() {} +SoundAsset::~SoundAsset() { + debug("SoundAsset::~SoundAsset(%d)", _id); +} void SoundAsset::play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle) { if (_data.size() == 0) return; - Audio::AudioStream *sound = Audio::makeRawStream(&_data.front(), _length, _frequency, Audio::FLAG_UNSIGNED); + Audio::AudioStream *sound = Audio::makeRawStream(&_data.front(), _length, _frequency, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO); mixer->playStream(Audio::Mixer::kPlainSoundType, soundHandle, sound); } uint32 SoundAsset::getPlayLength() { - - return _length / _frequency; + // Transform to milliseconds + return _length * 1000 / _frequency; } void SoundAsset::decode10(Common::SeekableReadStream *stream) { -- cgit v1.2.3 From 5c38a0c33b3c7487fcfa441c4d6406c5decce809 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 9 Aug 2016 19:55:43 +0200 Subject: MACVENTURE: Add win game dialog --- engines/macventure/dialog.cpp | 36 ++++++++++++++++++++++----------- engines/macventure/gui.cpp | 23 +++++++++++++-------- engines/macventure/gui.h | 7 ++++--- engines/macventure/macventure.cpp | 3 +++ engines/macventure/prebuilt_dialogs.cpp | 12 +++++++++++ engines/macventure/prebuilt_dialogs.h | 6 +++++- 6 files changed, 63 insertions(+), 24 deletions(-) diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index fe01d8fd8a..7cbf0cb610 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -45,18 +45,30 @@ Dialog::~Dialog() { } void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { - switch(action) { - case kDACloseDialog: - _gui->closeDialog(); - break; - case kDASubmit: - _gui->setTextInput(_userInput); - _gui->closeDialog(); - break; - case kDASaveAs: - _gui->saveInto(0); - _gui->closeDialog(); - break; + switch(action) { + case kDACloseDialog: + _gui->closeDialog(); + break; + case kDASubmit: + _gui->setTextInput(_userInput); + _gui->closeDialog(); + break; + case kDASaveAs: + _gui->saveGame(); + _gui->closeDialog(); + break; + case kDALoadGame: + _gui->loadGame(); + _gui->closeDialog(); + break; + case kDANewGame: + _gui->newGame(); + _gui->closeDialog(); + break; + case kDAQuit: + _gui->quitGame(); + _gui->closeDialog(); + break; } } diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index deb4a09a77..6c8122d156 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -867,13 +867,20 @@ void Gui::getTextFromUser() { showPrebuiltDialog(kSpeakDialog); } -void Gui::loadGame(int slot) { - _engine->loadGameState(slot); +void Gui::loadGame() { + _engine->scummVMSaveLoadDialog(false); } -void Gui::saveInto(int slot) { - _engine->saveGameState(slot, "desc"); - _engine->preparedToRun(); +void Gui::saveGame() { + _engine->scummVMSaveLoadDialog(true); +} + +void Gui::newGame() { + warning("New Game not implemented!"); +} + +void Gui::quitGame() { + _engine->requestQuit(); } void Gui::createInnerSurface(Graphics::ManagedSurface *innerSurface, Graphics::ManagedSurface *outerSurface, const BorderBounds &borders) { @@ -1098,13 +1105,13 @@ void Gui::handleMenuAction(MenuAction action) { warning("Unimplemented MacVenture Menu Action: New"); break; case MacVenture::kMenuActionOpen: - _engine->scummVMSaveLoadDialog(false); + loadGame(); break; case MacVenture::kMenuActionSave: - _engine->scummVMSaveLoadDialog(true); + saveGame(); break; case MacVenture::kMenuActionSaveAs: - _engine->scummVMSaveLoadDialog(true); + saveGame(); break; case MacVenture::kMenuActionQuit: debug("MacVenture Menu Action: Quit"); diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 7d1a08aa5b..185171f6b9 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -157,9 +157,10 @@ public: void setTextInput(Common::String str); void closeDialog(); - // TODO: Currently unused, we are using ScummVM dialogs instead. - void loadGame(int slot); - void saveInto(int slot); + void loadGame(); + void saveGame(); + void newGame(); + void quitGame(); void createInnerSurface(Graphics::ManagedSurface *innerSurface, Graphics::ManagedSurface *outerSurface, const BorderBounds &borders); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index beee71aae5..a1b2387a87 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -293,10 +293,13 @@ void MacVentureEngine::gameChanged() { } void MacVentureEngine::winGame() { + _gui->showPrebuiltDialog(kWinGameDialog); _gameState = kGameStateWinnig; } void MacVentureEngine::loseGame() { + _gui->showPrebuiltDialog(kWinGameDialog); + _paused = true; _gameState = kGameStateLosing; } diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp index 13d2d446bf..945808bfcc 100644 --- a/engines/macventure/prebuilt_dialogs.cpp +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -47,6 +47,18 @@ PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} } +}, + + { /* kWinGameDialog */ + Common::Rect(20, 100, 400, 200), + { + {kDEPlainText, "You Won!", kDANone, Common::Point(10, 10), 400, 20}, + {kDEPlainText, "What do you want to do?", kDANone, Common::Point(10, 30), 400, 20}, + {kDEButton, "New Game", kDANewGame, Common::Point(40, 30), 50, 20}, + {kDEButton, "Load", kDALoadGame, Common::Point(100, 30), 50, 20}, + {kDEButton, "Quit", kDAQuit, Common::Point(160, 30), 50, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } } }; diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 58e8f0b823..5deda1b7e9 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -31,12 +31,16 @@ enum DialogAction { kDANone, kDACloseDialog, kDASubmit, - kDASaveAs + kDASaveAs, + kDALoadGame, + kDAQuit, + kDANewGame }; enum PrebuiltDialogs { kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead. kSpeakDialog = 1, + kWinGameDialog = 2, kPrebuiltDialogCount }; -- cgit v1.2.3 From 90298b00d359ac3895a93a32813a95fea4e3efab Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 9 Aug 2016 20:13:08 +0200 Subject: MACVENTURE: Fix indentation in dialog system --- engines/macventure/dialog.cpp | 253 ++++++++++++++++---------------- engines/macventure/dialog.h | 79 +++++----- engines/macventure/prebuilt_dialogs.cpp | 65 ++++---- engines/macventure/prebuilt_dialogs.h | 50 +++---- 4 files changed, 223 insertions(+), 224 deletions(-) diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 7cbf0cb610..0edec40c4d 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -27,216 +27,215 @@ namespace MacVenture { Dialog::Dialog(Gui *gui, Common::Point pos, uint width, uint height) : - _gui(gui), _bounds(Common::Rect(pos.x, pos.y, pos.x + width, pos.y + height)) {} + _gui(gui), _bounds(Common::Rect(pos.x, pos.y, pos.x + width, pos.y + height)) {} Dialog::Dialog(Gui *gui, PrebuiltDialogs prebuilt) { - _gui = gui; - const PrebuiltDialog &dialog = prebuiltDialogs[prebuilt]; - _bounds = dialog.bounds; - for (int i = 0; dialog.elements[i].type != kDEEnd; i++) { - addPrebuiltElement(dialog.elements[i]); - } + _gui = gui; + const PrebuiltDialog &dialog = prebuiltDialogs[prebuilt]; + _bounds = dialog.bounds; + for (int i = 0; dialog.elements[i].type != kDEEnd; i++) { + addPrebuiltElement(dialog.elements[i]); + } } Dialog::~Dialog() { - for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { - delete *it; - } + for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { + delete *it; + } } void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { switch(action) { - case kDACloseDialog: - _gui->closeDialog(); - break; - case kDASubmit: - _gui->setTextInput(_userInput); - _gui->closeDialog(); - break; - case kDASaveAs: - _gui->saveGame(); - _gui->closeDialog(); - break; - case kDALoadGame: - _gui->loadGame(); - _gui->closeDialog(); - break; - case kDANewGame: - _gui->newGame(); - _gui->closeDialog(); - break; - case kDAQuit: - _gui->quitGame(); - _gui->closeDialog(); - break; + case kDACloseDialog: + _gui->closeDialog(); + break; + case kDASubmit: + _gui->setTextInput(_userInput); + _gui->closeDialog(); + break; + case kDASaveAs: + _gui->saveGame(); + _gui->closeDialog(); + break; + case kDALoadGame: + _gui->loadGame(); + _gui->closeDialog(); + break; + case kDANewGame: + _gui->newGame(); + _gui->closeDialog(); + break; + case kDAQuit: + _gui->quitGame(); + _gui->closeDialog(); + break; + default: + break; } } const Graphics::Font& Dialog::getFont() { - return _gui->getCurrentFont(); + return _gui->getCurrentFont(); } bool Dialog::processEvent(Common::Event event) { - for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { - if ((*it)->processEvent(this, event)) return true; - } + for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { + if ((*it)->processEvent(this, event)) return true; + } } void Dialog::addButton(Common::String title, MacVenture::DialogAction action, Common::Point position, uint width, uint height) { - _elements.push_back(new DialogButton(this, title, action, position, width, height)); + _elements.push_back(new DialogButton(this, title, action, position, width, height)); } void Dialog::addText(Common::String content, Common::Point position) { - _elements.push_back(new DialogPlainText(this, content, position)); + _elements.push_back(new DialogPlainText(this, content, position)); } void Dialog::addTextInput(Common::Point position, int width, int height) { - _elements.push_back(new DialogTextInput(this, position, width, height)); + _elements.push_back(new DialogTextInput(this, position, width, height)); } void Dialog::draw() { - Graphics::ManagedSurface compose; - // Compose the surface - compose.create(_bounds.width(), _bounds.height()); - Common::Rect base(0, 0, _bounds.width(), _bounds.height()); - compose.fillRect(base, kColorWhite); - compose.frameRect(base, kColorBlack); - for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { - (*it)->draw(this, compose); - } - - g_system->copyRectToScreen(compose.getPixels(), compose.pitch, - _bounds.left, _bounds.top, _bounds.width(), _bounds.height()); -} + Graphics::ManagedSurface compose; + // Compose the surface + compose.create(_bounds.width(), _bounds.height()); + Common::Rect base(0, 0, _bounds.width(), _bounds.height()); + compose.fillRect(base, kColorWhite); + compose.frameRect(base, kColorBlack); + for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { + (*it)->draw(this, compose); + } + + g_system->copyRectToScreen(compose.getPixels(), compose.pitch, + _bounds.left, _bounds.top, _bounds.width(), _bounds.height()); + } void Dialog::localize(Common::Point &point) { - point.x -= _bounds.left; - point.y -= _bounds.top; + point.x -= _bounds.left; + point.y -= _bounds.top; } void Dialog::setUserInput(Common::String content) { - _userInput = content; + _userInput = content; } void Dialog::addPrebuiltElement(const MacVenture::PrebuiltDialogElement &element) { - switch(element.type) { - case kDEButton: - addButton(element.title, element.action, element.position, element.width, element.height); - break; - case kDEPlainText: - addText(element.title, element.position); - break; - case kDETextInput: - addTextInput(element.position, element.width, element.height); - break; - } + switch(element.type) { + case kDEButton: + addButton(element.title, element.action, element.position, element.width, element.height); + break; + case kDEPlainText: + addText(element.title, element.position); + break; + case kDETextInput: + addTextInput(element.position, element.width, element.height); + break; + default: + break; + } } // Dialog Element DialogElement::DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width, uint height) : - _text(title), _action(action) { - if (width == 0) { - width = dialog->getFont().getStringWidth(title); - } - if (height == 0) { - height = dialog->getFont().getFontHeight(); - } - _bounds = Common::Rect(position.x, position.y, position.x + width, position.y + height); - } + _text(title), _action(action) { + if (width == 0) { + width = dialog->getFont().getStringWidth(title); + } + if (height == 0) { + height = dialog->getFont().getFontHeight(); + } + _bounds = Common::Rect(position.x, position.y, position.x + width, position.y + height); +} bool DialogElement::processEvent(MacVenture::Dialog *dialog, Common::Event event) { - return doProcessEvent(dialog, event); + return doProcessEvent(dialog, event); } void DialogElement::draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { - doDraw(dialog, target); + doDraw(dialog, target); } const Common::String& DialogElement::getText() { - return doGetText(); + return doGetText(); } const Common::String& DialogElement::doGetText() { - return _text; + return _text; } // CONCRETE DIALOG ELEMENTS DialogButton::DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width, uint height): - DialogElement(dialog, title, action, position, width, height) {} + DialogElement(dialog, title, action, position, width, height) {} bool DialogButton::doProcessEvent(MacVenture::Dialog *dialog, Common::Event event) { - Common::Point mouse = event.mouse; - if (event.type == Common::EVENT_LBUTTONDOWN) { - dialog->localize(mouse); - if (_bounds.contains(mouse)) { - debugC(1, kMVDebugGUI, "Click! Button: %s", _text.c_str()); - dialog->handleDialogAction(this, _action); - return true; - } - } - return false; + Common::Point mouse = event.mouse; + if (event.type == Common::EVENT_LBUTTONDOWN) { + dialog->localize(mouse); + if (_bounds.contains(mouse)) { + debugC(1, kMVDebugGUI, "Click! Button: %s", _text.c_str()); + dialog->handleDialogAction(this, _action); + return true; + } + } + return false; } void DialogButton::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { - target.fillRect(_bounds, kColorWhite); - target.frameRect(_bounds, kColorBlack); - // Draw title - dialog->getFont().drawString( - &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); + target.fillRect(_bounds, kColorWhite); + target.frameRect(_bounds, kColorBlack); + // Draw title + dialog->getFont().drawString( + &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); } DialogPlainText::DialogPlainText(Dialog *dialog, Common::String content, Common::Point position) : - DialogElement(dialog, content, kDANone, position, 0, 0) { } + DialogElement(dialog, content, kDANone, position, 0, 0) { } DialogPlainText::~DialogPlainText() {} bool DialogPlainText::doProcessEvent(MacVenture::Dialog *dialog, Common::Event event) { - return false; + return false; } void DialogPlainText::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { - // Draw contents - dialog->getFont().drawString( - &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); + // Draw contents + dialog->getFont().drawString( + &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack, Graphics::kTextAlignCenter); } DialogTextInput::DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height) : - DialogElement(dialog, "", kDANone, position, width, height) {} + DialogElement(dialog, "", kDANone, position, width, height) {} DialogTextInput::~DialogTextInput() {} bool DialogTextInput::doProcessEvent(Dialog *dialog, Common::Event event) { - if (event.type == Common::EVENT_KEYDOWN) { - switch (event.kbd.keycode) { - case Common::KEYCODE_BACKSPACE: - if (!_text.empty()) { - _text.deleteLastChar(); - dialog->setUserInput(_text); - return true; - } - break; - - default: - if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) { - _text += (char)event.kbd.ascii; - dialog->setUserInput(_text); - return true; - } - - break; + if (event.type == Common::EVENT_KEYDOWN) { + switch (event.kbd.keycode) { + case Common::KEYCODE_BACKSPACE: + if (!_text.empty()) { + _text.deleteLastChar(); + dialog->setUserInput(_text); + return true; + } + break; + default: + if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) { + _text += (char)event.kbd.ascii; + dialog->setUserInput(_text); + return true; + } + break; } } return false; } + void DialogTextInput::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { - target.fillRect(_bounds, kColorWhite); - target.frameRect(_bounds, kColorBlack); - dialog->getFont().drawString( - &target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack); + target.fillRect(_bounds, kColorWhite); + target.frameRect(_bounds, kColorBlack); + dialog->getFont().drawString(&target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack); } - - - } // End of namespace MacVenture diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index a01011f2b8..2ea38b1548 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -35,85 +35,86 @@ class Gui; class DialogElement; extern PrebuiltDialog prebuiltDialogs[]; - class Dialog { public: Dialog(Gui *gui, Common::Point pos, uint width, uint height); - Dialog(Gui *gui, PrebuiltDialogs prebuilt); + Dialog(Gui *gui, PrebuiltDialogs prebuilt); ~Dialog(); - bool processEvent(Common::Event event); - void draw(); - void localize(Common::Point &point); - void handleDialogAction(DialogElement *trigger, DialogAction action); + bool processEvent(Common::Event event); + void draw(); + void localize(Common::Point &point); + void handleDialogAction(DialogElement *trigger, DialogAction action); - const Graphics::Font& getFont(); + const Graphics::Font& getFont(); - void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); - void addText(Common::String content, Common::Point position); - void addTextInput(Common::Point position, int width, int height); + void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); + void addText(Common::String content, Common::Point position); + void addTextInput(Common::Point position, int width, int height); - void setUserInput(Common::String content); + void setUserInput(Common::String content); private: - void addPrebuiltElement(const PrebuiltDialogElement &element); + void addPrebuiltElement(const PrebuiltDialogElement &element); private: - Gui *_gui; + Gui *_gui; - Common::String _userInput; - Common::Array _elements; - Common::Rect _bounds; + Common::String _userInput; + Common::Array _elements; + Common::Rect _bounds; }; class DialogElement { public: - DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); - virtual ~DialogElement() {} + DialogElement(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); + virtual ~DialogElement() {} - bool processEvent(Dialog *dialog, Common::Event event); - void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); - const Common::String& getText(); + bool processEvent(Dialog *dialog, Common::Event event); + void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); + const Common::String& getText(); private: - virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0; - virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0; - virtual const Common::String& doGetText(); + virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0; + virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0; + virtual const Common::String& doGetText(); protected: - Common::String _text; - Common::Rect _bounds; - DialogAction _action; + Common::String _text; + Common::Rect _bounds; + DialogAction _action; }; // Dialog elements class DialogButton : public DialogElement { public: - DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); - ~DialogButton() {} + DialogButton(Dialog *dialog, Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); + ~DialogButton() {} private: - bool doProcessEvent(Dialog *dialog, Common::Event event); - void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); + bool doProcessEvent(Dialog *dialog, Common::Event event); + void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); }; class DialogPlainText : public DialogElement { public: - DialogPlainText(Dialog *dialog, Common::String content, Common::Point position); - ~DialogPlainText(); + DialogPlainText(Dialog *dialog, Common::String content, Common::Point position); + ~DialogPlainText(); + private: - bool doProcessEvent(Dialog *dialog, Common::Event event); - void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); + bool doProcessEvent(Dialog *dialog, Common::Event event); + void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); }; class DialogTextInput : public DialogElement { public: - DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height); - ~DialogTextInput(); + DialogTextInput(Dialog *dialog, Common::Point position, uint width, uint height); + ~DialogTextInput(); + private: - bool doProcessEvent(Dialog *dialog, Common::Event event); - void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); + bool doProcessEvent(Dialog *dialog, Common::Event event); + void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); }; } // End of namespace MacVenture diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp index 945808bfcc..bb9ea65b68 100644 --- a/engines/macventure/prebuilt_dialogs.cpp +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -26,40 +26,39 @@ namespace MacVenture { PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { - {/* kSaveAsDialog */ - Common::Rect(0, 146, 456, 254), - { - {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, - {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, - {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, - {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - }, + {/* kSaveAsDialog */ + Common::Rect(0, 146, 456, 254), + { + {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, + {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, + {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, + {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + }, - { /* kSpeakDialog */ - Common::Rect(20, 92, 400, 200), - { - {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, - {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, - {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } -}, - - { /* kWinGameDialog */ - Common::Rect(20, 100, 400, 200), - { - {kDEPlainText, "You Won!", kDANone, Common::Point(10, 10), 400, 20}, - {kDEPlainText, "What do you want to do?", kDANone, Common::Point(10, 30), 400, 20}, - {kDEButton, "New Game", kDANewGame, Common::Point(40, 30), 50, 20}, - {kDEButton, "Load", kDALoadGame, Common::Point(100, 30), 50, 20}, - {kDEButton, "Quit", kDAQuit, Common::Point(160, 30), 50, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - } + { /* kSpeakDialog */ + Common::Rect(20, 92, 400, 200), + { + {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, + {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, + {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + }, + { /* kWinGameDialog */ + Common::Rect(20, 100, 400, 200), + { + {kDEPlainText, "You Won!", kDANone, Common::Point(10, 10), 400, 20}, + {kDEPlainText, "What do you want to do?", kDANone, Common::Point(10, 30), 400, 20}, + {kDEButton, "New Game", kDANewGame, Common::Point(40, 30), 50, 20}, + {kDEButton, "Load", kDALoadGame, Common::Point(100, 30), 50, 20}, + {kDEButton, "Quit", kDAQuit, Common::Point(160, 30), 50, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + } }; } // End of namespace MacVenture diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 5deda1b7e9..4c6f386770 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -28,47 +28,47 @@ namespace MacVenture { enum DialogAction { - kDANone, - kDACloseDialog, - kDASubmit, - kDASaveAs, - kDALoadGame, - kDAQuit, - kDANewGame + kDANone, + kDACloseDialog, + kDASubmit, + kDASaveAs, + kDALoadGame, + kDAQuit, + kDANewGame }; enum PrebuiltDialogs { - kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead. - kSpeakDialog = 1, - kWinGameDialog = 2, - kPrebuiltDialogCount + kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead. + kSpeakDialog = 1, + kWinGameDialog = 2, + kPrebuiltDialogCount }; enum PrebuiltElementType { - kDEPlainText, - kDEButton, - kDETextInput, - kDEEnd + kDEPlainText, + kDEButton, + kDETextInput, + kDEEnd }; struct PrebuiltDialogElement { - PrebuiltElementType type; - Common::String title; - DialogAction action; - Common::Point position; - uint width; - uint height; + PrebuiltElementType type; + Common::String title; + DialogAction action; + Common::Point position; + uint width; + uint height; }; // Prebuilt dialogs enum { - // HACK - kMaxPrebuiltDialogElements = 10 + // HACK + kMaxPrebuiltDialogElements = 10 }; struct PrebuiltDialog { - Common::Rect bounds; - PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; + Common::Rect bounds; + PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; }; } // End of namespace MacVenture -- cgit v1.2.3 From c8a2b0afe29da6daab4f448f1eb0acc108cdf8ae Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 10 Aug 2016 16:40:24 +0200 Subject: MACVENTURE: Fix engine mause in dialog --- engines/macventure/gui.cpp | 2 +- engines/macventure/macventure.cpp | 16 ++++++++++------ engines/macventure/macventure.h | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 6c8122d156..2c2e4b5281 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -876,7 +876,7 @@ void Gui::saveGame() { } void Gui::newGame() { - warning("New Game not implemented!"); + _engine->newGame(); } void Gui::quitGame() { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index a1b2387a87..b3b3463cf5 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -182,9 +182,9 @@ Common::Error MacVentureEngine::run() { while (_gameState != kGameStateQuitting) { processEvents(); - if (_gameState != kGameStateQuitting) { + if (_gameState != kGameStateQuitting && !_gui->isDialogOpen()) { - if (_prepared && !_gui->isDialogOpen()) { + if (_prepared) { _prepared = false; if (!_halted) @@ -207,16 +207,20 @@ Common::Error MacVentureEngine::run() { endGame(); } } - _gui->draw(); - - g_system->updateScreen(); - g_system->delayMillis(50); } + _gui->draw(); + + g_system->updateScreen(); + g_system->delayMillis(50); } return Common::kNoError; } +void MacVentureEngine::newGame() { + warning("New Game not implemented!"); +} + void MacVentureEngine::reset() { resetInternals(); resetGui(); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index e9d4e12bfc..576fd9b323 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -184,6 +184,7 @@ public: bool canSaveGameStateCurrently(); virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); + void newGame(); void initDebugChannels(); -- cgit v1.2.3 From 1d5b7a6e19377c0b279c337ef4ca60749b31f6c9 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 10 Aug 2016 16:45:14 +0200 Subject: MACVENTURE: Refactor world to extract new game method --- engines/macventure/macventure.cpp | 2 +- engines/macventure/world.cpp | 33 ++++++++++++++++++++++----------- engines/macventure/world.h | 2 ++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index b3b3463cf5..37e1472338 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -304,7 +304,7 @@ void MacVentureEngine::winGame() { void MacVentureEngine::loseGame() { _gui->showPrebuiltDialog(kWinGameDialog); _paused = true; - _gameState = kGameStateLosing; + //_gameState = kGameStateLosing; } void MacVentureEngine::clickToContinue() { diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 012e872272..2c9b55c6ab 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -8,25 +8,17 @@ namespace MacVenture { World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _resourceManager = resMan; _engine = engine; + _saveGame = NULL; - if ((_startGameFileName = _engine->getStartGameFileName()) == "") - error("Could not load initial game configuration"); - Common::File saveGameFile; - if (!saveGameFile.open(_startGameFileName)) - error("Could not load initial game configuration"); + startNewGame(); - debug("Loading save game state from %s", _startGameFileName.c_str()); - Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); + //_-------------------- - _saveGame = new SaveGame(_engine, saveGameRes); _objectConstants = new Container(_engine->getFilePath(kObjectPathID)); calculateObjectRelations(); _gameText = new Container(_engine->getFilePath(kTextPathID)); - - delete saveGameRes; - saveGameFile.close(); } @@ -39,6 +31,25 @@ World::~World() { delete _objectConstants; } +void World::startNewGame() { + if (_saveGame) + delete _saveGame; + + if ((_startGameFileName = _engine->getStartGameFileName()) == "") + error("Could not load initial game configuration"); + + Common::File saveGameFile; + if (!saveGameFile.open(_startGameFileName)) + error("Could not load initial game configuration"); + + debug("Loading save game state from %s", _startGameFileName.c_str()); + Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); + + _saveGame = new SaveGame(_engine, saveGameRes); + + delete saveGameRes; + saveGameFile.close(); +} uint32 World::getObjAttr(ObjID objID, uint32 attrID) { uint res; diff --git a/engines/macventure/world.h b/engines/macventure/world.h index f3933c5f7e..e78ab7f0db 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -92,6 +92,8 @@ public: World(MacVentureEngine *engine, Common::MacResManager *resMan); ~World(); + void startNewGame(); + void setObjAttr(ObjID objID, uint32 attrID, Attribute value); void setGlobal(uint32 attrID, Attribute value); void updateObj(ObjID objID); -- cgit v1.2.3 From 0cd9e876297872269d83f38e93e6525dd4efd8e5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 10 Aug 2016 17:05:05 +0200 Subject: MACVENTURE: Add 'new game' functionality --- engines/macventure/macventure.cpp | 51 +++++++++++++++++++++++++-------------- engines/macventure/macventure.h | 10 +++++--- engines/macventure/world.cpp | 5 ++-- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 37e1472338..0a27babb26 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -153,15 +153,7 @@ Common::Error MacVentureEngine::run() { _soundManager = new SoundManager(this, _mixer); - _paused = false; - _halted = false; - _cmdReady = false; - _haltedAtEnd = false; - _haltedInSelection = false; - _clickToContinue = true; - _gameState = kGameStateInit; - _destObject = 0; - _prepared = true; + setInitialFlags(); int directSaveSlotLoading = ConfMan.getInt("save_slot"); if (directSaveSlotLoading >= 0) { @@ -169,10 +161,7 @@ Common::Error MacVentureEngine::run() { error("Could not load game from slot '%d'", directSaveSlotLoading); } } else { - _cmdReady = true; - ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); - _currentSelection.push_back(playerParent);// Push the parent of the player - _world->setObjAttr(playerParent, kAttrContainerOpen, 1); + setNewGameState(); } _selectedControl = kStartOrResume; @@ -208,17 +197,42 @@ Common::Error MacVentureEngine::run() { } } } - _gui->draw(); - - g_system->updateScreen(); - g_system->delayMillis(50); + refreshScreen(); } return Common::kNoError; } +void MacVentureEngine::refreshScreen() { + _gui->draw(); + g_system->updateScreen(); + g_system->delayMillis(50); +} + void MacVentureEngine::newGame() { - warning("New Game not implemented!"); + _world->startNewGame(); + reset(); + setInitialFlags(); + setNewGameState(); +} + +void MacVentureEngine::setInitialFlags() { + _paused = false; + _halted = false; + _cmdReady = false; + _haltedAtEnd = false; + _haltedInSelection = false; + _clickToContinue = true; + _gameState = kGameStateInit; + _destObject = 0; + _prepared = true; +} + +void MacVentureEngine::setNewGameState() { + _cmdReady = true; + ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); + _currentSelection.push_back(playerParent);// Push the parent of the player + _world->setObjAttr(playerParent, kAttrContainerOpen, 1); } void MacVentureEngine::reset() { @@ -241,6 +255,7 @@ void MacVentureEngine::resetGui() { _gui->updateWindowInfo(kInventoryStart, 1, _world->getChildren(1, true)); updateControls(); updateExits(); + refreshScreen(); } void MacVentureEngine::requestQuit() { diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 576fd9b323..3f0ce0cc7b 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -185,17 +185,19 @@ public: virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); void newGame(); + void setInitialFlags(); + void setNewGameState(); void initDebugChannels(); + void reset(); + void resetInternals(); + void resetGui(); + void refreshScreen(); // datafiles.cpp void loadDataBundle(); Common::SeekableReadStream *getBorderFile(MVWindowType windowType, bool isActive); - void reset(); - void resetInternals(); - void resetGui(); - void requestQuit(); void requestUnpause(); void selectControl(ControlAction action); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 2c9b55c6ab..82a8952f02 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -10,11 +10,8 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _engine = engine; _saveGame = NULL; - startNewGame(); - //_-------------------- - _objectConstants = new Container(_engine->getFilePath(kObjectPathID)); calculateObjectRelations(); @@ -47,6 +44,8 @@ void World::startNewGame() { _saveGame = new SaveGame(_engine, saveGameRes); + calculateObjectRelations(); + delete saveGameRes; saveGameFile.close(); } -- cgit v1.2.3 From 02138548aeb91ee6d435dc71763c74bfed125121 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 10 Aug 2016 17:22:46 +0200 Subject: MACVENTURE: Fix win game dialog --- engines/macventure/prebuilt_dialogs.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp index bb9ea65b68..76d2c15ed4 100644 --- a/engines/macventure/prebuilt_dialogs.cpp +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -50,13 +50,13 @@ PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { }, { /* kWinGameDialog */ - Common::Rect(20, 100, 400, 200), + Common::Rect(20, 100, 320, 200), { - {kDEPlainText, "You Won!", kDANone, Common::Point(10, 10), 400, 20}, - {kDEPlainText, "What do you want to do?", kDANone, Common::Point(10, 30), 400, 20}, - {kDEButton, "New Game", kDANewGame, Common::Point(40, 30), 50, 20}, - {kDEButton, "Load", kDALoadGame, Common::Point(100, 30), 50, 20}, - {kDEButton, "Quit", kDAQuit, Common::Point(160, 30), 50, 20}, + {kDEPlainText, "You Won!", kDANone, Common::Point(20, 16), 280, 20}, + {kDEPlainText, "What do you want to do?", kDANone, Common::Point(20, 30), 280, 20}, + {kDEButton, "New Game", kDANewGame, Common::Point(20, 60), 70, 20}, + {kDEButton, "Load", kDALoadGame, Common::Point(110, 60), 70, 20}, + {kDEButton, "Quit", kDAQuit, Common::Point(200, 60), 70, 20}, {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} } } -- cgit v1.2.3 From e886f2c6e170ae2af96371c5c3e035cef8a05827 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 10 Aug 2016 17:28:55 +0200 Subject: MACVENTURE: Add lose game dialog --- engines/macventure/macventure.cpp | 2 +- engines/macventure/prebuilt_dialogs.cpp | 12 ++++++++++++ engines/macventure/prebuilt_dialogs.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 0a27babb26..a18bdcfef2 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -317,7 +317,7 @@ void MacVentureEngine::winGame() { } void MacVentureEngine::loseGame() { - _gui->showPrebuiltDialog(kWinGameDialog); + _gui->showPrebuiltDialog(kLoseGameDialog); _paused = true; //_gameState = kGameStateLosing; } diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp index 76d2c15ed4..46b71ab93a 100644 --- a/engines/macventure/prebuilt_dialogs.cpp +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -59,6 +59,18 @@ PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { {kDEButton, "Quit", kDAQuit, Common::Point(200, 60), 70, 20}, {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} } + }, + + { /* kLoseGameDialog */ + Common::Rect(20, 100, 320, 200), + { + {kDEPlainText, "You Died", kDANone, Common::Point(20, 16), 280, 20}, + {kDEPlainText, "What do you want to do?", kDANone, Common::Point(20, 30), 280, 20}, + {kDEButton, "New Game", kDANewGame, Common::Point(20, 60), 70, 20}, + {kDEButton, "Load", kDALoadGame, Common::Point(110, 60), 70, 20}, + {kDEButton, "Quit", kDAQuit, Common::Point(200, 60), 70, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } } }; } // End of namespace MacVenture diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 4c6f386770..1c97847455 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -41,6 +41,7 @@ enum PrebuiltDialogs { kSaveAsDialog = 0, //TODO: Currently unused, we are using ScummVM dialogs instead. kSpeakDialog = 1, kWinGameDialog = 2, + kLoseGameDialog = 3, kPrebuiltDialogCount }; -- cgit v1.2.3 From 896e08cde8cd13d0ba3c4c7df253d4619e3b5933 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 11 Aug 2016 09:17:23 +0200 Subject: MACVENTURE: Add proper flags to gui debug rects --- engines/macventure/gui.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 2c2e4b5281..56381369bb 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -22,6 +22,8 @@ #include "common/file.h" #include "common/system.h" +#include "common/debug-channels.h" +#include "common/debug.h" #include "image/bmp.h" #include "macventure/gui.h" @@ -29,8 +31,6 @@ namespace MacVenture { -#define MACVENTURE_DEBUG_GUI true - enum MenuAction; enum { @@ -567,7 +567,7 @@ void Gui::drawMainGameWindow() { drawObjectsInWindow(data, _mainGameWindow->getSurface()); - if (MACVENTURE_DEBUG_GUI) { + if (DebugMan.isDebugChannelEnabled(kMVDebugGUI)) { Graphics::MacWindow *win = findWindow(data.refcon); Common::Rect innerDims = win->getInnerDimensions(); int x = win->getDimensions().left; @@ -597,7 +597,7 @@ void Gui::drawInventories() { srf->fillRect(srf->getBounds(), kColorWhite); drawObjectsInWindow(data, srf); - if (MACVENTURE_DEBUG_GUI) { + if (DebugMan.isDebugChannelEnabled(kMVDebugGUI)) { Graphics::MacWindow *win = findWindow(data.refcon); Common::Rect innerDims = win->getInnerDimensions(); int x = win->getDimensions().left; @@ -676,8 +676,7 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur } } - // For test - if (MACVENTURE_DEBUG_GUI) { + if (DebugMan.isDebugChannelEnabled(kMVDebugGUI)) { Common::Rect testBounds = _engine->getObjBounds(child); testBounds.translate(-targetData.scrollPos.x, -targetData.scrollPos.y); surface->frameRect(testBounds, kColorGreen); -- cgit v1.2.3 From 1bb3d1412918be5faa0f1994beb6afaddf3b768a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 11 Aug 2016 10:00:50 +0200 Subject: MACVENTURE: Unify NULLs --- engines/macventure/controls.cpp | 2 +- engines/macventure/datafiles.cpp | 2 +- engines/macventure/gui.cpp | 14 +++++++------- engines/macventure/sound.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/engines/macventure/controls.cpp b/engines/macventure/controls.cpp index 26807a3308..898ddac8e8 100644 --- a/engines/macventure/controls.cpp +++ b/engines/macventure/controls.cpp @@ -24,7 +24,7 @@ namespace MacVenture { CommandButton::CommandButton() { - _gui = nullptr; + _gui = NULL; } CommandButton::CommandButton(ControlData data, Gui *g) { diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp index 77ecaee626..496fa919c8 100644 --- a/engines/macventure/datafiles.cpp +++ b/engines/macventure/datafiles.cpp @@ -74,7 +74,7 @@ Common::SeekableReadStream *MacVentureEngine::getBorderFile(MVWindowType windowT filename += (isActive ? "_act.bmp" : "_inac.bmp"); if (!_dataBundle->hasFile(filename)) { warning("Missing border file '%s' in data bundle", filename.c_str()); - return nullptr; + return NULL; } return _dataBundle->createReadStreamForMember(filename); diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 56381369bb..65b11ee402 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -103,11 +103,11 @@ void menuCommandsCallback(int action, Common::String &text, void *data); Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _engine = engine; _resourceManager = resman; - _windowData = nullptr; - _controlData = nullptr; + _windowData = NULL; + _controlData = NULL; _draggedObj.id = 0; _draggedObj.pos = Common::Point(0, 0); - _dialog = nullptr; + _dialog = NULL; _cursor = new Cursor(this); @@ -846,7 +846,7 @@ void Gui::showPrebuiltDialog(PrebuiltDialogs type) { } bool Gui::isDialogOpen() { - return _dialog != nullptr; + return _dialog != NULL; } void Gui::setTextInput(Common::String str) { @@ -856,7 +856,7 @@ void Gui::setTextInput(Common::String str) { void Gui::closeDialog() { delete _dialog; - _dialog = nullptr; + _dialog = NULL; } void Gui::getTextFromUser() { @@ -950,7 +950,7 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { } switch (reference) { case MacVenture::kNoWindow: - return nullptr; + return NULL; case MacVenture::kCommandsWindow: return _controlsWindow; case MacVenture::kMainGameWindow: @@ -964,7 +964,7 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { case MacVenture::kDiplomaWindow: return _diplomaWindow; } - return nullptr; + return NULL; } void Gui::ensureInventoryOpen(WindowReference reference, ObjID id) { diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index f05c88fcd6..455a1916ac 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -30,7 +30,7 @@ namespace MacVenture { // SoundManager SoundManager::SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer) { - _container = nullptr; + _container = NULL; Common::String filename = engine->getFilePath(kSoundPathID); _container = new Container(filename); _mixer = mixer; -- cgit v1.2.3 From 4e3daab04f8243f4672d723b51948d8700e74847 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 11 Aug 2016 18:20:26 +0200 Subject: MACVENTURE: Minor refactorings --- engines/macventure/macventure.cpp | 50 +++++++++++++++++++++------------------ engines/macventure/macventure.h | 4 +++- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index a18bdcfef2..1ef657f032 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -334,7 +334,9 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID targ return; } - if (type == kUpdateWindow) { obj.target = target; } + if (type == kUpdateWindow) { + obj.target = target; + } if (type != kHightlightExits) { obj.object = objID; @@ -350,14 +352,6 @@ void MacVentureEngine::enqueueObject(ObjectQueueID type, ObjID objID, ObjID targ _objQueue.push_back(obj); } -bool MacVentureEngine::isObjEnqueued(ObjID objID) { - Common::Array::const_iterator it; - for (it = _objQueue.begin(); it != _objQueue.end(); it++) { - if ((*it).object == objID) return true; - } - return false; -} - void MacVentureEngine::enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text) { QueuedText newText; newText.id = type; @@ -403,28 +397,26 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool //} } if (objID > 0) { - int i = findObjectInArray(objID, _currentSelection); + int currentObjectIndex = findObjectInArray(objID, _currentSelection); + + if (currentObjectIndex >= 0) + unselectAll(); if (isDoubleClick) { - if (i >= 0) - unselectAll(); selectObject(objID); _destObject = objID; - _deltaPoint = Common::Point(0, 0); + setDeltaPoint(Common::Point(0, 0)); if (!_cmdReady) { selectControl(kActivateObject); _activeControl = kActivateObject; _cmdReady = true; } - preparedToRun(); } else { - if (i >= 0) - unselectAll(); selectObject(objID); if (getInvolvedObjects() == 1) _cmdReady = true; - preparedToRun(); } + preparedToRun(); } } } @@ -432,14 +424,14 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent) { _destObject = newParent; - updateDelta(delta); + setDeltaPoint(delta); selectControl(kMoveObject); activateCommand(kMoveObject); refreshReady(); preparedToRun(); } -void MacVentureEngine::updateDelta(Common::Point newPos) { +void MacVentureEngine::setDeltaPoint(Common::Point newPos) { debugC(4, kMVDebugMain, "Update delta: Old(%d, %d), New(%d, %d)", _deltaPoint.x, _deltaPoint.y, newPos.x, newPos.y); @@ -489,7 +481,7 @@ Common::String MacVentureEngine::getStartGameFileName() { Common::String result = Common::String(fileName, length); // HACK, see definition of toASCII toASCII(result); - return result; + return result; } const GlobalSettings& MacVentureEngine::getGlobalSettings() const { @@ -537,7 +529,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { while (!_currentSelection.empty()) { ObjID obj = _currentSelection.front(); _currentSelection.remove_at(0); - if ((_gameState == kGameStateInit || _gameState == kGameStatePlaying) && _world->isObjActive(obj)) { + if (isGameRunning() && _world->isObjActive(obj)) { if (_scriptEngine->runControl(_selectedControl, obj, _destObject, _deltaPoint)) { _haltedInSelection = true; return true; @@ -548,7 +540,7 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { if (_selectedControl == 1) _gameChanged = false; - else if (_gameState == kGameStateInit || _gameState == kGameStatePlaying) { + else if (isGameRunning()) { if (_scriptEngine->runControl(kTick, _selectedControl, _destObject, _deltaPoint)) { _haltedAtEnd = true; return true; @@ -675,7 +667,7 @@ void MacVentureEngine::resetVars() { _activeControl = kNoCommand; _currentSelection.clear(); _destObject = 0; - _deltaPoint = Common::Point(0, 0); + setDeltaPoint(Common::Point(0, 0)); _cmdReady = false; } @@ -918,6 +910,18 @@ void MacVentureEngine::zoomObject(ObjID objID) { warning("zoomObject: unimplemented"); } +bool MacVentureEngine::isObjEnqueued(ObjID objID) { + Common::Array::const_iterator it; + for (it = _objQueue.begin(); it != _objQueue.end(); it++) { + if ((*it).object == objID) return true; + } + return false; +} + +bool MacVentureEngine::isGameRunning() { + return (_gameState == kGameStateInit || _gameState == kGameStatePlaying); +} + ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlType id) { switch (id) { case MacVenture::kControlExitBox: diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 3f0ce0cc7b..a87af74333 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -222,7 +222,7 @@ public: void handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick); void handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent); - void updateDelta(Common::Point newPos); + void setDeltaPoint(Common::Point newPos); void focusObjWin(ObjID objID); void updateWindow(WindowReference winID); @@ -296,6 +296,8 @@ private: bool isObjEnqueued(ObjID obj); + bool isGameRunning(); + // Data loading bool loadGlobalSettings(); bool loadTextHuffman(); -- cgit v1.2.3 From 580c8136f44b59b48aeb776c0d62ad20ab8c07ef Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 11 Aug 2016 19:41:12 +0200 Subject: MACVENTURE: Some more refactoring --- engines/macventure/macventure.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 1ef657f032..2eb3115bb4 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -761,18 +761,17 @@ void MacVentureEngine::highlightExit(ObjID objID) { void MacVentureEngine::selectPrimaryObject(ObjID objID) { if (objID == _destObject) return; int idx; + debugC(5, kMVDebugMain, "Select primary object (%d)", objID); if (_destObject > 0 && (idx = findObjectInArray(_destObject, _selectedObjs)) != -1 && - findObjectInArray(_destObject, _currentSelection) == -1) - { - _selectedObjs.remove_at(idx); - highlightExit(_destObject); + findObjectInArray(_destObject, _currentSelection) == -1) { + unselectAll(); } _destObject = objID; if (findObjectInArray(_destObject, _selectedObjs) == -1) { - _selectedObjs.push_back(_destObject); - highlightExit(_destObject); + selectObject(_destObject); } + _cmdReady = true; } -- cgit v1.2.3 From 7b9c63b1b919ce042f72b9cd05bde5e84b8edf85 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 12 Aug 2016 10:02:24 +0200 Subject: MACVENTURE: Delete duplicate code --- engines/macventure/gui.cpp | 3 +-- engines/macventure/macventure.cpp | 20 ++++---------------- engines/macventure/macventure.h | 2 -- engines/macventure/script.cpp | 2 +- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 65b11ee402..b66e2ee598 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1247,7 +1247,7 @@ bool Gui::processEvent(Common::Event &event) { bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { if (_engine->needsClickToContinue()) { - _engine->activateCommand(kClickToContinue); + _engine->selectControl(kClickToContinue); return true; } @@ -1271,7 +1271,6 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { } _engine->selectControl(data.getData().refcon); - _engine->activateCommand(data.getData().refcon); _engine->refreshReady(); _engine->preparedToRun(); } diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 2eb3115bb4..48511c9330 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -270,21 +270,13 @@ void MacVentureEngine::requestUnpause() { void MacVentureEngine::selectControl(ControlAction id) { debugC(2, kMVDebugMain, "Select control %x", id); - _selectedControl = id; -} - -void MacVentureEngine::activateCommand(ControlAction id) { if (id == kClickToContinue) { _clickToContinue = false; _paused = true; return; } - if (id != _activeControl) { - if (_activeControl) - _activeControl = kNoCommand; - _activeControl = id; - } - debugC(2, kMVDebugMain, "Activating Command %x... Command %x is active", id, _activeControl); + + _selectedControl = id; refreshReady(); } @@ -408,7 +400,6 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool setDeltaPoint(Common::Point(0, 0)); if (!_cmdReady) { selectControl(kActivateObject); - _activeControl = kActivateObject; _cmdReady = true; } } else { @@ -426,7 +417,6 @@ void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID _destObject = newParent; setDeltaPoint(delta); selectControl(kMoveObject); - activateCommand(kMoveObject); refreshReady(); preparedToRun(); } @@ -655,16 +645,14 @@ void MacVentureEngine::playSounds(bool pause) { } void MacVentureEngine::updateControls() { - if (_activeControl) - _activeControl = kNoCommand; + _selectedControl = kNoCommand; _gui->clearControls(); toggleExits(); resetVars(); } void MacVentureEngine::resetVars() { - _selectedControl = kNoCommand; - _activeControl = kNoCommand; + selectControl(kNoCommand); _currentSelection.clear(); _destObject = 0; setDeltaPoint(Common::Point(0, 0)); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index a87af74333..72d09a8b11 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -201,7 +201,6 @@ public: void requestQuit(); void requestUnpause(); void selectControl(ControlAction action); - void activateCommand(ControlAction id); void refreshReady(); void preparedToRun(); void gameChanged(); @@ -344,7 +343,6 @@ private: // Attributes // Selections ObjID _destObject; ControlAction _selectedControl; - ControlAction _activeControl; Common::Array _currentSelection; Common::Array _selectedObjs; Common::Point _deltaPoint; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index d191cefa12..a051ca8f75 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1083,7 +1083,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { - _engine->activateCommand((ControlAction)state->pop()); + _engine->selectControl((ControlAction)state->pop()); } void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { -- cgit v1.2.3 From 8417e6f22deaf026c3c59cfc9175d357c6ec286a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 12 Aug 2016 12:02:41 +0200 Subject: MACVENTURE: Delete unnecessary attribute --- engines/macventure/macventure.cpp | 28 ++++++++++++---------------- engines/macventure/macventure.h | 1 - 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 48511c9330..b96a8bfeec 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -163,7 +163,7 @@ Common::Error MacVentureEngine::run() { } else { setNewGameState(); } - _selectedControl = kStartOrResume; + selectControl(kStartOrResume); _gui->addChild(kSelfWindow, 1); _gui->updateWindow(kSelfWindow, false); @@ -243,7 +243,6 @@ void MacVentureEngine::reset() { void MacVentureEngine::resetInternals() { _scriptEngine->reset(); _currentSelection.clear(); - _selectedObjs.clear(); _objQueue.clear(); _textQueue.clear(); } @@ -645,7 +644,7 @@ void MacVentureEngine::playSounds(bool pause) { } void MacVentureEngine::updateControls() { - _selectedControl = kNoCommand; + selectControl(kNoCommand); _gui->clearControls(); toggleExits(); resetVars(); @@ -670,20 +669,16 @@ void MacVentureEngine::selectObject(ObjID objID) { if (findParentWindow(objID) != findParentWindow(_currentSelection[0])) unselectAll(); } - if (findObjectInArray(objID, _currentSelection) == -1) + if (findObjectInArray(objID, _currentSelection) == -1) { _currentSelection.push_back(objID); - if (findObjectInArray(objID, _selectedObjs) == -1) { - _selectedObjs.push_back(objID); highlightExit(objID); } } void MacVentureEngine::unselectObject(ObjID objID) { int idxCur = findObjectInArray(objID, _currentSelection); - int idxSel = findObjectInArray(objID, _selectedObjs); - if (idxCur != -1) _currentSelection.remove_at(idxCur); - if (idxSel != -1) { - _selectedObjs.remove_at(idxSel); + if (idxCur != -1){ + _currentSelection.remove_at(idxCur); highlightExit(objID); } } @@ -751,12 +746,11 @@ void MacVentureEngine::selectPrimaryObject(ObjID objID) { int idx; debugC(5, kMVDebugMain, "Select primary object (%d)", objID); if (_destObject > 0 && - (idx = findObjectInArray(_destObject, _selectedObjs)) != -1 && - findObjectInArray(_destObject, _currentSelection) == -1) { + (idx = findObjectInArray(_destObject, _currentSelection)) != -1) { unselectAll(); } _destObject = objID; - if (findObjectInArray(_destObject, _selectedObjs) == -1) { + if (findObjectInArray(_destObject, _currentSelection) == -1) { selectObject(_destObject); } @@ -885,9 +879,11 @@ void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { } void MacVentureEngine::toggleExits() { - while (!_selectedObjs.empty()) { - ObjID obj = _selectedObjs.front(); - _selectedObjs.remove_at(0); + warning("delete this when done testing!"); + Common::Array exits = _currentSelection; + while (!exits.empty()) { + ObjID obj = exits.front(); + exits.remove_at(0); highlightExit(obj); updateWindow(findParentWindow(obj)); } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 72d09a8b11..e78774db0c 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -344,7 +344,6 @@ private: // Attributes ObjID _destObject; ControlAction _selectedControl; Common::Array _currentSelection; - Common::Array _selectedObjs; Common::Point _deltaPoint; Common::String _userInput; -- cgit v1.2.3 From 479f01b5a708ed1e3294ef1d553d37d270cb97c4 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 12 Aug 2016 12:42:24 +0200 Subject: MACVENTURE: Implement gui reloading --- engines/macventure/gui.cpp | 21 ++++++++++++++++----- engines/macventure/gui.h | 3 +++ engines/macventure/macventure.cpp | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index b66e2ee598..85f1cdbea7 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -112,6 +112,7 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _cursor = new Cursor(this); _consoleText = new ConsoleText(this); + _graphics = NULL; initGUI(); } @@ -136,10 +137,7 @@ Gui::~Gui() { if (_dialog) delete _dialog; - Common::HashMap::const_iterator it = _assets.begin(); - for (; it != _assets.end(); it++) { - delete it->_value; - } + clearAssets(); } void Gui::initGUI() { @@ -169,8 +167,12 @@ void Gui::initGUI() { } -void Gui::draw() { +void Gui::reloadInternals() { + loadGraphics(); + clearAssets(); +} +void Gui::draw() { // Will be performance-improved after the milestone _wm.setFullRefresh(true); @@ -352,9 +354,18 @@ void Gui::loadBorder(Graphics::MacWindow * target, MVWindowType type, bool activ } void Gui::loadGraphics() { + if (_graphics) + delete _graphics; _graphics = new Container(_engine->getFilePath(kGraphicPathID)); } +void Gui::clearAssets() { + Common::HashMap::const_iterator it = _assets.begin(); + for (; it != _assets.end(); it++) { + delete it->_value; + } +} + bool Gui::loadMenus() { if (kLoadStaticMenus) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 185171f6b9..5835202904 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -98,6 +98,8 @@ public: Gui(MacVentureEngine *engine, Common::MacResManager *resman); ~Gui(); + void reloadInternals(); + void draw(); void drawMenu(); void drawTitle(); @@ -211,6 +213,7 @@ private: // Methods void loadBorders(Graphics::MacWindow *target, MVWindowType type); void loadBorder(Graphics::MacWindow *target, MVWindowType type, bool active); void loadGraphics(); + void clearAssets(); // Drawers void drawWindows(); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index b96a8bfeec..21fb709994 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -248,6 +248,7 @@ void MacVentureEngine::resetInternals() { } void MacVentureEngine::resetGui() { + _gui->reloadInternals(); _gui->updateWindowInfo(kMainGameWindow, getParent(1), _world->getChildren(getParent(1), true)); // HACK! should update all inventories _gui->ensureInventoryOpen(kInventoryStart, 1); -- cgit v1.2.3 From 44a6f8a1dbdfa271aaa9ccf4b1ecc48e275ca11a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 16:57:42 +0200 Subject: MACVENTURE: Fix minor memory leaks --- engines/macventure/container.h | 13 ++++++++++--- engines/macventure/gui.cpp | 11 ++++++++++- engines/macventure/image.cpp | 9 +++++++-- engines/macventure/macventure.cpp | 22 ++++++++++++++++++++-- engines/macventure/script.cpp | 1 + engines/macventure/stringtable.h | 1 + engines/macventure/text.cpp | 3 ++- engines/macventure/world.cpp | 7 ++++++- 8 files changed, 57 insertions(+), 10 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 013a11dafc..1abab1c6d0 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -52,6 +52,12 @@ public: _header = _res->readUint32BE(); _simplified = false; + for (uint i = 0; i < 16; ++i) + _huff.push_back(0); + + for (uint i = 0; i < 16; ++i) + _lens.push_back(0); + if (!(_header & 0x80000000)) { // Is simplified container _simplified = true; @@ -97,7 +103,8 @@ public: for (uint j = 0; j < 64; ++j) { uint32 length = 0; - uint32 mask = _res->readUint32BE(); + uint32 mask = 0; + mask = _res->readUint32BE(); mask >>= (16 - bits); mask &= 0xFFFF; debugC(11, kMVDebugContainer, "Load mask of object &%d:%d is %x", i, j, mask); @@ -202,8 +209,8 @@ protected: ContainerHeader _header; - uint16 _huff[15]; // huffman masks - uint8 _lens[16]; // huffman lengths + Common::Array _huff; // huffman masks + Common::Array _lens; // huffman lengths Common::Array _groups; Common::String _filename; diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 85f1cdbea7..f8f9497b8b 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -138,6 +138,9 @@ Gui::~Gui() { delete _dialog; clearAssets(); + + if (_graphics) + delete _graphics; } void Gui::initGUI() { @@ -421,6 +424,7 @@ bool Gui::loadMenus() { } i++; + delete res; } return true; @@ -463,12 +467,15 @@ bool Gui::loadWindows() { res->read(newTitle, data.titleLength); newTitle[data.titleLength] = '\0'; data.title = Common::String(newTitle); + delete[] newTitle; } data.scrollPos = Common::Point(0, 0); debugC(4, kMVDebugGUI, "Window loaded: %s", data.title.c_str()); _windowData->push_back(data); + + delete res; } return true; @@ -518,7 +525,9 @@ bool Gui::loadControls() { } - i++; + _controlData->push_back(CommandButton(data, this)); + + delete res; } return true; diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index a89eae94be..604d9dbfc6 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -98,9 +98,12 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight return; } if (size == 2) { - realID = _container->getItem(id)->readUint16BE(); + Common::SeekableReadStream *newItemStream = _container->getItem(id); + realID = newItemStream->readUint16BE(); + delete newItemStream; } - Common::BitStream32BEMSB stream(_container->getItem(realID), true); + Common::SeekableReadStream *baseStream = _container->getItem(realID); + Common::BitStream32BEMSB stream(baseStream); uint8 mode = stream.getBits(3); int w, h; @@ -133,6 +136,8 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight decodePPIC3(stream, data, bitHeight, bitWidth, rowBytes); break; } + + delete baseStream; } void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 21fb709994..81bb267dfa 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -55,7 +55,9 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD initDebugChannels(); _debugger = NULL; + _resourceManager = NULL; _gui = NULL; + _world = NULL; _scriptEngine = NULL; _filenames = NULL; @@ -82,9 +84,15 @@ MacVentureEngine::~MacVentureEngine() { if (_debugger) delete _debugger; + if (_resourceManager) + delete _resourceManager; + if (_gui) delete _gui; + if (_world) + delete _world; + if (_scriptEngine) delete _scriptEngine; @@ -471,6 +479,10 @@ Common::String MacVentureEngine::getStartGameFileName() { Common::String result = Common::String(fileName, length); // HACK, see definition of toASCII toASCII(result); + + delete[] fileName; + delete res; + return result; } @@ -1065,11 +1077,11 @@ ControlAction MacVentureEngine::getSelectedControl() { bool MacVentureEngine::loadGlobalSettings() { Common::MacResIDArray resArray; - Common::SeekableReadStream *res; if ((resArray = _resourceManager->getResIDArray(MKTAG('G', 'N', 'R', 'L'))).size() == 0) return false; + Common::SeekableReadStream *res; res = _resourceManager->getResource(MKTAG('G', 'N', 'R', 'L'), kGlobalSettingsID); if (res) { _globalSettings.numObjects = res->readUint16BE(); @@ -1103,9 +1115,9 @@ bool MacVentureEngine::loadGlobalSettings() { _globalSettings.commands = new uint8[_globalSettings.numCommands]; res->read(_globalSettings.commands, _globalSettings.numCommands); + delete res; return true; } - return false; } @@ -1136,6 +1148,12 @@ bool MacVentureEngine::loadTextHuffman() { _textHuffman = new HuffmanLists(numEntries, lengths, masks, values); debugC(4, kMVDebugMain, "Text is huffman-encoded"); + + + delete res; + delete masks; + delete lengths; + delete values; return true; } return false; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index a051ca8f75..5aa8e3cc19 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1208,6 +1208,7 @@ void ScriptAsset::loadInstructions() { for (uint i = 0; i < amount; i++) { _instructions.push_back(res->readByte()); } + delete res; debugC(2, kMVDebugScript, "SCRIPT: Load %d instructions for script %d", amount, _id); } diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index f05b793ced..0a5419e235 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -90,6 +90,7 @@ private: delete[] str; } + delete res; return true; } diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 74b5685e7f..d15401ac3a 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -117,7 +117,7 @@ void TextAsset::decodeOld() { void TextAsset::decodeHuffman() { _decoded = Common::String(""); Common::SeekableReadStream *res = _container->getItem(_id); - Common::BitStream8MSB stream(res); + Common::BitStream8MSB stream(res, true); uint16 strLen = 0; if (stream.getBit()) { strLen = stream.getBits(15); @@ -174,6 +174,7 @@ void TextAsset::decodeHuffman() { } } _decoded += '\0'; + delete res; debugC(4, kMVDebugText, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); } Common::String TextAsset::getNoun(ObjID subval) { diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 82a8952f02..708ccfec33 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -9,6 +9,7 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _resourceManager = resMan; _engine = engine; _saveGame = NULL; + _gameText = NULL; startNewGame(); @@ -26,6 +27,9 @@ World::~World() { if (_objectConstants) delete _objectConstants; + + if (_gameText) + delete _gameText; } void World::startNewGame() { @@ -45,7 +49,7 @@ void World::startNewGame() { _saveGame = new SaveGame(_engine, saveGameRes); calculateObjectRelations(); - + delete saveGameRes; saveGameFile.close(); } @@ -70,6 +74,7 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { if (res & 0x8000) res = -((res ^ 0xffff) + 1); debugC(5, kMVDebugMain, "Attribute %x from object %x is %x", attrID, objID, res); + delete objStream; return res; } -- cgit v1.2.3 From 019f3d4b626f290fa7e2bc6c6be0ab5c43ecd468 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 17:45:49 +0200 Subject: MACVENTURE: Add wrapper class for global settings --- engines/macventure/gui.cpp | 10 ++--- engines/macventure/macventure.cpp | 88 ++++++++++++++++++++++++--------------- engines/macventure/macventure.h | 49 +++++++++++++--------- engines/macventure/world.cpp | 22 +++++----- 4 files changed, 99 insertions(+), 70 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index f8f9497b8b..834ffc1e19 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -314,14 +314,14 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { if (_windowData->back().refcon < 0x80) { // There is already another inventory window newData.bounds = _windowData->back().bounds; // Inventory windows are always last - newData.bounds.translate(newData.bounds.left + settings.invOffsetX, newData.bounds.top + settings.invOffsetY); + newData.bounds.translate(newData.bounds.left + settings._invOffsetX, newData.bounds.top + settings._invOffsetY); } else { BorderBounds bbs = borderBounds(kInvWindow); newData.bounds = Common::Rect( - settings.invLeft - bbs.leftOffset, - settings.invTop - bbs.topOffset, - settings.invLeft + settings.invWidth, - settings.invTop + settings.invHeight); + settings._invLeft - bbs.leftOffset, + settings._invTop - bbs.topOffset, + settings._invLeft + settings._invWidth, + settings._invTop + settings._invHeight); } newData.type = kInvWindow; newData.hasCloseBox = true; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 81bb267dfa..9c601dde9c 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -56,6 +56,7 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD _debugger = NULL; _resourceManager = NULL; + _globalSettings = NULL; _gui = NULL; _world = NULL; _scriptEngine = NULL; @@ -87,6 +88,9 @@ MacVentureEngine::~MacVentureEngine() { if (_resourceManager) delete _resourceManager; + if (_globalSettings) + delete _globalSettings; + if (_gui) delete _gui; @@ -487,7 +491,7 @@ Common::String MacVentureEngine::getStartGameFileName() { } const GlobalSettings& MacVentureEngine::getGlobalSettings() const { - return _globalSettings; + return *_globalSettings; } // Private engine methods @@ -979,7 +983,7 @@ uint32 MacVentureEngine::randBetween(uint32 min, uint32 max) { } uint32 MacVentureEngine::getInvolvedObjects() { - return (_selectedControl ? _globalSettings.cmdArgCnts[_selectedControl - 1] : 3000); + return (_selectedControl ? getGlobalSettings()._cmdArgCnts[_selectedControl - 1] : 3000); } Common::Point MacVentureEngine::getObjPosition(ObjID objID) { @@ -1084,37 +1088,8 @@ bool MacVentureEngine::loadGlobalSettings() { Common::SeekableReadStream *res; res = _resourceManager->getResource(MKTAG('G', 'N', 'R', 'L'), kGlobalSettingsID); if (res) { - _globalSettings.numObjects = res->readUint16BE(); - _globalSettings.numGlobals = res->readUint16BE(); - _globalSettings.numCommands = res->readUint16BE(); - _globalSettings.numAttributes = res->readUint16BE(); - _globalSettings.numGroups = res->readUint16BE(); - res->readUint16BE(); // unknown - _globalSettings.invTop = res->readUint16BE(); - _globalSettings.invLeft = res->readUint16BE(); - _globalSettings.invWidth = res->readUint16BE(); - _globalSettings.invHeight = res->readUint16BE(); - _globalSettings.invOffsetY = res->readUint16BE(); - _globalSettings.invOffsetX = res->readSint16BE(); - _globalSettings.defaultFont = res->readUint16BE(); - _globalSettings.defaultSize = res->readUint16BE(); - - _globalSettings.attrIndices = new uint8[_globalSettings.numAttributes]; - res->read(_globalSettings.attrIndices, _globalSettings.numAttributes); - - _globalSettings.attrMasks = new uint16[_globalSettings.numAttributes]; - for (int i = 0; i < _globalSettings.numAttributes; i++) - _globalSettings.attrMasks[i] = res->readUint16BE(); - - _globalSettings.attrShifts = new uint8[_globalSettings.numAttributes]; - res->read(_globalSettings.attrShifts, _globalSettings.numAttributes); - - _globalSettings.cmdArgCnts = new uint8[_globalSettings.numCommands]; - res->read(_globalSettings.cmdArgCnts, _globalSettings.numCommands); - - _globalSettings.commands = new uint8[_globalSettings.numCommands]; - res->read(_globalSettings.commands, _globalSettings.numCommands); - + _globalSettings = new GlobalSettings(); + _globalSettings->loadSettings(res); delete res; return true; } @@ -1149,7 +1124,6 @@ bool MacVentureEngine::loadTextHuffman() { _textHuffman = new HuffmanLists(numEntries, lengths, masks, values); debugC(4, kMVDebugMain, "Text is huffman-encoded"); - delete res; delete masks; delete lengths; @@ -1159,6 +1133,52 @@ bool MacVentureEngine::loadTextHuffman() { return false; } +// Global Settings +GlobalSettings::GlobalSettings() { +} + +GlobalSettings::~GlobalSettings() { + +} +void GlobalSettings::loadSettings(Common::SeekableReadStream *dataStream) { + _numObjects = dataStream->readUint16BE(); + _numGlobals = dataStream->readUint16BE(); + _numCommands = dataStream->readUint16BE(); + _numAttributes = dataStream->readUint16BE(); + _numGroups = dataStream->readUint16BE(); + dataStream->readUint16BE(); // unknown + _invTop = dataStream->readUint16BE(); + _invLeft = dataStream->readUint16BE(); + _invWidth = dataStream->readUint16BE(); + _invHeight = dataStream->readUint16BE(); + _invOffsetY = dataStream->readUint16BE(); + _invOffsetX = dataStream->readSint16BE(); + _defaultFont = dataStream->readUint16BE(); + _defaultSize = dataStream->readUint16BE(); + + uint8 *attrIndices = new uint8[_numAttributes]; + dataStream->read(attrIndices, _numAttributes); + _attrIndices = Common::Array(attrIndices, _numAttributes); + delete[] attrIndices; + + for (int i = 0; i < _numAttributes; i++) + _attrMasks.push_back(dataStream->readUint16BE()); + + uint8 *attrShifts = new uint8[_numAttributes]; + dataStream->read(attrShifts, _numAttributes); + _attrShifts = Common::Array(attrShifts, _numAttributes); + delete[] attrShifts; + + uint8 *cmdArgCnts = new uint8[_numCommands]; + dataStream->read(cmdArgCnts, _numCommands); + _cmdArgCnts = Common::Array(cmdArgCnts, _numCommands); + delete[] cmdArgCnts; + + uint8 *commands = new uint8[_numCommands]; + dataStream->read(commands, _numCommands); + _commands = Common::Array(commands, _numCommands); + delete[] commands; +} } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index e78774db0c..7e53eb229d 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -91,25 +91,34 @@ enum FilePathID { }; -struct GlobalSettings { - uint16 numObjects; // number of game objects defined - uint16 numGlobals; // number of globals defined - uint16 numCommands; // number of commands defined - uint16 numAttributes; // number of attributes - uint16 numGroups; // number of object groups - uint16 invTop; // inventory window bounds - uint16 invLeft; - uint16 invHeight; - uint16 invWidth; - uint16 invOffsetY; // positioning offset for - uint16 invOffsetX; // new inventory windows - uint16 defaultFont; // default font - uint16 defaultSize; // default font size - uint8 *attrIndices; // attribute indices into attribute table - uint16 *attrMasks; // attribute masks - uint8 *attrShifts; // attribute bit shifts - uint8 *cmdArgCnts; // command argument counts - uint8 *commands; // command buttons +class GlobalSettings { +public: + GlobalSettings(); + ~GlobalSettings(); + + void loadSettings(Common::SeekableReadStream *dataStream); + +// HACK MAybe this should be private, but the class is only here to handle +// memory allocation/deallocation +public: + uint16 _numObjects; // number of game objects defined + uint16 _numGlobals; // number of globals defined + uint16 _numCommands; // number of commands defined + uint16 _numAttributes; // number of attributes + uint16 _numGroups; // number of object groups + uint16 _invTop; // inventory window bounds + uint16 _invLeft; + uint16 _invHeight; + uint16 _invWidth; + uint16 _invOffsetY; // positioning offset for + uint16 _invOffsetX; // new inventory windows + uint16 _defaultFont; // default font + uint16 _defaultSize; // default font size + Common::Array _attrIndices; // attribute indices into attribute table + Common::Array _attrMasks; // attribute masks + Common::Array _attrShifts; // attribute bit shifts + Common::Array _cmdArgCnts; // command argument counts + Common::Array _commands; // command buttons }; enum GameState { @@ -327,7 +336,7 @@ private: // Attributes // Engine state GameState _gameState; - GlobalSettings _globalSettings; + GlobalSettings *_globalSettings; HuffmanLists *_textHuffman; bool _oldTextEncoding; bool _paused, _halted, _cmdReady, _prepared; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 708ccfec33..20695dbff6 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -56,7 +56,7 @@ void World::startNewGame() { uint32 World::getObjAttr(ObjID objID, uint32 attrID) { uint res; - uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; + uint32 index = _engine->getGlobalSettings()._attrIndices[attrID]; // HACK, but if I try to initialize it in the else clause, it goes out of scope and segfaults Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); if (!(index & 0x80)) { // It's not a constant @@ -69,8 +69,8 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { res = objStream->readByte() << 8; res |= objStream->readByte(); } - res &= _engine->getGlobalSettings().attrMasks[attrID]; - res >>= _engine->getGlobalSettings().attrShifts[attrID]; + res &= _engine->getGlobalSettings()._attrMasks[attrID]; + res >>= _engine->getGlobalSettings()._attrShifts[attrID]; if (res & 0x8000) res = -((res ^ 0xffff) + 1); debugC(5, kMVDebugMain, "Attribute %x from object %x is %x", attrID, objID, res); @@ -88,11 +88,11 @@ void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) { if (attrID < kAttrOtherDoor) _engine->enqueueObject(kUpdateObject, objID); - uint32 idx = _engine->getGlobalSettings().attrIndices[attrID]; - value <<= _engine->getGlobalSettings().attrShifts[attrID]; - value &= _engine->getGlobalSettings().attrMasks[attrID]; + uint32 idx = _engine->getGlobalSettings()._attrIndices[attrID]; + value <<= _engine->getGlobalSettings()._attrShifts[attrID]; + value &= _engine->getGlobalSettings()._attrMasks[attrID]; Attribute oldVal = _saveGame->getAttr(objID, idx); - oldVal &= ~_engine->getGlobalSettings().attrMasks[attrID]; + oldVal &= ~_engine->getGlobalSettings()._attrMasks[attrID]; _saveGame->setAttr(idx, objID, (value | oldVal)); _engine->gameChanged(); } @@ -195,7 +195,7 @@ bool World::intersects(ObjID objID, Common::Rect rect) { void World::calculateObjectRelations() { _relations.clear(); ObjID val, next; - uint32 numObjs = _engine->getGlobalSettings().numObjects; + uint32 numObjs = _engine->getGlobalSettings()._numObjects; const AttributeGroup &parents = *_saveGame->getGroup(0); for (uint i = 0; i < numObjs * 2; i++) { _relations.push_back(0); @@ -305,9 +305,9 @@ void SaveGame::saveInto(Common::OutSaveFile *file) { void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) { GlobalSettings settings = engine->getGlobalSettings(); - for (int i = 0; i < settings.numGroups; ++i) { + for (int i = 0; i < settings._numGroups; ++i) { AttributeGroup g; - for (int j = 0; j < settings.numObjects; ++j) + for (int j = 0; j < settings._numObjects; ++j) g.push_back(res->readUint16BE()); _groups.push_back(g); @@ -316,7 +316,7 @@ void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream * res) { GlobalSettings settings = engine->getGlobalSettings(); - for (int i = 0; i < settings.numGlobals; ++i) { + for (int i = 0; i < settings._numGlobals; ++i) { _globals.push_back(res->readUint16BE()); } } -- cgit v1.2.3 From 2f2d9bead758a001e3e003bc782540ad4c0c3d22 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 18:05:37 +0200 Subject: MACVENTURE: Fix double free --- engines/macventure/text.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index d15401ac3a..76ea7dfd96 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -174,7 +174,6 @@ void TextAsset::decodeHuffman() { } } _decoded += '\0'; - delete res; debugC(4, kMVDebugText, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); } Common::String TextAsset::getNoun(ObjID subval) { -- cgit v1.2.3 From 28698ba697012edd1b3159400342d04b5d3df530 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 18:13:29 +0200 Subject: MACVENTURE: Fix leak on loadControls --- engines/macventure/controls.h | 2 +- engines/macventure/gui.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/engines/macventure/controls.h b/engines/macventure/controls.h index a780f6328b..574ae6afbe 100644 --- a/engines/macventure/controls.h +++ b/engines/macventure/controls.h @@ -69,7 +69,7 @@ struct ControlData { ControlAction refcon; ControlType type; uint8 titleLength; - char* title; + Common::String title; uint16 border; }; diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 834ffc1e19..bf8455eb91 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -512,9 +512,11 @@ bool Gui::loadControls() { data.type = (ControlType)id; id++; data.titleLength = res->readByte(); if (data.titleLength) { - data.title = new char[data.titleLength + 1]; - res->read(data.title, data.titleLength); - data.title[data.titleLength] = '\0'; + char *title = new char[data.titleLength + 1]; + res->read(title, data.titleLength); + title[data.titleLength] = '\0'; + data.title = Common::String(title); + delete[] title; } if (data.type != kControlExitBox) { BorderBounds bbs = borderBounds(getWindowData(kCommandsWindow).type); -- cgit v1.2.3 From d1cd77208e9517c50a65a32f33dfe5ce5039ef1e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 19:12:05 +0200 Subject: MACVENTURE: Fix mismatched new and delete[] --- engines/macventure/container.h | 3 ++- engines/macventure/gui.cpp | 2 +- engines/macventure/macventure.cpp | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 1abab1c6d0..6979afbb4e 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -196,7 +196,8 @@ public: } - Common::SeekableReadStream *res = _res->readStream(getItemByteSize(id) * 2); + // HACK Should Limit the size of the stream returned + Common::SeekableReadStream *res = _res->readStream(_res->size() - _res->pos() + 1); return res; } diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index bf8455eb91..ff14cf3b5d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -171,8 +171,8 @@ void Gui::initGUI() { } void Gui::reloadInternals() { - loadGraphics(); clearAssets(); + loadGraphics(); } void Gui::draw() { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 9c601dde9c..16be24b2c4 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -1125,9 +1125,9 @@ bool MacVentureEngine::loadTextHuffman() { debugC(4, kMVDebugMain, "Text is huffman-encoded"); delete res; - delete masks; - delete lengths; - delete values; + delete[] masks; + delete[] lengths; + delete[] values; return true; } return false; -- cgit v1.2.3 From 6f9a17199cc01b72de2045cda7eee2c97e8c6ccb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 20:08:35 +0200 Subject: MACVENTURE: Fix leak on text decoding --- engines/macventure/text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 76ea7dfd96..745def2cc4 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -43,7 +43,7 @@ TextAsset::TextAsset(MacVentureEngine *engine, ObjID objid, ObjID source, ObjID void TextAsset::decodeOld() { Common::SeekableReadStream *res = _container->getItem(_id); uint16 strLen = res->readUint16BE(); - Common::BitStream32BELSB stream(res); + Common::BitStream32BELSB stream(res, true); char* str = new char[strLen + 1]; bool lowercase = false; char c; -- cgit v1.2.3 From 2f1368646f11e9569bd981a93035a2e43edd2aca Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sat, 13 Aug 2016 23:46:29 +0200 Subject: MACVENTURE: Fix window object drawing --- engines/macventure/gui.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index ff14cf3b5d..9359097b8a 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -367,6 +367,7 @@ void Gui::clearAssets() { for (; it != _assets.end(); it++) { delete it->_value; } + _assets.clear(); } bool Gui::loadMenus() { @@ -672,9 +673,11 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur if (targetData.children.size() == 0) return; - Graphics::ManagedSurface *composeSurface = new Graphics::ManagedSurface(); - createInnerSurface(composeSurface, surface, border); - composeSurface->clear(kColorGreen); + Graphics::ManagedSurface composeSurface; + createInnerSurface(&composeSurface, surface, border); + assert(composeSurface.w <= surface->w && + composeSurface.h <= surface->h); + composeSurface.clear(kColorGreen); for (uint i = 0; i < targetData.children.size(); i++) { child = targetData.children[i].obj; @@ -684,7 +687,7 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur ensureAssetLoaded(child); _assets[child]->blitInto( - composeSurface, + &composeSurface, pos.x, pos.y, mode); @@ -694,7 +697,7 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur child == _draggedObj.id) { _assets[child]->blitInto( - composeSurface, pos.x, pos.y, kBlitOR); + &composeSurface, pos.x, pos.y, kBlitOR); } } @@ -705,8 +708,7 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur } } Common::Point composePosition = Common::Point(border.leftOffset, border.topOffset); - surface->transBlitFrom(*composeSurface, composePosition, kColorGreen); - delete composeSurface; + surface->transBlitFrom(composeSurface, composePosition, kColorGreen); } void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { -- cgit v1.2.3 From d86a426dcbf0ca0ec38df70bfe4567b2fada08ce Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 14 Aug 2016 10:55:25 +0200 Subject: MACVENTURE: Fix image overflow blitting --- engines/macventure/image.cpp | 64 ++++++++++++++++++++++++++++++++++---------- engines/macventure/image.h | 5 ++-- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 604d9dbfc6..812e2e3dad 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -86,6 +86,7 @@ ImageAsset::ImageAsset(ObjID original, Container * container) { } ImageAsset::~ImageAsset() { + debugC(3, kMVDebugImage, "~ImageAsset(%d)", _id / 2); } void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight, uint &bitWidth, uint &rowBytes) { @@ -348,7 +349,7 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { return val; } -void ImageAsset::blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode) { +void ImageAsset::blitInto(Graphics::ManagedSurface *target, int x, int y, BlitMode mode) { if (mode == kBlitDirect) { blitDirect(target, x, y, _imgData, _imgBitHeight, _imgBitWidth, _imgRowBytes); } else if (mode < kBlitXOR){ @@ -417,12 +418,14 @@ int ImageAsset::getHeight() { void ImageAsset::blitDirect(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array& data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; byte pix = 0; for (uint x = 0; x < w; x++) { + assert(ox + x <= target->w); + assert(oy + y <= target->h); pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); pix = pix ? kColorBlack : kColorWhite; *((byte *)target->getBasePtr(ox + x, oy + y)) = pix; @@ -432,12 +435,14 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, int ox, int oy, c void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; byte pix = 0; for (uint x = 0; x < w; x++) { + assert(ox + x <= target->w); + assert(oy + y <= target->h); pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; } @@ -446,12 +451,14 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, cons void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; byte pix = 0; for (uint x = 0; x < w; x++) { + assert(ox + x <= target->w); + assert(oy + y <= target->h); pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorBlack; } @@ -460,7 +467,7 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const void ImageAsset::blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; - calculateSubsection(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); + calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); for (uint y = 0; y < h; y++) { uint bmpofs = (y + sy) * rowBytes; @@ -468,6 +475,8 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, int ox, int oy, cons for (uint x = 0; x < w; x++) { pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); if (pix) { // We need to xor + assert(ox + x <= target->w); + assert(oy + y <= target->h); byte p = *((byte *)target->getBasePtr(ox + x, oy + y)); *((byte *)target->getBasePtr(ox + x, oy + y)) = (p == kColorWhite) ? kColorBlack : kColorWhite; @@ -476,15 +485,42 @@ void ImageAsset::blitXOR(Graphics::ManagedSurface * target, int ox, int oy, cons } } -void ImageAsset::calculateSubsection(Graphics::ManagedSurface *target, int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h) { - sx = (ox < 0) ? -ox : 0; - sy = (oy < 0) ? -oy : 0; - ox = (ox < 0) ? 0 : ox; - oy = (oy < 0) ? 0 : oy; - w = MAX((int)(bitWidth - sx), 0); - h = MAX((int)(bitHeight - sy), 0); - w = w > target->w ? target->w : w; - h = h > target->h ? target->h : h; +void ImageAsset::calculateSectionToDraw(Graphics::ManagedSurface *target, int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h) { + + calculateSectionInDirection(target->w, bitWidth, ox, sx, w); + calculateSectionInDirection(target->h, bitHeight, oy, sy, h); + + assert(w <= target->w); + assert((int)w >= 0); + assert(w <= bitWidth); + assert(h <= target->h); + assert((int)h >= 0); + assert(h <= bitHeight); +} + +void ImageAsset::calculateSectionInDirection(uint targetWhole, uint originWhole, int &originPosition, uint &startPosition, uint &blittedWhole) { + blittedWhole = originWhole; + if (originPosition + blittedWhole > targetWhole) { + if (originPosition > (int)targetWhole) { + blittedWhole = 0; + } else { + blittedWhole = (blittedWhole) - ((blittedWhole + originPosition) - targetWhole); + } + + } + if (originPosition < 0) { + if (ABS(originPosition) > (int)blittedWhole) { + blittedWhole = 0; + } else { + blittedWhole -= -originPosition; + } + } + + startPosition = 0; + if (originPosition < 0) { + startPosition = -originPosition; + originPosition = 0; + } } } // End of namespace MacVenture diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 3910f83fa8..1f7d3e91b4 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -58,7 +58,7 @@ public: ImageAsset(ObjID original, Container *container); ~ImageAsset(); - void blitInto(Graphics::ManagedSurface *target, uint32 x, uint32 y, BlitMode mode); + void blitInto(Graphics::ManagedSurface *target, int x, int y, BlitMode mode); bool isPointInside(Common::Point point); bool isRectInside(Common::Rect rect); @@ -82,7 +82,8 @@ private: void blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); void blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void calculateSubsection(Graphics::ManagedSurface *target, int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h); + void calculateSectionToDraw(Graphics::ManagedSurface *target, int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h); + void calculateSectionInDirection(uint targetWhole, uint originWhole, int &originPosition, uint &startPosition, uint &blittedWhole); private: ObjID _id; -- cgit v1.2.3 From 62af855e33aee4cf8e7a66cc9c2b5d0948f526b1 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 14 Aug 2016 12:21:04 +0200 Subject: MACVENTURE: Fix operate command --- engines/macventure/macventure.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 16be24b2c4..1244c83d16 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -683,8 +683,9 @@ void MacVentureEngine::unselectAll() { void MacVentureEngine::selectObject(ObjID objID) { if (!_currentSelection.empty()) { - if (findParentWindow(objID) != findParentWindow(_currentSelection[0])) - unselectAll(); + if (findParentWindow(objID) != findParentWindow(_currentSelection[0])) { + //unselectAll(); + } } if (findObjectInArray(objID, _currentSelection) == -1) { _currentSelection.push_back(objID); @@ -896,7 +897,6 @@ void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { } void MacVentureEngine::toggleExits() { - warning("delete this when done testing!"); Common::Array exits = _currentSelection; while (!exits.empty()) { ObjID obj = exits.front(); -- cgit v1.2.3 From fd01961d55e5e749adea193cdadd184aefcd5887 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 14 Aug 2016 20:57:26 +0200 Subject: MACVENTURE: Fix lost constant --- engines/macventure/gui.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 9359097b8a..66136100b6 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -59,6 +59,8 @@ enum { kDragThreshold = 5 }; +const bool kLoadStaticMenus = true; + static const Graphics::MenuData menuSubItems[] = { { kMenuHighLevel, "File", 0, 0, false }, { kMenuHighLevel, "Edit", 0, 0, false }, -- cgit v1.2.3 From 09fe00eb2a8f11e274901a4af4e19ec5275ff7e8 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 15 Aug 2016 11:28:30 +0200 Subject: MACVENTURE: Fix indentation and braces --- engines/macventure/container.h | 4 +-- engines/macventure/controls.h | 35 ++++++++++++++------------- engines/macventure/dialog.cpp | 20 +++++++-------- engines/macventure/gui.cpp | 13 ++++------ engines/macventure/image.cpp | 6 ++--- engines/macventure/macventure.cpp | 17 ++++--------- engines/macventure/module.mk | 21 ++++++++-------- engines/macventure/object.cpp | 30 ----------------------- engines/macventure/object.h | 38 ----------------------------- engines/macventure/script.cpp | 10 +++----- engines/macventure/sound.cpp | 2 +- engines/macventure/text.cpp | 51 ++++++++++++++------------------------- engines/macventure/windows.h | 4 +-- engines/macventure/world.cpp | 4 +-- 14 files changed, 78 insertions(+), 177 deletions(-) delete mode 100644 engines/macventure/object.cpp delete mode 100644 engines/macventure/object.h diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 6979afbb4e..b65c1578cd 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -210,8 +210,8 @@ protected: ContainerHeader _header; - Common::Array _huff; // huffman masks - Common::Array _lens; // huffman lengths + Common::Array _huff; // huffman masks + Common::Array _lens; // huffman lengths Common::Array _groups; Common::String _filename; diff --git a/engines/macventure/controls.h b/engines/macventure/controls.h index 574ae6afbe..3f23aa825d 100644 --- a/engines/macventure/controls.h +++ b/engines/macventure/controls.h @@ -41,24 +41,25 @@ enum ControlType { // HACK, should correspond exactly with the types of controls }; enum ControlAction { // HACK, figure out a way to put it in engine - kNoCommand = 0, - kStartOrResume = 1, - kClose = 2, - kTick = 3, - kActivateObject = 4, - kMoveObject = 5, - kConsume = 6, - kExamine = 7, - kGo = 8, - kHit = 9, - kOpen = 10, - kOperate = 11, - kSpeak = 12, - kBabble = 13, - kTargetName = 14, - kDebugObject = 15, - kClickToContinue = 16 + kNoCommand = 0, + kStartOrResume = 1, + kClose = 2, + kTick = 3, + kActivateObject = 4, + kMoveObject = 5, + kConsume = 6, + kExamine = 7, + kGo = 8, + kHit = 9, + kOpen = 10, + kOperate = 11, + kSpeak = 12, + kBabble = 13, + kTargetName = 14, + kDebugObject = 15, + kClickToContinue = 16 }; + struct ControlData { Common::Rect bounds; uint16 scrollValue; diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 0edec40c4d..ce420a25c3 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -46,7 +46,7 @@ Dialog::~Dialog() { void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { switch(action) { - case kDACloseDialog: + case kDACloseDialog: _gui->closeDialog(); break; case kDASubmit: @@ -71,7 +71,7 @@ void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { break; default: break; - } + } } const Graphics::Font& Dialog::getFont() { @@ -84,11 +84,11 @@ bool Dialog::processEvent(Common::Event event) { } } -void Dialog::addButton(Common::String title, MacVenture::DialogAction action, Common::Point position, uint width, uint height) { +void Dialog::addButton(Common::String title, MacVenture::DialogAction action, Common::Point position, uint width, uint height) { _elements.push_back(new DialogButton(this, title, action, position, width, height)); } -void Dialog::addText(Common::String content, Common::Point position) { +void Dialog::addText(Common::String content, Common::Point position) { _elements.push_back(new DialogPlainText(this, content, position)); } @@ -96,7 +96,7 @@ void Dialog::addTextInput(Common::Point position, int width, int height) { _elements.push_back(new DialogTextInput(this, position, width, height)); } -void Dialog::draw() { +void Dialog::draw() { Graphics::ManagedSurface compose; // Compose the surface compose.create(_bounds.width(), _bounds.height()); @@ -149,7 +149,7 @@ DialogElement::DialogElement(Dialog *dialog, Common::String title, DialogAction _bounds = Common::Rect(position.x, position.y, position.x + width, position.y + height); } -bool DialogElement::processEvent(MacVenture::Dialog *dialog, Common::Event event) { +bool DialogElement::processEvent(MacVenture::Dialog *dialog, Common::Event event) { return doProcessEvent(dialog, event); } @@ -218,7 +218,7 @@ bool DialogTextInput::doProcessEvent(Dialog *dialog, Common::Event event) { if (!_text.empty()) { _text.deleteLastChar(); dialog->setUserInput(_text); - return true; + return true; } break; default: @@ -228,9 +228,9 @@ bool DialogTextInput::doProcessEvent(Dialog *dialog, Common::Event event) { return true; } break; - } - } - return false; + } + } + return false; } void DialogTextInput::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) { diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 66136100b6..8ced27957d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -594,7 +594,7 @@ void Gui::drawMainGameWindow() { if (DebugMan.isDebugChannelEnabled(kMVDebugGUI)) { Graphics::MacWindow *win = findWindow(data.refcon); - Common::Rect innerDims = win->getInnerDimensions(); + Common::Rect innerDims = win->getInnerDimensions(); int x = win->getDimensions().left; int y = win->getDimensions().top; innerDims.translate(-x, -y); @@ -624,7 +624,7 @@ void Gui::drawInventories() { if (DebugMan.isDebugChannelEnabled(kMVDebugGUI)) { Graphics::MacWindow *win = findWindow(data.refcon); - Common::Rect innerDims = win->getInnerDimensions(); + Common::Rect innerDims = win->getInnerDimensions(); int x = win->getDimensions().left; int y = win->getDimensions().top; innerDims.translate(-x, -y); @@ -846,8 +846,7 @@ void Gui::updateExit(ObjID obj) { _exitsData->remove_at(ctl); if (!_engine->isHiddenExit(obj) && - _engine->getParent(obj) == _engine->getParent(1)) - { + _engine->getParent(obj) == _engine->getParent(1)) { ControlData data; data.titleLength = 0; data.refcon = (ControlAction)obj; // Objects can be exits (actions) @@ -1290,8 +1289,7 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { if (it->isInsideBounds(position)) { it->select(); data = *it; - } - else { + } else { it->unselect(); } } @@ -1357,8 +1355,7 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even button = *it; _engine->handleObjectSelect(button.getData().refcon, kExitsWindow, false, false); return true; - } - else { + } else { it->unselect(); } } diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 812e2e3dad..1b0e59d565 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -122,8 +122,7 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight data.push_back(0); } - switch (mode) - { + switch (mode) { case MacVenture::kPPIC0: decodePPIC0(stream, data, bitHeight, bitWidth, rowBytes); break; @@ -279,8 +278,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st for (uint y = 0; y < bitHeight; y++) { uint16 v = 0; if (flags & 2) { - for (uint x = 0; x < rowBytes; x++) - { + for (uint x = 0; x < rowBytes; x++) { data[pos] ^= v; v = data[pos]; pos++; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 1244c83d16..76a4791572 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -393,12 +393,7 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool } else { if (objID == 0) { unselectAll(); - //if (windata.type == kAnimateBack) { - //doLasso(win, event, canDrag); - //} - //else { - objID = win; - //} + objID = win; } if (objID > 0) { int currentObjectIndex = findObjectInArray(objID, _currentSelection); @@ -543,10 +538,9 @@ bool MacVenture::MacVentureEngine::runScriptEngine() { updateState(true); } } - if (_selectedControl == 1) + if (_selectedControl == 1) { _gameChanged = false; - - else if (isGameRunning()) { + } else if (isGameRunning()) { if (_scriptEngine->runControl(kTick, _selectedControl, _destObject, _deltaPoint)) { _haltedAtEnd = true; return true; @@ -1024,7 +1018,7 @@ ObjID MacVentureEngine::getParent(ObjID objID) { Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { Common::Point pos = getObjPosition(objID); - WindowReference win = findParentWindow(objID); + WindowReference win = findParentWindow(objID); if (win != kNoWindow) { // If it's not in a window YET, we don't really care about the border BorderBounds bounds = borderBounds(_gui->getWindowData(win).type); // HACK pos.x += bounds.leftOffset; @@ -1045,8 +1039,7 @@ uint MacVentureEngine::getOverlapPercent(ObjID one, ObjID other) { Common::Rect oneBounds = getObjBounds(one); Common::Rect otherBounds = getObjBounds(other); if (otherBounds.intersects(oneBounds) || - oneBounds.intersects(otherBounds)) - { + oneBounds.intersects(otherBounds)) { uint areaOne = oneBounds.width() * oneBounds.height(); uint areaOther = otherBounds.width() * otherBounds.height(); return (areaOther * 100 / areaOne) | 0; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 7b81018394..ee240269fc 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -1,21 +1,20 @@ MODULE := engines/macventure MODULE_OBJS := \ - image.o \ + controls.o \ + datafiles.o \ detection.o \ - object.o \ - text.o \ - world.o \ - script.o \ - macventure.o \ - gui.o \ dialog.o \ - controls.o \ + gui.o \ + image.o \ + macventure.o \ prebuilt_dialogs.o \ - windows.o \ - sound.o \ saveload.o \ - datafiles.o + script.o \ + sound.o \ + text.o \ + windows.o \ + world.o MODULE_DIRS += \ diff --git a/engines/macventure/object.cpp b/engines/macventure/object.cpp deleted file mode 100644 index 18a734ccd1..0000000000 --- a/engines/macventure/object.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 "macventure/object.h" - -namespace MacVenture { - -Object::Object() {} -Object::~Object() {} - -} // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/object.h b/engines/macventure/object.h deleted file mode 100644 index 1712ec6c17..0000000000 --- a/engines/macventure/object.h +++ /dev/null @@ -1,38 +0,0 @@ -/* 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. -* -*/ - -#ifndef MACVENTURE_OBJECT_H -#define MACVENTURE_OBJECT_H - -#include "macventure/macventure.h" - -namespace MacVenture { - -class Object { -public: - Object(); - ~Object(); -}; - -} // End of namespace MacVenture - -#endif \ No newline at end of file diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5aa8e3cc19..3dc9509555 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -648,17 +648,13 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { if (step<0) step += num; word end = 0; word start = 0; - for (word i = 1;i= num) start -= num; - if (start == end) - { + if (start == end) { end++; start = end; - } - else - { + } else { word a = state->peek(end); word b = state->peek(start); state->poke(end, b); diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 455a1916ac..eb0941607c 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -56,7 +56,7 @@ uint32 SoundManager::playSound(ObjID sound) { void SoundManager::ensureLoaded(ObjID sound) { if (!_assets.contains(sound)) - _assets[sound] = new SoundAsset(_container, sound); + _assets[sound] = new SoundAsset(_container, sound); } SoundAsset::SoundAsset(Container *container, ObjID id) : diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 745def2cc4..095b0f3332 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -34,8 +34,7 @@ TextAsset::TextAsset(MacVentureEngine *engine, ObjID objid, ObjID source, ObjID if (_isOld) { decodeOld(); - } - else { + } else { decodeHuffman(); } } @@ -51,35 +50,28 @@ void TextAsset::decodeOld() { char val = stream.getBits(5); if (val == 0x0) { // Space c = ' '; - } - else if (val >= 0x1 && val <= 0x1A) { + } else if (val >= 0x1 && val <= 0x1A) { if (lowercase) { // Ascii a-z c = val + 0x60; - } - else { // Ascii A-Z + } else { // Ascii A-Z c = val + 0x40; } lowercase = true; - } - else if (val == 0x1B) { + } else if (val == 0x1B) { if (lowercase) { c = '.'; - } - else { + } else { c = ','; } lowercase = true; - } - else if (val == 0x1C) { + } else if (val == 0x1C) { if (lowercase) { c = 0x27; // Ascii ' - } - else { + } else { c = 0x22; // Ascii '"' } lowercase = true; - } - else if (val == 0x1D) { // Composite + } else if (val == 0x1D) { // Composite ObjID subval = stream.getBits(16); Common::String child; if (subval & 0x8000) { @@ -95,15 +87,12 @@ void TextAsset::decodeOld() { c = '?'; // HACK Will fix later, should append } lowercase = true; - } - else if (val == 0x1E) { + } else if (val == 0x1E) { c = stream.getBits(8); lowercase = true; - } - else if (val == 0x1F) { + } else if (val == 0x1F) { lowercase = !lowercase; - } - else { + } else { warning("Unrecognized char in old text %d, pos %d", _id, i); } str[i] = c; @@ -121,8 +110,7 @@ void TextAsset::decodeHuffman() { uint16 strLen = 0; if (stream.getBit()) { strLen = stream.getBits(15); - } - else { + } else { strLen = stream.getBits(7); } // OK up to here @@ -179,22 +167,19 @@ void TextAsset::decodeHuffman() { Common::String TextAsset::getNoun(ObjID subval) { ObjID obj; Common::String name; - if (subval & 8) + if (subval & 8) { obj = _targetObj; - else + } else { obj = _sourceObj; - if ((subval & 3) == 1) - { + } + if ((subval & 3) == 1) { uint idx = _engine->getPrefixNdx(obj); idx = ((idx >> 4) & 3) + 1; name = _engine->getNoun(idx); - } - else - { + } else { // HACK, there should be a pool of assets or something like in the GUI name = *TextAsset(_engine, obj, _sourceObj, _targetObj, _container, _isOld, _huffman).decode(); - switch (subval & 3) - { + switch (subval & 3) { case 2: name = _engine->getPrefixString(0, obj) + name; break; diff --git a/engines/macventure/windows.h b/engines/macventure/windows.h index fe3f9275d0..1727698ad4 100644 --- a/engines/macventure/windows.h +++ b/engines/macventure/windows.h @@ -27,7 +27,7 @@ #include "common/array.h" namespace MacVenture { - // massive HACK +// massive HACK typedef uint32 ObjID; enum WindowReference { @@ -92,7 +92,7 @@ struct BorderBounds { uint16 bottomOffset; BorderBounds(uint16 l, uint16 t, uint16 r, uint16 b) : - leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} + leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} }; } #endif diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 20695dbff6..35cfbd1533 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -5,7 +5,7 @@ namespace MacVenture { -World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { +World::World(MacVentureEngine *engine, Common::MacResManager *resMan) { _resourceManager = resMan; _engine = engine; _saveGame = NULL; @@ -104,7 +104,7 @@ bool MacVenture::World::isObjActive(ObjID obj) { if (!getAncestor(obj)) return false; // If our ancestor is the garbage (obj 0), we're inactive if (_engine->getInvolvedObjects() >= 2 && // If (we need > 1 objs for the command) && destObj > 0 && // we have a destination object && - !getAncestor(destObj)) // but that destination object is in the garbage + !getAncestor(destObj)) // but that destination object is in the garbage return false; if (selectedControl != kMoveObject) return true; // We only need one // Handle move object -- cgit v1.2.3 From 9c0777efbf5a59df90728087276245208c13988f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 15 Aug 2016 12:45:21 +0200 Subject: MACVENTURE: Fix some compiler warnings --- engines/macventure/datafiles.cpp | 1 + engines/macventure/detection.cpp | 4 +--- engines/macventure/dialog.cpp | 1 + engines/macventure/gui.cpp | 12 ++++-------- engines/macventure/image.cpp | 4 ++-- engines/macventure/macventure.cpp | 4 +--- engines/macventure/script.cpp | 8 +++++--- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp index 496fa919c8..a86e922193 100644 --- a/engines/macventure/datafiles.cpp +++ b/engines/macventure/datafiles.cpp @@ -61,6 +61,7 @@ Common::String windowTypeName(MVWindowType windowType) { case kRDoc10: return "RDoc10"; } + return ""; } void MacVentureEngine::loadDataBundle() { diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 9bf94cfdd4..d0a2940269 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -93,8 +93,6 @@ SaveStateList MacVentureMetaEngine::listSaves(const char *target) const { SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { int slotNum = atoi(file->c_str() + file->size() - 3); - Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); - SaveStateDescriptor desc; // Do not allow save slot 0 (used for auto-saving) to be deleted or // overwritten. @@ -104,7 +102,7 @@ SaveStateList MacVentureMetaEngine::listSaves(const char *target) const { if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { - SaveStateDescriptor desc = loadMetaData(in, slotNum); + desc = loadMetaData(in, slotNum); if (desc.getSaveSlot() != slotNum) { // invalid delete in; diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index ce420a25c3..043cd38a92 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -82,6 +82,7 @@ bool Dialog::processEvent(Common::Event event) { for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { if ((*it)->processEvent(this, event)) return true; } + return false; } void Dialog::addButton(Common::String title, MacVenture::DialogAction action, Common::Point position, uint width, uint height) { diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 8ced27957d..310cf92443 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -392,7 +392,6 @@ bool Gui::loadMenus() { int i = 1; for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); - bool enabled; uint16 key; uint16 style; uint8 titleLength; @@ -400,7 +399,6 @@ bool Gui::loadMenus() { /* Skip menuID, width, height, resourceID, placeholder */ for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } - enabled = res->readUint32BE(); titleLength = res->readByte(); title = new char[titleLength + 1]; res->read(title, titleLength); @@ -410,7 +408,7 @@ bool Gui::loadMenus() { _menu->addMenuItem(title); // Read submenu items - while (titleLength = res->readByte()) { + while ((titleLength = res->readByte())) { title = new char[titleLength + 1]; res->read(title, titleLength); title[titleLength] = '\0'; @@ -495,7 +493,6 @@ bool Gui::loadControls() { if ((resArray = _resourceManager->getResIDArray(MKTAG('C', 'N', 'T', 'L'))).size() == 0) return false; - uint16 commandsBorder = borderBounds(kPlainDBox).topOffset; uint32 id = kControlExitBox; for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = _resourceManager->getResource(MKTAG('C', 'N', 'T', 'L'), *iter); @@ -553,7 +550,6 @@ void Gui::drawCommandsWindow() { if (_engine->needsClickToContinue()) { Graphics::ManagedSurface *srf = _controlsWindow->getSurface(); WindowData data = getWindowData(kCommandsWindow); - uint16 border = borderBounds(data.type).topOffset; srf->fillRect(Common::Rect(0, 0, srf->w, srf->h), kColorWhite); getCurrentFont().drawString( srf, @@ -618,12 +614,10 @@ void Gui::drawInventories() { Graphics::MacWindow *win = findWindow(data.refcon); srf = win->getSurface(); srf->clear(kColorGreen); - BorderBounds border = borderBounds(data.type); srf->fillRect(srf->getBounds(), kColorWhite); drawObjectsInWindow(data, srf); if (DebugMan.isDebugChannelEnabled(kMVDebugGUI)) { - Graphics::MacWindow *win = findWindow(data.refcon); Common::Rect innerDims = win->getInnerDimensions(); int x = win->getDimensions().left; int y = win->getDimensions().top; @@ -988,13 +982,15 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) { return _exitsWindow; case MacVenture::kDiplomaWindow: return _diplomaWindow; + default: + return NULL; } return NULL; } void Gui::ensureInventoryOpen(WindowReference reference, ObjID id) { assert(reference < 0x80 && reference >= kInventoryStart); - if (reference - kInventoryStart == _inventoryWindows.size()) { + if (reference - kInventoryStart == (int)_inventoryWindows.size()) { createInventoryWindow(id); } } diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index 1b0e59d565..a472c6880a 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -118,7 +118,7 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight bitWidth = w; bitHeight = h; - for (int i = 0; i < rowBytes * h; i++) { + for (uint i = 0; i < rowBytes * h; i++) { data.push_back(0); } @@ -300,7 +300,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st if (flags & 2) delta *= 2; pos = 0; uint q = delta; - for (int i = 0; i < bitHeight * rowBytes - delta; i++) { + for (uint i = 0; i < bitHeight * rowBytes - delta; i++) { data[q] ^= data[pos]; q++; pos++; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 76a4791572..0542665d3c 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -377,8 +377,6 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool win = kMainGameWindow; } - bool canDrag = (objID && !_world->getObjAttr(objID, kAttrInvisible)); - const WindowData &windata = _gui->getWindowData(win); if (shiftPressed) { @@ -802,7 +800,7 @@ void MacVentureEngine::openObject(ObjID objID) { void MacVentureEngine::closeObject(ObjID objID) { warning("closeObject: not fully implemented"); - bool success = _gui->tryCloseWindow(getObjWindow(objID)); + _gui->tryCloseWindow(getObjWindow(objID)); return; } diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 3dc9509555..c743e49a55 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -119,7 +119,7 @@ bool ScriptEngine::execFrame(bool execAll) { } } - uint highest = 0; + int highest = 0; uint localHigh = 0; do { // Saved function calls highest = 0; @@ -914,6 +914,7 @@ bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { if (execFrame(true)) { return true; } + return false; } bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { @@ -926,6 +927,7 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse frame->scripts.pop_front(); script = frame->scripts.front(); debugC(2, kMVDebugScript, "SCRIPT: Return from fuction %d", id); + return false; } void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { @@ -1072,9 +1074,9 @@ void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { word txt = state->pop(); if (_engine->showTextEntry(txt, frame->src, frame->dest)) { - state->push(0xFFFF); + state->push(0xFF); } else { - state->push(0x0000); + state->push(0x00); } } -- cgit v1.2.3 From 234a3b95a29e3ec11c9c02a2435bf42829550cce Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 15 Aug 2016 20:49:02 +0200 Subject: MACVENTURE: Fix cursor warning --- engines/macventure/cursor.cpp | 128 ++++++++++++++++++++++++++++++++++++++++++ engines/macventure/gui.h | 117 ++++---------------------------------- engines/macventure/image.cpp | 29 +++++----- engines/macventure/module.mk | 1 + 4 files changed, 154 insertions(+), 121 deletions(-) create mode 100644 engines/macventure/cursor.cpp diff --git a/engines/macventure/cursor.cpp b/engines/macventure/cursor.cpp new file mode 100644 index 0000000000..655615a523 --- /dev/null +++ b/engines/macventure/cursor.cpp @@ -0,0 +1,128 @@ +/* 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 "macventure/gui.h" + +namespace MacVenture { + +static void cursorTimerHandler(void *refCon); + +static const ClickState _transitionTable[kCursorStateCount][kCursorInputCount] = { + /* Button down, Button Up, Tick */ + /* Idle */ {kCursorSCStart, kCursorIdle, kCursorIdle }, + /* SC Start */ {kCursorSCStart, kCursorDCStart, kCursorSCDrag}, + /* SC Do */ {kCursorSCDrag, kCursorIdle, kCursorSCDrag}, + /* DC Start */ {kCursorDCDo, kCursorDCStart, kCursorSCSink}, + /* DC Do */ {kCursorDCDo, kCursorIdle, kCursorDCDo }, + /* SC Sink */ {kCursorIdle, kCursorIdle, kCursorIdle } +}; + +Cursor::Cursor(Gui *gui) { + _gui = gui; + _state = kCursorIdle; +} +Cursor::~Cursor() {} + +void Cursor::tick() { + changeState(kTickCol); +} + +bool Cursor::processEvent(const Common::Event &event) { + if (event.type == Common::EVENT_MOUSEMOVE) { + _pos = event.mouse; + return true; + } + if (event.type == Common::EVENT_LBUTTONDOWN) { + changeState(kButtonDownCol); + return true; + } + if (event.type == Common::EVENT_LBUTTONUP) { + changeState(kButtonUpCol); + return true; + } + + return false; +} + +Common::Point Cursor::getPos() { + return _pos; +} + +bool Cursor::canSelectDraggable() { + return _state == kCursorSCDrag; +} + +void Cursor::changeState(CursorInput input) { + debugC(3, kMVDebugGUI, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); + if (_state != _transitionTable[_state][input]) { + executeStateOut(); + _state = _transitionTable[_state][input]; + executeStateIn(); + } +} + +void Cursor::executeStateIn() { + switch (_state) { + case kCursorSCStart: + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); + _gui->selectForDrag(_pos); + break; + case kCursorDCStart: + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); + break; + case kCursorSCSink: + _gui->handleSingleClick(); + changeState(kTickCol); + break; + default: + break; + } +} + +void Cursor::executeStateOut() { + switch (_state) { + case kCursorIdle: + break; + case kCursorSCStart: + g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); + break; + case kCursorSCDrag: + _gui->handleSingleClick(); + break; + case kCursorDCStart: + g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); + break; + case kCursorDCDo: + _gui->handleDoubleClick(); + break; + default: + break; + } +} + +static void cursorTimerHandler(void *refCon) { + Cursor *cursor = (Cursor *)refCon; + cursor->tick(); +} + + +} // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 5835202904..28ee85ddae 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -83,15 +83,6 @@ struct DraggedObj { bool hasMoved; }; -enum CursorState { - // HACK, I should define a proper FSM for this - kCursorIdle, - kCursorSingleClick, // Triggered when mouse goes up - kCursorSingleClickAwait, // Triggered when we are in single click and mouse goes down - kCursorSingleClickTrap, // Trap state, for when we are in await, and the timer goes off - kCursorDoubleClick -}; - class Gui { public: @@ -251,9 +242,6 @@ private: // Methods }; -static void cursorTimerHandler(void *refCon); - -class Cursor { enum ClickState { kCursorIdle = 0, kCursorSCStart = 1, @@ -271,103 +259,22 @@ enum CursorInput { // Columns for the FSM transition table kCursorInputCount }; - -ClickState _transitionTable[kCursorStateCount][kCursorInputCount] = { - /* Button down, Button Up, Tick */ - /* Idle */ {kCursorSCStart, kCursorIdle, kCursorIdle }, - /* SC Start */ {kCursorSCStart, kCursorDCStart, kCursorSCDrag}, - /* SC Do */ {kCursorSCDrag, kCursorIdle, kCursorSCDrag}, - /* DC Start */ {kCursorDCDo, kCursorDCStart, kCursorSCSink}, - /* DC Do */ {kCursorDCDo, kCursorIdle, kCursorDCDo }, - /* SC Sink */ {kCursorIdle, kCursorIdle, kCursorIdle }, -}; +class Cursor { public: - Cursor(Gui *gui) { - _gui = gui; - _state = kCursorIdle; - } - - ~Cursor() {} - - void tick() { - changeState(kTickCol); - } + Cursor(Gui *gui); + ~Cursor(); - bool processEvent(const Common::Event &event) { - if (event.type == Common::EVENT_MOUSEMOVE) { - _pos = event.mouse; - return true; - } - if (event.type == Common::EVENT_LBUTTONDOWN) { - changeState(kButtonDownCol); - return true; - } - if (event.type == Common::EVENT_LBUTTONUP) { - changeState(kButtonUpCol); - return true; - } - - return false; - } - - Common::Point getPos() { - return _pos; - } - - bool canSelectDraggable() { - return _state == kCursorSCDrag; - } + void tick(); + bool processEvent(const Common::Event &event); + Common::Point getPos(); + bool canSelectDraggable(); private: - void changeState(CursorInput input) { - debugC(3, kMVDebugGUI, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); - if (_state != _transitionTable[_state][input]) { - executeStateOut(); - _state = _transitionTable[_state][input]; - executeStateIn(); - } - } - - void executeStateIn() { - switch (_state) { - case kCursorSCStart: - g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); - _gui->selectForDrag(_pos); - break; - case kCursorDCStart: - g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 300000, this, "macVentureCursor"); - break; - case kCursorSCSink: - _gui->handleSingleClick(); - changeState(kTickCol); - break; - default: - break; - } - } - - void executeStateOut() { - switch (_state) { - case kCursorIdle: - break; - case kCursorSCStart: - g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); - break; - case kCursorSCDrag: - _gui->handleSingleClick(); - break; - case kCursorDCStart: - g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); - break; - case kCursorDCDo: - _gui->handleDoubleClick(); - break; - default: - break; - } - } + void changeState(CursorInput input); + void executeStateIn(); + void executeStateOut(); private: @@ -377,10 +284,6 @@ private: ClickState _state; }; -static void cursorTimerHandler(void *refCon) { - Cursor *cursor = (Cursor *)refCon; - cursor->tick(); -} enum { diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index a472c6880a..f4d46b039f 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -24,7 +24,7 @@ namespace MacVenture { -PPICHuff PPIC1Huff = { +static const PPICHuff PPIC1Huff = { // Masks { 0x0000,0x2000,0x4000,0x5000,0x6000,0x7000,0x8000,0x9000,0xa000, 0xb000,0xc000,0xd000,0xd800,0xe000,0xe800,0xf000,0xf800 }, @@ -35,7 +35,7 @@ PPICHuff PPIC1Huff = { 0x02,0x04,0x0b,0x0d,0xe } }; -PPICHuff PPIC2Huff = { +static const PPICHuff PPIC2Huff = { // Masks { 0x0000,0x4000,0x8000,0xc000,0xc800,0xd000,0xd800,0xe000,0xe800, 0xf000,0xf400,0xf600,0xf800,0xfa00,0xfc00,0xfe00,0xff00 }, @@ -47,18 +47,19 @@ PPICHuff PPIC2Huff = { }; // Used to load the huffman table in PPIC3 decoding -byte loadBits[] = { - 0x08, 0x0f, 0x02, 0xff, 0x00, - 0x04, 0xff, 0x01, - 0x07, 0x09, 0x08, 0xff, 0x03, - 0x04, 0xff, 0x04, - 0x0a, 0x07, 0x0a, 0x0b, 0x06, 0xff, 0x05, - 0x06, 0x06, 0x0b, 0xff, 0x07, - 0x03, 0xff, 0x09, - 0x04, 0x03, 0x0e, 0xff, 0x0c, - 0x02, 0xff, 0x0d, - 0x01, 0xff, 0x0f, - 0xff }; +static const byte loadBits[] = { + 0x08, 0x0f, 0x02, 0xff, 0x00, + 0x04, 0xff, 0x01, + 0x07, 0x09, 0x08, 0xff, 0x03, + 0x04, 0xff, 0x04, + 0x0a, 0x07, 0x0a, 0x0b, 0x06, 0xff, 0x05, + 0x06, 0x06, 0x0b, 0xff, 0x07, + 0x03, 0xff, 0x09, + 0x04, 0x03, 0x0e, 0xff, 0x0c, + 0x02, 0xff, 0x0d, + 0x01, 0xff, 0x0f, + 0xff +}; ImageAsset::ImageAsset(ObjID original, Container * container) { _id = (original * 2); diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index ee240269fc..44b0fa06d9 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -2,6 +2,7 @@ MODULE := engines/macventure MODULE_OBJS := \ controls.o \ + cursor.o \ datafiles.o \ detection.o \ dialog.o \ -- cgit v1.2.3 From b1eb6da6fab27b215ffd339ccef7e43169ad0a17 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 10:40:46 +0200 Subject: MACVENTURE: Add prefixes to error messages --- engines/macventure/container.h | 2 +- engines/macventure/datafiles.cpp | 2 +- engines/macventure/gui.cpp | 8 ++++---- engines/macventure/macventure.cpp | 6 +++--- engines/macventure/menu.cpp | 2 +- engines/macventure/saveload.cpp | 2 +- engines/macventure/stringtable.h | 2 +- engines/macventure/world.cpp | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/engines/macventure/container.h b/engines/macventure/container.h index b65c1578cd..6b9c6462ca 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -46,7 +46,7 @@ public: _filename = filename; if (!_file.open(_filename)) - error("Could not open %s", _filename.c_str()); + error("CONTAINER: Could not open %s", _filename.c_str()); _res = _file.readStream(_file.size()); _header = _res->readUint32BE(); diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp index a86e922193..9532434f03 100644 --- a/engines/macventure/datafiles.cpp +++ b/engines/macventure/datafiles.cpp @@ -67,7 +67,7 @@ Common::String windowTypeName(MVWindowType windowType) { void MacVentureEngine::loadDataBundle() { _dataBundle = Common::makeZipArchive(MACVENTURE_DATA_BUNDLE); if (!_dataBundle) - error("Couldn't load data bundle '%s'.", MACVENTURE_DATA_BUNDLE.c_str()); + error("ENGINE: Couldn't load data bundle '%s'.", MACVENTURE_DATA_BUNDLE.c_str()); } Common::SeekableReadStream *MacVentureEngine::getBorderFile(MVWindowType windowType, bool isActive) { diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 310cf92443..264e577792 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -152,21 +152,21 @@ void Gui::initGUI() { // Menu _menu = _wm.addMenu(); if (!loadMenus()) - error("Could not load menus"); + error("GUI: Could not load menus"); _menu->setCommandsCallback(menuCommandsCallback, this); _menu->calcDimensions(); loadGraphics(); if (!loadWindows()) - error("Could not load windows"); + error("GUI: Could not load windows"); initWindows(); assignObjReferences(); if (!loadControls()) - error("Could not load controls"); + error("GUI: Could not load controls"); draw(); @@ -960,7 +960,7 @@ WindowData & Gui::findWindowData(WindowReference reference) { if (iter->refcon == reference) return *iter; - error("Could not locate the desired window data"); + error("GUI: Could not locate the desired window data"); } Graphics::MacWindow * Gui::findWindow(WindowReference reference) { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 0542665d3c..ef2b7fadb0 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -143,11 +143,11 @@ Common::Error MacVentureEngine::run() { _resourceManager = new Common::MacResManager(); if (!_resourceManager->open(getGameFileName())) - error("Could not open %s as a resource fork", getGameFileName()); + error("ENGINE: Could not open %s as a resource fork", getGameFileName()); // Engine-wide loading if (!loadGlobalSettings()) - error("Could not load the engine settings"); + error("ENGINE: Could not load the engine settings"); _oldTextEncoding = !loadTextHuffman(); @@ -170,7 +170,7 @@ Common::Error MacVentureEngine::run() { int directSaveSlotLoading = ConfMan.getInt("save_slot"); if (directSaveSlotLoading >= 0) { if (loadGameState(directSaveSlotLoading).getCode() != Common::kNoError) { - error("Could not load game from slot '%d'", directSaveSlotLoading); + error("ENGINE: Could not load game from slot '%d'", directSaveSlotLoading); } } else { setNewGameState(); diff --git a/engines/macventure/menu.cpp b/engines/macventure/menu.cpp index dd3c495e10..ea80104959 100644 --- a/engines/macventure/menu.cpp +++ b/engines/macventure/menu.cpp @@ -35,7 +35,7 @@ Menu::Menu(MacVentureEngine *engine, Graphics::MacWindowManager *wm) { _menu = _wm->addMenu(); if (!loadMenuData()) - error("Could not load menu data from %s", _engine->getGameFileName()); + error("GUI: Could not load menu data from %s", _engine->getGameFileName()); } Menu::~Menu() { diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index 54009a1127..a341487cf1 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -75,7 +75,7 @@ Common::Error MacVentureEngine::loadGameState(int slot) { Common::String saveFileName = Common::String::format("%s.%03d", _targetName.c_str(), slot); Common::InSaveFile *file; if(!(file = getSaveFileManager()->openForLoading(saveFileName))) { - error("missing savegame file %s", saveFileName.c_str()); + error("ENGINE: Missing savegame file %s", saveFileName.c_str()); } _world->loadGameFrom(file); reset(); diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index 0a5419e235..a03fb28a0d 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -47,7 +47,7 @@ public: _id = id; if (!loadStrings()) - error("Could not load string table %x", id); + error("ENGINE: Could not load string table %x", id); } ~StringTable() { diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 35cfbd1533..4ef55094bb 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -37,11 +37,11 @@ void World::startNewGame() { delete _saveGame; if ((_startGameFileName = _engine->getStartGameFileName()) == "") - error("Could not load initial game configuration"); + error("WORLD: Could not load initial game configuration"); Common::File saveGameFile; if (!saveGameFile.open(_startGameFileName)) - error("Could not load initial game configuration"); + error("WORLD: Could not load initial game configuration"); debug("Loading save game state from %s", _startGameFileName.c_str()); Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); -- cgit v1.2.3 From 1c687a7e2c1a848de426a23180c80e07dd4bd135 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 10:41:44 +0200 Subject: MACVENTURE: Remove unused files --- engines/macventure/menu.cpp | 53 ------------------------------------------ engines/macventure/menu.h | 56 --------------------------------------------- 2 files changed, 109 deletions(-) delete mode 100644 engines/macventure/menu.cpp delete mode 100644 engines/macventure/menu.h diff --git a/engines/macventure/menu.cpp b/engines/macventure/menu.cpp deleted file mode 100644 index ea80104959..0000000000 --- a/engines/macventure/menu.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* 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 "macventure/menu.h" -#include "macventure/macventure.h" - -#include "common/file.h" -#include "graphics/macgui/macwindowmanager.h" - -namespace MacVenture { - -Menu::Menu(MacVentureEngine *engine, Graphics::MacWindowManager *wm) { - - _engine = engine; - _wm = wm; - - _menu = _wm->addMenu(); - - if (!loadMenuData()) - error("GUI: Could not load menu data from %s", _engine->getGameFileName()); -} - -Menu::~Menu() { - delete _ -} - -void Menu::draw() { - -} - -bool Menu::loadMenuData() { - -} - -} // End of namespace MacVenture \ No newline at end of file diff --git a/engines/macventure/menu.h b/engines/macventure/menu.h deleted file mode 100644 index dab6369e15..0000000000 --- a/engines/macventure/menu.h +++ /dev/null @@ -1,56 +0,0 @@ -/* 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. -* -*/ - -#ifndef MACVENTURE_MENU_H -#define MACVENTURE_MENU_H - -namespace MacVenture { - -class MacVentureEngine; - -class Graphics::MacWindowManager; - -class Menu { - -public: - Menu(MacVentureEngine *engine, Graphics::MacWindowManager *wm); - ~Menu(); - - void draw(); - -private: // Attributes - - MacVentureEngine *_engine; - Graphics::MacWindowManager *_wm; - Graphics::Menu *_menu; - -private: // Methods - - void init(); - bool loadMenuData(); - -}; - -} // End of namespace MacVenture - -#endif - -- cgit v1.2.3 From b24c04736c377be9bdf9142e852dd6ff6afb8a0e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 10:50:41 +0200 Subject: MACVENTURE: Extract implementation of Container --- engines/macventure/container.cpp | 180 +++++++++++++++++++++++++++++++++++++++ engines/macventure/container.h | 153 +-------------------------------- engines/macventure/module.mk | 1 + 3 files changed, 185 insertions(+), 149 deletions(-) create mode 100644 engines/macventure/container.cpp diff --git a/engines/macventure/container.cpp b/engines/macventure/container.cpp new file mode 100644 index 0000000000..73f706a0c5 --- /dev/null +++ b/engines/macventure/container.cpp @@ -0,0 +1,180 @@ +/* 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 "macventure/container.h" + +namespace MacVenture { + +Container::Container(Common::String filename) { + _filename = filename; + + if (!_file.open(_filename)) + error("CONTAINER: Could not open %s", _filename.c_str()); + + _res = _file.readStream(_file.size()); + _header = _res->readUint32BE(); + _simplified = false; + + for (uint i = 0; i < 16; ++i) + _huff.push_back(0); + + for (uint i = 0; i < 16; ++i) + _lens.push_back(0); + + if (!(_header & 0x80000000)) { + // Is simplified container + _simplified = true; + int dataLen = _res->size() - sizeof(_header); + _lenObjs = _header; + _numObjs = dataLen / _lenObjs; + } else { + _header &= 0x7fffffff; + _res->seek(_header, SEEK_SET); + _numObjs = _res->readUint16BE(); + + for (uint i = 0; i < 15; ++i) + _huff[i] = _res->readUint16BE(); + + for (uint i = 0; i < 16; ++i) + _lens[i] = _res->readByte(); + + // Read groups + uint numGroups = _numObjs / 64; + if ((_numObjs % 64) > 0) + numGroups++; + + for (uint i = 0; i < numGroups; ++i) { + ItemGroup group; + + // Place myself in the correct position to read group + _res->seek(_header + (i * 6) + 0x30, SEEK_SET); + byte b1, b2, b3; + b1 = _res->readByte(); + b2 = _res->readByte(); + b3 = _res->readByte(); + group.bitOffset = (b1 << 16) + (b2 << 8) + (b3 << 0); + + b1 = _res->readByte(); + b2 = _res->readByte(); + b3 = _res->readByte(); + group.offset = (b1 << 16) + (b2 << 8) + (b3 << 0); + + // Place the bit reader in the correct position + // group.bitOffset indicates the offset from the start of the subHeader + _res->seek(_header + (group.bitOffset >> 3), SEEK_SET); + uint32 bits = group.bitOffset & 7; + + for (uint j = 0; j < 64; ++j) { + uint32 length = 0; + uint32 mask = 0; + mask = _res->readUint32BE(); + mask >>= (16 - bits); + mask &= 0xFFFF; + debugC(11, kMVDebugContainer, "Load mask of object &%d:%d is %x", i, j, mask); + _res->seek(-4, SEEK_CUR); + // Look in the Huffman table + int x = 0; + for (x = 0; x < 16; x++) { + if (_huff[x] > mask) break; + } + + // I will opt to copy the code from webventure, + // But according to the docs, this call should suffice: + // length = bitStream.getBits(_lens[x]); + // The problem is that _lens[] usually contains values larger + // Than 32, so we have to read them with the method below + + //This code below, taken from the implementation, seems to give the same results. + + uint32 bitSize = _lens[x]; + bits += bitSize & 0xF; + if (bits & 0x10) { + bits &= 0xF; + _res->seek(2, SEEK_CUR); + } + bitSize >>= 4; + if (bitSize) { + length = _res->readUint32BE(); + _res->seek(-4, SEEK_CUR); + bitSize--; + if (bitSize == 0) length = 0; + else length >>= (32 - bitSize) - bits; + length &= (1 << bitSize) - 1; + length |= 1 << bitSize; + bits += bitSize; + if (bits & 0x10) { + bits &= 0xF; + _res->seek(2, SEEK_CUR); + } + } + + group.lengths[j] = length; + debugC(11, kMVDebugContainer, "Load legth of object %d:%d is %d", i, j, length); + } + + _groups.push_back(group); + } + } +} + +Container::~Container() { + + if (_file.isOpen()) + _file.close(); + + if (_res) + delete _res; +} + +uint32 Container::getItemByteSize(uint32 id) { + if (_simplified) { + return _lenObjs; + } else { + uint32 groupID = (id >> 6); + uint32 objectIndex = id & 0x3f; // Index within the group + return _groups[groupID].lengths[objectIndex]; + } +} + +Common::SeekableReadStream *Container::getItem(uint32 id) { + if (_simplified) { + _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); + } else { + uint32 groupID = (id >> 6); + uint32 objectIndex = id & 0x3f; // Index within the group + + uint32 offset = 0; + for (uint i = 0; i < objectIndex; i++) { + offset += _groups[groupID].lengths[i]; + } + + _res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); + + } + + // HACK Should Limit the size of the stream returned + Common::SeekableReadStream *res = _res->readStream(_res->size() - _res->pos() + 1); + return res; +} + + +} // End of namespace MacVenture diff --git a/engines/macventure/container.h b/engines/macventure/container.h index 6b9c6462ca..e630bdf1be 100644 --- a/engines/macventure/container.h +++ b/engines/macventure/container.h @@ -42,164 +42,19 @@ typedef uint32 ContainerHeader; class Container { public: - Container(Common::String filename) { - _filename = filename; - - if (!_file.open(_filename)) - error("CONTAINER: Could not open %s", _filename.c_str()); - - _res = _file.readStream(_file.size()); - _header = _res->readUint32BE(); - _simplified = false; - - for (uint i = 0; i < 16; ++i) - _huff.push_back(0); - - for (uint i = 0; i < 16; ++i) - _lens.push_back(0); - - if (!(_header & 0x80000000)) { - // Is simplified container - _simplified = true; - int dataLen = _res->size() - sizeof(_header); - _lenObjs = _header; - _numObjs = dataLen / _lenObjs; - } else { - _header &= 0x7fffffff; - _res->seek(_header, SEEK_SET); - _numObjs = _res->readUint16BE(); - - for (uint i = 0; i < 15; ++i) - _huff[i] = _res->readUint16BE(); - - for (uint i = 0; i < 16; ++i) - _lens[i] = _res->readByte(); - - // Read groups - uint numGroups = _numObjs / 64; - if ((_numObjs % 64) > 0) - numGroups++; - - for (uint i = 0; i < numGroups; ++i) { - ItemGroup group; - - // Place myself in the correct position to read group - _res->seek(_header + (i * 6) + 0x30, SEEK_SET); - byte b1, b2, b3; - b1 = _res->readByte(); - b2 = _res->readByte(); - b3 = _res->readByte(); - group.bitOffset = (b1 << 16) + (b2 << 8) + (b3 << 0); - - b1 = _res->readByte(); - b2 = _res->readByte(); - b3 = _res->readByte(); - group.offset = (b1 << 16) + (b2 << 8) + (b3 << 0); - - // Place the bit reader in the correct position - // group.bitOffset indicates the offset from the start of the subHeader - _res->seek(_header + (group.bitOffset >> 3), SEEK_SET); - uint32 bits = group.bitOffset & 7; - - for (uint j = 0; j < 64; ++j) { - uint32 length = 0; - uint32 mask = 0; - mask = _res->readUint32BE(); - mask >>= (16 - bits); - mask &= 0xFFFF; - debugC(11, kMVDebugContainer, "Load mask of object &%d:%d is %x", i, j, mask); - _res->seek(-4, SEEK_CUR); - // Look in the Huffman table - int x = 0; - for (x = 0; x < 16; x++) { - if (_huff[x] > mask) break; - } - - // I will opt to copy the code from webventure, - // But according to the docs, this call should suffice: - // length = bitStream.getBits(_lens[x]); - // The problem is that _lens[] usually contains values larger - // Than 32, so we have to read them with the method below - - //This code below, taken from the implementation, seems to give the same results. - - uint32 bitSize = _lens[x]; - bits += bitSize & 0xF; - if (bits & 0x10) { - bits &= 0xF; - _res->seek(2, SEEK_CUR); - } - bitSize >>= 4; - if (bitSize) { - length = _res->readUint32BE(); - _res->seek(-4, SEEK_CUR); - bitSize--; - if (bitSize == 0) length = 0; - else length >>= (32 - bitSize) - bits; - length &= (1 << bitSize) - 1; - length |= 1 << bitSize; - bits += bitSize; - if (bits & 0x10) { - bits &= 0xF; - _res->seek(2, SEEK_CUR); - } - } - - group.lengths[j] = length; - debugC(11, kMVDebugContainer, "Load legth of object %d:%d is %d", i, j, length); - } - - _groups.push_back(group); - } - } - } - - ~Container() { - - if (_file.isOpen()) - _file.close(); - - if (_res) - delete _res; - } + Container(Common::String filename); + ~Container(); public: /** * Must be called before retrieving an object. */ - uint32 getItemByteSize(uint32 id) { - if (_simplified) { - return _lenObjs; - } else { - uint32 groupID = (id >> 6); - uint32 objectIndex = id & 0x3f; // Index within the group - return _groups[groupID].lengths[objectIndex]; - } - } + uint32 getItemByteSize(uint32 id); /** * getItemByteSize should be called before this one */ - Common::SeekableReadStream *getItem(uint32 id) { - if (_simplified) { - _res->seek((id * _lenObjs) + sizeof(_header), SEEK_SET); - } else { - uint32 groupID = (id >> 6); - uint32 objectIndex = id & 0x3f; // Index within the group - - uint32 offset = 0; - for (uint i = 0; i < objectIndex; i++) { - offset += _groups[groupID].lengths[i]; - } - - _res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); - - } - - // HACK Should Limit the size of the stream returned - Common::SeekableReadStream *res = _res->readStream(_res->size() - _res->pos() + 1); - return res; - } + Common::SeekableReadStream *getItem(uint32 id); protected: diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 44b0fa06d9..227eb41e28 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -1,6 +1,7 @@ MODULE := engines/macventure MODULE_OBJS := \ + container.o \ controls.o \ cursor.o \ datafiles.o \ -- cgit v1.2.3 From f928deebaf09e9498da9658f36bf318d67660733 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 11:59:54 +0200 Subject: MACVENTURE: Implement quit from menu --- engines/macventure/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 264e577792..9346a1bd5c 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1134,7 +1134,7 @@ void Gui::handleMenuAction(MenuAction action) { saveGame(); break; case MacVenture::kMenuActionQuit: - debug("MacVenture Menu Action: Quit"); + _engine->requestQuit(); break; case MacVenture::kMenuActionUndo: warning("Unimplemented MacVenture Menu Action: Undo"); -- cgit v1.2.3 From 34fdec37b26c7328f07f6251263f1c1afc7d1629 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 12:14:20 +0200 Subject: MACVENTURE: Fix debug messages --- engines/macventure/container.cpp | 4 ++-- engines/macventure/dialog.cpp | 2 +- engines/macventure/gui.cpp | 2 +- engines/macventure/macventure.cpp | 13 ++++++------- engines/macventure/script.cpp | 14 +++++++------- engines/macventure/sound.cpp | 5 ++--- engines/macventure/stringtable.h | 2 +- engines/macventure/text.cpp | 4 ++-- engines/macventure/world.cpp | 2 +- 9 files changed, 23 insertions(+), 25 deletions(-) diff --git a/engines/macventure/container.cpp b/engines/macventure/container.cpp index 73f706a0c5..1781f96a07 100644 --- a/engines/macventure/container.cpp +++ b/engines/macventure/container.cpp @@ -89,7 +89,7 @@ Container::Container(Common::String filename) { mask = _res->readUint32BE(); mask >>= (16 - bits); mask &= 0xFFFF; - debugC(11, kMVDebugContainer, "Load mask of object &%d:%d is %x", i, j, mask); + debugC(4, kMVDebugContainer, "Load mask of object &%d:%d is %x", i, j, mask); _res->seek(-4, SEEK_CUR); // Look in the Huffman table int x = 0; @@ -128,7 +128,7 @@ Container::Container(Common::String filename) { } group.lengths[j] = length; - debugC(11, kMVDebugContainer, "Load legth of object %d:%d is %d", i, j, length); + debugC(4, kMVDebugContainer, "Load legth of object %d:%d is %d", i, j, length); } _groups.push_back(group); diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 043cd38a92..27ef224712 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -176,7 +176,7 @@ bool DialogButton::doProcessEvent(MacVenture::Dialog *dialog, Common::Event even if (event.type == Common::EVENT_LBUTTONDOWN) { dialog->localize(mouse); if (_bounds.contains(mouse)) { - debugC(1, kMVDebugGUI, "Click! Button: %s", _text.c_str()); + debugC(2, kMVDebugGUI, "Click! Button: %s", _text.c_str()); dialog->handleDialogAction(this, _action); return true; } diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 9346a1bd5c..ac429d03d9 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -472,7 +472,7 @@ bool Gui::loadWindows() { } data.scrollPos = Common::Point(0, 0); - debugC(4, kMVDebugGUI, "Window loaded: %s", data.title.c_str()); + debugC(1, kMVDebugGUI, "Window loaded: %s", data.title.c_str()); _windowData->push_back(data); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index ef2b7fadb0..2c91680926 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -36,7 +36,7 @@ namespace MacVenture { // HACK, see below void toASCII(Common::String &str) { - debugC(1, kMVDebugMain, "toASCII: %s", str.c_str()); + debugC(3, kMVDebugMain, "toASCII: %s", str.c_str()); Common::String::iterator it = str.begin(); for (; it != str.end(); it++) { if (*it == '\216') { str.replace(it, it + 1, "e"); } @@ -506,7 +506,7 @@ void MacVentureEngine::processEvents() { } bool MacVenture::MacVentureEngine::runScriptEngine() { - debugC(4, kMVDebugMain, "MAIN: Running script engine"); + debugC(3, kMVDebugMain, "Running script engine"); if (_haltedAtEnd) { _haltedAtEnd = false; if (_scriptEngine->resume(false)) { @@ -754,7 +754,7 @@ void MacVentureEngine::highlightExit(ObjID objID) { void MacVentureEngine::selectPrimaryObject(ObjID objID) { if (objID == _destObject) return; int idx; - debugC(5, kMVDebugMain, "Select primary object (%d)", objID); + debugC(4, kMVDebugMain, "Select primary object (%d)", objID); if (_destObject > 0 && (idx = findObjectInArray(_destObject, _currentSelection)) != -1) { unselectAll(); @@ -776,8 +776,7 @@ void MacVentureEngine::focusObjectWindow(ObjID objID) { } void MacVentureEngine::openObject(ObjID objID) { - - debugC(1, kMVDebugMain, "Open Object[%d] parent[%d] x[%d] y[%d]", + debugC(3, kMVDebugMain, "Open Object[%d] parent[%d] x[%d] y[%d]", objID, _world->getObjAttr(objID, kAttrParentObject), _world->getObjAttr(objID, kAttrPosX), @@ -807,7 +806,7 @@ void MacVentureEngine::closeObject(ObjID objID) { void MacVentureEngine::checkObject(QueuedObject old) { //warning("checkObject: unimplemented"); bool hasChanged = false; - debugC(1, kMVDebugMain, "Check Object[%d] parent[%d] x[%d] y[%d]", + debugC(3, kMVDebugMain, "Check Object[%d] parent[%d] x[%d] y[%d]", old.object, old.parent, old.x, @@ -874,7 +873,7 @@ void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { WindowReference from = getObjWindow(fromID); WindowReference to = getObjWindow(toID); WindowReference tmp = to; - debugC(1, kMVDebugMain, "Swap Object[%d] to Object[%d], from win[%d] to win[%d] ", + debugC(3, kMVDebugMain, "Swap Object[%d] to Object[%d], from win[%d] to win[%d] ", fromID, toID, from, to); if (!to) { diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index c743e49a55..c88ac0bf3e 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -51,14 +51,14 @@ bool ScriptEngine::runControl(ControlAction action, ObjID source, ObjID destinat frame.haltedInFirst = false; frame.haltedInFamily = false; _frames.push_back(frame); - debugC(3, kMVDebugScript, "SCRIPT: Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", + debugC(3, kMVDebugScript, "Stored frame %d, action: %d src: %d dest: %d point: (%d, %d)", _frames.size() - 1, frame.action, frame.src, frame.dest, frame.x, frame.y); return resume(true); } bool ScriptEngine::resume(bool execAll) { - debugC(3, kMVDebugScript, "SCRIPT: Resume"); + debugC(3, kMVDebugScript, "Resume Script"); while (_frames.size()) { bool fail = execFrame(execAll); if (fail) return true; @@ -146,7 +146,7 @@ bool ScriptEngine::execFrame(bool execAll) { bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { - debugC(2, kMVDebugScript, "SCRIPT: Loading function %d", scriptID); + debugC(2, kMVDebugScript, "Loading function %d", scriptID); // Insert the new script at the front frame->scripts.push_front(ScriptAsset(scriptID, _scripts)); return runFunc(frame); @@ -169,7 +169,7 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { byte op; while (script.hasNext()) { op = script.fetch(); - debugC(3, kMVDebugScript, "SCRIPT: I'm running operation %d", op); + debugC(4, kMVDebugScript, "Running operation %d", op); if (!(op & 0x80)) { state->push(op); } else { @@ -921,12 +921,12 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; - debugC(2, kMVDebugScript, "SCRIPT: Call function: %d", id); + debugC(2, kMVDebugScript, "Call function: %d", id); if (loadScript(frame, id)) return true; frame->scripts.pop_front(); script = frame->scripts.front(); - debugC(2, kMVDebugScript, "SCRIPT: Return from fuction %d", id); + debugC(2, kMVDebugScript, "Return from fuction %d", id); return false; } @@ -1207,7 +1207,7 @@ void ScriptAsset::loadInstructions() { _instructions.push_back(res->readByte()); } delete res; - debugC(2, kMVDebugScript, "SCRIPT: Load %d instructions for script %d", amount, _id); + debugC(2, kMVDebugScript, "Load %d instructions for script %d", amount, _id); } } // End of namespace MacVenture diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index eb0941607c..590da2eef3 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -61,9 +61,8 @@ void SoundManager::ensureLoaded(ObjID sound) { SoundAsset::SoundAsset(Container *container, ObjID id) : _container(container), _id(id), _length(0), _frequency(1) { - debug("SoundAsset::SoundAsset(%d)", _id); if (_container->getItemByteSize(_id) == 0) - warning("Trying to load an empty sound asset."); + warning("Trying to load an empty sound asset (%d).", _id); Common::SeekableReadStream *stream = _container->getItem(_id); @@ -101,7 +100,7 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : } SoundAsset::~SoundAsset() { - debug("SoundAsset::~SoundAsset(%d)", _id); + debugC(3, kMVDebugSound, "~SoundAsset(%d)", _id); } void SoundAsset::play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle) { diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index a03fb28a0d..54aba03337 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -85,7 +85,7 @@ private: // HACK until a proper special char implementation is found, this will have to do. Common::String result = Common::String(str); toASCII(result); - debugC(5, kMVDebugText, "Loaded string %s", str); + debugC(4, kMVDebugText, "Loaded string %s", str); _strings.push_back(Common::String(result)); delete[] str; } diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 095b0f3332..5a2d029714 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -99,7 +99,7 @@ void TextAsset::decodeOld() { } str[strLen] = '\0'; - debugC(3, kMVDebugText, "Decoded %d string (old): %s", _id, str); + debugC(3, kMVDebugText, "Decoded string [%d] (old encoding): %s", _id, str); _decoded = Common::String(str); } @@ -162,7 +162,7 @@ void TextAsset::decodeHuffman() { } } _decoded += '\0'; - debugC(4, kMVDebugText, "Decoded %d'th string (new): %s", _id, _decoded.c_str()); + debugC(3, kMVDebugText, "Decoded string [%d] (new encoding): %s", _id, _decoded.c_str()); } Common::String TextAsset::getNoun(ObjID subval) { ObjID obj; diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 4ef55094bb..c514ebd535 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -43,7 +43,7 @@ void World::startNewGame() { if (!saveGameFile.open(_startGameFileName)) error("WORLD: Could not load initial game configuration"); - debug("Loading save game state from %s", _startGameFileName.c_str()); + debugC(2, kMVDebugMain, "Loading save game state from %s", _startGameFileName.c_str()); Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size()); _saveGame = new SaveGame(_engine, saveGameRes); -- cgit v1.2.3 From e5cf0332f2d08c7f6bc45c1f1fd8edaf276ea76d Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 12:45:08 +0200 Subject: MACVENTURE: Break up one-line ifs and fix braces --- engines/macventure/container.cpp | 33 +++++++------ engines/macventure/datafiles.cpp | 3 +- engines/macventure/dialog.cpp | 4 +- engines/macventure/gui.cpp | 97 +++++++++++++++++++++++++++++---------- engines/macventure/gui.h | 8 +++- engines/macventure/image.cpp | 60 ++++++++++++++++-------- engines/macventure/macventure.cpp | 49 ++++++++++++++------ engines/macventure/script.cpp | 65 ++++++++++++++++++-------- engines/macventure/sound.cpp | 47 +++++++++++++------ engines/macventure/text.cpp | 4 +- engines/macventure/world.cpp | 42 ++++++++++++----- 11 files changed, 293 insertions(+), 119 deletions(-) diff --git a/engines/macventure/container.cpp b/engines/macventure/container.cpp index 1781f96a07..ff98d6961f 100644 --- a/engines/macventure/container.cpp +++ b/engines/macventure/container.cpp @@ -27,18 +27,21 @@ namespace MacVenture { Container::Container(Common::String filename) { _filename = filename; - if (!_file.open(_filename)) + if (!_file.open(_filename)) { error("CONTAINER: Could not open %s", _filename.c_str()); + } _res = _file.readStream(_file.size()); _header = _res->readUint32BE(); _simplified = false; - for (uint i = 0; i < 16; ++i) + for (uint i = 0; i < 16; ++i) { _huff.push_back(0); + } - for (uint i = 0; i < 16; ++i) + for (uint i = 0; i < 16; ++i) { _lens.push_back(0); + } if (!(_header & 0x80000000)) { // Is simplified container @@ -51,16 +54,19 @@ Container::Container(Common::String filename) { _res->seek(_header, SEEK_SET); _numObjs = _res->readUint16BE(); - for (uint i = 0; i < 15; ++i) + for (uint i = 0; i < 15; ++i) { _huff[i] = _res->readUint16BE(); + } - for (uint i = 0; i < 16; ++i) + for (uint i = 0; i < 16; ++i) { _lens[i] = _res->readByte(); + } // Read groups uint numGroups = _numObjs / 64; - if ((_numObjs % 64) > 0) + if ((_numObjs % 64) > 0) { numGroups++; + } for (uint i = 0; i < numGroups; ++i) { ItemGroup group; @@ -94,7 +100,9 @@ Container::Container(Common::String filename) { // Look in the Huffman table int x = 0; for (x = 0; x < 16; x++) { - if (_huff[x] > mask) break; + if (_huff[x] > mask) { + break; + } } // I will opt to copy the code from webventure, @@ -116,8 +124,11 @@ Container::Container(Common::String filename) { length = _res->readUint32BE(); _res->seek(-4, SEEK_CUR); bitSize--; - if (bitSize == 0) length = 0; - else length >>= (32 - bitSize) - bits; + if (bitSize == 0) { + length = 0; + } else { + length >>= (32 - bitSize) - bits; + } length &= (1 << bitSize) - 1; length |= 1 << bitSize; bits += bitSize; @@ -126,11 +137,9 @@ Container::Container(Common::String filename) { _res->seek(2, SEEK_CUR); } } - group.lengths[j] = length; debugC(4, kMVDebugContainer, "Load legth of object %d:%d is %d", i, j, length); } - _groups.push_back(group); } } @@ -166,9 +175,7 @@ Common::SeekableReadStream *Container::getItem(uint32 id) { for (uint i = 0; i < objectIndex; i++) { offset += _groups[groupID].lengths[i]; } - _res->seek(_groups[groupID].offset + offset + sizeof(_header), SEEK_SET); - } // HACK Should Limit the size of the stream returned diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp index 9532434f03..aa47869bcd 100644 --- a/engines/macventure/datafiles.cpp +++ b/engines/macventure/datafiles.cpp @@ -66,8 +66,9 @@ Common::String windowTypeName(MVWindowType windowType) { void MacVentureEngine::loadDataBundle() { _dataBundle = Common::makeZipArchive(MACVENTURE_DATA_BUNDLE); - if (!_dataBundle) + if (!_dataBundle) { error("ENGINE: Couldn't load data bundle '%s'.", MACVENTURE_DATA_BUNDLE.c_str()); + } } Common::SeekableReadStream *MacVentureEngine::getBorderFile(MVWindowType windowType, bool isActive) { diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 27ef224712..7c375d425c 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -80,7 +80,9 @@ const Graphics::Font& Dialog::getFont() { bool Dialog::processEvent(Common::Event event) { for (Common::Array::iterator it = _elements.begin(); it != _elements.end(); it++) { - if ((*it)->processEvent(this, event)) return true; + if ((*it)->processEvent(this, event)) { + return true; + } } return false; } diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index ac429d03d9..f4cb8eeb6f 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -267,7 +267,9 @@ void Gui::setWindowTitle(WindowReference winID, Common::String string) { } void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array &children) { - if (ref == kNoWindow) return; + if (ref == kNoWindow) { + return; + } WindowData &data = findWindowData(ref); data.children.clear(); data.objRef = objID; @@ -284,9 +286,15 @@ void Gui::updateWindowInfo(WindowReference ref, ObjID objID, const Common::Array data.children.push_back(DrawableObject(child, kBlitBIC)); } } - if (originx != 0x7fff) data.bounds.left = originx; - if (originy != 0x7fff) data.bounds.top = originy; - if (ref != kMainGameWindow) data.updateScroll = true; + if (originx != 0x7fff) { + data.bounds.left = originx; + } + if (originy != 0x7fff) { + data.bounds.top = originy; + } + if (ref != kMainGameWindow) { + data.updateScroll = true; + } } void Gui::addChild(WindowReference target, ObjID child) { @@ -297,7 +305,9 @@ void Gui::removeChild(WindowReference target, ObjID child) { WindowData &data = findWindowData(target); uint index = 0; for (;index < data.children.size(); index++) { - if (data.children[index].obj == child) break; + if (data.children[index].obj == child) { + break; + } } if (index < data.children.size()) @@ -602,7 +612,9 @@ void Gui::drawMainGameWindow() { void Gui::drawSelfWindow() { drawObjectsInWindow(getWindowData(kSelfWindow), _selfWindow->getSurface()); - if (_engine->isObjSelected(1)) invertWindowColors(kSelfWindow); + if (_engine->isObjSelected(1)) { + invertWindowColors(kSelfWindow); + } findWindow(kSelfWindow)->setDirty(true); } @@ -667,7 +679,9 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur ObjID child; BlitMode mode; - if (targetData.children.size() == 0) return; + if (targetData.children.size() == 0) { + return; + } Graphics::ManagedSurface composeSurface; createInnerSurface(&composeSurface, surface, border); @@ -736,12 +750,20 @@ void Gui::drawDraggedObject() { uint h = asset->getHeight() + MIN((int16)0, _draggedObj.pos.y); // In case of overflow from the bottom/left - if (_draggedObj.pos.x > 0 && _draggedObj.pos.x + w > kScreenWidth) { w = kScreenWidth - _draggedObj.pos.x; } - if (_draggedObj.pos.y > 0 && _draggedObj.pos.y + h > kScreenHeight) { h = kScreenHeight - _draggedObj.pos.y; } + if (_draggedObj.pos.x > 0 && _draggedObj.pos.x + w > kScreenWidth) { + w = kScreenWidth - _draggedObj.pos.x; + } + if (_draggedObj.pos.y > 0 && _draggedObj.pos.y + h > kScreenHeight) { + h = kScreenHeight - _draggedObj.pos.y; + } Common::Point target = _draggedObj.pos; - if (target.x < 0) { target.x = 0; } - if (target.y < 0) { target.y = 0; } + if (target.x < 0) { + target.x = 0; + } + if (target.y < 0) { + target.y = 0; + } _draggedSurface.create(w, h, _screen.format); _draggedSurface.blitFrom( @@ -766,11 +788,15 @@ void Gui::drawDraggedObject() { } void Gui::drawDialog() { - if (_dialog) _dialog->draw(); + if (_dialog) { + _dialog->draw(); + } } void Gui::updateWindow(WindowReference winID, bool containerOpen) { - if (winID == kNoWindow) return; + if (winID == kNoWindow) { + return; + } if (winID == kSelfWindow || containerOpen) { WindowData &data = findWindowData(winID); if (winID == kCommandsWindow) { @@ -822,8 +848,9 @@ void Gui::unselectExits() { } void Gui::updateExit(ObjID obj) { - if (!_engine->isObjExit(obj)) return; - + if (!_engine->isObjExit(obj)) { + return; + } BorderBounds border = borderBounds(getWindowData(kExitsWindow).type); int ctl = -1; @@ -943,7 +970,9 @@ Common::Point Gui::getGlobalScrolledSurfacePosition(WindowReference reference) { const WindowData &data = getWindowData(reference); BorderBounds border = borderBounds(data.type); Graphics::MacWindow *win = findWindow(reference); - if (!win) return Common::Point(0, 0); + if (!win) { + return Common::Point(0, 0); + } return Common::Point( win->getDimensions().left + border.leftOffset - data.scrollPos.x, win->getDimensions().top + border.topOffset - data.scrollPos.y); @@ -1010,12 +1039,16 @@ WindowReference Gui::findObjWindow(ObjID objID) { // This is a bit of a HACK, we take advantage of the consecutive nature of references for (uint i = kCommandsWindow; i <= kDiplomaWindow; i++) { const WindowData &data = getWindowData((WindowReference)i); - if (data.objRef == objID) { return data.refcon; } + if (data.objRef == objID) { + return data.refcon; + } } for (uint i = kInventoryStart; i < _inventoryWindows.size() + kInventoryStart; i++) { const WindowData &data = getWindowData((WindowReference)i); - if (data.objRef == objID) { return data.refcon; } + if (data.objRef == objID) { + return data.refcon; + } } return kNoWindow; @@ -1068,7 +1101,9 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point cli void Gui::handleDragRelease(bool shiftPressed, bool isDoubleClick) { if (_draggedObj.id != 0) { WindowReference destinationWindow = findWindowAtPoint(_draggedObj.pos); - if (destinationWindow == kNoWindow) return; + if (destinationWindow == kNoWindow) { + return; + } if (_draggedObj.hasMoved) { const WindowData &destinationWindowData = getWindowData(destinationWindow); ObjID destObject = destinationWindowData.objRef; @@ -1246,7 +1281,9 @@ bool Gui::processEvent(Common::Event &event) { processed |= _cursor->processEvent(event); - if (_dialog && _dialog->processEvent(event)) return true; + if (_dialog && _dialog->processEvent(event)) { + return true; + } if (event.type == Common::EVENT_MOUSEMOVE) { if (_draggedObj.id != 0) { @@ -1370,7 +1407,9 @@ bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & ev bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (event.type == Common::EVENT_LBUTTONDOWN && click == kBorderCloseButton) { WindowReference ref = findWindowAtPoint(event.mouse); - if (ref == kNoWindow) return false; + if (ref == kNoWindow) { + return false; + } if (click == kBorderCloseButton) { removeInventoryWindow(ref); @@ -1384,7 +1423,9 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (event.type == Common::EVENT_LBUTTONDOWN) { // Find the appropriate window WindowReference ref = findWindowAtPoint(event.mouse); - if (ref == kNoWindow) return false; + if (ref == kNoWindow) { + return false; + } WindowData &data = findWindowData((WindowReference) ref); @@ -1406,7 +1447,9 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { void Gui::selectForDrag(Common::Point cursorPosition) { WindowReference ref = findWindowAtPoint(cursorPosition); - if (ref == kNoWindow) return; + if (ref == kNoWindow) { + return; + } Graphics::MacWindow *win = findWindow(ref); WindowData &data = findWindowData((WindowReference) ref); @@ -1418,13 +1461,17 @@ void Gui::selectForDrag(Common::Point cursorPosition) { void Gui::handleSingleClick() { debugC(2, kMVDebugGUI, "Registered Single Click"); // HACK THERE HAS TO BE A MORE ELEGANT WAY - if (_dialog) return; + if (_dialog) { + return; + } handleDragRelease(false, false); } void Gui::handleDoubleClick() { debugC(2, kMVDebugGUI, "Registered Double Click"); - if (_dialog) return; + if (_dialog) { + return; + } handleDragRelease(false, true); } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 28ee85ddae..4ad1709e25 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -344,11 +344,15 @@ public: } void scrollDown() { - if (_scrollPos < (int)(_lines.size() - 1)) _scrollPos++; + if (_scrollPos < (int)(_lines.size() - 1)) { + _scrollPos++; + } } void scrollUp() { - if (_scrollPos > 0) _scrollPos--; + if (_scrollPos > 0) { + _scrollPos--; + } } diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index f4d46b039f..c1bfd75158 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -109,11 +109,17 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight uint8 mode = stream.getBits(3); int w, h; - if (stream.getBit()) h = stream.getBits(10); - else h = stream.getBits(6); + if (stream.getBit()) { + h = stream.getBits(10); + } else { + h = stream.getBits(6); + } - if (stream.getBit()) w = stream.getBits(10); - else w = stream.getBits(6); + if (stream.getBit()) { + w = stream.getBits(10); + } else { + w = stream.getBits(6); + } rowBytes = ((w + 0xF) >> 3) & 0xFFFE; bitWidth = w; @@ -284,8 +290,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st v = data[pos]; pos++; } - } - else { + } else { for (uint x = 0; x < rowBytes; x++) { uint16 val = data[pos] ^ v; val ^= (val >> 4) & 0xf; @@ -298,7 +303,9 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st } if (flags & 4) { uint16 delta = rowBytes * 4; - if (flags & 2) delta *= 2; + if (flags & 2) { + delta *= 2; + } pos = 0; uint q = delta; for (uint i = 0; i < bitHeight * rowBytes - delta; i++) { @@ -318,8 +325,9 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { uint16 dw = stream.peekBits(16); uint16 i = 0; for (;i < 16; i++) { - if (huff.masks[i + 1] > dw) + if (huff.masks[i + 1] > dw) { break; + } } stream.skip(huff.lens[i]); uint8 val = huff.symbols[i]; @@ -351,7 +359,7 @@ byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { void ImageAsset::blitInto(Graphics::ManagedSurface *target, int x, int y, BlitMode mode) { if (mode == kBlitDirect) { blitDirect(target, x, y, _imgData, _imgBitHeight, _imgBitWidth, _imgRowBytes); - } else if (mode < kBlitXOR){ + } else if (mode < kBlitXOR) { if (_container->getItemByteSize(_mask)) { // Has mask switch (mode) { case MacVenture::kBlitBIC: @@ -383,35 +391,46 @@ void ImageAsset::blitInto(Graphics::ManagedSurface *target, int x, int y, BlitMo } bool ImageAsset::isPointInside(Common::Point point) { - if (point.x >= _maskBitWidth || point.y >= _maskBitHeight) return false; - if (_maskData.empty()) return false; + if (point.x >= _maskBitWidth || point.y >= _maskBitHeight) { + return false; + } + if (_maskData.empty()) { + return false; + } // We see if the point lands on the mask. uint pix = _maskData[(point.y * _maskRowBytes) + (point.x >> 3)] & (1 << (7 - (point.x & 7))); return pix != 0; } bool ImageAsset::isRectInside(Common::Rect rect) { - // HACK is it &&, or ||? - if (_maskData.empty()) return (rect.width() > 0 && rect.height() > 0); + if (_maskData.empty()) { + return (rect.width() > 0 && rect.height() > 0); + } for (int y = rect.top; y < rect.top + rect.height(); y++) { uint bmpofs = y * _maskRowBytes; byte pix; for (int x = rect.left; x < rect.left + rect.width(); x++) { pix = _maskData[bmpofs + (x >> 3)] & (1 << (7 - (x & 7))); - if (pix) return true; + if (pix) { + return true; + } } } return false; } int ImageAsset::getWidth() { - if (_imgData.size() == 0) return 0; + if (_imgData.size() == 0) { + return 0; + } return MAX(0, (int)_imgBitWidth); } int ImageAsset::getHeight() { - if (_imgData.size() == 0) return 0; + if (_imgData.size() == 0) { + return 0; + } return MAX(0, (int)_imgBitHeight); } @@ -443,7 +462,9 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, cons assert(ox + x <= target->w); assert(oy + y <= target->h); pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); - if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; + if (pix) { + *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorWhite; + } } } } @@ -459,7 +480,9 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const assert(ox + x <= target->w); assert(oy + y <= target->h); pix = data[bmpofs + ((x + sx) >> 3)] & (1 << (7 - ((x + sx) & 7))); - if (pix) *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorBlack; + if (pix) { + *((byte *)target->getBasePtr(ox + x, oy + y)) = kColorBlack; + } } } } @@ -505,7 +528,6 @@ void ImageAsset::calculateSectionInDirection(uint targetWhole, uint originWhole, } else { blittedWhole = (blittedWhole) - ((blittedWhole + originPosition) - targetWhole); } - } if (originPosition < 0) { if (ABS(originPosition) > (int)blittedWhole) { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 2c91680926..7f754c470d 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -39,8 +39,12 @@ void toASCII(Common::String &str) { debugC(3, kMVDebugMain, "toASCII: %s", str.c_str()); Common::String::iterator it = str.begin(); for (; it != str.end(); it++) { - if (*it == '\216') { str.replace(it, it + 1, "e"); } - if (*it == '\210') { str.replace(it, it + 1, "a"); } + if (*it == '\216') { + str.replace(it, it + 1, "e"); + } + if (*it == '\210') { + str.replace(it, it + 1, "a"); + } } } @@ -687,7 +691,7 @@ void MacVentureEngine::selectObject(ObjID objID) { void MacVentureEngine::unselectObject(ObjID objID) { int idxCur = findObjectInArray(objID, _currentSelection); - if (idxCur != -1){ + if (idxCur != -1) { _currentSelection.remove_at(idxCur); highlightExit(objID); } @@ -709,8 +713,11 @@ int MacVentureEngine::findObjectInArray(ObjID objID, const Common::Array bool found = false; uint i = 0; while (i < list.size() && !found) { - if (list[i] == objID) found = true; - else i++; + if (list[i] == objID) { + found = true; + } else { + i++; + } } // HACK, should use iterator return found ? i : -1; @@ -752,7 +759,9 @@ void MacVentureEngine::highlightExit(ObjID objID) { } void MacVentureEngine::selectPrimaryObject(ObjID objID) { - if (objID == _destObject) return; + if (objID == _destObject) { + return; + } int idx; debugC(4, kMVDebugMain, "Select primary object (%d)", objID); if (_destObject > 0 && @@ -782,7 +791,9 @@ void MacVentureEngine::openObject(ObjID objID) { _world->getObjAttr(objID, kAttrPosX), _world->getObjAttr(objID, kAttrPosY)); - if (getObjWindow(objID)) return; + if (getObjWindow(objID)) { + return; + } if (objID == _world->getObjAttr(1, kAttrParentObject)) { _gui->updateWindowInfo(kMainGameWindow, objID, _world->getChildren(objID, true)); _gui->updateWindow(kMainGameWindow, _world->getObjAttr(objID, kAttrContainerOpen)); @@ -850,14 +861,20 @@ void MacVentureEngine::checkObject(QueuedObject old) { ObjID cur = id; ObjID root = _world->getObjAttr(1, kAttrParentObject); while (cur != root) { - if (cur == 0 || !_world->getObjAttr(cur, kAttrContainerOpen)) break; + if (cur == 0 || !_world->getObjAttr(cur, kAttrContainerOpen)) { + break; + } cur = _world->getObjAttr(cur, kAttrParentObject); } if (cur == root) { - if (win) return; + if (win) { + return; + } enqueueObject(kOpenWindow, id); //open } else { - if (!win) return; + if (!win) { + return; + } enqueueObject(kCloseWindow, id); //close } @@ -904,7 +921,9 @@ void MacVentureEngine::zoomObject(ObjID objID) { bool MacVentureEngine::isObjEnqueued(ObjID objID) { Common::Array::const_iterator it; for (it = _objQueue.begin(); it != _objQueue.end(); it++) { - if ((*it).object == objID) return true; + if ((*it).object == objID) { + return true; + } } return false; } @@ -1049,9 +1068,13 @@ WindowReference MacVentureEngine::getObjWindow(ObjID objID) { } WindowReference MacVentureEngine::findParentWindow(ObjID objID) { - if (objID == 1) return kSelfWindow; + if (objID == 1) { + return kSelfWindow; + } ObjID parent = _world->getObjAttr(objID, kAttrParentObject); - if (parent == 0) return kNoWindow; + if (parent == 0) { + return kNoWindow; + } return getObjWindow(parent); } diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index c88ac0bf3e..f7e49c68e3 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -61,7 +61,9 @@ bool ScriptEngine::resume(bool execAll) { debugC(3, kMVDebugScript, "Resume Script"); while (_frames.size()) { bool fail = execFrame(execAll); - if (fail) return true; + if (fail) { + return true; + } } return false; } @@ -80,8 +82,11 @@ bool ScriptEngine::execFrame(bool execAll) { // Do first dispatch script (script 0) if (frame->haltedInFirst || doFirst) { // We were stuck or it's the first time frame->haltedInFirst = false; - if (doFirst) { fail = loadScript(frame, 0); } - else { fail = resumeFunc(frame); } + if (doFirst) { + fail = loadScript(frame, 0); + } else { + fail = resumeFunc(frame); + } if (fail) { frame->haltedInFirst = true; _engine->preparedToRun(); @@ -97,7 +102,9 @@ bool ScriptEngine::execFrame(bool execAll) { Common::Array family = _world->getFamily(_world->getObjAttr(1, kAttrParentObject), false); uint32 i = frame->familyIdx; for (; i < family.size(); i++) { - if (doFamily) { fail = loadScript(frame, family[i]); } + if (doFamily) { + fail = loadScript(frame, family[i]); + } else { fail = resumeFunc(frame); } if (fail) { // We are stuck, so we don't shift the frame frame->haltedInFamily = true; @@ -123,8 +130,7 @@ bool ScriptEngine::execFrame(bool execAll) { uint localHigh = 0; do { // Saved function calls highest = 0; - for (uint i = 0; i saves.size(); i++) - { + for (uint i = 0; i saves.size(); i++) { if (highest < frame->saves[i].rank) { highest = frame->saves[i].rank; localHigh = i; @@ -156,7 +162,9 @@ bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { bool ScriptEngine::resumeFunc(EngineFrame * frame) { bool fail = runFunc(frame); - if (fail) return fail; + if (fail) { + return fail; + } frame->scripts.pop_front(); if (frame->scripts.size()) return resumeFunc(frame); @@ -645,12 +653,16 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { word step = neg16(state->pop()); word num = neg16(state->pop()); step %= num; - if (step<0) step += num; + if (step < 0) { + step += num; + } word end = 0; word start = 0; for (word i = 1;i= num) start -= num; + if (start >= num) { + start -= num; + } if (start == end) { end++; start = end; @@ -710,7 +722,9 @@ void ScriptEngine::op9dDMOD(EngineState * state, EngineFrame * frame) { void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { word val = neg16(state->pop()); - if (val<0) val = -val; + if (val < 0) { + val = -val; + } state->push(val); } @@ -837,14 +851,18 @@ void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b != 0) script->branch(val); + if (b != 0) { + script->branch(val); + } } void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b != 0) script->branch(val); + if (b != 0) { + script->branch(val); + } } void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *script) { @@ -853,14 +871,18 @@ void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset val = val | script->fetch(); val = neg16(val); word b = state->pop(); - if (b == 0) script->branch(val); + if (b == 0) { + script->branch(val); + } } void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); - if (b == 0) script->branch(val); + if (b == 0) { + script->branch(val); + } } void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { @@ -886,18 +908,22 @@ void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { word lo = state->pop(); - for (uint i = 0;isaves.size();i++) - if (frame->saves[i].rank >= lo) + for (uint i = 0;isaves.size();i++) { + if (frame->saves[i].rank >= lo) { frame->saves[i].rank = 0; + } + } } void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { word hi = state->pop(); word lo = state->pop(); - for (uint i = 0;isaves.size();i++) + for (uint i = 0;isaves.size();i++) { if (frame->saves[i].rank >= lo && - frame->saves[i].rank <= hi) + frame->saves[i].rank <= hi) { frame->saves[i].rank = 0; + } + } } bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { @@ -942,8 +968,9 @@ void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { _world->setObjAttr(to, kAttrContainerOpen, _world->getObjAttr(from, 6)); _world->setObjAttr(from, kAttrContainerOpen, 0); Common::Array children = _world->getChildren(from, true); - for (uint i = 0; i < children.size(); i++) + for (uint i = 0; i < children.size(); i++) { _world->setObjAttr(children[i], 0, to); + } } void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 590da2eef3..492bf55b43 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -104,7 +104,9 @@ SoundAsset::~SoundAsset() { } void SoundAsset::play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle) { - if (_data.size() == 0) return; + if (_data.size() == 0) { + return; + } Audio::AudioStream *sound = Audio::makeRawStream(&_data.front(), _length, _frequency, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO); mixer->playStream(Audio::Mixer::kPlainSoundType, soundHandle, sound); } @@ -127,8 +129,11 @@ void SoundAsset::decode10(Common::SeekableReadStream *stream) { _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; byte ch = 0; for (uint i = 0; i < _length; i++) { - if (i & 1) ch >>= 4; - else ch = stream->readByte(); + if (i & 1) { + ch >>= 4; + } else { + ch = stream->readByte(); + } _data.push_back(wavtable[ch & 0xf]); } } @@ -156,14 +161,18 @@ void SoundAsset::decode12(Common::SeekableReadStream *stream) { ch -= 0x80; uint32 env= ch * scale; ch = (env >> 8) & 0xff; - if (ch & 0x80) ch = 0x7f; + if (ch & 0x80) { + ch = 0x7f; + } ch += 0x80; } else { ch = (ch ^ 0xff) + 1; ch -= 0x80; uint32 env = ch * scale; ch = (env >> 8) & 0xff; - if (ch & 0x80) ch = 0x7f; + if (ch & 0x80) { + ch = 0x7f; + } ch += 0x80; ch = (ch ^ 0xff) + 1; } @@ -185,8 +194,11 @@ void SoundAsset::decode18(Common::SeekableReadStream *stream) { _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; byte ch = 0; for (uint i = 0; i < _length; i++) { - if (i & 1) ch >>= 4; - else ch = stream->readByte(); + if (i & 1) { + ch >>= 4; + } else { + ch = stream->readByte(); + } _data.push_back(wavtable[ch & 0xf]); } } @@ -204,8 +216,11 @@ void SoundAsset::decode1a(Common::SeekableReadStream *stream) { _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; byte ch = 0; for (uint i = 0; i < _length; i++) { - if (i & 1) ch >>= 4; - else ch = stream->readByte(); + if (i & 1) { + ch >>= 4; + } else { + ch = stream->readByte(); + } _data.push_back(wavtable[ch & 0xf]); } } @@ -231,8 +246,11 @@ void SoundAsset::decode78(Common::SeekableReadStream *stream) { _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; byte ch = 0; for (uint i = 0; i < _length; i++) { - if (i & 1) ch <<= 4; - else ch = stream->readByte(); + if (i & 1) { + ch <<= 4; + } else { + ch = stream->readByte(); + } _data.push_back(wavtable[(ch >> 4) & 0xf]); } } @@ -250,8 +268,11 @@ void SoundAsset::decode7e(Common::SeekableReadStream *stream) { uint32 last=0x80; byte ch = 0; for (uint i = 0; i < _length; i++) { - if (i & 1) ch <<= 4; - else ch = stream->readByte(); + if (i & 1) { + ch <<= 4; + } else { + ch = stream->readByte(); + } last += wavtable[(ch >> 4) & 0xf]; _data.push_back(last & 0xff); } diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 5a2d029714..7981692c0a 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -123,7 +123,9 @@ void TextAsset::decodeHuffman() { uint32 entry; // Find the length index for (entry = 0; entry < _huffman->getNumEntries(); entry++) { - if (mask < _huffman->getMask(entry)) break; + if (mask < _huffman->getMask(entry)) { + break; + } } stream.skip(_huffman->getLength(entry)); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index c514ebd535..fc563cb639 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -63,7 +63,9 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { res = _saveGame->getAttr(objID, index); } else { index &= 0x7F; - if (objStream->size() == 0) return 0; + if (objStream->size() == 0) { + return 0; + } // Look for the right attribute inside the object objStream->skip(index * 2); res = objStream->readByte() << 8; @@ -79,8 +81,10 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { } void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) { - if (attrID == kAttrPosX || attrID == kAttrPosY) {} + if (attrID == kAttrPosX || attrID == kAttrPosY) { // Round to scale + // Intentionally empty, we don't seem to require this functionality + } if (attrID == kAttrParentObject) setParent(objID, value); @@ -101,15 +105,24 @@ bool MacVenture::World::isObjActive(ObjID obj) { ObjID destObj = _engine->getDestObject(); Common::Point p = _engine->getDeltaPoint(); ControlAction selectedControl = _engine->getSelectedControl(); - if (!getAncestor(obj)) return false; // If our ancestor is the garbage (obj 0), we're inactive + if (!getAncestor(obj)) { + return false; // If our ancestor is the garbage (obj 0), we're inactive + } if (_engine->getInvolvedObjects() >= 2 && // If (we need > 1 objs for the command) && destObj > 0 && // we have a destination object && - !getAncestor(destObj)) // but that destination object is in the garbage + !getAncestor(destObj)) { // but that destination object is in the garbage return false; - if (selectedControl != kMoveObject) return true; // We only need one + } + if (selectedControl != kMoveObject) { + return true; // We only need one + } // Handle move object - if (!isObjDraggable(obj)) return false; // We can't move it - if (getObjAttr(1, kAttrParentObject) != destObj) return true; // if the target is not the player's parent, we can go + if (!isObjDraggable(obj)) { + return false; // We can't move it + } + if (getObjAttr(1, kAttrParentObject) != destObj) { + return true; // if the target is not the player's parent, we can go + } Common::Rect rect(kScreenWidth, kScreenHeight); rect.top -= getObjAttr(obj, kAttrPosY) + p.y; rect.left -= getObjAttr(obj, kAttrPosX) + p.x; @@ -173,7 +186,7 @@ void World::releaseChildren(ObjID objID) { } Common::String World::getText(ObjID objID, ObjID source, ObjID target) { - if (objID & 0x8000){ + if (objID & 0x8000) { return _engine->getUserInput(); } TextAsset text = TextAsset(_engine, objID, source, target, _gameText, _engine->isOldText(), _engine->getDecodingHuffman()); @@ -203,7 +216,9 @@ void World::calculateObjectRelations() { for (uint i = numObjs - 1; i > 0; i--) { val = parents[i]; next = _relations[val * 2]; - if (next) { _relations[i * 2 + 1] = next; } + if (next) { + _relations[i * 2 + 1] = next; + } _relations[val * 2] = i; } } @@ -231,7 +246,9 @@ void World::setParent(ObjID child, ObjID newParent) { } void World::loadGameFrom(Common::InSaveFile *file) { - if (_saveGame) delete _saveGame; + if (_saveGame) { + delete _saveGame; + } _saveGame = new SaveGame(_engine, file); calculateObjectRelations(); } @@ -287,7 +304,7 @@ void SaveGame::saveInto(Common::OutSaveFile *file) { warning("Saving the game not yet tested!"); // Save attibutes Common::Array::const_iterator itg; - for(itg = _groups.begin(); itg != _groups.end(); itg++) { + for (itg = _groups.begin(); itg != _groups.end(); itg++) { Common::Array::const_iterator ita; for (ita = itg->begin(); ita != itg->end(); ita++) { file->writeUint16BE((*ita)); @@ -307,8 +324,9 @@ void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * GlobalSettings settings = engine->getGlobalSettings(); for (int i = 0; i < settings._numGroups; ++i) { AttributeGroup g; - for (int j = 0; j < settings._numObjects; ++j) + for (int j = 0; j < settings._numObjects; ++j) { g.push_back(res->readUint16BE()); + } _groups.push_back(g); } -- cgit v1.2.3 From 8bea8ecb17d6615b8bf095b31cb41d2201f8f8a5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 12:48:05 +0200 Subject: MACVENTURE: Remove unnecessary comment --- engines/macventure/controls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/controls.h b/engines/macventure/controls.h index 3f23aa825d..0adbf06a9f 100644 --- a/engines/macventure/controls.h +++ b/engines/macventure/controls.h @@ -40,7 +40,7 @@ enum ControlType { // HACK, should correspond exactly with the types of controls kControlClickToContinue = 9 }; -enum ControlAction { // HACK, figure out a way to put it in engine +enum ControlAction { kNoCommand = 0, kStartOrResume = 1, kClose = 2, -- cgit v1.2.3 From fa815e73adb88bfd42eb2bec8b2afabbc0e8d7ad Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 12:52:21 +0200 Subject: MACVENTURE: Fix indentation --- engines/macventure/dialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 7c375d425c..ab77f119ea 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -49,7 +49,7 @@ void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { case kDACloseDialog: _gui->closeDialog(); break; - case kDASubmit: + case kDASubmit: _gui->setTextInput(_userInput); _gui->closeDialog(); break; -- cgit v1.2.3 From ace515643654b07002ee528bbc01f679f699b8cb Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 17:01:30 +0200 Subject: MACVENTURE: Enforce const in prebuilt dialogs --- engines/macventure/dialog.cpp | 2 +- engines/macventure/dialog.h | 1 - engines/macventure/gui.h | 1 - engines/macventure/prebuilt_dialogs.cpp | 2 +- engines/macventure/prebuilt_dialogs.h | 3 +++ 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index ab77f119ea..c6315271b1 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -31,7 +31,7 @@ Dialog::Dialog(Gui *gui, Common::Point pos, uint width, uint height) : Dialog::Dialog(Gui *gui, PrebuiltDialogs prebuilt) { _gui = gui; - const PrebuiltDialog &dialog = prebuiltDialogs[prebuilt]; + const PrebuiltDialog &dialog = g_prebuiltDialogs[prebuilt]; _bounds = dialog.bounds; for (int i = 0; dialog.elements[i].type != kDEEnd; i++) { addPrebuiltElement(dialog.elements[i]); diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index 2ea38b1548..34f99dc643 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -33,7 +33,6 @@ namespace MacVenture { using namespace Graphics::MacGUIConstants; class Gui; class DialogElement; -extern PrebuiltDialog prebuiltDialogs[]; class Dialog { public: diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 4ad1709e25..f521286dc7 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -53,7 +53,6 @@ class ImageAsset; class Dialog; BorderBounds borderBounds(MVWindowType type); -extern PrebuiltDialog prebuiltDialogs[]; enum MenuAction { kMenuActionAbout, diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp index 46b71ab93a..49f2853203 100644 --- a/engines/macventure/prebuilt_dialogs.cpp +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -24,7 +24,7 @@ namespace MacVenture { -PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { +const PrebuiltDialog g_prebuiltDialogs[kPrebuiltDialogCount] = { {/* kSaveAsDialog */ Common::Rect(0, 146, 456, 254), diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 1c97847455..9aff5c7926 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -71,6 +71,9 @@ struct PrebuiltDialog { Common::Rect bounds; PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; }; + +extern const PrebuiltDialog g_prebuiltDialogs[]; + } // End of namespace MacVenture #endif -- cgit v1.2.3 From 68b171f328712d39072b5fd133eec93cb1bea3dd Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Tue, 16 Aug 2016 17:47:32 +0200 Subject: MACVENTURE: Remove constructors from prebuilt dialogs --- engines/macventure/dialog.cpp | 17 ++++++++--- engines/macventure/dialog.h | 2 ++ engines/macventure/prebuilt_dialogs.cpp | 54 ++++++++++++++++----------------- engines/macventure/prebuilt_dialogs.h | 14 +++++++-- 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index c6315271b1..383befc1b8 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -32,7 +32,7 @@ Dialog::Dialog(Gui *gui, Common::Point pos, uint width, uint height) : Dialog::Dialog(Gui *gui, PrebuiltDialogs prebuilt) { _gui = gui; const PrebuiltDialog &dialog = g_prebuiltDialogs[prebuilt]; - _bounds = dialog.bounds; + calculateBoundsFromPrebuilt(dialog.bounds); for (int i = 0; dialog.elements[i].type != kDEEnd; i++) { addPrebuiltElement(dialog.elements[i]); } @@ -124,15 +124,16 @@ void Dialog::setUserInput(Common::String content) { } void Dialog::addPrebuiltElement(const MacVenture::PrebuiltDialogElement &element) { + Common::Point position(element.left, element.top); switch(element.type) { case kDEButton: - addButton(element.title, element.action, element.position, element.width, element.height); + addButton(element.title, element.action, position, element.width, element.height); break; case kDEPlainText: - addText(element.title, element.position); + addText(element.title, position); break; case kDETextInput: - addTextInput(element.position, element.width, element.height); + addTextInput(position, element.width, element.height); break; default: break; @@ -241,4 +242,12 @@ void DialogTextInput::doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurfac target.frameRect(_bounds, kColorBlack); dialog->getFont().drawString(&target, _text, _bounds.left, _bounds.top, _bounds.width(), kColorBlack); } + +void Dialog::calculateBoundsFromPrebuilt(const PrebuiltDialogBounds &bounds) { + _bounds = Common::Rect( + bounds.left, + bounds.top, + bounds.right, + bounds.bottom); +} } // End of namespace MacVenture diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index 34f99dc643..7e85ccc2ba 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -57,6 +57,8 @@ public: private: void addPrebuiltElement(const PrebuiltDialogElement &element); + void calculateBoundsFromPrebuilt(const PrebuiltDialogBounds &bounds); + private: Gui *_gui; diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp index 49f2853203..6137fed219 100644 --- a/engines/macventure/prebuilt_dialogs.cpp +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -27,49 +27,49 @@ namespace MacVenture { const PrebuiltDialog g_prebuiltDialogs[kPrebuiltDialogCount] = { {/* kSaveAsDialog */ - Common::Rect(0, 146, 456, 254), + {0, 146, 456, 254}, { - {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, - {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, - {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, - {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + {kDEButton, "YES", kDASaveAs, 24, 68, 120, 22}, + {kDEButton, "NO", kDACloseDialog, 168, 68, 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, 312, 68, 120, 22}, + {kDEPlainText, "Save As...", kDANone, 100, 10, 340, 38}, + {kDETextInput, "", kDANone, 100, 30, 340, 20}, + {kDEEnd, "", kDANone, 0, 0, 0, 0} } }, { /* kSpeakDialog */ - Common::Rect(20, 92, 400, 200), + {20, 92, 400, 200}, { - {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, - {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, - {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + {kDEButton, "OK", kDASubmit, 10, 70, 50, 20}, + {kDEButton, "CANCEL", kDACloseDialog, 96, 70, 50, 20}, + {kDEPlainText, "What would you like to say?", kDANone, 10, 10, 400, 20}, + {kDETextInput, "", kDANone, 10, 25, 350, 40}, + {kDEEnd, "", kDANone, 0, 0, 0, 0} } }, { /* kWinGameDialog */ - Common::Rect(20, 100, 320, 200), + {20, 100, 320, 200}, { - {kDEPlainText, "You Won!", kDANone, Common::Point(20, 16), 280, 20}, - {kDEPlainText, "What do you want to do?", kDANone, Common::Point(20, 30), 280, 20}, - {kDEButton, "New Game", kDANewGame, Common::Point(20, 60), 70, 20}, - {kDEButton, "Load", kDALoadGame, Common::Point(110, 60), 70, 20}, - {kDEButton, "Quit", kDAQuit, Common::Point(200, 60), 70, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + {kDEPlainText, "You Won!", kDANone, 20, 16, 280, 20}, + {kDEPlainText, "What do you want to do?", kDANone, 20, 30, 280, 20}, + {kDEButton, "New Game", kDANewGame, 20, 60, 70, 20}, + {kDEButton, "Load", kDALoadGame, 110, 60, 70, 20}, + {kDEButton, "Quit", kDAQuit, 200, 60, 70, 20}, + {kDEEnd, "", kDANone, 0, 0, 0, 0} } }, { /* kLoseGameDialog */ - Common::Rect(20, 100, 320, 200), + {20, 100, 320, 200}, { - {kDEPlainText, "You Died", kDANone, Common::Point(20, 16), 280, 20}, - {kDEPlainText, "What do you want to do?", kDANone, Common::Point(20, 30), 280, 20}, - {kDEButton, "New Game", kDANewGame, Common::Point(20, 60), 70, 20}, - {kDEButton, "Load", kDALoadGame, Common::Point(110, 60), 70, 20}, - {kDEButton, "Quit", kDAQuit, Common::Point(200, 60), 70, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + {kDEPlainText, "You Died", kDANone, 20, 16, 280, 20}, + {kDEPlainText, "What do you want to do?", kDANone, 20, 30, 280, 20}, + {kDEButton, "New Game", kDANewGame, 20, 60, 70, 20}, + {kDEButton, "Load", kDALoadGame, 110, 60, 70, 20}, + {kDEButton, "Quit", kDAQuit, 200, 60, 70, 20}, + {kDEEnd, "", kDANone, 0, 0, 0, 0} } } }; diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 9aff5c7926..9cd8f4c1a4 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -52,11 +52,19 @@ enum PrebuiltElementType { kDEEnd }; +struct PrebuiltDialogBounds { + uint left; + uint top; + uint right; + uint bottom; +}; + struct PrebuiltDialogElement { PrebuiltElementType type; - Common::String title; + const char *title; DialogAction action; - Common::Point position; + uint left; + uint top; uint width; uint height; }; @@ -68,7 +76,7 @@ enum { }; struct PrebuiltDialog { - Common::Rect bounds; + PrebuiltDialogBounds bounds; PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; }; -- cgit v1.2.3 From 19c7bcf9d492dc25ef7458df001accfced21edff Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 14:35:25 +0200 Subject: MACVENTURE: Fix formatting --- engines/macventure/controls.cpp | 2 +- engines/macventure/controls.h | 2 +- engines/macventure/detection.cpp | 8 +- engines/macventure/dialog.cpp | 6 +- engines/macventure/dialog.h | 6 +- engines/macventure/gui.cpp | 32 +++--- engines/macventure/gui.h | 3 +- engines/macventure/image.cpp | 47 +++++--- engines/macventure/image.h | 8 +- engines/macventure/macventure.cpp | 21 ++-- engines/macventure/macventure.h | 8 +- engines/macventure/saveload.cpp | 3 +- engines/macventure/script.cpp | 235 +++++++++++++++++++------------------- engines/macventure/script.h | 6 +- engines/macventure/sound.cpp | 6 +- engines/macventure/stringtable.h | 2 +- engines/macventure/text.cpp | 2 +- engines/macventure/world.cpp | 17 +-- 18 files changed, 216 insertions(+), 198 deletions(-) diff --git a/engines/macventure/controls.cpp b/engines/macventure/controls.cpp index 898ddac8e8..078ea88dce 100644 --- a/engines/macventure/controls.cpp +++ b/engines/macventure/controls.cpp @@ -59,7 +59,7 @@ bool CommandButton::isInsideBounds(const Common::Point point) const { return _data.bounds.contains(point); } -const ControlData& CommandButton::getData() const { +const ControlData &CommandButton::getData() const { return _data; } diff --git a/engines/macventure/controls.h b/engines/macventure/controls.h index 0adbf06a9f..81b5278396 100644 --- a/engines/macventure/controls.h +++ b/engines/macventure/controls.h @@ -90,7 +90,7 @@ public: void draw(Graphics::ManagedSurface &surface) const; bool isInsideBounds(const Common::Point point) const; - const ControlData& getData() const; + const ControlData &getData() const; void select(); void unselect(); bool isSelected(); diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index d0a2940269..9329a9a185 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -54,14 +54,14 @@ public: _md5Bytes = 5000000; // TODO: Upper limit, adjust it once all games are added } - virtual const char * getName() const override { + virtual const char *getName() const override { return "MacVenture"; } - virtual const char * getOriginalCopyright() const override { + virtual const char *getOriginalCopyright() const override { return "(C) ICOM Simulations"; } - virtual bool createInstance(OSystem * syst, Engine ** engine, const ADGameDescription * desc) const; + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; virtual bool hasFeature(MetaEngineFeature f) const; virtual SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; @@ -121,7 +121,7 @@ SaveStateList MacVentureMetaEngine::listSaves(const char *target) const { int MacVentureMetaEngine::getMaximumSaveSlot() const { return 999; } -bool MacVentureMetaEngine::createInstance(OSystem * syst, Engine ** engine, const ADGameDescription *game) const { +bool MacVentureMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *game) const { if (game) { *engine = new MacVenture::MacVentureEngine(syst, game); } diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index 383befc1b8..7827bddffd 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -74,7 +74,7 @@ void Dialog::handleDialogAction(DialogElement *trigger, DialogAction action) { } } -const Graphics::Font& Dialog::getFont() { +const Graphics::Font &Dialog::getFont() { return _gui->getCurrentFont(); } @@ -161,11 +161,11 @@ void DialogElement::draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &t doDraw(dialog, target); } -const Common::String& DialogElement::getText() { +const Common::String &DialogElement::getText() { return doGetText(); } -const Common::String& DialogElement::doGetText() { +const Common::String &DialogElement::doGetText() { return _text; } diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index 7e85ccc2ba..67331d7eb3 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -46,7 +46,7 @@ public: void localize(Common::Point &point); void handleDialogAction(DialogElement *trigger, DialogAction action); - const Graphics::Font& getFont(); + const Graphics::Font &getFont(); void addButton(Common::String title, DialogAction action, Common::Point position, uint width = 0, uint height = 0); void addText(Common::String content, Common::Point position); @@ -74,12 +74,12 @@ public: bool processEvent(Dialog *dialog, Common::Event event); void draw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target); - const Common::String& getText(); + const Common::String &getText(); private: virtual bool doProcessEvent(Dialog *dialog, Common::Event event) = 0; virtual void doDraw(MacVenture::Dialog *dialog, Graphics::ManagedSurface &target) = 0; - virtual const Common::String& doGetText(); + virtual const Common::String &doGetText(); protected: Common::String _text; diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index f4cb8eeb6f..d0af4ed51f 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -249,11 +249,11 @@ void Gui::initWindows() { loadBorders(_exitsWindow, findWindowData(kExitsWindow).type); } -const WindowData& Gui::getWindowData(WindowReference reference) { +const WindowData &Gui::getWindowData(WindowReference reference) { return findWindowData(reference); } -const Graphics::Font& Gui::getCurrentFont() { +const Graphics::Font &Gui::getCurrentFont() { return *_wm.getFont("Chicago-12", Graphics::FontManager::kBigGUIFont); } @@ -351,12 +351,12 @@ WindowReference Gui::createInventoryWindow(ObjID objRef) { return newData.refcon; } -void Gui::loadBorders(Graphics::MacWindow * target, MVWindowType type) { +void Gui::loadBorders(Graphics::MacWindow *target, MVWindowType type) { loadBorder(target, type, false); loadBorder(target, type, true); } -void Gui::loadBorder(Graphics::MacWindow * target, MVWindowType type, bool active) { +void Gui::loadBorder(Graphics::MacWindow *target, MVWindowType type, bool active) { Common::SeekableReadStream *stream = _engine->getBorderFile(type, active); @@ -405,7 +405,7 @@ bool Gui::loadMenus() { uint16 key; uint16 style; uint8 titleLength; - char* title; + char *title; /* Skip menuID, width, height, resourceID, placeholder */ for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } @@ -474,7 +474,7 @@ bool Gui::loadWindows() { res->readUint32BE(); // Skip the true id. For some reason it's reading 0 data.titleLength = res->readByte(); if (data.titleLength) { - char* newTitle = new char[data.titleLength + 1]; + char *newTitle = new char[data.titleLength + 1]; res->read(newTitle, data.titleLength); newTitle[data.titleLength] = '\0'; data.title = Common::String(newTitle); @@ -721,7 +721,7 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur surface->transBlitFrom(composeSurface, composePosition, kColorGreen); } -void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * surface) { +void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface) { WindowData &data = findWindowData(target); BorderBounds border = borderBounds(data.type); @@ -881,7 +881,7 @@ void Gui::updateExit(ObjID obj) { } } -void Gui::printText(const Common::String & text) { +void Gui::printText(const Common::String &text) { debugC(1, kMVDebugGUI, "Print Text: %s", text.c_str()); _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } @@ -978,7 +978,7 @@ Common::Point Gui::getGlobalScrolledSurfacePosition(WindowReference reference) { win->getDimensions().top + border.topOffset - data.scrollPos.y); } -WindowData & Gui::findWindowData(WindowReference reference) { +WindowData &Gui::findWindowData(WindowReference reference) { assert(_windowData); Common::List::iterator iter = _windowData->begin(); @@ -992,7 +992,7 @@ WindowData & Gui::findWindowData(WindowReference reference) { error("GUI: Could not locate the desired window data"); } -Graphics::MacWindow * Gui::findWindow(WindowReference reference) { +Graphics::MacWindow *Gui::findWindow(WindowReference reference) { if (reference < 0x80 && reference >= kInventoryStart) { // It's an inventory window return _inventoryWindows[reference - kInventoryStart]; } @@ -1334,14 +1334,14 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { return false; } -bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & event) { +bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event &event) { if (_engine->needsClickToContinue()) return true; return false; } -bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & event) { +bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event &event) { if (_engine->needsClickToContinue()) return true; @@ -1357,7 +1357,7 @@ bool MacVenture::Gui::processOutConsoleEvents(WindowClick click, Common::Event & return getWindowData(kOutConsoleWindow).visible; } -bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event) { +bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event &event) { if (_engine->needsClickToContinue()) return true; @@ -1367,7 +1367,7 @@ bool MacVenture::Gui::processSelfEvents(WindowClick click, Common::Event & event return true; } -bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & event) { +bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONUP) { if (_engine->needsClickToContinue()) { return true; @@ -1397,14 +1397,14 @@ bool MacVenture::Gui::processExitsEvents(WindowClick click, Common::Event & even return getWindowData(kExitsWindow).visible; } -bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event & event) { +bool MacVenture::Gui::processDiplomaEvents(WindowClick click, Common::Event &event) { if (_engine->needsClickToContinue()) return true; return getWindowData(kDiplomaWindow).visible; } -bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { +bool Gui::processInventoryEvents(WindowClick click, Common::Event &event) { if (event.type == Common::EVENT_LBUTTONDOWN && click == kBorderCloseButton) { WindowReference ref = findWindowAtPoint(event.mouse); if (ref == kNoWindow) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index f521286dc7..960c2b8ba3 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -313,8 +313,9 @@ public: if (wrappedLines.empty()) // Sometimes we have empty lines _lines.push_back(""); - for (Common::StringArray::const_iterator j = wrappedLines.begin(); j != wrappedLines.end(); ++j) + for (Common::StringArray::const_iterator j = wrappedLines.begin(); j != wrappedLines.end(); ++j) { _lines.push_back(*j); + } updateScroll(); } diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index c1bfd75158..f0146e344a 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -61,7 +61,7 @@ static const byte loadBits[] = { 0xff }; -ImageAsset::ImageAsset(ObjID original, Container * container) { +ImageAsset::ImageAsset(ObjID original, Container *container) { _id = (original * 2); _mask = (original * 2) + 1; @@ -147,7 +147,7 @@ void ImageAsset::decodePPIC(ObjID id, Common::Array &data, uint &bitHeight delete baseStream; } -void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::decodePPIC0(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint words = bitWidth >> 4; uint bytes = bitWidth & 0xF; uint v = 0; @@ -170,15 +170,15 @@ void ImageAsset::decodePPIC0(Common::BitStream & stream, Common::Array &da } -void ImageAsset::decodePPIC1(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::decodePPIC1(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { decodeHuffGraphic(PPIC1Huff, stream, data, bitHeight, bitWidth, rowBytes); } -void ImageAsset::decodePPIC2(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::decodePPIC2(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { decodeHuffGraphic(PPIC2Huff, stream, data, bitHeight, bitWidth, rowBytes); } -void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::decodePPIC3(Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { // We need to load the huffman from the PPIC itself PPICHuff huff; uint16 v, bits; @@ -192,10 +192,13 @@ void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &da huff.symbols[loadBits[load++]] = v; } huff.symbols[0x10] = 0; - for (uint i = 0x10; i > 0; i--) - for (uint j = i; j <= 0x10; j++) - if (huff.symbols[j] >= huff.symbols[i - 1]) + for (uint i = 0x10; i > 0; i--) { + for (uint j = i; j <= 0x10; j++) { + if (huff.symbols[j] >= huff.symbols[i - 1]) { huff.symbols[j]++; + } + } + } for (int i = 0x10; i >= 0; i--) { if (huff.symbols[i] == 0x10) { @@ -207,14 +210,19 @@ void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &da bits = stream.getBits(2) + 1; uint16 mask = 0; for (uint i = 0; i < 0xf; i++) { - if (i) - while (!stream.getBit()) bits++; + if (i) { + while (!stream.getBit()) { + bits++; + } + } huff.lens[i] = bits; huff.masks[i] = mask; mask += 1 << (16 - bits); } huff.masks[0xf] = mask; - while (mask&(1 << (16 - bits))) bits++; + while (mask&(1 << (16 - bits))) { + bits++; + } huff.masks[0x10] = mask | (1 << (16 - bits)); huff.lens[0xf] = bits; huff.lens[0x10] = bits; @@ -222,14 +230,15 @@ void ImageAsset::decodePPIC3(Common::BitStream & stream, Common::Array &da decodeHuffGraphic(huff, stream, data, bitHeight, bitWidth, rowBytes); } -void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { byte flags = 0; _walkRepeat = 0; _walkLast = 0; - if (bitWidth & 3) + if (bitWidth & 3) { flags = stream.getBits(5); - else + } else { flags = stream.getBits(4) << 1; + } byte odd = 0; byte blank = bitWidth & 0xf; @@ -316,7 +325,7 @@ void ImageAsset::decodeHuffGraphic(const PPICHuff & huff, Common::BitStream & st } } -byte ImageAsset::walkHuff(const PPICHuff & huff, Common::BitStream & stream) { +byte ImageAsset::walkHuff(const PPICHuff &huff, Common::BitStream &stream) { if (_walkRepeat) { _walkRepeat--; _walkLast = ((_walkLast << 8) & 0xFF00) | (_walkLast >> 8); @@ -434,7 +443,7 @@ int ImageAsset::getHeight() { return MAX(0, (int)_imgBitHeight); } -void ImageAsset::blitDirect(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array& data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::blitDirect(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); @@ -451,7 +460,7 @@ void ImageAsset::blitDirect(Graphics::ManagedSurface * target, int ox, int oy, c } } -void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::blitBIC(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); @@ -469,7 +478,7 @@ void ImageAsset::blitBIC(Graphics::ManagedSurface * target, int ox, int oy, cons } } -void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::blitOR(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); @@ -487,7 +496,7 @@ void ImageAsset::blitOR(Graphics::ManagedSurface * target, int ox, int oy, const } } -void ImageAsset::blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { +void ImageAsset::blitXOR(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes) { uint sx, sy, w, h; calculateSectionToDraw(target, ox, oy, bitWidth, bitHeight, sx, sy, w, h); diff --git a/engines/macventure/image.h b/engines/macventure/image.h index 1f7d3e91b4..a026c3b8fa 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -77,10 +77,10 @@ private: void decodeHuffGraphic(const PPICHuff &huff, Common::BitStream &stream, Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); byte walkHuff(const PPICHuff &huff, Common::BitStream &stream); - void blitDirect(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void blitBIC(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void blitOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); - void blitXOR(Graphics::ManagedSurface * target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitDirect(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitBIC(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitOR(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); + void blitXOR(Graphics::ManagedSurface *target, int ox, int oy, const Common::Array &data, uint bitHeight, uint bitWidth, uint rowBytes); void calculateSectionToDraw(Graphics::ManagedSurface *target, int &ox, int &oy, uint bitWidth, uint bitHeight, uint &sx, uint &sy, uint &w, uint &h); void calculateSectionInDirection(uint targetWhole, uint originWhole, int &originPosition, uint &startPosition, uint &blittedWhole); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 7f754c470d..999d41147b 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -387,10 +387,11 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool // Do shift ;) } else { if (_selectedControl && _currentSelection.size() > 0 && getInvolvedObjects() > 1) { - if (objID == 0) + if (objID == 0) { selectPrimaryObject(windata.objRef); - else + } else { selectPrimaryObject(objID); + } preparedToRun(); } else { if (objID == 0) { @@ -633,7 +634,7 @@ void MacVentureEngine::printTexts() { } void MacVentureEngine::playSounds(bool pause) { - int delay=0; + int delay = 0; while (!_soundQueue.empty()) { QueuedSound item = _soundQueue.front(); _soundQueue.remove_at(0); @@ -984,7 +985,7 @@ bool MacVentureEngine::isOldText() const { return _oldTextEncoding; } -const HuffmanLists * MacVentureEngine::getDecodingHuffman() const { +const HuffmanLists *MacVentureEngine::getDecodingHuffman() const { return _textHuffman; } @@ -1122,17 +1123,20 @@ bool MacVentureEngine::loadTextHuffman() { res->readUint16BE(); // Skip uint32 *masks = new uint32[numEntries]; - for (uint i = 0; i < numEntries - 1; i++) + for (uint i = 0; i < numEntries - 1; i++) { // For some reason there are one lass mask than entries masks[i] = res->readUint16BE(); + } uint32 *lengths = new uint32[numEntries]; - for (uint i = 0; i < numEntries; i++) + for (uint i = 0; i < numEntries; i++) { lengths[i] = res->readByte(); + } uint32 *values = new uint32[numEntries]; - for (uint i = 0; i < numEntries; i++) + for (uint i = 0; i < numEntries; i++) { values[i] = res->readByte(); + } _textHuffman = new HuffmanLists(numEntries, lengths, masks, values); debugC(4, kMVDebugMain, "Text is huffman-encoded"); @@ -1175,8 +1179,9 @@ void GlobalSettings::loadSettings(Common::SeekableReadStream *dataStream) { _attrIndices = Common::Array(attrIndices, _numAttributes); delete[] attrIndices; - for (int i = 0; i < _numAttributes; i++) + for (int i = 0; i < _numAttributes; i++) { _attrMasks.push_back(dataStream->readUint16BE()); + } uint8 *attrShifts = new uint8[_numAttributes]; dataStream->read(attrShifts, _numAttributes); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 7e53eb229d..6908bc6050 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -20,8 +20,8 @@ * */ -#ifndef MACVENTURE_H -#define MACVENTURE_H +#ifndef MACVENTURE_MACVENTURE_H +#define MACVENTURE_MACVENTURE_H #include "engines/engine.h" #include "common/scummsys.h" @@ -243,7 +243,7 @@ public: bool isPaused(); bool needsClickToContinue(); Common::String getCommandsPausedString() const; - const GlobalSettings& getGlobalSettings() const; + const GlobalSettings &getGlobalSettings() const; Common::String getFilePath(FilePathID id) const; bool isOldText() const; const HuffmanLists *getDecodingHuffman() const; @@ -310,7 +310,7 @@ private: bool loadGlobalSettings(); bool loadTextHuffman(); - const char* getGameFileName() const; + const char *getGameFileName() const; private: // Attributes diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index a341487cf1..e5cc9b6fa5 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -54,8 +54,9 @@ SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { // Depends on MACVENTURE_DESC_LENGTH byte descSize = s->readByte(); s->seek(-(5 + MACVENTURE_DESC_LENGTH + descSize), SEEK_END); - for (int i = 0; i < descSize; ++i) + for (int i = 0; i < descSize; ++i) { name += s->readByte(); + } desc.setDescription(name); return desc; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index f7e49c68e3..5f5273c6d7 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -29,7 +29,7 @@ namespace MacVenture { -ScriptEngine::ScriptEngine(MacVentureEngine * engine, World * world) { +ScriptEngine::ScriptEngine(MacVentureEngine *engine, World *world) { _engine = engine; _world = world; _scripts = new Container(_engine->getFilePath(kFilterPathID)); @@ -100,12 +100,12 @@ bool ScriptEngine::execFrame(bool execAll) { if (frame->haltedInFamily || doFamily) { // We have to do the family or we were stuck here frame->haltedInFamily = false; Common::Array family = _world->getFamily(_world->getObjAttr(1, kAttrParentObject), false); - uint32 i = frame->familyIdx; - for (; i < family.size(); i++) { + for (uint32 i = frame->familyIdx; i < family.size(); i++) { if (doFamily) { fail = loadScript(frame, family[i]); + } else { + fail = resumeFunc(frame); } - else { fail = resumeFunc(frame); } if (fail) { // We are stuck, so we don't shift the frame frame->haltedInFamily = true; frame->familyIdx = i; @@ -130,7 +130,7 @@ bool ScriptEngine::execFrame(bool execAll) { uint localHigh = 0; do { // Saved function calls highest = 0; - for (uint i = 0; i saves.size(); i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (highest < frame->saves[i].rank) { highest = frame->saves[i].rank; localHigh = i; @@ -150,7 +150,7 @@ bool ScriptEngine::execFrame(bool execAll) { return false; } -bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { +bool ScriptEngine::loadScript(EngineFrame *frame, uint32 scriptID) { if (_scripts->getItemByteSize(scriptID) > 0) { debugC(2, kMVDebugScript, "Loading function %d", scriptID); // Insert the new script at the front @@ -160,7 +160,7 @@ bool ScriptEngine::loadScript(EngineFrame * frame, uint32 scriptID) { return false; } -bool ScriptEngine::resumeFunc(EngineFrame * frame) { +bool ScriptEngine::resumeFunc(EngineFrame *frame) { bool fail = runFunc(frame); if (fail) { return fail; @@ -525,81 +525,81 @@ word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { return sum; } -void MacVenture::ScriptEngine::op80GATT(EngineState * state, EngineFrame * frame) { +void MacVenture::ScriptEngine::op80GATT(EngineState *state, EngineFrame *frame) { word obj = state->pop(); word attr = state->pop(); state->push(_world->getObjAttr(obj, attr)); } -void ScriptEngine::op81SATT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op81SATT(EngineState *state, EngineFrame *frame) { word obj = state->pop(); word attr = state->pop(); word val = neg16(state->pop()); _world->setObjAttr(obj, attr, val); } -void ScriptEngine::op82SUCH(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op82SUCH(EngineState *state, EngineFrame *frame) { word obj = state->pop(); word attr = state->pop(); word recursive = neg16(state->pop()); state->push(sumChildrenAttr(obj, attr, recursive)); } -void ScriptEngine::op83PUCT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op83PUCT(EngineState *state, EngineFrame *frame) { state->push(frame->action); } -void ScriptEngine::op84PUOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op84PUOB(EngineState *state, EngineFrame *frame) { state->push(frame->src); } -void ScriptEngine::op85PUTA(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op85PUTA(EngineState *state, EngineFrame *frame) { state->push(frame->dest); } -void ScriptEngine::op86PUDX(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op86PUDX(EngineState *state, EngineFrame *frame) { state->push(frame->x); } -void ScriptEngine::op87PUDY(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op87PUDY(EngineState *state, EngineFrame *frame) { state->push(frame->y); } -void ScriptEngine::op88PUIB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { state->push(script->fetch()); } -void ScriptEngine::op89PUI(EngineState * state, EngineFrame * frame, ScriptAsset * script) { +void ScriptEngine::op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); state->push(val); } -void ScriptEngine::op8aGGLO(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8aGGLO(EngineState *state, EngineFrame *frame) { word idx = state->pop(); state->push(_world->getGlobal(idx)); } -void ScriptEngine::op8bSGLO(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8bSGLO(EngineState *state, EngineFrame *frame) { word idx = state->pop(); word val = neg16(state->pop()); _world->setGlobal(idx, val); _engine->gameChanged(); } -void ScriptEngine::op8cRAND(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8cRAND(EngineState *state, EngineFrame *frame) { word max = state->pop(); state->push(_engine->randBetween(0, max)); } -void ScriptEngine::op8dCOPY(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8dCOPY(EngineState *state, EngineFrame *frame) { word val = state->pop(); state->push(val); state->push(val); } -void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8eCOPYN(EngineState *state, EngineFrame *frame) { word n = state->pop(); word offs = n - 1; word val; @@ -610,14 +610,14 @@ void ScriptEngine::op8eCOPYN(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::op8fSWAP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op8fSWAP(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(b); state->push(a); } -void ScriptEngine::op90SWAPN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op90SWAPN(EngineState *state, EngineFrame *frame) { word idx = state->pop(); word a = state->peek(idx); word b = state->peek(0); @@ -625,22 +625,22 @@ void ScriptEngine::op90SWAPN(EngineState * state, EngineFrame * frame) { state->poke(0, a); } -void ScriptEngine::op91POP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op91POP(EngineState *state, EngineFrame *frame) { state->pop(); } -void ScriptEngine::op92COPYP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op92COPYP(EngineState *state, EngineFrame *frame) { word val = state->peek(1); state->push(val); } -void ScriptEngine::op93COPYPN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op93COPYPN(EngineState *state, EngineFrame *frame) { word idx = state->pop(); word val = state->peek(idx); state->push(val); } -void ScriptEngine::op94SHUFF(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op94SHUFF(EngineState *state, EngineFrame *frame) { word a = state->pop(); word b = state->pop(); word c = state->pop(); @@ -649,7 +649,7 @@ void ScriptEngine::op94SHUFF(EngineState * state, EngineFrame * frame) { state->push(b); } -void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op95SORT(EngineState *state, EngineFrame *frame) { word step = neg16(state->pop()); word num = neg16(state->pop()); step %= num; @@ -658,7 +658,7 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { } word end = 0; word start = 0; - for (word i = 1;i= num) { start -= num; @@ -675,52 +675,52 @@ void ScriptEngine::op95SORT(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::op96CLEAR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op96CLEAR(EngineState *state, EngineFrame *frame) { state->clear(); } -void ScriptEngine::op97SIZE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op97SIZE(EngineState *state, EngineFrame *frame) { state->push(state->size()); } -void ScriptEngine::op98ADD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op98ADD(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a + b); } -void ScriptEngine::op99SUB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op99SUB(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a - b); } -void ScriptEngine::op9aMUL(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9aMUL(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); state->push(a * b); } -void ScriptEngine::op9bDIV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9bDIV(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); state->push((a / b) | 0); } -void ScriptEngine::op9cMOD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); state->push(a % b); } -void ScriptEngine::op9dDMOD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9dDMOD(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a % b); state->push((a / b) | 0); } -void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { word val = neg16(state->pop()); if (val < 0) { val = -val; @@ -728,110 +728,110 @@ void ScriptEngine::op9eABS(EngineState * state, EngineFrame * frame) { state->push(val); } -void ScriptEngine::op9fNEG(EngineState * state, EngineFrame * frame) { +void ScriptEngine::op9fNEG(EngineState *state, EngineFrame *frame) { word val = -neg16(state->pop()); state->push(val); } -void ScriptEngine::opa0AND(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa0AND(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a & b); } -void ScriptEngine::opa1OR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa1OR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a | b); } -void ScriptEngine::opa2XOR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa2XOR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(a ^ b); } -void ScriptEngine::opa3NOT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa3NOT(EngineState *state, EngineFrame *frame) { word a = state->pop(); state->push(a ^ 0xFFFF); } -void ScriptEngine::opa4LAND(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa4LAND(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((a && b) ? 0xFFFF : 0); } -void ScriptEngine::opa5LOR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa5LOR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((a || b) ? 0xFFFF : 0); } -void ScriptEngine::opa6LXOR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa6LXOR(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((!a != !b) ? 0xFFFF : 0); } -void ScriptEngine::opa7LNOT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa7LNOT(EngineState *state, EngineFrame *frame) { word a = state->pop(); state->push((a == 0) ? 0xFFFF : 0); } -void ScriptEngine::opa8GTU(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa8GTU(EngineState *state, EngineFrame *frame) { uint16 b = state->pop(); uint16 a = state->pop(); state->push((a > b) ? 0xFFFF : 0); } -void ScriptEngine::opa9LTU(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opa9LTU(EngineState *state, EngineFrame *frame) { uint16 b = state->pop(); uint16 a = state->pop(); state->push((a < b) ? 0xFFFF : 0); } -void ScriptEngine::opaaGTS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opaaGTS(EngineState *state, EngineFrame *frame) { // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a > b) ? 0xFFFF : 0); } -void ScriptEngine::opabLTS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opabLTS(EngineState *state, EngineFrame *frame) { // HACK !!! May not need the neg16, since word is already a signed int!! word b = neg16(state->pop()); word a = neg16(state->pop()); state->push((a < b) ? 0xFFFF : 0); } -void ScriptEngine::opacEQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opacEQ(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push((a == b) ? 0xFFFF : 0); } -void ScriptEngine::opadEQS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opadEQS(EngineState *state, EngineFrame *frame) { Common::String b = _world->getText(state->pop(), 0, 0); // HACK, these destinations might be wrong Common::String a = _world->getText(state->pop(), 0, 0); state->push((a == b) ? 1 : 0); } -void ScriptEngine::opaeCONT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opaeCONT(EngineState *state, EngineFrame *frame) { Common::String needle = _world->getText(state->pop(), 0, 0); Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } -void ScriptEngine::opafCONTW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opafCONTW(EngineState *state, EngineFrame *frame) { Common::String needle = _world->getText(state->pop(), 0, 0); Common::String haystack = _world->getText(state->pop(), 0, 0); haystack.toLowercase(); state->push(haystack.contains(needle) ? 1 : 0); } -void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); @@ -839,13 +839,13 @@ void ScriptEngine::opb0BRA(EngineState * state, EngineFrame * frame, ScriptAsset script->branch(val); } -void ScriptEngine::opb1BRAB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); script->branch(val); } -void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); @@ -856,7 +856,7 @@ void ScriptEngine::opb2BEQ(EngineState * state, EngineFrame * frame, ScriptAsset } } -void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); @@ -865,7 +865,7 @@ void ScriptEngine::opb3BEQB(EngineState * state, EngineFrame * frame, ScriptAsse } } -void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val <<= 8; val = val | script->fetch(); @@ -876,7 +876,7 @@ void ScriptEngine::opb4BNE(EngineState * state, EngineFrame * frame, ScriptAsset } } -void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsset *script) { +void ScriptEngine::opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { word val = script->fetch(); val = neg8(val); word b = state->pop(); @@ -885,13 +885,13 @@ void ScriptEngine::opb5BNEB(EngineState * state, EngineFrame * frame, ScriptAsse } } -void ScriptEngine::opb6CLAT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb6CLAT(EngineState *state, EngineFrame *frame) { word rank = state->pop(); word func = state->pop(); frame->saves.push_back(FunCall(func, rank)); } -void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb7CCA(EngineState *state, EngineFrame *frame) { word func = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].func == func) @@ -899,26 +899,26 @@ void ScriptEngine::opb7CCA(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::opb8CLOW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb8CLOW(EngineState *state, EngineFrame *frame) { word hi = state->pop(); - for (uint i = 0;isaves.size();i++) + for (uint i = 0; i < frame->saves.size(); i++) if (frame->saves[i].rank <= hi) frame->saves[i].rank = 0; } -void ScriptEngine::opb9CHI(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opb9CHI(EngineState *state, EngineFrame *frame) { word lo = state->pop(); - for (uint i = 0;isaves.size();i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo) { frame->saves[i].rank = 0; } } } -void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbaCRAN(EngineState *state, EngineFrame *frame) { word hi = state->pop(); word lo = state->pop(); - for (uint i = 0;isaves.size();i++) { + for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo && frame->saves[i].rank <= hi) { frame->saves[i].rank = 0; @@ -926,7 +926,7 @@ void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) { } } -bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { +bool ScriptEngine::opbbFORK(EngineState *state, EngineFrame *frame) { EngineFrame newframe; newframe.action = (ControlAction)state->pop(); newframe.src = state->pop(); @@ -943,7 +943,7 @@ bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { return false; } -bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { +bool ScriptEngine::opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script) { word id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; @@ -956,12 +956,12 @@ bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsse return false; } -void ScriptEngine::opbdFOOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbdFOOB(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _engine->enqueueObject(kFocusWindow, obj); } -void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbeSWOB(EngineState *state, EngineFrame *frame) { ObjID from = state->pop(); ObjID to = state->pop(); _engine->enqueueObject(kUpdateWindow, from, to); @@ -973,62 +973,63 @@ void ScriptEngine::opbeSWOB(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::opbfSNOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opbfSNOB(EngineState *state, EngineFrame *frame) { _engine->enqueueObject(kAnimateBack, frame->src); } -void ScriptEngine::opc0TEXI(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc0TEXI(EngineState *state, EngineFrame *frame) { _engine->enqueueObject(kHightlightExits, 0); } -void ScriptEngine::opc1PTXT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc1PTXT(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); } -void ScriptEngine::opc2PNEW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc2PNEW(EngineState *state, EngineFrame *frame) { _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } -void ScriptEngine::opc3PTNE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc3PTNE(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } -void ScriptEngine::opc4PNTN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc4PNTN(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } -void ScriptEngine::opc5PNUM(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc5PNUM(EngineState *state, EngineFrame *frame) { word tid = state->pop(); _engine->enqueueText(kTextNumber, frame->dest, frame->src, tid); } -void ScriptEngine::opc6P2(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc6P2(EngineState *state, EngineFrame *frame) { state->push(2); } -void ScriptEngine::opc7PLBG(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc7PLBG(EngineState *state, EngineFrame *frame) { word target = state->pop(); _engine->enqueueSound(kSoundPlay, target); } -void ScriptEngine::opc8PLAW(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc8PLAW(EngineState *state, EngineFrame *frame) { word target = state->pop(); _engine->enqueueSound(kSoundPlayAndWait, target); } -void ScriptEngine::opc9WAIT(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opc9WAIT(EngineState *state, EngineFrame *frame) { _engine->enqueueSound(kSoundWait, 0); } -void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { - for (uint i = 0; i < 3; i++) // We skip year, month and date +void ScriptEngine::opcaTIME(EngineState *state, EngineFrame *frame) { + for (uint i = 0; i < 3; i++) {// We skip year, month and date state->push(0x00); + } uint32 totalPlayTime = _engine->getTotalPlayTime() / 1000; // In seconds word hours = totalPlayTime / 3600; @@ -1041,12 +1042,12 @@ void ScriptEngine::opcaTIME(EngineState * state, EngineFrame * frame) { debugC(2, kMVDebugScript, "Saved time: h[%d] m[%d] s[%d]", hours, minutes, totalPlayTime); } -void ScriptEngine::opcbDAY(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opcbDAY(EngineState *state, EngineFrame *frame) { // Probaby irrelevant, so we push Day [9] state->push(9); } -void ScriptEngine::opccCHLD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opccCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; word obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); @@ -1056,49 +1057,49 @@ void ScriptEngine::opccCHLD(EngineState * state, EngineFrame * frame) { state->push(children.size()); } -void ScriptEngine::opcdNCHLD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opcdNCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; word obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); state->push(children.size()); } -void ScriptEngine::opceVERS(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opceVERS(EngineState *state, EngineFrame *frame) { state->push(86); } -void ScriptEngine::opcfPSCE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opcfPSCE(EngineState *state, EngineFrame *frame) { state->push(0); //Not release } -void ScriptEngine::opd0P1(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd0P1(EngineState *state, EngineFrame *frame) { state->push(1); } -void ScriptEngine::opd1GOBD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd1GOBD(EngineState *state, EngineFrame *frame) { word obj = state->pop(); Common::Rect bounds = _engine->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); } -void ScriptEngine::opd2GOVP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd2GOVP(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); state->push(_engine->getOverlapPercent(b, a)); } -void ScriptEngine::opd3CAPC(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd3CAPC(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _world->captureChildren(obj); } -void ScriptEngine::opd4RELC(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd4RELC(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _world->releaseChildren(obj); } -void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd5DLOG(EngineState *state, EngineFrame *frame) { word txt = state->pop(); if (_engine->showTextEntry(txt, frame->src, frame->dest)) { state->push(0xFF); @@ -1107,60 +1108,60 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) { } } -void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd6ACMD(EngineState *state, EngineFrame *frame) { _engine->selectControl((ControlAction)state->pop()); } -void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd7LOSE(EngineState *state, EngineFrame *frame) { _engine->loseGame(); } -void ScriptEngine::opd8WIN(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd8WIN(EngineState *state, EngineFrame *frame) { _engine->winGame(); } -void ScriptEngine::opd9SLEEP(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opd9SLEEP(EngineState *state, EngineFrame *frame) { word ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->preparedToRun(); } -void ScriptEngine::opdaCLICK(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdaCLICK(EngineState *state, EngineFrame *frame) { _engine->updateState(false); _engine->clickToContinue(); } -void ScriptEngine::opdbROBQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdbROBQ(EngineState *state, EngineFrame *frame) { _engine->runObjQueue(); } -void ScriptEngine::opdcRSQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdcRSQ(EngineState *state, EngineFrame *frame) { _engine->playSounds(true); } -void ScriptEngine::opddRTQ(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opddRTQ(EngineState *state, EngineFrame *frame) { _engine->printTexts(); } -void ScriptEngine::opdeUPSC(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdeUPSC(EngineState *state, EngineFrame *frame) { _engine->updateState(true); } -void ScriptEngine::opdfFMAI(EngineState * state, EngineFrame * frame) { +void ScriptEngine::opdfFMAI(EngineState *state, EngineFrame *frame) { word ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->revert(); } -void ScriptEngine::ope0CHGR(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope0CHGR(EngineState *state, EngineFrame *frame) { state->pop(); } -void ScriptEngine::ope1CHSO(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope1CHSO(EngineState *state, EngineFrame *frame) { state->pop(); } -void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope2MDIV(EngineState *state, EngineFrame *frame) { word b = state->pop(); word a = state->pop(); a *= b; @@ -1169,25 +1170,25 @@ void ScriptEngine::ope2MDIV(EngineState * state, EngineFrame * frame) { state->push(a | 0); } -void ScriptEngine::ope3UPOB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope3UPOB(EngineState *state, EngineFrame *frame) { word obj = state->pop(); _world->updateObj(obj); } -void ScriptEngine::ope4PLEV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope4PLEV(EngineState *state, EngineFrame *frame) { state->push(0); } -void ScriptEngine::ope5WEV(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope5WEV(EngineState *state, EngineFrame *frame) { op00NOOP(0xe5); } -void ScriptEngine::ope6GFIB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope6GFIB(EngineState *state, EngineFrame *frame) { state->push(0); op00NOOP(0xe6); } -void ScriptEngine::ope7CFIB(EngineState * state, EngineFrame * frame) { +void ScriptEngine::ope7CFIB(EngineState *state, EngineFrame *frame) { state->pop(); op00NOOP(0xe7); } @@ -1198,7 +1199,7 @@ void ScriptEngine::op00NOOP(byte op) { -ScriptAsset::ScriptAsset(ObjID id, Container * container) { +ScriptAsset::ScriptAsset(ObjID id, Container *container) { _id = id; _container = container; _ip = 0x0; diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 5760a31e8a..afeed4a848 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -148,9 +148,9 @@ public: private: bool execFrame(bool execAll); - bool loadScript(EngineFrame * frame, uint32 scriptID); - bool resumeFunc(EngineFrame * frame); - bool runFunc(EngineFrame * frame); + bool loadScript(EngineFrame *frame, uint32 scriptID); + bool resumeFunc(EngineFrame *frame); + bool runFunc(EngineFrame *frame); private: diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index 492bf55b43..fd39e2bf5e 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -37,7 +37,7 @@ SoundManager::SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer) { debugC(1, kMVDebugSound, "Created sound manager with file %s", filename.c_str()); } -SoundManager::~SoundManager(){ +SoundManager::~SoundManager() { if (_container) delete _container; @@ -159,7 +159,7 @@ void SoundAsset::decode12(Common::SeekableReadStream *stream) { byte ch = stream->readByte(); if (ch & 0x80) { ch -= 0x80; - uint32 env= ch * scale; + uint32 env = ch * scale; ch = (env >> 8) & 0xff; if (ch & 0x80) { ch = 0x7f; @@ -265,7 +265,7 @@ void SoundAsset::decode7e(Common::SeekableReadStream *stream) { stream->readUint32BE(); _length = stream->readUint32BE(); _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; - uint32 last=0x80; + uint32 last = 0x80; byte ch = 0; for (uint i = 0; i < _length; i++) { if (i & 1) { diff --git a/engines/macventure/stringtable.h b/engines/macventure/stringtable.h index 54aba03337..2f1d671696 100644 --- a/engines/macventure/stringtable.h +++ b/engines/macventure/stringtable.h @@ -79,7 +79,7 @@ private: uint8 strLength = 0; for (uint i = 0; i < numStrings; ++i) { strLength = res->readByte(); - char* str = new char[strLength + 1]; + char *str = new char[strLength + 1]; res->read(str, strLength); str[strLength] = '\0'; // HACK until a proper special char implementation is found, this will have to do. diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 7981692c0a..a2777f8774 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -43,7 +43,7 @@ void TextAsset::decodeOld() { Common::SeekableReadStream *res = _container->getItem(_id); uint16 strLen = res->readUint16BE(); Common::BitStream32BELSB stream(res, true); - char* str = new char[strLen + 1]; + char *str = new char[strLen + 1]; bool lowercase = false; char c; for (uint16 i = 0; i < strLen; i++) { diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index fc563cb639..4847dcf0f1 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -131,8 +131,9 @@ bool MacVenture::World::isObjActive(ObjID obj) { ObjID World::getAncestor(ObjID objID) { ObjID root = getObjAttr(1, kAttrParentObject); - while (objID != 0 && objID != 1 && objID != root) + while (objID != 0 && objID != 1 && objID != root) { objID = getObjAttr(objID, kAttrParentObject); + } return objID; } @@ -279,11 +280,11 @@ void SaveGame::setAttr(uint32 attrID, ObjID objID, Attribute value) { _groups[attrID][objID] = value; } -const Common::Array& MacVenture::SaveGame::getGroups() { +const Common::Array &MacVenture::SaveGame::getGroups() { return _groups; } -const AttributeGroup * SaveGame::getGroup(uint32 groupID) { +const AttributeGroup *SaveGame::getGroup(uint32 groupID) { assert(groupID < _groups.size()); return &(_groups[groupID]); } @@ -292,11 +293,11 @@ void SaveGame::setGlobal(uint32 attrID, Attribute value) { _globals[attrID] = value; } -const Common::Array& SaveGame::getGlobals() { +const Common::Array &SaveGame::getGlobals() { return _globals; } -const Common::String & SaveGame::getText() { +const Common::String &SaveGame::getText() { return _text; } @@ -320,7 +321,7 @@ void SaveGame::saveInto(Common::OutSaveFile *file) { file->write(_text.c_str(), _text.size()); } -void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) { +void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream *res) { GlobalSettings settings = engine->getGlobalSettings(); for (int i = 0; i < settings._numGroups; ++i) { AttributeGroup g; @@ -332,14 +333,14 @@ void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * } } -void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream * res) { +void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream *res) { GlobalSettings settings = engine->getGlobalSettings(); for (int i = 0; i < settings._numGlobals; ++i) { _globals.push_back(res->readUint16BE()); } } -void SaveGame::loadText(MacVentureEngine *engine, Common::SeekableReadStream * res) { +void SaveGame::loadText(MacVentureEngine *engine, Common::SeekableReadStream *res) { _text = "Placeholder Console Text"; } -- cgit v1.2.3 From d8e4d18f7a2226aec3010683de8f40dee3b7e831 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 15:46:00 +0200 Subject: MACVENTURE: Remove leftover comments and document magic constants --- engines/macventure/gui.cpp | 33 ++++++--------------------------- engines/macventure/gui.h | 1 - engines/macventure/image.h | 1 - engines/macventure/macventure.cpp | 38 +++++++++++--------------------------- engines/macventure/script.cpp | 4 ++-- engines/macventure/text.cpp | 3 +-- engines/macventure/world.cpp | 2 ++ 7 files changed, 22 insertions(+), 60 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d0af4ed51f..27454054d5 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -187,6 +187,7 @@ void Gui::draw() { drawDraggedObject(); drawDialog(); + // TODO: When window titles with custom borders are in MacGui, this should be used. //drawWindowTitle(kMainGameWindow, _mainGameWindow->getSurface()); } @@ -408,7 +409,9 @@ bool Gui::loadMenus() { char *title; /* Skip menuID, width, height, resourceID, placeholder */ - for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } + for (int skip = 0; skip < 5; skip++) { + res->readUint16BE(); + } titleLength = res->readByte(); title = new char[titleLength + 1]; res->read(title, titleLength); @@ -518,7 +521,7 @@ bool Gui::loadControls() { data.scrollMax = res->readUint16BE(); data.scrollMin = res->readUint16BE(); data.cdef = res->readUint16BE(); - data.refcon = (ControlAction)res->readUint32BE();//(ControlType)id; id++; + data.refcon = (ControlAction)res->readUint32BE(); data.type = (ControlType)id; id++; data.titleLength = res->readByte(); if (data.titleLength) { @@ -660,10 +663,6 @@ void Gui::drawExitsWindow() { } findWindow(kExitsWindow)->setDirty(true); - - // To be deleted - //g_system->copyRectToScreen(srf->getPixels(), srf->pitch, 0, 0, srf->w, srf->h); - //g_system->updateScreen(); } void Gui::drawConsoleWindow() { @@ -722,21 +721,7 @@ void Gui::drawObjectsInWindow(const WindowData &targetData, Graphics::ManagedSur } void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface *surface) { - WindowData &data = findWindowData(target); - BorderBounds border = borderBounds(data.type); - - uint left = 10;//getCurrentFont().getStringWidth(data.title) - 10; - uint right = 30;//getCurrentFont().getStringWidth(data.title) + 10; - - surface->fillRect(Common::Rect(left, 0, right, border.topOffset - 1), kColorGray); - getCurrentFont().drawString( - surface, - data.title, - 0, - right, - right - left, - kColorBlack, - Graphics::kTextAlignCenter); + // TODO: Implement when MacGui supports titles in windows with custom borders. } void Gui::drawDraggedObject() { @@ -1290,12 +1275,6 @@ bool Gui::processEvent(Common::Event &event) { moveDraggedObject(event.mouse); } processed = true; - - // TEST - //Common::Rect mr = calculateClickRect(event.mouse, _screen.getBounds()); - //_screen.fillRect(mr, kColorGreen); - //g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h); - //g_system->updateScreen(); } processed |= _wm.processEvent(event); diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 960c2b8ba3..8ae4a1534d 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -71,7 +71,6 @@ enum MenuAction { kMenuActionCommand }; -//} using namespace MacVentureMenuActions; struct DraggedObj { ObjID id; diff --git a/engines/macventure/image.h b/engines/macventure/image.h index a026c3b8fa..6f6b9600ac 100644 --- a/engines/macventure/image.h +++ b/engines/macventure/image.h @@ -37,7 +37,6 @@ enum BlitMode { kBlitBIC = 1, kBlitOR = 2, kBlitXOR = 3 - //kBlitNONE = 4, }; enum GraphicsEncoding { diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 999d41147b..e28bc4e9ba 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -384,7 +384,7 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool const WindowData &windata = _gui->getWindowData(win); if (shiftPressed) { - // Do shift ;) + // TODO: Implement shift functionality. } else { if (_selectedControl && _currentSelection.size() > 0 && getInvolvedObjects() > 1) { if (objID == 0) { @@ -450,14 +450,12 @@ bool MacVentureEngine::showTextEntry(ObjID text, ObjID srcObj, ObjID destObj) { debugC(3, kMVDebugMain, "Showing speech dialog, asset %d from %d to %d", text, srcObj, destObj); _gui->getTextFromUser(); - // HACK WITH FLAGS _prepared = false; warning("Show text entry: not fully tested"); return true; } void MacVentureEngine::setTextInput(Common::String content) { - // HACK WITH FLAGS _prepared = true; _userInput = content; _clickToContinue = false; @@ -646,7 +644,7 @@ void MacVentureEngine::playSounds(bool pause) { delay = _soundManager->playSound(item.reference); break; case kSoundWait: - //wait for sound to finish? + // Empty in the original. break; } } @@ -681,6 +679,7 @@ void MacVentureEngine::unselectAll() { void MacVentureEngine::selectObject(ObjID objID) { if (!_currentSelection.empty()) { if (findParentWindow(objID) != findParentWindow(_currentSelection[0])) { + // TODO: Needs further testing, but it doesn't seem necessary. //unselectAll(); } } @@ -731,11 +730,7 @@ uint MacVentureEngine::getPrefixNdx(ObjID obj) { Common::String MacVentureEngine::getPrefixString(uint flag, ObjID obj) { uint ndx = getPrefixNdx(obj); ndx = ((ndx) >> flag) & 3; - if (ndx) { - return _decodingNamingArticles->getString(ndx); - } else { - return Common::String("m1551gn0 "); - } + return _decodingNamingArticles->getString(ndx); } Common::String MacVentureEngine::getNoun(ObjID ndx) { @@ -743,20 +738,9 @@ Common::String MacVentureEngine::getNoun(ObjID ndx) { } void MacVentureEngine::highlightExit(ObjID objID) { - //ObjID ctl = _gui->getWinChild(obj); - /*if (ctl) { - if (findObjectInArray(obj, _selectedObjs) != -1) - _gui->selectExit(ctl); - else - _gui->unselectExit(ctl); - } - if (obj == _world->getObjAttr(1, kAttrParentObject)) { - if (findObjectInArray(obj, _selectedObjs) != -1) - _gui->selectExit(obj); - else - _gui->unselectExit(obj); - }*/ - //updateWindow(findParentWindow(obj)); + // TODO: It seems unnecessary since the GUI checks whether an object + // is selected, which includes exits. + warning("STUB: highlightExit"); } void MacVentureEngine::selectPrimaryObject(ObjID objID) { @@ -816,7 +800,6 @@ void MacVentureEngine::closeObject(ObjID objID) { } void MacVentureEngine::checkObject(QueuedObject old) { - //warning("checkObject: unimplemented"); bool hasChanged = false; debugC(3, kMVDebugMain, "Check Object[%d] parent[%d] x[%d] y[%d]", old.object, @@ -887,7 +870,6 @@ void MacVentureEngine::checkObject(QueuedObject old) { } void MacVentureEngine::reflectSwap(ObjID fromID, ObjID toID) { - //warning("reflectSwap: untested"); WindowReference from = getObjWindow(fromID); WindowReference to = getObjWindow(toID); WindowReference tmp = to; @@ -936,7 +918,7 @@ bool MacVentureEngine::isGameRunning() { ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlType id) { switch (id) { case MacVenture::kControlExitBox: - return kActivateObject;//?? + return kActivateObject;//?? Like this in the original case MacVenture::kControlExamine: return kExamine; case MacVenture::kControlOpen: @@ -994,6 +976,8 @@ uint32 MacVentureEngine::randBetween(uint32 min, uint32 max) { } uint32 MacVentureEngine::getInvolvedObjects() { + // If there is no valid control selected, we return a number too big + // to be useful. There is no control that uses that many objects. return (_selectedControl ? getGlobalSettings()._cmdArgCnts[_selectedControl - 1] : 3000); } @@ -1048,7 +1032,7 @@ Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { } uint MacVentureEngine::getOverlapPercent(ObjID one, ObjID other) { - //not the same parent? 0 overlap + // If it's not the same parent, there's 0 overlap if (_world->getObjAttr(one, kAttrParentObject) != _world->getObjAttr(other, kAttrParentObject)) return 0; diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index 5f5273c6d7..f0a3bac4c5 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -1065,11 +1065,11 @@ void ScriptEngine::opcdNCHLD(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opceVERS(EngineState *state, EngineFrame *frame) { - state->push(86); + state->push(86); // Engine version is irrelevant. Like this in the original. } void ScriptEngine::opcfPSCE(EngineState *state, EngineFrame *frame) { - state->push(0); //Not release + state->push(0); // Any value greater than 0 indicates "Release". } void ScriptEngine::opd0P1(EngineState *state, EngineFrame *frame) { diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index a2777f8774..46a54bd4ab 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -113,12 +113,11 @@ void TextAsset::decodeHuffman() { } else { strLen = stream.getBits(7); } - // OK up to here uint32 mask = 0; uint32 symbol = 0; char c; for (uint16 i = 0; i < strLen; i++) { - mask = stream.peekBits(16); // The mask is OK + mask = stream.peekBits(16); uint32 entry; // Find the length index diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index 4847dcf0f1..7c14618f3e 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -317,6 +317,7 @@ void SaveGame::saveInto(Common::OutSaveFile *file) { file->writeUint16BE((*global)); } // Save text + // TODO: Insert text from GUI console _text = "Hello"; file->write(_text.c_str(), _text.size()); } @@ -341,6 +342,7 @@ void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream } void SaveGame::loadText(MacVentureEngine *engine, Common::SeekableReadStream *res) { + // TODO: Load console text. For now, the GUI doesn't even look at this. _text = "Placeholder Console Text"; } -- cgit v1.2.3 From 12ce17d90c8409c29cb8f88d9af3ffd6a28bd459 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 15:50:18 +0200 Subject: MACVENTURE: Merge detection tables into detection.cpp --- engines/macventure/detection.cpp | 13 +++++++++++-- engines/macventure/detection_tables.h | 35 ----------------------------------- 2 files changed, 11 insertions(+), 37 deletions(-) delete mode 100644 engines/macventure/detection_tables.h diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 9329a9a185..2b161142c4 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -29,13 +29,22 @@ namespace MacVenture { +#define ADGF_DEFAULT (ADGF_DROPLANGUAGE|ADGF_DROPPLATFORM|ADGF_MACRESFORK) + +#define BASEGAME(n, v, f, md5, s) {n, v, AD_ENTRY1s(f, md5, s), Common::EN_ANY, Common::kPlatformMacintosh, ADGF_DEFAULT, GUIO0()} + +static const ADGameDescription gameDescriptions[] = { + BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "ebbfbcbf93938bd2900cb0c0213b19ad", 68974), // Zojoi Rerelease + BASEGAME("deja_vu", "Zojoi Rerelease", "Deja Vu.bin", "5e9f5a8e3c8eb29ed02b34ae5937354f", 69034), // Zojoi Rerelease + BASEGAME("deja_vu2", "Zojoi Rerelease", "Lost in Las Vegas.bin", "8f8e1d8d41f577ee0fbc03847969af0d", 66520), // Zojoi Rerelease + AD_TABLE_END_MARKER +}; + const char *MacVentureEngine::getGameFileName() const { return _gameDescription->filesDescriptions[0].fileName; } } // End of namespace MacVenture -#include "macventure/detection_tables.h" - static const PlainGameDescriptor macventureGames[] = { { "shadowgate", "Shadowgate" }, { "deja_vu", "Deja Vu"}, diff --git a/engines/macventure/detection_tables.h b/engines/macventure/detection_tables.h deleted file mode 100644 index 6ba51e0086..0000000000 --- a/engines/macventure/detection_tables.h +++ /dev/null @@ -1,35 +0,0 @@ -/* 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. -* -*/ - -namespace MacVenture { - -#define ADGF_DEFAULT (ADGF_DROPLANGUAGE|ADGF_DROPPLATFORM|ADGF_MACRESFORK) - -#define BASEGAME(n, v, f, md5, s) {n, v, AD_ENTRY1s(f, md5, s), Common::EN_ANY, Common::kPlatformMacintosh, ADGF_DEFAULT, GUIO0()} - -static const ADGameDescription gameDescriptions[] = { - BASEGAME("shadowgate", "Zojoi Rerelease", "Shadowgate.bin", "ebbfbcbf93938bd2900cb0c0213b19ad", 68974), // Zojoi Rerelease - BASEGAME("deja_vu", "Zojoi Rerelease", "Deja Vu.bin", "5e9f5a8e3c8eb29ed02b34ae5937354f", 69034), // Zojoi Rerelease - BASEGAME("deja_vu2", "Zojoi Rerelease", "Lost in Las Vegas.bin", "8f8e1d8d41f577ee0fbc03847969af0d", 66520), // Zojoi Rerelease - AD_TABLE_END_MARKER -}; -} // End of namespace MacVenture -- cgit v1.2.3 From 97af2b6e14ab25e37aa0c3d226c0264ac2a8ec12 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 16:51:10 +0200 Subject: MACVENTURE: Remove word typedef --- engines/macventure/script.cpp | 222 +++++++++++++++++++++--------------------- engines/macventure/script.h | 33 +++---- 2 files changed, 127 insertions(+), 128 deletions(-) diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index f0a3bac4c5..e18bf65979 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -504,20 +504,20 @@ bool ScriptEngine::runFunc(EngineFrame *frame) { return false; } -word ScriptEngine::neg16(word val) { +int16 ScriptEngine::neg16(int16 val) { if (val & 0x8000) val = -((val ^ 0xFFFF) + 1); return val; } -word ScriptEngine::neg8(word val) { +int16 ScriptEngine::neg8(int16 val) { if (val & 0x80) val = -((val ^ 0xff) + 1); return val; } -word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { - word sum = 0; +int16 ScriptEngine::sumChildrenAttr(int16 obj, int16 attr, bool recursive) { + int16 sum = 0; Common::Array children = _world->getChildren(obj, recursive); for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { sum += _world->getObjAttr(*it, attr); @@ -526,22 +526,22 @@ word ScriptEngine::sumChildrenAttr(word obj, word attr, bool recursive) { } void MacVenture::ScriptEngine::op80GATT(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); - word attr = state->pop(); + int16 obj = state->pop(); + int16 attr = state->pop(); state->push(_world->getObjAttr(obj, attr)); } void ScriptEngine::op81SATT(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); - word attr = state->pop(); - word val = neg16(state->pop()); + int16 obj = state->pop(); + int16 attr = state->pop(); + int16 val = neg16(state->pop()); _world->setObjAttr(obj, attr, val); } void ScriptEngine::op82SUCH(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); - word attr = state->pop(); - word recursive = neg16(state->pop()); + int16 obj = state->pop(); + int16 attr = state->pop(); + int16 recursive = neg16(state->pop()); state->push(sumChildrenAttr(obj, attr, recursive)); } @@ -570,39 +570,39 @@ void ScriptEngine::op88PUIB(EngineState *state, EngineFrame *frame, ScriptAsset } void ScriptEngine::op89PUI(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); state->push(val); } void ScriptEngine::op8aGGLO(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); + int16 idx = state->pop(); state->push(_world->getGlobal(idx)); } void ScriptEngine::op8bSGLO(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); - word val = neg16(state->pop()); + int16 idx = state->pop(); + int16 val = neg16(state->pop()); _world->setGlobal(idx, val); _engine->gameChanged(); } void ScriptEngine::op8cRAND(EngineState *state, EngineFrame *frame) { - word max = state->pop(); + int16 max = state->pop(); state->push(_engine->randBetween(0, max)); } void ScriptEngine::op8dCOPY(EngineState *state, EngineFrame *frame) { - word val = state->pop(); + int16 val = state->pop(); state->push(val); state->push(val); } void ScriptEngine::op8eCOPYN(EngineState *state, EngineFrame *frame) { - word n = state->pop(); - word offs = n - 1; - word val; + int16 n = state->pop(); + int16 offs = n - 1; + int16 val; while (n) { val = state->peek(offs); state->push(val); @@ -611,16 +611,16 @@ void ScriptEngine::op8eCOPYN(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op8fSWAP(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(b); state->push(a); } void ScriptEngine::op90SWAPN(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); - word a = state->peek(idx); - word b = state->peek(0); + int16 idx = state->pop(); + int16 a = state->peek(idx); + int16 b = state->peek(0); state->poke(idx, b); state->poke(0, a); } @@ -630,35 +630,35 @@ void ScriptEngine::op91POP(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op92COPYP(EngineState *state, EngineFrame *frame) { - word val = state->peek(1); + int16 val = state->peek(1); state->push(val); } void ScriptEngine::op93COPYPN(EngineState *state, EngineFrame *frame) { - word idx = state->pop(); - word val = state->peek(idx); + int16 idx = state->pop(); + int16 val = state->peek(idx); state->push(val); } void ScriptEngine::op94SHUFF(EngineState *state, EngineFrame *frame) { - word a = state->pop(); - word b = state->pop(); - word c = state->pop(); + int16 a = state->pop(); + int16 b = state->pop(); + int16 c = state->pop(); state->push(a); state->push(c); state->push(b); } void ScriptEngine::op95SORT(EngineState *state, EngineFrame *frame) { - word step = neg16(state->pop()); - word num = neg16(state->pop()); + int16 step = neg16(state->pop()); + int16 num = neg16(state->pop()); step %= num; if (step < 0) { step += num; } - word end = 0; - word start = 0; - for (word i = 1; i < num; i++) { + int16 end = 0; + int16 start = 0; + for (int16 i = 1; i < num; i++) { start += step; if (start >= num) { start -= num; @@ -667,8 +667,8 @@ void ScriptEngine::op95SORT(EngineState *state, EngineFrame *frame) { end++; start = end; } else { - word a = state->peek(end); - word b = state->peek(start); + int16 a = state->peek(end); + int16 b = state->peek(start); state->poke(end, b); state->poke(start, a); } @@ -684,14 +684,14 @@ void ScriptEngine::op97SIZE(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op98ADD(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a + b); } void ScriptEngine::op99SUB(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a - b); } @@ -714,14 +714,14 @@ void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op9dDMOD(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a % b); state->push((a / b) | 0); } void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { - word val = neg16(state->pop()); + int16 val = neg16(state->pop()); if (val < 0) { val = -val; } @@ -729,53 +729,53 @@ void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { } void ScriptEngine::op9fNEG(EngineState *state, EngineFrame *frame) { - word val = -neg16(state->pop()); + int16 val = -neg16(state->pop()); state->push(val); } void ScriptEngine::opa0AND(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a & b); } void ScriptEngine::opa1OR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a | b); } void ScriptEngine::opa2XOR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(a ^ b); } void ScriptEngine::opa3NOT(EngineState *state, EngineFrame *frame) { - word a = state->pop(); + int16 a = state->pop(); state->push(a ^ 0xFFFF); } void ScriptEngine::opa4LAND(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((a && b) ? 0xFFFF : 0); } void ScriptEngine::opa5LOR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((a || b) ? 0xFFFF : 0); } void ScriptEngine::opa6LXOR(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((!a != !b) ? 0xFFFF : 0); } void ScriptEngine::opa7LNOT(EngineState *state, EngineFrame *frame) { - word a = state->pop(); + int16 a = state->pop(); state->push((a == 0) ? 0xFFFF : 0); } @@ -792,22 +792,22 @@ void ScriptEngine::opa9LTU(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opaaGTS(EngineState *state, EngineFrame *frame) { - // HACK !!! May not need the neg16, since word is already a signed int!! - word b = neg16(state->pop()); - word a = neg16(state->pop()); + // HACK !!! May not need the neg16, since it's already a signed int!! + int16 b = neg16(state->pop()); + int16 a = neg16(state->pop()); state->push((a > b) ? 0xFFFF : 0); } void ScriptEngine::opabLTS(EngineState *state, EngineFrame *frame) { - // HACK !!! May not need the neg16, since word is already a signed int!! - word b = neg16(state->pop()); - word a = neg16(state->pop()); + // HACK !!! May not need the neg16, since it's already a signed int!! + int16 b = neg16(state->pop()); + int16 a = neg16(state->pop()); state->push((a < b) ? 0xFFFF : 0); } void ScriptEngine::opacEQ(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push((a == b) ? 0xFFFF : 0); } @@ -832,7 +832,7 @@ void ScriptEngine::opafCONTW(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); val = neg16(val); @@ -840,59 +840,59 @@ void ScriptEngine::opb0BRA(EngineState *state, EngineFrame *frame, ScriptAsset * } void ScriptEngine::opb1BRAB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val = neg8(val); script->branch(val); } void ScriptEngine::opb2BEQ(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); val = neg16(val); - word b = state->pop(); + int16 b = state->pop(); if (b != 0) { script->branch(val); } } void ScriptEngine::opb3BEQB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val = neg8(val); - word b = state->pop(); + int16 b = state->pop(); if (b != 0) { script->branch(val); } } void ScriptEngine::opb4BNE(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val <<= 8; val = val | script->fetch(); val = neg16(val); - word b = state->pop(); + int16 b = state->pop(); if (b == 0) { script->branch(val); } } void ScriptEngine::opb5BNEB(EngineState *state, EngineFrame *frame, ScriptAsset *script) { - word val = script->fetch(); + int16 val = script->fetch(); val = neg8(val); - word b = state->pop(); + int16 b = state->pop(); if (b == 0) { script->branch(val); } } void ScriptEngine::opb6CLAT(EngineState *state, EngineFrame *frame) { - word rank = state->pop(); - word func = state->pop(); + int16 rank = state->pop(); + int16 func = state->pop(); frame->saves.push_back(FunCall(func, rank)); } void ScriptEngine::opb7CCA(EngineState *state, EngineFrame *frame) { - word func = state->pop(); + int16 func = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].func == func) frame->saves[i].rank = 0; @@ -900,14 +900,14 @@ void ScriptEngine::opb7CCA(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opb8CLOW(EngineState *state, EngineFrame *frame) { - word hi = state->pop(); + int16 hi = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) if (frame->saves[i].rank <= hi) frame->saves[i].rank = 0; } void ScriptEngine::opb9CHI(EngineState *state, EngineFrame *frame) { - word lo = state->pop(); + int16 lo = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo) { frame->saves[i].rank = 0; @@ -916,8 +916,8 @@ void ScriptEngine::opb9CHI(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opbaCRAN(EngineState *state, EngineFrame *frame) { - word hi = state->pop(); - word lo = state->pop(); + int16 hi = state->pop(); + int16 lo = state->pop(); for (uint i = 0; i < frame->saves.size(); i++) { if (frame->saves[i].rank >= lo && frame->saves[i].rank <= hi) { @@ -944,7 +944,7 @@ bool ScriptEngine::opbbFORK(EngineState *state, EngineFrame *frame) { } bool ScriptEngine::opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script) { - word id = state->pop(); + int16 id = state->pop(); ScriptAsset newfun = ScriptAsset(id, _scripts); ScriptAsset current = script; debugC(2, kMVDebugScript, "Call function: %d", id); @@ -957,7 +957,7 @@ bool ScriptEngine::opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset } void ScriptEngine::opbdFOOB(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _engine->enqueueObject(kFocusWindow, obj); } @@ -982,7 +982,7 @@ void ScriptEngine::opc0TEXI(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opc1PTXT(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); } @@ -991,20 +991,20 @@ void ScriptEngine::opc2PNEW(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opc3PTNE(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } void ScriptEngine::opc4PNTN(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); _engine->enqueueText(kTextPlain, frame->dest, frame->src, tid); _engine->enqueueText(kTextNewLine, frame->dest, frame->src, 0); } void ScriptEngine::opc5PNUM(EngineState *state, EngineFrame *frame) { - word tid = state->pop(); + int16 tid = state->pop(); _engine->enqueueText(kTextNumber, frame->dest, frame->src, tid); } @@ -1013,12 +1013,12 @@ void ScriptEngine::opc6P2(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opc7PLBG(EngineState *state, EngineFrame *frame) { - word target = state->pop(); + int16 target = state->pop(); _engine->enqueueSound(kSoundPlay, target); } void ScriptEngine::opc8PLAW(EngineState *state, EngineFrame *frame) { - word target = state->pop(); + int16 target = state->pop(); _engine->enqueueSound(kSoundPlayAndWait, target); } @@ -1032,10 +1032,10 @@ void ScriptEngine::opcaTIME(EngineState *state, EngineFrame *frame) { } uint32 totalPlayTime = _engine->getTotalPlayTime() / 1000; // In seconds - word hours = totalPlayTime / 3600; + int16 hours = totalPlayTime / 3600; totalPlayTime %= 3600; state->push(hours); - word minutes = totalPlayTime / 60; + int16 minutes = totalPlayTime / 60; totalPlayTime %= 60; state->push(minutes); state->push(totalPlayTime); @@ -1049,7 +1049,7 @@ void ScriptEngine::opcbDAY(EngineState *state, EngineFrame *frame) { void ScriptEngine::opccCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; - word obj = state->pop(); + int16 obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); for (Common::Array::const_iterator it = children.begin(); it != children.end(); it++) { state->push(*it); @@ -1059,7 +1059,7 @@ void ScriptEngine::opccCHLD(EngineState *state, EngineFrame *frame) { void ScriptEngine::opcdNCHLD(EngineState *state, EngineFrame *frame) { bool recursive = state->pop() != 0; - word obj = state->pop(); + int16 obj = state->pop(); Common::Array children = _world->getChildren(obj, recursive); state->push(children.size()); } @@ -1077,30 +1077,30 @@ void ScriptEngine::opd0P1(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opd1GOBD(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); Common::Rect bounds = _engine->getObjBounds(obj); state->push(bounds.width()); state->push(bounds.height()); } void ScriptEngine::opd2GOVP(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); state->push(_engine->getOverlapPercent(b, a)); } void ScriptEngine::opd3CAPC(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _world->captureChildren(obj); } void ScriptEngine::opd4RELC(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _world->releaseChildren(obj); } void ScriptEngine::opd5DLOG(EngineState *state, EngineFrame *frame) { - word txt = state->pop(); + int16 txt = state->pop(); if (_engine->showTextEntry(txt, frame->src, frame->dest)) { state->push(0xFF); } else { @@ -1121,7 +1121,7 @@ void ScriptEngine::opd8WIN(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opd9SLEEP(EngineState *state, EngineFrame *frame) { - word ticks = state->pop(); + int16 ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->preparedToRun(); } @@ -1148,7 +1148,7 @@ void ScriptEngine::opdeUPSC(EngineState *state, EngineFrame *frame) { } void ScriptEngine::opdfFMAI(EngineState *state, EngineFrame *frame) { - word ticks = state->pop(); + int16 ticks = state->pop(); g_system->delayMillis((ticks / 60) * 1000); _engine->revert(); } @@ -1162,16 +1162,16 @@ void ScriptEngine::ope1CHSO(EngineState *state, EngineFrame *frame) { } void ScriptEngine::ope2MDIV(EngineState *state, EngineFrame *frame) { - word b = state->pop(); - word a = state->pop(); + int16 b = state->pop(); + int16 a = state->pop(); a *= b; - word c = state->pop(); + int16 c = state->pop(); a /= c; state->push(a | 0); } void ScriptEngine::ope3UPOB(EngineState *state, EngineFrame *frame) { - word obj = state->pop(); + int16 obj = state->pop(); _world->updateObj(obj); } @@ -1220,7 +1220,7 @@ bool ScriptAsset::hasNext() { return _ip < _instructions.size(); } -void ScriptAsset::branch(word amount) { +void ScriptAsset::branch(int16 amount) { _ip += amount; } diff --git a/engines/macventure/script.h b/engines/macventure/script.h index afeed4a848..e5ad6e5f6c 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -34,7 +34,6 @@ class Container; class World; typedef uint32 ObjID; -typedef int16 word; class ScriptAsset { public: @@ -44,7 +43,7 @@ public: void reset(); uint8 fetch(); bool hasNext(); - void branch(word amount); + void branch(int16 amount); ObjID getId(); @@ -66,22 +65,22 @@ public: clear(); } - void push(word data) { + void push(int16 data) { sp--; stack[sp] = unneg16(data); } - word pop() { - word v = stack[sp]; + int16 pop() { + int16 v = stack[sp]; sp++; return v; } - word peek(word off) { + int16 peek(int16 off) { return stack[sp + off]; } - void poke(word off, word val) { + void poke(int16 off, int16 val) { stack[sp + off] = unneg16(val); } @@ -92,12 +91,12 @@ public: } } - word size() { + int16 size() { return 0x80 - sp; } private: - word unneg16(word data) { + int16 unneg16(int16 data) { if (data < 0) data = ((-data) ^ 0xFFFF) + 1; @@ -106,15 +105,15 @@ private: private: - word stack[0x80]; - word sp; + int16 stack[0x80]; + int16 sp; }; struct FunCall { - word func; - word rank; + int16 func; + int16 rank; - FunCall(word f, word r) { + FunCall(int16 f, int16 r) { func = f; rank = r; } @@ -155,9 +154,9 @@ private: private: // Aux - word neg16(word val); - word neg8(word val); - word sumChildrenAttr(word obj, word attr, bool recursive); + int16 neg16(int16 val); + int16 neg8(int16 val); + int16 sumChildrenAttr(int16 obj, int16 attr, bool recursive); // Opcodes void op80GATT(EngineState *state, EngineFrame *frame); //get attribute -- cgit v1.2.3 From 69f2302a1adb9ead458e38a45429477eac2b6ce4 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 17 Aug 2016 17:19:05 +0200 Subject: MACVENTURE: Remove JavaScript constructs --- engines/macventure/image.cpp | 2 +- engines/macventure/macventure.cpp | 2 +- engines/macventure/script.cpp | 16 +++++++++++++--- engines/macventure/script.h | 1 + engines/macventure/sound.cpp | 15 ++++++++------- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index f0146e344a..aeb5a501a8 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -187,7 +187,7 @@ void ImageAsset::decodePPIC3(Common::BitStream &stream, Common::Array &dat v = stream.getBits(bits); while ((bits = loadBits[load++]) != 0xFF) { huff.symbols[loadBits[load++]] = v % bits; - v = (v / bits) | 0; + v = (bits != 0) ? (v / bits) : 0; } huff.symbols[loadBits[load++]] = v; } diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index e28bc4e9ba..b6fcba5d91 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -1043,7 +1043,7 @@ uint MacVentureEngine::getOverlapPercent(ObjID one, ObjID other) { oneBounds.intersects(otherBounds)) { uint areaOne = oneBounds.width() * oneBounds.height(); uint areaOther = otherBounds.width() * otherBounds.height(); - return (areaOther * 100 / areaOne) | 0; + return (areaOne != 0) ? (areaOther * 100 / areaOne) : 0; } return 0; } diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp index e18bf65979..d3731489e4 100644 --- a/engines/macventure/script.cpp +++ b/engines/macventure/script.cpp @@ -525,6 +525,13 @@ int16 ScriptEngine::sumChildrenAttr(int16 obj, int16 attr, bool recursive) { return sum; } +void ScriptEngine::ensureNonzeroDivisor(int16 divisor, byte opcode) { + // TODO Untested, since that occassion rarely comes up. + if (divisor == 0) { + error("SCRIPT: Attempt to divide by 0 in operation %x", opcode); + } +} + void MacVenture::ScriptEngine::op80GATT(EngineState *state, EngineFrame *frame) { int16 obj = state->pop(); int16 attr = state->pop(); @@ -704,7 +711,8 @@ void ScriptEngine::op9aMUL(EngineState *state, EngineFrame *frame) { void ScriptEngine::op9bDIV(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); - state->push((a / b) | 0); + ensureNonzeroDivisor(b, 0x9b); + state->push(a / b); } void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { @@ -716,8 +724,9 @@ void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) { void ScriptEngine::op9dDMOD(EngineState *state, EngineFrame *frame) { int16 b = state->pop(); int16 a = state->pop(); + ensureNonzeroDivisor(b, 0x9d); state->push(a % b); - state->push((a / b) | 0); + state->push(a / b); } void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) { @@ -1166,8 +1175,9 @@ void ScriptEngine::ope2MDIV(EngineState *state, EngineFrame *frame) { int16 a = state->pop(); a *= b; int16 c = state->pop(); + ensureNonzeroDivisor(c, 0xe2); a /= c; - state->push(a | 0); + state->push(a); } void ScriptEngine::ope3UPOB(EngineState *state, EngineFrame *frame) { diff --git a/engines/macventure/script.h b/engines/macventure/script.h index e5ad6e5f6c..0e81e41168 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -157,6 +157,7 @@ private: int16 neg16(int16 val); int16 neg8(int16 val); int16 sumChildrenAttr(int16 obj, int16 attr, bool recursive); + void ensureNonzeroDivisor(int16 divisor, byte opcode); // Opcodes void op80GATT(EngineState *state, EngineFrame *frame); //get attribute diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index fd39e2bf5e..422e365790 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -126,7 +126,7 @@ void SoundAsset::decode10(Common::SeekableReadStream *stream) { _length = stream->readUint32BE() * 2; //Unused stream->readUint16BE(); - _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + _frequency = (stream->readUint32BE() * 22100 / 0x10000); byte ch = 0; for (uint i = 0; i < _length; i++) { if (i & 1) { @@ -147,7 +147,7 @@ void SoundAsset::decode12(Common::SeekableReadStream *stream) { stream->seek(base, SEEK_SET); _length = stream->readUint32BE() - 6; stream->readUint16BE(); - _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + _frequency = (stream->readUint32BE() * 22100 / 0x10000); stream->seek(0xe2, SEEK_SET); // TODO: Possible source of bugs, the original just assigns the seek to the scales uint32 scales = stream->pos() + 0xe2; @@ -191,7 +191,8 @@ void SoundAsset::decode18(Common::SeekableReadStream *stream) { _length = stream->readUint32BE() * 2; //Unused stream->readUint16BE(); - _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + // TODO: It had `| 0` at the end of this line, possible source of bugs. + _frequency = (stream->readUint32BE() * 22100 / 0x10000); byte ch = 0; for (uint i = 0; i < _length; i++) { if (i & 1) { @@ -213,7 +214,7 @@ void SoundAsset::decode1a(Common::SeekableReadStream *stream) { _length = stream->readUint32BE(); //Unused stream->readUint16BE(); - _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + _frequency = (stream->readUint32BE() * 22100 / 0x10000); byte ch = 0; for (uint i = 0; i < _length; i++) { if (i & 1) { @@ -228,7 +229,7 @@ void SoundAsset::decode1a(Common::SeekableReadStream *stream) { void SoundAsset::decode44(Common::SeekableReadStream *stream) { stream->seek(0x5e, SEEK_SET); _length = stream->readUint32BE(); - _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + _frequency = (stream->readUint32BE() * 22100 / 0x10000); for (uint i = 0; i < _length; i++) { _data.push_back(stream->readByte()); } @@ -243,7 +244,7 @@ void SoundAsset::decode78(Common::SeekableReadStream *stream) { //Unused stream->readUint32BE(); _length = stream->readUint32BE(); - _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + _frequency = (stream->readUint32BE() * 22100 / 0x10000); byte ch = 0; for (uint i = 0; i < _length; i++) { if (i & 1) { @@ -264,7 +265,7 @@ void SoundAsset::decode7e(Common::SeekableReadStream *stream) { //Unused stream->readUint32BE(); _length = stream->readUint32BE(); - _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0; + _frequency = (stream->readUint32BE() * 22100 / 0x10000); uint32 last = 0x80; byte ch = 0; for (uint i = 0; i < _length; i++) { -- cgit v1.2.3 From ccd5ad5162652dd3bcc06136ed1917b9f0f0b2ac Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 19 Aug 2016 15:09:07 +0200 Subject: MACVENTURE: Fix double overflow when blitting --- engines/macventure/image.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp index aeb5a501a8..172121af0b 100644 --- a/engines/macventure/image.cpp +++ b/engines/macventure/image.cpp @@ -530,27 +530,24 @@ void ImageAsset::calculateSectionToDraw(Graphics::ManagedSurface *target, int &o } void ImageAsset::calculateSectionInDirection(uint targetWhole, uint originWhole, int &originPosition, uint &startPosition, uint &blittedWhole) { + startPosition = 0; blittedWhole = originWhole; - if (originPosition + blittedWhole > targetWhole) { - if (originPosition > (int)targetWhole) { - blittedWhole = 0; - } else { - blittedWhole = (blittedWhole) - ((blittedWhole + originPosition) - targetWhole); - } - } if (originPosition < 0) { if (ABS(originPosition) > (int)blittedWhole) { blittedWhole = 0; } else { blittedWhole -= -originPosition; } - } - - startPosition = 0; - if (originPosition < 0) { startPosition = -originPosition; originPosition = 0; } + if (originPosition + blittedWhole > targetWhole) { + if (originPosition > (int)targetWhole) { + blittedWhole = 0; + } else { + blittedWhole = targetWhole - originPosition; + } + } } } // End of namespace MacVenture -- cgit v1.2.3 From b884e6e29f26018f01cbaec5731e7a06f0b10d6e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 19 Aug 2016 16:41:25 +0200 Subject: MACVENTURE: Fix game file path retrieval --- engines/macventure/macventure.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index b6fcba5d91..826409f30b 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -955,11 +955,10 @@ Common::String MacVentureEngine::getCommandsPausedString() const { } Common::String MacVentureEngine::getFilePath(FilePathID id) const { - const Common::Array &names = _filenames->getStrings(); if (id <= 3) { // We don't want a file in the subdirectory - return Common::String(names[id]); + return _filenames->getString(id); } else { // We want a game file - return Common::String(names[3] + "/" + names[id]); + return _filenames->getString(3) + "/" + _filenames->getString(id); } } -- cgit v1.2.3 From d1ce6793fa7f46935709d4bf7f84d0b13c535193 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 19 Aug 2016 16:56:44 +0200 Subject: MACVENTURE: Add static array for border names --- engines/macventure/datafiles.cpp | 55 ++++++++++++++++++++-------------------- engines/macventure/windows.h | 3 ++- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp index aa47869bcd..d41aa99d4c 100644 --- a/engines/macventure/datafiles.cpp +++ b/engines/macventure/datafiles.cpp @@ -32,34 +32,35 @@ namespace MacVenture { #define MACVENTURE_DATA_BUNDLE Common::String("macventure.zip") +struct BorderName { + MVWindowType type; + const char *name; +}; + +static const BorderName g_borderNames[] = { + {kDocument, "Document"}, + {kDBox, "DBox"}, + {kPlainDBox, "PlainDBox"}, + {kAltBox, "AltBox"}, + {kNoGrowDoc, "NoGrowDoc"}, + {kMovableDBox, "MovableDBox"}, + {kZoomDoc, "ZoomDoc"}, + {kZoomNoGrow, "ZoomNoGrow"}, + {kInvWindow, "InvWindow"}, + {kRDoc16, "RDoc16"}, + {kRDoc4, "RDoc4"}, + {kRDoc6, "RDoc6"}, + {kRDoc10, "RDoc10"}, + {kNoType, "No type"} +}; + Common::String windowTypeName(MVWindowType windowType) { - switch (windowType) { - case kDocument: - return "Document"; - case kDBox: - return "DBox"; - case kPlainDBox: - return "PlainDBox"; - case kAltBox: - return "AltBox"; - case kNoGrowDoc: - return "NoGrowDoc"; - case kMovableDBox: - return "MovableDBox"; - case kZoomDoc: - return "ZoomDoc"; - case kZoomNoGrow: - return "ZoomNoGrow"; - case kInvWindow: - return "InvWindow"; - case kRDoc16: - return "RDoc16"; - case kRDoc4: - return "RDoc4"; - case kRDoc6: - return "RDoc6"; - case kRDoc10: - return "RDoc10"; + int i = 0; + while (g_borderNames[i].type != kNoType) { + i++; + if (g_borderNames[i].type == windowType) { + return g_borderNames[i].name; + } } return ""; } diff --git a/engines/macventure/windows.h b/engines/macventure/windows.h index 1727698ad4..fd3acefa7b 100644 --- a/engines/macventure/windows.h +++ b/engines/macventure/windows.h @@ -55,7 +55,8 @@ enum MVWindowType { kRDoc16 = 0x10, kRDoc4 = 0x12, kRDoc6 = 0x14, - kRDoc10 = 0x16 + kRDoc10 = 0x16, + kNoType = 0xFF }; struct DrawableObject { -- cgit v1.2.3 From 059c9a64d9505901a0c150e55af3c2ded372a214 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 19 Aug 2016 17:02:48 +0200 Subject: MACVENTURE: Substitute charcodes with char constants --- engines/macventure/text.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/macventure/text.cpp b/engines/macventure/text.cpp index 46a54bd4ab..6671c28750 100644 --- a/engines/macventure/text.cpp +++ b/engines/macventure/text.cpp @@ -66,9 +66,9 @@ void TextAsset::decodeOld() { lowercase = true; } else if (val == 0x1C) { if (lowercase) { - c = 0x27; // Ascii ' + c = '\''; } else { - c = 0x22; // Ascii '"' + c = '"'; } lowercase = true; } else if (val == 0x1D) { // Composite -- cgit v1.2.3 From 1210f05842b927ef07b4817552002b97cdd6906e Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 21 Aug 2016 13:19:08 +0200 Subject: MACVENTURE: Fix upper limit in savefile names --- engines/macventure/saveload.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index e5cc9b6fa5..1b56980ecd 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -63,8 +63,8 @@ SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { } void writeMetaData(Common::OutSaveFile *file, Common::String desc) { - if (desc.size() >= (1 << (MACVENTURE_DESC_LENGTH * 4))) { - desc.erase((1 << (MACVENTURE_DESC_LENGTH * 4)) - 1); + if (desc.size() >= (1 << (MACVENTURE_DESC_LENGTH * 8))) { + desc.erase((1 << (MACVENTURE_DESC_LENGTH * 8)) - 1); } file->writeString(desc); file->writeUint32BE(MACVENTURE_SAVE_HEADER); @@ -121,8 +121,8 @@ bool MacVentureEngine::scummVMSaveLoadDialog(bool isSave) { desc = dialog.createDefaultSaveDescription(slot); } - if (desc.size() > (1 << MACVENTURE_DESC_LENGTH * 4) - 1) - desc = Common::String(desc.c_str(), (1 << MACVENTURE_DESC_LENGTH * 4) - 1); + if (desc.size() > (1 << MACVENTURE_DESC_LENGTH * 8) - 1) + desc = Common::String(desc.c_str(), (1 << MACVENTURE_DESC_LENGTH * 8) - 1); if (slot < 0) return true; -- cgit v1.2.3 From 0d868742d4016f8f50a8135c20115d911d920cf5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 21 Aug 2016 16:19:55 +0200 Subject: MACVENTURE: Add thumbnail to savegames --- engines/macventure/detection.cpp | 29 ++++++++++++++++++++++++++++- engines/macventure/saveload.cpp | 34 +++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 2b161142c4..801cc599cd 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -75,13 +75,16 @@ public: virtual SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; virtual void removeSaveState(const char *target, int slot) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; }; bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { return (f == kSupportsListSaves) || (f == kSupportsLoadingDuringStartup) || - (f == kSupportsDeleteSave); + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail); } bool MacVentureEngine::hasFeature(EngineFeature f) const { @@ -141,6 +144,30 @@ void MacVentureMetaEngine::removeSaveState(const char *target, int slot) const { g_system->getSavefileManager()->removeSavefile(Common::String::format("%s.%03d", target, slot)); } + +SaveStateDescriptor MacVentureMetaEngine::querySaveMetaInfos(const char *target, int slot) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + SaveStateDescriptor desc; + Common::String saveFileName; + Common::String pattern = target; + pattern += ".###"; + Common::StringArray filenames = saveFileMan->listSavefiles(pattern); + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + int slotNum = atoi(file->c_str() + file->size() - 3); + if (slotNum == slot) { + saveFileName = *file; + } + } + + Common::InSaveFile *in = saveFileMan->openForLoading(saveFileName); + if (in) { + desc = loadMetaData(in, slot); + delete in; + return desc; + } + return SaveStateDescriptor(-1, ""); +} + } // End of namespace MacVenture #if PLUGIN_ENABLED_DYNAMIC(MACVENTURE) diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index 1b56980ecd..a1a5e3c244 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -26,16 +26,19 @@ #include "common/savefile.h" #include "engines/savestate.h" #include "gui/saveload.h" +#include "graphics/thumbnail.h" namespace MacVenture { #define MACVENTURE_SAVE_HEADER MKTAG('M', 'V', 'S', 'S') // (M)ac(V)enture (S)cummVM (S)ave (0x4d565353, uint32) #define MACVENTURE_SAVE_VERSION 1 //1 BYTE -#define MACVENTURE_DESC_LENGTH 1 //1 BYTE for the description length +#define MACVENTURE_DESC_LENGTH 4 //4 BYTE for the metadata length SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { // Metadata is stored at the end of the file - // |DESCRIPTION | + // |THUMBNAIL | + // | | + // |DESCSIZE| DESCRIPTION | // |HEADER |VERSION|DESCLEN| s->seek(-(5 + MACVENTURE_DESC_LENGTH), SEEK_END); uint32 sig = s->readUint32BE(); @@ -49,12 +52,18 @@ SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { // Save is valid, set its slot number desc.setSaveSlot(slot); + // Depends on MACVENTURE_DESC_LENGTH + uint32 metaSize = s->readUint32BE(); + s->seek(-(5 + MACVENTURE_DESC_LENGTH + metaSize), SEEK_END); + + // Load the thumbnail + Graphics::Surface *thumb = Graphics::loadThumbnail(*s); + desc.setThumbnail(thumb); + // Load the description Common::String name; - // Depends on MACVENTURE_DESC_LENGTH - byte descSize = s->readByte(); - s->seek(-(5 + MACVENTURE_DESC_LENGTH + descSize), SEEK_END); - for (int i = 0; i < descSize; ++i) { + uint32 descSize = s->readUint32BE(); + for (uint32 i = 0; i < descSize; ++i) { name += s->readByte(); } desc.setDescription(name); @@ -63,13 +72,15 @@ SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { } void writeMetaData(Common::OutSaveFile *file, Common::String desc) { - if (desc.size() >= (1 << (MACVENTURE_DESC_LENGTH * 8))) { - desc.erase((1 << (MACVENTURE_DESC_LENGTH * 8)) - 1); - } + uint thumbSize = file->pos(); + Graphics::saveThumbnail(*file); + thumbSize = file->pos() - thumbSize; + + file->writeUint32BE(desc.size()); file->writeString(desc); file->writeUint32BE(MACVENTURE_SAVE_HEADER); file->writeByte(MACVENTURE_SAVE_VERSION); - file->writeByte(desc.size()); + file->writeUint32BE(4 + desc.size() + thumbSize); } Common::Error MacVentureEngine::loadGameState(int slot) { @@ -121,9 +132,10 @@ bool MacVentureEngine::scummVMSaveLoadDialog(bool isSave) { desc = dialog.createDefaultSaveDescription(slot); } + /* if (desc.size() > (1 << MACVENTURE_DESC_LENGTH * 8) - 1) desc = Common::String(desc.c_str(), (1 << MACVENTURE_DESC_LENGTH * 8) - 1); - + */ if (slot < 0) return true; -- cgit v1.2.3 From b7b258474f0a135f626ec3d46d19b4f54926f50f Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 21 Aug 2016 16:42:19 +0200 Subject: MACVENTURE: Add creation date and playtime to savegames --- engines/macventure/detection.cpp | 4 +++- engines/macventure/saveload.cpp | 46 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 801cc599cd..10676d5b25 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -84,7 +84,9 @@ bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { (f == kSupportsLoadingDuringStartup) || (f == kSupportsDeleteSave) || (f == kSavesSupportMetaInfo) || - (f == kSavesSupportThumbnail); + (f == kSavesSupportThumbnail) || + (f == kSavesSupportCreationDate) || + (f == kSavesSupportPlayTime); } bool MacVentureEngine::hasFeature(EngineFeature f) const { diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index a1a5e3c244..53736302d2 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -68,19 +68,63 @@ SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { } desc.setDescription(name); + // Load date + uint32 saveDate = s->readUint32LE(); + int day = (saveDate >> 24) & 0xFF; + int month = (saveDate >> 16) & 0xFF; + int year = saveDate & 0xFFFF; + desc.setSaveDate(year, month, day); + + uint16 saveTime = s->readUint16LE(); + int hour = (saveTime >> 8) & 0xFF; + int minutes = saveTime & 0xFF; + desc.setSaveTime(hour, minutes); + + // Load playtime + uint32 playTime = s->readUint32LE(); + desc.setPlayTime(playTime * 1000); + return desc; } +uint saveCurrentDate(Common::OutSaveFile *file) { + TimeDate curTime; + g_system->getTimeAndDate(curTime); + + uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); + uint16 saveTime = ((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF); + + file->writeUint32LE(saveDate); + file->writeUint16LE(saveTime); + + // Return the number of bytes occupied + return 6; +} + +uint savePlayTime(Common::OutSaveFile *file) { + uint32 playTime = g_engine->getTotalPlayTime() / 1000; + file->writeUint32LE(playTime); + // Return the number of bytes occupied + return 4; +} + void writeMetaData(Common::OutSaveFile *file, Common::String desc) { + + // Write thumbnail uint thumbSize = file->pos(); Graphics::saveThumbnail(*file); thumbSize = file->pos() - thumbSize; + // Write description file->writeUint32BE(desc.size()); file->writeString(desc); + + uint dateSize = saveCurrentDate(file); + uint playTimeSize = savePlayTime(file); + file->writeUint32BE(MACVENTURE_SAVE_HEADER); file->writeByte(MACVENTURE_SAVE_VERSION); - file->writeUint32BE(4 + desc.size() + thumbSize); + file->writeUint32BE(4 + desc.size() + dateSize + playTimeSize + thumbSize); } Common::Error MacVentureEngine::loadGameState(int slot) { -- cgit v1.2.3 From 841c22704c33057a292a1b0d44ba104d77dd8c18 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 24 Aug 2016 11:43:58 +0200 Subject: MACVENTURE: Include border bitmaps in ScummVM --- Makefile.common | 3 +++ devtools/create_macventure/AltBox_act.bmp | Bin 0 -> 822 bytes devtools/create_macventure/AltBox_inac.bmp | Bin 0 -> 822 bytes devtools/create_macventure/InvWindow_act.bmp | Bin 0 -> 16686 bytes devtools/create_macventure/InvWindow_inac.bmp | Bin 0 -> 8414 bytes devtools/create_macventure/NoGrowDoc_act.bmp | Bin 0 -> 8622 bytes devtools/create_macventure/NoGrowDoc_inac.bmp | Bin 0 -> 8622 bytes devtools/create_macventure/PlainDBox_act.bmp | Bin 0 -> 6966 bytes devtools/create_macventure/PlainDBox_inac.bmp | Bin 0 -> 6966 bytes devtools/create_macventure/RDoc4_act.bmp | Bin 0 -> 8694 bytes devtools/create_macventure/RDoc4_inac.bmp | Bin 0 -> 8694 bytes devtools/create_macventure/ZoomDoc_act.bmp | Bin 0 -> 11302 bytes devtools/create_macventure/ZoomDoc_inac.bmp | Bin 0 -> 8622 bytes devtools/create_macventure/create_macventure.sh | 8 ++++++++ engines/macventure/datafiles.cpp | 2 +- 15 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 devtools/create_macventure/AltBox_act.bmp create mode 100644 devtools/create_macventure/AltBox_inac.bmp create mode 100644 devtools/create_macventure/InvWindow_act.bmp create mode 100644 devtools/create_macventure/InvWindow_inac.bmp create mode 100644 devtools/create_macventure/NoGrowDoc_act.bmp create mode 100644 devtools/create_macventure/NoGrowDoc_inac.bmp create mode 100644 devtools/create_macventure/PlainDBox_act.bmp create mode 100644 devtools/create_macventure/PlainDBox_inac.bmp create mode 100644 devtools/create_macventure/RDoc4_act.bmp create mode 100644 devtools/create_macventure/RDoc4_inac.bmp create mode 100644 devtools/create_macventure/ZoomDoc_act.bmp create mode 100644 devtools/create_macventure/ZoomDoc_inac.bmp create mode 100755 devtools/create_macventure/create_macventure.sh diff --git a/Makefile.common b/Makefile.common index df24d397de..762b9051d0 100644 --- a/Makefile.common +++ b/Makefile.common @@ -285,6 +285,9 @@ endif ifdef ENABLE_WINTERMUTE DIST_FILES_ENGINEDATA+=wintermute.zip endif +ifdef ENABLE_MACVENTURE +DIST_FILES_ENGINEDATA+=macventure.dat +endif DIST_FILES_ENGINEDATA:=$(addprefix $(srcdir)/dists/engine-data/,$(DIST_FILES_ENGINEDATA)) # pred.dic is currently only used for the AGI engine diff --git a/devtools/create_macventure/AltBox_act.bmp b/devtools/create_macventure/AltBox_act.bmp new file mode 100644 index 0000000000..aa9fa7e841 Binary files /dev/null and b/devtools/create_macventure/AltBox_act.bmp differ diff --git a/devtools/create_macventure/AltBox_inac.bmp b/devtools/create_macventure/AltBox_inac.bmp new file mode 100644 index 0000000000..aa9fa7e841 Binary files /dev/null and b/devtools/create_macventure/AltBox_inac.bmp differ diff --git a/devtools/create_macventure/InvWindow_act.bmp b/devtools/create_macventure/InvWindow_act.bmp new file mode 100644 index 0000000000..a38b0a9834 Binary files /dev/null and b/devtools/create_macventure/InvWindow_act.bmp differ diff --git a/devtools/create_macventure/InvWindow_inac.bmp b/devtools/create_macventure/InvWindow_inac.bmp new file mode 100644 index 0000000000..f3f2cfaa8b Binary files /dev/null and b/devtools/create_macventure/InvWindow_inac.bmp differ diff --git a/devtools/create_macventure/NoGrowDoc_act.bmp b/devtools/create_macventure/NoGrowDoc_act.bmp new file mode 100644 index 0000000000..3570e798d9 Binary files /dev/null and b/devtools/create_macventure/NoGrowDoc_act.bmp differ diff --git a/devtools/create_macventure/NoGrowDoc_inac.bmp b/devtools/create_macventure/NoGrowDoc_inac.bmp new file mode 100644 index 0000000000..f3f97652e5 Binary files /dev/null and b/devtools/create_macventure/NoGrowDoc_inac.bmp differ diff --git a/devtools/create_macventure/PlainDBox_act.bmp b/devtools/create_macventure/PlainDBox_act.bmp new file mode 100644 index 0000000000..6521080588 Binary files /dev/null and b/devtools/create_macventure/PlainDBox_act.bmp differ diff --git a/devtools/create_macventure/PlainDBox_inac.bmp b/devtools/create_macventure/PlainDBox_inac.bmp new file mode 100644 index 0000000000..6521080588 Binary files /dev/null and b/devtools/create_macventure/PlainDBox_inac.bmp differ diff --git a/devtools/create_macventure/RDoc4_act.bmp b/devtools/create_macventure/RDoc4_act.bmp new file mode 100644 index 0000000000..ab78661359 Binary files /dev/null and b/devtools/create_macventure/RDoc4_act.bmp differ diff --git a/devtools/create_macventure/RDoc4_inac.bmp b/devtools/create_macventure/RDoc4_inac.bmp new file mode 100644 index 0000000000..ab78661359 Binary files /dev/null and b/devtools/create_macventure/RDoc4_inac.bmp differ diff --git a/devtools/create_macventure/ZoomDoc_act.bmp b/devtools/create_macventure/ZoomDoc_act.bmp new file mode 100644 index 0000000000..b2ccc9c602 Binary files /dev/null and b/devtools/create_macventure/ZoomDoc_act.bmp differ diff --git a/devtools/create_macventure/ZoomDoc_inac.bmp b/devtools/create_macventure/ZoomDoc_inac.bmp new file mode 100644 index 0000000000..963949b392 Binary files /dev/null and b/devtools/create_macventure/ZoomDoc_inac.bmp differ diff --git a/devtools/create_macventure/create_macventure.sh b/devtools/create_macventure/create_macventure.sh new file mode 100755 index 0000000000..1408179039 --- /dev/null +++ b/devtools/create_macventure/create_macventure.sh @@ -0,0 +1,8 @@ +printf "Creating border file...\n" + +zip -r macventure.zip *.bmp +mv macventure.zip macventure.dat + +echo done + +ls -l macventure.dat diff --git a/engines/macventure/datafiles.cpp b/engines/macventure/datafiles.cpp index d41aa99d4c..2c17b66209 100644 --- a/engines/macventure/datafiles.cpp +++ b/engines/macventure/datafiles.cpp @@ -30,7 +30,7 @@ namespace MacVenture { -#define MACVENTURE_DATA_BUNDLE Common::String("macventure.zip") +#define MACVENTURE_DATA_BUNDLE Common::String("macventure.dat") struct BorderName { MVWindowType type; -- cgit v1.2.3 From e15e6dcfb35a164567165685d79e891b48e8d73a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 22 Aug 2016 16:58:20 +0200 Subject: MACVENTURE: Fix menu flags and add newgame --- engines/macventure/gui.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 27454054d5..4084a89b52 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -78,15 +78,15 @@ static const Graphics::MenuData menuSubItems[] = { { kMenuFile, NULL, 0, 0, false }, { kMenuFile, "Quit", kMenuActionQuit, 0, true }, - { kMenuEdit, "Undo", kMenuActionUndo, 'Z', true }, + { kMenuEdit, "Undo", kMenuActionUndo, 'Z', false }, { kMenuEdit, NULL, 0, 0, false }, - { kMenuEdit, "Cut", kMenuActionCut, 'K', true }, - { kMenuEdit, "Copy", kMenuActionCopy, 'C', true }, - { kMenuEdit, "Paste", kMenuActionPaste, 'V', true }, - { kMenuEdit, "Clear", kMenuActionClear, 'B', true }, + { kMenuEdit, "Cut", kMenuActionCut, 'K', false }, + { kMenuEdit, "Copy", kMenuActionCopy, 'C', false }, + { kMenuEdit, "Paste", kMenuActionPaste, 'V', false }, + { kMenuEdit, "Clear", kMenuActionClear, 'B', false }, - { kMenuSpecial, "Clean Up", kMenuActionCleanUp, 0, true }, - { kMenuSpecial, "Mess Up", kMenuActionMessUp, 0, true }, + { kMenuSpecial, "Clean Up", kMenuActionCleanUp, 0, false }, + { kMenuSpecial, "Mess Up", kMenuActionMessUp, 0, false }, { 0, NULL, 0, 0, false } }; @@ -1142,7 +1142,7 @@ void Gui::handleMenuAction(MenuAction action) { warning("Unimplemented MacVenture Menu Action: About"); break; case MacVenture::kMenuActionNew: - warning("Unimplemented MacVenture Menu Action: New"); + _engine->newGame(); break; case MacVenture::kMenuActionOpen: loadGame(); -- cgit v1.2.3 From 31e1e02ad6f589d927c361026722cfaf7ac74d94 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Mon, 22 Aug 2016 17:03:29 +0200 Subject: MACVENTURE: Fix window initialization --- engines/macventure/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 4084a89b52..dff41b3c23 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -218,7 +218,7 @@ void Gui::initWindows() { loadBorders(_controlsWindow, findWindowData(kCommandsWindow).type); // Main Game Window - _mainGameWindow = _wm.addWindow(true, true, true); + _mainGameWindow = _wm.addWindow(false, false, false); _mainGameWindow->setDimensions(getWindowData(kMainGameWindow).bounds); _mainGameWindow->setActive(false); _mainGameWindow->setCallback(mainGameWindowCallback, this); -- cgit v1.2.3