mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-03 07:59:38 +00:00
MACVENTURE: Add text decoding (without composite)
This commit is contained in:
parent
aae8378afd
commit
9c10b431ce
57
engines/macventure/hufflists.h
Normal file
57
engines/macventure/hufflists.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/* ScummVM - Graphic Adventure Engine
|
||||||
|
*
|
||||||
|
* ScummVM is the legal property of its developers, whose names
|
||||||
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||||
|
* file distributed with this source distribution.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MACVENTURE_HUFFLIST_H
|
||||||
|
#define MACVENTURE_HUFFLIST_H
|
||||||
|
|
||||||
|
namespace MacVenture {
|
||||||
|
|
||||||
|
// The engine uses a <= comparison instead of ==, so I can't use Common::Huffman
|
||||||
|
class HuffmanLists {
|
||||||
|
public:
|
||||||
|
HuffmanLists() {
|
||||||
|
_numEntries = 0;
|
||||||
|
}
|
||||||
|
HuffmanLists(uint32 num, uint32 *lens, uint32 *masks, uint32 *symbols) {
|
||||||
|
_numEntries = num;
|
||||||
|
_lens = Common::Array<uint32>(lens, num);
|
||||||
|
_masks = Common::Array<uint32>(masks, num);
|
||||||
|
_symbols = Common::Array<uint32>(symbols, num);
|
||||||
|
}
|
||||||
|
~HuffmanLists() {}
|
||||||
|
|
||||||
|
|
||||||
|
uint32 getNumEntries() const { return _numEntries; }
|
||||||
|
uint32 getLength(uint32 index) const { return _lens[index]; }
|
||||||
|
uint32 getMask(uint32 index) const { return _masks[index]; }
|
||||||
|
uint32 getSymbol(uint32 index) const { return _symbols[index]; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32 _numEntries;
|
||||||
|
Common::Array<uint32> _lens;
|
||||||
|
Common::Array<uint32> _masks;
|
||||||
|
Common::Array<uint32> _symbols;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End of namespace MacVenture
|
||||||
|
|
||||||
|
#endif
|
@ -42,6 +42,7 @@ MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameD
|
|||||||
_rnd = new Common::RandomSource("macventure");
|
_rnd = new Common::RandomSource("macventure");
|
||||||
|
|
||||||
_debugger= NULL;
|
_debugger= NULL;
|
||||||
|
_gui = NULL;
|
||||||
|
|
||||||
debug("MacVenture::MacVentureEngine()");
|
debug("MacVenture::MacVentureEngine()");
|
||||||
}
|
}
|
||||||
@ -143,7 +144,7 @@ void MacVentureEngine::requestUnpause() {
|
|||||||
|
|
||||||
void MacVentureEngine::selectControl(ControlReference id) {
|
void MacVentureEngine::selectControl(ControlReference id) {
|
||||||
ControlAction action = referenceToAction(id);
|
ControlAction action = referenceToAction(id);
|
||||||
debug(7, "Select control %x", action);
|
debug(4, "Select control %x", action);
|
||||||
_selectedControl = action;
|
_selectedControl = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ void MacVentureEngine::activateCommand(ControlReference id) {
|
|||||||
_activeControl = kNoCommand;
|
_activeControl = kNoCommand;
|
||||||
_activeControl = action;
|
_activeControl = action;
|
||||||
}
|
}
|
||||||
debug(7, "Activating Command %x... Command %x is active", action, _activeControl);
|
debug(4, "Activating Command %x... Command %x is active", action, _activeControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacVentureEngine::refreshReady() {
|
void MacVentureEngine::refreshReady() {
|
||||||
@ -213,7 +214,7 @@ void MacVentureEngine::processEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MacVenture::MacVentureEngine::runScriptEngine() {
|
bool MacVenture::MacVentureEngine::runScriptEngine() {
|
||||||
debug(5, "MAIN: Running script engine");
|
debug(4, "MAIN: Running script engine");
|
||||||
if (_haltedAtEnd) {
|
if (_haltedAtEnd) {
|
||||||
_haltedAtEnd = false;
|
_haltedAtEnd = false;
|
||||||
if (_scriptEngine->resume()) {
|
if (_scriptEngine->resume()) {
|
||||||
@ -335,6 +336,14 @@ Common::String MacVentureEngine::getFilePath(FilePathID id) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MacVentureEngine::isOldText() const {
|
||||||
|
return _oldTextEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
const HuffmanLists * MacVentureEngine::getDecodingHuffman() const {
|
||||||
|
return _textHuffman;
|
||||||
|
}
|
||||||
|
|
||||||
// Data loading
|
// Data loading
|
||||||
|
|
||||||
bool MacVentureEngine::loadGlobalSettings() {
|
bool MacVentureEngine::loadGlobalSettings() {
|
||||||
@ -400,7 +409,7 @@ bool MacVentureEngine::loadTextHuffman() {
|
|||||||
// For some reason there are one lass mask than entries
|
// For some reason there are one lass mask than entries
|
||||||
masks[i] = res->readUint16BE();
|
masks[i] = res->readUint16BE();
|
||||||
|
|
||||||
uint8 *lengths = new uint8[numEntries];
|
uint32 *lengths = new uint32[numEntries];
|
||||||
for (uint i = 0; i < numEntries; i++)
|
for (uint i = 0; i < numEntries; i++)
|
||||||
lengths[i] = res->readByte();
|
lengths[i] = res->readByte();
|
||||||
|
|
||||||
@ -408,8 +417,8 @@ bool MacVentureEngine::loadTextHuffman() {
|
|||||||
for (uint i = 0; i < numEntries; i++)
|
for (uint i = 0; i < numEntries; i++)
|
||||||
values[i] = res->readByte();
|
values[i] = res->readByte();
|
||||||
|
|
||||||
_textHuffman = new Common::Huffman(0, numEntries, masks, lengths, values);
|
_textHuffman = new HuffmanLists(numEntries, lengths, masks, values);
|
||||||
debug(5, "Text is huffman-encoded");
|
debug(4, "Text is huffman-encoded");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "macventure/gui.h"
|
#include "macventure/gui.h"
|
||||||
#include "macventure/world.h"
|
#include "macventure/world.h"
|
||||||
|
#include "macventure/hufflists.h"
|
||||||
#include "macventure/stringtable.h"
|
#include "macventure/stringtable.h"
|
||||||
#include "macventure/script.h"
|
#include "macventure/script.h"
|
||||||
|
|
||||||
@ -158,6 +159,8 @@ public:
|
|||||||
Common::String getCommandsPausedString() const;
|
Common::String getCommandsPausedString() const;
|
||||||
const GlobalSettings& getGlobalSettings() const;
|
const GlobalSettings& getGlobalSettings() const;
|
||||||
Common::String getFilePath(FilePathID id) const;
|
Common::String getFilePath(FilePathID id) const;
|
||||||
|
bool isOldText() const;
|
||||||
|
const HuffmanLists *getDecodingHuffman() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processEvents();
|
void processEvents();
|
||||||
@ -193,7 +196,7 @@ private: // Attributes
|
|||||||
GameState _gameState;
|
GameState _gameState;
|
||||||
GlobalSettings _globalSettings;
|
GlobalSettings _globalSettings;
|
||||||
StringTable *_filenames;
|
StringTable *_filenames;
|
||||||
Common::Huffman *_textHuffman;
|
HuffmanLists *_textHuffman;
|
||||||
bool _oldTextEncoding;
|
bool _oldTextEncoding;
|
||||||
bool _paused, _halted, _cmdReady, _prepared;
|
bool _paused, _halted, _cmdReady, _prepared;
|
||||||
bool _haltedAtEnd, _haltedInSelection;
|
bool _haltedAtEnd, _haltedInSelection;
|
||||||
|
@ -4,6 +4,7 @@ MODULE_OBJS := \
|
|||||||
detection.o \
|
detection.o \
|
||||||
gui.o \
|
gui.o \
|
||||||
object.o \
|
object.o \
|
||||||
|
text.o \
|
||||||
macventure.o \
|
macventure.o \
|
||||||
world.o \
|
world.o \
|
||||||
|
|
||||||
|
146
engines/macventure/text.cpp
Normal file
146
engines/macventure/text.cpp
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/* ScummVM - Graphic Adventure Engine
|
||||||
|
*
|
||||||
|
* ScummVM is the legal property of its developers, whose names
|
||||||
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||||
|
* file distributed with this source distribution.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "macventure/text.h"
|
||||||
|
|
||||||
|
namespace MacVenture {
|
||||||
|
TextAsset::TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman) {
|
||||||
|
_id = objid;
|
||||||
|
_container = container;
|
||||||
|
_huffman = huffman;
|
||||||
|
|
||||||
|
if (isOld) {
|
||||||
|
decodeOld();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
decodeHuffman();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAsset::decodeOld() {
|
||||||
|
Common::SeekableReadStream *res = _container->getItem(_id);
|
||||||
|
uint16 strLen = res->readUint16BE();
|
||||||
|
Common::BitStream32BELSB stream(res);
|
||||||
|
char* str = new char[strLen + 1];
|
||||||
|
bool lowercase = false;
|
||||||
|
char c;
|
||||||
|
for (uint16 i = 0; i < strLen; i++) {
|
||||||
|
char val = stream.getBits(5);
|
||||||
|
if (val == 0x0) { // Space
|
||||||
|
c = ' ';
|
||||||
|
}
|
||||||
|
else if (val >= 0x1 && val <= 0x1A) {
|
||||||
|
if (lowercase) { // Ascii a-z
|
||||||
|
c = val + 0x60;
|
||||||
|
}
|
||||||
|
else { // Ascii A-Z
|
||||||
|
c = val + 0x40;
|
||||||
|
}
|
||||||
|
lowercase = true;
|
||||||
|
}
|
||||||
|
else if (val == 0x1B) {
|
||||||
|
if (lowercase) {
|
||||||
|
c = '.';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c = ',';
|
||||||
|
}
|
||||||
|
lowercase = true;
|
||||||
|
}
|
||||||
|
else if (val == 0x1C) {
|
||||||
|
if (lowercase) {
|
||||||
|
c = 0x27; // Ascii '
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c = 0x22; // Ascii '"'
|
||||||
|
}
|
||||||
|
lowercase = true;
|
||||||
|
}
|
||||||
|
else if (val == 0x1D) { // Composite
|
||||||
|
warning("Composite strings not implemented");
|
||||||
|
stream.getBits(16);
|
||||||
|
lowercase = true;
|
||||||
|
}
|
||||||
|
else if (val == 0x1E) {
|
||||||
|
c = stream.getBits(8);
|
||||||
|
lowercase = true;
|
||||||
|
}
|
||||||
|
else if (val == 0x1F) {
|
||||||
|
lowercase = !lowercase;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
warning("Unrecognized char in old text %d, pos %d", _id, i);
|
||||||
|
}
|
||||||
|
str[i] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
str[strLen] = '\0';
|
||||||
|
debug(7, "Decoded %d string (old): %s", _id, str);
|
||||||
|
_decoded = Common::String(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAsset::decodeHuffman() {
|
||||||
|
_decoded = Common::String("Huffman string");
|
||||||
|
Common::SeekableReadStream *res = _container->getItem(_id);
|
||||||
|
Common::BitStream32BEMSB stream(res);
|
||||||
|
uint16 strLen = 0;
|
||||||
|
if (stream.getBit()) {
|
||||||
|
strLen = stream.getBits(15);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strLen = stream.getBits(7);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* str = new char[strLen + 1];
|
||||||
|
uint32 mask = 0;
|
||||||
|
uint32 symbol = 0;
|
||||||
|
char c;
|
||||||
|
for (uint16 i = 0; i < strLen; i++) {
|
||||||
|
mask = stream.peekBits(16); // The mask is OK, so it means that I don't know how to use the huffman
|
||||||
|
uint32 entry;
|
||||||
|
// Find the length index
|
||||||
|
for (entry = 0; entry < _huffman->getNumEntries(); entry++) {
|
||||||
|
if (mask < _huffman->getMask(entry)) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.skip(_huffman->getLength(entry));
|
||||||
|
|
||||||
|
symbol = _huffman->getSymbol(entry);
|
||||||
|
|
||||||
|
if (symbol == 1) { // 7-bit ascii
|
||||||
|
c = stream.getBits(7);
|
||||||
|
}
|
||||||
|
else if (symbol == 2) { // Composite
|
||||||
|
warning("Composite huffman strings not implemented");
|
||||||
|
}
|
||||||
|
else { // Plain ascii
|
||||||
|
c = symbol & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
str[i] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
str[strLen] = '\0';
|
||||||
|
debug(7, "Decoded %d'th string (new): %s", _id, str);
|
||||||
|
_decoded = Common::String(str);
|
||||||
|
}
|
||||||
|
} // End of namespace MacVenture
|
56
engines/macventure/text.h
Normal file
56
engines/macventure/text.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* ScummVM - Graphic Adventure Engine
|
||||||
|
*
|
||||||
|
* ScummVM is the legal property of its developers, whose names
|
||||||
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||||
|
* file distributed with this source distribution.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MACVENTURE_TEXT_H
|
||||||
|
#define MACVENTURE_TEXT_H
|
||||||
|
|
||||||
|
#include "macventure/macventure.h"
|
||||||
|
#include "macventure/hufflists.h"
|
||||||
|
|
||||||
|
namespace MacVenture {
|
||||||
|
typedef uint32 ObjID;
|
||||||
|
|
||||||
|
class TextAsset {
|
||||||
|
public:
|
||||||
|
TextAsset(ObjID objid, Container *container, bool isOld, const HuffmanLists *huffman);
|
||||||
|
~TextAsset() {}
|
||||||
|
|
||||||
|
const Common::String *decode() {
|
||||||
|
return &_decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void decodeOld();
|
||||||
|
void decodeHuffman();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Container *_container;
|
||||||
|
ObjID _id;
|
||||||
|
const HuffmanLists *_huffman;
|
||||||
|
|
||||||
|
Common::String _decoded;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End of namespace MacVenture
|
||||||
|
|
||||||
|
#endif
|
@ -19,7 +19,12 @@ World::World(MacVentureEngine *engine, Common::MacResManager *resMan) {
|
|||||||
|
|
||||||
_saveGame = new SaveGame(_engine, saveGameRes);
|
_saveGame = new SaveGame(_engine, saveGameRes);
|
||||||
_objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str());
|
_objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str());
|
||||||
|
//_gameText = new Container(_engine->getFilePath(kTextPathID).c_str());
|
||||||
|
_gameText = new Container("Shadowgate II/Shadow Text");
|
||||||
|
|
||||||
|
ObjID tid = (ObjID)1;
|
||||||
|
TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman());
|
||||||
|
|
||||||
delete saveGameRes;
|
delete saveGameRes;
|
||||||
saveGameFile.close();
|
saveGameFile.close();
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,13 @@
|
|||||||
|
|
||||||
#include "macventure/macventure.h"
|
#include "macventure/macventure.h"
|
||||||
#include "macventure/container.h"
|
#include "macventure/container.h"
|
||||||
|
#include "macventure/text.h"
|
||||||
|
|
||||||
namespace MacVenture {
|
namespace MacVenture {
|
||||||
|
|
||||||
typedef uint32 ObjID;
|
typedef uint32 ObjID;
|
||||||
typedef Common::Array<uint16> AttributeGroup;
|
typedef Common::Array<uint16> AttributeGroup;
|
||||||
|
class TextAsset;
|
||||||
|
|
||||||
enum ObjectAttributeID {
|
enum ObjectAttributeID {
|
||||||
kAttrParentObject = 0,
|
kAttrParentObject = 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user