From 2141c99b59945401508628bd2701beb08aeb7cf5 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Apr 2014 16:55:41 +0200 Subject: CGE2: Initial commit, implement detection. --- engines/cge2/cge2.cpp | 60 +++++++++++++++++++++++++++++++ engines/cge2/cge2.h | 47 +++++++++++++++++++++++++ engines/cge2/configure.engine | 3 ++ engines/cge2/detection.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++ engines/cge2/module.mk | 13 +++++++ 5 files changed, 205 insertions(+) create mode 100644 engines/cge2/cge2.cpp create mode 100644 engines/cge2/cge2.h create mode 100644 engines/cge2/configure.engine create mode 100644 engines/cge2/detection.cpp create mode 100644 engines/cge2/module.mk (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp new file mode 100644 index 0000000000..488076f3f5 --- /dev/null +++ b/engines/cge2/cge2.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 "cge2/cge2.h" + +namespace CGE2 { + +CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) + : Engine(syst), _gameDescription(gameDescription) { +} + +CGE2Engine::~CGE2Engine() { +} + +bool CGE2Engine::hasFeature(EngineFeature f) const { + return false; +} + +bool CGE2Engine::canLoadGameStateCurrently() { + return false; +} +bool CGE2Engine::canSaveGameStateCurrently() { + return false; +} + +Common::Error CGE2Engine::loadGameState(int slot) { + warning("STUB: CGE2Engine::loadGameState()"); + return Common::kNoError; +} + +Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { + warning("STUB: CGE2Engine::saveGameState()"); + return Common::kNoError; +} + +Common::Error CGE2Engine::run() { + warning("STUB: CGE2Engine::run()"); + return Common::kNoError; +} + +} // End of namespace CGE2 diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h new file mode 100644 index 0000000000..46aa4a3a21 --- /dev/null +++ b/engines/cge2/cge2.h @@ -0,0 +1,47 @@ +/* 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 CGE2_H +#define CGE2_H + +#include "engines/engine.h" +#include "engines/advancedDetector.h" + +namespace CGE2 { + +class CGE2Engine : public Engine { +public: + CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); + ~CGE2Engine(); + virtual bool hasFeature(EngineFeature f) const; + virtual bool canLoadGameStateCurrently(); + virtual bool canSaveGameStateCurrently(); + virtual Common::Error loadGameState(int slot); + virtual Common::Error saveGameState(int slot, const Common::String &desc); + virtual Common::Error run(); + + const ADGameDescription *_gameDescription; +}; + +} // End of namespace CGE2 + +#endif // CGE2_H diff --git a/engines/cge2/configure.engine b/engines/cge2/configure.engine new file mode 100644 index 0000000000..6ccbfee088 --- /dev/null +++ b/engines/cge2/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 cge2 "CGE2" no diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp new file mode 100644 index 0000000000..96ec1ed731 --- /dev/null +++ b/engines/cge2/detection.cpp @@ -0,0 +1,82 @@ +/* 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 "cge2/cge2.h" +#include "engines/advancedDetector.h" + +namespace CGE2 { + +static const PlainGameDescriptor CGE2Games[] = { + { "sfinx2", "Sfinx" }, // TODO: Remove Sfinx from CGE1 completely, so the two gameIDs won't collide. + { 0, 0 } +}; + +static const ADGameDescription gameDescriptions[] = { // TODO: Add ENG version too. + { + "sfinx", "Sfinx Freeware", + { + { "vol.cat", 0, "21197b287d397c53261b6616bf0dd880", 129024 }, + { "vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844 }, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() + }, + + AD_TABLE_END_MARKER +}; + +class CGE2MetaEngine : public AdvancedMetaEngine { +public: + CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games) { + _singleid = "sfinx"; + } + + virtual const char *getName() const { + return "CGE2"; + } + + virtual const char *getOriginalCopyright() const { + return "Sfinx (c) 1997 L.K. Avalon"; + } + + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual bool hasFeature(MetaEngineFeature f) const; +}; + +bool CGE2MetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + if (desc) { + *engine = new CGE2::CGE2Engine(syst, desc); + } + return desc != 0; +} + +bool CGE2MetaEngine::hasFeature(MetaEngineFeature f) const { + return false; +} + +} // End of namespace CGE2 + +#if PLUGIN_ENABLED_DYNAMIC(CGE2) + REGISTER_PLUGIN_DYNAMIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); +#else + REGISTER_PLUGIN_STATIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); +#endif diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk new file mode 100644 index 0000000000..75f2743286 --- /dev/null +++ b/engines/cge2/module.mk @@ -0,0 +1,13 @@ +MODULE := engines/cge2 + +MODULE_OBJS = \ + cge2.o \ + detection.o + +# This module can be built as a plugin +ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) +PLUGIN := 1 +endif + +# Include common rules +include $(srcdir)/rules.mk -- cgit v1.2.3 From b429e746a7ba8f745225952b8a632c5cd9b2f8f0 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Apr 2014 17:34:38 +0200 Subject: CGE2: Remove detection of Sfinx from CGE1. --- engines/cge/cge.h | 6 --- engines/cge/detection.cpp | 113 +++++++++++++++------------------------------ engines/cge2/detection.cpp | 2 +- 3 files changed, 39 insertions(+), 82 deletions(-) (limited to 'engines') diff --git a/engines/cge/cge.h b/engines/cge/cge.h index a65069ff46..c43358f252 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -80,12 +80,6 @@ class Talk; #define kSayTheEnd 41 -enum GameType { - kGameTypeNone = 0, - kGameTypeSoltys, - kGameTypeSfinx -}; - // our engine debug channels enum { kCGEDebugBitmap = 1 << 0, diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 4c2f81c1ae..60558f147e 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -33,7 +33,6 @@ namespace CGE { struct CgeGameDescription { ADGameDescription desc; - GameType gameType; }; #define GAMEOPTION_COLOR_BLIND_DEFAULT_OFF GUIO_GAMEOPTIONS1 @@ -42,117 +41,81 @@ struct CgeGameDescription { static const PlainGameDescriptor CGEGames[] = { { "soltys", "Soltys" }, - { "sfinx", "Sfinx" }, { 0, 0 } }; namespace CGE { -static const CgeGameDescription gameDescriptions[] = { - - { - { - "soltys", "", - { - {"vol.cat", 0, "0c33e2c304821a2444d297fc5e2d67c6", 50176}, - {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437572}, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() - }, - kGameTypeSoltys - }, +static const ADGameDescription gameDescriptions[] = { { + "soltys", "", { - "soltys", "Soltys Freeware", - { - {"vol.cat", 0, "0c33e2c304821a2444d297fc5e2d67c6", 50176}, - {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437676}, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + {"vol.cat", 0, "0c33e2c304821a2444d297fc5e2d67c6", 50176}, + {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437572}, + AD_LISTEND }, - kGameTypeSoltys + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() }, { + "soltys", "Soltys Freeware", { - "soltys", "Soltys Demo (not supported)", - { - {"vol.cat", 0, "1e077c8ff58109a187f07ac54b0c873a", 18788}, - {"vol.dat", 0, "75d385a6074c58b69f7730481f256051", 1796710}, - AD_LISTEND - }, - Common::EN_ANY, Common::kPlatformDOS, ADGF_DEMO , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + {"vol.cat", 0, "0c33e2c304821a2444d297fc5e2d67c6", 50176}, + {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437676}, + AD_LISTEND }, - kGameTypeSoltys + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, { + "soltys", "Soltys Demo (not supported)", { - "soltys", "Soltys Demo (not supported)", - { - {"vol.cat", 0, "f17987487fab1ebddd781d8d02fedecc", 7168}, - {"vol.dat", 0, "c5d9b15863cab61dc125551576dece04", 1075272}, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformDOS, ADGF_DEMO , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + {"vol.cat", 0, "1e077c8ff58109a187f07ac54b0c873a", 18788}, + {"vol.dat", 0, "75d385a6074c58b69f7730481f256051", 1796710}, + AD_LISTEND }, - kGameTypeSoltys + Common::EN_ANY, Common::kPlatformDOS, ADGF_DEMO , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, { + "soltys", "Soltys Demo (not supported)", { - "soltys", "Soltys Freeware v1.0", - { - {"vol.cat", 0, "f1675684c68ab90272f5776f8f2c3974", 50176}, - {"vol.dat", 0, "4ffeff4abc99ac5999b55ccfc56ab1df", 8430868}, - AD_LISTEND - }, - Common::EN_ANY, Common::kPlatformDOS, ADGF_NO_FLAGS , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + {"vol.cat", 0, "f17987487fab1ebddd781d8d02fedecc", 7168}, + {"vol.dat", 0, "c5d9b15863cab61dc125551576dece04", 1075272}, + AD_LISTEND }, - kGameTypeSoltys + Common::PL_POL, Common::kPlatformDOS, ADGF_DEMO , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, { + "soltys", "Soltys Freeware v1.0", { - "soltys", "Soltys Freeware v1.0", - { - {"vol.cat", 0, "20fdce799adb618100ef9ee2362be875", 50176}, - {"vol.dat", 0, "0e43331c846094d77f5dd201827e0a3b", 8439339}, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + {"vol.cat", 0, "f1675684c68ab90272f5776f8f2c3974", 50176}, + {"vol.dat", 0, "4ffeff4abc99ac5999b55ccfc56ab1df", 8430868}, + AD_LISTEND }, - kGameTypeSoltys + Common::EN_ANY, Common::kPlatformDOS, ADGF_NO_FLAGS , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, { + "soltys", "Soltys Freeware v1.0", { - "soltys", "Soltys Freeware v1.0", - { - {"vol.cat", 0, "fcae86b20eaa5cedec17b24fa5e85eb4", 50176}, - {"vol.dat", 0, "ff10d54acc2c95696c57e05819b6906f", 8450151}, - AD_LISTEND - }, - Common::ES_ESP, Common::kPlatformDOS, ADGF_NO_FLAGS , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + {"vol.cat", 0, "20fdce799adb618100ef9ee2362be875", 50176}, + {"vol.dat", 0, "0e43331c846094d77f5dd201827e0a3b", 8439339}, + AD_LISTEND }, - kGameTypeSoltys + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, { + "soltys", "Soltys Freeware v1.0", { - // Polish version, provided by Strangerke - "sfinx", "Sfinx Freeware", - { - {"vol.cat", 0, "21197b287d397c53261b6616bf0dd880", 129024}, - {"vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844}, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + {"vol.cat", 0, "fcae86b20eaa5cedec17b24fa5e85eb4", 50176}, + {"vol.dat", 0, "ff10d54acc2c95696c57e05819b6906f", 8450151}, + AD_LISTEND }, - kGameTypeSfinx + Common::ES_ESP, Common::kPlatformDOS, ADGF_NO_FLAGS , GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, - {AD_TABLE_END_MARKER, kGameTypeNone} + AD_TABLE_END_MARKER }; static const ADFileBasedFallback fileBasedFallback[] = { - { &gameDescriptions[0].desc, { "vol.cat", "vol.dat", 0 } }, + { &gameDescriptions[0], { "vol.cat", "vol.dat", 0 } }, { 0, { 0 } } }; } // End of namespace CGE diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 96ec1ed731..12430780b1 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -26,7 +26,7 @@ namespace CGE2 { static const PlainGameDescriptor CGE2Games[] = { - { "sfinx2", "Sfinx" }, // TODO: Remove Sfinx from CGE1 completely, so the two gameIDs won't collide. + { "sfinx", "Sfinx" }, { 0, 0 } }; -- cgit v1.2.3 From aad77304a8727ba1d2a1b802a95c7f8085d50853 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Apr 2014 20:11:32 +0200 Subject: CGE2: Add copyright comments to the source files. --- engines/cge2/cge2.cpp | 5 +++++ engines/cge2/cge2.h | 5 +++++ engines/cge2/detection.cpp | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 488076f3f5..0b06cd0fb4 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -20,6 +20,11 @@ * */ +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + #include "cge2/cge2.h" namespace CGE2 { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 46aa4a3a21..ee4ecf62b1 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -20,6 +20,11 @@ * */ +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef CGE2_H #define CGE2_H diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 12430780b1..9c63af1ec6 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -20,6 +20,11 @@ * */ +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + #include "cge2/cge2.h" #include "engines/advancedDetector.h" @@ -55,7 +60,7 @@ public: } virtual const char *getOriginalCopyright() const { - return "Sfinx (c) 1997 L.K. Avalon"; + return "Sfinx (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon"; } virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; -- cgit v1.2.3 From b58965e4e62259fc000dd731f694a24244268983 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 26 Apr 2014 08:02:00 +0200 Subject: CGE2: Add file I/O. --- engines/cge2/cge2.cpp | 6 ++ engines/cge2/cge2.h | 5 + engines/cge2/fileio.cpp | 247 ++++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/fileio.h | 120 +++++++++++++++++++++++ engines/cge2/module.mk | 3 +- 5 files changed, 380 insertions(+), 1 deletion(-) create mode 100644 engines/cge2/fileio.cpp create mode 100644 engines/cge2/fileio.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 0b06cd0fb4..8f84f5e31a 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -31,11 +31,16 @@ namespace CGE2 { CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription) { + _resman = nullptr; } CGE2Engine::~CGE2Engine() { } +void CGE2Engine::init() { + _resman = new ResourceManager(); +} + bool CGE2Engine::hasFeature(EngineFeature f) const { return false; } @@ -58,6 +63,7 @@ Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { } Common::Error CGE2Engine::run() { + init(); warning("STUB: CGE2Engine::run()"); return Common::kNoError; } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index ee4ecf62b1..068b371ff6 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -30,6 +30,7 @@ #include "engines/engine.h" #include "engines/advancedDetector.h" +#include "cge2/fileio.h" namespace CGE2 { @@ -45,6 +46,10 @@ public: virtual Common::Error run(); const ADGameDescription *_gameDescription; + + ResourceManager *_resman; +private: + void init(); }; } // End of namespace CGE2 diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp new file mode 100644 index 0000000000..4da2c52cfa --- /dev/null +++ b/engines/cge2/fileio.cpp @@ -0,0 +1,247 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "common/system.h" +#include "common/str.h" +#include "common/debug.h" +#include "common/debug-channels.h" +#include "common/memstream.h" +#include "cge2/cge2.h" +#include "cge2/fileio.h" + +namespace CGE2 { + +/*----------------------------------------------------------------------- + * BtPage + *-----------------------------------------------------------------------*/ +void BtPage::readBTree(Common::ReadStream &s) { + _header._count = s.readUint16LE(); + _header._down = s.readUint16LE(); + + if (_header._down == kBtValNone) { + // Leaf list + for (int i = 0; i < kBtLeafCount; ++i) { + s.read(_leaf[i]._key, kBtKeySize); + _leaf[i]._pos = s.readUint32LE(); + _leaf[i]._size = s.readUint32LE(); + } + } else { + // Root index + for (int i = 0; i < kBtInnerCount; ++i) { + s.read(_inner[i]._key, kBtKeySize); + _inner[i]._down = s.readUint16LE(); + } + } +} + +/*----------------------------------------------------------------------- + * ResourceManager + *-----------------------------------------------------------------------*/ +ResourceManager::ResourceManager() { + _datFile = new Common::File(); + _datFile->open(kDatName); + + _catFile = new Common::File(); + _catFile->open(kCatName); + + if (!_datFile->isOpen() || !_catFile->isOpen()) + error("Unable to open data files"); + + for (int i = 0; i < kBtLevel; i++) { + _buff[i]._page = new BtPage; + _buff[i]._pageNo = kBtValNone; + _buff[i]._index = -1; + assert(_buff[i]._page != NULL); + } +} + +ResourceManager::~ResourceManager() { + _datFile->close(); + delete _datFile; + + _catFile->close(); + delete _catFile; + + for (int i = 0; i < kBtLevel; i++) + delete _buff[i]._page; +} + +void ResourceManager::XCrypt(byte *buf, uint16 length) { + byte *b = buf; + + for (uint16 i = 0; i < length; i++) + *b++ ^= kCryptSeed; +} + +bool ResourceManager::seek(int32 offs, int whence) { + return _datFile->seek(offs, whence); +} + +uint16 ResourceManager::read(byte *buf, uint16 length) { + if (!_datFile->isOpen()) + return 0; + + uint16 bytesRead = _datFile->read(buf, length); + if (!bytesRead) + error("Read %s - %d bytes", _datFile->getName(), length); + XCrypt(buf, length); + return bytesRead; +} + +BtPage *ResourceManager::getPage(int level, uint16 pageId) { + if (_buff[level]._pageNo != pageId) { + int32 pos = pageId * kBtSize; + _buff[level]._pageNo = pageId; + assert(_catFile->size() > pos); + // In the original, there was a check verifying if the + // purpose was to write a new file. This should only be + // to create a new file, thus it was removed. + _catFile->seek(pageId * kBtSize, SEEK_SET); + + // Read in the page + byte buffer[kBtSize]; + int bytesRead = catRead(buffer, kBtSize); + + // Unpack it into the page structure + Common::MemoryReadStream stream(buffer, bytesRead, DisposeAfterUse::NO); + _buff[level]._page->readBTree(stream); + _buff[level]._index = -1; + } + return _buff[level]._page; +} + +BtKeypack *ResourceManager::find(const char *key) { + int lev = 0; + uint16 nxt = kBtValRoot; + while (!_catFile->eos()) { + BtPage *pg = getPage(lev, nxt); + // search + if (pg->_header._down != kBtValNone) { + int i; + for (i = 0; i < pg->_header._count; i++) { + // Does this work, or does it have to compare the entire buffer? + if (scumm_strnicmp((const char *)key, (const char*)pg->_inner[i]._key, kBtKeySize) < 0) + break; + } + nxt = (i) ? pg->_inner[i - 1]._down : pg->_header._down; + _buff[lev]._index = i - 1; + lev++; + } else { + int i; + for (i = 0; i < pg->_header._count - 1; i++) { + if (scumm_stricmp((const char *)key, (const char *)pg->_leaf[i]._key) <= 0) + break; + } + _buff[lev]._index = i; + return &pg->_leaf[i]; + } + } + return NULL; +} + +bool ResourceManager::exist(const char *name) { + return scumm_stricmp(find(name)->_key, name) == 0; +} + +uint16 ResourceManager::catRead(byte *buf, uint16 length) { + if (!_catFile->isOpen()) + return 0; + + uint16 bytesRead = _catFile->read(buf, length); + if (!bytesRead) + error("Read %s - %d bytes", _catFile->getName(), length); + XCrypt(buf, length); + return bytesRead; +} + +/*----------------------------------------------------------------------- + * EncryptedStream + *-----------------------------------------------------------------------*/ +EncryptedStream::EncryptedStream(CGE2Engine *vm, const char *name) : _vm(vm) { + _error = false; + BtKeypack *kp = _vm->_resman->find(name); + if (scumm_stricmp(kp->_key, name) != 0) + _error = true; + + _vm->_resman->seek(kp->_pos); + byte *dataBuffer; + int bufSize; + + if ((strlen(name) > 4) && (scumm_stricmp(name + strlen(name) - 4, ".SPR") == 0)) { + // SPR files have some inconsistencies. Some have extra 0x1A at the end, some others + // do not have a carriage return at the end of the last line + // Therefore, we remove this ending 0x1A and add extra new lines. + // This fixes bug #3537527 + dataBuffer = (byte *)malloc(kp->_size + 2); + _vm->_resman->read(dataBuffer, kp->_size); + if (dataBuffer[kp->_size - 1] == 0x1A) + dataBuffer[kp->_size - 1] = '\n'; + dataBuffer[kp->_size] = '\n'; + dataBuffer[kp->_size + 1] = '\n'; + bufSize = kp->_size + 2; + } else { + dataBuffer = (byte *)malloc(kp->_size); + _vm->_resman->read(dataBuffer, kp->_size); + bufSize = kp->_size; + } + + _readStream = new Common::MemoryReadStream(dataBuffer, bufSize, DisposeAfterUse::YES); +} + +uint32 EncryptedStream::read(byte *dataPtr, uint32 dataSize) { + return _readStream->read(dataPtr, dataSize); +} + +bool EncryptedStream::err() { + return (_error & _readStream->err()); +} + +bool EncryptedStream::eos() { + return _readStream->eos(); +} + +bool EncryptedStream::seek(int32 offset) { + return _readStream->seek(offset); +} + +Common::String EncryptedStream::readLine() { + return _readStream->readLine(); +} + +int32 EncryptedStream::size() { + return _readStream->size(); +} + +int32 EncryptedStream::pos() { + return _readStream->pos(); +} + +EncryptedStream::~EncryptedStream() { + delete _readStream; +} + +} // End of namespace CGE2 diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h new file mode 100644 index 0000000000..42bb2ee352 --- /dev/null +++ b/engines/cge2/fileio.h @@ -0,0 +1,120 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_FILEIO_H +#define CGE2_FILEIO_H + +#include "common/file.h" + +namespace CGE2 { + +class CGE2Engine; + +#define kBtSize 2048 +#define kBtKeySize 13 +#define kBtLevel 2 +#define kBtInnerCount ((kBtSize - 4 /*sizeof(Header) */) / (kBtKeySize + 2 /*sizeof(Inner) */)) +#define kBtLeafCount ((kBtSize - 4 /*sizeof(Header) */) / (kBtKeySize + 4 + 4 /*sizeof(BtKeypack) */)) +#define kBtValNone 0xFFFF +#define kBtValRoot 0 +#define kCatName "VOL.CAT" +#define kDatName "VOL.DAT" +#define kCryptSeed 0xA5 + +struct BtKeypack { + char _key[kBtKeySize]; + uint32 _pos; + uint32 _size; +}; + +struct Inner { + uint8 _key[kBtKeySize]; + uint16 _down; +}; + +struct Header { + uint16 _count; + uint16 _down; +}; + +struct BtPage { + Header _header; + union { + // dummy filler to make proper size of union + uint8 _data[kBtSize - 4]; /* 4 is the size of struct Header */ + // inner version of data: key + word-sized page link + Inner _inner[kBtInnerCount]; + // leaf version of data: key + all user data + BtKeypack _leaf[kBtLeafCount]; + }; + + void readBTree(Common::ReadStream &s); +}; + +class ResourceManager { +private: + struct { + BtPage *_page; + uint16 _pageNo; + int _index; + } _buff[kBtLevel]; + + BtPage *getPage(int level, uint16 pageId); + uint16 catRead(byte *buf, uint16 length); + Common::File *_catFile; + Common::File *_datFile; + void XCrypt(byte *buf, uint16 length); +public: + ResourceManager(); + ~ResourceManager(); + uint16 read(byte *buf, uint16 length); + bool seek(int32 offs, int whence = SEEK_SET); + + BtKeypack *find(const char *key); + bool exist(const char *name); +}; + +class EncryptedStream { +private: + CGE2Engine *_vm; + Common::SeekableReadStream *_readStream; + bool _error; +public: + EncryptedStream(CGE2Engine *vm, const char *name); + ~EncryptedStream(); + bool err(); + bool eos(); + bool seek(int32 offset); + int32 pos(); + int32 size(); + uint32 read(byte *dataPtr, uint32 dataSize); + Common::String readLine(); +}; + +} // End of namespace CGE2 + +#endif // CGE2_FILEIO_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 75f2743286..fc710b663a 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -2,7 +2,8 @@ MODULE := engines/cge2 MODULE_OBJS = \ cge2.o \ - detection.o + detection.o \ + fileio.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) -- cgit v1.2.3 From d9e0e882b7bb1e2d32e80334b434c0d6962a84d7 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Apr 2014 09:34:34 +0200 Subject: CGE2: Deallocate _resman in destructor. --- engines/cge2/cge2.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 8f84f5e31a..41b6249382 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -35,6 +35,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) } CGE2Engine::~CGE2Engine() { + delete _resman; } void CGE2Engine::init() { -- cgit v1.2.3 From 258d7ea535c2891bed4132e649c66fb86967a2a0 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Apr 2014 10:24:35 +0200 Subject: CGE2: Implement deinitialization properly. --- engines/cge2/cge2.cpp | 9 +++++---- engines/cge2/cge2.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 41b6249382..56393d20db 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -34,14 +34,14 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _resman = nullptr; } -CGE2Engine::~CGE2Engine() { - delete _resman; -} - void CGE2Engine::init() { _resman = new ResourceManager(); } +void CGE2Engine::deinit() { + delete _resman; +} + bool CGE2Engine::hasFeature(EngineFeature f) const { return false; } @@ -66,6 +66,7 @@ Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { Common::Error CGE2Engine::run() { init(); warning("STUB: CGE2Engine::run()"); + deinit(); return Common::kNoError; } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 068b371ff6..f84c9a8212 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -37,7 +37,6 @@ namespace CGE2 { class CGE2Engine : public Engine { public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); - ~CGE2Engine(); virtual bool hasFeature(EngineFeature f) const; virtual bool canLoadGameStateCurrently(); virtual bool canSaveGameStateCurrently(); @@ -50,6 +49,7 @@ public: ResourceManager *_resman; private: void init(); + void deinit(); }; } // End of namespace CGE2 -- cgit v1.2.3 From ec71f936280496d349310ea0091dbe26b90ae540 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Apr 2014 09:50:40 +0200 Subject: CGE2: Add parts of the graphics code. --- engines/cge2/bitmap.cpp | 369 +++++++++++++++++ engines/cge2/bitmap.h | 87 ++++ engines/cge2/cge2.cpp | 44 ++ engines/cge2/cge2.h | 18 + engines/cge2/general.h | 43 ++ engines/cge2/module.mk | 4 +- engines/cge2/vga13h.cpp | 1016 +++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/vga13h.h | 243 ++++++++++++ 8 files changed, 1823 insertions(+), 1 deletion(-) create mode 100644 engines/cge2/bitmap.cpp create mode 100644 engines/cge2/bitmap.h create mode 100644 engines/cge2/general.h create mode 100644 engines/cge2/vga13h.cpp create mode 100644 engines/cge2/vga13h.h (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp new file mode 100644 index 0000000000..77c7eb9c41 --- /dev/null +++ b/engines/cge2/bitmap.cpp @@ -0,0 +1,369 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/bitmap.h" +#include "cge2/cge2.h" +#include "cge2/vga13h.h" +//#include "cge/cge_main.h" +#include "common/system.h" +#include "common/debug.h" +#include "common/debug-channels.h" + +namespace CGE2 { + +Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(NULL), _v(NULL), _map(0), _vm(vm) { + char pat[kMaxPath]; + forceExt(pat, fname, ".VBM"); + + if (_vm->_resman->exist(pat)) { + EncryptedStream file(_vm, pat); + if (file.err()) + error("Unable to find VBM [%s]", fname); + if (!loadVBM(&file)) + error("Bad VBM [%s]", fname); + } else { + error("Bad VBM [%s]", fname); + } +} + +Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0), _b(NULL), _vm(vm) { + if (map) + code(); +} + +// following routine creates filled rectangle +// immediately as VGA video chunks, in near memory as fast as possible, +// especially for text line real time display +Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill) + : _w((w + 3) & ~3), // only full uint32 allowed! + _h(h), _m(NULL), _map(0), _b(NULL), _vm(vm) { + + uint16 dsiz = _w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = _h * lsiz; // - last gape, but + plane trailer + uint8 *v = new uint8[4 * psiz + _h * sizeof(*_b)];// the same for 4 planes + // + room for wash table + assert(v != NULL); + + WRITE_LE_UINT16(v, (kBmpCPY | dsiz)); // data chunk hader + memset(v + 2, fill, dsiz); // data bytes + WRITE_LE_UINT16(v + lsiz - 2, (kBmpSKP | ((kScrWidth / 4) - dsiz))); // gap + + // Replicate lines + byte *destP; + for (destP = v + lsiz; destP < (v + psiz); destP += lsiz) + Common::copy(v, v + lsiz, destP); + + WRITE_LE_UINT16(v + psiz - 2, kBmpEOI); // plane trailer uint16 + + // Replicate planes + for (destP = v + psiz; destP < (v + 4 * psiz); destP += psiz) + Common::copy(v, v + psiz, destP); + + HideDesc *b = (HideDesc *)(v + 4 * psiz); + b->_skip = (kScrWidth - _w) >> 2; + b->_hide = _w >> 2; + + // Replicate across the entire table + for (HideDesc *hdP = b + 1; hdP < (b + _h); hdP++) + *hdP = *b; + + b->_skip = 0; // fix the first entry + _v = v; + _b = b; +} + +Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0), _b(NULL), _vm(vm) { + uint8 *v0 = bmp._v; + if (!v0) + return; + + uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); + uint16 siz = vsiz + _h * sizeof(HideDesc); + uint8 *v1 = new uint8[siz]; + assert(v1 != NULL); + memcpy(v1, v0, siz); + _b = (HideDesc *)((_v = v1) + vsiz); +} + +Bitmap::~Bitmap() { + free(_m); + delete[] _v; +} + +Bitmap &Bitmap::operator=(const Bitmap &bmp) { + if (this == &bmp) + return *this; + + uint8 *v0 = bmp._v; + _w = bmp._w; + _h = bmp._h; + _m = NULL; + _map = 0; + _vm = bmp._vm; + delete[] _v; + + if (v0 == NULL) { + _v = NULL; + } else { + uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; + uint16 siz = vsiz + _h * sizeof(HideDesc); + uint8 *v1 = new uint8[siz]; + assert(v1 != NULL); + memcpy(v1, v0, siz); + _b = (HideDesc *)((_v = v1) + vsiz); + } + return *this; +} + +char *Bitmap::forceExt(char *buf, const char *name, const char *ext) { + strcpy(buf, name); + char *dot = strrchr(buf, '.'); + if (dot) + *dot = '\0'; + strcat(buf, ext); + + return buf; +} + +BitmapPtr Bitmap::code() { + if (!_m) + return NULL; + + uint16 cnt; + + if (_v) { // old X-map exists, so remove it + delete[] _v; + _v = NULL; + } + + while (true) { // at most 2 times: for (V == NULL) & for allocated block; + uint8 *im = _v + 2; + uint16 *cp = (uint16 *) _v; + int bpl; + + if (_v) { // 2nd pass - fill the hide table + for (uint16 i = 0; i < _h; i++) { + _b[i]._skip = 0xFFFF; + _b[i]._hide = 0x0000; + } + } + for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane + uint8 *bm = _m; + bool skip = (bm[bpl] == kPixelTransp); + uint16 j; + + cnt = 0; + for (uint16 i = 0; i < _h; i++) { // once per each line + uint8 pix; + for (j = bpl; j < _w; j += 4) { + pix = bm[j]; + if (_v && pix != kPixelTransp) { + if (j < _b[i]._skip) + _b[i]._skip = j; + + if (j >= _b[i]._hide) + _b[i]._hide = j + 1; + } + if ((pix == kPixelTransp) != skip || cnt >= 0x3FF0) { // end of block + cnt |= (skip) ? kBmpSKP : kBmpCPY; + if (_v) + WRITE_LE_UINT16(cp, cnt); // store block description uint16 + + cp = (uint16 *) im; + im += 2; + skip = (pix == kPixelTransp); + cnt = 0; + } + if (!skip) { + if (_v) + *im = pix; + im++; + } + cnt++; + } + + bm += _w; + if (_w < kScrWidth) { + if (skip) { + cnt += (kScrWidth - j + 3) / 4; + } else { + cnt |= kBmpCPY; + if (_v) + WRITE_LE_UINT16(cp, cnt); + + cp = (uint16 *) im; + im += 2; + skip = true; + cnt = (kScrWidth - j + 3) / 4; + } + } + } + if (cnt && ! skip) { + cnt |= kBmpCPY; + if (_v) + WRITE_LE_UINT16(cp, cnt); + + cp = (uint16 *) im; + im += 2; + } + if (_v) + WRITE_LE_UINT16(cp, kBmpEOI); + cp = (uint16 *) im; + im += 2; + } + if (_v) + break; + + uint16 sizV = (uint16)(im - 2 - _v); + _v = new uint8[sizV + _h * sizeof(*_b)]; + assert(_v != NULL); + + _b = (HideDesc *)(_v + sizV); + } + cnt = 0; + for (uint16 i = 0; i < _h; i++) { + if (_b[i]._skip == 0xFFFF) { // whole line is skipped + _b[i]._skip = (cnt + kScrWidth) >> 2; + cnt = 0; + } else { + uint16 s = _b[i]._skip & ~3; + uint16 h = (_b[i]._hide + 3) & ~3; + _b[i]._skip = (cnt + s) >> 2; + _b[i]._hide = (h - s) >> 2; + cnt = kScrWidth - h; + } + } + + return this; +} + +bool Bitmap::solidAt(int16 x, int16 y) { + if ((x >= _w) || (y >= _h)) + return false; + + uint8 *m = _v; + uint16 r = static_cast(x) % 4; + uint16 n0 = (kScrWidth * y + x) / 4; + uint16 n = 0; + + while (r) { + uint16 w, t; + + w = READ_LE_UINT16(m); + m += 2; + t = w & 0xC000; + w &= 0x3FFF; + + switch (t) { + case kBmpEOI: + r--; + // No break on purpose + case kBmpSKP: + w = 0; + break; + case kBmpREP: + w = 1; + break; + } + m += w; + } + + while (true) { + uint16 w, t; + + w = READ_LE_UINT16(m); + m += 2; + t = w & 0xC000; + w &= 0x3FFF; + + if (n > n0) + return false; + + n += w; + switch (t) { + case kBmpEOI: + return false; + case kBmpSKP: + w = 0; + break; + case kBmpREP: + case kBmpCPY: + if (n - w <= n0 && n > n0) + return true; + break; + } + m += ((t == kBmpREP) ? 1 : w); + } +} + +bool Bitmap::loadVBM(EncryptedStream *f) { + uint16 p = 0, n = 0; + if (!f->err()) + f->read((uint8 *)&p, sizeof(p)); + p = FROM_LE_16(p); + + if (!f->err()) + f->read((uint8 *)&n, sizeof(n)); + n = FROM_LE_16(n); + + if (!f->err()) + f->read((uint8 *)&_w, sizeof(_w)); + _w = FROM_LE_16(_w); + + if (!f->err()) + f->read((uint8 *)&_h, sizeof(_h)); + _h = FROM_LE_16(_h); + + if (!f->err()) { + if (p) { + if (_vm->_bitmapPalette) { + // Read in the palette + byte palData[kPalSize]; + f->read(palData, kPalSize); + + const byte *srcP = palData; + for (int idx = 0; idx < kPalCount; idx++, srcP += 3) { + _vm->_bitmapPalette[idx]._r = *srcP; + _vm->_bitmapPalette[idx]._g = *(srcP + 1); + _vm->_bitmapPalette[idx]._b = *(srcP + 2); + } + } else + f->seek(f->pos() + kPalSize); + } + } + if ((_v = new uint8[n]) == NULL) + return false; + + if (!f->err()) + f->read(_v, n); + + _b = (HideDesc *)(_v + n - _h * sizeof(HideDesc)); + return (!f->err()); +} + +} // End of namespace CGE2 diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h new file mode 100644 index 0000000000..3d3c27f97e --- /dev/null +++ b/engines/cge2/bitmap.h @@ -0,0 +1,87 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_BITMAP_H +#define CGE2_BITMAP_H + +#include "cge/general.h" +#include "common/file.h" + +namespace CGE2 { + +class CGE2Engine; +class EncryptedStream; + +#define kMaxPath 128 +enum { + kBmpEOI = 0x0000, + kBmpSKP = 0x4000, + kBmpREP = 0x8000, + kBmpCPY = 0xC000 +}; + +#include "common/pack-start.h" + +struct HideDesc { + uint16 _skip; + uint16 _hide; +} PACKED_STRUCT; + +#include "common/pack-end.h" + +class Bitmap { + CGE2Engine *_vm; + char *forceExt(char *buf, const char *name, const char *ext); + bool loadVBM(EncryptedStream *f); +public: + uint16 _w; + uint16 _h; + uint8 *_m; + uint8 *_v; + int32 _map; + HideDesc *_b; + + Bitmap(CGE2Engine *vm, const char *fname); + Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map); + Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill); + Bitmap(CGE2Engine *vm, const Bitmap &bmp); + ~Bitmap(); + + Bitmap *code(); + Bitmap &operator=(const Bitmap &bmp); + void hide(int16 x, int16 y); + void show(int16 x, int16 y); + void xShow(int16 x, int16 y); + bool solidAt(int16 x, int16 y); +}; + + +typedef Bitmap *BitmapPtr; + +} // End of namespace CGE2 + +#endif // CGE2_BITMAP_H diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 56393d20db..955c5eb0ea 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -25,21 +25,34 @@ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon */ +#include "engines/util.h" + #include "cge2/cge2.h" +#include "cge2/bitmap.h" +#include "cge2/vga13h.h" namespace CGE2 { CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription) { _resman = nullptr; + _vga = nullptr; + _sprite = nullptr; + + _quitFlag = false; + _bitmapPalette = nullptr; + _mode = 0; } void CGE2Engine::init() { _resman = new ResourceManager(); + _vga = new Vga(this); } void CGE2Engine::deinit() { delete _resman; + delete _vga; + delete _sprite; } bool CGE2Engine::hasFeature(EngineFeature f) const { @@ -64,10 +77,41 @@ Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { } Common::Error CGE2Engine::run() { + initGraphics(kScrWidth, kScrHeight, false); + init(); warning("STUB: CGE2Engine::run()"); + showTitle("WELCOME"); deinit(); return Common::kNoError; } +bool CGE2Engine::showTitle(const char *name) { + if (_quitFlag) + return false; + + _bitmapPalette = _vga->_sysPal; + BitmapPtr *LB = new BitmapPtr[2]; + LB[0] = new Bitmap(this, name); + LB[1] = NULL; + _bitmapPalette = NULL; + + Sprite D(this, LB); + D._flags._kill = true; + D._flags._bDel = true; + D.center(); + D.show(2); + + _vga->sunset(); + _vga->copyPage(1, 2); + _vga->copyPage(0, 1); + _vga->sunrise(_vga->_sysPal); + + _vga->update(); + + warning("STUB: CGE2Engine::showTitle()"); + + return true; +} + } // End of namespace CGE2 diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index f84c9a8212..814c607a93 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -30,10 +30,20 @@ #include "engines/engine.h" #include "engines/advancedDetector.h" +#include "common/system.h" #include "cge2/fileio.h" +#include "cge2/general.h" namespace CGE2 { +class Vga; +class Sprite; + +#define kScrWidth 320 +#define kScrHeight 240 +#define kMaxFile 128 +#define kPathMax 128 + class CGE2Engine : public Engine { public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); @@ -44,9 +54,17 @@ public: virtual Common::Error saveGameState(int slot, const Common::String &desc); virtual Common::Error run(); + bool showTitle(const char *name); + const ADGameDescription *_gameDescription; + bool _quitFlag; + Dac *_bitmapPalette; + int _mode; + ResourceManager *_resman; + Vga *_vga; + Sprite *_sprite; private: void init(); void deinit(); diff --git a/engines/cge2/general.h b/engines/cge2/general.h new file mode 100644 index 0000000000..7d5c60f191 --- /dev/null +++ b/engines/cge2/general.h @@ -0,0 +1,43 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_GENERAL_H +#define CGE2_GENERAL_H + +#include "common/file.h" + +namespace CGE2 { + +struct Dac { + uint8 _r; + uint8 _g; + uint8 _b; +}; + +} // End of namespace CGE2 + +#endif // CGE2_GENERAL_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index fc710b663a..493488f745 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -3,7 +3,9 @@ MODULE := engines/cge2 MODULE_OBJS = \ cge2.o \ detection.o \ - fileio.o + fileio.o \ + vga13h.o \ + bitmap.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp new file mode 100644 index 0000000000..26fba8bfd8 --- /dev/null +++ b/engines/cge2/vga13h.cpp @@ -0,0 +1,1016 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "common/array.h" +#include "common/config-manager.h" +#include "common/rect.h" +#include "graphics/palette.h" +#include "cge2/general.h" +#include "cge2/vga13h.h" +#include "cge2/bitmap.h" +//#include "cge/text.h" +//#include "cge/cge_main.h" +#include "cge2/cge2.h" +#include "cge2/vga13h.h" + +namespace CGE2 { + +Seq *getConstantSeq(bool seqFlag) { + const Seq seq1[] = { { 0, 0, 0, 0, 0 } }; + const Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; + + Seq *seq; + if (seqFlag) { + seq = (Seq *)malloc(1 * sizeof(Seq)); + *seq = seq1[0]; + } else { + seq = (Seq *)malloc(2 * sizeof(Seq)); + seq[0] = seq2[0]; + seq[1] = seq2[1]; + } + + return seq; +} + +Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) + : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), + _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), + _ext(NULL), _ref(-1), _scene(0), _vm(vm) { + memset(_file, 0, sizeof(_file)); + memset(&_flags, 0, sizeof(_flags)); + _ref = 0; + _x = _y = 0; + _w = _h = 0; + _time = 0; + _seqPtr = 0; + _shpCnt = 0; + _prev = _next = NULL; + + setShapeList(shpP); +} + +Sprite::~Sprite() { + if (_vm->_sprite == this) + _vm->_sprite = NULL; + + contract(); +} + +BitmapPtr Sprite::shp() { + SprExt *e = _ext; + if (!e || !e->_seq) + return NULL; + + int i = e->_seq[_seqPtr]._now; + if (i >= _shpCnt) + error("Invalid PHASE in SPRITE::Shp() %s", _file); + return e->_shpList[i]; +} + +BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { + BitmapPtr *r = (_ext) ? _ext->_shpList : NULL; + + _shpCnt = 0; + _w = 0; + _h = 0; + + if (shpP) { + BitmapPtr *p; + for (p = shpP; *p; p++) { + BitmapPtr b = (*p); // ->Code(); + if (b->_w > _w) + _w = b->_w; + if (b->_h > _h) + _h = b->_h; + _shpCnt++; + } + expand(); + _ext->_shpList = shpP; + _flags._bDel = true; + if (!_ext->_seq) + setSeq(getConstantSeq(_shpCnt < 2)); + } + return r; +} + +bool Sprite::works(Sprite *spr) { + //if (!spr || !spr->_ext) + // return false; + + //CommandHandler::Command *c = spr->_ext->_take; + //if (c != NULL) { + // c += spr->_takePtr; + // if (c->_ref == _ref) + // if (c->_commandType != kCmdLabel || (c->_val == 0 || c->_val == _vm->_now)) + // return true; + //} + + warning("STUB: Sprite::works()"); + + return false; +} + +Seq *Sprite::setSeq(Seq *seq) { + if (_ext) { + free(_ext->_seq); + _ext->_seq = NULL; + } + +// expand(); + warning("STUB: Sprite::setSeq()"); + + Seq *s = _ext->_seq; + _ext->_seq = seq; + if (_seqPtr == kNoSeq) + step(0); + else if (_time == 0) + step(_seqPtr); + return s; +} + +bool Sprite::seqTest(int n) { + if (n >= 0) + return (_seqPtr == n); + if (_ext) + return (_ext->_seq[_seqPtr]._next == _seqPtr); + return true; +} + +//CommandHandler::Command *Sprite::snList(SnList type) { +// SprExt *e = _ext; +// if (e) +// return (type == kNear) ? e->_near : e->_take; +// return NULL; +//} + +void Sprite::setName(char *newName) { + if (!_ext) + return; + + if (_ext->_name) { + delete[] _ext->_name; + _ext->_name = NULL; + } + if (newName) { + _ext->_name = new char[strlen(newName) + 1]; + assert(_ext->_name != NULL); + strcpy(_ext->_name, newName); + } +} + +Sprite *Sprite::expand() { + if (_ext) + return this; + + _ext = new SprExt; + assert(_ext != NULL); + if (!*_file) + return this; + + static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; + char fname[kPathMax]; + + Common::Array shplist; + for (int i = 0; i < _shpCnt + 1; ++i) + shplist.push_back(NULL); + + Seq *seq = NULL; + int shapeCount = 0, + seqCount = 0, + nearCount = 0, + takeCount = 0, + maxnow = 0, + maxnxt = 0; + + warning("STUB: Sprite::expand()"); + + //CommandHandler::Command *nearList = NULL; + //CommandHandler::Command *takeList = NULL; + //_vm->mergeExt(fname, _file, kSprExt); + //if (_vm->_resman->exist(fname)) { // sprite description file exist + // EncryptedStream sprf(_vm, fname); + // if (sprf.err()) + // error("Bad SPR [%s]", fname); + // Common::String line; + // char tmpStr[kLineMax + 1]; + // int lcnt = 0; + + // for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { + // int len = line.size(); + // Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + // lcnt++; + // if (len == 0 || *tmpStr == '.') + // continue; + + // CommandHandler::Command *c; + // switch (_vm->takeEnum(Comd, strtok(tmpStr, " =\t"))) { + // case 0: + // // Name + // setName(strtok(NULL, "")); + // break; + // case 1: + // // Phase + // // In case the shape index gets too high, increase the array size + // while ((shapeCount + 1) >= (int)shplist.size()) { + // shplist.push_back(NULL); + // ++_shpCnt; + // } + // shplist[shapeCount++] = new Bitmap(_vm, strtok(NULL, " \t,;/")); + // break; + // case 2: + // // Seq + // seq = (Seq *)realloc(seq, (seqCount + 1) * sizeof(*seq)); + // assert(seq != NULL); + // Seq *s; + // s = &seq[seqCount++]; + // s->_now = atoi(strtok(NULL, " \t,;/")); + // if (s->_now > maxnow) + // maxnow = s->_now; + // s->_next = atoi(strtok(NULL, " \t,;/")); + // switch (s->_next) { + // case 0xFF: + // s->_next = seqCount; + // break; + // case 0xFE: + // s->_next = seqCount - 1; + // break; + // } + // if (s->_next > maxnxt) + // maxnxt = s->_next; + // s->_dx = atoi(strtok(NULL, " \t,;/")); + // s->_dy = atoi(strtok(NULL, " \t,;/")); + // s->_dly = atoi(strtok(NULL, " \t,;/")); + // break; + // case 3: + // // Near + // if (_nearPtr == kNoPtr) + // break; + // nearList = (CommandHandler::Command *)realloc(nearList, (nearCount + 1) * sizeof(*nearList)); + // assert(nearList != NULL); + // c = &nearList[nearCount++]; + // if ((c->_commandType = (CommandType)_vm->takeEnum(CommandHandler::_commandText, strtok(NULL, " \t,;/"))) < 0) + // error("Bad NEAR in %d [%s]", lcnt, fname); + // c->_ref = atoi(strtok(NULL, " \t,;/")); + // c->_val = atoi(strtok(NULL, " \t,;/")); + // c->_spritePtr = NULL; + // break; + // case 4: + // // Take + // if (_takePtr == kNoPtr) + // break; + // takeList = (CommandHandler::Command *)realloc(takeList, (takeCount + 1) * sizeof(*takeList)); + // assert(takeList != NULL); + // c = &takeList[takeCount++]; + // if ((c->_commandType = (CommandType)_vm->takeEnum(CommandHandler::_commandText, strtok(NULL, " \t,;/"))) < 0) + // error("Bad NEAR in %d [%s]", lcnt, fname); + // c->_ref = atoi(strtok(NULL, " \t,;/")); + // c->_val = atoi(strtok(NULL, " \t,;/")); + // c->_spritePtr = NULL; + // break; + // } + // } + //} else { + // // no sprite description: try to read immediately from .BMP + // shplist[shapeCount++] = new Bitmap(_vm, _file); + //} + + //shplist[shapeCount] = NULL; + //if (seq) { + // if (maxnow >= shapeCount) + // error("Bad PHASE in SEQ [%s]", fname); + // if (maxnxt >= seqCount) + // error("Bad JUMP in SEQ [%s]", fname); + // setSeq(seq); + //} else + // setSeq(getConstantSeq(_shpCnt == 1)); + + //// Set the shape list + //BitmapPtr *shapeList = new BitmapPtr[shplist.size()]; + //for (uint i = 0; i < shplist.size(); ++i) + // shapeList[i] = shplist[i]; + + //setShapeList(shapeList); + + //if (nearList) + // nearList[nearCount - 1]._spritePtr = _ext->_near = nearList; + //else + // _nearPtr = kNoPtr; + //if (takeList) + // takeList[takeCount - 1]._spritePtr = _ext->_take = takeList; + //else + // _takePtr = kNoPtr; + + return this; +} + +Sprite *Sprite::contract() { + //SprExt *e = _ext; + //if (!e) + // return this; + + //if (e->_name) + // delete[] e->_name; + //if (_flags._bDel && e->_shpList) { + // for (int i = 0; e->_shpList[i]; i++) + // delete e->_shpList[i]; + // delete[] e->_shpList; + //} + + //free(e->_seq); + //free(e->_near); + //free(e->_take); + + //delete e; + //_ext = NULL; + + warning("STUB: Sprite::contract()"); + + return this; +} + +Sprite *Sprite::backShow(bool fast) { + expand(); + show(2); + show(1); + if (fast) + show(0); + contract(); + return this; +} + +void Sprite::step(int nr) { + if (nr >= 0) + _seqPtr = nr; + if (_ext) { + Seq *seq; + if (nr < 0) + _seqPtr = _ext->_seq[_seqPtr]._next; + seq = _ext->_seq + _seqPtr; + if (seq->_dly >= 0) { + gotoxy(_x + (seq->_dx), _y + (seq->_dy)); + _time = seq->_dly; + } + } +} + +//void Sprite::tick() { +// step(); +//} + +void Sprite::makeXlat(uint8 *x) { + if (!_ext) + return; + + if (_flags._xlat) + killXlat(); + for (BitmapPtr *b = _ext->_shpList; *b; b++) + (*b)->_m = x; + _flags._xlat = true; +} + +void Sprite::killXlat() { + if (!_flags._xlat || !_ext) + return; + + uint8 *m = (*_ext->_shpList)->_m; + free(m); + + for (BitmapPtr *b = _ext->_shpList; *b; b++) + (*b)->_m = NULL; + _flags._xlat = false; +} + +void Sprite::gotoxy(int x, int y) { + int xo = _x, yo = _y; + if (_x < kScrWidth) { + if (x < 0) + x = 0; + if (x + _w > kScrWidth) + x = (kScrWidth - _w); + _x = x; + } + if (_h < kScrHeight) { + if (y < 0) + y = 0; + if (y + _h > kScrHeight) + y = (kScrHeight - _h); + _y = y; + } + if (_next) + if (_next->_flags._slav) + _next->gotoxy(_next->_x - xo + _x, _next->_y - yo + _y); + if (_flags._shad) + _prev->gotoxy(_prev->_x - xo + _x, _prev->_y - yo + _y); +} + +void Sprite::center() { + gotoxy((kScrWidth - _w) / 2, (kScrHeight - _h) / 2); +} + +void Sprite::show() { + SprExt *e; + e = _ext; + e->_x0 = e->_x1; + e->_y0 = e->_y1; + e->_b0 = e->_b1; + e->_x1 = _x; + e->_y1 = _y; + e->_b1 = shp(); + if (!_flags._hide) { + if (_flags._xlat) + e->_b1->xShow(e->_x1, e->_y1); + else + e->_b1->show(e->_x1, e->_y1); + } +} + +void Sprite::show(uint16 pg) { + Graphics::Surface *a = _vm->_vga->_page[1]; + _vm->_vga->_page[1] = _vm->_vga->_page[pg & 3]; + shp()->show(_x, _y); + _vm->_vga->_page[1] = a; +} + +void Sprite::hide() { + SprExt *e = _ext; + if (e->_b0) + e->_b0->hide(e->_x0, e->_y0); +} + +BitmapPtr Sprite::ghost() { + SprExt *e = _ext; + if (!e->_b1) + return NULL; + + BitmapPtr bmp = new Bitmap(_vm, 0, 0, (uint8 *)NULL); + assert(bmp != NULL); + bmp->_w = e->_b1->_w; + bmp->_h = e->_b1->_h; + bmp->_b = new HideDesc[bmp->_h]; + assert(bmp->_b != NULL); + bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); + bmp->_map = (e->_y1 << 16) + e->_x1; + return bmp; +} + +void Sprite::sync(Common::Serializer &s) { + uint16 unused = 0; + + s.syncAsUint16LE(unused); + s.syncAsUint16LE(unused); // _ext + s.syncAsUint16LE(_ref); + s.syncAsByte(_scene); + + // bitfield in-memory storage is unpredictable, so to avoid + // any issues, pack/unpack everything manually + uint16 flags = 0; + if (s.isLoading()) { + s.syncAsUint16LE(flags); + _flags._hide = flags & 0x0001 ? true : false; + _flags._near = flags & 0x0002 ? true : false; + _flags._drag = flags & 0x0004 ? true : false; + _flags._hold = flags & 0x0008 ? true : false; + _flags._dummy = flags & 0x0010 ? true : false; + _flags._slav = flags & 0x0020 ? true : false; + _flags._syst = flags & 0x0040 ? true : false; + _flags._kill = flags & 0x0080 ? true : false; + _flags._xlat = flags & 0x0100 ? true : false; + _flags._port = flags & 0x0200 ? true : false; + _flags._kept = flags & 0x0400 ? true : false; + _flags._east = flags & 0x0800 ? true : false; + _flags._shad = flags & 0x1000 ? true : false; + _flags._back = flags & 0x2000 ? true : false; + _flags._bDel = flags & 0x4000 ? true : false; + _flags._tran = flags & 0x8000 ? true : false; + } else { + flags = (flags << 1) | _flags._tran; + flags = (flags << 1) | _flags._bDel; + flags = (flags << 1) | _flags._back; + flags = (flags << 1) | _flags._shad; + flags = (flags << 1) | _flags._east; + flags = (flags << 1) | _flags._kept; + flags = (flags << 1) | _flags._port; + flags = (flags << 1) | _flags._xlat; + flags = (flags << 1) | _flags._kill; + flags = (flags << 1) | _flags._syst; + flags = (flags << 1) | _flags._slav; + flags = (flags << 1) | _flags._dummy; + flags = (flags << 1) | _flags._hold; + flags = (flags << 1) | _flags._drag; + flags = (flags << 1) | _flags._near; + flags = (flags << 1) | _flags._hide; + s.syncAsUint16LE(flags); + } + + s.syncAsUint16LE(_x); + s.syncAsUint16LE(_y); + s.syncAsByte(_z); + s.syncAsUint16LE(_w); + s.syncAsUint16LE(_h); + s.syncAsUint16LE(_time); + s.syncAsByte(_nearPtr); + s.syncAsByte(_takePtr); + s.syncAsSint16LE(_seqPtr); + s.syncAsUint16LE(_shpCnt); + s.syncBytes((byte *)&_file[0], 9); + _file[8] = '\0'; + + s.syncAsUint16LE(unused); // _prev + s.syncAsUint16LE(unused); // _next +} + +Queue::Queue(bool show) : _head(NULL), _tail(NULL), _show(show) { +} + +Queue::~Queue() { + clear(); +} + +void Queue::clear() { + while (_head) { + Sprite *s = remove(_head); + if (s->_flags._kill) + delete s; + } +} + +void Queue::append(Sprite *spr) { + if (_tail) { + spr->_prev = _tail; + _tail->_next = spr; + } else + _head = spr; + _tail = spr; + if (_show) + spr->expand(); + else + spr->contract(); +} + +void Queue::insert(Sprite *spr, Sprite *nxt) { + if (nxt == _head) { + spr->_next = _head; + _head = spr; + if (!_tail) + _tail = spr; + } else { + assert(nxt); + spr->_next = nxt; + spr->_prev = nxt->_prev; + if (spr->_prev) + spr->_prev->_next = spr; + } + if (spr->_next) + spr->_next->_prev = spr; + if (_show) + spr->expand(); + else + spr->contract(); +} + +void Queue::insert(Sprite *spr) { + Sprite *s; + for (s = _head; s; s = s->_next) + if (s->_z > spr->_z) + break; + if (s) + insert(spr, s); + else + append(spr); + if (_show) + spr->expand(); + else + spr->contract(); +} + +template +inline bool contains(const Common::List &l, const T &v) { + return (Common::find(l.begin(), l.end(), v) != l.end()); +} + +Sprite *Queue::remove(Sprite *spr) { + if (spr == _head) + _head = spr->_next; + if (spr == _tail) + _tail = spr->_prev; + if (spr->_next) + spr->_next->_prev = spr->_prev; + if (spr->_prev) + spr->_prev->_next = spr->_next; + spr->_prev = NULL; + spr->_next = NULL; + return spr; +} + +Sprite *Queue::locate(int ref) { + for (Sprite *spr = _head; spr; spr = spr->_next) { + if (spr->_ref == ref) + return spr; + } + return NULL; +} + +Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0), _vm(vm) { + _oldColors = NULL; + _newColors = NULL; + _showQ = new Queue(true); + _spareQ = new Queue(false); + _sysPal = new Dac[kPalCount]; + + for (int idx = 0; idx < 4; idx++) { + _page[idx] = new Graphics::Surface(); + _page[idx]->create(kScrWidth, kScrHeight, Graphics::PixelFormat::createFormatCLUT8()); + } + + /*if (ConfMan.getBool("enable_color_blind")) + _mono = 1;*/ + + warning("STUB: Vga::Vga()"); + + _oldColors = (Dac *)malloc(sizeof(Dac) * kPalCount); + _newColors = (Dac *)malloc(sizeof(Dac) * kPalCount); + getColors(_oldColors); + sunset(); + setColors(); + clear(0); +} + +Vga::~Vga() { + _mono = 0; + + Common::String buffer = ""; +/* + clear(0); + setMode(_oldMode); + setColors(); + restoreScreen(_oldScreen); + sunrise(_oldColors); +*/ + warning("STUB: Vga::~Vga()"); + + free(_oldColors); + free(_newColors); + if (_msg) + buffer = Common::String(_msg); + if (_name) + buffer = buffer + " [" + _name + "]"; + + debugN("%s", buffer.c_str()); + + delete _showQ; + delete _spareQ; + delete[] _sysPal; + + for (int idx = 0; idx < 4; idx++) { + _page[idx]->free(); + delete _page[idx]; + } +} + +void Vga::waitVR() { + // Since some of the game parts rely on using vertical sync as a delay mechanism, + // we're introducing a short delay to simulate it + g_system->delayMillis(5); +} + +void Vga::getColors(Dac *tab) { + byte palData[kPalSize]; + g_system->getPaletteManager()->grabPalette(palData, 0, kPalCount); + palToDac(palData, tab); +} + +uint8 Vga::closest(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB) { +#define f(col, lum) ((((uint16)(col)) << 8) / lum) + uint16 i, dif = 0xFFFF, found = 0; + uint16 L = colR + colG + colB; + if (!L) + L++; + uint16 R = f(colR, L), G = f(colG, L), B = f(colB, L); + for (i = 0; i < 256; i++) { + uint16 l = pal[i]._r + pal[i]._g + pal[i]._b; + if (!l) + l++; + int r = f(pal[i]._r, l), g = f(pal[i]._g, l), b = f(pal[i]._b, l); + uint16 D = ((r > R) ? (r - R) : (R - r)) + + ((g > G) ? (g - G) : (G - g)) + + ((b > B) ? (b - B) : (B - b)) + + ((l > L) ? (l - L) : (L - l)) * 10 ; + + if (D < dif) { + found = i; + dif = D; + if (D == 0) + break; // exact! + } + } + return found; +#undef f +} + +uint8 *Vga::glass(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB) { + uint8 *x = (uint8 *)malloc(256); + if (x) { + uint16 i; + for (i = 0; i < 256; i++) { + x[i] = closest(pal, ((uint16)(pal[i]._r) * colR) / 255, + ((uint16)(pal[i]._g) * colG) / 255, + ((uint16)(pal[i]._b) * colB) / 255); + } + } + return x; +} + +void Vga::palToDac(const byte *palData, Dac *tab) { + const byte *colP = palData; + for (int idx = 0; idx < kPalCount; idx++, colP += 3) { + tab[idx]._r = *colP >> 2; + tab[idx]._g = *(colP + 1) >> 2; + tab[idx]._b = *(colP + 2) >> 2; + } +} + +void Vga::dacToPal(const Dac *tab, byte *palData) { + for (int idx = 0; idx < kPalCount; idx++, palData += 3) { + *palData = tab[idx]._r << 2; + *(palData + 1) = tab[idx]._g << 2; + *(palData + 2) = tab[idx]._b << 2; + } +} + +void Vga::setColors(Dac *tab, int lum) { + Dac *palP = tab, *destP = _newColors; + for (int idx = 0; idx < kPalCount; idx++, palP++, destP++) { + destP->_r = (palP->_r * lum) >> 6; + destP->_g = (palP->_g * lum) >> 6; + destP->_b = (palP->_b * lum) >> 6; + } + + if (_mono) { + destP = _newColors; + for (int idx = 0; idx < kPalCount; idx++, destP++) { + // Form a greyscalce color from 30% R, 59% G, 11% B + uint8 intensity = (((int)destP->_r * 77) + ((int)destP->_g * 151) + ((int)destP->_b * 28)) >> 8; + destP->_r = intensity; + destP->_g = intensity; + destP->_b = intensity; + } + } + + _setPal = true; +} + +void Vga::setColors() { + memset(_newColors, 0, kPalSize); + updateColors(); +} + +void Vga::sunrise(Dac *tab) { + for (int i = 0; i <= 64; i += kFadeStep) { + setColors(tab, i); + waitVR(); + updateColors(); + } +} + +void Vga::sunset() { + Dac tab[256]; + getColors(tab); + for (int i = 64; i >= 0; i -= kFadeStep) { + setColors(tab, i); + waitVR(); + updateColors(); + } +} + +void Vga::show() { + for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) + spr->show(); + update(); + for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) + spr->hide(); + + _frmCnt++; +} + +void Vga::updateColors() { + byte palData[kPalSize]; + dacToPal(_newColors, palData); + g_system->getPaletteManager()->setPalette(palData, 0, 256); +} + +void Vga::update() { + SWAP(Vga::_page[0], Vga::_page[1]); + + if (_setPal) { + updateColors(); + _setPal = false; + } + /*if (_vm->_showBoundariesFl) { + Vga::_page[0]->hLine(0, 200 - kPanHeight, 320, 0xee); + if (_vm->_barriers[_vm->_now]._horz != 255) { + for (int i = 0; i < 8; i++) + Vga::_page[0]->vLine((_vm->_barriers[_vm->_now]._horz * 8) + i, 0, 200, 0xff); + } + if (_vm->_barriers[_vm->_now]._vert != 255) { + for (int i = 0; i < 4; i++) + Vga::_page[0]->hLine(0, 80 + (_vm->_barriers[_vm->_now]._vert * 4) + i, 320, 0xff); + } + }*/ + + warning("STUB: Vga::update()"); + + g_system->copyRectToScreen(Vga::_page[0]->getPixels(), kScrWidth, 0, 0, kScrWidth, kScrHeight); + g_system->updateScreen(); +} + +void Vga::clear(uint8 color) { + for (int paneNum = 0; paneNum < 4; paneNum++) + _page[paneNum]->fillRect(Common::Rect(0, 0, kScrWidth, kScrHeight), color); +} + +void Vga::copyPage(uint16 d, uint16 s) { + _page[d]->copyFrom(*_page[s]); +} + +//-------------------------------------------------------------------------- + +void Bitmap::xShow(int16 x, int16 y) { + const byte *srcP = (const byte *)_v; + byte *destEndP = (byte *)_vm->_vga->_page[1]->getBasePtr(0, kScrHeight); + byte *lookupTable = _m; + + // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a + // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data + // must be decompressed and inserted into the surface + for (int planeCtr = 0; planeCtr < 4; planeCtr++) { + byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x + planeCtr, y); + + for (;;) { + uint16 v = READ_LE_UINT16(srcP); + srcP += 2; + int cmd = v >> 14; + int count = v & 0x3FFF; + + if (cmd == 0) { + // End of image + break; + } + + assert(destP < destEndP); + + if (cmd == 2) + srcP++; + else if (cmd == 3) + srcP += count; + + // Handle a set of pixels + while (count-- > 0) { + // Transfer operation + switch (cmd) { + case 1: + // SKIP + break; + case 2: + case 3: + // TINT + *destP = lookupTable[*destP]; + break; + } + + // Move to next dest position + destP += 4; + } + } + } +} + + +void Bitmap::show(int16 x, int16 y) { + const byte *srcP = (const byte *)_v; + byte *destEndP = (byte *)_vm->_vga->_page[1]->getBasePtr(0, kScrHeight); + + // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a + // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data + // must be decompressed and inserted into the surface + for (int planeCtr = 0; planeCtr < 4; planeCtr++) { + byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x + planeCtr, y); + + for (;;) { + uint16 v = READ_LE_UINT16(srcP); + srcP += 2; + int cmd = v >> 14; + int count = v & 0x3FFF; + + if (cmd == 0) { + // End of image + break; + } + + assert(destP < destEndP); + + // Handle a set of pixels + while (count-- > 0) { + // Transfer operation + switch (cmd) { + case 1: + // SKIP + break; + case 2: + // REPEAT + *destP = *srcP; + break; + case 3: + // COPY + *destP = *srcP++; + break; + } + + // Move to next dest position + destP += 4; + } + + if (cmd == 2) + srcP++; + } + } +} + + +void Bitmap::hide(int16 x, int16 y) { + for (int yp = y; yp < y + _h; yp++) { + const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(x, yp); + byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x, yp); + + Common::copy(srcP, srcP + _w, destP); + } +} + +/*--------------------------------------------------------------------------*/ + +HorizLine::HorizLine(CGE2Engine *vm) : Sprite(vm, NULL), _vm(vm) { + // Set the sprite list + BitmapPtr *HL = new BitmapPtr[2]; + HL[0] = new Bitmap(_vm, "HLINE"); + HL[1] = NULL; + + setShapeList(HL); +} + +SceneLight::SceneLight(CGE2Engine *vm) : Sprite(vm, NULL), _vm(vm) { + // Set the sprite list + BitmapPtr *PR = new BitmapPtr[2]; + PR[0] = new Bitmap(_vm, "PRESS"); + PR[1] = NULL; + + setShapeList(PR); +} + +Speaker::Speaker(CGE2Engine *vm): Sprite(vm, NULL), _vm(vm) { + // Set the sprite list + BitmapPtr *SP = new BitmapPtr[3]; + SP[0] = new Bitmap(_vm, "SPK_L"); + SP[1] = new Bitmap(_vm, "SPK_R"); + SP[2] = NULL; + + setShapeList(SP); +} + +PocLight::PocLight(CGE2Engine *vm): Sprite(vm, NULL), _vm(vm) { + // Set the sprite list + BitmapPtr *LI = new BitmapPtr[5]; + LI[0] = new Bitmap(_vm, "LITE0"); + LI[1] = new Bitmap(_vm, "LITE1"); + LI[2] = new Bitmap(_vm, "LITE2"); + LI[3] = new Bitmap(_vm, "LITE3"); + LI[4] = NULL; + + setShapeList(LI); + + _flags._kill = false; +} + +} // End of namespace CGE2 diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h new file mode 100644 index 0000000000..e761c5c35c --- /dev/null +++ b/engines/cge2/vga13h.h @@ -0,0 +1,243 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_VGA13H_H +#define CGE2_VGA13H_H + +#include "common/serializer.h" +#include "common/events.h" +#include "graphics/surface.h" +#include "cge2/general.h" +#include "cge2/bitmap.h" +//#include "cge/snail.h" +#include "cge2/cge2.h" + +namespace CGE2 { + +#define kFadeStep 2 +#define kVgaColDark 207 +#define kVgaColDarkGray 225 /*219*/ +#define kVgaColGray 231 +#define kVgaColLightGray 237 +#define kPixelTransp 0xFE +#define kNoSeq (-1) +#define kNoPtr ((uint8)-1) +#define kSprExt ".SPR" +#define kPalCount 256 +#define kPalSize (kPalCount * 3) + +struct Seq { + uint8 _now; + uint8 _next; + int8 _dx; + int8 _dy; + int _dly; +}; + +class SprExt { +public: + int _x0; + int _y0; + int _x1; + int _y1; + BitmapPtr _b0; + BitmapPtr _b1; + BitmapPtr *_shpList; + Seq *_seq; + char *_name; + /*CommandHandler::Command *_near; + CommandHandler::Command *_take;*/ + SprExt() : + _x0(0), _y0(0), + _x1(0), _y1(0), + _b0(NULL), _b1(NULL), + _shpList(NULL), _seq(NULL), + _name(NULL)/*, _near(NULL), _take(NULL)*/ + {} +}; + +class Sprite { +protected: + SprExt *_ext; +public: + int _ref; + signed char _scene; + struct Flags { + uint16 _hide : 1; // general visibility switch + uint16 _near : 1; // Near action lock + uint16 _drag : 1; // sprite is moveable + uint16 _hold : 1; // sprite is held with mouse + uint16 _dummy : 1; // intrrupt driven animation + uint16 _slav : 1; // slave object + uint16 _syst : 1; // system object + uint16 _kill : 1; // dispose memory after remove + uint16 _xlat : 1; // 2nd way display: xlat table + uint16 _port : 1; // portable + uint16 _kept : 1; // kept in pocket + uint16 _east : 1; // talk to east (in opposite to west) + uint16 _shad : 1; // shadow + uint16 _back : 1; // 'send to background' request + uint16 _bDel : 1; // delete bitmaps in ~SPRITE + uint16 _tran : 1; // transparent (untouchable) + } _flags; + int _x; + int _y; + signed char _z; + uint16 _w; + uint16 _h; + uint16 _time; + uint8 _nearPtr; + uint8 _takePtr; + int _seqPtr; + int _shpCnt; + char _file[kMaxFile]; + Sprite *_prev; + Sprite *_next; + + bool works(Sprite *spr); + bool seqTest(int n); + inline bool active() { + return _ext != NULL; + } + + Sprite(CGE2Engine *vm, BitmapPtr *shp); + virtual ~Sprite(); + BitmapPtr shp(); + BitmapPtr *setShapeList(BitmapPtr *shp); + Sprite *expand(); + Sprite *contract(); + Sprite *backShow(bool fast = false); + void setName(char *newName); + inline char *name() { + return (_ext) ? _ext->_name : NULL; + } + void gotoxy(int x, int y); + void center(); + void show(); + void hide(); + BitmapPtr ghost(); + void show(uint16 pg); + void makeXlat(uint8 *x); + void killXlat(); + void step(int nr = -1); + Seq *setSeq(Seq *seq); + //CommandHandler::Command *snList(SnList type); + /*virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); + virtual void tick();*/ + void sync(Common::Serializer &s); +private: + CGE2Engine *_vm; +}; + +class Queue { + Sprite *_head; + Sprite *_tail; +public: + Queue(bool show); + ~Queue(); + + bool _show; + + void append(Sprite *spr); + void insert(Sprite *spr, Sprite *nxt); + void insert(Sprite *spr); + Sprite *remove(Sprite *spr); + Sprite *first() { + return _head; + } + Sprite *last() { + return _tail; + } + Sprite *locate(int ref); + void clear(); +}; + +class Vga { + CGE2Engine *_vm; + bool _setPal; + Dac *_oldColors; + Dac *_newColors; + const char *_msg; + const char *_name; + + void updateColors(); + void setColors(); + void waitVR(); + uint8 closest(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB); + +public: + uint32 _frmCnt; + Queue *_showQ; + Queue *_spareQ; + int _mono; + Graphics::Surface *_page[4]; + Dac *_sysPal; + + Vga(CGE2Engine *vm); + ~Vga(); + + uint8 *glass(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB); + void getColors(Dac *tab); + void setColors(Dac *tab, int lum); + void clear(uint8 color); + void copyPage(uint16 d, uint16 s); + void sunrise(Dac *tab); + void sunset(); + void show(); + void update(); + + void palToDac(const byte *palData, Dac *tab); + void dacToPal(const Dac *tab, byte *palData); +}; + +class HorizLine: public Sprite { + CGE2Engine *_vm; +public: + HorizLine(CGE2Engine *vm); +}; + +class SceneLight: public Sprite { + CGE2Engine *_vm; +public: + SceneLight(CGE2Engine *vm); +}; + +class Speaker: public Sprite { + CGE2Engine *_vm; +public: + Speaker(CGE2Engine *vm); +}; + +class PocLight: public Sprite { + CGE2Engine *_vm; +public: + PocLight(CGE2Engine *vm); +}; + +} // End of namespace CGE2 + +#endif // CGE2_VGA13H_H -- cgit v1.2.3 From 8e3bbbea7c97ac222a7f061b68fe161b455bf0f8 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 1 May 2014 22:52:20 +0200 Subject: CGE2: Add sound code with working MIDI parts. --- engines/cge2/cge2.cpp | 20 +++- engines/cge2/cge2.h | 7 ++ engines/cge2/module.mk | 3 +- engines/cge2/sound.cpp | 290 +++++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/sound.h | 135 +++++++++++++++++++++++ 5 files changed, 453 insertions(+), 2 deletions(-) create mode 100644 engines/cge2/sound.cpp create mode 100644 engines/cge2/sound.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 955c5eb0ea..370846faf7 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -30,6 +30,7 @@ #include "cge2/cge2.h" #include "cge2/bitmap.h" #include "cge2/vga13h.h" +#include "cge2/sound.h" namespace CGE2 { @@ -38,21 +39,31 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _resman = nullptr; _vga = nullptr; _sprite = nullptr; + _midiPlayer = nullptr; + _fx = nullptr; + _sound = nullptr; _quitFlag = false; _bitmapPalette = nullptr; _mode = 0; + _music = true; } void CGE2Engine::init() { _resman = new ResourceManager(); _vga = new Vga(this); + _fx = new Fx(this, 16); + _sound = new Sound(this); + _midiPlayer = new MusicPlayer(this); } void CGE2Engine::deinit() { delete _resman; delete _vga; delete _sprite; + delete _fx; + delete _sound; + delete _midiPlayer; } bool CGE2Engine::hasFeature(EngineFeature f) const { @@ -77,11 +88,18 @@ Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { } Common::Error CGE2Engine::run() { + warning("STUB: CGE2Engine::run()"); + initGraphics(kScrWidth, kScrHeight, false); init(); - warning("STUB: CGE2Engine::run()"); + showTitle("WELCOME"); + + // Temporary code to test the midi player. + _midiPlayer->loadMidi(1); + g_system->delayMillis(100000); + deinit(); return Common::kNoError; } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 814c607a93..9f7fcf6244 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -38,6 +38,9 @@ namespace CGE2 { class Vga; class Sprite; +class MusicPlayer; +class Fx; +class Sound; #define kScrWidth 320 #define kScrHeight 240 @@ -61,10 +64,14 @@ public: bool _quitFlag; Dac *_bitmapPalette; int _mode; + bool _music; ResourceManager *_resman; Vga *_vga; Sprite *_sprite; + MusicPlayer *_midiPlayer; + Fx *_fx; + Sound *_sound; private: void init(); void deinit(); diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 493488f745..f885933e9d 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -5,7 +5,8 @@ MODULE_OBJS = \ detection.o \ fileio.o \ vga13h.o \ - bitmap.o + bitmap.o \ + sound.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp new file mode 100644 index 0000000000..a3e866f05f --- /dev/null +++ b/engines/cge2/sound.cpp @@ -0,0 +1,290 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/sound.h" +//#include "cge/text.h" +//#include "cge/cge_main.h" +#include "common/config-manager.h" +#include "common/memstream.h" +#include "audio/decoders/raw.h" +#include "audio/audiostream.h" +#include "cge2/cge2.h" + +namespace CGE2 { + +DataCk::DataCk(byte *buf, int bufSize) { + _buf = buf; + _ckSize = bufSize; +} + +DataCk::~DataCk() { + free(_buf); +} + +Sound::Sound(CGE2Engine *vm) : _vm(vm) { + _audioStream = NULL; + _soundRepeatCount = 1; + open(); +} + +Sound::~Sound() { + close(); +} + +void Sound::close() { + _vm->_midiPlayer->killMidi(); +} + +void Sound::open() { + setRepeat(1); + play((*_vm->_fx)[30000], 8); +} + +void Sound::setRepeat(int16 count) { + _soundRepeatCount = count; +} + +int16 Sound::getRepeat() { + return _soundRepeatCount; +} + +void Sound::play(DataCk *wav, int pan) { + if (wav) { + stop(); + _smpinf._saddr = &*(wav->addr()); + _smpinf._slen = (uint16)wav->size(); + _smpinf._span = pan; + _smpinf._counter = getRepeat(); + sndDigiStart(&_smpinf); + } +} + +void Sound::sndDigiStart(SmpInfo *PSmpInfo) { + // Create an audio stream wrapper for sound + Common::MemoryReadStream *stream = new Common::MemoryReadStream(PSmpInfo->_saddr, + PSmpInfo->_slen, DisposeAfterUse::NO); + _audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); + + // Start the new sound + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, + Audio::makeLoopingAudioStream(_audioStream, (uint)PSmpInfo->_counter)); + + // CGE pan: + // 8 = Center + // Less = Left + // More = Right + _vm->_mixer->setChannelBalance(_soundHandle, (int8)CLIP(((PSmpInfo->_span - 8) * 16), -127, 127)); +} + +void Sound::stop() { + sndDigiStop(&_smpinf); +} + +void Sound::sndDigiStop(SmpInfo *PSmpInfo) { + if (_vm->_mixer->isSoundHandleActive(_soundHandle)) + _vm->_mixer->stopHandle(_soundHandle); + _audioStream = NULL; +} + +Fx::Fx(CGE2Engine *vm, int size) : _current(NULL), _vm(vm) { + _cache = new Handler[size]; + for (_size = 0; _size < size; _size++) { + _cache[_size]._ref = 0; + _cache[_size]._wav = NULL; + } +} + +Fx::~Fx() { + clear(); + delete[] _cache; +} + +void Fx::clear() { + for (Handler *p = _cache, *q = p + _size; p < q; p++) { + if (p->_ref) { + p->_ref = 0; + delete p->_wav; + p->_wav = NULL; + } + } + _current = NULL; +} + +int Fx::find(int ref) { + int i = 0; + for (Handler *p = _cache, *q = p + _size; p < q; p++) { + if (p->_ref == ref) + break; + else + ++i; + } + return i; +} + +void Fx::name(int ref, int sub) { + warning("STUB: Fx::name()"); +} + +DataCk *Fx::load(int idx, int ref) { + char filename[12]; + warning("TODO: Implement Fx::load() with the use of Fx::name() properly in paralell with Snail! It just won't work this way."); + sprintf(filename, "FX%05d.WAV", ref); + + EncryptedStream file(_vm, filename); + DataCk *wav = loadWave(&file); + if (wav) { + Handler *p = &_cache[idx]; + delete p->_wav; + p->_wav = wav; + p->_ref = ref; + } else { + warning("Unable to load %s", filename); + } + return wav; +} + +DataCk *Fx::loadWave(EncryptedStream *file) { + byte *data = (byte *)malloc(file->size()); + + if (!data) + return 0; + + file->read(data, file->size()); + + return new DataCk(data, file->size()); +} + +DataCk *Fx::operator[](int ref) { + int i; + if ((i = find(ref)) < _size) + _current = _cache[i]._wav; + else { + if ((i = find(0)) >= _size) { + clear(); + i = 0; + } + _current = load(i, ref); + } + return _current; +} + +MusicPlayer::MusicPlayer(CGE2Engine *vm) : _vm(vm) { + _data = NULL; + _isGM = false; + + MidiPlayer::createDriver(); + + int ret = _driver->open(); + if (ret == 0) { + if (_nativeMT32) + _driver->sendMT32Reset(); + else + _driver->sendGMReset(); + + // TODO: Load cmf.ins with the instrument table. It seems that an + // interface for such an operation is supported for AdLib. Maybe for + // this card, setting instruments is necessary. + + _driver->setTimerCallback(this, &timerCallback); + } + _dataSize = -1; +} + +MusicPlayer::~MusicPlayer() { + killMidi(); +} + +void MusicPlayer::killMidi() { + Audio::MidiPlayer::stop(); + + free(_data); + _data = NULL; +} + +void MusicPlayer::loadMidi(int ref) { + warning("STUB: MusicPlayer::loadMidi()"); // if (MidiNotify) MidiNotify(); + + // Work out the filename and check the given MIDI file exists + Common::String filename = Common::String::format("%.2dSG%.2d.MID", ref >> 8, ref & 0xFF); + if (!_vm->_resman->exist(filename.c_str())) + return; + + // Stop any currently playing MIDI file + killMidi(); + + // Read in the data for the file + EncryptedStream mid(_vm, filename.c_str()); + _dataSize = mid.size(); + _data = (byte *)malloc(_dataSize); + mid.read(_data, _dataSize); + + // Start playing the music + sndMidiStart(); +} + +void MusicPlayer::sndMidiStart() { + _isGM = true; + + MidiParser *parser = MidiParser::createParser_SMF(); + if (parser->loadMusic(_data, _dataSize)) { + parser->setTrack(0); + parser->setMidiDriver(this); + parser->setTimerRate(_driver->getBaseTempo()); + parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); + + _parser = parser; + + syncVolume(); + + // Al the tracks are supposed to loop + _isLooping = true; + _isPlaying = true; + } +} + +void MusicPlayer::send(uint32 b) { + if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) { + b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; + } + + Audio::MidiPlayer::send(b); +} + +void MusicPlayer::sendToChannel(byte channel, uint32 b) { + if (!_channelsTable[channel]) { + _channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel(); + // If a new channel is allocated during the playback, make sure + // its volume is correctly initialized. + if (_channelsTable[channel]) + _channelsTable[channel]->volume(_channelsVolume[channel] * _masterVolume / 255); + } + + if (_channelsTable[channel]) + _channelsTable[channel]->send(b); +} + +} // End of namespace CGE2 diff --git a/engines/cge2/sound.h b/engines/cge2/sound.h new file mode 100644 index 0000000000..c488c3fbba --- /dev/null +++ b/engines/cge2/sound.h @@ -0,0 +1,135 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_SOUND_H +#define CGE2_SOUND_H + +#include "cge2/fileio.h" +#include "audio/audiostream.h" +#include "audio/decoders/wave.h" +#include "audio/fmopl.h" +#include "audio/mididrv.h" +#include "audio/midiparser.h" +#include "audio/midiplayer.h" +#include "audio/mixer.h" +#include "common/memstream.h" + +namespace CGE2 { + +class CGE2Engine; + +// sample info +struct SmpInfo { + const uint8 *_saddr; // address + uint16 _slen; // length + uint16 _span; // left/right pan (0-15) + int _counter; // number of time the sample should be played +}; + +class DataCk { + byte *_buf; + int _ckSize; +public: + DataCk(byte *buf, int bufSize); + ~DataCk(); + inline const byte *addr() { + return _buf; + } + inline int size() { + return _ckSize; + } +}; + +class Sound { +public: + SmpInfo _smpinf; + + Sound(CGE2Engine *vm); + ~Sound(); + void open(); + void close(); + void play(DataCk *wav, int pan); + int16 getRepeat(); + void setRepeat(int16 count); + void stop(); +private: + int _soundRepeatCount; + CGE2Engine *_vm; + Audio::SoundHandle _soundHandle; + Audio::RewindableAudioStream *_audioStream; + + void sndDigiStart(SmpInfo *PSmpInfo); + void sndDigiStop(SmpInfo *PSmpInfo); +}; + +class Fx { + CGE2Engine *_vm; + struct Handler { + int _ref; + DataCk *_wav; + } *_cache; + int _size; + + DataCk *load(int idx, int ref); + DataCk *loadWave(EncryptedStream *file); + int find(int ref); +public: + DataCk *_current; + + Fx(CGE2Engine *vm, int size); + ~Fx(); + void clear(); + void name(int ref, int sub); + DataCk *operator[](int ref); +}; + +class MusicPlayer: public Audio::MidiPlayer { +private: + CGE2Engine *_vm; + byte *_data; + int _dataSize; + bool _isGM; + + // Start MIDI File + void sndMidiStart(); + + // Stop MIDI File + void sndMidiStop(); +public: + MusicPlayer(CGE2Engine *vm); + ~MusicPlayer(); + + void loadMidi(int ref); + void killMidi(); + + virtual void send(uint32 b); + virtual void sendToChannel(byte channel, uint32 b); +}; + +} // End of namespace CGE2 + +#endif // CGE2_SOUND_H -- cgit v1.2.3 From b595d9ee0a66c3a8980b0c513529bd0ff0ffe5b5 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 5 May 2014 18:59:17 +0200 Subject: CGE2: Add Text and a reduced skeleton of cge2_main. --- engines/cge2/cge2.cpp | 11 ++-- engines/cge2/cge2.h | 8 +++ engines/cge2/cge2_main.cpp | 70 +++++++++++++++++++++ engines/cge2/cge2_main.h | 38 ++++++++++++ engines/cge2/module.mk | 4 +- engines/cge2/text.cpp | 152 +++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/text.h | 67 ++++++++++++++++++++ 7 files changed, 344 insertions(+), 6 deletions(-) create mode 100644 engines/cge2/cge2_main.cpp create mode 100644 engines/cge2/cge2_main.h create mode 100644 engines/cge2/text.cpp create mode 100644 engines/cge2/text.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 370846faf7..bc2ce5615d 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -31,6 +31,7 @@ #include "cge2/bitmap.h" #include "cge2/vga13h.h" #include "cge2/sound.h" +#include "cge2/text.h" namespace CGE2 { @@ -42,11 +43,13 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _midiPlayer = nullptr; _fx = nullptr; _sound = nullptr; + _text = nullptr; _quitFlag = false; _bitmapPalette = nullptr; _mode = 0; _music = true; + _startupMode = 1; } void CGE2Engine::init() { @@ -55,6 +58,7 @@ void CGE2Engine::init() { _fx = new Fx(this, 16); _sound = new Sound(this); _midiPlayer = new MusicPlayer(this); + _text = new Text(this, "CGE"); } void CGE2Engine::deinit() { @@ -64,6 +68,7 @@ void CGE2Engine::deinit() { delete _fx; delete _sound; delete _midiPlayer; + delete _text; } bool CGE2Engine::hasFeature(EngineFeature f) const { @@ -93,12 +98,8 @@ Common::Error CGE2Engine::run() { initGraphics(kScrWidth, kScrHeight, false); init(); - - showTitle("WELCOME"); - // Temporary code to test the midi player. - _midiPlayer->loadMidi(1); - g_system->delayMillis(100000); + cge2_main(); deinit(); return Common::kNoError; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 9f7fcf6244..2c06832edd 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -41,6 +41,7 @@ class Sprite; class MusicPlayer; class Fx; class Sound; +class Text; #define kScrWidth 320 #define kScrHeight 240 @@ -58,6 +59,11 @@ public: virtual Common::Error run(); bool showTitle(const char *name); + void cge2_main(); + char *mergeExt(char *buf, const char *name, const char *ext); + void inf(const char *text, bool wideSpace = false); + void movie(const char *ext); + void runGame(); const ADGameDescription *_gameDescription; @@ -65,6 +71,7 @@ public: Dac *_bitmapPalette; int _mode; bool _music; + int _startupMode; ResourceManager *_resman; Vga *_vga; @@ -72,6 +79,7 @@ public: MusicPlayer *_midiPlayer; Fx *_fx; Sound *_sound; + Text *_text; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp new file mode 100644 index 0000000000..d3feb0a49f --- /dev/null +++ b/engines/cge2/cge2_main.cpp @@ -0,0 +1,70 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "sound.h" +#include "cge2/cge2_main.h" +#include "cge2/cge2.h" +#include "cge2/vga13h.h" +#include "cge2/text.h" + +namespace CGE2 { + +void CGE2Engine::movie(const char *ext) { + warning("STUB: CGE2Engine::movie()"); +} + +void CGE2Engine::runGame() { + warning("STUB: CGE2Engine::runGame()"); +} + +void CGE2Engine::cge2_main() { + warning("STUB: CGE2Engine::cge2_main()"); + + _mode++; + + if (showTitle("WELCOME")) { + if (_mode == 1) + movie(kIntroExt); + if (_text->getText(255) != NULL) { + runGame(); + _startupMode = 2; + } else + _vga->sunset(); + } else + _vga->sunset(); +} + +char *CGE2Engine::mergeExt(char *buf, const char *name, const char *ext) { + strcpy(buf, name); + char *dot = strrchr(buf, '.'); + if (!dot) + strcat(buf, ext); + + return buf; +} + +} // End of namespace CGE2 diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h new file mode 100644 index 0000000000..a1fb071b69 --- /dev/null +++ b/engines/cge2/cge2_main.h @@ -0,0 +1,38 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_MAIN_H +#define CGE2_MAIN_H + +namespace CGE2 { + +#define kLineMax 512 +#define kIntroExt ".I80" + +} // End of namespace CGE2 + +#endif // CGE2_MAIN_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index f885933e9d..4fb9156fce 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -6,7 +6,9 @@ MODULE_OBJS = \ fileio.o \ vga13h.o \ bitmap.o \ - sound.o + sound.o \ + cge2_main.o \ + text.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp new file mode 100644 index 0000000000..e65c19f202 --- /dev/null +++ b/engines/cge2/text.cpp @@ -0,0 +1,152 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +//#include "cge/general.h" +#include "cge2/text.h" +//#include "cge/talk.h" +//#include "cge/game.h" +//#include "cge/snail.h" +#include "cge2/cge2_main.h" +#include "common/str.h" + +namespace CGE2 { + +Text::Text(CGE2Engine *vm, const char *fname) : _vm(vm) { + _vm->mergeExt(_fileName, fname, kSayExt); + if (!_vm->_resman->exist(_fileName)) + error("No talk (%s)", _fileName); + int16 txtCount = count() + 1; + if (!txtCount) + error("Unable to read dialog file %s", _fileName); + + _cache = new Handler[txtCount]; + for (_size = 0; _size < txtCount; _size++) { + _cache[_size]._ref = 0; + _cache[_size]._text = NULL; + } + load(); +} + +Text::~Text() { + clear(); + delete[] _cache; +} + +int16 Text::count() { + EncryptedStream tf(_vm, _fileName); + if (tf.err()) + return -1; + + Common::String line; + char tmpStr[kLineMax + 1]; + + int counter = 0; + + for (line = tf.readLine(); !tf.eos(); line = tf.readLine()) { + char *s; + assert(line.size() <= 513); + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) + continue; + if (!Common::isDigit(*s)) + continue; + + counter++; + } + return counter; +} + +void Text::clear() { + for (Handler *p = _cache, *q = p + _size; p < q; p++) { + if (p->_ref) { + p->_ref = 0; + delete[] p->_text; + p->_text = NULL; + } + } +} + +void Text::load() { + EncryptedStream tf(_vm, _fileName); + assert(!tf.err()); + + Common::String line; + char tmpStr[kLineMax + 1]; + int idx; + + for (idx = 0, line = tf.readLine(); !tf.eos(); line = tf.readLine()) { + int n = line.size(); + char *s; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) + continue; + if (!Common::isDigit(*s)) + continue; + + int r = atoi(s); + + s += strlen(s); + if (s < tmpStr + n) + ++s; + + _cache[idx]._ref = r; + _cache[idx]._text = new char[strlen(s) + 1]; + strcpy(_cache[idx]._text, s); + idx++; + } +} + +char *Text::getText(int ref) { + int i; + for (i = 0; (i < _size) && (_cache[i]._ref != ref); i++) + ; + + if (i < _size) + return _cache[i]._text; + + warning("getText: Unable to find ref %d", ref); + return NULL; +} + +void Text::say(const char *text, Sprite *spr) { + warning("STUB: Text::say()"); +} + +void CGE2Engine::inf(const char *text, bool wideSpace) { + warning("STUB: CGE2Engine::inf()"); +} + +void Text::sayTime(Sprite *spr) { + TimeDate curTime; + _vm->_system->getTimeAndDate(curTime); + + char t[6]; + sprintf(t, "%d:%02d", curTime.tm_hour, curTime.tm_min); + say(t, spr); +} + +} // End of namespace CGE2 diff --git a/engines/cge2/text.h b/engines/cge2/text.h new file mode 100644 index 0000000000..634a3c8766 --- /dev/null +++ b/engines/cge2/text.h @@ -0,0 +1,67 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_TEXT_H +#define CGE2_TEXT_H + +//#include "cge/talk.h" +#include "cge2/cge2.h" + +namespace CGE2 { + +#define kSayExt ".SAY" +#define kSysTextMax 1000 +#define kTextNoMouse 95 +#define kInfName 101 +#define kSayName 102 +#define kInfRef 301 +#define kSayRef 302 + + +class Text { + struct Handler { + int _ref; + char *_text; + } *_cache; + int _size; + char _fileName[kPathMax]; + void load(); + int16 count(); +public: + Text(CGE2Engine *vm, const char *fname); + ~Text(); + void clear(); + char *getText(int ref); + void say(const char *text, Sprite *spr); + void sayTime(Sprite *spr); +private: + CGE2Engine *_vm; +}; + +} // End of namespace CGE2 + +#endif // CGE2_TEXT_H -- cgit v1.2.3 From a0c5805c8efba2e184b737dc7869092318743004 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 5 May 2014 20:31:21 +0200 Subject: CGE2: Read identifiers properly in Text::load(). --- engines/cge2/fileio.cpp | 8 ++++++++ engines/cge2/fileio.h | 1 + engines/cge2/text.cpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 4da2c52cfa..fb39cd3ad7 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -232,6 +232,14 @@ Common::String EncryptedStream::readLine() { return _readStream->readLine(); } +int EncryptedStream::number(char *s) { + int r = atoi(s); + char *pp = strchr(s, ':'); + if (pp) + r = (r << 8) + atoi(pp + 1); + return r; +} + int32 EncryptedStream::size() { return _readStream->size(); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 42bb2ee352..0597c6ac08 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -113,6 +113,7 @@ public: int32 size(); uint32 read(byte *dataPtr, uint32 dataSize); Common::String readLine(); + int number(char *s); }; } // End of namespace CGE2 diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index e65c19f202..de33717c55 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -107,7 +107,7 @@ void Text::load() { if (!Common::isDigit(*s)) continue; - int r = atoi(s); + int r = tf.number(s); s += strlen(s); if (s < tmpStr + n) -- cgit v1.2.3 From 0cbed1f53bc5caf936b21fc65080479f4be22c32 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 6 May 2014 21:02:58 +0200 Subject: CGE2: Start implementation of movie() and connected functions. --- engines/cge2/cge2.cpp | 1 + engines/cge2/cge2.h | 3 ++ engines/cge2/cge2_main.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index bc2ce5615d..853f84f25d 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -50,6 +50,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _mode = 0; _music = true; _startupMode = 1; + _now = 1; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 2c06832edd..01c38fa881 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -64,6 +64,8 @@ public: void inf(const char *text, bool wideSpace = false); void movie(const char *ext); void runGame(); + void loadScript(const char *fname); + void loadSprite(const char *fname, int ref, int scene, int col, int row, int pos); const ADGameDescription *_gameDescription; @@ -72,6 +74,7 @@ public: int _mode; bool _music; int _startupMode; + int _now; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index d3feb0a49f..34946c7c4b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -33,8 +33,103 @@ namespace CGE2 { +void CGE2Engine::loadSprite(const char *fname, int ref, int scene, int col = 0, int row = 0, int pos = 0) { + warning("STUB: CGE2Engine::loadSprite"); +} + +void CGE2Engine::loadScript(const char *fname) { + EncryptedStream scrf(this, fname); + + if (scrf.err()) + return; + + bool ok = true; + int lcnt = 0; + + char tmpStr[kLineMax + 1]; + Common::String line; + + int lineNum = 0; + for (line = scrf.readLine(); !scrf.eos(); line = scrf.readLine()) { + lineNum++; + + char *p; + + lcnt++; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + if ((line.size() == 0) || (*tmpStr == ';')) // Comments start with ';' - don't bother with them. + continue; + + ok = false; // not OK if break + + // sprite ident number + if ((p = strtok(tmpStr, " \t\n")) == NULL) + break; + int SpI = scrf.number(p); + + // sprite file name + char *SpN; + if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) + break; + + // sprite scene + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + int SpA = scrf.number(p); + + // sprite column + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + int SpX = scrf.number(p); + + // sprite row + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + int SpY = scrf.number(p); + + // sprite Z pos + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + int SpZ = scrf.number(p); + + // sprite life + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + bool BkG = scrf.number(p) == 0; + + ok = true; // no break: OK + + _sprite = NULL; + loadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); + if (_sprite) { + warning("STUB: CGE2Engine::loadScript - SPARE:: thing"); + if (BkG) + _sprite->_flags._back = true; + } + } + + if (!ok) + error("Bad INI line %d [%s]", lineNum, fname); // Counting starts from 0! +} + void CGE2Engine::movie(const char *ext) { - warning("STUB: CGE2Engine::movie()"); + assert(ext); + + if (_quitFlag) + return; + + char fn[12]; + sprintf(fn, "CGE.%s", (*ext == '.') ? ext + 1 : ext); + + if (_resman->exist(fn)) { + int now = _now; + _now = atoi(ext + 1); + loadScript(fn); + + warning("STUB: CGE2Engine::movie()"); + + _now = now; + } } void CGE2Engine::runGame() { -- cgit v1.2.3 From e3c4caabfaed1c91f16e05157af3555fc2ccc018 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 10:45:38 +0200 Subject: CGE2: Make number() static, add token() to File I/O. --- engines/cge2/cge2_main.cpp | 28 ++++++++++++++-------------- engines/cge2/fileio.cpp | 4 ++++ engines/cge2/fileio.h | 3 ++- 3 files changed, 20 insertions(+), 15 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 34946c7c4b..40dd98585b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -63,39 +63,39 @@ void CGE2Engine::loadScript(const char *fname) { ok = false; // not OK if break // sprite ident number - if ((p = strtok(tmpStr, " \t\n")) == NULL) + if ((p = EncryptedStream::token(tmpStr)) == NULL) break; - int SpI = scrf.number(p); + int SpI = EncryptedStream::number(p); // sprite file name char *SpN; - if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) + if ((SpN = EncryptedStream::token(NULL)) == NULL) break; // sprite scene - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = EncryptedStream::token(NULL)) == NULL) break; - int SpA = scrf.number(p); + int SpA = EncryptedStream::number(p); // sprite column - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = EncryptedStream::token(NULL)) == NULL) break; - int SpX = scrf.number(p); + int SpX = EncryptedStream::number(p); // sprite row - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = EncryptedStream::token(NULL)) == NULL) break; - int SpY = scrf.number(p); + int SpY = EncryptedStream::number(p); // sprite Z pos - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = EncryptedStream::token(NULL)) == NULL) break; - int SpZ = scrf.number(p); + int SpZ = EncryptedStream::number(p); // sprite life - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = EncryptedStream::token(NULL)) == NULL) break; - bool BkG = scrf.number(p) == 0; + bool BkG = EncryptedStream::number(p) == 0; ok = true; // no break: OK @@ -126,7 +126,7 @@ void CGE2Engine::movie(const char *ext) { _now = atoi(ext + 1); loadScript(fn); - warning("STUB: CGE2Engine::movie()"); + warning("STUB: CGE2Engine::movie()"); _now = now; } diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index fb39cd3ad7..7677699fed 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -240,6 +240,10 @@ int EncryptedStream::number(char *s) { return r; } +char *EncryptedStream::token(char *s) { + return strtok(s, " =\t,;/()"); +} + int32 EncryptedStream::size() { return _readStream->size(); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 0597c6ac08..a596d71341 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -113,7 +113,8 @@ public: int32 size(); uint32 read(byte *dataPtr, uint32 dataSize); Common::String readLine(); - int number(char *s); + static int number(char *s); + static char *token(char *s); }; } // End of namespace CGE2 -- cgit v1.2.3 From a3b274ba622c67cb597fa9b49b55ff416dc34236 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 10:46:18 +0200 Subject: CGE2: Add new types: V2D and V3D. --- engines/cge2/general.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'engines') diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 7d5c60f191..5564cd03ee 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -29,15 +29,77 @@ #define CGE2_GENERAL_H #include "common/file.h" +#include "common/rect.h" +#include "cge2/fileio.h" namespace CGE2 { +#define SCR_WID_ 320 + struct Dac { uint8 _r; uint8 _g; uint8 _b; }; +// From CGETYPE.H: +class V3D { +public: + double X, Y, Z; + V3D(void) { } + V3D(double x, double y, double z = 0) : X(x), Y(y), Z(z) { } + V3D(const V3D &p) : X(p.X), Y(p.Y), Z(p.Z) { } + V3D operator + (const V3D& p) const { return V3D(X + p.X, Y + p.Y, Z + p.Z); } + V3D operator - (const V3D& p) const { return V3D(X - p.X, Y - p.Y, Z - p.Z); } + V3D operator * (long n) const { return V3D(X * n, Y * n, Z * n); } + V3D operator / (long n) const { return V3D(X / n, Y / n, Z / n); } + bool operator == (V3D& p) const { return X == p.X && Y == p.Y && Z == p.Z; } + bool operator != (V3D& p) const { return X != p.X || Y != p.Y || Z != p.Z; } + V3D& operator += (const V3D& x) { return *this = *this + x; } + V3D& operator -= (const V3D& x) { return *this = *this - x; } +}; + +class V2D : public Common::Point { + double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } + double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } +public: + V2D& operator = (const V3D& p3) { + double m = Eye.Z / (p3.Z - Eye.Z); + x = round((Eye.X + (Eye.X - p3.X) * m)); + y = round((Eye.Y + (Eye.Y - p3.Y) * m)); + return *this; + } + V2D(void) { } + V2D(const V3D& p3) { *this = p3; } + V2D(int x, int y) : Common::Point(x, y) { } + static V3D Eye; + static void SetEye(const V3D &e) { Eye = e; } + static void SetEye(const V2D& e2, int z = -SCR_WID_) { + Eye.X = e2.x; Eye.Y = e2.y; Eye.Z = z; + } + static void SetEye(const char *s) { + char *tempStr; + strcpy(tempStr, s); + Eye.X = atoi(EncryptedStream::token(tempStr)); + Eye.Y = atoi(EncryptedStream::token(tempStr)); + Eye.Z = atoi(EncryptedStream::token(tempStr)); + } + bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } + bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } + bool operator >(const V2D& p) const { return (x > p.x) && (y > p.y); } + bool operator >= (const V2D& p) const { return (x >= p.x) && (y >= p.y); } + V2D operator + (const V2D& p) const { return V2D(x + p.x, y + p.y); } + V2D operator - (const V2D& p) const { return V2D(x - p.x, y - p.y); } + uint16 Area(void) { return x * y; } + bool Limited(const V2D& p) { + return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); + } + V2D Scale(int z) { + double m = Eye.Z / (Eye.Z - z); + return V2D(trunc(m * x), trunc(m * y)); + } +}; + } // End of namespace CGE2 #endif // CGE2_GENERAL_H -- cgit v1.2.3 From 5c8d9241aa119c60313cb9d74c033a690fd57fa0 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 13:43:02 +0200 Subject: CGE2: Use nullptrs instead of NULLs. --- engines/cge2/cge2_main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 40dd98585b..4907dd3cd4 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -69,31 +69,31 @@ void CGE2Engine::loadScript(const char *fname) { // sprite file name char *SpN; - if ((SpN = EncryptedStream::token(NULL)) == NULL) + if ((SpN = EncryptedStream::token(nullptr)) == NULL) break; // sprite scene - if ((p = EncryptedStream::token(NULL)) == NULL) + if ((p = EncryptedStream::token(nullptr)) == NULL) break; int SpA = EncryptedStream::number(p); // sprite column - if ((p = EncryptedStream::token(NULL)) == NULL) + if ((p = EncryptedStream::token(nullptr)) == NULL) break; int SpX = EncryptedStream::number(p); // sprite row - if ((p = EncryptedStream::token(NULL)) == NULL) + if ((p = EncryptedStream::token(nullptr)) == NULL) break; int SpY = EncryptedStream::number(p); // sprite Z pos - if ((p = EncryptedStream::token(NULL)) == NULL) + if ((p = EncryptedStream::token(nullptr)) == NULL) break; int SpZ = EncryptedStream::number(p); // sprite life - if ((p = EncryptedStream::token(NULL)) == NULL) + if ((p = EncryptedStream::token(nullptr)) == NULL) break; bool BkG = EncryptedStream::number(p) == 0; -- cgit v1.2.3 From 42f3dd6d2b0adf0822066e5e1cf2c83e553094d5 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 14:31:12 +0200 Subject: CGE2: Some renaming in V3D and V2D. --- engines/cge2/general.h | 51 +++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'engines') diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 5564cd03ee..a9b7002235 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -45,16 +45,16 @@ struct Dac { // From CGETYPE.H: class V3D { public: - double X, Y, Z; + double _x, _y, _z; V3D(void) { } - V3D(double x, double y, double z = 0) : X(x), Y(y), Z(z) { } - V3D(const V3D &p) : X(p.X), Y(p.Y), Z(p.Z) { } - V3D operator + (const V3D& p) const { return V3D(X + p.X, Y + p.Y, Z + p.Z); } - V3D operator - (const V3D& p) const { return V3D(X - p.X, Y - p.Y, Z - p.Z); } - V3D operator * (long n) const { return V3D(X * n, Y * n, Z * n); } - V3D operator / (long n) const { return V3D(X / n, Y / n, Z / n); } - bool operator == (V3D& p) const { return X == p.X && Y == p.Y && Z == p.Z; } - bool operator != (V3D& p) const { return X != p.X || Y != p.Y || Z != p.Z; } + V3D(double x, double y, double z = 0) : _x(x), _y(y), _z(z) { } + V3D(const V3D &p) : _x(p._x), _y(p._y), _z(p._z) { } + V3D operator + (const V3D& p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); } + V3D operator - (const V3D& p) const { return V3D(_x - p._x, _y - p._y, _z - p._z); } + V3D operator * (long n) const { return V3D(_x * n, _y * n, _z * n); } + V3D operator / (long n) const { return V3D(_x / n, _y / n, _z / n); } + bool operator == (V3D& p) const { return _x == p._x && _y == p._y && _z == p._z; } + bool operator != (V3D& p) const { return _x != p._x || _y != p._y || _z != p._z; } V3D& operator += (const V3D& x) { return *this = *this + x; } V3D& operator -= (const V3D& x) { return *this = *this - x; } }; @@ -64,25 +64,25 @@ class V2D : public Common::Point { double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } public: V2D& operator = (const V3D& p3) { - double m = Eye.Z / (p3.Z - Eye.Z); - x = round((Eye.X + (Eye.X - p3.X) * m)); - y = round((Eye.Y + (Eye.Y - p3.Y) * m)); + double m = Eye._z / (p3._z - Eye._z); + x = round((Eye._x + (Eye._x - p3._x) * m)); + y = round((Eye._y + (Eye._y - p3._y) * m)); return *this; } V2D(void) { } V2D(const V3D& p3) { *this = p3; } V2D(int x, int y) : Common::Point(x, y) { } static V3D Eye; - static void SetEye(const V3D &e) { Eye = e; } - static void SetEye(const V2D& e2, int z = -SCR_WID_) { - Eye.X = e2.x; Eye.Y = e2.y; Eye.Z = z; + static void setEye(const V3D &e) { Eye = e; } + static void setEye(const V2D& e2, int z = -SCR_WID_) { + Eye._x = e2.x; Eye._y = e2.y; Eye._z = z; } - static void SetEye(const char *s) { + static void setEye(const char *s) { char *tempStr; strcpy(tempStr, s); - Eye.X = atoi(EncryptedStream::token(tempStr)); - Eye.Y = atoi(EncryptedStream::token(tempStr)); - Eye.Z = atoi(EncryptedStream::token(tempStr)); + Eye._x = atoi(EncryptedStream::token(tempStr)); + Eye._y = atoi(EncryptedStream::token(tempStr)); + Eye._z = atoi(EncryptedStream::token(tempStr)); } bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } @@ -90,14 +90,19 @@ public: bool operator >= (const V2D& p) const { return (x >= p.x) && (y >= p.y); } V2D operator + (const V2D& p) const { return V2D(x + p.x, y + p.y); } V2D operator - (const V2D& p) const { return V2D(x - p.x, y - p.y); } - uint16 Area(void) { return x * y; } - bool Limited(const V2D& p) { + uint16 area(void) { return x * y; } + bool limited(const V2D& p) { return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); } - V2D Scale(int z) { - double m = Eye.Z / (Eye.Z - z); + V2D scale(int z) { + double m = Eye._z / (Eye._z - z); return V2D(trunc(m * x), trunc(m * y)); } + static V3D screenToGround(V2D pos) { + double z = V2D::Eye._z + (V2D::Eye._y*V2D::Eye._z) / (double(pos.y) - V2D::Eye._y); + double x = V2D::Eye._x - ((double(pos.x) - V2D::Eye._x) * (z - V2D::Eye._z)) / V2D::Eye._z; + return V3D(round(x), 0, round(z)); + } }; } // End of namespace CGE2 -- cgit v1.2.3 From fbb1a8da93a1d4efcf75df3379c3ecaa3235672b Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 14:32:51 +0200 Subject: CGE2: Rework loadScript(), start implementation of loadSprite(). --- engines/cge2/cge2.h | 2 +- engines/cge2/cge2_main.cpp | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 01c38fa881..e4426433e4 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -65,7 +65,7 @@ public: void movie(const char *ext); void runGame(); void loadScript(const char *fname); - void loadSprite(const char *fname, int ref, int scene, int col, int row, int pos); + void loadSprite(const char *fname, int ref, int scene, V3D &pos); const ADGameDescription *_gameDescription; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 4907dd3cd4..f5d694344b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -30,11 +30,22 @@ #include "cge2/cge2.h" #include "cge2/vga13h.h" #include "cge2/text.h" +#include "cge2/snail.h" namespace CGE2 { -void CGE2Engine::loadSprite(const char *fname, int ref, int scene, int col = 0, int row = 0, int pos = 0) { - warning("STUB: CGE2Engine::loadSprite"); +void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { + char pat[kLineMax]; + int shpcnt = 0; + int seqcnt = 0; + int cnt[kActions]; + int section = idPHASE; + bool frnt = true; + bool east = false; + bool port = false; + bool tran = false; + warning("STUB: CGE2Engine::loadSprite()"); + } void CGE2Engine::loadScript(const char *fname) { @@ -62,6 +73,8 @@ void CGE2Engine::loadScript(const char *fname) { ok = false; // not OK if break + V3D P; + // sprite ident number if ((p = EncryptedStream::token(tmpStr)) == NULL) break; @@ -80,17 +93,17 @@ void CGE2Engine::loadScript(const char *fname) { // sprite column if ((p = EncryptedStream::token(nullptr)) == NULL) break; - int SpX = EncryptedStream::number(p); + P._x = EncryptedStream::number(p); // sprite row if ((p = EncryptedStream::token(nullptr)) == NULL) break; - int SpY = EncryptedStream::number(p); + P._y = EncryptedStream::number(p); // sprite Z pos if ((p = EncryptedStream::token(nullptr)) == NULL) break; - int SpZ = EncryptedStream::number(p); + P._z = EncryptedStream::number(p); // sprite life if ((p = EncryptedStream::token(nullptr)) == NULL) @@ -100,7 +113,7 @@ void CGE2Engine::loadScript(const char *fname) { ok = true; // no break: OK _sprite = NULL; - loadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); + loadSprite(SpN, SpI, SpA, P); if (_sprite) { warning("STUB: CGE2Engine::loadScript - SPARE:: thing"); if (BkG) -- cgit v1.2.3 From 72cccb80008979ed4f23404681df173d007f34ed Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 16:51:03 +0200 Subject: CGE2: Add Hero. --- engines/cge2/cge2.cpp | 8 +++ engines/cge2/cge2.h | 7 +++ engines/cge2/general.h | 4 +- engines/cge2/hero.cpp | 140 +++++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/hero.h | 98 ++++++++++++++++++++++++++++++++++ engines/cge2/module.mk | 3 +- engines/cge2/vga13h.h | 3 +- 7 files changed, 258 insertions(+), 5 deletions(-) create mode 100644 engines/cge2/hero.cpp create mode 100644 engines/cge2/hero.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 853f84f25d..cf521907a9 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -32,6 +32,7 @@ #include "cge2/vga13h.h" #include "cge2/sound.h" #include "cge2/text.h" +#include "cge2/hero.h" namespace CGE2 { @@ -44,6 +45,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _fx = nullptr; _sound = nullptr; _text = nullptr; + for (int i = 0; i < 2; i++) + _heroTab[i] = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -51,6 +54,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _music = true; _startupMode = 1; _now = 1; + _sex = true; } void CGE2Engine::init() { @@ -60,6 +64,8 @@ void CGE2Engine::init() { _sound = new Sound(this); _midiPlayer = new MusicPlayer(this); _text = new Text(this, "CGE"); + for (int i = 0; i < 2; i++) + _heroTab[i] = new HeroTab(); } void CGE2Engine::deinit() { @@ -70,6 +76,8 @@ void CGE2Engine::deinit() { delete _sound; delete _midiPlayer; delete _text; + for (int i = 0; i < 2; i++) + delete _heroTab[i]; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index e4426433e4..c0a7d4a3bf 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -42,11 +42,16 @@ class MusicPlayer; class Fx; class Sound; class Text; +struct HeroTab; #define kScrWidth 320 #define kScrHeight 240 #define kMaxFile 128 #define kPathMax 128 +#define kDimMax 8 +#define kWayMax 10 +#define kPocketMax 4 +#define kCaveMax 100 class CGE2Engine : public Engine { public: @@ -75,6 +80,7 @@ public: bool _music; int _startupMode; int _now; + bool _sex; ResourceManager *_resman; Vga *_vga; @@ -83,6 +89,7 @@ public: Fx *_fx; Sound *_sound; Text *_text; + HeroTab *_heroTab[2]; private: void init(); void deinit(); diff --git a/engines/cge2/general.h b/engines/cge2/general.h index a9b7002235..9da00be6cd 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -60,8 +60,8 @@ public: }; class V2D : public Common::Point { - double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } - double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } + static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } + static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } public: V2D& operator = (const V3D& p3) { double m = Eye._z / (p3._z - Eye._z); diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp new file mode 100644 index 0000000000..8f5c44d776 --- /dev/null +++ b/engines/cge2/hero.cpp @@ -0,0 +1,140 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/hero.h" + +namespace CGE2 { + +Sprite *Hero::expand(void) { + warning("STUB: Hero::expand()"); + return this; +} + +void Hero::setCurrent(void) { + warning("STUB: Hero::setCurrent()"); +} + +void Hero::hStep(void) { + warning("STUB: Hero::hStep()"); +} + +Sprite *Hero::setContact(void) { + warning("STUB: Hero::setContact()"); + return this; +} + +void Hero::tick(void) { + warning("STUB: Hero::tick()"); +} + +int Hero::distance(V3D pos) { + warning("STUB: Hero::distance()"); + return 0; +} + +int Hero::distance(Sprite *spr) { + warning("STUB: Hero::distance()"); + return 0; +} + +void Hero::turn(Dir d) { + warning("STUB: Hero::turn()"); +} + +void Hero::park(void) { + warning("STUB: Hero::park()"); +} + +bool Hero::lower(Sprite * spr) { + warning("STUB: Hero::lower()"); + return false; +} + +void Hero::reach(int mode) { + warning("STUB: Hero::reach()"); +} + +void Hero::fun(void) { + warning("STUB: Hero::fun()"); +} + +void Hero::operator ++ (void) { + warning("STUB: Hero::operator ++()"); +} + +void Hero::operator -- (void) { + warning("STUB: Hero::operator --()"); +} + +bool Sprite::works(Sprite *spr) { + warning("STUB: Hero::works()"); + return false; +} + +uint32 Hero::len(V2D v) { + warning("STUB: Hero::works()"); + return 0; +} + +bool Hero::findWay(void){ + warning("STUB: Hero::findWay()"); + return false; +} + +int Hero::snap(int p, int q, int grid) { + warning("STUB: Hero::findWay()"); + return 0; +} + +void Hero::walkTo(V3D pos) { + warning("STUB: Hero::walkTo()"); +} + +void Hero::walkTo(Sprite *spr) { + warning("STUB: Hero::walkTo()"); +} + +int Hero::cross(const V2D &a, const V2D &b) { + warning("STUB: Hero::cross()"); + return 0; +} + +int Hero::mapCross(const V2D &a, const V2D &b) { + warning("STUB: Hero::mapCross()"); + return 0; +} + +int Hero::mapCross(const V3D &a, const V3D &b) { + warning("STUB: Hero::mapCross()"); + return 0; +} + +void Hero::setCave(int c) { + warning("STUB: Hero::mapCross()"); +} + +} // End of namespace CGE2 diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h new file mode 100644 index 0000000000..50020dab42 --- /dev/null +++ b/engines/cge2/hero.h @@ -0,0 +1,98 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_HERO_H +#define CGE2_HERO_H + +#include "cge2/cge2.h" +#include "cge2/vga13h.h" +#include "cge2/snail.h" + +namespace CGE2 { + +#define kMaxTry 400 + +class Hero; + +struct HeroTab { + Hero *_ptr; + Sprite *_face; + Sprite *_pocket[kPocketMax + 1]; + int _pocPtr; + V2D _posTab[kCaveMax]; +}; + +class Hero : public Sprite { + int _hig[kDimMax]; + Sprite *_contact; +public: + BitmapPtr _dim[kDimMax]; + V3D _trace[kWayMax]; + enum Dir { kNoDir = -1, kSS, kWW, kNN, kEE } _dir; + int _curDim; + int _tracePtr; + int _reachStart, _reachCycle, _sayStart, _funStart; + int _funDel0, _funDel; + int _maxDist; + bool _ignoreMap; + Hero(void); + void tick(void); + Sprite *expand(void); + Sprite *contract(void) { return this; } + Sprite *setContact(void); + int stepSize(void) { return _ext->_seq[7]._dx; } + int distance(V3D pos); + int distance(Sprite * spr); + void turn(Dir d); + void park(void); + static uint32 len(V2D v); + bool findWay(void); + static int snap(int p, int q, int grid); + void walkTo(V3D pos); + void walkTo(V2D pos) { walkTo(V2D::screenToGround(pos)); } + void walkTo(Sprite *spr); + void say(void) { step(_sayStart); } + void fun(void); + void resetFun(void) { _funDel = _funDel0; } + void hStep(void); + bool lower(Sprite * spr); + int cross(const V2D &a, const V2D &b); + int mapCross(const V2D &a, const V2D &b); + int mapCross(const V3D &a, const V3D &b); + Hero *other(void) { return _vm->_heroTab[!(_ref & 1)]->_ptr;} + Action action(void) { return (Action)(_ref % 10); } + void reach(int mode); + void setCurrent(void); + void setCave(int c); + void operator ++ (void); + void operator -- (void); +}; + + + +} // End of namespace CGE2 + +#endif // CGE2_HERO_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 4fb9156fce..62ce51ebb6 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -8,7 +8,8 @@ MODULE_OBJS = \ bitmap.o \ sound.o \ cge2_main.o \ - text.o + text.o \ + hero.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index e761c5c35c..b7325d8b9a 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -83,6 +83,7 @@ public: class Sprite { protected: SprExt *_ext; + CGE2Engine *_vm; public: int _ref; signed char _scene; @@ -149,8 +150,6 @@ public: /*virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); virtual void tick();*/ void sync(Common::Serializer &s); -private: - CGE2Engine *_vm; }; class Queue { -- cgit v1.2.3 From 12a9d0a759fd0129ced1f8815d1da569cd4378c2 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 18:32:29 +0200 Subject: CGE2: Add kIdTab and _lineCount to EncryptedStream. --- engines/cge2/fileio.cpp | 9 ++++++++- engines/cge2/fileio.h | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 7677699fed..6cc9f8b8de 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -181,7 +181,7 @@ uint16 ResourceManager::catRead(byte *buf, uint16 length) { /*----------------------------------------------------------------------- * EncryptedStream *-----------------------------------------------------------------------*/ -EncryptedStream::EncryptedStream(CGE2Engine *vm, const char *name) : _vm(vm) { +EncryptedStream::EncryptedStream(CGE2Engine *vm, const char *name) : _vm(vm), _lineCount(0) { _error = false; BtKeypack *kp = _vm->_resman->find(name); if (scumm_stricmp(kp->_key, name) != 0) @@ -229,6 +229,7 @@ bool EncryptedStream::seek(int32 offset) { } Common::String EncryptedStream::readLine() { + _lineCount++; return _readStream->readLine(); } @@ -256,4 +257,10 @@ EncryptedStream::~EncryptedStream() { delete _readStream; } +const char *EncryptedStream::kIdTab[] = { + "[near]", "[mtake]", "[ftake]", "[phase]", "[seq]", + "Name", "Type", "Front", "East", + "Portable", "Transparent", + NULL }; + } // End of namespace CGE2 diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index a596d71341..0d32cab3c2 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -102,7 +102,11 @@ class EncryptedStream { private: CGE2Engine *_vm; Common::SeekableReadStream *_readStream; + const char **_tab; + int _lineCount; bool _error; + + static const char *kIdTab[]; public: EncryptedStream(CGE2Engine *vm, const char *name); ~EncryptedStream(); @@ -115,6 +119,7 @@ public: Common::String readLine(); static int number(char *s); static char *token(char *s); + int getLineCount() { return _lineCount; } }; } // End of namespace CGE2 -- cgit v1.2.3 From d12e25ccd0114726a3cf04324f06cbbb14e8fa48 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 18:32:56 +0200 Subject: CGE2: Remove unnecessary whitespaces. --- engines/cge2/hero.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 50020dab42..893c36b189 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -91,8 +91,6 @@ public: void operator -- (void); }; - - } // End of namespace CGE2 #endif // CGE2_HERO_H -- cgit v1.2.3 From 9ffdff539203cf2774317bd274ae606a47148037 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 19:04:52 +0200 Subject: CGE2: Implement EncryptedStream::ident(). --- engines/cge2/fileio.cpp | 14 +++++++++++++- engines/cge2/fileio.h | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 6cc9f8b8de..91a9954e94 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -245,6 +245,17 @@ char *EncryptedStream::token(char *s) { return strtok(s, " =\t,;/()"); } +ID EncryptedStream::ident(const char *s) { + if (s) { + for (const char **e = kIdTab; *e; e++) { + if (scumm_stricmp(s, *e) == 0) { + return ID(e - kIdTab); + } + } + } + return kIdNone; +} + int32 EncryptedStream::size() { return _readStream->size(); } @@ -261,6 +272,7 @@ const char *EncryptedStream::kIdTab[] = { "[near]", "[mtake]", "[ftake]", "[phase]", "[seq]", "Name", "Type", "Front", "East", "Portable", "Transparent", - NULL }; + NULL +}; } // End of namespace CGE2 diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 0d32cab3c2..fdf1b8325e 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -45,6 +45,13 @@ class CGE2Engine; #define kDatName "VOL.DAT" #define kCryptSeed 0xA5 +enum ID { + kIdNear, kIdMTake, kIdFTake, kIdPhase, kIdSeq, + kIdName, kIdType, kIdFront, kIdEast, + kIdPortable, kIdTransparent, + kIdNone +}; + struct BtKeypack { char _key[kBtKeySize]; uint32 _pos; @@ -119,6 +126,7 @@ public: Common::String readLine(); static int number(char *s); static char *token(char *s); + static ID ident(const char *s); int getLineCount() { return _lineCount; } }; -- cgit v1.2.3 From b674ab2a09bec35b27583d8c463d137ded285e52 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 8 May 2014 19:23:36 +0200 Subject: CGE2: Further implement loadSprite(), fix compilation error. --- engines/cge2/cge2_main.cpp | 24 +++++++++++++++++------- engines/cge2/snail.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 engines/cge2/snail.h (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f5d694344b..117385adf0 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -31,21 +31,34 @@ #include "cge2/vga13h.h" #include "cge2/text.h" #include "cge2/snail.h" +#include "cge2/hero.h" namespace CGE2 { void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { - char pat[kLineMax]; int shpcnt = 0; int seqcnt = 0; int cnt[kActions]; - int section = idPHASE; + for (int i = 0; i < kActions; i++) + cnt[i] = 0; + int section = kIdPhase; bool frnt = true; bool east = false; bool port = false; bool tran = false; + Hero *h; + + char tmpStr[kLineMax]; + mergeExt(tmpStr, fname, kSprExt); + + if (_resman->exist(tmpStr)) { // sprite description file exist + EncryptedStream sprf(this, tmpStr); + if (sprf.err()) + error("Bad SPR [%s]", tmpStr); + + } + warning("STUB: CGE2Engine::loadSprite()"); - } void CGE2Engine::loadScript(const char *fname) { @@ -60,10 +73,7 @@ void CGE2Engine::loadScript(const char *fname) { char tmpStr[kLineMax + 1]; Common::String line; - int lineNum = 0; for (line = scrf.readLine(); !scrf.eos(); line = scrf.readLine()) { - lineNum++; - char *p; lcnt++; @@ -122,7 +132,7 @@ void CGE2Engine::loadScript(const char *fname) { } if (!ok) - error("Bad INI line %d [%s]", lineNum, fname); // Counting starts from 0! + error("Bad INI line %d [%s]", scrf.getLineCount(), fname); } void CGE2Engine::movie(const char *ext) { diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h new file mode 100644 index 0000000000..cc60882962 --- /dev/null +++ b/engines/cge2/snail.h @@ -0,0 +1,37 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_SNAIL_H +#define CGE2_SNAIL_H + +namespace CGE2 { + +enum Action { kNear, kMTake, kFTake, kActions }; + +} // End of namespace CGE2 + +#endif -- cgit v1.2.3 From cb6548919712d91ae4cfbdefd20f6f0f147ced6c Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 9 May 2014 13:11:50 +0200 Subject: CGE2: Implement CGE2Engine::loadSprite(). Add Snail during the process and revise or expand a lot of other parts of the engine. --- engines/cge2/cge2.cpp | 3 +- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 139 ++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/cge2_main.h | 3 +- engines/cge2/fileio.cpp | 20 +++++-- engines/cge2/fileio.h | 4 +- engines/cge2/hero.cpp | 9 ++- engines/cge2/hero.h | 2 +- engines/cge2/module.mk | 3 +- engines/cge2/snail.cpp | 60 +++++++++++++++++++ engines/cge2/snail.h | 85 +++++++++++++++++++++++++++ engines/cge2/vga13h.cpp | 71 ++++++++++++----------- engines/cge2/vga13h.h | 18 ++++-- 13 files changed, 359 insertions(+), 59 deletions(-) create mode 100644 engines/cge2/snail.cpp (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index cf521907a9..c3ec6a92eb 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -126,7 +126,8 @@ bool CGE2Engine::showTitle(const char *name) { Sprite D(this, LB); D._flags._kill = true; - D._flags._bDel = true; + // D._flags._bDel = true; + warning("STUB: Sprite::showTitle() - Flags changed compared to CGE1's Sprite type."); D.center(); D.show(2); diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c0a7d4a3bf..79ac2c7488 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -71,6 +71,7 @@ public: void runGame(); void loadScript(const char *fname); void loadSprite(const char *fname, int ref, int scene, V3D &pos); + void badLab(const char *fn); const ADGameDescription *_gameDescription; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 117385adf0..23fe4cbfa9 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -35,20 +35,25 @@ namespace CGE2 { +void CGE2Engine::badLab(const char *fn) { + error("Misplaced label in %s!", fn); +} + void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { int shpcnt = 0; int seqcnt = 0; int cnt[kActions]; for (int i = 0; i < kActions; i++) cnt[i] = 0; - int section = kIdPhase; + ID section = kIdPhase; bool frnt = true; bool east = false; bool port = false; bool tran = false; Hero *h; + ID id; - char tmpStr[kLineMax]; + char tmpStr[kLineMax + 1]; mergeExt(tmpStr, fname, kSprExt); if (_resman->exist(tmpStr)) { // sprite description file exist @@ -56,9 +61,137 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { if (sprf.err()) error("Bad SPR [%s]", tmpStr); + int label = kNoByte; + Common::String line; + + for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ + int len = line.size(); + if (len == 0 || *tmpStr == ';') + continue; + + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *p; + p = EncryptedStream::token(tmpStr); + if (*p == '@') { + if (label != kNoByte) + badLab(fname); + label = atoi(p + 1); + continue; + } + + id = EncryptedStream::ident(p); + switch (id) { + case kIdName: // will be taken in Expand routine + if (label != kNoByte) + badLab(fname); + break; + case kIdType: + if (label != kNoByte) + badLab(fname); + break; + case kIdNear: + case kIdMTake: + case kIdFTake: + case kIdPhase: + case kIdSeq: + if (label != kNoByte) + badLab(fname); + section = id; + break; + case kIdFront: + if (label != kNoByte) + badLab(fname); + p = EncryptedStream::token(nullptr); + frnt = EncryptedStream::testBool(p); + break; + case kIdEast: + if (label != kNoByte) + badLab(fname); + p = EncryptedStream::token(nullptr); + east = EncryptedStream::testBool(p); + break; + case kIdPortable: + if (label != kNoByte) + badLab(fname); + p = EncryptedStream::token(nullptr); + port = EncryptedStream::testBool(p); + break; + case kIdTransparent: + if (label != kNoByte) + badLab(fname); + p = EncryptedStream::token(nullptr); + tran = EncryptedStream::testBool(p); + break; + default: + if (id >= kIdNear) + break; + switch (section) { + case kIdNear: + case kIdMTake: + case kIdFTake: + if (Snail::com(p) >= 0) + ++cnt[section]; + else + error("Bad line %d [%s]", sprf.getLineCount(), tmpStr); + break; + case kIdPhase: + if (label != kNoByte) + badLab(fname); + ++shpcnt; + break; + case kIdSeq: + if (label != kNoByte) + badLab(fname); + ++seqcnt; + break; + } + break; + } + label = kNoByte; + } + + if (!shpcnt) { + error("No shapes - %s", fname); + } + } else // No sprite description: mono-shaped sprite with only .BMP file. + ++shpcnt; + + // Make sprite of choosen type: + char c = *fname | 0x20; + if (c >= 'a' && c <= 'z' && fname[1] == '0' && fname[2] == '\0') { + h = new Hero(this); + if (h) { + h->gotoxyz(pos); + _sprite = h; + } + } else { + if (_sprite) + delete _sprite; + _sprite = new Sprite(this); + if (_sprite) + _sprite->gotoxyz(pos); } - warning("STUB: CGE2Engine::loadSprite()"); + if (_sprite) { + _sprite->_flags._frnt = frnt; + _sprite->_flags._east = east; + _sprite->_flags._port = port; + _sprite->_flags._tran = tran; + _sprite->_flags._kill = true; + + // Extract the filename, without the extension + Common::strlcpy(_sprite->_file, fname, sizeof(_sprite->_file)); + char *p = strchr(_sprite->_file, '.'); + if (p) + *p = '\0'; + + _sprite->_shpCnt = shpcnt; + _sprite->_seqPtr = seqcnt; + + for (int i = 0; i < kActions; i++) + _sprite->_actionCtrl[i]._cnt = cnt[i]; + } } void CGE2Engine::loadScript(const char *fname) { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index a1fb071b69..8420a2d1db 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -30,8 +30,9 @@ namespace CGE2 { -#define kLineMax 512 +#define kLineMax 512 #define kIntroExt ".I80" +#define kNoByte -1 } // End of namespace CGE2 diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 91a9954e94..6a20b6b561 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -245,15 +245,23 @@ char *EncryptedStream::token(char *s) { return strtok(s, " =\t,;/()"); } -ID EncryptedStream::ident(const char *s) { - if (s) { - for (const char **e = kIdTab; *e; e++) { - if (scumm_stricmp(s, *e) == 0) { - return ID(e - kIdTab); +int EncryptedStream::takeEnum(const char **tab, const char *text) { + if (text) { + for (const char **e = tab; *e; e++) { + if (scumm_stricmp(text, *e) == 0) { + return e - tab; } } } - return kIdNone; + return -1; +} + +ID EncryptedStream::ident(const char *s) { + return ID(takeEnum(kIdTab, s)); +} + +bool EncryptedStream::testBool(char *s) { + return number(s) != 0; } int32 EncryptedStream::size() { diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index fdf1b8325e..758d841226 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -49,7 +49,7 @@ enum ID { kIdNear, kIdMTake, kIdFTake, kIdPhase, kIdSeq, kIdName, kIdType, kIdFront, kIdEast, kIdPortable, kIdTransparent, - kIdNone + kIdNone = -1 }; struct BtKeypack { @@ -126,7 +126,9 @@ public: Common::String readLine(); static int number(char *s); static char *token(char *s); + static int takeEnum(const char **tab, const char *text); static ID ident(const char *s); + static bool testBool(char *s); int getLineCount() { return _lineCount; } }; diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 8f5c44d776..44ff85040d 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -29,6 +29,10 @@ namespace CGE2 { +Hero::Hero(CGE2Engine *vm) : Sprite(vm) { + warning("STUB: Hero::Hero()"); +} + Sprite *Hero::expand(void) { warning("STUB: Hero::expand()"); return this; @@ -90,11 +94,6 @@ void Hero::operator -- (void) { warning("STUB: Hero::operator --()"); } -bool Sprite::works(Sprite *spr) { - warning("STUB: Hero::works()"); - return false; -} - uint32 Hero::len(V2D v) { warning("STUB: Hero::works()"); return 0; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 893c36b189..21f4ec39e7 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -58,7 +58,7 @@ public: int _funDel0, _funDel; int _maxDist; bool _ignoreMap; - Hero(void); + Hero(CGE2Engine *vm); void tick(void); Sprite *expand(void); Sprite *contract(void) { return this; } diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 62ce51ebb6..4a7a412152 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -9,7 +9,8 @@ MODULE_OBJS = \ sound.o \ cge2_main.o \ text.o \ - hero.o + hero.o \ + snail.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp new file mode 100644 index 0000000000..245da9972a --- /dev/null +++ b/engines/cge2/snail.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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/snail.h" +#include "cge2/fileio.h" + +namespace CGE2 { + +const char *Snail::comTxt[] = { + "NOP", "USE", "PAUSE", "INF", "CAVE", + "SLAVE", "FOCUS", "SETX", "SETY", "SETZ", + "ADD", "SUB", "MUL", "DIV", "IF", "FLAG", + "FLASH", "LIGHT", "CYCLE", + "CLEAR", "TALK", "MOUSE", + "MAP", "COUNT", "MIDI", + "SETDLG", "MSKDLG", + ".DUMMY.", + "WAIT", "HIDE", "ROOM", + "SAY", "SOUND", "TIME", "KILL", + "RSEQ", "SEQ", "SEND", "SWAP", + "KEEP", "GIVE", + "GETPOS", "GOTO", "MOVEX", "MOVEY", + "MOVEZ", "TRANS", "PORT", + "NEXT", "NNEXT", "MTNEXT", "FTNEXT", + "RNNEXT", "RMTNEXT", "RFTNEXT", + "RMNEAR", "RMMTAKE", "RMFTAKE", + "SETREF", "BACKPT", + "WALKTO", "REACH", "COVER", "UNCOVER", + NULL }; + +int Snail::com(const char *com) { + int i = EncryptedStream::takeEnum(comTxt, com); + return (i < 0) ? i : i + kSNCom0 + 1; +} + +} // End of namespace CGE2. diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index cc60882962..5cdb22150f 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -28,10 +28,95 @@ #ifndef CGE2_SNAIL_H #define CGE2_SNAIL_H +#include "cge2/cge2_main.h" + namespace CGE2 { enum Action { kNear, kMTake, kFTake, kActions }; +enum SNCom { + kSNCom0 = 128, + kSNNop, // NOP instrukcja "pusta" :: do nothing + kSNUse, // USE | hint for using + kSNPause, // PAUSE -1 oczekiwanie /72 sekund :: delay /72 seconds + kSNInf, // INF -1 prezentacja tekstu o numerze :: show text referrenced by + kSNCave, // CAVE -1 przejœcie na planszê :: go to board + kSNSlave, // SLAVE + kSNFocus, // FOCUS zmiana aktywnego bohatera (-1 cyklicznie) :: change active hero + kSNSetX, // SETX ustawienie przesuniêcia sprajtu :: set sprite shift in x axis + kSNSetY, // SETX ustawienie przesuniêcia sprajtu :: set sprite shift in y axis + kSNSetZ, // SETX ustawienie przesuniêcia sprajtu :: set sprite shift in z axis + kSNAdd, // ADD suma dwóch wektorów :: sum vectors + kSNSub, // SUB ró¿nica dwóch wektorów :: subtract vectors + kSNMul, // MUL iloczyn wektora przez liczbê :: multiply vector by number + kSNDiv, // DIV iloraz wektora przez liczbê :: divide vector by number + kSNIf, // IF + kSNFlag, // FLAG nadanie wartoœci znacznikowi :: set flag to + kSNFlash, // FLASH -1 0|1 rozjaœnienie ca³ego obrazu (tak/nie) :: lighten whole image (on/off) + kSNLight, // LIGHT + kSNCycle, // CYCLE cykliczne przesuwanie kolorow od 1 :: rotate colors from 1 + kSNClear, // CLEAR -1 0 wyzerowanie kolejki kSNAIL :: clear kSNAIL queue + kSNTalk, // TALK -1 0|1 zezwolenie na dialogi (tak/nie) :: enable speach (on/off) + kSNMouse, // MOUSE -1 0|1 zezwolenie na mysz (tak/nie) :: enable mouse (on/off) + kSNMap, // MAP 0|1 0 chwilowe wylaczenie mapy dla bohatera :: temporarily turn off map for hero + kSNCount, // COUNT + kSNMidi, // MIDI -1 muzyka MIDI nr (-1 = cisza) :: play MIDI referenced by (-1 = off) + kSNSetDlg, // SETDLG 0..3 0..3 przelaczenie trybu mowy :: switch of speach mode + kSNMskDlg, // MSKDLG 0..3 0..3 przelaczenie maski trybu mowy :: switch of speach mode mask + + kSNSpr, + + kSNWait, // WAIT |-1 oczekiwanie na SEQ (-1 = stoi) :: wait for SEQ (-1 = freeze) + kSNHide, // HIDE 0|1 widzialnoœæ sprajtu :: visibility of sprite + kSNRoom, // ROOM 0|1 dodatkowe miejsce w kieszeni (nie/tak) :: additional room in pocket (no/yes) + kSNSay, // SAY wyg³oszenie tekstu o numerze :: say text referenced by + kSNSound, // SOUND wyemitowanie efektu :: play sound effect referenced by + kSNTime, // TIME 0 wyg³oszenie bie¿¹cego czasu :: say current time + kSNKill, // KILL 0 usuniêcie sprajtu :: remove sprite + kSNRSeq, // RSEQ wzglêdny skok SEQ o :: relative jump SEQ lines + kSNSeq, // SEQ skok do SEQ :: jump to certain SEQ + kSNSend, // SEND przeniesienie sprajtu na planszê :: move sprite to board + kSNSwap, // SWAP spr2> zamiana sprajtów :: sprite exchange + kSNKeep, // KEEP sprajt do kieszeni ze skokiem do :: take sprite into pocket and jump to + kSNGive, // GIVE sprajt z kieszeni ze skokiem do :: remove sprite from pocket and jump to + kSNGetPos, // GETPOS pobranie pozycji sprajtu :: take sprite's position + kSNGoto, // GOTO przesuniêcie sprajtu na dana pozycje :: move sprite to position + kSNMoveX, // MOVEX przesuniêcie wzglêdne po osi X :: relative move along X axis + kSNMoveY, // MOVEY przesuniêcie wzglêdne po osi Y :: relative move along Y axis + kSNMoveZ, // MOVEZ przesuniêcie wzglêdne po osi Z :: relative move along Z axis + kSNTrans, // TRANS 0|1 ustalenie przezroczystoœci logicznej :: clear/set logical transparency + kSNPort, // PORT 0|1 ustalenie "bralnoœci" sprajtu :: clear/set "takeability" of sprite + kSNNext, // NEXT skok do - NEAR lub TAKE :: jump to - NEAR or TAKE + kSNNNext, // NNEXT skok do - NEAR :: jump to - NEAR + kSNMTNext, // MTNEXT skok do - TAKE :: jump to - TAKE + kSNFTNext, // FTNEXT skok do - TAKE :: jump to - TAKE + kSNRNNext, // RNNEXT skok wzglêdny do - NEAR :: relative jump to - NEAR + kSNRMTNext, // RMTNEXT skok wzglêdny do - TAKE :: relative jump to - TAKE + kSNRFTNext, // RFTNEXT skok wzglêdny do - TAKE :: relative jump to - TAKE + kSNRMNear, // RMNEAR 0 usuniêcie listy NEAR :: remove NEAR list + kSNRMMTake, // RMMTAKE 0 usuniêcie listy TAKE :: remove TAKE list + kSNRMFTake, // RMFTAKE 0 usuniêcie listy TAKE :: remove TAKE list + kSNSetRef, // RETREF zmiana numeru sprajta :: change reference of sprite to + kSNBackPt, // BACKPT 0 wmalowanie sprajtu w t³o :: paint sprite onto the background + kSNWalk, // WALK | podejd¿ do sprajtu lub punktu :: go close to the sprite or point + kSNReach, // REACH | siêgnij do lub sposobem :: reach the sprite or point with method + kSNCover, // COVER przykrycie sprajtu sprajtem :: cover sprite with sprite + kSNUncover, // UNCOVER odtworzenie sytuacji sprzed COVER :: restore the state before COVER + + kSNDim, + kSNExec, + kSNStep, + kSNGhost, + + kSNNOne = kNoByte +}; + +class Snail { + static const char *comTxt[]; +public: + static int com(const char *com); +}; + } // End of namespace CGE2 #endif diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 26fba8bfd8..1d757ff63f 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -56,6 +56,10 @@ Seq *getConstantSeq(bool seqFlag) { return seq; } +Sprite::Sprite(CGE2Engine *vm) { + warning("STUB: Sprite::Sprite()"); +} + Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), @@ -74,10 +78,7 @@ Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) } Sprite::~Sprite() { - if (_vm->_sprite == this) - _vm->_sprite = NULL; - - contract(); + warning("STUB: Sprite::~Sprite()"); } BitmapPtr Sprite::shp() { @@ -110,7 +111,10 @@ BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { } expand(); _ext->_shpList = shpP; - _flags._bDel = true; + + //_flags._bDel = true; + warning("STUB: Sprite::sync() - Flags changed compared to CGE1's Sprite type."); + if (!_ext->_seq) setSeq(getConstantSeq(_shpCnt < 2)); } @@ -371,7 +375,7 @@ void Sprite::step(int nr) { _seqPtr = _ext->_seq[_seqPtr]._next; seq = _ext->_seq + _seqPtr; if (seq->_dly >= 0) { - gotoxy(_x + (seq->_dx), _y + (seq->_dy)); + gotoxyz(_x + (seq->_dx), _y + (seq->_dy)); _time = seq->_dly; } } @@ -404,31 +408,28 @@ void Sprite::killXlat() { _flags._xlat = false; } -void Sprite::gotoxy(int x, int y) { - int xo = _x, yo = _y; - if (_x < kScrWidth) { - if (x < 0) - x = 0; - if (x + _w > kScrWidth) - x = (kScrWidth - _w); - _x = x; - } - if (_h < kScrHeight) { - if (y < 0) - y = 0; - if (y + _h > kScrHeight) - y = (kScrHeight - _h); - _y = y; - } - if (_next) - if (_next->_flags._slav) - _next->gotoxy(_next->_x - xo + _x, _next->_y - yo + _y); - if (_flags._shad) - _prev->gotoxy(_prev->_x - xo + _x, _prev->_y - yo + _y); +void Sprite::gotoxyz(int x, int y, int z) { + warning("STUB: Sprite::gotoxyz()"); +} + +void Sprite::gotoxyz(void) { + warning("STUB: Sprite::gotoxyz()"); +} + +void Sprite::gotoxyz(V2D pos) { + warning("STUB: Sprite::gotoxyz()"); +} + +void Sprite::gotoxyz_(V2D pos) { + warning("STUB: Sprite::gotoxyz()"); +} + +void Sprite::gotoxyz(V3D pos) { + warning("STUB: Sprite::gotoxyz()"); } void Sprite::center() { - gotoxy((kScrWidth - _w) / 2, (kScrHeight - _h) / 2); + gotoxyz((kScrWidth - _w) / 2, (kScrHeight - _h) / 2); } void Sprite::show() { @@ -494,9 +495,9 @@ void Sprite::sync(Common::Serializer &s) { _flags._near = flags & 0x0002 ? true : false; _flags._drag = flags & 0x0004 ? true : false; _flags._hold = flags & 0x0008 ? true : false; - _flags._dummy = flags & 0x0010 ? true : false; + //_flags._dummy = flags & 0x0010 ? true : false; _flags._slav = flags & 0x0020 ? true : false; - _flags._syst = flags & 0x0040 ? true : false; + //_flags._syst = flags & 0x0040 ? true : false; _flags._kill = flags & 0x0080 ? true : false; _flags._xlat = flags & 0x0100 ? true : false; _flags._port = flags & 0x0200 ? true : false; @@ -504,11 +505,11 @@ void Sprite::sync(Common::Serializer &s) { _flags._east = flags & 0x0800 ? true : false; _flags._shad = flags & 0x1000 ? true : false; _flags._back = flags & 0x2000 ? true : false; - _flags._bDel = flags & 0x4000 ? true : false; + //_flags._bDel = flags & 0x4000 ? true : false; _flags._tran = flags & 0x8000 ? true : false; } else { flags = (flags << 1) | _flags._tran; - flags = (flags << 1) | _flags._bDel; + //flags = (flags << 1) | _flags._bDel; flags = (flags << 1) | _flags._back; flags = (flags << 1) | _flags._shad; flags = (flags << 1) | _flags._east; @@ -516,9 +517,9 @@ void Sprite::sync(Common::Serializer &s) { flags = (flags << 1) | _flags._port; flags = (flags << 1) | _flags._xlat; flags = (flags << 1) | _flags._kill; - flags = (flags << 1) | _flags._syst; + //flags = (flags << 1) | _flags._syst; flags = (flags << 1) | _flags._slav; - flags = (flags << 1) | _flags._dummy; + //flags = (flags << 1) | _flags._dummy; flags = (flags << 1) | _flags._hold; flags = (flags << 1) | _flags._drag; flags = (flags << 1) | _flags._near; @@ -526,6 +527,8 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(flags); } + warning("STUB: Sprite::sync() - Flags changed compared to CGE1's Sprite type."); + s.syncAsUint16LE(_x); s.syncAsUint16LE(_y); s.syncAsByte(_z); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index b7325d8b9a..8061acf411 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -33,7 +33,7 @@ #include "graphics/surface.h" #include "cge2/general.h" #include "cge2/bitmap.h" -//#include "cge/snail.h" +#include "cge2/snail.h" #include "cge2/cge2.h" namespace CGE2 { @@ -89,20 +89,20 @@ public: signed char _scene; struct Flags { uint16 _hide : 1; // general visibility switch - uint16 _near : 1; // Near action lock uint16 _drag : 1; // sprite is moveable uint16 _hold : 1; // sprite is held with mouse - uint16 _dummy : 1; // intrrupt driven animation + uint16 _trim : 1; // Trim flag uint16 _slav : 1; // slave object - uint16 _syst : 1; // system object uint16 _kill : 1; // dispose memory after remove uint16 _xlat : 1; // 2nd way display: xlat table uint16 _port : 1; // portable uint16 _kept : 1; // kept in pocket + uint16 _frnt : 1; // stay in front of sprite uint16 _east : 1; // talk to east (in opposite to west) + uint16 _near : 1; // Near action lock uint16 _shad : 1; // shadow uint16 _back : 1; // 'send to background' request - uint16 _bDel : 1; // delete bitmaps in ~SPRITE + uint16 _zmov : 1; // sprite needs Z-update in queue uint16 _tran : 1; // transparent (untouchable) } _flags; int _x; @@ -118,6 +118,7 @@ public: char _file[kMaxFile]; Sprite *_prev; Sprite *_next; + struct { byte _ptr, _cnt; } _actionCtrl[kActions]; bool works(Sprite *spr); bool seqTest(int n); @@ -125,6 +126,7 @@ public: return _ext != NULL; } + Sprite(CGE2Engine *vm); Sprite(CGE2Engine *vm, BitmapPtr *shp); virtual ~Sprite(); BitmapPtr shp(); @@ -136,7 +138,11 @@ public: inline char *name() { return (_ext) ? _ext->_name : NULL; } - void gotoxy(int x, int y); + void gotoxyz(int x, int y, int z = 0); + void gotoxyz(void); + void gotoxyz(V2D pos); + void gotoxyz_(V2D pos); + void gotoxyz(V3D pos); void center(); void show(); void hide(); -- cgit v1.2.3 From 09b4092d530d99ba6b7c1aba9a009b39591a95dd Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 9 May 2014 13:25:11 +0200 Subject: CGE2: Remove Polish comments form SNCom. --- engines/cge2/snail.h | 118 +++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 5cdb22150f..80aa33f5d5 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -36,72 +36,72 @@ enum Action { kNear, kMTake, kFTake, kActions }; enum SNCom { kSNCom0 = 128, - kSNNop, // NOP instrukcja "pusta" :: do nothing - kSNUse, // USE | hint for using - kSNPause, // PAUSE -1 oczekiwanie /72 sekund :: delay /72 seconds - kSNInf, // INF -1 prezentacja tekstu o numerze :: show text referrenced by - kSNCave, // CAVE -1 przejœcie na planszê :: go to board + kSNNop, // NOP :: do nothing + kSNUse, // USE | :: hint for using + kSNPause, // PAUSE -1 :: delay /72 seconds + kSNInf, // INF -1 :: show text referrenced by + kSNCave, // CAVE -1 :: go to board kSNSlave, // SLAVE - kSNFocus, // FOCUS zmiana aktywnego bohatera (-1 cyklicznie) :: change active hero - kSNSetX, // SETX ustawienie przesuniêcia sprajtu :: set sprite shift in x axis - kSNSetY, // SETX ustawienie przesuniêcia sprajtu :: set sprite shift in y axis - kSNSetZ, // SETX ustawienie przesuniêcia sprajtu :: set sprite shift in z axis - kSNAdd, // ADD suma dwóch wektorów :: sum vectors - kSNSub, // SUB ró¿nica dwóch wektorów :: subtract vectors - kSNMul, // MUL iloczyn wektora przez liczbê :: multiply vector by number - kSNDiv, // DIV iloraz wektora przez liczbê :: divide vector by number + kSNFocus, // FOCUS :: change active hero + kSNSetX, // SETX :: set sprite shift in x axis + kSNSetY, // SETX :: set sprite shift in y axis + kSNSetZ, // SETX :: set sprite shift in z axis + kSNAdd, // ADD :: sum vectors + kSNSub, // SUB :: subtract vectors + kSNMul, // MUL :: multiply vector by number + kSNDiv, // DIV :: divide vector by number kSNIf, // IF - kSNFlag, // FLAG nadanie wartoœci znacznikowi :: set flag to - kSNFlash, // FLASH -1 0|1 rozjaœnienie ca³ego obrazu (tak/nie) :: lighten whole image (on/off) + kSNFlag, // FLAG :: set flag to + kSNFlash, // FLASH -1 0|1 :: lighten whole image (on/off) kSNLight, // LIGHT - kSNCycle, // CYCLE cykliczne przesuwanie kolorow od 1 :: rotate colors from 1 - kSNClear, // CLEAR -1 0 wyzerowanie kolejki kSNAIL :: clear kSNAIL queue - kSNTalk, // TALK -1 0|1 zezwolenie na dialogi (tak/nie) :: enable speach (on/off) - kSNMouse, // MOUSE -1 0|1 zezwolenie na mysz (tak/nie) :: enable mouse (on/off) - kSNMap, // MAP 0|1 0 chwilowe wylaczenie mapy dla bohatera :: temporarily turn off map for hero + kSNCycle, // CYCLE :: rotate colors from 1 + kSNClear, // CLEAR -1 0 :: clear kSNAIL queue + kSNTalk, // TALK -1 0|1 :: enable speach (on/off) + kSNMouse, // MOUSE -1 0|1 :: enable mouse (on/off) + kSNMap, // MAP 0|1 0 :: temporarily turn off map for hero kSNCount, // COUNT - kSNMidi, // MIDI -1 muzyka MIDI nr (-1 = cisza) :: play MIDI referenced by (-1 = off) - kSNSetDlg, // SETDLG 0..3 0..3 przelaczenie trybu mowy :: switch of speach mode - kSNMskDlg, // MSKDLG 0..3 0..3 przelaczenie maski trybu mowy :: switch of speach mode mask + kSNMidi, // MIDI -1 :: play MIDI referenced by (-1 = off) + kSNSetDlg, // SETDLG 0..3 0..3 :: switch of speach mode + kSNMskDlg, // MSKDLG 0..3 0..3 :: switch of speach mode mask kSNSpr, - kSNWait, // WAIT |-1 oczekiwanie na SEQ (-1 = stoi) :: wait for SEQ (-1 = freeze) - kSNHide, // HIDE 0|1 widzialnoœæ sprajtu :: visibility of sprite - kSNRoom, // ROOM 0|1 dodatkowe miejsce w kieszeni (nie/tak) :: additional room in pocket (no/yes) - kSNSay, // SAY wyg³oszenie tekstu o numerze :: say text referenced by - kSNSound, // SOUND wyemitowanie efektu :: play sound effect referenced by - kSNTime, // TIME 0 wyg³oszenie bie¿¹cego czasu :: say current time - kSNKill, // KILL 0 usuniêcie sprajtu :: remove sprite - kSNRSeq, // RSEQ wzglêdny skok SEQ o :: relative jump SEQ lines - kSNSeq, // SEQ skok do SEQ :: jump to certain SEQ - kSNSend, // SEND przeniesienie sprajtu na planszê :: move sprite to board - kSNSwap, // SWAP spr2> zamiana sprajtów :: sprite exchange - kSNKeep, // KEEP sprajt do kieszeni ze skokiem do :: take sprite into pocket and jump to - kSNGive, // GIVE sprajt z kieszeni ze skokiem do :: remove sprite from pocket and jump to - kSNGetPos, // GETPOS pobranie pozycji sprajtu :: take sprite's position - kSNGoto, // GOTO przesuniêcie sprajtu na dana pozycje :: move sprite to position - kSNMoveX, // MOVEX przesuniêcie wzglêdne po osi X :: relative move along X axis - kSNMoveY, // MOVEY przesuniêcie wzglêdne po osi Y :: relative move along Y axis - kSNMoveZ, // MOVEZ przesuniêcie wzglêdne po osi Z :: relative move along Z axis - kSNTrans, // TRANS 0|1 ustalenie przezroczystoœci logicznej :: clear/set logical transparency - kSNPort, // PORT 0|1 ustalenie "bralnoœci" sprajtu :: clear/set "takeability" of sprite - kSNNext, // NEXT skok do - NEAR lub TAKE :: jump to - NEAR or TAKE - kSNNNext, // NNEXT skok do - NEAR :: jump to - NEAR - kSNMTNext, // MTNEXT skok do - TAKE :: jump to - TAKE - kSNFTNext, // FTNEXT skok do - TAKE :: jump to - TAKE - kSNRNNext, // RNNEXT skok wzglêdny do - NEAR :: relative jump to - NEAR - kSNRMTNext, // RMTNEXT skok wzglêdny do - TAKE :: relative jump to - TAKE - kSNRFTNext, // RFTNEXT skok wzglêdny do - TAKE :: relative jump to - TAKE - kSNRMNear, // RMNEAR 0 usuniêcie listy NEAR :: remove NEAR list - kSNRMMTake, // RMMTAKE 0 usuniêcie listy TAKE :: remove TAKE list - kSNRMFTake, // RMFTAKE 0 usuniêcie listy TAKE :: remove TAKE list - kSNSetRef, // RETREF zmiana numeru sprajta :: change reference of sprite to - kSNBackPt, // BACKPT 0 wmalowanie sprajtu w t³o :: paint sprite onto the background - kSNWalk, // WALK | podejd¿ do sprajtu lub punktu :: go close to the sprite or point - kSNReach, // REACH | siêgnij do lub sposobem :: reach the sprite or point with method - kSNCover, // COVER przykrycie sprajtu sprajtem :: cover sprite with sprite - kSNUncover, // UNCOVER odtworzenie sytuacji sprzed COVER :: restore the state before COVER + kSNWait, // WAIT |-1 :: wait for SEQ (-1 = freeze) + kSNHide, // HIDE 0|1 :: visibility of sprite + kSNRoom, // ROOM 0|1 :: additional room in pocket (no/yes) + kSNSay, // SAY :: say text referenced by + kSNSound, // SOUND :: play sound effect referenced by + kSNTime, // TIME 0 :: say current time + kSNKill, // KILL 0 :: remove sprite + kSNRSeq, // RSEQ :: relative jump SEQ lines + kSNSeq, // SEQ :: jump to certain SEQ + kSNSend, // SEND :: move sprite to board + kSNSwap, // SWAP spr2> :: sprite exchange + kSNKeep, // KEEP :: take sprite into pocket and jump to + kSNGive, // GIVE :: remove sprite from pocket and jump to + kSNGetPos, // GETPOS :: take sprite's position + kSNGoto, // GOTO :: move sprite to position + kSNMoveX, // MOVEX :: relative move along X axis + kSNMoveY, // MOVEY :: relative move along Y axis + kSNMoveZ, // MOVEZ :: relative move along Z axis + kSNTrans, // TRANS 0|1 :: clear/set logical transparency + kSNPort, // PORT 0|1 :: clear/set "takeability" of sprite + kSNNext, // NEXT :: jump to - NEAR or TAKE + kSNNNext, // NNEXT :: jump to - NEAR + kSNMTNext, // MTNEXT :: jump to - TAKE + kSNFTNext, // FTNEXT :: jump to - TAKE + kSNRNNext, // RNNEXT :: relative jump to - NEAR + kSNRMTNext, // RMTNEXT :: relative jump to - TAKE + kSNRFTNext, // RFTNEXT :: relative jump to - TAKE + kSNRMNear, // RMNEAR 0 :: remove NEAR list + kSNRMMTake, // RMMTAKE 0 :: remove TAKE list + kSNRMFTake, // RMFTAKE 0 :: remove TAKE list + kSNSetRef, // RETREF :: change reference of sprite to + kSNBackPt, // BACKPT 0 :: paint sprite onto the background + kSNWalk, // WALK | :: go close to the sprite or point + kSNReach, // REACH | :: reach the sprite or point with method + kSNCover, // COVER :: cover sprite with sprite + kSNUncover, // UNCOVER :: restore the state before COVER kSNDim, kSNExec, -- cgit v1.2.3 From c75c026df8897c3a7aa4721a4e8f204e92f08daf Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 10 May 2014 10:11:02 +0200 Subject: CGE2: Reimplement constructors of Sprite. --- engines/cge2/vga13h.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 1d757ff63f..a696cad554 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -56,23 +56,39 @@ Seq *getConstantSeq(bool seqFlag) { return seq; } -Sprite::Sprite(CGE2Engine *vm) { - warning("STUB: Sprite::Sprite()"); +byte Sprite::_constY = 0; +byte Sprite::_follow = 0; + +Sprite::Sprite(CGE2Engine *vm) + : _siz(0, 0), _nearPtr(0), _takePtr(0), + _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), + _ext(NULL), _ref(-1), _scene(0), _vm(vm), + _pos2D(kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { + memset(_actionCtrl, 0, sizeof(_actionCtrl)); + memset(_file, 0, sizeof(_file)); + memset(&_flags, 0, sizeof(_flags)); + _flags._frnt = 1; + + _ref = 0; + _w = _h = 0; + _seqPtr = 0; + _shpCnt = 0; } Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) - : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), + : _siz(0, 0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), - _ext(NULL), _ref(-1), _scene(0), _vm(vm) { + _ext(NULL), _ref(-1), _scene(0), _vm(vm), + _pos2D(kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { + memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); + _flags._frnt = 1; + _ref = 0; - _x = _y = 0; _w = _h = 0; - _time = 0; _seqPtr = 0; _shpCnt = 0; - _prev = _next = NULL; setShapeList(shpP); } -- cgit v1.2.3 From 724899fc1939e26b1805deb9f9c9c7fc19c9a5ee Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 10 May 2014 11:12:30 +0200 Subject: CGE2: Rework Sprite a bit, make _eye an engine variable. Also move screenToGround() during the process. --- engines/cge2/cge2.cpp | 6 +++++- engines/cge2/cge2.h | 5 ++++- engines/cge2/general.h | 46 +++++++++++++++++++++------------------------- engines/cge2/hero.cpp | 7 +++++++ engines/cge2/hero.h | 13 +++++++++++-- engines/cge2/vga13h.cpp | 46 +++++++++++----------------------------------- engines/cge2/vga13h.h | 8 +++++--- 7 files changed, 64 insertions(+), 67 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index c3ec6a92eb..986c616b65 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -33,6 +33,7 @@ #include "cge2/sound.h" #include "cge2/text.h" #include "cge2/hero.h" +#include "cge2/general.h" namespace CGE2 { @@ -47,6 +48,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _text = nullptr; for (int i = 0; i < 2; i++) _heroTab[i] = nullptr; + _eye = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -65,7 +67,8 @@ void CGE2Engine::init() { _midiPlayer = new MusicPlayer(this); _text = new Text(this, "CGE"); for (int i = 0; i < 2; i++) - _heroTab[i] = new HeroTab(); + _heroTab[i] = new HeroTab(this); + _eye = new V3D(); } void CGE2Engine::deinit() { @@ -78,6 +81,7 @@ void CGE2Engine::deinit() { delete _text; for (int i = 0; i < 2; i++) delete _heroTab[i]; + delete _eye; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 79ac2c7488..e4a40426f7 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -32,7 +32,6 @@ #include "engines/advancedDetector.h" #include "common/system.h" #include "cge2/fileio.h" -#include "cge2/general.h" namespace CGE2 { @@ -43,6 +42,9 @@ class Fx; class Sound; class Text; struct HeroTab; +class V3D; +class V2D; +class Dac; #define kScrWidth 320 #define kScrHeight 240 @@ -91,6 +93,7 @@ public: Sound *_sound; Text *_text; HeroTab *_heroTab[2]; + V3D *_eye; private: void init(); void deinit(); diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 9da00be6cd..9c89f525ac 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -31,6 +31,7 @@ #include "common/file.h" #include "common/rect.h" #include "cge2/fileio.h" +#include "cge2/cge2.h" namespace CGE2 { @@ -60,49 +61,44 @@ public: }; class V2D : public Common::Point { - static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } - static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } + CGE2Engine *_vm; public: V2D& operator = (const V3D& p3) { - double m = Eye._z / (p3._z - Eye._z); - x = round((Eye._x + (Eye._x - p3._x) * m)); - y = round((Eye._y + (Eye._y - p3._y) * m)); + double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); + x = round((_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m)); + y = round((_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m)); return *this; } - V2D(void) { } - V2D(const V3D& p3) { *this = p3; } - V2D(int x, int y) : Common::Point(x, y) { } - static V3D Eye; - static void setEye(const V3D &e) { Eye = e; } - static void setEye(const V2D& e2, int z = -SCR_WID_) { - Eye._x = e2.x; Eye._y = e2.y; Eye._z = z; + V2D(CGE2Engine *vm) : _vm(vm) { } + V2D(CGE2Engine *vm, const V3D& p3) : _vm(vm) { *this = p3; } + V2D(CGE2Engine *vm, int x, int y) : _vm(vm), Common::Point(x, y) { } + void setEye(V3D &e) { _vm->_eye = &e; } + void setEye(const V2D& e2, int z = -SCR_WID_) { + _vm->_eye->_x = e2.x; _vm->_eye->_y = e2.y; _vm->_eye->_z = z; } - static void setEye(const char *s) { + void setEye(const char *s) { char *tempStr; strcpy(tempStr, s); - Eye._x = atoi(EncryptedStream::token(tempStr)); - Eye._y = atoi(EncryptedStream::token(tempStr)); - Eye._z = atoi(EncryptedStream::token(tempStr)); + _vm->_eye->_x = atoi(EncryptedStream::token(tempStr)); + _vm->_eye->_y = atoi(EncryptedStream::token(tempStr)); + _vm->_eye->_z = atoi(EncryptedStream::token(tempStr)); } bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } bool operator >(const V2D& p) const { return (x > p.x) && (y > p.y); } bool operator >= (const V2D& p) const { return (x >= p.x) && (y >= p.y); } - V2D operator + (const V2D& p) const { return V2D(x + p.x, y + p.y); } - V2D operator - (const V2D& p) const { return V2D(x - p.x, y - p.y); } + V2D operator + (const V2D& p) const { return V2D(_vm, x + p.x, y + p.y); } + V2D operator - (const V2D& p) const { return V2D(_vm, x - p.x, y - p.y); } uint16 area(void) { return x * y; } bool limited(const V2D& p) { return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); } V2D scale(int z) { - double m = Eye._z / (Eye._z - z); - return V2D(trunc(m * x), trunc(m * y)); - } - static V3D screenToGround(V2D pos) { - double z = V2D::Eye._z + (V2D::Eye._y*V2D::Eye._z) / (double(pos.y) - V2D::Eye._y); - double x = V2D::Eye._x - ((double(pos.x) - V2D::Eye._x) * (z - V2D::Eye._z)) / V2D::Eye._z; - return V3D(round(x), 0, round(z)); + double m = _vm->_eye->_z / (_vm->_eye->_z - z); + return V2D(_vm, trunc(m * x), trunc(m * y)); } + static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } + static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } }; } // End of namespace CGE2 diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 44ff85040d..3a6d1d2920 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -117,6 +117,13 @@ void Hero::walkTo(Sprite *spr) { warning("STUB: Hero::walkTo()"); } +V3D Hero::screenToGround(V2D pos) { + double z = _vm->_eye->_z + (_vm->_eye->_y * _vm->_eye->_z) / (double(pos.y) - _vm->_eye->_y); + double x = _vm->_eye->_x - ((double(pos.x) - _vm->_eye->_x) * (z - _vm->_eye->_z)) / _vm->_eye->_z; + return V3D(V2D::round(x), 0, V2D::round(z)); +} + + int Hero::cross(const V2D &a, const V2D &b) { warning("STUB: Hero::cross()"); return 0; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 21f4ec39e7..032a46d1b3 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -42,7 +42,15 @@ struct HeroTab { Sprite *_face; Sprite *_pocket[kPocketMax + 1]; int _pocPtr; - V2D _posTab[kCaveMax]; + V2D *_posTab[kCaveMax]; + HeroTab(CGE2Engine *vm) { + for (int i = 0; i < kCaveMax; i++) + _posTab[i] = new V2D(vm); + } + ~HeroTab() { + for (int i = 0; i < kCaveMax; i++) + delete _posTab[i]; + } }; class Hero : public Sprite { @@ -72,7 +80,8 @@ public: bool findWay(void); static int snap(int p, int q, int grid); void walkTo(V3D pos); - void walkTo(V2D pos) { walkTo(V2D::screenToGround(pos)); } + void walkTo(V2D pos) { walkTo(screenToGround(pos)); } + V3D screenToGround(V2D pos); void walkTo(Sprite *spr); void say(void) { step(_sayStart); } void fun(void); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index a696cad554..0a9add0633 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -60,10 +60,10 @@ byte Sprite::_constY = 0; byte Sprite::_follow = 0; Sprite::Sprite(CGE2Engine *vm) - : _siz(0, 0), _nearPtr(0), _takePtr(0), + : _siz(_vm, 0, 0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), _ext(NULL), _ref(-1), _scene(0), _vm(vm), - _pos2D(kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { + _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); @@ -76,10 +76,10 @@ Sprite::Sprite(CGE2Engine *vm) } Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) - : _siz(0, 0), _nearPtr(0), _takePtr(0), + : _siz(_vm, 0, 0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), _ext(NULL), _ref(-1), _scene(0), _vm(vm), - _pos2D(kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { + _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); @@ -383,18 +383,7 @@ Sprite *Sprite::backShow(bool fast) { } void Sprite::step(int nr) { - if (nr >= 0) - _seqPtr = nr; - if (_ext) { - Seq *seq; - if (nr < 0) - _seqPtr = _ext->_seq[_seqPtr]._next; - seq = _ext->_seq + _seqPtr; - if (seq->_dly >= 0) { - gotoxyz(_x + (seq->_dx), _y + (seq->_dy)); - _time = seq->_dly; - } - } + warning("STUB: Sprite::step()"); } //void Sprite::tick() { @@ -449,26 +438,13 @@ void Sprite::center() { } void Sprite::show() { - SprExt *e; - e = _ext; - e->_x0 = e->_x1; - e->_y0 = e->_y1; - e->_b0 = e->_b1; - e->_x1 = _x; - e->_y1 = _y; - e->_b1 = shp(); - if (!_flags._hide) { - if (_flags._xlat) - e->_b1->xShow(e->_x1, e->_y1); - else - e->_b1->show(e->_x1, e->_y1); - } + warning("STUB: Sprite::show()"); } void Sprite::show(uint16 pg) { Graphics::Surface *a = _vm->_vga->_page[1]; _vm->_vga->_page[1] = _vm->_vga->_page[pg & 3]; - shp()->show(_x, _y); + shp()->show(_pos2D.x, _pos2D.y); _vm->_vga->_page[1] = a; } @@ -545,9 +521,9 @@ void Sprite::sync(Common::Serializer &s) { warning("STUB: Sprite::sync() - Flags changed compared to CGE1's Sprite type."); - s.syncAsUint16LE(_x); - s.syncAsUint16LE(_y); - s.syncAsByte(_z); + s.syncAsUint16LE(_pos3D._x); + s.syncAsUint16LE(_pos3D._y); + s.syncAsByte(_pos3D._z); s.syncAsUint16LE(_w); s.syncAsUint16LE(_h); s.syncAsUint16LE(_time); @@ -614,7 +590,7 @@ void Queue::insert(Sprite *spr, Sprite *nxt) { void Queue::insert(Sprite *spr) { Sprite *s; for (s = _head; s; s = s->_next) - if (s->_z > spr->_z) + if (s->_pos3D._z > spr->_pos3D._z) break; if (s) insert(spr, s); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 8061acf411..487df10ba8 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -105,9 +105,6 @@ public: uint16 _zmov : 1; // sprite needs Z-update in queue uint16 _tran : 1; // transparent (untouchable) } _flags; - int _x; - int _y; - signed char _z; uint16 _w; uint16 _h; uint16 _time; @@ -119,6 +116,11 @@ public: Sprite *_prev; Sprite *_next; struct { byte _ptr, _cnt; } _actionCtrl[kActions]; + V2D _pos2D; + V3D _pos3D; + V2D _siz; + static byte _constY; + static byte _follow; bool works(Sprite *spr); bool seqTest(int n); -- cgit v1.2.3 From 3af6ff54570d290e80f4cf77b1beab071a39b026 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 10 May 2014 14:03:27 +0200 Subject: CGE2: Implement Sprite::gotoxyz(). --- engines/cge2/cge2.h | 2 ++ engines/cge2/vga13h.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index e4a40426f7..f3cf574faf 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -48,6 +48,8 @@ class Dac; #define kScrWidth 320 #define kScrHeight 240 +#define kPanHeight 40 +#define kWorldHeight (kScrHeight - kPanHeight) #define kMaxFile 128 #define kPathMax 128 #define kDimMax 8 diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 0a9add0633..22bd4f4a18 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -414,23 +414,78 @@ void Sprite::killXlat() { } void Sprite::gotoxyz(int x, int y, int z) { - warning("STUB: Sprite::gotoxyz()"); + gotoxyz(V3D(x, y, z)); } void Sprite::gotoxyz(void) { - warning("STUB: Sprite::gotoxyz()"); + gotoxyz(_pos3D); } void Sprite::gotoxyz(V2D pos) { - warning("STUB: Sprite::gotoxyz()"); + V2D o = _pos2D; + int ctr = _siz.x >> 1; + int rem = _siz.x - ctr; + byte trim = 0; + + if (_ref / 10 == 14) { // HERO + int z = V2D::trunc(_pos3D._z); + ctr = (ctr * V2D::trunc(_vm->_eye->_z) / (V2D::trunc(_vm->_eye->_z) - z)); + rem = (rem * V2D::trunc(_vm->_eye->_z) / (V2D::trunc(_vm->_eye->_z) - z)); + ctr = (ctr * 3) / 4; + rem = (rem * 3) / 4; + } + + if (pos.x - ctr < 0) { + pos.x = ctr; + ++trim; + } + if (pos.x + rem > kScrWidth) { + pos.x = kScrWidth - rem; + ++trim; + } + _pos2D.x = pos.x; + + if (pos.y < -kPanHeight) { + pos.y = -kPanHeight; + ++trim; + } + if (pos.y + _siz.y > kWorldHeight) { + pos.y = kWorldHeight - _siz.y; + ++trim; + } + _pos2D.y = pos.y; + + _flags._trim = (trim != 0); + + if (!_follow) { + double m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); + _pos3D._x = (_vm->_eye->_x + V2D::round(_vm->_eye->_x - _pos2D.x) / m); + if (!_constY) + _pos3D._y = (_vm->_eye->_y + V2D::round(_vm->_eye->_y - _pos2D.y) / m); + } + + if (_next && _next->_flags._slav) + _next->gotoxyz(_next->_pos2D - o + _pos2D); + + if (_flags._shad) + _prev->gotoxyz(_prev->_pos2D - o + _pos2D); + + if (_ref == 141 && _pos3D._y >= 5) + warning("Sprite::gotoxyz - asm nop"); } void Sprite::gotoxyz_(V2D pos) { - warning("STUB: Sprite::gotoxyz()"); + _constY++; + gotoxyz(pos); + --_constY; } void Sprite::gotoxyz(V3D pos) { - warning("STUB: Sprite::gotoxyz()"); + _follow++; + if (pos._z != _pos3D._z) + _flags._zmov = true; + gotoxyz(V2D(_vm, _pos3D = pos)); + --_follow; } void Sprite::center() { -- cgit v1.2.3 From 89bece4b420f90c1fd3adc6b63fe05a9815f5957 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 10 May 2014 14:45:02 +0200 Subject: CGE2: Implement ~Sprite(). --- engines/cge2/vga13h.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 22bd4f4a18..ada6642831 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -94,7 +94,10 @@ Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) } Sprite::~Sprite() { - warning("STUB: Sprite::~Sprite()"); + if (_vm->_sprite == this) + _vm->_sprite = NULL; + + contract(); } BitmapPtr Sprite::shp() { -- cgit v1.2.3 From 49d78527922f65c400056f0b4f98c26ee9d3a9c5 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 12 May 2014 22:24:21 +0200 Subject: CGE2: Add Spare. --- engines/cge2/cge2.cpp | 4 +++ engines/cge2/cge2.h | 2 ++ engines/cge2/module.mk | 3 +- engines/cge2/spare.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/spare.h | 53 ++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 engines/cge2/spare.cpp create mode 100644 engines/cge2/spare.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 986c616b65..c9fb590400 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -34,6 +34,7 @@ #include "cge2/text.h" #include "cge2/hero.h" #include "cge2/general.h" +#include "cge2/spare.h" namespace CGE2 { @@ -49,6 +50,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) for (int i = 0; i < 2; i++) _heroTab[i] = nullptr; _eye = nullptr; + _spare = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -69,6 +71,7 @@ void CGE2Engine::init() { for (int i = 0; i < 2; i++) _heroTab[i] = new HeroTab(this); _eye = new V3D(); + _spare = new Spare(this); } void CGE2Engine::deinit() { @@ -82,6 +85,7 @@ void CGE2Engine::deinit() { for (int i = 0; i < 2; i++) delete _heroTab[i]; delete _eye; + delete _spare; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index f3cf574faf..bca5d1a62a 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -45,6 +45,7 @@ struct HeroTab; class V3D; class V2D; class Dac; +class Spare; #define kScrWidth 320 #define kScrHeight 240 @@ -96,6 +97,7 @@ public: Text *_text; HeroTab *_heroTab[2]; V3D *_eye; + Spare *_spare; private: void init(); void deinit(); diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 4a7a412152..60b7db519c 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -10,7 +10,8 @@ MODULE_OBJS = \ cge2_main.o \ text.o \ hero.o \ - snail.o + snail.o \ + spare.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp new file mode 100644 index 0000000000..c1e536ac01 --- /dev/null +++ b/engines/cge2/spare.cpp @@ -0,0 +1,87 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/spare.h" + +namespace CGE2 { + +void Spare::synchronize() { + warning("STUB: Spare::Load"); +} + +void Spare::clear() { + _container.clear(); +} + +Spare::Spare(CGE2Engine *vm) : _vm(vm) {} + +Sprite *Spare::take(int ref) { + for (int i = 0; i < _container.size(); i++) { + if (_container[i]._ref == ref) { + return &_container[i]; + } + } + return nullptr; +} + +void Spare::takeCave(int cav) { + int ref = cav << 8; + Sprite *spr = take(ref); + _vm->_vga->_showQ->insert(spr); +} + +void Spare::make(Sprite *spr) { + _container.insert_at(_container.size(), *spr); +} + +void Spare::dispose(Sprite *spr) { + warning("STUB: Spare::Dispose()"); + + if (spr) { + _vm->_vga->_showQ->remove(spr); + + for (int i = 0; i < _container.size(); i++) { + if (spr == &_container[i]) { + _container.remove_at(i); + } + } + } +} + +void Spare::dispose(int ref) { + dispose(_vm->_vga->_showQ->locate(ref)); +} + +void Spare::dispose() { + for (int i = 0; i < _container.size(); i++) { + if (_container[i]._ref > 255) { + dispose(&_container[i]); + } + } +} + +} // End of namespace CGE2 diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h new file mode 100644 index 0000000000..8cfb65b905 --- /dev/null +++ b/engines/cge2/spare.h @@ -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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_SPARE_H +#define CGE2_SPARE_H + +#include "cge2/vga13h.h" + +namespace CGE2 { + +class Spare { + CGE2Engine *_vm; + Common::Array _container; +public: + void make(Sprite *spr); + Spare(CGE2Engine *vm); + Sprite *take(int ref); + void takeCave(int cav); + void dispose(Sprite *spr); + void dispose(int ref); + void dispose(); + void synchronize(); + uint16 count() { _container.size(); } + void clear(); +}; + +} // End of namespace CGE2 + +#endif // CGE2_SPARE_H -- cgit v1.2.3 From 18182d5d2b75a42ff453aaa9ad6f60eb54bc898c Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 07:46:13 +0200 Subject: CGE2: Spare: store pointers instead of objects. --- engines/cge2/spare.cpp | 12 ++++++------ engines/cge2/spare.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index c1e536ac01..9a50f51900 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -41,8 +41,8 @@ Spare::Spare(CGE2Engine *vm) : _vm(vm) {} Sprite *Spare::take(int ref) { for (int i = 0; i < _container.size(); i++) { - if (_container[i]._ref == ref) { - return &_container[i]; + if (_container[i]->_ref == ref) { + return _container[i]; } } return nullptr; @@ -55,7 +55,7 @@ void Spare::takeCave(int cav) { } void Spare::make(Sprite *spr) { - _container.insert_at(_container.size(), *spr); + _container.insert_at(_container.size(), spr); } void Spare::dispose(Sprite *spr) { @@ -65,7 +65,7 @@ void Spare::dispose(Sprite *spr) { _vm->_vga->_showQ->remove(spr); for (int i = 0; i < _container.size(); i++) { - if (spr == &_container[i]) { + if (spr == _container[i]) { _container.remove_at(i); } } @@ -78,8 +78,8 @@ void Spare::dispose(int ref) { void Spare::dispose() { for (int i = 0; i < _container.size(); i++) { - if (_container[i]._ref > 255) { - dispose(&_container[i]); + if (_container[i]->_ref > 255) { + dispose(_container[i]); } } } diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 8cfb65b905..3fc7ecfc94 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -34,7 +34,7 @@ namespace CGE2 { class Spare { CGE2Engine *_vm; - Common::Array _container; + Common::Array _container; public: void make(Sprite *spr); Spare(CGE2Engine *vm); -- cgit v1.2.3 From 631e9ef37e0bfd40deca4ee95a4a2186695434eb Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 07:49:28 +0200 Subject: CGE2: Fix Spare. --- engines/cge2/spare.cpp | 4 ++-- engines/cge2/spare.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 9a50f51900..1bc4f47e78 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -34,11 +34,11 @@ void Spare::synchronize() { } void Spare::clear() { + for (int i = 0; i < _container.size(); i++) + delete _container[i]; _container.clear(); } -Spare::Spare(CGE2Engine *vm) : _vm(vm) {} - Sprite *Spare::take(int ref) { for (int i = 0; i < _container.size(); i++) { if (_container[i]->_ref == ref) { diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 3fc7ecfc94..cf0c29bfd4 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -37,14 +37,14 @@ class Spare { Common::Array _container; public: void make(Sprite *spr); - Spare(CGE2Engine *vm); + Spare(CGE2Engine *vm) : _vm(vm) {} Sprite *take(int ref); void takeCave(int cav); void dispose(Sprite *spr); void dispose(int ref); void dispose(); void synchronize(); - uint16 count() { _container.size(); } + uint16 count() { return _container.size(); } void clear(); }; -- cgit v1.2.3 From 6aead2cb0345f7bef3221f7aab042d1e6ba1cbc9 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 08:48:48 +0200 Subject: CGE2: Add destructor to Spare. --- engines/cge2/spare.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index cf0c29bfd4..2fd235bd5e 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -36,8 +36,9 @@ class Spare { CGE2Engine *_vm; Common::Array _container; public: - void make(Sprite *spr); Spare(CGE2Engine *vm) : _vm(vm) {} + ~Spare() { clear(); } + void make(Sprite *spr); Sprite *take(int ref); void takeCave(int cav); void dispose(Sprite *spr); -- cgit v1.2.3 From 0fbdbd82720750779363b43e3a81c2bd9106b105 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 09:03:29 +0200 Subject: CGE2: Rename take() to locate(). --- engines/cge2/spare.cpp | 4 ++-- engines/cge2/spare.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 1bc4f47e78..5553e1d2cf 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -39,7 +39,7 @@ void Spare::clear() { _container.clear(); } -Sprite *Spare::take(int ref) { +Sprite *Spare::locate(int ref) { for (int i = 0; i < _container.size(); i++) { if (_container[i]->_ref == ref) { return _container[i]; @@ -50,7 +50,7 @@ Sprite *Spare::take(int ref) { void Spare::takeCave(int cav) { int ref = cav << 8; - Sprite *spr = take(ref); + Sprite *spr = locate(ref); _vm->_vga->_showQ->insert(spr); } diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 2fd235bd5e..c89a968212 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -39,7 +39,7 @@ public: Spare(CGE2Engine *vm) : _vm(vm) {} ~Spare() { clear(); } void make(Sprite *spr); - Sprite *take(int ref); + Sprite *locate(int ref); void takeCave(int cav); void dispose(Sprite *spr); void dispose(int ref); -- cgit v1.2.3 From d7c54653092bc4ed24011a88a6748a98a0a99312 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 09:07:06 +0200 Subject: CGE2: Rename make() to store(). --- engines/cge2/spare.cpp | 2 +- engines/cge2/spare.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 5553e1d2cf..451cf21f9f 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -54,7 +54,7 @@ void Spare::takeCave(int cav) { _vm->_vga->_showQ->insert(spr); } -void Spare::make(Sprite *spr) { +void Spare::store(Sprite *spr) { _container.insert_at(_container.size(), spr); } diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index c89a968212..e1689c3d99 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -38,7 +38,7 @@ class Spare { public: Spare(CGE2Engine *vm) : _vm(vm) {} ~Spare() { clear(); } - void make(Sprite *spr); + void store(Sprite *spr); Sprite *locate(int ref); void takeCave(int cav); void dispose(Sprite *spr); -- cgit v1.2.3 From 6e509152544cd895da1b63923bbc2adf890e6d5f Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 09:07:32 +0200 Subject: CGE2: Finish implementation of loadScript(). --- engines/cge2/cge2_main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 23fe4cbfa9..38320c4a62 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -32,6 +32,7 @@ #include "cge2/text.h" #include "cge2/snail.h" #include "cge2/hero.h" +#include "cge2/spare.h" namespace CGE2 { @@ -174,6 +175,8 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { } if (_sprite) { + _sprite->_ref = ref; + _sprite->_flags._frnt = frnt; _sprite->_flags._east = east; _sprite->_flags._port = port; @@ -258,9 +261,15 @@ void CGE2Engine::loadScript(const char *fname) { _sprite = NULL; loadSprite(SpN, SpI, SpA, P); if (_sprite) { - warning("STUB: CGE2Engine::loadScript - SPARE:: thing"); if (BkG) _sprite->_flags._back = true; + + int n = _spare->count(); + if (_spare->locate(_sprite->_ref) == nullptr) + _spare->store(_sprite); + _sprite = nullptr; + if (_spare->count() == n) + error("Durplicated reference! %s", SpN); } } -- cgit v1.2.3 From 86c4e8336d1e84f53c6a4ec4dcbb57274ae662ec Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 09:27:50 +0200 Subject: CGE2: Add caveUp() and showBak(). --- engines/cge2/cge2.h | 2 ++ engines/cge2/cge2_main.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index bca5d1a62a..82f0faff04 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -77,6 +77,8 @@ public: void loadScript(const char *fname); void loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); + void caveUp(int cav); + void showBak(int ref); const ADGameDescription *_gameDescription; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 38320c4a62..dbf9afef99 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -288,8 +288,9 @@ void CGE2Engine::movie(const char *ext) { if (_resman->exist(fn)) { int now = _now; - _now = atoi(ext + 1); + _now = atoi(ext + 2); loadScript(fn); + caveUp(_now); warning("STUB: CGE2Engine::movie()"); @@ -297,6 +298,31 @@ void CGE2Engine::movie(const char *ext) { } } +void CGE2Engine::caveUp(int cav) { + _now = cav; + int bakRef = _now << 8; + if (_music) + _midiPlayer->loadMidi(bakRef); + showBak(bakRef); + + warning("STUB: CGE2Engine::caveUp()"); +} + +void CGE2Engine::showBak(int ref) { + Sprite *spr = _spare->locate(ref); + if (spr != nullptr) { + _bitmapPalette = _vga->_sysPal; + warning("Check again this ^ !"); + spr->expand(); + _bitmapPalette = NULL; + //spr->show(2); + _vga->copyPage(1, 2); + _spare->dispose(spr); + + warning("STUB: CGE2Engine::showBak()"); + } +} + void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } -- cgit v1.2.3 From 2f404690e79377eb960d0acba36f09441c4693fd Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 09:51:22 +0200 Subject: CGE2: Rename Snail to CommandHandler, expand it. --- engines/cge2/cge2.h | 4 ++ engines/cge2/cge2_main.cpp | 2 +- engines/cge2/snail.cpp | 33 +++++++-- engines/cge2/snail.h | 172 ++++++++++++++++++++++++++------------------- 4 files changed, 133 insertions(+), 78 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 82f0faff04..cfa783ef44 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -58,6 +58,10 @@ class Spare; #define kPocketMax 4 #define kCaveMax 100 +enum CallbackType { + kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume +}; + class CGE2Engine : public Engine { public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index dbf9afef99..be503275d1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -131,7 +131,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { case kIdNear: case kIdMTake: case kIdFTake: - if (Snail::com(p) >= 0) + if (CommandHandler::com(p) >= 0) ++cnt[section]; else error("Bad line %d [%s]", sprf.getLineCount(), tmpStr); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 245da9972a..68cccea5dc 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -30,7 +30,7 @@ namespace CGE2 { -const char *Snail::comTxt[] = { +const char *CommandHandler::_commandText[] = { "NOP", "USE", "PAUSE", "INF", "CAVE", "SLAVE", "FOCUS", "SETX", "SETY", "SETZ", "ADD", "SUB", "MUL", "DIV", "IF", "FLAG", @@ -52,9 +52,34 @@ const char *Snail::comTxt[] = { "WALKTO", "REACH", "COVER", "UNCOVER", NULL }; -int Snail::com(const char *com) { - int i = EncryptedStream::takeEnum(comTxt, com); - return (i < 0) ? i : i + kSNCom0 + 1; +void CommandHandler::runCommand() { + warning("STUB: CommandHandler::runCommand()"); +} + +void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { + warning("STUB: CommandHandler::addCommand()"); +} + +void CommandHandler::addCallback(CommandType com, int ref, int val, CallbackType cbType) { + warning("STUB: CommandHandler::addCallback()"); +} + +void CommandHandler::insertCommand(CommandType com, int ref, int val, void *ptr) { + warning("STUB: CommandHandler::insertCommand()"); +} + +bool CommandHandler::idle() { + warning("STUB: CommandHandler::idle()"); + return false; +} + +void CommandHandler::reset() { + warning("STUB: CommandHandler::reset()"); +} + +int CommandHandler::com(const char *com) { + int i = EncryptedStream::takeEnum(_commandText, com); + return (i < 0) ? i : i + kCmdCom0 + 1; } } // End of namespace CGE2. diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 80aa33f5d5..c8dea19b02 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -28,93 +28,119 @@ #ifndef CGE2_SNAIL_H #define CGE2_SNAIL_H +#include "cge2/cge2.h" #include "cge2/cge2_main.h" namespace CGE2 { enum Action { kNear, kMTake, kFTake, kActions }; -enum SNCom { - kSNCom0 = 128, - kSNNop, // NOP :: do nothing - kSNUse, // USE | :: hint for using - kSNPause, // PAUSE -1 :: delay /72 seconds - kSNInf, // INF -1 :: show text referrenced by - kSNCave, // CAVE -1 :: go to board - kSNSlave, // SLAVE - kSNFocus, // FOCUS :: change active hero - kSNSetX, // SETX :: set sprite shift in x axis - kSNSetY, // SETX :: set sprite shift in y axis - kSNSetZ, // SETX :: set sprite shift in z axis - kSNAdd, // ADD :: sum vectors - kSNSub, // SUB :: subtract vectors - kSNMul, // MUL :: multiply vector by number - kSNDiv, // DIV :: divide vector by number - kSNIf, // IF - kSNFlag, // FLAG :: set flag to - kSNFlash, // FLASH -1 0|1 :: lighten whole image (on/off) - kSNLight, // LIGHT - kSNCycle, // CYCLE :: rotate colors from 1 - kSNClear, // CLEAR -1 0 :: clear kSNAIL queue - kSNTalk, // TALK -1 0|1 :: enable speach (on/off) - kSNMouse, // MOUSE -1 0|1 :: enable mouse (on/off) - kSNMap, // MAP 0|1 0 :: temporarily turn off map for hero - kSNCount, // COUNT - kSNMidi, // MIDI -1 :: play MIDI referenced by (-1 = off) - kSNSetDlg, // SETDLG 0..3 0..3 :: switch of speach mode - kSNMskDlg, // MSKDLG 0..3 0..3 :: switch of speach mode mask +enum CommandType { + kCmdCom0 = 128, + kCmdNop, // NOP :: do nothing + kCmdUse, // USE | :: hint for using + kCmdPause, // PAUSE -1 :: delay /72 seconds + kCmdInf, // INF -1 :: show text referrenced by + kCmdCave, // CAVE -1 :: go to board + kCmdSlave, // SLAVE + kCmdFocus, // FOCUS :: change active hero + kCmdSetX, // SETX :: set sprite shift in x axis + kCmdSetY, // SETX :: set sprite shift in y axis + kCmdSetZ, // SETX :: set sprite shift in z axis + kCmdAdd, // ADD :: sum vectors + kCmdSub, // SUB :: subtract vectors + kCmdMul, // MUL :: multiply vector by number + kCmdDiv, // DIV :: divide vector by number + kCmdIf, // IF + kCmdFlag, // FLAG :: set flag to + kCmdFlash, // FLASH -1 0|1 :: lighten whole image (on/off) + kCmdLight, // LIGHT + kCmdCycle, // CYCLE :: rotate colors from 1 + kCmdClear, // CLEAR -1 0 :: clear kCmdAIL queue + kCmdTalk, // TALK -1 0|1 :: enable speach (on/off) + kCmdMouse, // MOUSE -1 0|1 :: enable mouse (on/off) + kCmdMap, // MAP 0|1 0 :: temporarily turn off map for hero + kCmdCount, // COUNT + kCmdMidi, // MIDI -1 :: play MIDI referenced by (-1 = off) + kCmdSetDlg, // SETDLG 0..3 0..3 :: switch of speach mode + kCmdMskDlg, // MSKDLG 0..3 0..3 :: switch of speach mode mask - kSNSpr, + kCmdSpr, - kSNWait, // WAIT |-1 :: wait for SEQ (-1 = freeze) - kSNHide, // HIDE 0|1 :: visibility of sprite - kSNRoom, // ROOM 0|1 :: additional room in pocket (no/yes) - kSNSay, // SAY :: say text referenced by - kSNSound, // SOUND :: play sound effect referenced by - kSNTime, // TIME 0 :: say current time - kSNKill, // KILL 0 :: remove sprite - kSNRSeq, // RSEQ :: relative jump SEQ lines - kSNSeq, // SEQ :: jump to certain SEQ - kSNSend, // SEND :: move sprite to board - kSNSwap, // SWAP spr2> :: sprite exchange - kSNKeep, // KEEP :: take sprite into pocket and jump to - kSNGive, // GIVE :: remove sprite from pocket and jump to - kSNGetPos, // GETPOS :: take sprite's position - kSNGoto, // GOTO :: move sprite to position - kSNMoveX, // MOVEX :: relative move along X axis - kSNMoveY, // MOVEY :: relative move along Y axis - kSNMoveZ, // MOVEZ :: relative move along Z axis - kSNTrans, // TRANS 0|1 :: clear/set logical transparency - kSNPort, // PORT 0|1 :: clear/set "takeability" of sprite - kSNNext, // NEXT :: jump to - NEAR or TAKE - kSNNNext, // NNEXT :: jump to - NEAR - kSNMTNext, // MTNEXT :: jump to - TAKE - kSNFTNext, // FTNEXT :: jump to - TAKE - kSNRNNext, // RNNEXT :: relative jump to - NEAR - kSNRMTNext, // RMTNEXT :: relative jump to - TAKE - kSNRFTNext, // RFTNEXT :: relative jump to - TAKE - kSNRMNear, // RMNEAR 0 :: remove NEAR list - kSNRMMTake, // RMMTAKE 0 :: remove TAKE list - kSNRMFTake, // RMFTAKE 0 :: remove TAKE list - kSNSetRef, // RETREF :: change reference of sprite to - kSNBackPt, // BACKPT 0 :: paint sprite onto the background - kSNWalk, // WALK | :: go close to the sprite or point - kSNReach, // REACH | :: reach the sprite or point with method - kSNCover, // COVER :: cover sprite with sprite - kSNUncover, // UNCOVER :: restore the state before COVER + kCmdWait, // WAIT |-1 :: wait for SEQ (-1 = freeze) + kCmdHide, // HIDE 0|1 :: visibility of sprite + kCmdRoom, // ROOM 0|1 :: additional room in pocket (no/yes) + kCmdSay, // SAY :: say text referenced by + kCmdSound, // SOUND :: play sound effect referenced by + kCmdTime, // TIME 0 :: say current time + kCmdKill, // KILL 0 :: remove sprite + kCmdRSeq, // RSEQ :: relative jump SEQ lines + kCmdSeq, // SEQ :: jump to certain SEQ + kCmdSend, // SEND :: move sprite to board + kCmdSwap, // SWAP spr2> :: sprite exchange + kCmdKeep, // KEEP :: take sprite into pocket and jump to + kCmdGive, // GIVE :: remove sprite from pocket and jump to + kCmdGetPos, // GETPOS :: take sprite's position + kCmdGoto, // GOTO :: move sprite to position + kCmdMoveX, // MOVEX :: relative move along X axis + kCmdMoveY, // MOVEY :: relative move along Y axis + kCmdMoveZ, // MOVEZ :: relative move along Z axis + kCmdTrans, // TRANS 0|1 :: clear/set logical transparency + kCmdPort, // PORT 0|1 :: clear/set "takeability" of sprite + kCmdNext, // NEXT :: jump to - NEAR or TAKE + kCmdNNext, // NNEXT :: jump to - NEAR + kCmdMTNext, // MTNEXT :: jump to - TAKE + kCmdFTNext, // FTNEXT :: jump to - TAKE + kCmdRNNext, // RNNEXT :: relative jump to - NEAR + kCmdRMTNext, // RMTNEXT :: relative jump to - TAKE + kCmdRFTNext, // RFTNEXT :: relative jump to - TAKE + kCmdRMNear, // RMNEAR 0 :: remove NEAR list + kCmdRMMTake, // RMMTAKE 0 :: remove TAKE list + kCmdRMFTake, // RMFTAKE 0 :: remove TAKE list + kCmdSetRef, // RETREF :: change reference of sprite to + kCmdBackPt, // BACKPT 0 :: paint sprite onto the background + kCmdWalk, // WALK | :: go close to the sprite or point + kCmdReach, // REACH | :: reach the sprite or point with method + kCmdCover, // COVER :: cover sprite with sprite + kCmdUncover, // UNCOVER :: restore the state before COVER - kSNDim, - kSNExec, - kSNStep, - kSNGhost, + kCmdDim, + kCmdExec, + kCmdStep, + kCmdGhost, - kSNNOne = kNoByte + kCmdNOne = kNoByte }; -class Snail { - static const char *comTxt[]; +class CommandHandler { public: + struct Command { + CommandType _commandType; + int _ref; + int _val; + void *_spritePtr; + CallbackType _cbType; + } *_commandList; + static const char *_commandText[]; + bool _talkEnable; + + CommandHandler(CGE2Engine *vm, bool turbo); + ~CommandHandler(); + void runCommand(); + void addCommand(CommandType com, int ref, int val, void *ptr); + void addCallback(CommandType com, int ref, int val, CallbackType cbType); + void insertCommand(CommandType com, int ref, int val, void *ptr); + bool idle(); + void reset(); static int com(const char *com); +private: + CGE2Engine *_vm; + bool _turbo; + uint8 _head; + uint8 _tail; + bool _busy; + bool _textDelay; + uint32 _timerExpiry; }; } // End of namespace CGE2 -- cgit v1.2.3 From e30296976c56301f7d4f90868b6f95af87d2de4a Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 10:29:41 +0200 Subject: CGE2: Instantiate CommandHandler. --- engines/cge2/cge2.cpp | 3 +++ engines/cge2/cge2.h | 2 ++ engines/cge2/snail.cpp | 10 +++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index c9fb590400..0c8318a507 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -51,6 +51,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _heroTab[i] = nullptr; _eye = nullptr; _spare = nullptr; + _commandHandler = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -72,6 +73,7 @@ void CGE2Engine::init() { _heroTab[i] = new HeroTab(this); _eye = new V3D(); _spare = new Spare(this); + _commandHandler = new CommandHandler(this, false); } void CGE2Engine::deinit() { @@ -86,6 +88,7 @@ void CGE2Engine::deinit() { delete _heroTab[i]; delete _eye; delete _spare; + delete _commandHandler; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index cfa783ef44..b28840817f 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -46,6 +46,7 @@ class V3D; class V2D; class Dac; class Spare; +class CommandHandler; #define kScrWidth 320 #define kScrHeight 240 @@ -104,6 +105,7 @@ public: HeroTab *_heroTab[2]; V3D *_eye; Spare *_spare; + CommandHandler *_commandHandler; private: void init(); void deinit(); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 68cccea5dc..52aefe2d40 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -52,6 +52,14 @@ const char *CommandHandler::_commandText[] = { "WALKTO", "REACH", "COVER", "UNCOVER", NULL }; +CommandHandler::CommandHandler(CGE2Engine *vm, bool turbo) : _vm(vm) { + warning("STUB: CommandHandler::CommandHandler()"); +} + +CommandHandler::~CommandHandler() { + warning("STUB: CommandHandler::~CommandHandler()"); +} + void CommandHandler::runCommand() { warning("STUB: CommandHandler::runCommand()"); } @@ -78,7 +86,7 @@ void CommandHandler::reset() { } int CommandHandler::com(const char *com) { - int i = EncryptedStream::takeEnum(_commandText, com); + int i = _vm->takeEnum(_commandText, com); return (i < 0) ? i : i + kCmdCom0 + 1; } -- cgit v1.2.3 From c108a1830600b3ae45d69b0b48a4747ba4b54819 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 10:37:23 +0200 Subject: CGE2: Make some static functions non-static. EncryptedStream -> CGE2Engine Namely: * CGE2Engine::number(char *s) * char *CGE2Engine::token(char *s) * int CGE2Engine::takeEnum(const char **tab, const char *text) * ID CGE2Engine::ident(const char *s) * bool CGE2Engine::testBool(char *s) * int CommandHandler::com(const char *com) --- engines/cge2/cge2.h | 6 ++++ engines/cge2/cge2_main.cpp | 79 ++++++++++++++++++++++++++++++++-------------- engines/cge2/fileio.cpp | 31 ------------------ engines/cge2/fileio.h | 9 ++---- engines/cge2/general.h | 6 ++-- engines/cge2/snail.h | 2 +- engines/cge2/text.cpp | 2 +- 7 files changed, 68 insertions(+), 67 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index b28840817f..be2c129fb5 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -85,6 +85,12 @@ public: void caveUp(int cav); void showBak(int ref); + int number(char *s); + char *token(char *s); + int takeEnum(const char **tab, const char *text); + ID ident(const char *s); + bool testBool(char *s); + const ADGameDescription *_gameDescription; bool _quitFlag; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index be503275d1..352c62c6c1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -36,6 +36,37 @@ namespace CGE2 { +int CGE2Engine::number(char *s) { + int r = atoi(s); + char *pp = strchr(s, ':'); + if (pp) + r = (r << 8) + atoi(pp + 1); + return r; +} + +char *CGE2Engine::token(char *s) { + return strtok(s, " =\t,;/()"); +} + +int CGE2Engine::takeEnum(const char **tab, const char *text) { + if (text) { + for (const char **e = tab; *e; e++) { + if (scumm_stricmp(text, *e) == 0) { + return e - tab; + } + } + } + return -1; +} + +ID CGE2Engine::ident(const char *s) { + return ID(takeEnum(EncryptedStream::kIdTab, s)); +} + +bool CGE2Engine::testBool(char *s) { + return number(s) != 0; +} + void CGE2Engine::badLab(const char *fn) { error("Misplaced label in %s!", fn); } @@ -73,7 +104,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); char *p; - p = EncryptedStream::token(tmpStr); + p = token(tmpStr); if (*p == '@') { if (label != kNoByte) badLab(fname); @@ -81,7 +112,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { continue; } - id = EncryptedStream::ident(p); + id = ident(p); switch (id) { case kIdName: // will be taken in Expand routine if (label != kNoByte) @@ -103,26 +134,26 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { case kIdFront: if (label != kNoByte) badLab(fname); - p = EncryptedStream::token(nullptr); - frnt = EncryptedStream::testBool(p); + p = token(nullptr); + frnt = testBool(p); break; case kIdEast: if (label != kNoByte) badLab(fname); - p = EncryptedStream::token(nullptr); - east = EncryptedStream::testBool(p); + p = token(nullptr); + east = testBool(p); break; case kIdPortable: if (label != kNoByte) badLab(fname); - p = EncryptedStream::token(nullptr); - port = EncryptedStream::testBool(p); + p = token(nullptr); + port = testBool(p); break; case kIdTransparent: if (label != kNoByte) badLab(fname); - p = EncryptedStream::token(nullptr); - tran = EncryptedStream::testBool(p); + p = token(nullptr); + tran = testBool(p); break; default: if (id >= kIdNear) @@ -131,7 +162,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { case kIdNear: case kIdMTake: case kIdFTake: - if (CommandHandler::com(p) >= 0) + if (_commandHandler->com(p) >= 0) ++cnt[section]; else error("Bad line %d [%s]", sprf.getLineCount(), tmpStr); @@ -222,39 +253,39 @@ void CGE2Engine::loadScript(const char *fname) { V3D P; // sprite ident number - if ((p = EncryptedStream::token(tmpStr)) == NULL) + if ((p = token(tmpStr)) == NULL) break; - int SpI = EncryptedStream::number(p); + int SpI = number(p); // sprite file name char *SpN; - if ((SpN = EncryptedStream::token(nullptr)) == NULL) + if ((SpN = token(nullptr)) == NULL) break; // sprite scene - if ((p = EncryptedStream::token(nullptr)) == NULL) + if ((p = token(nullptr)) == NULL) break; - int SpA = EncryptedStream::number(p); + int SpA = number(p); // sprite column - if ((p = EncryptedStream::token(nullptr)) == NULL) + if ((p = token(nullptr)) == NULL) break; - P._x = EncryptedStream::number(p); + P._x = number(p); // sprite row - if ((p = EncryptedStream::token(nullptr)) == NULL) + if ((p = token(nullptr)) == NULL) break; - P._y = EncryptedStream::number(p); + P._y = number(p); // sprite Z pos - if ((p = EncryptedStream::token(nullptr)) == NULL) + if ((p = token(nullptr)) == NULL) break; - P._z = EncryptedStream::number(p); + P._z = number(p); // sprite life - if ((p = EncryptedStream::token(nullptr)) == NULL) + if ((p = token(nullptr)) == NULL) break; - bool BkG = EncryptedStream::number(p) == 0; + bool BkG = number(p) == 0; ok = true; // no break: OK diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 6a20b6b561..a9e9563867 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -233,37 +233,6 @@ Common::String EncryptedStream::readLine() { return _readStream->readLine(); } -int EncryptedStream::number(char *s) { - int r = atoi(s); - char *pp = strchr(s, ':'); - if (pp) - r = (r << 8) + atoi(pp + 1); - return r; -} - -char *EncryptedStream::token(char *s) { - return strtok(s, " =\t,;/()"); -} - -int EncryptedStream::takeEnum(const char **tab, const char *text) { - if (text) { - for (const char **e = tab; *e; e++) { - if (scumm_stricmp(text, *e) == 0) { - return e - tab; - } - } - } - return -1; -} - -ID EncryptedStream::ident(const char *s) { - return ID(takeEnum(kIdTab, s)); -} - -bool EncryptedStream::testBool(char *s) { - return number(s) != 0; -} - int32 EncryptedStream::size() { return _readStream->size(); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 758d841226..315002268c 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -112,8 +112,6 @@ private: const char **_tab; int _lineCount; bool _error; - - static const char *kIdTab[]; public: EncryptedStream(CGE2Engine *vm, const char *name); ~EncryptedStream(); @@ -124,12 +122,9 @@ public: int32 size(); uint32 read(byte *dataPtr, uint32 dataSize); Common::String readLine(); - static int number(char *s); - static char *token(char *s); - static int takeEnum(const char **tab, const char *text); - static ID ident(const char *s); - static bool testBool(char *s); int getLineCount() { return _lineCount; } + + static const char *kIdTab[]; }; } // End of namespace CGE2 diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 9c89f525ac..62b41a9ebb 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -79,9 +79,9 @@ public: void setEye(const char *s) { char *tempStr; strcpy(tempStr, s); - _vm->_eye->_x = atoi(EncryptedStream::token(tempStr)); - _vm->_eye->_y = atoi(EncryptedStream::token(tempStr)); - _vm->_eye->_z = atoi(EncryptedStream::token(tempStr)); + _vm->_eye->_x = atoi(_vm->token(tempStr)); + _vm->_eye->_y = atoi(_vm->token(tempStr)); + _vm->_eye->_z = atoi(_vm->token(tempStr)); } bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index c8dea19b02..b364aa92d0 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -132,7 +132,7 @@ public: void insertCommand(CommandType com, int ref, int val, void *ptr); bool idle(); void reset(); - static int com(const char *com); + int com(const char *com); private: CGE2Engine *_vm; bool _turbo; diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index de33717c55..2f8e9b4011 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -107,7 +107,7 @@ void Text::load() { if (!Common::isDigit(*s)) continue; - int r = tf.number(s); + int r = _vm->number(s); s += strlen(s); if (s < tmpStr + n) -- cgit v1.2.3 From e8148cf1deafc0300ea758ab06e7a95d382c0fc6 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 11:58:42 +0200 Subject: CGE2: Rework SprExt, stub more functions of Sprite. --- engines/cge2/vga13h.cpp | 15 +++++---------- engines/cge2/vga13h.h | 19 +++++++------------ 2 files changed, 12 insertions(+), 22 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index ada6642831..79c4861b4a 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -209,7 +209,7 @@ Sprite *Sprite::expand() { if (_ext) return this; - _ext = new SprExt; + _ext = new SprExt(_vm); assert(_ext != NULL); if (!*_file) return this; @@ -507,9 +507,7 @@ void Sprite::show(uint16 pg) { } void Sprite::hide() { - SprExt *e = _ext; - if (e->_b0) - e->_b0->hide(e->_x0, e->_y0); + warning("STUB: Sprite::hide()"); } BitmapPtr Sprite::ghost() { @@ -519,12 +517,9 @@ BitmapPtr Sprite::ghost() { BitmapPtr bmp = new Bitmap(_vm, 0, 0, (uint8 *)NULL); assert(bmp != NULL); - bmp->_w = e->_b1->_w; - bmp->_h = e->_b1->_h; - bmp->_b = new HideDesc[bmp->_h]; - assert(bmp->_b != NULL); - bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); - bmp->_map = (e->_y1 << 16) + e->_x1; + + warning("STUB: Sprite::ghost()"); + return bmp; } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 487df10ba8..d2fb198470 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -60,23 +60,18 @@ struct Seq { class SprExt { public: - int _x0; - int _y0; - int _x1; - int _y1; + V2D _p0; + V2D _p1; BitmapPtr _b0; BitmapPtr _b1; BitmapPtr *_shpList; + int _location; Seq *_seq; char *_name; - /*CommandHandler::Command *_near; - CommandHandler::Command *_take;*/ - SprExt() : - _x0(0), _y0(0), - _x1(0), _y1(0), - _b0(NULL), _b1(NULL), - _shpList(NULL), _seq(NULL), - _name(NULL)/*, _near(NULL), _take(NULL)*/ + CommandHandler::Command *_actions[kActions]; + SprExt(CGE2Engine *vm) : _p0(vm, 0, 0), _p1(vm, 0, 0), + _b0(NULL), _b1(NULL),_shpList(NULL), _location(0), + _seq(NULL), _name(NULL) {} }; -- cgit v1.2.3 From 78429a723863728b2c95f286a1c313cc6f17d010 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 16:47:55 +0200 Subject: CGE2: More revision and stubbing in Sprite. --- engines/cge2/cge2.cpp | 2 +- engines/cge2/vga13h.cpp | 87 +++++++++++++++++-------------------------------- engines/cge2/vga13h.h | 34 ++++++++++--------- 3 files changed, 49 insertions(+), 74 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 0c8318a507..4afafdc807 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -135,7 +135,7 @@ bool CGE2Engine::showTitle(const char *name) { LB[1] = NULL; _bitmapPalette = NULL; - Sprite D(this, LB); + Sprite D(this, LB, 2); D._flags._kill = true; // D._flags._bDel = true; warning("STUB: Sprite::showTitle() - Flags changed compared to CGE1's Sprite type."); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 79c4861b4a..47b0d6fa0f 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -56,41 +56,33 @@ Seq *getConstantSeq(bool seqFlag) { return seq; } +void(*Sprite::notify) (void) = nullptr; + byte Sprite::_constY = 0; byte Sprite::_follow = 0; Sprite::Sprite(CGE2Engine *vm) - : _siz(_vm, 0, 0), _nearPtr(0), _takePtr(0), - _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), + : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), + _next(NULL), _prev(NULL), _time(0), _ext(NULL), _ref(-1), _scene(0), _vm(vm), _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); _flags._frnt = 1; - - _ref = 0; - _w = _h = 0; - _seqPtr = 0; - _shpCnt = 0; } -Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP) - : _siz(_vm, 0, 0), _nearPtr(0), _takePtr(0), - _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), - _ext(NULL), _ref(-1), _scene(0), _vm(vm), - _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { +Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP, int cnt) + : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), + _next(NULL), _prev(NULL), _time(0), + _ext(NULL), _ref(-1), _scene(0), _vm(vm), + _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); _flags._frnt = 1; - _ref = 0; - _w = _h = 0; - _seqPtr = 0; - _shpCnt = 0; - - setShapeList(shpP); + setShapeList(shpP, cnt); } Sprite::~Sprite() { @@ -111,33 +103,8 @@ BitmapPtr Sprite::shp() { return e->_shpList[i]; } -BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { - BitmapPtr *r = (_ext) ? _ext->_shpList : NULL; - - _shpCnt = 0; - _w = 0; - _h = 0; - - if (shpP) { - BitmapPtr *p; - for (p = shpP; *p; p++) { - BitmapPtr b = (*p); // ->Code(); - if (b->_w > _w) - _w = b->_w; - if (b->_h > _h) - _h = b->_h; - _shpCnt++; - } - expand(); - _ext->_shpList = shpP; - - //_flags._bDel = true; - warning("STUB: Sprite::sync() - Flags changed compared to CGE1's Sprite type."); - - if (!_ext->_seq) - setSeq(getConstantSeq(_shpCnt < 2)); - } - return r; +void Sprite::setShapeList(BitmapPtr *shp, int cnt) { + warning("STUB: Sprite::setShapeList()"); } bool Sprite::works(Sprite *spr) { @@ -492,7 +459,7 @@ void Sprite::gotoxyz(V3D pos) { } void Sprite::center() { - gotoxyz((kScrWidth - _w) / 2, (kScrHeight - _h) / 2); + gotoxyz(kScrWidth >> 1, (kWorldHeight - _siz.y) >> 1, 0); } void Sprite::show() { @@ -577,11 +544,7 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(_pos3D._x); s.syncAsUint16LE(_pos3D._y); s.syncAsByte(_pos3D._z); - s.syncAsUint16LE(_w); - s.syncAsUint16LE(_h); s.syncAsUint16LE(_time); - s.syncAsByte(_nearPtr); - s.syncAsByte(_takePtr); s.syncAsSint16LE(_seqPtr); s.syncAsUint16LE(_shpCnt); s.syncBytes((byte *)&_file[0], 9); @@ -1019,35 +982,41 @@ void Bitmap::hide(int16 x, int16 y) { /*--------------------------------------------------------------------------*/ -HorizLine::HorizLine(CGE2Engine *vm) : Sprite(vm, NULL), _vm(vm) { +HorizLine::HorizLine(CGE2Engine *vm) : Sprite(vm), _vm(vm) { // Set the sprite list BitmapPtr *HL = new BitmapPtr[2]; HL[0] = new Bitmap(_vm, "HLINE"); HL[1] = NULL; - setShapeList(HL); + setShapeList(HL, 1); + + warning("HorizLine::HorizLine() - Recheck this!"); } -SceneLight::SceneLight(CGE2Engine *vm) : Sprite(vm, NULL), _vm(vm) { +SceneLight::SceneLight(CGE2Engine *vm) : Sprite(vm), _vm(vm) { // Set the sprite list BitmapPtr *PR = new BitmapPtr[2]; PR[0] = new Bitmap(_vm, "PRESS"); PR[1] = NULL; - setShapeList(PR); + setShapeList(PR, 1); + + warning("SceneLight::SceneLight() - Recheck this!"); } -Speaker::Speaker(CGE2Engine *vm): Sprite(vm, NULL), _vm(vm) { +Speaker::Speaker(CGE2Engine *vm): Sprite(vm), _vm(vm) { // Set the sprite list BitmapPtr *SP = new BitmapPtr[3]; SP[0] = new Bitmap(_vm, "SPK_L"); SP[1] = new Bitmap(_vm, "SPK_R"); SP[2] = NULL; - setShapeList(SP); + setShapeList(SP, 2); + + warning("Speaker::Speaker() - Recheck this!"); } -PocLight::PocLight(CGE2Engine *vm): Sprite(vm, NULL), _vm(vm) { +PocLight::PocLight(CGE2Engine *vm): Sprite(vm), _vm(vm) { // Set the sprite list BitmapPtr *LI = new BitmapPtr[5]; LI[0] = new Bitmap(_vm, "LITE0"); @@ -1056,9 +1025,11 @@ PocLight::PocLight(CGE2Engine *vm): Sprite(vm, NULL), _vm(vm) { LI[3] = new Bitmap(_vm, "LITE3"); LI[4] = NULL; - setShapeList(LI); + setShapeList(LI, 4); _flags._kill = false; + + warning("PocLight::PocLight() - Recheck this!"); } } // End of namespace CGE2 diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index d2fb198470..437cba05f1 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -100,20 +100,18 @@ public: uint16 _zmov : 1; // sprite needs Z-update in queue uint16 _tran : 1; // transparent (untouchable) } _flags; - uint16 _w; - uint16 _h; + V2D _pos2D; + V3D _pos3D; + V2D _siz; uint16 _time; - uint8 _nearPtr; - uint8 _takePtr; + struct { byte _ptr, _cnt; } _actionCtrl[kActions]; int _seqPtr; + int _seqCnt; int _shpCnt; char _file[kMaxFile]; + // Following trailer is not saved with the game: Sprite *_prev; Sprite *_next; - struct { byte _ptr, _cnt; } _actionCtrl[kActions]; - V2D _pos2D; - V3D _pos3D; - V2D _siz; static byte _constY; static byte _follow; @@ -122,12 +120,14 @@ public: inline bool active() { return _ext != NULL; } - Sprite(CGE2Engine *vm); - Sprite(CGE2Engine *vm, BitmapPtr *shp); + Sprite(CGE2Engine *vm, BitmapPtr *shp, int cnt); virtual ~Sprite(); BitmapPtr shp(); - BitmapPtr *setShapeList(BitmapPtr *shp); + void setShapeList(BitmapPtr *shp, int cnt); + void moveShapesHi(void); + void moveShapesLo(void); + int LabVal(Action snq, int lab); Sprite *expand(); Sprite *contract(); Sprite *backShow(bool fast = false); @@ -141,18 +141,22 @@ public: void gotoxyz_(V2D pos); void gotoxyz(V3D pos); void center(); + void show(uint16 pg); + void hide(uint16 pg); void show(); void hide(); BitmapPtr ghost(); - void show(uint16 pg); void makeXlat(uint8 *x); void killXlat(); void step(int nr = -1); Seq *setSeq(Seq *seq); - //CommandHandler::Command *snList(SnList type); - /*virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); - virtual void tick();*/ + CommandHandler::Command *snList(Action type); + //virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); + //virtual void tick(); + void clrHide(void) { if (_ext) _ext->_b0 = NULL; } void sync(Common::Serializer &s); + + static void (*notify) (void); }; class Queue { -- cgit v1.2.3 From 4ee1ab07aea7d07a661b58770721f6edce4d5f18 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 17:04:51 +0200 Subject: CGE2: Add a self-not warning to Bitmap. --- engines/cge2/bitmap.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 77c7eb9c41..6237feaa5d 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -113,6 +113,8 @@ Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(N Bitmap::~Bitmap() { free(_m); delete[] _v; + + warning("Bitmap: Don't forget to review the whole implemenation!"); } Bitmap &Bitmap::operator=(const Bitmap &bmp) { -- cgit v1.2.3 From c202328ecf9fc244e0e3974c303056b811726af7 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 13 May 2014 17:27:12 +0200 Subject: CGE2: Implement Sprite::setShapeList(). --- engines/cge2/vga13h.cpp | 31 ++++++++++++++++++++++++++++++- engines/cge2/vga13h.h | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 47b0d6fa0f..054769e93e 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -61,6 +61,17 @@ void(*Sprite::notify) (void) = nullptr; byte Sprite::_constY = 0; byte Sprite::_follow = 0; +Seq Sprite::_stdSeq8[] = +{ { 0, 0, 0, 0, 0, 0 }, + { 1, 1, 0, 0, 0, 0 }, + { 2, 2, 0, 0, 0, 0 }, + { 3, 3, 0, 0, 0, 0 }, + { 4, 4, 0, 0, 0, 0 }, + { 5, 5, 0, 0, 0, 0 }, + { 6, 6, 0, 0, 0, 0 }, + { 7, 7, 0, 0, 0, 0 }, +}; + Sprite::Sprite(CGE2Engine *vm) : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), _next(NULL), _prev(NULL), _time(0), @@ -104,7 +115,25 @@ BitmapPtr Sprite::shp() { } void Sprite::setShapeList(BitmapPtr *shp, int cnt) { - warning("STUB: Sprite::setShapeList()"); + _shpCnt = cnt; + _siz.x = 0; + _siz.y = 0; + + if (shp) { + for (int i = 0; i < cnt; i++) { + BitmapPtr p = *shp + i; + if (p->_w > _siz.x) + _siz.x = p->_w; + if (p->_h > _siz.y) + _siz.y = p->_w; + } + expand(); + _ext->_shpList = shp; + if (!_ext->_seq) { + setSeq(_stdSeq8); + _seqCnt = (cnt < ARRAYSIZE(_stdSeq8)) ? cnt : ARRAYSIZE(_stdSeq8); + } + } } bool Sprite::works(Sprite *spr) { diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 437cba05f1..f8c7bf462d 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -55,6 +55,7 @@ struct Seq { uint8 _next; int8 _dx; int8 _dy; + int8 _dz; int _dly; }; @@ -114,6 +115,7 @@ public: Sprite *_next; static byte _constY; static byte _follow; + static Seq _stdSeq8[]; bool works(Sprite *spr); bool seqTest(int n); -- cgit v1.2.3 From 945f12f2ad04ce60d2d072548799a440ebb32da6 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 10:58:59 +0200 Subject: CGE2: Move setEye()s to CGE2Engine. --- engines/cge2/cge2.cpp | 6 ++++++ engines/cge2/cge2.h | 6 ++++++ engines/cge2/cge2_main.cpp | 18 ++++++++++++++++++ engines/cge2/general.h | 11 ----------- 4 files changed, 30 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 4afafdc807..85e8e889aa 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -50,6 +50,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) for (int i = 0; i < 2; i++) _heroTab[i] = nullptr; _eye = nullptr; + for (int i = 0; i < kCaveMax; i++) + _eyeTab[i] = nullptr; _spare = nullptr; _commandHandler = nullptr; @@ -72,6 +74,8 @@ void CGE2Engine::init() { for (int i = 0; i < 2; i++) _heroTab[i] = new HeroTab(this); _eye = new V3D(); + for (int i = 0; i < kCaveMax; i++) + _eyeTab[i] = new V3D(); _spare = new Spare(this); _commandHandler = new CommandHandler(this, false); } @@ -87,6 +91,8 @@ void CGE2Engine::deinit() { for (int i = 0; i < 2; i++) delete _heroTab[i]; delete _eye; + for (int i = 0; i < kCaveMax; i++) + delete _eyeTab[i]; delete _spare; delete _commandHandler; } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index be2c129fb5..fa161f360a 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -84,6 +84,11 @@ public: void badLab(const char *fn); void caveUp(int cav); void showBak(int ref); + void loadTab(); + + void setEye(V3D &e); + void setEye(const V2D& e2, int z = -kScrWidth); + void setEye(const char *s); int number(char *s); char *token(char *s); @@ -110,6 +115,7 @@ public: Text *_text; HeroTab *_heroTab[2]; V3D *_eye; + V3D *_eyeTab[kCaveMax]; Spare *_spare; CommandHandler *_commandHandler; private: diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 352c62c6c1..a0717a374a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -384,4 +384,22 @@ char *CGE2Engine::mergeExt(char *buf, const char *name, const char *ext) { return buf; } +void CGE2Engine::setEye(V3D &e) { + _eye = &e; +} + +void CGE2Engine::setEye(const V2D& e2, int z) { + _eye->_x = e2.x; + _eye->_y = e2.y; + _eye->_z = z; +} + +void CGE2Engine::setEye(const char *s) { + char tempStr[kLineMax]; + strcpy(tempStr, s); + _eye->_x = atoi(token(tempStr)); + _eye->_y = atoi(token(NULL)); + _eye->_z = atoi(token(NULL)); +} + } // End of namespace CGE2 diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 62b41a9ebb..747fb84e45 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -72,17 +72,6 @@ public: V2D(CGE2Engine *vm) : _vm(vm) { } V2D(CGE2Engine *vm, const V3D& p3) : _vm(vm) { *this = p3; } V2D(CGE2Engine *vm, int x, int y) : _vm(vm), Common::Point(x, y) { } - void setEye(V3D &e) { _vm->_eye = &e; } - void setEye(const V2D& e2, int z = -SCR_WID_) { - _vm->_eye->_x = e2.x; _vm->_eye->_y = e2.y; _vm->_eye->_z = z; - } - void setEye(const char *s) { - char *tempStr; - strcpy(tempStr, s); - _vm->_eye->_x = atoi(_vm->token(tempStr)); - _vm->_eye->_y = atoi(_vm->token(tempStr)); - _vm->_eye->_z = atoi(_vm->token(tempStr)); - } bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } bool operator >(const V2D& p) const { return (x > p.x) && (y > p.y); } -- cgit v1.2.3 From b2cbc7cdd17d2e998cc2dd4273ec8966fbe8e58f Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 10:59:46 +0200 Subject: CGE2: Partially implement loadTab(), then use it. --- engines/cge2/cge2_main.cpp | 11 +++++++++++ engines/cge2/cge2_main.h | 1 + 2 files changed, 12 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a0717a374a..9ee9459cca 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -358,9 +358,20 @@ void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } +void CGE2Engine::loadTab() { + char *n = _text->getText(240); + setEye(_text->getText(240)); + for (int i = 0; i < kCaveMax; i++) + _eyeTab[i] == _eye; + + warning("STUB: CGE2Engine::loadTab()"); +} + void CGE2Engine::cge2_main() { warning("STUB: CGE2Engine::cge2_main()"); + loadTab(); + _mode++; if (showTitle("WELCOME")) { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 8420a2d1db..ee622dc9ca 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -33,6 +33,7 @@ namespace CGE2 { #define kLineMax 512 #define kIntroExt ".I80" #define kNoByte -1 +#define kTabName "CGE.TAB" } // End of namespace CGE2 -- cgit v1.2.3 From 99c15216c71f5f75632a7e38573a2387be39fed9 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 11:16:35 +0200 Subject: CGE2: Add Bitmap::xLatPos(). --- engines/cge2/bitmap.cpp | 5 +++++ engines/cge2/bitmap.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 6237feaa5d..39483b067d 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -368,4 +368,9 @@ bool Bitmap::loadVBM(EncryptedStream *f) { return (!f->err()); } +void Bitmap::xLatPos(V2D& p) { + p.x -= (_w >> 1); + p.y = kWorldHeight - p.y - _h; +} + } // End of namespace CGE2 diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 3d3c27f97e..ea7146f0d7 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -28,7 +28,7 @@ #ifndef CGE2_BITMAP_H #define CGE2_BITMAP_H -#include "cge/general.h" +#include "cge2/general.h" #include "common/file.h" namespace CGE2 { @@ -77,6 +77,7 @@ public: void show(int16 x, int16 y); void xShow(int16 x, int16 y); bool solidAt(int16 x, int16 y); + void xLatPos(V2D& p); }; -- cgit v1.2.3 From 4e7bcb5f36c6abd07413323573670b140523f9b0 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 11:20:13 +0200 Subject: CGE2: Fix ShowTitle(). Now it REALLY puts the picture to the middle of the screen. --- engines/cge2/cge2.cpp | 9 +++++---- engines/cge2/vga13h.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 85e8e889aa..8d7f58fb44 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -141,16 +141,17 @@ bool CGE2Engine::showTitle(const char *name) { LB[1] = NULL; _bitmapPalette = NULL; - Sprite D(this, LB, 2); + Sprite D(this, LB, 1); D._flags._kill = true; - // D._flags._bDel = true; warning("STUB: Sprite::showTitle() - Flags changed compared to CGE1's Sprite type."); - D.center(); + D.gotoxyz(kScrWidth >> 1, -(kPanHeight >> 1)); + _vga->sunset(); + D.show(2); - _vga->sunset(); _vga->copyPage(1, 2); _vga->copyPage(0, 1); + _vga->sunrise(_vga->_sysPal); _vga->update(); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 054769e93e..6fc22384aa 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -125,7 +125,7 @@ void Sprite::setShapeList(BitmapPtr *shp, int cnt) { if (p->_w > _siz.x) _siz.x = p->_w; if (p->_h > _siz.y) - _siz.y = p->_w; + _siz.y = p->_h; } expand(); _ext->_shpList = shp; @@ -497,7 +497,7 @@ void Sprite::show() { void Sprite::show(uint16 pg) { Graphics::Surface *a = _vm->_vga->_page[1]; - _vm->_vga->_page[1] = _vm->_vga->_page[pg & 3]; + _vm->_vga->_page[1] = _vm->_vga->_page[pg]; shp()->show(_pos2D.x, _pos2D.y); _vm->_vga->_page[1] = a; } @@ -950,6 +950,10 @@ void Bitmap::xShow(int16 x, int16 y) { void Bitmap::show(int16 x, int16 y) { + V2D pos(_vm, x, y); + xLatPos(pos); + x = pos.x; + y = pos.y; const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)_vm->_vga->_page[1]->getBasePtr(0, kScrHeight); -- cgit v1.2.3 From 6d7becb1daf00938b904dd482ce3a7a72e0d5945 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 12:21:24 +0200 Subject: CGE2: Add newRandom(). --- engines/cge2/cge2.cpp | 2 +- engines/cge2/cge2.h | 4 ++++ engines/cge2/cge2_main.cpp | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 8d7f58fb44..bd93ed22e1 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -39,7 +39,7 @@ namespace CGE2 { CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) - : Engine(syst), _gameDescription(gameDescription) { + : Engine(syst), _gameDescription(gameDescription), _randomSource("cge") { _resman = nullptr; _vga = nullptr; _sprite = nullptr; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index fa161f360a..bbd709094e 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -28,6 +28,7 @@ #ifndef CGE2_H #define CGE2_H +#include "common/random.h" #include "engines/engine.h" #include "engines/advancedDetector.h" #include "common/system.h" @@ -85,6 +86,7 @@ public: void caveUp(int cav); void showBak(int ref); void loadTab(); + int newRandom(int range); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -98,6 +100,8 @@ public: const ADGameDescription *_gameDescription; + Common::RandomSource _randomSource; + bool _quitFlag; Dac *_bitmapPalette; int _mode; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9ee9459cca..6d59cc88a4 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -413,4 +413,11 @@ void CGE2Engine::setEye(const char *s) { _eye->_z = atoi(token(NULL)); } +int CGE2Engine::newRandom(int range) { + if (!range) + return 0; + + return _randomSource.getRandomNumber(range - 1); +} + } // End of namespace CGE2 -- cgit v1.2.3 From 365bad47aec09be62da92cd6dae228ebcc896bf8 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 12:23:27 +0200 Subject: CGE2: Move showTitle() from cge2.cpp to cge2_main.cpp. --- engines/cge2/cge2.cpp | 30 ------------------------------ engines/cge2/cge2_main.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index bd93ed22e1..158ac7cce5 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -131,34 +131,4 @@ Common::Error CGE2Engine::run() { return Common::kNoError; } -bool CGE2Engine::showTitle(const char *name) { - if (_quitFlag) - return false; - - _bitmapPalette = _vga->_sysPal; - BitmapPtr *LB = new BitmapPtr[2]; - LB[0] = new Bitmap(this, name); - LB[1] = NULL; - _bitmapPalette = NULL; - - Sprite D(this, LB, 1); - D._flags._kill = true; - warning("STUB: Sprite::showTitle() - Flags changed compared to CGE1's Sprite type."); - D.gotoxyz(kScrWidth >> 1, -(kPanHeight >> 1)); - _vga->sunset(); - - D.show(2); - - _vga->copyPage(1, 2); - _vga->copyPage(0, 1); - - _vga->sunrise(_vga->_sysPal); - - _vga->update(); - - warning("STUB: CGE2Engine::showTitle()"); - - return true; -} - } // End of namespace CGE2 diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 6d59cc88a4..9647eebafd 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -420,4 +420,34 @@ int CGE2Engine::newRandom(int range) { return _randomSource.getRandomNumber(range - 1); } +bool CGE2Engine::showTitle(const char *name) { + if (_quitFlag) + return false; + + _bitmapPalette = _vga->_sysPal; + BitmapPtr *LB = new BitmapPtr[2]; + LB[0] = new Bitmap(this, name); + LB[1] = NULL; + _bitmapPalette = NULL; + + Sprite D(this, LB, 1); + D._flags._kill = true; + warning("STUB: Sprite::showTitle() - Flags changed compared to CGE1's Sprite type."); + D.gotoxyz(kScrWidth >> 1, -(kPanHeight >> 1)); + _vga->sunset(); + + D.show(2); + + _vga->copyPage(1, 2); + _vga->copyPage(0, 1); + + _vga->sunrise(_vga->_sysPal); + + _vga->update(); + + warning("STUB: CGE2Engine::showTitle()"); + + return true; +} + } // End of namespace CGE2 -- cgit v1.2.3 From dc370d49949ceae0b8aa519ee5a73c00ccac2d34 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 14:56:26 +0200 Subject: CGE2: Partially implement Sprite::expand(). --- engines/cge2/vga13h.cpp | 188 +++++++++++++++++------------------------------- 1 file changed, 65 insertions(+), 123 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 6fc22384aa..08a5a6b18e 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -205,143 +205,85 @@ Sprite *Sprite::expand() { if (_ext) return this; + if (notify != nullptr) + notify(); + _ext = new SprExt(_vm); assert(_ext != NULL); + if (!*_file) return this; - static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char fname[kPathMax]; Common::Array shplist; - for (int i = 0; i < _shpCnt + 1; ++i) + for (int i = 0; i < _shpCnt; ++i) shplist.push_back(NULL); - Seq *seq = NULL; - int shapeCount = 0, - seqCount = 0, - nearCount = 0, - takeCount = 0, + int cnt[kActions], + shpcnt = 0, + seqcnt = 0, maxnow = 0, maxnxt = 0; - warning("STUB: Sprite::expand()"); - - //CommandHandler::Command *nearList = NULL; - //CommandHandler::Command *takeList = NULL; - //_vm->mergeExt(fname, _file, kSprExt); - //if (_vm->_resman->exist(fname)) { // sprite description file exist - // EncryptedStream sprf(_vm, fname); - // if (sprf.err()) - // error("Bad SPR [%s]", fname); - // Common::String line; - // char tmpStr[kLineMax + 1]; - // int lcnt = 0; - - // for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { - // int len = line.size(); - // Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - // lcnt++; - // if (len == 0 || *tmpStr == '.') - // continue; - - // CommandHandler::Command *c; - // switch (_vm->takeEnum(Comd, strtok(tmpStr, " =\t"))) { - // case 0: - // // Name - // setName(strtok(NULL, "")); - // break; - // case 1: - // // Phase - // // In case the shape index gets too high, increase the array size - // while ((shapeCount + 1) >= (int)shplist.size()) { - // shplist.push_back(NULL); - // ++_shpCnt; - // } - // shplist[shapeCount++] = new Bitmap(_vm, strtok(NULL, " \t,;/")); - // break; - // case 2: - // // Seq - // seq = (Seq *)realloc(seq, (seqCount + 1) * sizeof(*seq)); - // assert(seq != NULL); - // Seq *s; - // s = &seq[seqCount++]; - // s->_now = atoi(strtok(NULL, " \t,;/")); - // if (s->_now > maxnow) - // maxnow = s->_now; - // s->_next = atoi(strtok(NULL, " \t,;/")); - // switch (s->_next) { - // case 0xFF: - // s->_next = seqCount; - // break; - // case 0xFE: - // s->_next = seqCount - 1; - // break; - // } - // if (s->_next > maxnxt) - // maxnxt = s->_next; - // s->_dx = atoi(strtok(NULL, " \t,;/")); - // s->_dy = atoi(strtok(NULL, " \t,;/")); - // s->_dly = atoi(strtok(NULL, " \t,;/")); - // break; - // case 3: - // // Near - // if (_nearPtr == kNoPtr) - // break; - // nearList = (CommandHandler::Command *)realloc(nearList, (nearCount + 1) * sizeof(*nearList)); - // assert(nearList != NULL); - // c = &nearList[nearCount++]; - // if ((c->_commandType = (CommandType)_vm->takeEnum(CommandHandler::_commandText, strtok(NULL, " \t,;/"))) < 0) - // error("Bad NEAR in %d [%s]", lcnt, fname); - // c->_ref = atoi(strtok(NULL, " \t,;/")); - // c->_val = atoi(strtok(NULL, " \t,;/")); - // c->_spritePtr = NULL; - // break; - // case 4: - // // Take - // if (_takePtr == kNoPtr) - // break; - // takeList = (CommandHandler::Command *)realloc(takeList, (takeCount + 1) * sizeof(*takeList)); - // assert(takeList != NULL); - // c = &takeList[takeCount++]; - // if ((c->_commandType = (CommandType)_vm->takeEnum(CommandHandler::_commandText, strtok(NULL, " \t,;/"))) < 0) - // error("Bad NEAR in %d [%s]", lcnt, fname); - // c->_ref = atoi(strtok(NULL, " \t,;/")); - // c->_val = atoi(strtok(NULL, " \t,;/")); - // c->_spritePtr = NULL; - // break; - // } - // } - //} else { - // // no sprite description: try to read immediately from .BMP - // shplist[shapeCount++] = new Bitmap(_vm, _file); - //} + Seq *seq; + if (_seqCnt) { + seq = new Seq[_seqCnt]; + if (seq == NULL) + error("No core %s", fname); + } else + seq = nullptr; + + for (int i = 0; i < kActions; i++) + cnt[i] = 0; + + for (int i = 0; i < kActions; i++){ + byte n = _actionCtrl[i]._cnt; + if (n) { + _ext->_actions[i] = new CommandHandler::Command[n]; + if (_ext->_actions[i] == nullptr) + error("No core %s", fname); + } else + _ext->_actions[i] = nullptr; + } + + int section = kIdPhase; - //shplist[shapeCount] = NULL; - //if (seq) { - // if (maxnow >= shapeCount) - // error("Bad PHASE in SEQ [%s]", fname); - // if (maxnxt >= seqCount) - // error("Bad JUMP in SEQ [%s]", fname); - // setSeq(seq); - //} else - // setSeq(getConstantSeq(_shpCnt == 1)); - - //// Set the shape list - //BitmapPtr *shapeList = new BitmapPtr[shplist.size()]; - //for (uint i = 0; i < shplist.size(); ++i) - // shapeList[i] = shplist[i]; - - //setShapeList(shapeList); - - //if (nearList) - // nearList[nearCount - 1]._spritePtr = _ext->_near = nearList; - //else - // _nearPtr = kNoPtr; - //if (takeList) - // takeList[takeCount - 1]._spritePtr = _ext->_take = takeList; - //else - // _takePtr = kNoPtr; + _vm->mergeExt(fname, _file, kSprExt); + if (_vm->_resman->exist(fname)) { // sprite description file exist + + warning("STUB: Sprite::expand()"); + + } else // no sprite description: try to read immediately from .BMP + shplist[shpcnt++] = new Bitmap (_vm, _file); + + if (seq) { + if (maxnow >= shpcnt) + error("Bad PHASE in SEQ %s", fname); + if (maxnxt && maxnxt >= seqcnt) + error("Bad JUMP in SEQ %s", fname); + setSeq(seq); + } else { + setSeq(_stdSeq8); + _seqCnt = (shpcnt < ARRAYSIZE(_stdSeq8)) ? shpcnt : ARRAYSIZE(_stdSeq8); + } + + // Set the shape list + BitmapPtr *shapeList = new BitmapPtr[shplist.size()]; + for (uint i = 0; i < shplist.size(); ++i) + shapeList[i] = shplist[i]; + + setShapeList(shapeList, shpcnt); + + if (_file[2] == '~') { // FLY-type sprite + Seq *seq = _ext->_seq; + int x = (seq + 1)->_dx, y = (seq + 1)->_dy, z = (seq + 1)->_dz; + // random position + seq->_dx = _vm->newRandom(x + x) - x; + seq->_dy = _vm->newRandom(y + y) - y; + seq->_dz = _vm->newRandom(z + z) - z; + gotoxyz(_pos3D + V3D(seq->_dx, seq->_dy, seq->_dz)); + } return this; } -- cgit v1.2.3 From 45714a12f1b522f302fc06ec5c8fd1412a05e3f4 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 15 May 2014 15:03:59 +0200 Subject: CGE2: Implement showBak(). --- engines/cge2/cge2_main.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9647eebafd..941f2b8ca4 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -343,14 +343,11 @@ void CGE2Engine::showBak(int ref) { Sprite *spr = _spare->locate(ref); if (spr != nullptr) { _bitmapPalette = _vga->_sysPal; - warning("Check again this ^ !"); spr->expand(); _bitmapPalette = NULL; - //spr->show(2); + spr->show(2); _vga->copyPage(1, 2); _spare->dispose(spr); - - warning("STUB: CGE2Engine::showBak()"); } } -- cgit v1.2.3 From b3cdf9ca3883072d33ca59e1e274eacc57fae4c1 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 16 May 2014 01:04:01 +0200 Subject: CGE2: Implement loadTab(). --- engines/cge2/cge2_main.cpp | 31 +++++++++++++++++++++++++++++-- engines/cge2/fileio.cpp | 8 ++++++++ engines/cge2/fileio.h | 2 ++ 3 files changed, 39 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 941f2b8ca4..ce84b23f2f 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -356,12 +356,39 @@ void CGE2Engine::runGame() { } void CGE2Engine::loadTab() { - char *n = _text->getText(240); setEye(_text->getText(240)); for (int i = 0; i < kCaveMax; i++) _eyeTab[i] == _eye; - warning("STUB: CGE2Engine::loadTab()"); + if (_resman->exist(kTabName)) { + EncryptedStream f(this, kTabName); + Common::File output; + for (int i = 0; i < kCaveMax; i++) { + for (int j = 0; j < 3; j++) { + signed b = f.readSigned(); + unsigned a = f.readUnsigned(); + uint16 round = uint16((long(a) << 16) / 100); + + if (round > 0x7FFF) + b++; + + switch (j) { + case 0: + _eyeTab[i]->_x = b; + break; + case 1: + _eyeTab[i]->_y = b; + break; + case 2: + _eyeTab[i]->_z = b; + break; + } + + } + } + } + + warning("STUB: CGE2Engine::loadTab() - Recheck this"); } void CGE2Engine::cge2_main() { diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index a9e9563867..5885871b29 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -216,6 +216,14 @@ uint32 EncryptedStream::read(byte *dataPtr, uint32 dataSize) { return _readStream->read(dataPtr, dataSize); } +unsigned EncryptedStream::readUnsigned() { + return _readStream->readUint16BE(); +} + +signed EncryptedStream::readSigned() { + return _readStream->readSint16BE(); +} + bool EncryptedStream::err() { return (_error & _readStream->err()); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 315002268c..a35b014311 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -121,6 +121,8 @@ public: int32 pos(); int32 size(); uint32 read(byte *dataPtr, uint32 dataSize); + unsigned readUnsigned(); + signed readSigned(); Common::String readLine(); int getLineCount() { return _lineCount; } -- cgit v1.2.3 From cb72489106881afb9a9f509d8bad4345ad2f78a6 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 17 May 2014 22:18:57 +0200 Subject: CGE2: Fix deinit(). --- engines/cge2/cge2.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 158ac7cce5..907ef9a8cd 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -90,9 +90,13 @@ void CGE2Engine::deinit() { delete _text; for (int i = 0; i < 2; i++) delete _heroTab[i]; - delete _eye; - for (int i = 0; i < kCaveMax; i++) + for (int i = 0; i < kCaveMax; i++) { + if (_eye == _eyeTab[i]) + _eye = nullptr; delete _eyeTab[i]; + } + if (_eye != nullptr) + delete _eye; delete _spare; delete _commandHandler; } -- cgit v1.2.3 From f121349503bdd3076574d11465d7b7acf3d93142 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 17 May 2014 22:34:31 +0200 Subject: CGE2: Further implement caveUp(), add stubbed loadMap(). --- engines/cge2/cge2.cpp | 1 + engines/cge2/cge2.h | 3 +++ engines/cge2/cge2_main.cpp | 9 +++++++++ 3 files changed, 13 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 907ef9a8cd..7bb861dd1d 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -62,6 +62,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _startupMode = 1; _now = 1; _sex = true; + _mouseTop = kWorldHeight / 3; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index bbd709094e..7e92664352 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -51,6 +51,7 @@ class CommandHandler; #define kScrWidth 320 #define kScrHeight 240 +#define kScrDepth 480 #define kPanHeight 40 #define kWorldHeight (kScrHeight - kPanHeight) #define kMaxFile 128 @@ -87,6 +88,7 @@ public: void showBak(int ref); void loadTab(); int newRandom(int range); + void loadMap(int cav); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -109,6 +111,7 @@ public: int _startupMode; int _now; bool _sex; + int _mouseTop; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index ce84b23f2f..9a84220299 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -335,6 +335,11 @@ void CGE2Engine::caveUp(int cav) { if (_music) _midiPlayer->loadMidi(bakRef); showBak(bakRef); + _eye = _eyeTab[_now]; + _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; + loadTab(); + + _vga->update(); warning("STUB: CGE2Engine::caveUp()"); } @@ -351,6 +356,10 @@ void CGE2Engine::showBak(int ref) { } } +void CGE2Engine::loadMap(int cav) { + warning("STUB: CGE2Engine::loadMap()"); +} + void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } -- cgit v1.2.3 From bb4679672c721dc58ec81eee1a22ae2727b1a4fc Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 17 May 2014 23:14:19 +0200 Subject: CGE2: Revise Queue. --- engines/cge2/vga13h.cpp | 78 +++++++++++++++++++++++++------------------------ engines/cge2/vga13h.h | 3 +- 2 files changed, 41 insertions(+), 40 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 08a5a6b18e..a52b8e6b96 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -314,12 +314,7 @@ Sprite *Sprite::contract() { } Sprite *Sprite::backShow(bool fast) { - expand(); - show(2); - show(1); - if (fast) - show(0); - contract(); + warning("STUB: Sprite::backShow()"); return this; } @@ -525,7 +520,7 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(unused); // _next } -Queue::Queue(bool show) : _head(NULL), _tail(NULL), _show(show) { +Queue::Queue(bool show) : _head(NULL), _tail(NULL) { } Queue::~Queue() { @@ -541,52 +536,51 @@ void Queue::clear() { } void Queue::append(Sprite *spr) { - if (_tail) { - spr->_prev = _tail; - _tail->_next = spr; - } else - _head = spr; - _tail = spr; - if (_show) + if (spr->_flags._back) + spr->backShow(); + else { spr->expand(); - else - spr->contract(); + if (_tail) { + spr->_prev = _tail; + _tail->_next = spr; + } else + _head = spr; + + _tail = spr; + } } void Queue::insert(Sprite *spr, Sprite *nxt) { - if (nxt == _head) { - spr->_next = _head; - _head = spr; - if (!_tail) - _tail = spr; - } else { - assert(nxt); - spr->_next = nxt; - spr->_prev = nxt->_prev; - if (spr->_prev) - spr->_prev->_next = spr; - } - if (spr->_next) - spr->_next->_prev = spr; - if (_show) + if (spr->_flags._back) + spr->backShow(); + else { spr->expand(); - else - spr->contract(); + if (nxt == _head) { + spr->_next = _head; + _head = spr; + if (!_tail) + _tail = spr; + } else { + spr->_next = nxt; + spr->_prev = nxt->_prev; + if (spr->_prev) + spr->_prev->_next = spr; + } + if (spr->_next) + spr->_next->_prev = spr; + } } void Queue::insert(Sprite *spr) { Sprite *s; for (s = _head; s; s = s->_next) - if (s->_pos3D._z > spr->_pos3D._z) + if (s->_pos3D._z < spr->_pos3D._z) break; + if (s) insert(spr, s); else append(spr); - if (_show) - spr->expand(); - else - spr->contract(); } template @@ -616,6 +610,14 @@ Sprite *Queue::locate(int ref) { return NULL; } +bool Queue::locate(Sprite *spr) { + Sprite *s; + for (s = _head; s; s = s->_next) + if (s == spr) + return true; + return false; +} + Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0), _vm(vm) { _oldColors = NULL; _newColors = NULL; diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index f8c7bf462d..e517a75f81 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -168,8 +168,6 @@ public: Queue(bool show); ~Queue(); - bool _show; - void append(Sprite *spr); void insert(Sprite *spr, Sprite *nxt); void insert(Sprite *spr); @@ -181,6 +179,7 @@ public: return _tail; } Sprite *locate(int ref); + bool locate(Sprite *spr); void clear(); }; -- cgit v1.2.3 From 997564d1f64559276b496b34be87ab947b0e1f1c Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 17 May 2014 23:20:21 +0200 Subject: CGE2: Reimplement backShow(). --- engines/cge2/vga13h.cpp | 8 +++++--- engines/cge2/vga13h.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index a52b8e6b96..fc5f9b4fa6 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -313,9 +313,11 @@ Sprite *Sprite::contract() { return this; } -Sprite *Sprite::backShow(bool fast) { - warning("STUB: Sprite::backShow()"); - return this; +void Sprite::backShow(void) { + expand(); + show(2); + show(1); + _vm->_spare->dispose(this); } void Sprite::step(int nr) { diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index e517a75f81..894f7b7019 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -35,6 +35,7 @@ #include "cge2/bitmap.h" #include "cge2/snail.h" #include "cge2/cge2.h" +#include "cge2/spare.h" namespace CGE2 { @@ -132,7 +133,7 @@ public: int LabVal(Action snq, int lab); Sprite *expand(); Sprite *contract(); - Sprite *backShow(bool fast = false); + void backShow(void); void setName(char *newName); inline char *name() { return (_ext) ? _ext->_name : NULL; -- cgit v1.2.3 From e0d871530622c0618c9ef350fa63d6039b223f0e Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 17 May 2014 23:33:46 +0200 Subject: CGE2: Further implement caveUp(), implement openPocket(). --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 7e92664352..bb49d0a692 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -89,6 +89,7 @@ public: void loadTab(); int newRandom(int range); void loadMap(int cav); + void openPocket(); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9a84220299..07873c64aa 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -338,6 +338,9 @@ void CGE2Engine::caveUp(int cav) { _eye = _eyeTab[_now]; _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; loadTab(); + _spare->takeCave(bakRef); + openPocket(); + _vga->update(); @@ -360,6 +363,15 @@ void CGE2Engine::loadMap(int cav) { warning("STUB: CGE2Engine::loadMap()"); } +void CGE2Engine::openPocket() { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax + 1; j++) { + int ref = (_heroTab[i])->_pocket[j]->_ref; + _heroTab[i]->_pocket[j] = (ref == -1) ? nullptr : _vga->_showQ->locate(ref); + } + } +} + void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } -- cgit v1.2.3 From 28357ab6cb4cf432baa7e5c26af76e79c6c7abde Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 18 May 2014 10:57:26 +0200 Subject: CGE2: Remove unnecessary call of loadTab(), add TODO to caveUp(). --- engines/cge2/cge2_main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 07873c64aa..d2188d7a8b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -337,14 +337,17 @@ void CGE2Engine::caveUp(int cav) { showBak(bakRef); _eye = _eyeTab[_now]; _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; - loadTab(); _spare->takeCave(bakRef); openPocket(); + warning("STUB: CGE2Engine::caveUp()"); + // TODO: Implement "Hero" things here! + + _vga->update(); - warning("STUB: CGE2Engine::caveUp()"); + } void CGE2Engine::showBak(int ref) { -- cgit v1.2.3 From 3e97ade38842b29e01692c00c452c30afe4ea67f Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 18 May 2014 11:04:30 +0200 Subject: CGE2: Revise takeCave(). --- engines/cge2/spare.cpp | 6 +++--- engines/cge2/spare.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 451cf21f9f..aff61b3f28 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -48,10 +48,10 @@ Sprite *Spare::locate(int ref) { return nullptr; } -void Spare::takeCave(int cav) { - int ref = cav << 8; +void Spare::takeCave(int ref) { Sprite *spr = locate(ref); - _vm->_vga->_showQ->insert(spr); + if (spr != nullptr) + _vm->_vga->_showQ->insert(spr); } void Spare::store(Sprite *spr) { diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index e1689c3d99..54683b9c65 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -40,7 +40,7 @@ public: ~Spare() { clear(); } void store(Sprite *spr); Sprite *locate(int ref); - void takeCave(int cav); + void takeCave(int ref); // Note that it takes the ref of the sprite now, not the number of the scene, like the original! void dispose(Sprite *spr); void dispose(int ref); void dispose(); -- cgit v1.2.3 From 938a2e66c214b9db4de563061639c74265e70fdb Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 18 May 2014 11:37:06 +0200 Subject: CGE2: Implement Spare::dispose(), add Spare::update(). --- engines/cge2/spare.cpp | 20 ++++++++++++++------ engines/cge2/spare.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index aff61b3f28..4c66e96285 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -58,16 +58,24 @@ void Spare::store(Sprite *spr) { _container.insert_at(_container.size(), spr); } -void Spare::dispose(Sprite *spr) { - warning("STUB: Spare::Dispose()"); +void Spare::update(Sprite *spr) { + Sprite *sp = locate(spr->_ref); + if (sp == nullptr) + store(spr); +} +void Spare::dispose(Sprite *spr) { if (spr) { _vm->_vga->_showQ->remove(spr); - - for (int i = 0; i < _container.size(); i++) { - if (spr == _container[i]) { - _container.remove_at(i); + update(spr->contract()); + if (spr->_ref / 10 != 14) { // IIRC if it's == 14, it's the sprite of a Hero. No idea yet why it shouldn't be deleted then. + for (int i = 0; i < _container.size(); i++) { + if (spr == _container[i]) { + _container.remove_at(i); + } } + + delete spr; } } } diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 54683b9c65..6e8f8c5987 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -41,6 +41,7 @@ public: void store(Sprite *spr); Sprite *locate(int ref); void takeCave(int ref); // Note that it takes the ref of the sprite now, not the number of the scene, like the original! + void update(Sprite *spr); void dispose(Sprite *spr); void dispose(int ref); void dispose(); -- cgit v1.2.3 From 412d30ca33adce079ed8ce0768f7662f5b055dc3 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 18 May 2014 14:01:25 +0200 Subject: CGE2: Add release() to BitMap. --- engines/cge2/bitmap.cpp | 6 ++++-- engines/cge2/bitmap.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 39483b067d..4bde584ec8 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -111,10 +111,12 @@ Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(N } Bitmap::~Bitmap() { + release(); +} + +void Bitmap::release() { free(_m); delete[] _v; - - warning("Bitmap: Don't forget to review the whole implemenation!"); } Bitmap &Bitmap::operator=(const Bitmap &bmp) { diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index ea7146f0d7..7f467903af 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -73,6 +73,7 @@ public: Bitmap *code(); Bitmap &operator=(const Bitmap &bmp); + void release(); void hide(int16 x, int16 y); void show(int16 x, int16 y); void xShow(int16 x, int16 y); -- cgit v1.2.3 From 47e55f16646403a1dea870231e4f294c0858b9a7 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 18 May 2014 14:15:13 +0200 Subject: CGE2: Initialize _actions[] in SprExt's constructor. --- engines/cge2/vga13h.cpp | 8 ++++++++ engines/cge2/vga13h.h | 5 +---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index fc5f9b4fa6..51a8c107ef 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -72,6 +72,14 @@ Seq Sprite::_stdSeq8[] = { 7, 7, 0, 0, 0, 0 }, }; +SprExt::SprExt(CGE2Engine *vm) + : _p0(vm, 0, 0), _p1(vm, 0, 0), + _b0(NULL), _b1(NULL), _shpList(NULL), + _location(0), _seq(NULL), _name(NULL) { + for (int i = 0; i < kActions; i++) + _actions[i] = nullptr; +} + Sprite::Sprite(CGE2Engine *vm) : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), _next(NULL), _prev(NULL), _time(0), diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 894f7b7019..8f73f42375 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -71,10 +71,7 @@ public: Seq *_seq; char *_name; CommandHandler::Command *_actions[kActions]; - SprExt(CGE2Engine *vm) : _p0(vm, 0, 0), _p1(vm, 0, 0), - _b0(NULL), _b1(NULL),_shpList(NULL), _location(0), - _seq(NULL), _name(NULL) - {} + SprExt(CGE2Engine *vm); }; class Sprite { -- cgit v1.2.3 From 122db4053023ab18ef957585fa31361a0dec8922 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 18 May 2014 14:18:45 +0200 Subject: CGE2: Implement Sprite::contract(): --- engines/cge2/vga13h.cpp | 51 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 51a8c107ef..57c84e020e 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -297,26 +297,41 @@ Sprite *Sprite::expand() { } Sprite *Sprite::contract() { - //SprExt *e = _ext; - //if (!e) - // return this; - - //if (e->_name) - // delete[] e->_name; - //if (_flags._bDel && e->_shpList) { - // for (int i = 0; e->_shpList[i]; i++) - // delete e->_shpList[i]; - // delete[] e->_shpList; - //} + SprExt *e = _ext; + if (!e) + return this; - //free(e->_seq); - //free(e->_near); - //free(e->_take); + if (_file[2] == '~') { // FLY-type sprite + Seq *seq = _ext->_seq; + // return to middle + gotoxyz(_pos3D - V3D(seq->_dx, seq->_dy, seq->_dz)); + seq->_dx = seq->_dy = seq->_dz = 0; + } - //delete e; - //_ext = NULL; + if (notify) + notify(); - warning("STUB: Sprite::contract()"); + if (e->_name) + delete[] e->_name; + + if (e->_shpList) { + for (int i = 0; i < _shpCnt; i++) + e->_shpList[i]->release(); + delete[] e->_shpList; + } + + if (e->_seq) { + if (e->_seq == _stdSeq8) + _seqCnt = 0; + else + delete[] e->_seq; + } + + for (int i = 0; i < kActions; i++) + if (e->_actions[i]) + delete[] e->_actions[i]; + + _ext = nullptr; return this; } @@ -379,7 +394,7 @@ void Sprite::gotoxyz(V2D pos) { rem = (rem * V2D::trunc(_vm->_eye->_z) / (V2D::trunc(_vm->_eye->_z) - z)); ctr = (ctr * 3) / 4; rem = (rem * 3) / 4; - } + } if (pos.x - ctr < 0) { pos.x = ctr; -- cgit v1.2.3 From 5d2f7cd3fd6b33fa9465817682fb8380dc25587d Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 16:08:24 +0200 Subject: CGE2: Stub openPocket() for now. --- engines/cge2/cge2_main.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index d2188d7a8b..e9674c1e60 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -367,12 +367,7 @@ void CGE2Engine::loadMap(int cav) { } void CGE2Engine::openPocket() { - for (int i = 0; i < 2; i++) { - for (int j = 0; j < kPocketMax + 1; j++) { - int ref = (_heroTab[i])->_pocket[j]->_ref; - _heroTab[i]->_pocket[j] = (ref == -1) ? nullptr : _vga->_showQ->locate(ref); - } - } + warning("STUB: CGE2Engine::openPocket()"); } void CGE2Engine::runGame() { -- cgit v1.2.3 From 6bcbe5e8baca1b5607308039d42f20e9a7d03632 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 16:16:24 +0200 Subject: CGE2: Further implement caveUp(), add stub for selectPocket(). --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index bb49d0a692..4b505cb5cb 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -90,6 +90,7 @@ public: int newRandom(int range); void loadMap(int cav); void openPocket(); + void selectPocket(int n); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e9674c1e60..1ce8ea42d1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -343,6 +343,10 @@ void CGE2Engine::caveUp(int cav) { warning("STUB: CGE2Engine::caveUp()"); // TODO: Implement "Hero" things here! + _sound->stop(); + _fx->clear(); + + selectPocket(-1); _vga->update(); @@ -370,6 +374,10 @@ void CGE2Engine::openPocket() { warning("STUB: CGE2Engine::openPocket()"); } +void CGE2Engine::selectPocket(int n) { + warning("STUB: CGE2Engine::selectPocket()"); +} + void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } -- cgit v1.2.3 From 57b9a31ac2b027dc4ddf41ad05c85bae808d4537 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 16:32:53 +0200 Subject: CGE2: Add stubbed Font and Talk. All to further implement caveUp(). --- engines/cge2/cge2.cpp | 3 ++ engines/cge2/cge2.h | 16 +++++++++ engines/cge2/cge2_main.cpp | 1 + engines/cge2/cge2_main.h | 1 + engines/cge2/module.mk | 3 +- engines/cge2/talk.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/talk.h | 78 ++++++++++++++++++++++++++++++++++++++++ engines/cge2/text.h | 2 +- 8 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 engines/cge2/talk.cpp create mode 100644 engines/cge2/talk.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 7bb861dd1d..54d3ee4c02 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -54,6 +54,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _eyeTab[i] = nullptr; _spare = nullptr; _commandHandler = nullptr; + _infoLine = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -79,6 +80,7 @@ void CGE2Engine::init() { _eyeTab[i] = new V3D(); _spare = new Spare(this); _commandHandler = new CommandHandler(this, false); + _infoLine = new InfoLine(this, kInfoW); } void CGE2Engine::deinit() { @@ -100,6 +102,7 @@ void CGE2Engine::deinit() { delete _eye; delete _spare; delete _commandHandler; + delete _infoLine; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 4b505cb5cb..59eef76989 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -48,6 +48,7 @@ class V2D; class Dac; class Spare; class CommandHandler; +class InfoLine; #define kScrWidth 320 #define kScrHeight 240 @@ -65,6 +66,20 @@ enum CallbackType { kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume }; +class Font { + char _path[kPathMax]; + void load(); + CGE2Engine *_vm; +public: + uint8 *_widthArr; + uint16 *_pos; + uint8 *_map; + Font(CGE2Engine *vm, const char *name); + ~Font(); + uint16 width(const char *text); + void save(); +}; + class CGE2Engine : public Engine { public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); @@ -127,6 +142,7 @@ public: V3D *_eyeTab[kCaveMax]; Spare *_spare; CommandHandler *_commandHandler; + InfoLine *_infoLine; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 1ce8ea42d1..2a979a02f7 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -347,6 +347,7 @@ void CGE2Engine::caveUp(int cav) { _fx->clear(); selectPocket(-1); + _infoLine->setText(nullptr); _vga->update(); diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index ee622dc9ca..9e9dca0ba2 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -34,6 +34,7 @@ namespace CGE2 { #define kIntroExt ".I80" #define kNoByte -1 #define kTabName "CGE.TAB" +#define kInfoW 140 } // End of namespace CGE2 diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 60b7db519c..4347dba315 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -11,7 +11,8 @@ MODULE_OBJS = \ text.o \ hero.o \ snail.o \ - spare.o + spare.o \ + talk.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp new file mode 100644 index 0000000000..2913327320 --- /dev/null +++ b/engines/cge2/talk.cpp @@ -0,0 +1,88 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/general.h" +#include "cge2/talk.h" +//#include "cge2/game.h" +//#include "cge2/events.h" +#include "cge2/cge2_main.h" + +namespace CGE2 { + +Font::Font(CGE2Engine *vm, const char *name) : _vm(vm) { + warning("STUB: Font::Font()"); +} + +Font::~Font() { + warning("STUB: Font::~Font()"); +} + +void Font::load() { + warning("STUB: Font::load()"); +} + +uint16 Font::width(const char *text) { + warning("STUB: Font::width()"); + return 0; +} + +Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace) + : Sprite(vm), _mode(mode), _wideSpace(wideSpace), _vm(vm) { + warning("STUB: Talk::Talk()"); +} + +Talk::Talk(CGE2Engine *vm) + : Sprite(vm), _mode(kTBPure), _vm(vm) { + warning("STUB: Talk::Talk()"); +} + +void Talk::update(const char *text) { + warning("STUB: Talk::update()"); +} + +Bitmap *Talk::box(uint16 w, uint16 h) { + warning("STUB: Talk::box()"); + return *_ts; +} + +InfoLine::InfoLine(CGE2Engine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) { + warning("STUB: InfoLine::InfoLine()"); +} + +void InfoLine::update(const char *text) { + warning("STUB: InfoLine::update()"); +} + +void InfoLine::update() { + warning("STUB: InfoLine::update()"); +} + +void InfoLine::setText(const char *txt) { + warning("STUB: InfoLine::setText()"); +} + +} // End of namespace CGE2 diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h new file mode 100644 index 0000000000..2d4c235d9d --- /dev/null +++ b/engines/cge2/talk.h @@ -0,0 +1,78 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_TALK_H +#define CGE2_TALK_H + +#include "cge2/general.h" +#include "cge2/vga13h.h" + +namespace CGE2 { + +#define kTextColFG kVgaColDark // foreground color +#define kTextColBG kVgaColGray // background color +#define kTextHMargin (6&~1) // EVEN horizontal margins! +#define kTextVMargin 5 // vertical margins +#define kTextLineSpace 2 // line spacing +#define kTextRoundCorner 3 // rounded corners +#define kWidSize 256 +#define kPosSize 256 +#define kMapSize (256*8) +#define kFontHigh 8 +#define kFontExt ".CFT" + +enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; + +class Talk : public Sprite { +protected: + TextBoxStyle _mode; + BitmapPtr *_ts; + Bitmap *box(uint16 w, uint16 h); + bool _wideSpace; +public: + Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace = false); + Talk(CGE2Engine *vm); + + virtual void update(const char *text); +private: + CGE2Engine *_vm; +}; + +class InfoLine : public Talk { + const char *_oldText; +public: + InfoLine(CGE2Engine *vm, uint16 wid); + void update(const char *text); + void update(); + void setText(const char *txt); +private: + CGE2Engine *_vm; +}; + +} // End of namespace CGE2 + +#endif // CGE2_TALK_H diff --git a/engines/cge2/text.h b/engines/cge2/text.h index 634a3c8766..bca774357a 100644 --- a/engines/cge2/text.h +++ b/engines/cge2/text.h @@ -28,7 +28,7 @@ #ifndef CGE2_TEXT_H #define CGE2_TEXT_H -//#include "cge/talk.h" +#include "cge2/talk.h" #include "cge2/cge2.h" namespace CGE2 { -- cgit v1.2.3 From b5931e205063c71ec82c7d80287b9228b2852cdc Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 16:38:26 +0200 Subject: CGE2: Further implement caveUp(), add stub for busy(). --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 59eef76989..d5015c28ab 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -106,6 +106,7 @@ public: void loadMap(int cav); void openPocket(); void selectPocket(int n); + void busy(bool on); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 2a979a02f7..4a0076d9d7 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -348,7 +348,7 @@ void CGE2Engine::caveUp(int cav) { selectPocket(-1); _infoLine->setText(nullptr); - + busy(false); _vga->update(); @@ -379,6 +379,10 @@ void CGE2Engine::selectPocket(int n) { warning("STUB: CGE2Engine::selectPocket()"); } +void CGE2Engine::busy(bool on) { + warning("STUB: CGE2Engine::selectPocket()"); +} + void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } -- cgit v1.2.3 From e6229a259608de6bf1c9f81d2e66101addef1339 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 17:10:18 +0200 Subject: CGE2: Add Mouse in events.h to further implement caveUp(). --- engines/cge2/cge2.cpp | 5 ++++ engines/cge2/cge2.h | 4 +++ engines/cge2/cge2_main.cpp | 13 ++++++++-- engines/cge2/events.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/events.h | 59 ++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/module.mk | 3 ++- 6 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 engines/cge2/events.cpp create mode 100644 engines/cge2/events.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 54d3ee4c02..385fe4ea73 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -35,6 +35,7 @@ #include "cge2/hero.h" #include "cge2/general.h" #include "cge2/spare.h" +#include "cge2/events.h" namespace CGE2 { @@ -55,6 +56,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _spare = nullptr; _commandHandler = nullptr; _infoLine = nullptr; + _mouse = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -64,6 +66,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _now = 1; _sex = true; _mouseTop = kWorldHeight / 3; + _dark = false; } void CGE2Engine::init() { @@ -81,6 +84,7 @@ void CGE2Engine::init() { _spare = new Spare(this); _commandHandler = new CommandHandler(this, false); _infoLine = new InfoLine(this, kInfoW); + _mouse = new Mouse(this); } void CGE2Engine::deinit() { @@ -103,6 +107,7 @@ void CGE2Engine::deinit() { delete _spare; delete _commandHandler; delete _infoLine; + delete _mouse; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index d5015c28ab..f3a9a287c8 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -49,6 +49,7 @@ class Dac; class Spare; class CommandHandler; class InfoLine; +class Mouse; #define kScrWidth 320 #define kScrHeight 240 @@ -107,6 +108,7 @@ public: void openPocket(); void selectPocket(int n); void busy(bool on); + void show(); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -130,6 +132,7 @@ public: int _now; bool _sex; int _mouseTop; + bool _dark; ResourceManager *_resman; Vga *_vga; @@ -144,6 +147,7 @@ public: Spare *_spare; CommandHandler *_commandHandler; InfoLine *_infoLine; + Mouse *_mouse; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 4a0076d9d7..a20dbb6cfd 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -33,6 +33,7 @@ #include "cge2/snail.h" #include "cge2/hero.h" #include "cge2/spare.h" +#include "cge2/events.h" namespace CGE2 { @@ -350,9 +351,13 @@ void CGE2Engine::caveUp(int cav) { _infoLine->setText(nullptr); busy(false); - _vga->update(); + if (!_dark) + _vga->sunset(); + show(); + _vga->copyPage(1, 0); + show(); - + _vga->update(); } void CGE2Engine::showBak(int ref) { @@ -383,6 +388,10 @@ void CGE2Engine::busy(bool on) { warning("STUB: CGE2Engine::selectPocket()"); } +void CGE2Engine::show() { + warning("STUB: CGE2Engine::show()"); +} + void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp new file mode 100644 index 0000000000..3675909d74 --- /dev/null +++ b/engines/cge2/events.cpp @@ -0,0 +1,61 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "gui/saveload.h" +#include "gui/about.h" +#include "gui/message.h" +#include "common/config-manager.h" +#include "common/events.h" +#include "engines/advancedDetector.h" +#include "cge2/events.h" +#include "cge2/text.h" +#include "cge2/cge2_main.h" + +namespace CGE2 { +/*----------------- MOUSE interface -----------------*/ + +Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { + warning("STUB: Mouse::Mouse() - Recheck the whole implementation!!!"); +} + +Mouse::~Mouse() { + warning("STUB: Mouse::~Mouse()"); +} + +void Mouse::on() { + warning("STUB: Mouse::on()"); +} + +void Mouse::off() { + warning("STUB: Mouse::off()"); +} + +void Mouse::newMouse(Common::Event &event) { + warning("STUB: Mouse::newMouse()"); +} + +} // End of namespace CGE2 diff --git a/engines/cge2/events.h b/engines/cge2/events.h new file mode 100644 index 0000000000..1442d85b39 --- /dev/null +++ b/engines/cge2/events.h @@ -0,0 +1,59 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_EVENTS_H +#define CGE2_EVENTS_H + +#include "common/events.h" +#include "cge2/talk.h" +#include "cge2/vga13h.h" + +namespace CGE2 { + +/*----------------- MOUSE interface -----------------*/ + +class Mouse : public Sprite { +public: + Sprite *_hold; + bool _active; + int _hx; + int _hy; + bool _exist; + int _buttons; + Sprite *_busy; + Mouse(CGE2Engine *vm); + ~Mouse(); + void on(); + void off(); + void newMouse(Common::Event &event); +private: + CGE2Engine *_vm; +}; + +} // End of namespace CGE + +#endif // #define CGE2_EVENTS_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 4347dba315..7272ed3829 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -12,7 +12,8 @@ MODULE_OBJS = \ hero.o \ snail.o \ spare.o \ - talk.o + talk.o \ + events.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) -- cgit v1.2.3 From 63e57b2eb62c7c3fe2a1b4d878da5941648b6603 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 17:23:50 +0200 Subject: CGE2: Fix formatting in general.h. --- engines/cge2/general.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'engines') diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 747fb84e45..bd145e1731 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -50,36 +50,36 @@ public: V3D(void) { } V3D(double x, double y, double z = 0) : _x(x), _y(y), _z(z) { } V3D(const V3D &p) : _x(p._x), _y(p._y), _z(p._z) { } - V3D operator + (const V3D& p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); } - V3D operator - (const V3D& p) const { return V3D(_x - p._x, _y - p._y, _z - p._z); } - V3D operator * (long n) const { return V3D(_x * n, _y * n, _z * n); } - V3D operator / (long n) const { return V3D(_x / n, _y / n, _z / n); } - bool operator == (V3D& p) const { return _x == p._x && _y == p._y && _z == p._z; } - bool operator != (V3D& p) const { return _x != p._x || _y != p._y || _z != p._z; } - V3D& operator += (const V3D& x) { return *this = *this + x; } - V3D& operator -= (const V3D& x) { return *this = *this - x; } + V3D operator+(const V3D &p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); } + V3D operator-(const V3D &p) const { return V3D(_x - p._x, _y - p._y, _z - p._z); } + V3D operator*(long n) const { return V3D(_x * n, _y * n, _z * n); } + V3D operator/ (long n) const { return V3D(_x / n, _y / n, _z / n); } + bool operator==(V3D &p) const { return _x == p._x && _y == p._y && _z == p._z; } + bool operator!=(V3D &p) const { return _x != p._x || _y != p._y || _z != p._z; } + V3D& operator+=(const V3D &x) { return *this = *this + x; } + V3D& operator-=(const V3D &x) { return *this = *this - x; } }; class V2D : public Common::Point { CGE2Engine *_vm; public: - V2D& operator = (const V3D& p3) { + V2D& operator=(const V3D &p3) { double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); x = round((_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m)); y = round((_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m)); return *this; } V2D(CGE2Engine *vm) : _vm(vm) { } - V2D(CGE2Engine *vm, const V3D& p3) : _vm(vm) { *this = p3; } + V2D(CGE2Engine *vm, const V3D &p3) : _vm(vm) { *this = p3; } V2D(CGE2Engine *vm, int x, int y) : _vm(vm), Common::Point(x, y) { } - bool operator < (const V2D& p) const { return (x < p.x) && (y < p.y); } - bool operator <= (const V2D& p) const { return (x <= p.x) && (y <= p.y); } - bool operator >(const V2D& p) const { return (x > p.x) && (y > p.y); } - bool operator >= (const V2D& p) const { return (x >= p.x) && (y >= p.y); } - V2D operator + (const V2D& p) const { return V2D(_vm, x + p.x, y + p.y); } - V2D operator - (const V2D& p) const { return V2D(_vm, x - p.x, y - p.y); } + bool operator<(const V2D &p) const { return (x < p.x) && (y < p.y); } + bool operator<=(const V2D &p) const { return (x <= p.x) && (y <= p.y); } + bool operator>(const V2D &p) const { return (x > p.x) && (y > p.y); } + bool operator>=(const V2D &p) const { return (x >= p.x) && (y >= p.y); } + V2D operator+(const V2D &p) const { return V2D(_vm, x + p.x, y + p.y); } + V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); } uint16 area(void) { return x * y; } - bool limited(const V2D& p) { + bool limited(const V2D &p) { return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); } V2D scale(int z) { -- cgit v1.2.3 From 06ed289509f7d9d164bddebee0c1ef85b864deef Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 17:56:19 +0200 Subject: CGE2: Revise Spare::takeCave(). --- engines/cge2/cge2_main.cpp | 3 ++- engines/cge2/spare.cpp | 14 ++++++++++---- engines/cge2/spare.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a20dbb6cfd..4ea069a356 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -208,6 +208,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { if (_sprite) { _sprite->_ref = ref; + _sprite->_scene = scene; _sprite->_flags._frnt = frnt; _sprite->_flags._east = east; @@ -338,7 +339,7 @@ void CGE2Engine::caveUp(int cav) { showBak(bakRef); _eye = _eyeTab[_now]; _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; - _spare->takeCave(bakRef); + _spare->takeCave(_now); openPocket(); warning("STUB: CGE2Engine::caveUp()"); diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 4c66e96285..dbd8425eed 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -48,10 +48,16 @@ Sprite *Spare::locate(int ref) { return nullptr; } -void Spare::takeCave(int ref) { - Sprite *spr = locate(ref); - if (spr != nullptr) - _vm->_vga->_showQ->insert(spr); +void Spare::takeCave(int cav) { + int bakRef = cav << 8; + Common::Array tempCont = _container; + for (int i = 0; i < tempCont.size(); i++) { + Sprite *spr = tempCont[i]; + int c = spr->_scene; + if ((c == _vm->_now || c == 0) && spr->_ref != bakRef) { + _vm->_vga->_showQ->insert(spr); + } + } } void Spare::store(Sprite *spr) { diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 6e8f8c5987..7bd520d9d0 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -40,7 +40,7 @@ public: ~Spare() { clear(); } void store(Sprite *spr); Sprite *locate(int ref); - void takeCave(int ref); // Note that it takes the ref of the sprite now, not the number of the scene, like the original! + void takeCave(int cav); void update(Sprite *spr); void dispose(Sprite *spr); void dispose(int ref); -- cgit v1.2.3 From 36534403e3f49cf8eee8de17d0de9bc36ff6464b Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 18:02:30 +0200 Subject: CGE2: Further implement caveUp(). --- engines/cge2/cge2_main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 4ea069a356..ed9f37aa41 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -358,7 +358,9 @@ void CGE2Engine::caveUp(int cav) { _vga->copyPage(1, 0); show(); - _vga->update(); + _sprite = _vga->_showQ->first(); + if (_startupMode) + _vga->sunrise(_vga->_sysPal); } void CGE2Engine::showBak(int ref) { -- cgit v1.2.3 From bf820481b7077ed3c6dc0599377bbbc4655ff8a7 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 19 May 2014 23:24:23 +0200 Subject: CGE2: Implement feedSnail(). --- engines/cge2/cge2.cpp | 9 +++- engines/cge2/cge2.h | 11 +++++ engines/cge2/cge2_main.cpp | 40 ++++++++++++++++ engines/cge2/cge2_main.h | 1 + engines/cge2/snail.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/snail.h | 2 - engines/cge2/spare.cpp | 6 +-- engines/cge2/vga13h.cpp | 10 ++++ engines/cge2/vga13h.h | 2 +- 9 files changed, 186 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 385fe4ea73..fe94e16387 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -36,6 +36,7 @@ #include "cge2/general.h" #include "cge2/spare.h" #include "cge2/events.h" +#include "cge2/talk.h" namespace CGE2 { @@ -55,8 +56,10 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _eyeTab[i] = nullptr; _spare = nullptr; _commandHandler = nullptr; + _commandHandlerTurbo = nullptr; _infoLine = nullptr; _mouse = nullptr; + _talk = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -83,14 +86,15 @@ void CGE2Engine::init() { _eyeTab[i] = new V3D(); _spare = new Spare(this); _commandHandler = new CommandHandler(this, false); + _commandHandlerTurbo = new CommandHandler(this, true); _infoLine = new InfoLine(this, kInfoW); _mouse = new Mouse(this); + _talk = new Talk(this); } void CGE2Engine::deinit() { delete _resman; delete _vga; - delete _sprite; delete _fx; delete _sound; delete _midiPlayer; @@ -105,9 +109,12 @@ void CGE2Engine::deinit() { if (_eye != nullptr) delete _eye; delete _spare; + delete _sprite; delete _commandHandler; + delete _commandHandlerTurbo; delete _infoLine; delete _mouse; + delete _talk; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index f3a9a287c8..0a275d5c9d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -50,6 +50,8 @@ class Spare; class CommandHandler; class InfoLine; class Mouse; +class Talk; +class Hero; #define kScrWidth 320 #define kScrHeight 240 @@ -67,6 +69,8 @@ enum CallbackType { kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume }; +enum Action { kNear, kMTake, kFTake, kActions }; + class Font { char _path[kPathMax]; void load(); @@ -109,6 +113,11 @@ public: void selectPocket(int n); void busy(bool on); void show(); + void feedSnail(Sprite *spr, Action snq, Hero *hero); + int freePockets(int sx); + int findActivePocket(int ref); + void pocFul(); + void killText(); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -146,8 +155,10 @@ public: V3D *_eyeTab[kCaveMax]; Spare *_spare; CommandHandler *_commandHandler; + CommandHandler *_commandHandlerTurbo; InfoLine *_infoLine; Mouse *_mouse; + Talk *_talk; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index ed9f37aa41..591f28a57d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -361,6 +361,9 @@ void CGE2Engine::caveUp(int cav) { _sprite = _vga->_showQ->first(); if (_startupMode) _vga->sunrise(_vga->_sysPal); + + feedSnail(_vga->_showQ->locate(bakRef + 255), kNear, _heroTab[_sex]->_ptr); + //setDrawColors(); } void CGE2Engine::showBak(int ref) { @@ -518,4 +521,41 @@ bool CGE2Engine::showTitle(const char *name) { return true; } +int CGE2Engine::freePockets(int sx) { + int n = 0; + for (int i = 0; i < kPocketMax; i++){ + if (_heroTab[sx]->_pocket[i] == nullptr) + ++n; + } + return n; +} + +int CGE2Engine::findActivePocket(int ref) { + for (int i = 0; i < kPocketMax; i++) { + Sprite *spr = _heroTab[_sex]->_pocket[i]; + if (ref >= 0) { + if (spr && spr->_ref == ref) + return i; + } else if (!spr) + return i; + } + return -1; +} + +void CGE2Engine::pocFul() { + Hero *h = _heroTab[_sex]->_ptr; + h->park(); + _commandHandler->addCommand(kCmdWait, -1, -1, h); + _commandHandler->addCommand(kCmdSound, -1, 2, h); + _commandHandler->addCommand(kCmdSay, -1, kPocketFull + _sex, h); +} + +void CGE2Engine::killText() { + if (!_talk) + return; + + _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, _talk); + _talk = NULL; +} + } // End of namespace CGE2 diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 9e9dca0ba2..432a6a4b10 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -35,6 +35,7 @@ namespace CGE2 { #define kNoByte -1 #define kTabName "CGE.TAB" #define kInfoW 140 +#define kPocketFull 170 } // End of namespace CGE2 diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 52aefe2d40..c883606422 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -27,6 +27,7 @@ #include "cge2/snail.h" #include "cge2/fileio.h" +#include "cge2/hero.h" namespace CGE2 { @@ -90,4 +91,116 @@ int CommandHandler::com(const char *com) { return (i < 0) ? i : i + kCmdCom0 + 1; } +void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { + if (!spr || !spr->active()) + return; + + int cnt = spr->_actionCtrl[snq]._cnt; + if (cnt) { + byte ptr = spr->_actionCtrl[snq]._ptr; + CommandHandler::Command *comtab = spr->snList(snq); + CommandHandler::Command *c = &comtab[ptr]; + CommandHandler::Command *p; + CommandHandler::Command *q = &comtab[cnt]; + + warning("STUB: CGE2Engine::feedSnail()"); + // Dont bother with pockets (inventory system) for now... TODO: Implement it later!!! + /* + int pocFre = freePockets(hero->_ref & 1); + int pocReq = 0; + for (p = c; p < q && p->_commandType != kCmdNext; p++) { // scan commands + // drop from pocket? + if ((p->_commandType == kCmdSend && p->_val != _now) + || p->_commandType == kCmdGive) { + int ref = p->_ref; + if (ref < 0) + ref = spr->_ref; + if (findActivePocket(ref) >= 0) + --pocReq; + } + // make/dispose additional room? + if (p->_commandType == kCmdRoom) { + if (p->_val == 0) + ++pocReq; + else + --pocReq; + } + // put into pocket? + if (p->_commandType == kCmdKeep) + ++pocReq; + // overloaded? + if (pocReq > pocFre) { + pocFul(); + return; + } + }*/ + + while (c < q) { + if (c->_commandType == kCmdTalk) { + if ((_commandHandler->_talkEnable = (c->_val != 0)) == false) + killText(); + } + if (c->_commandType == kCmdWalk || c->_commandType == kCmdReach) { + if (c->_val == -1) + c->_val = spr->_ref; + } + if (c->_commandType == kCmdNext) { + Sprite *s; + + switch (c->_ref) { + case -2: + s = hero; + break; + case -1: + s = spr; + break; + default: + s = _vga->_showQ->locate(c->_ref); + break; + } + + if (s) { + if (s->_actionCtrl[snq]._cnt) { + int v; + switch (c->_val) { + case -1: + v = int(c - comtab + 1); + break; + case -2: + v = int(c - comtab); + break; + case -3: + v = -1; + break; + default: + v = c->_val; + if ((v > 255) && s) + v = s->labVal(snq, v >> 8); + break; + } + if (v >= 0) + s->_actionCtrl[snq]._ptr = v; + } + } + if (s == spr) + break; + } + if (c->_commandType == kCmdIf) { + Sprite *s = (c->_ref < 0) ? spr : _vga->_showQ->locate(c->_ref); + if (s) { // sprite extsts + if (!s->seqTest(-1)) { // not parked + int v = c->_val; + if (v > 255) if (s) v = s->labVal(snq, v >> 8); + c = comtab + (v - 1); + } + } + } else + _commandHandler->addCommand(c->_commandType, c->_ref, c->_val, spr); + + ++c; + } + } + +} + } // End of namespace CGE2. diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index b364aa92d0..00e0d0912a 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -33,8 +33,6 @@ namespace CGE2 { -enum Action { kNear, kMTake, kFTake, kActions }; - enum CommandType { kCmdCom0 = 128, kCmdNop, // NOP :: do nothing diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index dbd8425eed..2f7a1381bf 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -34,8 +34,6 @@ void Spare::synchronize() { } void Spare::clear() { - for (int i = 0; i < _container.size(); i++) - delete _container[i]; _container.clear(); } @@ -78,10 +76,10 @@ void Spare::dispose(Sprite *spr) { for (int i = 0; i < _container.size(); i++) { if (spr == _container[i]) { _container.remove_at(i); + delete spr; + break; } } - - delete spr; } } } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 57c84e020e..d11e71f5fc 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -209,6 +209,16 @@ void Sprite::setName(char *newName) { } } +int Sprite::labVal(Action snq, int lab) { + warning("STUB: Sprite::labVal()"); + return 0; +} + +CommandHandler::Command *Sprite::snList(Action type) { + SprExt *e = _ext; + return (e) ? e->_actions[type] : NULL; +} + Sprite *Sprite::expand() { if (_ext) return this; diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 8f73f42375..6750aeebd1 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -127,7 +127,7 @@ public: void setShapeList(BitmapPtr *shp, int cnt); void moveShapesHi(void); void moveShapesLo(void); - int LabVal(Action snq, int lab); + int labVal(Action snq, int lab); Sprite *expand(); Sprite *contract(); void backShow(void); -- cgit v1.2.3 From 8a1b90acaf85166200e84f823471fbc497f9711e Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 22 May 2014 14:01:05 +0200 Subject: CGE2: Fix loadSprite(). --- engines/cge2/cge2_main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 591f28a57d..3a4ff180c0 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -99,11 +99,10 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ int len = line.size(); + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); if (len == 0 || *tmpStr == ';') continue; - - Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - + char *p; p = token(tmpStr); if (*p == '@') { -- cgit v1.2.3 From ba8e801ada1be7dbf7329ca444e20a24f7dca166 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 10:05:02 +0200 Subject: CGE2: Implement Sprite::expand(). Add functions: *Bitmap::moveHi() *Bitmap::moveLo() *CGE2Engine::tail() and warning comments to various places during the process. Also add _lab data member to CommandHandler::Command. --- engines/cge2/bitmap.cpp | 10 ++++ engines/cge2/bitmap.h | 2 + engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 10 +++- engines/cge2/cge2_main.h | 2 +- engines/cge2/snail.h | 1 + engines/cge2/vga13h.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 131 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 4bde584ec8..10fd6f1163 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -375,4 +375,14 @@ void Bitmap::xLatPos(V2D& p) { p.y = kWorldHeight - p.y - _h; } +bool Bitmap::moveHi(void) { + warning("STUB: Bitmap::moveHi()"); + return true; +} + +bool Bitmap::moveLo(void) { + warning("STUB: Bitmap::moveLo()"); + return true; +} + } // End of namespace CGE2 diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 7f467903af..07f83b8045 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -79,6 +79,8 @@ public: void xShow(int16 x, int16 y); bool solidAt(int16 x, int16 y); void xLatPos(V2D& p); + bool moveHi(void); + bool moveLo(void); }; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 0a275d5c9d..5e16864cb5 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -125,6 +125,7 @@ public: int number(char *s); char *token(char *s); + char *tail(char *s); int takeEnum(const char **tab, const char *text); ID ident(const char *s); bool testBool(char *s); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 3a4ff180c0..f11965c07d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -37,7 +37,7 @@ namespace CGE2 { -int CGE2Engine::number(char *s) { +int CGE2Engine::number(char *s) { // TODO: Rework it later to include the preceding token() call! int r = atoi(s); char *pp = strchr(s, ':'); if (pp) @@ -49,6 +49,12 @@ char *CGE2Engine::token(char *s) { return strtok(s, " =\t,;/()"); } +char *CGE2Engine::tail(char *s) { + if (s && (*s == '=')) + s++; + return s; +} + int CGE2Engine::takeEnum(const char **tab, const char *text) { if (text) { for (const char **e = tab; *e; e++) { @@ -222,7 +228,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { *p = '\0'; _sprite->_shpCnt = shpcnt; - _sprite->_seqPtr = seqcnt; + _sprite->_seqCnt = seqcnt; for (int i = 0; i < kActions; i++) _sprite->_actionCtrl[i]._cnt = cnt[i]; diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 432a6a4b10..1472e2ef7b 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -32,7 +32,7 @@ namespace CGE2 { #define kLineMax 512 #define kIntroExt ".I80" -#define kNoByte -1 +#define kNoByte -1 // Recheck this! We have no proof for it's original value. #define kTabName "CGE.TAB" #define kInfoW 140 #define kPocketFull 170 diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 00e0d0912a..a2f4bec028 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -114,6 +114,7 @@ class CommandHandler { public: struct Command { CommandType _commandType; + byte _lab; int _ref; int _val; void *_spritePtr; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index d11e71f5fc..992d0c0d10 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -232,8 +232,6 @@ Sprite *Sprite::expand() { if (!*_file) return this; - char fname[kPathMax]; - Common::Array shplist; for (int i = 0; i < _shpCnt; ++i) shplist.push_back(NULL); @@ -244,6 +242,9 @@ Sprite *Sprite::expand() { maxnow = 0, maxnxt = 0; + char fname[kPathMax]; + _vm->mergeExt(fname, _file, kSprExt); + Seq *seq; if (_seqCnt) { seq = new Seq[_seqCnt]; @@ -265,14 +266,114 @@ Sprite *Sprite::expand() { _ext->_actions[i] = nullptr; } - int section = kIdPhase; - - _vm->mergeExt(fname, _file, kSprExt); if (_vm->_resman->exist(fname)) { // sprite description file exist + EncryptedStream sprf(_vm, fname); + if (sprf.err()) + error("Bad SPR [%s]", fname); + + int label = kNoByte; + ID section = kIdPhase; + ID id; + Common::String line; + char tmpStr[kLineMax + 1]; + + for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ + int len = line.size(); + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + if (len == 0 || *tmpStr == ';') + continue; + + char *p = _vm->token(tmpStr); + if (*p == '@') { + label = atoi(p + 1); + continue; + } - warning("STUB: Sprite::expand()"); + id = _vm->ident(p); + switch (id) { + case kIdType: + break; + case kIdNear: + case kIdMTake: + case kIdFTake: + case kIdPhase: + case kIdSeq: + section = id; + break; + case kIdName: + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + for (p = tmpStr; *p != '='; p++); // We search for the = + setName(_vm->tail(p)); + break; + default: + if (id >= kIdNear) + break; + Seq *s; + switch (section) { + case kIdNear: + case kIdMTake: + case kIdFTake: + id = (ID)_vm->_commandHandler->com(p); + if (_actionCtrl[section]._cnt) { + CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; + c->_commandType = CommandType(id); + c->_lab = label; + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + c->_ref = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + c->_val = _vm->number(p); + c->_spritePtr = nullptr; + } + break; + case kIdSeq: + s = &seq[seqcnt++]; + s->_now = atoi(p); + if (s->_now > maxnow) + maxnow = s->_now; + if ((p = _vm->token(nullptr)) == NULL) + break; + s->_next = _vm->number(p); + switch (s->_next) { + case 0xFF: + s->_next = seqcnt; + break; + case 0xFE: + s->_next = seqcnt - 1; + break; + } + if (s->_next > maxnxt) + maxnxt = s->_next; + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dx = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dy = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dz = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dly = _vm->number(p); + break; + case kIdPhase: + BitmapPtr bmp = new Bitmap(_vm, p); + shplist[shpcnt] = bmp; + if (!shplist[shpcnt]->moveHi()) + error("No EMS"); + shpcnt++; + break; + } + break; + } + label = kNoByte; + } - } else // no sprite description: try to read immediately from .BMP + if (!shpcnt) + error("No shapes - %s", fname); + } else // no sprite description: try to read immediately from .BMP shplist[shpcnt++] = new Bitmap (_vm, _file); if (seq) { -- cgit v1.2.3 From afa15dd74f0a97d373409bb39333b5f25e7f507a Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 10:12:48 +0200 Subject: CGE2: Add explanation to comment in caveUp(). --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f11965c07d..05dcc802bf 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -368,7 +368,7 @@ void CGE2Engine::caveUp(int cav) { _vga->sunrise(_vga->_sysPal); feedSnail(_vga->_showQ->locate(bakRef + 255), kNear, _heroTab[_sex]->_ptr); - //setDrawColors(); + //setDrawColors(); - It's only for debugging purposes. Can be left out for now. } void CGE2Engine::showBak(int ref) { -- cgit v1.2.3 From e98554309d85578826001d9305b0e4c4df658450 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 10:55:58 +0200 Subject: CGE2: Add mainLoop() and handleFrame(). Also implement connecting things. --- engines/cge2/cge2.cpp | 2 ++ engines/cge2/cge2.h | 5 ++++ engines/cge2/cge2_main.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/cge2_main.h | 8 +++--- engines/cge2/vga13h.cpp | 6 ++--- engines/cge2/vga13h.h | 2 +- 6 files changed, 78 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index fe94e16387..89ec3b0b42 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -70,6 +70,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _sex = true; _mouseTop = kWorldHeight / 3; _dark = false; + _lastFrame = 0; + _lastTick = 0; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 5e16864cb5..0c3670ff00 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -86,6 +86,9 @@ public: }; class CGE2Engine : public Engine { +private: + uint32 _lastFrame, _lastTick; + void tick(); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); virtual bool hasFeature(EngineFeature f) const; @@ -118,6 +121,8 @@ public: int findActivePocket(int ref); void pocFul(); void killText(); + void mainLoop(); + void handleFrame(); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 05dcc802bf..ad1d3a6a4c 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -330,8 +330,15 @@ void CGE2Engine::movie(const char *ext) { loadScript(fn); caveUp(_now); + while (!_commandHandler->idle() && !_quitFlag) + mainLoop(); + warning("STUB: CGE2Engine::movie()"); + _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); + _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); + _vga->_showQ->clear(); + _spare->clear(); _now = now; } } @@ -383,8 +390,62 @@ void CGE2Engine::showBak(int ref) { } } +void CGE2Engine::mainLoop() { + _vga->show(); + _commandHandlerTurbo->runCommand(); + _commandHandler->runCommand(); + + // Handle a delay between game frames + handleFrame(); + + // Handle any pending events + //_eventManager->poll(); + warning("STUB: CGE2Engine::mainLoop() - Event handling is missing!"); + + // Check shouldQuit() + _quitFlag = shouldQuit(); +} + +void CGE2Engine::handleFrame() { + // Game frame delay + uint32 millis = g_system->getMillis(); + while (!_quitFlag && (millis < (_lastFrame + kGameFrameDelay))) { + // Handle any pending events + //_eventManager->poll(); + warning("STUB: CGE2Engine::handleFrame() - Event handling is missing!"); + + if (millis >= (_lastTick + kGameTickDelay)) { + // Dispatch the tick to any active objects + tick(); + _lastTick = millis; + } + + // Slight delay + g_system->delayMillis(5); + millis = g_system->getMillis(); + } + _lastFrame = millis; + + if (millis >= (_lastTick + kGameTickDelay)) { + // Dispatch the tick to any active objects + tick(); + _lastTick = millis; + } +} + +void CGE2Engine::tick() { + for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { + if (spr->_time) { + if (!spr->_flags._hide) { + if (--spr->_time == 0) + spr->tick(); + } + } + } +} + void CGE2Engine::loadMap(int cav) { - warning("STUB: CGE2Engine::loadMap()"); + warning("STUB: CGE2Engine::loadMap()"); } void CGE2Engine::openPocket() { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 1472e2ef7b..a0a8bd16a1 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -31,11 +31,13 @@ namespace CGE2 { #define kLineMax 512 -#define kIntroExt ".I80" -#define kNoByte -1 // Recheck this! We have no proof for it's original value. -#define kTabName "CGE.TAB" +#define kIntroExt ".I80" +#define kNoByte -1 // Recheck this! We have no proof for it's original value. +#define kTabName "CGE.TAB" #define kInfoW 140 #define kPocketFull 170 +#define kGameFrameDelay (1000 / 50) +#define kGameTickDelay (1000 / 62) } // End of namespace CGE2 diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 992d0c0d10..46515e7171 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -458,9 +458,9 @@ void Sprite::step(int nr) { warning("STUB: Sprite::step()"); } -//void Sprite::tick() { -// step(); -//} +void Sprite::tick() { + step(); +} void Sprite::makeXlat(uint8 *x) { if (!_ext) diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 6750aeebd1..77a2fd35be 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -152,7 +152,7 @@ public: Seq *setSeq(Seq *seq); CommandHandler::Command *snList(Action type); //virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); - //virtual void tick(); + virtual void tick(); void clrHide(void) { if (_ext) _ext->_b0 = NULL; } void sync(Common::Serializer &s); -- cgit v1.2.3 From 7777a48dabefbd03c0ca986056b3ae81322de4c1 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 11:19:42 +0200 Subject: CGE2: Fix caveUp(). Remove CGE2Engine::show() to do so. --- engines/cge2/cge2.h | 1 - engines/cge2/cge2_main.cpp | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 0c3670ff00..2ffc2125e5 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -115,7 +115,6 @@ public: void openPocket(); void selectPocket(int n); void busy(bool on); - void show(); void feedSnail(Sprite *spr, Action snq, Hero *hero); int freePockets(int sx); int findActivePocket(int ref); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index ad1d3a6a4c..2b3ab44414 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -366,9 +366,9 @@ void CGE2Engine::caveUp(int cav) { if (!_dark) _vga->sunset(); - show(); + _vga->show(); _vga->copyPage(1, 0); - show(); + _vga->show(); _sprite = _vga->_showQ->first(); if (_startupMode) @@ -460,10 +460,6 @@ void CGE2Engine::busy(bool on) { warning("STUB: CGE2Engine::selectPocket()"); } -void CGE2Engine::show() { - warning("STUB: CGE2Engine::show()"); -} - void CGE2Engine::runGame() { warning("STUB: CGE2Engine::runGame()"); } -- cgit v1.2.3 From c734aa08b1c564e724c8ec2a60719221bb07cff1 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 11:22:43 +0200 Subject: CGE2: Implement Sprite::show(). --- engines/cge2/vga13h.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 46515e7171..b258ae7414 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -565,7 +565,15 @@ void Sprite::center() { } void Sprite::show() { - warning("STUB: Sprite::show()"); + SprExt *e = _ext; + if (e) { + e->_p0 = e->_p1; + e->_b0 = e->_b1; + e->_p1 = _pos2D; + e->_b1 = shp(); + } + if (!_flags._hide) + e->_b1->show(e->_p1.x, e->_p1.y); } void Sprite::show(uint16 pg) { -- cgit v1.2.3 From 02817a7bd5b5ade5afb51f2ea545238d284b2fd8 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 11:40:56 +0200 Subject: CGE2: Implement Sprite::hide(). --- engines/cge2/vga13h.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index b258ae7414..662ea4495e 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -584,7 +584,9 @@ void Sprite::show(uint16 pg) { } void Sprite::hide() { - warning("STUB: Sprite::hide()"); + SprExt *e = _ext; + if (e->_b0) + e->_b0->hide(e->_p0.x, e->_p0.y); } BitmapPtr Sprite::ghost() { @@ -1093,6 +1095,10 @@ void Bitmap::show(int16 x, int16 y) { void Bitmap::hide(int16 x, int16 y) { + V2D pos(_vm, x, y); + xLatPos(pos); + x = pos.x; + y = pos.y; for (int yp = y; yp < y + _h; yp++) { const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(x, yp); byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x, yp); -- cgit v1.2.3 From 4dcfe4d7853cc59b0c93f43115dc13d17470386f Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 12:56:48 +0200 Subject: CGE2: Start implementation of CommandHandler. Implement constructor, destructor, addCommand() and add clear() ant _count. --- engines/cge2/snail.cpp | 26 ++++++++++++++++++++++---- engines/cge2/snail.h | 4 +++- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index c883606422..5b61d1f7ef 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -53,12 +53,14 @@ const char *CommandHandler::_commandText[] = { "WALKTO", "REACH", "COVER", "UNCOVER", NULL }; -CommandHandler::CommandHandler(CGE2Engine *vm, bool turbo) : _vm(vm) { - warning("STUB: CommandHandler::CommandHandler()"); +CommandHandler::CommandHandler(CGE2Engine *vm, bool turbo) + : _turbo(turbo), _textDelay(false), _timerExpiry(0), _talkEnable(true), + _head(0), _tail(0), _commandList((Command *)malloc(sizeof(Command)* 256)), + _count(1), _vm(vm) { } CommandHandler::~CommandHandler() { - warning("STUB: CommandHandler::~CommandHandler()"); + free(_commandList); } void CommandHandler::runCommand() { @@ -66,7 +68,17 @@ void CommandHandler::runCommand() { } void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { - warning("STUB: CommandHandler::addCommand()"); + if (ref == 2) + ref = 142 - _vm->_sex; + Command *headCmd = &_commandList[_head++]; + headCmd->_commandType = com; + headCmd->_ref = ref; + headCmd->_val = val; + headCmd->_spritePtr = ptr; + headCmd->_cbType = kNullCB; + if (headCmd->_commandType == kCmdClear) { + clear(); + } } void CommandHandler::addCallback(CommandType com, int ref, int val, CallbackType cbType) { @@ -86,6 +98,12 @@ void CommandHandler::reset() { warning("STUB: CommandHandler::reset()"); } +void CommandHandler::clear() { + _tail = _head; + _vm->killText(); + _timerExpiry = 0; +} + int CommandHandler::com(const char *com) { int i = _vm->takeEnum(_commandText, com); return (i < 0) ? i : i + kCmdCom0 + 1; diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index a2f4bec028..889b16cd2d 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -131,6 +131,7 @@ public: void insertCommand(CommandType com, int ref, int val, void *ptr); bool idle(); void reset(); + void clear(); int com(const char *com); private: CGE2Engine *_vm; @@ -139,7 +140,8 @@ private: uint8 _tail; bool _busy; bool _textDelay; - uint32 _timerExpiry; + uint32 _timerExpiry; // "pause" in the original. + int _count; }; } // End of namespace CGE2 -- cgit v1.2.3 From e2ca4382d86ac869f8628441924cc7f19a0b7b4e Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 13:06:50 +0200 Subject: CGE2: Implement CommandHandler::idle(). --- engines/cge2/cge2.cpp | 1 + engines/cge2/cge2.h | 1 + engines/cge2/snail.cpp | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 89ec3b0b42..2f9cf1a7a3 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -72,6 +72,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _dark = false; _lastFrame = 0; _lastTick = 0; + _waitRef = 0; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 2ffc2125e5..f1982f7a04 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -147,6 +147,7 @@ public: bool _sex; int _mouseTop; bool _dark; + int _waitRef; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 5b61d1f7ef..1eafd616d6 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -90,8 +90,7 @@ void CommandHandler::insertCommand(CommandType com, int ref, int val, void *ptr) } bool CommandHandler::idle() { - warning("STUB: CommandHandler::idle()"); - return false; + return (!_vm->_waitRef && _head == _tail); } void CommandHandler::reset() { -- cgit v1.2.3 From 947f4b860759940dfc6420ca84870b210b1253c5 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 23 May 2014 15:23:19 +0200 Subject: CGE2: Partially implement CommandHandler::runCommand(). --- engines/cge2/cge2.cpp | 10 ++ engines/cge2/cge2.h | 49 ++++++ engines/cge2/cge2_main.cpp | 15 ++ engines/cge2/snail.cpp | 404 ++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/snail.h | 3 + 5 files changed, 480 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 2f9cf1a7a3..e15e096d9f 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -60,6 +60,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _infoLine = nullptr; _mouse = nullptr; _talk = nullptr; + for (int i = 0; i < kMaxPoint; i++) + _point[i] = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -72,7 +74,10 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _dark = false; _lastFrame = 0; _lastTick = 0; + _waitSeq = 0; _waitRef = 0; + _commandStat = { nullptr, { 0 , 0 } }; + _taken = false; } void CGE2Engine::init() { @@ -93,6 +98,8 @@ void CGE2Engine::init() { _infoLine = new InfoLine(this, kInfoW); _mouse = new Mouse(this); _talk = new Talk(this); + for (int i = 0; i < kMaxPoint; i++) + _point[i] = new V3D(); } void CGE2Engine::deinit() { @@ -118,6 +125,9 @@ void CGE2Engine::deinit() { delete _infoLine; delete _mouse; delete _talk; + for (int i = 0; i < kMaxPoint; i++) { + delete _point[i]; + } } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index f1982f7a04..4e5adde36d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -52,6 +52,7 @@ class InfoLine; class Mouse; class Talk; class Hero; +class Bitmap; #define kScrWidth 320 #define kScrHeight 240 @@ -64,6 +65,7 @@ class Hero; #define kWayMax 10 #define kPocketMax 4 #define kCaveMax 100 +#define kMaxPoint 4 enum CallbackType { kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume @@ -108,6 +110,7 @@ public: void loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); void caveUp(int cav); + void switchCave(int cav); void showBak(int ref); void loadTab(); int newRandom(int range); @@ -122,6 +125,7 @@ public: void killText(); void mainLoop(); void handleFrame(); + Sprite *locate(int ref); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -134,6 +138,44 @@ public: ID ident(const char *s); bool testBool(char *s); + void snKill(Sprite *spr); + void snHide(Sprite *spr, int val); + void snMidi(int val); + void snSetDlg(int clr, int set); + void snMskDlg(int clr, int set); + void snSeq(Sprite *spr, int val); + void snRSeq(Sprite *spr, int val); + void snSend(Sprite *spr, int val); + void snSwap(Sprite *spr, int val); + void snCover(Sprite *spr, int val); + void snUncover(Sprite *spr, Sprite *spr2); + void snFocus(int val); + void snKeep(Sprite *spr, int val); + void snGive(Sprite *spr, int val); + void snGoto(Sprite *spr, int val); + void snMove(Sprite *spr, V3D pos); + void snSlave(Sprite *spr, int val); + void snTrans(Sprite *spr, int val); + void snPort(Sprite *spr, int val); + void snMouse(int val); + void snNNext(Sprite *spr, Action act, int val); + void snRNNext(Sprite *spr, int val); + void snRMTNext(Sprite *spr, int val); + void snRFTNext(Sprite *spr, int val); + void snRmNear(Sprite *spr); + void snRmMTake(Sprite *spr); + void snRmFTake(Sprite *spr); + void snFlag(int ref, int val); + void snSetRef(Sprite *spr, int val); + void snBackPt(Sprite *spr, int val); + void snFlash(int val); + void snLight(int val); + void snWalk(Sprite *spr, int val); + void snReach(Sprite *spr, int val); + void snSound(Sprite *spr, int val, int cnt); + void snRoom(Sprite *spr, int val); + void snGhost(Bitmap *bmp); + const ADGameDescription *_gameDescription; Common::RandomSource _randomSource; @@ -147,7 +189,13 @@ public: bool _sex; int _mouseTop; bool _dark; + int _waitSeq; int _waitRef; + struct CommandStat { + int *_wait; + int _ref[2]; + } _commandStat; + bool _taken; ResourceManager *_resman; Vga *_vga; @@ -165,6 +213,7 @@ public: InfoLine *_infoLine; Mouse *_mouse; Talk *_talk; + V3D *_point[kMaxPoint]; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 2b3ab44414..fba0cd060d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -378,6 +378,10 @@ void CGE2Engine::caveUp(int cav) { //setDrawColors(); - It's only for debugging purposes. Can be left out for now. } +void CGE2Engine::switchCave(int cav) { + warning("STUB: CGE2Engine::switchCave()"); +} + void CGE2Engine::showBak(int ref) { Sprite *spr = _spare->locate(ref); if (spr != nullptr) { @@ -433,6 +437,17 @@ void CGE2Engine::handleFrame() { } } +Sprite *CGE2Engine::locate(int ref) { + _taken = false; + Sprite *spr = _vga->_showQ->locate(ref); + if (!spr) { + spr = _spare->locate(ref); + if (spr) + _taken = true; + } + return spr; +} + void CGE2Engine::tick() { for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time) { diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 1eafd616d6..052188c6e0 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -28,6 +28,7 @@ #include "cge2/snail.h" #include "cge2/fileio.h" #include "cge2/hero.h" +#include "cge2/text.h" namespace CGE2 { @@ -64,7 +65,408 @@ CommandHandler::~CommandHandler() { } void CommandHandler::runCommand() { - warning("STUB: CommandHandler::runCommand()"); + if (!_turbo && _vm->_commandStat._wait) { + if (*(_vm->_commandStat._wait)) + return; + else { + ++_vm->_commandStat._ref[0]; + warning("STUB: CommandHandler::runCommand() - Sound code missing!"); + _vm->_commandStat._wait = nullptr; + } + } + + uint8 tmpHead = _head; + while (_tail != tmpHead) { + Command tailCmd = _commandList[_tail]; + + if (!_turbo) { // only for the slower one + if (_vm->_waitRef) + break; + if (_timerExpiry) { + // Delay in progress + if (_timerExpiry > g_system->getMillis()) + // Delay not yet ended + break; + + // Delay is finished + _timerExpiry = 0; + } else { + if (_textDelay) { + if (_vm->_talk) { + _vm->snKill((Sprite *)_vm->_talk); + _vm->_talk = nullptr; + } + _textDelay = false; + } + } + if (_vm->_talk && tailCmd._commandType != kCmdPause) + break; + } + ++_tail; + _vm->_taken = false; + Sprite *spr; + if (tailCmd._commandType > kCmdSpr) + spr = (tailCmd._ref < 0) ? ((Sprite *)tailCmd._spritePtr) : _vm->locate(tailCmd._ref); + + switch (tailCmd._commandType) { + case kCmdUse: + break; + case kCmdPause: + _timerExpiry = g_system->getMillis() + tailCmd._val * kCommandFrameDelay; + if (_vm->_talk) + _textDelay = true; + break; + case kCmdWait: + if (spr && spr->active() && (spr->_scene == _vm->_now || spr->_scene == 0)) { + _vm->_waitSeq = tailCmd._val; + _vm->_waitRef = spr->_ref; + } + break; + case kCmdHide: + _vm->snHide(spr, tailCmd._val); + break; + case kCmdSay: + if (spr && spr->active() && _talkEnable) //-- mouth animation + warning("STUB: CommandHandler::runCommand() - Mouth animation missing!"); + break; + case kCmdInf: + if (_talkEnable) + _vm->inf(((tailCmd._val) >= 0) ? _vm->_text->getText(tailCmd._val) : (const char *)tailCmd._spritePtr); + break; + case kCmdTime: + warning("STUB: CommandHandler::runCommand() - Something missing connected to kCmdTime!"); + break; + case kCmdCave: + _vm->switchCave(tailCmd._val); + break; + case kCmdMidi: + _vm->snMidi(tailCmd._val); + break; + case kCmdSetDlg: + _vm->snSetDlg(tailCmd._ref, tailCmd._val); + break; + case kCmdMskDlg: + _vm->snMskDlg(tailCmd._ref, tailCmd._val); + break; + case kCmdKill: + _vm->snKill(spr); + break; + case kCmdSeq: + _vm->snSeq(spr, tailCmd._val); + break; + case kCmdRSeq: + _vm->snRSeq(spr, tailCmd._val); + break; + case kCmdSend: + _vm->snSend(spr, tailCmd._val); + break; + case kCmdSwap: + _vm->snSwap(spr, tailCmd._val); + break; + case kCmdCover: + _vm->snCover(spr, tailCmd._val); + break; + case kCmdUncover: + _vm->snUncover(spr, (tailCmd._val >= 0) ? _vm->locate(tailCmd._val) : ((Sprite *)tailCmd._spritePtr)); + break; + case kCmdFocus: + _vm->snFocus(tailCmd._val); + break; + case kCmdKeep: + _vm->snKeep(spr, tailCmd._val); + break; + case kCmdGive: + _vm->snGive(spr, tailCmd._val); + break; + case kCmdSetX: + _vm->_point[tailCmd._val]->_x = tailCmd._ref; + break; + case kCmdSetY: + _vm->_point[tailCmd._val]->_y = tailCmd._ref; + break; + case kCmdSetZ: + _vm->_point[tailCmd._val]->_z = tailCmd._ref; + break; + case kCmdAdd: + *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) + *(_vm->_point[tailCmd._val]); + break; + case kCmdSub: + *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) - *(_vm->_point[tailCmd._val]); + break; + case kCmdMul: + *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) * tailCmd._val; + break; + case kCmdDiv: + *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) / tailCmd._val; + break; + case kCmdGetPos: + if (spr) + *(_vm->_point[tailCmd._val]) = spr->_pos3D; + break; + case kCmdGoto: + _vm->snGoto(spr, tailCmd._val); + break; + case kCmdMoveX: + _vm->snMove(spr, V3D(tailCmd._val, 0, 0)); + break; + case kCmdMoveY: + _vm->snMove(spr, V3D(0, tailCmd._val, 0)); + break; + case kCmdMoveZ: + _vm->snMove(spr, V3D(0, 0, tailCmd._val)); + break; + case kCmdSlave: + _vm->snSlave(spr, tailCmd._val); + break; + case kCmdTrans: + _vm->snTrans(spr, tailCmd._val); + break; + case kCmdPort: + _vm->snPort(spr, tailCmd._val); + break; + case kCmdNext: + break; + case kCmdIf: + break; + case kCmdTalk: + break; + case kCmdMouse: + _vm->snMouse(tailCmd._val != 0); + break; + case kCmdNNext: + _vm->snNNext(spr, kNear, tailCmd._val); + break; + case kCmdMTNext: + _vm->snNNext(spr, kMTake, tailCmd._val); + break; + case kCmdFTNext: + _vm->snNNext(spr, kFTake, tailCmd._val); + break; + case kCmdRNNext: + _vm->snRNNext(spr, tailCmd._val); + break; + case kCmdRMTNext: + _vm->snRMTNext(spr, tailCmd._val); + break; + case kCmdRFTNext: + _vm->snRFTNext(spr, tailCmd._val); + break; + case kCmdRMNear: + _vm->snRmNear(spr); + break; + case kCmdRMMTake: + _vm->snRmMTake(spr); + break; + case kCmdRMFTake: + _vm->snRmFTake(spr); + break; + case kCmdFlag: + _vm->snFlag(tailCmd._ref & 3, tailCmd._val); + break; + case kCmdSetRef: + _vm->snSetRef(spr, tailCmd._val); + break; + case kCmdBackPt: + _vm->snBackPt(spr, tailCmd._val); + break; + case kCmdFlash: + _vm->snFlash(tailCmd._val != 0); + break; + case kCmdLight: + _vm->snLight(tailCmd._val != 0); + break; + case kCmdCycle: + warning("Unhandled command - kCmdCycle"); + break; + case kCmdWalk: + _vm->snWalk(spr, tailCmd._val); + break; + case kCmdReach: + _vm->snReach(spr, tailCmd._val); + break; + case kCmdSound: + _vm->snSound(spr, tailCmd._val, _count); + _count = 1; + break; + case kCmdMap: + _vm->_heroTab[tailCmd._ref & 1]->_ptr->_ignoreMap = tailCmd._val == 0; + break; + case kCmdCount: + _count = tailCmd._val; + break; + case kCmdRoom: + _vm->snRoom(spr, tailCmd._val); + break; + case kCmdDim: + warning("Unhandled command - kCmdDim"); + break; + case kCmdExec: + warning("Unhandled command - kCmdExec"); + break; + case kCmdStep: + spr->step(); + break; + case kCmdGhost: + _vm->snGhost((Bitmap *)tailCmd._spritePtr); + break; + default: + warning("Unhandled command"); + break; + } + + if (_vm->_taken) + _vm->_spare->dispose(spr); + + if (!_turbo) + break; + } +} + +void CGE2Engine::snKill(Sprite *spr) { + warning("STUB: CGE2Engine::snKill()"); +} + +void CGE2Engine::snHide(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snHide()"); +} + +void CGE2Engine::snMidi(int val) { + warning("STUB: CGE2Engine::snMidi()"); +} + +void CGE2Engine::snSetDlg(int clr, int set) { + warning("STUB: CGE2Engine::snSetDlg()"); +} + +void CGE2Engine::snMskDlg(int clr, int set) { + warning("STUB: CGE2Engine::snMskDlg()"); +} + +void CGE2Engine::snSeq(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snSeq()"); +} + +void CGE2Engine::snRSeq(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snRSeq()"); +} + +void CGE2Engine::snSend(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snSend()"); +} + +void CGE2Engine::snSwap(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snSwap()"); +} +void CGE2Engine::snCover(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snCover()"); +} + +void CGE2Engine::snUncover(Sprite *spr, Sprite *spr2) { + warning("STUB: CGE2Engine::snUncover()"); +} + +void CGE2Engine::snFocus(int val) { + warning("STUB: CGE2Engine::snFocus()"); +} + +void CGE2Engine::snKeep(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snKeep()"); +} + +void CGE2Engine::snGive(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snGive()"); +} + +void CGE2Engine::snGoto(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snGoto()"); +} + +void CGE2Engine::snMove(Sprite *spr, V3D pos) { + warning("STUB: CGE2Engine::snMove()"); +} + +void CGE2Engine::snSlave(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snSlave()"); +} + +void CGE2Engine::snTrans(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snTrans()"); +} + +void CGE2Engine::snPort(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snPort()"); +} + +void CGE2Engine::snMouse(int val) { + warning("STUB: CGE2Engine::snMouse()"); +} + +void CGE2Engine::snNNext(Sprite *spr, Action act, int val) { + warning("STUB: CGE2Engine::snNNext()"); +} + +void CGE2Engine::snRNNext(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snRNNext()"); +} + +void CGE2Engine::snRMTNext(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snRMTNext()"); +} + +void CGE2Engine::snRFTNext(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snRFTNext()"); +} + +void CGE2Engine::snRmNear(Sprite *spr) { + warning("STUB: CGE2Engine::snRmNear()"); +} + +void CGE2Engine::snRmMTake(Sprite *spr) { + warning("STUB: CGE2Engine::snRmMTake()"); +} + +void CGE2Engine::snRmFTake(Sprite *spr) { + warning("STUB: CGE2Engine::snRmFTake()"); +} + +void CGE2Engine::snFlag(int ref, int val) { + warning("STUB: CGE2Engine::snFlag()"); +} + +void CGE2Engine::snSetRef(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snSetRef()"); +} + +void CGE2Engine::snBackPt(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snBackPt()"); +} + +void CGE2Engine::snFlash(int val) { + warning("STUB: CGE2Engine::snFlash()"); +} + +void CGE2Engine::snLight(int val) { + warning("STUB: CGE2Engine::snLight()"); +} + +void CGE2Engine::snWalk(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snWalk()"); +} + +void CGE2Engine::snReach(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snReach()"); +} + +void CGE2Engine::snSound(Sprite *spr, int val, int cnt) { + warning("STUB: CGE2Engine::snSound()"); +} + +void CGE2Engine::snRoom(Sprite *spr, int val) { + warning("STUB: CGE2Engine::snRoom()"); +} + +void CGE2Engine::snGhost(Bitmap *bmp) { + warning("STUB: CGE2Engine::snGhost()"); } void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 889b16cd2d..e3c231596b 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -33,6 +33,9 @@ namespace CGE2 { +#define kCommandFrameRate 80 +#define kCommandFrameDelay (1000 / kCommandFrameRate) + enum CommandType { kCmdCom0 = 128, kCmdNop, // NOP :: do nothing -- cgit v1.2.3 From eb800807849989fc44f85ec2113520e868c4f7a8 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 24 May 2014 00:11:43 +0200 Subject: CGE2: Some refactoring and fixing regarding runCommand(). --- engines/cge2/cge2.cpp | 4 ++-- engines/cge2/snail.cpp | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index e15e096d9f..ef4646194e 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -97,7 +97,6 @@ void CGE2Engine::init() { _commandHandlerTurbo = new CommandHandler(this, true); _infoLine = new InfoLine(this, kInfoW); _mouse = new Mouse(this); - _talk = new Talk(this); for (int i = 0; i < kMaxPoint; i++) _point[i] = new V3D(); } @@ -124,7 +123,8 @@ void CGE2Engine::deinit() { delete _commandHandlerTurbo; delete _infoLine; delete _mouse; - delete _talk; + if (_talk != nullptr) + delete _talk; for (int i = 0; i < kMaxPoint; i++) { delete _point[i]; } diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 052188c6e0..ad643ac724 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -90,15 +90,14 @@ void CommandHandler::runCommand() { // Delay is finished _timerExpiry = 0; - } else { - if (_textDelay) { - if (_vm->_talk) { - _vm->snKill((Sprite *)_vm->_talk); - _vm->_talk = nullptr; - } - _textDelay = false; + } else if (_textDelay) { + if (_vm->_talk) { + _vm->snKill((Sprite *)_vm->_talk); + _vm->_talk = nullptr; } + _textDelay = false; } + if (_vm->_talk && tailCmd._commandType != kCmdPause) break; } -- cgit v1.2.3 From 0566d095bbb6bc02d24b90bb3e7ac3b1bf42561b Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 24 May 2014 08:57:55 +0200 Subject: CGE2: Partially implement Sprite::step(). --- engines/cge2/vga13h.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 662ea4495e..14bf97bbc4 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -455,7 +455,35 @@ void Sprite::backShow(void) { } void Sprite::step(int nr) { - warning("STUB: Sprite::step()"); + if (nr >= 0) + _seqPtr = nr; + + if (_ext) { + V3D p = _pos3D; + Seq *seq; + + if (nr < 0) + _seqPtr = _ext->_seq[_seqPtr]._next; + + if (_file[2] == '~') { // FLY-type sprite + warning("STUB: Sprite::step() - FLY-type sprite"); + } else { + seq = _ext->_seq + _seqPtr; + if (seq->_dz == 127 && seq->_dx != 0) { + _vm->_commandHandlerTurbo->addCommand(kCmdSound, -1, 256 * seq->_dy + seq->_dx, this); + } else { + p._x += seq->_dx; + p._y += seq->_dy; + p._z += seq->_dz; + //if (!_flags._kept) + // gotoxyz(p); + warning("Sprite::step()"); + } + } + if (seq->_dly >= 0) + _time = seq->_dly; + } else if (_vm->_waitRef && _vm->_waitRef == _ref) + _vm->_waitRef = 0; } void Sprite::tick() { -- cgit v1.2.3 From 9c8c734a3c6c5e1af9436a08cde39fe5474e42ac Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 24 May 2014 08:59:06 +0200 Subject: CGE2: Revise CGE2Engine::tick(). --- engines/cge2/cge2_main.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index fba0cd060d..5dcec22178 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -451,12 +451,18 @@ Sprite *CGE2Engine::locate(int ref) { void CGE2Engine::tick() { for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time) { - if (!spr->_flags._hide) { - if (--spr->_time == 0) - spr->tick(); - } + if (--spr->_time == 0) + spr->tick(); + } + if (_waitRef) { + if (_waitRef == _sprite->_ref) + if (spr->seqTest(_waitSeq)) + _waitRef = 0; } } + + //Mouse->Tick(); + warning("STUB: CGE2Engine::tick() - Mouse"); } void CGE2Engine::loadMap(int cav) { -- cgit v1.2.3 From b82a0fa3e5f36e8b0b47ff129ad18fe93bdac225 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 24 May 2014 09:04:41 +0200 Subject: CGE2: Add isHero(). --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 4 ++++ engines/cge2/spare.cpp | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 4e5adde36d..8e45ba3ba7 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -126,6 +126,7 @@ public: void mainLoop(); void handleFrame(); Sprite *locate(int ref); + bool isHero(Sprite *spr); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 5dcec22178..cf4b4fd66d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -448,6 +448,10 @@ Sprite *CGE2Engine::locate(int ref) { return spr; } +bool CGE2Engine::isHero(Sprite *spr) { + return spr && spr->_ref / 10 == 14; +} + void CGE2Engine::tick() { for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time) { diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 2f7a1381bf..650af7b273 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -72,7 +72,7 @@ void Spare::dispose(Sprite *spr) { if (spr) { _vm->_vga->_showQ->remove(spr); update(spr->contract()); - if (spr->_ref / 10 != 14) { // IIRC if it's == 14, it's the sprite of a Hero. No idea yet why it shouldn't be deleted then. + if (!_vm->isHero(spr)) { for (int i = 0; i < _container.size(); i++) { if (spr == _container[i]) { _container.remove_at(i); -- cgit v1.2.3 From 4cf5c28fee6d71277a7ca2bea5663aa12e387a68 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 24 May 2014 09:06:22 +0200 Subject: CGE2: Implement snRSeq() and snSeq(). --- engines/cge2/snail.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index ad643ac724..edbc78c7ad 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -342,11 +342,17 @@ void CGE2Engine::snMskDlg(int clr, int set) { } void CGE2Engine::snSeq(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snSeq()"); + if (spr) { + if (isHero(spr) && val == 0) + ((Hero*)spr)->park(); + else + spr->step(val); + } } void CGE2Engine::snRSeq(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snRSeq()"); + if (spr) + snSeq(spr, spr->_seqPtr + val); } void CGE2Engine::snSend(Sprite *spr, int val) { -- cgit v1.2.3 From 3c86aa288b532ddf9370fdcf33f144b43ffab5cc Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 24 May 2014 10:47:07 +0200 Subject: CGE2: Implement snSound(). Rework the whole Fx class during the process. The intro animation is working now. --- engines/cge2/cge2.h | 2 +- engines/cge2/snail.cpp | 20 ++++++++++++-- engines/cge2/sound.cpp | 74 +++++++++++++------------------------------------- engines/cge2/sound.h | 13 +++------ 4 files changed, 41 insertions(+), 68 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 8e45ba3ba7..d40d417ae8 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -173,7 +173,7 @@ public: void snLight(int val); void snWalk(Sprite *spr, int val); void snReach(Sprite *spr, int val); - void snSound(Sprite *spr, int val, int cnt); + void snSound(Sprite *spr, int wav); void snRoom(Sprite *spr, int val); void snGhost(Bitmap *bmp); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index edbc78c7ad..3de42ddfc0 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -29,6 +29,7 @@ #include "cge2/fileio.h" #include "cge2/hero.h" #include "cge2/text.h" +#include "cge2/sound.h" namespace CGE2 { @@ -284,7 +285,7 @@ void CommandHandler::runCommand() { _vm->snReach(spr, tailCmd._val); break; case kCmdSound: - _vm->snSound(spr, tailCmd._val, _count); + _vm->snSound(spr, tailCmd._val); _count = 1; break; case kCmdMap: @@ -462,8 +463,21 @@ void CGE2Engine::snReach(Sprite *spr, int val) { warning("STUB: CGE2Engine::snReach()"); } -void CGE2Engine::snSound(Sprite *spr, int val, int cnt) { - warning("STUB: CGE2Engine::snSound()"); +void CGE2Engine::snSound(Sprite *spr, int wav) { + if (wav == -1) + _sound->stop(); + else { + if (_sound->_smpinf._counter && wav < 20) + return; + if (_commandStat._wait && ((wav & 255) > 80)) + return; + + _commandStat._ref[1] = wav; + _commandStat._ref[0] = !_fx->exist(_commandStat._ref[1]); + _sound->play(_fx->load(_commandStat._ref[1], _commandStat._ref[0]), + (spr) ? (spr->_pos2D.x / (kScrWidth / 16)) : 8); + } + } void CGE2Engine::snRoom(Sprite *spr, int val) { diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index a3e866f05f..9f5ec2bb6c 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -61,7 +61,8 @@ void Sound::close() { void Sound::open() { setRepeat(1); - play((*_vm->_fx)[30000], 8); + warning("STUB: Sound::open()"); + play(_vm->_fx->load(99, 99)); } void Sound::setRepeat(int16 count) { @@ -111,60 +112,37 @@ void Sound::sndDigiStop(SmpInfo *PSmpInfo) { } Fx::Fx(CGE2Engine *vm, int size) : _current(NULL), _vm(vm) { - _cache = new Handler[size]; - for (_size = 0; _size < size; _size++) { - _cache[_size]._ref = 0; - _cache[_size]._wav = NULL; - } } Fx::~Fx() { clear(); - delete[] _cache; } void Fx::clear() { - for (Handler *p = _cache, *q = p + _size; p < q; p++) { - if (p->_ref) { - p->_ref = 0; - delete p->_wav; - p->_wav = NULL; - } - } + if (_current) + delete _current; _current = NULL; } -int Fx::find(int ref) { - int i = 0; - for (Handler *p = _cache, *q = p + _size; p < q; p++) { - if (p->_ref == ref) - break; - else - ++i; - } - return i; +Common::String Fx::name(int ref, int sub) { + char name[] = "%.2dfx%.2d.WAV\0"; + char subn[] = "%.2dfx%.2d?.WAV\0"; + char *p = (sub) ? subn : name; + Common::String filename = Common::String::format(p, ref >> 8, ref & 0xFF); + if (sub) + filename.setChar('@' + sub, 6); + return filename; } -void Fx::name(int ref, int sub) { - warning("STUB: Fx::name()"); +bool Fx::exist(int ref, int sub) { + return _vm->_resman->exist(name(ref, sub).c_str()); } -DataCk *Fx::load(int idx, int ref) { - char filename[12]; - warning("TODO: Implement Fx::load() with the use of Fx::name() properly in paralell with Snail! It just won't work this way."); - sprintf(filename, "FX%05d.WAV", ref); - - EncryptedStream file(_vm, filename); - DataCk *wav = loadWave(&file); - if (wav) { - Handler *p = &_cache[idx]; - delete p->_wav; - p->_wav = wav; - p->_ref = ref; - } else { - warning("Unable to load %s", filename); - } - return wav; +DataCk *Fx::load(int ref, int sub) { + Common::String filename = name(ref, sub); + EncryptedStream file(_vm, filename.c_str()); + clear(); + return (_current = loadWave(&file)); } DataCk *Fx::loadWave(EncryptedStream *file) { @@ -178,20 +156,6 @@ DataCk *Fx::loadWave(EncryptedStream *file) { return new DataCk(data, file->size()); } -DataCk *Fx::operator[](int ref) { - int i; - if ((i = find(ref)) < _size) - _current = _cache[i]._wav; - else { - if ((i = find(0)) >= _size) { - clear(); - i = 0; - } - _current = load(i, ref); - } - return _current; -} - MusicPlayer::MusicPlayer(CGE2Engine *vm) : _vm(vm) { _data = NULL; _isGM = false; diff --git a/engines/cge2/sound.h b/engines/cge2/sound.h index c488c3fbba..6fa2b2a553 100644 --- a/engines/cge2/sound.h +++ b/engines/cge2/sound.h @@ -72,7 +72,7 @@ public: ~Sound(); void open(); void close(); - void play(DataCk *wav, int pan); + void play(DataCk *wav, int pan = 8); int16 getRepeat(); void setRepeat(int16 count); void stop(); @@ -88,23 +88,18 @@ private: class Fx { CGE2Engine *_vm; - struct Handler { - int _ref; - DataCk *_wav; - } *_cache; int _size; - DataCk *load(int idx, int ref); DataCk *loadWave(EncryptedStream *file); - int find(int ref); + Common::String name(int ref, int sub); public: DataCk *_current; Fx(CGE2Engine *vm, int size); ~Fx(); void clear(); - void name(int ref, int sub); - DataCk *operator[](int ref); + bool exist(int ref, int sub = 0); + DataCk *load(int ref, int sub = 0); }; class MusicPlayer: public Audio::MidiPlayer { -- cgit v1.2.3 From 0986347b9366cd27b5c41fa878a702beae781e6a Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 25 May 2014 15:59:49 +0200 Subject: CGE2: Adjust the delay times to DOSBox's output. --- engines/cge2/cge2_main.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index a0a8bd16a1..96966975a3 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -36,8 +36,8 @@ namespace CGE2 { #define kTabName "CGE.TAB" #define kInfoW 140 #define kPocketFull 170 -#define kGameFrameDelay (1000 / 50) -#define kGameTickDelay (1000 / 62) +#define kGameFrameDelay (750 / 50) +#define kGameTickDelay (750 / 62) } // End of namespace CGE2 -- cgit v1.2.3 From 921385b30c53eed03143e25509a28e079cbdc34d Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 09:23:31 +0200 Subject: CGE2: Add stub for keyboard handling. --- engines/cge2/cge2.cpp | 3 +++ engines/cge2/cge2.h | 2 ++ engines/cge2/events.cpp | 24 ++++++++++++++++++++++++ engines/cge2/events.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index ef4646194e..7c4d1f13c8 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -59,6 +59,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _commandHandlerTurbo = nullptr; _infoLine = nullptr; _mouse = nullptr; + _keyboard = nullptr; _talk = nullptr; for (int i = 0; i < kMaxPoint; i++) _point[i] = nullptr; @@ -97,6 +98,7 @@ void CGE2Engine::init() { _commandHandlerTurbo = new CommandHandler(this, true); _infoLine = new InfoLine(this, kInfoW); _mouse = new Mouse(this); + _keyboard = new Keyboard(this); for (int i = 0; i < kMaxPoint; i++) _point[i] = new V3D(); } @@ -123,6 +125,7 @@ void CGE2Engine::deinit() { delete _commandHandlerTurbo; delete _infoLine; delete _mouse; + delete _keyboard; if (_talk != nullptr) delete _talk; for (int i = 0; i < kMaxPoint; i++) { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index d40d417ae8..d067e40153 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -50,6 +50,7 @@ class Spare; class CommandHandler; class InfoLine; class Mouse; +class Keyboard; class Talk; class Hero; class Bitmap; @@ -213,6 +214,7 @@ public: CommandHandler *_commandHandlerTurbo; InfoLine *_infoLine; Mouse *_mouse; + Keyboard *_keyboard; Talk *_talk; V3D *_point[kMaxPoint]; private: diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 3675909d74..670ea61c93 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -36,6 +36,30 @@ #include "cge2/cge2_main.h" namespace CGE2 { + +/*----------------- KEYBOARD interface -----------------*/ + +Keyboard::Keyboard(CGE2Engine *vm) : _client(NULL), _vm(vm) { + warning("STUB: Keyboard::Keyboard() - Recheck the whole implementation!!!"); +} + +Keyboard::~Keyboard() { +} + +Sprite *Keyboard::setClient(Sprite *spr) { + warning("STUB: Keyboard::setClient()"); + return spr; +} + +bool Keyboard::getKey(Common::Event &event) { + warning("STUB: Keyboard::getKey()"); + return false; +} + +void Keyboard::newKeyboard(Common::Event &event) { + warning("STUB: Keyboard::newKeyboard()"); +} + /*----------------- MOUSE interface -----------------*/ Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { diff --git a/engines/cge2/events.h b/engines/cge2/events.h index 1442d85b39..99f017bae3 100644 --- a/engines/cge2/events.h +++ b/engines/cge2/events.h @@ -34,6 +34,35 @@ namespace CGE2 { +/*----------------- KEYBOARD interface -----------------*/ + +#define kEventMax 256 + +enum EventMask { + kMouseRoll = 1 << 0, + kMouseLeftDown = 1 << 1, + kMouseLeftUp = 1 << 2, + kMouseRightDown = 1 << 3, + kMouseRightUp = 1 << 4, + kEventAttn = 1 << 5, + kEventKeyb = 1 << 7 +}; + +class Keyboard { +private: + bool getKey(Common::Event &event); + CGE2Engine *_vm; +public: + Sprite *_client; + bool _keyAlt; + + void newKeyboard(Common::Event &event); + Sprite *setClient(Sprite *spr); + + Keyboard(CGE2Engine *vm); + ~Keyboard(); +}; + /*----------------- MOUSE interface -----------------*/ class Mouse : public Sprite { -- cgit v1.2.3 From 14e3df21ef1a1cc3e3c599605cd84faf353a2e6f Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 09:37:52 +0200 Subject: CGE2: Add stub for System. --- engines/cge2/cge2.cpp | 3 +++ engines/cge2/cge2.h | 2 ++ engines/cge2/cge2_main.cpp | 12 ++++++++++++ engines/cge2/cge2_main.h | 14 ++++++++++++++ 4 files changed, 31 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 7c4d1f13c8..18016ec561 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -63,6 +63,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _talk = nullptr; for (int i = 0; i < kMaxPoint; i++) _point[i] = nullptr; + _sys = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -101,6 +102,7 @@ void CGE2Engine::init() { _keyboard = new Keyboard(this); for (int i = 0; i < kMaxPoint; i++) _point[i] = new V3D(); + _sys = new System(this); } void CGE2Engine::deinit() { @@ -131,6 +133,7 @@ void CGE2Engine::deinit() { for (int i = 0; i < kMaxPoint; i++) { delete _point[i]; } + delete _sys; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index d067e40153..5275fa7bc8 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -54,6 +54,7 @@ class Keyboard; class Talk; class Hero; class Bitmap; +class System; #define kScrWidth 320 #define kScrHeight 240 @@ -217,6 +218,7 @@ public: Keyboard *_keyboard; Talk *_talk; V3D *_point[kMaxPoint]; + System *_sys; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index cf4b4fd66d..501fa594cf 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -37,6 +37,18 @@ namespace CGE2 { +System::System(CGE2Engine *vm) : Sprite(vm), _vm(vm) { + warning("STUB: System::System()"); +} + +void System::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { + warning("STUB: System::touch()"); +} + +void System::tick() { + warning("STUB: System::tick()"); +} + int CGE2Engine::number(char *s) { // TODO: Rework it later to include the preceding token() call! int r = atoi(s); char *pp = strchr(s, ':'); diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 96966975a3..7146e43115 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -39,6 +39,20 @@ namespace CGE2 { #define kGameFrameDelay (750 / 50) #define kGameTickDelay (750 / 62) +class System : public Sprite { +public: + int _funDel; + int _blinkCounter; + Sprite *_blinkSprite; + + System(CGE2Engine *vm); + + virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); + void tick(); +private: + CGE2Engine *_vm; +}; + } // End of namespace CGE2 #endif // CGE2_MAIN_H -- cgit v1.2.3 From 54956d8a810e111f42731487743d5c9221dee42a Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 09:57:41 +0200 Subject: CGE2: Move things around to fix broken compilation of cross-includes. V2D and V3D are moved to vga13h.h --- engines/cge2/bitmap.h | 1 + engines/cge2/cge2.cpp | 1 + engines/cge2/cge2_main.h | 3 ++- engines/cge2/general.h | 52 ++---------------------------------------------- engines/cge2/snail.h | 3 ++- engines/cge2/vga13h.cpp | 4 ++-- engines/cge2/vga13h.h | 49 ++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 58 insertions(+), 55 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 07f83b8045..e5f38a05d7 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -35,6 +35,7 @@ namespace CGE2 { class CGE2Engine; class EncryptedStream; +class V2D; #define kMaxPath 128 enum { diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 18016ec561..88fdfbb74d 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -37,6 +37,7 @@ #include "cge2/spare.h" #include "cge2/events.h" #include "cge2/talk.h" +#include "cge2/cge2_main.h" namespace CGE2 { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 7146e43115..a37370546b 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -28,11 +28,12 @@ #ifndef CGE2_MAIN_H #define CGE2_MAIN_H +#include "cge2/events.h" + namespace CGE2 { #define kLineMax 512 #define kIntroExt ".I80" -#define kNoByte -1 // Recheck this! We have no proof for it's original value. #define kTabName "CGE.TAB" #define kInfoW 140 #define kPocketFull 170 diff --git a/engines/cge2/general.h b/engines/cge2/general.h index bd145e1731..0239402ea3 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -29,67 +29,19 @@ #define CGE2_GENERAL_H #include "common/file.h" -#include "common/rect.h" -#include "cge2/fileio.h" -#include "cge2/cge2.h" namespace CGE2 { #define SCR_WID_ 320 +class CGE2Engine; + struct Dac { uint8 _r; uint8 _g; uint8 _b; }; -// From CGETYPE.H: -class V3D { -public: - double _x, _y, _z; - V3D(void) { } - V3D(double x, double y, double z = 0) : _x(x), _y(y), _z(z) { } - V3D(const V3D &p) : _x(p._x), _y(p._y), _z(p._z) { } - V3D operator+(const V3D &p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); } - V3D operator-(const V3D &p) const { return V3D(_x - p._x, _y - p._y, _z - p._z); } - V3D operator*(long n) const { return V3D(_x * n, _y * n, _z * n); } - V3D operator/ (long n) const { return V3D(_x / n, _y / n, _z / n); } - bool operator==(V3D &p) const { return _x == p._x && _y == p._y && _z == p._z; } - bool operator!=(V3D &p) const { return _x != p._x || _y != p._y || _z != p._z; } - V3D& operator+=(const V3D &x) { return *this = *this + x; } - V3D& operator-=(const V3D &x) { return *this = *this - x; } -}; - -class V2D : public Common::Point { - CGE2Engine *_vm; -public: - V2D& operator=(const V3D &p3) { - double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); - x = round((_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m)); - y = round((_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m)); - return *this; - } - V2D(CGE2Engine *vm) : _vm(vm) { } - V2D(CGE2Engine *vm, const V3D &p3) : _vm(vm) { *this = p3; } - V2D(CGE2Engine *vm, int x, int y) : _vm(vm), Common::Point(x, y) { } - bool operator<(const V2D &p) const { return (x < p.x) && (y < p.y); } - bool operator<=(const V2D &p) const { return (x <= p.x) && (y <= p.y); } - bool operator>(const V2D &p) const { return (x > p.x) && (y > p.y); } - bool operator>=(const V2D &p) const { return (x >= p.x) && (y >= p.y); } - V2D operator+(const V2D &p) const { return V2D(_vm, x + p.x, y + p.y); } - V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); } - uint16 area(void) { return x * y; } - bool limited(const V2D &p) { - return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); - } - V2D scale(int z) { - double m = _vm->_eye->_z / (_vm->_eye->_z - z); - return V2D(_vm, trunc(m * x), trunc(m * y)); - } - static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } - static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } -}; - } // End of namespace CGE2 #endif // CGE2_GENERAL_H diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index e3c231596b..afd52dfd45 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -29,12 +29,13 @@ #define CGE2_SNAIL_H #include "cge2/cge2.h" -#include "cge2/cge2_main.h" namespace CGE2 { #define kCommandFrameRate 80 #define kCommandFrameDelay (1000 / kCommandFrameRate) +#define kNoByte -1 // Recheck this! We have no proof for it's original value. + enum CommandType { kCmdCom0 = 128, diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 14bf97bbc4..bbfd6c471c 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -32,8 +32,8 @@ #include "cge2/general.h" #include "cge2/vga13h.h" #include "cge2/bitmap.h" -//#include "cge/text.h" -//#include "cge/cge_main.h" +#include "cge2/text.h" +#include "cge2/cge2_main.h" #include "cge2/cge2.h" #include "cge2/vga13h.h" diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 77a2fd35be..20d97ee4eb 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -34,8 +34,8 @@ #include "cge2/general.h" #include "cge2/bitmap.h" #include "cge2/snail.h" -#include "cge2/cge2.h" #include "cge2/spare.h" +#include "cge2/cge2.h" namespace CGE2 { @@ -51,6 +51,53 @@ namespace CGE2 { #define kPalCount 256 #define kPalSize (kPalCount * 3) +// From CGETYPE.H: +class V3D { +public: + double _x, _y, _z; + V3D(void) { } + V3D(double x, double y, double z = 0) : _x(x), _y(y), _z(z) { } + V3D(const V3D &p) : _x(p._x), _y(p._y), _z(p._z) { } + V3D operator+(const V3D &p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); } + V3D operator-(const V3D &p) const { return V3D(_x - p._x, _y - p._y, _z - p._z); } + V3D operator*(long n) const { return V3D(_x * n, _y * n, _z * n); } + V3D operator/ (long n) const { return V3D(_x / n, _y / n, _z / n); } + bool operator==(V3D &p) const { return _x == p._x && _y == p._y && _z == p._z; } + bool operator!=(V3D &p) const { return _x != p._x || _y != p._y || _z != p._z; } + V3D& operator+=(const V3D &x) { return *this = *this + x; } + V3D& operator-=(const V3D &x) { return *this = *this - x; } +}; + +class V2D : public Common::Point { + CGE2Engine *_vm; +public: + V2D& operator=(const V3D &p3) { + double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); + x = round((_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m)); + y = round((_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m)); + return *this; + } + V2D(CGE2Engine *vm) : _vm(vm) { } + V2D(CGE2Engine *vm, const V3D &p3) : _vm(vm) { *this = p3; } + V2D(CGE2Engine *vm, int x, int y) : _vm(vm), Common::Point(x, y) { } + bool operator<(const V2D &p) const { return (x < p.x) && (y < p.y); } + bool operator<=(const V2D &p) const { return (x <= p.x) && (y <= p.y); } + bool operator>(const V2D &p) const { return (x > p.x) && (y > p.y); } + bool operator>=(const V2D &p) const { return (x >= p.x) && (y >= p.y); } + V2D operator+(const V2D &p) const { return V2D(_vm, x + p.x, y + p.y); } + V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); } + uint16 area(void) { return x * y; } + bool limited(const V2D &p) { + return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); + } + V2D scale(int z) { + double m = _vm->_eye->_z / (_vm->_eye->_z - z); + return V2D(_vm, trunc(m * x), trunc(m * y)); + } + static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } + static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } +}; + struct Seq { uint8 _now; uint8 _next; -- cgit v1.2.3 From 4e232814d5f96a7a0ed8aa2e249497c0d63dbace Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 10:33:47 +0200 Subject: CGE2: Implement runGame(). --- engines/cge2/cge2.cpp | 6 ++++ engines/cge2/cge2.h | 10 +++++++ engines/cge2/cge2_main.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/cge2_main.h | 9 ++++++ 4 files changed, 93 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 88fdfbb74d..dd2ca16bf4 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -65,6 +65,9 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) for (int i = 0; i < kMaxPoint; i++) _point[i] = nullptr; _sys = nullptr; + _busyPtr = nullptr; + for (int i = 0; i < 2; i++) + _vol[i] = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -81,6 +84,9 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _waitRef = 0; _commandStat = { nullptr, { 0 , 0 } }; _taken = false; + _endGame = false; + for (int i = 0; i < 4; i++) + _flag[i] = false; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 5275fa7bc8..8520424ea5 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -68,6 +68,9 @@ class System; #define kPocketMax 4 #define kCaveMax 100 #define kMaxPoint 4 +#define kInfoX 160 +#define kInfoY -11 +#define kInfoW 180 enum CallbackType { kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume @@ -129,6 +132,9 @@ public: void handleFrame(); Sprite *locate(int ref); bool isHero(Sprite *spr); + void loadUser(); + void checkSaySwitch(); + void qGame(); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -199,6 +205,8 @@ public: int _ref[2]; } _commandStat; bool _taken; + bool _endGame; + bool _flag[4]; ResourceManager *_resman; Vga *_vga; @@ -219,6 +227,8 @@ public: Talk *_talk; V3D *_point[kMaxPoint]; System *_sys; + Sprite *_busyPtr; + Sprite *_vol[2]; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 501fa594cf..ff80c59669 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -498,7 +498,74 @@ void CGE2Engine::busy(bool on) { } void CGE2Engine::runGame() { - warning("STUB: CGE2Engine::runGame()"); + if (_quitFlag) + return; + + selectPocket(-1); + + loadUser(); + + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); + if (!_music) + _midiPlayer->killMidi(); + + checkSaySwitch(); + + _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); + _infoLine->setText(nullptr); + _vga->_showQ->insert(_infoLine); + + caveUp(_now); + _startupMode = 0; + _mouse->center(); + _mouse->off(); + _mouse->on(); + + _keyboard->setClient(_sys); + _commandHandler->addCommand(kCmdSeq, kPowerRef, 1, nullptr); + + _busyPtr = _vga->_showQ->locate(kBusyRef); + + _vol[0] = _vga->_showQ->locate(kDvolRef); + _vol[1] = _vga->_showQ->locate(kMvolRef); + + // these sprites are loaded with SeqPtr==0 (why?!) + if (_vol[0]) + _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); + if (_vol[1]) + _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); + // TODO: Recheck these! ^ + + // main loop + while (!_endGame && !_quitFlag) { + if (_flag[3]) // Flag FINIS + _commandHandler->addCallback(kCmdExec, -1, 0, kQGame); + mainLoop(); + } + + // If finishing game due to closing ScummVM window, explicitly save the game + if (!_endGame && canSaveGameStateCurrently()) + qGame(); + + _keyboard->setClient(nullptr); + _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); + _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); + _mouse->off(); + _vga->_showQ->clear(); + _vga->_spareQ->clear(); +} + +void CGE2Engine::loadUser() { + warning("STUB: CGE2Engine::loadUser()"); +} + +void CGE2Engine::checkSaySwitch() { + warning("STUB: CGE2Engine::checkSaySwitch()"); +} + +void CGE2Engine::qGame() { + warning("STUB: CGE2Engine::qGame()"); + _endGame = true; } void CGE2Engine::loadTab() { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index a37370546b..98e7fbb1a3 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -40,6 +40,15 @@ namespace CGE2 { #define kGameFrameDelay (750 / 50) #define kGameTickDelay (750 / 62) +#define kMusicRef 122 +#define kPowerRef 123 +#define kDvolRef 124 +#define kMvolRef 125 +#define kRef 126 +#define kBusyRef 127 +#define kCapRef 128 +#define kVoxRef 129 + class System : public Sprite { public: int _funDel; -- cgit v1.2.3 From 8fa31d1168ab6b361125a001fb3a38f0f7389129 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 15:57:23 +0200 Subject: CGE2: Comment out calling of the intro animation during testing. --- engines/cge2/cge2_main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index ff80c59669..a2ebc34860 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -612,8 +612,10 @@ void CGE2Engine::cge2_main() { _mode++; if (showTitle("WELCOME")) { +#if 0 if (_mode == 1) movie(kIntroExt); +#endif if (_text->getText(255) != NULL) { runGame(); _startupMode = 2; -- cgit v1.2.3 From 75546134c817a2f267c4ffff13b822ccf7e5e923 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 15:58:07 +0200 Subject: CGE2: Implement loadUser() and loadPos(). Revise File I/O a bit to do so. --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 35 +++++++++++++++++++++++++++++++---- engines/cge2/fileio.cpp | 8 ++++++-- engines/cge2/fileio.h | 5 +++-- 4 files changed, 41 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 8520424ea5..c2e0dab2be 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -135,6 +135,7 @@ public: void loadUser(); void checkSaySwitch(); void qGame(); + void loadPos(); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a2ebc34860..83569cc98a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -556,7 +556,35 @@ void CGE2Engine::runGame() { } void CGE2Engine::loadUser() { - warning("STUB: CGE2Engine::loadUser()"); + // set scene + if (_mode == 0) { // user .SVG file found + warning("STUB: CGE2Engine::loadUser()"); + // Missing loading from save file. TODO: Implement it with the saving/loading! + } else if (_mode == 1) { + loadScript("CGE.INI"); + loadPos(); + // Missing saving to save file. TODO: Implement it with the saving/loading! + } +} + +void CGE2Engine::loadPos() { + if (_resman->exist("CGE.HXY")) { + for (int cav = 0; cav < kCaveMax; cav++) + _heroTab[1]->_posTab[cav] = new V2D(this, 180, 10); + + EncryptedStream file(this, "CGE.HXY"); + + for (int cav = 0; cav < kCaveMax; cav++) { + _heroTab[0]->_posTab[cav]->x = file.readSint16LE(); + _heroTab[0]->_posTab[cav]->y = file.readSint16LE(); + } + + for (int cav = 0; cav < 41; cav++) { // (564 - 400) / 4 = 41 + _heroTab[1]->_posTab[cav]->x = file.readSint16LE(); + _heroTab[1]->_posTab[cav]->y = file.readSint16LE(); + } + } else + error("Missing file: CGE.HXY"); } void CGE2Engine::checkSaySwitch() { @@ -575,11 +603,10 @@ void CGE2Engine::loadTab() { if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); - Common::File output; for (int i = 0; i < kCaveMax; i++) { for (int j = 0; j < 3; j++) { - signed b = f.readSigned(); - unsigned a = f.readUnsigned(); + signed b = f.readSint16BE(); + unsigned a = f.readUint16BE(); uint16 round = uint16((long(a) << 16) / 100); if (round > 0x7FFF) diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 5885871b29..fc6303bbe2 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -216,14 +216,18 @@ uint32 EncryptedStream::read(byte *dataPtr, uint32 dataSize) { return _readStream->read(dataPtr, dataSize); } -unsigned EncryptedStream::readUnsigned() { +unsigned EncryptedStream::readUint16BE() { return _readStream->readUint16BE(); } -signed EncryptedStream::readSigned() { +signed EncryptedStream::readSint16BE() { return _readStream->readSint16BE(); } +signed EncryptedStream::readSint16LE() { + return _readStream->readSint16LE(); +} + bool EncryptedStream::err() { return (_error & _readStream->err()); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index a35b014311..ab5de22d07 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -121,8 +121,9 @@ public: int32 pos(); int32 size(); uint32 read(byte *dataPtr, uint32 dataSize); - unsigned readUnsigned(); - signed readSigned(); + unsigned readUint16BE(); + signed readSint16BE(); + signed readSint16LE(); Common::String readLine(); int getLineCount() { return _lineCount; } -- cgit v1.2.3 From 43ce991b84b75b290a9098c940a3d5294ff3eb66 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 16:09:49 +0200 Subject: CGE2: Rework loadUser(). --- engines/cge2/cge2_main.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 83569cc98a..3f8f8623e6 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -556,15 +556,10 @@ void CGE2Engine::runGame() { } void CGE2Engine::loadUser() { - // set scene - if (_mode == 0) { // user .SVG file found - warning("STUB: CGE2Engine::loadUser()"); - // Missing loading from save file. TODO: Implement it with the saving/loading! - } else if (_mode == 1) { - loadScript("CGE.INI"); - loadPos(); - // Missing saving to save file. TODO: Implement it with the saving/loading! - } + warning("STUB: CGE2Engine::loadUser()"); + // Missing loading from file. TODO: Implement it with the saving/loading! + loadScript("CGE.INI"); + loadPos(); } void CGE2Engine::loadPos() { -- cgit v1.2.3 From 62e36f92793efea211715f65c7845baa95c16135 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 16:30:32 +0200 Subject: CGE2: Rework EncryptedStream::readLine(). --- engines/cge2/cge2_main.cpp | 14 +++++++------- engines/cge2/fileio.cpp | 5 ++++- engines/cge2/fileio.h | 1 + engines/cge2/vga13h.cpp | 5 ++--- 4 files changed, 14 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 3f8f8623e6..eea59a4a4b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -116,11 +116,10 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { Common::String line; for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ - int len = line.size(); - Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - if (len == 0 || *tmpStr == ';') + if (line.size() == 0) continue; - + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + char *p; p = token(tmpStr); if (*p == '@') { @@ -260,13 +259,14 @@ void CGE2Engine::loadScript(const char *fname) { Common::String line; for (line = scrf.readLine(); !scrf.eos(); line = scrf.readLine()) { + if (line.size() == 0) + continue; + char *p; lcnt++; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - if ((line.size() == 0) || (*tmpStr == ';')) // Comments start with ';' - don't bother with them. - continue; - + ok = false; // not OK if break V3D P; diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index fc6303bbe2..4fec4a67ca 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -242,7 +242,10 @@ bool EncryptedStream::seek(int32 offset) { Common::String EncryptedStream::readLine() { _lineCount++; - return _readStream->readLine(); + Common::String line = _readStream->readLine(); + if (!line.empty() && (line[0] == ';' || line[0] == '.' || line[0] == '*')) + line.clear(); // Returns an empty string, if the line is invalid. + return line; } int32 EncryptedStream::size() { diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index ab5de22d07..83a14560ad 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -105,6 +105,7 @@ public: bool exist(const char *name); }; +// TODO: Revise the whole class! class EncryptedStream { private: CGE2Engine *_vm; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index bbfd6c471c..d428a10039 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -278,10 +278,9 @@ Sprite *Sprite::expand() { char tmpStr[kLineMax + 1]; for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ - int len = line.size(); - Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - if (len == 0 || *tmpStr == ';') + if (line.size() == 0) continue; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); char *p = _vm->token(tmpStr); if (*p == '@') { -- cgit v1.2.3 From 8af90ab6b7311601b7889a16ff7014e7184dde51 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 26 May 2014 17:40:09 +0200 Subject: CGE2: Stub out actual use of _infoLine in runGame(). --- engines/cge2/cge2_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index eea59a4a4b..87091572a7 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -513,7 +513,8 @@ void CGE2Engine::runGame() { _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); _infoLine->setText(nullptr); - _vga->_showQ->insert(_infoLine); + //_vga->_showQ->insert(_infoLine); + warning("STUB: CGE2Engine::runGame() - Info Line is missing!"); caveUp(_now); _startupMode = 0; -- cgit v1.2.3 From 06ae8de1561bfe392019cd3ce2f1bba498e4a607 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 29 May 2014 18:19:01 +0200 Subject: CGE2: Fix movie(). --- engines/cge2/cge2_main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 87091572a7..e1641b9f12 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -383,8 +383,7 @@ void CGE2Engine::caveUp(int cav) { _vga->show(); _sprite = _vga->_showQ->first(); - if (_startupMode) - _vga->sunrise(_vga->_sysPal); + _vga->sunrise(_vga->_sysPal); feedSnail(_vga->_showQ->locate(bakRef + 255), kNear, _heroTab[_sex]->_ptr); //setDrawColors(); - It's only for debugging purposes. Can be left out for now. -- cgit v1.2.3 From 8f28501e3cf78d666796a467b700bbc6c60e68a2 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 29 May 2014 18:22:26 +0200 Subject: CGE2: Remove unnecessary comment from vga13h.cpp. --- engines/cge2/vga13h.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index d428a10039..695789fdb5 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -187,13 +187,6 @@ bool Sprite::seqTest(int n) { return true; } -//CommandHandler::Command *Sprite::snList(SnList type) { -// SprExt *e = _ext; -// if (e) -// return (type == kNear) ? e->_near : e->_take; -// return NULL; -//} - void Sprite::setName(char *newName) { if (!_ext) return; -- cgit v1.2.3 From e6e0847b7bbbbfee4ff6d4bac997c31a2c32b7b2 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 29 May 2014 18:24:55 +0200 Subject: CGE2: Finish implementation of Sprite::setSeq(). --- engines/cge2/vga13h.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 695789fdb5..97a31bbb69 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -162,13 +162,7 @@ bool Sprite::works(Sprite *spr) { } Seq *Sprite::setSeq(Seq *seq) { - if (_ext) { - free(_ext->_seq); - _ext->_seq = NULL; - } - -// expand(); - warning("STUB: Sprite::setSeq()"); + expand(); Seq *s = _ext->_seq; _ext->_seq = seq; -- cgit v1.2.3 From 566419f3ad868272df5bce837558592668c5aff6 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 29 May 2014 18:49:45 +0200 Subject: CGE2: Implement snHide(). --- engines/cge2/snail.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 3de42ddfc0..45ca715d26 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -327,7 +327,11 @@ void CGE2Engine::snKill(Sprite *spr) { } void CGE2Engine::snHide(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snHide()"); + if (spr) { + spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide); + if (spr->_flags._shad) + spr->_prev->_flags._hide = spr->_flags._hide; + } } void CGE2Engine::snMidi(int val) { -- cgit v1.2.3 From 7c73ce5d8b516976180aa38e76f75e88b1cbc474 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 29 May 2014 19:58:38 +0200 Subject: CGE2: Implement snSend(). --- engines/cge2/bitmap.h | 2 +- engines/cge2/cge2.h | 4 ++++ engines/cge2/cge2_main.cpp | 8 ++++++++ engines/cge2/snail.cpp | 38 +++++++++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index e5f38a05d7..82c3b07e31 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -50,7 +50,7 @@ enum { struct HideDesc { uint16 _skip; uint16 _hide; -} PACKED_STRUCT; +}; #include "common/pack-end.h" diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c2e0dab2be..cac5a08936 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -136,6 +136,8 @@ public: void checkSaySwitch(); void qGame(); void loadPos(); + void releasePocket(Sprite *spr); + void switchHero(bool sex); void setEye(V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); @@ -185,6 +187,8 @@ public: void snSound(Sprite *spr, int wav); void snRoom(Sprite *spr, int val); void snGhost(Bitmap *bmp); + + void hide1(Sprite *spr); const ADGameDescription *_gameDescription; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e1641b9f12..d4cee68871 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -582,6 +582,10 @@ void CGE2Engine::loadPos() { error("Missing file: CGE.HXY"); } +void CGE2Engine::releasePocket(Sprite *spr) { + warning("STUB: CGE2Engine::releasePocket()"); +} + void CGE2Engine::checkSaySwitch() { warning("STUB: CGE2Engine::checkSaySwitch()"); } @@ -748,4 +752,8 @@ void CGE2Engine::killText() { _talk = NULL; } +void CGE2Engine::switchHero(bool sex) { + warning("STUB: CGE2Engine::switchHero()"); +} + } // End of namespace CGE2 diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 45ca715d26..d92862a1ed 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -361,7 +361,39 @@ void CGE2Engine::snRSeq(Sprite *spr, int val) { } void CGE2Engine::snSend(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snSend()"); + if (!spr) + return; + + // Sending", spr->File + // from cave", spr->Cave + // to cave", val + bool was1 = (_vga->_showQ->locate(spr->_ref) != nullptr); + bool val1 = (val == 0 || val == _now); + spr->_scene = val; + releasePocket(spr); + if (val1 != was1) { + if (was1) { + // deactivating + hide1(spr); + spr->_flags._slav = false; + if (spr == _heroTab[_sex]->_ptr) + if (_heroTab[!_sex]->_ptr->_scene == _now) + switchHero(!_sex); + _spare->dispose(spr); + } else { + // activating + if (byte(spr->_ref) == 0) + _bitmapPalette = _vga->_sysPal; + _vga->_showQ->insert(spr); + if (isHero(spr)) { + V2D p = *_heroTab[spr->_ref & 1]->_posTab[val]; + spr->gotoxyz(V3D(p.x, 0, p.y)); + ((Hero*)spr)->setCurrent(); + } + _taken = false; + _bitmapPalette = NULL; + } + } } void CGE2Engine::snSwap(Sprite *spr, int val) { @@ -492,6 +524,10 @@ void CGE2Engine::snGhost(Bitmap *bmp) { warning("STUB: CGE2Engine::snGhost()"); } +void CGE2Engine::hide1(Sprite *spr) { + _commandHandlerTurbo->addCommand(kCmdGhost, -1, 0, spr->ghost()); +} + void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { if (ref == 2) ref = 142 - _vm->_sex; -- cgit v1.2.3 From 60825760fd6eaa4a50c9a9e0bd9a2a5b0380d95c Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 29 May 2014 20:05:51 +0200 Subject: CGE2: Implement snGhost(). Also implement Sprite::ghost(). --- engines/cge2/snail.cpp | 7 ++++++- engines/cge2/vga13h.cpp | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index d92862a1ed..ede6206d1f 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -521,7 +521,12 @@ void CGE2Engine::snRoom(Sprite *spr, int val) { } void CGE2Engine::snGhost(Bitmap *bmp) { - warning("STUB: CGE2Engine::snGhost()"); + V2D p(this, *bmp->_v & 0xFFFF, *bmp->_v >> 16); + bmp->hide(p.x, p.y); + delete bmp->_b; + bmp->_v = nullptr; + bmp->_b = nullptr; + delete bmp; } void CGE2Engine::hide1(Sprite *spr) { diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 97a31bbb69..98daf56f3d 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -606,12 +606,18 @@ void Sprite::hide() { BitmapPtr Sprite::ghost() { SprExt *e = _ext; if (!e->_b1) - return NULL; - - BitmapPtr bmp = new Bitmap(_vm, 0, 0, (uint8 *)NULL); - assert(bmp != NULL); - - warning("STUB: Sprite::ghost()"); + return nullptr; + + BitmapPtr bmp = new Bitmap(_vm, 0, 0, (uint8 *)nullptr); + assert(bmp != nullptr); + bmp->_w = e->_b1->_w; + bmp->_h = e->_b1->_h; + bmp->_b = new HideDesc[bmp->_h]; + assert(bmp->_b != nullptr); + memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc)* bmp->_h); + uint8 *v = new uint8; + *v = (e->_p1.y << 16) + e->_p1.x; + bmp->_v = v; return bmp; } -- cgit v1.2.3 From 2c453f8f662e65b3b85593d6a00a85c347852e4b Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 30 May 2014 10:30:16 +0200 Subject: CGE2: Fix some warnings. --- engines/cge2/cge2.h | 2 +- engines/cge2/cge2_main.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index cac5a08936..66bcd911e9 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -45,7 +45,7 @@ class Text; struct HeroTab; class V3D; class V2D; -class Dac; +struct Dac; class Spare; class CommandHandler; class InfoLine; diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 98e7fbb1a3..272cdf79d5 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -35,7 +35,6 @@ namespace CGE2 { #define kLineMax 512 #define kIntroExt ".I80" #define kTabName "CGE.TAB" -#define kInfoW 140 #define kPocketFull 170 #define kGameFrameDelay (750 / 50) #define kGameTickDelay (750 / 62) -- cgit v1.2.3 From 6275f50d8052e480dd279f103e472e37a90493a8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 10:30:32 +0200 Subject: CGE2: Fix commandStat initialization --- engines/cge2/cge2.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index dd2ca16bf4..273c9dac0d 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -82,7 +82,9 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _lastTick = 0; _waitSeq = 0; _waitRef = 0; - _commandStat = { nullptr, { 0 , 0 } }; + _commandStat._wait = nullptr; + _commandStat._ref[0] = 0; + _commandStat._ref[1] = 0; _taken = false; _endGame = false; for (int i = 0; i < 4; i++) -- cgit v1.2.3 From 8654042d05117cd5c435b2aeb8cdaffa50545e8e Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 10:38:36 +0200 Subject: CGE2: Silence a warning by adding a safeguard in step() --- engines/cge2/vga13h.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 98daf56f3d..09e8accd1c 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -446,7 +446,7 @@ void Sprite::step(int nr) { if (_ext) { V3D p = _pos3D; - Seq *seq; + Seq *seq = nullptr; if (nr < 0) _seqPtr = _ext->_seq[_seqPtr]._next; @@ -466,7 +466,7 @@ void Sprite::step(int nr) { warning("Sprite::step()"); } } - if (seq->_dly >= 0) + if (seq && (seq->_dly >= 0)) _time = seq->_dly; } else if (_vm->_waitRef && _vm->_waitRef == _ref) _vm->_waitRef = 0; -- cgit v1.2.3 From 3035903f6f957569a88d904bc7b36c21aa97f546 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 10:41:14 +0200 Subject: CGE2: Clarify a STUB warning --- engines/cge2/vga13h.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 09e8accd1c..618fb8a987 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -463,7 +463,7 @@ void Sprite::step(int nr) { p._z += seq->_dz; //if (!_flags._kept) // gotoxyz(p); - warning("Sprite::step()"); + warning("STUB: Sprite::step()"); } } if (seq && (seq->_dly >= 0)) -- cgit v1.2.3 From 7ecb734a6ad6c276c725dbec84c173e9b6a26e0d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 10:41:32 +0200 Subject: CGE2: Fix eyetab initialization --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index d4cee68871..9e9d6da76a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -598,7 +598,7 @@ void CGE2Engine::qGame() { void CGE2Engine::loadTab() { setEye(_text->getText(240)); for (int i = 0; i < kCaveMax; i++) - _eyeTab[i] == _eye; + _eyeTab[i] = _eye; if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); -- cgit v1.2.3 From bea9e0532ec230c89cf76656ed4be0db3eb4bc13 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 10:44:56 +0200 Subject: CGE2: Move an unused variable in a STUB clock, initialize it (in the comment). That fixes a warning --- engines/cge2/snail.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index ede6206d1f..73d29cd59f 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -583,7 +583,6 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { byte ptr = spr->_actionCtrl[snq]._ptr; CommandHandler::Command *comtab = spr->snList(snq); CommandHandler::Command *c = &comtab[ptr]; - CommandHandler::Command *p; CommandHandler::Command *q = &comtab[cnt]; warning("STUB: CGE2Engine::feedSnail()"); @@ -591,7 +590,8 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { /* int pocFre = freePockets(hero->_ref & 1); int pocReq = 0; - for (p = c; p < q && p->_commandType != kCmdNext; p++) { // scan commands + CommandHandler::Command *p = c; + for (; p < q && p->_commandType != kCmdNext; p++) { // scan commands // drop from pocket? if ((p->_commandType == kCmdSend && p->_val != _now) || p->_commandType == kCmdGive) { -- cgit v1.2.3 From 8a712c840d4c65edf4c1f51273d77c6c38ca80a6 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 10:52:10 +0200 Subject: CGE2: Fix several signed/unsigned comparisons --- engines/cge2/spare.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 650af7b273..be2fc64d23 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -38,10 +38,9 @@ void Spare::clear() { } Sprite *Spare::locate(int ref) { - for (int i = 0; i < _container.size(); i++) { - if (_container[i]->_ref == ref) { + for (uint i = 0; i < _container.size(); ++i) { + if (_container[i]->_ref == ref) return _container[i]; - } } return nullptr; } @@ -49,7 +48,7 @@ Sprite *Spare::locate(int ref) { void Spare::takeCave(int cav) { int bakRef = cav << 8; Common::Array tempCont = _container; - for (int i = 0; i < tempCont.size(); i++) { + for (uint i = 0; i < tempCont.size(); ++i) { Sprite *spr = tempCont[i]; int c = spr->_scene; if ((c == _vm->_now || c == 0) && spr->_ref != bakRef) { @@ -73,7 +72,7 @@ void Spare::dispose(Sprite *spr) { _vm->_vga->_showQ->remove(spr); update(spr->contract()); if (!_vm->isHero(spr)) { - for (int i = 0; i < _container.size(); i++) { + for (uint i = 0; i < _container.size(); ++i) { if (spr == _container[i]) { _container.remove_at(i); delete spr; @@ -89,10 +88,9 @@ void Spare::dispose(int ref) { } void Spare::dispose() { - for (int i = 0; i < _container.size(); i++) { - if (_container[i]->_ref > 255) { + for (uint i = 0; i < _container.size(); ++i) { + if (_container[i]->_ref > 255) dispose(_container[i]); - } } } -- cgit v1.2.3 From 5ad4e157e5398347651a0da0db07f9daf01bf373 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 10:56:02 +0200 Subject: CGE2: Silence a warning in runCommand --- engines/cge2/snail.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 73d29cd59f..f00b02c7bd 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -104,7 +104,7 @@ void CommandHandler::runCommand() { } ++_tail; _vm->_taken = false; - Sprite *spr; + Sprite *spr = nullptr; if (tailCmd._commandType > kCmdSpr) spr = (tailCmd._ref < 0) ? ((Sprite *)tailCmd._spritePtr) : _vm->locate(tailCmd._ref); @@ -314,7 +314,7 @@ void CommandHandler::runCommand() { break; } - if (_vm->_taken) + if (_vm->_taken && spr) _vm->_spare->dispose(spr); if (!_turbo) -- cgit v1.2.3 From e34113a94cf3762880fc33694b61af4d18f5fb8c Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 30 May 2014 12:48:58 +0200 Subject: CGE2: Fix assignments and deinitialization of _eye and _eyeTab. --- engines/cge2/cge2.cpp | 5 +---- engines/cge2/cge2.h | 2 +- engines/cge2/cge2_main.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 273c9dac0d..d0d5740e7a 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -124,12 +124,9 @@ void CGE2Engine::deinit() { for (int i = 0; i < 2; i++) delete _heroTab[i]; for (int i = 0; i < kCaveMax; i++) { - if (_eye == _eyeTab[i]) - _eye = nullptr; delete _eyeTab[i]; } - if (_eye != nullptr) - delete _eye; + delete _eye; delete _spare; delete _sprite; delete _commandHandler; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 66bcd911e9..c7c16d4224 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -139,7 +139,7 @@ public: void releasePocket(Sprite *spr); void switchHero(bool sex); - void setEye(V3D &e); + void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); void setEye(const char *s); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9e9d6da76a..f468d15d66 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -361,7 +361,7 @@ void CGE2Engine::caveUp(int cav) { if (_music) _midiPlayer->loadMidi(bakRef); showBak(bakRef); - _eye = _eyeTab[_now]; + *_eye = *(_eyeTab[_now]); _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; _spare->takeCave(_now); openPocket(); @@ -598,7 +598,7 @@ void CGE2Engine::qGame() { void CGE2Engine::loadTab() { setEye(_text->getText(240)); for (int i = 0; i < kCaveMax; i++) - _eyeTab[i] = _eye; + *(_eyeTab[i]) = *_eye; if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); @@ -660,8 +660,8 @@ char *CGE2Engine::mergeExt(char *buf, const char *name, const char *ext) { return buf; } -void CGE2Engine::setEye(V3D &e) { - _eye = &e; +void CGE2Engine::setEye(const V3D &e) { + *_eye = e; } void CGE2Engine::setEye(const V2D& e2, int z) { -- cgit v1.2.3 From 7e8923f757d990972f2bc5ff995c98c0243b7fba Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 30 May 2014 16:10:51 +0200 Subject: CGE2: Add detection for the WIP English translation --- engines/cge2/detection.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 9c63af1ec6..e417a13853 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -35,7 +35,7 @@ static const PlainGameDescriptor CGE2Games[] = { { 0, 0 } }; -static const ADGameDescription gameDescriptions[] = { // TODO: Add ENG version too. +static const ADGameDescription gameDescriptions[] = { { "sfinx", "Sfinx Freeware", { @@ -45,7 +45,15 @@ static const ADGameDescription gameDescriptions[] = { // TODO: Add ENG version t }, Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() }, - + { + "sfinx", "Sfinx English Alfa v0.1", + { + {"vol.cat", 0, "41a61030468e33828f3531fd53ef0319", 129024}, + {"vol.dat", 0, "978ebe56442c111d193fdb4d960cc58d", 34382498}, + AD_LISTEND + }, + Common::EN_ANY, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() + }, AD_TABLE_END_MARKER }; -- cgit v1.2.3 From 82898716cf24098e664211a5e2f904f9fe98d2d5 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 31 May 2014 15:22:29 +0200 Subject: CGE2: Reimplement Vga::show(). --- engines/cge2/vga13h.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 618fb8a987..bc042a5e5b 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -957,13 +957,41 @@ void Vga::sunset() { } void Vga::show() { - for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) + _vm->_infoLine->update(); + + for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) { spr->show(); + } + + //_vm->_mouse->show(); update(); - for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) + + for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) { spr->hide(); + if (spr->_flags._zmov) { + Sprite *s = nullptr; + Sprite *p = spr->_prev; + Sprite *n = spr->_next; + + if (spr->_flags._shad) { + s = p; + p = s->_prev; + } - _frmCnt++; + if ((p && spr->_pos3D._z > p->_pos3D._z) || + (n && spr->_pos3D._z < n->_pos3D._z)) { + _showQ->insert(_showQ->remove(spr)); + if (s) { + //s->gotoxyz(V3D(s->_pos3D._x, s->_pos3D._y, spr->_pos3D._z)); + //_showQ->insert(_showQ->remove(s), spr); + // These two lines are also commented out in the original. + } + } + spr->_flags._zmov = false; + } + } + //_vm->_mouse->hide(); + warning("STUB: Vga::show() - Mouse handling is missing!"); } void Vga::updateColors() { -- cgit v1.2.3 From 8eb6a4db8bb73df76c5cc1d90775d0925a5a6adb Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 1 Jun 2014 21:44:07 +0200 Subject: CGE2: Add display of mouse cursor. The actual click-handling is not working yet. --- engines/cge2/cge2.cpp | 3 + engines/cge2/cge2.h | 3 + engines/cge2/cge2_main.cpp | 27 +++++-- engines/cge2/events.cpp | 174 +++++++++++++++++++++++++++++++++++++++++++-- engines/cge2/events.h | 27 +++++++ engines/cge2/vga13h.cpp | 14 ++-- engines/cge2/vga13h.h | 2 +- 7 files changed, 233 insertions(+), 17 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index d0d5740e7a..c4ae02757a 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -68,6 +68,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _busyPtr = nullptr; for (int i = 0; i < 2; i++) _vol[i] = nullptr; + _eventManager = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -112,6 +113,7 @@ void CGE2Engine::init() { for (int i = 0; i < kMaxPoint; i++) _point[i] = new V3D(); _sys = new System(this); + _eventManager = new EventManager(this); } void CGE2Engine::deinit() { @@ -140,6 +142,7 @@ void CGE2Engine::deinit() { delete _point[i]; } delete _sys; + delete _eventManager; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c7c16d4224..925cb67f50 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -55,6 +55,7 @@ class Talk; class Hero; class Bitmap; class System; +class EventManager; #define kScrWidth 320 #define kScrHeight 240 @@ -131,6 +132,7 @@ public: void mainLoop(); void handleFrame(); Sprite *locate(int ref); + Sprite *spriteAt(int x, int y); bool isHero(Sprite *spr); void loadUser(); void checkSaySwitch(); @@ -234,6 +236,7 @@ public: System *_sys; Sprite *_busyPtr; Sprite *_vol[2]; + EventManager *_eventManager; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f468d15d66..e9fc11bd86 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -385,6 +385,11 @@ void CGE2Engine::caveUp(int cav) { _sprite = _vga->_showQ->first(); _vga->sunrise(_vga->_sysPal); + _dark = false; + + if (!_startupMode) + _mouse->on(); + feedSnail(_vga->_showQ->locate(bakRef + 255), kNear, _heroTab[_sex]->_ptr); //setDrawColors(); - It's only for debugging purposes. Can be left out for now. } @@ -414,8 +419,7 @@ void CGE2Engine::mainLoop() { handleFrame(); // Handle any pending events - //_eventManager->poll(); - warning("STUB: CGE2Engine::mainLoop() - Event handling is missing!"); + _eventManager->poll(); // Check shouldQuit() _quitFlag = shouldQuit(); @@ -426,8 +430,7 @@ void CGE2Engine::handleFrame() { uint32 millis = g_system->getMillis(); while (!_quitFlag && (millis < (_lastFrame + kGameFrameDelay))) { // Handle any pending events - //_eventManager->poll(); - warning("STUB: CGE2Engine::handleFrame() - Event handling is missing!"); + _eventManager->poll(); if (millis >= (_lastTick + kGameTickDelay)) { // Dispatch the tick to any active objects @@ -476,8 +479,7 @@ void CGE2Engine::tick() { } } - //Mouse->Tick(); - warning("STUB: CGE2Engine::tick() - Mouse"); + _mouse->tick(); } void CGE2Engine::loadMap(int cav) { @@ -756,4 +758,17 @@ void CGE2Engine::switchHero(bool sex) { warning("STUB: CGE2Engine::switchHero()"); } +Sprite *CGE2Engine::spriteAt(int x, int y) { + Sprite *spr = NULL, *tail = _vga->_showQ->last(); + if (tail) { + for (spr = tail->_prev; spr; spr = spr->_prev) { + if (!spr->_flags._hide && !spr->_flags._tran) { + if (spr->shp()->solidAt(x - spr->_pos2D.x, y - spr->_pos2D.y)) + break; + } + } + } + return spr; +} + } // End of namespace CGE2 diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 670ea61c93..5c0300f1e1 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -63,23 +63,187 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { - warning("STUB: Mouse::Mouse() - Recheck the whole implementation!!!"); + _hold = NULL; + _hx = 0; + _hy = 0; + _exist = true; + _buttons = 0; + _busy = NULL; + _active = false; + _flags._kill = false; + + setSeq(_stdSeq8); + + BitmapPtr *MC = new BitmapPtr[3]; + MC[0] = new Bitmap(_vm, "MOUSE"); + MC[1] = new Bitmap(_vm, "DUMMY"); + MC[2] = NULL; + setShapeList(MC, 2); + + step(1); + on(); + off(); } Mouse::~Mouse() { - warning("STUB: Mouse::~Mouse()"); + off(); } void Mouse::on() { - warning("STUB: Mouse::on()"); + if (_seqPtr && _exist) { + _active = true; + step(0); + if (_busy) + _busy->step(0); + } } void Mouse::off() { - warning("STUB: Mouse::off()"); + if (_seqPtr == 0) { + if (_exist) { + _active = false; + } + + step(1); + if (_busy) + _busy->step(1); + } } void Mouse::newMouse(Common::Event &event) { - warning("STUB: Mouse::newMouse()"); + if (!_active) + return; + + CGE2Event &evt = _vm->_eventManager->getNextEvent(); + evt._x = event.mouse.x; + evt._y = event.mouse.y; + evt._keyCode = Common::KEYCODE_INVALID; + evt._spritePtr = _vm->spriteAt(evt._x, evt._y); + + switch (event.type) { + case Common::EVENT_MOUSEMOVE: + evt._mask = kMouseRoll; + break; + case Common::EVENT_LBUTTONDOWN: + evt._mask = kMouseLeftDown; + _buttons |= 1; + break; + case Common::EVENT_LBUTTONUP: + evt._mask = kMouseLeftUp; + _buttons &= ~1; + break; + case Common::EVENT_RBUTTONDOWN: + evt._mask = kMouseRightDown; + _buttons |= 2; + break; + case Common::EVENT_RBUTTONUP: + evt._mask = kMouseRightUp; + _buttons &= ~2; + break; + default: + break; + } +} + +/*----------------- EventManager interface -----------------*/ + +EventManager::EventManager(CGE2Engine *vm) : _vm(vm){ + _eventQueueHead = 0; + _eventQueueTail = 0; + memset(&_eventQueue, 0, kEventMax * sizeof(CGE2Event)); + memset(&_event, 0, sizeof(Common::Event)); +} + +void EventManager::poll() { + while (g_system->getEventManager()->pollEvent(_event)) { + switch (_event.type) { + case Common::EVENT_KEYDOWN: + case Common::EVENT_KEYUP: + // Handle keyboard events + _vm->_keyboard->newKeyboard(_event); + handleEvents(); + break; + case Common::EVENT_MOUSEMOVE: + case Common::EVENT_LBUTTONDOWN: + case Common::EVENT_LBUTTONUP: + case Common::EVENT_RBUTTONDOWN: + case Common::EVENT_RBUTTONUP: + // Handle mouse events + _vm->_mouse->newMouse(_event); + handleEvents(); + break; + default: + break; + } + } +} + +void EventManager::handleEvents() { + while (_eventQueueTail != _eventQueueHead) { + CGE2Event e = _eventQueue[_eventQueueTail]; + if (e._mask) { + if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) + _vm->_mouse->_hold->touch(e._mask | kEventAttn, e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y, e._keyCode); + + // update mouse cursor position + if (e._mask & kMouseRoll) + _vm->_mouse->gotoxyz(e._x, kWorldHeight - e._y); + + // activate current touched SPRITE + if (e._spritePtr) { + if (e._mask & kEventKeyb) + e._spritePtr->touch(e._mask, e._x, e._y, e._keyCode); + else + e._spritePtr->touch(e._mask, e._x - e._spritePtr->_pos2D.x, e._y - e._spritePtr->_pos2D.y, e._keyCode); + } else if (_vm->_sys) + _vm->_sys->touch(e._mask, e._x, e._y, e._keyCode); + + if (e._mask & kMouseLeftDown) { + _vm->_mouse->_hold = e._spritePtr; + if (_vm->_mouse->_hold) { + _vm->_mouse->_hold->_flags._hold = true; + + if (_vm->_mouse->_hold->_flags._drag) { + _vm->_mouse->_hx = e._x - _vm->_mouse->_hold->_pos2D.x; + _vm->_mouse->_hy = e._y - _vm->_mouse->_hold->_pos2D.y; + } + } + } + + if (e._mask & kMouseLeftUp) { + if (_vm->_mouse->_hold) { + _vm->_mouse->_hold->_flags._hold = false; + _vm->_mouse->_hold = NULL; + } + } + ///Touched = e.Ptr; + + // discard Text if button released + if (e._mask & (kMouseLeftUp | kMouseRightUp)) + _vm->killText(); + } + _eventQueueTail = (_eventQueueTail + 1) % kEventMax; + } + if (_vm->_mouse->_hold) { + if (_vm->_mouse->_hold->_flags._drag) + _vm->_mouse->_hold->gotoxyz(_vm->_mouse->_pos2D.x - _vm->_mouse->_hx, kWorldHeight - _vm->_mouse->_pos2D.y - _vm->_mouse->_hy); + } +} + +void EventManager::clearEvent(Sprite *spr) { + if (spr) { + for (uint16 e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) + if (_eventQueue[e]._spritePtr == spr) + _eventQueue[e]._mask = 0; + } else + _eventQueueTail = _eventQueueHead; +} + +CGE2Event &EventManager::getNextEvent() { + CGE2Event &evt = _eventQueue[_eventQueueHead]; + _eventQueueHead = (_eventQueueHead + 1) % kEventMax; + + return evt; } } // End of namespace CGE2 diff --git a/engines/cge2/events.h b/engines/cge2/events.h index 99f017bae3..39fbf536b9 100644 --- a/engines/cge2/events.h +++ b/engines/cge2/events.h @@ -65,6 +65,14 @@ public: /*----------------- MOUSE interface -----------------*/ +struct CGE2Event { + uint16 _mask; + uint16 _x; + uint16 _y; + Common::KeyCode _keyCode; + Sprite *_spritePtr; +}; + class Mouse : public Sprite { public: Sprite *_hold; @@ -83,6 +91,25 @@ private: CGE2Engine *_vm; }; +/*----------------- EventManager interface -----------------*/ + +class EventManager { +private: + CGE2Engine *_vm; + Common::Event _event; + CGE2Event _eventQueue[kEventMax]; + uint16 _eventQueueHead; + uint16 _eventQueueTail; + + void handleEvents(); +public: + EventManager(CGE2Engine *vm); + void poll(); + void clearEvent(Sprite *spr); + + CGE2Event &getNextEvent(); +}; + } // End of namespace CGE #endif // #define CGE2_EVENTS_H diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index bc042a5e5b..8158d6da96 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -129,7 +129,7 @@ void Sprite::setShapeList(BitmapPtr *shp, int cnt) { if (shp) { for (int i = 0; i < cnt; i++) { - BitmapPtr p = *shp + i; + BitmapPtr p = *(shp + i); if (p->_w > _siz.x) _siz.x = p->_w; if (p->_h > _siz.y) @@ -472,6 +472,11 @@ void Sprite::step(int nr) { _vm->_waitRef = 0; } +#pragma argsused +void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { + warning("STUB: Sprite::touch()"); +} + void Sprite::tick() { step(); } @@ -530,7 +535,7 @@ void Sprite::gotoxyz(V2D pos) { ++trim; } _pos2D.x = pos.x; - + if (pos.y < -kPanHeight) { pos.y = -kPanHeight; ++trim; @@ -963,7 +968,7 @@ void Vga::show() { spr->show(); } - //_vm->_mouse->show(); + _vm->_mouse->show(); update(); for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) { @@ -990,8 +995,7 @@ void Vga::show() { spr->_flags._zmov = false; } } - //_vm->_mouse->hide(); - warning("STUB: Vga::show() - Mouse handling is missing!"); + _vm->_mouse->hide(); } void Vga::updateColors() { diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 20d97ee4eb..a4829b6947 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -198,7 +198,7 @@ public: void step(int nr = -1); Seq *setSeq(Seq *seq); CommandHandler::Command *snList(Action type); - //virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); + virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); virtual void tick(); void clrHide(void) { if (_ext) _ext->_b0 = NULL; } void sync(Common::Serializer &s); -- cgit v1.2.3 From ff21b2d5c8f8510ea5cfc6e59385c272d9774af9 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 10:03:15 +0200 Subject: CGE2: Implement Hero::expand(), move Sprite::works()'s stub to hero.cpp. --- engines/cge2/bitmap.cpp | 9 ++- engines/cge2/bitmap.h | 2 + engines/cge2/hero.cpp | 195 +++++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/hero.h | 4 +- engines/cge2/vga13h.cpp | 19 +---- 5 files changed, 204 insertions(+), 25 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 10fd6f1163..dfc5bcadd2 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -35,7 +35,14 @@ namespace CGE2 { -Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(NULL), _v(NULL), _map(0), _vm(vm) { +Bitmap::Bitmap() : _w(0), _h(0), _v(NULL), _b(NULL) { +} + +void Bitmap::setVM(CGE2Engine *vm) { + _vm = vm; +} + +Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(NULL), _v(NULL), _b(NULL), _map(0), _vm(vm) { char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 82c3b07e31..102fb1c8ca 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -66,12 +66,14 @@ public: int32 _map; HideDesc *_b; + Bitmap(); Bitmap(CGE2Engine *vm, const char *fname); Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map); Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill); Bitmap(CGE2Engine *vm, const Bitmap &bmp); ~Bitmap(); + void setVM(CGE2Engine *vm); Bitmap *code(); Bitmap &operator=(const Bitmap &bmp); void release(); diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 3a6d1d2920..0c28d4c7f0 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -26,15 +26,185 @@ */ #include "cge2/hero.h" +#include "cge2/text.h" +#include "cge2/cge2_main.h" namespace CGE2 { -Hero::Hero(CGE2Engine *vm) : Sprite(vm) { - warning("STUB: Hero::Hero()"); +Hero::Hero(CGE2Engine *vm) + : Sprite(vm), _contact(nullptr), _dir(kNoDir), + _curDim(0), _tracePtr(-1), _ignoreMap(false) { } -Sprite *Hero::expand(void) { - warning("STUB: Hero::expand()"); +Sprite *Hero::expand(void) { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! + if (_ext) + return this; + + char *text = _vm->_text->getText(_ref + 100); + char fname[kMaxPath]; + _vm->mergeExt(fname, _file, kSprExt); + _ext = new SprExt(_vm); + if (_ext == nullptr) + error("No core %s", fname); + + if (*_file) { + int cnt[kActions]; + int shpcnt = 0; + int seqcnt = 0; + int maxnow = 0; + int maxnxt = 0; + Seq *seq; + int section = kIdPhase; + + for (int i = 0; i < kDimMax; i++) { + _dim[i] = new Bitmap[_shpCnt]; + for (int j = 0; j < _shpCnt; j++) + _dim[i][j].setVM(_vm); + } + + if (_seqCnt) { + seq = new Seq[_seqCnt]; + if (seq == nullptr) + error("No core %s", fname); + } else + seq = nullptr; + + for (int i = 0; i < kActions; i++) + cnt[i] = 0; + + for (int i = 0; i < kActions; i++) { + byte n = _actionCtrl[i]._cnt; + if (n) { + _ext->_actions[i] = new CommandHandler::Command[n]; + if (_ext->_actions[i] == nullptr) + error("No core %s", fname); + } else + _ext->_actions[i] = nullptr; + } + + if (_vm->_resman->exist(fname)) { // sprite description file exist + EncryptedStream sprf(_vm, fname); + if (sprf.err()) + error("Bad SPR [%s]", fname); + + ID id; + Common::String line; + char tmpStr[kLineMax + 1]; + + for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { + if (line.size() == 0) + continue; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *p = _vm->token(tmpStr); + + id = _vm->ident(p); + switch (id) { + case kIdNear: + case kIdMTake: + case kIdFTake: + case kIdPhase: + case kIdSeq: + section = id; + break; + case kIdName: + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + for (p = tmpStr; *p != '='; p++); // We search for the = + setName(_vm->tail(p)); + break; + default: + if (id >= kIdNear) + break; + Seq *s; + switch (section) { + case kIdNear: + case kIdMTake: + case kIdFTake: + id = (ID)_vm->_commandHandler->com(p); + if (_actionCtrl[section]._cnt) { + CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; + c->_commandType = CommandType(id); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + c->_ref = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + c->_val = _vm->number(p); + c->_spritePtr = nullptr; + } + break; + case kIdSeq: + s = &seq[seqcnt++]; + s->_now = atoi(p); + if (s->_now > maxnow) + maxnow = s->_now; + if ((p = _vm->token(nullptr)) == NULL) + break; + s->_next = _vm->number(p); + switch (s->_next) { + case 0xFF: + s->_next = seqcnt; + break; + case 0xFE: + s->_next = seqcnt - 1; + break; + } + if (s->_next > maxnxt) + maxnxt = s->_next; + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dx = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dy = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dz = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dly = _vm->number(p); + break; + case kIdPhase: + for (int i = 0; i < kDimMax; i++) { + char *q = p; + q[1] = '0' + i; + Bitmap b(_vm, q); + if (!b.moveHi()) + error("No EMS %s", q); + _dim[i][shpcnt] = b; + if (!shpcnt) + _hig[i] = b._h; + } + ++shpcnt; + break; + } + } + } + if (seq) { + if (maxnow >= shpcnt) + error("Bad PHASE in SEQ %s", fname); + if (maxnxt >= seqcnt) + error("Bad JUMP in SEQ %s", fname); + setSeq(seq); + } else + setSeq(_stdSeq8); + + BitmapPtr *bmp = new BitmapPtr[shpcnt]; + for (int i = 0; i < shpcnt; i++) + bmp[i] = &_dim[0][i]; + setShapeList(bmp, shpcnt); + delete[] bmp; + } + } + _reachStart = atoi(_vm->token(text)); + _reachCycle = atoi(_vm->token(nullptr)); + _sayStart = atoi(_vm->token(nullptr)); + _funStart = atoi(_vm->token(nullptr)); + _funDel = _funDel0 = (72 / _ext->_seq[0]._dly) * atoi(_vm->token(nullptr)); + int i = stepSize() / 2; + _maxDist = sqrt(double(i * i * 2)); + setCurrent(); + return this; } @@ -143,4 +313,21 @@ void Hero::setCave(int c) { warning("STUB: Hero::mapCross()"); } +bool Sprite::works(Sprite *spr) { + //if (!spr || !spr->_ext) + // return false; + + //CommandHandler::Command *c = spr->_ext->_take; + //if (c != NULL) { + // c += spr->_takePtr; + // if (c->_ref == _ref) + // if (c->_commandType != kCmdLabel || (c->_val == 0 || c->_val == _vm->_now)) + // return true; + //} + + warning("STUB: Sprite::works()"); + + return false; +} + } // End of namespace CGE2 diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 032a46d1b3..9723be8ca8 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -96,8 +96,8 @@ public: void reach(int mode); void setCurrent(void); void setCave(int c); - void operator ++ (void); - void operator -- (void); + void operator++(void); + void operator--(void); }; } // End of namespace CGE2 diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 8158d6da96..e4b7dbffc7 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -144,23 +144,6 @@ void Sprite::setShapeList(BitmapPtr *shp, int cnt) { } } -bool Sprite::works(Sprite *spr) { - //if (!spr || !spr->_ext) - // return false; - - //CommandHandler::Command *c = spr->_ext->_take; - //if (c != NULL) { - // c += spr->_takePtr; - // if (c->_ref == _ref) - // if (c->_commandType != kCmdLabel || (c->_val == 0 || c->_val == _vm->_now)) - // return true; - //} - - warning("STUB: Sprite::works()"); - - return false; -} - Seq *Sprite::setSeq(Seq *seq) { expand(); @@ -264,7 +247,7 @@ Sprite *Sprite::expand() { Common::String line; char tmpStr[kLineMax + 1]; - for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ + for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { if (line.size() == 0) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); -- cgit v1.2.3 From 219f4f6695af35d139b32a3daf5371e19d70c71c Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 13:43:28 +0200 Subject: CGE2: Implement Hero::setCurrent(). --- engines/cge2/hero.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 0c28d4c7f0..5a6e437824 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -209,7 +209,16 @@ Sprite *Hero::expand(void) { // It's very similar to Sprite's expand, but doesn' } void Hero::setCurrent(void) { - warning("STUB: Hero::setCurrent()"); + double m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); + int h = -(V2D::trunc(m * _siz.y)); + + int i = 0; + for (; i < kDimMax; i++) { + if (h >= (_hig[i] + _hig[i + 1]) / 2) + break; + } + + _ext->_shpList = &_dim[_curDim = i]; } void Hero::hStep(void) { -- cgit v1.2.3 From 562644db48a894bff55eeef03f89ce3b1ecc4c51 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 13:50:47 +0200 Subject: CGE2: Remove unnecessary void parameters in Hero. --- engines/cge2/hero.cpp | 20 ++++++++++---------- engines/cge2/hero.h | 32 ++++++++++++++++---------------- 2 files changed, 26 insertions(+), 26 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 5a6e437824..151b3da475 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -36,7 +36,7 @@ Hero::Hero(CGE2Engine *vm) _curDim(0), _tracePtr(-1), _ignoreMap(false) { } -Sprite *Hero::expand(void) { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! +Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! if (_ext) return this; @@ -208,7 +208,7 @@ Sprite *Hero::expand(void) { // It's very similar to Sprite's expand, but doesn' return this; } -void Hero::setCurrent(void) { +void Hero::setCurrent() { double m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); int h = -(V2D::trunc(m * _siz.y)); @@ -221,16 +221,16 @@ void Hero::setCurrent(void) { _ext->_shpList = &_dim[_curDim = i]; } -void Hero::hStep(void) { +void Hero::hStep() { warning("STUB: Hero::hStep()"); } -Sprite *Hero::setContact(void) { +Sprite *Hero::setContact() { warning("STUB: Hero::setContact()"); return this; } -void Hero::tick(void) { +void Hero::tick() { warning("STUB: Hero::tick()"); } @@ -248,7 +248,7 @@ void Hero::turn(Dir d) { warning("STUB: Hero::turn()"); } -void Hero::park(void) { +void Hero::park() { warning("STUB: Hero::park()"); } @@ -261,15 +261,15 @@ void Hero::reach(int mode) { warning("STUB: Hero::reach()"); } -void Hero::fun(void) { +void Hero::fun() { warning("STUB: Hero::fun()"); } -void Hero::operator ++ (void) { +void Hero::operator ++ () { warning("STUB: Hero::operator ++()"); } -void Hero::operator -- (void) { +void Hero::operator -- () { warning("STUB: Hero::operator --()"); } @@ -278,7 +278,7 @@ uint32 Hero::len(V2D v) { return 0; } -bool Hero::findWay(void){ +bool Hero::findWay(){ warning("STUB: Hero::findWay()"); return false; } diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 9723be8ca8..8face03944 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -67,37 +67,37 @@ public: int _maxDist; bool _ignoreMap; Hero(CGE2Engine *vm); - void tick(void); - Sprite *expand(void); - Sprite *contract(void) { return this; } - Sprite *setContact(void); - int stepSize(void) { return _ext->_seq[7]._dx; } + void tick(); + Sprite *expand(); + Sprite *contract() { return this; } + Sprite *setContact(); + int stepSize() { return _ext->_seq[7]._dx; } int distance(V3D pos); int distance(Sprite * spr); void turn(Dir d); - void park(void); + void park(); static uint32 len(V2D v); - bool findWay(void); + bool findWay(); static int snap(int p, int q, int grid); void walkTo(V3D pos); void walkTo(V2D pos) { walkTo(screenToGround(pos)); } V3D screenToGround(V2D pos); void walkTo(Sprite *spr); - void say(void) { step(_sayStart); } - void fun(void); - void resetFun(void) { _funDel = _funDel0; } - void hStep(void); + void say() { step(_sayStart); } + void fun(); + void resetFun() { _funDel = _funDel0; } + void hStep(); bool lower(Sprite * spr); int cross(const V2D &a, const V2D &b); int mapCross(const V2D &a, const V2D &b); int mapCross(const V3D &a, const V3D &b); - Hero *other(void) { return _vm->_heroTab[!(_ref & 1)]->_ptr;} - Action action(void) { return (Action)(_ref % 10); } + Hero *other() { return _vm->_heroTab[!(_ref & 1)]->_ptr;} + Action action() { return (Action)(_ref % 10); } void reach(int mode); - void setCurrent(void); + void setCurrent(); void setCave(int c); - void operator++(void); - void operator--(void); + void operator++(); + void operator--(); }; } // End of namespace CGE2 -- cgit v1.2.3 From 79ef03801d90064291aaa4709c8560c9c98cf5b7 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 13:58:52 +0200 Subject: CGE2: Implement CGE2Eninge::switchHero(). --- engines/cge2/cge2_main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e9fc11bd86..1ca99bd5ff 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -755,7 +755,21 @@ void CGE2Engine::killText() { } void CGE2Engine::switchHero(bool sex) { - warning("STUB: CGE2Engine::switchHero()"); + if (sex != _sex) { + int scene = _heroTab[sex]->_ptr->_scene; + if (_blinkSprite) { + _blinkSprite->_flags._hide = false; + _blinkSprite = nullptr; + } + if (scene >= 0) { + _commandHandler->addCommand(kCmdSeq, -1, 2, _heroTab[_sex]->_face); + _sex = !_sex; + switchCave(scene); + } + } + Sprite *face = _heroTab[_sex]->_face; + if (face->_seqPtr == 0) + _commandHandler->addCommand(kCmdSeq, -1, 1, face); } Sprite *CGE2Engine::spriteAt(int x, int y) { -- cgit v1.2.3 From 0e62716038ec5ba108cbc272b1b06b49a608b11b Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 14:33:30 +0200 Subject: CGE2: Add and use Spare::take(). --- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/spare.cpp | 14 ++++++++++++++ engines/cge2/spare.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 1ca99bd5ff..532836186c 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -399,7 +399,7 @@ void CGE2Engine::switchCave(int cav) { } void CGE2Engine::showBak(int ref) { - Sprite *spr = _spare->locate(ref); + Sprite *spr = _spare->take(ref); if (spr != nullptr) { _bitmapPalette = _vga->_sysPal; spr->expand(); diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index be2fc64d23..043122199c 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -45,6 +45,19 @@ Sprite *Spare::locate(int ref) { return nullptr; } +Sprite *Spare::take(int ref) { + Sprite *spr = nullptr; + if ((spr = locate(ref)) != nullptr) { + for (uint i = 0; i < _container.size(); ++i) { + if (spr == _container[i]) { + _container.remove_at(i); + break; + } + } + } + return spr; +} + void Spare::takeCave(int cav) { int bakRef = cav << 8; Common::Array tempCont = _container; @@ -52,6 +65,7 @@ void Spare::takeCave(int cav) { Sprite *spr = tempCont[i]; int c = spr->_scene; if ((c == _vm->_now || c == 0) && spr->_ref != bakRef) { + spr = take(spr->_ref); _vm->_vga->_showQ->insert(spr); } } diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 7bd520d9d0..18909225db 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -40,6 +40,7 @@ public: ~Spare() { clear(); } void store(Sprite *spr); Sprite *locate(int ref); + Sprite *take(int ref); void takeCave(int cav); void update(Sprite *spr); void dispose(Sprite *spr); -- cgit v1.2.3 From 21513b448fe7061ffa0c0ed92465386ffacfb3b6 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 14:37:41 +0200 Subject: CGE2: Partially implement and use loadGame(). --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 925cb67f50..b51ae2750d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -112,6 +112,7 @@ public: void inf(const char *text, bool wideSpace = false); void movie(const char *ext); void runGame(); + void loadGame(); void loadScript(const char *fname); void loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 532836186c..78d743596b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -561,9 +561,50 @@ void CGE2Engine::loadUser() { warning("STUB: CGE2Engine::loadUser()"); // Missing loading from file. TODO: Implement it with the saving/loading! loadScript("CGE.INI"); + loadGame(); loadPos(); } +void CGE2Engine::loadGame() { + warning("STUB: CGE2Engine::loadGame()"); + + // load sprites & pocket + + Sprite *s; + Hero *h; + + // initialize Andzia + s = _spare->take(142); + if (s) { + h = new Hero(this); + *(Sprite*)h = *s; + delete s; + h->expand(); + _spare->update(h); + } + _heroTab[0]->_ptr = h; + s = _spare->take(152); + _vga->_showQ->insert(s); + _heroTab[0]->_face = s; + + // initialize Wacek + s = _spare->take(141); + if (s) { + h = new Hero(this); + *(Sprite*)h = *s; + delete s; + h->expand(); + _spare->update(h); + } + _heroTab[1]->_ptr = h; + s = _spare->take(151); + _vga->_showQ->insert(s); + _heroTab[1]->_face = s; + + //--- start! + switchHero(_sex); +} + void CGE2Engine::loadPos() { if (_resman->exist("CGE.HXY")) { for (int cav = 0; cav < kCaveMax; cav++) -- cgit v1.2.3 From 87db3d2d750c3c609ded7576f14e35a22f96f849 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 14:38:40 +0200 Subject: CGE2: Add _blinkSprite. This also fixes previously broken compilation in 79ef038. --- engines/cge2/cge2.cpp | 3 +++ engines/cge2/cge2.h | 1 + 2 files changed, 4 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index c4ae02757a..f616a6064d 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -69,6 +69,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) for (int i = 0; i < 2; i++) _vol[i] = nullptr; _eventManager = nullptr; + _blinkSprite = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -143,6 +144,8 @@ void CGE2Engine::deinit() { } delete _sys; delete _eventManager; + if (_blinkSprite != nullptr) + delete _blinkSprite; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index b51ae2750d..09e1e0f900 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -238,6 +238,7 @@ public: Sprite *_busyPtr; Sprite *_vol[2]; EventManager *_eventManager; + Sprite *_blinkSprite; private: void init(); void deinit(); -- cgit v1.2.3 From 6d73870431d0a713520f09d7d8eb4f4512651f23 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 14:46:59 +0200 Subject: CGE2: Move then implement Sprite::touch(). Also add stubs for called functions. --- engines/cge2/cge2.h | 2 ++ engines/cge2/cge2_main.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/vga13h.cpp | 5 --- 3 files changed, 87 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 09e1e0f900..69f8b758ae 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -141,6 +141,8 @@ public: void loadPos(); void releasePocket(Sprite *spr); void switchHero(bool sex); + void optionTouch(int opt, uint16 mask); + void offUse(); void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 78d743596b..cec22f24ad 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -826,4 +826,89 @@ Sprite *CGE2Engine::spriteAt(int x, int y) { return spr; } +#pragma argsused +void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { + if ((mask & kEventAttn) != 0) + return; + + if (!_vm->_startupMode) + _vm->_infoLine->setText(name()); + + if (_ref < 0) + return; // cannot access system sprites + + if (_ref / 10 == 12) { + _vm->optionTouch(_ref % 10, mask); + return; + } + + if (_vm->isHero(this) && !_vm->_blinkSprite) { + _vm->switchHero(this == _vm->_heroTab[1]->_ptr); + } else { // not HERO || sprite from pocket ready to use + if (_flags._kept) { // sprite in pocket + for (int sex = 0; sex < 2; sex++) { + for (int p = 0; p < kPocketMax; p++) { + if (_vm->_heroTab[sex]->_pocket[p] == this) { + _vm->switchHero(sex); + if (_vm->_sex == sex) { + if (_vm->_blinkSprite) + _vm->_blinkSprite->_flags._hide = false; + if (_vm->_blinkSprite == this) + _vm->_blinkSprite = nullptr; + else + _vm->_blinkSprite = this; + } + } + } + } + } else { // sprite NOT in pocket + Hero *h = _vm->_heroTab[_vm->_sex]->_ptr; + if (!_vm->_talk) { + if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1)) h->walkTo(this); + else { + if (_vm->_blinkSprite) { + if (works(_vm->_blinkSprite)) { + _vm->feedSnail(_vm->_blinkSprite, (_vm->_sex) ? kMTake : kFTake, _vm->_heroTab[_vm->_sex]->_ptr); + _vm->_blinkSprite->_flags._hide = false; + _vm->_blinkSprite = nullptr; + } else + _vm->offUse(); + + _vm->selectPocket(-1); + } else { // no pocket sprite selected + if (_flags._port) { // portable + if (_vm->findActivePocket(-1) < 0) + _vm->pocFul(); + else { + _vm->_commandHandler->addCommand(kCmdReach, -2, _ref, nullptr); + _vm->_commandHandler->addCommand(kCmdKeep, -1, -1, this); + _flags._port = false; + } + } else { // non-portable + Action a = h->action(); + if (_actionCtrl[a]._cnt) { + CommandHandler::Command *cmdList = snList(a); + if (cmdList[_actionCtrl[a]._ptr]._commandType == kCmdNext) + _vm->offUse(); + else + _vm->feedSnail(this, a, h); + } else + _vm->offUse(); + } + } + } + } + } + } +} + +void CGE2Engine::optionTouch(int opt, uint16 mask) { + warning("STUB: CGE2Engine::optionTouch()"); +} + +void CGE2Engine::offUse() { + warning("STUB: CGE2Engine::offUse()"); +} + + } // End of namespace CGE2 diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index e4b7dbffc7..cfcf25f802 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -455,11 +455,6 @@ void Sprite::step(int nr) { _vm->_waitRef = 0; } -#pragma argsused -void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { - warning("STUB: Sprite::touch()"); -} - void Sprite::tick() { step(); } -- cgit v1.2.3 From 5d9e31c708849ef495e07da9271e1039d177a0d4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 07:12:18 +0200 Subject: CGE2: Fix rounding error, remove (original) debug code --- engines/cge2/vga13h.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index cfcf25f802..fb219998de 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -528,9 +528,9 @@ void Sprite::gotoxyz(V2D pos) { if (!_follow) { double m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); - _pos3D._x = (_vm->_eye->_x + V2D::round(_vm->_eye->_x - _pos2D.x) / m); + _pos3D._x = V2D::round(_vm->_eye->_x + (_vm->_eye->_x - _pos2D.x) / m); if (!_constY) - _pos3D._y = (_vm->_eye->_y + V2D::round(_vm->_eye->_y - _pos2D.y) / m); + _pos3D._y = V2D::round(_vm->_eye->_y + (_vm->_eye->_y - _pos2D.y) / m); } if (_next && _next->_flags._slav) @@ -538,9 +538,6 @@ void Sprite::gotoxyz(V2D pos) { if (_flags._shad) _prev->gotoxyz(_prev->_pos2D - o + _pos2D); - - if (_ref == 141 && _pos3D._y >= 5) - warning("Sprite::gotoxyz - asm nop"); } void Sprite::gotoxyz_(V2D pos) { -- cgit v1.2.3 From 41f9195f5608df90ab08f397678f064d4e785b5b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 07:28:33 +0200 Subject: CGE2: Fix flags synchronization --- engines/cge2/vga13h.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index fb219998de..ff58ccd25d 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -616,43 +616,41 @@ void Sprite::sync(Common::Serializer &s) { if (s.isLoading()) { s.syncAsUint16LE(flags); _flags._hide = flags & 0x0001 ? true : false; - _flags._near = flags & 0x0002 ? true : false; - _flags._drag = flags & 0x0004 ? true : false; - _flags._hold = flags & 0x0008 ? true : false; - //_flags._dummy = flags & 0x0010 ? true : false; - _flags._slav = flags & 0x0020 ? true : false; - //_flags._syst = flags & 0x0040 ? true : false; - _flags._kill = flags & 0x0080 ? true : false; - _flags._xlat = flags & 0x0100 ? true : false; - _flags._port = flags & 0x0200 ? true : false; - _flags._kept = flags & 0x0400 ? true : false; - _flags._east = flags & 0x0800 ? true : false; + _flags._drag = flags & 0x0002 ? true : false; + _flags._hold = flags & 0x0004 ? true : false; + _flags._trim = flags & 0x0008 ? true : false; + _flags._slav = flags & 0x0010 ? true : false; + _flags._kill = flags & 0x0020 ? true : false; + _flags._xlat = flags & 0x0040 ? true : false; + _flags._port = flags & 0x0080 ? true : false; + _flags._kept = flags & 0x0100 ? true : false; + _flags._frnt = flags & 0x0200 ? true : false; + _flags._east = flags & 0x0400 ? true : false; + _flags._near = flags & 0x0800 ? true : false; _flags._shad = flags & 0x1000 ? true : false; _flags._back = flags & 0x2000 ? true : false; - //_flags._bDel = flags & 0x4000 ? true : false; + _flags._zmov = flags & 0x4000 ? true : false; _flags._tran = flags & 0x8000 ? true : false; } else { flags = (flags << 1) | _flags._tran; - //flags = (flags << 1) | _flags._bDel; + flags = (flags << 1) | _flags._zmov; flags = (flags << 1) | _flags._back; flags = (flags << 1) | _flags._shad; + flags = (flags << 1) | _flags._near; flags = (flags << 1) | _flags._east; + flags = (flags << 1) | _flags._frnt; flags = (flags << 1) | _flags._kept; flags = (flags << 1) | _flags._port; flags = (flags << 1) | _flags._xlat; flags = (flags << 1) | _flags._kill; - //flags = (flags << 1) | _flags._syst; flags = (flags << 1) | _flags._slav; - //flags = (flags << 1) | _flags._dummy; + flags = (flags << 1) | _flags._trim; flags = (flags << 1) | _flags._hold; flags = (flags << 1) | _flags._drag; - flags = (flags << 1) | _flags._near; flags = (flags << 1) | _flags._hide; s.syncAsUint16LE(flags); } - warning("STUB: Sprite::sync() - Flags changed compared to CGE1's Sprite type."); - s.syncAsUint16LE(_pos3D._x); s.syncAsUint16LE(_pos3D._y); s.syncAsByte(_pos3D._z); -- cgit v1.2.3 From 46d93eb780621392b563995c5c72ffb398e6206e Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 07:35:21 +0200 Subject: CGE2: Rework style in touch() --- engines/cge2/cge2_main.cpp | 92 ++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 48 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index cec22f24ad..64f39a37ea 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -844,59 +844,55 @@ void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { if (_vm->isHero(this) && !_vm->_blinkSprite) { _vm->switchHero(this == _vm->_heroTab[1]->_ptr); - } else { // not HERO || sprite from pocket ready to use - if (_flags._kept) { // sprite in pocket - for (int sex = 0; sex < 2; sex++) { - for (int p = 0; p < kPocketMax; p++) { - if (_vm->_heroTab[sex]->_pocket[p] == this) { - _vm->switchHero(sex); - if (_vm->_sex == sex) { - if (_vm->_blinkSprite) - _vm->_blinkSprite->_flags._hide = false; - if (_vm->_blinkSprite == this) - _vm->_blinkSprite = nullptr; - else - _vm->_blinkSprite = this; - } + } else if (_flags._kept) { // sprite in pocket + for (int sex = 0; sex < 2; sex++) { + for (int p = 0; p < kPocketMax; p++) { + if (_vm->_heroTab[sex]->_pocket[p] == this) { + _vm->switchHero(sex); + if (_vm->_sex == sex) { + if (_vm->_blinkSprite) + _vm->_blinkSprite->_flags._hide = false; + if (_vm->_blinkSprite == this) + _vm->_blinkSprite = nullptr; + else + _vm->_blinkSprite = this; } } } - } else { // sprite NOT in pocket - Hero *h = _vm->_heroTab[_vm->_sex]->_ptr; - if (!_vm->_talk) { - if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1)) h->walkTo(this); + } + } else { // sprite NOT in pocket + Hero *h = _vm->_heroTab[_vm->_sex]->_ptr; + if (!_vm->_talk) { + if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1)) + h->walkTo(this); + else if (_vm->_blinkSprite) { + if (works(_vm->_blinkSprite)) { + _vm->feedSnail(_vm->_blinkSprite, (_vm->_sex) ? kMTake : kFTake, _vm->_heroTab[_vm->_sex]->_ptr); + _vm->_blinkSprite->_flags._hide = false; + _vm->_blinkSprite = nullptr; + } else + _vm->offUse(); + + _vm->selectPocket(-1); + // else, no pocket sprite selected + } else if (_flags._port) { // portable + if (_vm->findActivePocket(-1) < 0) + _vm->pocFul(); else { - if (_vm->_blinkSprite) { - if (works(_vm->_blinkSprite)) { - _vm->feedSnail(_vm->_blinkSprite, (_vm->_sex) ? kMTake : kFTake, _vm->_heroTab[_vm->_sex]->_ptr); - _vm->_blinkSprite->_flags._hide = false; - _vm->_blinkSprite = nullptr; - } else - _vm->offUse(); - - _vm->selectPocket(-1); - } else { // no pocket sprite selected - if (_flags._port) { // portable - if (_vm->findActivePocket(-1) < 0) - _vm->pocFul(); - else { - _vm->_commandHandler->addCommand(kCmdReach, -2, _ref, nullptr); - _vm->_commandHandler->addCommand(kCmdKeep, -1, -1, this); - _flags._port = false; - } - } else { // non-portable - Action a = h->action(); - if (_actionCtrl[a]._cnt) { - CommandHandler::Command *cmdList = snList(a); - if (cmdList[_actionCtrl[a]._ptr]._commandType == kCmdNext) - _vm->offUse(); - else - _vm->feedSnail(this, a, h); - } else - _vm->offUse(); - } - } + _vm->_commandHandler->addCommand(kCmdReach, -2, _ref, nullptr); + _vm->_commandHandler->addCommand(kCmdKeep, -1, -1, this); + _flags._port = false; } + } else { // non-portable + Action a = h->action(); + if (_actionCtrl[a]._cnt) { + CommandHandler::Command *cmdList = snList(a); + if (cmdList[_actionCtrl[a]._ptr]._commandType == kCmdNext) + _vm->offUse(); + else + _vm->feedSnail(this, a, h); + } else + _vm->offUse(); } } } -- cgit v1.2.3 From 7ef509608e957cb62cda7265e173f1a30a69b659 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 07:42:17 +0200 Subject: CGE2: USe an int for sex instead of a boolean --- engines/cge2/cge2.cpp | 2 +- engines/cge2/cge2.h | 4 ++-- engines/cge2/cge2_main.cpp | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index f616a6064d..4bac09a1a0 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -77,7 +77,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _music = true; _startupMode = 1; _now = 1; - _sex = true; + _sex = 1; _mouseTop = kWorldHeight / 3; _dark = false; _lastFrame = 0; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 69f8b758ae..2c34b0a1c3 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -140,7 +140,7 @@ public: void qGame(); void loadPos(); void releasePocket(Sprite *spr); - void switchHero(bool sex); + void switchHero(int sex); void optionTouch(int opt, uint16 mask); void offUse(); @@ -205,7 +205,7 @@ public: bool _music; int _startupMode; int _now; - bool _sex; + int _sex; int _mouseTop; bool _dark; int _waitSeq; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 64f39a37ea..e379977d6c 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -573,7 +573,7 @@ void CGE2Engine::loadGame() { Sprite *s; Hero *h; - // initialize Andzia + // initialize Andzia/Anna s = _spare->take(142); if (s) { h = new Hero(this); @@ -587,7 +587,7 @@ void CGE2Engine::loadGame() { _vga->_showQ->insert(s); _heroTab[0]->_face = s; - // initialize Wacek + // initialize Wacek/Vincent s = _spare->take(141); if (s) { h = new Hero(this); @@ -795,7 +795,7 @@ void CGE2Engine::killText() { _talk = NULL; } -void CGE2Engine::switchHero(bool sex) { +void CGE2Engine::switchHero(int sex) { if (sex != _sex) { int scene = _heroTab[sex]->_ptr->_scene; if (_blinkSprite) { @@ -804,7 +804,7 @@ void CGE2Engine::switchHero(bool sex) { } if (scene >= 0) { _commandHandler->addCommand(kCmdSeq, -1, 2, _heroTab[_sex]->_face); - _sex = !_sex; + _sex ^= 1; switchCave(scene); } } @@ -843,10 +843,10 @@ void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { } if (_vm->isHero(this) && !_vm->_blinkSprite) { - _vm->switchHero(this == _vm->_heroTab[1]->_ptr); + _vm->switchHero((this == _vm->_heroTab[1]->_ptr) ? 1 : 0); } else if (_flags._kept) { // sprite in pocket - for (int sex = 0; sex < 2; sex++) { - for (int p = 0; p < kPocketMax; p++) { + for (int sex = 0; sex < 2; ++sex) { + for (int p = 0; p < kPocketMax; ++p) { if (_vm->_heroTab[sex]->_pocket[p] == this) { _vm->switchHero(sex); if (_vm->_sex == sex) { -- cgit v1.2.3 From de8affdec579542767cfd827f2dd19a035319d65 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 17:39:10 +0200 Subject: CGE2: Silence some gcc warnings --- engines/cge2/cge2_main.cpp | 4 ++-- engines/cge2/hero.cpp | 2 +- engines/cge2/snail.cpp | 2 +- engines/cge2/snail.h | 2 +- engines/cge2/vga13h.cpp | 19 +++++++++++-------- engines/cge2/vga13h.h | 6 +++--- 6 files changed, 19 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e379977d6c..4fb0b2981e 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -179,7 +179,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { case kIdNear: case kIdMTake: case kIdFTake: - if (_commandHandler->com(p) >= 0) + if (_commandHandler->getComId(p) >= 0) ++cnt[section]; else error("Bad line %d [%s]", sprf.getLineCount(), tmpStr); @@ -818,7 +818,7 @@ Sprite *CGE2Engine::spriteAt(int x, int y) { if (tail) { for (spr = tail->_prev; spr; spr = spr->_prev) { if (!spr->_flags._hide && !spr->_flags._tran) { - if (spr->shp()->solidAt(x - spr->_pos2D.x, y - spr->_pos2D.y)) + if (spr->getShp()->solidAt(x - spr->_pos2D.x, y - spr->_pos2D.y)) break; } } diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 151b3da475..a6c1849d60 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -120,7 +120,7 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo case kIdNear: case kIdMTake: case kIdFTake: - id = (ID)_vm->_commandHandler->com(p); + id = (ID)_vm->_commandHandler->getComId(p); if (_actionCtrl[section]._cnt) { CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; c->_commandType = CommandType(id); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index f00b02c7bd..e355c44348 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -569,7 +569,7 @@ void CommandHandler::clear() { _timerExpiry = 0; } -int CommandHandler::com(const char *com) { +int CommandHandler::getComId(const char *com) { int i = _vm->takeEnum(_commandText, com); return (i < 0) ? i : i + kCmdCom0 + 1; } diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index afd52dfd45..6b0bdea546 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -136,7 +136,7 @@ public: bool idle(); void reset(); void clear(); - int com(const char *com); + int getComId(const char *com); private: CGE2Engine *_vm; bool _turbo; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index ff58ccd25d..bc2e07c0eb 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -111,7 +111,7 @@ Sprite::~Sprite() { contract(); } -BitmapPtr Sprite::shp() { +BitmapPtr Sprite::getShp() { SprExt *e = _ext; if (!e || !e->_seq) return NULL; @@ -282,7 +282,7 @@ Sprite *Sprite::expand() { case kIdNear: case kIdMTake: case kIdFTake: - id = (ID)_vm->_commandHandler->com(p); + id = (ID)_vm->_commandHandler->getComId(p); if (_actionCtrl[section]._cnt) { CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; c->_commandType = CommandType(id); @@ -327,7 +327,7 @@ Sprite *Sprite::expand() { error("Unexpected end of file! %s", fname); s->_dly = _vm->number(p); break; - case kIdPhase: + case kIdPhase: { BitmapPtr bmp = new Bitmap(_vm, p); shplist[shpcnt] = bmp; if (!shplist[shpcnt]->moveHi()) @@ -335,6 +335,9 @@ Sprite *Sprite::expand() { shpcnt++; break; } + default: + break; + } break; } label = kNoByte; @@ -382,10 +385,10 @@ Sprite *Sprite::contract() { return this; if (_file[2] == '~') { // FLY-type sprite - Seq *seq = _ext->_seq; + Seq *curSeq = _ext->_seq; // return to middle - gotoxyz(_pos3D - V3D(seq->_dx, seq->_dy, seq->_dz)); - seq->_dx = seq->_dy = seq->_dz = 0; + gotoxyz(_pos3D - V3D(curSeq->_dx, curSeq->_dy, curSeq->_dz)); + curSeq->_dx = curSeq->_dy = curSeq->_dz = 0; } if (notify) @@ -564,7 +567,7 @@ void Sprite::show() { e->_p0 = e->_p1; e->_b0 = e->_b1; e->_p1 = _pos2D; - e->_b1 = shp(); + e->_b1 = getShp(); } if (!_flags._hide) e->_b1->show(e->_p1.x, e->_p1.y); @@ -573,7 +576,7 @@ void Sprite::show() { void Sprite::show(uint16 pg) { Graphics::Surface *a = _vm->_vga->_page[1]; _vm->_vga->_page[1] = _vm->_vga->_page[pg]; - shp()->show(_pos2D.x, _pos2D.y); + getShp()->show(_pos2D.x, _pos2D.y); _vm->_vga->_page[1] = a; } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index a4829b6947..574a60711d 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -73,8 +73,8 @@ class V2D : public Common::Point { public: V2D& operator=(const V3D &p3) { double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); - x = round((_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m)); - y = round((_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m)); + x = round(_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m); + y = round(_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m); return *this; } V2D(CGE2Engine *vm) : _vm(vm) { } @@ -170,7 +170,7 @@ public: Sprite(CGE2Engine *vm); Sprite(CGE2Engine *vm, BitmapPtr *shp, int cnt); virtual ~Sprite(); - BitmapPtr shp(); + BitmapPtr getShp(); void setShapeList(BitmapPtr *shp, int cnt); void moveShapesHi(void); void moveShapesLo(void); -- cgit v1.2.3 From 11ebdcb5e0f25a6030a3ee3419d823aef6622980 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 20:18:48 +0200 Subject: CGE2: nullify some pointers --- engines/cge2/bitmap.cpp | 5 ++++- engines/cge2/cge2_main.cpp | 2 ++ engines/cge2/hero.cpp | 1 + engines/cge2/snail.cpp | 1 + engines/cge2/sound.cpp | 4 ++-- engines/cge2/spare.cpp | 1 + engines/cge2/text.cpp | 2 +- engines/cge2/vga13h.cpp | 26 ++++++++++++++++++-------- 8 files changed, 30 insertions(+), 12 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index dfc5bcadd2..39883601a1 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -124,6 +124,8 @@ Bitmap::~Bitmap() { void Bitmap::release() { free(_m); delete[] _v; + _m = nullptr; + _v = nullptr; } Bitmap &Bitmap::operator=(const Bitmap &bmp) { @@ -137,6 +139,7 @@ Bitmap &Bitmap::operator=(const Bitmap &bmp) { _map = 0; _vm = bmp._vm; delete[] _v; + _v = nullptr; if (v0 == NULL) { _v = NULL; @@ -169,7 +172,7 @@ BitmapPtr Bitmap::code() { if (_v) { // old X-map exists, so remove it delete[] _v; - _v = NULL; + _v = nullptr; } while (true) { // at most 2 times: for (V == NULL) & for allocated block; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 4fb0b2981e..696b840eb8 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -579,6 +579,7 @@ void CGE2Engine::loadGame() { h = new Hero(this); *(Sprite*)h = *s; delete s; + s = nullptr; h->expand(); _spare->update(h); } @@ -593,6 +594,7 @@ void CGE2Engine::loadGame() { h = new Hero(this); *(Sprite*)h = *s; delete s; + s = nullptr; h->expand(); _spare->update(h); } diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index a6c1849d60..030020ebb9 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -194,6 +194,7 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo bmp[i] = &_dim[0][i]; setShapeList(bmp, shpcnt); delete[] bmp; + bmp = nullptr; } } _reachStart = atoi(_vm->token(text)); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index e355c44348..8de2e130c8 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -527,6 +527,7 @@ void CGE2Engine::snGhost(Bitmap *bmp) { bmp->_v = nullptr; bmp->_b = nullptr; delete bmp; + bmp = nullptr; } void CGE2Engine::hide1(Sprite *spr) { diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index 9f5ec2bb6c..b497ebf27b 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -121,7 +121,7 @@ Fx::~Fx() { void Fx::clear() { if (_current) delete _current; - _current = NULL; + _current = nullptr; } Common::String Fx::name(int ref, int sub) { @@ -186,7 +186,7 @@ void MusicPlayer::killMidi() { Audio::MidiPlayer::stop(); free(_data); - _data = NULL; + _data = nullptr; } void MusicPlayer::loadMidi(int ref) { diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 043122199c..445247177d 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -90,6 +90,7 @@ void Spare::dispose(Sprite *spr) { if (spr == _container[i]) { _container.remove_at(i); delete spr; + spr = nullptr; break; } } diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 2f8e9b4011..554d6ba88c 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -85,7 +85,7 @@ void Text::clear() { if (p->_ref) { p->_ref = 0; delete[] p->_text; - p->_text = NULL; + p->_text = nullptr; } } } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index bc2e07c0eb..ded90aeaef 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -170,7 +170,7 @@ void Sprite::setName(char *newName) { if (_ext->_name) { delete[] _ext->_name; - _ext->_name = NULL; + _ext->_name = nullptr; } if (newName) { _ext->_name = new char[strlen(newName) + 1]; @@ -394,25 +394,33 @@ Sprite *Sprite::contract() { if (notify) notify(); - if (e->_name) + if (e->_name) { delete[] e->_name; + e->_name = nullptr; + } if (e->_shpList) { for (int i = 0; i < _shpCnt; i++) e->_shpList[i]->release(); delete[] e->_shpList; + e->_shpList = nullptr; } if (e->_seq) { if (e->_seq == _stdSeq8) _seqCnt = 0; - else + else { delete[] e->_seq; + e->_seq = nullptr; + } } - for (int i = 0; i < kActions; i++) - if (e->_actions[i]) + for (int i = 0; i < kActions; i++) { + if (e->_actions[i]) { delete[] e->_actions[i]; + e->_actions[i]; + } + } _ext = nullptr; @@ -479,9 +487,9 @@ void Sprite::killXlat() { uint8 *m = (*_ext->_shpList)->_m; free(m); - + for (BitmapPtr *b = _ext->_shpList; *b; b++) - (*b)->_m = NULL; + (*b)->_m = nullptr; _flags._xlat = false; } @@ -677,8 +685,10 @@ Queue::~Queue() { void Queue::clear() { while (_head) { Sprite *s = remove(_head); - if (s->_flags._kill) + if (s->_flags._kill) { delete s; + s = nullptr; + } } } -- cgit v1.2.3 From 160edae77aa07f520c5331876d91a713eab5cee8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 22:12:59 +0200 Subject: CGE2: Silence some gcc and cppcheck warnings --- engines/cge2/bitmap.cpp | 20 ++++++++++---------- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/snail.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 39883601a1..e7ca459009 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -35,14 +35,14 @@ namespace CGE2 { -Bitmap::Bitmap() : _w(0), _h(0), _v(NULL), _b(NULL) { +Bitmap::Bitmap() : _w(0), _h(0), _v(nullptr), _b(nullptr), _m(nullptr), _map(0), _vm(nullptr) { } void Bitmap::setVM(CGE2Engine *vm) { _vm = vm; } -Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(NULL), _v(NULL), _b(NULL), _map(0), _vm(vm) { +Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(nullptr), _v(nullptr), _b(nullptr), _map(0), _vm(vm) { char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); @@ -57,7 +57,7 @@ Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(NULL), _v(NULL), _b(NULL) } } -Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0), _b(NULL), _vm(vm) { +Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(nullptr), _map(0), _b(nullptr), _vm(vm) { if (map) code(); } @@ -67,7 +67,7 @@ Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _ // especially for text line real time display Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill) : _w((w + 3) & ~3), // only full uint32 allowed! - _h(h), _m(NULL), _map(0), _b(NULL), _vm(vm) { + _h(h), _m(nullptr), _map(0), _b(nullptr), _vm(vm) { uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap @@ -104,7 +104,7 @@ Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill) _b = b; } -Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0), _b(NULL), _vm(vm) { +Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(nullptr), _v(nullptr), _map(0), _b(nullptr), _vm(vm) { uint8 *v0 = bmp._v; if (!v0) return; @@ -112,7 +112,7 @@ Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(N uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = new uint8[siz]; - assert(v1 != NULL); + assert(v1 != nullptr); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); } @@ -135,19 +135,19 @@ Bitmap &Bitmap::operator=(const Bitmap &bmp) { uint8 *v0 = bmp._v; _w = bmp._w; _h = bmp._h; - _m = NULL; + _m = nullptr; _map = 0; _vm = bmp._vm; delete[] _v; _v = nullptr; - if (v0 == NULL) { - _v = NULL; + if (v0 == nullptr) { + _v = nullptr; } else { uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = new uint8[siz]; - assert(v1 != NULL); + assert(v1 != nullptr); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); } diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 696b840eb8..9d47397721 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -571,7 +571,7 @@ void CGE2Engine::loadGame() { // load sprites & pocket Sprite *s; - Hero *h; + Hero *h = nullptr; // initialize Andzia/Anna s = _spare->take(142); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 8de2e130c8..7961e6d054 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -523,7 +523,7 @@ void CGE2Engine::snRoom(Sprite *spr, int val) { void CGE2Engine::snGhost(Bitmap *bmp) { V2D p(this, *bmp->_v & 0xFFFF, *bmp->_v >> 16); bmp->hide(p.x, p.y); - delete bmp->_b; + delete[] bmp->_b; bmp->_v = nullptr; bmp->_b = nullptr; delete bmp; -- cgit v1.2.3 From aabe883dc2b82c2ab4cca062c1192b74dd8b321f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 22:34:39 +0200 Subject: CGE2: Fix some more GCC warnings --- engines/cge2/cge2_main.cpp | 2 ++ engines/cge2/vga13h.cpp | 32 ++++++++++++++++---------------- engines/cge2/vga13h.h | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9d47397721..9ab9eb0c0b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -194,6 +194,8 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { badLab(fname); ++seqcnt; break; + default: + break; } break; } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index ded90aeaef..644c75395d 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -40,8 +40,8 @@ namespace CGE2 { Seq *getConstantSeq(bool seqFlag) { - const Seq seq1[] = { { 0, 0, 0, 0, 0 } }; - const Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; + const Seq seq1[] = { { 0, 0, 0, 0, 0, 0 } }; + const Seq seq2[] = { { 0, 1, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0, 0 } }; Seq *seq; if (seqFlag) { @@ -215,13 +215,13 @@ Sprite *Sprite::expand() { char fname[kPathMax]; _vm->mergeExt(fname, _file, kSprExt); - Seq *seq; + Seq *curSeq; if (_seqCnt) { - seq = new Seq[_seqCnt]; - if (seq == NULL) + curSeq = new Seq[_seqCnt]; + if (curSeq == nullptr) error("No core %s", fname); } else - seq = nullptr; + curSeq = nullptr; for (int i = 0; i < kActions; i++) cnt[i] = 0; @@ -297,7 +297,7 @@ Sprite *Sprite::expand() { } break; case kIdSeq: - s = &seq[seqcnt++]; + s = &curSeq[seqcnt++]; s->_now = atoi(p); if (s->_now > maxnow) maxnow = s->_now; @@ -348,12 +348,12 @@ Sprite *Sprite::expand() { } else // no sprite description: try to read immediately from .BMP shplist[shpcnt++] = new Bitmap (_vm, _file); - if (seq) { + if (curSeq) { if (maxnow >= shpcnt) error("Bad PHASE in SEQ %s", fname); if (maxnxt && maxnxt >= seqcnt) error("Bad JUMP in SEQ %s", fname); - setSeq(seq); + setSeq(curSeq); } else { setSeq(_stdSeq8); _seqCnt = (shpcnt < ARRAYSIZE(_stdSeq8)) ? shpcnt : ARRAYSIZE(_stdSeq8); @@ -367,13 +367,13 @@ Sprite *Sprite::expand() { setShapeList(shapeList, shpcnt); if (_file[2] == '~') { // FLY-type sprite - Seq *seq = _ext->_seq; - int x = (seq + 1)->_dx, y = (seq + 1)->_dy, z = (seq + 1)->_dz; + Seq *curSeq = _ext->_seq; + int x = (curSeq + 1)->_dx, y = (curSeq + 1)->_dy, z = (curSeq + 1)->_dz; // random position - seq->_dx = _vm->newRandom(x + x) - x; - seq->_dy = _vm->newRandom(y + y) - y; - seq->_dz = _vm->newRandom(z + z) - z; - gotoxyz(_pos3D + V3D(seq->_dx, seq->_dy, seq->_dz)); + curSeq->_dx = _vm->newRandom(x + x) - x; + curSeq->_dy = _vm->newRandom(y + y) - y; + curSeq->_dz = _vm->newRandom(z + z) - z; + gotoxyz(_pos3D + V3D(curSeq->_dx, curSeq->_dy, curSeq->_dz)); } return this; @@ -418,7 +418,7 @@ Sprite *Sprite::contract() { for (int i = 0; i < kActions; i++) { if (e->_actions[i]) { delete[] e->_actions[i]; - e->_actions[i]; + e->_actions[i] = nullptr; } } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 574a60711d..391c56c9c1 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -79,7 +79,7 @@ public: } V2D(CGE2Engine *vm) : _vm(vm) { } V2D(CGE2Engine *vm, const V3D &p3) : _vm(vm) { *this = p3; } - V2D(CGE2Engine *vm, int x, int y) : _vm(vm), Common::Point(x, y) { } + V2D(CGE2Engine *vm, int posx, int posy) : _vm(vm), Common::Point(posx, posy) { } bool operator<(const V2D &p) const { return (x < p.x) && (y < p.y); } bool operator<=(const V2D &p) const { return (x <= p.x) && (y <= p.y); } bool operator>(const V2D &p) const { return (x > p.x) && (y > p.y); } -- cgit v1.2.3 From 516ad6e84377e14c4cbba9f25b99a523c1b0d276 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 22:41:19 +0200 Subject: CGE2: Reduce the scope of some variables --- engines/cge2/hero.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 030020ebb9..30fd252a7e 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -49,10 +49,6 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo if (*_file) { int cnt[kActions]; - int shpcnt = 0; - int seqcnt = 0; - int maxnow = 0; - int maxnxt = 0; Seq *seq; int section = kIdPhase; @@ -90,6 +86,10 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo ID id; Common::String line; char tmpStr[kLineMax + 1]; + int shpcnt = 0; + int seqcnt = 0; + int maxnow = 0; + int maxnxt = 0; for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { if (line.size() == 0) -- cgit v1.2.3 From c5072db8fb6706768ad4a116c9cb3bd3c5f5efa3 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 3 Jun 2014 22:46:59 +0200 Subject: CGE2: Fix remaining shadowed variables --- engines/cge2/cge2_main.cpp | 12 +++++------- engines/cge2/sound.cpp | 6 +++--- engines/cge2/vga13h.cpp | 12 ++++++------ 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9ab9eb0c0b..a60b31bf34 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -818,13 +818,11 @@ void CGE2Engine::switchHero(int sex) { } Sprite *CGE2Engine::spriteAt(int x, int y) { - Sprite *spr = NULL, *tail = _vga->_showQ->last(); - if (tail) { - for (spr = tail->_prev; spr; spr = spr->_prev) { - if (!spr->_flags._hide && !spr->_flags._tran) { - if (spr->getShp()->solidAt(x - spr->_pos2D.x, y - spr->_pos2D.y)) - break; - } + Sprite *spr = NULL, *queueTail = _vga->_showQ->last(); + if (queueTail) { + for (spr = queueTail->_prev; spr; spr = spr->_prev) { + if (!spr->_flags._hide && !spr->_flags._tran && spr->getShp()->solidAt(x - spr->_pos2D.x, y - spr->_pos2D.y)) + break; } } return spr; diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index b497ebf27b..c657a37e46 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -125,9 +125,9 @@ void Fx::clear() { } Common::String Fx::name(int ref, int sub) { - char name[] = "%.2dfx%.2d.WAV\0"; - char subn[] = "%.2dfx%.2d?.WAV\0"; - char *p = (sub) ? subn : name; + char fxname[] = "%.2dfx%.2d.WAV\0"; + char subName[] = "%.2dfx%.2d?.WAV\0"; + char *p = (sub) ? subName : fxname; Common::String filename = Common::String::format(p, ref >> 8, ref & 0xFF); if (sub) filename.setChar('@' + sub, 6); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 644c75395d..334aa99716 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -367,13 +367,13 @@ Sprite *Sprite::expand() { setShapeList(shapeList, shpcnt); if (_file[2] == '~') { // FLY-type sprite - Seq *curSeq = _ext->_seq; - int x = (curSeq + 1)->_dx, y = (curSeq + 1)->_dy, z = (curSeq + 1)->_dz; + Seq *nextSeq = _ext->_seq; + int x = (nextSeq + 1)->_dx, y = (nextSeq + 1)->_dy, z = (nextSeq + 1)->_dz; // random position - curSeq->_dx = _vm->newRandom(x + x) - x; - curSeq->_dy = _vm->newRandom(y + y) - y; - curSeq->_dz = _vm->newRandom(z + z) - z; - gotoxyz(_pos3D + V3D(curSeq->_dx, curSeq->_dy, curSeq->_dz)); + nextSeq->_dx = _vm->newRandom(x + x) - x; + nextSeq->_dy = _vm->newRandom(y + y) - y; + nextSeq->_dz = _vm->newRandom(z + z) - z; + gotoxyz(_pos3D + V3D(nextSeq->_dx, nextSeq->_dy, nextSeq->_dz)); } return this; -- cgit v1.2.3 From b6d8e2b24716f9d1c8e91be15f5cba6da7764cae Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 4 Jun 2014 01:03:51 +0200 Subject: CGE2: Unstub some code used to move sprites --- engines/cge2/vga13h.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 334aa99716..d7f8fb23fe 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -455,9 +455,8 @@ void Sprite::step(int nr) { p._x += seq->_dx; p._y += seq->_dy; p._z += seq->_dz; - //if (!_flags._kept) - // gotoxyz(p); - warning("STUB: Sprite::step()"); + if (!_flags._kept) + gotoxyz(p); } } if (seq && (seq->_dly >= 0)) -- cgit v1.2.3 From 8d00ce68d5361d854b04d2b84af0b786c06823af Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 4 Jun 2014 01:08:25 +0200 Subject: CGE2: Remove 2 useless stubs --- engines/cge2/bitmap.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index e7ca459009..f42e2b2057 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -385,13 +385,13 @@ void Bitmap::xLatPos(V2D& p) { p.y = kWorldHeight - p.y - _h; } -bool Bitmap::moveHi(void) { - warning("STUB: Bitmap::moveHi()"); +bool Bitmap::moveHi() { + // No implementation needed in ScummVM return true; } -bool Bitmap::moveLo(void) { - warning("STUB: Bitmap::moveLo()"); +bool Bitmap::moveLo() { + // No implementation needed in ScummVM return true; } -- cgit v1.2.3 From a0aa7df19c7ce3ce4912286dc646a6ea1495d07d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 4 Jun 2014 07:10:27 +0200 Subject: CGE2: Remove useless 'void' --- engines/cge2/bitmap.h | 4 ++-- engines/cge2/vga13h.cpp | 6 +++--- engines/cge2/vga13h.h | 21 ++++++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 102fb1c8ca..88ab3d8bd8 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -82,8 +82,8 @@ public: void xShow(int16 x, int16 y); bool solidAt(int16 x, int16 y); void xLatPos(V2D& p); - bool moveHi(void); - bool moveLo(void); + bool moveHi(); + bool moveLo(); }; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index d7f8fb23fe..fee570a237 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -56,7 +56,7 @@ Seq *getConstantSeq(bool seqFlag) { return seq; } -void(*Sprite::notify) (void) = nullptr; +void (*Sprite::notify)() = nullptr; byte Sprite::_constY = 0; byte Sprite::_follow = 0; @@ -427,7 +427,7 @@ Sprite *Sprite::contract() { return this; } -void Sprite::backShow(void) { +void Sprite::backShow() { expand(); show(2); show(1); @@ -496,7 +496,7 @@ void Sprite::gotoxyz(int x, int y, int z) { gotoxyz(V3D(x, y, z)); } -void Sprite::gotoxyz(void) { +void Sprite::gotoxyz() { gotoxyz(_pos3D); } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 391c56c9c1..583cf73a7d 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -55,7 +55,7 @@ namespace CGE2 { class V3D { public: double _x, _y, _z; - V3D(void) { } + V3D() { } V3D(double x, double y, double z = 0) : _x(x), _y(y), _z(z) { } V3D(const V3D &p) : _x(p._x), _y(p._y), _z(p._z) { } V3D operator+(const V3D &p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); } @@ -72,6 +72,8 @@ class V2D : public Common::Point { CGE2Engine *_vm; public: V2D& operator=(const V3D &p3) { + if (p3._z == 200) + warning(""); double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); x = round(_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m); y = round(_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m); @@ -86,16 +88,17 @@ public: bool operator>=(const V2D &p) const { return (x >= p.x) && (y >= p.y); } V2D operator+(const V2D &p) const { return V2D(_vm, x + p.x, y + p.y); } V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); } - uint16 area(void) { return x * y; } + uint16 area() { return x * y; } bool limited(const V2D &p) { return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); } V2D scale(int z) { double m = _vm->_eye->_z / (_vm->_eye->_z - z); + warning("scale: %f %f %f, x, y, m"); return V2D(_vm, trunc(m * x), trunc(m * y)); } static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } - static double round(double number) { return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5); } + static double round(double number) { return number < 0.0 ? ceil(number) : floor(number); } }; struct Seq { @@ -172,18 +175,18 @@ public: virtual ~Sprite(); BitmapPtr getShp(); void setShapeList(BitmapPtr *shp, int cnt); - void moveShapesHi(void); - void moveShapesLo(void); + void moveShapesHi(); + void moveShapesLo(); int labVal(Action snq, int lab); Sprite *expand(); Sprite *contract(); - void backShow(void); + void backShow(); void setName(char *newName); inline char *name() { return (_ext) ? _ext->_name : NULL; } void gotoxyz(int x, int y, int z = 0); - void gotoxyz(void); + void gotoxyz(); void gotoxyz(V2D pos); void gotoxyz_(V2D pos); void gotoxyz(V3D pos); @@ -200,10 +203,10 @@ public: CommandHandler::Command *snList(Action type); virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); virtual void tick(); - void clrHide(void) { if (_ext) _ext->_b0 = NULL; } + void clrHide() { if (_ext) _ext->_b0 = NULL; } void sync(Common::Serializer &s); - static void (*notify) (void); + static void (*notify) (); }; class Queue { -- cgit v1.2.3 From 58ee44ceb263b33f40b9eef89254cb8db2f00410 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 4 Jun 2014 22:50:32 +0200 Subject: CGE2: Remove unnecessary check from Sprite::step(). --- engines/cge2/vga13h.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index fee570a237..26e6604f00 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -455,8 +455,7 @@ void Sprite::step(int nr) { p._x += seq->_dx; p._y += seq->_dy; p._z += seq->_dz; - if (!_flags._kept) - gotoxyz(p); + gotoxyz(p); } } if (seq && (seq->_dly >= 0)) -- cgit v1.2.3 From 26b7ecd2eee36cc1ef05689be60cd5b3c6843245 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 4 Jun 2014 22:57:02 +0200 Subject: CGE2: Get rid of _spareQ. CGE2 uses an instance of Spare instead of it. --- engines/cge2/cge2_main.cpp | 1 - engines/cge2/vga13h.cpp | 2 -- engines/cge2/vga13h.h | 1 - 3 files changed, 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a60b31bf34..ee53e53bcc 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -556,7 +556,6 @@ void CGE2Engine::runGame() { _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); _mouse->off(); _vga->_showQ->clear(); - _vga->_spareQ->clear(); } void CGE2Engine::loadUser() { diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 26e6604f00..9fb2a47aca 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -777,7 +777,6 @@ Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _oldColors = NULL; _newColors = NULL; _showQ = new Queue(true); - _spareQ = new Queue(false); _sysPal = new Dac[kPalCount]; for (int idx = 0; idx < 4; idx++) { @@ -821,7 +820,6 @@ Vga::~Vga() { debugN("%s", buffer.c_str()); delete _showQ; - delete _spareQ; delete[] _sysPal; for (int idx = 0; idx < 4; idx++) { diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 583cf73a7d..0c45ab8489 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -247,7 +247,6 @@ class Vga { public: uint32 _frmCnt; Queue *_showQ; - Queue *_spareQ; int _mono; Graphics::Surface *_page[4]; Dac *_sysPal; -- cgit v1.2.3 From 7838852f9401772307e93cb79da98855ebb143b2 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 5 Jun 2014 00:11:35 +0200 Subject: CGE2: Stub buggy part of loadTab(). --- engines/cge2/cge2_main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index ee53e53bcc..e1a2b0b4fe 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -646,6 +646,7 @@ void CGE2Engine::loadTab() { for (int i = 0; i < kCaveMax; i++) *(_eyeTab[i]) = *_eye; + /* if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); for (int i = 0; i < kCaveMax; i++) { @@ -672,8 +673,8 @@ void CGE2Engine::loadTab() { } } } - - warning("STUB: CGE2Engine::loadTab() - Recheck this"); + */ + warning("STUB: CGE2Engine::loadTab()"); } void CGE2Engine::cge2_main() { -- cgit v1.2.3 From 85d9e9238c4f34ef983e1e91230e937c0dccd017 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 5 Jun 2014 00:45:33 +0200 Subject: CGE2: Remove _m and xShow() from Bitmap, makeXlat() and killXlat() from Sprite. They are not used in CGE2 at all (or used differently). --- engines/cge2/bitmap.cpp | 21 ++++++-------- engines/cge2/bitmap.h | 4 +-- engines/cge2/vga13h.cpp | 76 ------------------------------------------------- engines/cge2/vga13h.h | 2 -- 4 files changed, 10 insertions(+), 93 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index f42e2b2057..47714284d3 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -35,14 +35,14 @@ namespace CGE2 { -Bitmap::Bitmap() : _w(0), _h(0), _v(nullptr), _b(nullptr), _m(nullptr), _map(0), _vm(nullptr) { +Bitmap::Bitmap() : _w(0), _h(0), _v(nullptr), _b(nullptr), _map(0), _vm(nullptr) { } void Bitmap::setVM(CGE2Engine *vm) { _vm = vm; } -Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(nullptr), _v(nullptr), _b(nullptr), _map(0), _vm(vm) { +Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _v(nullptr), _b(nullptr), _map(0), _vm(vm) { char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); @@ -57,9 +57,9 @@ Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(nullptr), _v(nullptr), _b } } -Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(nullptr), _map(0), _b(nullptr), _vm(vm) { +Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _v(nullptr), _map(0), _b(nullptr), _vm(vm) { if (map) - code(); + code(map); } // following routine creates filled rectangle @@ -67,7 +67,7 @@ Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _ // especially for text line real time display Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill) : _w((w + 3) & ~3), // only full uint32 allowed! - _h(h), _m(nullptr), _map(0), _b(nullptr), _vm(vm) { + _h(h), _map(0), _b(nullptr), _vm(vm) { uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap @@ -104,7 +104,7 @@ Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill) _b = b; } -Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(nullptr), _v(nullptr), _map(0), _b(nullptr), _vm(vm) { +Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _v(nullptr), _map(0), _b(nullptr), _vm(vm) { uint8 *v0 = bmp._v; if (!v0) return; @@ -122,9 +122,7 @@ Bitmap::~Bitmap() { } void Bitmap::release() { - free(_m); delete[] _v; - _m = nullptr; _v = nullptr; } @@ -135,7 +133,6 @@ Bitmap &Bitmap::operator=(const Bitmap &bmp) { uint8 *v0 = bmp._v; _w = bmp._w; _h = bmp._h; - _m = nullptr; _map = 0; _vm = bmp._vm; delete[] _v; @@ -164,8 +161,8 @@ char *Bitmap::forceExt(char *buf, const char *name, const char *ext) { return buf; } -BitmapPtr Bitmap::code() { - if (!_m) +BitmapPtr Bitmap::code(uint8 *map) { + if (!map) return NULL; uint16 cnt; @@ -187,7 +184,7 @@ BitmapPtr Bitmap::code() { } } for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane - uint8 *bm = _m; + uint8 *bm = map; bool skip = (bm[bpl] == kPixelTransp); uint16 j; diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 88ab3d8bd8..bcc51d874f 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -61,7 +61,6 @@ class Bitmap { public: uint16 _w; uint16 _h; - uint8 *_m; uint8 *_v; int32 _map; HideDesc *_b; @@ -74,12 +73,11 @@ public: ~Bitmap(); void setVM(CGE2Engine *vm); - Bitmap *code(); + Bitmap *code(uint8 *map); Bitmap &operator=(const Bitmap &bmp); void release(); void hide(int16 x, int16 y); void show(int16 x, int16 y); - void xShow(int16 x, int16 y); bool solidAt(int16 x, int16 y); void xLatPos(V2D& p); bool moveHi(); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 9fb2a47aca..c7979f1668 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -468,29 +468,6 @@ void Sprite::tick() { step(); } -void Sprite::makeXlat(uint8 *x) { - if (!_ext) - return; - - if (_flags._xlat) - killXlat(); - for (BitmapPtr *b = _ext->_shpList; *b; b++) - (*b)->_m = x; - _flags._xlat = true; -} - -void Sprite::killXlat() { - if (!_flags._xlat || !_ext) - return; - - uint8 *m = (*_ext->_shpList)->_m; - free(m); - - for (BitmapPtr *b = _ext->_shpList; *b; b++) - (*b)->_m = nullptr; - _flags._xlat = false; -} - void Sprite::gotoxyz(int x, int y, int z) { gotoxyz(V3D(x, y, z)); } @@ -1020,59 +997,6 @@ void Vga::copyPage(uint16 d, uint16 s) { _page[d]->copyFrom(*_page[s]); } -//-------------------------------------------------------------------------- - -void Bitmap::xShow(int16 x, int16 y) { - const byte *srcP = (const byte *)_v; - byte *destEndP = (byte *)_vm->_vga->_page[1]->getBasePtr(0, kScrHeight); - byte *lookupTable = _m; - - // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a - // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data - // must be decompressed and inserted into the surface - for (int planeCtr = 0; planeCtr < 4; planeCtr++) { - byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x + planeCtr, y); - - for (;;) { - uint16 v = READ_LE_UINT16(srcP); - srcP += 2; - int cmd = v >> 14; - int count = v & 0x3FFF; - - if (cmd == 0) { - // End of image - break; - } - - assert(destP < destEndP); - - if (cmd == 2) - srcP++; - else if (cmd == 3) - srcP += count; - - // Handle a set of pixels - while (count-- > 0) { - // Transfer operation - switch (cmd) { - case 1: - // SKIP - break; - case 2: - case 3: - // TINT - *destP = lookupTable[*destP]; - break; - } - - // Move to next dest position - destP += 4; - } - } - } -} - - void Bitmap::show(int16 x, int16 y) { V2D pos(_vm, x, y); xLatPos(pos); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 0c45ab8489..9144595053 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -196,8 +196,6 @@ public: void show(); void hide(); BitmapPtr ghost(); - void makeXlat(uint8 *x); - void killXlat(); void step(int nr = -1); Seq *setSeq(Seq *seq); CommandHandler::Command *snList(Action type); -- cgit v1.2.3 From c6fd9bf8ce06a9512ec6e8ff6d844718576d26a0 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 6 Jun 2014 12:00:22 +0200 Subject: CGE2: Remove stub from Vga::update(). It was for displaying debug lines. May be placed back again later during some debugging. --- engines/cge2/vga13h.cpp | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index c7979f1668..01d0bf325b 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -970,19 +970,6 @@ void Vga::update() { updateColors(); _setPal = false; } - /*if (_vm->_showBoundariesFl) { - Vga::_page[0]->hLine(0, 200 - kPanHeight, 320, 0xee); - if (_vm->_barriers[_vm->_now]._horz != 255) { - for (int i = 0; i < 8; i++) - Vga::_page[0]->vLine((_vm->_barriers[_vm->_now]._horz * 8) + i, 0, 200, 0xff); - } - if (_vm->_barriers[_vm->_now]._vert != 255) { - for (int i = 0; i < 4; i++) - Vga::_page[0]->hLine(0, 80 + (_vm->_barriers[_vm->_now]._vert * 4) + i, 320, 0xff); - } - }*/ - - warning("STUB: Vga::update()"); g_system->copyRectToScreen(Vga::_page[0]->getPixels(), kScrWidth, 0, 0, kScrWidth, kScrHeight); g_system->updateScreen(); -- cgit v1.2.3 From f2c006976541e00411b4f9154efe9ab16c633472 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 6 Jun 2014 14:57:34 +0200 Subject: CGE2: Change BitmapPtr *_shpList -> BitmapPtr _shpList. Update rest of the code accordingly. --- engines/cge2/bitmap.cpp | 3 +- engines/cge2/cge2_main.cpp | 10 +++---- engines/cge2/events.cpp | 7 ++--- engines/cge2/hero.cpp | 9 ++---- engines/cge2/vga13h.cpp | 70 ++++++++++------------------------------------ engines/cge2/vga13h.h | 6 ++-- 6 files changed, 29 insertions(+), 76 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 47714284d3..ff7c3e1998 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -122,7 +122,8 @@ Bitmap::~Bitmap() { } void Bitmap::release() { - delete[] _v; + if (_v != nullptr) + delete[] _v; _v = nullptr; } diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e1a2b0b4fe..99447efad2 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -737,13 +737,13 @@ bool CGE2Engine::showTitle(const char *name) { return false; _bitmapPalette = _vga->_sysPal; - BitmapPtr *LB = new BitmapPtr[2]; - LB[0] = new Bitmap(this, name); - LB[1] = NULL; - _bitmapPalette = NULL; + BitmapPtr LB = new Bitmap[1]; + LB[0] = Bitmap(this, name); + _bitmapPalette = nullptr; Sprite D(this, LB, 1); D._flags._kill = true; + strcpy(D._file, "hatter"); warning("STUB: Sprite::showTitle() - Flags changed compared to CGE1's Sprite type."); D.gotoxyz(kScrWidth >> 1, -(kPanHeight >> 1)); _vga->sunset(); @@ -758,7 +758,7 @@ bool CGE2Engine::showTitle(const char *name) { _vga->update(); warning("STUB: CGE2Engine::showTitle()"); - + return true; } diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 5c0300f1e1..c036d5d676 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -74,10 +74,9 @@ Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _vm setSeq(_stdSeq8); - BitmapPtr *MC = new BitmapPtr[3]; - MC[0] = new Bitmap(_vm, "MOUSE"); - MC[1] = new Bitmap(_vm, "DUMMY"); - MC[2] = NULL; + BitmapPtr MC = new Bitmap[2]; + MC[0] = Bitmap(_vm, "MOUSE"); + MC[1] = Bitmap(_vm, "DUMMY"); setShapeList(MC, 2); step(1); diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 30fd252a7e..04ff05ce93 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -189,12 +189,7 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo } else setSeq(_stdSeq8); - BitmapPtr *bmp = new BitmapPtr[shpcnt]; - for (int i = 0; i < shpcnt; i++) - bmp[i] = &_dim[0][i]; - setShapeList(bmp, shpcnt); - delete[] bmp; - bmp = nullptr; + setShapeList(_dim[0], shpcnt); } } _reachStart = atoi(_vm->token(text)); @@ -219,7 +214,7 @@ void Hero::setCurrent() { break; } - _ext->_shpList = &_dim[_curDim = i]; + _ext->_shpList = _dim[_curDim = i]; } void Hero::hStep() { diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 01d0bf325b..b8fe54d437 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -91,7 +91,7 @@ Sprite::Sprite(CGE2Engine *vm) _flags._frnt = 1; } -Sprite::Sprite(CGE2Engine *vm, BitmapPtr *shpP, int cnt) +Sprite::Sprite(CGE2Engine *vm, BitmapPtr shpP, int cnt) : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), _next(NULL), _prev(NULL), _time(0), _ext(NULL), _ref(-1), _scene(0), _vm(vm), @@ -119,17 +119,17 @@ BitmapPtr Sprite::getShp() { int i = e->_seq[_seqPtr]._now; if (i >= _shpCnt) error("Invalid PHASE in SPRITE::Shp() %s", _file); - return e->_shpList[i]; + return e->_shpList + i; } -void Sprite::setShapeList(BitmapPtr *shp, int cnt) { +void Sprite::setShapeList(BitmapPtr shp, int cnt) { _shpCnt = cnt; _siz.x = 0; _siz.y = 0; if (shp) { for (int i = 0; i < cnt; i++) { - BitmapPtr p = *(shp + i); + BitmapPtr p = shp + i; if (p->_w > _siz.x) _siz.x = p->_w; if (p->_h > _siz.y) @@ -202,9 +202,7 @@ Sprite *Sprite::expand() { if (!*_file) return this; - Common::Array shplist; - for (int i = 0; i < _shpCnt; ++i) - shplist.push_back(NULL); + BitmapPtr shplist = new Bitmap[_shpCnt]; int cnt[kActions], shpcnt = 0, @@ -328,9 +326,8 @@ Sprite *Sprite::expand() { s->_dly = _vm->number(p); break; case kIdPhase: { - BitmapPtr bmp = new Bitmap(_vm, p); - shplist[shpcnt] = bmp; - if (!shplist[shpcnt]->moveHi()) + shplist[shpcnt] = Bitmap(_vm, p); + if (!shplist[shpcnt].moveHi()) error("No EMS"); shpcnt++; break; @@ -346,7 +343,7 @@ Sprite *Sprite::expand() { if (!shpcnt) error("No shapes - %s", fname); } else // no sprite description: try to read immediately from .BMP - shplist[shpcnt++] = new Bitmap (_vm, _file); + shplist[shpcnt++] = Bitmap(_vm, _file); if (curSeq) { if (maxnow >= shpcnt) @@ -359,12 +356,7 @@ Sprite *Sprite::expand() { _seqCnt = (shpcnt < ARRAYSIZE(_stdSeq8)) ? shpcnt : ARRAYSIZE(_stdSeq8); } - // Set the shape list - BitmapPtr *shapeList = new BitmapPtr[shplist.size()]; - for (uint i = 0; i < shplist.size(); ++i) - shapeList[i] = shplist[i]; - - setShapeList(shapeList, shpcnt); + setShapeList(shplist, shpcnt); if (_file[2] == '~') { // FLY-type sprite Seq *nextSeq = _ext->_seq; @@ -401,7 +393,7 @@ Sprite *Sprite::contract() { if (e->_shpList) { for (int i = 0; i < _shpCnt; i++) - e->_shpList[i]->release(); + e->_shpList[i].release(); delete[] e->_shpList; e->_shpList = nullptr; } @@ -1055,53 +1047,19 @@ void Bitmap::hide(int16 x, int16 y) { /*--------------------------------------------------------------------------*/ HorizLine::HorizLine(CGE2Engine *vm) : Sprite(vm), _vm(vm) { - // Set the sprite list - BitmapPtr *HL = new BitmapPtr[2]; - HL[0] = new Bitmap(_vm, "HLINE"); - HL[1] = NULL; - - setShapeList(HL, 1); - - warning("HorizLine::HorizLine() - Recheck this!"); + warning("HorizLine::HorizLine()"); } SceneLight::SceneLight(CGE2Engine *vm) : Sprite(vm), _vm(vm) { - // Set the sprite list - BitmapPtr *PR = new BitmapPtr[2]; - PR[0] = new Bitmap(_vm, "PRESS"); - PR[1] = NULL; - - setShapeList(PR, 1); - - warning("SceneLight::SceneLight() - Recheck this!"); + warning("SceneLight::SceneLight()"); } Speaker::Speaker(CGE2Engine *vm): Sprite(vm), _vm(vm) { - // Set the sprite list - BitmapPtr *SP = new BitmapPtr[3]; - SP[0] = new Bitmap(_vm, "SPK_L"); - SP[1] = new Bitmap(_vm, "SPK_R"); - SP[2] = NULL; - - setShapeList(SP, 2); - - warning("Speaker::Speaker() - Recheck this!"); + warning("Speaker::Speaker()"); } PocLight::PocLight(CGE2Engine *vm): Sprite(vm), _vm(vm) { - // Set the sprite list - BitmapPtr *LI = new BitmapPtr[5]; - LI[0] = new Bitmap(_vm, "LITE0"); - LI[1] = new Bitmap(_vm, "LITE1"); - LI[2] = new Bitmap(_vm, "LITE2"); - LI[3] = new Bitmap(_vm, "LITE3"); - LI[4] = NULL; - - setShapeList(LI, 4); - - _flags._kill = false; - - warning("PocLight::PocLight() - Recheck this!"); + warning("PocLight::PocLight()"); } } // End of namespace CGE2 diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 9144595053..09eb61accf 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -116,7 +116,7 @@ public: V2D _p1; BitmapPtr _b0; BitmapPtr _b1; - BitmapPtr *_shpList; + BitmapPtr _shpList; int _location; Seq *_seq; char *_name; @@ -171,10 +171,10 @@ public: return _ext != NULL; } Sprite(CGE2Engine *vm); - Sprite(CGE2Engine *vm, BitmapPtr *shp, int cnt); + Sprite(CGE2Engine *vm, BitmapPtr shp, int cnt); virtual ~Sprite(); BitmapPtr getShp(); - void setShapeList(BitmapPtr *shp, int cnt); + void setShapeList(BitmapPtr shp, int cnt); void moveShapesHi(); void moveShapesLo(); int labVal(Action snq, int lab); -- cgit v1.2.3 From 63a153165a0c2b933dde0c4023a96526d716bdb4 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 6 Jun 2014 16:45:02 +0200 Subject: CGE2: Implement Font. --- engines/cge2/cge2.cpp | 3 +++ engines/cge2/cge2.h | 16 ++---------- engines/cge2/talk.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++------ engines/cge2/talk.h | 19 ++++++++++++-- 4 files changed, 86 insertions(+), 24 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 4bac09a1a0..c80bf502d8 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -70,6 +70,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _vol[i] = nullptr; _eventManager = nullptr; _blinkSprite = nullptr; + _font = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -115,6 +116,7 @@ void CGE2Engine::init() { _point[i] = new V3D(); _sys = new System(this); _eventManager = new EventManager(this); + _font = new Font(this); } void CGE2Engine::deinit() { @@ -146,6 +148,7 @@ void CGE2Engine::deinit() { delete _eventManager; if (_blinkSprite != nullptr) delete _blinkSprite; + delete _font; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 2c34b0a1c3..2db0d48d0f 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -56,6 +56,7 @@ class Hero; class Bitmap; class System; class EventManager; +class Font; #define kScrWidth 320 #define kScrHeight 240 @@ -79,20 +80,6 @@ enum CallbackType { enum Action { kNear, kMTake, kFTake, kActions }; -class Font { - char _path[kPathMax]; - void load(); - CGE2Engine *_vm; -public: - uint8 *_widthArr; - uint16 *_pos; - uint8 *_map; - Font(CGE2Engine *vm, const char *name); - ~Font(); - uint16 width(const char *text); - void save(); -}; - class CGE2Engine : public Engine { private: uint32 _lastFrame, _lastTick; @@ -241,6 +228,7 @@ public: Sprite *_vol[2]; EventManager *_eventManager; Sprite *_blinkSprite; + Font *_font; private: void init(); void deinit(); diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 2913327320..cff0945fcb 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -27,27 +27,83 @@ #include "cge2/general.h" #include "cge2/talk.h" -//#include "cge2/game.h" -//#include "cge2/events.h" #include "cge2/cge2_main.h" namespace CGE2 { -Font::Font(CGE2Engine *vm, const char *name) : _vm(vm) { - warning("STUB: Font::Font()"); +Font::Font(CGE2Engine *vm) : _vm(vm) { + _map = new uint8[kMapSize]; + _pos = new uint16[kPosSize]; + _widthArr = new uint8[kWidSize]; + + assert((_map != NULL) && (_pos != NULL) && (_widthArr != NULL)); + load(); } Font::~Font() { - warning("STUB: Font::~Font()"); + delete[] _map; + delete[] _pos; + delete[] _widthArr; } void Font::load() { - warning("STUB: Font::load()"); + char *path = "CGE.CFT"; + if (!_vm->_resman->exist(path)) + error("Missing configuration file! %s", path); + + EncryptedStream fontFile(_vm, path); + assert(!fontFile.err()); + + fontFile.read(_widthArr, kWidSize); + assert(!fontFile.err()); + + uint16 p = 0; + for (uint16 i = 0; i < kPosSize; i++) { + _pos[i] = p; + p += _widthArr[i]; + } + fontFile.read(_map, p); + + path = "CGE.TXC"; + if (!_vm->_resman->exist(path)) + error("Missing configuration file! %s", path); + + // Reading in _colorSet: + EncryptedStream colorFile(_vm, path); + assert(!colorFile.err()); + + char tmpStr[kLineMax + 1]; + Common::String line; + int n = 0; + + for (line = colorFile.readLine(); !colorFile.eos(); line = colorFile.readLine()){ + if (line.size() == 0) + continue; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *p; + + if ((p = _vm->token(tmpStr)) == NULL) + error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); + _colorSet[n][0] = _vm->number(p); + + for (int i = 1; i < 4; i++) { + if ((p = _vm->token(nullptr)) == NULL) + error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); + _colorSet[n][i] = _vm->number(p); + } + + n++; + } } uint16 Font::width(const char *text) { - warning("STUB: Font::width()"); - return 0; + uint16 w = 0; + if (!text) + return 0; + while (*text) + w += _widthArr[(unsigned char)*(text++)]; + return w; } Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace) diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index 2d4c235d9d..a9e5d63f9b 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -33,8 +33,6 @@ namespace CGE2 { -#define kTextColFG kVgaColDark // foreground color -#define kTextColBG kVgaColGray // background color #define kTextHMargin (6&~1) // EVEN horizontal margins! #define kTextVMargin 5 // vertical margins #define kTextLineSpace 2 // line spacing @@ -44,6 +42,23 @@ namespace CGE2 { #define kMapSize (256*8) #define kFontHigh 8 #define kFontExt ".CFT" +#define kCaptionSide 24 +#define kInfName 101 +#define kSayName 102 +#define kColorNum 6 + +class Font { + void load(); + CGE2Engine *_vm; +public: + uint8 *_widthArr; + uint16 *_pos; + uint8 *_map; + uint8 _colorSet[kColorNum][4]; + Font(CGE2Engine *vm); + ~Font(); + uint16 width(const char *text); +}; enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; -- cgit v1.2.3 From 9efb2ef1a9e57ee1bf01a0111a1bdbd387486938 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 6 Jun 2014 21:35:29 +0200 Subject: CGE2: Implement Talk. --- engines/cge2/cge2.h | 1 + engines/cge2/talk.cpp | 139 ++++++++++++++++++++++++++++++++++++++++++++++---- engines/cge2/talk.h | 14 +++-- 3 files changed, 139 insertions(+), 15 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 2db0d48d0f..ec206af1db 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -130,6 +130,7 @@ public: void switchHero(int sex); void optionTouch(int opt, uint16 mask); void offUse(); + void setAutoColors(); void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index cff0945fcb..df88f72774 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -31,6 +31,10 @@ namespace CGE2 { +void CGE2Engine::setAutoColors() { + warning("STUB: CGE2Engine::setAutoColors()"); +} + Font::Font(CGE2Engine *vm) : _vm(vm) { _map = new uint8[kMapSize]; _pos = new uint16[kPosSize]; @@ -106,23 +110,138 @@ uint16 Font::width(const char *text) { return w; } -Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace) - : Sprite(vm), _mode(mode), _wideSpace(wideSpace), _vm(vm) { - warning("STUB: Talk::Talk()"); +Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, ColorBank color, bool wideSpace) + : Sprite(vm), _mode(mode), _created(false), _wideSpace(wideSpace), _vm(vm) { + _color = _vm->_font->_colorSet[color]; + + if (color == kCBRel) + _vm->setAutoColors(); + update(text); } -Talk::Talk(CGE2Engine *vm) +Talk::Talk(CGE2Engine *vm, ColorBank color) : Sprite(vm), _mode(kTBPure), _vm(vm) { - warning("STUB: Talk::Talk()"); + _color = _vm->_font->_colorSet[color]; + + if (color == kCBRel) + _vm->setAutoColors(); } -void Talk::update(const char *text) { - warning("STUB: Talk::update()"); +uint8 *Talk::box(V2D siz) { + uint8 *b, *p, *q; + uint16 n, r = (_mode == kTBRound) ? kTextRoundCorner : 0; + const byte lt = _color[1], bg = _color[2], dk = _color[3]; + int i; + + if (siz.x < 8) siz.x = 8; + if (siz.y < 8) siz.y = 8; + b = new uint8[n = siz.area()]; + if (!b) + error("No core!"); + memset(b, bg, n); + + if (_mode) { + p = b; + q = b + n - siz.x; + memset(p, lt, siz.x); + memset(q, dk, siz.x); + while (p < q) { + p += siz.x; + *(p - 1) = dk; + *p = lt; + } + p = b; + for (i = 0; i < r; i++) { + int j; + for (j = 0; j < r - i; j++) { + p[j] = kPixelTransp; + p[siz.x - j - 1] = kPixelTransp; + q[j] = kPixelTransp; + q[siz.x - j - 1] = kPixelTransp; + } + p[j] = lt; + p[siz.x - j - 1] = dk; + q[j] = lt; + q[siz.x - j - 1] = dk; + p += siz.x; + q -= siz.x; + } + } + return b; } -Bitmap *Talk::box(uint16 w, uint16 h) { - warning("STUB: Talk::box()"); - return *_ts; +void Talk::update(const char *text) { + const uint16 vmarg = (_mode) ? kTextVMargin : 0; + const uint16 hmarg = (_mode) ? kTextHMargin : 0; + uint16 mw; + uint16 mh; + uint16 ln = vmarg; + uint8 *m; + uint8 *map; + uint8 fg = _color[0]; + + if (_created) { + mw = _ext->_shpList->_w; + mh = _ext->_shpList->_h; + delete _ext->_shpList; + } else { + uint16 k = 2 * hmarg; + mh = 2 * vmarg + kFontHigh; + mw = 0; + for (const char *p = text; *p; p++) { + if (*p == '|' || *p == '\n') { + mh += kFontHigh + kTextLineSpace; + if (k > mw) + mw = k; + k = 2 * hmarg; + } else if ((*p == 0x20) && (_vm->_font->_widthArr[(unsigned char)*p] > 4) && (!_wideSpace)) + k += _vm->_font->_widthArr[(unsigned char)*p] - 2; + else + k += _vm->_font->_widthArr[(unsigned char)*p]; + } + if (k > mw) + mw = k; + + _created = true; + } + + V2D sz(_vm, mw, mh); + map = box(sz); + + m = map + ln * mw + hmarg; + + while (*text) { + if (*text == '|' || *text == '\n') { + m = map + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; + } else { + int cw = _vm->_font->_widthArr[(unsigned char)*text]; + uint8 *f = _vm->_font->_map + _vm->_font->_pos[(unsigned char)*text]; + + // Handle properly space size, after it was enlarged to display properly + // 'F1' text. + int8 fontStart = 0; + if ((*text == 0x20) && (cw > 4) && (!_wideSpace)) + fontStart = 2; + + for (int i = fontStart; i < cw; i++) { + uint8 *pp = m; + uint16 n; + uint16 b = *(f++); + for (n = 0; n < kFontHigh; n++) { + if (b & 1) + *pp = fg; + b >>= 1; + pp += mw; + } + m++; + } + } + text++; + } + BitmapPtr b = new Bitmap[1]; + b[0] = Bitmap(_vm, sz.x, sz.y, map); + delete[] map; + setShapeList(b, 1); } InfoLine::InfoLine(CGE2Engine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) { diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index a9e5d63f9b..771478c5d1 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -62,17 +62,21 @@ public: enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; +enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; + class Talk : public Sprite { protected: TextBoxStyle _mode; - BitmapPtr *_ts; - Bitmap *box(uint16 w, uint16 h); + bool _created; + uint8 *box(V2D siz); bool _wideSpace; public: - Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace = false); - Talk(CGE2Engine *vm); + uint8 *_color; + + Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode = kTBPure, ColorBank color = kCBStd, bool wideSpace = false); + Talk(CGE2Engine *vm, ColorBank color = kCBStd); - virtual void update(const char *text); + void update(const char *text); private: CGE2Engine *_vm; }; -- cgit v1.2.3 From 152d795b456e4e71e85322cdfcfa402241bf9365 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 6 Jun 2014 22:07:32 +0200 Subject: CGE2: Implement InfoLine. Move initialization of _font, so it precedes _infoLine's and doesn't cause more problems. --- engines/cge2/cge2.cpp | 6 ++-- engines/cge2/cge2.h | 2 +- engines/cge2/cge2_main.cpp | 3 +- engines/cge2/talk.cpp | 69 ++++++++++++++++++++++++++++++++++++++++------ engines/cge2/talk.h | 9 +++--- 5 files changed, 70 insertions(+), 19 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index c80bf502d8..231e72b6f3 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -58,6 +58,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _spare = nullptr; _commandHandler = nullptr; _commandHandlerTurbo = nullptr; + _font = nullptr; _infoLine = nullptr; _mouse = nullptr; _keyboard = nullptr; @@ -70,7 +71,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _vol[i] = nullptr; _eventManager = nullptr; _blinkSprite = nullptr; - _font = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -109,6 +109,7 @@ void CGE2Engine::init() { _spare = new Spare(this); _commandHandler = new CommandHandler(this, false); _commandHandlerTurbo = new CommandHandler(this, true); + _font = new Font(this); _infoLine = new InfoLine(this, kInfoW); _mouse = new Mouse(this); _keyboard = new Keyboard(this); @@ -116,7 +117,6 @@ void CGE2Engine::init() { _point[i] = new V3D(); _sys = new System(this); _eventManager = new EventManager(this); - _font = new Font(this); } void CGE2Engine::deinit() { @@ -136,6 +136,7 @@ void CGE2Engine::deinit() { delete _sprite; delete _commandHandler; delete _commandHandlerTurbo; + delete _font; delete _infoLine; delete _mouse; delete _keyboard; @@ -148,7 +149,6 @@ void CGE2Engine::deinit() { delete _eventManager; if (_blinkSprite != nullptr) delete _blinkSprite; - delete _font; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index ec206af1db..d049339dee 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -219,6 +219,7 @@ public: Spare *_spare; CommandHandler *_commandHandler; CommandHandler *_commandHandlerTurbo; + Font *_font; InfoLine *_infoLine; Mouse *_mouse; Keyboard *_keyboard; @@ -229,7 +230,6 @@ public: Sprite *_vol[2]; EventManager *_eventManager; Sprite *_blinkSprite; - Font *_font; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 99447efad2..a37abbceed 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -516,8 +516,7 @@ void CGE2Engine::runGame() { _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); _infoLine->setText(nullptr); - //_vga->_showQ->insert(_infoLine); - warning("STUB: CGE2Engine::runGame() - Info Line is missing!"); + _vga->_showQ->insert(_infoLine); caveUp(_now); _startupMode = 0; diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index df88f72774..ee4a675fc3 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -244,20 +244,71 @@ void Talk::update(const char *text) { setShapeList(b, 1); } -InfoLine::InfoLine(CGE2Engine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) { - warning("STUB: InfoLine::InfoLine()"); +InfoLine::InfoLine(CGE2Engine *vm, uint16 w, ColorBank color) +: Talk(vm), _oldText(nullptr), _newText(nullptr), _realTime(false), _vm(vm) { + BitmapPtr b = new Bitmap[1]; + if (color == kCBRel) + _vm->setAutoColors(); + _color = _vm->_font->_colorSet[color]; + V2D siz = V2D(_vm, w, kFontHigh); + b[0] = Bitmap(_vm, siz.x, siz.y, _color[2]); + setShapeList(b, 1); } void InfoLine::update(const char *text) { - warning("STUB: InfoLine::update()"); -} + if (!_realTime && text == _oldText) + return; + + _oldText = text; + + uint16 w = _ext->_shpList->_w; + uint16 h = _ext->_shpList->_h; + uint8 *v = _ext->_shpList->_v; + uint16 dsiz = w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = h * lsiz; // - last gape, but + plane trailer + uint16 size = 4 * psiz; // whole map size + uint8 fg = _color[0]; + uint8 bg = _color[2]; -void InfoLine::update() { - warning("STUB: InfoLine::update()"); -} + // clear whole rectangle + memset(v + 2, bg, dsiz); // data bytes + for (byte *pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { + Common::copy(v, v + lsiz, pDest); + } + *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 + for (byte *pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { + Common::copy(v, v + psiz, pDest); + } -void InfoLine::setText(const char *txt) { - warning("STUB: InfoLine::setText()"); + // paint text line + if (_newText) { + uint8 *p = v + 2, *q = p + size; + + while (*text) { + uint16 cw = _vm->_font->_widthArr[(unsigned char)*text]; + uint8 *fp = _vm->_font->_map + _vm->_font->_pos[(unsigned char)*text]; + + // Handle properly space size, after it was enlarged to display properly + // 'F1' text. + int8 fontStart = 0; + if ((*text == 0x20) && (cw > 4) && (!_wideSpace)) + fontStart = 2; + + for (int i = fontStart; i < cw; i++) { + uint16 b = fp[i]; + for (uint16 n = 0; n < kFontHigh; n++) { + if (b & 1) + *p = fg; + b >>= 1; + p += lsiz; + } + if (p >= q) + p = p - size + 1; + } + text++; + } + } } } // End of namespace CGE2 diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index 771478c5d1..84ba7281f9 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -82,12 +82,13 @@ private: }; class InfoLine : public Talk { - const char *_oldText; + const char *_oldText, *_newText; public: - InfoLine(CGE2Engine *vm, uint16 wid); + bool _realTime; + InfoLine(CGE2Engine *vm, uint16 wid, ColorBank color = kCBStd); void update(const char *text); - void update(); - void setText(const char *txt); + void update() { update(_newText); } + void setText(const char *txt) { _newText = txt; } private: CGE2Engine *_vm; }; -- cgit v1.2.3 From 97bb1370a317b7ce3784889d74b61b6e5fd7bc84 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 6 Jun 2014 22:20:05 +0200 Subject: CGE2: Reimplement the way of handling y coord. In CGE2, the top left coords are (0, kScreenHeight), not (0,0). --- engines/cge2/events.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index c036d5d676..55c384cf9c 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -155,6 +155,7 @@ EventManager::EventManager(CGE2Engine *vm) : _vm(vm){ void EventManager::poll() { while (g_system->getEventManager()->pollEvent(_event)) { + _event.mouse.y = kScrHeight - _event.mouse.y; switch (_event.type) { case Common::EVENT_KEYDOWN: case Common::EVENT_KEYUP: @@ -186,7 +187,7 @@ void EventManager::handleEvents() { // update mouse cursor position if (e._mask & kMouseRoll) - _vm->_mouse->gotoxyz(e._x, kWorldHeight - e._y); + _vm->_mouse->gotoxyz(e._x, e._y); // activate current touched SPRITE if (e._spritePtr) { -- cgit v1.2.3 From 968f24af4787563c27c839ada08d4772b1ecd1b9 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 6 Jun 2014 22:26:27 +0200 Subject: CGE2: Fix coord conversion in EventManager::poll(). --- engines/cge2/events.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 55c384cf9c..75da3fac40 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -155,7 +155,7 @@ EventManager::EventManager(CGE2Engine *vm) : _vm(vm){ void EventManager::poll() { while (g_system->getEventManager()->pollEvent(_event)) { - _event.mouse.y = kScrHeight - _event.mouse.y; + _event.mouse.y = kWorldHeight - _event.mouse.y; switch (_event.type) { case Common::EVENT_KEYDOWN: case Common::EVENT_KEYUP: -- cgit v1.2.3 From 23d40712c6c7af0977fe2d38751f922e30a8b3b6 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 7 Jun 2014 19:40:29 +0200 Subject: CGE2: Refine implementation of Queue::insert(). --- engines/cge2/vga13h.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index b8fe54d437..60323913a8 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -696,6 +696,9 @@ void Queue::insert(Sprite *spr, Sprite *nxt) { } void Queue::insert(Sprite *spr) { + if (locate(spr)) + return; // We only queue it if it's not already queued. + Sprite *s; for (s = _head; s; s = s->_next) if (s->_pos3D._z < spr->_pos3D._z) -- cgit v1.2.3 From acb81c5e74ac2b54fc9b430d439389fb82233069 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 7 Jun 2014 19:44:16 +0200 Subject: CGE2: Fully implement caveUp(). Also implement connected parts of Hero. --- engines/cge2/cge2_main.cpp | 16 ++++++++++++--- engines/cge2/hero.cpp | 51 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a37abbceed..a5456477c8 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -368,9 +368,19 @@ void CGE2Engine::caveUp(int cav) { _spare->takeCave(_now); openPocket(); - warning("STUB: CGE2Engine::caveUp()"); - // TODO: Implement "Hero" things here! - + for (int i = 0; i < 2; i++) { + Hero *h = _heroTab[i]->_ptr; + if (h && h->_scene == _now) { + V2D p = *_heroTab[i]->_posTab[_now]; + h->gotoxyz(V3D(p.x, 0, p.y)); + h->clrHide(); + _vga->_showQ->insert(h); + h->park(); + h->setCurrent(); + h->setContact(); + } + } + _sound->stop(); _fx->clear(); diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 04ff05ce93..3e22d72942 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -222,8 +222,19 @@ void Hero::hStep() { } Sprite *Hero::setContact() { - warning("STUB: Hero::setContact()"); - return this; + Sprite *spr; + int md = _maxDist << 1; + for (spr = _vm->_vga->_showQ->first(); spr; spr = spr->_next) { + if (spr->_actionCtrl[kNear]._cnt && (spr->_ref & 255) != 255) { + if (distance(spr) <= md) { + if (spr == _contact) + return nullptr; + else + break; + } + } + } + return (_contact = spr); } void Hero::tick() { @@ -231,13 +242,29 @@ void Hero::tick() { } int Hero::distance(V3D pos) { - warning("STUB: Hero::distance()"); - return 0; + V3D di = _pos3D - pos; + long x = V2D::round(di._x); + long z = V2D::round(di._z); + return ((x * x + z * z) * (x * x + z * z)); } int Hero::distance(Sprite *spr) { - warning("STUB: Hero::distance()"); - return 0; + V3D pos = spr->_pos3D; + int mdx = (spr->_siz.x >> 1) + (_siz.x >> 1); + int dx = V2D::round(_pos3D._x - spr->_pos3D._x); + if (dx < 0) { + mdx = -mdx; + if (dx > mdx) + pos._x = _pos3D._x; + else + pos._x += mdx; + } else { + if (dx < mdx) + pos._x = _pos3D._x; + else + pos._x += mdx; + } + return distance(pos); } void Hero::turn(Dir d) { @@ -245,7 +272,17 @@ void Hero::turn(Dir d) { } void Hero::park() { - warning("STUB: Hero::park()"); + if (_dir != kNoDir) { + step(8 + 5 * _dir); + _dir = kNoDir; + _trace[0] = _pos3D; + _tracePtr = -1; + setCurrent(); + _flags._zmov = true; + } + _ignoreMap = false; + if (_time == 0) + ++_time; } bool Hero::lower(Sprite * spr) { -- cgit v1.2.3 From bb216eba2f8f9fd04a4e338393e37723b1328390 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 7 Jun 2014 20:33:52 +0200 Subject: CGE2: Implement System::touch(). --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++-- engines/cge2/cge2_main.h | 2 +- engines/cge2/events.cpp | 2 +- 4 files changed, 57 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index d049339dee..f25df58740 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -73,6 +73,7 @@ class Font; #define kInfoX 160 #define kInfoY -11 #define kInfoW 180 +#define kPocketsWidth 59 enum CallbackType { kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a5456477c8..065e905810 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -41,8 +41,60 @@ System::System(CGE2Engine *vm) : Sprite(vm), _vm(vm) { warning("STUB: System::System()"); } -void System::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { - warning("STUB: System::touch()"); +void System::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { + if (mask & kEventKeyb) { + if (keyCode == Common::KEYCODE_ESCAPE) { + // The original was calling keyClick() + // The sound is uselessly annoying and noisy, so it has been removed + _vm->killText(); + if (_vm->_startupMode == 1) { + _vm->_commandHandler->addCommand(kCmdClear, -1, 0, NULL); + return; + } + } + } else { + if (_vm->_startupMode) + return; + int selectedScene = 0; + _vm->_infoLine->setText(nullptr); + + if (mask & kMouseLeftUp) { + if (pos.y >= 0) { // world + if (!_vm->_talk && pos.y < _vm->_mouseTop) + _vm->_heroTab[_vm->_sex]->_ptr->walkTo(pos); + } else { // panel + if (_vm->_commandHandler->idle()) { + int sex = pos.x < kPocketsWidth; + if (sex || pos.x >= kScrWidth - kPocketsWidth) { + _vm->switchHero(sex); + if (_vm->_sex == sex) { + int dx = kPocketsWidth >> 1, + dy = 1 - (kPanHeight >> 1); + Sprite *s; + if (!sex) + pos.x -= kScrWidth - kPocketsWidth; + dx -= pos.x; + dy -= pos.y; + if (dx * dx + dy * dy > 10 * 10) { + int n = 0; + if (1 - pos.y >= (kPanHeight >> 1)) + n += 2; + if (pos.x >= (kPocketsWidth >> 1)) + ++n; + s = _vm->_heroTab[_vm->_sex]->_pocket[n]; + if (_vm->_blinkSprite) + _vm->_blinkSprite->_flags._hide = false; + if (_vm->_blinkSprite == s) + _vm->_blinkSprite = nullptr; + else + _vm->_blinkSprite = s; + } + } + } + } + } + } + } } void System::tick() { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index 272cdf79d5..a0bd780ab1 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -56,7 +56,7 @@ public: System(CGE2Engine *vm); - virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); + virtual void touch(uint16 mask, V2D pos, Common::KeyCode keyCode); void tick(); private: CGE2Engine *_vm; diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 75da3fac40..a143c77a7d 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -196,7 +196,7 @@ void EventManager::handleEvents() { else e._spritePtr->touch(e._mask, e._x - e._spritePtr->_pos2D.x, e._y - e._spritePtr->_pos2D.y, e._keyCode); } else if (_vm->_sys) - _vm->_sys->touch(e._mask, e._x, e._y, e._keyCode); + _vm->_sys->touch(e._mask, V2D(_vm, e._x, e._y), e._keyCode); if (e._mask & kMouseLeftDown) { _vm->_mouse->_hold = e._spritePtr; -- cgit v1.2.3 From 0cad1988e4103172a0d3281606b34d4fd381c30b Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 7 Jun 2014 21:07:46 +0200 Subject: CGE2: Remove unnecessary variable from System::touch(). --- engines/cge2/cge2_main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 065e905810..7d9e715123 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -55,7 +55,6 @@ void System::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { } else { if (_vm->_startupMode) return; - int selectedScene = 0; _vm->_infoLine->setText(nullptr); if (mask & kMouseLeftUp) { -- cgit v1.2.3 From f2a1d4f1c865861dc42deb99a8b4aa4a97ecb235 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 7 Jun 2014 21:09:19 +0200 Subject: CGE2: Implement walkTo() and snap() in Hero. --- engines/cge2/hero.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- engines/cge2/hero.h | 2 ++ 2 files changed, 49 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 3e22d72942..f429c400c8 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -317,16 +317,59 @@ bool Hero::findWay(){ } int Hero::snap(int p, int q, int grid) { - warning("STUB: Hero::findWay()"); - return 0; + int d = q - p; + d = ((d >= 0) ? d : -d) % grid; + if (d > (grid >> 1)) + d -= grid; + return (q >= p) ? (q - d) : (q + d); } void Hero::walkTo(V3D pos) { - warning("STUB: Hero::walkTo()"); + if (distance(pos) <= _maxDist) + return; + int stp = stepSize(); + pos._x = snap(V2D::round(_pos3D._x), V2D::round(pos._x), stp); + pos._y = 0; + pos._z = snap(V2D::round(_pos3D._z), V2D::round(pos._z), stp); + + V2D p0(_vm, V2D::round(_pos3D._x), V2D::round(_pos3D._z)); + V2D p1(_vm, V2D::round(pos._x), V2D::round(pos._z)); + resetFun(); + int cnt = mapCross(p0, p1); + if ((cnt & 1) == 0) { // even == way exists + _trace[_tracePtr = 0] = pos; + if (!findWay()) { + int i; + ++_tracePtr; + for (i = stp; i < kMaxTry; i += stp) { + _trace[_tracePtr] = pos + V3D(i, 0, 0); + if (!mapCross(_trace[_tracePtr - 1], _trace[_tracePtr]) && findWay()) + break; + + _trace[_tracePtr] = pos + V3D(-i, 0, 0); + if (!mapCross(_trace[_tracePtr - 1], _trace[_tracePtr]) && findWay()) + break; + + _trace[_tracePtr] = pos + V3D(0, 0, i); + if (!mapCross(_trace[_tracePtr - 1], _trace[_tracePtr]) && findWay()) + break; + + _trace[_tracePtr] = pos + V3D(0, 0, -i); + if (!mapCross(_trace[_tracePtr - 1], _trace[_tracePtr]) && findWay()) + break; + } + if (i >= kMaxTry) + _trace[_tracePtr] = V3D(_pos3D._x, 0, pos._z); // not found + } + } } void Hero::walkTo(Sprite *spr) { - warning("STUB: Hero::walkTo()"); + int mdx = _siz.x >> 1; + int stp = (stepSize() + 1) / 2; + if (!spr->_flags._east) + mdx = -mdx; + walkTo(spr->_pos3D + V3D(mdx, 0, (!spr->_flags._frnt || spr->_pos3D._z < 8) ? stp : -stp)); } V3D Hero::screenToGround(V2D pos) { diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 8face03944..8a8d400c26 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -31,6 +31,8 @@ #include "cge2/vga13h.h" #include "cge2/snail.h" +#define kMaxTry 400 + namespace CGE2 { #define kMaxTry 400 -- cgit v1.2.3 From a62e044174f296cc8cf7dced7b35cc3d4fe0ea01 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 7 Jun 2014 21:35:48 +0200 Subject: CGE2: Keep on implementing Hero. Also add a couple of helping functions to CGE2Engine. --- engines/cge2/cge2.h | 4 ++++ engines/cge2/hero.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index f25df58740..0533e19bd8 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -132,6 +132,10 @@ public: void optionTouch(int opt, uint16 mask); void offUse(); void setAutoColors(); + bool cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d); + bool contain(const V2D &a, const V2D &b, const V2D &p); + int sgn(long n); + int mapCross(const V2D &a, const V2D &b); void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index f429c400c8..0c46b827f0 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -307,12 +307,33 @@ void Hero::operator -- () { } uint32 Hero::len(V2D v) { - warning("STUB: Hero::works()"); - return 0; + long x = v.x, y = v.y; + return (uint32)((x * x + y * y) * (x * x + y * y)); } bool Hero::findWay(){ - warning("STUB: Hero::findWay()"); + V2D p0(_vm, V2D::round(_pos3D._x), V2D::round(_pos3D._z)); + V2D p1(_vm, V2D::round(_trace[_tracePtr]._x), V2D::round(_trace[_tracePtr]._z)); + bool pvOk; + bool phOk; + V2D ph(_vm, p1.x, p0.y); + V2D pv(_vm, p0.x, p1.y); + pvOk = (!mapCross(p0, pv) && !mapCross(pv, p1)); + phOk = (!mapCross(p0, ph) && !mapCross(ph, p1)); + int md = (_maxDist >> 1); + if (pvOk && (len(ph - p0) <= md || len(p1 - ph) <= md)) + return true; + if (phOk && (len(pv - p0) <= md || len(p1 - pv) <= md)) + return true; + + if (pvOk) { + _trace[++_tracePtr] = V3D(pv.x, 0, pv.y); + return true; + } + if (phOk) { + _trace[++_tracePtr] = V3D(ph.x, 0, ph.y); + return true; + } return false; } @@ -380,22 +401,48 @@ V3D Hero::screenToGround(V2D pos) { int Hero::cross(const V2D &a, const V2D &b) { - warning("STUB: Hero::cross()"); + int x = V2D::trunc(_pos3D._x); + int z = V2D::trunc(_pos3D._z); + int r = ((_siz.x / 3) * V2D::trunc(_vm->_eye->_z)) / (V2D::trunc(_vm->_eye->_z) - z); + return _vm->cross(a, b, V2D(_vm, x - r, z), V2D(_vm, x + r, z)) << 1; +} + + + +bool CGE2Engine::cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d) { + warning("STUB: CGE2Engine::cross()"); + return false; +} + +bool CGE2Engine::contain(const V2D &a, const V2D &b, const V2D &p) { + warning("STUB: CGE2Engine::contain()"); + return false; +} + +int CGE2Engine::sgn(long n) { + warning("STUB: CGE2Engine::sgn()"); return 0; } int Hero::mapCross(const V2D &a, const V2D &b) { - warning("STUB: Hero::mapCross()"); - return 0; + Hero *o = other(); + int n = (o->_scene == _scene) ? o->cross(a, b) : 0; + if (!_ignoreMap) + n += _vm->mapCross(a, b); + return n; } int Hero::mapCross(const V3D &a, const V3D &b) { - warning("STUB: Hero::mapCross()"); + return mapCross(V2D(_vm, V2D::round(a._x), V2D::round(a._z)), V2D(_vm, V2D::round(b._x), V2D::round(b._z))); +} + +int CGE2Engine::mapCross(const V2D &a, const V2D &b) { + warning("STUB: CGE2Engine::cross()"); return 0; } void Hero::setCave(int c) { - warning("STUB: Hero::mapCross()"); + warning("STUB: Hero::setCave()"); } bool Sprite::works(Sprite *spr) { -- cgit v1.2.3 From 9aa80d6d05f11afcb0682699c1a631ed9287341b Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 07:30:31 +0200 Subject: CGE2: Implement helper functions connected to Hero. Also rework Hero::len() during the process. --- engines/cge2/cge2.h | 1 + engines/cge2/hero.cpp | 32 ++++++++++++++++++++------------ engines/cge2/hero.h | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 0533e19bd8..be2bbd33e3 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -134,6 +134,7 @@ public: void setAutoColors(); bool cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d); bool contain(const V2D &a, const V2D &b, const V2D &p); + long det(const V2D &a, const V2D &b, const V2D &c); int sgn(long n); int mapCross(const V2D &a, const V2D &b); diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 0c46b827f0..5ebce6ef4f 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -306,9 +306,8 @@ void Hero::operator -- () { warning("STUB: Hero::operator --()"); } -uint32 Hero::len(V2D v) { - long x = v.x, y = v.y; - return (uint32)((x * x + y * y) * (x * x + y * y)); +int Hero::len(V2D v) { + return ((v.x * v.x + v.y * v.y) * (v.x * v.x + v.y * v.y)); } bool Hero::findWay(){ @@ -399,7 +398,6 @@ V3D Hero::screenToGround(V2D pos) { return V3D(V2D::round(x), 0, V2D::round(z)); } - int Hero::cross(const V2D &a, const V2D &b) { int x = V2D::trunc(_pos3D._x); int z = V2D::trunc(_pos3D._z); @@ -407,21 +405,31 @@ int Hero::cross(const V2D &a, const V2D &b) { return _vm->cross(a, b, V2D(_vm, x - r, z), V2D(_vm, x + r, z)) << 1; } - - bool CGE2Engine::cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d) { - warning("STUB: CGE2Engine::cross()"); - return false; + if (contain(a, b, c)) + return true; + if (contain(a, b, d)) + return true; + if (contain(c, d, a)) + return true; + if (contain(c, d, b)) + return true; + return sgn(det(a, b, c)) != sgn(det(a, b, d)) && sgn(det(c, d, a)) != sgn(det(c, d, b)); } bool CGE2Engine::contain(const V2D &a, const V2D &b, const V2D &p) { - warning("STUB: CGE2Engine::contain()"); - return false; + if (det(a, b, p)) + return false; + return ((long)(a.x - p.x) * (p.x - b.x) >= 0 && (long)(a.y - p.y) * (p.y - b.y) >= 0); +} + +long CGE2Engine::det(const V2D &a, const V2D &b, const V2D &c) { + long n = ((long)a.x * b.y + (long)b.x * c.y + (long)c.x*a.y) - ((long)c.x*b.y + (long)b.x*a.y + (long)a.x*c.y); + return n; } int CGE2Engine::sgn(long n) { - warning("STUB: CGE2Engine::sgn()"); - return 0; + return (n == 0) ? 0 : ((n > 0) ? 1 : -1); } int Hero::mapCross(const V2D &a, const V2D &b) { diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 8a8d400c26..c9933867a1 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -78,7 +78,7 @@ public: int distance(Sprite * spr); void turn(Dir d); void park(); - static uint32 len(V2D v); + int len(V2D v); bool findWay(); static int snap(int p, int q, int grid); void walkTo(V3D pos); -- cgit v1.2.3 From 8c3e63e47139c4ff168e93b105297e7f8f669016 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 07:38:16 +0200 Subject: CGE2: Reduce number of unhandled commands (seemingly). --- engines/cge2/cge2.h | 2 ++ engines/cge2/snail.cpp | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index be2bbd33e3..dcbffdf389 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -181,10 +181,12 @@ public: void snBackPt(Sprite *spr, int val); void snFlash(int val); void snLight(int val); + void snCycle(int cnt); void snWalk(Sprite *spr, int val); void snReach(Sprite *spr, int val); void snSound(Sprite *spr, int wav); void snRoom(Sprite *spr, int val); + void snDim(Sprite *spr, int val); void snGhost(Bitmap *bmp); void hide1(Sprite *spr); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 7961e6d054..1368652e3b 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -276,7 +276,7 @@ void CommandHandler::runCommand() { _vm->snLight(tailCmd._val != 0); break; case kCmdCycle: - warning("Unhandled command - kCmdCycle"); + _vm->snCycle(tailCmd._val); break; case kCmdWalk: _vm->snWalk(spr, tailCmd._val); @@ -298,7 +298,7 @@ void CommandHandler::runCommand() { _vm->snRoom(spr, tailCmd._val); break; case kCmdDim: - warning("Unhandled command - kCmdDim"); + _vm->snDim(spr, tailCmd._val); break; case kCmdExec: warning("Unhandled command - kCmdExec"); @@ -491,6 +491,10 @@ void CGE2Engine::snLight(int val) { warning("STUB: CGE2Engine::snLight()"); } +void CGE2Engine::snCycle(int cnt) { + warning("STUB: CGE2Engine::snCycle()"); +} + void CGE2Engine::snWalk(Sprite *spr, int val) { warning("STUB: CGE2Engine::snWalk()"); } @@ -520,6 +524,15 @@ void CGE2Engine::snRoom(Sprite *spr, int val) { warning("STUB: CGE2Engine::snRoom()"); } +void CGE2Engine::snDim(Sprite *spr, int val) { + if (isHero(spr)) { + if (val > 0) + ++*(Hero*)spr; + if (val < 0) + --*(Hero*)spr; + } +} + void CGE2Engine::snGhost(Bitmap *bmp) { V2D p(this, *bmp->_v & 0xFFFF, *bmp->_v >> 16); bmp->hide(p.x, p.y); -- cgit v1.2.3 From 5a7924678ac8af99e6cd58edc3f5cb3342253038 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 07:41:25 +0200 Subject: CGE2: Further implement Hero's functions. --- engines/cge2/hero.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 5ebce6ef4f..601e289528 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -298,14 +298,6 @@ void Hero::fun() { warning("STUB: Hero::fun()"); } -void Hero::operator ++ () { - warning("STUB: Hero::operator ++()"); -} - -void Hero::operator -- () { - warning("STUB: Hero::operator --()"); -} - int Hero::len(V2D v) { return ((v.x * v.x + v.y * v.y) * (v.x * v.x + v.y * v.y)); } @@ -450,7 +442,18 @@ int CGE2Engine::mapCross(const V2D &a, const V2D &b) { } void Hero::setCave(int c) { - warning("STUB: Hero::setCave()"); + _scene = c; + resetFun(); +} + +void Hero::operator++() { + if (_curDim > 0) + _ext->_shpList = _dim[--_curDim]; +} + +void Hero::operator--() { + if (_curDim < kDimMax - 1) + _ext->_shpList = _dim[++_curDim]; } bool Sprite::works(Sprite *spr) { -- cgit v1.2.3 From 5fca8c328ca49e3de7b3d9e4dc03293dab504e89 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 07:44:46 +0200 Subject: CGE2: Fix stub message in CGE2Engine::mapCross(). --- engines/cge2/hero.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 601e289528..62568aecaa 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -437,7 +437,7 @@ int Hero::mapCross(const V3D &a, const V3D &b) { } int CGE2Engine::mapCross(const V2D &a, const V2D &b) { - warning("STUB: CGE2Engine::cross()"); + warning("STUB: CGE2Engine::mapCross()"); return 0; } -- cgit v1.2.3 From cfe03245fae13dff869ea6f8c934fb510161e431 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 07:52:21 +0200 Subject: CGE2: Handle kCmdNop correctly. --- engines/cge2/snail.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 1368652e3b..d41aa80aa7 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -309,6 +309,8 @@ void CommandHandler::runCommand() { case kCmdGhost: _vm->snGhost((Bitmap *)tailCmd._spritePtr); break; + case kCmdNop: // Do nothing. + break; default: warning("Unhandled command"); break; -- cgit v1.2.3 From 9afe6bd570e5445db951792f338d2781ad67d1ee Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 09:53:47 +0200 Subject: CGE2: Add, implement and use Map. --- engines/cge2/cge2.cpp | 4 ++ engines/cge2/cge2.h | 3 +- engines/cge2/cge2_main.cpp | 6 +-- engines/cge2/map.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/map.h | 54 +++++++++++++++++++++++++++ engines/cge2/module.mk | 3 +- 6 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 engines/cge2/map.cpp create mode 100644 engines/cge2/map.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 231e72b6f3..b32ca76489 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -38,6 +38,7 @@ #include "cge2/events.h" #include "cge2/talk.h" #include "cge2/cge2_main.h" +#include "cge2/map.h" namespace CGE2 { @@ -71,6 +72,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _vol[i] = nullptr; _eventManager = nullptr; _blinkSprite = nullptr; + _map = nullptr; _quitFlag = false; _bitmapPalette = nullptr; @@ -117,6 +119,7 @@ void CGE2Engine::init() { _point[i] = new V3D(); _sys = new System(this); _eventManager = new EventManager(this); + _map = new Map(this); } void CGE2Engine::deinit() { @@ -149,6 +152,7 @@ void CGE2Engine::deinit() { delete _eventManager; if (_blinkSprite != nullptr) delete _blinkSprite; + delete _map; } bool CGE2Engine::hasFeature(EngineFeature f) const { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index dcbffdf389..4fc8576678 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -57,6 +57,7 @@ class Bitmap; class System; class EventManager; class Font; +class Map; #define kScrWidth 320 #define kScrHeight 240 @@ -109,7 +110,6 @@ public: void showBak(int ref); void loadTab(); int newRandom(int range); - void loadMap(int cav); void openPocket(); void selectPocket(int n); void busy(bool on); @@ -238,6 +238,7 @@ public: Sprite *_vol[2]; EventManager *_eventManager; Sprite *_blinkSprite; + Map *_map; private: void init(); void deinit(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 7d9e715123..e256d72db6 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -34,6 +34,7 @@ #include "cge2/hero.h" #include "cge2/spare.h" #include "cge2/events.h" +#include "cge2/map.h" namespace CGE2 { @@ -416,6 +417,7 @@ void CGE2Engine::caveUp(int cav) { showBak(bakRef); *_eye = *(_eyeTab[_now]); _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; + _map->load(_now); _spare->takeCave(_now); openPocket(); @@ -545,10 +547,6 @@ void CGE2Engine::tick() { _mouse->tick(); } -void CGE2Engine::loadMap(int cav) { - warning("STUB: CGE2Engine::loadMap()"); -} - void CGE2Engine::openPocket() { warning("STUB: CGE2Engine::openPocket()"); } diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp new file mode 100644 index 0000000000..ed8ce21b3b --- /dev/null +++ b/engines/cge2/map.cpp @@ -0,0 +1,92 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/map.h" +#include "cge2/cge2_main.h" + +namespace CGE2 { + +Map::Map(CGE2Engine *vm) :_vm(vm) {} + +Map::~Map() { + _container.clear(); +} + +int Map::convertCoord(int coord) { + return (coord + (kMapGrid >> 1)) & kMapMask; +} + +void Map::load(int cave) { + char fname[] = "%.2d.MAP\0"; + Common::String filename = Common::String::format(fname, cave); + clear(); + if (!_vm->_resman->exist(filename.c_str())) + return; + + EncryptedStream file(_vm, filename.c_str()); + + char tmpStr[kLineMax + 1]; + Common::String line; + + for (line = file.readLine(); !file.eos(); line = file.readLine()) { + if (line.size() == 0) + continue; + + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *currPos = tmpStr; + currPos = strtok(currPos, " (),"); + int x = atoi(currPos); + currPos = strtok(nullptr, " (),"); + int y = atoi(currPos); + _container.push_back(V2D(_vm, convertCoord(x), convertCoord(y))); + + while (true) { + currPos = strtok(nullptr, " (),"); + if (currPos == nullptr) + break; + int x = atoi(currPos); + currPos = strtok(nullptr, " (),"); + int y = atoi(currPos); + _container.push_back(V2D(_vm, convertCoord(x), convertCoord(y))); + } + } +} + +int Map::size() { + return _container.size(); +} + +void Map::clear() { + _container.clear(); +} + +V2D &Map::operator[](int idx) { + return _container[idx]; +} + +} // End of namespace CGE2 diff --git a/engines/cge2/map.h b/engines/cge2/map.h new file mode 100644 index 0000000000..7b792b25dd --- /dev/null +++ b/engines/cge2/map.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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_MAP_H +#define CGE2_MAP_H + +#include "cge2/vga13h.h" + +namespace CGE2 { + +#define kMapGrid 4 +#define kMapMask (~(kMapGrid - 1)) + +class Map { + CGE2Engine *_vm; + Common::Array _container; + + int convertCoord(int coord); +public: + Map(CGE2Engine *vm); + ~Map(); + void load(int cave); + int size(); + void clear(); + V2D &operator[](int idx); +}; + +} // End of namespace CGE2 + +#endif // CGE2_MAP_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 7272ed3829..dc74de5ed6 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -13,7 +13,8 @@ MODULE_OBJS = \ snail.o \ spare.o \ talk.o \ - events.o + events.o \ + map.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) -- cgit v1.2.3 From 1d8536e6df8db7dec0cc4fb05f85bf67183e848d Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 11:06:12 +0200 Subject: CGE2: Replace tab with space. --- engines/cge2/map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp index ed8ce21b3b..1ae9451ecc 100644 --- a/engines/cge2/map.cpp +++ b/engines/cge2/map.cpp @@ -36,7 +36,7 @@ Map::~Map() { _container.clear(); } -int Map::convertCoord(int coord) { +int Map::convertCoord(int coord) { return (coord + (kMapGrid >> 1)) & kMapMask; } -- cgit v1.2.3 From acbd19bec43302ec97e0f00513351410dc540618 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 12:42:05 +0200 Subject: CGE2: Some rework in Map. --- engines/cge2/map.cpp | 51 ++++++++++++++++++++++++++------------------------- engines/cge2/map.h | 7 ++++--- 2 files changed, 30 insertions(+), 28 deletions(-) (limited to 'engines') diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp index 1ae9451ecc..579f44b681 100644 --- a/engines/cge2/map.cpp +++ b/engines/cge2/map.cpp @@ -36,53 +36,54 @@ Map::~Map() { _container.clear(); } -int Map::convertCoord(int coord) { - return (coord + (kMapGrid >> 1)) & kMapMask; +void Map::clear() { + _container.clear(); } -void Map::load(int cave) { - char fname[] = "%.2d.MAP\0"; - Common::String filename = Common::String::format(fname, cave); +void Map::load(int scene) { clear(); - if (!_vm->_resman->exist(filename.c_str())) + + char fname[] = "%.2d.MAP\0"; + Common::String fileName = Common::String::format(fname, scene); + if (!_vm->_resman->exist(fileName.c_str())) return; - EncryptedStream file(_vm, filename.c_str()); + EncryptedStream file(_vm, fileName.c_str()); - char tmpStr[kLineMax + 1]; Common::String line; - for (line = file.readLine(); !file.eos(); line = file.readLine()) { if (line.size() == 0) continue; + char tmpStr[kLineMax + 1]; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); char *currPos = tmpStr; - currPos = strtok(currPos, " (),"); - int x = atoi(currPos); - currPos = strtok(nullptr, " (),"); - int y = atoi(currPos); - _container.push_back(V2D(_vm, convertCoord(x), convertCoord(y))); - + int x = nextNum(currPos); while (true) { - currPos = strtok(nullptr, " (),"); - if (currPos == nullptr) - break; - int x = atoi(currPos); - currPos = strtok(nullptr, " (),"); - int y = atoi(currPos); + int y = nextNum(nullptr); _container.push_back(V2D(_vm, convertCoord(x), convertCoord(y))); + x = nextNum(nullptr); + if (x == -1) // We stop if there are no more data left to process in the current line. + break; } } } -int Map::size() { - return _container.size(); +int Map::nextNum(char *currPos) { + currPos = strtok(currPos, " (),"); + if (currPos == nullptr) + return -1; + int num = atoi(currPos); + return num; } -void Map::clear() { - _container.clear(); +int Map::convertCoord(int coord) { + return (coord + (kMapGrid >> 1)) & kMapMask; +} + +int Map::size() { + return _container.size(); } V2D &Map::operator[](int idx) { diff --git a/engines/cge2/map.h b/engines/cge2/map.h index 7b792b25dd..10448f0fd5 100644 --- a/engines/cge2/map.h +++ b/engines/cge2/map.h @@ -39,13 +39,14 @@ class Map { CGE2Engine *_vm; Common::Array _container; - int convertCoord(int coord); + int convertCoord(int coord); + int nextNum(char *currPos); public: Map(CGE2Engine *vm); ~Map(); - void load(int cave); - int size(); void clear(); + void load(int scene); + int size(); V2D &operator[](int idx); }; -- cgit v1.2.3 From ba8bc2e40b94aa6055222550651452c3645c2515 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 12:55:19 +0200 Subject: CGE2: Rework empty-checks of strings. --- engines/cge2/cge2_main.cpp | 4 ++-- engines/cge2/hero.cpp | 2 +- engines/cge2/map.cpp | 2 +- engines/cge2/talk.cpp | 2 +- engines/cge2/vga13h.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e256d72db6..20b16fa227 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -168,7 +168,7 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { Common::String line; for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ - if (line.size() == 0) + if (line.empty()) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); @@ -313,7 +313,7 @@ void CGE2Engine::loadScript(const char *fname) { Common::String line; for (line = scrf.readLine(); !scrf.eos(); line = scrf.readLine()) { - if (line.size() == 0) + if (line.empty()) continue; char *p; diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 62568aecaa..de0dc2688a 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -92,7 +92,7 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo int maxnxt = 0; for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { - if (line.size() == 0) + if (line.empty()) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp index 579f44b681..6dbf57f08d 100644 --- a/engines/cge2/map.cpp +++ b/engines/cge2/map.cpp @@ -52,7 +52,7 @@ void Map::load(int scene) { Common::String line; for (line = file.readLine(); !file.eos(); line = file.readLine()) { - if (line.size() == 0) + if (line.empty()) continue; char tmpStr[kLineMax + 1]; diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index ee4a675fc3..acadd2e001 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -81,7 +81,7 @@ void Font::load() { int n = 0; for (line = colorFile.readLine(); !colorFile.eos(); line = colorFile.readLine()){ - if (line.size() == 0) + if (line.empty()) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 60323913a8..7da9535030 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -246,7 +246,7 @@ Sprite *Sprite::expand() { char tmpStr[kLineMax + 1]; for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { - if (line.size() == 0) + if (line.empty()) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); -- cgit v1.2.3 From 93010a840734507b84554ad47e50eec7db34a939 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 8 Jun 2014 14:26:42 +0200 Subject: CGE2: Implement CGE2Engine::mapCross(). Rework Map during the process. --- engines/cge2/hero.cpp | 20 ++++++++++++++++++-- engines/cge2/map.cpp | 4 ++-- engines/cge2/map.h | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index de0dc2688a..530ff11458 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -28,6 +28,7 @@ #include "cge2/hero.h" #include "cge2/text.h" #include "cge2/cge2_main.h" +#include "cge2/map.h" namespace CGE2 { @@ -437,8 +438,23 @@ int Hero::mapCross(const V3D &a, const V3D &b) { } int CGE2Engine::mapCross(const V2D &a, const V2D &b) { - warning("STUB: CGE2Engine::mapCross()"); - return 0; + int cnt = 0; + V2D *n0 = nullptr; + V2D *p = nullptr; + for (int i = 0; i < _map->size(); i++) { + V2D *n = _map->getCoord(i); + if (p) { + if (cross(a, b, *n0, *n)) + ++cnt; + + if (n == p) + p = nullptr; + } else { + p = n; + } + n0 = n; + } + return cnt; } void Hero::setCave(int c) { diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp index 6dbf57f08d..8a9a5db4e2 100644 --- a/engines/cge2/map.cpp +++ b/engines/cge2/map.cpp @@ -86,8 +86,8 @@ int Map::size() { return _container.size(); } -V2D &Map::operator[](int idx) { - return _container[idx]; +V2D *Map::getCoord(int idx) { + return &_container[idx]; } } // End of namespace CGE2 diff --git a/engines/cge2/map.h b/engines/cge2/map.h index 10448f0fd5..206479b929 100644 --- a/engines/cge2/map.h +++ b/engines/cge2/map.h @@ -47,7 +47,7 @@ public: void clear(); void load(int scene); int size(); - V2D &operator[](int idx); + V2D *getCoord(int idx); }; } // End of namespace CGE2 -- cgit v1.2.3 From 5d80601c06c02db12147b64c5c17feeaf5565bc8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 8 Jun 2014 22:53:38 +0200 Subject: CGE2: Reduce the scope of a couple of variables, fix style --- engines/cge2/talk.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index acadd2e001..87703834e7 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -128,21 +128,21 @@ Talk::Talk(CGE2Engine *vm, ColorBank color) } uint8 *Talk::box(V2D siz) { - uint8 *b, *p, *q; uint16 n, r = (_mode == kTBRound) ? kTextRoundCorner : 0; const byte lt = _color[1], bg = _color[2], dk = _color[3]; - int i; - if (siz.x < 8) siz.x = 8; - if (siz.y < 8) siz.y = 8; - b = new uint8[n = siz.area()]; + if (siz.x < 8) + siz.x = 8; + if (siz.y < 8) + siz.y = 8; + uint8 *b = new uint8[n = siz.area()]; if (!b) error("No core!"); memset(b, bg, n); if (_mode) { - p = b; - q = b + n - siz.x; + uint8 *p = b; + uint8 *q = b + n - siz.x; memset(p, lt, siz.x); memset(q, dk, siz.x); while (p < q) { @@ -151,9 +151,9 @@ uint8 *Talk::box(V2D siz) { *p = lt; } p = b; - for (i = 0; i < r; i++) { - int j; - for (j = 0; j < r - i; j++) { + for (int i = 0; i < r; i++) { + int j = 0; + for (; j < r - i; j++) { p[j] = kPixelTransp; p[siz.x - j - 1] = kPixelTransp; q[j] = kPixelTransp; -- cgit v1.2.3 From 76fa66fc8ce531d3391a81259e13474b429277f5 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 9 Jun 2014 23:19:57 +0200 Subject: CGE2: Fix endless loop regarding kCmdWait. --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 20b16fa227..764bdde5d8 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -538,7 +538,7 @@ void CGE2Engine::tick() { spr->tick(); } if (_waitRef) { - if (_waitRef == _sprite->_ref) + if (_waitRef == spr->_ref) if (spr->seqTest(_waitSeq)) _waitRef = 0; } -- cgit v1.2.3 From 63fa2d4906dbe119c552e993ae0f4cd2a4079ddb Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 9 Jun 2014 23:34:40 +0200 Subject: CGE2: Simplify if-statements. --- engines/cge2/cge2_main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 764bdde5d8..99b0f26c21 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -533,13 +533,11 @@ bool CGE2Engine::isHero(Sprite *spr) { void CGE2Engine::tick() { for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { - if (spr->_time) { - if (--spr->_time == 0) + if (spr->_time && (--spr->_time == 0)) spr->tick(); - } + if (_waitRef) { - if (_waitRef == spr->_ref) - if (spr->seqTest(_waitSeq)) + if (_waitRef == spr->_ref && spr->seqTest(_waitSeq)) _waitRef = 0; } } -- cgit v1.2.3 From 12c531284b4108ce1935982a924971339bec188a Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 9 Jun 2014 23:54:45 +0200 Subject: CGE2: Implement a couple of command handling functions. --- engines/cge2/snail.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index d41aa80aa7..3af4c88d37 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -422,7 +422,13 @@ void CGE2Engine::snGive(Sprite *spr, int val) { } void CGE2Engine::snGoto(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snGoto()"); + if (spr) { + V3D eye = *_eye; + if (spr->_scene > 0) + setEye(*_eyeTab[spr->_scene]); + spr->gotoxyz(*_point[val]); + setEye(eye); + } } void CGE2Engine::snMove(Sprite *spr, V3D pos) { @@ -446,7 +452,11 @@ void CGE2Engine::snMouse(int val) { } void CGE2Engine::snNNext(Sprite *spr, Action act, int val) { - warning("STUB: CGE2Engine::snNNext()"); + if (spr) { + if (val > 255) + val = spr->labVal(act, val >> 8); + spr->_actionCtrl[act]._ptr = val; + } } void CGE2Engine::snRNNext(Sprite *spr, int val) { @@ -466,7 +476,8 @@ void CGE2Engine::snRmNear(Sprite *spr) { } void CGE2Engine::snRmMTake(Sprite *spr) { - warning("STUB: CGE2Engine::snRmMTake()"); + if (spr) + spr->_actionCtrl[kMTake]._cnt = 0; } void CGE2Engine::snRmFTake(Sprite *spr) { -- cgit v1.2.3 From e10f22b62f85b5d940a4274e65a53b907f2eae4b Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 10 Jun 2014 14:02:17 +0200 Subject: CGE2: Move kLineMax to cge2.h. --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.h | 1 - engines/cge2/hero.cpp | 1 - engines/cge2/map.cpp | 1 - engines/cge2/talk.cpp | 1 - engines/cge2/text.cpp | 1 - 6 files changed, 1 insertion(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 4fc8576678..ebee2edbd7 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -75,6 +75,7 @@ class Map; #define kInfoY -11 #define kInfoW 180 #define kPocketsWidth 59 +#define kLineMax 512 enum CallbackType { kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index a0bd780ab1..e59c6f0b45 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -32,7 +32,6 @@ namespace CGE2 { -#define kLineMax 512 #define kIntroExt ".I80" #define kTabName "CGE.TAB" #define kPocketFull 170 diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 530ff11458..5efb24e88d 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -27,7 +27,6 @@ #include "cge2/hero.h" #include "cge2/text.h" -#include "cge2/cge2_main.h" #include "cge2/map.h" namespace CGE2 { diff --git a/engines/cge2/map.cpp b/engines/cge2/map.cpp index 8a9a5db4e2..1ed0ea7daf 100644 --- a/engines/cge2/map.cpp +++ b/engines/cge2/map.cpp @@ -26,7 +26,6 @@ */ #include "cge2/map.h" -#include "cge2/cge2_main.h" namespace CGE2 { diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 87703834e7..a6d9945665 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -27,7 +27,6 @@ #include "cge2/general.h" #include "cge2/talk.h" -#include "cge2/cge2_main.h" namespace CGE2 { diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 554d6ba88c..ac222f9030 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -30,7 +30,6 @@ //#include "cge/talk.h" //#include "cge/game.h" //#include "cge/snail.h" -#include "cge2/cge2_main.h" #include "common/str.h" namespace CGE2 { -- cgit v1.2.3 From 71b0a4cc69185ee6b6f01b488a958c7c19503c3f Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 10 Jun 2014 14:02:33 +0200 Subject: CGE2: Implement Sprite::labVal(). --- engines/cge2/vga13h.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 7da9535030..486db29061 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -180,8 +180,64 @@ void Sprite::setName(char *newName) { } int Sprite::labVal(Action snq, int lab) { - warning("STUB: Sprite::labVal()"); - return 0; + int lv = -1; + if (active()) { + int n = _actionCtrl[snq]._cnt; + CommandHandler::Command *com = snList(snq); + + int i; + for (i = 0; i < n; i++) + if (com[i]._lab == lab) + break; + if (i < n) + return i; + } else { + char tmpStr[kLineMax + 1]; + _vm->mergeExt(tmpStr, _file, kSprExt); + + if (_vm->_resman->exist(tmpStr)) { // sprite description file exist + EncryptedStream sprf(_vm, tmpStr); + if (sprf.err()) + error("Bad SPR [%s]", tmpStr); + + int cnt = 0; + int section = kIdPhase; + ID id; + Common::String line; + + while (lv == -1 && !sprf.eos()) { + line = sprf.readLine(); + if (line.empty()) + continue; + + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *p; + p = _vm->token(tmpStr); + + if (*p == '@') { + if (section == snq && atoi(p + 1) == lab) + lv = cnt; + } else { + id = _vm->ident(p); + switch (id) { + case kIdMTake: + case kIdFTake: + case kIdNear: + case kIdPhase: + case kIdSeq: + section = id; + break; + default: + if (id < 0 && section == snq) + ++cnt; + break; + } + } + } + } + } + return lv; } CommandHandler::Command *Sprite::snList(Action type) { -- cgit v1.2.3 From 85c55333b334f18f795118a3a3e4a2d2c210253b Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 10 Jun 2014 14:38:30 +0200 Subject: CGE2: Handle kCmdSetRef. Fix Snail during the process. --- engines/cge2/snail.cpp | 7 +++++-- engines/cge2/spare.cpp | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 3af4c88d37..6957f8f50e 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -488,8 +488,11 @@ void CGE2Engine::snFlag(int ref, int val) { warning("STUB: CGE2Engine::snFlag()"); } -void CGE2Engine::snSetRef(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snSetRef()"); +void CGE2Engine::snSetRef(Sprite *spr, int val) { // TODO:: Recheck this! + if (spr) { + spr->_ref = val; + _spare->update(spr); + } } void CGE2Engine::snBackPt(Sprite *spr, int val) { diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 445247177d..63e85e8ed6 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -79,6 +79,8 @@ void Spare::update(Sprite *spr) { Sprite *sp = locate(spr->_ref); if (sp == nullptr) store(spr); + else + *sp = *spr; } void Spare::dispose(Sprite *spr) { -- cgit v1.2.3 From 5a5fe344a0f26f164b4908109bbf7cfa39e6c47f Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 10 Jun 2014 17:27:59 +0200 Subject: CGE2: Implement display of speech bubbles. The sound code connected to them is still gappy. --- engines/cge2/bitmap.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/bitmap.h | 9 ++++++- engines/cge2/cge2.cpp | 2 ++ engines/cge2/cge2.h | 3 +++ engines/cge2/general.h | 2 -- engines/cge2/snail.cpp | 21 ++++++++++++++-- engines/cge2/text.cpp | 45 ++++++++++++++++++++++++++++++++- engines/cge2/vga13h.cpp | 10 +++++++- 8 files changed, 150 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index ff7c3e1998..7a7a88430c 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -28,7 +28,7 @@ #include "cge2/bitmap.h" #include "cge2/cge2.h" #include "cge2/vga13h.h" -//#include "cge/cge_main.h" +#include "cge2/talk.h" #include "common/system.h" #include "common/debug.h" #include "common/debug-channels.h" @@ -393,4 +393,68 @@ bool Bitmap::moveLo() { return true; } +#define _ kPixelTransp, +#define L 1, +#define G 2, +#define D 3, +#define kDesignSize 240 + +uint8 *Bitmap::paint(int which, uint8 colorSet[][4]) { + uint8 kSLDesign[kDesignSize] = { + G G G G G G G G G _ _ _ _ _ _ + L G G G G G G G G D _ _ _ _ _ + _ L G G G G G G G D _ _ _ _ _ + _ _ L G G G G G G G D _ _ _ _ + _ _ _ L G G G G G G D _ _ _ _ + _ _ _ _ L G G G G G D _ _ _ _ + _ _ _ _ _ L G G G G G D _ _ _ + _ _ _ _ _ _ L G G G G D _ _ _ + _ _ _ _ _ _ _ L G G G D _ _ _ + _ _ _ _ _ _ _ _ L G G G D _ _ + _ _ _ _ _ _ _ _ _ L G G D _ _ + _ _ _ _ _ _ _ _ _ _ L G D _ _ + _ _ _ _ _ _ _ _ _ _ _ L G D _ + _ _ _ _ _ _ _ _ _ _ _ _ L D _ + _ _ _ _ _ _ _ _ _ _ _ _ _ L D + _ _ _ _ _ _ _ _ _ _ _ _ _ _ D + }; + + uint8 kSRDesign[kDesignSize] = { + _ _ _ _ _ _ G G G G G G G G G + _ _ _ _ _ L G G G G G G G G D + _ _ _ _ _ L G G G G G G G D _ + _ _ _ _ L G G G G G G G D _ _ + _ _ _ _ L G G G G G G D _ _ _ + _ _ _ _ L G G G G G D _ _ _ _ + _ _ _ L G G G G G D _ _ _ _ _ + _ _ _ L G G G G D _ _ _ _ _ _ + _ _ _ L G G G D _ _ _ _ _ _ _ + _ _ L G G G D _ _ _ _ _ _ _ _ + _ _ L G G D _ _ _ _ _ _ _ _ _ + _ _ L G D _ _ _ _ _ _ _ _ _ _ + _ L G D _ _ _ _ _ _ _ _ _ _ _ + _ L D _ _ _ _ _ _ _ _ _ _ _ _ + L D _ _ _ _ _ _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ _ _ _ _ _ _ + }; + + uint8 *des = new uint8[kDesignSize]; + switch (which) { + case 0: + memcpy(des, kSLDesign, sizeof(kSLDesign)); + break; + case 1: + memcpy(des, kSRDesign, sizeof(kSRDesign)); + break; + default: + error("Wrong parameter in Bitmap::paint!"); + break; + } + + for (int i = 0; i < kDesignSize; i++) + if (des[i] >= 1 && des[i] <= 3) + des[i] = colorSet[kCBSay][des[i]]; + return des; +} + } // End of namespace CGE2 diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index bcc51d874f..8bff8fe99c 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -37,7 +37,8 @@ class CGE2Engine; class EncryptedStream; class V2D; -#define kMaxPath 128 +#define kMaxPath 128 + enum { kBmpEOI = 0x0000, kBmpSKP = 0x4000, @@ -56,9 +57,13 @@ struct HideDesc { class Bitmap { CGE2Engine *_vm; + char *forceExt(char *buf, const char *name, const char *ext); bool loadVBM(EncryptedStream *f); public: + static uint8 *kSLDesign; + static uint8 *kSRDesign; + uint16 _w; uint16 _h; uint8 *_v; @@ -82,6 +87,8 @@ public: void xLatPos(V2D& p); bool moveHi(); bool moveLo(); + + static uint8 *paint(int des, uint8 colorSet[][4]); }; diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index b32ca76489..565615c9ed 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -94,6 +94,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _endGame = false; for (int i = 0; i < 4; i++) _flag[i] = false; + _sayCap = true; + _sayVox = true; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index ebee2edbd7..a3d6f99a22 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -189,6 +189,7 @@ public: void snRoom(Sprite *spr, int val); void snDim(Sprite *spr, int val); void snGhost(Bitmap *bmp); + void snSay(Sprite *spr, int val); void hide1(Sprite *spr); @@ -214,6 +215,8 @@ public: bool _taken; bool _endGame; bool _flag[4]; + bool _sayCap; + bool _sayVox; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/general.h b/engines/cge2/general.h index 0239402ea3..7213c2e24d 100644 --- a/engines/cge2/general.h +++ b/engines/cge2/general.h @@ -32,8 +32,6 @@ namespace CGE2 { -#define SCR_WID_ 320 - class CGE2Engine; struct Dac { diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 6957f8f50e..aa0988f293 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -126,8 +126,7 @@ void CommandHandler::runCommand() { _vm->snHide(spr, tailCmd._val); break; case kCmdSay: - if (spr && spr->active() && _talkEnable) //-- mouth animation - warning("STUB: CommandHandler::runCommand() - Mouth animation missing!"); + _vm->snSay(spr, tailCmd._val); break; case kCmdInf: if (_talkEnable) @@ -559,6 +558,24 @@ void CGE2Engine::snGhost(Bitmap *bmp) { bmp = nullptr; } +void CGE2Engine::snSay(Sprite *spr, int val) { + if (spr && spr->active() && _commandHandler->_talkEnable) { + //-- mouth animation + if (isHero(spr) && spr->seqTest(-1)) + ((Hero *)spr)->say(); + if (_sayCap) + _text->say(_text->getText(val), spr); + if (_sayVox) { + int i = val; + if (i < 256) + i -= 100; + // TODO: These 2 lines may need some re-check with the whole sound-code! + snSound(spr, i); + _commandStat._wait = &_sound->_smpinf._counter; + } + } +} + void CGE2Engine::hide1(Sprite *spr) { _commandHandlerTurbo->addCommand(kCmdGhost, -1, 0, spr->ghost()); } diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index ac222f9030..83088eab25 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -132,7 +132,50 @@ char *Text::getText(int ref) { } void Text::say(const char *text, Sprite *spr) { - warning("STUB: Text::say()"); + _vm->killText(); + + _vm->_talk = new Talk(_vm, text, kTBRound, kCBSay); + if (!_vm->_talk) + return; + + Speaker *speaker = new Speaker(_vm); + + bool east = spr->_flags._east; + V2D d(_vm, 20, spr->_siz.y - 2); + if (!east) + d.x = -d.x; + if (_vm->isHero(spr)) + d = d.scale(V2D::trunc(spr->_pos3D._z)); + V2D pos = spr->_pos2D + d; + uint16 sw = (speaker->_siz.x >> 1); + if (!east) + sw = -sw; + + if (east) { + if (pos.x + sw + kTextRoundCorner + kCaptionSide >= kScrWidth) + east = false; + } else { + if (pos.x <= kCaptionSide + kTextRoundCorner - sw) + east = true; + } + if (east != (d.x > 0)) { + d.x = -d.x; + sw = -sw; + } + pos.x = spr->_pos2D.x + d.x + sw; + + _vm->_talk->_flags._kill = true; + _vm->_talk->setName(getText(kSayName)); + _vm->_talk->gotoxyz(pos.x, pos.y + speaker->_siz.y - 1, 0); + + speaker->gotoxyz(pos.x, V2D::trunc(_vm->_talk->_pos3D._y) - speaker->_siz.y + 1, 0); + speaker->_flags._slav = true; + speaker->_flags._kill = true; + speaker->setName(getText(kSayName)); + speaker->step(east); + + _vm->_vga->_showQ->append(_vm->_talk); + _vm->_vga->_showQ->append(speaker); } void CGE2Engine::inf(const char *text, bool wideSpace) { diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 486db29061..61b367b7a5 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1114,7 +1114,15 @@ SceneLight::SceneLight(CGE2Engine *vm) : Sprite(vm), _vm(vm) { } Speaker::Speaker(CGE2Engine *vm): Sprite(vm), _vm(vm) { - warning("Speaker::Speaker()"); + // Set the sprite list + BitmapPtr SP = new Bitmap[2]; + uint8 *map = Bitmap::paint(0, _vm->_font->_colorSet); + SP[0] = Bitmap(_vm, 15, 16, map); + delete[] map; + map = Bitmap::paint(1, _vm->_font->_colorSet); + SP[1] = Bitmap(_vm, 15, 16, map); + delete[] map; + setShapeList(SP, 2); } PocLight::PocLight(CGE2Engine *vm): Sprite(vm), _vm(vm) { -- cgit v1.2.3 From 45f8bd755cd6d741f6c342272e01ce1af6464ea7 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 12 Jun 2014 01:18:10 +0200 Subject: CGE2: Fix code computing distance --- engines/cge2/hero.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 5efb24e88d..d6dab6d3f0 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -245,7 +245,7 @@ int Hero::distance(V3D pos) { V3D di = _pos3D - pos; long x = V2D::round(di._x); long z = V2D::round(di._z); - return ((x * x + z * z) * (x * x + z * z)); + return (int)sqrt((long double)(x * x + z * z)); } int Hero::distance(Sprite *spr) { -- cgit v1.2.3 From 207f3c8be22b03b8f33e1f92a9010613747a5d03 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 12 Jun 2014 07:20:55 +0200 Subject: CGE2: Implement FXP code. Still WIP, loadTab to be fixed --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 37 +++++++------------- engines/cge2/fileio.cpp | 4 +++ engines/cge2/fileio.h | 1 + engines/cge2/hero.cpp | 39 +++++++++++---------- engines/cge2/text.cpp | 4 +-- engines/cge2/vga13h.cpp | 39 +++++++++++++++------ engines/cge2/vga13h.h | 86 ++++++++++++++++++++++++++++++++++++++-------- 8 files changed, 142 insertions(+), 69 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index a3d6f99a22..cb5e6205e8 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -43,6 +43,7 @@ class Fx; class Sound; class Text; struct HeroTab; +class FXP; class V3D; class V2D; struct Dac; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 99b0f26c21..2809de16e2 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -702,34 +702,23 @@ void CGE2Engine::loadTab() { for (int i = 0; i < kCaveMax; i++) *(_eyeTab[i]) = *_eye; - /* - if (_resman->exist(kTabName)) { +if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); for (int i = 0; i < kCaveMax; i++) { - for (int j = 0; j < 3; j++) { - signed b = f.readSint16BE(); - unsigned a = f.readUint16BE(); - uint16 round = uint16((long(a) << 16) / 100); - - if (round > 0x7FFF) - b++; - - switch (j) { - case 0: - _eyeTab[i]->_x = b; - break; - case 1: - _eyeTab[i]->_y = b; - break; - case 2: - _eyeTab[i]->_z = b; - break; - } - - } + int16 varI = f.readSint16LE(); + int16 varF = f.readUint16LE(); + _eyeTab[i]->_x = FXP(varI, varF); + + varI = f.readSint16LE(); + varF = f.readUint16LE(); + _eyeTab[i]->_y = FXP(varI, varF); + + varI = f.readSint16LE(); + varF = f.readUint16LE(); + _eyeTab[i]->_z = FXP(varI, varF); } } - */ + warning("STUB: CGE2Engine::loadTab()"); } diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 4fec4a67ca..0ec1bce043 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -228,6 +228,10 @@ signed EncryptedStream::readSint16LE() { return _readStream->readSint16LE(); } +signed EncryptedStream::readUint16LE() { + return _readStream->readUint16LE(); +} + bool EncryptedStream::err() { return (_error & _readStream->err()); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 83a14560ad..6bf59424ef 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -125,6 +125,7 @@ public: unsigned readUint16BE(); signed readSint16BE(); signed readSint16LE(); + signed readUint16LE(); Common::String readLine(); int getLineCount() { return _lineCount; } diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index d6dab6d3f0..2671d0ea60 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -205,8 +205,9 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo } void Hero::setCurrent() { - double m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); - int h = -(V2D::trunc(m * _siz.y)); + FXP m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); + FXP tmp = m * _siz.y; + int h = -(tmp.trunc()); int i = 0; for (; i < kDimMax; i++) { @@ -243,15 +244,15 @@ void Hero::tick() { int Hero::distance(V3D pos) { V3D di = _pos3D - pos; - long x = V2D::round(di._x); - long z = V2D::round(di._z); - return (int)sqrt((long double)(x * x + z * z)); + int x = di._x.round(); + int z = di._z.round(); + return ((int)sqrt((long double)x * x + z * z)); } int Hero::distance(Sprite *spr) { V3D pos = spr->_pos3D; int mdx = (spr->_siz.x >> 1) + (_siz.x >> 1); - int dx = V2D::round(_pos3D._x - spr->_pos3D._x); + int dx = (_pos3D._x - spr->_pos3D._x).round(); if (dx < 0) { mdx = -mdx; if (dx > mdx) @@ -303,8 +304,8 @@ int Hero::len(V2D v) { } bool Hero::findWay(){ - V2D p0(_vm, V2D::round(_pos3D._x), V2D::round(_pos3D._z)); - V2D p1(_vm, V2D::round(_trace[_tracePtr]._x), V2D::round(_trace[_tracePtr]._z)); + V2D p0(_vm, _pos3D._x.round(), _pos3D._z.round()); + V2D p1(_vm, _trace[_tracePtr]._x.round(), _trace[_tracePtr]._z.round()); bool pvOk; bool phOk; V2D ph(_vm, p1.x, p0.y); @@ -340,12 +341,12 @@ void Hero::walkTo(V3D pos) { if (distance(pos) <= _maxDist) return; int stp = stepSize(); - pos._x = snap(V2D::round(_pos3D._x), V2D::round(pos._x), stp); + pos._x = snap(_pos3D._x.round(), pos._x.round(), stp); pos._y = 0; - pos._z = snap(V2D::round(_pos3D._z), V2D::round(pos._z), stp); + pos._z = snap(_pos3D._z.round(), pos._z.round(), stp); - V2D p0(_vm, V2D::round(_pos3D._x), V2D::round(_pos3D._z)); - V2D p1(_vm, V2D::round(pos._x), V2D::round(pos._z)); + V2D p0(_vm, _pos3D._x.round(), _pos3D._z.round()); + V2D p1(_vm, pos._x.round(), pos._z.round()); resetFun(); int cnt = mapCross(p0, p1); if ((cnt & 1) == 0) { // even == way exists @@ -385,15 +386,15 @@ void Hero::walkTo(Sprite *spr) { } V3D Hero::screenToGround(V2D pos) { - double z = _vm->_eye->_z + (_vm->_eye->_y * _vm->_eye->_z) / (double(pos.y) - _vm->_eye->_y); - double x = _vm->_eye->_x - ((double(pos.x) - _vm->_eye->_x) * (z - _vm->_eye->_z)) / _vm->_eye->_z; - return V3D(V2D::round(x), 0, V2D::round(z)); + FXP z = _vm->_eye->_z + (_vm->_eye->_y * _vm->_eye->_z) / (FXP(pos.y) - _vm->_eye->_y); + FXP x = _vm->_eye->_x - ((FXP(pos.x) - _vm->_eye->_x) * (z - _vm->_eye->_z)) / _vm->_eye->_z; + return V3D(x.round(), 0, z.round()); } int Hero::cross(const V2D &a, const V2D &b) { - int x = V2D::trunc(_pos3D._x); - int z = V2D::trunc(_pos3D._z); - int r = ((_siz.x / 3) * V2D::trunc(_vm->_eye->_z)) / (V2D::trunc(_vm->_eye->_z) - z); + int x = _pos3D._x.trunc(); + int z = _pos3D._z.trunc(); + int r = ((_siz.x / 3) * _vm->_eye->_z.trunc()) / (_vm->_eye->_z.trunc()- z); return _vm->cross(a, b, V2D(_vm, x - r, z), V2D(_vm, x + r, z)) << 1; } @@ -433,7 +434,7 @@ int Hero::mapCross(const V2D &a, const V2D &b) { } int Hero::mapCross(const V3D &a, const V3D &b) { - return mapCross(V2D(_vm, V2D::round(a._x), V2D::round(a._z)), V2D(_vm, V2D::round(b._x), V2D::round(b._z))); + return mapCross(V2D(_vm, a._x.round(), a._z.round()), V2D(_vm, b._x.round(), b._z.round())); } int CGE2Engine::mapCross(const V2D &a, const V2D &b) { diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 83088eab25..cf4dda4703 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -145,7 +145,7 @@ void Text::say(const char *text, Sprite *spr) { if (!east) d.x = -d.x; if (_vm->isHero(spr)) - d = d.scale(V2D::trunc(spr->_pos3D._z)); + d = d.scale(spr->_pos3D._z.trunc()); V2D pos = spr->_pos2D + d; uint16 sw = (speaker->_siz.x >> 1); if (!east) @@ -168,7 +168,7 @@ void Text::say(const char *text, Sprite *spr) { _vm->_talk->setName(getText(kSayName)); _vm->_talk->gotoxyz(pos.x, pos.y + speaker->_siz.y - 1, 0); - speaker->gotoxyz(pos.x, V2D::trunc(_vm->_talk->_pos3D._y) - speaker->_siz.y + 1, 0); + speaker->gotoxyz(pos.x, _vm->_talk->_pos3D._y.trunc() - speaker->_siz.y + 1, 0); speaker->_flags._slav = true; speaker->_flags._kill = true; speaker->setName(getText(kSayName)); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 61b367b7a5..e59e82579e 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -531,9 +531,9 @@ void Sprite::gotoxyz(V2D pos) { byte trim = 0; if (_ref / 10 == 14) { // HERO - int z = V2D::trunc(_pos3D._z); - ctr = (ctr * V2D::trunc(_vm->_eye->_z) / (V2D::trunc(_vm->_eye->_z) - z)); - rem = (rem * V2D::trunc(_vm->_eye->_z) / (V2D::trunc(_vm->_eye->_z) - z)); + int z = _pos3D._z.trunc(); + ctr = (ctr * _vm->_eye->_z.trunc()) / (_vm->_eye->_z.trunc() - z); + rem = (rem * _vm->_eye->_z.trunc()) / (_vm->_eye->_z.trunc() - z); ctr = (ctr * 3) / 4; rem = (rem * 3) / 4; } @@ -561,10 +561,15 @@ void Sprite::gotoxyz(V2D pos) { _flags._trim = (trim != 0); if (!_follow) { - double m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); - _pos3D._x = V2D::round(_vm->_eye->_x + (_vm->_eye->_x - _pos2D.x) / m); - if (!_constY) - _pos3D._y = V2D::round(_vm->_eye->_y + (_vm->_eye->_y - _pos2D.y) / m); + // CHECKME: Original was using Pos2d.Eye, which shouldn't make a difference (static var) + FXP m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); + _pos3D._x = (_vm->_eye->_x + (_vm->_eye->_x - _pos2D.x) / m); + _pos3D._x.round(); + + if (!_constY) { + _pos3D._y = _vm->_eye->_y + (_vm->_eye->_y - _pos2D.y) / m; + _pos3D._y.round(); + } } if (_next && _next->_flags._slav) @@ -685,9 +690,23 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(flags); } - s.syncAsUint16LE(_pos3D._x); - s.syncAsUint16LE(_pos3D._y); - s.syncAsByte(_pos3D._z); + int pos = 0; + if (s.isLoading()) { + s.syncAsSint16LE(pos); + _pos3D._x = FXP(pos, 0); + s.syncAsSint16LE(pos); + _pos3D._y = pos; + s.syncAsSint16LE(pos); + _pos3D._z = pos; + } else { + pos = _pos3D._x.trunc(); + s.syncAsUint16LE(pos); + pos = _pos3D._y.trunc(); + s.syncAsUint16LE(pos); + pos = _pos3D._z.trunc(); + s.syncAsByte(pos); + } + s.syncAsUint16LE(_time); s.syncAsSint16LE(_seqPtr); s.syncAsUint16LE(_shpCnt); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 09eb61accf..73667bca91 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -51,19 +51,74 @@ namespace CGE2 { #define kPalCount 256 #define kPalSize (kPalCount * 3) +// From FXP.H +class FXP // fixed point +{ + uint16 f; + int16 i; + long& Joined (void) const { return *(long *)&f; } +public: + FXP (void) { } + FXP (int i0, int f0 = 0) : i(i0), f((int) ((((long) f0) << 16)/100)) { } + FXP& operator = (const int& x) { i = x; f = 0; return *this; } + FXP operator + (const FXP& x) const { FXP y; y.Joined() = Joined()+x.Joined(); return y; } + FXP operator - (const FXP& x) const { FXP y; y.Joined() = Joined()-x.Joined(); return y; } + FXP operator * (const FXP& x) const { + FXP y; long t; + y.i = i * x.i; + t = ((long) f * x.f) >> 16; + t += ((long) i * x.f) + ((long) f * x.i); + y.f = t & 0xFFFF; + y.i += t >> 16; + return y; + } + FXP operator / (const FXP& x) const { + FXP y; bool sign = false; + long j = Joined(), jx = x.Joined(); + if (j < 0) { + j = -j; + sign ^= 1; + } + if (jx < 0) { + jx = -jx; + sign ^= 1; + } + y.i = signed(j / jx); + long r = j - jx * y.i; + //-- binary division + y.f = unsigned((r << 4) / (jx >> 12)); + //------------------ + if (sign) + y.Joined() = -y.Joined(); + + return y; + } + //int& operator = (int& a, const FXP& b) { return a = b.i; } + friend int& operator += (int& a, const FXP& b) { return a += b.i; } + friend int& operator -= (int& a, const FXP& b) { return a -= b.i; } + friend FXP& operator += (FXP& a, const int& b) { a.i += b; return a; } + friend FXP& operator -= (FXP& a, const int& b) { a.i -= b; return a; } + friend bool operator == (const FXP &a, const FXP &b) { return (a.i == b.i) && (a.f == b.f); } + friend bool operator != (const FXP &a, const FXP &b) { return (a.i != b.i) || (a.f != b.f); } + friend bool operator < (const FXP &a, const FXP &b) { return (a.i < b.i) || ((a.i == b.i) && (a.f < b.f)); } + friend bool operator > (const FXP &a, const FXP &b) { return (a.i > b.i) || ((a.i == b.i) && (a.f > b.f)); } + int trunc(void) const { return i; } + int round(void) const { return i + (f > 0x7FFF); } +}; + // From CGETYPE.H: class V3D { public: - double _x, _y, _z; + FXP _x, _y, _z; V3D() { } - V3D(double x, double y, double z = 0) : _x(x), _y(y), _z(z) { } + V3D(FXP x, FXP y, FXP z = 0) : _x(x), _y(y), _z(z) { } V3D(const V3D &p) : _x(p._x), _y(p._y), _z(p._z) { } V3D operator+(const V3D &p) const { return V3D(_x + p._x, _y + p._y, _z + p._z); } V3D operator-(const V3D &p) const { return V3D(_x - p._x, _y - p._y, _z - p._z); } V3D operator*(long n) const { return V3D(_x * n, _y * n, _z * n); } V3D operator/ (long n) const { return V3D(_x / n, _y / n, _z / n); } - bool operator==(V3D &p) const { return _x == p._x && _y == p._y && _z == p._z; } - bool operator!=(V3D &p) const { return _x != p._x || _y != p._y || _z != p._z; } + bool operator==(const V3D &p) const { return _x == p._x && _y == p._y && _z == p._z; } + bool operator!=(const V3D &p) const { return _x != p._x || _y != p._y || _z != p._z; } V3D& operator+=(const V3D &x) { return *this = *this + x; } V3D& operator-=(const V3D &x) { return *this = *this - x; } }; @@ -72,11 +127,11 @@ class V2D : public Common::Point { CGE2Engine *_vm; public: V2D& operator=(const V3D &p3) { - if (p3._z == 200) - warning(""); - double m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); - x = round(_vm->_eye->_x + (_vm->_eye->_x - p3._x) * m); - y = round(_vm->_eye->_y + (_vm->_eye->_y - p3._y) * m); + FXP m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); + FXP posx = _vm->_eye->_x + (_vm->_eye->_x - p3._x) * m; + x = posx.round(); + FXP posy = _vm->_eye->_y + (_vm->_eye->_y - p3._y) * m; + y = posy.round(); return *this; } V2D(CGE2Engine *vm) : _vm(vm) { } @@ -88,14 +143,17 @@ public: bool operator>=(const V2D &p) const { return (x >= p.x) && (y >= p.y); } V2D operator+(const V2D &p) const { return V2D(_vm, x + p.x, y + p.y); } V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); } + bool operator==(const V3D &p) const { V3D tmp(x, y); return tmp._x == p._x && tmp._y == p._y && tmp._z == p._z; } + bool operator!=(const V3D &p) const { V3D tmp(x, y); return tmp._x != p._x || tmp._y != p._y || tmp._z == p._z; } uint16 area() { return x * y; } bool limited(const V2D &p) { - return (uint16(x) < uint16(p.x)) && (uint16(y) < uint16(p.y)); + return ((x < p.x) && (y < p.y)); } - V2D scale(int z) { - double m = _vm->_eye->_z / (_vm->_eye->_z - z); - warning("scale: %f %f %f, x, y, m"); - return V2D(_vm, trunc(m * x), trunc(m * y)); + V2D scale (int z) { + FXP m = _vm->_eye->_z / (_vm->_eye->_z - z); + FXP posx = m * x; + FXP posy = m * y; + return V2D(_vm, posx.trunc(), posy.trunc()); } static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } static double round(double number) { return number < 0.0 ? ceil(number) : floor(number); } -- cgit v1.2.3 From dfc94267d568a8e7b261961417fdf5716717cbd0 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 12 Jun 2014 21:05:19 +0200 Subject: CGE2: Get somewhat better values --- engines/cge2/cge2_main.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 2809de16e2..032c73cb2a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -705,16 +705,28 @@ void CGE2Engine::loadTab() { if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); for (int i = 0; i < kCaveMax; i++) { - int16 varI = f.readSint16LE(); - int16 varF = f.readUint16LE(); + int16 varI = f.readSint16BE(); + int16 varF = f.readUint16BE(); + if (varF & 0x8000) { + varI = -varI; + varF &= 0x7FFF; + } _eyeTab[i]->_x = FXP(varI, varF); - varI = f.readSint16LE(); - varF = f.readUint16LE(); + varI = f.readSint16BE(); + varF = f.readUint16BE(); + if (varF & 0x8000) { + varI = -varI; + varF &= 0x7FFF; + } _eyeTab[i]->_y = FXP(varI, varF); - varI = f.readSint16LE(); - varF = f.readUint16LE(); + varI = f.readSint16BE(); + varF = f.readUint16BE(); + if (varF & 0x8000) { + varI = -varI; + varF &= 0x7FFF; + } _eyeTab[i]->_z = FXP(varI, varF); } } -- cgit v1.2.3 From 162c840937027ae2935fddd7d660c28713a7b004 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 12 Jun 2014 23:49:06 -0400 Subject: CGE2: Fix FXP initialiation and division operator --- engines/cge2/vga13h.h | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 73667bca91..dee551fe82 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -58,7 +58,7 @@ class FXP // fixed point int16 i; long& Joined (void) const { return *(long *)&f; } public: - FXP (void) { } + FXP (void): f(0), i(0) { } FXP (int i0, int f0 = 0) : i(i0), f((int) ((((long) f0) << 16)/100)) { } FXP& operator = (const int& x) { i = x; f = 0; return *this; } FXP operator + (const FXP& x) const { FXP y; y.Joined() = Joined()+x.Joined(); return y; } @@ -74,22 +74,24 @@ public: } FXP operator / (const FXP& x) const { FXP y; bool sign = false; - long j = Joined(), jx = x.Joined(); - if (j < 0) { - j = -j; - sign ^= 1; + if (!x.empty()) { + long j = Joined(), jx = x.Joined(); + if (j < 0) { + j = -j; + sign ^= 1; + } + if (jx < 0) { + jx = -jx; + sign ^= 1; + } + y.i = signed(j / jx); + long r = j - jx * y.i; + //-- binary division + y.f = unsigned((r << 4) / (jx >> 12)); + //------------------ + if (sign) + y.Joined() = -y.Joined(); } - if (jx < 0) { - jx = -jx; - sign ^= 1; - } - y.i = signed(j / jx); - long r = j - jx * y.i; - //-- binary division - y.f = unsigned((r << 4) / (jx >> 12)); - //------------------ - if (sign) - y.Joined() = -y.Joined(); return y; } @@ -104,6 +106,7 @@ public: friend bool operator > (const FXP &a, const FXP &b) { return (a.i > b.i) || ((a.i == b.i) && (a.f > b.f)); } int trunc(void) const { return i; } int round(void) const { return i + (f > 0x7FFF); } + bool empty() const { return i == 0 && f == 0; } }; // From CGETYPE.H: -- cgit v1.2.3 From 6ac5e2cfcfa3e13b3eb93c88790c7babcb7af6d2 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 14:07:19 +0200 Subject: CGE2: Fix initialization of HeroTab. --- engines/cge2/hero.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'engines') diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index c9933867a1..26b6dcc12a 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -46,6 +46,11 @@ struct HeroTab { int _pocPtr; V2D *_posTab[kCaveMax]; HeroTab(CGE2Engine *vm) { + _ptr = nullptr; + _face = nullptr; + for (int i = 0; i < kPocketMax + 1; i++) + _pocket[i] = nullptr; + _pocPtr = 0; for (int i = 0; i < kCaveMax; i++) _posTab[i] = new V2D(vm); } -- cgit v1.2.3 From 95c844a0351d8865aa5190bb5572dff23b8886fd Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 16:13:36 +0200 Subject: CGE2: Implement snKill(). Add and implement Sprite::setCave() during the process. --- engines/cge2/snail.cpp | 18 +++++++++++++++++- engines/cge2/vga13h.cpp | 4 ++++ engines/cge2/vga13h.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index aa0988f293..07cded033e 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -30,6 +30,7 @@ #include "cge2/hero.h" #include "cge2/text.h" #include "cge2/sound.h" +#include "cge2/events.h" namespace CGE2 { @@ -324,7 +325,22 @@ void CommandHandler::runCommand() { } void CGE2Engine::snKill(Sprite *spr) { - warning("STUB: CGE2Engine::snKill()"); + if (spr) { + if (spr->_flags._kept) + releasePocket(spr); + Sprite *nx = spr->_next; + hide1(spr); + _vga->_showQ->remove(spr); + _eventManager->clearEvent(spr); + if (spr->_flags._kill) + delete spr; + else { + spr->setCave(-1); + _spare->dispose(spr); + } + if (nx && nx->_flags._slav) + snKill(nx); + } } void CGE2Engine::snHide(Sprite *spr, int val) { diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index e59e82579e..28f738c6c7 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -516,6 +516,10 @@ void Sprite::tick() { step(); } +void Sprite::setCave(int c) { + _scene = c; +} + void Sprite::gotoxyz(int x, int y, int z) { gotoxyz(V3D(x, y, z)); } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index dee551fe82..c864e481af 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -262,6 +262,7 @@ public: CommandHandler::Command *snList(Action type); virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); virtual void tick(); + virtual void setCave(int c); void clrHide() { if (_ext) _ext->_b0 = NULL; } void sync(Common::Serializer &s); -- cgit v1.2.3 From 2ad2be370e6464a660170ff19a0c74d6fb77e055 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 16:31:32 +0200 Subject: CGE2: Implement Hero::tick(). --- engines/cge2/hero.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 2671d0ea60..a4d0441569 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -239,7 +239,62 @@ Sprite *Hero::setContact() { } void Hero::tick() { - warning("STUB: Hero::tick()"); + int z = _pos3D._z.trunc(); + //-- maybe not exactly wid/2, but wid/3 ? + int d = ((_siz.x / 2) * _vm->_eye->_z.trunc()) / (_vm->_eye->_z.trunc() - z); + + if (_dir != kNoDir) { // just walking... + if (_flags._hold || _tracePtr < 0) + park(); + else { + Sprite *spr = setContact(); + if (spr) + _vm->feedSnail(spr, kNear, this); + } + } + //--------------------------------------------------------------- + if (_tracePtr >= 0) { + if (distance(_trace[_tracePtr]) <= _maxDist) + --_tracePtr; + + if (_tracePtr < 0) + park(); + else { + int stp = stepSize() / 2; + int dx = _trace[_tracePtr]._x.round() - _pos3D._x.round(); + int dz = _trace[_tracePtr]._z.round() - _pos3D._z.round(); + Dir dir = (dx > stp) ? kEE : ((-dx > stp) ? kWW : ((dz > stp) ? kNN : kSS)); + turn(dir); + } + } + + //--------------------------------------------------------------- + hStep(); + setCurrent(); + switch (_dir) { + case kSS: + if (_pos3D._z < stepSize() / 2) + park(); + break; + case kWW: + if (_pos2D.x <= d) + park(); + break; + case kNN: + if (_pos3D._z > kScrDepth) + park(); + break; + case kEE: + if (_pos2D.x >= kScrWidth - 1 - d) + park(); + break; + } + if (_flags._trim) + gotoxyz_(_pos2D); + if (_pos3D._z.trunc() != z) + _flags._zmov = true; + if (--_funDel == 0) + fun(); } int Hero::distance(V3D pos) { -- cgit v1.2.3 From bad8e7ea26a645affa74e2971fdac87e4afc20e7 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 17:02:17 +0200 Subject: CGE2: Fix Sprite::ghost and snGhost(). --- engines/cge2/snail.cpp | 2 +- engines/cge2/vga13h.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 07cded033e..c086d2b17b 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -565,7 +565,7 @@ void CGE2Engine::snDim(Sprite *spr, int val) { } void CGE2Engine::snGhost(Bitmap *bmp) { - V2D p(this, *bmp->_v & 0xFFFF, *bmp->_v >> 16); + V2D p(this, bmp->_map & 0xFFFF, bmp->_map >> 16); bmp->hide(p.x, p.y); delete[] bmp->_b; bmp->_v = nullptr; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 28f738c6c7..24987813a5 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -641,6 +641,7 @@ BitmapPtr Sprite::ghost() { uint8 *v = new uint8; *v = (e->_p1.y << 16) + e->_p1.x; bmp->_v = v; + bmp->_map = (e->_p1.y << 16) + e->_p1.x; return bmp; } -- cgit v1.2.3 From 235d0fffbd0f827b6dd43ba52a934417b75efbab Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 19:36:36 +0200 Subject: CGE2: Reimplement Hero::setCave(). --- engines/cge2/hero.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index a4d0441569..87e74f0bda 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -513,7 +513,7 @@ int CGE2Engine::mapCross(const V2D &a, const V2D &b) { } void Hero::setCave(int c) { - _scene = c; + Sprite::setCave(c); resetFun(); } -- cgit v1.2.3 From 3aae5cfa06c0753f20631fe2843f69f08f0ae6fd Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 19:39:24 +0200 Subject: CGE2: Implement Hero::hStep(). --- engines/cge2/hero.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 87e74f0bda..d2c1b64874 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -219,7 +219,20 @@ void Hero::setCurrent() { } void Hero::hStep() { - warning("STUB: Hero::hStep()"); + if (!_ignoreMap && _ext) { + Seq *seq = _ext->_seq; + int ptr = seq[_seqPtr]._next; + seq += ptr; + if (seq->_dx | seq->_dz) { + V2D p0(_vm, _pos3D._x.round(), _pos3D._z.round()); + V2D p1(_vm, p0.x + seq->_dx, p0.y + seq->_dz); + if (mapCross(p0, p1)) { + park(); + return; + } + } + } + step(); } Sprite *Hero::setContact() { -- cgit v1.2.3 From 95e3f240d620f5e3788743782ef910446a01ab79 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 19:41:43 +0200 Subject: CGE2: Implement Hero::turn(). --- engines/cge2/hero.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index d2c1b64874..49d1361f42 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -337,7 +337,12 @@ int Hero::distance(Sprite *spr) { } void Hero::turn(Dir d) { - warning("STUB: Hero::turn()"); + Dir dir = (_dir == kNoDir) ? kSS : _dir; + if (d != _dir) { + step((d == dir) ? 57 : (8 + 4 * dir + d)); + _dir = d; + } + resetFun(); } void Hero::park() { -- cgit v1.2.3 From 0bd781a3dcb844ffc570166ee53084ed1b643c00 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 19:52:28 +0200 Subject: CGE2: Implement releasePocket(). --- engines/cge2/cge2_main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 032c73cb2a..655910ff2a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -685,7 +685,16 @@ void CGE2Engine::loadPos() { } void CGE2Engine::releasePocket(Sprite *spr) { - warning("STUB: CGE2Engine::releasePocket()"); + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax; j++) { + Sprite *poc = _heroTab[i]->_pocket[j]; + if (poc == spr) { + spr->_flags._kept = false; + poc = nullptr; + return; + } + } + } } void CGE2Engine::checkSaySwitch() { -- cgit v1.2.3 From 52fb03fc97d852a0a5c19d72599d678ac536514d Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 22:19:41 +0200 Subject: CGE2: Fix Sprite::touch(). Not it only takes action if the user actually clicked. --- engines/cge2/cge2_main.cpp | 96 +++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 47 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 655910ff2a..d9d22c84b1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -910,57 +910,59 @@ void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { return; } - if (_vm->isHero(this) && !_vm->_blinkSprite) { - _vm->switchHero((this == _vm->_heroTab[1]->_ptr) ? 1 : 0); - } else if (_flags._kept) { // sprite in pocket - for (int sex = 0; sex < 2; ++sex) { - for (int p = 0; p < kPocketMax; ++p) { - if (_vm->_heroTab[sex]->_pocket[p] == this) { - _vm->switchHero(sex); - if (_vm->_sex == sex) { - if (_vm->_blinkSprite) - _vm->_blinkSprite->_flags._hide = false; - if (_vm->_blinkSprite == this) - _vm->_blinkSprite = nullptr; - else - _vm->_blinkSprite = this; + if ((mask & kMouseLeftUp) && _vm->_commandHandler->idle()) { + if (_vm->isHero(this) && !_vm->_blinkSprite) { + _vm->switchHero((this == _vm->_heroTab[1]->_ptr) ? 1 : 0); + } else if (_flags._kept) { // sprite in pocket + for (int sex = 0; sex < 2; ++sex) { + for (int p = 0; p < kPocketMax; ++p) { + if (_vm->_heroTab[sex]->_pocket[p] == this) { + _vm->switchHero(sex); + if (_vm->_sex == sex) { + if (_vm->_blinkSprite) + _vm->_blinkSprite->_flags._hide = false; + if (_vm->_blinkSprite == this) + _vm->_blinkSprite = nullptr; + else + _vm->_blinkSprite = this; + } } } } - } - } else { // sprite NOT in pocket - Hero *h = _vm->_heroTab[_vm->_sex]->_ptr; - if (!_vm->_talk) { - if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1)) - h->walkTo(this); - else if (_vm->_blinkSprite) { - if (works(_vm->_blinkSprite)) { - _vm->feedSnail(_vm->_blinkSprite, (_vm->_sex) ? kMTake : kFTake, _vm->_heroTab[_vm->_sex]->_ptr); - _vm->_blinkSprite->_flags._hide = false; - _vm->_blinkSprite = nullptr; - } else - _vm->offUse(); - - _vm->selectPocket(-1); - // else, no pocket sprite selected - } else if (_flags._port) { // portable - if (_vm->findActivePocket(-1) < 0) - _vm->pocFul(); - else { - _vm->_commandHandler->addCommand(kCmdReach, -2, _ref, nullptr); - _vm->_commandHandler->addCommand(kCmdKeep, -1, -1, this); - _flags._port = false; - } - } else { // non-portable - Action a = h->action(); - if (_actionCtrl[a]._cnt) { - CommandHandler::Command *cmdList = snList(a); - if (cmdList[_actionCtrl[a]._ptr]._commandType == kCmdNext) + } else { // sprite NOT in pocket + Hero *h = _vm->_heroTab[_vm->_sex]->_ptr; + if (!_vm->_talk) { + if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1)) + h->walkTo(this); + else if (_vm->_blinkSprite) { + if (works(_vm->_blinkSprite)) { + _vm->feedSnail(_vm->_blinkSprite, (_vm->_sex) ? kMTake : kFTake, _vm->_heroTab[_vm->_sex]->_ptr); + _vm->_blinkSprite->_flags._hide = false; + _vm->_blinkSprite = nullptr; + } else _vm->offUse(); - else - _vm->feedSnail(this, a, h); - } else - _vm->offUse(); + + _vm->selectPocket(-1); + // else, no pocket sprite selected + } else if (_flags._port) { // portable + if (_vm->findActivePocket(-1) < 0) + _vm->pocFul(); + else { + _vm->_commandHandler->addCommand(kCmdReach, -2, _ref, nullptr); + _vm->_commandHandler->addCommand(kCmdKeep, -1, -1, this); + _flags._port = false; + } + } else { // non-portable + Action a = h->action(); + if (_actionCtrl[a]._cnt) { + CommandHandler::Command *cmdList = snList(a); + if (cmdList[_actionCtrl[a]._ptr]._commandType == kCmdNext) + _vm->offUse(); + else + _vm->feedSnail(this, a, h); + } else + _vm->offUse(); + } } } } -- cgit v1.2.3 From 63c0cb40feb9acfb600503688358af28da4f14b7 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 22:20:19 +0200 Subject: CGE2: Stub snSay again. --- engines/cge2/snail.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index c086d2b17b..ee94ab8894 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -585,9 +585,7 @@ void CGE2Engine::snSay(Sprite *spr, int val) { int i = val; if (i < 256) i -= 100; - // TODO: These 2 lines may need some re-check with the whole sound-code! - snSound(spr, i); - _commandStat._wait = &_sound->_smpinf._counter; + warning("STUB: CGE2Engine::snSay"); // TODO: Implement it with the revision of the sound code! } } } -- cgit v1.2.3 From 2b5eec4427814e501f4a11103befedaf4628f528 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 22:29:39 +0200 Subject: CGE2: Implement snCover and snUncover. Also add and implement expandSprite(). --- engines/cge2/cge2.h | 1 + engines/cge2/snail.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index cb5e6205e8..968fe2bb41 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -193,6 +193,7 @@ public: void snSay(Sprite *spr, int val); void hide1(Sprite *spr); + Sprite *expandSprite(Sprite *spr); const ADGameDescription *_gameDescription; diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index ee94ab8894..86ce006e4a 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -416,12 +416,40 @@ void CGE2Engine::snSend(Sprite *spr, int val) { void CGE2Engine::snSwap(Sprite *spr, int val) { warning("STUB: CGE2Engine::snSwap()"); } + void CGE2Engine::snCover(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snCover()"); + bool tak = _taken; + Sprite *xspr = locate(val); + if (spr && xspr) { + spr->_flags._hide = true; + xspr->setCave(spr->_scene); + xspr->gotoxyz(spr->_pos3D); + expandSprite(xspr); + if ((xspr->_flags._shad = spr->_flags._shad) == true) { + _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); + spr->_flags._shad = false; + } + feedSnail(xspr, kNear, _heroTab[_sex]->_ptr); + _taken = false; + } + if (_taken) + _spare->dispose(xspr); + _taken = tak; } void CGE2Engine::snUncover(Sprite *spr, Sprite *spr2) { - warning("STUB: CGE2Engine::snUncover()"); + if (spr && spr2) { + spr->_flags._hide = false; + spr->setCave(spr2->_scene); + if ((spr->_flags._shad = spr2->_flags._shad) == true) { + _vga->_showQ->insert(_vga->_showQ->remove(spr2->_prev), spr); + spr2->_flags._shad = false; + } + spr->gotoxyz(spr2->_pos3D); + snSend(spr2, -1); + if (spr->_time == 0) + ++spr->_time; + } } void CGE2Engine::snFocus(int val) { @@ -594,6 +622,12 @@ void CGE2Engine::hide1(Sprite *spr) { _commandHandlerTurbo->addCommand(kCmdGhost, -1, 0, spr->ghost()); } +Sprite *CGE2Engine::expandSprite(Sprite *spr) { + if (spr) + _vga->_showQ->insert(spr); + return spr; +} + void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { if (ref == 2) ref = 142 - _vm->_sex; -- cgit v1.2.3 From a2c3a11708840f7b21d971241ad2b1fa70d74025 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 13 Jun 2014 22:36:32 +0200 Subject: CGE2: Rename setCave() to setScene(). --- engines/cge2/hero.cpp | 4 ++-- engines/cge2/hero.h | 2 +- engines/cge2/snail.cpp | 6 +++--- engines/cge2/vga13h.cpp | 2 +- engines/cge2/vga13h.h | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 49d1361f42..f68cf82539 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -530,8 +530,8 @@ int CGE2Engine::mapCross(const V2D &a, const V2D &b) { return cnt; } -void Hero::setCave(int c) { - Sprite::setCave(c); +void Hero::setScene(int c) { + Sprite::setScene(c); resetFun(); } diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 26b6dcc12a..69ee7b7810 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -102,7 +102,7 @@ public: Action action() { return (Action)(_ref % 10); } void reach(int mode); void setCurrent(); - void setCave(int c); + void setScene(int c); void operator++(); void operator--(); }; diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 86ce006e4a..bf9108df26 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -335,7 +335,7 @@ void CGE2Engine::snKill(Sprite *spr) { if (spr->_flags._kill) delete spr; else { - spr->setCave(-1); + spr->setScene(-1); _spare->dispose(spr); } if (nx && nx->_flags._slav) @@ -422,7 +422,7 @@ void CGE2Engine::snCover(Sprite *spr, int val) { Sprite *xspr = locate(val); if (spr && xspr) { spr->_flags._hide = true; - xspr->setCave(spr->_scene); + xspr->setScene(spr->_scene); xspr->gotoxyz(spr->_pos3D); expandSprite(xspr); if ((xspr->_flags._shad = spr->_flags._shad) == true) { @@ -440,7 +440,7 @@ void CGE2Engine::snCover(Sprite *spr, int val) { void CGE2Engine::snUncover(Sprite *spr, Sprite *spr2) { if (spr && spr2) { spr->_flags._hide = false; - spr->setCave(spr2->_scene); + spr->setScene(spr2->_scene); if ((spr->_flags._shad = spr2->_flags._shad) == true) { _vga->_showQ->insert(_vga->_showQ->remove(spr2->_prev), spr); spr2->_flags._shad = false; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 24987813a5..71e472f766 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -516,7 +516,7 @@ void Sprite::tick() { step(); } -void Sprite::setCave(int c) { +void Sprite::setScene(int c) { _scene = c; } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index c864e481af..67506c8739 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -262,7 +262,7 @@ public: CommandHandler::Command *snList(Action type); virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); virtual void tick(); - virtual void setCave(int c); + virtual void setScene(int c); void clrHide() { if (_ext) _ext->_b0 = NULL; } void sync(Common::Serializer &s); -- cgit v1.2.3 From 28717ff056015d3aafdb1c91b7535cdc82a235cf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 13 Jun 2014 23:22:44 -0400 Subject: CGE2: Fix vertical screen clipping in Bitmap::show and Bitmap::hide --- engines/cge2/vga13h.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 71e472f766..302d12938f 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1064,8 +1064,11 @@ void Bitmap::show(int16 x, int16 y) { xLatPos(pos); x = pos.x; y = pos.y; + + // TODO: This doesn't currently support left/right side clipping const byte *srcP = (const byte *)_v; - byte *destEndP = (byte *)_vm->_vga->_page[1]->getBasePtr(0, kScrHeight); + byte *screenStartP = (byte *)_vm->_vga->_page[1]->getPixels(); + byte *screenEndP = (byte *)_vm->_vga->_page[1]->getBasePtr(0, kScrHeight); // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data @@ -1084,8 +1087,6 @@ void Bitmap::show(int16 x, int16 y) { break; } - assert(destP < destEndP); - // Handle a set of pixels while (count-- > 0) { // Transfer operation @@ -1095,11 +1096,14 @@ void Bitmap::show(int16 x, int16 y) { break; case 2: // REPEAT - *destP = *srcP; + if (destP >= screenStartP && destP < screenEndP) + *destP = *srcP; break; case 3: // COPY - *destP = *srcP++; + if (destP >= screenStartP && destP < screenEndP) + *destP = *srcP; + srcP++; break; } @@ -1120,10 +1124,12 @@ void Bitmap::hide(int16 x, int16 y) { x = pos.x; y = pos.y; for (int yp = y; yp < y + _h; yp++) { - const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(x, yp); - byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x, yp); + if (yp >= 0 && yp < kScrHeight) { + const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(x, yp); + byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x, yp); - Common::copy(srcP, srcP + _w, destP); + Common::copy(srcP, srcP + _w, destP); + } } } -- cgit v1.2.3 From 3d63184fee4e8b533763ecf2cae187f76954ac97 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 14 Jun 2014 19:46:18 +0200 Subject: CGE2: Rethink Spare::dispose(). --- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/spare.cpp | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index d9d22c84b1..9a736efdf0 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -370,7 +370,7 @@ void CGE2Engine::loadScript(const char *fname) { int n = _spare->count(); if (_spare->locate(_sprite->_ref) == nullptr) - _spare->store(_sprite); + _spare->dispose(_sprite); _sprite = nullptr; if (_spare->count() == n) error("Durplicated reference! %s", SpN); diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 63e85e8ed6..9531fe68f2 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -87,16 +87,6 @@ void Spare::dispose(Sprite *spr) { if (spr) { _vm->_vga->_showQ->remove(spr); update(spr->contract()); - if (!_vm->isHero(spr)) { - for (uint i = 0; i < _container.size(); ++i) { - if (spr == _container[i]) { - _container.remove_at(i); - delete spr; - spr = nullptr; - break; - } - } - } } } -- cgit v1.2.3 From 58c312d9e9ac5d78e39ee2ddbb40305bba689aec Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 14 Jun 2014 20:13:08 +0200 Subject: CGE2: Implement snReach() and connected functions. --- engines/cge2/hero.cpp | 23 ++++++++++++++++++++--- engines/cge2/snail.cpp | 18 ++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index f68cf82539..2090d497c1 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -360,12 +360,29 @@ void Hero::park() { } bool Hero::lower(Sprite * spr) { - warning("STUB: Hero::lower()"); - return false; + return (spr->_pos3D._y + (spr->_siz.y >> 2) < 10); } void Hero::reach(int mode) { - warning("STUB: Hero::reach()"); + Sprite *spr = nullptr; + if (mode >= 4) { + spr = _vm->_vga->_showQ->locate(mode); + if (spr) { + mode = !spr->_flags._east; // 0-1 + if (lower(spr)) // 2-3 + mode += 2; + } + } + // note: insert SNAIL commands in reverse order + _vm->_commandHandler->insertCommand(kCmdPause, -1, 24, nullptr); + _vm->_commandHandler->insertCommand(kCmdSeq, -1, _reachStart + _reachCycle * mode, this); + if (spr) { + _vm->_commandHandler->insertCommand(kCmdWait, -1, -1, this); + _vm->_commandHandler->insertCommand(kCmdWalk, -1, spr->_ref, this); + } + // sequence is not finished, + // now it is just at sprite appear (disappear) point + resetFun(); } void Hero::fun() { diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index bf9108df26..f8664b4ea0 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -559,7 +559,8 @@ void CGE2Engine::snWalk(Sprite *spr, int val) { } void CGE2Engine::snReach(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snReach()"); + if (isHero(spr)) + ((Hero *)spr)->reach(val); } void CGE2Engine::snSound(Sprite *spr, int wav) { @@ -647,7 +648,20 @@ void CommandHandler::addCallback(CommandType com, int ref, int val, CallbackType } void CommandHandler::insertCommand(CommandType com, int ref, int val, void *ptr) { - warning("STUB: CommandHandler::insertCommand()"); + if (ref == -2) + ref = 142 - _vm->_sex; + --_tail; + Command *tailCmd = &_commandList[_tail]; + tailCmd->_commandType = com; + tailCmd->_ref = ref; + tailCmd->_val = val; + tailCmd->_spritePtr = ptr; + tailCmd->_cbType = kNullCB; + if (com == kCmdClear) { + _tail = _head; + _vm->killText(); + _timerExpiry = 0; + } } bool CommandHandler::idle() { -- cgit v1.2.3 From 600c32adf91a3fa4d8c54e4b7f85bd8cc06b6746 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 14 Jun 2014 20:27:26 +0200 Subject: CGE2: Implement snWalk(). --- engines/cge2/snail.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index f8664b4ea0..6b9ade6d58 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -555,7 +555,16 @@ void CGE2Engine::snCycle(int cnt) { } void CGE2Engine::snWalk(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snWalk()"); + if (isHero(spr)) { + if (val < kMaxPoint) + ((Hero *)spr)->walkTo(*_point[val]); + else { + Sprite *s = _vga->_showQ->locate(val); + if (s) + ((Hero *)spr)->walkTo(s); + } + ((Hero *)spr)->_time = 1; + } } void CGE2Engine::snReach(Sprite *spr, int val) { -- cgit v1.2.3 From c48c585f88a4c037e3fe5f2363a7aaca1946b343 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 14 Jun 2014 19:34:30 -0400 Subject: CGE2: Fix loading of fixed-point integer values --- engines/cge2/cge2_main.cpp | 33 +++++++++------------------------ engines/cge2/fileio.cpp | 4 ++++ engines/cge2/fileio.h | 1 + engines/cge2/vga13h.cpp | 1 - engines/cge2/vga13h.h | 2 +- 5 files changed, 15 insertions(+), 26 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9a736efdf0..802b72ed4d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -711,36 +711,21 @@ void CGE2Engine::loadTab() { for (int i = 0; i < kCaveMax; i++) *(_eyeTab[i]) = *_eye; -if (_resman->exist(kTabName)) { + if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); + uint32 v; + for (int i = 0; i < kCaveMax; i++) { - int16 varI = f.readSint16BE(); - int16 varF = f.readUint16BE(); - if (varF & 0x8000) { - varI = -varI; - varF &= 0x7FFF; - } - _eyeTab[i]->_x = FXP(varI, varF); + v = f.readUint32LE(); + _eyeTab[i]->_x = FXP(v >> 8, static_cast((int8)(v & 0xff))); - varI = f.readSint16BE(); - varF = f.readUint16BE(); - if (varF & 0x8000) { - varI = -varI; - varF &= 0x7FFF; - } - _eyeTab[i]->_y = FXP(varI, varF); + v = f.readUint32LE(); + _eyeTab[i]->_y = FXP(v >> 8, static_cast((int8)(v & 0xff))); - varI = f.readSint16BE(); - varF = f.readUint16BE(); - if (varF & 0x8000) { - varI = -varI; - varF &= 0x7FFF; - } - _eyeTab[i]->_z = FXP(varI, varF); + v = f.readUint32LE(); + _eyeTab[i]->_z = FXP(v >> 8, static_cast((int8)(v & 0xff))); } } - - warning("STUB: CGE2Engine::loadTab()"); } void CGE2Engine::cge2_main() { diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 0ec1bce043..cc07ef6fc1 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -232,6 +232,10 @@ signed EncryptedStream::readUint16LE() { return _readStream->readUint16LE(); } +uint32 EncryptedStream::readUint32LE() { + return _readStream->readUint32LE(); +} + bool EncryptedStream::err() { return (_error & _readStream->err()); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 6bf59424ef..093850735a 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -126,6 +126,7 @@ public: signed readSint16BE(); signed readSint16LE(); signed readUint16LE(); + uint32 readUint32LE(); Common::String readLine(); int getLineCount() { return _lineCount; } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 302d12938f..5c3b59b084 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1065,7 +1065,6 @@ void Bitmap::show(int16 x, int16 y) { x = pos.x; y = pos.y; - // TODO: This doesn't currently support left/right side clipping const byte *srcP = (const byte *)_v; byte *screenStartP = (byte *)_vm->_vga->_page[1]->getPixels(); byte *screenEndP = (byte *)_vm->_vga->_page[1]->getBasePtr(0, kScrHeight); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 67506c8739..90889718d5 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -59,7 +59,7 @@ class FXP // fixed point long& Joined (void) const { return *(long *)&f; } public: FXP (void): f(0), i(0) { } - FXP (int i0, int f0 = 0) : i(i0), f((int) ((((long) f0) << 16)/100)) { } + FXP (int i0, int f0 = 0) : i(i0), f(0) { } FXP& operator = (const int& x) { i = x; f = 0; return *this; } FXP operator + (const FXP& x) const { FXP y; y.Joined() = Joined()+x.Joined(); return y; } FXP operator - (const FXP& x) const { FXP y; y.Joined() = Joined()-x.Joined(); return y; } -- cgit v1.2.3 From 0f923c7e98d183a93f3f9415f34c81acd0615049 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 15 Jun 2014 11:12:13 +0200 Subject: CGE2: Change the Flags structure to make use of booleans --- engines/cge2/vga13h.cpp | 32 ++++++++++++++++---------------- engines/cge2/vga13h.h | 32 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 5c3b59b084..ba652a6260 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -676,22 +676,22 @@ void Sprite::sync(Common::Serializer &s) { _flags._zmov = flags & 0x4000 ? true : false; _flags._tran = flags & 0x8000 ? true : false; } else { - flags = (flags << 1) | _flags._tran; - flags = (flags << 1) | _flags._zmov; - flags = (flags << 1) | _flags._back; - flags = (flags << 1) | _flags._shad; - flags = (flags << 1) | _flags._near; - flags = (flags << 1) | _flags._east; - flags = (flags << 1) | _flags._frnt; - flags = (flags << 1) | _flags._kept; - flags = (flags << 1) | _flags._port; - flags = (flags << 1) | _flags._xlat; - flags = (flags << 1) | _flags._kill; - flags = (flags << 1) | _flags._slav; - flags = (flags << 1) | _flags._trim; - flags = (flags << 1) | _flags._hold; - flags = (flags << 1) | _flags._drag; - flags = (flags << 1) | _flags._hide; + flags = (flags << 1) | (_flags._tran ? 1 : 0); + flags = (flags << 1) | (_flags._zmov ? 1 : 0); + flags = (flags << 1) | (_flags._back ? 1 : 0); + flags = (flags << 1) | (_flags._shad ? 1 : 0); + flags = (flags << 1) | (_flags._near ? 1 : 0); + flags = (flags << 1) | (_flags._east ? 1 : 0); + flags = (flags << 1) | (_flags._frnt ? 1 : 0); + flags = (flags << 1) | (_flags._kept ? 1 : 0); + flags = (flags << 1) | (_flags._port ? 1 : 0); + flags = (flags << 1) | (_flags._xlat ? 1 : 0); + flags = (flags << 1) | (_flags._kill ? 1 : 0); + flags = (flags << 1) | (_flags._slav ? 1 : 0); + flags = (flags << 1) | (_flags._trim ? 1 : 0); + flags = (flags << 1) | (_flags._hold ? 1 : 0); + flags = (flags << 1) | (_flags._drag ? 1 : 0); + flags = (flags << 1) | (_flags._hide ? 1 : 0); s.syncAsUint16LE(flags); } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 90889718d5..359c20fc9f 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -193,22 +193,22 @@ public: int _ref; signed char _scene; struct Flags { - uint16 _hide : 1; // general visibility switch - uint16 _drag : 1; // sprite is moveable - uint16 _hold : 1; // sprite is held with mouse - uint16 _trim : 1; // Trim flag - uint16 _slav : 1; // slave object - uint16 _kill : 1; // dispose memory after remove - uint16 _xlat : 1; // 2nd way display: xlat table - uint16 _port : 1; // portable - uint16 _kept : 1; // kept in pocket - uint16 _frnt : 1; // stay in front of sprite - uint16 _east : 1; // talk to east (in opposite to west) - uint16 _near : 1; // Near action lock - uint16 _shad : 1; // shadow - uint16 _back : 1; // 'send to background' request - uint16 _zmov : 1; // sprite needs Z-update in queue - uint16 _tran : 1; // transparent (untouchable) + bool _hide : true; // general visibility switch + bool _drag : true; // sprite is moveable + bool _hold : true; // sprite is held with mouse + bool _trim : true; // Trim flag + bool _slav : true; // slave object + bool _kill : true; // dispose memory after remove + bool _xlat : true; // 2nd way display: xlat table + bool _port : true; // portable + bool _kept : true; // kept in pocket + bool _frnt : true; // stay in front of sprite + bool _east : true; // talk to east (in opposite to west) + bool _near : true; // Near action lock + bool _shad : true; // shadow + bool _back : true; // 'send to background' request + bool _zmov : true; // sprite needs Z-update in queue + bool _tran : true; // transparent (untouchable) } _flags; V2D _pos2D; V3D _pos3D; -- cgit v1.2.3 From c82246ee555581e22231c69c83b9abdac84c70ab Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 15 Jun 2014 11:25:56 +0200 Subject: CGE2: remove useless code related to boolean values --- engines/cge2/vga13h.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index ba652a6260..48c0b1be11 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -659,22 +659,22 @@ void Sprite::sync(Common::Serializer &s) { uint16 flags = 0; if (s.isLoading()) { s.syncAsUint16LE(flags); - _flags._hide = flags & 0x0001 ? true : false; - _flags._drag = flags & 0x0002 ? true : false; - _flags._hold = flags & 0x0004 ? true : false; - _flags._trim = flags & 0x0008 ? true : false; - _flags._slav = flags & 0x0010 ? true : false; - _flags._kill = flags & 0x0020 ? true : false; - _flags._xlat = flags & 0x0040 ? true : false; - _flags._port = flags & 0x0080 ? true : false; - _flags._kept = flags & 0x0100 ? true : false; - _flags._frnt = flags & 0x0200 ? true : false; - _flags._east = flags & 0x0400 ? true : false; - _flags._near = flags & 0x0800 ? true : false; - _flags._shad = flags & 0x1000 ? true : false; - _flags._back = flags & 0x2000 ? true : false; - _flags._zmov = flags & 0x4000 ? true : false; - _flags._tran = flags & 0x8000 ? true : false; + _flags._hide = flags & 0x0001; + _flags._drag = flags & 0x0002; + _flags._hold = flags & 0x0004; + _flags._trim = flags & 0x0008; + _flags._slav = flags & 0x0010; + _flags._kill = flags & 0x0020; + _flags._xlat = flags & 0x0040; + _flags._port = flags & 0x0080; + _flags._kept = flags & 0x0100; + _flags._frnt = flags & 0x0200; + _flags._east = flags & 0x0400; + _flags._near = flags & 0x0800; + _flags._shad = flags & 0x1000; + _flags._back = flags & 0x2000; + _flags._zmov = flags & 0x4000; + _flags._tran = flags & 0x8000; } else { flags = (flags << 1) | (_flags._tran ? 1 : 0); flags = (flags << 1) | (_flags._zmov ? 1 : 0); -- cgit v1.2.3 From ae96463036ff99540478b7355746d8fd653ff527 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 15 Jun 2014 20:52:25 +0200 Subject: CGE2: Rework EventManager::handleEvents(). Also add and implement spriteAt() during the process. --- engines/cge2/cge2.h | 1 + engines/cge2/events.cpp | 55 ++++++++++++++++++------------------------------- engines/cge2/events.h | 2 ++ engines/cge2/talk.cpp | 14 +++++++++++++ 4 files changed, 37 insertions(+), 35 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 968fe2bb41..611976819b 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -139,6 +139,7 @@ public: long det(const V2D &a, const V2D &b, const V2D &c); int sgn(long n); int mapCross(const V2D &a, const V2D &b); + Sprite *spriteAt(V2D pos); void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index a143c77a7d..79455aff66 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -62,7 +62,7 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ -Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { +Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _point(_vm), _vm(vm) { _hold = NULL; _hx = 0; _hy = 0; @@ -181,42 +181,31 @@ void EventManager::poll() { void EventManager::handleEvents() { while (_eventQueueTail != _eventQueueHead) { CGE2Event e = _eventQueue[_eventQueueTail]; + _vm->_mouse->_point = V2D(_vm, e._x, e._y); if (e._mask) { - if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) - _vm->_mouse->_hold->touch(e._mask | kEventAttn, e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y, e._keyCode); - - // update mouse cursor position - if (e._mask & kMouseRoll) - _vm->_mouse->gotoxyz(e._x, e._y); + if (e._mask & kMouseMask) { + e._spritePtr = _vm->spriteAt(_vm->_mouse->_point); + e._x += (_vm->_mouse->_siz.x >> 1); + e._y -= _vm->_mouse->_siz.y; + if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) { + _vm->_mouse->_hold->touch(e._mask | kEventAttn, + e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y, e._keyCode); + } + // update mouse cursor position + if (e._mask & kMouseRoll) + _vm->_mouse->gotoxyz(V2D(_vm, e._x, e._y)); + } // activate current touched SPRITE if (e._spritePtr) { if (e._mask & kEventKeyb) - e._spritePtr->touch(e._mask, e._x, e._y, e._keyCode); - else - e._spritePtr->touch(e._mask, e._x - e._spritePtr->_pos2D.x, e._y - e._spritePtr->_pos2D.y, e._keyCode); - } else if (_vm->_sys) - _vm->_sys->touch(e._mask, V2D(_vm, e._x, e._y), e._keyCode); - - if (e._mask & kMouseLeftDown) { - _vm->_mouse->_hold = e._spritePtr; - if (_vm->_mouse->_hold) { - _vm->_mouse->_hold->_flags._hold = true; - - if (_vm->_mouse->_hold->_flags._drag) { - _vm->_mouse->_hx = e._x - _vm->_mouse->_hold->_pos2D.x; - _vm->_mouse->_hy = e._y - _vm->_mouse->_hold->_pos2D.y; - } + e._spritePtr->touch(e._mask, _vm->_mouse->_point.x, _vm->_mouse->_point.y, e._keyCode); + else { + V2D temp = _vm->_mouse->_point - e._spritePtr->_pos2D; + e._spritePtr->touch(e._mask, temp.x, temp.y, e._keyCode); } - } - - if (e._mask & kMouseLeftUp) { - if (_vm->_mouse->_hold) { - _vm->_mouse->_hold->_flags._hold = false; - _vm->_mouse->_hold = NULL; - } - } - ///Touched = e.Ptr; + } else if (_vm->_sys) + _vm->_sys->touch(e._mask, _vm->_mouse->_point, e._keyCode); // discard Text if button released if (e._mask & (kMouseLeftUp | kMouseRightUp)) @@ -224,10 +213,6 @@ void EventManager::handleEvents() { } _eventQueueTail = (_eventQueueTail + 1) % kEventMax; } - if (_vm->_mouse->_hold) { - if (_vm->_mouse->_hold->_flags._drag) - _vm->_mouse->_hold->gotoxyz(_vm->_mouse->_pos2D.x - _vm->_mouse->_hx, kWorldHeight - _vm->_mouse->_pos2D.y - _vm->_mouse->_hy); - } } void EventManager::clearEvent(Sprite *spr) { diff --git a/engines/cge2/events.h b/engines/cge2/events.h index 39fbf536b9..2522c34049 100644 --- a/engines/cge2/events.h +++ b/engines/cge2/events.h @@ -45,6 +45,7 @@ enum EventMask { kMouseRightDown = 1 << 3, kMouseRightUp = 1 << 4, kEventAttn = 1 << 5, + kMouseMask = (kMouseRoll | kMouseLeftDown | kMouseLeftUp | kMouseRightDown | kMouseRightUp), kEventKeyb = 1 << 7 }; @@ -75,6 +76,7 @@ struct CGE2Event { class Mouse : public Sprite { public: + V2D _point; Sprite *_hold; bool _active; int _hx; diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index a6d9945665..54e9ea3764 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -34,6 +34,20 @@ void CGE2Engine::setAutoColors() { warning("STUB: CGE2Engine::setAutoColors()"); } +Sprite *CGE2Engine::spriteAt(V2D pos) { + Sprite *spr; + + for (spr = _vga->_showQ->last(); spr; spr = spr->_prev) { + if (!spr->_flags._hide && !spr->_flags._tran) { + V2D temp = pos - spr->_pos2D; + if (spr->getShp()->solidAt(temp.x, temp.y)) + break; + } + } + + return spr; +} + Font::Font(CGE2Engine *vm) : _vm(vm) { _map = new uint8[kMapSize]; _pos = new uint16[kPosSize]; -- cgit v1.2.3 From baffdd97e22851ad050bbeb1e800e38606b8f4c1 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 15 Jun 2014 21:11:27 +0200 Subject: CGE2: Fix coordinates of mouse handling. Now infoLine is working properly. Rework solidAt() to achieve that. Also move spriteAt from talk.cpp to cge2_main.cpp, and remove the older version which didn't use V2D as a parameter. --- engines/cge2/bitmap.cpp | 11 +++++++---- engines/cge2/bitmap.h | 2 +- engines/cge2/cge2.h | 1 - engines/cge2/cge2_main.cpp | 23 ++++++++++++----------- engines/cge2/events.cpp | 2 +- engines/cge2/talk.cpp | 14 -------------- 6 files changed, 21 insertions(+), 32 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 7a7a88430c..c62a784110 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -274,13 +274,16 @@ BitmapPtr Bitmap::code(uint8 *map) { return this; } -bool Bitmap::solidAt(int16 x, int16 y) { - if ((x >= _w) || (y >= _h)) +bool Bitmap::solidAt(V2D pos) { + pos.x += _w >> 1; + pos.y = _h - pos.y; + + if (!pos.limited(V2D(_vm, _w, _h))) return false; uint8 *m = _v; - uint16 r = static_cast(x) % 4; - uint16 n0 = (kScrWidth * y + x) / 4; + uint16 r = static_cast(pos.x) % 4; + uint16 n0 = (kScrWidth * pos.y + pos.x) / 4; uint16 n = 0; while (r) { diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 8bff8fe99c..2c7b31b110 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -83,7 +83,7 @@ public: void release(); void hide(int16 x, int16 y); void show(int16 x, int16 y); - bool solidAt(int16 x, int16 y); + bool solidAt(V2D pos); void xLatPos(V2D& p); bool moveHi(); bool moveLo(); diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 611976819b..0206a3ce6d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -123,7 +123,6 @@ public: void mainLoop(); void handleFrame(); Sprite *locate(int ref); - Sprite *spriteAt(int x, int y); bool isHero(Sprite *spr); void loadUser(); void checkSaySwitch(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 802b72ed4d..198f4a359e 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -868,17 +868,6 @@ void CGE2Engine::switchHero(int sex) { _commandHandler->addCommand(kCmdSeq, -1, 1, face); } -Sprite *CGE2Engine::spriteAt(int x, int y) { - Sprite *spr = NULL, *queueTail = _vga->_showQ->last(); - if (queueTail) { - for (spr = queueTail->_prev; spr; spr = spr->_prev) { - if (!spr->_flags._hide && !spr->_flags._tran && spr->getShp()->solidAt(x - spr->_pos2D.x, y - spr->_pos2D.y)) - break; - } - } - return spr; -} - #pragma argsused void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { if ((mask & kEventAttn) != 0) @@ -961,5 +950,17 @@ void CGE2Engine::offUse() { warning("STUB: CGE2Engine::offUse()"); } +Sprite *CGE2Engine::spriteAt(V2D pos) { + Sprite *spr; + + for (spr = _vga->_showQ->last(); spr; spr = spr->_prev) { + if (!spr->_flags._hide && !spr->_flags._tran) { + if (spr->getShp()->solidAt(pos - spr->_pos2D)) + break; + } + } + + return spr; +} } // End of namespace CGE2 diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 79455aff66..c3433dfb87 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -117,7 +117,7 @@ void Mouse::newMouse(Common::Event &event) { evt._x = event.mouse.x; evt._y = event.mouse.y; evt._keyCode = Common::KEYCODE_INVALID; - evt._spritePtr = _vm->spriteAt(evt._x, evt._y); + evt._spritePtr = _vm->spriteAt(V2D(_vm, evt._x, evt._y)); switch (event.type) { case Common::EVENT_MOUSEMOVE: diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 54e9ea3764..a6d9945665 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -34,20 +34,6 @@ void CGE2Engine::setAutoColors() { warning("STUB: CGE2Engine::setAutoColors()"); } -Sprite *CGE2Engine::spriteAt(V2D pos) { - Sprite *spr; - - for (spr = _vga->_showQ->last(); spr; spr = spr->_prev) { - if (!spr->_flags._hide && !spr->_flags._tran) { - V2D temp = pos - spr->_pos2D; - if (spr->getShp()->solidAt(temp.x, temp.y)) - break; - } - } - - return spr; -} - Font::Font(CGE2Engine *vm) : _vm(vm) { _map = new uint8[kMapSize]; _pos = new uint16[kPosSize]; -- cgit v1.2.3 From e3b5686c43fe1f2f05d7d760d6377a4d3cafce7a Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 15 Jun 2014 21:23:14 +0200 Subject: CGE2: Rename caves to scenes. --- engines/cge2/cge2.cpp | 6 +++--- engines/cge2/cge2.h | 8 ++++---- engines/cge2/cge2_main.cpp | 22 +++++++++++----------- engines/cge2/hero.h | 6 +++--- engines/cge2/snail.cpp | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 565615c9ed..135f786de0 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -54,7 +54,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) for (int i = 0; i < 2; i++) _heroTab[i] = nullptr; _eye = nullptr; - for (int i = 0; i < kCaveMax; i++) + for (int i = 0; i < kSceneMax; i++) _eyeTab[i] = nullptr; _spare = nullptr; _commandHandler = nullptr; @@ -108,7 +108,7 @@ void CGE2Engine::init() { for (int i = 0; i < 2; i++) _heroTab[i] = new HeroTab(this); _eye = new V3D(); - for (int i = 0; i < kCaveMax; i++) + for (int i = 0; i < kSceneMax; i++) _eyeTab[i] = new V3D(); _spare = new Spare(this); _commandHandler = new CommandHandler(this, false); @@ -133,7 +133,7 @@ void CGE2Engine::deinit() { delete _text; for (int i = 0; i < 2; i++) delete _heroTab[i]; - for (int i = 0; i < kCaveMax; i++) { + for (int i = 0; i < kSceneMax; i++) { delete _eyeTab[i]; } delete _eye; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 0206a3ce6d..e19ca576d3 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -70,7 +70,7 @@ class Map; #define kDimMax 8 #define kWayMax 10 #define kPocketMax 4 -#define kCaveMax 100 +#define kSceneMax 100 #define kMaxPoint 4 #define kInfoX 160 #define kInfoY -11 @@ -107,8 +107,8 @@ public: void loadScript(const char *fname); void loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); - void caveUp(int cav); - void switchCave(int cav); + void sceneUp(int cav); + void switchScene(int cav); void showBak(int ref); void loadTab(); int newRandom(int range); @@ -229,7 +229,7 @@ public: Text *_text; HeroTab *_heroTab[2]; V3D *_eye; - V3D *_eyeTab[kCaveMax]; + V3D *_eyeTab[kSceneMax]; Spare *_spare; CommandHandler *_commandHandler; CommandHandler *_commandHandlerTurbo; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 198f4a359e..f4b90d3e2d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -394,7 +394,7 @@ void CGE2Engine::movie(const char *ext) { int now = _now; _now = atoi(ext + 2); loadScript(fn); - caveUp(_now); + sceneUp(_now); while (!_commandHandler->idle() && !_quitFlag) mainLoop(); @@ -409,7 +409,7 @@ void CGE2Engine::movie(const char *ext) { } } -void CGE2Engine::caveUp(int cav) { +void CGE2Engine::sceneUp(int cav) { _now = cav; int bakRef = _now << 8; if (_music) @@ -418,7 +418,7 @@ void CGE2Engine::caveUp(int cav) { *_eye = *(_eyeTab[_now]); _mouseTop = V2D(this, V3D(0, 1, kScrDepth)).y; _map->load(_now); - _spare->takeCave(_now); + _spare->takeScene(_now); openPocket(); for (int i = 0; i < 2; i++) { @@ -459,8 +459,8 @@ void CGE2Engine::caveUp(int cav) { //setDrawColors(); - It's only for debugging purposes. Can be left out for now. } -void CGE2Engine::switchCave(int cav) { - warning("STUB: CGE2Engine::switchCave()"); +void CGE2Engine::switchScene(int cav) { + warning("STUB: CGE2Engine::switchScene()"); } void CGE2Engine::showBak(int ref) { @@ -575,7 +575,7 @@ void CGE2Engine::runGame() { _infoLine->setText(nullptr); _vga->_showQ->insert(_infoLine); - caveUp(_now); + sceneUp(_now); _startupMode = 0; _mouse->center(); _mouse->off(); @@ -666,12 +666,12 @@ void CGE2Engine::loadGame() { void CGE2Engine::loadPos() { if (_resman->exist("CGE.HXY")) { - for (int cav = 0; cav < kCaveMax; cav++) + for (int cav = 0; cav < kSceneMax; cav++) _heroTab[1]->_posTab[cav] = new V2D(this, 180, 10); EncryptedStream file(this, "CGE.HXY"); - for (int cav = 0; cav < kCaveMax; cav++) { + for (int cav = 0; cav < kSceneMax; cav++) { _heroTab[0]->_posTab[cav]->x = file.readSint16LE(); _heroTab[0]->_posTab[cav]->y = file.readSint16LE(); } @@ -708,14 +708,14 @@ void CGE2Engine::qGame() { void CGE2Engine::loadTab() { setEye(_text->getText(240)); - for (int i = 0; i < kCaveMax; i++) + for (int i = 0; i < kSceneMax; i++) *(_eyeTab[i]) = *_eye; if (_resman->exist(kTabName)) { EncryptedStream f(this, kTabName); uint32 v; - for (int i = 0; i < kCaveMax; i++) { + for (int i = 0; i < kSceneMax; i++) { v = f.readUint32LE(); _eyeTab[i]->_x = FXP(v >> 8, static_cast((int8)(v & 0xff))); @@ -860,7 +860,7 @@ void CGE2Engine::switchHero(int sex) { if (scene >= 0) { _commandHandler->addCommand(kCmdSeq, -1, 2, _heroTab[_sex]->_face); _sex ^= 1; - switchCave(scene); + switchScene(scene); } } Sprite *face = _heroTab[_sex]->_face; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 69ee7b7810..628f7c1580 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -44,18 +44,18 @@ struct HeroTab { Sprite *_face; Sprite *_pocket[kPocketMax + 1]; int _pocPtr; - V2D *_posTab[kCaveMax]; + V2D *_posTab[kSceneMax]; HeroTab(CGE2Engine *vm) { _ptr = nullptr; _face = nullptr; for (int i = 0; i < kPocketMax + 1; i++) _pocket[i] = nullptr; _pocPtr = 0; - for (int i = 0; i < kCaveMax; i++) + for (int i = 0; i < kSceneMax; i++) _posTab[i] = new V2D(vm); } ~HeroTab() { - for (int i = 0; i < kCaveMax; i++) + for (int i = 0; i < kSceneMax; i++) delete _posTab[i]; } }; diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 6b9ade6d58..5e417a1b8c 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -137,7 +137,7 @@ void CommandHandler::runCommand() { warning("STUB: CommandHandler::runCommand() - Something missing connected to kCmdTime!"); break; case kCmdCave: - _vm->switchCave(tailCmd._val); + _vm->switchScene(tailCmd._val); break; case kCmdMidi: _vm->snMidi(tailCmd._val); @@ -381,9 +381,9 @@ void CGE2Engine::snSend(Sprite *spr, int val) { if (!spr) return; - // Sending", spr->File - // from cave", spr->Cave - // to cave", val + // Sending", spr->_file + // from scene", spr->_scene + // to scene", val bool was1 = (_vga->_showQ->locate(spr->_ref) != nullptr); bool val1 = (val == 0 || val == _now); spr->_scene = val; -- cgit v1.2.3 From 7f4af90777136170ca6682e8315725cda9b3c50d Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 15 Jun 2014 21:24:59 +0200 Subject: CGE2: Fix compilation broken by previous commit. --- engines/cge2/spare.cpp | 2 +- engines/cge2/spare.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 9531fe68f2..2977a586f3 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -58,7 +58,7 @@ Sprite *Spare::take(int ref) { return spr; } -void Spare::takeCave(int cav) { +void Spare::takeScene(int cav) { int bakRef = cav << 8; Common::Array tempCont = _container; for (uint i = 0; i < tempCont.size(); ++i) { diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 18909225db..77bdb3319f 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -41,7 +41,7 @@ public: void store(Sprite *spr); Sprite *locate(int ref); Sprite *take(int ref); - void takeCave(int cav); + void takeScene(int cav); void update(Sprite *spr); void dispose(Sprite *spr); void dispose(int ref); -- cgit v1.2.3 From c488c15289d9a5c21fc6bad54c9614f54dd8b3bf Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 15 Jun 2014 21:29:32 +0200 Subject: CGE2: Rework Sprite::touch to use V2D for coords. --- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/events.cpp | 10 ++++------ engines/cge2/vga13h.h | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f4b90d3e2d..c0b41e4756 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -869,7 +869,7 @@ void CGE2Engine::switchHero(int sex) { } #pragma argsused -void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { +void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { if ((mask & kEventAttn) != 0) return; diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index c3433dfb87..0c163a5454 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -189,7 +189,7 @@ void EventManager::handleEvents() { e._y -= _vm->_mouse->_siz.y; if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) { _vm->_mouse->_hold->touch(e._mask | kEventAttn, - e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y, e._keyCode); + V2D(_vm, e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y), e._keyCode); } // update mouse cursor position if (e._mask & kMouseRoll) @@ -199,11 +199,9 @@ void EventManager::handleEvents() { // activate current touched SPRITE if (e._spritePtr) { if (e._mask & kEventKeyb) - e._spritePtr->touch(e._mask, _vm->_mouse->_point.x, _vm->_mouse->_point.y, e._keyCode); - else { - V2D temp = _vm->_mouse->_point - e._spritePtr->_pos2D; - e._spritePtr->touch(e._mask, temp.x, temp.y, e._keyCode); - } + e._spritePtr->touch(e._mask, _vm->_mouse->_point, e._keyCode); + else + e._spritePtr->touch(e._mask, _vm->_mouse->_point - e._spritePtr->_pos2D, e._keyCode); } else if (_vm->_sys) _vm->_sys->touch(e._mask, _vm->_mouse->_point, e._keyCode); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 359c20fc9f..32cf38df59 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -260,7 +260,7 @@ public: void step(int nr = -1); Seq *setSeq(Seq *seq); CommandHandler::Command *snList(Action type); - virtual void touch(uint16 mask, int x, int y, Common::KeyCode keyCode); + virtual void touch(uint16 mask, V2D pos, Common::KeyCode keyCode); virtual void tick(); virtual void setScene(int c); void clrHide() { if (_ext) _ext->_b0 = NULL; } -- cgit v1.2.3 From 9023240545bdadd0ccea93dddae30d1e13f5b107 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 15 Jun 2014 21:33:41 +0200 Subject: CGE2: Rework show() and hide() in Bitmap to use V2Ds as parameters. --- engines/cge2/bitmap.h | 4 ++-- engines/cge2/snail.cpp | 2 +- engines/cge2/vga13h.cpp | 25 ++++++++++--------------- 3 files changed, 13 insertions(+), 18 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 2c7b31b110..e7a4637b87 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -81,8 +81,8 @@ public: Bitmap *code(uint8 *map); Bitmap &operator=(const Bitmap &bmp); void release(); - void hide(int16 x, int16 y); - void show(int16 x, int16 y); + void hide(V2D pos); + void show(V2D pos); bool solidAt(V2D pos); void xLatPos(V2D& p); bool moveHi(); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 5e417a1b8c..068ccf86d5 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -604,7 +604,7 @@ void CGE2Engine::snDim(Sprite *spr, int val) { void CGE2Engine::snGhost(Bitmap *bmp) { V2D p(this, bmp->_map & 0xFFFF, bmp->_map >> 16); - bmp->hide(p.x, p.y); + bmp->hide(p); delete[] bmp->_b; bmp->_v = nullptr; bmp->_b = nullptr; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 48c0b1be11..24376d91bb 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -610,20 +610,20 @@ void Sprite::show() { e->_b1 = getShp(); } if (!_flags._hide) - e->_b1->show(e->_p1.x, e->_p1.y); + e->_b1->show(e->_p1); } void Sprite::show(uint16 pg) { Graphics::Surface *a = _vm->_vga->_page[1]; _vm->_vga->_page[1] = _vm->_vga->_page[pg]; - getShp()->show(_pos2D.x, _pos2D.y); + getShp()->show(_pos2D); _vm->_vga->_page[1] = a; } void Sprite::hide() { SprExt *e = _ext; if (e->_b0) - e->_b0->hide(e->_p0.x, e->_p0.y); + e->_b0->hide(e->_p0); } BitmapPtr Sprite::ghost() { @@ -1059,11 +1059,8 @@ void Vga::copyPage(uint16 d, uint16 s) { _page[d]->copyFrom(*_page[s]); } -void Bitmap::show(int16 x, int16 y) { - V2D pos(_vm, x, y); +void Bitmap::show(V2D pos) { xLatPos(pos); - x = pos.x; - y = pos.y; const byte *srcP = (const byte *)_v; byte *screenStartP = (byte *)_vm->_vga->_page[1]->getPixels(); @@ -1073,7 +1070,7 @@ void Bitmap::show(int16 x, int16 y) { // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data // must be decompressed and inserted into the surface for (int planeCtr = 0; planeCtr < 4; planeCtr++) { - byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x + planeCtr, y); + byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(pos.x + planeCtr, pos.y); for (;;) { uint16 v = READ_LE_UINT16(srcP); @@ -1117,15 +1114,13 @@ void Bitmap::show(int16 x, int16 y) { } -void Bitmap::hide(int16 x, int16 y) { - V2D pos(_vm, x, y); +void Bitmap::hide(V2D pos) { xLatPos(pos); - x = pos.x; - y = pos.y; - for (int yp = y; yp < y + _h; yp++) { + + for (int yp = pos.y; yp < pos.y + _h; yp++) { if (yp >= 0 && yp < kScrHeight) { - const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(x, yp); - byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(x, yp); + const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(pos.x, yp); + byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(pos.x, yp); Common::copy(srcP, srcP + _w, destP); } -- cgit v1.2.3 From 40262bad980ffb0a86492e67c5430b24e6454438 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 15 Jun 2014 22:48:23 +0200 Subject: CGE: Remove (broken) variable length specification --- engines/cge2/vga13h.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 32cf38df59..a6e12fe8a1 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -193,22 +193,22 @@ public: int _ref; signed char _scene; struct Flags { - bool _hide : true; // general visibility switch - bool _drag : true; // sprite is moveable - bool _hold : true; // sprite is held with mouse - bool _trim : true; // Trim flag - bool _slav : true; // slave object - bool _kill : true; // dispose memory after remove - bool _xlat : true; // 2nd way display: xlat table - bool _port : true; // portable - bool _kept : true; // kept in pocket - bool _frnt : true; // stay in front of sprite - bool _east : true; // talk to east (in opposite to west) - bool _near : true; // Near action lock - bool _shad : true; // shadow - bool _back : true; // 'send to background' request - bool _zmov : true; // sprite needs Z-update in queue - bool _tran : true; // transparent (untouchable) + bool _hide; // general visibility switch + bool _drag; // sprite is moveable + bool _hold; // sprite is held with mouse + bool _trim; // Trim flag + bool _slav; // slave object + bool _kill; // dispose memory after remove + bool _xlat; // 2nd way display: xlat table + bool _port; // portable + bool _kept; // kept in pocket + bool _frnt; // stay in front of sprite + bool _east; // talk to east (in opposite to west) + bool _near; // Near action lock + bool _shad; // shadow + bool _back; // 'send to background' request + bool _zmov; // sprite needs Z-update in queue + bool _tran; // transparent (untouchable) } _flags; V2D _pos2D; V3D _pos3D; -- cgit v1.2.3 From 186d90e5b58c09e04f570b51f97a7bd3315dcbde Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 17 Jun 2014 15:37:55 +0200 Subject: CGE2: Implement switching between scenes. Minor modification in Spare again to do so. --- engines/cge2/cge2.cpp | 1 + engines/cge2/cge2.h | 14 ++++++++-- engines/cge2/cge2_main.cpp | 70 +++++++++++++++++++++++++++++++++++++++++----- engines/cge2/snail.cpp | 41 +++++++++++++++++++++++++-- engines/cge2/spare.cpp | 2 +- 5 files changed, 115 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 135f786de0..96beff7195 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -96,6 +96,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _flag[i] = false; _sayCap = true; _sayVox = true; + _req = 1; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index e19ca576d3..bc4a16c33f 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -78,8 +78,11 @@ class Map; #define kPocketsWidth 59 #define kLineMax 512 +#define kExitOkText 40 +#define kCrackedText 44 + enum CallbackType { - kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume + kNullCB = 0, kQGame, kXScene, kSoundSetVolume }; enum Action { kNear, kMTake, kFTake, kActions }; @@ -108,7 +111,9 @@ public: void loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); void sceneUp(int cav); - void switchScene(int cav); + void sceneDown(); + void closePocket(); + void switchScene(int scene); void showBak(int ref); void loadTab(); int newRandom(int range); @@ -126,7 +131,6 @@ public: bool isHero(Sprite *spr); void loadUser(); void checkSaySwitch(); - void qGame(); void loadPos(); void releasePocket(Sprite *spr); void switchHero(int sex); @@ -194,6 +198,9 @@ public: void hide1(Sprite *spr); Sprite *expandSprite(Sprite *spr); + void qGame(); + void xScene(); + void sndSetVolume(); const ADGameDescription *_gameDescription; @@ -219,6 +226,7 @@ public: bool _flag[4]; bool _sayCap; bool _sayVox; + int _req; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index c0b41e4756..0fc2d5af71 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -459,8 +459,69 @@ void CGE2Engine::sceneUp(int cav) { //setDrawColors(); - It's only for debugging purposes. Can be left out for now. } -void CGE2Engine::switchScene(int cav) { - warning("STUB: CGE2Engine::switchScene()"); +void CGE2Engine::sceneDown() { + busy(true); + _commandStat._wait = nullptr; // unlock snail + Sprite *spr = _vga->_showQ->locate((_now << 8) | 254); + if (spr) + feedSnail(spr, kNear, _heroTab[_sex]->_ptr); + while (!(_commandHandler->idle() && _commandHandlerTurbo->idle())) { + _commandHandlerTurbo->runCommand(); + _commandHandler->runCommand(); + } + closePocket(); + for (int i = 0; i < 2; i++) + _spare->update(_vga->_showQ->remove(_heroTab[i]->_ptr)); + _spare->dispose(); +} + +void CGE2Engine::closePocket() { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax + 1; j++) { + Sprite *spr = _heroTab[i]->_pocket[j]; + _heroTab[i]->_pocket[j] = (Sprite*)((spr) ? spr->_ref : -1); + } + } +} + +void CGE2Engine::switchScene(int scene) { + if (scene == _now) + return; + + if (scene >= 0) { + if (!_flag[2]) // PROT + _flag[2] = true; + else { + int t = _text->getText(kCrackedText) ? kCrackedText : kExitOkText; + _commandHandler->addCommand(kCmdInf, -1, t, nullptr); + return; + } + } + + _req = scene; + for (int i = 0; i < 2; i++) { + Hero *h = _heroTab[i]->_ptr; + if (h->_scene == _now) { + delete _heroTab[i]->_posTab[_now]; + V2D *temp = new V2D(this, h->_pos3D._x.trunc(), h->_pos3D._z.trunc()); + _heroTab[i]->_posTab[_now] = temp; + } + } + *(_eyeTab[_now]) = *_eye; + if (scene < 0) + _commandHandler->addCallback(kCmdExec, -1, 0, kQGame); // quit game + else { + if (_heroTab[_sex]->_ptr->_scene == _now) { + _heroTab[_sex]->_ptr->setScene(scene); + if (_heroTab[!_sex]->_ptr->_scene == _now) + _heroTab[!_sex]->_ptr->setScene(scene); + } + _mouse->off(); + if (_heroTab[_sex]->_ptr) + _heroTab[_sex]->_ptr->park(); + killText(); + _commandHandler->addCallback(kCmdExec, -1, 0, kXScene); // switch scene + } } void CGE2Engine::showBak(int ref) { @@ -701,11 +762,6 @@ void CGE2Engine::checkSaySwitch() { warning("STUB: CGE2Engine::checkSaySwitch()"); } -void CGE2Engine::qGame() { - warning("STUB: CGE2Engine::qGame()"); - _endGame = true; -} - void CGE2Engine::loadTab() { setEye(_text->getText(240)); for (int i = 0; i < kSceneMax; i++) diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 068ccf86d5..d799f28cc1 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -301,7 +301,20 @@ void CommandHandler::runCommand() { _vm->snDim(spr, tailCmd._val); break; case kCmdExec: - warning("Unhandled command - kCmdExec"); + switch (tailCmd._cbType) { + case kQGame: + _vm->qGame(); + break; + case kXScene: + _vm->xScene(); + break; + case kSoundSetVolume: + _vm->sndSetVolume(); + break; + default: + error("Unknown Callback Type in SNEXEC"); + break; + } break; case kCmdStep: spr->step(); @@ -638,6 +651,20 @@ Sprite *CGE2Engine::expandSprite(Sprite *spr) { return spr; } +void CGE2Engine::qGame() { + warning("STUB: CGE2Engine::qGame()"); + _endGame = true; +} + +void CGE2Engine::xScene() { + sceneDown(); + sceneUp(_req); +} + +void CGE2Engine::sndSetVolume() { + warning("STUB: CGE2Engine::sndSetVolume()"); +} + void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { if (ref == 2) ref = 142 - _vm->_sex; @@ -653,7 +680,17 @@ void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { } void CommandHandler::addCallback(CommandType com, int ref, int val, CallbackType cbType) { - warning("STUB: CommandHandler::addCallback()"); + Command *headCmd = &_commandList[_head++]; + headCmd->_commandType = com; + headCmd->_ref = ref; + headCmd->_val = val; + headCmd->_spritePtr = NULL; + headCmd->_cbType = cbType; + if (headCmd->_commandType == kCmdClear) { + _tail = _head; + _vm->killText(); + _timerExpiry = 0; + } } void CommandHandler::insertCommand(CommandType com, int ref, int val, void *ptr) { diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 2977a586f3..8382310e1b 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -65,7 +65,7 @@ void Spare::takeScene(int cav) { Sprite *spr = tempCont[i]; int c = spr->_scene; if ((c == _vm->_now || c == 0) && spr->_ref != bakRef) { - spr = take(spr->_ref); + spr = locate(spr->_ref); _vm->_vga->_showQ->insert(spr); } } -- cgit v1.2.3 From 26901479d3e60eed76dfd306988b27408b22e3ee Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 17 Jun 2014 15:38:24 +0200 Subject: CGE2: Fix initialization of _posTab. Fixes a possible memory leak. --- engines/cge2/cge2_main.cpp | 1 + engines/cge2/hero.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 0fc2d5af71..5fa44531df 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -733,6 +733,7 @@ void CGE2Engine::loadPos() { EncryptedStream file(this, "CGE.HXY"); for (int cav = 0; cav < kSceneMax; cav++) { + _heroTab[0]->_posTab[cav] = new V2D(this); _heroTab[0]->_posTab[cav]->x = file.readSint16LE(); _heroTab[0]->_posTab[cav]->y = file.readSint16LE(); } diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 628f7c1580..7ddc871e06 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -52,7 +52,7 @@ struct HeroTab { _pocket[i] = nullptr; _pocPtr = 0; for (int i = 0; i < kSceneMax; i++) - _posTab[i] = new V2D(vm); + _posTab[i] = nullptr; } ~HeroTab() { for (int i = 0; i < kSceneMax; i++) -- cgit v1.2.3 From fb97e24a5adfb117add2cfa959c075a2af569fad Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 18 Jun 2014 20:43:24 +0200 Subject: CGE2: Fix coords of misplaced speech bubbles. The origin of the bug is that when we added the command (triggered by a mouse-click on a sprite) to display a speech bubble we checked the command's reference wrong and didn't bind (by modifying the reference) the bubble to a certain hero. So they just appeared randomly above the sprites what triggered the event, or even in worse places. --- engines/cge2/snail.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index d799f28cc1..e3c3baaccc 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -666,7 +666,7 @@ void CGE2Engine::sndSetVolume() { } void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { - if (ref == 2) + if (ref == -2) ref = 142 - _vm->_sex; Command *headCmd = &_commandList[_head++]; headCmd->_commandType = com; -- cgit v1.2.3 From d85d3229e6a790e9d6caf3a422632d562dcc3e3f Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 18 Jun 2014 22:37:54 +0200 Subject: CGE2: Implement functions connected to inventory handling. Also move closePocket() closer to the others and fix the stub message in busy(). --- engines/cge2/cge2_main.cpp | 38 ++++++++++++++++++++++++++------------ engines/cge2/snail.cpp | 5 +---- 2 files changed, 27 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 5fa44531df..b17f48dacd 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -475,15 +475,6 @@ void CGE2Engine::sceneDown() { _spare->dispose(); } -void CGE2Engine::closePocket() { - for (int i = 0; i < 2; i++) { - for (int j = 0; j < kPocketMax + 1; j++) { - Sprite *spr = _heroTab[i]->_pocket[j]; - _heroTab[i]->_pocket[j] = (Sprite*)((spr) ? spr->_ref : -1); - } - } -} - void CGE2Engine::switchScene(int scene) { if (scene == _now) return; @@ -607,15 +598,38 @@ void CGE2Engine::tick() { } void CGE2Engine::openPocket() { - warning("STUB: CGE2Engine::openPocket()"); + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax + 1; j++) { + int ref = (int)_heroTab[i]->_pocket[j]; + _heroTab[i]->_pocket[j] = (ref == -1) ? nullptr : _vga->_showQ->locate(ref); + } + } +} + +void CGE2Engine::closePocket() { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax + 1; j++) { + Sprite *spr = _heroTab[i]->_pocket[j]; + _heroTab[i]->_pocket[j] = (Sprite*)((spr) ? spr->_ref : -1); + } + } } + void CGE2Engine::selectPocket(int n) { - warning("STUB: CGE2Engine::selectPocket()"); + Sprite **p = _heroTab[_sex]->_pocket; + int &pp = _heroTab[_sex]->_pocPtr; + if (n < 0 || pp == n) { + n = findActivePocket(-1); + if (n >= 0) + pp = n; + } else if (p[n]) { + pp = n; + } } void CGE2Engine::busy(bool on) { - warning("STUB: CGE2Engine::selectPocket()"); + warning("STUB: CGE2Engine::busy()"); } void CGE2Engine::runGame() { diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index e3c3baaccc..3a17168893 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -740,9 +740,6 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { CommandHandler::Command *c = &comtab[ptr]; CommandHandler::Command *q = &comtab[cnt]; - warning("STUB: CGE2Engine::feedSnail()"); - // Dont bother with pockets (inventory system) for now... TODO: Implement it later!!! - /* int pocFre = freePockets(hero->_ref & 1); int pocReq = 0; CommandHandler::Command *p = c; @@ -771,7 +768,7 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { pocFul(); return; } - }*/ + } while (c < q) { if (c->_commandType == kCmdTalk) { -- cgit v1.2.3 From ea5697d5a0ff66c7e93db4e53c881980df0a5971 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 18 Jun 2014 22:58:33 +0200 Subject: CGE2: Implement snKeep(). Now the inventory system is (at least partially) working. --- engines/cge2/snail.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 3a17168893..d40789c6d1 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -469,8 +469,39 @@ void CGE2Engine::snFocus(int val) { warning("STUB: CGE2Engine::snFocus()"); } -void CGE2Engine::snKeep(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snKeep()"); +void CGE2Engine::snKeep(Sprite *spr, int stp) { + int sex = _sex; + if (stp > 127) { + _sex = stp & 1; // for another hero + stp = -1; + } + HeroTab *ht = _heroTab[_sex]; + selectPocket(-1); + int pp = ht->_pocPtr; + + if (spr && !spr->_flags._kept && ht->_pocket[pp] == nullptr) { + V3D pos(14, -10, -1); + snSound(ht->_ptr, 3); + if (_taken) { + _vga->_showQ->insert(spr); + _taken = false; + } + ht->_pocket[pp] = spr; + spr->setScene(0); + spr->_flags._kept = true; + if (!_sex) + pos._x += kScrWidth - 58; + if (pp & 1) + pos._x += 29; + if (pp >> 1) + pos._y -= 20; + pos._y -= (spr->_siz.y / 2); + spr->gotoxyz(pos); + if (stp >= 0) + spr->step(stp); + } + _sex = sex; + selectPocket(-1); } void CGE2Engine::snGive(Sprite *spr, int val) { -- cgit v1.2.3 From 7a549f2693222743dd76697534664fdc498a456c Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 18 Jun 2014 23:34:26 +0200 Subject: CGE2: Implement offUse(). --- engines/cge2/cge2.h | 2 ++ engines/cge2/cge2_main.cpp | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index bc4a16c33f..e743d7b819 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -80,6 +80,8 @@ class Map; #define kExitOkText 40 #define kCrackedText 44 +#define kOffUseCount 130 +#define kOffUseText 131 enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index b17f48dacd..c27b16073c 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -1018,7 +1018,24 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { } void CGE2Engine::offUse() { - warning("STUB: CGE2Engine::offUse()"); + int seq = 0; + int offUseCount = atoi(_text->getText(kOffUseCount)); + + // This fixes the issue of empty speech bubbles in the original. + // Now we only let this cycle pass if it randoms a valid value for getText(). + int txt = 0; + do { + txt = kOffUseText + _sex * offUseCount + newRandom(offUseCount); + } while (_text->getText(txt) == nullptr); + + Hero *h = _heroTab[_sex]->_ptr; + h->park(); + _commandHandler->addCommand(kCmdWait, -1, -1, h); + _commandHandler->addCommand(kCmdSeq, -1, seq, h); + if (!_sayVox) + _commandHandler->addCommand(kCmdSound, -1, 6 + _sex, h); + _commandHandler->addCommand(kCmdWait, -1, -1, h); + _commandHandler->addCommand(kCmdSay, -1, txt, h); } Sprite *CGE2Engine::spriteAt(V2D pos) { -- cgit v1.2.3 From d7e70eb5fac638e386f6da1bbf93d9256adb3596 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 19 Jun 2014 00:09:01 +0200 Subject: CGE2: Implement inf(). --- engines/cge2/cge2.h | 4 +++- engines/cge2/talk.h | 2 -- engines/cge2/text.cpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index e743d7b819..bb59c48446 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -89,6 +89,8 @@ enum CallbackType { enum Action { kNear, kMTake, kFTake, kActions }; +enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; + class CGE2Engine : public Engine { private: uint32 _lastFrame, _lastTick; @@ -105,7 +107,7 @@ public: bool showTitle(const char *name); void cge2_main(); char *mergeExt(char *buf, const char *name, const char *ext); - void inf(const char *text, bool wideSpace = false); + void inf(const char *text, ColorBank col = kCBInf); void movie(const char *ext); void runGame(); void loadGame(); diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index 84ba7281f9..cddcdc2c5e 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -62,8 +62,6 @@ public: enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; -enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; - class Talk : public Sprite { protected: TextBoxStyle _mode; diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index cf4dda4703..c7f6a06894 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -178,8 +178,15 @@ void Text::say(const char *text, Sprite *spr) { _vm->_vga->_showQ->append(speaker); } -void CGE2Engine::inf(const char *text, bool wideSpace) { - warning("STUB: CGE2Engine::inf()"); +void CGE2Engine::inf(const char *text, ColorBank col) { + killText(); + _talk = new Talk(this, text, kTBRect, col); + if (_talk) { + _talk->_flags._kill = true; + _talk->setName(_text->getText(kInfName)); + _talk->center(); + _vga->_showQ->append(_talk); + } } void Text::sayTime(Sprite *spr) { -- cgit v1.2.3 From 535b70934e80591aed0cd221c9a9928de3ede2f4 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 19 Jun 2014 10:44:00 +0200 Subject: CGE2: Comment out code and add TODO in switchScene(). --- engines/cge2/cge2_main.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index c27b16073c..669b28d4d3 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -479,6 +479,9 @@ void CGE2Engine::switchScene(int scene) { if (scene == _now) return; + /* TODO:: Recheck this flag-thing! As far as it seems it's only for checking if the game + is being run from the CD-ROM. In this context, it's useless for us. + if (scene >= 0) { if (!_flag[2]) // PROT _flag[2] = true; @@ -488,6 +491,7 @@ void CGE2Engine::switchScene(int scene) { return; } } + */ _req = scene; for (int i = 0; i < 2; i++) { -- cgit v1.2.3 From 56c7df46d3f713bdf8817217807570bcf0d976c9 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 19 Jun 2014 11:34:25 +0200 Subject: CGE2: Implement showing the selected item in the inventory. Now the selected item's picture is blinking until deselected. --- engines/cge2/cge2.cpp | 3 --- engines/cge2/cge2.h | 4 +++- engines/cge2/cge2_main.cpp | 56 +++++++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 25 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 96beff7195..9e1e30a109 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -71,7 +71,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) for (int i = 0; i < 2; i++) _vol[i] = nullptr; _eventManager = nullptr; - _blinkSprite = nullptr; _map = nullptr; _quitFlag = false; @@ -153,8 +152,6 @@ void CGE2Engine::deinit() { } delete _sys; delete _eventManager; - if (_blinkSprite != nullptr) - delete _blinkSprite; delete _map; } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index bb59c48446..c02b01c33a 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -83,6 +83,9 @@ class Map; #define kOffUseCount 130 #define kOffUseText 131 +#define kSysTimeRate 6 // 12 Hz +#define kBlinkRate 4 // 3 Hz + enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume }; @@ -255,7 +258,6 @@ public: Sprite *_busyPtr; Sprite *_vol[2]; EventManager *_eventManager; - Sprite *_blinkSprite; Map *_map; private: void init(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 669b28d4d3..816eea1889 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -39,7 +39,9 @@ namespace CGE2 { System::System(CGE2Engine *vm) : Sprite(vm), _vm(vm) { - warning("STUB: System::System()"); + _blinkCounter = 0; + _blinkSprite = nullptr; + tick(); } void System::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { @@ -82,12 +84,12 @@ void System::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { if (pos.x >= (kPocketsWidth >> 1)) ++n; s = _vm->_heroTab[_vm->_sex]->_pocket[n]; - if (_vm->_blinkSprite) - _vm->_blinkSprite->_flags._hide = false; - if (_vm->_blinkSprite == s) - _vm->_blinkSprite = nullptr; + if (_vm->_sys->_blinkSprite) + _vm->_sys->_blinkSprite->_flags._hide = false; + if (_vm->_sys->_blinkSprite == s) + _vm->_sys->_blinkSprite = nullptr; else - _vm->_blinkSprite = s; + _vm->_sys->_blinkSprite = s; } } } @@ -98,7 +100,15 @@ void System::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { } void System::tick() { - warning("STUB: System::tick()"); + _time = kSysTimeRate; + + if (_blinkCounter) + --_blinkCounter; + else { + if (_blinkSprite) + _blinkSprite->_flags._hide ^= 1; + _blinkCounter = kBlinkRate; + } } int CGE2Engine::number(char *s) { // TODO: Rework it later to include the preceding token() call! @@ -588,6 +598,10 @@ bool CGE2Engine::isHero(Sprite *spr) { } void CGE2Engine::tick() { + // system pseudo-sprite + if (_sys && _sys->_time && (--_sys->_time == 0)) + _sys->tick(); + for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time && (--spr->_time == 0)) spr->tick(); @@ -928,9 +942,9 @@ void CGE2Engine::killText() { void CGE2Engine::switchHero(int sex) { if (sex != _sex) { int scene = _heroTab[sex]->_ptr->_scene; - if (_blinkSprite) { - _blinkSprite->_flags._hide = false; - _blinkSprite = nullptr; + if (_sys->_blinkSprite) { + _sys->_blinkSprite->_flags._hide = false; + _sys->_blinkSprite = nullptr; } if (scene >= 0) { _commandHandler->addCommand(kCmdSeq, -1, 2, _heroTab[_sex]->_face); @@ -960,7 +974,7 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { } if ((mask & kMouseLeftUp) && _vm->_commandHandler->idle()) { - if (_vm->isHero(this) && !_vm->_blinkSprite) { + if (_vm->isHero(this) && !_vm->_sys->_blinkSprite) { _vm->switchHero((this == _vm->_heroTab[1]->_ptr) ? 1 : 0); } else if (_flags._kept) { // sprite in pocket for (int sex = 0; sex < 2; ++sex) { @@ -968,12 +982,12 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { if (_vm->_heroTab[sex]->_pocket[p] == this) { _vm->switchHero(sex); if (_vm->_sex == sex) { - if (_vm->_blinkSprite) - _vm->_blinkSprite->_flags._hide = false; - if (_vm->_blinkSprite == this) - _vm->_blinkSprite = nullptr; + if (_vm->_sys->_blinkSprite) + _vm->_sys->_blinkSprite->_flags._hide = false; + if (_vm->_sys->_blinkSprite == this) + _vm->_sys->_blinkSprite = nullptr; else - _vm->_blinkSprite = this; + _vm->_sys->_blinkSprite = this; } } } @@ -983,11 +997,11 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { if (!_vm->_talk) { if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1)) h->walkTo(this); - else if (_vm->_blinkSprite) { - if (works(_vm->_blinkSprite)) { - _vm->feedSnail(_vm->_blinkSprite, (_vm->_sex) ? kMTake : kFTake, _vm->_heroTab[_vm->_sex]->_ptr); - _vm->_blinkSprite->_flags._hide = false; - _vm->_blinkSprite = nullptr; + else if (_vm->_sys->_blinkSprite) { + if (works(_vm->_sys->_blinkSprite)) { + _vm->feedSnail(_vm->_sys->_blinkSprite, (_vm->_sex) ? kMTake : kFTake, _vm->_heroTab[_vm->_sex]->_ptr); + _vm->_sys->_blinkSprite->_flags._hide = false; + _vm->_sys->_blinkSprite = nullptr; } else _vm->offUse(); -- cgit v1.2.3 From ff99cb9658eacdcf9bf0cafb22b0529e76a4b3f9 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 19 Jun 2014 11:43:01 +0200 Subject: CGE2: Implement Sprite::works(). Now Anna is also reachable/playable. --- engines/cge2/hero.cpp | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 2090d497c1..0958563395 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -563,20 +563,38 @@ void Hero::operator--() { } bool Sprite::works(Sprite *spr) { - //if (!spr || !spr->_ext) - // return false; - - //CommandHandler::Command *c = spr->_ext->_take; - //if (c != NULL) { - // c += spr->_takePtr; - // if (c->_ref == _ref) - // if (c->_commandType != kCmdLabel || (c->_val == 0 || c->_val == _vm->_now)) - // return true; - //} - - warning("STUB: Sprite::works()"); - - return false; + if (!spr || !spr->_ext) + return false; + + bool ok = false; + + Action a = _vm->_heroTab[_vm->_sex]->_ptr->action(); + CommandHandler::Command *ct = spr->_ext->_actions[a]; + if (ct) { + int i = spr->_actionCtrl[a]._ptr; + int n = spr->_actionCtrl[a]._cnt; + while (i < n && !ok) { + CommandHandler::Command *c = &ct[i++]; + if (c->_commandType != kCmdUse) + break; + ok = (c->_ref == _ref); + if (c->_val > 255) { + if (ok) { + int p = spr->labVal(a, c->_val >> 8); + if (p >= 0) + spr->_actionCtrl[a]._ptr = p; + else + ok = false; + } + } else { + if (c->_val && c->_val != _vm->_now) + ok = false; + break; + } + } + } + + return ok; } } // End of namespace CGE2 -- cgit v1.2.3 From ea9b4d0729a8f88515164a2d823247b48e55e5b2 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 19 Jun 2014 11:50:42 +0200 Subject: CGE2: Implement snMouse(). --- engines/cge2/cge2.h | 2 +- engines/cge2/snail.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c02b01c33a..62d57fb63a 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -181,7 +181,7 @@ public: void snSlave(Sprite *spr, int val); void snTrans(Sprite *spr, int val); void snPort(Sprite *spr, int val); - void snMouse(int val); + void snMouse(bool on); void snNNext(Sprite *spr, Action act, int val); void snRNNext(Sprite *spr, int val); void snRMTNext(Sprite *spr, int val); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index d40789c6d1..b7731aebb8 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -534,8 +534,11 @@ void CGE2Engine::snPort(Sprite *spr, int val) { warning("STUB: CGE2Engine::snPort()"); } -void CGE2Engine::snMouse(int val) { - warning("STUB: CGE2Engine::snMouse()"); +void CGE2Engine::snMouse(bool on) { + if (on) + _mouse->on(); + else + _mouse->off(); } void CGE2Engine::snNNext(Sprite *spr, Action act, int val) { -- cgit v1.2.3 From 76846bf4f5567a314c185b77629c0313c9dab22f Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 19 Jun 2014 12:23:00 +0200 Subject: CGE2: Implement Hero::fun(). --- engines/cge2/hero.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 0958563395..1ddf870214 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -386,7 +386,12 @@ void Hero::reach(int mode) { } void Hero::fun() { - warning("STUB: Hero::fun()"); + if (_vm->_commandHandler->idle()) { + park(); + _vm->_commandHandler->addCommand(kCmdWait, -1, -1, this); + _vm->_commandHandler->addCommand(kCmdSeq, -1, _funStart, this); + } + _funDel = _funDel0 >> 2; } int Hero::len(V2D v) { -- cgit v1.2.3 From fcd387553f5242139e78db87f91047c55705e259 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 19 Jun 2014 12:30:44 +0200 Subject: CGE2: Implement optionTouch(). Add stubs for called functions. --- engines/cge2/cge2.h | 9 +++++++- engines/cge2/cge2_main.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 62d57fb63a..db79c64d7c 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -141,7 +141,6 @@ public: void loadPos(); void releasePocket(Sprite *spr); void switchHero(int sex); - void optionTouch(int opt, uint16 mask); void offUse(); void setAutoColors(); bool cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d); @@ -151,6 +150,14 @@ public: int mapCross(const V2D &a, const V2D &b); Sprite *spriteAt(V2D pos); + void optionTouch(int opt, uint16 mask); + void switchColorMode(); + void switchMusic(); + void quit(); + void setVolume(int idx, int cnt); + void switchCap(); + void switchVox(); + void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); void setEye(const char *s); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 816eea1889..f16f0ce340 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -1032,7 +1032,62 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { } void CGE2Engine::optionTouch(int opt, uint16 mask) { - warning("STUB: CGE2Engine::optionTouch()"); + switch (opt) { + case 1: + if (mask & kMouseLeftUp) + switchColorMode(); + break; + case 2: + if (mask & kMouseLeftUp) + switchMusic(); + break; + case 3: + if (mask & kMouseLeftUp) + quit(); + break; + case 4: + if (mask & (kMouseLeftUp | kMouseRightUp)) + setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); + break; + case 5: + if (mask & (kMouseLeftUp | kMouseRightUp)) + setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); + break; + case 8: + if (mask & kMouseLeftUp) + switchCap(); + break; + case 9: + if (mask & kMouseLeftUp) + switchVox(); + break; + default: + break; + } +} + +void CGE2Engine::switchColorMode() { + warning("STUB: CGE2Engine::switchColorMode()"); +} + +void CGE2Engine::switchMusic() { + warning("STUB: CGE2Engine::switchMusic()"); +} + +void CGE2Engine::quit() { + warning("STUB: CGE2Engine::quit()"); +} + +void CGE2Engine::setVolume(int idx, int cnt) { + warning("STUB: CGE2Engine::setVolume()"); +} + +void CGE2Engine::switchCap() { + warning("STUB: CGE2Engine::switchCap()"); +} + +void CGE2Engine::switchVox() { + warning("STUB: CGE2Engine::switchVox()"); } void CGE2Engine::offUse() { -- cgit v1.2.3 From e708c1e5cd14e1eed2f9e68ff4335cdd00b93f20 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 21 Jun 2014 01:57:18 +0200 Subject: CGE2: Implement "quit menu". Now the "main switch" on the menu panel is working. Also move a couple of defines from cge2_main.h to cge2.h during the process. --- engines/cge2/cge2.h | 66 ++++++++++++------- engines/cge2/cge2_main.cpp | 23 ++++++- engines/cge2/cge2_main.h | 15 ----- engines/cge2/module.mk | 3 +- engines/cge2/vmenu.cpp | 154 +++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/vmenu.h | 86 +++++++++++++++++++++++++ 6 files changed, 307 insertions(+), 40 deletions(-) create mode 100644 engines/cge2/vmenu.cpp create mode 100644 engines/cge2/vmenu.h (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index db79c64d7c..17d68fb221 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -60,31 +60,50 @@ class EventManager; class Font; class Map; -#define kScrWidth 320 -#define kScrHeight 240 -#define kScrDepth 480 -#define kPanHeight 40 -#define kWorldHeight (kScrHeight - kPanHeight) -#define kMaxFile 128 -#define kPathMax 128 -#define kDimMax 8 -#define kWayMax 10 -#define kPocketMax 4 -#define kSceneMax 100 -#define kMaxPoint 4 -#define kInfoX 160 -#define kInfoY -11 -#define kInfoW 180 -#define kPocketsWidth 59 -#define kLineMax 512 +#define kScrWidth 320 +#define kScrHeight 240 +#define kScrDepth 480 +#define kPanHeight 40 +#define kWorldHeight (kScrHeight - kPanHeight) +#define kMaxFile 128 +#define kPathMax 128 +#define kDimMax 8 +#define kWayMax 10 +#define kPocketMax 4 +#define kSceneMax 100 +#define kMaxPoint 4 +#define kInfoX 160 +#define kInfoY -11 +#define kInfoW 180 +#define kPocketsWidth 59 +#define kLineMax 512 -#define kExitOkText 40 -#define kCrackedText 44 -#define kOffUseCount 130 -#define kOffUseText 131 +#define kIntroExt ".I80" +#define kTabName "CGE.TAB" +#define kPocketFull 170 +#define kGameFrameDelay (750 / 50) +#define kGameTickDelay (750 / 62) -#define kSysTimeRate 6 // 12 Hz -#define kBlinkRate 4 // 3 Hz +#define kMusicRef 122 +#define kPowerRef 123 +#define kDvolRef 124 +#define kMvolRef 125 +#define kRef 126 +#define kBusyRef 127 +#define kCapRef 128 +#define kVoxRef 129 + +#define kExitOkText 40 +#define kCrackedText 44 +#define kOffUseCount 130 +#define kOffUseText 131 + +#define kSysTimeRate 6 // 12 Hz +#define kBlinkRate 4 // 3 Hz + +#define kQuitTitle 200 +#define kQuitText 201 +#define kNoQuitText 202 enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume @@ -149,6 +168,7 @@ public: int sgn(long n); int mapCross(const V2D &a, const V2D &b); Sprite *spriteAt(V2D pos); + void keyClick(); void optionTouch(int opt, uint16 mask); void switchColorMode(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f16f0ce340..34e7cfe50f 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -35,6 +35,7 @@ #include "cge2/spare.h" #include "cge2/events.h" #include "cge2/map.h" +#include "cge2/vmenu.h" namespace CGE2 { @@ -1075,7 +1076,27 @@ void CGE2Engine::switchMusic() { } void CGE2Engine::quit() { - warning("STUB: CGE2Engine::quit()"); + Common::Array quitMenu; // Deleted in VMenu's destructor. + quitMenu.push_back(new StartCountDownChoice(this)); + quitMenu.push_back(new ResetQSwitchChoice(this)); + + if (_commandHandler->idle()) { + if (VMenu::_addr) { + _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, VMenu::_addr); + ResetQSwitchChoice rqsChoice(this); + rqsChoice.proc(); + } else { + quitMenu[0]->_text = _text->getText(kQuitText); + quitMenu[1]->_text = _text->getText(kNoQuitText); + (new VMenu(this, quitMenu, V2D(this, -1, -1), kCBMnu))->setName(_text->getText(kQuitTitle)); + _commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 0, nullptr); + keyClick(); + } + } +} + +void CGE2Engine::keyClick() { + _commandHandlerTurbo->addCommand(kCmdSound, -1, 5, nullptr); } void CGE2Engine::setVolume(int idx, int cnt) { diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index e59c6f0b45..d6f2371964 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -32,21 +32,6 @@ namespace CGE2 { -#define kIntroExt ".I80" -#define kTabName "CGE.TAB" -#define kPocketFull 170 -#define kGameFrameDelay (750 / 50) -#define kGameTickDelay (750 / 62) - -#define kMusicRef 122 -#define kPowerRef 123 -#define kDvolRef 124 -#define kMvolRef 125 -#define kRef 126 -#define kBusyRef 127 -#define kCapRef 128 -#define kVoxRef 129 - class System : public Sprite { public: int _funDel; diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index dc74de5ed6..9a6e0cb595 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -14,7 +14,8 @@ MODULE_OBJS = \ spare.o \ talk.o \ events.o \ - map.o + map.o \ + vmenu.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp new file mode 100644 index 0000000000..55ddc2aec0 --- /dev/null +++ b/engines/cge2/vmenu.cpp @@ -0,0 +1,154 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/cge2.h" +#include "cge2/vmenu.h" +#include "cge2/events.h" + +namespace CGE2 { + +void StartCountDownChoice::proc() { + _vm->switchScene(-1); +} + +void ResetQSwitchChoice::proc() { + _vm->_commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 1, nullptr); + _vm->keyClick(); +} + +MenuBar::MenuBar(CGE2Engine *vm, uint16 w, byte *c) : Talk(vm) { + _color = c; + int h = kFontHigh + 2 * kMenuBarVerticalMargin, i = (w += 2 * kMenuBarHorizontalMargin) * h; + uint8 *p = new uint8[i]; + uint8 *p1; + uint8 *p2; + uint8 lt = _color[kLt]; + uint8 rb = _color[kRb]; + BitmapPtr b; + + memset(p + w, kPixelTransp, i - 2 * w); + memset(p, lt, w); + memset(p + i - w, rb, w); + p1 = p; + p2 = p + i - 1; + for (i = 0; i < h; i++) { + *p1 = lt; + *p2 = rb; + p1 += w; + p2 -= w; + } + b = new Bitmap[1]; + b[0] = Bitmap(vm, w, h, p); + delete[] p; + setShapeList(b, 1); + _flags._slav = true; + _flags._tran = true; + _flags._kill = true; +} + +VMenu *VMenu::_addr = nullptr; + +VMenu::VMenu(CGE2Engine *vm, Common::Array list, V2D pos, ColorBank col) + : Talk(vm, vmGather(list), kTBRect, col), _menu(list), _bar(nullptr), _items(list.size()), _vm(vm) { + delete[] _vmgt; // Lefotver of vmGather. + + _addr = this; + _recent = -1; + _flags._kill = true; + + if (pos.x < 0 || pos.y < 0) + center(); + else + gotoxyz(V2D(_vm, pos.x - _siz.x / 2, pos.y - (kTextVMargin + kFontHigh / 2))); + + _vm->_vga->_showQ->append(this); + _bar = new MenuBar(_vm, _siz.x - 2 * kTextHMargin, _color); + _bar->gotoxyz(V2D(_vm, _pos2D.x, _pos2D.y + kTextVMargin - kMenuBarVerticalMargin)); + _vm->_vga->_showQ->append(_bar); +} + +char *VMenu::vmGather(Common::Array list) { + int len = 0; + int h = 0; + + for (int i = 0; i < list.size(); i++) { + len += strlen(list[i]->_text); + ++h; + } + _vmgt = new char[len + h]; + if (_vmgt) { + *_vmgt = '\0'; + for (int i = 0; i < list.size(); i++) { + if (*_vmgt) + strcat(_vmgt, "|"); + strcat(_vmgt, list[i]->_text); + ++h; + } + } + return _vmgt; +} + + +VMenu::~VMenu() { + _addr = nullptr; + + for (int i = 0; i < _menu.size(); i++) { + delete _menu[i]; + } +} + +void VMenu::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { + int h = kFontHigh + kTextLineSpace; + int n = 0; + bool ok = false; + + if (_items) { + Sprite::touch(mask, pos, keyCode); + + pos.y -= kTextVMargin - 1; + if (pos.y >= 0) { + if (pos.x < 0) + pos.x = -pos.x; + n = pos.y / h; + if (n < _items) + ok = (pos.x <= (_siz.x >> 1) - kTextHMargin); + else + n = _items - 1; + } + + _bar->gotoxyz(V2D(_vm, _pos2D.x, _pos2D.y + kTextVMargin + n * h - kMenuBarVerticalMargin)); + n = _items - 1 - n; + + if (ok && (mask & kMouseLeftUp)) { + _items = 0; + _vm->_commandHandlerTurbo->addCommand(kCmdKill, -1, 0, this); + _menu[_recent = n]->proc(); + } + } +} + +} // End of namespace CGE2 diff --git a/engines/cge2/vmenu.h b/engines/cge2/vmenu.h new file mode 100644 index 0000000000..c988e1ed2b --- /dev/null +++ b/engines/cge2/vmenu.h @@ -0,0 +1,86 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_VMENU_H +#define CGE2_VMENU_H + +#define kMenuBarVerticalMargin 1 +#define kMenuBarHorizontalMargin 3 +#define kLt 3 +#define kRb 1 + +#include "cge2/talk.h" + +namespace CGE2 { + +class Choice { +protected: + CGE2Engine *_vm; +public: + char *_text; + virtual void proc() = 0; + + Choice(CGE2Engine *vm) : _vm(vm), _text(nullptr) {} +}; + +class StartCountDownChoice : public Choice { +public: + StartCountDownChoice(CGE2Engine *vm) : Choice(vm) {} + void proc(); +}; + +class ResetQSwitchChoice : public Choice { +public: + ResetQSwitchChoice(CGE2Engine *vm) : Choice(vm) {} + void proc(); +}; + +class MenuBar : public Talk { +public: + MenuBar(CGE2Engine *vm, uint16 w, byte *c); +}; + +class VMenu : public Talk { + CGE2Engine *_vm; + + uint16 _items; + Common::Array _menu; +public: + char *_vmgt; + static VMenu *_addr; + int _recent; + MenuBar *_bar; + + VMenu(CGE2Engine *vm, Common::Array list, V2D pos, ColorBank col); + ~VMenu(void); + void touch(uint16 mask, V2D pos, Common::KeyCode keyCode); + char *vmGather(Common::Array list); +}; + +} // End of namespace CGE2 + +#endif // CGE2_VMENU_H -- cgit v1.2.3 From 7faa95bfdd7d5fd2eb2719269090f23b43bfc6bc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 21 Jun 2014 18:33:31 +0200 Subject: CGE2: Avoid some signed/unsigned comparisons --- engines/cge2/vmenu.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp index 55ddc2aec0..a2f2f05389 100644 --- a/engines/cge2/vmenu.cpp +++ b/engines/cge2/vmenu.cpp @@ -95,14 +95,14 @@ char *VMenu::vmGather(Common::Array list) { int len = 0; int h = 0; - for (int i = 0; i < list.size(); i++) { + for (uint i = 0; i < list.size(); i++) { len += strlen(list[i]->_text); ++h; } _vmgt = new char[len + h]; if (_vmgt) { *_vmgt = '\0'; - for (int i = 0; i < list.size(); i++) { + for (uint i = 0; i < list.size(); i++) { if (*_vmgt) strcat(_vmgt, "|"); strcat(_vmgt, list[i]->_text); @@ -116,7 +116,7 @@ char *VMenu::vmGather(Common::Array list) { VMenu::~VMenu() { _addr = nullptr; - for (int i = 0; i < _menu.size(); i++) { + for (uint i = 0; i < _menu.size(); i++) { delete _menu[i]; } } -- cgit v1.2.3 From f1b14c6d31b1f7eafe4720302460c6265fb87025 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 21 Jun 2014 18:45:28 +0200 Subject: CGE2: Reduce the scope of some variables --- engines/cge2/vmenu.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp index a2f2f05389..fa4c29c1d7 100644 --- a/engines/cge2/vmenu.cpp +++ b/engines/cge2/vmenu.cpp @@ -122,13 +122,12 @@ VMenu::~VMenu() { } void VMenu::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { - int h = kFontHigh + kTextLineSpace; - int n = 0; - bool ok = false; - if (_items) { Sprite::touch(mask, pos, keyCode); + int n = 0; + bool ok = false; + int h = kFontHigh + kTextLineSpace; pos.y -= kTextVMargin - 1; if (pos.y >= 0) { if (pos.x < 0) -- cgit v1.2.3 From fc5c92b5d0b46c0728a5642e43b06741871f8ec7 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 13:05:24 +0200 Subject: CGE2: Implement snGive() and snRmNear(). --- engines/cge2/snail.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index b7731aebb8..824d4e3c1d 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -505,7 +505,16 @@ void CGE2Engine::snKeep(Sprite *spr, int stp) { } void CGE2Engine::snGive(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snGive()"); + if (spr) { + int p = findActivePocket(spr->_ref); + if (p >= 0) { + releasePocket(spr); + spr->setScene(_now); + if (val >= 0) + spr->step(val); + } + } + selectPocket(-1); } void CGE2Engine::snGoto(Sprite *spr, int val) { @@ -562,7 +571,8 @@ void CGE2Engine::snRFTNext(Sprite *spr, int val) { } void CGE2Engine::snRmNear(Sprite *spr) { - warning("STUB: CGE2Engine::snRmNear()"); + if (spr) + spr->_actionCtrl[kNear]._cnt = 0; } void CGE2Engine::snRmMTake(Sprite *spr) { -- cgit v1.2.3 From f36cfb629ce6d23fc0f7a4437ea3b71daa11833f Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 13:26:55 +0200 Subject: CGE2: Fix mapCross(). --- engines/cge2/hero.cpp | 2 +- engines/cge2/vga13h.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 1ddf870214..5e075d8fa2 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -542,7 +542,7 @@ int CGE2Engine::mapCross(const V2D &a, const V2D &b) { if (cross(a, b, *n0, *n)) ++cnt; - if (n == p) + if (*n == *p) p = nullptr; } else { p = n; diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index a6e12fe8a1..948c3ab9b3 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -148,6 +148,7 @@ public: V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); } bool operator==(const V3D &p) const { V3D tmp(x, y); return tmp._x == p._x && tmp._y == p._y && tmp._z == p._z; } bool operator!=(const V3D &p) const { V3D tmp(x, y); return tmp._x != p._x || tmp._y != p._y || tmp._z == p._z; } + bool operator==(const V2D &p) const { return x == p.x && y == p.y; } uint16 area() { return x * y; } bool limited(const V2D &p) { return ((x < p.x) && (y < p.y)); -- cgit v1.2.3 From 8ae41648f9b7240aee5418afad3da4d6035b0c6e Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 13:38:47 +0200 Subject: CGE2: Implement snSwap(). --- engines/cge2/cge2.h | 1 + engines/cge2/snail.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 17d68fb221..130b1bac08 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -169,6 +169,7 @@ public: int mapCross(const V2D &a, const V2D &b); Sprite *spriteAt(V2D pos); void keyClick(); + void swapInPocket(Sprite *spr, Sprite *xspr); void optionTouch(int opt, uint16 mask); void switchColorMode(); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 824d4e3c1d..4a932e5fb0 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -427,7 +427,38 @@ void CGE2Engine::snSend(Sprite *spr, int val) { } void CGE2Engine::snSwap(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snSwap()"); + bool tak = _taken; + Sprite *xspr = locate(val); + if (spr && xspr) { + bool was1 = (_vga->_showQ->locate(spr->_ref) != nullptr); + bool xwas1 = (_vga->_showQ->locate(val) != nullptr); + + int tmp = spr->_scene; + spr->setScene(xspr->_scene); + xspr->setScene(tmp); + + SWAP(spr->_pos2D, xspr->_pos2D); + SWAP(spr->_pos3D, xspr->_pos3D); + if (spr->_flags._kept) + swapInPocket(spr, xspr); + if (xwas1 != was1) { + if (was1) { + hide1(spr); + _spare->dispose(spr); + } else + expandSprite(spr); + if (xwas1) { + hide1(xspr); + _spare->dispose(xspr); + } else { + expandSprite(xspr); + _taken = false; + } + } + } + if (_taken) + _spare->dispose(xspr); + _taken = tak; } void CGE2Engine::snCover(Sprite *spr, int val) { @@ -689,6 +720,22 @@ void CGE2Engine::hide1(Sprite *spr) { _commandHandlerTurbo->addCommand(kCmdGhost, -1, 0, spr->ghost()); } +void CGE2Engine::swapInPocket(Sprite *spr, Sprite *xspr) { + int i, j; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax; j++) { + Sprite *&poc = _heroTab[i]->_pocket[j]; + if (poc == spr) { + spr->_flags._kept = false; + poc = xspr; + xspr->_flags._kept = true; + xspr->_flags._port = false; + return; + } + } + } +} + Sprite *CGE2Engine::expandSprite(Sprite *spr) { if (spr) _vga->_showQ->insert(spr); -- cgit v1.2.3 From af646247f30af15c3641a1ec481d00d9a8eb9239 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 22 Jun 2014 13:48:58 +0200 Subject: CGE2: Remove useless variable declarations --- engines/cge2/snail.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 4a932e5fb0..300c02a66a 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -721,7 +721,6 @@ void CGE2Engine::hide1(Sprite *spr) { } void CGE2Engine::swapInPocket(Sprite *spr, Sprite *xspr) { - int i, j; for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { Sprite *&poc = _heroTab[i]->_pocket[j]; -- cgit v1.2.3 From cb3dce698c3903f180bfe4a19fca287d3affeea6 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 14:10:23 +0200 Subject: CGE2: Rework Hero::len(). --- engines/cge2/hero.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 5e075d8fa2..fdec752ed2 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -395,7 +395,7 @@ void Hero::fun() { } int Hero::len(V2D v) { - return ((v.x * v.x + v.y * v.y) * (v.x * v.x + v.y * v.y)); + return sqrt(double(v.x * v.x + v.y * v.y)); } bool Hero::findWay(){ -- cgit v1.2.3 From 6015eddc41643ac71d7fa57a99a7378ecd5a1da7 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 18:44:33 +0200 Subject: CGE2: Remove double definition kMaxTry. --- engines/cge2/hero.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 7ddc871e06..2998d7efe1 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -31,8 +31,6 @@ #include "cge2/vga13h.h" #include "cge2/snail.h" -#define kMaxTry 400 - namespace CGE2 { #define kMaxTry 400 -- cgit v1.2.3 From 7b628c7ffc779f065fcd60caa2c1d1172460b9be Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 19:06:40 +0200 Subject: CGE2: Fix some formatting in Hero. --- engines/cge2/hero.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index fdec752ed2..3e9a439f1a 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -489,7 +489,7 @@ V3D Hero::screenToGround(V2D pos) { int Hero::cross(const V2D &a, const V2D &b) { int x = _pos3D._x.trunc(); int z = _pos3D._z.trunc(); - int r = ((_siz.x / 3) * _vm->_eye->_z.trunc()) / (_vm->_eye->_z.trunc()- z); + int r = ((_siz.x / 3) * _vm->_eye->_z.trunc()) / (_vm->_eye->_z.trunc() - z); return _vm->cross(a, b, V2D(_vm, x - r, z), V2D(_vm, x + r, z)) << 1; } @@ -512,7 +512,7 @@ bool CGE2Engine::contain(const V2D &a, const V2D &b, const V2D &p) { } long CGE2Engine::det(const V2D &a, const V2D &b, const V2D &c) { - long n = ((long)a.x * b.y + (long)b.x * c.y + (long)c.x*a.y) - ((long)c.x*b.y + (long)b.x*a.y + (long)a.x*c.y); + long n = ((long)a.x * b.y + (long)b.x * c.y + (long)c.x * a.y) - ((long)c.x * b.y + (long)b.x * a.y + (long)a.x * c.y); return n; } -- cgit v1.2.3 From c8ed838c054d743ec692d21e643717097f1681e5 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 19:28:55 +0200 Subject: CGE2: Fix formatting in FXP. --- engines/cge2/vga13h.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 948c3ab9b3..13401751e9 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -61,8 +61,8 @@ public: FXP (void): f(0), i(0) { } FXP (int i0, int f0 = 0) : i(i0), f(0) { } FXP& operator = (const int& x) { i = x; f = 0; return *this; } - FXP operator + (const FXP& x) const { FXP y; y.Joined() = Joined()+x.Joined(); return y; } - FXP operator - (const FXP& x) const { FXP y; y.Joined() = Joined()-x.Joined(); return y; } + FXP operator + (const FXP& x) const { FXP y; y.Joined() = Joined() + x.Joined(); return y; } + FXP operator - (const FXP& x) const { FXP y; y.Joined() = Joined() - x.Joined(); return y; } FXP operator * (const FXP& x) const { FXP y; long t; y.i = i * x.i; -- cgit v1.2.3 From 19bc15193941d9afd5a896c8bdead2e896f780bd Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 22 Jun 2014 23:11:27 +0200 Subject: CGE2: Some more formatting fix in FXP. --- engines/cge2/vga13h.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 13401751e9..6876bcd825 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -52,8 +52,7 @@ namespace CGE2 { #define kPalSize (kPalCount * 3) // From FXP.H -class FXP // fixed point -{ +class FXP { // fixed point uint16 f; int16 i; long& Joined (void) const { return *(long *)&f; } @@ -67,7 +66,7 @@ public: FXP y; long t; y.i = i * x.i; t = ((long) f * x.f) >> 16; - t += ((long) i * x.f) + ((long) f * x.i); + t += ((long) i * x.f) + ((long) f * x.i); y.f = t & 0xFFFF; y.i += t >> 16; return y; -- cgit v1.2.3 From 2226eb078969dc4217bb490e594819e027187590 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 23 Jun 2014 10:20:24 +0200 Subject: CGE2: Implement snSay(), reimplement some parts of the sound code. --- engines/cge2/snail.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 300c02a66a..5ec62746f9 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -286,13 +286,12 @@ void CommandHandler::runCommand() { break; case kCmdSound: _vm->snSound(spr, tailCmd._val); - _count = 1; break; case kCmdMap: _vm->_heroTab[tailCmd._ref & 1]->_ptr->_ignoreMap = tailCmd._val == 0; break; case kCmdCount: - _count = tailCmd._val; + _vm->_sound->setRepeat(tailCmd._val); break; case kCmdRoom: _vm->snRoom(spr, tailCmd._val); @@ -512,7 +511,10 @@ void CGE2Engine::snKeep(Sprite *spr, int stp) { if (spr && !spr->_flags._kept && ht->_pocket[pp] == nullptr) { V3D pos(14, -10, -1); + int16 oldRepeat = _sound->getRepeat(); + _sound->setRepeat(1); snSound(ht->_ptr, 3); + _sound->setRepeat(oldRepeat); if (_taken) { _vga->_showQ->insert(spr); _taken = false; @@ -674,7 +676,8 @@ void CGE2Engine::snSound(Sprite *spr, int wav) { _sound->play(_fx->load(_commandStat._ref[1], _commandStat._ref[0]), (spr) ? (spr->_pos2D.x / (kScrWidth / 16)) : 8); } - + + _sound->setRepeat(1); } void CGE2Engine::snRoom(Sprite *spr, int val) { @@ -711,7 +714,14 @@ void CGE2Engine::snSay(Sprite *spr, int val) { int i = val; if (i < 256) i -= 100; - warning("STUB: CGE2Engine::snSay"); // TODO: Implement it with the revision of the sound code! + int16 oldRepeat = _sound->getRepeat(); + _sound->setRepeat(1); + snSound(spr, i); + _sound->setRepeat(oldRepeat); + //_commandStat._wait = &_sound->_smpinf._counter; + // This line is commented out for now since I wasn't able to find where this flag is reset + // and it's prevented the main loop from doing anything. + // TODO: Recheck this later! At the moment it seems working fine. } } } -- cgit v1.2.3 From 23adc159ef4dff0a7d08ba2b11d9847805e5dea8 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 23 Jun 2014 11:50:49 +0200 Subject: CGE2: Implement busy() and revise connected parts of the engine. --- engines/cge2/cge2.cpp | 2 ++ engines/cge2/cge2.h | 5 +++++ engines/cge2/cge2_main.cpp | 16 +++++++++++++++- engines/cge2/sound.cpp | 3 ++- engines/cge2/vga13h.cpp | 10 ++++------ 5 files changed, 28 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 9e1e30a109..6976a6fc82 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -96,6 +96,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _sayCap = true; _sayVox = true; _req = 1; + _midiNotify = nullptr; + _spriteNotify = nullptr; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 130b1bac08..c569bf9458 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -113,6 +113,8 @@ enum Action { kNear, kMTake, kFTake, kActions }; enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; +typedef void (CGE2Engine::*NotifyFunctionType)(); + class CGE2Engine : public Engine { private: uint32 _lastFrame, _lastTick; @@ -170,6 +172,7 @@ public: Sprite *spriteAt(V2D pos); void keyClick(); void swapInPocket(Sprite *spr, Sprite *xspr); + void busyStep(); void optionTouch(int opt, uint16 mask); void switchColorMode(); @@ -262,6 +265,8 @@ public: bool _sayCap; bool _sayVox; int _req; + NotifyFunctionType _midiNotify; + NotifyFunctionType _spriteNotify; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 34e7cfe50f..797dbe22d1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -648,7 +648,21 @@ void CGE2Engine::selectPocket(int n) { } void CGE2Engine::busy(bool on) { - warning("STUB: CGE2Engine::busy()"); + if (on) { + _spriteNotify = _midiNotify = &CGE2::CGE2Engine::busyStep; + busyStep(); + } else { + if (_busyPtr) + _busyPtr->step(0); + _spriteNotify = _midiNotify = nullptr; + } +} + +void CGE2Engine::busyStep() { + if (_busyPtr) { + _busyPtr->step((_busyPtr->_seqPtr) ? -1 : 1); + _busyPtr->show(0); + } } void CGE2Engine::runGame() { diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index c657a37e46..652907b37d 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -190,7 +190,8 @@ void MusicPlayer::killMidi() { } void MusicPlayer::loadMidi(int ref) { - warning("STUB: MusicPlayer::loadMidi()"); // if (MidiNotify) MidiNotify(); + if (_vm->_midiNotify != nullptr) + (_vm->*_vm->_midiNotify)(); // Work out the filename and check the given MIDI file exists Common::String filename = Common::String::format("%.2dSG%.2d.MID", ref >> 8, ref & 0xFF); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 24376d91bb..1c48a96210 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -56,8 +56,6 @@ Seq *getConstantSeq(bool seqFlag) { return seq; } -void (*Sprite::notify)() = nullptr; - byte Sprite::_constY = 0; byte Sprite::_follow = 0; @@ -249,8 +247,8 @@ Sprite *Sprite::expand() { if (_ext) return this; - if (notify != nullptr) - notify(); + if (_vm->_spriteNotify != nullptr) + (_vm->*_vm->_spriteNotify)(); _ext = new SprExt(_vm); assert(_ext != NULL); @@ -439,8 +437,8 @@ Sprite *Sprite::contract() { curSeq->_dx = curSeq->_dy = curSeq->_dz = 0; } - if (notify) - notify(); + if (_vm->_spriteNotify != nullptr) + (_vm->*_vm->_spriteNotify)(); if (e->_name) { delete[] e->_name; -- cgit v1.2.3 From 0eece817ebb5f6463467294f274da1dfb0b3164c Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 23 Jun 2014 13:11:54 +0200 Subject: CGE2: Fix releasePocket(). Now the inventory system is working as intended. --- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/vga13h.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 797dbe22d1..6c572d0b46 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -796,7 +796,7 @@ void CGE2Engine::loadPos() { void CGE2Engine::releasePocket(Sprite *spr) { for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { - Sprite *poc = _heroTab[i]->_pocket[j]; + Sprite *&poc = _heroTab[i]->_pocket[j]; if (poc == spr) { spr->_flags._kept = false; poc = nullptr; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 1c48a96210..2c8a3a6801 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -104,7 +104,7 @@ Sprite::Sprite(CGE2Engine *vm, BitmapPtr shpP, int cnt) Sprite::~Sprite() { if (_vm->_sprite == this) - _vm->_sprite = NULL; + _vm->_sprite = nullptr; contract(); } -- cgit v1.2.3 From 840eef8eb199c032a119357bd6bad394d287e78f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 23 Jun 2014 18:10:05 +0200 Subject: CGE2: Add a big hack to work around the coordinates issue --- engines/cge2/cge2_main.cpp | 3 ++- engines/cge2/hero.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 6c572d0b46..2940833deb 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -1010,7 +1010,8 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { } else { // sprite NOT in pocket Hero *h = _vm->_heroTab[_vm->_sex]->_ptr; if (!_vm->_talk) { - if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1)) + // HACK: the "+3" is a ugly hack used to compensate a pathfinding issue. To be fixed!! + if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1) + 3) h->walkTo(this); else if (_vm->_sys->_blinkSprite) { if (works(_vm->_sys->_blinkSprite)) { diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 3e9a439f1a..d1caf1f43e 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -314,7 +314,8 @@ int Hero::distance(V3D pos) { V3D di = _pos3D - pos; int x = di._x.round(); int z = di._z.round(); - return ((int)sqrt((long double)x * x + z * z)); + int retval = (int)sqrt((long double)x * x + z * z); + return retval; } int Hero::distance(Sprite *spr) { -- cgit v1.2.3 From 3dd6c9f7aad7acf43cf90e5405047706ec697adc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 24 Jun 2014 22:14:19 +0200 Subject: CGE2: Implement a couple of stubs --- engines/cge2/cge2_main.cpp | 5 ++++- engines/cge2/snail.cpp | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 2940833deb..5d4a97fd80 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -807,7 +807,10 @@ void CGE2Engine::releasePocket(Sprite *spr) { } void CGE2Engine::checkSaySwitch() { - warning("STUB: CGE2Engine::checkSaySwitch()"); +// if (SNDDrvInfo.DDEV == DEV_QUIET) +// _sayVox = !(_sayCap = true); + _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); + _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); } void CGE2Engine::loadTab() { diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 5ec62746f9..49041bb272 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -592,15 +592,18 @@ void CGE2Engine::snNNext(Sprite *spr, Action act, int val) { } void CGE2Engine::snRNNext(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snRNNext()"); + if (spr) + spr->_actionCtrl[kNear]._ptr += val; } void CGE2Engine::snRMTNext(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snRMTNext()"); + if (spr) + spr->_actionCtrl[kMTake]._ptr += val; } -void CGE2Engine::snRFTNext(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snRFTNext()"); +void CGE2Engine::snRFTNext(Sprite * spr, int val) { + if (spr) + spr->_actionCtrl[kFTake]._ptr += val; } void CGE2Engine::snRmNear(Sprite *spr) { @@ -614,7 +617,8 @@ void CGE2Engine::snRmMTake(Sprite *spr) { } void CGE2Engine::snRmFTake(Sprite *spr) { - warning("STUB: CGE2Engine::snRmFTake()"); + if (spr) + spr->_actionCtrl[kFTake]._cnt = 0; } void CGE2Engine::snFlag(int ref, int val) { -- cgit v1.2.3 From 2bc35f6f6db4fd963d6348e2772d928d136480f8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 24 Jun 2014 23:36:37 +0200 Subject: CGE2: Add a work around for missing VBM in scene 4 --- engines/cge2/bitmap.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index c62a784110..6c7e39a00d 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -44,7 +44,14 @@ void Bitmap::setVM(CGE2Engine *vm) { Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _v(nullptr), _b(nullptr), _map(0), _vm(vm) { char pat[kMaxPath]; - forceExt(pat, fname, ".VBM"); + + if (!strcmp(fname, "04tal201")) { + strcpy(pat, "04tal202"); + warning("Workaround for missing VBM: 04tal201"); + } else + strcpy(pat, fname); + + forceExt(pat, pat, ".VBM"); if (_vm->_resman->exist(pat)) { EncryptedStream file(_vm, pat); @@ -53,7 +60,7 @@ Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _v(nullptr), _b(nullptr), _m if (!loadVBM(&file)) error("Bad VBM [%s]", fname); } else { - error("Bad VBM [%s]", fname); + warning("Missing VBM [%s]", pat); } } -- cgit v1.2.3 From 384f1b664bc10c18a1501093b80fa4d6ca146475 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 25 Jun 2014 19:36:59 +0200 Subject: CGE2: Implement snMidi() --- engines/cge2/snail.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 49041bb272..9b77fe359e 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -364,7 +364,10 @@ void CGE2Engine::snHide(Sprite *spr, int val) { } void CGE2Engine::snMidi(int val) { - warning("STUB: CGE2Engine::snMidi()"); + if (val < 0) + _midiPlayer->killMidi(); + else if (_music) + _midiPlayer->loadMidi(val); } void CGE2Engine::snSetDlg(int clr, int set) { -- cgit v1.2.3 From 00c867f8ea983cc2194a0bf2208d48511605d685 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 25 Jun 2014 19:37:25 +0200 Subject: CGE2: Add a safeguard in Sprite::show() --- engines/cge2/vga13h.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 2c8a3a6801..9507ade704 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -612,6 +612,7 @@ void Sprite::show() { } void Sprite::show(uint16 pg) { + assert(pg < 4); Graphics::Surface *a = _vm->_vga->_page[1]; _vm->_vga->_page[1] = _vm->_vga->_page[pg]; getShp()->show(_pos2D); @@ -802,8 +803,8 @@ Sprite *Queue::remove(Sprite *spr) { spr->_next->_prev = spr->_prev; if (spr->_prev) spr->_prev->_next = spr->_next; - spr->_prev = NULL; - spr->_next = NULL; + spr->_prev = nullptr; + spr->_next = nullptr; return spr; } -- cgit v1.2.3 From 014d6bd9f0d561b0fff4748a46606281042046e0 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 26 Jun 2014 21:07:24 +0200 Subject: CGE2: Hopefully fix compilation for GCC --- engines/cge2/cge2_main.cpp | 4 ++-- engines/cge2/hero.h | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 5d4a97fd80..75b9affc1a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -619,7 +619,7 @@ void CGE2Engine::tick() { void CGE2Engine::openPocket() { for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax + 1; j++) { - int ref = (int)_heroTab[i]->_pocket[j]; + int ref = (int)_heroTab[i]->_downPocketId[j]; _heroTab[i]->_pocket[j] = (ref == -1) ? nullptr : _vga->_showQ->locate(ref); } } @@ -629,7 +629,7 @@ void CGE2Engine::closePocket() { for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax + 1; j++) { Sprite *spr = _heroTab[i]->_pocket[j]; - _heroTab[i]->_pocket[j] = (Sprite*)((spr) ? spr->_ref : -1); + _heroTab[i]->_downPocketId[j] = (spr) ? spr->_ref : -1; } } } diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 2998d7efe1..41eb3ac020 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -41,13 +41,16 @@ struct HeroTab { Hero *_ptr; Sprite *_face; Sprite *_pocket[kPocketMax + 1]; + int _downPocketId[kPocketMax + 1]; int _pocPtr; V2D *_posTab[kSceneMax]; HeroTab(CGE2Engine *vm) { _ptr = nullptr; _face = nullptr; - for (int i = 0; i < kPocketMax + 1; i++) + for (int i = 0; i < kPocketMax + 1; i++) { _pocket[i] = nullptr; + _downPocketId[i] = -1; + } _pocPtr = 0; for (int i = 0; i < kSceneMax; i++) _posTab[i] = nullptr; -- cgit v1.2.3 From e9396f8d1035b771d8c3fe99d8b815a3db39cfe5 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 27 Jun 2014 01:09:34 +0200 Subject: CGE2: Fix some GCC warnings --- engines/cge2/talk.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index a6d9945665..ddd98ac29c 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -50,7 +50,8 @@ Font::~Font() { } void Font::load() { - char *path = "CGE.CFT"; + char path[10]; + strcpy(path, "CGE.CFT"); if (!_vm->_resman->exist(path)) error("Missing configuration file! %s", path); @@ -67,7 +68,7 @@ void Font::load() { } fontFile.read(_map, p); - path = "CGE.TXC"; + strcpy(path, "CGE.TXC"); if (!_vm->_resman->exist(path)) error("Missing configuration file! %s", path); @@ -84,16 +85,16 @@ void Font::load() { continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - char *p; + char *token; - if ((p = _vm->token(tmpStr)) == NULL) + if ((token = _vm->token(tmpStr)) == NULL) error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); - _colorSet[n][0] = _vm->number(p); + _colorSet[n][0] = _vm->number(token); for (int i = 1; i < 4; i++) { - if ((p = _vm->token(nullptr)) == NULL) + if ((token = _vm->token(nullptr)) == NULL) error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); - _colorSet[n][i] = _vm->number(p); + _colorSet[n][i] = _vm->number(token); } n++; -- cgit v1.2.3 From b08b3eac33a6f4039df5f55a15557f7a2eca245f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 27 Jun 2014 07:34:27 +0200 Subject: CGE2: Add a virtual destructor in Choice, some minor cleanup --- engines/cge2/text.cpp | 2 +- engines/cge2/vga13h.h | 2 +- engines/cge2/vmenu.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index c7f6a06894..24fc8e5376 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -45,7 +45,7 @@ Text::Text(CGE2Engine *vm, const char *fname) : _vm(vm) { _cache = new Handler[txtCount]; for (_size = 0; _size < txtCount; _size++) { _cache[_size]._ref = 0; - _cache[_size]._text = NULL; + _cache[_size]._text = nullptr; } load(); } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 6876bcd825..5e1280c6c9 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -55,7 +55,7 @@ namespace CGE2 { class FXP { // fixed point uint16 f; int16 i; - long& Joined (void) const { return *(long *)&f; } + long& Joined() const { return *(long *)&f; } public: FXP (void): f(0), i(0) { } FXP (int i0, int f0 = 0) : i(i0), f(0) { } diff --git a/engines/cge2/vmenu.h b/engines/cge2/vmenu.h index c988e1ed2b..724fb5d865 100644 --- a/engines/cge2/vmenu.h +++ b/engines/cge2/vmenu.h @@ -45,6 +45,7 @@ public: virtual void proc() = 0; Choice(CGE2Engine *vm) : _vm(vm), _text(nullptr) {} + virtual ~Choice() {} }; class StartCountDownChoice : public Choice { @@ -76,7 +77,7 @@ public: MenuBar *_bar; VMenu(CGE2Engine *vm, Common::Array list, V2D pos, ColorBank col); - ~VMenu(void); + ~VMenu(); void touch(uint16 mask, V2D pos, Common::KeyCode keyCode); char *vmGather(Common::Array list); }; -- cgit v1.2.3 From 723bdc12add207c5a8c87e3b3300e61458e568b5 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 27 Jun 2014 12:10:34 +0200 Subject: CGE2: Make Hero's expand() and contract() virtual. Now it mimics the original correctly. --- engines/cge2/vga13h.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 5e1280c6c9..617e1a7204 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -239,8 +239,8 @@ public: void moveShapesHi(); void moveShapesLo(); int labVal(Action snq, int lab); - Sprite *expand(); - Sprite *contract(); + virtual Sprite *expand(); + virtual Sprite *contract(); void backShow(); void setName(char *newName); inline char *name() { -- cgit v1.2.3 From 2514d866301ca9c9bcc26b54031889e2a0e5a28d Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 27 Jun 2014 23:40:23 +0200 Subject: CGE2: Implement Sprite::step() fully. --- engines/cge2/vga13h.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 9507ade704..29ee5c8b44 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -492,7 +492,36 @@ void Sprite::step(int nr) { _seqPtr = _ext->_seq[_seqPtr]._next; if (_file[2] == '~') { // FLY-type sprite - warning("STUB: Sprite::step() - FLY-type sprite"); + seq = _ext->_seq; + // return to middle + p._x -= seq->_dx; + p._y -= seq->_dy; + p._z -= seq->_dz; + // generate motion + if (_vm->newRandom(10) < 5) { + if ((seq + 1)->_dx) + seq->_dx += _vm->newRandom(3) - 1; + if ((seq + 1)->_dy) + seq->_dy += _vm->newRandom(3) - 1; + if ((seq + 1)->_dz) + seq->_dz += _vm->newRandom(3) - 1; + } + if (seq->_dx < -(seq + 1)->_dx) + seq->_dx += 2; + if (seq->_dx >= (seq + 1)->_dx) + seq->_dx -= 2; + if (seq->_dy < -(seq + 1)->_dy) + seq->_dy += 2; + if (seq->_dy >= (seq + 1)->_dy) + seq->_dy -= 2; + if (seq->_dz < -(seq + 1)->_dz) + seq->_dz += 2; + if (seq->_dz >= (seq + 1)->_dz) + seq->_dz -= 2; + p._x += seq->_dx; + p._y += seq->_dy; + p._z += seq->_dz; + gotoxyz(p); } else { seq = _ext->_seq + _seqPtr; if (seq->_dz == 127 && seq->_dx != 0) { -- cgit v1.2.3 From 6f2e4a76cc590652145daec12174136eb8f5d0a8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 28 Jun 2014 00:46:32 +0200 Subject: CGE2: Add workaround for badly named VBM file in room 11 --- engines/cge2/bitmap.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 6c7e39a00d..93818c05bf 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -48,6 +48,9 @@ Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _v(nullptr), _b(nullptr), _m if (!strcmp(fname, "04tal201")) { strcpy(pat, "04tal202"); warning("Workaround for missing VBM: 04tal201"); + } else if (!strcmp(fname, "11oqlist-")) { + strcpy(pat, "11oqlist"); + warning("Workaround for wrong VBM name: 11oqlist-"); } else strcpy(pat, fname); -- cgit v1.2.3 From 69c8871c3f6fda7baca65f6c389a35c58943f21e Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 28 Jun 2014 19:53:05 +0200 Subject: CGE2: Silence GCC warning in Hero::tick(). --- engines/cge2/hero.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index d1caf1f43e..dfc0e4b351 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -301,6 +301,8 @@ void Hero::tick() { if (_pos2D.x >= kScrWidth - 1 - d) park(); break; + default: + break; } if (_flags._trim) gotoxyz_(_pos2D); -- cgit v1.2.3 From f69ee470ed7d28d4dfd31b7339c7b4a160e52543 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 28 Jun 2014 21:38:21 +0200 Subject: CGE2: Rework FXP::Joined(). This commit hopefully silence a great wall of GCC warnings. --- engines/cge2/vga13h.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 617e1a7204..9d26bd8f74 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -55,13 +55,22 @@ namespace CGE2 { class FXP { // fixed point uint16 f; int16 i; - long& Joined() const { return *(long *)&f; } + long getJoined() const { + long ret = 0; + ret += f; + ret += i << 16; + return ret; + } + void setJoined(long joined) { + i = joined >> 16; + f = joined; + } public: FXP (void): f(0), i(0) { } FXP (int i0, int f0 = 0) : i(i0), f(0) { } FXP& operator = (const int& x) { i = x; f = 0; return *this; } - FXP operator + (const FXP& x) const { FXP y; y.Joined() = Joined() + x.Joined(); return y; } - FXP operator - (const FXP& x) const { FXP y; y.Joined() = Joined() - x.Joined(); return y; } + FXP operator + (const FXP& x) const { FXP y; y.setJoined(getJoined() + x.getJoined()); return y; } + FXP operator - (const FXP& x) const { FXP y; y.setJoined(getJoined() - x.getJoined()); return y; } FXP operator * (const FXP& x) const { FXP y; long t; y.i = i * x.i; @@ -74,7 +83,7 @@ public: FXP operator / (const FXP& x) const { FXP y; bool sign = false; if (!x.empty()) { - long j = Joined(), jx = x.Joined(); + long j = getJoined(), jx = x.getJoined(); if (j < 0) { j = -j; sign ^= 1; @@ -89,7 +98,7 @@ public: y.f = unsigned((r << 4) / (jx >> 12)); //------------------ if (sign) - y.Joined() = -y.Joined(); + y.setJoined(-y.getJoined()); } return y; -- cgit v1.2.3 From 2f80cf6faf10e6e10728a19a72c414587b14cd26 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 28 Jun 2014 21:39:16 +0200 Subject: CGE2: Fix formatting of FXP's operators. --- engines/cge2/vga13h.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 9d26bd8f74..6c68c8cf07 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -68,10 +68,10 @@ class FXP { // fixed point public: FXP (void): f(0), i(0) { } FXP (int i0, int f0 = 0) : i(i0), f(0) { } - FXP& operator = (const int& x) { i = x; f = 0; return *this; } - FXP operator + (const FXP& x) const { FXP y; y.setJoined(getJoined() + x.getJoined()); return y; } - FXP operator - (const FXP& x) const { FXP y; y.setJoined(getJoined() - x.getJoined()); return y; } - FXP operator * (const FXP& x) const { + FXP& operator=(const int& x) { i = x; f = 0; return *this; } + FXP operator+(const FXP& x) const { FXP y; y.setJoined(getJoined() + x.getJoined()); return y; } + FXP operator-(const FXP& x) const { FXP y; y.setJoined(getJoined() - x.getJoined()); return y; } + FXP operator*(const FXP& x) const { FXP y; long t; y.i = i * x.i; t = ((long) f * x.f) >> 16; @@ -80,7 +80,7 @@ public: y.i += t >> 16; return y; } - FXP operator / (const FXP& x) const { + FXP operator/(const FXP& x) const { FXP y; bool sign = false; if (!x.empty()) { long j = getJoined(), jx = x.getJoined(); @@ -104,14 +104,14 @@ public: return y; } //int& operator = (int& a, const FXP& b) { return a = b.i; } - friend int& operator += (int& a, const FXP& b) { return a += b.i; } - friend int& operator -= (int& a, const FXP& b) { return a -= b.i; } - friend FXP& operator += (FXP& a, const int& b) { a.i += b; return a; } - friend FXP& operator -= (FXP& a, const int& b) { a.i -= b; return a; } - friend bool operator == (const FXP &a, const FXP &b) { return (a.i == b.i) && (a.f == b.f); } - friend bool operator != (const FXP &a, const FXP &b) { return (a.i != b.i) || (a.f != b.f); } - friend bool operator < (const FXP &a, const FXP &b) { return (a.i < b.i) || ((a.i == b.i) && (a.f < b.f)); } - friend bool operator > (const FXP &a, const FXP &b) { return (a.i > b.i) || ((a.i == b.i) && (a.f > b.f)); } + friend int& operator+=(int& a, const FXP& b) { return a += b.i; } + friend int& operator-=(int& a, const FXP& b) { return a -= b.i; } + friend FXP& operator+=(FXP& a, const int& b) { a.i += b; return a; } + friend FXP& operator-=(FXP& a, const int& b) { a.i -= b; return a; } + friend bool operator==(const FXP &a, const FXP &b) { return (a.i == b.i) && (a.f == b.f); } + friend bool operator!=(const FXP &a, const FXP &b) { return (a.i != b.i) || (a.f != b.f); } + friend bool operator<(const FXP &a, const FXP &b) { return (a.i < b.i) || ((a.i == b.i) && (a.f < b.f)); } + friend bool operator>(const FXP &a, const FXP &b) { return (a.i > b.i) || ((a.i == b.i) && (a.f > b.f)); } int trunc(void) const { return i; } int round(void) const { return i + (f > 0x7FFF); } bool empty() const { return i == 0 && f == 0; } -- cgit v1.2.3 From 160212c8e3219b28968ad653a0d730223b338a38 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 28 Jun 2014 23:44:48 +0200 Subject: CGE2: Add fallback detection for the currently WIP English translation. --- engines/cge2/detection.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index e417a13853..cbe78dae4f 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -45,15 +45,6 @@ static const ADGameDescription gameDescriptions[] = { }, Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() }, - { - "sfinx", "Sfinx English Alfa v0.1", - { - {"vol.cat", 0, "41a61030468e33828f3531fd53ef0319", 129024}, - {"vol.dat", 0, "978ebe56442c111d193fdb4d960cc58d", 34382498}, - AD_LISTEND - }, - Common::EN_ANY, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() - }, AD_TABLE_END_MARKER }; @@ -73,6 +64,8 @@ public: virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; virtual bool hasFeature(MetaEngineFeature f) const; + + const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; }; bool CGE2MetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { @@ -86,6 +79,32 @@ bool CGE2MetaEngine::hasFeature(MetaEngineFeature f) const { return false; } +const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { + static ADGameDescription desc; + + for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { + if (file->isDirectory()) { + continue; + } + if (file->getName().equalsIgnoreCase("lang.eng")) { + Common::File dataFile; + if (!dataFile.open(*file)) { + continue; + } + + desc.gameid = "sfinx"; + desc.extra = "Sfinx English Alfa v0.1"; + desc.language = Common::EN_ANY; + desc.platform = Common::kPlatformDOS; + desc.flags = ADGF_NO_FLAGS; + desc.guioptions = GUIO0(); + + return (const ADGameDescription *)&desc; + } + } + return 0; +} + } // End of namespace CGE2 #if PLUGIN_ENABLED_DYNAMIC(CGE2) -- cgit v1.2.3 From 38a59bee3e85f82672ce88befb2e428d243416db Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 29 Jun 2014 20:36:54 +0200 Subject: CGE2: Add skeleton for save/load system. Also rename loadGame() to loadHeroes(). --- engines/cge2/cge2.cpp | 22 +---- engines/cge2/cge2.h | 19 ++++- engines/cge2/cge2_main.cpp | 6 +- engines/cge2/detection.cpp | 51 ++---------- engines/cge2/detection.h | 80 ++++++++++++++++++ engines/cge2/module.mk | 3 +- engines/cge2/saveload.cpp | 197 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 309 insertions(+), 69 deletions(-) create mode 100644 engines/cge2/detection.h create mode 100644 engines/cge2/saveload.cpp (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 6976a6fc82..1a9f48d317 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -35,7 +35,6 @@ #include "cge2/hero.h" #include "cge2/general.h" #include "cge2/spare.h" -#include "cge2/events.h" #include "cge2/talk.h" #include "cge2/cge2_main.h" #include "cge2/map.h" @@ -158,24 +157,9 @@ void CGE2Engine::deinit() { } bool CGE2Engine::hasFeature(EngineFeature f) const { - return false; -} - -bool CGE2Engine::canLoadGameStateCurrently() { - return false; -} -bool CGE2Engine::canSaveGameStateCurrently() { - return false; -} - -Common::Error CGE2Engine::loadGameState(int slot) { - warning("STUB: CGE2Engine::loadGameState()"); - return Common::kNoError; -} - -Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { - warning("STUB: CGE2Engine::saveGameState()"); - return Common::kNoError; + return + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); } Common::Error CGE2Engine::run() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c569bf9458..e3606b821b 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -29,6 +29,8 @@ #define CGE2_H #include "common/random.h" +#include "common/savefile.h" +#include "common/serializer.h" #include "engines/engine.h" #include "engines/advancedDetector.h" #include "common/system.h" @@ -59,6 +61,7 @@ class System; class EventManager; class Font; class Map; +struct SavegameHeader; #define kScrWidth 320 #define kScrHeight 240 @@ -105,6 +108,10 @@ class Map; #define kQuitText 201 #define kNoQuitText 202 +#define kSavegameVersion 1 +#define kSavegameStrSize 12 +#define kSavegameStr "SCUMMVM_CGE2" + enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume }; @@ -119,22 +126,28 @@ class CGE2Engine : public Engine { private: uint32 _lastFrame, _lastTick; void tick(); + + Common::String generateSaveName(int slot); + void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); + void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); + void syncHeader(Common::Serializer &s); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); virtual bool hasFeature(EngineFeature f) const; - virtual bool canLoadGameStateCurrently(); virtual bool canSaveGameStateCurrently(); - virtual Common::Error loadGameState(int slot); + virtual bool canLoadGameStateCurrently(); virtual Common::Error saveGameState(int slot, const Common::String &desc); + virtual Common::Error loadGameState(int slot); virtual Common::Error run(); + static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); bool showTitle(const char *name); void cge2_main(); char *mergeExt(char *buf, const char *name, const char *ext); void inf(const char *text, ColorBank col = kCBInf); void movie(const char *ext); void runGame(); - void loadGame(); + void loadHeroes(); void loadScript(const char *fname); void loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 75b9affc1a..77ad7181fc 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -726,12 +726,12 @@ void CGE2Engine::loadUser() { warning("STUB: CGE2Engine::loadUser()"); // Missing loading from file. TODO: Implement it with the saving/loading! loadScript("CGE.INI"); - loadGame(); + loadHeroes(); loadPos(); } -void CGE2Engine::loadGame() { - warning("STUB: CGE2Engine::loadGame()"); +void CGE2Engine::loadHeroes() { // Original name: loadGame() + warning("STUB: CGE2Engine::loadHeroes()"); // load sprites & pocket diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index cbe78dae4f..599934b57d 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -25,49 +25,10 @@ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon */ -#include "cge2/cge2.h" -#include "engines/advancedDetector.h" +#include "cge2/detection.h" namespace CGE2 { -static const PlainGameDescriptor CGE2Games[] = { - { "sfinx", "Sfinx" }, - { 0, 0 } -}; - -static const ADGameDescription gameDescriptions[] = { - { - "sfinx", "Sfinx Freeware", - { - { "vol.cat", 0, "21197b287d397c53261b6616bf0dd880", 129024 }, - { "vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844 }, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() - }, - AD_TABLE_END_MARKER -}; - -class CGE2MetaEngine : public AdvancedMetaEngine { -public: - CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games) { - _singleid = "sfinx"; - } - - virtual const char *getName() const { - return "CGE2"; - } - - virtual const char *getOriginalCopyright() const { - return "Sfinx (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon"; - } - - virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; - virtual bool hasFeature(MetaEngineFeature f) const; - - const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; -}; - bool CGE2MetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { if (desc) { *engine = new CGE2::CGE2Engine(syst, desc); @@ -76,7 +37,11 @@ bool CGE2MetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGame } bool CGE2MetaEngine::hasFeature(MetaEngineFeature f) const { - return false; + return + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail) || + (f == kSavesSupportCreationDate); } const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { @@ -108,7 +73,7 @@ const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, } // End of namespace CGE2 #if PLUGIN_ENABLED_DYNAMIC(CGE2) - REGISTER_PLUGIN_DYNAMIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); +REGISTER_PLUGIN_DYNAMIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); #else - REGISTER_PLUGIN_STATIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); +REGISTER_PLUGIN_STATIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); #endif diff --git a/engines/cge2/detection.h b/engines/cge2/detection.h new file mode 100644 index 0000000000..556980774a --- /dev/null +++ b/engines/cge2/detection.h @@ -0,0 +1,80 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef CGE2_DETECTION_H +#define CGE2_DETECTION_H + +#include "cge2/cge2.h" +#include "engines/advancedDetector.h" + +namespace CGE2 { + +static const PlainGameDescriptor CGE2Games[] = { + { "sfinx", "Sfinx" }, + { 0, 0 } +}; + +static const ADGameDescription gameDescriptions[] = { + { + "sfinx", "Sfinx Freeware", + { + { "vol.cat", 0, "21197b287d397c53261b6616bf0dd880", 129024 }, + { "vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844 }, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() + }, + AD_TABLE_END_MARKER +}; + +class CGE2MetaEngine : public AdvancedMetaEngine { +public: + CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games) { + _singleid = "sfinx"; + } + + virtual const char *getName() const { + return "CGE2"; + } + + virtual const char *getOriginalCopyright() const { + return "Sfinx (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon"; + } + + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual bool hasFeature(MetaEngineFeature f) const; + virtual int getMaximumSaveSlot() const; + virtual SaveStateList listSaves(const char *target) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; + virtual void removeSaveState(const char *target, int slot) const; + + const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; +}; + +} // End of namespace CGE2 + +#endif // CGE2_DETECTION_H diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 9a6e0cb595..cb2b51e5d3 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -15,7 +15,8 @@ MODULE_OBJS = \ talk.o \ events.o \ map.o \ - vmenu.o + vmenu.o \ + saveload.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp new file mode 100644 index 0000000000..ac059e5d8f --- /dev/null +++ b/engines/cge2/saveload.cpp @@ -0,0 +1,197 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/detection.h" +#include "common/config-manager.h" +#include "common/savefile.h" +#include "common/system.h" +#include "graphics/thumbnail.h" +#include "graphics/surface.h" +#include "graphics/palette.h" +#include "graphics/scaler.h" +#include "cge2/events.h" +#include "cge2/snail.h" +#include "cge2/hero.h" + +namespace CGE2 { + +struct SavegameHeader { + uint8 version; + Common::String saveName; + Graphics::Surface *thumbnail; + int saveYear, saveMonth, saveDay; + int saveHour, saveMinutes; +}; + +int CGE2MetaEngine::getMaximumSaveSlot() const { + return 99; +} + +SaveStateList CGE2MetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".???"; + + filenames = saveFileMan->listSavefiles(pattern); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(filename->c_str() + filename->size() - 3); + + if (slotNum >= 0 && slotNum <= 99) { + + Common::InSaveFile *file = saveFileMan->openForLoading(*filename); + if (file) { + CGE2::SavegameHeader header; + + // Check to see if it's a ScummVM savegame or not + char buffer[kSavegameStrSize + 1]; + file->read(buffer, kSavegameStrSize + 1); + + if (!strncmp(buffer, kSavegameStr, kSavegameStrSize + 1)) { + // Valid savegame + if (CGE2::CGE2Engine::readSavegameHeader(file, header)) { + saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); + if (header.thumbnail) { + header.thumbnail->free(); + delete header.thumbnail; + } + } + } else { + // Must be an original format savegame + saveList.push_back(SaveStateDescriptor(slotNum, "Unknown")); + } + + delete file; + } + } + } + + return saveList; +} + +SaveStateDescriptor CGE2MetaEngine::querySaveMetaInfos(const char *target, int slot) const { + Common::String fileName = Common::String::format("%s.%03d", target, slot); + Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName); + + if (f) { + CGE2::SavegameHeader header; + + // Check to see if it's a ScummVM savegame or not + char buffer[kSavegameStrSize + 1]; + f->read(buffer, kSavegameStrSize + 1); + + bool hasHeader = !strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) && + CGE2::CGE2Engine::readSavegameHeader(f, header); + delete f; + + if (!hasHeader) { + // Original savegame perhaps? + SaveStateDescriptor desc(slot, "Unknown"); + return desc; + } else { + // Create the return descriptor + SaveStateDescriptor desc(slot, header.saveName); + desc.setThumbnail(header.thumbnail); + desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); + desc.setSaveTime(header.saveHour, header.saveMinutes); + + // Slot 0 is used for the 'automatic save on exit' save in Soltys, thus + // we prevent it from being deleted or overwritten by accident. + desc.setDeletableFlag(slot != 0); + desc.setWriteProtectedFlag(slot == 0); + + return desc; + } + } + + return SaveStateDescriptor(); +} + +bool CGE2Engine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) { + header.thumbnail = nullptr; + + // Get the savegame version + header.version = in->readByte(); + if (header.version > kSavegameVersion) + return false; + + // Read in the string + header.saveName.clear(); + char ch; + while ((ch = (char)in->readByte()) != '\0') + header.saveName += ch; + + // Get the thumbnail + header.thumbnail = Graphics::loadThumbnail(*in); + if (!header.thumbnail) + return false; + + // Read in save date/time + header.saveYear = in->readSint16LE(); + header.saveMonth = in->readSint16LE(); + header.saveDay = in->readSint16LE(); + header.saveHour = in->readSint16LE(); + header.saveMinutes = in->readSint16LE(); + + return true; +} + +void CGE2MetaEngine::removeSaveState(const char *target, int slot) const { + Common::String fileName = Common::String::format("%s.%03d", target, slot); + g_system->getSavefileManager()->removeSavefile(fileName); +} + +bool CGE2Engine::canSaveGameStateCurrently() { + bool isHeroVisible = false; + for (int i = 0; i < 2; i++) { + isHeroVisible = !_heroTab[i]->_ptr->_flags._hide; + if (isHeroVisible) + break; + } + return (_startupMode == 0) && _mouse->_active && + _commandHandler->idle() && isHeroVisible; +} + +bool CGE2Engine::canLoadGameStateCurrently() { + return (_startupMode == 0) && _mouse->_active; +} + +Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { + warning("STUB: CGE2Engine::saveGameState()"); + return Common::kNoError; +} + +Common::Error CGE2Engine::loadGameState(int slot) { + warning("STUB: CGE2Engine::loadGameState()"); + return Common::kNoError; +} + +} // End of namespace CGE2 -- cgit v1.2.3 From b6d4281917d10effdd3890f8d1f740558da409c4 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 29 Jun 2014 21:38:46 +0200 Subject: CGE2: Call loadPos() from loadHero() instead of loadUser(). --- engines/cge2/cge2_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 77ad7181fc..2e70125fa6 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -727,7 +727,6 @@ void CGE2Engine::loadUser() { // Missing loading from file. TODO: Implement it with the saving/loading! loadScript("CGE.INI"); loadHeroes(); - loadPos(); } void CGE2Engine::loadHeroes() { // Original name: loadGame() @@ -770,6 +769,8 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() //--- start! switchHero(_sex); + + loadPos(); } void CGE2Engine::loadPos() { -- cgit v1.2.3 From ade740de1098930d5b9827b98c844d300ded04b8 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 29 Jun 2014 22:52:03 +0200 Subject: CGE2: Implement saving. --- engines/cge2/saveload.cpp | 123 +++++++++++++++++++++++++++++++++++++++++++--- engines/cge2/spare.cpp | 5 +- engines/cge2/spare.h | 2 +- engines/cge2/vga13h.cpp | 54 +++++++++++--------- engines/cge2/vga13h.h | 1 + 5 files changed, 153 insertions(+), 32 deletions(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index ac059e5d8f..971b044e35 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -36,9 +36,13 @@ #include "cge2/events.h" #include "cge2/snail.h" #include "cge2/hero.h" +#include "cge2/text.h" namespace CGE2 { +#define kSavegameCheckSum (1997 + _now + _music + kWorldHeight) +#define kBadSVG 99 + struct SavegameHeader { uint8 version; Common::String saveName; @@ -123,11 +127,6 @@ SaveStateDescriptor CGE2MetaEngine::querySaveMetaInfos(const char *target, int s desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); desc.setSaveTime(header.saveHour, header.saveMinutes); - // Slot 0 is used for the 'automatic save on exit' save in Soltys, thus - // we prevent it from being deleted or overwritten by accident. - desc.setDeletableFlag(slot != 0); - desc.setWriteProtectedFlag(slot == 0); - return desc; } } @@ -185,10 +184,122 @@ bool CGE2Engine::canLoadGameStateCurrently() { } Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { - warning("STUB: CGE2Engine::saveGameState()"); + // Set up the serializer + Common::String slotName = generateSaveName(slot); + Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(slotName); + + // Write out the ScummVM savegame header + SavegameHeader header; + header.saveName = desc; + header.version = kSavegameVersion; + writeSavegameHeader(saveFile, header); + + // Write out the data of the savegame + syncGame(NULL, saveFile); + + // Finish writing out game data + saveFile->finalize(); + delete saveFile; + return Common::kNoError; } +/** +* Support method that generates a savegame name +* @param slot Slot number +*/ +Common::String CGE2Engine::generateSaveName(int slot) { + return Common::String::format("%s.%03d", _targetName.c_str(), slot); +} + +void CGE2Engine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header) { + // Write out a savegame header + out->write(kSavegameStr, kSavegameStrSize + 1); + + out->writeByte(kSavegameVersion); + + // Write savegame name + out->write(header.saveName.c_str(), header.saveName.size() + 1); + + // Get the active palette + uint8 thumbPalette[256 * 3]; + g_system->getPaletteManager()->grabPalette(thumbPalette, 0, 256); + + // Create a thumbnail and save it + Graphics::Surface *thumb = new Graphics::Surface(); + Graphics::Surface *s = _vga->_page[0]; + ::createThumbnail(thumb, (const byte *)s->getPixels(), kScrWidth, kScrHeight, thumbPalette); + Graphics::saveThumbnail(*out, *thumb); + thumb->free(); + delete thumb; + + // Write out the save date/time + TimeDate td; + g_system->getTimeAndDate(td); + out->writeSint16LE(td.tm_year + 1900); + out->writeSint16LE(td.tm_mon + 1); + out->writeSint16LE(td.tm_mday); + out->writeSint16LE(td.tm_hour); + out->writeSint16LE(td.tm_min); +} + +void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream) { + Common::Serializer s(readStream, writeStream); + + // Synchronise header data + syncHeader(s); + + if (s.isSaving()) { + for (int i = 0; i < kSceneMax; i++) + _eyeTab[i]->sync(s); + + _spare->sync(s); + + // The references of the items in the heroes pockets: + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax; j++) { + Sprite *spr = _heroTab[i]->_pocket[j]; + int ref = (spr) ? spr->_ref : -1; + s.syncAsSint16LE(ref); + } + } + + for (int i = 0; i < kMaxPoint; i++) + _point[i]->sync(s); + } else { + // Loading game + } +} + +void CGE2Engine::syncHeader(Common::Serializer &s) { + s.syncAsUint16LE(_now); + s.syncAsUint16LE(_sex); + s.syncAsUint16LE(_music); + s.syncAsUint16LE(_waitSeq); + s.syncAsUint16LE(_waitRef); + s.syncAsUint16LE(_sayCap); + s.syncAsUint16LE(_sayVox); + for (int i = 0; i < 4; i++) + s.syncAsUint16LE(_flag[i]); + + if (s.isLoading()) { + // Reset scene values + //initSceneValues(); + } + + if (s.isSaving()) { + // Write checksum + int checksum = kSavegameCheckSum; + s.syncAsUint16LE(checksum); + } else { + // Read checksum and validate it + uint16 checksum = 0; + s.syncAsUint16LE(checksum); + if (checksum != kSavegameCheckSum) + error("%s", _text->getText(kBadSVG)); + } +} + Common::Error CGE2Engine::loadGameState(int slot) { warning("STUB: CGE2Engine::loadGameState()"); return Common::kNoError; diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 8382310e1b..76f0065196 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -29,8 +29,9 @@ namespace CGE2 { -void Spare::synchronize() { - warning("STUB: Spare::Load"); +void Spare::sync(Common::Serializer &s) { + for (int i = 0; i < _container.size(); i++) + _container[i]->sync(s); } void Spare::clear() { diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 77bdb3319f..7dc6ce60f5 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -46,7 +46,7 @@ public: void dispose(Sprite *spr); void dispose(int ref); void dispose(); - void synchronize(); + void sync(Common::Serializer &s); uint16 count() { return _container.size(); } void clear(); }; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 29ee5c8b44..a181621008 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -39,6 +39,25 @@ namespace CGE2 { +void V3D::sync(Common::Serializer &s) { + int pos = 0; + if (s.isLoading()) { + s.syncAsSint16LE(pos); + _x = FXP(pos); + s.syncAsSint16LE(pos); + _y = FXP(pos); + s.syncAsSint16LE(pos); + _z = FXP(pos); + } else { + pos = _x.trunc(); + s.syncAsUint16LE(pos); + pos = _y.trunc(); + s.syncAsUint16LE(pos); + pos = _z.trunc(); + s.syncAsByte(pos); + } +} + Seq *getConstantSeq(bool seqFlag) { const Seq seq1[] = { { 0, 0, 0, 0, 0, 0 } }; const Seq seq2[] = { { 0, 1, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0, 0 } }; @@ -675,10 +694,6 @@ BitmapPtr Sprite::ghost() { } void Sprite::sync(Common::Serializer &s) { - uint16 unused = 0; - - s.syncAsUint16LE(unused); - s.syncAsUint16LE(unused); // _ext s.syncAsUint16LE(_ref); s.syncAsByte(_scene); @@ -723,31 +738,24 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(flags); } - int pos = 0; - if (s.isLoading()) { - s.syncAsSint16LE(pos); - _pos3D._x = FXP(pos, 0); - s.syncAsSint16LE(pos); - _pos3D._y = pos; - s.syncAsSint16LE(pos); - _pos3D._z = pos; - } else { - pos = _pos3D._x.trunc(); - s.syncAsUint16LE(pos); - pos = _pos3D._y.trunc(); - s.syncAsUint16LE(pos); - pos = _pos3D._z.trunc(); - s.syncAsByte(pos); - } + s.syncAsSint16LE(_pos2D.x); + s.syncAsSint16LE(_pos2D.y); + + _pos3D.sync(s); + + s.syncAsSint16LE(_siz.x); + s.syncAsSint16LE(_siz.y); s.syncAsUint16LE(_time); + for (int i = 0; i < kActions; i++){ + s.syncAsSint16LE(_actionCtrl->_ptr); + s.syncAsSint16LE(_actionCtrl->_cnt); + } s.syncAsSint16LE(_seqPtr); + s.syncAsSint16LE(_seqCnt); s.syncAsUint16LE(_shpCnt); s.syncBytes((byte *)&_file[0], 9); _file[8] = '\0'; - - s.syncAsUint16LE(unused); // _prev - s.syncAsUint16LE(unused); // _next } Queue::Queue(bool show) : _head(NULL), _tail(NULL) { diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 6c68c8cf07..c42b7a746e 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -132,6 +132,7 @@ public: bool operator!=(const V3D &p) const { return _x != p._x || _y != p._y || _z != p._z; } V3D& operator+=(const V3D &x) { return *this = *this + x; } V3D& operator-=(const V3D &x) { return *this = *this - x; } + void sync(Common::Serializer &s); }; class V2D : public Common::Point { -- cgit v1.2.3 From 7810df976b2c2df324092add3f06b0841e1b0dca Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 30 Jun 2014 01:10:17 +0200 Subject: CGE2: Rework Hero::expand() so it won't modify Text's content. --- engines/cge2/hero.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index dfc0e4b351..7e6c384a46 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -40,7 +40,10 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo if (_ext) return this; - char *text = _vm->_text->getText(_ref + 100); + Common::String str(_vm->_text->getText(_ref + 100)); + char text[kLineMax + 1]; + strcpy(text, str.c_str()); + char fname[kMaxPath]; _vm->mergeExt(fname, _file, kSprExt); _ext = new SprExt(_vm); -- cgit v1.2.3 From b48c94a5415ece41319d5aa814e4ad16cf1ff4a8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 2 Jul 2014 01:33:37 +0200 Subject: CGE2: Fix GCC warning --- engines/cge2/spare.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 76f0065196..d202be9aff 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -30,7 +30,7 @@ namespace CGE2 { void Spare::sync(Common::Serializer &s) { - for (int i = 0; i < _container.size(); i++) + for (uint i = 0; i < _container.size(); i++) _container[i]->sync(s); } -- cgit v1.2.3 From 1305bc8aa8b46459dfea08ad52309a57dbda64d8 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 2 Jul 2014 22:57:49 +0200 Subject: CGE2: Add, implement and use saveHeroPos(). --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index e3606b821b..af16311ab2 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -155,6 +155,7 @@ public: void sceneDown(); void closePocket(); void switchScene(int scene); + void saveHeroPos(); void showBak(int ref); void loadTab(); int newRandom(int range); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 2e70125fa6..dead21d5a4 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -505,14 +505,9 @@ void CGE2Engine::switchScene(int scene) { */ _req = scene; - for (int i = 0; i < 2; i++) { - Hero *h = _heroTab[i]->_ptr; - if (h->_scene == _now) { - delete _heroTab[i]->_posTab[_now]; - V2D *temp = new V2D(this, h->_pos3D._x.trunc(), h->_pos3D._z.trunc()); - _heroTab[i]->_posTab[_now] = temp; - } - } + + saveHeroPos(); + *(_eyeTab[_now]) = *_eye; if (scene < 0) _commandHandler->addCallback(kCmdExec, -1, 0, kQGame); // quit game @@ -530,6 +525,17 @@ void CGE2Engine::switchScene(int scene) { } } +void CGE2Engine::saveHeroPos() { + for (int i = 0; i < 2; i++) { + Hero *h = _heroTab[i]->_ptr; + if (h->_scene == _now) { + delete _heroTab[i]->_posTab[_now]; + V2D *temp = new V2D(this, h->_pos3D._x.trunc(), h->_pos3D._z.trunc()); + _heroTab[i]->_posTab[_now] = temp; + } + } +} + void CGE2Engine::showBak(int ref) { Sprite *spr = _spare->take(ref); if (spr != nullptr) { -- cgit v1.2.3 From b9dc93c451d891704d828e3c384aae015a63ff40 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 3 Jul 2014 00:39:23 +0200 Subject: CGE2: Heavily rework memory management of Sprites. Hopefully it will solve a bunch of memory leak problems. Now Spare is a central container, which stores pointers to every Sprite currently used by the engine. Because of that, there's no more need for Queue's clear(). In case of snKill(), it's just a safeguard, since it's only used by the engine to "kill" the speech bubbles, but we will check Spare anyway, so it's the safest this way. --- engines/cge2/cge2.cpp | 2 +- engines/cge2/cge2_main.cpp | 8 ++------ engines/cge2/snail.cpp | 5 +++-- engines/cge2/spare.cpp | 3 +++ engines/cge2/vga13h.cpp | 14 -------------- engines/cge2/vga13h.h | 2 -- 6 files changed, 9 insertions(+), 25 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 1a9f48d317..e6df241ea9 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -126,6 +126,7 @@ void CGE2Engine::init() { } void CGE2Engine::deinit() { + delete _spare; delete _resman; delete _vga; delete _fx; @@ -138,7 +139,6 @@ void CGE2Engine::deinit() { delete _eyeTab[i]; } delete _eye; - delete _spare; delete _sprite; delete _commandHandler; delete _commandHandlerTurbo; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index dead21d5a4..5a4b2c1443 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -280,8 +280,6 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { _sprite = h; } } else { - if (_sprite) - delete _sprite; _sprite = new Sprite(this); if (_sprite) _sprite->gotoxyz(pos); @@ -414,7 +412,6 @@ void CGE2Engine::movie(const char *ext) { _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); - _vga->_showQ->clear(); _spare->clear(); _now = now; } @@ -725,7 +722,6 @@ void CGE2Engine::runGame() { _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); _mouse->off(); - _vga->_showQ->clear(); } void CGE2Engine::loadUser() { @@ -749,7 +745,6 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() h = new Hero(this); *(Sprite*)h = *s; delete s; - s = nullptr; h->expand(); _spare->update(h); } @@ -757,6 +752,7 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() s = _spare->take(152); _vga->_showQ->insert(s); _heroTab[0]->_face = s; + _spare->update(s); // initialize Wacek/Vincent s = _spare->take(141); @@ -764,7 +760,6 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() h = new Hero(this); *(Sprite*)h = *s; delete s; - s = nullptr; h->expand(); _spare->update(h); } @@ -772,6 +767,7 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() s = _spare->take(151); _vga->_showQ->insert(s); _heroTab[1]->_face = s; + _spare->update(s); //--- start! switchHero(_sex); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 9b77fe359e..609196cc26 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -344,9 +344,10 @@ void CGE2Engine::snKill(Sprite *spr) { hide1(spr); _vga->_showQ->remove(spr); _eventManager->clearEvent(spr); - if (spr->_flags._kill) + if (spr->_flags._kill) { + _spare->take(spr->_ref); delete spr; - else { + } else { spr->setScene(-1); _spare->dispose(spr); } diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index d202be9aff..dde37d4fbe 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -35,6 +35,9 @@ void Spare::sync(Common::Serializer &s) { } void Spare::clear() { + for (int i = 0; i < _container.size(); i++) + delete _container[i]; + _container.clear(); } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index a181621008..3ce690ed6a 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -761,20 +761,6 @@ void Sprite::sync(Common::Serializer &s) { Queue::Queue(bool show) : _head(NULL), _tail(NULL) { } -Queue::~Queue() { - clear(); -} - -void Queue::clear() { - while (_head) { - Sprite *s = remove(_head); - if (s->_flags._kill) { - delete s; - s = nullptr; - } - } -} - void Queue::append(Sprite *spr) { if (spr->_flags._back) spr->backShow(); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index c42b7a746e..ce914ce2c8 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -284,7 +284,6 @@ class Queue { Sprite *_tail; public: Queue(bool show); - ~Queue(); void append(Sprite *spr); void insert(Sprite *spr, Sprite *nxt); @@ -298,7 +297,6 @@ public: } Sprite *locate(int ref); bool locate(Sprite *spr); - void clear(); }; class Vga { -- cgit v1.2.3 From aeaac02332a8faa32a7f6c534309b71432dd3a2b Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 3 Jul 2014 00:50:42 +0200 Subject: CGE2: Silence warning. --- engines/cge2/spare.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index dde37d4fbe..5db4772fc7 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -36,6 +36,7 @@ void Spare::sync(Common::Serializer &s) { void Spare::clear() { for (int i = 0; i < _container.size(); i++) + for (uint i = 0; i < _container.size(); i++) delete _container[i]; _container.clear(); -- cgit v1.2.3 From f155546ecb03e0a308cdb6b2308ab01c992e71ce Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 3 Jul 2014 01:19:30 +0200 Subject: CGE2: Partially working save/load system. There's a mayor bug which blocks the toolbar from interaction after loading. To be investigated during the upcoming days. --- engines/cge2/cge2.h | 2 + engines/cge2/cge2_main.cpp | 3 +- engines/cge2/saveload.cpp | 110 ++++++++++++++++++++++++++++++++++++++------- engines/cge2/spare.cpp | 25 +++++++++-- engines/cge2/spare.h | 2 +- engines/cge2/vga13h.cpp | 28 +++++------- engines/cge2/vga13h.h | 3 ++ 7 files changed, 131 insertions(+), 42 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index af16311ab2..aade31f2b8 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -131,6 +131,8 @@ private: void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); void syncHeader(Common::Serializer &s); + bool loadGame(int slotNumber); + void resetGame(); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); virtual bool hasFeature(EngineFeature f) const; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 5a4b2c1443..071340508c 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -729,6 +729,7 @@ void CGE2Engine::loadUser() { // Missing loading from file. TODO: Implement it with the saving/loading! loadScript("CGE.INI"); loadHeroes(); + loadPos(); } void CGE2Engine::loadHeroes() { // Original name: loadGame() @@ -771,8 +772,6 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() //--- start! switchHero(_sex); - - loadPos(); } void CGE2Engine::loadPos() { diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 971b044e35..8d0237e702 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -37,6 +37,7 @@ #include "cge2/snail.h" #include "cge2/hero.h" #include "cge2/text.h" +#include "cge2/sound.h" namespace CGE2 { @@ -195,7 +196,10 @@ Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { writeSavegameHeader(saveFile, header); // Write out the data of the savegame - syncGame(NULL, saveFile); + saveHeroPos(); + sceneDown(); + syncGame(nullptr, saveFile); + sceneUp(_now); // Finish writing out game data saveFile->finalize(); @@ -249,13 +253,11 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS // Synchronise header data syncHeader(s); - if (s.isSaving()) { - for (int i = 0; i < kSceneMax; i++) - _eyeTab[i]->sync(s); - - _spare->sync(s); + // Synchronise _spare and mingled with it, the sprites of the heroes' + _spare->sync(s, _heroTab); - // The references of the items in the heroes pockets: + if (s.isSaving()) { + // Save the references of the items in the heroes pockets: for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { Sprite *spr = _heroTab[i]->_pocket[j]; @@ -263,11 +265,23 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS s.syncAsSint16LE(ref); } } - - for (int i = 0; i < kMaxPoint; i++) - _point[i]->sync(s); } else { - // Loading game + // Load items to the pockets + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax; j++) { + int ref = 0; + s.syncAsSint16LE(ref); + _heroTab[i]->_pocket[j] = _spare->locate(ref); + } + } + } + + // Heroes' _posTabs + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kSceneMax; j++) { + s.syncAsSint16LE(_heroTab[i]->_posTab[j]->x); + s.syncAsSint16LE(_heroTab[i]->_posTab[j]->y); + } } } @@ -282,11 +296,6 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { for (int i = 0; i < 4; i++) s.syncAsUint16LE(_flag[i]); - if (s.isLoading()) { - // Reset scene values - //initSceneValues(); - } - if (s.isSaving()) { // Write checksum int checksum = kSavegameCheckSum; @@ -301,8 +310,75 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { } Common::Error CGE2Engine::loadGameState(int slot) { - warning("STUB: CGE2Engine::loadGameState()"); + // Clear current game activity + sceneDown(); + resetGame(); + // If music is playing, kill it. + if (_music) + _midiPlayer->killMidi(); + + if (!loadGame(slot)) + return Common::kReadingFailed; + + loadHeroes(); + + sceneUp(_now); + + _busyPtr = _vga->_showQ->locate(kBusyRef); + + _vol[0] = _vga->_showQ->locate(kDvolRef); + _vol[1] = _vga->_showQ->locate(kMvolRef); + return Common::kNoError; } +void CGE2Engine::resetGame() { + _busyPtr = nullptr; + busy(false); + _spare->clear(); + _vga->_showQ->clear(); + _commandHandler->reset(); +} + +bool CGE2Engine::loadGame(int slotNumber) { + Common::MemoryReadStream *readStream; + + // Open up the savegame file + Common::String slotName = generateSaveName(slotNumber); + Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName); + + // Read the data into a data buffer + int size = saveFile->size(); + byte *dataBuffer = (byte *)malloc(size); + saveFile->read(dataBuffer, size); + readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES); + delete saveFile; + + // Check to see if it's a ScummVM savegame or not + char buffer[kSavegameStrSize + 1]; + readStream->read(buffer, kSavegameStrSize + 1); + + if (strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) != 0) { + delete readStream; + return false; + } else { + SavegameHeader saveHeader; + + if (!readSavegameHeader(readStream, saveHeader)) { + delete readStream; + return false; + } + + // Delete the thumbnail + saveHeader.thumbnail->free(); + delete saveHeader.thumbnail; + } + + // Get in the savegame + syncGame(readStream, nullptr); + + delete readStream; + return true; +} + } // End of namespace CGE2 diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 5db4772fc7..4bc4a5f9d8 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -29,13 +29,30 @@ namespace CGE2 { -void Spare::sync(Common::Serializer &s) { - for (uint i = 0; i < _container.size(); i++) - _container[i]->sync(s); +void Spare::sync(Common::Serializer &s, HeroTab *heroTab[2]) { + if (s.isSaving()) { + int size = 0; + for (uint i = 0; i < _container.size(); i++) + if (_container[i]->_ref >= 141) + size++; + s.syncAsSint16LE(size); + + for (uint i = 0; i < _container.size(); i++) + if (_container[i]->_ref >= 141) + _container[i]->sync(s); + } else { + int size; + s.syncAsSint16LE(size); + + for (int i = 0; i < size; i++) { + Sprite *sprite = new Sprite(_vm); + sprite->sync(s); + store(sprite); + } + } } void Spare::clear() { - for (int i = 0; i < _container.size(); i++) for (uint i = 0; i < _container.size(); i++) delete _container[i]; diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 7dc6ce60f5..d34ca4855e 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -46,7 +46,7 @@ public: void dispose(Sprite *spr); void dispose(int ref); void dispose(); - void sync(Common::Serializer &s); + void sync(Common::Serializer &s, HeroTab *heroTab[2]); uint16 count() { return _container.size(); } void clear(); }; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 3ce690ed6a..f40c84ebfc 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -40,22 +40,14 @@ namespace CGE2 { void V3D::sync(Common::Serializer &s) { - int pos = 0; - if (s.isLoading()) { - s.syncAsSint16LE(pos); - _x = FXP(pos); - s.syncAsSint16LE(pos); - _y = FXP(pos); - s.syncAsSint16LE(pos); - _z = FXP(pos); - } else { - pos = _x.trunc(); - s.syncAsUint16LE(pos); - pos = _y.trunc(); - s.syncAsUint16LE(pos); - pos = _z.trunc(); - s.syncAsByte(pos); - } + _x.sync(s); + _y.sync(s); + _z.sync(s); +} + +void FXP::sync(Common::Serializer &s) { + s.syncAsUint16LE(f); + s.syncAsSint16LE(i); } Seq *getConstantSeq(bool seqFlag) { @@ -748,8 +740,8 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(_time); for (int i = 0; i < kActions; i++){ - s.syncAsSint16LE(_actionCtrl->_ptr); - s.syncAsSint16LE(_actionCtrl->_cnt); + s.syncAsByte(_actionCtrl[i]._ptr); + s.syncAsByte(_actionCtrl[i]._cnt); } s.syncAsSint16LE(_seqPtr); s.syncAsSint16LE(_seqCnt); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index ce914ce2c8..7dd7933302 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -115,6 +115,7 @@ public: int trunc(void) const { return i; } int round(void) const { return i + (f > 0x7FFF); } bool empty() const { return i == 0 && f == 0; } + void sync(Common::Serializer &s); }; // From CGETYPE.H: @@ -274,6 +275,7 @@ public: virtual void tick(); virtual void setScene(int c); void clrHide() { if (_ext) _ext->_b0 = NULL; } + void sync(Common::Serializer &s); static void (*notify) (); @@ -297,6 +299,7 @@ public: } Sprite *locate(int ref); bool locate(Sprite *spr); + void clear() { _head = _tail = nullptr; } }; class Vga { -- cgit v1.2.3 From 927be46c8738ea474476e94ed9868be3c4c0dcf6 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 3 Jul 2014 09:24:25 +0200 Subject: CGE2: Remove unnecessary parameter from Spare::sync(). --- engines/cge2/saveload.cpp | 4 ++-- engines/cge2/spare.cpp | 2 +- engines/cge2/spare.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 8d0237e702..cb1e981318 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -253,8 +253,8 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS // Synchronise header data syncHeader(s); - // Synchronise _spare and mingled with it, the sprites of the heroes' - _spare->sync(s, _heroTab); + // Synchronise _spare + _spare->sync(s); if (s.isSaving()) { // Save the references of the items in the heroes pockets: diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 4bc4a5f9d8..a0c3f741eb 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -29,7 +29,7 @@ namespace CGE2 { -void Spare::sync(Common::Serializer &s, HeroTab *heroTab[2]) { +void Spare::sync(Common::Serializer &s) { if (s.isSaving()) { int size = 0; for (uint i = 0; i < _container.size(); i++) diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index d34ca4855e..7dc6ce60f5 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -46,7 +46,7 @@ public: void dispose(Sprite *spr); void dispose(int ref); void dispose(); - void sync(Common::Serializer &s, HeroTab *heroTab[2]); + void sync(Common::Serializer &s); uint16 count() { return _container.size(); } void clear(); }; -- cgit v1.2.3 From ddf4f4598de95ea8b631d9e77c3da4178d61c1d2 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 3 Jul 2014 09:47:10 +0200 Subject: CGE2: Rename saveHeroPos() to storeHeroPos(). --- engines/cge2/cge2.h | 2 +- engines/cge2/cge2_main.cpp | 4 ++-- engines/cge2/saveload.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index aade31f2b8..dddf0c3e23 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -157,7 +157,7 @@ public: void sceneDown(); void closePocket(); void switchScene(int scene); - void saveHeroPos(); + void storeHeroPos(); void showBak(int ref); void loadTab(); int newRandom(int range); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 071340508c..804294d478 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -503,7 +503,7 @@ void CGE2Engine::switchScene(int scene) { _req = scene; - saveHeroPos(); + storeHeroPos(); *(_eyeTab[_now]) = *_eye; if (scene < 0) @@ -522,7 +522,7 @@ void CGE2Engine::switchScene(int scene) { } } -void CGE2Engine::saveHeroPos() { +void CGE2Engine::storeHeroPos() { for (int i = 0; i < 2; i++) { Hero *h = _heroTab[i]->_ptr; if (h->_scene == _now) { diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index cb1e981318..f6cbbf93e1 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -196,7 +196,7 @@ Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { writeSavegameHeader(saveFile, header); // Write out the data of the savegame - saveHeroPos(); + storeHeroPos(); sceneDown(); syncGame(nullptr, saveFile); sceneUp(_now); -- cgit v1.2.3 From dbbafb5d8939453bba847dc49b7a87b534020d48 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 3 Jul 2014 10:04:29 +0200 Subject: CGE2: Rename and heavily rework Bitmap::forceExt(). Since the extension is always ".VBM" in case of Bitmaps, there's no need to pass it as an argument. --- engines/cge2/bitmap.cpp | 18 ++++++++---------- engines/cge2/bitmap.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 93818c05bf..396610ad84 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -53,8 +53,8 @@ Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _v(nullptr), _b(nullptr), _m warning("Workaround for wrong VBM name: 11oqlist-"); } else strcpy(pat, fname); - - forceExt(pat, pat, ".VBM"); + + strcpy(pat, addExt(pat).c_str()); if (_vm->_resman->exist(pat)) { EncryptedStream file(_vm, pat); @@ -162,14 +162,12 @@ Bitmap &Bitmap::operator=(const Bitmap &bmp) { return *this; } -char *Bitmap::forceExt(char *buf, const char *name, const char *ext) { - strcpy(buf, name); - char *dot = strrchr(buf, '.'); - if (dot) - *dot = '\0'; - strcat(buf, ext); - - return buf; +Common::String Bitmap::addExt(const char *name) { + Common::String fname; + fname = Common::String::format("%s.VBM", name); + if (fname.size() >= kMaxPath) + error("Bitmap's filename is too long %s", name); + return fname; } BitmapPtr Bitmap::code(uint8 *map) { diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index e7a4637b87..3d71635b67 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -58,7 +58,7 @@ struct HideDesc { class Bitmap { CGE2Engine *_vm; - char *forceExt(char *buf, const char *name, const char *ext); + static Common::String addExt(const char *name); bool loadVBM(EncryptedStream *f); public: static uint8 *kSLDesign; -- cgit v1.2.3 From a3071a00f98b4e322c28281e026ac85a751db071 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 4 Jul 2014 13:26:27 +0200 Subject: CGE2: Replace addExt() wit setExtension(). --- engines/cge2/bitmap.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 396610ad84..4d1fb6a043 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -53,8 +53,8 @@ Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _v(nullptr), _b(nullptr), _m warning("Workaround for wrong VBM name: 11oqlist-"); } else strcpy(pat, fname); - - strcpy(pat, addExt(pat).c_str()); + + strcpy(pat, setExtension(pat, ".VBM").c_str()); if (_vm->_resman->exist(pat)) { EncryptedStream file(_vm, pat); @@ -162,12 +162,16 @@ Bitmap &Bitmap::operator=(const Bitmap &bmp) { return *this; } -Common::String Bitmap::addExt(const char *name) { - Common::String fname; - fname = Common::String::format("%s.VBM", name); - if (fname.size() >= kMaxPath) - error("Bitmap's filename is too long %s", name); - return fname; +// Blatant rip from hopkins engine where it's ripped from gob engine. Hi DrMcCoy, hi Strangerke! ;> +Common::String Bitmap::setExtension(const Common::String &str, const Common::String &ext) { + if (str.empty()) + return str; + + const char *dot = strrchr(str.c_str(), '.'); + if (dot) + return Common::String(str.c_str(), dot - str.c_str()) + ext; + + return str + ext; } BitmapPtr Bitmap::code(uint8 *map) { -- cgit v1.2.3 From 07fa4831426142a6ec0bede7af979a0628e53ea4 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 4 Jul 2014 18:04:40 +0200 Subject: CGE2: Fix broken compilation by previous commit. --- engines/cge2/bitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 3d71635b67..159631ec05 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -58,7 +58,7 @@ struct HideDesc { class Bitmap { CGE2Engine *_vm; - static Common::String addExt(const char *name); + Common::String setExtension(const Common::String &str, const Common::String &ext); bool loadVBM(EncryptedStream *f); public: static uint8 *kSLDesign; -- cgit v1.2.3 From 8b8216bf2cfbaa016aa20a15eb7ac9069d8f9f21 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 4 Jul 2014 18:39:03 +0200 Subject: CGE2: Fully implement the save/load system. Now the toolbar is working too after loading. --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 65 +++++++++++++++++++++++++--------------------- engines/cge2/saveload.cpp | 23 +++++----------- engines/cge2/spare.cpp | 2 +- 4 files changed, 44 insertions(+), 47 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index dddf0c3e23..f126da591f 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -149,6 +149,7 @@ public: void inf(const char *text, ColorBank col = kCBInf); void movie(const char *ext); void runGame(); + void initToolbar(); void loadHeroes(); void loadScript(const char *fname); void loadSprite(const char *fname, int ref, int scene, V3D &pos); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 804294d478..935a3c94e3 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -672,40 +672,11 @@ void CGE2Engine::runGame() { if (_quitFlag) return; - selectPocket(-1); - loadUser(); - _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); - if (!_music) - _midiPlayer->killMidi(); - - checkSaySwitch(); - - _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); - _infoLine->setText(nullptr); - _vga->_showQ->insert(_infoLine); + initToolbar(); sceneUp(_now); - _startupMode = 0; - _mouse->center(); - _mouse->off(); - _mouse->on(); - - _keyboard->setClient(_sys); - _commandHandler->addCommand(kCmdSeq, kPowerRef, 1, nullptr); - - _busyPtr = _vga->_showQ->locate(kBusyRef); - - _vol[0] = _vga->_showQ->locate(kDvolRef); - _vol[1] = _vga->_showQ->locate(kMvolRef); - - // these sprites are loaded with SeqPtr==0 (why?!) - if (_vol[0]) - _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); - if (_vol[1]) - _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); - // TODO: Recheck these! ^ // main loop while (!_endGame && !_quitFlag) { @@ -795,6 +766,40 @@ void CGE2Engine::loadPos() { error("Missing file: CGE.HXY"); } +void CGE2Engine::initToolbar() { + selectPocket(-1); + + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); + if (!_music) + _midiPlayer->killMidi(); + + checkSaySwitch(); + + _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); + _infoLine->setText(nullptr); + _vga->_showQ->insert(_infoLine); + + _startupMode = 0; + _mouse->center(); + _mouse->off(); + _mouse->on(); + + _keyboard->setClient(_sys); + _commandHandler->addCommand(kCmdSeq, kPowerRef, 1, nullptr); + + _busyPtr = _vga->_showQ->locate(kBusyRef); + + _vol[0] = _vga->_showQ->locate(kDvolRef); + _vol[1] = _vga->_showQ->locate(kMvolRef); + + // these sprites are loaded with SeqPtr==0 (why?!) + if (_vol[0]) + _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); + if (_vol[1]) + _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); + // TODO: Recheck these! ^ +} + void CGE2Engine::releasePocket(Sprite *spr) { for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index f6cbbf93e1..0ea957f9e1 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -38,6 +38,7 @@ #include "cge2/hero.h" #include "cge2/text.h" #include "cge2/sound.h" +#include "cge2/cge2_main.h" namespace CGE2 { @@ -260,8 +261,7 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS // Save the references of the items in the heroes pockets: for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { - Sprite *spr = _heroTab[i]->_pocket[j]; - int ref = (spr) ? spr->_ref : -1; + int ref = _heroTab[i]->_downPocketId[j]; s.syncAsSint16LE(ref); } } @@ -271,7 +271,7 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS for (int j = 0; j < kPocketMax; j++) { int ref = 0; s.syncAsSint16LE(ref); - _heroTab[i]->_pocket[j] = _spare->locate(ref); + _heroTab[i]->_downPocketId[j] = ref; } } } @@ -310,25 +310,13 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { } Common::Error CGE2Engine::loadGameState(int slot) { - // Clear current game activity sceneDown(); resetGame(); - // If music is playing, kill it. - if (_music) - _midiPlayer->killMidi(); - if (!loadGame(slot)) return Common::kReadingFailed; - + initToolbar(); loadHeroes(); - sceneUp(_now); - - _busyPtr = _vga->_showQ->locate(kBusyRef); - - _vol[0] = _vga->_showQ->locate(kDvolRef); - _vol[1] = _vga->_showQ->locate(kMvolRef); - return Common::kNoError; } @@ -338,6 +326,9 @@ void CGE2Engine::resetGame() { _spare->clear(); _vga->_showQ->clear(); _commandHandler->reset(); + loadScript("CGE.INI"); + delete _infoLine; + _infoLine = new InfoLine(this, kInfoW); } bool CGE2Engine::loadGame(int slotNumber) { diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index a0c3f741eb..93c8a2674d 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -47,7 +47,7 @@ void Spare::sync(Common::Serializer &s) { for (int i = 0; i < size; i++) { Sprite *sprite = new Sprite(_vm); sprite->sync(s); - store(sprite); + update(sprite); } } } -- cgit v1.2.3 From 31bba2e38c0bfad3b990ccf9884c6f8f578a19ee Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 4 Jul 2014 18:59:33 +0200 Subject: CGE2: Remove unnecessary warning and debug info from showTitle(). --- engines/cge2/cge2_main.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 935a3c94e3..77df792e94 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -908,8 +908,6 @@ bool CGE2Engine::showTitle(const char *name) { Sprite D(this, LB, 1); D._flags._kill = true; - strcpy(D._file, "hatter"); - warning("STUB: Sprite::showTitle() - Flags changed compared to CGE1's Sprite type."); D.gotoxyz(kScrWidth >> 1, -(kPanHeight >> 1)); _vga->sunset(); -- cgit v1.2.3 From e15f40978a6904dec7a50cfefbb2a05c454c6c74 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 4 Jul 2014 19:07:38 +0200 Subject: CGE2: Implement loading from the Launcher. --- engines/cge2/cge2.cpp | 4 +++- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 18 +++++++++++++----- engines/cge2/detection.cpp | 4 +++- engines/cge2/saveload.cpp | 9 ++++++--- 5 files changed, 26 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index e6df241ea9..aa87f99a3b 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -26,7 +26,7 @@ */ #include "engines/util.h" - +#include "common/config-manager.h" #include "cge2/cge2.h" #include "cge2/bitmap.h" #include "cge2/vga13h.h" @@ -123,6 +123,8 @@ void CGE2Engine::init() { _sys = new System(this); _eventManager = new EventManager(this); _map = new Map(this); + + _startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; } void CGE2Engine::deinit() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index f126da591f..a2cd13107e 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -284,6 +284,7 @@ public: int _req; NotifyFunctionType _midiNotify; NotifyFunctionType _spriteNotify; + int _startGameSlot; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 77df792e94..b9787b07e1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -696,11 +696,13 @@ void CGE2Engine::runGame() { } void CGE2Engine::loadUser() { - warning("STUB: CGE2Engine::loadUser()"); - // Missing loading from file. TODO: Implement it with the saving/loading! - loadScript("CGE.INI"); - loadHeroes(); loadPos(); + if (_startGameSlot != -1) + loadGame(_startGameSlot); + else { + loadScript("CGE.INI"); + loadHeroes(); + } } void CGE2Engine::loadHeroes() { // Original name: loadGame() @@ -847,7 +849,11 @@ void CGE2Engine::cge2_main() { loadTab(); - _mode++; + if (_startGameSlot != -1) { + // Starting up a savegame from the launcher + _mode++; + runGame(); + } if (showTitle("WELCOME")) { #if 0 @@ -900,6 +906,8 @@ int CGE2Engine::newRandom(int range) { bool CGE2Engine::showTitle(const char *name) { if (_quitFlag) return false; + + _mode++; _bitmapPalette = _vga->_sysPal; BitmapPtr LB = new Bitmap[1]; diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 599934b57d..6d4f6339d9 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -41,7 +41,9 @@ bool CGE2MetaEngine::hasFeature(MetaEngineFeature f) const { (f == kSupportsDeleteSave) || (f == kSavesSupportMetaInfo) || (f == kSavesSupportThumbnail) || - (f == kSavesSupportCreationDate); + (f == kSavesSupportCreationDate) || + (f == kSupportsListSaves) || + (f == kSupportsLoadingDuringStartup); } const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 0ea957f9e1..3890e74341 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -311,11 +311,8 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { Common::Error CGE2Engine::loadGameState(int slot) { sceneDown(); - resetGame(); if (!loadGame(slot)) return Common::kReadingFailed; - initToolbar(); - loadHeroes(); sceneUp(_now); return Common::kNoError; } @@ -365,10 +362,16 @@ bool CGE2Engine::loadGame(int slotNumber) { delete saveHeader.thumbnail; } + resetGame(); + // Get in the savegame syncGame(readStream, nullptr); delete readStream; + + initToolbar(); + loadHeroes(); + return true; } -- cgit v1.2.3 From 21a4c44bea2e413444716994671f63e8fe6aa373 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 Jul 2014 22:05:02 -0400 Subject: CGE2: Add extra clipping to Bitmap::hide --- engines/cge2/vga13h.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index f40c84ebfc..805c1e751b 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1131,12 +1131,15 @@ void Bitmap::show(V2D pos) { void Bitmap::hide(V2D pos) { xLatPos(pos); - for (int yp = pos.y; yp < pos.y + _h; yp++) { + int w = MIN(_w, kScrWidth - pos.x); + int h = MIN(_h, kScrHeight - pos.y); + + for (int yp = pos.y; yp < pos.y + h; yp++) { if (yp >= 0 && yp < kScrHeight) { const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(pos.x, yp); byte *destP = (byte *)_vm->_vga->_page[1]->getBasePtr(pos.x, yp); - Common::copy(srcP, srcP + _w, destP); + Common::copy(srcP, srcP + w, destP); } } } -- cgit v1.2.3 From c5855b4293522f365329593e41a16e68b1424967 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 7 Jul 2014 10:41:43 +0200 Subject: CGE2: Add workaround for the missing dialogs in room 21 (concert) --- engines/cge2/text.cpp | 15 +++++++++------ engines/cge2/text.h | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 24fc8e5376..ecc5521a14 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -38,16 +38,19 @@ Text::Text(CGE2Engine *vm, const char *fname) : _vm(vm) { _vm->mergeExt(_fileName, fname, kSayExt); if (!_vm->_resman->exist(_fileName)) error("No talk (%s)", _fileName); - int16 txtCount = count() + 1; - if (!txtCount) + _txtCount = count(); + if (_txtCount == -1) error("Unable to read dialog file %s", _fileName); - _cache = new Handler[txtCount]; - for (_size = 0; _size < txtCount; _size++) { + _txtCount += 2; + _cache = new Handler[_txtCount]; + for (_size = 0; _size < _txtCount; _size++) { _cache[_size]._ref = 0; _cache[_size]._text = nullptr; } load(); + _cache[_txtCount - 1]._ref = 0; + _cache[_txtCount - 1]._text = ""; } Text::~Text() { @@ -127,8 +130,8 @@ char *Text::getText(int ref) { if (i < _size) return _cache[i]._text; - warning("getText: Unable to find ref %d", ref); - return NULL; + warning("getText: Unable to find ref %d:%d", ref / 256, ref % 256); + return _cache[_txtCount - 1]._text; } void Text::say(const char *text, Sprite *spr) { diff --git a/engines/cge2/text.h b/engines/cge2/text.h index bca774357a..88ed501158 100644 --- a/engines/cge2/text.h +++ b/engines/cge2/text.h @@ -48,6 +48,7 @@ class Text { char *_text; } *_cache; int _size; + int16 _txtCount; char _fileName[kPathMax]; void load(); int16 count(); -- cgit v1.2.3 From c7aa91019b08c52976356031cf2059333ab6fd23 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 7 Jul 2014 21:42:45 +0200 Subject: CGE2: Replace NULL with nullptr everywhere. --- engines/cge2/bitmap.cpp | 8 ++++---- engines/cge2/cge2_main.cpp | 28 ++++++++++++++-------------- engines/cge2/events.cpp | 8 ++++---- engines/cge2/fileio.cpp | 6 +++--- engines/cge2/hero.cpp | 14 +++++++------- engines/cge2/snail.cpp | 6 +++--- engines/cge2/sound.cpp | 8 ++++---- engines/cge2/talk.cpp | 6 +++--- engines/cge2/text.cpp | 4 ++-- engines/cge2/vga13h.cpp | 44 ++++++++++++++++++++++---------------------- engines/cge2/vga13h.h | 6 +++--- 11 files changed, 69 insertions(+), 69 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 4d1fb6a043..fd2f6a441f 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -84,7 +84,7 @@ Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill) uint16 psiz = _h * lsiz; // - last gape, but + plane trailer uint8 *v = new uint8[4 * psiz + _h * sizeof(*_b)];// the same for 4 planes // + room for wash table - assert(v != NULL); + assert(v != nullptr); WRITE_LE_UINT16(v, (kBmpCPY | dsiz)); // data chunk hader memset(v + 2, fill, dsiz); // data bytes @@ -176,7 +176,7 @@ Common::String Bitmap::setExtension(const Common::String &str, const Common::Str BitmapPtr Bitmap::code(uint8 *map) { if (!map) - return NULL; + return nullptr; uint16 cnt; @@ -265,7 +265,7 @@ BitmapPtr Bitmap::code(uint8 *map) { uint16 sizV = (uint16)(im - 2 - _v); _v = new uint8[sizV + _h * sizeof(*_b)]; - assert(_v != NULL); + assert(_v != nullptr); _b = (HideDesc *)(_v + sizV); } @@ -383,7 +383,7 @@ bool Bitmap::loadVBM(EncryptedStream *f) { f->seek(f->pos() + kPalSize); } } - if ((_v = new uint8[n]) == NULL) + if ((_v = new uint8[n]) == nullptr) return false; if (!f->err()) diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index b9787b07e1..be83beda1f 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -52,7 +52,7 @@ void System::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { // The sound is uselessly annoying and noisy, so it has been removed _vm->killText(); if (_vm->_startupMode == 1) { - _vm->_commandHandler->addCommand(kCmdClear, -1, 0, NULL); + _vm->_commandHandler->addCommand(kCmdClear, -1, 0, nullptr); return; } } @@ -335,43 +335,43 @@ void CGE2Engine::loadScript(const char *fname) { V3D P; // sprite ident number - if ((p = token(tmpStr)) == NULL) + if ((p = token(tmpStr)) == nullptr) break; int SpI = number(p); // sprite file name char *SpN; - if ((SpN = token(nullptr)) == NULL) + if ((SpN = token(nullptr)) == nullptr) break; // sprite scene - if ((p = token(nullptr)) == NULL) + if ((p = token(nullptr)) == nullptr) break; int SpA = number(p); // sprite column - if ((p = token(nullptr)) == NULL) + if ((p = token(nullptr)) == nullptr) break; P._x = number(p); // sprite row - if ((p = token(nullptr)) == NULL) + if ((p = token(nullptr)) == nullptr) break; P._y = number(p); // sprite Z pos - if ((p = token(nullptr)) == NULL) + if ((p = token(nullptr)) == nullptr) break; P._z = number(p); // sprite life - if ((p = token(nullptr)) == NULL) + if ((p = token(nullptr)) == nullptr) break; bool BkG = number(p) == 0; ok = true; // no break: OK - _sprite = NULL; + _sprite = nullptr; loadSprite(SpN, SpI, SpA, P); if (_sprite) { if (BkG) @@ -538,7 +538,7 @@ void CGE2Engine::showBak(int ref) { if (spr != nullptr) { _bitmapPalette = _vga->_sysPal; spr->expand(); - _bitmapPalette = NULL; + _bitmapPalette = nullptr; spr->show(2); _vga->copyPage(1, 2); _spare->dispose(spr); @@ -860,7 +860,7 @@ void CGE2Engine::cge2_main() { if (_mode == 1) movie(kIntroExt); #endif - if (_text->getText(255) != NULL) { + if (_text->getText(255) != nullptr) { runGame(); _startupMode = 2; } else @@ -892,8 +892,8 @@ void CGE2Engine::setEye(const char *s) { char tempStr[kLineMax]; strcpy(tempStr, s); _eye->_x = atoi(token(tempStr)); - _eye->_y = atoi(token(NULL)); - _eye->_z = atoi(token(NULL)); + _eye->_y = atoi(token(nullptr)); + _eye->_z = atoi(token(nullptr)); } int CGE2Engine::newRandom(int range) { @@ -967,7 +967,7 @@ void CGE2Engine::killText() { return; _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, _talk); - _talk = NULL; + _talk = nullptr; } void CGE2Engine::switchHero(int sex) { diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 0c163a5454..c56f005fbb 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -39,7 +39,7 @@ namespace CGE2 { /*----------------- KEYBOARD interface -----------------*/ -Keyboard::Keyboard(CGE2Engine *vm) : _client(NULL), _vm(vm) { +Keyboard::Keyboard(CGE2Engine *vm) : _client(nullptr), _vm(vm) { warning("STUB: Keyboard::Keyboard() - Recheck the whole implementation!!!"); } @@ -62,13 +62,13 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ -Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(NULL), _hold(NULL), _hx(0), _point(_vm), _vm(vm) { - _hold = NULL; +Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(nullptr), _hold(nullptr), _hx(0), _point(_vm), _vm(vm) { + _hold = nullptr; _hx = 0; _hy = 0; _exist = true; _buttons = 0; - _busy = NULL; + _busy = nullptr; _active = false; _flags._kill = false; diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index cc07ef6fc1..257e977d45 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -75,7 +75,7 @@ ResourceManager::ResourceManager() { _buff[i]._page = new BtPage; _buff[i]._pageNo = kBtValNone; _buff[i]._index = -1; - assert(_buff[i]._page != NULL); + assert(_buff[i]._page != nullptr); } } @@ -160,7 +160,7 @@ BtKeypack *ResourceManager::find(const char *key) { return &pg->_leaf[i]; } } - return NULL; + return nullptr; } bool ResourceManager::exist(const char *name) { @@ -272,7 +272,7 @@ const char *EncryptedStream::kIdTab[] = { "[near]", "[mtake]", "[ftake]", "[phase]", "[seq]", "Name", "Type", "Front", "East", "Portable", "Transparent", - NULL + nullptr }; } // End of namespace CGE2 diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 7e6c384a46..4b50cccd8b 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -127,10 +127,10 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo if (_actionCtrl[section]._cnt) { CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; c->_commandType = CommandType(id); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); c->_ref = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); c->_val = _vm->number(p); c->_spritePtr = nullptr; @@ -141,7 +141,7 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo s->_now = atoi(p); if (s->_now > maxnow) maxnow = s->_now; - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) break; s->_next = _vm->number(p); switch (s->_next) { @@ -154,16 +154,16 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo } if (s->_next > maxnxt) maxnxt = s->_next; - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dx = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dy = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dz = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dly = _vm->number(p); break; diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 609196cc26..62dfd996e9 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -54,7 +54,7 @@ const char *CommandHandler::_commandText[] = { "RMNEAR", "RMMTAKE", "RMFTAKE", "SETREF", "BACKPT", "WALKTO", "REACH", "COVER", "UNCOVER", - NULL }; + nullptr }; CommandHandler::CommandHandler(CGE2Engine *vm, bool turbo) : _turbo(turbo), _textDelay(false), _timerExpiry(0), _talkEnable(true), @@ -424,7 +424,7 @@ void CGE2Engine::snSend(Sprite *spr, int val) { ((Hero*)spr)->setCurrent(); } _taken = false; - _bitmapPalette = NULL; + _bitmapPalette = nullptr; } } } @@ -792,7 +792,7 @@ void CommandHandler::addCallback(CommandType com, int ref, int val, CallbackType headCmd->_commandType = com; headCmd->_ref = ref; headCmd->_val = val; - headCmd->_spritePtr = NULL; + headCmd->_spritePtr = nullptr; headCmd->_cbType = cbType; if (headCmd->_commandType == kCmdClear) { _tail = _head; diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index 652907b37d..51764b7b3e 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -46,7 +46,7 @@ DataCk::~DataCk() { } Sound::Sound(CGE2Engine *vm) : _vm(vm) { - _audioStream = NULL; + _audioStream = nullptr; _soundRepeatCount = 1; open(); } @@ -108,10 +108,10 @@ void Sound::stop() { void Sound::sndDigiStop(SmpInfo *PSmpInfo) { if (_vm->_mixer->isSoundHandleActive(_soundHandle)) _vm->_mixer->stopHandle(_soundHandle); - _audioStream = NULL; + _audioStream = nullptr; } -Fx::Fx(CGE2Engine *vm, int size) : _current(NULL), _vm(vm) { +Fx::Fx(CGE2Engine *vm, int size) : _current(nullptr), _vm(vm) { } Fx::~Fx() { @@ -157,7 +157,7 @@ DataCk *Fx::loadWave(EncryptedStream *file) { } MusicPlayer::MusicPlayer(CGE2Engine *vm) : _vm(vm) { - _data = NULL; + _data = nullptr; _isGM = false; MidiPlayer::createDriver(); diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index ddd98ac29c..eda812333c 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -39,7 +39,7 @@ Font::Font(CGE2Engine *vm) : _vm(vm) { _pos = new uint16[kPosSize]; _widthArr = new uint8[kWidSize]; - assert((_map != NULL) && (_pos != NULL) && (_widthArr != NULL)); + assert((_map != nullptr) && (_pos != nullptr) && (_widthArr != nullptr)); load(); } @@ -87,12 +87,12 @@ void Font::load() { char *token; - if ((token = _vm->token(tmpStr)) == NULL) + if ((token = _vm->token(tmpStr)) == nullptr) error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); _colorSet[n][0] = _vm->number(token); for (int i = 1; i < 4; i++) { - if ((token = _vm->token(nullptr)) == NULL) + if ((token = _vm->token(nullptr)) == nullptr) error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); _colorSet[n][i] = _vm->number(token); } diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index ecc5521a14..5826f6e5bb 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -72,7 +72,7 @@ int16 Text::count() { char *s; assert(line.size() <= 513); Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) + if ((s = strtok(tmpStr, " =,;/\t\n")) == nullptr) continue; if (!Common::isDigit(*s)) continue; @@ -104,7 +104,7 @@ void Text::load() { int n = line.size(); char *s; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) + if ((s = strtok(tmpStr, " =,;/\t\n")) == nullptr) continue; if (!Common::isDigit(*s)) continue; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 805c1e751b..340f9c0966 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -83,16 +83,16 @@ Seq Sprite::_stdSeq8[] = SprExt::SprExt(CGE2Engine *vm) : _p0(vm, 0, 0), _p1(vm, 0, 0), - _b0(NULL), _b1(NULL), _shpList(NULL), - _location(0), _seq(NULL), _name(NULL) { + _b0(nullptr), _b1(nullptr), _shpList(nullptr), + _location(0), _seq(nullptr), _name(nullptr) { for (int i = 0; i < kActions; i++) _actions[i] = nullptr; } Sprite::Sprite(CGE2Engine *vm) : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), - _next(NULL), _prev(NULL), _time(0), - _ext(NULL), _ref(-1), _scene(0), _vm(vm), + _next(nullptr), _prev(nullptr), _time(0), + _ext(nullptr), _ref(-1), _scene(0), _vm(vm), _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); @@ -102,8 +102,8 @@ Sprite::Sprite(CGE2Engine *vm) Sprite::Sprite(CGE2Engine *vm, BitmapPtr shpP, int cnt) : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), - _next(NULL), _prev(NULL), _time(0), - _ext(NULL), _ref(-1), _scene(0), _vm(vm), + _next(nullptr), _prev(nullptr), _time(0), + _ext(nullptr), _ref(-1), _scene(0), _vm(vm), _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); @@ -123,7 +123,7 @@ Sprite::~Sprite() { BitmapPtr Sprite::getShp() { SprExt *e = _ext; if (!e || !e->_seq) - return NULL; + return nullptr; int i = e->_seq[_seqPtr]._now; if (i >= _shpCnt) @@ -183,7 +183,7 @@ void Sprite::setName(char *newName) { } if (newName) { _ext->_name = new char[strlen(newName) + 1]; - assert(_ext->_name != NULL); + assert(_ext->_name != nullptr); strcpy(_ext->_name, newName); } } @@ -251,7 +251,7 @@ int Sprite::labVal(Action snq, int lab) { CommandHandler::Command *Sprite::snList(Action type) { SprExt *e = _ext; - return (e) ? e->_actions[type] : NULL; + return (e) ? e->_actions[type] : nullptr; } Sprite *Sprite::expand() { @@ -262,7 +262,7 @@ Sprite *Sprite::expand() { (_vm->*_vm->_spriteNotify)(); _ext = new SprExt(_vm); - assert(_ext != NULL); + assert(_ext != nullptr); if (!*_file) return this; @@ -350,10 +350,10 @@ Sprite *Sprite::expand() { CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; c->_commandType = CommandType(id); c->_lab = label; - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); c->_ref = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); c->_val = _vm->number(p); c->_spritePtr = nullptr; @@ -364,7 +364,7 @@ Sprite *Sprite::expand() { s->_now = atoi(p); if (s->_now > maxnow) maxnow = s->_now; - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) break; s->_next = _vm->number(p); switch (s->_next) { @@ -377,16 +377,16 @@ Sprite *Sprite::expand() { } if (s->_next > maxnxt) maxnxt = s->_next; - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dx = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dy = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dz = _vm->number(p); - if ((p = _vm->token(nullptr)) == NULL) + if ((p = _vm->token(nullptr)) == nullptr) error("Unexpected end of file! %s", fname); s->_dly = _vm->number(p); break; @@ -750,7 +750,7 @@ void Sprite::sync(Common::Serializer &s) { _file[8] = '\0'; } -Queue::Queue(bool show) : _head(NULL), _tail(NULL) { +Queue::Queue(bool show) : _head(nullptr), _tail(nullptr) { } void Queue::append(Sprite *spr) { @@ -828,7 +828,7 @@ Sprite *Queue::locate(int ref) { if (spr->_ref == ref) return spr; } - return NULL; + return nullptr; } bool Queue::locate(Sprite *spr) { @@ -839,9 +839,9 @@ bool Queue::locate(Sprite *spr) { return false; } -Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0), _vm(vm) { - _oldColors = NULL; - _newColors = NULL; +Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(nullptr), _name(nullptr), _setPal(false), _mono(0), _vm(vm) { + _oldColors = nullptr; + _newColors = nullptr; _showQ = new Queue(true); _sysPal = new Dac[kPalCount]; diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 7dd7933302..17ce4d3dc9 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -240,7 +240,7 @@ public: bool works(Sprite *spr); bool seqTest(int n); inline bool active() { - return _ext != NULL; + return _ext != nullptr; } Sprite(CGE2Engine *vm); Sprite(CGE2Engine *vm, BitmapPtr shp, int cnt); @@ -255,7 +255,7 @@ public: void backShow(); void setName(char *newName); inline char *name() { - return (_ext) ? _ext->_name : NULL; + return (_ext) ? _ext->_name : nullptr; } void gotoxyz(int x, int y, int z = 0); void gotoxyz(); @@ -274,7 +274,7 @@ public: virtual void touch(uint16 mask, V2D pos, Common::KeyCode keyCode); virtual void tick(); virtual void setScene(int c); - void clrHide() { if (_ext) _ext->_b0 = NULL; } + void clrHide() { if (_ext) _ext->_b0 = nullptr; } void sync(Common::Serializer &s); -- cgit v1.2.3 From 1335247f8235c4abd3062ff0989ea2a3cd5b608b Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 7 Jul 2014 21:52:16 +0200 Subject: CGE2: Hopefully fix memory leak problems regarding _ext. --- engines/cge2/hero.cpp | 3 +++ engines/cge2/vga13h.cpp | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 4b50cccd8b..85eb09bede 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -46,6 +46,9 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo char fname[kMaxPath]; _vm->mergeExt(fname, _file, kSprExt); + + if (_ext != nullptr) + delete _ext; _ext = new SprExt(_vm); if (_ext == nullptr) error("No core %s", fname); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 340f9c0966..d7e0552253 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -261,8 +261,14 @@ Sprite *Sprite::expand() { if (_vm->_spriteNotify != nullptr) (_vm->*_vm->_spriteNotify)(); + char fname[kPathMax]; + _vm->mergeExt(fname, _file, kSprExt); + + if (_ext != nullptr) + delete _ext; _ext = new SprExt(_vm); - assert(_ext != nullptr); + if (_ext == nullptr) + error("No core %s", fname); if (!*_file) return this; @@ -275,9 +281,6 @@ Sprite *Sprite::expand() { maxnow = 0, maxnxt = 0; - char fname[kPathMax]; - _vm->mergeExt(fname, _file, kSprExt); - Seq *curSeq; if (_seqCnt) { curSeq = new Seq[_seqCnt]; @@ -479,6 +482,7 @@ Sprite *Sprite::contract() { } } + delete _ext; _ext = nullptr; return this; -- cgit v1.2.3 From 10a37ea478050c37d368f31815fb189f4c7af7b1 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 7 Jul 2014 23:35:27 +0200 Subject: CGE2: Fix Hero::setCurrent(). This fixes a crash regarding the mechanic on scene 6. --- engines/cge2/hero.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 85eb09bede..393aa4b87c 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -216,7 +216,7 @@ void Hero::setCurrent() { int h = -(tmp.trunc()); int i = 0; - for (; i < kDimMax; i++) { + for (; i < kDimMax - 1; i++) { if (h >= (_hig[i] + _hig[i + 1]) / 2) break; } -- cgit v1.2.3 From be5ec466b3028f15a8aa51331426b3cd317fe789 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 7 Jul 2014 23:58:06 +0200 Subject: CGE2: Fix another probable memory-leak source. --- engines/cge2/hero.cpp | 13 +++++++++++++ engines/cge2/hero.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 393aa4b87c..f9c9996604 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -34,6 +34,10 @@ namespace CGE2 { Hero::Hero(CGE2Engine *vm) : Sprite(vm), _contact(nullptr), _dir(kNoDir), _curDim(0), _tracePtr(-1), _ignoreMap(false) { + + for (int i = 0; i < kDimMax; i++) { + _dim[i] = nullptr; + } } Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! @@ -210,6 +214,15 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo return this; } +Sprite *Hero::contract() { + for (int i = 0; i < kDimMax; i++) { + if (_dim[i] != nullptr) + delete[] _dim[i]; + } + + return this; +} + void Hero::setCurrent() { FXP m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); FXP tmp = m * _siz.y; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 41eb3ac020..c277b4a780 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -77,7 +77,7 @@ public: Hero(CGE2Engine *vm); void tick(); Sprite *expand(); - Sprite *contract() { return this; } + Sprite *contract(); Sprite *setContact(); int stepSize() { return _ext->_seq[7]._dx; } int distance(V3D pos); -- cgit v1.2.3 From 3935a427f94c7619c56976db3c8c4aeca1df500b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 7 Jul 2014 21:48:02 -0400 Subject: CGE2: Add extra clipping to Bitmap::hide --- engines/cge2/vga13h.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index d7e0552253..a53a1160b8 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1134,10 +1134,24 @@ void Bitmap::show(V2D pos) { void Bitmap::hide(V2D pos) { xLatPos(pos); - + + // Perform clipping to screen int w = MIN(_w, kScrWidth - pos.x); int h = MIN(_h, kScrHeight - pos.y); + if (pos.x < 0) { + w -= -pos.x; + pos.x = 0; + if (w < 0) + return; + } + if (pos.y < 0) { + h -= -pos.y; + pos.y = 0; + if (h < 0) + return; + } + // Perform copying of screen section for (int yp = pos.y; yp < pos.y + h; yp++) { if (yp >= 0 && yp < kScrHeight) { const byte *srcP = (const byte *)_vm->_vga->_page[2]->getBasePtr(pos.x, yp); -- cgit v1.2.3 From a73aea1ce8cb72607d258063f48b8540925b79e2 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 8 Jul 2014 09:44:51 +0200 Subject: CGE2: Fix GCC warning, rewrite Text::clear() --- engines/cge2/text.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 5826f6e5bb..e1b25525c3 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -49,8 +49,10 @@ Text::Text(CGE2Engine *vm, const char *fname) : _vm(vm) { _cache[_size]._text = nullptr; } load(); - _cache[_txtCount - 1]._ref = 0; - _cache[_txtCount - 1]._text = ""; + + _cache[_txtCount - 1]._ref = -1; + _cache[_txtCount - 1]._text = new char[3]; + strcpy(_cache[_txtCount - 1]._text, ""); } Text::~Text() { @@ -83,11 +85,11 @@ int16 Text::count() { } void Text::clear() { - for (Handler *p = _cache, *q = p + _size; p < q; p++) { - if (p->_ref) { - p->_ref = 0; - delete[] p->_text; - p->_text = nullptr; + for (int i = 0; i < _txtCount; i++) { + if (_cache[i]._ref) { + _cache[i]._ref = 0; + delete[] _cache[i]._text; + _cache[i]._text = nullptr; } } } -- cgit v1.2.3 From b75d308697f96902ea8a290aa5fb7e3bbadbd69e Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 8 Jul 2014 14:08:36 +0200 Subject: CGE2: Rework CGE2Engine::locate(). --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index be83beda1f..071e49b0d1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -590,7 +590,7 @@ Sprite *CGE2Engine::locate(int ref) { _taken = false; Sprite *spr = _vga->_showQ->locate(ref); if (!spr) { - spr = _spare->locate(ref); + spr = _spare->take(ref); if (spr) _taken = true; } -- cgit v1.2.3 From ffbed9f86de014075a363430fb9c822758431ea8 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 8 Jul 2014 14:08:55 +0200 Subject: CGE2: Comment out Hero::contract() for now. --- engines/cge2/hero.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index f9c9996604..65138cd791 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -215,11 +215,12 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo } Sprite *Hero::contract() { + /* TODO: Recheck this later! for (int i = 0; i < kDimMax; i++) { if (_dim[i] != nullptr) delete[] _dim[i]; } - + */ return this; } -- cgit v1.2.3 From d0a6fa4ce2594bf84cb1e6c12108fb96055beb1e Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 10:41:36 +0200 Subject: CGE2: Implement switchColorMode(). --- engines/cge2/cge2_main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 071e49b0d1..76829b00aa 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -1099,7 +1099,9 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { } void CGE2Engine::switchColorMode() { - warning("STUB: CGE2Engine::switchColorMode()"); + _commandHandlerTurbo->addCommand(kCmdSeq, 121, _vga->_mono = !_vga->_mono, NULL); + keyClick(); + _vga->setColors(_vga->_sysPal, 64); } void CGE2Engine::switchMusic() { -- cgit v1.2.3 From 45da1e7c741a1906b60ad3d55a9e0087fd9a4a3e Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 11:17:30 +0200 Subject: CGE2: Implement switchVox() and switchCap(). --- engines/cge2/cge2.cpp | 2 ++ engines/cge2/cge2.h | 2 ++ engines/cge2/cge2_main.cpp | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index aa87f99a3b..16deafba48 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -97,6 +97,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _req = 1; _midiNotify = nullptr; _spriteNotify = nullptr; + _enaCap = true; + _enaVox = true; } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index a2cd13107e..252fad07bd 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -285,6 +285,8 @@ public: NotifyFunctionType _midiNotify; NotifyFunctionType _spriteNotify; int _startGameSlot; + bool _enaCap; + bool _enaVox; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 76829b00aa..b7dcf65b33 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -1137,11 +1137,23 @@ void CGE2Engine::setVolume(int idx, int cnt) { } void CGE2Engine::switchCap() { - warning("STUB: CGE2Engine::switchCap()"); + if (_enaCap) { + _sayCap = !_sayCap; + if (!_sayCap) + _sayVox = true; + keyClick(); + checkSaySwitch(); + } } void CGE2Engine::switchVox() { - warning("STUB: CGE2Engine::switchVox()"); + if (_enaVox) { + _sayVox = !_sayVox; + if (!_sayVox) + _sayCap = true; + keyClick(); + checkSaySwitch(); + } } void CGE2Engine::offUse() { -- cgit v1.2.3 From 5a1383343fb645b5fbd80060da81253b2443bf28 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 11:33:02 +0200 Subject: CGE2: Rework number(). --- engines/cge2/cge2_main.cpp | 29 ++++++++++------------------- engines/cge2/hero.cpp | 28 +++++++--------------------- engines/cge2/talk.cpp | 14 +++++--------- engines/cge2/vga13h.cpp | 28 +++++++--------------------- 4 files changed, 29 insertions(+), 70 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index b7dcf65b33..a46767b433 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -112,7 +112,10 @@ void System::tick() { } } -int CGE2Engine::number(char *s) { // TODO: Rework it later to include the preceding token() call! +int CGE2Engine::number(char *str) { + char *s = token(str); + if (s == nullptr) + error("Wrong input for CGE2Engine::number()"); int r = atoi(s); char *pp = strchr(s, ':'); if (pp) @@ -335,9 +338,7 @@ void CGE2Engine::loadScript(const char *fname) { V3D P; // sprite ident number - if ((p = token(tmpStr)) == nullptr) - break; - int SpI = number(p); + int SpI = number(tmpStr); // sprite file name char *SpN; @@ -345,29 +346,19 @@ void CGE2Engine::loadScript(const char *fname) { break; // sprite scene - if ((p = token(nullptr)) == nullptr) - break; - int SpA = number(p); + int SpA = number(nullptr); // sprite column - if ((p = token(nullptr)) == nullptr) - break; - P._x = number(p); + P._x = number(nullptr); // sprite row - if ((p = token(nullptr)) == nullptr) - break; - P._y = number(p); + P._y = number(nullptr); // sprite Z pos - if ((p = token(nullptr)) == nullptr) - break; - P._z = number(p); + P._z = number(nullptr); // sprite life - if ((p = token(nullptr)) == nullptr) - break; - bool BkG = number(p) == 0; + bool BkG = number(nullptr) == 0; ok = true; // no break: OK diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 65138cd791..6281e4dd5e 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -134,12 +134,8 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo if (_actionCtrl[section]._cnt) { CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; c->_commandType = CommandType(id); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - c->_ref = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - c->_val = _vm->number(p); + c->_ref = _vm->number(nullptr); + c->_val = _vm->number(nullptr); c->_spritePtr = nullptr; } break; @@ -148,9 +144,7 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo s->_now = atoi(p); if (s->_now > maxnow) maxnow = s->_now; - if ((p = _vm->token(nullptr)) == nullptr) - break; - s->_next = _vm->number(p); + s->_next = _vm->number(nullptr); switch (s->_next) { case 0xFF: s->_next = seqcnt; @@ -161,18 +155,10 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo } if (s->_next > maxnxt) maxnxt = s->_next; - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dx = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dy = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dz = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dly = _vm->number(p); + s->_dx = _vm->number(nullptr); + s->_dy = _vm->number(nullptr); + s->_dz = _vm->number(nullptr); + s->_dly = _vm->number(nullptr); break; case kIdPhase: for (int i = 0; i < kDimMax; i++) { diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index eda812333c..fd1c140e04 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -87,15 +87,11 @@ void Font::load() { char *token; - if ((token = _vm->token(tmpStr)) == nullptr) - error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); - _colorSet[n][0] = _vm->number(token); - - for (int i = 1; i < 4; i++) { - if ((token = _vm->token(nullptr)) == nullptr) - error("Wrong line! (%d) in %s", colorFile.getLineCount(), path); - _colorSet[n][i] = _vm->number(token); - } + + _colorSet[n][0] = _vm->number(tmpStr); + + for (int i = 1; i < 4; i++) + _colorSet[n][i] = _vm->number(nullptr); n++; } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index a53a1160b8..069c2672ae 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -353,12 +353,8 @@ Sprite *Sprite::expand() { CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; c->_commandType = CommandType(id); c->_lab = label; - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - c->_ref = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - c->_val = _vm->number(p); + c->_ref = _vm->number(nullptr); + c->_val = _vm->number(nullptr); c->_spritePtr = nullptr; } break; @@ -367,9 +363,7 @@ Sprite *Sprite::expand() { s->_now = atoi(p); if (s->_now > maxnow) maxnow = s->_now; - if ((p = _vm->token(nullptr)) == nullptr) - break; - s->_next = _vm->number(p); + s->_next = _vm->number(nullptr); switch (s->_next) { case 0xFF: s->_next = seqcnt; @@ -380,18 +374,10 @@ Sprite *Sprite::expand() { } if (s->_next > maxnxt) maxnxt = s->_next; - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dx = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dy = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dz = _vm->number(p); - if ((p = _vm->token(nullptr)) == nullptr) - error("Unexpected end of file! %s", fname); - s->_dly = _vm->number(p); + s->_dx = _vm->number(nullptr); + s->_dy = _vm->number(nullptr); + s->_dz = _vm->number(nullptr); + s->_dly = _vm->number(nullptr); break; case kIdPhase: { shplist[shpcnt] = Bitmap(_vm, p); -- cgit v1.2.3 From c1bda3c973cda3c3d7ed73aac8ca8be7ce6f0bc8 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 11:53:52 +0200 Subject: CGE2: Remove unnecessary stub from run(). --- engines/cge2/cge2.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 16deafba48..1fb880c4df 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -167,8 +167,6 @@ bool CGE2Engine::hasFeature(EngineFeature f) const { } Common::Error CGE2Engine::run() { - warning("STUB: CGE2Engine::run()"); - initGraphics(kScrWidth, kScrHeight, false); init(); -- cgit v1.2.3 From 8f869c74c09858dd3fd553c30ca645d942b4cdb0 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 11:55:27 +0200 Subject: CGE2: Add option for enabling color blind mode from the Launcher. --- engines/cge2/detection.cpp | 2 +- engines/cge2/detection.h | 21 +++++++++++++++++++-- engines/cge2/vga13h.cpp | 6 ++---- 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 6d4f6339d9..5fcbe2ed7a 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -64,7 +64,7 @@ const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, desc.language = Common::EN_ANY; desc.platform = Common::kPlatformDOS; desc.flags = ADGF_NO_FLAGS; - desc.guioptions = GUIO0(); + desc.guioptions = GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF); return (const ADGameDescription *)&desc; } diff --git a/engines/cge2/detection.h b/engines/cge2/detection.h index 556980774a..51e2988c86 100644 --- a/engines/cge2/detection.h +++ b/engines/cge2/detection.h @@ -30,9 +30,12 @@ #include "cge2/cge2.h" #include "engines/advancedDetector.h" +#include "common/translation.h" namespace CGE2 { +#define GAMEOPTION_COLOR_BLIND_DEFAULT_OFF GUIO_GAMEOPTIONS1 + static const PlainGameDescriptor CGE2Games[] = { { "sfinx", "Sfinx" }, { 0, 0 } @@ -46,14 +49,28 @@ static const ADGameDescription gameDescriptions[] = { { "vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844 }, AD_LISTEND }, - Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO0() + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) }, AD_TABLE_END_MARKER }; +static const ADExtraGuiOptionsMap optionsList[] = { + { + GAMEOPTION_COLOR_BLIND_DEFAULT_OFF, + { + _s("Color Blind Mode"), + _s("Enable Color Blind Mode by default"), + "enable_color_blind", + false + } + }, + + AD_EXTRA_GUI_OPTIONS_TERMINATOR +}; + class CGE2MetaEngine : public AdvancedMetaEngine { public: - CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games) { + CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games, optionsList) { _singleid = "sfinx"; } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 069c2672ae..10c6bbd5a4 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -840,10 +840,8 @@ Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(nullptr), _name(nullptr), _setPal(fa _page[idx]->create(kScrWidth, kScrHeight, Graphics::PixelFormat::createFormatCLUT8()); } - /*if (ConfMan.getBool("enable_color_blind")) - _mono = 1;*/ - - warning("STUB: Vga::Vga()"); + if (ConfMan.getBool("enable_color_blind")) + _mono = 1; _oldColors = (Dac *)malloc(sizeof(Dac) * kPalCount); _newColors = (Dac *)malloc(sizeof(Dac) * kPalCount); -- cgit v1.2.3 From 2f8abb06c34fa6ed418682a05da9a944789e4429 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 12:46:49 +0200 Subject: CGE2: Implement Sound::open(), add stub for checkSaySwitch(). --- engines/cge2/cge2_main.cpp | 1 + engines/cge2/sound.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a46767b433..cda7b20531 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -807,6 +807,7 @@ void CGE2Engine::releasePocket(Sprite *spr) { } void CGE2Engine::checkSaySwitch() { + warning("STUB: CGE2Engine::checkSaySwitch()"); // if (SNDDrvInfo.DDEV == DEV_QUIET) // _sayVox = !(_sayCap = true); _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index 51764b7b3e..a7815b7d05 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -61,7 +61,7 @@ void Sound::close() { void Sound::open() { setRepeat(1); - warning("STUB: Sound::open()"); + _vm->checkSaySwitch(); play(_vm->_fx->load(99, 99)); } -- cgit v1.2.3 From 3dc79442c9e1a92649f2a52b8e8ef0a9f890ae93 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 12:51:03 +0200 Subject: CGE2: Fix Sound::open(). --- engines/cge2/sound.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index a7815b7d05..b7b39d2722 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -61,7 +61,8 @@ void Sound::close() { void Sound::open() { setRepeat(1); - _vm->checkSaySwitch(); + if (_vm->_commandHandlerTurbo != nullptr) + _vm->checkSaySwitch(); play(_vm->_fx->load(99, 99)); } -- cgit v1.2.3 From ec88528080e0c393598042902aca771396f72b1f Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 12:53:51 +0200 Subject: CGE2: Remove unnecessary stub from cge2_main(). --- engines/cge2/cge2_main.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index cda7b20531..2148848868 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -837,8 +837,6 @@ void CGE2Engine::loadTab() { } void CGE2Engine::cge2_main() { - warning("STUB: CGE2Engine::cge2_main()"); - loadTab(); if (_startGameSlot != -1) { -- cgit v1.2.3 From 55f91da1ee02fcf8be40e10beccbc7e509b03902 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 12:56:16 +0200 Subject: CGE2: Remove unused local variable from loadScript(). --- engines/cge2/cge2_main.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 2148848868..ff8621fd63 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -328,8 +328,6 @@ void CGE2Engine::loadScript(const char *fname) { if (line.empty()) continue; - char *p; - lcnt++; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); -- cgit v1.2.3 From dbea97b7c451fedec35bac35dcff3af7b62e5b1e Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 12:57:11 +0200 Subject: CGE2: Remove unnecessary stub from loadHeroes(). --- engines/cge2/cge2_main.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index ff8621fd63..bdfd5523be 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -695,8 +695,6 @@ void CGE2Engine::loadUser() { } void CGE2Engine::loadHeroes() { // Original name: loadGame() - warning("STUB: CGE2Engine::loadHeroes()"); - // load sprites & pocket Sprite *s; -- cgit v1.2.3 From dc2330a3b14cd31806785cc8b2fd98a49d3721fc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 9 Jul 2014 15:48:47 +0200 Subject: CGE2: Implement the keyboard handler --- engines/cge2/cge2_main.h | 2 ++ engines/cge2/events.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index d6f2371964..e2f67854a8 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -32,6 +32,8 @@ namespace CGE2 { +#define kShowScummVMVersion 10 + class System : public Sprite { public: int _funDel; diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index c56f005fbb..7dab8f72e6 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -41,23 +41,89 @@ namespace CGE2 { Keyboard::Keyboard(CGE2Engine *vm) : _client(nullptr), _vm(vm) { warning("STUB: Keyboard::Keyboard() - Recheck the whole implementation!!!"); + _keyAlt = false; } Keyboard::~Keyboard() { } Sprite *Keyboard::setClient(Sprite *spr) { - warning("STUB: Keyboard::setClient()"); + SWAP(_client, spr); return spr; } bool Keyboard::getKey(Common::Event &event) { - warning("STUB: Keyboard::getKey()"); - return false; + Common::KeyCode keycode = event.kbd.keycode; + + if (((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) && event.type == Common::EVENT_KEYDOWN) + _keyAlt = true; + else + _keyAlt = false; + + switch (keycode) { + case Common::KEYCODE_F1: + if (event.type == Common::EVENT_KEYUP) + return false; + // Display ScummVM version and translation strings + for (int i = 0; i < 5; i++) + _vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, NULL); + return false; + case Common::KEYCODE_F5: + if (_vm->canSaveGameStateCurrently()) { + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save", true); + int16 savegameId = dialog->runModalWithCurrentTarget(); + Common::String savegameDescription = dialog->getResultString(); + delete dialog; + + if (savegameId != -1) + _vm->saveGameState(savegameId, savegameDescription); + } + return false; + case Common::KEYCODE_F7: + if (_vm->canLoadGameStateCurrently()) { + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore", false); + int16 savegameId = dialog->runModalWithCurrentTarget(); + delete dialog; + + if (savegameId != -1) + _vm->loadGameState(savegameId); + } + return false; + case Common::KEYCODE_d: + /* + if (event.kbd.flags & Common::KBD_CTRL) { + // Start the debugger + _vm->getDebugger()->attach(); + _vm->getDebugger()->onFrame(); + return false; + } + */ + break; + case Common::KEYCODE_x: + if (event.kbd.flags & Common::KBD_ALT) { + _vm->quit(); + return false; + } + break; + default: + break; + } + + return true; } void Keyboard::newKeyboard(Common::Event &event) { - warning("STUB: Keyboard::newKeyboard()"); + if (!getKey(event)) + return; + + if ((event.type == Common::EVENT_KEYDOWN) && (_client)) { + CGE2Event &evt = _vm->_eventManager->getNextEvent(); + evt._x = 0; + evt._y = 0; + evt._keyCode = event.kbd.keycode; // Keycode + evt._mask = kEventKeyb; // Event mask + evt._spritePtr = _client; // Sprite pointer + } } /*----------------- MOUSE interface -----------------*/ -- cgit v1.2.3 From 1be1ce6117a97c73f1bab24b4421a8fbc5c5ec2c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 9 Jul 2014 16:44:23 +0200 Subject: CGE2: Set widespace for Inf text, update first line of info text in CGE.SAY --- engines/cge2/cge2_main.h | 2 +- engines/cge2/text.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h index e2f67854a8..afbe7b3d23 100644 --- a/engines/cge2/cge2_main.h +++ b/engines/cge2/cge2_main.h @@ -32,7 +32,7 @@ namespace CGE2 { -#define kShowScummVMVersion 10 +#define kShowScummVMVersion 15 class System : public Sprite { public: diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index e1b25525c3..9ebed58590 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -185,7 +185,7 @@ void Text::say(const char *text, Sprite *spr) { void CGE2Engine::inf(const char *text, ColorBank col) { killText(); - _talk = new Talk(this, text, kTBRect, col); + _talk = new Talk(this, text, kTBRect, col, true); if (_talk) { _talk->_flags._kill = true; _talk->setName(_text->getText(kInfName)); -- cgit v1.2.3 From f57d2ff4d6268e0bf2dd8edf419fde6b649a9f34 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 16:30:31 +0200 Subject: CGE2: Remove unnecessary stub from Keyboard's constructor. --- engines/cge2/events.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 7dab8f72e6..48febd2a85 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -40,7 +40,6 @@ namespace CGE2 { /*----------------- KEYBOARD interface -----------------*/ Keyboard::Keyboard(CGE2Engine *vm) : _client(nullptr), _vm(vm) { - warning("STUB: Keyboard::Keyboard() - Recheck the whole implementation!!!"); _keyAlt = false; } -- cgit v1.2.3 From fcce50e6fe954ed275de29da60d29cc99ce77008 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 9 Jul 2014 16:31:12 +0200 Subject: CGE2: Hook handling of F10 into the Keyboard::getKey(). --- engines/cge2/events.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 48febd2a85..ecb6183540 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -104,6 +104,10 @@ bool Keyboard::getKey(Common::Event &event) { return false; } break; + case Common::KEYCODE_F10: + if (_vm->_commandHandler->idle()) + _vm->switchScene(-1); // Exits the game. + return false; default: break; } -- cgit v1.2.3 From 4d2c1315ac24870ac8b2d53cdc6b274893df7157 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 9 Jul 2014 18:48:16 +0200 Subject: CGE2: Silence a GCC warning, reduce the scope of a variable --- engines/cge2/talk.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index fd1c140e04..227e0135bd 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -77,17 +77,12 @@ void Font::load() { assert(!colorFile.err()); char tmpStr[kLineMax + 1]; - Common::String line; int n = 0; - for (line = colorFile.readLine(); !colorFile.eos(); line = colorFile.readLine()){ + for (Common::String line = colorFile.readLine(); !colorFile.eos(); line = colorFile.readLine()){ if (line.empty()) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - - char *token; - - _colorSet[n][0] = _vm->number(tmpStr); for (int i = 1; i < 4; i++) -- cgit v1.2.3 From 89295b789552a337645e8218e1f237772f0ac1ed Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 14 Jul 2014 18:00:21 +0200 Subject: CGE2: Remove unnecessary comment from ~Vga(). --- engines/cge2/vga13h.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 10c6bbd5a4..fef9b6b834 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -855,14 +855,6 @@ Vga::~Vga() { _mono = 0; Common::String buffer = ""; -/* - clear(0); - setMode(_oldMode); - setColors(); - restoreScreen(_oldScreen); - sunrise(_oldColors); -*/ - warning("STUB: Vga::~Vga()"); free(_oldColors); free(_newColors); -- cgit v1.2.3 From b941fe226d07477f114197dcc69c581dd173e689 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 14 Jul 2014 18:04:16 +0200 Subject: CGE2: Unstub movie(). --- engines/cge2/cge2_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index bdfd5523be..edf9db9b1d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -394,10 +394,10 @@ void CGE2Engine::movie(const char *ext) { loadScript(fn); sceneUp(_now); + _keyboard->setClient(_sys); while (!_commandHandler->idle() && !_quitFlag) mainLoop(); - - warning("STUB: CGE2Engine::movie()"); + _keyboard->setClient(nullptr); _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); -- cgit v1.2.3 From 807f354cba9866248c8f7bd0d0bc9367aa4981af Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 14 Jul 2014 18:14:20 +0200 Subject: CGE2: Remove unused classes from vga13h. --- engines/cge2/vga13h.cpp | 15 --------------- engines/cge2/vga13h.h | 18 ------------------ 2 files changed, 33 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index fef9b6b834..02d536c3e8 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1107,7 +1107,6 @@ void Bitmap::show(V2D pos) { } } - void Bitmap::hide(V2D pos) { xLatPos(pos); @@ -1138,16 +1137,6 @@ void Bitmap::hide(V2D pos) { } } -/*--------------------------------------------------------------------------*/ - -HorizLine::HorizLine(CGE2Engine *vm) : Sprite(vm), _vm(vm) { - warning("HorizLine::HorizLine()"); -} - -SceneLight::SceneLight(CGE2Engine *vm) : Sprite(vm), _vm(vm) { - warning("SceneLight::SceneLight()"); -} - Speaker::Speaker(CGE2Engine *vm): Sprite(vm), _vm(vm) { // Set the sprite list BitmapPtr SP = new Bitmap[2]; @@ -1160,8 +1149,4 @@ Speaker::Speaker(CGE2Engine *vm): Sprite(vm), _vm(vm) { setShapeList(SP, 2); } -PocLight::PocLight(CGE2Engine *vm): Sprite(vm), _vm(vm) { - warning("PocLight::PocLight()"); -} - } // End of namespace CGE2 diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 17ce4d3dc9..77bece6884 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -339,30 +339,12 @@ public: void dacToPal(const Dac *tab, byte *palData); }; -class HorizLine: public Sprite { - CGE2Engine *_vm; -public: - HorizLine(CGE2Engine *vm); -}; - -class SceneLight: public Sprite { - CGE2Engine *_vm; -public: - SceneLight(CGE2Engine *vm); -}; - class Speaker: public Sprite { CGE2Engine *_vm; public: Speaker(CGE2Engine *vm); }; -class PocLight: public Sprite { - CGE2Engine *_vm; -public: - PocLight(CGE2Engine *vm); -}; - } // End of namespace CGE2 #endif // CGE2_VGA13H_H -- cgit v1.2.3 From 2f8967d95948aae6f15e4949d2b06a7e6b7674a4 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 14 Jul 2014 18:15:49 +0200 Subject: CGE2: Unstub showTitle(). --- engines/cge2/cge2_main.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index edf9db9b1d..bddb83b84f 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -913,8 +913,6 @@ bool CGE2Engine::showTitle(const char *name) { _vga->sunrise(_vga->_sysPal); _vga->update(); - - warning("STUB: CGE2Engine::showTitle()"); return true; } -- cgit v1.2.3 From 753b5f89bab3eb2cdd6d0f4567a76d5d4fd83624 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 14 Jul 2014 18:17:07 +0200 Subject: CGE2: Unstub CommandHandler::reset(). --- engines/cge2/snail.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 62dfd996e9..df4c67cbcc 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -823,7 +823,7 @@ bool CommandHandler::idle() { } void CommandHandler::reset() { - warning("STUB: CommandHandler::reset()"); + _tail = _head; } void CommandHandler::clear() { -- cgit v1.2.3 From 035fb6ad1cdb8ca126ac8dd5a930b954f650061c Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 13:53:26 +0200 Subject: CGE2: Hopefully fix a memory leak problem regarding Hero::_dim; --- engines/cge2/hero.cpp | 28 +++++++++------------------- engines/cge2/hero.h | 2 +- 2 files changed, 10 insertions(+), 20 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 6281e4dd5e..677811885e 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -33,11 +33,7 @@ namespace CGE2 { Hero::Hero(CGE2Engine *vm) : Sprite(vm), _contact(nullptr), _dir(kNoDir), - _curDim(0), _tracePtr(-1), _ignoreMap(false) { - - for (int i = 0; i < kDimMax; i++) { - _dim[i] = nullptr; - } + _curDim(0), _tracePtr(-1), _ignoreMap(false), _isDimLoaded(false) { } Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! @@ -62,10 +58,14 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo Seq *seq; int section = kIdPhase; - for (int i = 0; i < kDimMax; i++) { - _dim[i] = new Bitmap[_shpCnt]; - for (int j = 0; j < _shpCnt; j++) - _dim[i][j].setVM(_vm); + if (!_isDimLoaded) { + for (int i = 0; i < kDimMax; i++) { + _dim[i] = new Bitmap[_shpCnt]; + for (int j = 0; j < _shpCnt; j++) + _dim[i][j].setVM(_vm); + } + + _isDimLoaded = true; } if (_seqCnt) { @@ -200,16 +200,6 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo return this; } -Sprite *Hero::contract() { - /* TODO: Recheck this later! - for (int i = 0; i < kDimMax; i++) { - if (_dim[i] != nullptr) - delete[] _dim[i]; - } - */ - return this; -} - void Hero::setCurrent() { FXP m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); FXP tmp = m * _siz.y; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index c277b4a780..f45a65211b 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -62,6 +62,7 @@ struct HeroTab { }; class Hero : public Sprite { + bool _isDimLoaded; int _hig[kDimMax]; Sprite *_contact; public: @@ -77,7 +78,6 @@ public: Hero(CGE2Engine *vm); void tick(); Sprite *expand(); - Sprite *contract(); Sprite *setContact(); int stepSize() { return _ext->_seq[7]._dx; } int distance(V3D pos); -- cgit v1.2.3 From 470736b9c456cc9217f7377dbd543774eebcb88b Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 14:19:55 +0200 Subject: CGE2: Remove unnecessary comment from sceneUp(). --- engines/cge2/cge2_main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index bddb83b84f..0e2e702288 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -453,7 +453,6 @@ void CGE2Engine::sceneUp(int cav) { _mouse->on(); feedSnail(_vga->_showQ->locate(bakRef + 255), kNear, _heroTab[_sex]->_ptr); - //setDrawColors(); - It's only for debugging purposes. Can be left out for now. } void CGE2Engine::sceneDown() { -- cgit v1.2.3 From 8861b0b583f1cd56ff5e8f7a8b408f696c85f545 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 14:41:46 +0200 Subject: CGE2: Get rid of _mode. --- engines/cge2/cge2.cpp | 1 - engines/cge2/cge2.h | 1 - engines/cge2/cge2_main.cpp | 6 +----- 3 files changed, 1 insertion(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 1fb880c4df..b820ba53a7 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -74,7 +74,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _quitFlag = false; _bitmapPalette = nullptr; - _mode = 0; _music = true; _startupMode = 1; _now = 1; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 252fad07bd..d97ba3d675 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -263,7 +263,6 @@ public: bool _quitFlag; Dac *_bitmapPalette; - int _mode; bool _music; int _startupMode; int _now; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 0e2e702288..29592d73f1 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -836,14 +836,12 @@ void CGE2Engine::cge2_main() { if (_startGameSlot != -1) { // Starting up a savegame from the launcher - _mode++; runGame(); } if (showTitle("WELCOME")) { #if 0 - if (_mode == 1) - movie(kIntroExt); + movie(kIntroExt); #endif if (_text->getText(255) != nullptr) { runGame(); @@ -891,8 +889,6 @@ int CGE2Engine::newRandom(int range) { bool CGE2Engine::showTitle(const char *name) { if (_quitFlag) return false; - - _mode++; _bitmapPalette = _vga->_sysPal; BitmapPtr LB = new Bitmap[1]; -- cgit v1.2.3 From d9471679319e5a5bbc61c71fc3a07548d242fe6d Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 15:17:00 +0200 Subject: CGE2: Fix the intro animation. --- engines/cge2/cge2_main.cpp | 1 + engines/cge2/snail.cpp | 54 ++++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 26 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 29592d73f1..d0a11643e3 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -402,6 +402,7 @@ void CGE2Engine::movie(const char *ext) { _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); _spare->clear(); + _vga->_showQ->clear(); _now = now; } } diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index df4c67cbcc..7ba0c3638e 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -848,33 +848,35 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { CommandHandler::Command *c = &comtab[ptr]; CommandHandler::Command *q = &comtab[cnt]; - int pocFre = freePockets(hero->_ref & 1); - int pocReq = 0; - CommandHandler::Command *p = c; - for (; p < q && p->_commandType != kCmdNext; p++) { // scan commands - // drop from pocket? - if ((p->_commandType == kCmdSend && p->_val != _now) - || p->_commandType == kCmdGive) { - int ref = p->_ref; - if (ref < 0) - ref = spr->_ref; - if (findActivePocket(ref) >= 0) - --pocReq; - } - // make/dispose additional room? - if (p->_commandType == kCmdRoom) { - if (p->_val == 0) + if (hero != nullptr) { + int pocFre = freePockets(hero->_ref & 1); + int pocReq = 0; + CommandHandler::Command *p = c; + for (; p < q && p->_commandType != kCmdNext; p++) { // scan commands + // drop from pocket? + if ((p->_commandType == kCmdSend && p->_val != _now) + || p->_commandType == kCmdGive) { + int ref = p->_ref; + if (ref < 0) + ref = spr->_ref; + if (findActivePocket(ref) >= 0) + --pocReq; + } + // make/dispose additional room? + if (p->_commandType == kCmdRoom) { + if (p->_val == 0) + ++pocReq; + else + --pocReq; + } + // put into pocket? + if (p->_commandType == kCmdKeep) ++pocReq; - else - --pocReq; - } - // put into pocket? - if (p->_commandType == kCmdKeep) - ++pocReq; - // overloaded? - if (pocReq > pocFre) { - pocFul(); - return; + // overloaded? + if (pocReq > pocFre) { + pocFul(); + return; + } } } -- cgit v1.2.3 From 8fae34df055ecc90cce6324a8c9eb09112e21e31 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 16:22:43 +0200 Subject: CGE2: Implement snRoom(). --- engines/cge2/cge2.h | 2 +- engines/cge2/snail.cpp | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index d97ba3d675..b152b617d3 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -246,7 +246,7 @@ public: void snWalk(Sprite *spr, int val); void snReach(Sprite *spr, int val); void snSound(Sprite *spr, int wav); - void snRoom(Sprite *spr, int val); + void snRoom(Sprite *spr, bool on); void snDim(Sprite *spr, int val); void snGhost(Bitmap *bmp); void snSay(Sprite *spr, int val); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 7ba0c3638e..284cecff3f 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -688,8 +688,27 @@ void CGE2Engine::snSound(Sprite *spr, int wav) { _sound->setRepeat(1); } -void CGE2Engine::snRoom(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snRoom()"); +void CGE2Engine::snRoom(Sprite *spr, bool on) { + if (!isHero(spr)) + return; + int sx = spr->_ref & 1; + Sprite **p = _heroTab[sx]->_pocket; + if (on) { + if (freePockets(sx) == 0 && p[kPocketMax] == nullptr) { + SWAP(p[kPocketMax], p[kPocketMax - 1]); + snHide(p[kPocketMax], 1); + } + } else { + if (p[kPocketMax]) { + for (int i = 0; i < kPocketMax; i++) { + if (p[i] == nullptr) { + snHide(p[kPocketMax], 0); + SWAP(p[kPocketMax], p[i]); + break; + } + } + } + } } void CGE2Engine::snDim(Sprite *spr, int val) { -- cgit v1.2.3 From fbd8f2c390af8f73a138110450e4f2b98adffd49 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 15 Jul 2014 19:32:07 +0200 Subject: CGE2: Some rework in snail --- engines/cge2/snail.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 284cecff3f..84a0373ff5 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -691,21 +691,20 @@ void CGE2Engine::snSound(Sprite *spr, int wav) { void CGE2Engine::snRoom(Sprite *spr, bool on) { if (!isHero(spr)) return; - int sx = spr->_ref & 1; - Sprite **p = _heroTab[sx]->_pocket; + + int sex = spr->_ref & 1; + Sprite **p = _heroTab[sex]->_pocket; if (on) { - if (freePockets(sx) == 0 && p[kPocketMax] == nullptr) { + if (freePockets(sex) == 0 && p[kPocketMax] == nullptr) { SWAP(p[kPocketMax], p[kPocketMax - 1]); snHide(p[kPocketMax], 1); } - } else { - if (p[kPocketMax]) { - for (int i = 0; i < kPocketMax; i++) { - if (p[i] == nullptr) { - snHide(p[kPocketMax], 0); - SWAP(p[kPocketMax], p[i]); - break; - } + } else if (p[kPocketMax]) { + for (int i = 0; i < kPocketMax; i++) { + if (p[i] == nullptr) { + snHide(p[kPocketMax], 0); + SWAP(p[kPocketMax], p[i]); + break; } } } @@ -715,7 +714,7 @@ void CGE2Engine::snDim(Sprite *spr, int val) { if (isHero(spr)) { if (val > 0) ++*(Hero*)spr; - if (val < 0) + else if (val < 0) --*(Hero*)spr; } } @@ -951,7 +950,7 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { } if (c->_commandType == kCmdIf) { Sprite *s = (c->_ref < 0) ? spr : _vga->_showQ->locate(c->_ref); - if (s) { // sprite extsts + if (s) { // sprite exists if (!s->seqTest(-1)) { // not parked int v = c->_val; if (v > 255) if (s) v = s->labVal(snq, v >> 8); -- cgit v1.2.3 From 0b0f998aacb1d8804e8cdf2679df69966a643c41 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 22:15:06 +0200 Subject: CGE2: Try a different approach regarding _dim. Now it doesn't crash the hospital scene, but I am not entirely sure it's totally leak-free... --- engines/cge2/hero.cpp | 23 +++++++++++++++-------- engines/cge2/hero.h | 1 - 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 677811885e..0a72178fe7 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -33,7 +33,11 @@ namespace CGE2 { Hero::Hero(CGE2Engine *vm) : Sprite(vm), _contact(nullptr), _dir(kNoDir), - _curDim(0), _tracePtr(-1), _ignoreMap(false), _isDimLoaded(false) { + _curDim(0), _tracePtr(-1), _ignoreMap(false) { + + for (int i = 0; i < kDimMax; i++) { + _dim[i] = nullptr; + } } Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! @@ -57,15 +61,18 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo int cnt[kActions]; Seq *seq; int section = kIdPhase; - - if (!_isDimLoaded) { - for (int i = 0; i < kDimMax; i++) { - _dim[i] = new Bitmap[_shpCnt]; - for (int j = 0; j < _shpCnt; j++) - _dim[i][j].setVM(_vm); + + for (int i = 0; i < kDimMax; i++) { + if (_dim[i] != nullptr) { + delete[] _dim[i]; + _dim[i] = nullptr; } + } - _isDimLoaded = true; + for (int i = 0; i < kDimMax; i++) { + _dim[i] = new Bitmap[_shpCnt]; + for (int j = 0; j < _shpCnt; j++) + _dim[i][j].setVM(_vm); } if (_seqCnt) { diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index f45a65211b..e8cce711f4 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -62,7 +62,6 @@ struct HeroTab { }; class Hero : public Sprite { - bool _isDimLoaded; int _hig[kDimMax]; Sprite *_contact; public: -- cgit v1.2.3 From 7d6c02ce3f3e05b72538ca0b0a169dbf4868caef Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 23:12:58 +0200 Subject: CGE2: Add Hero::contract(). Fix the crash introduced by previous commit on the second scene. --- engines/cge2/hero.cpp | 13 +++++++++++++ engines/cge2/hero.h | 1 + 2 files changed, 14 insertions(+) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 0a72178fe7..cebfe73295 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -207,6 +207,19 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo return this; } +Sprite *Hero::contract() { + for (int i = 0; i < kDimMax; i++) { + if (_dim[i] != nullptr) { + delete[] _dim[i]; + if (_ext->_shpList == _dim[i]) + _ext->_shpList = nullptr; + _dim[i] = nullptr; + } + } + Sprite::contract(); + return this; +} + void Hero::setCurrent() { FXP m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); FXP tmp = m * _siz.y; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index e8cce711f4..c277b4a780 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -77,6 +77,7 @@ public: Hero(CGE2Engine *vm); void tick(); Sprite *expand(); + Sprite *contract(); Sprite *setContact(); int stepSize() { return _ext->_seq[7]._dx; } int distance(V3D pos); -- cgit v1.2.3 From 20eb951b3acf2c1d0be588f9375d3a92184aceee Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 15 Jul 2014 23:54:07 +0200 Subject: CGE2: Rework getText() so it works nicely with offUse(). --- engines/cge2/text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 9ebed58590..9989dabbf4 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -133,7 +133,7 @@ char *Text::getText(int ref) { return _cache[i]._text; warning("getText: Unable to find ref %d:%d", ref / 256, ref % 256); - return _cache[_txtCount - 1]._text; + return nullptr; } void Text::say(const char *text, Sprite *spr) { -- cgit v1.2.3 From a82bd2d9c600cd50fc29c3078f9f2d8c79ea18ff Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 17 Jul 2014 15:18:55 +0200 Subject: CGE2: Fix memory leak regarding Sprite::ghost(). uint8 *v = new uint8; was the faulty line in Sprite::ghost(), and it should be released right here. --- engines/cge2/snail.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 84a0373ff5..5c152f4af1 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -722,8 +722,8 @@ void CGE2Engine::snDim(Sprite *spr, int val) { void CGE2Engine::snGhost(Bitmap *bmp) { V2D p(this, bmp->_map & 0xFFFF, bmp->_map >> 16); bmp->hide(p); + bmp->release(); delete[] bmp->_b; - bmp->_v = nullptr; bmp->_b = nullptr; delete bmp; bmp = nullptr; -- cgit v1.2.3 From d9e82f8f8e1db2f5a3b03a512643b46553bcc88a Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 17 Jul 2014 15:41:49 +0200 Subject: CGE2: Get rid of _sprite. --- engines/cge2/cge2.cpp | 2 -- engines/cge2/cge2.h | 3 +-- engines/cge2/cge2_main.cpp | 54 ++++++++++++++++++++++++---------------------- engines/cge2/vga13h.cpp | 3 --- 4 files changed, 29 insertions(+), 33 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index b820ba53a7..cddf833c24 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -45,7 +45,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription), _randomSource("cge") { _resman = nullptr; _vga = nullptr; - _sprite = nullptr; _midiPlayer = nullptr; _fx = nullptr; _sound = nullptr; @@ -142,7 +141,6 @@ void CGE2Engine::deinit() { delete _eyeTab[i]; } delete _eye; - delete _sprite; delete _commandHandler; delete _commandHandlerTurbo; delete _font; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index b152b617d3..6f07102ea5 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -152,7 +152,7 @@ public: void initToolbar(); void loadHeroes(); void loadScript(const char *fname); - void loadSprite(const char *fname, int ref, int scene, V3D &pos); + Sprite *loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); void sceneUp(int cav); void sceneDown(); @@ -289,7 +289,6 @@ public: ResourceManager *_resman; Vga *_vga; - Sprite *_sprite; MusicPlayer *_midiPlayer; Fx *_fx; Sound *_sound; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index d0a11643e3..d9fcbb2a97 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -156,7 +156,7 @@ void CGE2Engine::badLab(const char *fn) { error("Misplaced label in %s!", fn); } -void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { +Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { int shpcnt = 0; int seqcnt = 0; int cnt[kActions]; @@ -275,40 +275,43 @@ void CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) { ++shpcnt; // Make sprite of choosen type: + Sprite *sprite = nullptr; char c = *fname | 0x20; if (c >= 'a' && c <= 'z' && fname[1] == '0' && fname[2] == '\0') { h = new Hero(this); if (h) { h->gotoxyz(pos); - _sprite = h; + sprite = h; } } else { - _sprite = new Sprite(this); - if (_sprite) - _sprite->gotoxyz(pos); + sprite = new Sprite(this); + if (sprite) + sprite->gotoxyz(pos); } - if (_sprite) { - _sprite->_ref = ref; - _sprite->_scene = scene; + if (sprite) { + sprite->_ref = ref; + sprite->_scene = scene; - _sprite->_flags._frnt = frnt; - _sprite->_flags._east = east; - _sprite->_flags._port = port; - _sprite->_flags._tran = tran; - _sprite->_flags._kill = true; + sprite->_flags._frnt = frnt; + sprite->_flags._east = east; + sprite->_flags._port = port; + sprite->_flags._tran = tran; + sprite->_flags._kill = true; // Extract the filename, without the extension - Common::strlcpy(_sprite->_file, fname, sizeof(_sprite->_file)); - char *p = strchr(_sprite->_file, '.'); + Common::strlcpy(sprite->_file, fname, sizeof(sprite->_file)); + char *p = strchr(sprite->_file, '.'); if (p) *p = '\0'; - _sprite->_shpCnt = shpcnt; - _sprite->_seqCnt = seqcnt; + sprite->_shpCnt = shpcnt; + sprite->_seqCnt = seqcnt; for (int i = 0; i < kActions; i++) - _sprite->_actionCtrl[i]._cnt = cnt[i]; + sprite->_actionCtrl[i]._cnt = cnt[i]; + + return sprite; } } @@ -360,16 +363,16 @@ void CGE2Engine::loadScript(const char *fname) { ok = true; // no break: OK - _sprite = nullptr; - loadSprite(SpN, SpI, SpA, P); - if (_sprite) { + Sprite *sprite = loadSprite(SpN, SpI, SpA, P); + if (sprite) { if (BkG) - _sprite->_flags._back = true; + sprite->_flags._back = true; int n = _spare->count(); - if (_spare->locate(_sprite->_ref) == nullptr) - _spare->dispose(_sprite); - _sprite = nullptr; + if (_spare->locate(sprite->_ref) == nullptr) + _spare->dispose(sprite); + else + delete sprite; if (_spare->count() == n) error("Durplicated reference! %s", SpN); } @@ -445,7 +448,6 @@ void CGE2Engine::sceneUp(int cav) { _vga->copyPage(1, 0); _vga->show(); - _sprite = _vga->_showQ->first(); _vga->sunrise(_vga->_sysPal); _dark = false; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 02d536c3e8..ea82fb7880 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -114,9 +114,6 @@ Sprite::Sprite(CGE2Engine *vm, BitmapPtr shpP, int cnt) } Sprite::~Sprite() { - if (_vm->_sprite == this) - _vm->_sprite = nullptr; - contract(); } -- cgit v1.2.3 From 2203b7df8c6d212899d86bb7460526b670ad44f1 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 17 Jul 2014 16:41:32 +0200 Subject: CGE2: Smaller revision regarding Spare. --- engines/cge2/spare.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 93c8a2674d..756f937ab5 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -73,11 +73,10 @@ Sprite *Spare::take(int ref) { for (uint i = 0; i < _container.size(); ++i) { if (spr == _container[i]) { _container.remove_at(i); - break; + return spr; } } } - return spr; } void Spare::takeScene(int cav) { @@ -94,7 +93,7 @@ void Spare::takeScene(int cav) { } void Spare::store(Sprite *spr) { - _container.insert_at(_container.size(), spr); + _container.push_back(spr); } void Spare::update(Sprite *spr) { -- cgit v1.2.3 From 5e780d3d97cc992a0cdb46266dfddfdaa229d605 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 17 Jul 2014 16:44:02 +0200 Subject: CGE2: Use locate() instead of take() where possible. --- engines/cge2/cge2_main.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index d9fcbb2a97..9111a10e58 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -525,14 +525,13 @@ void CGE2Engine::storeHeroPos() { } void CGE2Engine::showBak(int ref) { - Sprite *spr = _spare->take(ref); + Sprite *spr = _spare->locate(ref); if (spr != nullptr) { _bitmapPalette = _vga->_sysPal; spr->expand(); _bitmapPalette = nullptr; spr->show(2); _vga->copyPage(1, 2); - _spare->dispose(spr); } } @@ -712,10 +711,9 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() _spare->update(h); } _heroTab[0]->_ptr = h; - s = _spare->take(152); + s = _spare->locate(152); _vga->_showQ->insert(s); _heroTab[0]->_face = s; - _spare->update(s); // initialize Wacek/Vincent s = _spare->take(141); @@ -727,10 +725,9 @@ void CGE2Engine::loadHeroes() { // Original name: loadGame() _spare->update(h); } _heroTab[1]->_ptr = h; - s = _spare->take(151); + s = _spare->locate(151); _vga->_showQ->insert(s); _heroTab[1]->_face = s; - _spare->update(s); //--- start! switchHero(_sex); -- cgit v1.2.3 From 49cea2d927c4a9a278827e6c4d0877386bb327d2 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 17 Jul 2014 17:23:12 +0200 Subject: CGE2: Initialize _wideSpace in InfoLine's constructor. --- engines/cge2/talk.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 227e0135bd..b086627f80 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -237,6 +237,7 @@ void Talk::update(const char *text) { InfoLine::InfoLine(CGE2Engine *vm, uint16 w, ColorBank color) : Talk(vm), _oldText(nullptr), _newText(nullptr), _realTime(false), _vm(vm) { + _wideSpace = false; BitmapPtr b = new Bitmap[1]; if (color == kCBRel) _vm->setAutoColors(); -- cgit v1.2.3 From 5963a540ef161e804f756d54970b2c7cb55fcc00 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 17 Jul 2014 17:33:04 +0200 Subject: CGE2: Add destructor to Hero(). Hopefully it will cut short the leak problems with _dim[]. --- engines/cge2/hero.cpp | 4 ++++ engines/cge2/hero.h | 1 + 2 files changed, 5 insertions(+) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index cebfe73295..c9b8dc5a13 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -40,6 +40,10 @@ Hero::Hero(CGE2Engine *vm) } } +Hero::~Hero() { + contract(); +} + Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! if (_ext) return this; diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index c277b4a780..3b5329e12c 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -75,6 +75,7 @@ public: int _maxDist; bool _ignoreMap; Hero(CGE2Engine *vm); + ~Hero(); void tick(); Sprite *expand(); Sprite *contract(); -- cgit v1.2.3 From f3345f296f992ec2766fe9e9687f9997b0c34c6f Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 17 Jul 2014 20:50:16 +0200 Subject: CGE2: Use locate instead() of take() in CGE2Eninge::locate(). It fixes the regression with the hole of the sign post on the ground from scene 6 and the display bug in the hospital. --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9111a10e58..e0cd688988 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -580,7 +580,7 @@ Sprite *CGE2Engine::locate(int ref) { _taken = false; Sprite *spr = _vga->_showQ->locate(ref); if (!spr) { - spr = _spare->take(ref); + spr = _spare->locate(ref); if (spr) _taken = true; } -- cgit v1.2.3 From c285d3299c2c87f6d5c6279e7ebcb65274024b9b Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 18 Jul 2014 00:12:53 +0200 Subject: CGE2: Silence GCC warnings. --- engines/cge2/cge2_main.cpp | 4 ++-- engines/cge2/spare.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e0cd688988..938ad849be 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -310,9 +310,9 @@ Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) for (int i = 0; i < kActions; i++) sprite->_actionCtrl[i]._cnt = cnt[i]; - - return sprite; } + + return sprite; } void CGE2Engine::loadScript(const char *fname) { diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 756f937ab5..411327e40a 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -73,10 +73,11 @@ Sprite *Spare::take(int ref) { for (uint i = 0; i < _container.size(); ++i) { if (spr == _container[i]) { _container.remove_at(i); - return spr; + break; } } } + return spr; } void Spare::takeScene(int cav) { -- cgit v1.2.3 From db9e503cfcca7096a1260c96ed24aef3dc4ed450 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 18 Jul 2014 02:26:13 +0200 Subject: CGE2: Rework snSetRef(). --- engines/cge2/snail.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 5c152f4af1..1361c64469 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -629,10 +629,9 @@ void CGE2Engine::snFlag(int ref, int val) { warning("STUB: CGE2Engine::snFlag()"); } -void CGE2Engine::snSetRef(Sprite *spr, int val) { // TODO:: Recheck this! +void CGE2Engine::snSetRef(Sprite *spr, int val) { if (spr) { spr->_ref = val; - _spare->update(spr); } } -- cgit v1.2.3 From 1176721034b07ddc6517e0a8b96c5eedb0b57e08 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 21 Jul 2014 19:52:46 +0200 Subject: CGE2: Fix the issue of loading sprites with changed _ref. It fixes the problem with the multiply displayed Vulcanizer after giving him the glasses/basket ball, then saving and loading. --- engines/cge2/spare.cpp | 24 ++++++++++++++++++++++-- engines/cge2/spare.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 411327e40a..54918f7920 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -47,7 +47,17 @@ void Spare::sync(Common::Serializer &s) { for (int i = 0; i < size; i++) { Sprite *sprite = new Sprite(_vm); sprite->sync(s); - update(sprite); + + // In case the reference of the sprite is changed comapred to CGE.INI + // TODO: Rework the whole loading so it doesn't load every sprite from CGE.INI + // and then update them, but load everything from file, so this check isn't + // needed anymore. To do that, I also have to save/load the toolbar's sprites too. + Sprite *loc = locate(sprite->_file); + if (loc->_ref != sprite->_ref) { + loc->contract(); + *loc = *sprite; + } else + update(sprite); } } } @@ -67,6 +77,14 @@ Sprite *Spare::locate(int ref) { return nullptr; } +Sprite *Spare::locate(char *file) { + for (uint i = 0; i < _container.size(); ++i) { + if (strcmp(_container[i]->_file, file) == 0) + return _container[i]; + } + return nullptr; +} + Sprite *Spare::take(int ref) { Sprite *spr = nullptr; if ((spr = locate(ref)) != nullptr) { @@ -101,8 +119,10 @@ void Spare::update(Sprite *spr) { Sprite *sp = locate(spr->_ref); if (sp == nullptr) store(spr); - else + else { + sp->contract(); *sp = *spr; + } } void Spare::dispose(Sprite *spr) { diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index 7dc6ce60f5..cfc158d4b6 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -40,6 +40,7 @@ public: ~Spare() { clear(); } void store(Sprite *spr); Sprite *locate(int ref); + Sprite *locate(char *file); Sprite *take(int ref); void takeScene(int cav); void update(Sprite *spr); -- cgit v1.2.3 From 6e26422468b8667c86219069cea25466370656e1 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 21 Jul 2014 19:57:33 +0200 Subject: CGE2: Rework loading of sprites from file. Now it satisfies the needs described in the last commit's TODO comment. --- engines/cge2/cge2.h | 2 +- engines/cge2/cge2_main.cpp | 5 ++++- engines/cge2/saveload.cpp | 2 +- engines/cge2/spare.cpp | 12 +----------- 4 files changed, 7 insertions(+), 14 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 6f07102ea5..cd3a56617a 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -151,7 +151,7 @@ public: void runGame(); void initToolbar(); void loadHeroes(); - void loadScript(const char *fname); + void loadScript(const char *fname, bool onlyToolbar = false); Sprite *loadSprite(const char *fname, int ref, int scene, V3D &pos); void badLab(const char *fn); void sceneUp(int cav); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 938ad849be..51d9816445 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -315,7 +315,7 @@ Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) return sprite; } -void CGE2Engine::loadScript(const char *fname) { +void CGE2Engine::loadScript(const char *fname, bool onlyToolbar) { EncryptedStream scrf(this, fname); if (scrf.err()) @@ -341,6 +341,9 @@ void CGE2Engine::loadScript(const char *fname) { // sprite ident number int SpI = number(tmpStr); + if (onlyToolbar && SpI >= 141) + return; + // sprite file name char *SpN; if ((SpN = token(nullptr)) == nullptr) diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 3890e74341..b9a856f5f4 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -323,7 +323,7 @@ void CGE2Engine::resetGame() { _spare->clear(); _vga->_showQ->clear(); _commandHandler->reset(); - loadScript("CGE.INI"); + loadScript("CGE.INI", true); delete _infoLine; _infoLine = new InfoLine(this, kInfoW); } diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 54918f7920..547d070fc9 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -47,17 +47,7 @@ void Spare::sync(Common::Serializer &s) { for (int i = 0; i < size; i++) { Sprite *sprite = new Sprite(_vm); sprite->sync(s); - - // In case the reference of the sprite is changed comapred to CGE.INI - // TODO: Rework the whole loading so it doesn't load every sprite from CGE.INI - // and then update them, but load everything from file, so this check isn't - // needed anymore. To do that, I also have to save/load the toolbar's sprites too. - Sprite *loc = locate(sprite->_file); - if (loc->_ref != sprite->_ref) { - loc->contract(); - *loc = *sprite; - } else - update(sprite); + update(sprite); } } } -- cgit v1.2.3 From bac952917ffb4901ad03e67a6ba65f74e65ec5e4 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 21 Jul 2014 20:20:33 +0200 Subject: CGE2: Remove Spare::locate(char *file), since it's not used anymore. --- engines/cge2/spare.cpp | 8 -------- engines/cge2/spare.h | 1 - 2 files changed, 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 547d070fc9..4ca29009d8 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -67,14 +67,6 @@ Sprite *Spare::locate(int ref) { return nullptr; } -Sprite *Spare::locate(char *file) { - for (uint i = 0; i < _container.size(); ++i) { - if (strcmp(_container[i]->_file, file) == 0) - return _container[i]; - } - return nullptr; -} - Sprite *Spare::take(int ref) { Sprite *spr = nullptr; if ((spr = locate(ref)) != nullptr) { diff --git a/engines/cge2/spare.h b/engines/cge2/spare.h index cfc158d4b6..7dc6ce60f5 100644 --- a/engines/cge2/spare.h +++ b/engines/cge2/spare.h @@ -40,7 +40,6 @@ public: ~Spare() { clear(); } void store(Sprite *spr); Sprite *locate(int ref); - Sprite *locate(char *file); Sprite *take(int ref); void takeScene(int cav); void update(Sprite *spr); -- cgit v1.2.3 From 77b5c7e4adea3485a8c3cfb215eca4471deae443 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 22 Jul 2014 15:41:33 +0200 Subject: CGE2: Rename _commandStat to _soundStat. --- engines/cge2/cge2.cpp | 6 +++--- engines/cge2/cge2.h | 4 ++-- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/snail.cpp | 16 ++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index cddf833c24..e247cf507e 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -83,9 +83,9 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _lastTick = 0; _waitSeq = 0; _waitRef = 0; - _commandStat._wait = nullptr; - _commandStat._ref[0] = 0; - _commandStat._ref[1] = 0; + _soundStat._wait = nullptr; + _soundStat._ref[0] = 0; + _soundStat._ref[1] = 0; _taken = false; _endGame = false; for (int i = 0; i < 4; i++) diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index cd3a56617a..48d9bc84fe 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -271,10 +271,10 @@ public: bool _dark; int _waitSeq; int _waitRef; - struct CommandStat { + struct { int *_wait; int _ref[2]; - } _commandStat; + } _soundStat; bool _taken; bool _endGame; bool _flag[4]; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 51d9816445..f887bdc2fe 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -463,7 +463,7 @@ void CGE2Engine::sceneUp(int cav) { void CGE2Engine::sceneDown() { busy(true); - _commandStat._wait = nullptr; // unlock snail + _soundStat._wait = nullptr; // unlock snail Sprite *spr = _vga->_showQ->locate((_now << 8) | 254); if (spr) feedSnail(spr, kNear, _heroTab[_sex]->_ptr); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 1361c64469..cee4531fba 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -67,13 +67,13 @@ CommandHandler::~CommandHandler() { } void CommandHandler::runCommand() { - if (!_turbo && _vm->_commandStat._wait) { - if (*(_vm->_commandStat._wait)) + if (!_turbo && _vm->_soundStat._wait) { + if (*(_vm->_soundStat._wait)) return; else { - ++_vm->_commandStat._ref[0]; + ++_vm->_soundStat._ref[0]; warning("STUB: CommandHandler::runCommand() - Sound code missing!"); - _vm->_commandStat._wait = nullptr; + _vm->_soundStat._wait = nullptr; } } @@ -675,12 +675,12 @@ void CGE2Engine::snSound(Sprite *spr, int wav) { else { if (_sound->_smpinf._counter && wav < 20) return; - if (_commandStat._wait && ((wav & 255) > 80)) + if (_soundStat._wait && ((wav & 255) > 80)) return; - _commandStat._ref[1] = wav; - _commandStat._ref[0] = !_fx->exist(_commandStat._ref[1]); - _sound->play(_fx->load(_commandStat._ref[1], _commandStat._ref[0]), + _soundStat._ref[1] = wav; + _soundStat._ref[0] = !_fx->exist(_soundStat._ref[1]); + _sound->play(_fx->load(_soundStat._ref[1], _soundStat._ref[0]), (spr) ? (spr->_pos2D.x / (kScrWidth / 16)) : 8); } -- cgit v1.2.3 From e261886d92ea3c173d0e3a38cce73ac2b6d54c3f Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 22 Jul 2014 17:59:16 +0200 Subject: CGE2: Fix snSound(). --- engines/cge2/snail.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index cee4531fba..c8b1722134 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -286,6 +286,7 @@ void CommandHandler::runCommand() { break; case kCmdSound: _vm->snSound(spr, tailCmd._val); + _sound->setRepeat(1); break; case kCmdMap: _vm->_heroTab[tailCmd._ref & 1]->_ptr->_ignoreMap = tailCmd._val == 0; @@ -683,8 +684,6 @@ void CGE2Engine::snSound(Sprite *spr, int wav) { _sound->play(_fx->load(_soundStat._ref[1], _soundStat._ref[0]), (spr) ? (spr->_pos2D.x / (kScrWidth / 16)) : 8); } - - _sound->setRepeat(1); } void CGE2Engine::snRoom(Sprite *spr, bool on) { -- cgit v1.2.3 From 2f19de9ebe1d62d3bb6f93a121c68e52337a179f Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 22 Jul 2014 18:01:37 +0200 Subject: CGE2: Fix error introduced by previous commit. --- engines/cge2/snail.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index c8b1722134..8cb8d19b24 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -286,7 +286,7 @@ void CommandHandler::runCommand() { break; case kCmdSound: _vm->snSound(spr, tailCmd._val); - _sound->setRepeat(1); + _vm->_sound->setRepeat(1); break; case kCmdMap: _vm->_heroTab[tailCmd._ref & 1]->_ptr->_ignoreMap = tailCmd._val == 0; -- cgit v1.2.3 From def6b4fc3e38392c8345af9945cb3a1d208a7726 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 22 Jul 2014 18:54:48 +0200 Subject: CGE2: Add and use Sound::checkSoundHandle(). --- engines/cge2/cge2_main.cpp | 2 ++ engines/cge2/snail.cpp | 5 +---- engines/cge2/sound.cpp | 5 +++++ engines/cge2/sound.h | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f887bdc2fe..f8fa274bc8 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -551,6 +551,8 @@ void CGE2Engine::mainLoop() { // Check shouldQuit() _quitFlag = shouldQuit(); + + _sound->checkSoundHandle(); } void CGE2Engine::handleFrame() { diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 8cb8d19b24..9dce4dbbc8 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -742,10 +742,7 @@ void CGE2Engine::snSay(Sprite *spr, int val) { _sound->setRepeat(1); snSound(spr, i); _sound->setRepeat(oldRepeat); - //_commandStat._wait = &_sound->_smpinf._counter; - // This line is commented out for now since I wasn't able to find where this flag is reset - // and it's prevented the main loop from doing anything. - // TODO: Recheck this later! At the moment it seems working fine. + _soundStat._wait = &_sound->_smpinf._counter; } } } diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index b7b39d2722..7e886e5639 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -106,6 +106,11 @@ void Sound::stop() { sndDigiStop(&_smpinf); } +void Sound::checkSoundHandle() { + if (!_vm->_mixer->isSoundHandleActive(_soundHandle)) + _smpinf._counter = 0; +} + void Sound::sndDigiStop(SmpInfo *PSmpInfo) { if (_vm->_mixer->isSoundHandleActive(_soundHandle)) _vm->_mixer->stopHandle(_soundHandle); diff --git a/engines/cge2/sound.h b/engines/cge2/sound.h index 6fa2b2a553..e2e9482799 100644 --- a/engines/cge2/sound.h +++ b/engines/cge2/sound.h @@ -76,6 +76,7 @@ public: int16 getRepeat(); void setRepeat(int16 count); void stop(); + void checkSoundHandle(); private: int _soundRepeatCount; CGE2Engine *_vm; -- cgit v1.2.3 From aa6b4601d766f775e97c1b38332948a2a6a2c3e0 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 22 Jul 2014 18:59:22 +0200 Subject: CGE2: Change call order of checkSoundHandle(). --- engines/cge2/cge2_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f8fa274bc8..353abb8391 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -539,6 +539,8 @@ void CGE2Engine::showBak(int ref) { } void CGE2Engine::mainLoop() { + _sound->checkSoundHandle(); + _vga->show(); _commandHandlerTurbo->runCommand(); _commandHandler->runCommand(); @@ -551,8 +553,6 @@ void CGE2Engine::mainLoop() { // Check shouldQuit() _quitFlag = shouldQuit(); - - _sound->checkSoundHandle(); } void CGE2Engine::handleFrame() { -- cgit v1.2.3 From 848b2650e9427739b79e8b8c6c46f0501d6c3f18 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 22 Jul 2014 19:07:56 +0200 Subject: CGE2: Unstub CommandHandler::runCommand(). --- engines/cge2/snail.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 9dce4dbbc8..f6c6e2d71f 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -72,7 +72,13 @@ void CommandHandler::runCommand() { return; else { ++_vm->_soundStat._ref[0]; - warning("STUB: CommandHandler::runCommand() - Sound code missing!"); + if (_vm->_fx->exist(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0])) { + int16 oldRepeat = _vm->_sound->getRepeat(); + _vm->_sound->setRepeat(1); + _vm->_sound->play(_vm->_fx->load(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0]), _vm->_sound->_smpinf._span); + _vm->_sound->setRepeat(oldRepeat); + return; + } _vm->_soundStat._wait = nullptr; } } -- cgit v1.2.3 From 49f68a89132590ec5ef261451884249721de636b Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 22 Jul 2014 20:25:21 +0200 Subject: CGE2: Reimplement checkSaySwitch(). --- engines/cge2/cge2.cpp | 2 ++ engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 27 +++++++++++++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index e247cf507e..30529d9fbc 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -92,6 +92,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _flag[i] = false; _sayCap = true; _sayVox = true; + _oldSayVox = false; _req = 1; _midiNotify = nullptr; _spriteNotify = nullptr; @@ -164,6 +165,7 @@ bool CGE2Engine::hasFeature(EngineFeature f) const { } Common::Error CGE2Engine::run() { + syncSoundSettings(); initGraphics(kScrWidth, kScrHeight, false); init(); diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 48d9bc84fe..dbde43ae32 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -280,6 +280,7 @@ public: bool _flag[4]; bool _sayCap; bool _sayVox; + bool _oldSayVox; int _req; NotifyFunctionType _midiNotify; NotifyFunctionType _spriteNotify; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 353abb8391..65c5a746b9 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -26,6 +26,7 @@ */ #include "sound.h" +#include "common/config-manager.h" #include "cge2/cge2_main.h" #include "cge2/cge2.h" #include "cge2/vga13h.h" @@ -540,6 +541,7 @@ void CGE2Engine::showBak(int ref) { void CGE2Engine::mainLoop() { _sound->checkSoundHandle(); + checkSaySwitch(); _vga->show(); _commandHandlerTurbo->runCommand(); @@ -766,7 +768,7 @@ void CGE2Engine::initToolbar() { if (!_music) _midiPlayer->killMidi(); - checkSaySwitch(); + _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); // Sets the speech caption switch on. _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); _infoLine->setText(nullptr); @@ -807,11 +809,24 @@ void CGE2Engine::releasePocket(Sprite *spr) { } void CGE2Engine::checkSaySwitch() { - warning("STUB: CGE2Engine::checkSaySwitch()"); -// if (SNDDrvInfo.DDEV == DEV_QUIET) -// _sayVox = !(_sayCap = true); - _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); - _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + bool speechMute = mute; + if (!speechMute) + speechMute = ConfMan.getBool("speech_mute"); + + if (mute || speechMute) { + _sayVox = false; + _sayCap = true; + } + + if (_oldSayVox != _sayVox) { + _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); + _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); + } + + _oldSayVox = _sayVox; } void CGE2Engine::loadTab() { -- cgit v1.2.3 From 93b8f101c363e4e0b8bd8e27b504e8b037ae0aa3 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 09:28:57 +0200 Subject: CGE2: Implement switchMusic(): --- engines/cge2/cge2_main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 65c5a746b9..f5587e1e8a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -1104,7 +1104,9 @@ void CGE2Engine::switchColorMode() { } void CGE2Engine::switchMusic() { - warning("STUB: CGE2Engine::switchMusic()"); + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, (_music = !_music), nullptr); + keyClick(); + _commandHandlerTurbo->addCommand(kCmdMidi, -1, (_music) ? (_now << 8) : -1, nullptr); } void CGE2Engine::quit() { -- cgit v1.2.3 From 2f5e115e9a3b1a8cde9f17dade63b2ce1d0fa52d Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 09:29:24 +0200 Subject: CGE2: Use nullptr instead of NULL in switchColorMode(). --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f5587e1e8a..00b3adda38 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -1098,7 +1098,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { } void CGE2Engine::switchColorMode() { - _commandHandlerTurbo->addCommand(kCmdSeq, 121, _vga->_mono = !_vga->_mono, NULL); + _commandHandlerTurbo->addCommand(kCmdSeq, 121, _vga->_mono = !_vga->_mono, nullptr); keyClick(); _vga->setColors(_vga->_sysPal, 64); } -- cgit v1.2.3 From 71a9ead967180344310f28b329158cd5e812be31 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 09:52:05 +0200 Subject: CGE2: Add and implement checkSounds() and checkMusicSwitch(). --- engines/cge2/cge2.cpp | 1 + engines/cge2/cge2.h | 3 +++ engines/cge2/cge2_main.cpp | 24 +++++++++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 30529d9fbc..b6e406c1f7 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -74,6 +74,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _quitFlag = false; _bitmapPalette = nullptr; _music = true; + _musicMuted = false; _startupMode = 1; _now = 1; _sex = 1; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index dbde43ae32..df4e4f7fe0 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -190,6 +190,8 @@ public: void keyClick(); void swapInPocket(Sprite *spr, Sprite *xspr); void busyStep(); + void checkSounds(); + void checkMusicSwitch(); void optionTouch(int opt, uint16 mask); void switchColorMode(); @@ -264,6 +266,7 @@ public: bool _quitFlag; Dac *_bitmapPalette; bool _music; + bool _musicMuted; int _startupMode; int _now; int _sex; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 00b3adda38..37821fb375 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -540,8 +540,7 @@ void CGE2Engine::showBak(int ref) { } void CGE2Engine::mainLoop() { - _sound->checkSoundHandle(); - checkSaySwitch(); + checkSounds(); _vga->show(); _commandHandlerTurbo->runCommand(); @@ -557,6 +556,25 @@ void CGE2Engine::mainLoop() { _quitFlag = shouldQuit(); } +void CGE2Engine::checkSounds() { + _sound->checkSoundHandle(); + checkSaySwitch(); + checkMusicSwitch(); +} + +void CGE2Engine::checkMusicSwitch() { + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + _musicMuted = mute; + int musicVolume = ConfMan.getInt("music_volume"); + if (!_musicMuted) + _musicMuted = musicVolume == 0; + + if (_musicMuted && _music) + switchMusic(); +} + void CGE2Engine::handleFrame() { // Game frame delay uint32 millis = g_system->getMillis(); @@ -1069,7 +1087,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if (mask & kMouseLeftUp) + if ((mask & kMouseLeftUp) && !_musicMuted) switchMusic(); break; case 3: -- cgit v1.2.3 From b15b1043f91996c5213d7f1b5aa46202703a572b Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 10:00:03 +0200 Subject: CGE2: Updgrade checkSaySwitch(). Now it takes into account the "Speech volume" option in the Launcher and it only plays the keyClick() sound if the button is really switched, not every time it's clicked. --- engines/cge2/cge2_main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 37821fb375..4d38b1034b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -833,6 +833,10 @@ void CGE2Engine::checkSaySwitch() { bool speechMute = mute; if (!speechMute) speechMute = ConfMan.getBool("speech_mute"); + if (!speechMute) { + int speechVolume = ConfMan.getInt("speech_volume"); + speechMute = speechVolume == 0; + } if (mute || speechMute) { _sayVox = false; @@ -842,6 +846,7 @@ void CGE2Engine::checkSaySwitch() { if (_oldSayVox != _sayVox) { _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); + keyClick(); } _oldSayVox = _sayVox; @@ -1160,7 +1165,6 @@ void CGE2Engine::switchCap() { _sayCap = !_sayCap; if (!_sayCap) _sayVox = true; - keyClick(); checkSaySwitch(); } } @@ -1170,7 +1174,6 @@ void CGE2Engine::switchVox() { _sayVox = !_sayVox; if (!_sayVox) _sayCap = true; - keyClick(); checkSaySwitch(); } } -- cgit v1.2.3 From 4c3bd3e0f51d20019d0cfe237f23b3a0f237cf0e Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 10:09:27 +0200 Subject: CGE2: Add MidiPlayer::syncVolume() call to checkSounds(). --- engines/cge2/cge2_main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 4d38b1034b..8341f8a276 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -560,6 +560,7 @@ void CGE2Engine::checkSounds() { _sound->checkSoundHandle(); checkSaySwitch(); checkMusicSwitch(); + _midiPlayer->syncVolume(); } void CGE2Engine::checkMusicSwitch() { -- cgit v1.2.3 From 6336ddb3ce4a9b2b42fc53985bad2e6a69012188 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 12:31:06 +0200 Subject: CGE2: Keep music setting in sync with the Launcher. --- engines/cge2/cge2.cpp | 1 + engines/cge2/cge2.h | 3 ++- engines/cge2/cge2_main.cpp | 29 +++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index b6e406c1f7..916b12fef9 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -75,6 +75,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _bitmapPalette = nullptr; _music = true; _musicMuted = false; + _oldMusicVolume = ConfMan.getInt("music_volume");; _startupMode = 1; _now = 1; _sex = 1; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index df4e4f7fe0..0c5ab4d29c 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -195,7 +195,7 @@ public: void optionTouch(int opt, uint16 mask); void switchColorMode(); - void switchMusic(); + void switchMusic(bool on); void quit(); void setVolume(int idx, int cnt); void switchCap(); @@ -267,6 +267,7 @@ public: Dac *_bitmapPalette; bool _music; bool _musicMuted; + int _oldMusicVolume; int _startupMode; int _now; int _sex; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 8341f8a276..a22df8d896 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -571,9 +571,14 @@ void CGE2Engine::checkMusicSwitch() { int musicVolume = ConfMan.getInt("music_volume"); if (!_musicMuted) _musicMuted = musicVolume == 0; - - if (_musicMuted && _music) - switchMusic(); + + if (!_musicMuted && !_music) { + _oldMusicVolume = musicVolume; + switchMusic(_music = true); + } + if (_musicMuted && _music) { + switchMusic(_music = false); + } } void CGE2Engine::handleFrame() { @@ -1093,8 +1098,8 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && !_musicMuted) - switchMusic(); + if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) + switchMusic(_music = !_music); break; case 3: if (mask & kMouseLeftUp) @@ -1127,10 +1132,18 @@ void CGE2Engine::switchColorMode() { _vga->setColors(_vga->_sysPal, 64); } -void CGE2Engine::switchMusic() { - _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, (_music = !_music), nullptr); +void CGE2Engine::switchMusic(bool on) { + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); keyClick(); - _commandHandlerTurbo->addCommand(kCmdMidi, -1, (_music) ? (_now << 8) : -1, nullptr); + _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); + + if (!on) { + if (!_musicMuted) { + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + } + } else + ConfMan.setInt("music_volume", _oldMusicVolume); } void CGE2Engine::quit() { -- cgit v1.2.3 From 014b734c984c6e7d09ce6924d5e216525cffab5c Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 14:24:06 +0200 Subject: CGE2: Increase readability of code connected to music switch. --- engines/cge2/cge2.cpp | 1 - engines/cge2/cge2.h | 1 - engines/cge2/cge2_main.cpp | 36 ++++++++++++++++++++---------------- 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 916b12fef9..55ac835637 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -74,7 +74,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _quitFlag = false; _bitmapPalette = nullptr; _music = true; - _musicMuted = false; _oldMusicVolume = ConfMan.getInt("music_volume");; _startupMode = 1; _now = 1; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 0c5ab4d29c..b7b2dd3b65 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -266,7 +266,6 @@ public: bool _quitFlag; Dac *_bitmapPalette; bool _music; - bool _musicMuted; int _oldMusicVolume; int _startupMode; int _now; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a22df8d896..10e9bb97b5 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -567,16 +567,15 @@ void CGE2Engine::checkMusicSwitch() { bool mute = false; if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); - _musicMuted = mute; + bool musicMuted = mute; int musicVolume = ConfMan.getInt("music_volume"); - if (!_musicMuted) - _musicMuted = musicVolume == 0; - - if (!_musicMuted && !_music) { - _oldMusicVolume = musicVolume; + if (!musicMuted) + musicMuted = musicVolume == 0; + + if (!musicMuted && !_music) { switchMusic(_music = true); } - if (_musicMuted && _music) { + if (musicMuted && _music) { switchMusic(_music = false); } } @@ -1098,8 +1097,21 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) + if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) { switchMusic(_music = !_music); + + switch (_music) { + case false: + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + break; + case true: + ConfMan.setInt("music_volume", _oldMusicVolume); + break; + default: + break; + } + } break; case 3: if (mask & kMouseLeftUp) @@ -1136,14 +1148,6 @@ void CGE2Engine::switchMusic(bool on) { _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); keyClick(); _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); - - if (!on) { - if (!_musicMuted) { - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - } - } else - ConfMan.setInt("music_volume", _oldMusicVolume); } void CGE2Engine::quit() { -- cgit v1.2.3 From cd8b7c0d15ab6dd190a21ed2bc785959a077332d Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 14:47:43 +0200 Subject: CGE2: Move toolbar's functions from cge2_main.cpp to toolbar.cpp. --- engines/cge2/cge2_main.cpp | 183 -------------------------------------- engines/cge2/module.mk | 3 +- engines/cge2/toolbar.cpp | 217 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 184 deletions(-) create mode 100644 engines/cge2/toolbar.cpp (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 10e9bb97b5..ecc741efae 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -26,7 +26,6 @@ */ #include "sound.h" -#include "common/config-manager.h" #include "cge2/cge2_main.h" #include "cge2/cge2.h" #include "cge2/vga13h.h" @@ -34,9 +33,7 @@ #include "cge2/snail.h" #include "cge2/hero.h" #include "cge2/spare.h" -#include "cge2/events.h" #include "cge2/map.h" -#include "cge2/vmenu.h" namespace CGE2 { @@ -563,23 +560,6 @@ void CGE2Engine::checkSounds() { _midiPlayer->syncVolume(); } -void CGE2Engine::checkMusicSwitch() { - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - bool musicMuted = mute; - int musicVolume = ConfMan.getInt("music_volume"); - if (!musicMuted) - musicMuted = musicVolume == 0; - - if (!musicMuted && !_music) { - switchMusic(_music = true); - } - if (musicMuted && _music) { - switchMusic(_music = false); - } -} - void CGE2Engine::handleFrame() { // Game frame delay uint32 millis = g_system->getMillis(); @@ -657,7 +637,6 @@ void CGE2Engine::closePocket() { } } - void CGE2Engine::selectPocket(int n) { Sprite **p = _heroTab[_sex]->_pocket; int &pp = _heroTab[_sex]->_pocPtr; @@ -784,40 +763,6 @@ void CGE2Engine::loadPos() { error("Missing file: CGE.HXY"); } -void CGE2Engine::initToolbar() { - selectPocket(-1); - - _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); - if (!_music) - _midiPlayer->killMidi(); - - _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); // Sets the speech caption switch on. - - _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); - _infoLine->setText(nullptr); - _vga->_showQ->insert(_infoLine); - - _startupMode = 0; - _mouse->center(); - _mouse->off(); - _mouse->on(); - - _keyboard->setClient(_sys); - _commandHandler->addCommand(kCmdSeq, kPowerRef, 1, nullptr); - - _busyPtr = _vga->_showQ->locate(kBusyRef); - - _vol[0] = _vga->_showQ->locate(kDvolRef); - _vol[1] = _vga->_showQ->locate(kMvolRef); - - // these sprites are loaded with SeqPtr==0 (why?!) - if (_vol[0]) - _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); - if (_vol[1]) - _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); - // TODO: Recheck these! ^ -} - void CGE2Engine::releasePocket(Sprite *spr) { for (int i = 0; i < 2; i++) { for (int j = 0; j < kPocketMax; j++) { @@ -831,32 +776,6 @@ void CGE2Engine::releasePocket(Sprite *spr) { } } -void CGE2Engine::checkSaySwitch() { - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - bool speechMute = mute; - if (!speechMute) - speechMute = ConfMan.getBool("speech_mute"); - if (!speechMute) { - int speechVolume = ConfMan.getInt("speech_volume"); - speechMute = speechVolume == 0; - } - - if (mute || speechMute) { - _sayVox = false; - _sayCap = true; - } - - if (_oldSayVox != _sayVox) { - _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); - _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); - keyClick(); - } - - _oldSayVox = _sayVox; -} - void CGE2Engine::loadTab() { setEye(_text->getText(240)); for (int i = 0; i < kSceneMax; i++) @@ -1090,112 +1009,10 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { } } -void CGE2Engine::optionTouch(int opt, uint16 mask) { - switch (opt) { - case 1: - if (mask & kMouseLeftUp) - switchColorMode(); - break; - case 2: - if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) { - switchMusic(_music = !_music); - - switch (_music) { - case false: - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - break; - case true: - ConfMan.setInt("music_volume", _oldMusicVolume); - break; - default: - break; - } - } - break; - case 3: - if (mask & kMouseLeftUp) - quit(); - break; - case 4: - if (mask & (kMouseLeftUp | kMouseRightUp)) - setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); - break; - case 5: - if (mask & (kMouseLeftUp | kMouseRightUp)) - setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); - break; - case 8: - if (mask & kMouseLeftUp) - switchCap(); - break; - case 9: - if (mask & kMouseLeftUp) - switchVox(); - break; - default: - break; - } -} - -void CGE2Engine::switchColorMode() { - _commandHandlerTurbo->addCommand(kCmdSeq, 121, _vga->_mono = !_vga->_mono, nullptr); - keyClick(); - _vga->setColors(_vga->_sysPal, 64); -} - -void CGE2Engine::switchMusic(bool on) { - _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); - keyClick(); - _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); -} - -void CGE2Engine::quit() { - Common::Array quitMenu; // Deleted in VMenu's destructor. - quitMenu.push_back(new StartCountDownChoice(this)); - quitMenu.push_back(new ResetQSwitchChoice(this)); - - if (_commandHandler->idle()) { - if (VMenu::_addr) { - _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, VMenu::_addr); - ResetQSwitchChoice rqsChoice(this); - rqsChoice.proc(); - } else { - quitMenu[0]->_text = _text->getText(kQuitText); - quitMenu[1]->_text = _text->getText(kNoQuitText); - (new VMenu(this, quitMenu, V2D(this, -1, -1), kCBMnu))->setName(_text->getText(kQuitTitle)); - _commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 0, nullptr); - keyClick(); - } - } -} - void CGE2Engine::keyClick() { _commandHandlerTurbo->addCommand(kCmdSound, -1, 5, nullptr); } -void CGE2Engine::setVolume(int idx, int cnt) { - warning("STUB: CGE2Engine::setVolume()"); -} - -void CGE2Engine::switchCap() { - if (_enaCap) { - _sayCap = !_sayCap; - if (!_sayCap) - _sayVox = true; - checkSaySwitch(); - } -} - -void CGE2Engine::switchVox() { - if (_enaVox) { - _sayVox = !_sayVox; - if (!_sayVox) - _sayCap = true; - checkSaySwitch(); - } -} - void CGE2Engine::offUse() { int seq = 0; int offUseCount = atoi(_text->getText(kOffUseCount)); diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index cb2b51e5d3..e3cdf7673c 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -16,7 +16,8 @@ MODULE_OBJS = \ events.o \ map.o \ vmenu.o \ - saveload.o + saveload.o \ + toolbar.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp new file mode 100644 index 0000000000..693d940a21 --- /dev/null +++ b/engines/cge2/toolbar.cpp @@ -0,0 +1,217 @@ +/* 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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "sound.h" +#include "common/config-manager.h" +#include "cge2/cge2.h" +#include "cge2/events.h" +#include "cge2/vmenu.h" +#include "cge2/text.h" +#include "cge2/cge2_main.h" + +namespace CGE2 { + +void CGE2Engine::optionTouch(int opt, uint16 mask) { + switch (opt) { + case 1: + if (mask & kMouseLeftUp) + switchColorMode(); + break; + case 2: + if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) { + switchMusic(_music = !_music); + + switch (_music) { + case false: + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + break; + case true: + ConfMan.setInt("music_volume", _oldMusicVolume); + break; + default: + break; + } + } + break; + case 3: + if (mask & kMouseLeftUp) + quit(); + break; + case 4: + if (mask & (kMouseLeftUp | kMouseRightUp)) + setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); + break; + case 5: + if (mask & (kMouseLeftUp | kMouseRightUp)) + setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); + break; + case 8: + if (mask & kMouseLeftUp) + switchCap(); + break; + case 9: + if (mask & kMouseLeftUp) + switchVox(); + break; + default: + break; + } +} + +void CGE2Engine::switchColorMode() { + _commandHandlerTurbo->addCommand(kCmdSeq, 121, _vga->_mono = !_vga->_mono, nullptr); + keyClick(); + _vga->setColors(_vga->_sysPal, 64); +} + +void CGE2Engine::switchMusic(bool on) { + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); + keyClick(); + _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); +} + +void CGE2Engine::checkMusicSwitch() { + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + bool musicMuted = mute; + int musicVolume = ConfMan.getInt("music_volume"); + if (!musicMuted) + musicMuted = musicVolume == 0; + + if (!musicMuted && !_music) { + switchMusic(_music = true); + } + if (musicMuted && _music) { + switchMusic(_music = false); + } +} + +void CGE2Engine::quit() { + Common::Array quitMenu; // Deleted in VMenu's destructor. + quitMenu.push_back(new StartCountDownChoice(this)); + quitMenu.push_back(new ResetQSwitchChoice(this)); + + if (_commandHandler->idle()) { + if (VMenu::_addr) { + _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, VMenu::_addr); + ResetQSwitchChoice rqsChoice(this); + rqsChoice.proc(); + } else { + quitMenu[0]->_text = _text->getText(kQuitText); + quitMenu[1]->_text = _text->getText(kNoQuitText); + (new VMenu(this, quitMenu, V2D(this, -1, -1), kCBMnu))->setName(_text->getText(kQuitTitle)); + _commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 0, nullptr); + keyClick(); + } + } +} + +void CGE2Engine::setVolume(int idx, int cnt) { + warning("STUB: CGE2Engine::setVolume()"); +} + +void CGE2Engine::switchCap() { + if (_enaCap) { + _sayCap = !_sayCap; + if (!_sayCap) + _sayVox = true; + checkSaySwitch(); + } +} + +void CGE2Engine::switchVox() { + if (_enaVox) { + _sayVox = !_sayVox; + if (!_sayVox) + _sayCap = true; + checkSaySwitch(); + } +} + +void CGE2Engine::checkSaySwitch() { + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + bool speechMute = mute; + if (!speechMute) + speechMute = ConfMan.getBool("speech_mute"); + if (!speechMute) { + int speechVolume = ConfMan.getInt("speech_volume"); + speechMute = speechVolume == 0; + } + + if (speechMute) { + _sayVox = false; + _sayCap = true; + } + + if (_oldSayVox != _sayVox) { + _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); + _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); + keyClick(); + } + + _oldSayVox = _sayVox; +} + +void CGE2Engine::initToolbar() { + selectPocket(-1); + + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); + if (!_music) + _midiPlayer->killMidi(); + + _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); // Sets the speech caption switch on. + + _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); + _infoLine->setText(nullptr); + _vga->_showQ->insert(_infoLine); + + _startupMode = 0; + _mouse->center(); + _mouse->off(); + _mouse->on(); + + _keyboard->setClient(_sys); + _commandHandler->addCommand(kCmdSeq, kPowerRef, 1, nullptr); + + _busyPtr = _vga->_showQ->locate(kBusyRef); + + _vol[0] = _vga->_showQ->locate(kDvolRef); + _vol[1] = _vga->_showQ->locate(kMvolRef); + + // these sprites are loaded with SeqPtr==0 (why?!) + if (_vol[0]) + _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); + if (_vol[1]) + _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); + // TODO: Recheck these! ^ +} + +} // End of namespace CGE2 -- cgit v1.2.3 From a6eb08903351d916d2c243ca031392a5ebd2240a Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 14:56:11 +0200 Subject: CGE2: Move inventory system's functions from cge2_main.cpp to inventory.cpp. --- engines/cge2/cge2_main.cpp | 72 ------------------------------- engines/cge2/inventory.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/module.mk | 3 +- 3 files changed, 107 insertions(+), 73 deletions(-) create mode 100644 engines/cge2/inventory.cpp (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index ecc741efae..24adb0e0ae 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -619,36 +619,6 @@ void CGE2Engine::tick() { _mouse->tick(); } -void CGE2Engine::openPocket() { - for (int i = 0; i < 2; i++) { - for (int j = 0; j < kPocketMax + 1; j++) { - int ref = (int)_heroTab[i]->_downPocketId[j]; - _heroTab[i]->_pocket[j] = (ref == -1) ? nullptr : _vga->_showQ->locate(ref); - } - } -} - -void CGE2Engine::closePocket() { - for (int i = 0; i < 2; i++) { - for (int j = 0; j < kPocketMax + 1; j++) { - Sprite *spr = _heroTab[i]->_pocket[j]; - _heroTab[i]->_downPocketId[j] = (spr) ? spr->_ref : -1; - } - } -} - -void CGE2Engine::selectPocket(int n) { - Sprite **p = _heroTab[_sex]->_pocket; - int &pp = _heroTab[_sex]->_pocPtr; - if (n < 0 || pp == n) { - n = findActivePocket(-1); - if (n >= 0) - pp = n; - } else if (p[n]) { - pp = n; - } -} - void CGE2Engine::busy(bool on) { if (on) { _spriteNotify = _midiNotify = &CGE2::CGE2Engine::busyStep; @@ -763,19 +733,6 @@ void CGE2Engine::loadPos() { error("Missing file: CGE.HXY"); } -void CGE2Engine::releasePocket(Sprite *spr) { - for (int i = 0; i < 2; i++) { - for (int j = 0; j < kPocketMax; j++) { - Sprite *&poc = _heroTab[i]->_pocket[j]; - if (poc == spr) { - spr->_flags._kept = false; - poc = nullptr; - return; - } - } - } -} - void CGE2Engine::loadTab() { setEye(_text->getText(240)); for (int i = 0; i < kSceneMax; i++) @@ -879,35 +836,6 @@ bool CGE2Engine::showTitle(const char *name) { return true; } -int CGE2Engine::freePockets(int sx) { - int n = 0; - for (int i = 0; i < kPocketMax; i++){ - if (_heroTab[sx]->_pocket[i] == nullptr) - ++n; - } - return n; -} - -int CGE2Engine::findActivePocket(int ref) { - for (int i = 0; i < kPocketMax; i++) { - Sprite *spr = _heroTab[_sex]->_pocket[i]; - if (ref >= 0) { - if (spr && spr->_ref == ref) - return i; - } else if (!spr) - return i; - } - return -1; -} - -void CGE2Engine::pocFul() { - Hero *h = _heroTab[_sex]->_ptr; - h->park(); - _commandHandler->addCommand(kCmdWait, -1, -1, h); - _commandHandler->addCommand(kCmdSound, -1, 2, h); - _commandHandler->addCommand(kCmdSay, -1, kPocketFull + _sex, h); -} - void CGE2Engine::killText() { if (!_talk) return; diff --git a/engines/cge2/inventory.cpp b/engines/cge2/inventory.cpp new file mode 100644 index 0000000000..7029a6494c --- /dev/null +++ b/engines/cge2/inventory.cpp @@ -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. + * + */ + +/* + * This code is based on original Sfinx source code + * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge2/cge2.h" +#include "cge2/hero.h" + +namespace CGE2 { + +int CGE2Engine::findActivePocket(int ref) { + for (int i = 0; i < kPocketMax; i++) { + Sprite *spr = _heroTab[_sex]->_pocket[i]; + if (ref >= 0) { + if (spr && spr->_ref == ref) + return i; + } else if (!spr) + return i; + } + return -1; +} + +void CGE2Engine::selectPocket(int n) { + Sprite **p = _heroTab[_sex]->_pocket; + int &pp = _heroTab[_sex]->_pocPtr; + if (n < 0 || pp == n) { + n = findActivePocket(-1); + if (n >= 0) + pp = n; + } else if (p[n]) { + pp = n; + } +} + +void CGE2Engine::pocFul() { + Hero *h = _heroTab[_sex]->_ptr; + h->park(); + _commandHandler->addCommand(kCmdWait, -1, -1, h); + _commandHandler->addCommand(kCmdSound, -1, 2, h); + _commandHandler->addCommand(kCmdSay, -1, kPocketFull + _sex, h); +} + +void CGE2Engine::releasePocket(Sprite *spr) { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax; j++) { + Sprite *&poc = _heroTab[i]->_pocket[j]; + if (poc == spr) { + spr->_flags._kept = false; + poc = nullptr; + return; + } + } + } +} + +int CGE2Engine::freePockets(int sx) { + int n = 0; + for (int i = 0; i < kPocketMax; i++){ + if (_heroTab[sx]->_pocket[i] == nullptr) + ++n; + } + return n; +} + +void CGE2Engine::openPocket() { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax + 1; j++) { + int ref = (int)_heroTab[i]->_downPocketId[j]; + _heroTab[i]->_pocket[j] = (ref == -1) ? nullptr : _vga->_showQ->locate(ref); + } + } +} + +void CGE2Engine::closePocket() { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < kPocketMax + 1; j++) { + Sprite *spr = _heroTab[i]->_pocket[j]; + _heroTab[i]->_downPocketId[j] = (spr) ? spr->_ref : -1; + } + } +} + +} // End of namespace CGE2 diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index e3cdf7673c..256087fd17 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -17,7 +17,8 @@ MODULE_OBJS = \ map.o \ vmenu.o \ saveload.o \ - toolbar.o + toolbar.o \ + inventory.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) -- cgit v1.2.3 From 755fedcceba70267ea41ea5fed5a4e021c05b0e7 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 16:50:36 +0200 Subject: CGE2: Set speech only/text only/both modes according to Launcher options. --- engines/cge2/cge2.cpp | 9 ++++++++- engines/cge2/cge2.h | 2 ++ engines/cge2/saveload.cpp | 2 +- engines/cge2/sound.cpp | 2 +- engines/cge2/toolbar.cpp | 45 +++++++++++++++------------------------------ 5 files changed, 27 insertions(+), 33 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 55ac835637..94b876c724 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -91,6 +91,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _endGame = false; for (int i = 0; i < 4; i++) _flag[i] = false; + _enaVox = true; _sayCap = true; _sayVox = true; _oldSayVox = false; @@ -98,7 +99,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _midiNotify = nullptr; _spriteNotify = nullptr; _enaCap = true; - _enaVox = true; } void CGE2Engine::init() { @@ -177,4 +177,11 @@ Common::Error CGE2Engine::run() { return Common::kNoError; } +void CGE2Engine::syncSoundSettings() { + Engine::syncSoundSettings(); + + _enaCap = _sayCap = ConfMan.getBool("subtitles"); + _enaVox = _sayVox = !ConfMan.getBool("speech_mute"); +} + } // End of namespace CGE2 diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index b7b2dd3b65..62db99a4ab 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -133,6 +133,7 @@ private: void syncHeader(Common::Serializer &s); bool loadGame(int slotNumber); void resetGame(); + void syncSoundSettings(); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); virtual bool hasFeature(EngineFeature f) const; @@ -175,6 +176,7 @@ public: Sprite *locate(int ref); bool isHero(Sprite *spr); void loadUser(); + void switchSay(); void checkSaySwitch(); void loadPos(); void releasePocket(Sprite *spr); diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index b9a856f5f4..6d7bb2492a 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -366,9 +366,9 @@ bool CGE2Engine::loadGame(int slotNumber) { // Get in the savegame syncGame(readStream, nullptr); - delete readStream; + syncSoundSettings(); initToolbar(); loadHeroes(); diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index 7e886e5639..b42ba188b2 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -62,7 +62,7 @@ void Sound::close() { void Sound::open() { setRepeat(1); if (_vm->_commandHandlerTurbo != nullptr) - _vm->checkSaySwitch(); + _vm->switchSay(); play(_vm->_fx->load(99, 99)); } diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 693d940a21..e643632bbe 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -137,47 +137,32 @@ void CGE2Engine::setVolume(int idx, int cnt) { } void CGE2Engine::switchCap() { - if (_enaCap) { + if (_enaCap && _enaVox) { _sayCap = !_sayCap; - if (!_sayCap) + if (!_sayCap && _enaVox) _sayVox = true; - checkSaySwitch(); + keyClick(); + switchSay(); } } void CGE2Engine::switchVox() { - if (_enaVox) { + if (_enaVox && _enaCap) { _sayVox = !_sayVox; - if (!_sayVox) + if (!_sayVox && _enaCap) _sayCap = true; - checkSaySwitch(); + keyClick(); + switchSay(); } } -void CGE2Engine::checkSaySwitch() { - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - bool speechMute = mute; - if (!speechMute) - speechMute = ConfMan.getBool("speech_mute"); - if (!speechMute) { - int speechVolume = ConfMan.getInt("speech_volume"); - speechMute = speechVolume == 0; - } - - if (speechMute) { - _sayVox = false; - _sayCap = true; - } - - if (_oldSayVox != _sayVox) { - _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); - _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); - keyClick(); - } +void CGE2Engine::switchSay() { + _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); + _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); +} - _oldSayVox = _sayVox; +void CGE2Engine::checkSaySwitch() { + warning("STUB: checkSaySwitch()"); } void CGE2Engine::initToolbar() { @@ -187,7 +172,7 @@ void CGE2Engine::initToolbar() { if (!_music) _midiPlayer->killMidi(); - _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); // Sets the speech caption switch on. + switchSay(); _infoLine->gotoxyz(V3D(kInfoX, kInfoY, 0)); _infoLine->setText(nullptr); -- cgit v1.2.3 From 24cc8a8762ded511e8f69ee2790f38b913ddcae9 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 18:11:10 +0200 Subject: CGE2: Implement checkSaySwitch() and add/fix connected code. --- engines/cge2/cge2.cpp | 10 +++++----- engines/cge2/cge2.h | 4 ++-- engines/cge2/saveload.cpp | 2 +- engines/cge2/toolbar.cpp | 31 +++++++++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 94b876c724..5a5e3451aa 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -74,7 +74,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _quitFlag = false; _bitmapPalette = nullptr; _music = true; - _oldMusicVolume = ConfMan.getInt("music_volume");; + _oldMusicVolume = ConfMan.getInt("music_volume"); _startupMode = 1; _now = 1; _sex = 1; @@ -94,7 +94,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _enaVox = true; _sayCap = true; _sayVox = true; - _oldSayVox = false; + _oldSpeechVolume = ConfMan.getInt("speech_volume"); _req = 1; _midiNotify = nullptr; _spriteNotify = nullptr; @@ -167,6 +167,7 @@ bool CGE2Engine::hasFeature(EngineFeature f) const { Common::Error CGE2Engine::run() { syncSoundSettings(); + syncSpeechSettings(); initGraphics(kScrWidth, kScrHeight, false); init(); @@ -177,11 +178,10 @@ Common::Error CGE2Engine::run() { return Common::kNoError; } -void CGE2Engine::syncSoundSettings() { - Engine::syncSoundSettings(); - +void CGE2Engine::syncSpeechSettings() { _enaCap = _sayCap = ConfMan.getBool("subtitles"); _enaVox = _sayVox = !ConfMan.getBool("speech_mute"); } + } // End of namespace CGE2 diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 62db99a4ab..363c7c431c 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -133,7 +133,7 @@ private: void syncHeader(Common::Serializer &s); bool loadGame(int slotNumber); void resetGame(); - void syncSoundSettings(); + void syncSpeechSettings(); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); virtual bool hasFeature(EngineFeature f) const; @@ -285,7 +285,7 @@ public: bool _flag[4]; bool _sayCap; bool _sayVox; - bool _oldSayVox; + int _oldSpeechVolume; int _req; NotifyFunctionType _midiNotify; NotifyFunctionType _spriteNotify; diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 6d7bb2492a..3c57e621f2 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -368,7 +368,7 @@ bool CGE2Engine::loadGame(int slotNumber) { syncGame(readStream, nullptr); delete readStream; - syncSoundSettings(); + syncSpeechSettings(); initToolbar(); loadHeroes(); diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index e643632bbe..3c0ee52606 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -75,8 +75,21 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchCap(); break; case 9: - if (mask & kMouseLeftUp) + if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) { switchVox(); + + switch (_sayVox) { + case false: + _oldSpeechVolume = ConfMan.getInt("speech_volume"); + ConfMan.setInt("speech_volume", 0); + break; + case true: + ConfMan.setInt("speech_volume", _oldSpeechVolume); + break; + default: + break; + } + } break; default: break; @@ -162,7 +175,21 @@ void CGE2Engine::switchSay() { } void CGE2Engine::checkSaySwitch() { - warning("STUB: checkSaySwitch()"); + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + bool speechMuted = mute; + if (!speechMuted) { + int speechVolume = ConfMan.getInt("speech_volume"); + speechMuted = speechVolume == 0; + } + + if (!speechMuted && !_sayVox) { + switchVox(); + } + if (speechMuted && _sayVox) { + switchVox(); + } } void CGE2Engine::initToolbar() { -- cgit v1.2.3 From ff97d52d728a0a47f421dfdfabb40b30f0b1c920 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 18:55:09 +0200 Subject: CGE2: Distinguish SFX from speech when playing sounds. Now the sound options of ScummVM are taken into account when playing these two types of sounds. Until now, everything was considered SFX sound. --- engines/cge2/cge2.h | 3 ++- engines/cge2/snail.cpp | 8 ++++---- engines/cge2/sound.cpp | 40 ++++++++++++++++++++++++++-------------- engines/cge2/sound.h | 7 ++++--- 4 files changed, 36 insertions(+), 22 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 363c7c431c..380e7da04c 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -35,6 +35,7 @@ #include "engines/advancedDetector.h" #include "common/system.h" #include "cge2/fileio.h" +#include "audio/mixer.h" namespace CGE2 { @@ -249,7 +250,7 @@ public: void snCycle(int cnt); void snWalk(Sprite *spr, int val); void snReach(Sprite *spr, int val); - void snSound(Sprite *spr, int wav); + void snSound(Sprite *spr, int wav, Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType); void snRoom(Sprite *spr, bool on); void snDim(Sprite *spr, int val); void snGhost(Bitmap *bmp); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index f6c6e2d71f..aebe1f0778 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -75,7 +75,7 @@ void CommandHandler::runCommand() { if (_vm->_fx->exist(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0])) { int16 oldRepeat = _vm->_sound->getRepeat(); _vm->_sound->setRepeat(1); - _vm->_sound->play(_vm->_fx->load(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0]), _vm->_sound->_smpinf._span); + _vm->_sound->play(Audio::Mixer::kSFXSoundType, _vm->_fx->load(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0]), _vm->_sound->_smpinf._span); _vm->_sound->setRepeat(oldRepeat); return; } @@ -676,7 +676,7 @@ void CGE2Engine::snReach(Sprite *spr, int val) { ((Hero *)spr)->reach(val); } -void CGE2Engine::snSound(Sprite *spr, int wav) { +void CGE2Engine::snSound(Sprite *spr, int wav, Audio::Mixer::SoundType soundType) { if (wav == -1) _sound->stop(); else { @@ -687,7 +687,7 @@ void CGE2Engine::snSound(Sprite *spr, int wav) { _soundStat._ref[1] = wav; _soundStat._ref[0] = !_fx->exist(_soundStat._ref[1]); - _sound->play(_fx->load(_soundStat._ref[1], _soundStat._ref[0]), + _sound->play(soundType, _fx->load(_soundStat._ref[1], _soundStat._ref[0]), (spr) ? (spr->_pos2D.x / (kScrWidth / 16)) : 8); } } @@ -746,7 +746,7 @@ void CGE2Engine::snSay(Sprite *spr, int val) { i -= 100; int16 oldRepeat = _sound->getRepeat(); _sound->setRepeat(1); - snSound(spr, i); + snSound(spr, i, Audio::Mixer::kSpeechSoundType); _sound->setRepeat(oldRepeat); _soundStat._wait = &_sound->_smpinf._counter; } diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index b42ba188b2..27a3af826c 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -26,8 +26,6 @@ */ #include "cge2/sound.h" -//#include "cge/text.h" -//#include "cge/cge_main.h" #include "common/config-manager.h" #include "common/memstream.h" #include "audio/decoders/raw.h" @@ -63,7 +61,7 @@ void Sound::open() { setRepeat(1); if (_vm->_commandHandlerTurbo != nullptr) _vm->switchSay(); - play(_vm->_fx->load(99, 99)); + play(Audio::Mixer::kSFXSoundType, _vm->_fx->load(99, 99)); } void Sound::setRepeat(int16 count) { @@ -74,47 +72,61 @@ int16 Sound::getRepeat() { return _soundRepeatCount; } -void Sound::play(DataCk *wav, int pan) { +void Sound::play(Audio::Mixer::SoundType soundType, DataCk *wav, int pan) { if (wav) { stop(); _smpinf._saddr = &*(wav->addr()); _smpinf._slen = (uint16)wav->size(); _smpinf._span = pan; _smpinf._counter = getRepeat(); - sndDigiStart(&_smpinf); + sndDigiStart(&_smpinf, soundType); } } -void Sound::sndDigiStart(SmpInfo *PSmpInfo) { +void Sound::sndDigiStart(SmpInfo *PSmpInfo, Audio::Mixer::SoundType soundType) { // Create an audio stream wrapper for sound Common::MemoryReadStream *stream = new Common::MemoryReadStream(PSmpInfo->_saddr, PSmpInfo->_slen, DisposeAfterUse::NO); _audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); + // Decide which handle to use + Audio::SoundHandle *handle = nullptr; + switch (soundType) { + case Audio::Mixer::kSFXSoundType: + handle = &_soundHandle; + break; + case Audio::Mixer::kSpeechSoundType: + handle = &_speechHandle; + break; + default: + break; + } + // Start the new sound - _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, + _vm->_mixer->playStream(soundType, handle, Audio::makeLoopingAudioStream(_audioStream, (uint)PSmpInfo->_counter)); // CGE pan: // 8 = Center // Less = Left // More = Right - _vm->_mixer->setChannelBalance(_soundHandle, (int8)CLIP(((PSmpInfo->_span - 8) * 16), -127, 127)); + _vm->_mixer->setChannelBalance(*handle, (int8)CLIP(((PSmpInfo->_span - 8) * 16), -127, 127)); } void Sound::stop() { - sndDigiStop(&_smpinf); + sndDigiStop(_soundHandle); + sndDigiStop(_speechHandle); + _audioStream = nullptr; } void Sound::checkSoundHandle() { - if (!_vm->_mixer->isSoundHandleActive(_soundHandle)) + if (!_vm->_mixer->isSoundHandleActive(_speechHandle)) _smpinf._counter = 0; } -void Sound::sndDigiStop(SmpInfo *PSmpInfo) { - if (_vm->_mixer->isSoundHandleActive(_soundHandle)) - _vm->_mixer->stopHandle(_soundHandle); - _audioStream = nullptr; +void Sound::sndDigiStop(Audio::SoundHandle &handle) { + if (_vm->_mixer->isSoundHandleActive(handle)) + _vm->_mixer->stopHandle(handle); } Fx::Fx(CGE2Engine *vm, int size) : _current(nullptr), _vm(vm) { diff --git a/engines/cge2/sound.h b/engines/cge2/sound.h index e2e9482799..7dd549ca16 100644 --- a/engines/cge2/sound.h +++ b/engines/cge2/sound.h @@ -72,7 +72,7 @@ public: ~Sound(); void open(); void close(); - void play(DataCk *wav, int pan = 8); + void play(Audio::Mixer::SoundType soundType, DataCk *wav, int pan = 8); int16 getRepeat(); void setRepeat(int16 count); void stop(); @@ -81,10 +81,11 @@ private: int _soundRepeatCount; CGE2Engine *_vm; Audio::SoundHandle _soundHandle; + Audio::SoundHandle _speechHandle; Audio::RewindableAudioStream *_audioStream; - void sndDigiStart(SmpInfo *PSmpInfo); - void sndDigiStop(SmpInfo *PSmpInfo); + void sndDigiStart(SmpInfo *PSmpInfo, Audio::Mixer::SoundType soundType); + void sndDigiStop(Audio::SoundHandle &handle); }; class Fx { -- cgit v1.2.3 From 6743b8b6a3199cc75518e2c05625b76db361484f Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 18:55:41 +0200 Subject: CGE2: Remove redundant default labels. --- engines/cge2/toolbar.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 3c0ee52606..23c6fd17c0 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -53,8 +53,6 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { case true: ConfMan.setInt("music_volume", _oldMusicVolume); break; - default: - break; } } break; @@ -86,8 +84,6 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { case true: ConfMan.setInt("speech_volume", _oldSpeechVolume); break; - default: - break; } } break; -- cgit v1.2.3 From 7c65aa7aecef35e77c0f39c0e2c2a864858e6b9d Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 19:44:09 +0200 Subject: CGE2: Repair/rename checkSoundHandle(). --- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/sound.cpp | 4 ++-- engines/cge2/sound.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 24adb0e0ae..e4b34a001c 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -554,7 +554,7 @@ void CGE2Engine::mainLoop() { } void CGE2Engine::checkSounds() { - _sound->checkSoundHandle(); + _sound->checkSoundHandles(); checkSaySwitch(); checkMusicSwitch(); _midiPlayer->syncVolume(); diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index 27a3af826c..cc148d6090 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -119,8 +119,8 @@ void Sound::stop() { _audioStream = nullptr; } -void Sound::checkSoundHandle() { - if (!_vm->_mixer->isSoundHandleActive(_speechHandle)) +void Sound::checkSoundHandles() { + if (!_vm->_mixer->isSoundHandleActive(_speechHandle) && !_vm->_mixer->isSoundHandleActive(_soundHandle)) _smpinf._counter = 0; } diff --git a/engines/cge2/sound.h b/engines/cge2/sound.h index 7dd549ca16..b97cd11bd0 100644 --- a/engines/cge2/sound.h +++ b/engines/cge2/sound.h @@ -76,7 +76,7 @@ public: int16 getRepeat(); void setRepeat(int16 count); void stop(); - void checkSoundHandle(); + void checkSoundHandles(); private: int _soundRepeatCount; CGE2Engine *_vm; -- cgit v1.2.3 From 15a225697201482e93253a0d77e03a7d255c6c18 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 22:19:11 +0200 Subject: CGE2: Implement snTrans() and snPort(). --- engines/cge2/cge2.h | 4 ++-- engines/cge2/snail.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 380e7da04c..336d727787 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -232,8 +232,8 @@ public: void snGoto(Sprite *spr, int val); void snMove(Sprite *spr, V3D pos); void snSlave(Sprite *spr, int val); - void snTrans(Sprite *spr, int val); - void snPort(Sprite *spr, int val); + void snTrans(Sprite *spr, int trans); + void snPort(Sprite *spr, int port); void snMouse(bool on); void snNNext(Sprite *spr, Action act, int val); void snRNNext(Sprite *spr, int val); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index aebe1f0778..4ba8348817 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -579,12 +579,16 @@ void CGE2Engine::snSlave(Sprite *spr, int val) { warning("STUB: CGE2Engine::snSlave()"); } -void CGE2Engine::snTrans(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snTrans()"); +void CGE2Engine::snTrans(Sprite *spr, int trans) { + if (spr) { + spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); + } } -void CGE2Engine::snPort(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snPort()"); +void CGE2Engine::snPort(Sprite *spr, int port) { + if (spr) { + spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); + } } void CGE2Engine::snMouse(bool on) { -- cgit v1.2.3 From c84389813221559510a00f2aa1ad492051a5fa44 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 22:57:26 +0200 Subject: CGE2: Remove handling of unused opcodes. --- engines/cge2/cge2.h | 9 ----- engines/cge2/snail.cpp | 107 +------------------------------------------------ 2 files changed, 2 insertions(+), 114 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 336d727787..0c5492f6ca 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -218,21 +218,15 @@ public: void snKill(Sprite *spr); void snHide(Sprite *spr, int val); void snMidi(int val); - void snSetDlg(int clr, int set); - void snMskDlg(int clr, int set); void snSeq(Sprite *spr, int val); void snRSeq(Sprite *spr, int val); void snSend(Sprite *spr, int val); void snSwap(Sprite *spr, int val); void snCover(Sprite *spr, int val); void snUncover(Sprite *spr, Sprite *spr2); - void snFocus(int val); void snKeep(Sprite *spr, int val); void snGive(Sprite *spr, int val); void snGoto(Sprite *spr, int val); - void snMove(Sprite *spr, V3D pos); - void snSlave(Sprite *spr, int val); - void snTrans(Sprite *spr, int trans); void snPort(Sprite *spr, int port); void snMouse(bool on); void snNNext(Sprite *spr, Action act, int val); @@ -242,11 +236,8 @@ public: void snRmNear(Sprite *spr); void snRmMTake(Sprite *spr); void snRmFTake(Sprite *spr); - void snFlag(int ref, int val); void snSetRef(Sprite *spr, int val); - void snBackPt(Sprite *spr, int val); void snFlash(int val); - void snLight(int val); void snCycle(int cnt); void snWalk(Sprite *spr, int val); void snReach(Sprite *spr, int val); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 4ba8348817..1bc821d9b8 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -139,21 +139,12 @@ void CommandHandler::runCommand() { if (_talkEnable) _vm->inf(((tailCmd._val) >= 0) ? _vm->_text->getText(tailCmd._val) : (const char *)tailCmd._spritePtr); break; - case kCmdTime: - warning("STUB: CommandHandler::runCommand() - Something missing connected to kCmdTime!"); - break; case kCmdCave: _vm->switchScene(tailCmd._val); break; case kCmdMidi: _vm->snMidi(tailCmd._val); break; - case kCmdSetDlg: - _vm->snSetDlg(tailCmd._ref, tailCmd._val); - break; - case kCmdMskDlg: - _vm->snMskDlg(tailCmd._ref, tailCmd._val); - break; case kCmdKill: _vm->snKill(spr); break; @@ -175,9 +166,6 @@ void CommandHandler::runCommand() { case kCmdUncover: _vm->snUncover(spr, (tailCmd._val >= 0) ? _vm->locate(tailCmd._val) : ((Sprite *)tailCmd._spritePtr)); break; - case kCmdFocus: - _vm->snFocus(tailCmd._val); - break; case kCmdKeep: _vm->snKeep(spr, tailCmd._val); break; @@ -196,15 +184,6 @@ void CommandHandler::runCommand() { case kCmdAdd: *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) + *(_vm->_point[tailCmd._val]); break; - case kCmdSub: - *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) - *(_vm->_point[tailCmd._val]); - break; - case kCmdMul: - *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) * tailCmd._val; - break; - case kCmdDiv: - *(_vm->_point[tailCmd._ref]) = *(_vm->_point[tailCmd._ref]) / tailCmd._val; - break; case kCmdGetPos: if (spr) *(_vm->_point[tailCmd._val]) = spr->_pos3D; @@ -212,30 +191,11 @@ void CommandHandler::runCommand() { case kCmdGoto: _vm->snGoto(spr, tailCmd._val); break; - case kCmdMoveX: - _vm->snMove(spr, V3D(tailCmd._val, 0, 0)); - break; - case kCmdMoveY: - _vm->snMove(spr, V3D(0, tailCmd._val, 0)); - break; - case kCmdMoveZ: - _vm->snMove(spr, V3D(0, 0, tailCmd._val)); - break; - case kCmdSlave: - _vm->snSlave(spr, tailCmd._val); - break; - case kCmdTrans: - _vm->snTrans(spr, tailCmd._val); - break; case kCmdPort: _vm->snPort(spr, tailCmd._val); break; case kCmdNext: break; - case kCmdIf: - break; - case kCmdTalk: - break; case kCmdMouse: _vm->snMouse(tailCmd._val != 0); break; @@ -266,21 +226,12 @@ void CommandHandler::runCommand() { case kCmdRMFTake: _vm->snRmFTake(spr); break; - case kCmdFlag: - _vm->snFlag(tailCmd._ref & 3, tailCmd._val); - break; case kCmdSetRef: _vm->snSetRef(spr, tailCmd._val); break; - case kCmdBackPt: - _vm->snBackPt(spr, tailCmd._val); - break; case kCmdFlash: _vm->snFlash(tailCmd._val != 0); break; - case kCmdLight: - _vm->snLight(tailCmd._val != 0); - break; case kCmdCycle: _vm->snCycle(tailCmd._val); break; @@ -297,9 +248,6 @@ void CommandHandler::runCommand() { case kCmdMap: _vm->_heroTab[tailCmd._ref & 1]->_ptr->_ignoreMap = tailCmd._val == 0; break; - case kCmdCount: - _vm->_sound->setRepeat(tailCmd._val); - break; case kCmdRoom: _vm->snRoom(spr, tailCmd._val); break; @@ -378,14 +326,6 @@ void CGE2Engine::snMidi(int val) { _midiPlayer->loadMidi(val); } -void CGE2Engine::snSetDlg(int clr, int set) { - warning("STUB: CGE2Engine::snSetDlg()"); -} - -void CGE2Engine::snMskDlg(int clr, int set) { - warning("STUB: CGE2Engine::snMskDlg()"); -} - void CGE2Engine::snSeq(Sprite *spr, int val) { if (spr) { if (isHero(spr) && val == 0) @@ -506,10 +446,6 @@ void CGE2Engine::snUncover(Sprite *spr, Sprite *spr2) { } } -void CGE2Engine::snFocus(int val) { - warning("STUB: CGE2Engine::snFocus()"); -} - void CGE2Engine::snKeep(Sprite *spr, int stp) { int sex = _sex; if (stp > 127) { @@ -571,20 +507,6 @@ void CGE2Engine::snGoto(Sprite *spr, int val) { } } -void CGE2Engine::snMove(Sprite *spr, V3D pos) { - warning("STUB: CGE2Engine::snMove()"); -} - -void CGE2Engine::snSlave(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snSlave()"); -} - -void CGE2Engine::snTrans(Sprite *spr, int trans) { - if (spr) { - spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); - } -} - void CGE2Engine::snPort(Sprite *spr, int port) { if (spr) { spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); @@ -636,28 +558,16 @@ void CGE2Engine::snRmFTake(Sprite *spr) { spr->_actionCtrl[kFTake]._cnt = 0; } -void CGE2Engine::snFlag(int ref, int val) { - warning("STUB: CGE2Engine::snFlag()"); -} - void CGE2Engine::snSetRef(Sprite *spr, int val) { if (spr) { spr->_ref = val; } } -void CGE2Engine::snBackPt(Sprite *spr, int val) { - warning("STUB: CGE2Engine::snBackPt()"); -} - void CGE2Engine::snFlash(int val) { warning("STUB: CGE2Engine::snFlash()"); } -void CGE2Engine::snLight(int val) { - warning("STUB: CGE2Engine::snLight()"); -} - void CGE2Engine::snCycle(int cnt) { warning("STUB: CGE2Engine::snCycle()"); } @@ -904,10 +814,6 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { } while (c < q) { - if (c->_commandType == kCmdTalk) { - if ((_commandHandler->_talkEnable = (c->_val != 0)) == false) - killText(); - } if (c->_commandType == kCmdWalk || c->_commandType == kCmdReach) { if (c->_val == -1) c->_val = spr->_ref; @@ -953,17 +859,8 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { if (s == spr) break; } - if (c->_commandType == kCmdIf) { - Sprite *s = (c->_ref < 0) ? spr : _vga->_showQ->locate(c->_ref); - if (s) { // sprite exists - if (!s->seqTest(-1)) { // not parked - int v = c->_val; - if (v > 255) if (s) v = s->labVal(snq, v >> 8); - c = comtab + (v - 1); - } - } - } else - _commandHandler->addCommand(c->_commandType, c->_ref, c->_val, spr); + + _commandHandler->addCommand(c->_commandType, c->_ref, c->_val, spr); ++c; } -- cgit v1.2.3 From 12210ecf27eea137e2ac9f58312d7143a0a015cb Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 23:06:11 +0200 Subject: CGE2: Remove the unused opcodes. --- engines/cge2/snail.cpp | 12 +++++------- engines/cge2/snail.h | 13 +------------ 2 files changed, 6 insertions(+), 19 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 1bc821d9b8..5e889b2e61 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -36,23 +36,21 @@ namespace CGE2 { const char *CommandHandler::_commandText[] = { "NOP", "USE", "PAUSE", "INF", "CAVE", - "SLAVE", "FOCUS", "SETX", "SETY", "SETZ", - "ADD", "SUB", "MUL", "DIV", "IF", "FLAG", - "FLASH", "LIGHT", "CYCLE", + "SETX", "SETY", "SETZ", + "ADD", "SUB", "MUL", "DIV", "IF", + "FLASH", "CYCLE", "CLEAR", "TALK", "MOUSE", "MAP", "COUNT", "MIDI", - "SETDLG", "MSKDLG", ".DUMMY.", "WAIT", "HIDE", "ROOM", "SAY", "SOUND", "TIME", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", "GIVE", - "GETPOS", "GOTO", "MOVEX", "MOVEY", - "MOVEZ", "TRANS", "PORT", + "GETPOS", "GOTO", "PORT", "NEXT", "NNEXT", "MTNEXT", "FTNEXT", "RNNEXT", "RMTNEXT", "RFTNEXT", "RMNEAR", "RMMTAKE", "RMFTAKE", - "SETREF", "BACKPT", + "SETREF", "WALKTO", "REACH", "COVER", "UNCOVER", nullptr }; diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 6b0bdea546..a83926a3de 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -44,8 +44,6 @@ enum CommandType { kCmdPause, // PAUSE -1 :: delay /72 seconds kCmdInf, // INF -1 :: show text referrenced by kCmdCave, // CAVE -1 :: go to board - kCmdSlave, // SLAVE - kCmdFocus, // FOCUS :: change active hero kCmdSetX, // SETX :: set sprite shift in x axis kCmdSetY, // SETX :: set sprite shift in y axis kCmdSetZ, // SETX :: set sprite shift in z axis @@ -54,9 +52,7 @@ enum CommandType { kCmdMul, // MUL :: multiply vector by number kCmdDiv, // DIV :: divide vector by number kCmdIf, // IF - kCmdFlag, // FLAG :: set flag to kCmdFlash, // FLASH -1 0|1 :: lighten whole image (on/off) - kCmdLight, // LIGHT kCmdCycle, // CYCLE :: rotate colors from 1 kCmdClear, // CLEAR -1 0 :: clear kCmdAIL queue kCmdTalk, // TALK -1 0|1 :: enable speach (on/off) @@ -64,8 +60,6 @@ enum CommandType { kCmdMap, // MAP 0|1 0 :: temporarily turn off map for hero kCmdCount, // COUNT kCmdMidi, // MIDI -1 :: play MIDI referenced by (-1 = off) - kCmdSetDlg, // SETDLG 0..3 0..3 :: switch of speach mode - kCmdMskDlg, // MSKDLG 0..3 0..3 :: switch of speach mode mask kCmdSpr, @@ -84,10 +78,6 @@ enum CommandType { kCmdGive, // GIVE :: remove sprite from pocket and jump to kCmdGetPos, // GETPOS :: take sprite's position kCmdGoto, // GOTO :: move sprite to position - kCmdMoveX, // MOVEX :: relative move along X axis - kCmdMoveY, // MOVEY :: relative move along Y axis - kCmdMoveZ, // MOVEZ :: relative move along Z axis - kCmdTrans, // TRANS 0|1 :: clear/set logical transparency kCmdPort, // PORT 0|1 :: clear/set "takeability" of sprite kCmdNext, // NEXT :: jump to - NEAR or TAKE kCmdNNext, // NNEXT :: jump to - NEAR @@ -99,8 +89,7 @@ enum CommandType { kCmdRMNear, // RMNEAR 0 :: remove NEAR list kCmdRMMTake, // RMMTAKE 0 :: remove TAKE list kCmdRMFTake, // RMFTAKE 0 :: remove TAKE list - kCmdSetRef, // RETREF :: change reference of sprite to - kCmdBackPt, // BACKPT 0 :: paint sprite onto the background + kCmdSetRef, // RETREF :: change reference of sprite to kCmdWalk, // WALK | :: go close to the sprite or point kCmdReach, // REACH | :: reach the sprite or point with method kCmdCover, // COVER :: cover sprite with sprite -- cgit v1.2.3 From 6caee925df370a4d0b19c5ce37cbd52a91464d25 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 23:07:11 +0200 Subject: CGE2: Fix typo in SETREF's comment. --- engines/cge2/snail.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index a83926a3de..48b65cb171 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -89,7 +89,7 @@ enum CommandType { kCmdRMNear, // RMNEAR 0 :: remove NEAR list kCmdRMMTake, // RMMTAKE 0 :: remove TAKE list kCmdRMFTake, // RMFTAKE 0 :: remove TAKE list - kCmdSetRef, // RETREF :: change reference of sprite to + kCmdSetRef, // SETREF :: change reference of sprite to kCmdWalk, // WALK | :: go close to the sprite or point kCmdReach, // REACH | :: reach the sprite or point with method kCmdCover, // COVER :: cover sprite with sprite -- cgit v1.2.3 From 42f044012720563fed5e0899097548999d5537a4 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 23:13:25 +0200 Subject: CGE2: Remove more unused opcodes. --- engines/cge2/snail.cpp | 8 ++++---- engines/cge2/snail.h | 7 ------- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 5e889b2e61..e2f04cce74 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -37,13 +37,13 @@ namespace CGE2 { const char *CommandHandler::_commandText[] = { "NOP", "USE", "PAUSE", "INF", "CAVE", "SETX", "SETY", "SETZ", - "ADD", "SUB", "MUL", "DIV", "IF", + "ADD", "FLASH", "CYCLE", - "CLEAR", "TALK", "MOUSE", - "MAP", "COUNT", "MIDI", + "CLEAR", "MOUSE", + "MAP", "MIDI", ".DUMMY.", "WAIT", "HIDE", "ROOM", - "SAY", "SOUND", "TIME", "KILL", + "SAY", "SOUND", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", "GIVE", "GETPOS", "GOTO", "PORT", diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 48b65cb171..afe359b968 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -48,17 +48,11 @@ enum CommandType { kCmdSetY, // SETX :: set sprite shift in y axis kCmdSetZ, // SETX :: set sprite shift in z axis kCmdAdd, // ADD :: sum vectors - kCmdSub, // SUB :: subtract vectors - kCmdMul, // MUL :: multiply vector by number - kCmdDiv, // DIV :: divide vector by number - kCmdIf, // IF kCmdFlash, // FLASH -1 0|1 :: lighten whole image (on/off) kCmdCycle, // CYCLE :: rotate colors from 1 kCmdClear, // CLEAR -1 0 :: clear kCmdAIL queue - kCmdTalk, // TALK -1 0|1 :: enable speach (on/off) kCmdMouse, // MOUSE -1 0|1 :: enable mouse (on/off) kCmdMap, // MAP 0|1 0 :: temporarily turn off map for hero - kCmdCount, // COUNT kCmdMidi, // MIDI -1 :: play MIDI referenced by (-1 = off) kCmdSpr, @@ -68,7 +62,6 @@ enum CommandType { kCmdRoom, // ROOM 0|1 :: additional room in pocket (no/yes) kCmdSay, // SAY :: say text referenced by kCmdSound, // SOUND :: play sound effect referenced by - kCmdTime, // TIME 0 :: say current time kCmdKill, // KILL 0 :: remove sprite kCmdRSeq, // RSEQ :: relative jump SEQ lines kCmdSeq, // SEQ :: jump to certain SEQ -- cgit v1.2.3 From b85e5dcfdb482b3bfa6a513537e88ccd1eb695fe Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 23:19:02 +0200 Subject: CGE2: Remove kCmdDim and kCmdStep and connected code. --- engines/cge2/cge2.h | 1 - engines/cge2/snail.cpp | 15 --------------- engines/cge2/snail.h | 2 -- 3 files changed, 18 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 0c5492f6ca..8d3f052b63 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -243,7 +243,6 @@ public: void snReach(Sprite *spr, int val); void snSound(Sprite *spr, int wav, Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType); void snRoom(Sprite *spr, bool on); - void snDim(Sprite *spr, int val); void snGhost(Bitmap *bmp); void snSay(Sprite *spr, int val); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index e2f04cce74..510dc2d514 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -249,9 +249,6 @@ void CommandHandler::runCommand() { case kCmdRoom: _vm->snRoom(spr, tailCmd._val); break; - case kCmdDim: - _vm->snDim(spr, tailCmd._val); - break; case kCmdExec: switch (tailCmd._cbType) { case kQGame: @@ -268,9 +265,6 @@ void CommandHandler::runCommand() { break; } break; - case kCmdStep: - spr->step(); - break; case kCmdGhost: _vm->snGhost((Bitmap *)tailCmd._spritePtr); break; @@ -626,15 +620,6 @@ void CGE2Engine::snRoom(Sprite *spr, bool on) { } } -void CGE2Engine::snDim(Sprite *spr, int val) { - if (isHero(spr)) { - if (val > 0) - ++*(Hero*)spr; - else if (val < 0) - --*(Hero*)spr; - } -} - void CGE2Engine::snGhost(Bitmap *bmp) { V2D p(this, bmp->_map & 0xFFFF, bmp->_map >> 16); bmp->hide(p); diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index afe359b968..66e35dc06e 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -88,9 +88,7 @@ enum CommandType { kCmdCover, // COVER :: cover sprite with sprite kCmdUncover, // UNCOVER :: restore the state before COVER - kCmdDim, kCmdExec, - kCmdStep, kCmdGhost, kCmdNOne = kNoByte -- cgit v1.2.3 From 8a1d0461878b3a38c385d9c6c4c294ee88eb3472 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 23:22:46 +0200 Subject: CGE2: Fix kCmdWalk's comment. --- engines/cge2/snail.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 66e35dc06e..ed6aae79d8 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -83,7 +83,7 @@ enum CommandType { kCmdRMMTake, // RMMTAKE 0 :: remove TAKE list kCmdRMFTake, // RMFTAKE 0 :: remove TAKE list kCmdSetRef, // SETREF :: change reference of sprite to - kCmdWalk, // WALK | :: go close to the sprite or point + kCmdWalk, // WALKTO | :: go close to the sprite or point kCmdReach, // REACH | :: reach the sprite or point with method kCmdCover, // COVER :: cover sprite with sprite kCmdUncover, // UNCOVER :: restore the state before COVER -- cgit v1.2.3 From 737fc953a4a34b4d8cf020ba865dc4db18baef98 Mon Sep 17 00:00:00 2001 From: uruk Date: Thu, 24 Jul 2014 23:25:09 +0200 Subject: CGE2: Rearrange _commandText[]'s content. --- engines/cge2/snail.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 510dc2d514..8a1340f5dc 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -35,23 +35,12 @@ namespace CGE2 { const char *CommandHandler::_commandText[] = { - "NOP", "USE", "PAUSE", "INF", "CAVE", - "SETX", "SETY", "SETZ", - "ADD", - "FLASH", "CYCLE", - "CLEAR", "MOUSE", - "MAP", "MIDI", - ".DUMMY.", - "WAIT", "HIDE", "ROOM", - "SAY", "SOUND", "KILL", - "RSEQ", "SEQ", "SEND", "SWAP", - "KEEP", "GIVE", - "GETPOS", "GOTO", "PORT", - "NEXT", "NNEXT", "MTNEXT", "FTNEXT", - "RNNEXT", "RMTNEXT", "RFTNEXT", - "RMNEAR", "RMMTAKE", "RMFTAKE", - "SETREF", - "WALKTO", "REACH", "COVER", "UNCOVER", + "NOP", "USE", "PAUSE", "INF", "CAVE", "SETX", "SETY", "SETZ", "ADD", + "FLASH", "CYCLE", "CLEAR", "MOUSE", "MAP", "MIDI", ".DUMMY.", "WAIT", + "HIDE", "ROOM", "SAY", "SOUND", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", + "KEEP", "GIVE", "GETPOS", "GOTO", "PORT", "NEXT", "NNEXT", "MTNEXT", + "FTNEXT", "RNNEXT", "RMTNEXT", "RFTNEXT", "RMNEAR", "RMMTAKE", "RMFTAKE", + "SETREF", "WALKTO", "REACH", "COVER", "UNCOVER", nullptr }; CommandHandler::CommandHandler(CGE2Engine *vm, bool turbo) -- cgit v1.2.3 From d83a8162bb4e2795e158c48679b9f4db5cf6cc41 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 25 Jul 2014 10:55:53 +0200 Subject: CGE2: Remove unused constant in Talk, fix a warning --- engines/cge2/talk.cpp | 2 +- engines/cge2/talk.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index b086627f80..2e7f87dcca 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -53,7 +53,7 @@ void Font::load() { char path[10]; strcpy(path, "CGE.CFT"); if (!_vm->_resman->exist(path)) - error("Missing configuration file! %s", path); + error("Missing Font file! %s", path); EncryptedStream fontFile(_vm, path); assert(!fontFile.err()); diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index cddcdc2c5e..ec4a347c69 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -41,7 +41,6 @@ namespace CGE2 { #define kPosSize 256 #define kMapSize (256*8) #define kFontHigh 8 -#define kFontExt ".CFT" #define kCaptionSide 24 #define kInfName 101 #define kSayName 102 -- cgit v1.2.3 From 72c8dbaf669c850ad4d4d91a7a1befaa48d7f56d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 25 Jul 2014 10:58:54 +0200 Subject: CGE2: Update another warning --- engines/cge2/talk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 2e7f87dcca..8e5773c677 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -70,7 +70,7 @@ void Font::load() { strcpy(path, "CGE.TXC"); if (!_vm->_resman->exist(path)) - error("Missing configuration file! %s", path); + error("Missing Color file! %s", path); // Reading in _colorSet: EncryptedStream colorFile(_vm, path); -- cgit v1.2.3 From 3c0665edfa5fcbb1557aba3bc13c512f48f86dc6 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 19:19:52 +0200 Subject: CGE2: Rework loadUser(). Now initToolbar() works as intended both when starting a new game or when loading an old gamestate. --- engines/cge2/cge2_main.cpp | 10 +++++----- engines/cge2/saveload.cpp | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e4b34a001c..87ab2dea8f 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -643,9 +643,8 @@ void CGE2Engine::runGame() { loadUser(); - initToolbar(); - sceneUp(_now); + initToolbar(); // main loop while (!_endGame && !_quitFlag) { @@ -666,12 +665,13 @@ void CGE2Engine::runGame() { void CGE2Engine::loadUser() { loadPos(); + if (_startGameSlot != -1) loadGame(_startGameSlot); - else { + else loadScript("CGE.INI"); - loadHeroes(); - } + + loadHeroes(); } void CGE2Engine::loadHeroes() { // Original name: loadGame() diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 3c57e621f2..5e60f07bcd 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -369,9 +369,7 @@ bool CGE2Engine::loadGame(int slotNumber) { delete readStream; syncSpeechSettings(); - initToolbar(); - loadHeroes(); - + return true; } -- cgit v1.2.3 From aaf1f6a1a084ef1d5d40a4e8794014a62795b7db Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 20:24:10 +0200 Subject: CGE2: Fix initialization of sound switches on the toolbar. --- engines/cge2/cge2.cpp | 9 +++++++-- engines/cge2/cge2.h | 6 ++++++ engines/cge2/toolbar.cpp | 5 ++--- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 5a5e3451aa..d28215bc93 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -74,7 +74,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _quitFlag = false; _bitmapPalette = nullptr; _music = true; - _oldMusicVolume = ConfMan.getInt("music_volume"); _startupMode = 1; _now = 1; _sex = 1; @@ -94,11 +93,17 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _enaVox = true; _sayCap = true; _sayVox = true; - _oldSpeechVolume = ConfMan.getInt("speech_volume"); _req = 1; _midiNotify = nullptr; _spriteNotify = nullptr; _enaCap = true; + if (ConfMan.getBool("mute")) { + _oldSpeechVolume = _oldMusicVolume = _musicVolume = _sfxVolume = 0; + } else { + _oldSpeechVolume = ConfMan.getInt("speech_volume"); + _oldMusicVolume = _musicVolume = ConfMan.getInt("music_volume"); + _sfxVolume = ConfMan.getInt("sfx_volume"); + } } void CGE2Engine::init() { diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 8d3f052b63..e6c1308238 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -113,6 +113,10 @@ struct SavegameHeader; #define kSavegameStrSize 12 #define kSavegameStr "SCUMMVM_CGE2" +#define kSoundSwtichRate 25.7 +// == 257 / 10; where 10 equals to the sound switches' number of states +// and ScummVM has a scale of 257 different values for setting sounds. + enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume }; @@ -283,6 +287,8 @@ public: int _startGameSlot; bool _enaCap; bool _enaVox; + int _musicVolume; + int _sfxVolume; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 23c6fd17c0..08a21da753 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -214,11 +214,10 @@ void CGE2Engine::initToolbar() { _vol[0] = _vga->_showQ->locate(kDvolRef); _vol[1] = _vga->_showQ->locate(kMvolRef); - // these sprites are loaded with SeqPtr==0 (why?!) if (_vol[0]) - _vol[0]->step((/*(int)SNDDrvInfo.VOL4.DL * */ _vol[0]->_seqCnt + _vol[0]->_seqCnt / 2) >> 4); + _vol[0]->step(_sfxVolume / kSoundSwtichRate); if (_vol[1]) - _vol[1]->step((/*(int)SNDDrvInfo.VOL4.ML * */ _vol[1]->_seqCnt + _vol[1]->_seqCnt / 2) >> 4); + _vol[1]->step(_musicVolume / kSoundSwtichRate); // TODO: Recheck these! ^ } -- cgit v1.2.3 From 22f1207cffa251a77748a0fe531ddb6ec000b332 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 20:27:05 +0200 Subject: CGE2: Rename kSoundSwtichRate to kVolumeSwitchRate. --- engines/cge2/cge2.h | 4 ++-- engines/cge2/toolbar.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index e6c1308238..c23a101de8 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -113,8 +113,8 @@ struct SavegameHeader; #define kSavegameStrSize 12 #define kSavegameStr "SCUMMVM_CGE2" -#define kSoundSwtichRate 25.7 -// == 257 / 10; where 10 equals to the sound switches' number of states +#define kVolumeSwitchRate 25.7 +// == 257 / 10; where 10 equals to the volume switches' number of states // and ScummVM has a scale of 257 different values for setting sounds. enum CallbackType { diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 08a21da753..eafdaf4ce3 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -215,9 +215,9 @@ void CGE2Engine::initToolbar() { _vol[1] = _vga->_showQ->locate(kMvolRef); if (_vol[0]) - _vol[0]->step(_sfxVolume / kSoundSwtichRate); + _vol[0]->step(_sfxVolume / kVolumeSwtichRate); if (_vol[1]) - _vol[1]->step(_musicVolume / kSoundSwtichRate); + _vol[1]->step(_musicVolume / kVolumeSwtichRate); // TODO: Recheck these! ^ } -- cgit v1.2.3 From 98c6bfa0f573861517466fe06220a3730d314f40 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 20:29:42 +0200 Subject: CGE2: Fix broken compilation by previous commit. --- engines/cge2/toolbar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index eafdaf4ce3..01943e2e45 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -215,9 +215,9 @@ void CGE2Engine::initToolbar() { _vol[1] = _vga->_showQ->locate(kMvolRef); if (_vol[0]) - _vol[0]->step(_sfxVolume / kVolumeSwtichRate); + _vol[0]->step(_sfxVolume / kVolumeSwitchRate); if (_vol[1]) - _vol[1]->step(_musicVolume / kVolumeSwtichRate); + _vol[1]->step(_musicVolume / kVolumeSwitchRate); // TODO: Recheck these! ^ } -- cgit v1.2.3 From 9524f1d128df9588d0934ab3afa64f22d0df4fd0 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 20:30:12 +0200 Subject: CGE2: Remove useless TODO comment. --- engines/cge2/toolbar.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 01943e2e45..529f0b5125 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -218,7 +218,6 @@ void CGE2Engine::initToolbar() { _vol[0]->step(_sfxVolume / kVolumeSwitchRate); if (_vol[1]) _vol[1]->step(_musicVolume / kVolumeSwitchRate); - // TODO: Recheck these! ^ } } // End of namespace CGE2 -- cgit v1.2.3 From 668b133dabdf642ee08b53bab75a273c90cc9529 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 22:23:28 +0200 Subject: CGE2: Implement the music volume button on the toolbar. --- engines/cge2/cge2.h | 5 +--- engines/cge2/cge2_main.cpp | 1 + engines/cge2/toolbar.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c23a101de8..caf39227c6 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -113,10 +113,6 @@ struct SavegameHeader; #define kSavegameStrSize 12 #define kSavegameStr "SCUMMVM_CGE2" -#define kVolumeSwitchRate 25.7 -// == 257 / 10; where 10 equals to the volume switches' number of states -// and ScummVM has a scale of 257 different values for setting sounds. - enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume }; @@ -199,6 +195,7 @@ public: void busyStep(); void checkSounds(); void checkMusicSwitch(); + void checkVolumeSwitches(); void optionTouch(int opt, uint16 mask); void switchColorMode(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 87ab2dea8f..65f856d815 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -556,6 +556,7 @@ void CGE2Engine::mainLoop() { void CGE2Engine::checkSounds() { _sound->checkSoundHandles(); checkSaySwitch(); + checkVolumeSwitches(); checkMusicSwitch(); _midiPlayer->syncVolume(); } diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 529f0b5125..edabd123b0 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -35,6 +35,17 @@ namespace CGE2 { +#define kSoundNumtoStateRate 25.7 +// == 257 / 10; where 10 equals to the volume switches' number of states [0..9] +// and ScummVM has a scale of 257 different values for setting sounds. + +#define kSoundStatetoNumRate 28.45 +// == 256 / 9 + 0.1; where 256 is the positive range of numbers we can set the volume to +// and the 10 states of a switch cut this range up to 9 equally big parts. +// We don't take into account 0 regarding the 256 different values (it would be the 257th), +// since 0 * x == 0. +// 0.1 is only for correct rounding at the 10th state. + void CGE2Engine::optionTouch(int opt, uint16 mask) { switch (opt) { case 1: @@ -52,6 +63,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { break; case true: ConfMan.setInt("music_volume", _oldMusicVolume); + _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); break; } } @@ -142,7 +154,46 @@ void CGE2Engine::quit() { } void CGE2Engine::setVolume(int idx, int cnt) { - warning("STUB: CGE2Engine::setVolume()"); + if (cnt && _vol[idx]) { + int p = _vol[idx]->_seqPtr + cnt; + if (p >= 0 && p < _vol[idx]->_seqCnt) { + _vol[idx]->step(p); + int newVolume = p * kSoundStatetoNumRate; + switch (idx) { + case 0: + ConfMan.setInt("sfx_volume", newVolume); + break; + case 1: + if (newVolume == 0) + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", newVolume); + break; + default: + break; + } + } + } +} + +void CGE2Engine::checkVolumeSwitches() { + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + bool musicMuted = mute; + int musicVolume = ConfMan.getInt("music_volume"); + if (!musicMuted) + musicMuted = musicVolume == 0; + bool sfxMuted = mute; + int sfxVolume = ConfMan.getInt("sfx_volume"); + if (!sfxMuted) + sfxMuted = sfxVolume == 0; + + if ((!musicMuted && !_music) || (musicVolume != _oldMusicVolume)) { + _vol[1]->step(musicVolume / kSoundNumtoStateRate); + } + if (musicMuted && _music) { + _vol[1]->step(0); + } } void CGE2Engine::switchCap() { @@ -215,9 +266,9 @@ void CGE2Engine::initToolbar() { _vol[1] = _vga->_showQ->locate(kMvolRef); if (_vol[0]) - _vol[0]->step(_sfxVolume / kVolumeSwitchRate); + _vol[0]->step(_sfxVolume / kSoundNumtoStateRate); if (_vol[1]) - _vol[1]->step(_musicVolume / kVolumeSwitchRate); + _vol[1]->step(_musicVolume / kSoundNumtoStateRate); } } // End of namespace CGE2 -- cgit v1.2.3 From 944465431a4b0d4c8372456e52720f7baf5865ec Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 22:32:18 +0200 Subject: CGE2: Implement the sfx volume button on the toolbar. --- engines/cge2/cge2.cpp | 3 ++- engines/cge2/cge2.h | 2 ++ engines/cge2/toolbar.cpp | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index d28215bc93..9dbbf7db06 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -74,6 +74,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _quitFlag = false; _bitmapPalette = nullptr; _music = true; + _sfx = true; _startupMode = 1; _now = 1; _sex = 1; @@ -102,7 +103,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) } else { _oldSpeechVolume = ConfMan.getInt("speech_volume"); _oldMusicVolume = _musicVolume = ConfMan.getInt("music_volume"); - _sfxVolume = ConfMan.getInt("sfx_volume"); + _oldSfxVolume = _sfxVolume = ConfMan.getInt("sfx_volume"); } } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index caf39227c6..613168e88e 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -260,7 +260,9 @@ public: bool _quitFlag; Dac *_bitmapPalette; bool _music; + bool _sfx; int _oldMusicVolume; + int _oldSfxVolume; int _startupMode; int _now; int _sex; diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index edabd123b0..bf538b5f5a 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -194,6 +194,16 @@ void CGE2Engine::checkVolumeSwitches() { if (musicMuted && _music) { _vol[1]->step(0); } + + if ((!sfxMuted && !_sfx) || (sfxVolume != _oldSfxVolume)) { + _vol[0]->step(sfxVolume / kSoundNumtoStateRate); + _oldSfxVolume = sfxVolume; + _sfx = true; + } + if (sfxMuted && _sfx) { + _vol[0]->step(0); + _sfx = false; + } } void CGE2Engine::switchCap() { -- cgit v1.2.3 From eaddafdea707c03a7f4c6be0e7c24aafaae4dd34 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 22:34:39 +0200 Subject: CGE2: Get rid of unnecessary variables. --- engines/cge2/cge2.cpp | 6 +++--- engines/cge2/cge2.h | 2 -- engines/cge2/toolbar.cpp | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 9dbbf7db06..985a77a1a3 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -99,11 +99,11 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _spriteNotify = nullptr; _enaCap = true; if (ConfMan.getBool("mute")) { - _oldSpeechVolume = _oldMusicVolume = _musicVolume = _sfxVolume = 0; + _oldSpeechVolume = _oldMusicVolume = _oldSfxVolume = 0; } else { _oldSpeechVolume = ConfMan.getInt("speech_volume"); - _oldMusicVolume = _musicVolume = ConfMan.getInt("music_volume"); - _oldSfxVolume = _sfxVolume = ConfMan.getInt("sfx_volume"); + _oldMusicVolume = ConfMan.getInt("music_volume"); + _oldSfxVolume = ConfMan.getInt("sfx_volume"); } } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 613168e88e..987a77386c 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -286,8 +286,6 @@ public: int _startGameSlot; bool _enaCap; bool _enaVox; - int _musicVolume; - int _sfxVolume; ResourceManager *_resman; Vga *_vga; diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index bf538b5f5a..d8687e3944 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -276,9 +276,9 @@ void CGE2Engine::initToolbar() { _vol[1] = _vga->_showQ->locate(kMvolRef); if (_vol[0]) - _vol[0]->step(_sfxVolume / kSoundNumtoStateRate); + _vol[0]->step(ConfMan.getInt("sfx_volume") / kSoundNumtoStateRate); if (_vol[1]) - _vol[1]->step(_musicVolume / kSoundNumtoStateRate); + _vol[1]->step(ConfMan.getInt("music_volume") / kSoundNumtoStateRate); } } // End of namespace CGE2 -- cgit v1.2.3 From ac178b6013f3a1b090cfca1d8e9e2ad6429f4e77 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 22:43:20 +0200 Subject: CGE2: Fix optionTouch(). Now you can't change the sound options via the toolbar if the Mute All option is checked in the GGM/Launcher. --- engines/cge2/toolbar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index d8687e3944..2242cc41ff 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -73,11 +73,11 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { quit(); break; case 4: - if (mask & (kMouseLeftUp | kMouseRightUp)) + if ((mask & (kMouseLeftUp | kMouseRightUp)) && !ConfMan.getBool("mute")) setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); break; case 5: - if (mask & (kMouseLeftUp | kMouseRightUp)) + if ((mask & (kMouseLeftUp | kMouseRightUp)) && !ConfMan.getBool("mute")) setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); break; case 8: -- cgit v1.2.3 From 62e0a32a903321fd40234a245fd5b301ed50431c Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 22:53:49 +0200 Subject: CGE2: Repair checkVolumeSwitches(). --- engines/cge2/toolbar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 2242cc41ff..ce951f5baa 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -188,7 +188,8 @@ void CGE2Engine::checkVolumeSwitches() { if (!sfxMuted) sfxMuted = sfxVolume == 0; - if ((!musicMuted && !_music) || (musicVolume != _oldMusicVolume)) { + if ((!musicMuted && !_music) || + (musicVolume != _oldMusicVolume && !musicMuted)) { _vol[1]->step(musicVolume / kSoundNumtoStateRate); } if (musicMuted && _music) { -- cgit v1.2.3 From 8a9a088b31dd01facf1f4dd9f1dd1d2cadbfa2d0 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 22:59:39 +0200 Subject: CGE2: Fix optionTouch(). --- engines/cge2/toolbar.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index ce951f5baa..93b5c646da 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -60,6 +60,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { case false: _oldMusicVolume = ConfMan.getInt("music_volume"); ConfMan.setInt("music_volume", 0); + _vol[1]->step(0); break; case true: ConfMan.setInt("music_volume", _oldMusicVolume); -- cgit v1.2.3 From 870349078ec02f8d8921dd6bb32efd17cff68a24 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 23:05:23 +0200 Subject: CGE2: Refactor optionTouch(). --- engines/cge2/toolbar.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 93b5c646da..3556ec72ca 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -47,13 +47,14 @@ namespace CGE2 { // 0.1 is only for correct rounding at the 10th state. void CGE2Engine::optionTouch(int opt, uint16 mask) { + bool notMuted = !ConfMan.getBool("mute"); switch (opt) { case 1: if (mask & kMouseLeftUp) switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) { + if ((mask & kMouseLeftUp) && notMuted) { switchMusic(_music = !_music); switch (_music) { @@ -74,11 +75,11 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { quit(); break; case 4: - if ((mask & (kMouseLeftUp | kMouseRightUp)) && !ConfMan.getBool("mute")) + if ((mask & (kMouseLeftUp | kMouseRightUp)) && notMuted) setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); break; case 5: - if ((mask & (kMouseLeftUp | kMouseRightUp)) && !ConfMan.getBool("mute")) + if ((mask & (kMouseLeftUp | kMouseRightUp)) && notMuted) setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); break; case 8: @@ -86,7 +87,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchCap(); break; case 9: - if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) { + if ((mask & kMouseLeftUp) && notMuted) { switchVox(); switch (_sayVox) { -- cgit v1.2.3 From 85909a52e42fb1151322bd7b5601d042ff844fad Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 23:08:02 +0200 Subject: CGE2: Refactor optionTouch(). --- engines/cge2/toolbar.cpp | 50 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 3556ec72ca..6c4a3e7bac 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -54,21 +54,8 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && notMuted) { + if ((mask & kMouseLeftUp) && notMuted) switchMusic(_music = !_music); - - switch (_music) { - case false: - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - _vol[1]->step(0); - break; - case true: - ConfMan.setInt("music_volume", _oldMusicVolume); - _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); - break; - } - } break; case 3: if (mask & kMouseLeftUp) @@ -87,19 +74,8 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchCap(); break; case 9: - if ((mask & kMouseLeftUp) && notMuted) { + if ((mask & kMouseLeftUp) && notMuted) switchVox(); - - switch (_sayVox) { - case false: - _oldSpeechVolume = ConfMan.getInt("speech_volume"); - ConfMan.setInt("speech_volume", 0); - break; - case true: - ConfMan.setInt("speech_volume", _oldSpeechVolume); - break; - } - } break; default: break; @@ -116,6 +92,18 @@ void CGE2Engine::switchMusic(bool on) { _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); keyClick(); _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); + + switch (_music) { + case false: + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + _vol[1]->step(0); + break; + case true: + ConfMan.setInt("music_volume", _oldMusicVolume); + _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); + break; + } } void CGE2Engine::checkMusicSwitch() { @@ -226,6 +214,16 @@ void CGE2Engine::switchVox() { _sayCap = true; keyClick(); switchSay(); + + switch (_sayVox) { + case false: + _oldSpeechVolume = ConfMan.getInt("speech_volume"); + ConfMan.setInt("speech_volume", 0); + break; + case true: + ConfMan.setInt("speech_volume", _oldSpeechVolume); + break; + } } } -- cgit v1.2.3 From 266f1c7dee502db432b047c1bef29595ba0ce332 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 23:15:36 +0200 Subject: Revert "CGE2: Refactor optionTouch()." This reverts commit 85909a52e42fb1151322bd7b5601d042ff844fad. --- engines/cge2/toolbar.cpp | 50 +++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 6c4a3e7bac..3556ec72ca 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -54,8 +54,21 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && notMuted) + if ((mask & kMouseLeftUp) && notMuted) { switchMusic(_music = !_music); + + switch (_music) { + case false: + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + _vol[1]->step(0); + break; + case true: + ConfMan.setInt("music_volume", _oldMusicVolume); + _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); + break; + } + } break; case 3: if (mask & kMouseLeftUp) @@ -74,8 +87,19 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchCap(); break; case 9: - if ((mask & kMouseLeftUp) && notMuted) + if ((mask & kMouseLeftUp) && notMuted) { switchVox(); + + switch (_sayVox) { + case false: + _oldSpeechVolume = ConfMan.getInt("speech_volume"); + ConfMan.setInt("speech_volume", 0); + break; + case true: + ConfMan.setInt("speech_volume", _oldSpeechVolume); + break; + } + } break; default: break; @@ -92,18 +116,6 @@ void CGE2Engine::switchMusic(bool on) { _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); keyClick(); _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); - - switch (_music) { - case false: - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - _vol[1]->step(0); - break; - case true: - ConfMan.setInt("music_volume", _oldMusicVolume); - _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); - break; - } } void CGE2Engine::checkMusicSwitch() { @@ -214,16 +226,6 @@ void CGE2Engine::switchVox() { _sayCap = true; keyClick(); switchSay(); - - switch (_sayVox) { - case false: - _oldSpeechVolume = ConfMan.getInt("speech_volume"); - ConfMan.setInt("speech_volume", 0); - break; - case true: - ConfMan.setInt("speech_volume", _oldSpeechVolume); - break; - } } } -- cgit v1.2.3 From 5861b963ed4af0531052c2354159acdd57e661c7 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 23:19:11 +0200 Subject: CGE2: Now refactor optionTouch() the right way. --- engines/cge2/cge2.h | 2 ++ engines/cge2/toolbar.cpp | 50 +++++++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 22 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 987a77386c..9e85d03e7d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -196,6 +196,8 @@ public: void checkSounds(); void checkMusicSwitch(); void checkVolumeSwitches(); + void updateMusicVolume(); + void updateSpeechVolume(); void optionTouch(int opt, uint16 mask); void switchColorMode(); diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 3556ec72ca..b6bcfd7806 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -56,18 +56,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { case 2: if ((mask & kMouseLeftUp) && notMuted) { switchMusic(_music = !_music); - - switch (_music) { - case false: - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - _vol[1]->step(0); - break; - case true: - ConfMan.setInt("music_volume", _oldMusicVolume); - _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); - break; - } + updateMusicVolume(); } break; case 3: @@ -89,16 +78,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { case 9: if ((mask & kMouseLeftUp) && notMuted) { switchVox(); - - switch (_sayVox) { - case false: - _oldSpeechVolume = ConfMan.getInt("speech_volume"); - ConfMan.setInt("speech_volume", 0); - break; - case true: - ConfMan.setInt("speech_volume", _oldSpeechVolume); - break; - } + updateSpeechVolume(); } break; default: @@ -118,6 +98,20 @@ void CGE2Engine::switchMusic(bool on) { _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); } +void CGE2Engine::updateMusicVolume() { + switch (_music) { + case false: + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + _vol[1]->step(0); + break; + case true: + ConfMan.setInt("music_volume", _oldMusicVolume); + _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); + break; + } +} + void CGE2Engine::checkMusicSwitch() { bool mute = false; if (ConfMan.hasKey("mute")) @@ -229,6 +223,18 @@ void CGE2Engine::switchVox() { } } +void CGE2Engine::updateSpeechVolume() { + switch (_sayVox) { + case false: + _oldSpeechVolume = ConfMan.getInt("speech_volume"); + ConfMan.setInt("speech_volume", 0); + break; + case true: + ConfMan.setInt("speech_volume", _oldSpeechVolume); + break; + } +} + void CGE2Engine::switchSay() { _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); -- cgit v1.2.3 From 56da652e8f748155cea0269d3dec5f295905a9be Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 23:24:06 +0200 Subject: CGE2: Rearrange things a bit in cge2.h. --- engines/cge2/cge2.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 9e85d03e7d..c5f7b54afd 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -151,7 +151,6 @@ public: void inf(const char *text, ColorBank col = kCBInf); void movie(const char *ext); void runGame(); - void initToolbar(); void loadHeroes(); void loadScript(const char *fname, bool onlyToolbar = false); Sprite *loadSprite(const char *fname, int ref, int scene, V3D &pos); @@ -177,8 +176,6 @@ public: Sprite *locate(int ref); bool isHero(Sprite *spr); void loadUser(); - void switchSay(); - void checkSaySwitch(); void loadPos(); void releasePocket(Sprite *spr); void switchHero(int sex); @@ -193,19 +190,23 @@ public: void keyClick(); void swapInPocket(Sprite *spr, Sprite *xspr); void busyStep(); - void checkSounds(); - void checkMusicSwitch(); - void checkVolumeSwitches(); - void updateMusicVolume(); - void updateSpeechVolume(); void optionTouch(int opt, uint16 mask); void switchColorMode(); void switchMusic(bool on); + void updateMusicVolume(); + void checkMusicSwitch(); void quit(); void setVolume(int idx, int cnt); + void checkVolumeSwitches(); void switchCap(); void switchVox(); + void updateSpeechVolume(); + void switchSay(); + void checkSaySwitch(); + void initToolbar(); + + void checkSounds(); void setEye(const V3D &e); void setEye(const V2D& e2, int z = -kScrWidth); -- cgit v1.2.3 From 88286115c8dddfac4f45740c58a2e2d3a062be8d Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 23:34:58 +0200 Subject: CGE2: More refactoring in cge2.h and cge2.cpp. --- engines/cge2/cge2.cpp | 13 +++++++------ engines/cge2/cge2.h | 15 ++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 985a77a1a3..b05fca8f1d 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -70,11 +70,8 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _vol[i] = nullptr; _eventManager = nullptr; _map = nullptr; - _quitFlag = false; _bitmapPalette = nullptr; - _music = true; - _sfx = true; _startupMode = 1; _now = 1; _sex = 1; @@ -91,19 +88,23 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _endGame = false; for (int i = 0; i < 4; i++) _flag[i] = false; - _enaVox = true; - _sayCap = true; - _sayVox = true; _req = 1; _midiNotify = nullptr; _spriteNotify = nullptr; + _enaCap = true; + _enaVox = true; + _sayCap = true; + _sayVox = true; if (ConfMan.getBool("mute")) { _oldSpeechVolume = _oldMusicVolume = _oldSfxVolume = 0; + _music = _sfx = false; } else { _oldSpeechVolume = ConfMan.getInt("speech_volume"); _oldMusicVolume = ConfMan.getInt("music_volume"); _oldSfxVolume = ConfMan.getInt("sfx_volume"); + _music = _oldMusicVolume != 0; + _sfx = _oldSfxVolume != 0; } } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c5f7b54afd..94263ac641 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -262,10 +262,6 @@ public: bool _quitFlag; Dac *_bitmapPalette; - bool _music; - bool _sfx; - int _oldMusicVolume; - int _oldSfxVolume; int _startupMode; int _now; int _sex; @@ -280,15 +276,20 @@ public: bool _taken; bool _endGame; bool _flag[4]; - bool _sayCap; - bool _sayVox; - int _oldSpeechVolume; int _req; NotifyFunctionType _midiNotify; NotifyFunctionType _spriteNotify; int _startGameSlot; + bool _enaCap; bool _enaVox; + bool _sayCap; + bool _sayVox; + int _oldSpeechVolume; + int _oldMusicVolume; + int _oldSfxVolume; + bool _music; + bool _sfx; ResourceManager *_resman; Vga *_vga; -- cgit v1.2.3 From 6ac879270f34c8de99f172a7d56c25e12339a106 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 26 Jul 2014 11:44:35 +0200 Subject: CGE2: Repair display of version and translation strings. --- engines/cge2/events.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index ecb6183540..914f1255be 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -64,7 +64,7 @@ bool Keyboard::getKey(Common::Event &event) { if (event.type == Common::EVENT_KEYUP) return false; // Display ScummVM version and translation strings - for (int i = 0; i < 5; i++) + for (int i = 0; i < 3; i++) _vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, NULL); return false; case Common::KEYCODE_F5: -- cgit v1.2.3 From 8d21a21b6392bfd766780da3c7445241febcf81c Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 26 Jul 2014 12:08:54 +0200 Subject: CGE2: Change random source. --- engines/cge2/cge2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index b05fca8f1d..7c208d1215 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -42,7 +42,7 @@ namespace CGE2 { CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) - : Engine(syst), _gameDescription(gameDescription), _randomSource("cge") { + : Engine(syst), _gameDescription(gameDescription), _randomSource("cge2") { _resman = nullptr; _vga = nullptr; _midiPlayer = nullptr; -- cgit v1.2.3 From c78596a80e5dde89a37486417288be8cb65cc4b5 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 26 Jul 2014 12:52:27 +0200 Subject: CGE2: Remove another unused opcode. --- engines/cge2/snail.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index ed6aae79d8..3026f078c7 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -90,8 +90,6 @@ enum CommandType { kCmdExec, kCmdGhost, - - kCmdNOne = kNoByte }; class CommandHandler { -- cgit v1.2.3 From 0bfde974cde8eea024d66d35b5444ad4c1469701 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 26 Jul 2014 12:59:39 +0200 Subject: CGE2: Implement debug console and add a debug channel for opcodes. --- engines/cge2/cge2.cpp | 14 ++++++++++++++ engines/cge2/cge2.h | 16 +++++++++++++--- engines/cge2/console.h | 43 +++++++++++++++++++++++++++++++++++++++++++ engines/cge2/events.cpp | 2 -- engines/cge2/module.mk | 3 ++- engines/cge2/snail.cpp | 8 +++++++- engines/cge2/snail.h | 1 + 7 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 engines/cge2/console.h (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 7c208d1215..6f4c34c607 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -27,6 +27,8 @@ #include "engines/util.h" #include "common/config-manager.h" +#include "common/debug.h" +#include "common/debug-channels.h" #include "cge2/cge2.h" #include "cge2/bitmap.h" #include "cge2/vga13h.h" @@ -43,6 +45,10 @@ namespace CGE2 { CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription), _randomSource("cge2") { + + // Debug/console setup + DebugMan.addDebugChannel(kCGE2DebugOpcode, "opcode", "CGE2 opcode debug channel"); + _resman = nullptr; _vga = nullptr; _midiPlayer = nullptr; @@ -109,6 +115,9 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) } void CGE2Engine::init() { + // Create debugger console + _console = new CGE2Console(this); + _resman = new ResourceManager(); _vga = new Vga(this); _fx = new Fx(this, 16); @@ -137,6 +146,11 @@ void CGE2Engine::init() { } void CGE2Engine::deinit() { + // Remove all of our debug levels here + DebugMan.clearAllDebugChannels(); + + delete _console; + delete _spare; delete _resman; delete _vga; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 94263ac641..833cb66c72 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -35,6 +35,7 @@ #include "engines/advancedDetector.h" #include "common/system.h" #include "cge2/fileio.h" +#include "cge2/console.h" #include "audio/mixer.h" namespace CGE2 { @@ -113,6 +114,11 @@ struct SavegameHeader; #define kSavegameStrSize 12 #define kSavegameStr "SCUMMVM_CGE2" +// our engine debug channels +enum { + kCGE2DebugOpcode = 1 << 0, +}; + enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume }; @@ -128,6 +134,10 @@ private: uint32 _lastFrame, _lastTick; void tick(); + CGE2Console *_console; + void init(); + void deinit(); + Common::String generateSaveName(int slot); void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); @@ -143,6 +153,9 @@ public: virtual Common::Error saveGameState(int slot, const Common::String &desc); virtual Common::Error loadGameState(int slot); virtual Common::Error run(); + GUI::Debugger *getDebugger() { + return _console; + } static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); bool showTitle(const char *name); @@ -314,9 +327,6 @@ public: Sprite *_vol[2]; EventManager *_eventManager; Map *_map; -private: - void init(); - void deinit(); }; } // End of namespace CGE2 diff --git a/engines/cge2/console.h b/engines/cge2/console.h new file mode 100644 index 0000000000..cb2120d7e7 --- /dev/null +++ b/engines/cge2/console.h @@ -0,0 +1,43 @@ +/* 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 CGE2_CONSOLE_H +#define CGE2_CONSOLE_H + +#include "gui/debugger.h" + +namespace CGE2 { + +class CGE2Engine; + +class CGE2Console : public GUI::Debugger { +public: + CGE2Console(CGE2Engine *vm) : GUI::Debugger(), _vm(vm) {} + virtual ~CGE2Console() {} + +private: + CGE2Engine *_vm; +}; + +} // End of namespace CGE + +#endif // CGE2_CONSOLE_H diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 914f1255be..25ca77fa74 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -89,14 +89,12 @@ bool Keyboard::getKey(Common::Event &event) { } return false; case Common::KEYCODE_d: - /* if (event.kbd.flags & Common::KBD_CTRL) { // Start the debugger _vm->getDebugger()->attach(); _vm->getDebugger()->onFrame(); return false; } - */ break; case Common::KEYCODE_x: if (event.kbd.flags & Common::KBD_ALT) { diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk index 256087fd17..4b321d88a8 100644 --- a/engines/cge2/module.mk +++ b/engines/cge2/module.mk @@ -18,7 +18,8 @@ MODULE_OBJS = \ vmenu.o \ saveload.o \ toolbar.o \ - inventory.o + inventory.o \ + console.o # This module can be built as a plugin ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN) diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 8a1340f5dc..ba33dd04eb 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -40,7 +40,7 @@ const char *CommandHandler::_commandText[] = { "HIDE", "ROOM", "SAY", "SOUND", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", "GIVE", "GETPOS", "GOTO", "PORT", "NEXT", "NNEXT", "MTNEXT", "FTNEXT", "RNNEXT", "RMTNEXT", "RFTNEXT", "RMNEAR", "RMMTAKE", "RMFTAKE", - "SETREF", "WALKTO", "REACH", "COVER", "UNCOVER", + "SETREF", "WALKTO", "REACH", "COVER", "UNCOVER", "EXEC", "GHOST", nullptr }; CommandHandler::CommandHandler(CGE2Engine *vm, bool turbo) @@ -102,6 +102,8 @@ void CommandHandler::runCommand() { if (tailCmd._commandType > kCmdSpr) spr = (tailCmd._ref < 0) ? ((Sprite *)tailCmd._spritePtr) : _vm->locate(tailCmd._ref); + debugC(1, kCGE2DebugOpcode, getComStr(tailCmd._commandType)); + switch (tailCmd._commandType) { case kCmdUse: break; @@ -742,6 +744,10 @@ int CommandHandler::getComId(const char *com) { return (i < 0) ? i : i + kCmdCom0 + 1; } +const char *CommandHandler::getComStr(CommandType cmdType) { + return _commandText[cmdType - kCmdNop]; +} + void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { if (!spr || !spr->active()) return; diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 3026f078c7..55da49045f 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -115,6 +115,7 @@ public: void reset(); void clear(); int getComId(const char *com); + const char *getComStr(CommandType cmdType); private: CGE2Engine *_vm; bool _turbo; -- cgit v1.2.3 From 8e28a2c0d0fe03bf3ef0f6315ceeb637846f4881 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 26 Jul 2014 13:37:59 +0200 Subject: CGE2: Make the debug channel of the opcodes more verbose. --- engines/cge2/snail.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index ba33dd04eb..b4a78f0aaf 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -102,7 +102,15 @@ void CommandHandler::runCommand() { if (tailCmd._commandType > kCmdSpr) spr = (tailCmd._ref < 0) ? ((Sprite *)tailCmd._spritePtr) : _vm->locate(tailCmd._ref); - debugC(1, kCGE2DebugOpcode, getComStr(tailCmd._commandType)); + Common::String sprStr; + if (spr && spr->_file && tailCmd._commandType != kCmdGhost) + // In case of kCmdGhost _spritePtr stores a pointer to a Bitmap, not to a Sprite... + sprStr = Common::String(spr->_file); + else + sprStr = "None"; + if (sprStr.empty()) + sprStr = "None"; + debugC(1, kCGE2DebugOpcode, "Command: %s; Ref: %d; Val: %d; Sprite: %s;", getComStr(tailCmd._commandType), tailCmd._ref, tailCmd._val, sprStr.c_str()); switch (tailCmd._commandType) { case kCmdUse: -- cgit v1.2.3 From c394a685891cfab7d5f59233a5ca82cd0db92833 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 27 Jul 2014 00:46:30 +0200 Subject: CGE2: Fix misleading tabulation, improve warning --- engines/cge2/vga13h.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index ea82fb7880..617cb7d250 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -124,7 +124,7 @@ BitmapPtr Sprite::getShp() { int i = e->_seq[_seqPtr]._now; if (i >= _shpCnt) - error("Invalid PHASE in SPRITE::Shp() %s", _file); + error("Invalid PHASE in SPRITE::Shp() %s - %d", _file, i); return e->_shpList + i; } @@ -393,7 +393,7 @@ Sprite *Sprite::expand() { if (!shpcnt) error("No shapes - %s", fname); - } else // no sprite description: try to read immediately from .BMP + } else // no sprite description: try to read immediately from .BMP shplist[shpcnt++] = Bitmap(_vm, _file); if (curSeq) { -- cgit v1.2.3 From 73784c26b7737f4474ec33974fb3abe156370025 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 27 Jul 2014 18:45:07 +0200 Subject: CGE2: Add work around for piram_/pirami issue --- engines/cge2/fileio.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 257e977d45..11a01c67fb 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -156,6 +156,12 @@ BtKeypack *ResourceManager::find(const char *key) { if (scumm_stricmp((const char *)key, (const char *)pg->_leaf[i]._key) <= 0) break; } + + // FIXME: Terrible hack to work around a mix between 24piram_ and 24pirami + if (!strcmp(key, "24piram_.SPR") && (scumm_stricmp((const char *)key, (const char *)pg->_leaf[i]._key) < 0)) + ++i; + // + _buff[lev]._index = i; return &pg->_leaf[i]; } -- cgit v1.2.3 From ab2f720f379935a738c7c9a04d0cfc647c241467 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 16:08:44 +0200 Subject: CGE2: Remove commas at the end of enumerator lists. --- engines/cge2/cge2.h | 2 +- engines/cge2/snail.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 833cb66c72..81b2071f95 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -116,7 +116,7 @@ struct SavegameHeader; // our engine debug channels enum { - kCGE2DebugOpcode = 1 << 0, + kCGE2DebugOpcode = 1 << 0 }; enum CallbackType { diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 55da49045f..62201a9ab8 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -89,7 +89,7 @@ enum CommandType { kCmdUncover, // UNCOVER :: restore the state before COVER kCmdExec, - kCmdGhost, + kCmdGhost }; class CommandHandler { -- cgit v1.2.3 From cc7a70d967cc91d7829476f43550c28d0454f976 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 16:12:33 +0200 Subject: CGE2: Use if-else instead of switch-case with boolean values. --- engines/cge2/toolbar.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index b6bcfd7806..e595074435 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -99,16 +99,13 @@ void CGE2Engine::switchMusic(bool on) { } void CGE2Engine::updateMusicVolume() { - switch (_music) { - case false: + if (_music) { + ConfMan.setInt("music_volume", _oldMusicVolume); + _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); + } else { _oldMusicVolume = ConfMan.getInt("music_volume"); ConfMan.setInt("music_volume", 0); _vol[1]->step(0); - break; - case true: - ConfMan.setInt("music_volume", _oldMusicVolume); - _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); - break; } } @@ -224,14 +221,11 @@ void CGE2Engine::switchVox() { } void CGE2Engine::updateSpeechVolume() { - switch (_sayVox) { - case false: + if (_sayVox) { + ConfMan.setInt("speech_volume", _oldSpeechVolume); + } else { _oldSpeechVolume = ConfMan.getInt("speech_volume"); ConfMan.setInt("speech_volume", 0); - break; - case true: - ConfMan.setInt("speech_volume", _oldSpeechVolume); - break; } } -- cgit v1.2.3 From b9d13ae41dfa668b8937d333edb04e571e23c0ad Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 16:15:11 +0200 Subject: CGE2: Get rid of unused variables in Bitmap. --- engines/cge2/bitmap.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 159631ec05..12f7651b36 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -61,9 +61,6 @@ class Bitmap { Common::String setExtension(const Common::String &str, const Common::String &ext); bool loadVBM(EncryptedStream *f); public: - static uint8 *kSLDesign; - static uint8 *kSRDesign; - uint16 _w; uint16 _h; uint8 *_v; -- cgit v1.2.3 From fe77bfecf78d499bfb34e353e699e3d56a9f3a5a Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 16:16:55 +0200 Subject: CGE2: Rename Bitmap::paint() to makeSpeechBubleTail(). --- engines/cge2/bitmap.cpp | 2 +- engines/cge2/bitmap.h | 2 +- engines/cge2/vga13h.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index fd2f6a441f..2c7c010d53 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -414,7 +414,7 @@ bool Bitmap::moveLo() { #define D 3, #define kDesignSize 240 -uint8 *Bitmap::paint(int which, uint8 colorSet[][4]) { +uint8 *Bitmap::makeSpeechBubbleTail(int which, uint8 colorSet[][4]) { uint8 kSLDesign[kDesignSize] = { G G G G G G G G G _ _ _ _ _ _ L G G G G G G G G D _ _ _ _ _ diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 12f7651b36..8643c37467 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -85,7 +85,7 @@ public: bool moveHi(); bool moveLo(); - static uint8 *paint(int des, uint8 colorSet[][4]); + static uint8 *makeSpeechBubbleTail(int des, uint8 colorSet[][4]); }; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 617cb7d250..4e43e9e9d8 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1137,10 +1137,10 @@ void Bitmap::hide(V2D pos) { Speaker::Speaker(CGE2Engine *vm): Sprite(vm), _vm(vm) { // Set the sprite list BitmapPtr SP = new Bitmap[2]; - uint8 *map = Bitmap::paint(0, _vm->_font->_colorSet); + uint8 *map = Bitmap::makeSpeechBubbleTail(0, _vm->_font->_colorSet); SP[0] = Bitmap(_vm, 15, 16, map); delete[] map; - map = Bitmap::paint(1, _vm->_font->_colorSet); + map = Bitmap::makeSpeechBubbleTail(1, _vm->_font->_colorSet); SP[1] = Bitmap(_vm, 15, 16, map); delete[] map; setShapeList(SP, 2); -- cgit v1.2.3 From ae4adf4a9fd10a48fbdbb002d8686bd4560729ab Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 16:26:10 +0200 Subject: CGE2: Move implementation of Console into a .cpp file. Also get rid of unused _vm variable of it. --- engines/cge2/console.cpp | 33 +++++++++++++++++++++++++++++++++ engines/cge2/console.h | 7 ++----- 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 engines/cge2/console.cpp (limited to 'engines') diff --git a/engines/cge2/console.cpp b/engines/cge2/console.cpp new file mode 100644 index 0000000000..c67c7ab788 --- /dev/null +++ b/engines/cge2/console.cpp @@ -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. + * + */ + +#include "cge2/console.h" + +namespace CGE2 { + +CGE2Console::CGE2Console(CGE2Engine *vm) : GUI::Debugger() { +} + +CGE2Console::~CGE2Console() { +} + +} // End of namespace CGE diff --git a/engines/cge2/console.h b/engines/cge2/console.h index cb2120d7e7..15956bf728 100644 --- a/engines/cge2/console.h +++ b/engines/cge2/console.h @@ -31,11 +31,8 @@ class CGE2Engine; class CGE2Console : public GUI::Debugger { public: - CGE2Console(CGE2Engine *vm) : GUI::Debugger(), _vm(vm) {} - virtual ~CGE2Console() {} - -private: - CGE2Engine *_vm; + CGE2Console(CGE2Engine *vm); + virtual ~CGE2Console(); }; } // End of namespace CGE -- cgit v1.2.3 From fca11e77f8620889d4c8eb8513a6fc0dc89e3a04 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 16:29:51 +0200 Subject: CGE2: Get rid of more unused variables. --- engines/cge2/fileio.h | 1 - engines/cge2/snail.cpp | 2 +- engines/cge2/snail.h | 2 -- engines/cge2/sound.h | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 093850735a..0732b24c7b 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -110,7 +110,6 @@ class EncryptedStream { private: CGE2Engine *_vm; Common::SeekableReadStream *_readStream; - const char **_tab; int _lineCount; bool _error; public: diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index b4a78f0aaf..b6ae9dbdb0 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -46,7 +46,7 @@ const char *CommandHandler::_commandText[] = { CommandHandler::CommandHandler(CGE2Engine *vm, bool turbo) : _turbo(turbo), _textDelay(false), _timerExpiry(0), _talkEnable(true), _head(0), _tail(0), _commandList((Command *)malloc(sizeof(Command)* 256)), - _count(1), _vm(vm) { + _vm(vm) { } CommandHandler::~CommandHandler() { diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 62201a9ab8..82df181878 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -121,10 +121,8 @@ private: bool _turbo; uint8 _head; uint8 _tail; - bool _busy; bool _textDelay; uint32 _timerExpiry; // "pause" in the original. - int _count; }; } // End of namespace CGE2 diff --git a/engines/cge2/sound.h b/engines/cge2/sound.h index b97cd11bd0..2960dc32e4 100644 --- a/engines/cge2/sound.h +++ b/engines/cge2/sound.h @@ -90,7 +90,6 @@ private: class Fx { CGE2Engine *_vm; - int _size; DataCk *loadWave(EncryptedStream *file); Common::String name(int ref, int sub); -- cgit v1.2.3 From b911b66cc4ea2db2dcf869e1eba01f8aa7007ec6 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 16:40:06 +0200 Subject: CGE2: Keep in sync the in-game color blind option with the Launcher's. --- engines/cge2/toolbar.cpp | 2 ++ engines/cge2/vga13h.cpp | 7 ++----- engines/cge2/vga13h.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index e595074435..2604a2fee7 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -88,6 +88,8 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { void CGE2Engine::switchColorMode() { _commandHandlerTurbo->addCommand(kCmdSeq, 121, _vga->_mono = !_vga->_mono, nullptr); + ConfMan.setBool("enable_color_blind", _vga->_mono); + ConfMan.flushToDisk(); keyClick(); _vga->setColors(_vga->_sysPal, 64); } diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 4e43e9e9d8..c850db288b 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -826,7 +826,7 @@ bool Queue::locate(Sprite *spr) { return false; } -Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(nullptr), _name(nullptr), _setPal(false), _mono(0), _vm(vm) { +Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(nullptr), _name(nullptr), _setPal(false), _vm(vm) { _oldColors = nullptr; _newColors = nullptr; _showQ = new Queue(true); @@ -837,8 +837,7 @@ Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(nullptr), _name(nullptr), _setPal(fa _page[idx]->create(kScrWidth, kScrHeight, Graphics::PixelFormat::createFormatCLUT8()); } - if (ConfMan.getBool("enable_color_blind")) - _mono = 1; + _mono = ConfMan.getBool("enable_color_blind"); _oldColors = (Dac *)malloc(sizeof(Dac) * kPalCount); _newColors = (Dac *)malloc(sizeof(Dac) * kPalCount); @@ -849,8 +848,6 @@ Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(nullptr), _name(nullptr), _setPal(fa } Vga::~Vga() { - _mono = 0; - Common::String buffer = ""; free(_oldColors); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 77bece6884..d98402e3e5 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -318,7 +318,7 @@ class Vga { public: uint32 _frmCnt; Queue *_showQ; - int _mono; + bool _mono; Graphics::Surface *_page[4]; Dac *_sysPal; -- cgit v1.2.3 From db6cab7a6f92855b2264f1899011346dc2e1b91d Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 20:40:42 +0200 Subject: CGE2: Repair loading from savestate. --- engines/cge2/cge2_main.cpp | 6 +++--- engines/cge2/saveload.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 65f856d815..2669ac9fe7 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -669,10 +669,10 @@ void CGE2Engine::loadUser() { if (_startGameSlot != -1) loadGame(_startGameSlot); - else + else { loadScript("CGE.INI"); - - loadHeroes(); + loadHeroes(); + } } void CGE2Engine::loadHeroes() { // Original name: loadGame() diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 5e60f07bcd..c468f65855 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -369,6 +369,9 @@ bool CGE2Engine::loadGame(int slotNumber) { delete readStream; syncSpeechSettings(); + + loadHeroes(); + initToolbar(); return true; } -- cgit v1.2.3 From dd1637af9f8847be7077dc7962c1a4f4d527de95 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 28 Jul 2014 22:28:33 +0200 Subject: CGE2: Fix initialization of Mouse. --- engines/cge2/events.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 25ca77fa74..ccddc25505 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -129,7 +129,7 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ -Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(nullptr), _hold(nullptr), _hx(0), _point(_vm), _vm(vm) { +Mouse::Mouse(CGE2Engine *vm) : Sprite(vm), _busy(nullptr), _hold(nullptr), _hx(0), _point(vm), _vm(vm) { _hold = nullptr; _hx = 0; _hy = 0; -- cgit v1.2.3 From f538660c1558f6eb170bf82421cfe34155f6a9c3 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 08:48:45 +0200 Subject: CGE2: Fix graphic glitch at closing the game. --- engines/cge2/cge2_main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 2669ac9fe7..8c166848dc 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -762,6 +762,7 @@ void CGE2Engine::cge2_main() { if (_startGameSlot != -1) { // Starting up a savegame from the launcher runGame(); + return; } if (showTitle("WELCOME")) { -- cgit v1.2.3 From d95a4c5f726c8c4e9259132a07857d2c910ca1f8 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 09:05:41 +0200 Subject: CGE2: Get rid of _flag. --- engines/cge2/cge2.cpp | 2 -- engines/cge2/cge2.h | 1 - engines/cge2/cge2_main.cpp | 5 +---- engines/cge2/saveload.cpp | 4 +++- 4 files changed, 4 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 6f4c34c607..f175fceced 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -92,8 +92,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _soundStat._ref[1] = 0; _taken = false; _endGame = false; - for (int i = 0; i < 4; i++) - _flag[i] = false; _req = 1; _midiNotify = nullptr; _spriteNotify = nullptr; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 81b2071f95..7fd5431244 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -288,7 +288,6 @@ public: } _soundStat; bool _taken; bool _endGame; - bool _flag[4]; int _req; NotifyFunctionType _midiNotify; NotifyFunctionType _spriteNotify; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 8c166848dc..d07eef389b 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -648,11 +648,8 @@ void CGE2Engine::runGame() { initToolbar(); // main loop - while (!_endGame && !_quitFlag) { - if (_flag[3]) // Flag FINIS - _commandHandler->addCallback(kCmdExec, -1, 0, kQGame); + while (!_endGame && !_quitFlag) mainLoop(); - } // If finishing game due to closing ScummVM window, explicitly save the game if (!_endGame && canSaveGameStateCurrently()) diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index c468f65855..30d6b3dd46 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -286,6 +286,8 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS } void CGE2Engine::syncHeader(Common::Serializer &s) { + int dummy = 0; + s.syncAsUint16LE(_now); s.syncAsUint16LE(_sex); s.syncAsUint16LE(_music); @@ -294,7 +296,7 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { s.syncAsUint16LE(_sayCap); s.syncAsUint16LE(_sayVox); for (int i = 0; i < 4; i++) - s.syncAsUint16LE(_flag[i]); + s.syncAsUint16LE(dummy); // _flag if (s.isSaving()) { // Write checksum -- cgit v1.2.3 From 5016e09acf8884a9a06bc7871b564d3070875222 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 09:06:14 +0200 Subject: CGE2: Don't bother with saving/loading sound options. We always get them for the setting of the Launcher. --- engines/cge2/saveload.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 30d6b3dd46..ecf55d2a9c 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -290,11 +290,11 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { s.syncAsUint16LE(_now); s.syncAsUint16LE(_sex); - s.syncAsUint16LE(_music); + s.syncAsUint16LE(dummy); // _music s.syncAsUint16LE(_waitSeq); s.syncAsUint16LE(_waitRef); - s.syncAsUint16LE(_sayCap); - s.syncAsUint16LE(_sayVox); + s.syncAsUint16LE(dummy); // _sayCap + s.syncAsUint16LE(dummy); // _sayVox for (int i = 0; i < 4; i++) s.syncAsUint16LE(dummy); // _flag -- cgit v1.2.3 From d4e14253c45ef9e747a7b1e5082a959fa61c0eb5 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 10:38:05 +0200 Subject: CGE2: Implement snFlash(). --- engines/cge2/cge2.h | 2 +- engines/cge2/snail.cpp | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 7fd5431244..d947f01636 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -254,7 +254,7 @@ public: void snRmMTake(Sprite *spr); void snRmFTake(Sprite *spr); void snSetRef(Sprite *spr, int val); - void snFlash(int val); + void snFlash(bool on); void snCycle(int cnt); void snWalk(Sprite *spr, int val); void snReach(Sprite *spr, int val); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index b6ae9dbdb0..3fab991a69 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -555,8 +555,27 @@ void CGE2Engine::snSetRef(Sprite *spr, int val) { } } -void CGE2Engine::snFlash(int val) { - warning("STUB: CGE2Engine::snFlash()"); +void CGE2Engine::snFlash(bool on) { + if (on) { + Dac *pal = (Dac *)malloc(sizeof(Dac) * kPalCount); + if (pal) { + memcpy(pal, _vga->_sysPal, kPalSize); + for (int i = 0; i < kPalCount; i++) { + register int c; + c = pal[i]._r << 1; + pal[i]._r = (c < 64) ? c : 63; + c = pal[i]._g << 1; + pal[i]._g = (c < 64) ? c : 63; + c = pal[i]._b << 1; + pal[i]._b = (c < 64) ? c : 63; + } + _vga->setColors(pal, 64); + } + + free(pal); + } else + _vga->setColors(_vga->_sysPal, 64); + _dark = false; } void CGE2Engine::snCycle(int cnt) { -- cgit v1.2.3 From df59c0d0f6f3f5193a769e8a7f31fd08fe9ee31e Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 10:56:04 +0200 Subject: CGE2: Remove not useful comment from switchScene(). --- engines/cge2/cge2_main.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index d07eef389b..9bdd57a50c 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -478,20 +478,6 @@ void CGE2Engine::sceneDown() { void CGE2Engine::switchScene(int scene) { if (scene == _now) return; - - /* TODO:: Recheck this flag-thing! As far as it seems it's only for checking if the game - is being run from the CD-ROM. In this context, it's useless for us. - - if (scene >= 0) { - if (!_flag[2]) // PROT - _flag[2] = true; - else { - int t = _text->getText(kCrackedText) ? kCrackedText : kExitOkText; - _commandHandler->addCommand(kCmdInf, -1, t, nullptr); - return; - } - } - */ _req = scene; -- cgit v1.2.3 From 77610ad993cbfa6025a8e463ffce1c9f07ad3112 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 11:06:37 +0200 Subject: CGE2: Get rid of kCrackedText. --- engines/cge2/cge2.h | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index d947f01636..00306e7029 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -99,7 +99,6 @@ struct SavegameHeader; #define kVoxRef 129 #define kExitOkText 40 -#define kCrackedText 44 #define kOffUseCount 130 #define kOffUseText 131 -- cgit v1.2.3 From 3d69c67f9934731b452b6c66d71f2cd22b8a64fe Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 11:09:05 +0200 Subject: CGE2: Get rid of kExitOkText. --- engines/cge2/cge2.h | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 00306e7029..930995a041 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -98,7 +98,6 @@ struct SavegameHeader; #define kCapRef 128 #define kVoxRef 129 -#define kExitOkText 40 #define kOffUseCount 130 #define kOffUseText 131 -- cgit v1.2.3 From 70f54c6609c5f3f66e4223d35a895b6a18e9a9a0 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 11:12:35 +0200 Subject: CGE2: Remove unused code. --- engines/cge2/vga13h.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index c850db288b..6db73f4836 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1008,11 +1008,6 @@ void Vga::show() { if ((p && spr->_pos3D._z > p->_pos3D._z) || (n && spr->_pos3D._z < n->_pos3D._z)) { _showQ->insert(_showQ->remove(spr)); - if (s) { - //s->gotoxyz(V3D(s->_pos3D._x, s->_pos3D._y, spr->_pos3D._z)); - //_showQ->insert(_showQ->remove(s), spr); - // These two lines are also commented out in the original. - } } spr->_flags._zmov = false; } -- cgit v1.2.3 From 375a7c3b15ef68e95d7169973f7aaf144d7a35ac Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 11:17:07 +0200 Subject: CGE2: Implement snCycle, add stub for Vga::rotate(). --- engines/cge2/snail.cpp | 2 +- engines/cge2/vga13h.cpp | 5 +++++ engines/cge2/vga13h.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 3fab991a69..240b70a557 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -579,7 +579,7 @@ void CGE2Engine::snFlash(bool on) { } void CGE2Engine::snCycle(int cnt) { - warning("STUB: CGE2Engine::snCycle()"); + _vga->_rot._len = cnt; } void CGE2Engine::snWalk(Sprite *spr, int val) { diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 6db73f4836..856ee68faf 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -992,6 +992,7 @@ void Vga::show() { _vm->_mouse->show(); update(); + rotate(); for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) { spr->hide(); @@ -1033,6 +1034,10 @@ void Vga::update() { g_system->updateScreen(); } +void Vga::rotate() { + warning("STUB: Vga::rotate()"); +} + void Vga::clear(uint8 color) { for (int paneNum = 0; paneNum < 4; paneNum++) _page[paneNum]->fillRect(Common::Rect(0, 0, kScrWidth, kScrHeight), color); diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index d98402e3e5..d8fe7156b6 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -321,6 +321,7 @@ public: bool _mono; Graphics::Surface *_page[4]; Dac *_sysPal; + struct { uint8 _org, _len, _cnt, _dly; } _rot; Vga(CGE2Engine *vm); ~Vga(); @@ -334,6 +335,7 @@ public: void sunset(); void show(); void update(); + void rotate(); void palToDac(const byte *palData, Dac *tab); void dacToPal(const Dac *tab, byte *palData); -- cgit v1.2.3 From e828be1bf9ea8ac3cba5c46a8c7a838e06dca198 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 11:20:20 +0200 Subject: CGE2: Initialize Vga::_rot properly. --- engines/cge2/vga13h.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 856ee68faf..1a8597392e 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -827,6 +827,11 @@ bool Queue::locate(Sprite *spr) { } Vga::Vga(CGE2Engine *vm) : _frmCnt(0), _msg(nullptr), _name(nullptr), _setPal(false), _vm(vm) { + _rot._org = 1; + _rot._len = 0; + _rot._cnt = 0; + _rot._dly = 1; + _oldColors = nullptr; _newColors = nullptr; _showQ = new Queue(true); -- cgit v1.2.3 From 6e00d80b4bbb49453ab736f5ea84cec2ddfa05af Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 11:52:57 +0200 Subject: CGE2: Implement Vga::rotate(). --- engines/cge2/saveload.cpp | 2 +- engines/cge2/vga13h.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index ecf55d2a9c..c505358973 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -290,7 +290,7 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { s.syncAsUint16LE(_now); s.syncAsUint16LE(_sex); - s.syncAsUint16LE(dummy); // _music + s.syncAsUint16LE(_vga->_rot._len); s.syncAsUint16LE(_waitSeq); s.syncAsUint16LE(_waitRef); s.syncAsUint16LE(dummy); // _sayCap diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 1a8597392e..1cd2c95468 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -1040,7 +1040,14 @@ void Vga::update() { } void Vga::rotate() { - warning("STUB: Vga::rotate()"); + if (_rot._len) { + Dac c; + getColors(_newColors); + c = _newColors[_rot._org]; + memmove(_newColors + _rot._org, _newColors + _rot._org + 1, (_rot._len - 1) * sizeof(Dac)); + _newColors[_rot._org + _rot._len - 1] = c; + _setPal = true; + } } void Vga::clear(uint8 color) { -- cgit v1.2.3 From 95854c3a5743564aa2ef3e7c1d8ef21156ae7f2e Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 12:13:38 +0200 Subject: CGE2: Get rid of sndSetVolume() and connected code. --- engines/cge2/cge2.h | 3 +-- engines/cge2/snail.cpp | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 930995a041..4febca32d1 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -118,7 +118,7 @@ enum { }; enum CallbackType { - kNullCB = 0, kQGame, kXScene, kSoundSetVolume + kNullCB = 0, kQGame, kXScene }; enum Action { kNear, kMTake, kFTake, kActions }; @@ -265,7 +265,6 @@ public: Sprite *expandSprite(Sprite *spr); void qGame(); void xScene(); - void sndSetVolume(); const ADGameDescription *_gameDescription; diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 240b70a557..54ef036dc3 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -256,9 +256,6 @@ void CommandHandler::runCommand() { case kXScene: _vm->xScene(); break; - case kSoundSetVolume: - _vm->sndSetVolume(); - break; default: error("Unknown Callback Type in SNEXEC"); break; @@ -703,10 +700,6 @@ void CGE2Engine::xScene() { sceneUp(_req); } -void CGE2Engine::sndSetVolume() { - warning("STUB: CGE2Engine::sndSetVolume()"); -} - void CommandHandler::addCommand(CommandType com, int ref, int val, void *ptr) { if (ref == -2) ref = 142 - _vm->_sex; -- cgit v1.2.3 From cee669e76325dd9f6dca12262faf61cbe0392828 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 13:25:13 +0200 Subject: CGE2: Implement setAutoColors(). Add a redefinition of closest() to do so. --- engines/cge2/talk.cpp | 11 ++++++++++- engines/cge2/vga13h.cpp | 22 ++++++++++++++++++++++ engines/cge2/vga13h.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 8e5773c677..f6321d3e59 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -31,7 +31,16 @@ namespace CGE2 { void CGE2Engine::setAutoColors() { - warning("STUB: CGE2Engine::setAutoColors()"); + Dac def[4] = { + { 0, 0, 0 }, + { 220 >> 2, 220 >> 2, 220 >> 2 }, + { 190 >> 2, 190 >> 2, 190 >> 2 }, + { 160 >> 2, 160 >> 2, 160 >> 2 }, + }; + Dac pal[kPalCount]; + _vga->getColors(pal); + for (int i = 0; i < 4; i++) + _font->_colorSet[kCBRel][i] = _vga->closest(pal, def[i]); } Font::Font(CGE2Engine *vm) : _vm(vm) { diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 1cd2c95468..62b070dcac 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -913,6 +913,28 @@ uint8 Vga::closest(Dac *pal, const uint8 colR, const uint8 colG, const uint8 col #undef f } +uint8 Vga::closest(Dac *pal, Dac x) { + int exp = (sizeof(long) * 8 - 1); + long D = (1 << exp) - 1; // Maximume value of long. + long R = x._r; + long G = x._g; + long B = x._b; + int idx; + for (int n = 0; n < 256; n++) { + long dR = R - pal[n]._r; + long dG = G - pal[n]._g; + long dB = B - pal[n]._b, + d = dR * dR + dG * dG + dB * dB; + if (d < D) { + idx = n; + D = d; + if (!d) + break; + } + } + return idx; +} + uint8 *Vga::glass(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB) { uint8 *x = (uint8 *)malloc(256); if (x) { diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index d8fe7156b6..3ed5fd559f 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -336,6 +336,7 @@ public: void show(); void update(); void rotate(); + uint8 closest(Dac *pal, Dac x); void palToDac(const byte *palData, Dac *tab); void dacToPal(const Dac *tab, byte *palData); -- cgit v1.2.3 From 800ff40219c44c0961ff02faaf75d692f0d9a98a Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 13:25:39 +0200 Subject: CGE2: Move ColorBank and kColorNum to one place. They are strongly connected. --- engines/cge2/cge2.h | 6 ++++-- engines/cge2/talk.h | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 4febca32d1..05afd2640d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -112,6 +112,10 @@ struct SavegameHeader; #define kSavegameStrSize 12 #define kSavegameStr "SCUMMVM_CGE2" +#define kColorNum 6 + +enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; + // our engine debug channels enum { kCGE2DebugOpcode = 1 << 0 @@ -123,8 +127,6 @@ enum CallbackType { enum Action { kNear, kMTake, kFTake, kActions }; -enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; - typedef void (CGE2Engine::*NotifyFunctionType)(); class CGE2Engine : public Engine { diff --git a/engines/cge2/talk.h b/engines/cge2/talk.h index ec4a347c69..d7484655cc 100644 --- a/engines/cge2/talk.h +++ b/engines/cge2/talk.h @@ -44,7 +44,6 @@ namespace CGE2 { #define kCaptionSide 24 #define kInfName 101 #define kSayName 102 -#define kColorNum 6 class Font { void load(); -- cgit v1.2.3 From 02c0b419d6b28350c654eadccdb8fe7f1b1f1b7d Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 13:30:23 +0200 Subject: CGE2: Remove unnecessary CHECKME comment. --- engines/cge2/vga13h.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 62b070dcac..b3552686c8 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -590,7 +590,6 @@ void Sprite::gotoxyz(V2D pos) { _flags._trim = (trim != 0); if (!_follow) { - // CHECKME: Original was using Pos2d.Eye, which shouldn't make a difference (static var) FXP m = _vm->_eye->_z / (_pos3D._z - _vm->_eye->_z); _pos3D._x = (_vm->_eye->_x + (_vm->_eye->_x - _pos2D.x) / m); _pos3D._x.round(); -- cgit v1.2.3 From 2c5af2ae54c475167f6fae1b9792ef48dd01d86e Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 13:40:53 +0200 Subject: CGE2: Remove unused functions from EncryptedStream. --- engines/cge2/fileio.cpp | 12 ------------ engines/cge2/fileio.h | 4 ---- 2 files changed, 16 deletions(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 11a01c67fb..41ea1c1105 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -222,22 +222,10 @@ uint32 EncryptedStream::read(byte *dataPtr, uint32 dataSize) { return _readStream->read(dataPtr, dataSize); } -unsigned EncryptedStream::readUint16BE() { - return _readStream->readUint16BE(); -} - -signed EncryptedStream::readSint16BE() { - return _readStream->readSint16BE(); -} - signed EncryptedStream::readSint16LE() { return _readStream->readSint16LE(); } -signed EncryptedStream::readUint16LE() { - return _readStream->readUint16LE(); -} - uint32 EncryptedStream::readUint32LE() { return _readStream->readUint32LE(); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 0732b24c7b..0f3755beb5 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -105,7 +105,6 @@ public: bool exist(const char *name); }; -// TODO: Revise the whole class! class EncryptedStream { private: CGE2Engine *_vm; @@ -121,10 +120,7 @@ public: int32 pos(); int32 size(); uint32 read(byte *dataPtr, uint32 dataSize); - unsigned readUint16BE(); - signed readSint16BE(); signed readSint16LE(); - signed readUint16LE(); uint32 readUint32LE(); Common::String readLine(); int getLineCount() { return _lineCount; } -- cgit v1.2.3 From e51888d9cef36d8d9a329abbbd9198aaa555e7e4 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 15:59:43 +0200 Subject: CGE2: Refactor Hero::expand() and Sprite::expand(). --- engines/cge2/hero.cpp | 254 ++++++++++++++++++++++++------------------------ engines/cge2/vga13h.cpp | 19 ++-- 2 files changed, 138 insertions(+), 135 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index c9b8dc5a13..0b8e227590 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -44,14 +44,10 @@ Hero::~Hero() { contract(); } -Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! +Sprite *Hero::expand() { if (_ext) return this; - Common::String str(_vm->_text->getText(_ref + 100)); - char text[kLineMax + 1]; - strcpy(text, str.c_str()); - char fname[kMaxPath]; _vm->mergeExt(fname, _file, kSprExt); @@ -61,149 +57,157 @@ Sprite *Hero::expand() { // It's very similar to Sprite's expand, but doesn't bo if (_ext == nullptr) error("No core %s", fname); - if (*_file) { - int cnt[kActions]; - Seq *seq; - int section = kIdPhase; - - for (int i = 0; i < kDimMax; i++) { - if (_dim[i] != nullptr) { - delete[] _dim[i]; - _dim[i] = nullptr; - } - } + if (!*_file) + return this; - for (int i = 0; i < kDimMax; i++) { - _dim[i] = new Bitmap[_shpCnt]; - for (int j = 0; j < _shpCnt; j++) - _dim[i][j].setVM(_vm); + for (int i = 0; i < kDimMax; i++) { + if (_dim[i] != nullptr) { + delete[] _dim[i]; + _dim[i] = nullptr; } + } + for (int i = 0; i < kDimMax; i++) { + _dim[i] = new Bitmap[_shpCnt]; + for (int j = 0; j < _shpCnt; j++) + _dim[i][j].setVM(_vm); + } - if (_seqCnt) { - seq = new Seq[_seqCnt]; - if (seq == nullptr) + int cnt[kActions], + shpcnt = 0, + seqcnt = 0, + maxnow = 0, + maxnxt = 0; + + for (int i = 0; i < kActions; i++) + cnt[i] = 0; + + for (int i = 0; i < kActions; i++) { + byte n = _actionCtrl[i]._cnt; + if (n) { + _ext->_actions[i] = new CommandHandler::Command[n]; + if (_ext->_actions[i] == nullptr) error("No core %s", fname); } else - seq = nullptr; - - for (int i = 0; i < kActions; i++) - cnt[i] = 0; - - for (int i = 0; i < kActions; i++) { - byte n = _actionCtrl[i]._cnt; - if (n) { - _ext->_actions[i] = new CommandHandler::Command[n]; - if (_ext->_actions[i] == nullptr) - error("No core %s", fname); - } else - _ext->_actions[i] = nullptr; - } + _ext->_actions[i] = nullptr; + } - if (_vm->_resman->exist(fname)) { // sprite description file exist - EncryptedStream sprf(_vm, fname); - if (sprf.err()) - error("Bad SPR [%s]", fname); - - ID id; - Common::String line; - char tmpStr[kLineMax + 1]; - int shpcnt = 0; - int seqcnt = 0; - int maxnow = 0; - int maxnxt = 0; - - for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { - if (line.empty()) - continue; + Seq *curSeq; + if (_seqCnt) { + curSeq = new Seq[_seqCnt]; + if (curSeq == nullptr) + error("No core %s", fname); + } else + curSeq = nullptr; + + if (_vm->_resman->exist(fname)) { // sprite description file exist + EncryptedStream sprf(_vm, fname); + if (sprf.err()) + error("Bad SPR [%s]", fname); + + ID section = kIdPhase; + ID id; + Common::String line; + char tmpStr[kLineMax + 1]; + + for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { + if (line.empty()) + continue; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *p = _vm->token(tmpStr); + + id = _vm->ident(p); + switch (id) { + case kIdNear: + case kIdMTake: + case kIdFTake: + case kIdPhase: + case kIdSeq: + section = id; + break; + case kIdName: Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - - char *p = _vm->token(tmpStr); - - id = _vm->ident(p); - switch (id) { + for (p = tmpStr; *p != '='; p++); // We search for the = + setName(_vm->tail(p)); + break; + default: + if (id >= kIdNear) + break; + Seq *s; + switch (section) { case kIdNear: case kIdMTake: case kIdFTake: - case kIdPhase: - case kIdSeq: - section = id; - break; - case kIdName: - Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - for (p = tmpStr; *p != '='; p++); // We search for the = - setName(_vm->tail(p)); + id = (ID)_vm->_commandHandler->getComId(p); + if (_actionCtrl[section]._cnt) { + CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; + c->_commandType = CommandType(id); + c->_ref = _vm->number(nullptr); + c->_val = _vm->number(nullptr); + c->_spritePtr = nullptr; + } break; - default: - if (id >= kIdNear) - break; - Seq *s; - switch (section) { - case kIdNear: - case kIdMTake: - case kIdFTake: - id = (ID)_vm->_commandHandler->getComId(p); - if (_actionCtrl[section]._cnt) { - CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; - c->_commandType = CommandType(id); - c->_ref = _vm->number(nullptr); - c->_val = _vm->number(nullptr); - c->_spritePtr = nullptr; - } - break; - case kIdSeq: - s = &seq[seqcnt++]; - s->_now = atoi(p); - if (s->_now > maxnow) - maxnow = s->_now; - s->_next = _vm->number(nullptr); - switch (s->_next) { - case 0xFF: - s->_next = seqcnt; - break; - case 0xFE: - s->_next = seqcnt - 1; - break; - } - if (s->_next > maxnxt) - maxnxt = s->_next; - s->_dx = _vm->number(nullptr); - s->_dy = _vm->number(nullptr); - s->_dz = _vm->number(nullptr); - s->_dly = _vm->number(nullptr); + case kIdSeq: + s = &curSeq[seqcnt++]; + s->_now = atoi(p); + if (s->_now > maxnow) + maxnow = s->_now; + s->_next = _vm->number(nullptr); + switch (s->_next) { + case 0xFF: + s->_next = seqcnt; break; - case kIdPhase: - for (int i = 0; i < kDimMax; i++) { - char *q = p; - q[1] = '0' + i; - Bitmap b(_vm, q); - if (!b.moveHi()) - error("No EMS %s", q); - _dim[i][shpcnt] = b; - if (!shpcnt) - _hig[i] = b._h; - } - ++shpcnt; + case 0xFE: + s->_next = seqcnt - 1; break; } + if (s->_next > maxnxt) + maxnxt = s->_next; + s->_dx = _vm->number(nullptr); + s->_dy = _vm->number(nullptr); + s->_dz = _vm->number(nullptr); + s->_dly = _vm->number(nullptr); + break; + case kIdPhase: + for (int i = 0; i < kDimMax; i++) { + char *q = p; + q[1] = '0' + i; + Bitmap b(_vm, q); + if (!b.moveHi()) + error("No EMS %s", q); + _dim[i][shpcnt] = b; + if (!shpcnt) + _hig[i] = b._h; + } + ++shpcnt; + break; + default: + break; } } - if (seq) { - if (maxnow >= shpcnt) - error("Bad PHASE in SEQ %s", fname); - if (maxnxt >= seqcnt) - error("Bad JUMP in SEQ %s", fname); - setSeq(seq); - } else - setSeq(_stdSeq8); - - setShapeList(_dim[0], shpcnt); } + + if (curSeq) { + if (maxnow >= shpcnt) + error("Bad PHASE in SEQ %s", fname); + if (maxnxt >= seqcnt) + error("Bad JUMP in SEQ %s", fname); + setSeq(curSeq); + } else + setSeq(_stdSeq8); + + setShapeList(_dim[0], shpcnt); } + + Common::String str(_vm->_text->getText(_ref + 100)); + char text[kLineMax + 1]; + strcpy(text, str.c_str()); _reachStart = atoi(_vm->token(text)); _reachCycle = atoi(_vm->token(nullptr)); _sayStart = atoi(_vm->token(nullptr)); _funStart = atoi(_vm->token(nullptr)); _funDel = _funDel0 = (72 / _ext->_seq[0]._dly) * atoi(_vm->token(nullptr)); + int i = stepSize() / 2; _maxDist = sqrt(double(i * i * 2)); setCurrent(); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index b3552686c8..5f3cf18523 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -278,14 +278,6 @@ Sprite *Sprite::expand() { maxnow = 0, maxnxt = 0; - Seq *curSeq; - if (_seqCnt) { - curSeq = new Seq[_seqCnt]; - if (curSeq == nullptr) - error("No core %s", fname); - } else - curSeq = nullptr; - for (int i = 0; i < kActions; i++) cnt[i] = 0; @@ -299,6 +291,14 @@ Sprite *Sprite::expand() { _ext->_actions[i] = nullptr; } + Seq *curSeq; + if (_seqCnt) { + curSeq = new Seq[_seqCnt]; + if (curSeq == nullptr) + error("No core %s", fname); + } else + curSeq = nullptr; + if (_vm->_resman->exist(fname)) { // sprite description file exist EncryptedStream sprf(_vm, fname); if (sprf.err()) @@ -376,13 +376,12 @@ Sprite *Sprite::expand() { s->_dz = _vm->number(nullptr); s->_dly = _vm->number(nullptr); break; - case kIdPhase: { + case kIdPhase: shplist[shpcnt] = Bitmap(_vm, p); if (!shplist[shpcnt].moveHi()) error("No EMS"); shpcnt++; break; - } default: break; } -- cgit v1.2.3 From b33653000da25846bebe7a76c26337d49743884d Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 16:13:29 +0200 Subject: CGE2: Fix saving of moving heroes. --- engines/cge2/saveload.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index c505358973..652dbea1ec 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -230,6 +230,11 @@ void CGE2Engine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &h uint8 thumbPalette[256 * 3]; g_system->getPaletteManager()->grabPalette(thumbPalette, 0, 256); + // Stop the heroes from moving and redraw them before taking the picture. + for (int i = 0; i < 2; i++) + _heroTab[i]->_ptr->park(); + _vga->show(); + // Create a thumbnail and save it Graphics::Surface *thumb = new Graphics::Surface(); Graphics::Surface *s = _vga->_page[0]; -- cgit v1.2.3 From fc8f6d9cfef1345774ef3dc4a0193033597a4b04 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 16:27:18 +0200 Subject: CGE2: Fix initialization of volume switches. --- engines/cge2/cge2.h | 1 + engines/cge2/toolbar.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 05afd2640d..38b48aaa23 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -218,6 +218,7 @@ public: void switchSay(); void checkSaySwitch(); void initToolbar(); + void initVolumeSwitch(Sprite *volSwitch); void checkSounds(); diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 2604a2fee7..51614af8ed 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -281,9 +281,16 @@ void CGE2Engine::initToolbar() { _vol[1] = _vga->_showQ->locate(kMvolRef); if (_vol[0]) - _vol[0]->step(ConfMan.getInt("sfx_volume") / kSoundNumtoStateRate); + initVolumeSwitch(_vol[0]); if (_vol[1]) - _vol[1]->step(ConfMan.getInt("music_volume") / kSoundNumtoStateRate); + initVolumeSwitch(_vol[1]); +} + +void CGE2Engine::initVolumeSwitch(Sprite *volSwitch) { + int state = 0; + if (!ConfMan.getBool("mute")) + state = ConfMan.getInt("sfx_volume") / kSoundNumtoStateRate; + volSwitch->step(state); } } // End of namespace CGE2 -- cgit v1.2.3 From 4e32736e44a7bd90e34608d2ec7764b2ed260f52 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 16:41:56 +0200 Subject: CGE2: Prevent the engine from entering an endless loop when loading. Also remove CommandHandler::reset(), since it's not useful anymore. --- engines/cge2/saveload.cpp | 3 ++- engines/cge2/snail.cpp | 4 ---- engines/cge2/snail.h | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 652dbea1ec..b984a48e57 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -317,6 +317,8 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { } Common::Error CGE2Engine::loadGameState(int slot) { + _commandHandler->clear(); + _commandHandlerTurbo->clear(); sceneDown(); if (!loadGame(slot)) return Common::kReadingFailed; @@ -329,7 +331,6 @@ void CGE2Engine::resetGame() { busy(false); _spare->clear(); _vga->_showQ->clear(); - _commandHandler->reset(); loadScript("CGE.INI", true); delete _infoLine; _infoLine = new InfoLine(this, kInfoW); diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 54ef036dc3..48e8ffdb70 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -749,10 +749,6 @@ bool CommandHandler::idle() { return (!_vm->_waitRef && _head == _tail); } -void CommandHandler::reset() { - _tail = _head; -} - void CommandHandler::clear() { _tail = _head; _vm->killText(); diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h index 82df181878..7e618daac8 100644 --- a/engines/cge2/snail.h +++ b/engines/cge2/snail.h @@ -112,7 +112,6 @@ public: void addCallback(CommandType com, int ref, int val, CallbackType cbType); void insertCommand(CommandType com, int ref, int val, void *ptr); bool idle(); - void reset(); void clear(); int getComId(const char *com); const char *getComStr(CommandType cmdType); -- cgit v1.2.3 From 0b8a727a0e7538f4dd4040b3d741532fcac41920 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 18:42:00 +0200 Subject: CGE2: Repair computation of save checksum. --- engines/cge2/saveload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index b984a48e57..78a0631136 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -42,7 +42,7 @@ namespace CGE2 { -#define kSavegameCheckSum (1997 + _now + _music + kWorldHeight) +#define kSavegameCheckSum (1997 + _now + kWorldHeight) #define kBadSVG 99 struct SavegameHeader { -- cgit v1.2.3 From e5139cdd9cca259f22f47b2f55a15f4b32e0f047 Mon Sep 17 00:00:00 2001 From: uruk Date: Tue, 29 Jul 2014 20:59:29 +0200 Subject: CGE2: Fix loading during gameplay. --- engines/cge2/saveload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 78a0631136..63abe3abf9 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -323,6 +323,7 @@ Common::Error CGE2Engine::loadGameState(int slot) { if (!loadGame(slot)) return Common::kReadingFailed; sceneUp(_now); + initToolbar(); return Common::kNoError; } @@ -379,7 +380,6 @@ bool CGE2Engine::loadGame(int slotNumber) { syncSpeechSettings(); loadHeroes(); - initToolbar(); return true; } -- cgit v1.2.3 From 4139e79fccbc47c4d291371c8baf79b6e143eb62 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 29 Jul 2014 20:23:02 -0400 Subject: CGE2: Fixes for the FXP class --- engines/cge2/vga13h.cpp | 3 +- engines/cge2/vga13h.h | 78 ++++++++++++------------------------------------- 2 files changed, 20 insertions(+), 61 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 5f3cf18523..105fd3f5ad 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -46,8 +46,7 @@ void V3D::sync(Common::Serializer &s) { } void FXP::sync(Common::Serializer &s) { - s.syncAsUint16LE(f); - s.syncAsSint16LE(i); + s.syncAsSint32LE(v); } Seq *getConstantSeq(bool seqFlag) { diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 3ed5fd559f..f3354c5489 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -53,68 +53,28 @@ namespace CGE2 { // From FXP.H class FXP { // fixed point - uint16 f; - int16 i; - long getJoined() const { - long ret = 0; - ret += f; - ret += i << 16; - return ret; - } - void setJoined(long joined) { - i = joined >> 16; - f = joined; - } + int32 v; public: - FXP (void): f(0), i(0) { } - FXP (int i0, int f0 = 0) : i(i0), f(0) { } - FXP& operator=(const int& x) { i = x; f = 0; return *this; } - FXP operator+(const FXP& x) const { FXP y; y.setJoined(getJoined() + x.getJoined()); return y; } - FXP operator-(const FXP& x) const { FXP y; y.setJoined(getJoined() - x.getJoined()); return y; } - FXP operator*(const FXP& x) const { - FXP y; long t; - y.i = i * x.i; - t = ((long) f * x.f) >> 16; - t += ((long) i * x.f) + ((long) f * x.i); - y.f = t & 0xFFFF; - y.i += t >> 16; - return y; - } - FXP operator/(const FXP& x) const { - FXP y; bool sign = false; - if (!x.empty()) { - long j = getJoined(), jx = x.getJoined(); - if (j < 0) { - j = -j; - sign ^= 1; - } - if (jx < 0) { - jx = -jx; - sign ^= 1; - } - y.i = signed(j / jx); - long r = j - jx * y.i; - //-- binary division - y.f = unsigned((r << 4) / (jx >> 12)); - //------------------ - if (sign) - y.setJoined(-y.getJoined()); - } + FXP(void) : v(0) {} + FXP (int i0, int f0 = 0) : v((i0 * 256) + ((i0 < 0) ? -f0 : f0)) {} + FXP& operator=(const int& x) { v = x << 8; return *this; } + FXP operator+(const FXP& x) const { FXP y; y.v = v + x.v; return y; } + FXP operator-(const FXP& x) const { FXP y; y.v = v - x.v; return y; } + FXP operator*(const FXP& x) const { FXP y; y.v = v * x.v / 256; return y; } + FXP operator/(const FXP& x) const { FXP y; y.v = (x.v == 0) ? 0 : v * 256 / x.v; return y; } - return y; - } //int& operator = (int& a, const FXP& b) { return a = b.i; } - friend int& operator+=(int& a, const FXP& b) { return a += b.i; } - friend int& operator-=(int& a, const FXP& b) { return a -= b.i; } - friend FXP& operator+=(FXP& a, const int& b) { a.i += b; return a; } - friend FXP& operator-=(FXP& a, const int& b) { a.i -= b; return a; } - friend bool operator==(const FXP &a, const FXP &b) { return (a.i == b.i) && (a.f == b.f); } - friend bool operator!=(const FXP &a, const FXP &b) { return (a.i != b.i) || (a.f != b.f); } - friend bool operator<(const FXP &a, const FXP &b) { return (a.i < b.i) || ((a.i == b.i) && (a.f < b.f)); } - friend bool operator>(const FXP &a, const FXP &b) { return (a.i > b.i) || ((a.i == b.i) && (a.f > b.f)); } - int trunc(void) const { return i; } - int round(void) const { return i + (f > 0x7FFF); } - bool empty() const { return i == 0 && f == 0; } + friend int& operator+=(int& a, const FXP& b) { return a += b.trunc(); } + friend int& operator-=(int& a, const FXP& b) { return a -= b.trunc(); } + friend FXP& operator+=(FXP& a, const int& b) { a.v += b << 8; return a; } + friend FXP& operator-=(FXP& a, const int& b) { a.v -= b << 8; return a; } + friend bool operator==(const FXP &a, const FXP &b) { return a.v == b.v; } + friend bool operator!=(const FXP &a, const FXP &b) { return a.v != b.v; } + friend bool operator<(const FXP &a, const FXP &b) { return a.v < b.v; } + friend bool operator>(const FXP &a, const FXP &b) { return a.v > b.v; } + int trunc(void) const { return v >> 8; } + int round(void) const { return (v + 0x80) >> 8; } + bool empty() const { return v == 0; } void sync(Common::Serializer &s); }; -- cgit v1.2.3 From 6b48172ae1b6fe1f40709b7d70283deaed9bf86d Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 30 Jul 2014 09:01:18 +0200 Subject: CGE2: Disable checking the sound options while the intro animation is running. Since there are no toolbar during the intro, checking it's buttons would cause a crash. --- engines/cge2/cge2_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9bdd57a50c..c1a47b8000 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -523,7 +523,8 @@ void CGE2Engine::showBak(int ref) { } void CGE2Engine::mainLoop() { - checkSounds(); + if (_startupMode == 0) + checkSounds(); _vga->show(); _commandHandlerTurbo->runCommand(); -- cgit v1.2.3 From 06144cee4bcdcba00550b9bbee391f1ef22479fd Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 30 Jul 2014 09:05:07 +0200 Subject: CGE2: Remove dummies from save header and change save checksum. The old saves are broken by our new FXP implementation anyway. --- engines/cge2/saveload.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 63abe3abf9..4a9da882d5 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -42,7 +42,7 @@ namespace CGE2 { -#define kSavegameCheckSum (1997 + _now + kWorldHeight) +#define kSavegameCheckSum (1997 + _now + _sex + kWorldHeight) #define kBadSVG 99 struct SavegameHeader { @@ -291,17 +291,11 @@ void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteS } void CGE2Engine::syncHeader(Common::Serializer &s) { - int dummy = 0; - s.syncAsUint16LE(_now); s.syncAsUint16LE(_sex); s.syncAsUint16LE(_vga->_rot._len); s.syncAsUint16LE(_waitSeq); s.syncAsUint16LE(_waitRef); - s.syncAsUint16LE(dummy); // _sayCap - s.syncAsUint16LE(dummy); // _sayVox - for (int i = 0; i < 4; i++) - s.syncAsUint16LE(dummy); // _flag if (s.isSaving()) { // Write checksum -- cgit v1.2.3 From 733f72d810b6f28992e1b9d42050544ade35da14 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 30 Jul 2014 19:15:59 +0200 Subject: CGE2: Fix sunset() and sunrise(). Now they really do the fade-in/fade-out effect. --- engines/cge2/vga13h.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 105fd3f5ad..9340abf09e 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -994,6 +994,7 @@ void Vga::sunrise(Dac *tab) { setColors(tab, i); waitVR(); updateColors(); + g_system->updateScreen(); } } @@ -1004,6 +1005,7 @@ void Vga::sunset() { setColors(tab, i); waitVR(); updateColors(); + g_system->updateScreen(); } } -- cgit v1.2.3 From 6a38671cc27e91e9da9d0e214a8da639546b1d9e Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 30 Jul 2014 19:34:37 +0200 Subject: CGE2: Rearrange showTitle() and add some delay to the display. Now the splash screen doesn't vanish almost immediately right after it's drawn. --- engines/cge2/cge2_main.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index c1a47b8000..b4dd812079 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -808,16 +808,15 @@ bool CGE2Engine::showTitle(const char *name) { Sprite D(this, LB, 1); D._flags._kill = true; D.gotoxyz(kScrWidth >> 1, -(kPanHeight >> 1)); - _vga->sunset(); + _vga->sunset(); D.show(2); - _vga->copyPage(1, 2); _vga->copyPage(0, 1); - _vga->sunrise(_vga->_sysPal); - _vga->update(); + + g_system->delayMillis(2500); return true; } -- cgit v1.2.3 From 6d278157e16927f483d6cc397c0fe2d959cf22bb Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 30 Jul 2014 21:13:47 +0200 Subject: CGE2: Comment out delay in the splash screen during testing. --- engines/cge2/cge2_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index b4dd812079..127405a89d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -816,8 +816,9 @@ bool CGE2Engine::showTitle(const char *name) { _vga->sunrise(_vga->_sysPal); _vga->update(); +#if 0 g_system->delayMillis(2500); - +#endif return true; } -- cgit v1.2.3 From 0d662566bd2706919e8ed9c7abf79c5f0767f591 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 1 Aug 2014 11:16:39 -0400 Subject: CGE2: Further fixes to FXP operators to fix pathfinding --- engines/cge2/vga13h.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ engines/cge2/vga13h.h | 4 ++-- 2 files changed, 47 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 9340abf09e..cdf683d380 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -45,6 +45,51 @@ void V3D::sync(Common::Serializer &s) { _z.sync(s); } +FXP FXP::operator*(const FXP& x) const { + FXP y; + int32 t1 = (v >> 8) * x.v; + int32 t2 = (v & 0xFF) * x.v; + + y.v = t1 + t2; + return y; +} + +FXP FXP::operator/(const FXP& x) const { + FXP y; + if (x.v != 0) { + int32 v1 = this->v; + int32 v2 = x.v; + bool negFlag = false; + + if (v1 < 0) { + v1 = -v1; + negFlag = true; + } + if (v2 < 0) { + v2 = -v2; + negFlag ^= true; + } + + int32 v3 = v1 / v2; + v1 -= v3 * v2; + v3 <<= 8; + + if (v1 < 0xFFFFFF) { + v1 <<= 8; + } else { + v2 >>= 8; + } + v3 += v1 / v2; + + if (negFlag) + v3 = -v3; + + y.v = v3; + } + + return y; +} + void FXP::sync(Common::Serializer &s) { s.syncAsSint32LE(v); } diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index f3354c5489..52efd39849 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -60,8 +60,8 @@ public: FXP& operator=(const int& x) { v = x << 8; return *this; } FXP operator+(const FXP& x) const { FXP y; y.v = v + x.v; return y; } FXP operator-(const FXP& x) const { FXP y; y.v = v - x.v; return y; } - FXP operator*(const FXP& x) const { FXP y; y.v = v * x.v / 256; return y; } - FXP operator/(const FXP& x) const { FXP y; y.v = (x.v == 0) ? 0 : v * 256 / x.v; return y; } + FXP operator*(const FXP& x) const; + FXP operator/(const FXP& x) const; //int& operator = (int& a, const FXP& b) { return a = b.i; } friend int& operator+=(int& a, const FXP& b) { return a += b.trunc(); } -- cgit v1.2.3 From c012c762d014c4c77ab5165b0c45b3c51ec34149 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 1 Aug 2014 19:22:12 +0200 Subject: CGE2: Remove moveHi() and moveLo() from bitmap --- engines/cge2/bitmap.cpp | 14 +++----------- engines/cge2/bitmap.h | 2 -- engines/cge2/hero.cpp | 2 -- engines/cge2/vga13h.cpp | 9 +++------ 4 files changed, 6 insertions(+), 21 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 2c7c010d53..6629919118 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -398,16 +398,6 @@ void Bitmap::xLatPos(V2D& p) { p.y = kWorldHeight - p.y - _h; } -bool Bitmap::moveHi() { - // No implementation needed in ScummVM - return true; -} - -bool Bitmap::moveLo() { - // No implementation needed in ScummVM - return true; -} - #define _ kPixelTransp, #define L 1, #define G 2, @@ -466,9 +456,11 @@ uint8 *Bitmap::makeSpeechBubbleTail(int which, uint8 colorSet[][4]) { break; } - for (int i = 0; i < kDesignSize; i++) + for (int i = 0; i < kDesignSize; i++) { if (des[i] >= 1 && des[i] <= 3) des[i] = colorSet[kCBSay][des[i]]; + } + return des; } diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 8643c37467..30b8f487c5 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -82,8 +82,6 @@ public: void show(V2D pos); bool solidAt(V2D pos); void xLatPos(V2D& p); - bool moveHi(); - bool moveLo(); static uint8 *makeSpeechBubbleTail(int des, uint8 colorSet[][4]); }; diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 0b8e227590..821b7386ee 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -173,8 +173,6 @@ Sprite *Hero::expand() { char *q = p; q[1] = '0' + i; Bitmap b(_vm, q); - if (!b.moveHi()) - error("No EMS %s", q); _dim[i][shpcnt] = b; if (!shpcnt) _hig[i] = b._h; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index cdf683d380..1895c319dc 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -422,8 +422,6 @@ Sprite *Sprite::expand() { break; case kIdPhase: shplist[shpcnt] = Bitmap(_vm, p); - if (!shplist[shpcnt].moveHi()) - error("No EMS"); shpcnt++; break; default: @@ -957,11 +955,11 @@ uint8 Vga::closest(Dac *pal, const uint8 colR, const uint8 colG, const uint8 col uint8 Vga::closest(Dac *pal, Dac x) { int exp = (sizeof(long) * 8 - 1); - long D = (1 << exp) - 1; // Maximume value of long. + long D = (1 << exp) - 1; // Maximum value of long. long R = x._r; long G = x._g; long B = x._b; - int idx; + int idx = 255; for (int n = 0; n < 256; n++) { long dR = R - pal[n]._r; long dG = G - pal[n]._g; @@ -980,8 +978,7 @@ uint8 Vga::closest(Dac *pal, Dac x) { uint8 *Vga::glass(Dac *pal, const uint8 colR, const uint8 colG, const uint8 colB) { uint8 *x = (uint8 *)malloc(256); if (x) { - uint16 i; - for (i = 0; i < 256; i++) { + for (uint16 i = 0; i < 256; i++) { x[i] = closest(pal, ((uint16)(pal[i]._r) * colR) / 255, ((uint16)(pal[i]._g) * colG) / 255, ((uint16)(pal[i]._b) * colB) / 255); -- cgit v1.2.3 From 1a49887855d4b0075fa87203f3403250b308429b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 1 Aug 2014 19:36:24 +0200 Subject: CGE2: Some cosmetic changes --- engines/cge2/cge2.cpp | 26 +++++++++++++++----------- engines/cge2/cge2.h | 2 ++ engines/cge2/cge2_main.cpp | 28 ++++++++++++++++------------ 3 files changed, 33 insertions(+), 23 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index f175fceced..f938b8b87f 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -115,18 +115,20 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) void CGE2Engine::init() { // Create debugger console _console = new CGE2Console(this); - _resman = new ResourceManager(); _vga = new Vga(this); _fx = new Fx(this, 16); _sound = new Sound(this); _midiPlayer = new MusicPlayer(this); _text = new Text(this, "CGE"); + for (int i = 0; i < 2; i++) _heroTab[i] = new HeroTab(this); + _eye = new V3D(); for (int i = 0; i < kSceneMax; i++) _eyeTab[i] = new V3D(); + _spare = new Spare(this); _commandHandler = new CommandHandler(this, false); _commandHandlerTurbo = new CommandHandler(this, true); @@ -134,12 +136,13 @@ void CGE2Engine::init() { _infoLine = new InfoLine(this, kInfoW); _mouse = new Mouse(this); _keyboard = new Keyboard(this); + for (int i = 0; i < kMaxPoint; i++) _point[i] = new V3D(); + _sys = new System(this); _eventManager = new EventManager(this); _map = new Map(this); - _startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; } @@ -156,11 +159,13 @@ void CGE2Engine::deinit() { delete _sound; delete _midiPlayer; delete _text; + for (int i = 0; i < 2; i++) delete _heroTab[i]; - for (int i = 0; i < kSceneMax; i++) { + + for (int i = 0; i < kSceneMax; i++) delete _eyeTab[i]; - } + delete _eye; delete _commandHandler; delete _commandHandlerTurbo; @@ -168,20 +173,20 @@ void CGE2Engine::deinit() { delete _infoLine; delete _mouse; delete _keyboard; + if (_talk != nullptr) delete _talk; - for (int i = 0; i < kMaxPoint; i++) { + + for (int i = 0; i < kMaxPoint; i++) delete _point[i]; - } + delete _sys; delete _eventManager; delete _map; } bool CGE2Engine::hasFeature(EngineFeature f) const { - return - (f == kSupportsLoadingDuringRuntime) || - (f == kSupportsSavingDuringRuntime); + return (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime); } Common::Error CGE2Engine::run() { @@ -190,10 +195,9 @@ Common::Error CGE2Engine::run() { initGraphics(kScrWidth, kScrHeight, false); init(); - cge2_main(); - deinit(); + return Common::kNoError; } diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 38b48aaa23..4043f15b16 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -282,10 +282,12 @@ public: bool _dark; int _waitSeq; int _waitRef; + struct { int *_wait; int _ref[2]; } _soundStat; + bool _taken; bool _endGame; int _req; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 127405a89d..f3dad8bdec 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -134,9 +134,8 @@ char *CGE2Engine::tail(char *s) { int CGE2Engine::takeEnum(const char **tab, const char *text) { if (text) { for (const char **e = tab; *e; e++) { - if (scumm_stricmp(text, *e) == 0) { + if (scumm_stricmp(text, *e) == 0) return e - tab; - } } } return -1; @@ -158,8 +157,10 @@ Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) int shpcnt = 0; int seqcnt = 0; int cnt[kActions]; + for (int i = 0; i < kActions; i++) cnt[i] = 0; + ID section = kIdPhase; bool frnt = true; bool east = false; @@ -184,8 +185,7 @@ Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); - char *p; - p = token(tmpStr); + char *p = token(tmpStr); if (*p == '@') { if (label != kNoByte) badLab(fname); @@ -272,7 +272,7 @@ Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) } else // No sprite description: mono-shaped sprite with only .BMP file. ++shpcnt; - // Make sprite of choosen type: + // Make sprite of chosen type: Sprite *sprite = nullptr; char c = *fname | 0x20; if (c >= 'a' && c <= 'z' && fname[1] == '0' && fname[2] == '\0') { @@ -374,8 +374,9 @@ void CGE2Engine::loadScript(const char *fname, bool onlyToolbar) { _spare->dispose(sprite); else delete sprite; + if (_spare->count() == n) - error("Durplicated reference! %s", SpN); + error("Duplicate reference! %s", SpN); } } @@ -397,12 +398,12 @@ void CGE2Engine::movie(const char *ext) { _now = atoi(ext + 2); loadScript(fn); sceneUp(_now); - _keyboard->setClient(_sys); + while (!_commandHandler->idle() && !_quitFlag) mainLoop(); - _keyboard->setClient(nullptr); + _keyboard->setClient(nullptr); _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); _spare->clear(); @@ -445,10 +446,10 @@ void CGE2Engine::sceneUp(int cav) { if (!_dark) _vga->sunset(); + _vga->show(); _vga->copyPage(1, 0); _vga->show(); - _vga->sunrise(_vga->_sysPal); _dark = false; @@ -463,12 +464,15 @@ void CGE2Engine::sceneDown() { busy(true); _soundStat._wait = nullptr; // unlock snail Sprite *spr = _vga->_showQ->locate((_now << 8) | 254); + if (spr) feedSnail(spr, kNear, _heroTab[_sex]->_ptr); + while (!(_commandHandler->idle() && _commandHandlerTurbo->idle())) { _commandHandlerTurbo->runCommand(); _commandHandler->runCommand(); } + closePocket(); for (int i = 0; i < 2; i++) _spare->update(_vga->_showQ->remove(_heroTab[i]->_ptr)); @@ -480,10 +484,9 @@ void CGE2Engine::switchScene(int scene) { return; _req = scene; - storeHeroPos(); - *(_eyeTab[_now]) = *_eye; + if (scene < 0) _commandHandler->addCallback(kCmdExec, -1, 0, kQGame); // quit game else { @@ -630,7 +633,6 @@ void CGE2Engine::runGame() { return; loadUser(); - sceneUp(_now); initToolbar(); @@ -837,6 +839,7 @@ void CGE2Engine::switchHero(int sex) { _sys->_blinkSprite->_flags._hide = false; _sys->_blinkSprite = nullptr; } + if (scene >= 0) { _commandHandler->addCommand(kCmdSeq, -1, 2, _heroTab[_sex]->_face); _sex ^= 1; @@ -875,6 +878,7 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { if (_vm->_sex == sex) { if (_vm->_sys->_blinkSprite) _vm->_sys->_blinkSprite->_flags._hide = false; + if (_vm->_sys->_blinkSprite == this) _vm->_sys->_blinkSprite = nullptr; else -- cgit v1.2.3 From 96ab1d5d83950e764be4e13248584498e4d79c7c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Aug 2014 10:23:43 -0400 Subject: CGE2: Further FXP multiply fix to fix hero scaling --- engines/cge2/vga13h.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 1895c319dc..33d5ba1335 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -48,7 +48,7 @@ void V3D::sync(Common::Serializer &s) { FXP FXP::operator*(const FXP& x) const { FXP y; int32 t1 = (v >> 8) * x.v; - int32 t2 = (v & 0xFF) * x.v; + int32 t2 = ((v & 0xFF) * x.v) >> 8; y.v = t1 + t2; return y; -- cgit v1.2.3 From 0eb7e52490b3b7c66f68e65d65a9880fa7e13492 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 2 Aug 2014 19:04:41 +0200 Subject: CGE2: Update comment concerning a workaround for a non-fixable issue --- engines/cge2/fileio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 41ea1c1105..73b6cdab54 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -157,7 +157,7 @@ BtKeypack *ResourceManager::find(const char *key) { break; } - // FIXME: Terrible hack to work around a mix between 24piram_ and 24pirami + // Hack to work around a mix between 24piram_ and 24pirami if (!strcmp(key, "24piram_.SPR") && (scumm_stricmp((const char *)key, (const char *)pg->_leaf[i]._key) < 0)) ++i; // -- cgit v1.2.3 From 3376ab4f622c0ff1998bfe792efa9e030783b047 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 2 Aug 2014 19:05:30 +0200 Subject: CGE2: Update the comment about another non-fixable workaround --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f3dad8bdec..6a6066e10d 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -890,7 +890,7 @@ void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { } else { // sprite NOT in pocket Hero *h = _vm->_heroTab[_vm->_sex]->_ptr; if (!_vm->_talk) { - // HACK: the "+3" is a ugly hack used to compensate a pathfinding issue. To be fixed!! + // the "+3" is a hack used to work around a script issue in scene 5 if ((_ref & 0xFF) < 200 && h->distance(this) > (h->_maxDist << 1) + 3) h->walkTo(this); else if (_vm->_sys->_blinkSprite) { -- cgit v1.2.3 From f2de89c7bc3be8c6e77946c005ea7973276b5e0f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 2 Aug 2014 22:26:00 +0200 Subject: CGE2: Fix CppCheck warnings by reducing variable scope --- engines/cge2/hero.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 821b7386ee..3bb7c82713 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -72,11 +72,7 @@ Sprite *Hero::expand() { _dim[i][j].setVM(_vm); } - int cnt[kActions], - shpcnt = 0, - seqcnt = 0, - maxnow = 0, - maxnxt = 0; + int cnt[kActions]; for (int i = 0; i < kActions; i++) cnt[i] = 0; @@ -108,6 +104,10 @@ Sprite *Hero::expand() { ID id; Common::String line; char tmpStr[kLineMax + 1]; + int shpcnt = 0; + int seqcnt = 0; + int maxnow = 0; + int maxnxt = 0; for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { if (line.empty()) -- cgit v1.2.3 From d44ff5491281fb9bcd4cc8f4534988b0b2bcb052 Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 2 Aug 2014 23:17:25 +0200 Subject: CGE2: Fix error message in makeSpeechBubbleTail(). --- engines/cge2/bitmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 6629919118..60e7a80945 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -452,7 +452,7 @@ uint8 *Bitmap::makeSpeechBubbleTail(int which, uint8 colorSet[][4]) { memcpy(des, kSRDesign, sizeof(kSRDesign)); break; default: - error("Wrong parameter in Bitmap::paint!"); + error("Wrong parameter in Bitmap::makeSpeechBubbleTail!"); break; } -- cgit v1.2.3 From 9dc06870e79edd637280ef9a81391adca1eafabc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Aug 2014 01:49:59 +0200 Subject: CGE2: Start removing the checks on the return value of new --- engines/cge2/bitmap.cpp | 12 ++---------- engines/cge2/cge2_main.cpp | 9 +++------ engines/cge2/events.cpp | 3 +-- engines/cge2/hero.cpp | 17 +++++------------ engines/cge2/vga13h.cpp | 19 ++++--------------- 5 files changed, 15 insertions(+), 45 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 60e7a80945..289e156ee8 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -84,7 +84,6 @@ Bitmap::Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill) uint16 psiz = _h * lsiz; // - last gape, but + plane trailer uint8 *v = new uint8[4 * psiz + _h * sizeof(*_b)];// the same for 4 planes // + room for wash table - assert(v != nullptr); WRITE_LE_UINT16(v, (kBmpCPY | dsiz)); // data chunk hader memset(v + 2, fill, dsiz); // data bytes @@ -122,7 +121,6 @@ Bitmap::Bitmap(CGE2Engine *vm, const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _v(n uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = new uint8[siz]; - assert(v1 != nullptr); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); } @@ -149,13 +147,10 @@ Bitmap &Bitmap::operator=(const Bitmap &bmp) { delete[] _v; _v = nullptr; - if (v0 == nullptr) { - _v = nullptr; - } else { + if (v0) { uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = new uint8[siz]; - assert(v1 != nullptr); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); } @@ -265,8 +260,6 @@ BitmapPtr Bitmap::code(uint8 *map) { uint16 sizV = (uint16)(im - 2 - _v); _v = new uint8[sizV + _h * sizeof(*_b)]; - assert(_v != nullptr); - _b = (HideDesc *)(_v + sizV); } cnt = 0; @@ -383,8 +376,7 @@ bool Bitmap::loadVBM(EncryptedStream *f) { f->seek(f->pos() + kPalSize); } } - if ((_v = new uint8[n]) == nullptr) - return false; + _v = new uint8[n]; if (!f->err()) f->read(_v, n); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 6a6066e10d..e945fbfdec 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -277,14 +277,11 @@ Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) char c = *fname | 0x20; if (c >= 'a' && c <= 'z' && fname[1] == '0' && fname[2] == '\0') { h = new Hero(this); - if (h) { - h->gotoxyz(pos); - sprite = h; - } + h->gotoxyz(pos); + sprite = h; } else { sprite = new Sprite(this); - if (sprite) - sprite->gotoxyz(pos); + sprite->gotoxyz(pos); } if (sprite) { diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index ccddc25505..cf6d3b0b61 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -166,9 +166,8 @@ void Mouse::on() { void Mouse::off() { if (_seqPtr == 0) { - if (_exist) { + if (_exist) _active = false; - } step(1); if (_busy) diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 3bb7c82713..91f6354ce3 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -53,9 +53,8 @@ Sprite *Hero::expand() { if (_ext != nullptr) delete _ext; + _ext = new SprExt(_vm); - if (_ext == nullptr) - error("No core %s", fname); if (!*_file) return this; @@ -79,21 +78,15 @@ Sprite *Hero::expand() { for (int i = 0; i < kActions; i++) { byte n = _actionCtrl[i]._cnt; - if (n) { + if (n) _ext->_actions[i] = new CommandHandler::Command[n]; - if (_ext->_actions[i] == nullptr) - error("No core %s", fname); - } else + else _ext->_actions[i] = nullptr; } - Seq *curSeq; - if (_seqCnt) { + Seq *curSeq = nullptr; + if (_seqCnt) curSeq = new Seq[_seqCnt]; - if (curSeq == nullptr) - error("No core %s", fname); - } else - curSeq = nullptr; if (_vm->_resman->exist(fname)) { // sprite description file exist EncryptedStream sprf(_vm, fname); diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 33d5ba1335..03e6b3fe93 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -224,7 +224,6 @@ void Sprite::setName(char *newName) { } if (newName) { _ext->_name = new char[strlen(newName) + 1]; - assert(_ext->_name != nullptr); strcpy(_ext->_name, newName); } } @@ -308,8 +307,6 @@ Sprite *Sprite::expand() { if (_ext != nullptr) delete _ext; _ext = new SprExt(_vm); - if (_ext == nullptr) - error("No core %s", fname); if (!*_file) return this; @@ -327,21 +324,15 @@ Sprite *Sprite::expand() { for (int i = 0; i < kActions; i++){ byte n = _actionCtrl[i]._cnt; - if (n) { + if (n) _ext->_actions[i] = new CommandHandler::Command[n]; - if (_ext->_actions[i] == nullptr) - error("No core %s", fname); - } else + else _ext->_actions[i] = nullptr; } - Seq *curSeq; - if (_seqCnt) { + Seq *curSeq = nullptr; + if (_seqCnt) curSeq = new Seq[_seqCnt]; - if (curSeq == nullptr) - error("No core %s", fname); - } else - curSeq = nullptr; if (_vm->_resman->exist(fname)) { // sprite description file exist EncryptedStream sprf(_vm, fname); @@ -698,11 +689,9 @@ BitmapPtr Sprite::ghost() { return nullptr; BitmapPtr bmp = new Bitmap(_vm, 0, 0, (uint8 *)nullptr); - assert(bmp != nullptr); bmp->_w = e->_b1->_w; bmp->_h = e->_b1->_h; bmp->_b = new HideDesc[bmp->_h]; - assert(bmp->_b != nullptr); memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc)* bmp->_h); uint8 *v = new uint8; *v = (e->_p1.y << 16) + e->_p1.x; -- cgit v1.2.3 From 2b60bb9cc376f9e8e7866f07cb2012a6bf748914 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 09:27:36 +0200 Subject: CGE2: Fix possible null pointer dereference. --- engines/cge2/vga13h.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 03e6b3fe93..812aabf8f3 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -664,9 +664,10 @@ void Sprite::show() { e->_b0 = e->_b1; e->_p1 = _pos2D; e->_b1 = getShp(); + + if (!_flags._hide) + e->_b1->show(e->_p1); } - if (!_flags._hide) - e->_b1->show(e->_p1); } void Sprite::show(uint16 pg) { -- cgit v1.2.3 From 6558581d68c740d380e695cb9c150c81fc082bb8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Aug 2014 10:32:28 +0200 Subject: CGE2: Remove more checks on the return value of new --- engines/cge2/talk.cpp | 3 --- engines/cge2/text.cpp | 12 ++++-------- engines/cge2/vmenu.cpp | 15 +++++++-------- 3 files changed, 11 insertions(+), 19 deletions(-) (limited to 'engines') diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index f6321d3e59..dbdfc0d7ca 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -48,7 +48,6 @@ Font::Font(CGE2Engine *vm) : _vm(vm) { _pos = new uint16[kPosSize]; _widthArr = new uint8[kWidSize]; - assert((_map != nullptr) && (_pos != nullptr) && (_widthArr != nullptr)); load(); } @@ -136,8 +135,6 @@ uint8 *Talk::box(V2D siz) { if (siz.y < 8) siz.y = 8; uint8 *b = new uint8[n = siz.area()]; - if (!b) - error("No core!"); memset(b, bg, n); if (_mode) { diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 9989dabbf4..ca4c33625e 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -140,8 +140,6 @@ void Text::say(const char *text, Sprite *spr) { _vm->killText(); _vm->_talk = new Talk(_vm, text, kTBRound, kCBSay); - if (!_vm->_talk) - return; Speaker *speaker = new Speaker(_vm); @@ -186,12 +184,10 @@ void Text::say(const char *text, Sprite *spr) { void CGE2Engine::inf(const char *text, ColorBank col) { killText(); _talk = new Talk(this, text, kTBRect, col, true); - if (_talk) { - _talk->_flags._kill = true; - _talk->setName(_text->getText(kInfName)); - _talk->center(); - _vga->_showQ->append(_talk); - } + _talk->_flags._kill = true; + _talk->setName(_text->getText(kInfName)); + _talk->center(); + _vga->_showQ->append(_talk); } void Text::sayTime(Sprite *spr) { diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp index fa4c29c1d7..a84078f7a6 100644 --- a/engines/cge2/vmenu.cpp +++ b/engines/cge2/vmenu.cpp @@ -100,15 +100,14 @@ char *VMenu::vmGather(Common::Array list) { ++h; } _vmgt = new char[len + h]; - if (_vmgt) { - *_vmgt = '\0'; - for (uint i = 0; i < list.size(); i++) { - if (*_vmgt) - strcat(_vmgt, "|"); - strcat(_vmgt, list[i]->_text); - ++h; - } + *_vmgt = '\0'; + for (uint i = 0; i < list.size(); i++) { + if (*_vmgt) + strcat(_vmgt, "|"); + strcat(_vmgt, list[i]->_text); + ++h; } + return _vmgt; } -- cgit v1.2.3 From 239fa2a5cfee7a71b909ad338d14a54c5f44ca95 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 10:50:28 +0200 Subject: CGE2: Rename classes representing quit menu choices. --- engines/cge2/toolbar.cpp | 6 +++--- engines/cge2/vmenu.cpp | 4 ++-- engines/cge2/vmenu.h | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 51614af8ed..be9f73e5b4 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -130,13 +130,13 @@ void CGE2Engine::checkMusicSwitch() { void CGE2Engine::quit() { Common::Array quitMenu; // Deleted in VMenu's destructor. - quitMenu.push_back(new StartCountDownChoice(this)); - quitMenu.push_back(new ResetQSwitchChoice(this)); + quitMenu.push_back(new ExitGameChoice(this)); + quitMenu.push_back(new ReturnToGameChoice(this)); if (_commandHandler->idle()) { if (VMenu::_addr) { _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, VMenu::_addr); - ResetQSwitchChoice rqsChoice(this); + ReturnToGameChoice rqsChoice(this); rqsChoice.proc(); } else { quitMenu[0]->_text = _text->getText(kQuitText); diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp index a84078f7a6..ceb69f099d 100644 --- a/engines/cge2/vmenu.cpp +++ b/engines/cge2/vmenu.cpp @@ -31,11 +31,11 @@ namespace CGE2 { -void StartCountDownChoice::proc() { +void ExitGameChoice::proc() { _vm->switchScene(-1); } -void ResetQSwitchChoice::proc() { +void ReturnToGameChoice::proc() { _vm->_commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 1, nullptr); _vm->keyClick(); } diff --git a/engines/cge2/vmenu.h b/engines/cge2/vmenu.h index 724fb5d865..e28eee74b8 100644 --- a/engines/cge2/vmenu.h +++ b/engines/cge2/vmenu.h @@ -48,15 +48,15 @@ public: virtual ~Choice() {} }; -class StartCountDownChoice : public Choice { +class ExitGameChoice : public Choice { public: - StartCountDownChoice(CGE2Engine *vm) : Choice(vm) {} + ExitGameChoice(CGE2Engine *vm) : Choice(vm) {} void proc(); }; -class ResetQSwitchChoice : public Choice { +class ReturnToGameChoice : public Choice { public: - ResetQSwitchChoice(CGE2Engine *vm) : Choice(vm) {} + ReturnToGameChoice(CGE2Engine *vm) : Choice(vm) {} void proc(); }; -- cgit v1.2.3 From 8eae09afcac8c33ac0d7c8282001692f4f6df749 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 11:36:56 +0200 Subject: CGE2: Fix memory leak concerning the quit menu. --- engines/cge2/toolbar.cpp | 9 +++------ engines/cge2/vmenu.cpp | 12 +++++++++++- engines/cge2/vmenu.h | 9 +++++---- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index be9f73e5b4..5880dfce6a 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -129,18 +129,15 @@ void CGE2Engine::checkMusicSwitch() { } void CGE2Engine::quit() { - Common::Array quitMenu; // Deleted in VMenu's destructor. - quitMenu.push_back(new ExitGameChoice(this)); - quitMenu.push_back(new ReturnToGameChoice(this)); - if (_commandHandler->idle()) { if (VMenu::_addr) { _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, VMenu::_addr); ReturnToGameChoice rqsChoice(this); rqsChoice.proc(); } else { - quitMenu[0]->_text = _text->getText(kQuitText); - quitMenu[1]->_text = _text->getText(kNoQuitText); + Common::Array quitMenu; // Deleted in VMenu's destructor. + quitMenu.push_back(new ExitGameChoice(this)); + quitMenu.push_back(new ReturnToGameChoice(this)); (new VMenu(this, quitMenu, V2D(this, -1, -1), kCBMnu))->setName(_text->getText(kQuitTitle)); _commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 0, nullptr); keyClick(); diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp index ceb69f099d..6afe5e9a61 100644 --- a/engines/cge2/vmenu.cpp +++ b/engines/cge2/vmenu.cpp @@ -25,16 +25,26 @@ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon */ -#include "cge2/cge2.h" +#include "cge2/text.h" #include "cge2/vmenu.h" #include "cge2/events.h" namespace CGE2 { +Choice::Choice(CGE2Engine *vm) : _vm(vm), _text(nullptr) {} + +ExitGameChoice::ExitGameChoice(CGE2Engine *vm) : Choice(vm) { + _text = _vm->_text->getText(kQuitText); +} + void ExitGameChoice::proc() { _vm->switchScene(-1); } +ReturnToGameChoice::ReturnToGameChoice(CGE2Engine *vm) : Choice(vm) { + _text = _vm->_text->getText(kNoQuitText); +} + void ReturnToGameChoice::proc() { _vm->_commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 1, nullptr); _vm->keyClick(); diff --git a/engines/cge2/vmenu.h b/engines/cge2/vmenu.h index e28eee74b8..60796e750a 100644 --- a/engines/cge2/vmenu.h +++ b/engines/cge2/vmenu.h @@ -33,6 +33,7 @@ #define kLt 3 #define kRb 1 +#include "cge2/cge2.h" #include "cge2/talk.h" namespace CGE2 { @@ -42,21 +43,21 @@ protected: CGE2Engine *_vm; public: char *_text; + virtual void proc() = 0; - Choice(CGE2Engine *vm) : _vm(vm), _text(nullptr) {} - virtual ~Choice() {} + Choice(CGE2Engine *vm); }; class ExitGameChoice : public Choice { public: - ExitGameChoice(CGE2Engine *vm) : Choice(vm) {} + ExitGameChoice(CGE2Engine *vm); void proc(); }; class ReturnToGameChoice : public Choice { public: - ReturnToGameChoice(CGE2Engine *vm) : Choice(vm) {} + ReturnToGameChoice(CGE2Engine *vm); void proc(); }; -- cgit v1.2.3 From 241d07ff07c0002481fb81938066c675c5139df5 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 11:53:28 +0200 Subject: CGE2: Silence GCC warning concerning destructors of Choice's children. --- engines/cge2/vmenu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'engines') diff --git a/engines/cge2/vmenu.h b/engines/cge2/vmenu.h index 60796e750a..f34812dcf4 100644 --- a/engines/cge2/vmenu.h +++ b/engines/cge2/vmenu.h @@ -47,6 +47,7 @@ public: virtual void proc() = 0; Choice(CGE2Engine *vm); + virtual ~Choice() {}; }; class ExitGameChoice : public Choice { -- cgit v1.2.3 From 00bb645e5411d00fb3cfe7bbbe530507d5157a23 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 11:59:55 +0200 Subject: CGE2: Fix mismatched new/delete pair in Sprite::ghost() and snGhost(). --- engines/cge2/vga13h.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 812aabf8f3..486a42259f 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -694,7 +694,7 @@ BitmapPtr Sprite::ghost() { bmp->_h = e->_b1->_h; bmp->_b = new HideDesc[bmp->_h]; memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc)* bmp->_h); - uint8 *v = new uint8; + uint8 *v = new uint8[1]; *v = (e->_p1.y << 16) + e->_p1.x; bmp->_v = v; bmp->_map = (e->_p1.y << 16) + e->_p1.x; -- cgit v1.2.3 From 61083e5caba5d28689aaec8fd1f912df37eb0cf0 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 12:15:07 +0200 Subject: CGE2: Add RTL support. --- engines/cge2/cge2.cpp | 3 ++- engines/cge2/cge2_main.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index f938b8b87f..9c16bd4e0c 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -186,7 +186,8 @@ void CGE2Engine::deinit() { } bool CGE2Engine::hasFeature(EngineFeature f) const { - return (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime); + return (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime) + || (f == kSupportsRTL); } Common::Error CGE2Engine::run() { diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e945fbfdec..a7cbe01c74 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -645,6 +645,8 @@ void CGE2Engine::runGame() { _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); _mouse->off(); + + _vga->sunset(); } void CGE2Engine::loadUser() { -- cgit v1.2.3 From 60a77ae6d76195180707dfe67a3d34eb95b8ca74 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 14:46:11 +0200 Subject: CGE2: Add autosave functionality. --- engines/cge2/cge2.h | 1 + engines/cge2/cge2_main.cpp | 2 -- engines/cge2/saveload.cpp | 18 +++++++++++++----- engines/cge2/snail.cpp | 6 +++++- 4 files changed, 19 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 4043f15b16..fc097b9416 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -142,6 +142,7 @@ private: void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); void syncHeader(Common::Serializer &s); + void saveGame(int slotNumber, const Common::String &desc); bool loadGame(int slotNumber); void resetGame(); void syncSpeechSettings(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a7cbe01c74..e945fbfdec 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -645,8 +645,6 @@ void CGE2Engine::runGame() { _commandHandler->addCommand(kCmdClear, -1, 0, nullptr); _commandHandlerTurbo->addCommand(kCmdClear, -1, 0, nullptr); _mouse->off(); - - _vga->sunset(); } void CGE2Engine::loadUser() { diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 4a9da882d5..b95210eea0 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -129,6 +129,11 @@ SaveStateDescriptor CGE2MetaEngine::querySaveMetaInfos(const char *target, int s desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); desc.setSaveTime(header.saveHour, header.saveMinutes); + // Slot 0 is used for the 'automatic save on exit' save in Soltys, thus + // we prevent it from being deleted or overwritten by accident. + desc.setDeletableFlag(slot != 0); + desc.setWriteProtectedFlag(slot == 0); + return desc; } } @@ -186,8 +191,15 @@ bool CGE2Engine::canLoadGameStateCurrently() { } Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { + storeHeroPos(); + saveGame(slot, desc); + sceneUp(_now); + return Common::kNoError; +} + +void CGE2Engine::saveGame(int slotNumber, const Common::String &desc) { // Set up the serializer - Common::String slotName = generateSaveName(slot); + Common::String slotName = generateSaveName(slotNumber); Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(slotName); // Write out the ScummVM savegame header @@ -197,16 +209,12 @@ Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { writeSavegameHeader(saveFile, header); // Write out the data of the savegame - storeHeroPos(); sceneDown(); syncGame(nullptr, saveFile); - sceneUp(_now); // Finish writing out game data saveFile->finalize(); delete saveFile; - - return Common::kNoError; } /** diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 48e8ffdb70..29747672ba 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -691,7 +691,11 @@ Sprite *CGE2Engine::expandSprite(Sprite *spr) { } void CGE2Engine::qGame() { - warning("STUB: CGE2Engine::qGame()"); + // Write out the user's progress + saveGame(0, Common::String("Automatic Savegame")); + + busy(false); + _vga->sunset(); _endGame = true; } -- cgit v1.2.3 From 2697c71301caaad90436b89dfd911e8a7d911457 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Aug 2014 14:06:50 +0200 Subject: CGE2: Misc cleanup --- engines/cge2/hero.cpp | 52 +++++++++++++++++++++++-------------------------- engines/cge2/text.cpp | 7 +++---- engines/cge2/vga13h.cpp | 32 +++++++++++++++++++----------- 3 files changed, 48 insertions(+), 43 deletions(-) (limited to 'engines') diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 91f6354ce3..e8267b5af2 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -254,13 +254,11 @@ Sprite *Hero::setContact() { Sprite *spr; int md = _maxDist << 1; for (spr = _vm->_vga->_showQ->first(); spr; spr = spr->_next) { - if (spr->_actionCtrl[kNear]._cnt && (spr->_ref & 255) != 255) { - if (distance(spr) <= md) { - if (spr == _contact) - return nullptr; - else - break; - } + if (spr->_actionCtrl[kNear]._cnt && ((spr->_ref & 255) != 255) && (distance(spr) <= md)) { + if (spr == _contact) + return nullptr; + else + break; } } return (_contact = spr); @@ -321,8 +319,10 @@ void Hero::tick() { } if (_flags._trim) gotoxyz_(_pos2D); + if (_pos3D._z.trunc() != z) _flags._zmov = true; + if (--_funDel == 0) fun(); } @@ -345,12 +345,11 @@ int Hero::distance(Sprite *spr) { pos._x = _pos3D._x; else pos._x += mdx; - } else { - if (dx < mdx) - pos._x = _pos3D._x; - else - pos._x += mdx; - } + } else if (dx < mdx) + pos._x = _pos3D._x; + else + pos._x += mdx; + return distance(pos); } @@ -419,15 +418,14 @@ int Hero::len(V2D v) { bool Hero::findWay(){ V2D p0(_vm, _pos3D._x.round(), _pos3D._z.round()); V2D p1(_vm, _trace[_tracePtr]._x.round(), _trace[_tracePtr]._z.round()); - bool pvOk; - bool phOk; V2D ph(_vm, p1.x, p0.y); V2D pv(_vm, p0.x, p1.y); - pvOk = (!mapCross(p0, pv) && !mapCross(pv, p1)); - phOk = (!mapCross(p0, ph) && !mapCross(ph, p1)); + bool pvOk = (!mapCross(p0, pv) && !mapCross(pv, p1)); + bool phOk = (!mapCross(p0, ph) && !mapCross(ph, p1)); int md = (_maxDist >> 1); if (pvOk && (len(ph - p0) <= md || len(p1 - ph) <= md)) return true; + if (phOk && (len(pv - p0) <= md || len(p1 - pv) <= md)) return true; @@ -435,16 +433,17 @@ bool Hero::findWay(){ _trace[++_tracePtr] = V3D(pv.x, 0, pv.y); return true; } + if (phOk) { _trace[++_tracePtr] = V3D(ph.x, 0, ph.y); return true; } + return false; } int Hero::snap(int p, int q, int grid) { - int d = q - p; - d = ((d >= 0) ? d : -d) % grid; + int d = abs(q - p) % grid; if (d > (grid >> 1)) d -= grid; return (q >= p) ? (q - d) : (q + d); @@ -453,6 +452,7 @@ int Hero::snap(int p, int q, int grid) { void Hero::walkTo(V3D pos) { if (distance(pos) <= _maxDist) return; + int stp = stepSize(); pos._x = snap(_pos3D._x.round(), pos._x.round(), stp); pos._y = 0; @@ -512,26 +512,21 @@ int Hero::cross(const V2D &a, const V2D &b) { } bool CGE2Engine::cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d) { - if (contain(a, b, c)) - return true; - if (contain(a, b, d)) - return true; - if (contain(c, d, a)) - return true; - if (contain(c, d, b)) + if (contain(a, b, c) || contain(a, b, d) || contain(c, d, a) || contain(c, d, b)) return true; + return sgn(det(a, b, c)) != sgn(det(a, b, d)) && sgn(det(c, d, a)) != sgn(det(c, d, b)); } bool CGE2Engine::contain(const V2D &a, const V2D &b, const V2D &p) { if (det(a, b, p)) return false; + return ((long)(a.x - p.x) * (p.x - b.x) >= 0 && (long)(a.y - p.y) * (p.y - b.y) >= 0); } long CGE2Engine::det(const V2D &a, const V2D &b, const V2D &c) { - long n = ((long)a.x * b.y + (long)b.x * c.y + (long)c.x * a.y) - ((long)c.x * b.y + (long)b.x * a.y + (long)a.x * c.y); - return n; + return ((long)a.x * b.y + (long)b.x * c.y + (long)c.x * a.y) - ((long)c.x * b.y + (long)b.x * a.y + (long)a.x * c.y); } int CGE2Engine::sgn(long n) { @@ -543,6 +538,7 @@ int Hero::mapCross(const V2D &a, const V2D &b) { int n = (o->_scene == _scene) ? o->cross(a, b) : 0; if (!_ignoreMap) n += _vm->mapCross(a, b); + return n; } diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index ca4c33625e..605eed047f 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -157,10 +157,9 @@ void Text::say(const char *text, Sprite *spr) { if (east) { if (pos.x + sw + kTextRoundCorner + kCaptionSide >= kScrWidth) east = false; - } else { - if (pos.x <= kCaptionSide + kTextRoundCorner - sw) - east = true; - } + } else if (pos.x <= kCaptionSide + kTextRoundCorner - sw) + east = true; + if (east != (d.x > 0)) { d.x = -d.x; sw = -sw; diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 486a42259f..424138f6b0 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -74,11 +74,11 @@ FXP FXP::operator/(const FXP& x) const { v1 -= v3 * v2; v3 <<= 8; - if (v1 < 0xFFFFFF) { + if (v1 < 0xFFFFFF) v1 <<= 8; - } else { + else v2 >>= 8; - } + v3 += v1 / v2; if (negFlag) @@ -231,14 +231,16 @@ void Sprite::setName(char *newName) { int Sprite::labVal(Action snq, int lab) { int lv = -1; if (active()) { - int n = _actionCtrl[snq]._cnt; + int count = _actionCtrl[snq]._cnt; CommandHandler::Command *com = snList(snq); - int i; - for (i = 0; i < n; i++) + int i = 0; + for (; i < count; i++) { if (com[i]._lab == lab) break; - if (i < n) + } + + if (i < count) return i; } else { char tmpStr[kLineMax + 1]; @@ -431,7 +433,7 @@ Sprite *Sprite::expand() { if (curSeq) { if (maxnow >= shpcnt) error("Bad PHASE in SEQ %s", fname); - if (maxnxt && maxnxt >= seqcnt) + if (maxnxt && (maxnxt >= seqcnt)) error("Bad JUMP in SEQ %s", fname); setSeq(curSeq); } else { @@ -811,9 +813,10 @@ void Queue::insert(Sprite *spr) { return; // We only queue it if it's not already queued. Sprite *s; - for (s = _head; s; s = s->_next) + for (s = _head; s; s = s->_next) { if (s->_pos3D._z < spr->_pos3D._z) break; + } if (s) insert(spr, s); @@ -829,12 +832,16 @@ inline bool contains(const Common::List &l, const T &v) { Sprite *Queue::remove(Sprite *spr) { if (spr == _head) _head = spr->_next; + if (spr == _tail) _tail = spr->_prev; + if (spr->_next) spr->_next->_prev = spr->_prev; + if (spr->_prev) spr->_prev->_next = spr->_next; + spr->_prev = nullptr; spr->_next = nullptr; return spr; @@ -850,9 +857,11 @@ Sprite *Queue::locate(int ref) { bool Queue::locate(Sprite *spr) { Sprite *s; - for (s = _head; s; s = s->_next) + for (s = _head; s; s = s->_next) { if (s == spr) return true; + } + return false; } @@ -889,6 +898,7 @@ Vga::~Vga() { free(_newColors); if (_msg) buffer = Common::String(_msg); + if (_name) buffer = buffer + " [" + _name + "]"; @@ -1005,7 +1015,7 @@ void Vga::setColors(Dac *tab, int lum) { if (_mono) { destP = _newColors; for (int idx = 0; idx < kPalCount; idx++, destP++) { - // Form a greyscalce color from 30% R, 59% G, 11% B + // Form a grayscale color from 30% R, 59% G, 11% B uint8 intensity = (((int)destP->_r * 77) + ((int)destP->_g * 151) + ((int)destP->_b * 28)) >> 8; destP->_r = intensity; destP->_g = intensity; -- cgit v1.2.3 From 7dfb2b01f1b1655622d0537ceaac3d2c91c699ad Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 15:03:45 +0200 Subject: CGE2: Rearrange content of saveload.cpp and cge2.h a bit. --- engines/cge2/cge2.h | 10 ++- engines/cge2/saveload.cpp | 212 +++++++++++++++++++++++----------------------- 2 files changed, 112 insertions(+), 110 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index fc097b9416..630be47421 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -140,12 +140,12 @@ private: Common::String generateSaveName(int slot); void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); - void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); - void syncHeader(Common::Serializer &s); void saveGame(int slotNumber, const Common::String &desc); bool loadGame(int slotNumber); - void resetGame(); + void syncHeader(Common::Serializer &s); + void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); void syncSpeechSettings(); + void resetGame(); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); virtual bool hasFeature(EngineFeature f) const; @@ -154,11 +154,13 @@ public: virtual Common::Error saveGameState(int slot, const Common::String &desc); virtual Common::Error loadGameState(int slot); virtual Common::Error run(); + + static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); + GUI::Debugger *getDebugger() { return _console; } - static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); bool showTitle(const char *name); void cge2_main(); char *mergeExt(char *buf, const char *name, const char *ext); diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index b95210eea0..b5355966c3 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -141,35 +141,6 @@ SaveStateDescriptor CGE2MetaEngine::querySaveMetaInfos(const char *target, int s return SaveStateDescriptor(); } -bool CGE2Engine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) { - header.thumbnail = nullptr; - - // Get the savegame version - header.version = in->readByte(); - if (header.version > kSavegameVersion) - return false; - - // Read in the string - header.saveName.clear(); - char ch; - while ((ch = (char)in->readByte()) != '\0') - header.saveName += ch; - - // Get the thumbnail - header.thumbnail = Graphics::loadThumbnail(*in); - if (!header.thumbnail) - return false; - - // Read in save date/time - header.saveYear = in->readSint16LE(); - header.saveMonth = in->readSint16LE(); - header.saveDay = in->readSint16LE(); - header.saveHour = in->readSint16LE(); - header.saveMinutes = in->readSint16LE(); - - return true; -} - void CGE2MetaEngine::removeSaveState(const char *target, int slot) const { Common::String fileName = Common::String::format("%s.%03d", target, slot); g_system->getSavefileManager()->removeSavefile(fileName); @@ -186,10 +157,6 @@ bool CGE2Engine::canSaveGameStateCurrently() { _commandHandler->idle() && isHeroVisible; } -bool CGE2Engine::canLoadGameStateCurrently() { - return (_startupMode == 0) && _mouse->_active; -} - Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { storeHeroPos(); saveGame(slot, desc); @@ -217,12 +184,76 @@ void CGE2Engine::saveGame(int slotNumber, const Common::String &desc) { delete saveFile; } -/** -* Support method that generates a savegame name -* @param slot Slot number -*/ -Common::String CGE2Engine::generateSaveName(int slot) { - return Common::String::format("%s.%03d", _targetName.c_str(), slot); +bool CGE2Engine::canLoadGameStateCurrently() { + return (_startupMode == 0) && _mouse->_active; +} + +Common::Error CGE2Engine::loadGameState(int slot) { + _commandHandler->clear(); + _commandHandlerTurbo->clear(); + sceneDown(); + if (!loadGame(slot)) + return Common::kReadingFailed; + sceneUp(_now); + initToolbar(); + return Common::kNoError; +} + +bool CGE2Engine::loadGame(int slotNumber) { + Common::MemoryReadStream *readStream; + + // Open up the savegame file + Common::String slotName = generateSaveName(slotNumber); + Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName); + + // Read the data into a data buffer + int size = saveFile->size(); + byte *dataBuffer = (byte *)malloc(size); + saveFile->read(dataBuffer, size); + readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES); + delete saveFile; + + // Check to see if it's a ScummVM savegame or not + char buffer[kSavegameStrSize + 1]; + readStream->read(buffer, kSavegameStrSize + 1); + + if (strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) != 0) { + delete readStream; + return false; + } else { + SavegameHeader saveHeader; + + if (!readSavegameHeader(readStream, saveHeader)) { + delete readStream; + return false; + } + + // Delete the thumbnail + saveHeader.thumbnail->free(); + delete saveHeader.thumbnail; + } + + resetGame(); + + // Get in the savegame + syncGame(readStream, nullptr); + delete readStream; + + syncSpeechSettings(); + + loadHeroes(); + + return true; +} + +void CGE2Engine::resetGame() { + _busyPtr = nullptr; + busy(false); + _spare->clear(); + _vga->_showQ->clear(); + loadScript("CGE.INI", true); + delete _infoLine; + _infoLine = new InfoLine(this, kInfoW); } void CGE2Engine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header) { @@ -242,7 +273,7 @@ void CGE2Engine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &h for (int i = 0; i < 2; i++) _heroTab[i]->_ptr->park(); _vga->show(); - + // Create a thumbnail and save it Graphics::Surface *thumb = new Graphics::Surface(); Graphics::Surface *s = _vga->_page[0]; @@ -261,6 +292,35 @@ void CGE2Engine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &h out->writeSint16LE(td.tm_min); } +bool CGE2Engine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) { + header.thumbnail = nullptr; + + // Get the savegame version + header.version = in->readByte(); + if (header.version > kSavegameVersion) + return false; + + // Read in the string + header.saveName.clear(); + char ch; + while ((ch = (char)in->readByte()) != '\0') + header.saveName += ch; + + // Get the thumbnail + header.thumbnail = Graphics::loadThumbnail(*in); + if (!header.thumbnail) + return false; + + // Read in save date/time + header.saveYear = in->readSint16LE(); + header.saveMonth = in->readSint16LE(); + header.saveDay = in->readSint16LE(); + header.saveHour = in->readSint16LE(); + header.saveMinutes = in->readSint16LE(); + + return true; +} + void CGE2Engine::syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream) { Common::Serializer s(readStream, writeStream); @@ -318,72 +378,12 @@ void CGE2Engine::syncHeader(Common::Serializer &s) { } } -Common::Error CGE2Engine::loadGameState(int slot) { - _commandHandler->clear(); - _commandHandlerTurbo->clear(); - sceneDown(); - if (!loadGame(slot)) - return Common::kReadingFailed; - sceneUp(_now); - initToolbar(); - return Common::kNoError; -} - -void CGE2Engine::resetGame() { - _busyPtr = nullptr; - busy(false); - _spare->clear(); - _vga->_showQ->clear(); - loadScript("CGE.INI", true); - delete _infoLine; - _infoLine = new InfoLine(this, kInfoW); -} - -bool CGE2Engine::loadGame(int slotNumber) { - Common::MemoryReadStream *readStream; - - // Open up the savegame file - Common::String slotName = generateSaveName(slotNumber); - Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName); - - // Read the data into a data buffer - int size = saveFile->size(); - byte *dataBuffer = (byte *)malloc(size); - saveFile->read(dataBuffer, size); - readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES); - delete saveFile; - - // Check to see if it's a ScummVM savegame or not - char buffer[kSavegameStrSize + 1]; - readStream->read(buffer, kSavegameStrSize + 1); - - if (strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) != 0) { - delete readStream; - return false; - } else { - SavegameHeader saveHeader; - - if (!readSavegameHeader(readStream, saveHeader)) { - delete readStream; - return false; - } - - // Delete the thumbnail - saveHeader.thumbnail->free(); - delete saveHeader.thumbnail; - } - - resetGame(); - - // Get in the savegame - syncGame(readStream, nullptr); - delete readStream; - - syncSpeechSettings(); - - loadHeroes(); - - return true; +/** +* Support method that generates a savegame name +* @param slot Slot number +*/ +Common::String CGE2Engine::generateSaveName(int slot) { + return Common::String::format("%s.%03d", _targetName.c_str(), slot); } } // End of namespace CGE2 -- cgit v1.2.3 From 41fece64878ff982dc63a2b63d6f7e552c8fe6f3 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 15:18:44 +0200 Subject: CGE2: Remove #if 0-s. --- engines/cge2/cge2_main.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index e945fbfdec..8ee3d78ca3 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -749,9 +749,8 @@ void CGE2Engine::cge2_main() { } if (showTitle("WELCOME")) { -#if 0 movie(kIntroExt); -#endif + if (_text->getText(255) != nullptr) { runGame(); _startupMode = 2; @@ -815,9 +814,8 @@ bool CGE2Engine::showTitle(const char *name) { _vga->sunrise(_vga->_sysPal); _vga->update(); -#if 0 g_system->delayMillis(2500); -#endif + return true; } -- cgit v1.2.3 From b8b3e5af04f349ec353cffd73f399e21c4301f78 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Aug 2014 15:43:05 +0200 Subject: CGE2: Some more minor cleanup --- engines/cge2/bitmap.cpp | 12 +++---- engines/cge2/cge2_main.cpp | 17 ++++------ engines/cge2/detection.cpp | 11 +++--- engines/cge2/events.cpp | 9 ++--- engines/cge2/inventory.cpp | 7 ++-- engines/cge2/snail.cpp | 84 ++++++++++++++++++++++------------------------ engines/cge2/sound.cpp | 2 +- engines/cge2/spare.cpp | 3 +- engines/cge2/talk.cpp | 8 ++--- engines/cge2/toolbar.cpp | 34 ++++++++++--------- 10 files changed, 90 insertions(+), 97 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 289e156ee8..bcc9e98913 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -201,14 +201,14 @@ BitmapPtr Bitmap::code(uint8 *map) { uint8 pix; for (j = bpl; j < _w; j += 4) { pix = bm[j]; - if (_v && pix != kPixelTransp) { + if (_v && (pix != kPixelTransp)) { if (j < _b[i]._skip) _b[i]._skip = j; if (j >= _b[i]._hide) _b[i]._hide = j + 1; } - if ((pix == kPixelTransp) != skip || cnt >= 0x3FF0) { // end of block + if (((pix == kPixelTransp) != skip) || (cnt >= 0x3FF0)) { // end of block cnt |= (skip) ? kBmpSKP : kBmpCPY; if (_v) WRITE_LE_UINT16(cp, cnt); // store block description uint16 @@ -228,9 +228,9 @@ BitmapPtr Bitmap::code(uint8 *map) { bm += _w; if (_w < kScrWidth) { - if (skip) { + if (skip) cnt += (kScrWidth - j + 3) / 4; - } else { + else { cnt |= kBmpCPY; if (_v) WRITE_LE_UINT16(cp, cnt); @@ -333,7 +333,7 @@ bool Bitmap::solidAt(V2D pos) { break; case kBmpREP: case kBmpCPY: - if (n - w <= n0 && n > n0) + if ((n - w <= n0) && (n > n0)) return true; break; } @@ -449,7 +449,7 @@ uint8 *Bitmap::makeSpeechBubbleTail(int which, uint8 colorSet[][4]) { } for (int i = 0; i < kDesignSize; i++) { - if (des[i] >= 1 && des[i] <= 3) + if ((des[i] >= 1) && (des[i] <= 3)) des[i] = colorSet[kCBSay][des[i]]; } diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 8ee3d78ca3..cdf2aa648a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -266,9 +266,8 @@ Sprite *CGE2Engine::loadSprite(const char *fname, int ref, int scene, V3D &pos) label = kNoByte; } - if (!shpcnt) { + if (!shpcnt) error("No shapes - %s", fname); - } } else // No sprite description: mono-shaped sprite with only .BMP file. ++shpcnt; @@ -596,12 +595,10 @@ void CGE2Engine::tick() { for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time && (--spr->_time == 0)) - spr->tick(); + spr->tick(); - if (_waitRef) { - if (_waitRef == spr->_ref && spr->seqTest(_waitSeq)) - _waitRef = 0; - } + if (_waitRef && (_waitRef == spr->_ref) && spr->seqTest(_waitSeq)) + _waitRef = 0; } _mouse->tick(); @@ -951,10 +948,8 @@ Sprite *CGE2Engine::spriteAt(V2D pos) { Sprite *spr; for (spr = _vga->_showQ->last(); spr; spr = spr->_prev) { - if (!spr->_flags._hide && !spr->_flags._tran) { - if (spr->getShp()->solidAt(pos - spr->_pos2D)) - break; - } + if (!spr->_flags._hide && !spr->_flags._tran && (spr->getShp()->solidAt(pos - spr->_pos2D))) + break; } return spr; diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 5fcbe2ed7a..a7b25d1e05 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -30,9 +30,9 @@ namespace CGE2 { bool CGE2MetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { - if (desc) { + if (desc) *engine = new CGE2::CGE2Engine(syst, desc); - } + return desc != 0; } @@ -50,14 +50,13 @@ const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, static ADGameDescription desc; for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { - if (file->isDirectory()) { + if (file->isDirectory()) continue; - } + if (file->getName().equalsIgnoreCase("lang.eng")) { Common::File dataFile; - if (!dataFile.open(*file)) { + if (!dataFile.open(*file)) continue; - } desc.gameid = "sfinx"; desc.extra = "Sfinx English Alfa v0.1"; diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index cf6d3b0b61..7dd254d183 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -54,7 +54,7 @@ Sprite *Keyboard::setClient(Sprite *spr) { bool Keyboard::getKey(Common::Event &event) { Common::KeyCode keycode = event.kbd.keycode; - if (((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) && event.type == Common::EVENT_KEYDOWN) + if (((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) && (event.type == Common::EVENT_KEYDOWN)) _keyAlt = true; else _keyAlt = false; @@ -117,7 +117,7 @@ void Keyboard::newKeyboard(Common::Event &event) { if (!getKey(event)) return; - if ((event.type == Common::EVENT_KEYDOWN) && (_client)) { + if ((event.type == Common::EVENT_KEYDOWN) && _client) { CGE2Event &evt = _vm->_eventManager->getNextEvent(); evt._x = 0; evt._y = 0; @@ -253,7 +253,7 @@ void EventManager::handleEvents() { e._spritePtr = _vm->spriteAt(_vm->_mouse->_point); e._x += (_vm->_mouse->_siz.x >> 1); e._y -= _vm->_mouse->_siz.y; - if (_vm->_mouse->_hold && e._spritePtr != _vm->_mouse->_hold) { + if (_vm->_mouse->_hold && (e._spritePtr != _vm->_mouse->_hold)) { _vm->_mouse->_hold->touch(e._mask | kEventAttn, V2D(_vm, e._x - _vm->_mouse->_hold->_pos2D.x, e._y - _vm->_mouse->_hold->_pos2D.y), e._keyCode); } @@ -281,9 +281,10 @@ void EventManager::handleEvents() { void EventManager::clearEvent(Sprite *spr) { if (spr) { - for (uint16 e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) + for (uint16 e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) { if (_eventQueue[e]._spritePtr == spr) _eventQueue[e]._mask = 0; + } } else _eventQueueTail = _eventQueueHead; } diff --git a/engines/cge2/inventory.cpp b/engines/cge2/inventory.cpp index 7029a6494c..e62aa01e99 100644 --- a/engines/cge2/inventory.cpp +++ b/engines/cge2/inventory.cpp @@ -34,7 +34,7 @@ int CGE2Engine::findActivePocket(int ref) { for (int i = 0; i < kPocketMax; i++) { Sprite *spr = _heroTab[_sex]->_pocket[i]; if (ref >= 0) { - if (spr && spr->_ref == ref) + if (spr && (spr->_ref == ref)) return i; } else if (!spr) return i; @@ -45,13 +45,12 @@ int CGE2Engine::findActivePocket(int ref) { void CGE2Engine::selectPocket(int n) { Sprite **p = _heroTab[_sex]->_pocket; int &pp = _heroTab[_sex]->_pocPtr; - if (n < 0 || pp == n) { + if ((n < 0) || (pp == n)) { n = findActivePocket(-1); if (n >= 0) pp = n; - } else if (p[n]) { + } else if (p[n]) pp = n; - } } void CGE2Engine::pocFul() { diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp index 29747672ba..2cd5aca493 100644 --- a/engines/cge2/snail.cpp +++ b/engines/cge2/snail.cpp @@ -57,17 +57,16 @@ void CommandHandler::runCommand() { if (!_turbo && _vm->_soundStat._wait) { if (*(_vm->_soundStat._wait)) return; - else { - ++_vm->_soundStat._ref[0]; - if (_vm->_fx->exist(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0])) { - int16 oldRepeat = _vm->_sound->getRepeat(); - _vm->_sound->setRepeat(1); - _vm->_sound->play(Audio::Mixer::kSFXSoundType, _vm->_fx->load(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0]), _vm->_sound->_smpinf._span); - _vm->_sound->setRepeat(oldRepeat); - return; - } - _vm->_soundStat._wait = nullptr; + + ++_vm->_soundStat._ref[0]; + if (_vm->_fx->exist(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0])) { + int16 oldRepeat = _vm->_sound->getRepeat(); + _vm->_sound->setRepeat(1); + _vm->_sound->play(Audio::Mixer::kSFXSoundType, _vm->_fx->load(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0]), _vm->_sound->_smpinf._span); + _vm->_sound->setRepeat(oldRepeat); + return; } + _vm->_soundStat._wait = nullptr; } uint8 tmpHead = _head; @@ -77,6 +76,7 @@ void CommandHandler::runCommand() { if (!_turbo) { // only for the slower one if (_vm->_waitRef) break; + if (_timerExpiry) { // Delay in progress if (_timerExpiry > g_system->getMillis()) @@ -103,11 +103,12 @@ void CommandHandler::runCommand() { spr = (tailCmd._ref < 0) ? ((Sprite *)tailCmd._spritePtr) : _vm->locate(tailCmd._ref); Common::String sprStr; - if (spr && spr->_file && tailCmd._commandType != kCmdGhost) + if (spr && spr->_file && (tailCmd._commandType != kCmdGhost)) // In case of kCmdGhost _spritePtr stores a pointer to a Bitmap, not to a Sprite... sprStr = Common::String(spr->_file); else sprStr = "None"; + if (sprStr.empty()) sprStr = "None"; debugC(1, kCGE2DebugOpcode, "Command: %s; Ref: %d; Val: %d; Sprite: %s;", getComStr(tailCmd._commandType), tailCmd._ref, tailCmd._val, sprStr.c_str()); @@ -316,7 +317,7 @@ void CGE2Engine::snMidi(int val) { void CGE2Engine::snSeq(Sprite *spr, int val) { if (spr) { - if (isHero(spr) && val == 0) + if (isHero(spr) && (val == 0)) ((Hero*)spr)->park(); else spr->step(val); @@ -344,9 +345,8 @@ void CGE2Engine::snSend(Sprite *spr, int val) { // deactivating hide1(spr); spr->_flags._slav = false; - if (spr == _heroTab[_sex]->_ptr) - if (_heroTab[!_sex]->_ptr->_scene == _now) - switchHero(!_sex); + if ((spr == _heroTab[_sex]->_ptr) && (_heroTab[!_sex]->_ptr->_scene == _now)) + switchHero(!_sex); _spare->dispose(spr); } else { // activating @@ -496,9 +496,8 @@ void CGE2Engine::snGoto(Sprite *spr, int val) { } void CGE2Engine::snPort(Sprite *spr, int port) { - if (spr) { + if (spr) spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); - } } void CGE2Engine::snMouse(bool on) { @@ -547,9 +546,8 @@ void CGE2Engine::snRmFTake(Sprite *spr) { } void CGE2Engine::snSetRef(Sprite *spr, int val) { - if (spr) { + if (spr) spr->_ref = val; - } } void CGE2Engine::snFlash(bool on) { @@ -812,10 +810,9 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { } while (c < q) { - if (c->_commandType == kCmdWalk || c->_commandType == kCmdReach) { - if (c->_val == -1) - c->_val = spr->_ref; - } + if ((c->_val == -1) && (c->_commandType == kCmdWalk || c->_commandType == kCmdReach)) + c->_val = spr->_ref; + if (c->_commandType == kCmdNext) { Sprite *s; @@ -831,29 +828,28 @@ void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) { break; } - if (s) { - if (s->_actionCtrl[snq]._cnt) { - int v; - switch (c->_val) { - case -1: - v = int(c - comtab + 1); - break; - case -2: - v = int(c - comtab); - break; - case -3: - v = -1; - break; - default: - v = c->_val; - if ((v > 255) && s) - v = s->labVal(snq, v >> 8); - break; - } - if (v >= 0) - s->_actionCtrl[snq]._ptr = v; + if (s && s->_actionCtrl[snq]._cnt) { + int v; + switch (c->_val) { + case -1: + v = int(c - comtab + 1); + break; + case -2: + v = int(c - comtab); + break; + case -3: + v = -1; + break; + default: + v = c->_val; + if ((v > 255) && s) + v = s->labVal(snq, v >> 8); + break; } + if (v >= 0) + s->_actionCtrl[snq]._ptr = v; } + if (s == spr) break; } diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp index cc148d6090..c34eb00c01 100644 --- a/engines/cge2/sound.cpp +++ b/engines/cge2/sound.cpp @@ -250,7 +250,7 @@ void MusicPlayer::sndMidiStart() { } void MusicPlayer::send(uint32 b) { - if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) { + if (((b & 0xF0) == 0xC0) && !_isGM && !_nativeMT32) { b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; } diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp index 4ca29009d8..53f99e4e67 100644 --- a/engines/cge2/spare.cpp +++ b/engines/cge2/spare.cpp @@ -37,9 +37,10 @@ void Spare::sync(Common::Serializer &s) { size++; s.syncAsSint16LE(size); - for (uint i = 0; i < _container.size(); i++) + for (uint i = 0; i < _container.size(); i++) { if (_container[i]->_ref >= 141) _container[i]->sync(s); + } } else { int size; s.syncAsSint16LE(size); diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index dbdfc0d7ca..c39e064c22 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -186,7 +186,7 @@ void Talk::update(const char *text) { mh = 2 * vmarg + kFontHigh; mw = 0; for (const char *p = text; *p; p++) { - if (*p == '|' || *p == '\n') { + if ((*p == '|') || (*p == '\n')) { mh += kFontHigh + kTextLineSpace; if (k > mw) mw = k; @@ -208,9 +208,9 @@ void Talk::update(const char *text) { m = map + ln * mw + hmarg; while (*text) { - if (*text == '|' || *text == '\n') { + if ((*text == '|') || (*text == '\n')) m = map + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; - } else { + else { int cw = _vm->_font->_widthArr[(unsigned char)*text]; uint8 *f = _vm->_font->_map + _vm->_font->_pos[(unsigned char)*text]; @@ -254,7 +254,7 @@ InfoLine::InfoLine(CGE2Engine *vm, uint16 w, ColorBank color) } void InfoLine::update(const char *text) { - if (!_realTime && text == _oldText) + if (!_realTime && (text == _oldText)) return; _oldText = text; diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 5880dfce6a..4b328df6b0 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -115,17 +115,17 @@ void CGE2Engine::checkMusicSwitch() { bool mute = false; if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); + bool musicMuted = mute; int musicVolume = ConfMan.getInt("music_volume"); if (!musicMuted) musicMuted = musicVolume == 0; - if (!musicMuted && !_music) { + if (!musicMuted && !_music) switchMusic(_music = true); - } - if (musicMuted && _music) { + + if (musicMuted && _music) switchMusic(_music = false); - } } void CGE2Engine::quit() { @@ -148,7 +148,7 @@ void CGE2Engine::quit() { void CGE2Engine::setVolume(int idx, int cnt) { if (cnt && _vol[idx]) { int p = _vol[idx]->_seqPtr + cnt; - if (p >= 0 && p < _vol[idx]->_seqCnt) { + if ((p >= 0) && (p < _vol[idx]->_seqCnt)) { _vol[idx]->step(p); int newVolume = p * kSoundStatetoNumRate; switch (idx) { @@ -171,28 +171,29 @@ void CGE2Engine::checkVolumeSwitches() { bool mute = false; if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); + bool musicMuted = mute; int musicVolume = ConfMan.getInt("music_volume"); if (!musicMuted) musicMuted = musicVolume == 0; + bool sfxMuted = mute; int sfxVolume = ConfMan.getInt("sfx_volume"); if (!sfxMuted) sfxMuted = sfxVolume == 0; - if ((!musicMuted && !_music) || - (musicVolume != _oldMusicVolume && !musicMuted)) { + if ((!musicMuted && !_music) || (musicVolume != _oldMusicVolume && !musicMuted)) _vol[1]->step(musicVolume / kSoundNumtoStateRate); - } - if (musicMuted && _music) { + + if (musicMuted && _music) _vol[1]->step(0); - } if ((!sfxMuted && !_sfx) || (sfxVolume != _oldSfxVolume)) { _vol[0]->step(sfxVolume / kSoundNumtoStateRate); _oldSfxVolume = sfxVolume; _sfx = true; } + if (sfxMuted && _sfx) { _vol[0]->step(0); _sfx = false; @@ -220,9 +221,9 @@ void CGE2Engine::switchVox() { } void CGE2Engine::updateSpeechVolume() { - if (_sayVox) { + if (_sayVox) ConfMan.setInt("speech_volume", _oldSpeechVolume); - } else { + else { _oldSpeechVolume = ConfMan.getInt("speech_volume"); ConfMan.setInt("speech_volume", 0); } @@ -237,18 +238,18 @@ void CGE2Engine::checkSaySwitch() { bool mute = false; if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); + bool speechMuted = mute; if (!speechMuted) { int speechVolume = ConfMan.getInt("speech_volume"); speechMuted = speechVolume == 0; } - if (!speechMuted && !_sayVox) { + if (!speechMuted && !_sayVox) switchVox(); - } - if (speechMuted && _sayVox) { + + if (speechMuted && _sayVox) switchVox(); - } } void CGE2Engine::initToolbar() { @@ -279,6 +280,7 @@ void CGE2Engine::initToolbar() { if (_vol[0]) initVolumeSwitch(_vol[0]); + if (_vol[1]) initVolumeSwitch(_vol[1]); } -- cgit v1.2.3 From 07fc3fb3c368ad4c801fb3c0a804eb9a7a127685 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 19:16:18 +0200 Subject: CGE2: Some repair in Bitmap::code(). --- engines/cge2/bitmap.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index bcc9e98913..6d38f33b99 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -183,21 +183,20 @@ BitmapPtr Bitmap::code(uint8 *map) { while (true) { // at most 2 times: for (V == NULL) & for allocated block; uint8 *im = _v + 2; uint16 *cp = (uint16 *) _v; - int bpl; if (_v) { // 2nd pass - fill the hide table - for (uint16 i = 0; i < _h; i++) { + for (uint i = 0; i < _h; i++) { _b[i]._skip = 0xFFFF; _b[i]._hide = 0x0000; } } - for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane + for (int bpl = 0; bpl < 4; bpl++) { // once per each bitplane uint8 *bm = map; bool skip = (bm[bpl] == kPixelTransp); uint16 j; cnt = 0; - for (uint16 i = 0; i < _h; i++) { // once per each line + for (uint i = 0; i < _h; i++) { // once per each line uint8 pix; for (j = bpl; j < _w; j += 4) { pix = bm[j]; @@ -263,7 +262,7 @@ BitmapPtr Bitmap::code(uint8 *map) { _b = (HideDesc *)(_v + sizV); } cnt = 0; - for (uint16 i = 0; i < _h; i++) { + for (uint i = 0; i < _h; i++) { if (_b[i]._skip == 0xFFFF) { // whole line is skipped _b[i]._skip = (cnt + kScrWidth) >> 2; cnt = 0; -- cgit v1.2.3 From 11d2cf66b60799c12bec5279f801c402d90f1476 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 22:23:55 +0200 Subject: CGE2: Rework the handling of the sound buttons on the toolbar. Also keep in sync the volume settings and the audio mode of the game and the settings in the Launcher. --- engines/cge2/cge2.cpp | 20 +++---- engines/cge2/cge2.h | 10 +--- engines/cge2/cge2_main.cpp | 2 - engines/cge2/saveload.cpp | 2 - engines/cge2/toolbar.cpp | 126 +++++++++------------------------------------ 5 files changed, 31 insertions(+), 129 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 9c16bd4e0c..f3bc1de44c 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -96,15 +96,12 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _midiNotify = nullptr; _spriteNotify = nullptr; - _enaCap = true; - _enaVox = true; - _sayCap = true; - _sayVox = true; + _sayCap = ConfMan.getBool("subtitles"); + _sayVox = !ConfMan.getBool("speech_mute"); if (ConfMan.getBool("mute")) { - _oldSpeechVolume = _oldMusicVolume = _oldSfxVolume = 0; + _oldMusicVolume = _oldSfxVolume = 0; _music = _sfx = false; } else { - _oldSpeechVolume = ConfMan.getInt("speech_volume"); _oldMusicVolume = ConfMan.getInt("music_volume"); _oldSfxVolume = ConfMan.getInt("sfx_volume"); _music = _oldMusicVolume != 0; @@ -192,20 +189,17 @@ bool CGE2Engine::hasFeature(EngineFeature f) const { Common::Error CGE2Engine::run() { syncSoundSettings(); - syncSpeechSettings(); initGraphics(kScrWidth, kScrHeight, false); init(); cge2_main(); deinit(); - return Common::kNoError; -} + ConfMan.setBool("subtitles", _sayCap); + ConfMan.setBool("speech_mute", !_sayVox); + ConfMan.flushToDisk(); -void CGE2Engine::syncSpeechSettings() { - _enaCap = _sayCap = ConfMan.getBool("subtitles"); - _enaVox = _sayVox = !ConfMan.getBool("speech_mute"); + return Common::kNoError; } - } // End of namespace CGE2 diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 630be47421..8b2a2382e6 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -144,7 +144,6 @@ private: bool loadGame(int slotNumber); void syncHeader(Common::Serializer &s); void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); - void syncSpeechSettings(); void resetGame(); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); @@ -209,17 +208,13 @@ public: void optionTouch(int opt, uint16 mask); void switchColorMode(); - void switchMusic(bool on); - void updateMusicVolume(); - void checkMusicSwitch(); + void switchMusic(); void quit(); void setVolume(int idx, int cnt); void checkVolumeSwitches(); void switchCap(); void switchVox(); - void updateSpeechVolume(); void switchSay(); - void checkSaySwitch(); void initToolbar(); void initVolumeSwitch(Sprite *volSwitch); @@ -298,11 +293,8 @@ public: NotifyFunctionType _spriteNotify; int _startGameSlot; - bool _enaCap; - bool _enaVox; bool _sayCap; bool _sayVox; - int _oldSpeechVolume; int _oldMusicVolume; int _oldSfxVolume; bool _music; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index cdf2aa648a..9b4b1afd75 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -541,9 +541,7 @@ void CGE2Engine::mainLoop() { void CGE2Engine::checkSounds() { _sound->checkSoundHandles(); - checkSaySwitch(); checkVolumeSwitches(); - checkMusicSwitch(); _midiPlayer->syncVolume(); } diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index b5355966c3..a7d04bbc09 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -239,8 +239,6 @@ bool CGE2Engine::loadGame(int slotNumber) { syncGame(readStream, nullptr); delete readStream; - syncSpeechSettings(); - loadHeroes(); return true; diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 4b328df6b0..3972df9c67 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -54,10 +54,8 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && notMuted) { - switchMusic(_music = !_music); - updateMusicVolume(); - } + if ((mask & kMouseLeftUp) && notMuted) + switchMusic(); break; case 3: if (mask & kMouseLeftUp) @@ -72,14 +70,12 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); break; case 8: - if (mask & kMouseLeftUp) + if ((mask & kMouseLeftUp) && notMuted) switchCap(); break; case 9: - if ((mask & kMouseLeftUp) && notMuted) { + if ((mask & kMouseLeftUp) && notMuted) switchVox(); - updateSpeechVolume(); - } break; default: break; @@ -94,38 +90,12 @@ void CGE2Engine::switchColorMode() { _vga->setColors(_vga->_sysPal, 64); } -void CGE2Engine::switchMusic(bool on) { - _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); +void CGE2Engine::switchMusic() { + _music = !_music; + _mixer->muteSoundType(Audio::Mixer::kMusicSoundType, !_music); + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); keyClick(); - _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); -} - -void CGE2Engine::updateMusicVolume() { - if (_music) { - ConfMan.setInt("music_volume", _oldMusicVolume); - _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); - } else { - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - _vol[1]->step(0); - } -} - -void CGE2Engine::checkMusicSwitch() { - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - - bool musicMuted = mute; - int musicVolume = ConfMan.getInt("music_volume"); - if (!musicMuted) - musicMuted = musicVolume == 0; - - if (!musicMuted && !_music) - switchMusic(_music = true); - - if (musicMuted && _music) - switchMusic(_music = false); + _commandHandlerTurbo->addCommand(kCmdMidi, -1, _music ? (_now << 8) : -1, nullptr); } void CGE2Engine::quit() { @@ -168,65 +138,33 @@ void CGE2Engine::setVolume(int idx, int cnt) { } void CGE2Engine::checkVolumeSwitches() { - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - - bool musicMuted = mute; int musicVolume = ConfMan.getInt("music_volume"); - if (!musicMuted) - musicMuted = musicVolume == 0; - - bool sfxMuted = mute; - int sfxVolume = ConfMan.getInt("sfx_volume"); - if (!sfxMuted) - sfxMuted = sfxVolume == 0; - - if ((!musicMuted && !_music) || (musicVolume != _oldMusicVolume && !musicMuted)) + if (musicVolume != _oldMusicVolume) _vol[1]->step(musicVolume / kSoundNumtoStateRate); - if (musicMuted && _music) - _vol[1]->step(0); - - if ((!sfxMuted && !_sfx) || (sfxVolume != _oldSfxVolume)) { + int sfxVolume = ConfMan.getInt("sfx_volume"); + if (sfxVolume != _oldSfxVolume) { _vol[0]->step(sfxVolume / kSoundNumtoStateRate); _oldSfxVolume = sfxVolume; _sfx = true; } - - if (sfxMuted && _sfx) { - _vol[0]->step(0); - _sfx = false; - } } void CGE2Engine::switchCap() { - if (_enaCap && _enaVox) { - _sayCap = !_sayCap; - if (!_sayCap && _enaVox) - _sayVox = true; - keyClick(); - switchSay(); - } + _sayCap = !_sayCap; + if (!_sayCap) + _sayVox = true; + keyClick(); + switchSay(); } void CGE2Engine::switchVox() { - if (_enaVox && _enaCap) { - _sayVox = !_sayVox; - if (!_sayVox && _enaCap) - _sayCap = true; - keyClick(); - switchSay(); - } -} - -void CGE2Engine::updateSpeechVolume() { - if (_sayVox) - ConfMan.setInt("speech_volume", _oldSpeechVolume); - else { - _oldSpeechVolume = ConfMan.getInt("speech_volume"); - ConfMan.setInt("speech_volume", 0); - } + _mixer->muteSoundType(Audio::Mixer::kSpeechSoundType, _sayVox); + _sayVox = !_sayVox; + if (!_sayVox) + _sayCap = true; + keyClick(); + switchSay(); } void CGE2Engine::switchSay() { @@ -234,24 +172,6 @@ void CGE2Engine::switchSay() { _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); } -void CGE2Engine::checkSaySwitch() { - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - - bool speechMuted = mute; - if (!speechMuted) { - int speechVolume = ConfMan.getInt("speech_volume"); - speechMuted = speechVolume == 0; - } - - if (!speechMuted && !_sayVox) - switchVox(); - - if (speechMuted && _sayVox) - switchVox(); -} - void CGE2Engine::initToolbar() { selectPocket(-1); -- cgit v1.2.3 From 69b9a3fdffe5d13b9d200b612559320eda80851f Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 22:49:43 +0200 Subject: CGE2: Properly fade out if the player exits during the intro too. --- engines/cge2/cge2_main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 9b4b1afd75..f3a76d8593 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -749,8 +749,9 @@ void CGE2Engine::cge2_main() { if (_text->getText(255) != nullptr) { runGame(); _startupMode = 2; - } else - _vga->sunset(); + } + + _vga->sunset(); } else _vga->sunset(); } -- cgit v1.2.3 From 010a806a195f492119e2f0066d6ae398d74f3d28 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 22:50:16 +0200 Subject: CGE2: Rework canSaveGameStateCurrently(). --- engines/cge2/saveload.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index a7d04bbc09..0fb3fb20f8 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -147,14 +147,8 @@ void CGE2MetaEngine::removeSaveState(const char *target, int slot) const { } bool CGE2Engine::canSaveGameStateCurrently() { - bool isHeroVisible = false; - for (int i = 0; i < 2; i++) { - isHeroVisible = !_heroTab[i]->_ptr->_flags._hide; - if (isHeroVisible) - break; - } return (_startupMode == 0) && _mouse->_active && - _commandHandler->idle() && isHeroVisible; + _commandHandler->idle() && !(*_soundStat._wait); } Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { -- cgit v1.2.3 From 59bc45e79fa5d15dda7b777e310ade2f35f87610 Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 6 Aug 2014 17:44:12 +0200 Subject: CGE2: Get rid of _keyAlt. --- engines/cge2/events.cpp | 6 ------ engines/cge2/events.h | 1 - 2 files changed, 7 deletions(-) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 7dd254d183..3941492ca3 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -40,7 +40,6 @@ namespace CGE2 { /*----------------- KEYBOARD interface -----------------*/ Keyboard::Keyboard(CGE2Engine *vm) : _client(nullptr), _vm(vm) { - _keyAlt = false; } Keyboard::~Keyboard() { @@ -54,11 +53,6 @@ Sprite *Keyboard::setClient(Sprite *spr) { bool Keyboard::getKey(Common::Event &event) { Common::KeyCode keycode = event.kbd.keycode; - if (((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) && (event.type == Common::EVENT_KEYDOWN)) - _keyAlt = true; - else - _keyAlt = false; - switch (keycode) { case Common::KEYCODE_F1: if (event.type == Common::EVENT_KEYUP) diff --git a/engines/cge2/events.h b/engines/cge2/events.h index 2522c34049..d1aaca2ded 100644 --- a/engines/cge2/events.h +++ b/engines/cge2/events.h @@ -55,7 +55,6 @@ private: CGE2Engine *_vm; public: Sprite *_client; - bool _keyAlt; void newKeyboard(Common::Event &event); Sprite *setClient(Sprite *spr); -- cgit v1.2.3 From 895f8a5e595f0786a79b229810aba9d0a0e7b1ed Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 9 Aug 2014 13:51:31 +0200 Subject: CGE2: Remove commented out code from text.cpp. --- engines/cge2/text.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 605eed047f..1da310ccbd 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -25,11 +25,7 @@ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon */ -//#include "cge/general.h" #include "cge2/text.h" -//#include "cge/talk.h" -//#include "cge/game.h" -//#include "cge/snail.h" #include "common/str.h" namespace CGE2 { -- cgit v1.2.3 From 58822b47a73b8d733ceb0eee629bcbd557e4c6dc Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 9 Aug 2014 13:54:20 +0200 Subject: CGE2: Use spaces instead of tabs. --- engines/cge2/vga13h.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 424138f6b0..d8ecf5586f 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -128,7 +128,7 @@ Seq Sprite::_stdSeq8[] = SprExt::SprExt(CGE2Engine *vm) : _p0(vm, 0, 0), _p1(vm, 0, 0), _b0(nullptr), _b1(nullptr), _shpList(nullptr), - _location(0), _seq(nullptr), _name(nullptr) { + _location(0), _seq(nullptr), _name(nullptr) { for (int i = 0; i < kActions; i++) _actions[i] = nullptr; } @@ -136,8 +136,8 @@ SprExt::SprExt(CGE2Engine *vm) Sprite::Sprite(CGE2Engine *vm) : _siz(_vm, 0, 0), _seqPtr(kNoSeq), _seqCnt(0), _shpCnt(0), _next(nullptr), _prev(nullptr), _time(0), - _ext(nullptr), _ref(-1), _scene(0), _vm(vm), - _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { + _ext(nullptr), _ref(-1), _scene(0), _vm(vm), + _pos2D(_vm, kScrWidth >> 1, 0), _pos3D(kScrWidth >> 1, 0, 0) { memset(_actionCtrl, 0, sizeof(_actionCtrl)); memset(_file, 0, sizeof(_file)); memset(&_flags, 0, sizeof(_flags)); -- cgit v1.2.3 From 0ea126894005a2523e0b8a3bb48853e532aa518f Mon Sep 17 00:00:00 2001 From: uruk Date: Sat, 9 Aug 2014 17:22:19 +0200 Subject: CGE2: Fix canSaveGameStateCurrently(). --- engines/cge2/saveload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 0fb3fb20f8..309de335d8 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -148,7 +148,7 @@ void CGE2MetaEngine::removeSaveState(const char *target, int slot) const { bool CGE2Engine::canSaveGameStateCurrently() { return (_startupMode == 0) && _mouse->_active && - _commandHandler->idle() && !(*_soundStat._wait); + _commandHandler->idle() && (_soundStat._wait == nullptr); } Common::Error CGE2Engine::saveGameState(int slot, const Common::String &desc) { -- cgit v1.2.3 From 01950e1b1cb03281d2f3aa89462e496034ae05ee Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 14:48:33 +0200 Subject: CGE2: Remove unused function from vga13h.cpp. --- engines/cge2/vga13h.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index d8ecf5586f..330883141d 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -824,11 +824,6 @@ void Queue::insert(Sprite *spr) { append(spr); } -template -inline bool contains(const Common::List &l, const T &v) { - return (Common::find(l.begin(), l.end(), v) != l.end()); -} - Sprite *Queue::remove(Sprite *spr) { if (spr == _head) _head = spr->_next; -- cgit v1.2.3 From e709be446c1a3cac123aa6c6eb45be563deb99f4 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 14:53:49 +0200 Subject: CGE2: Remove unnecessary #pragma before Sprite::touch(). --- engines/cge2/cge2_main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index f3a76d8593..02efdfe982 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -842,7 +842,6 @@ void CGE2Engine::switchHero(int sex) { _commandHandler->addCommand(kCmdSeq, -1, 1, face); } -#pragma argsused void Sprite::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) { if ((mask & kEventAttn) != 0) return; -- cgit v1.2.3 From 1224d79e533325435c2d655b650bc7faf0c08b4f Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 14:54:47 +0200 Subject: CGE2: Fix typo in detection.cpp. --- engines/cge2/detection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index a7b25d1e05..1f0b67c495 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -59,7 +59,7 @@ const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, continue; desc.gameid = "sfinx"; - desc.extra = "Sfinx English Alfa v0.1"; + desc.extra = "Sfinx English Alpha v0.1"; desc.language = Common::EN_ANY; desc.platform = Common::kPlatformDOS; desc.flags = ADGF_NO_FLAGS; -- cgit v1.2.3 From 411e8ac5c8609631ba5e2a78d3603c32fc974e18 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:03:24 +0200 Subject: CGE2: Change return type of readSint16LE(). --- engines/cge2/fileio.cpp | 2 +- engines/cge2/fileio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 73b6cdab54..52a00ac129 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -222,7 +222,7 @@ uint32 EncryptedStream::read(byte *dataPtr, uint32 dataSize) { return _readStream->read(dataPtr, dataSize); } -signed EncryptedStream::readSint16LE() { +int16 EncryptedStream::readSint16LE() { return _readStream->readSint16LE(); } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 0f3755beb5..67b3754e85 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -120,7 +120,7 @@ public: int32 pos(); int32 size(); uint32 read(byte *dataPtr, uint32 dataSize); - signed readSint16LE(); + int16 readSint16LE(); uint32 readUint32LE(); Common::String readLine(); int getLineCount() { return _lineCount; } -- cgit v1.2.3 From eb13d6ece1fe580a573896127eb390728e7be47a Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:13:24 +0200 Subject: CGE2: Add necessary tabs in detection.cpp. --- engines/cge2/detection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 1f0b67c495..4acef7da36 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -74,7 +74,7 @@ const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, } // End of namespace CGE2 #if PLUGIN_ENABLED_DYNAMIC(CGE2) -REGISTER_PLUGIN_DYNAMIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); + REGISTER_PLUGIN_DYNAMIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); #else -REGISTER_PLUGIN_STATIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); + REGISTER_PLUGIN_STATIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine); #endif -- cgit v1.2.3 From 854849f57ae515ee84640f18881ffcd4e3b72846 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:28:43 +0200 Subject: CGE2: Get rid of detection.h, move things to detection.cpp. --- engines/cge2/cge2.h | 8 +++ engines/cge2/detection.cpp | 156 ++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/detection.h | 97 ---------------------------- engines/cge2/saveload.cpp | 102 ----------------------------- 4 files changed, 163 insertions(+), 200 deletions(-) delete mode 100644 engines/cge2/detection.h (limited to 'engines') diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 8b2a2382e6..4fc19a822d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -114,6 +114,14 @@ struct SavegameHeader; #define kColorNum 6 +struct SavegameHeader { + uint8 version; + Common::String saveName; + Graphics::Surface *thumbnail; + int saveYear, saveMonth, saveDay; + int saveHour, saveMinutes; +}; + enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar }; // our engine debug channels diff --git a/engines/cge2/detection.cpp b/engines/cge2/detection.cpp index 4acef7da36..c032e2348f 100644 --- a/engines/cge2/detection.cpp +++ b/engines/cge2/detection.cpp @@ -25,10 +25,71 @@ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon */ -#include "cge2/detection.h" +#include "cge2/cge2.h" +#include "engines/advancedDetector.h" +#include "common/translation.h" +#include "graphics/surface.h" namespace CGE2 { +#define GAMEOPTION_COLOR_BLIND_DEFAULT_OFF GUIO_GAMEOPTIONS1 + +static const PlainGameDescriptor CGE2Games[] = { + { "sfinx", "Sfinx" }, + { 0, 0 } +}; + +static const ADGameDescription gameDescriptions[] = { + { + "sfinx", "Sfinx Freeware", + { + { "vol.cat", 0, "21197b287d397c53261b6616bf0dd880", 129024 }, + { "vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844 }, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) + }, + AD_TABLE_END_MARKER +}; + +static const ADExtraGuiOptionsMap optionsList[] = { + { + GAMEOPTION_COLOR_BLIND_DEFAULT_OFF, + { + _s("Color Blind Mode"), + _s("Enable Color Blind Mode by default"), + "enable_color_blind", + false + } + }, + + AD_EXTRA_GUI_OPTIONS_TERMINATOR +}; + +class CGE2MetaEngine : public AdvancedMetaEngine { +public: + CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games, optionsList) { + _singleid = "sfinx"; + } + + virtual const char *getName() const { + return "CGE2"; + } + + virtual const char *getOriginalCopyright() const { + return "Sfinx (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon"; + } + + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual bool hasFeature(MetaEngineFeature f) const; + virtual int getMaximumSaveSlot() const; + virtual SaveStateList listSaves(const char *target) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; + virtual void removeSaveState(const char *target, int slot) const; + + const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; +}; + bool CGE2MetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { if (desc) *engine = new CGE2::CGE2Engine(syst, desc); @@ -71,6 +132,99 @@ const ADGameDescription *CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, return 0; } +int CGE2MetaEngine::getMaximumSaveSlot() const { + return 99; +} + +SaveStateList CGE2MetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".???"; + + filenames = saveFileMan->listSavefiles(pattern); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(filename->c_str() + filename->size() - 3); + + if (slotNum >= 0 && slotNum <= 99) { + + Common::InSaveFile *file = saveFileMan->openForLoading(*filename); + if (file) { + CGE2::SavegameHeader header; + + // Check to see if it's a ScummVM savegame or not + char buffer[kSavegameStrSize + 1]; + file->read(buffer, kSavegameStrSize + 1); + + if (!strncmp(buffer, kSavegameStr, kSavegameStrSize + 1)) { + // Valid savegame + if (CGE2::CGE2Engine::readSavegameHeader(file, header)) { + saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); + if (header.thumbnail) { + header.thumbnail->free(); + delete header.thumbnail; + } + } + } else { + // Must be an original format savegame + saveList.push_back(SaveStateDescriptor(slotNum, "Unknown")); + } + + delete file; + } + } + } + + return saveList; +} + +SaveStateDescriptor CGE2MetaEngine::querySaveMetaInfos(const char *target, int slot) const { + Common::String fileName = Common::String::format("%s.%03d", target, slot); + Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName); + + if (f) { + CGE2::SavegameHeader header; + + // Check to see if it's a ScummVM savegame or not + char buffer[kSavegameStrSize + 1]; + f->read(buffer, kSavegameStrSize + 1); + + bool hasHeader = !strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) && + CGE2::CGE2Engine::readSavegameHeader(f, header); + delete f; + + if (!hasHeader) { + // Original savegame perhaps? + SaveStateDescriptor desc(slot, "Unknown"); + return desc; + } else { + // Create the return descriptor + SaveStateDescriptor desc(slot, header.saveName); + desc.setThumbnail(header.thumbnail); + desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); + desc.setSaveTime(header.saveHour, header.saveMinutes); + + // Slot 0 is used for the 'automatic save on exit' save in Soltys, thus + // we prevent it from being deleted or overwritten by accident. + desc.setDeletableFlag(slot != 0); + desc.setWriteProtectedFlag(slot == 0); + + return desc; + } + } + + return SaveStateDescriptor(); +} + +void CGE2MetaEngine::removeSaveState(const char *target, int slot) const { + Common::String fileName = Common::String::format("%s.%03d", target, slot); + g_system->getSavefileManager()->removeSavefile(fileName); +} + } // End of namespace CGE2 #if PLUGIN_ENABLED_DYNAMIC(CGE2) diff --git a/engines/cge2/detection.h b/engines/cge2/detection.h deleted file mode 100644 index 51e2988c86..0000000000 --- a/engines/cge2/detection.h +++ /dev/null @@ -1,97 +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. - * - */ - -/* - * This code is based on original Sfinx source code - * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef CGE2_DETECTION_H -#define CGE2_DETECTION_H - -#include "cge2/cge2.h" -#include "engines/advancedDetector.h" -#include "common/translation.h" - -namespace CGE2 { - -#define GAMEOPTION_COLOR_BLIND_DEFAULT_OFF GUIO_GAMEOPTIONS1 - -static const PlainGameDescriptor CGE2Games[] = { - { "sfinx", "Sfinx" }, - { 0, 0 } -}; - -static const ADGameDescription gameDescriptions[] = { - { - "sfinx", "Sfinx Freeware", - { - { "vol.cat", 0, "21197b287d397c53261b6616bf0dd880", 129024 }, - { "vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844 }, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF) - }, - AD_TABLE_END_MARKER -}; - -static const ADExtraGuiOptionsMap optionsList[] = { - { - GAMEOPTION_COLOR_BLIND_DEFAULT_OFF, - { - _s("Color Blind Mode"), - _s("Enable Color Blind Mode by default"), - "enable_color_blind", - false - } - }, - - AD_EXTRA_GUI_OPTIONS_TERMINATOR -}; - -class CGE2MetaEngine : public AdvancedMetaEngine { -public: - CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games, optionsList) { - _singleid = "sfinx"; - } - - virtual const char *getName() const { - return "CGE2"; - } - - virtual const char *getOriginalCopyright() const { - return "Sfinx (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon"; - } - - virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; - virtual bool hasFeature(MetaEngineFeature f) const; - virtual int getMaximumSaveSlot() const; - virtual SaveStateList listSaves(const char *target) const; - SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; - virtual void removeSaveState(const char *target, int slot) const; - - const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const; -}; - -} // End of namespace CGE2 - -#endif // CGE2_DETECTION_H diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index 309de335d8..c9cedff83f 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -25,7 +25,6 @@ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon */ -#include "cge2/detection.h" #include "common/config-manager.h" #include "common/savefile.h" #include "common/system.h" @@ -45,107 +44,6 @@ namespace CGE2 { #define kSavegameCheckSum (1997 + _now + _sex + kWorldHeight) #define kBadSVG 99 -struct SavegameHeader { - uint8 version; - Common::String saveName; - Graphics::Surface *thumbnail; - int saveYear, saveMonth, saveDay; - int saveHour, saveMinutes; -}; - -int CGE2MetaEngine::getMaximumSaveSlot() const { - return 99; -} - -SaveStateList CGE2MetaEngine::listSaves(const char *target) const { - Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - Common::StringArray filenames; - Common::String pattern = target; - pattern += ".???"; - - filenames = saveFileMan->listSavefiles(pattern); - sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) - - SaveStateList saveList; - for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { - // Obtain the last 3 digits of the filename, since they correspond to the save slot - int slotNum = atoi(filename->c_str() + filename->size() - 3); - - if (slotNum >= 0 && slotNum <= 99) { - - Common::InSaveFile *file = saveFileMan->openForLoading(*filename); - if (file) { - CGE2::SavegameHeader header; - - // Check to see if it's a ScummVM savegame or not - char buffer[kSavegameStrSize + 1]; - file->read(buffer, kSavegameStrSize + 1); - - if (!strncmp(buffer, kSavegameStr, kSavegameStrSize + 1)) { - // Valid savegame - if (CGE2::CGE2Engine::readSavegameHeader(file, header)) { - saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); - if (header.thumbnail) { - header.thumbnail->free(); - delete header.thumbnail; - } - } - } else { - // Must be an original format savegame - saveList.push_back(SaveStateDescriptor(slotNum, "Unknown")); - } - - delete file; - } - } - } - - return saveList; -} - -SaveStateDescriptor CGE2MetaEngine::querySaveMetaInfos(const char *target, int slot) const { - Common::String fileName = Common::String::format("%s.%03d", target, slot); - Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName); - - if (f) { - CGE2::SavegameHeader header; - - // Check to see if it's a ScummVM savegame or not - char buffer[kSavegameStrSize + 1]; - f->read(buffer, kSavegameStrSize + 1); - - bool hasHeader = !strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) && - CGE2::CGE2Engine::readSavegameHeader(f, header); - delete f; - - if (!hasHeader) { - // Original savegame perhaps? - SaveStateDescriptor desc(slot, "Unknown"); - return desc; - } else { - // Create the return descriptor - SaveStateDescriptor desc(slot, header.saveName); - desc.setThumbnail(header.thumbnail); - desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); - desc.setSaveTime(header.saveHour, header.saveMinutes); - - // Slot 0 is used for the 'automatic save on exit' save in Soltys, thus - // we prevent it from being deleted or overwritten by accident. - desc.setDeletableFlag(slot != 0); - desc.setWriteProtectedFlag(slot == 0); - - return desc; - } - } - - return SaveStateDescriptor(); -} - -void CGE2MetaEngine::removeSaveState(const char *target, int slot) const { - Common::String fileName = Common::String::format("%s.%03d", target, slot); - g_system->getSavefileManager()->removeSavefile(fileName); -} - bool CGE2Engine::canSaveGameStateCurrently() { return (_startupMode == 0) && _mouse->_active && _commandHandler->idle() && (_soundStat._wait == nullptr); -- cgit v1.2.3 From 85101525454bf613aa35d72a356c506d2f7600c4 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:31:34 +0200 Subject: CGE2: Rename XCrpyt() to xCrypt(). --- engines/cge2/fileio.cpp | 6 +++--- engines/cge2/fileio.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index 52a00ac129..ea218647f9 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -90,7 +90,7 @@ ResourceManager::~ResourceManager() { delete _buff[i]._page; } -void ResourceManager::XCrypt(byte *buf, uint16 length) { +void ResourceManager::xCrypt(byte *buf, uint16 length) { byte *b = buf; for (uint16 i = 0; i < length; i++) @@ -108,7 +108,7 @@ uint16 ResourceManager::read(byte *buf, uint16 length) { uint16 bytesRead = _datFile->read(buf, length); if (!bytesRead) error("Read %s - %d bytes", _datFile->getName(), length); - XCrypt(buf, length); + xCrypt(buf, length); return bytesRead; } @@ -180,7 +180,7 @@ uint16 ResourceManager::catRead(byte *buf, uint16 length) { uint16 bytesRead = _catFile->read(buf, length); if (!bytesRead) error("Read %s - %d bytes", _catFile->getName(), length); - XCrypt(buf, length); + xCrypt(buf, length); return bytesRead; } diff --git a/engines/cge2/fileio.h b/engines/cge2/fileio.h index 67b3754e85..e236c73b49 100644 --- a/engines/cge2/fileio.h +++ b/engines/cge2/fileio.h @@ -94,7 +94,7 @@ private: uint16 catRead(byte *buf, uint16 length); Common::File *_catFile; Common::File *_datFile; - void XCrypt(byte *buf, uint16 length); + void xCrypt(byte *buf, uint16 length); public: ResourceManager(); ~ResourceManager(); -- cgit v1.2.3 From c3a5a9177b162beb70f28aa1f9408559f9482cbb Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:38:28 +0200 Subject: CGE2: Fix comment in runGame(). --- engines/cge2/cge2_main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 02efdfe982..c8c3a1e77a 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -632,7 +632,8 @@ void CGE2Engine::runGame() { while (!_endGame && !_quitFlag) mainLoop(); - // If finishing game due to closing ScummVM window, explicitly save the game + // If leaving the game (close window, return to launcher, etc. + // - except finishing the game), explicitly save it's state: if (!_endGame && canSaveGameStateCurrently()) qGame(); -- cgit v1.2.3 From f8e60e467fdcff8b36eb0bfad2a4c53459462fe6 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:42:55 +0200 Subject: CGE2: Make movie() safer. --- engines/cge2/cge2_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index c8c3a1e77a..7900eefb86 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -387,7 +387,7 @@ void CGE2Engine::movie(const char *ext) { return; char fn[12]; - sprintf(fn, "CGE.%s", (*ext == '.') ? ext + 1 : ext); + sprintf(fn, "CGE%s", ext); if (_resman->exist(fn)) { int now = _now; -- cgit v1.2.3 From 0d47893d5143dac35686890360591558eef7a72a Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:44:55 +0200 Subject: CGE2: Make matrixes static constants in makeSpeechBubbleTail(). --- engines/cge2/bitmap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 6d38f33b99..01e97ebc53 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -396,7 +396,7 @@ void Bitmap::xLatPos(V2D& p) { #define kDesignSize 240 uint8 *Bitmap::makeSpeechBubbleTail(int which, uint8 colorSet[][4]) { - uint8 kSLDesign[kDesignSize] = { + static const uint8 kSLDesign[kDesignSize] = { G G G G G G G G G _ _ _ _ _ _ L G G G G G G G G D _ _ _ _ _ _ L G G G G G G G D _ _ _ _ _ @@ -415,7 +415,7 @@ uint8 *Bitmap::makeSpeechBubbleTail(int which, uint8 colorSet[][4]) { _ _ _ _ _ _ _ _ _ _ _ _ _ _ D }; - uint8 kSRDesign[kDesignSize] = { + static const uint8 kSRDesign[kDesignSize] = { _ _ _ _ _ _ G G G G G G G G G _ _ _ _ _ L G G G G G G G G D _ _ _ _ _ L G G G G G G G D _ -- cgit v1.2.3 From 25ebfe461f576d26e3c01bcdfa0151dc9d1fc7fa Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:54:38 +0200 Subject: CGE2: Remove unnecessary comments from vga13h.h. --- engines/cge2/vga13h.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 52efd39849..a31da57372 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -51,8 +51,7 @@ namespace CGE2 { #define kPalCount 256 #define kPalSize (kPalCount * 3) -// From FXP.H -class FXP { // fixed point +class FXP { int32 v; public: FXP(void) : v(0) {} @@ -78,7 +77,6 @@ public: void sync(Common::Serializer &s); }; -// From CGETYPE.H: class V3D { public: FXP _x, _y, _z; -- cgit v1.2.3 From 7dfd108f68f5e7f99df3b290c48a9d485cb9c3b7 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 15:56:20 +0200 Subject: CGE2: Remove unused functions from V2D. --- engines/cge2/vga13h.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index a31da57372..cb823645dc 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -127,8 +127,6 @@ public: FXP posy = m * y; return V2D(_vm, posx.trunc(), posy.trunc()); } - static double trunc(double d) { return (d > 0) ? floor(d) : ceil(d); } - static double round(double number) { return number < 0.0 ? ceil(number) : floor(number); } }; struct Seq { -- cgit v1.2.3 From b3fed6c36904287713ca82c08606b882ceaeff68 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 16:03:38 +0200 Subject: CGE2: Return value instead of reference in FXP's operator=. --- engines/cge2/vga13h.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index cb823645dc..4d2d637212 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -56,7 +56,7 @@ class FXP { public: FXP(void) : v(0) {} FXP (int i0, int f0 = 0) : v((i0 * 256) + ((i0 < 0) ? -f0 : f0)) {} - FXP& operator=(const int& x) { v = x << 8; return *this; } + FXP operator=(const int& x) { v = x << 8; return *this; } FXP operator+(const FXP& x) const { FXP y; y.v = v + x.v; return y; } FXP operator-(const FXP& x) const { FXP y; y.v = v - x.v; return y; } FXP operator*(const FXP& x) const; -- cgit v1.2.3 From 5e375d0796b4da822ceb8e3d4294d9189101241a Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 16:06:10 +0200 Subject: CGE2: Fix formatting of operators' return values in vga13h.h. --- engines/cge2/vga13h.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 4d2d637212..652727cb32 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -63,10 +63,10 @@ public: FXP operator/(const FXP& x) const; //int& operator = (int& a, const FXP& b) { return a = b.i; } - friend int& operator+=(int& a, const FXP& b) { return a += b.trunc(); } - friend int& operator-=(int& a, const FXP& b) { return a -= b.trunc(); } - friend FXP& operator+=(FXP& a, const int& b) { a.v += b << 8; return a; } - friend FXP& operator-=(FXP& a, const int& b) { a.v -= b << 8; return a; } + friend int &operator+=(int& a, const FXP& b) { return a += b.trunc(); } + friend int &operator-=(int& a, const FXP& b) { return a -= b.trunc(); } + friend FXP &operator+=(FXP& a, const int& b) { a.v += b << 8; return a; } + friend FXP &operator-=(FXP& a, const int& b) { a.v -= b << 8; return a; } friend bool operator==(const FXP &a, const FXP &b) { return a.v == b.v; } friend bool operator!=(const FXP &a, const FXP &b) { return a.v != b.v; } friend bool operator<(const FXP &a, const FXP &b) { return a.v < b.v; } @@ -97,7 +97,7 @@ public: class V2D : public Common::Point { CGE2Engine *_vm; public: - V2D& operator=(const V3D &p3) { + V2D &operator=(const V3D &p3) { FXP m = _vm->_eye->_z / (p3._z - _vm->_eye->_z); FXP posx = _vm->_eye->_x + (_vm->_eye->_x - p3._x) * m; x = posx.round(); -- cgit v1.2.3 From 9c5bdc6dde233011a22dd85f42d37f01f29809b0 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 16:07:29 +0200 Subject: CGE2: Fix formatting in bitmap.h. --- engines/cge2/bitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 30b8f487c5..613222fc6e 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -81,7 +81,7 @@ public: void hide(V2D pos); void show(V2D pos); bool solidAt(V2D pos); - void xLatPos(V2D& p); + void xLatPos(V2D &p); static uint8 *makeSpeechBubbleTail(int des, uint8 colorSet[][4]); }; -- cgit v1.2.3 From 235e3d396e0aa9d8a0ad1427d189a5e9eb243344 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 16:09:04 +0200 Subject: CGE2: Fix formatting in events.cpp. --- engines/cge2/events.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 3941492ca3..ed1ec66bb1 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -206,7 +206,7 @@ void Mouse::newMouse(Common::Event &event) { /*----------------- EventManager interface -----------------*/ -EventManager::EventManager(CGE2Engine *vm) : _vm(vm){ +EventManager::EventManager(CGE2Engine *vm) : _vm(vm) { _eventQueueHead = 0; _eventQueueTail = 0; memset(&_eventQueue, 0, kEventMax * sizeof(CGE2Event)); -- cgit v1.2.3 From 3e3430ed5de5155fadd6d23ea719f413bcc4e6e6 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 16:10:14 +0200 Subject: CGE2: Fix EncryptedStream::err(). --- engines/cge2/fileio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/fileio.cpp b/engines/cge2/fileio.cpp index ea218647f9..6f8009716b 100644 --- a/engines/cge2/fileio.cpp +++ b/engines/cge2/fileio.cpp @@ -231,7 +231,7 @@ uint32 EncryptedStream::readUint32LE() { } bool EncryptedStream::err() { - return (_error & _readStream->err()); + return (_error || _readStream->err()); } bool EncryptedStream::eos() { -- cgit v1.2.3 From 02f3418d6f0382791c44dec8a5e232caa12109e9 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 20:32:56 +0200 Subject: CGE2: Fix some more formatting in vga13h.h. --- engines/cge2/vga13h.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 652727cb32..749374fd24 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -56,17 +56,17 @@ class FXP { public: FXP(void) : v(0) {} FXP (int i0, int f0 = 0) : v((i0 * 256) + ((i0 < 0) ? -f0 : f0)) {} - FXP operator=(const int& x) { v = x << 8; return *this; } - FXP operator+(const FXP& x) const { FXP y; y.v = v + x.v; return y; } - FXP operator-(const FXP& x) const { FXP y; y.v = v - x.v; return y; } - FXP operator*(const FXP& x) const; - FXP operator/(const FXP& x) const; + FXP operator=(const int &x) { v = x << 8; return *this; } + FXP operator+(const FXP &x) const { FXP y; y.v = v + x.v; return y; } + FXP operator-(const FXP &x) const { FXP y; y.v = v - x.v; return y; } + FXP operator*(const FXP &x) const; + FXP operator/(const FXP &x) const; //int& operator = (int& a, const FXP& b) { return a = b.i; } - friend int &operator+=(int& a, const FXP& b) { return a += b.trunc(); } - friend int &operator-=(int& a, const FXP& b) { return a -= b.trunc(); } - friend FXP &operator+=(FXP& a, const int& b) { a.v += b << 8; return a; } - friend FXP &operator-=(FXP& a, const int& b) { a.v -= b << 8; return a; } + friend int &operator+=(int &a, const FXP &b) { return a += b.trunc(); } + friend int &operator-=(int &a, const FXP &b) { return a -= b.trunc(); } + friend FXP &operator+=(FXP &a, const int &b) { a.v += b << 8; return a; } + friend FXP &operator-=(FXP &a, const int &b) { a.v -= b << 8; return a; } friend bool operator==(const FXP &a, const FXP &b) { return a.v == b.v; } friend bool operator!=(const FXP &a, const FXP &b) { return a.v != b.v; } friend bool operator<(const FXP &a, const FXP &b) { return a.v < b.v; } @@ -108,9 +108,9 @@ public: V2D(CGE2Engine *vm) : _vm(vm) { } V2D(CGE2Engine *vm, const V3D &p3) : _vm(vm) { *this = p3; } V2D(CGE2Engine *vm, int posx, int posy) : _vm(vm), Common::Point(posx, posy) { } - bool operator<(const V2D &p) const { return (x < p.x) && (y < p.y); } + bool operator<(const V2D &p) const { return (x < p.x) && (y < p.y); } bool operator<=(const V2D &p) const { return (x <= p.x) && (y <= p.y); } - bool operator>(const V2D &p) const { return (x > p.x) && (y > p.y); } + bool operator>(const V2D &p) const { return (x > p.x) && (y > p.y); } bool operator>=(const V2D &p) const { return (x >= p.x) && (y >= p.y); } V2D operator+(const V2D &p) const { return V2D(_vm, x + p.x, y + p.y); } V2D operator-(const V2D &p) const { return V2D(_vm, x - p.x, y - p.y); } -- cgit v1.2.3 From e488da5757a44fed4fda5c15fb8ab4f37e0ee350 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 20:34:18 +0200 Subject: CGE2: Remove unnecessary commented out code. --- engines/cge2/vga13h.h | 1 - 1 file changed, 1 deletion(-) (limited to 'engines') diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h index 749374fd24..346d140e3f 100644 --- a/engines/cge2/vga13h.h +++ b/engines/cge2/vga13h.h @@ -62,7 +62,6 @@ public: FXP operator*(const FXP &x) const; FXP operator/(const FXP &x) const; - //int& operator = (int& a, const FXP& b) { return a = b.i; } friend int &operator+=(int &a, const FXP &b) { return a += b.trunc(); } friend int &operator-=(int &a, const FXP &b) { return a -= b.trunc(); } friend FXP &operator+=(FXP &a, const int &b) { a.v += b << 8; return a; } -- cgit v1.2.3 From ae037b23153d60b19c95960c0c6e1e1ee61a906b Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 11 Aug 2014 20:43:08 +0200 Subject: CGE2: Use snprintf() instead of sprintf(). --- engines/cge2/cge2_main.cpp | 2 +- engines/cge2/text.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 7900eefb86..7c4a111d1f 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -387,7 +387,7 @@ void CGE2Engine::movie(const char *ext) { return; char fn[12]; - sprintf(fn, "CGE%s", ext); + snprintf(fn, 12, "CGE%s", ext); if (_resman->exist(fn)) { int now = _now; diff --git a/engines/cge2/text.cpp b/engines/cge2/text.cpp index 1da310ccbd..d51c04843d 100644 --- a/engines/cge2/text.cpp +++ b/engines/cge2/text.cpp @@ -190,7 +190,7 @@ void Text::sayTime(Sprite *spr) { _vm->_system->getTimeAndDate(curTime); char t[6]; - sprintf(t, "%d:%02d", curTime.tm_hour, curTime.tm_min); + snprintf(t, 6, "%d:%02d", curTime.tm_hour, curTime.tm_min); say(t, spr); } -- cgit v1.2.3