2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
2007-05-31 20:28:29 +00:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
*
|
2003-07-28 01:44:38 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:44:38 +00:00
|
|
|
*/
|
|
|
|
|
2006-02-12 19:57:23 +00:00
|
|
|
#ifndef SWORD2_RESMAN_H
|
|
|
|
#define SWORD2_RESMAN_H
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
namespace Common {
|
2011-04-25 19:29:26 +00:00
|
|
|
class File;
|
2005-05-10 22:56:25 +00:00
|
|
|
}
|
2005-02-21 02:29:18 +00:00
|
|
|
|
|
|
|
#define MAX_MEM_CACHE (8 * 1024 * 1024) // we keep up to 8 megs of resource data files in memory
|
2005-02-21 08:16:50 +00:00
|
|
|
#define MAX_res_files 20
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-02-22 07:37:50 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
class Sword2Engine;
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
struct Resource {
|
|
|
|
byte *ptr;
|
|
|
|
uint32 size;
|
|
|
|
uint32 refCount;
|
2005-02-21 02:29:18 +00:00
|
|
|
Resource *next, *prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ResourceFile {
|
|
|
|
char fileName[20];
|
|
|
|
int32 numEntries;
|
|
|
|
uint32 *entryTab;
|
|
|
|
uint8 cd;
|
2004-04-23 07:02:11 +00:00
|
|
|
};
|
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
class ResourceManager {
|
2003-09-26 10:07:18 +00:00
|
|
|
private:
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File *openCluFile(uint16 fileNum);
|
2007-03-01 17:13:23 +00:00
|
|
|
void readCluIndex(uint16 fileNum, Common::File *file);
|
2005-02-21 02:29:18 +00:00
|
|
|
void removeFromCacheList(Resource *res);
|
|
|
|
void addToCacheList(Resource *res);
|
2005-02-22 07:37:50 +00:00
|
|
|
void checkMemUsage();
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
Sword2Engine *_vm;
|
|
|
|
|
2005-12-21 10:57:48 +00:00
|
|
|
int _curCD;
|
2003-09-30 09:27:27 +00:00
|
|
|
uint32 _totalResFiles;
|
|
|
|
uint32 _totalClusters;
|
2003-09-26 10:07:18 +00:00
|
|
|
|
|
|
|
// Gode generated res-id to res number/rel number conversion table
|
|
|
|
|
2003-09-30 09:27:27 +00:00
|
|
|
uint16 *_resConvTable;
|
2005-02-21 02:29:18 +00:00
|
|
|
ResourceFile _resFiles[MAX_res_files];
|
|
|
|
Resource *_resList;
|
2003-09-26 10:07:18 +00:00
|
|
|
|
2005-02-21 08:16:50 +00:00
|
|
|
Resource *_cacheStart, *_cacheEnd;
|
2005-02-21 02:29:18 +00:00
|
|
|
uint32 _usedMem; // amount of used memory in bytes
|
2005-02-22 07:37:50 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
ResourceManager(Sword2Engine *vm); // read in the config file
|
|
|
|
~ResourceManager();
|
|
|
|
|
2006-04-26 06:12:03 +00:00
|
|
|
bool init();
|
|
|
|
|
2005-02-22 07:37:50 +00:00
|
|
|
uint32 getNumResFiles() { return _totalResFiles; }
|
|
|
|
uint32 getNumClusters() { return _totalClusters; }
|
|
|
|
ResourceFile *getResFiles() { return _resFiles; }
|
|
|
|
Resource *getResList() { return _resList; }
|
|
|
|
|
|
|
|
byte *openResource(uint32 res, bool dump = false);
|
|
|
|
void closeResource(uint32 res);
|
|
|
|
|
|
|
|
bool checkValid(uint32 res);
|
|
|
|
uint32 fetchLen(uint32 res);
|
2009-04-07 19:52:46 +00:00
|
|
|
uint8 fetchType(byte *ptr);
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
uint8 fetchType(uint32 res) {
|
|
|
|
byte *ptr = openResource(res);
|
2009-04-07 19:52:46 +00:00
|
|
|
uint8 type = fetchType(ptr);
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
closeResource(res);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2006-07-08 20:45:01 +00:00
|
|
|
byte *fetchName(uint32 res, byte *buf = NULL) {
|
|
|
|
static byte tempbuf[NAME_LEN];
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
buf = tempbuf;
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
byte *ptr = openResource(res);
|
|
|
|
memcpy(buf, ptr + 10, NAME_LEN);
|
|
|
|
closeResource(res);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *fetchName(byte *ptr) {
|
|
|
|
return ptr + 10;
|
|
|
|
}
|
2005-02-22 07:37:50 +00:00
|
|
|
|
|
|
|
// Prompts the user for the specified CD.
|
2005-12-21 10:57:48 +00:00
|
|
|
void askForCD(int cd);
|
2005-02-22 07:37:50 +00:00
|
|
|
|
2005-12-21 10:57:48 +00:00
|
|
|
void setCD(int cd) {
|
2006-01-01 16:29:23 +00:00
|
|
|
if (cd)
|
|
|
|
_curCD = cd;
|
2005-12-21 10:57:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int getCD() {
|
|
|
|
return _curCD;
|
|
|
|
}
|
2005-02-22 07:37:50 +00:00
|
|
|
|
|
|
|
void remove(int res);
|
|
|
|
void removeAll();
|
|
|
|
|
|
|
|
// ----console commands
|
|
|
|
|
|
|
|
void killAll(bool wantInfo);
|
|
|
|
void killAllObjects(bool wantInfo);
|
2005-02-21 02:29:18 +00:00
|
|
|
};
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|