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