mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-26 06:18:23 +00:00
SCI: Renamed some ResourceManager members, cleanup
svn-id: r38596
This commit is contained in:
parent
617c63c1ed
commit
e736b7fa62
@ -125,7 +125,7 @@ struct resource_index_struct {
|
||||
|
||||
typedef struct resource_index_struct resource_index_t;
|
||||
|
||||
typedef struct resource_source_struct {
|
||||
struct ResourceSource {
|
||||
int source_type;
|
||||
int scanned;
|
||||
union {
|
||||
@ -140,15 +140,15 @@ typedef struct resource_source_struct {
|
||||
struct _resource_struct *resource;
|
||||
} internal_map;
|
||||
} location;
|
||||
struct resource_source_struct *associated_map;
|
||||
struct resource_source_struct *next;
|
||||
} ResourceSource;
|
||||
ResourceSource *associated_map;
|
||||
ResourceSource *next;
|
||||
};
|
||||
|
||||
typedef struct _resource_altsource_struct {
|
||||
struct resource_altsource_t {
|
||||
ResourceSource *source;
|
||||
unsigned int file_offset;
|
||||
struct _resource_altsource_struct *next;
|
||||
} resource_altsource_t;
|
||||
resource_altsource_t *next;
|
||||
};
|
||||
|
||||
|
||||
typedef struct _resource_struct {
|
||||
@ -173,13 +173,13 @@ typedef struct _resource_struct {
|
||||
} resource_t; /* for storing resources in memory */
|
||||
|
||||
|
||||
typedef struct {
|
||||
int max_memory; /* Config option: Maximum total byte number allocated */
|
||||
struct ResourceManager {
|
||||
int _maxMemory; /* Config option: Maximum total byte number allocated */
|
||||
int sci_version; /* SCI resource version to use */
|
||||
|
||||
int resources_nr;
|
||||
ResourceSource *sources;
|
||||
resource_t *resources;
|
||||
int _resourcesNr;
|
||||
ResourceSource *_sources;
|
||||
resource_t *_resources;
|
||||
|
||||
int memory_locked; /* Amount of resource bytes in locked memory */
|
||||
int memory_lru; /* Amount of resource bytes under LRU control */
|
||||
@ -188,22 +188,22 @@ typedef struct {
|
||||
|
||||
resource_t *lru_first, *lru_last; /* Pointers to the first and last LRU queue entries */
|
||||
/* LRU queue: lru_first points to the most recent entry */
|
||||
} ResourceManager;
|
||||
};
|
||||
|
||||
/**** FUNCTION DECLARATIONS ****/
|
||||
|
||||
/**--- New Resource manager ---**/
|
||||
|
||||
ResourceManager *
|
||||
scir_new_resource_manager(char *dir, int version, int max_memory);
|
||||
scir_new_resource_manager(char *dir, int version, int maxMemory);
|
||||
/* Creates a new FreeSCI resource manager
|
||||
** Parameters: (char *) dir: Path to the resource and patch files (not modified or freed
|
||||
** by the resource manager)
|
||||
** (int) version: The SCI version to look for; use SCI_VERSION_AUTODETECT
|
||||
** in the default case.
|
||||
** (int) max_memory: Maximum number of bytes to allow allocated for resources
|
||||
** (int) maxMemory: Maximum number of bytes to allow allocated for resources
|
||||
** Returns : (ResourceManager *) A newly allocated resource manager
|
||||
** max_memory will not be interpreted as a hard limit, only as a restriction for resources
|
||||
** maxMemory will not be interpreted as a hard limit, only as a restriction for resources
|
||||
** which are not explicitly locked. However, a warning will be issued whenever this limit
|
||||
** is exceeded.
|
||||
*/
|
||||
@ -437,10 +437,10 @@ byte *pic_reorder(byte *inbuffer, int dsize);
|
||||
/*--- Internal helper functions ---*/
|
||||
|
||||
void
|
||||
_scir_free_resources(resource_t *resources, int resources_nr);
|
||||
_scir_free_resources(resource_t *resources, int resourcesNr);
|
||||
/* Frees a block of resources and associated data
|
||||
** Parameters: (resource_t *) resources: The resources to free
|
||||
** (int) resources_nr: Number of resources in the block
|
||||
** (int) resourcesNr: Number of resources in the block
|
||||
** Returns : (void)
|
||||
*/
|
||||
|
||||
|
@ -165,8 +165,8 @@ scir_add_external_map(ResourceManager *mgr, char *file_name) {
|
||||
malloc(sizeof(ResourceSource));
|
||||
|
||||
/* Add the new source to the SLL of sources */
|
||||
newsrc->next = mgr->sources;
|
||||
mgr->sources = newsrc;
|
||||
newsrc->next = mgr->_sources;
|
||||
mgr->_sources = newsrc;
|
||||
|
||||
newsrc->source_type = RESSOURCE_TYPE_EXTERNAL_MAP;
|
||||
newsrc->location.file.name = strdup(file_name);
|
||||
@ -183,8 +183,8 @@ scir_add_volume(ResourceManager *mgr, ResourceSource *map, char *filename,
|
||||
malloc(sizeof(ResourceSource));
|
||||
|
||||
/* Add the new source to the SLL of sources */
|
||||
newsrc->next = mgr->sources;
|
||||
mgr->sources = newsrc;
|
||||
newsrc->next = mgr->_sources;
|
||||
mgr->_sources = newsrc;
|
||||
|
||||
newsrc->source_type = RESSOURCE_TYPE_VOLUME;
|
||||
newsrc->scanned = 0;
|
||||
@ -200,8 +200,8 @@ scir_add_patch_dir(ResourceManager *mgr, int type, char *dirname) {
|
||||
malloc(sizeof(ResourceSource));
|
||||
|
||||
/* Add the new source to the SLL of sources */
|
||||
newsrc->next = mgr->sources;
|
||||
mgr->sources = newsrc;
|
||||
newsrc->next = mgr->_sources;
|
||||
mgr->_sources = newsrc;
|
||||
|
||||
newsrc->source_type = RESSOURCE_TYPE_DIRECTORY;
|
||||
newsrc->scanned = 0;
|
||||
@ -211,7 +211,7 @@ scir_add_patch_dir(ResourceManager *mgr, int type, char *dirname) {
|
||||
|
||||
ResourceSource *
|
||||
scir_get_volume(ResourceManager *mgr, ResourceSource *map, int volume_nr) {
|
||||
ResourceSource *seeker = mgr->sources;
|
||||
ResourceSource *seeker = mgr->_sources;
|
||||
|
||||
while (seeker) {
|
||||
if (seeker->source_type == RESSOURCE_TYPE_VOLUME &&
|
||||
@ -230,8 +230,8 @@ scir_get_volume(ResourceManager *mgr, ResourceSource *map, int volume_nr) {
|
||||
|
||||
static void
|
||||
_scir_init_trivial(ResourceManager *mgr) {
|
||||
mgr->resources_nr = 0;
|
||||
mgr->resources = (resource_t*)sci_malloc(1);
|
||||
mgr->_resourcesNr = 0;
|
||||
mgr->_resources = (resource_t*)sci_malloc(1);
|
||||
}
|
||||
|
||||
|
||||
@ -339,7 +339,7 @@ scir_test_resource(ResourceManager *mgr, int type, int number) {
|
||||
binseeker.type = type;
|
||||
binseeker.number = number;
|
||||
return (resource_t *)
|
||||
bsearch(&binseeker, mgr->resources, mgr->resources_nr,
|
||||
bsearch(&binseeker, mgr->_resources, mgr->_resourcesNr,
|
||||
sizeof(resource_t), resourcecmp);
|
||||
}
|
||||
|
||||
@ -472,7 +472,7 @@ _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, ResourceSour
|
||||
int preset_version = mgr->sci_version;
|
||||
int resource_error = 0;
|
||||
int dummy = mgr->sci_version;
|
||||
// resource_t **concat_ptr = &(mgr->resources[mgr->resources_nr-1].next);
|
||||
// resource_t **concat_ptr = &(mgr->_resources[mgr->_resourcesNr-1].next);
|
||||
|
||||
if (detected_version == NULL)
|
||||
detected_version = &dummy;
|
||||
@ -487,12 +487,12 @@ _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, ResourceSour
|
||||
case RESSOURCE_TYPE_DIRECTORY:
|
||||
if (mgr->sci_version <= SCI_VERSION_01)
|
||||
sci0_read_resource_patches(source,
|
||||
&mgr->resources,
|
||||
&mgr->resources_nr);
|
||||
&mgr->_resources,
|
||||
&mgr->_resourcesNr);
|
||||
else
|
||||
sci1_read_resource_patches(source,
|
||||
&mgr->resources,
|
||||
&mgr->resources_nr);
|
||||
&mgr->_resources,
|
||||
&mgr->_resourcesNr);
|
||||
break;
|
||||
case RESSOURCE_TYPE_EXTERNAL_MAP:
|
||||
if (preset_version <= SCI_VERSION_01_VGA_ODD
|
||||
@ -500,8 +500,8 @@ _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, ResourceSour
|
||||
resource_error =
|
||||
sci0_read_resource_map(mgr,
|
||||
source,
|
||||
&mgr->resources,
|
||||
&mgr->resources_nr,
|
||||
&mgr->_resources,
|
||||
&mgr->_resourcesNr,
|
||||
detected_version);
|
||||
|
||||
#if 0
|
||||
@ -536,8 +536,8 @@ _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, ResourceSour
|
||||
sci1_read_resource_map(mgr,
|
||||
source,
|
||||
scir_get_volume(mgr, source, 0),
|
||||
&mgr->resources,
|
||||
&mgr->resources_nr,
|
||||
&mgr->_resources,
|
||||
&mgr->_resourcesNr,
|
||||
detected_version);
|
||||
|
||||
if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND) {
|
||||
@ -555,7 +555,7 @@ _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, ResourceSour
|
||||
mgr->sci_version = *detected_version;
|
||||
break;
|
||||
}
|
||||
qsort(mgr->resources, mgr->resources_nr, sizeof(resource_t),
|
||||
qsort(mgr->_resources, mgr->_resourcesNr, sizeof(resource_t),
|
||||
resourcecmp); /* Sort resources */
|
||||
}
|
||||
return resource_error;
|
||||
@ -563,7 +563,7 @@ _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, ResourceSour
|
||||
|
||||
int
|
||||
scir_scan_new_sources(ResourceManager *mgr, int *detected_version) {
|
||||
_scir_scan_new_sources(mgr, detected_version, mgr->sources);
|
||||
_scir_scan_new_sources(mgr, detected_version, mgr->_sources);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -576,7 +576,7 @@ _scir_free_resource_sources(ResourceSource *rss) {
|
||||
}
|
||||
|
||||
ResourceManager *
|
||||
scir_new_resource_manager(char *dir, int version, int max_memory) {
|
||||
scir_new_resource_manager(char *dir, int version, int maxMemory) {
|
||||
int resource_error = 0;
|
||||
ResourceManager *mgr = (ResourceManager*)sci_malloc(sizeof(ResourceManager));
|
||||
char *caller_cwd = sci_getcwd();
|
||||
@ -588,28 +588,28 @@ scir_new_resource_manager(char *dir, int version, int max_memory) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mgr->max_memory = max_memory;
|
||||
mgr->_maxMemory = maxMemory;
|
||||
|
||||
mgr->memory_locked = 0;
|
||||
mgr->memory_lru = 0;
|
||||
|
||||
mgr->resource_path = dir;
|
||||
|
||||
mgr->resources = NULL;
|
||||
mgr->resources_nr = 0;
|
||||
mgr->sources = NULL;
|
||||
mgr->_resources = NULL;
|
||||
mgr->_resourcesNr = 0;
|
||||
mgr->_sources = NULL;
|
||||
mgr->sci_version = version;
|
||||
|
||||
scir_add_appropriate_sources(mgr, dir);
|
||||
scir_scan_new_sources(mgr, &resmap_version);
|
||||
|
||||
if (!mgr->resources || !mgr->resources_nr) {
|
||||
if (mgr->resources) {
|
||||
free(mgr->resources);
|
||||
mgr->resources = NULL;
|
||||
if (!mgr->_resources || !mgr->_resourcesNr) {
|
||||
if (mgr->_resources) {
|
||||
free(mgr->_resources);
|
||||
mgr->_resources = NULL;
|
||||
}
|
||||
sciprintf("Resmgr: Could not retrieve a resource list!\n");
|
||||
_scir_free_resource_sources(mgr->sources);
|
||||
_scir_free_resource_sources(mgr->_sources);
|
||||
free(mgr);
|
||||
chdir(caller_cwd);
|
||||
free(caller_cwd);
|
||||
@ -619,7 +619,7 @@ scir_new_resource_manager(char *dir, int version, int max_memory) {
|
||||
mgr->lru_first = NULL;
|
||||
mgr->lru_last = NULL;
|
||||
|
||||
qsort(mgr->resources, mgr->resources_nr, sizeof(resource_t),
|
||||
qsort(mgr->_resources, mgr->_resourcesNr, sizeof(resource_t),
|
||||
resourcecmp); /* Sort resources */
|
||||
|
||||
if (version == SCI_VERSION_AUTODETECT)
|
||||
@ -685,15 +685,15 @@ scir_new_resource_manager(char *dir, int version, int max_memory) {
|
||||
#if 0
|
||||
if (version <= SCI_VERSION_01)
|
||||
sci0_read_resource_patches(dir,
|
||||
&mgr->resources,
|
||||
&mgr->resources_nr);
|
||||
&mgr->_resources,
|
||||
&mgr->_resourcesNr);
|
||||
else
|
||||
sci1_read_resource_patches(dir,
|
||||
&mgr->resources,
|
||||
&mgr->resources_nr);
|
||||
&mgr->_resources,
|
||||
&mgr->_resourcesNr);
|
||||
#endif
|
||||
|
||||
qsort(mgr->resources, mgr->resources_nr, sizeof(resource_t),
|
||||
qsort(mgr->_resources, mgr->_resourcesNr, sizeof(resource_t),
|
||||
resourcecmp); /* Sort resources */
|
||||
}
|
||||
|
||||
@ -714,10 +714,10 @@ _scir_free_altsources(resource_altsource_t *dynressrc) {
|
||||
}
|
||||
|
||||
void
|
||||
_scir_free_resources(resource_t *resources, int resources_nr) {
|
||||
_scir_free_resources(resource_t *resources, int _resourcesNr) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < resources_nr; i++) {
|
||||
for (i = 0; i < _resourcesNr; i++) {
|
||||
resource_t *res = resources + i;
|
||||
|
||||
// FIXME: alt_sources->next may point to an invalid memory location
|
||||
@ -732,9 +732,9 @@ _scir_free_resources(resource_t *resources, int resources_nr) {
|
||||
|
||||
void
|
||||
scir_free_resource_manager(ResourceManager *mgr) {
|
||||
_scir_free_resources(mgr->resources, mgr->resources_nr);
|
||||
_scir_free_resource_sources(mgr->sources);
|
||||
mgr->resources = NULL;
|
||||
_scir_free_resources(mgr->_resources, mgr->_resourcesNr);
|
||||
_scir_free_resource_sources(mgr->_sources);
|
||||
mgr->_resources = NULL;
|
||||
|
||||
free(mgr);
|
||||
}
|
||||
@ -818,7 +818,7 @@ _scir_print_lru_list(ResourceManager *mgr) {
|
||||
|
||||
static void
|
||||
_scir_free_old_resources(ResourceManager *mgr, int last_invulnerable) {
|
||||
while (mgr->max_memory < mgr->memory_lru
|
||||
while (mgr->_maxMemory < mgr->memory_lru
|
||||
&& (!last_invulnerable || mgr->lru_first != mgr->lru_last)) {
|
||||
resource_t *goner = mgr->lru_last;
|
||||
if (!goner) {
|
||||
|
@ -433,8 +433,8 @@ sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource
|
||||
}
|
||||
|
||||
resources_nr = (fsize - types[0]) / entrysize;
|
||||
resource_start = resources = (resource_t*)sci_realloc(mgr->resources, (mgr->resources_nr + resources_nr) * sizeof(resource_t));
|
||||
resources += mgr->resources_nr;
|
||||
resource_start = resources = (resource_t*)sci_realloc(mgr->_resources, (mgr->_resourcesNr + resources_nr) * sizeof(resource_t));
|
||||
resources += mgr->_resourcesNr;
|
||||
|
||||
i = 0;
|
||||
while (types[i] == 0) i++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user