2005-01-17 10:57:15 +00:00
|
|
|
/* Copyright (C) 1994-1998 Revolution Software Ltd.
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2003-2006 The ScummVM project
|
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-09 15:12:44 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
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 {
|
|
|
|
class File;
|
|
|
|
}
|
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);
|
|
|
|
void readCluIndex(uint16 fileNum, Common::File *file = NULL);
|
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();
|
2005-02-21 02:29:18 +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();
|
|
|
|
|
|
|
|
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);
|
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);
|
|
|
|
uint8 type = ptr[0];
|
|
|
|
closeResource(res);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 fetchType(byte *ptr) {
|
|
|
|
return ptr[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *fetchName(uint32 res, byte *buf) {
|
|
|
|
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
|