1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
$Id: resource_manager.h,v 1.16 2001/12/15 01:30:07 mbn Exp $
------------------------------------------------------------------------
ClanLib, the platform independent game SDK.
This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
version 2. See COPYING for details.
For a total list of contributers see CREDITS.
See http://www.clanlib.org
------------------------------------------------------------------------
*/
//! clanCore="Resources"
//! header=core.h
#ifndef header_resource_manager
#define header_resource_manager
#include <list>
#include <string>
class CL_Resource;
class CL_InputSourceProvider;
class CL_ResourceManager_File;
class CL_ResourceManager
//: The ClanLib resource manager.
//- The resource manager is used to retrieve resources from a given resource source.
//- <p>This can either be a resource script file (used as input to the
//- datafile compiler), or a datafile with all the resources included into
//- one large gzipped resource file.</p>
//-
//- <p>To speedup loading of resources in a game, you can load entire sections
//- of resources at once. When a resource in the section is requested, it is
//- returned instantly without having to access the disk. This is especially
//- useful to make sure all the game resources are loaded before the game is
//- started.</p>
//-
//- <p>Resources are normally not retrieved using the get_resource() function.
//- Instead, you should load the resource using the appropiate resource type
//- class. For instance, a surface is easiest loaded like this:</p>
//-
//- CL_ResourceManager res_manager("my_datafile.dat", true);
//- CL_Surface my_surface("my_surface", res_manager);
//-
//- <p>Getting the same resource twice won't create a new instance of the
//- resource; they are reference counted.</p>
{
//! Construction:
public:
//: Resource Manager constructor.
//- config_file - the name of the file in which the resources are defined
//- provider - the optional inputprovider in which, the resource file is stored
//- read_directly_from_source - if true, any resources are loaded directly from their source, meaning that any datafile-directive is ignored.
CL_ResourceManager(
const std::string &config_file,
CL_InputSourceProvider *provider = NULL,
bool read_directly_from_source=false,
bool delete_inputsource_provider=false);
//: Resource Manager constructor.
//- file_name - the name of the file to open
//- is_datafile - indicates if the file is a scriptfile or a datafile
CL_ResourceManager(
const std::string &config_file,
const bool is_datafile );
//: Resource Manager constructor.
//- file_name - the name of the file to open
//- is_datafile - indicates if the file is a scriptfile or a datafile
//- additional_resources - additional resources to be included into the resource set.
CL_ResourceManager(
const std::string &config_file,
const bool is_datafile,
CL_ResourceManager &additional_resources);
//: Resource Manager Constructor
CL_ResourceManager(const CL_ResourceManager ©);
//: Construct empty resource manager.
CL_ResourceManager();
//: Resource Manager Destructor
~CL_ResourceManager();
//! Attributes:
public:
//: Returns a pointer to the CL_Resource representing the given resource
CL_Resource &get_resource(const std::string &res_id);
//: Returns a list of all resources available.
//: Primarily used by the datafile compiler to build datafiles from resources.
//- Returns - The list of resources available. You'll have to delete the list returned.
std::list<std::string> *get_all_resources();
//: Returns a list of all resources available matching a given type.
//: Primarily used by the ClanCompiler to build datafiles from resources.
//- Returns - The list of resources available. You'll have to delete the list returned.
std::list<std::string> *get_resources_of_type(const std::string &type_id);
//: Returns a pointer to the inputsourceprovider, in which all resources are stored
//: (this can be a fileprovider or a datafileprovider depending on method used to load the script file)
//- Returns - Pointer to inputsourceprovider containing resource data.
CL_InputSourceProvider *get_resource_provider() const;
//: Returns true if the resources are loaded from source. False if loaded from a datafile.
bool is_from_source();
//! Operations:
public:
//: Copy a resource manager.
void operator = (const CL_ResourceManager ©);
//: Add resources from an other resource manager.
void add_resources(const CL_ResourceManager &additional_resources);
//: Remove resources from an other resource manager.
void remove_resources(const CL_ResourceManager &additional_resources);
//: Loads all resources into memory.
void load_all();
//: Unloads all resources from memory.
void unload_all();
//: Loads all resources in a given section into memory.
void load_section(const std::string §ion_name);
//: Unloads all resources in a given section into memory.
void unload_section(const std::string §ion_name);
//! Implementation:
public:
//: Resource Manager Constructor
CL_ResourceManager(class CL_ResourceManager_File *impl);
//: Pointer to the implementation
CL_ResourceManager_File *impl;
};
#endif
|