mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-27 05:32:45 +00:00
CHEWY: Initial implementation of a resource manager, and a main loop
This commit is contained in:
parent
9dd2e5d24e
commit
039261e731
@ -20,12 +20,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/error.h"
|
||||
#include "common/events.h"
|
||||
#include "common/system.h"
|
||||
|
||||
#include "engines/engine.h"
|
||||
#include "engines/util.h"
|
||||
|
||||
#include "chewy/chewy.h"
|
||||
#include "chewy/resource.h"
|
||||
|
||||
namespace Chewy {
|
||||
|
||||
@ -33,6 +37,16 @@ ChewyEngine::ChewyEngine(OSystem *syst, const ChewyGameDescription *gameDesc)
|
||||
: Engine(syst),
|
||||
_gameDescription(gameDesc),
|
||||
_rnd("chewy") {
|
||||
|
||||
const Common::FSNode gameDataDir(ConfMan.get("path"));
|
||||
|
||||
SearchMan.addSubDirectoryMatching(gameDataDir, "back");
|
||||
SearchMan.addSubDirectoryMatching(gameDataDir, "cut");
|
||||
SearchMan.addSubDirectoryMatching(gameDataDir, "err");
|
||||
SearchMan.addSubDirectoryMatching(gameDataDir, "misc");
|
||||
SearchMan.addSubDirectoryMatching(gameDataDir, "room");
|
||||
SearchMan.addSubDirectoryMatching(gameDataDir, "sound");
|
||||
SearchMan.addSubDirectoryMatching(gameDataDir, "txt");
|
||||
}
|
||||
|
||||
ChewyEngine::~ChewyEngine() {
|
||||
@ -44,6 +58,28 @@ Common::Error ChewyEngine::run() {
|
||||
|
||||
initialize();
|
||||
|
||||
Resource *res = new Resource("comic.tgp");
|
||||
TBFChunk *cur = res->getChunk(1);
|
||||
|
||||
debug("Chunk 1: packed %d, type %d, pos %d, mode %d, comp %d, unpacked %d, width %d, height %d",
|
||||
cur->packedSize, cur->type, cur->pos, cur->screenMode, cur->compressionFlag, cur->unpackedSize,
|
||||
cur->width, cur->height
|
||||
);
|
||||
|
||||
delete res;
|
||||
|
||||
// Run a dummy loop
|
||||
Common::Event event;
|
||||
|
||||
while (!shouldQuit()) {
|
||||
while (g_system->getEventManager()->pollEvent(event)) {
|
||||
if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP)
|
||||
g_engine->quitGame();
|
||||
}
|
||||
|
||||
g_system->delayMillis(10);
|
||||
}
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,8 @@ MODULE := engines/chewy
|
||||
|
||||
MODULE_OBJS = \
|
||||
chewy.o \
|
||||
detection.o
|
||||
detection.o \
|
||||
resource.o
|
||||
|
||||
|
||||
# This module can be built as a plugin
|
||||
|
82
engines/chewy/resource.cpp
Normal file
82
engines/chewy/resource.cpp
Normal file
@ -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 "common/stream.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/textconsole.h"
|
||||
|
||||
#include "chewy/chewy.h"
|
||||
#include "chewy/resource.h"
|
||||
|
||||
namespace Chewy {
|
||||
|
||||
Resource::Resource(Common::String filename) {
|
||||
_stream.open(filename);
|
||||
uint32 magicBytes = MKTAG('N', 'G', 'S', '\0');
|
||||
if (_stream.readUint32BE() != magicBytes)
|
||||
error("Invalid resource - %s", filename.c_str());
|
||||
_stream.skip(2); // type
|
||||
_chunkCount = _stream.readUint16LE();
|
||||
|
||||
uint32 tbfID = MKTAG('T', 'B', 'F', '\0');
|
||||
|
||||
for (uint i = 0; i < _chunkCount; i++) {
|
||||
TBFChunk cur;
|
||||
cur.packedSize = _stream.readUint32LE();
|
||||
cur.type = _stream.readUint16LE();
|
||||
cur.pos = _stream.pos();
|
||||
if (_stream.readUint32BE() != tbfID)
|
||||
error("Corrupt resource %s", filename.c_str());
|
||||
|
||||
cur.screenMode = _stream.readUint16LE();
|
||||
cur.compressionFlag = _stream.readUint16LE();
|
||||
cur.unpackedSize = _stream.readUint32LE();
|
||||
cur.width = _stream.readUint16LE();
|
||||
cur.height = _stream.readUint16LE();
|
||||
_stream.read(cur.palette, 3 * 256);
|
||||
_stream.skip(cur.packedSize - TBF_CHUNK_HEADER_SIZE);
|
||||
|
||||
_tbfChunkList.push_back(cur);
|
||||
|
||||
/*debug("Chunk %d: packed %d, type %d, pos %d, mode %d, comp %d, unpacked %d, width %d, height %d",
|
||||
i, cur.packedSize, cur.type, cur.pos, cur.screenMode, cur.compressionFlag, cur.unpackedSize,
|
||||
cur.width, cur.height
|
||||
);*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Resource::~Resource() {
|
||||
_tbfChunkList.clear();
|
||||
_stream.close();
|
||||
}
|
||||
|
||||
TBFChunk *Resource::getChunk(int num) {
|
||||
return &_tbfChunkList[num];
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *Resource::getChunkData(int num) {
|
||||
// TODO
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // End of namespace Chewy
|
73
engines/chewy/resource.h
Normal file
73
engines/chewy/resource.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CHEWY_RESOURCE_H
|
||||
#define CHEWY_RESOURCE_H
|
||||
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/file.h"
|
||||
#include "common/util.h"
|
||||
#include "common/str.h"
|
||||
#include "common/hashmap.h"
|
||||
#include "common/hash-str.h"
|
||||
#include "common/random.h"
|
||||
|
||||
namespace Chewy {
|
||||
|
||||
// 4 + 2 + 2 + 4 + 2 + 2 + 768 = 784 bytes
|
||||
#define TBF_CHUNK_HEADER_SIZE 784
|
||||
|
||||
struct TBFChunk {
|
||||
uint32 packedSize; // includes header
|
||||
uint16 type;
|
||||
uint32 pos; // extra field
|
||||
|
||||
// TBF chunk header
|
||||
// ID (TBF, followed by a zero)
|
||||
uint16 screenMode;
|
||||
uint16 compressionFlag;
|
||||
uint32 unpackedSize;
|
||||
uint16 width;
|
||||
uint16 height;
|
||||
char palette[3 * 256];
|
||||
};
|
||||
|
||||
typedef Common::Array<TBFChunk> TBFChunkList;
|
||||
|
||||
class Resource {
|
||||
public:
|
||||
Resource(Common::String filename);
|
||||
~Resource();
|
||||
|
||||
TBFChunk *getChunk(int num);
|
||||
Common::SeekableReadStream *getChunkData(int num);
|
||||
|
||||
private:
|
||||
Common::File _stream;
|
||||
uint16 _chunkCount;
|
||||
TBFChunkList _tbfChunkList;
|
||||
};
|
||||
|
||||
} // End of namespace Chewy
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user