Public Member Functions | |
SegManager (ResourceManager *resMan, ScriptPatcher *scriptPatcher) | |
~SegManager () override | |
void | resetSegMan () |
void | saveLoadWithSerializer (Common::Serializer &ser) override |
Script * | allocateScript (int script_nr, SegmentId &seg_id) |
void | deallocateScript (int script_nr) |
void | reconstructStack (EngineState *s) |
SegmentId | getScriptSegment (int script_nr) const |
SegmentId | getScriptSegment (int script_nr, ScriptLoadType load, bool applyScriptPatches=true) |
int | instantiateScript (int script_nr, bool applyScriptPatches=true) |
void | uninstantiateScript (int script_nr) |
reg_t | getClassAddress (int classnr, ScriptLoadType lock, uint16 callerSegment, bool applyScriptPatches=true) |
Script * | getScript (SegmentId seg) |
Script * | getScriptIfLoaded (SegmentId seg) const |
Clone * | allocateClone (reg_t *addr) |
void | reconstructClones () |
DataStack * | allocateStack (int size) |
void | initSysStrings () |
List * | allocateList (reg_t *addr) |
Node * | allocateNode (reg_t *addr) |
reg_t | newNode (reg_t value, reg_t key) |
List * | lookupList (reg_t addr) |
Node * | lookupNode (reg_t addr, bool stopOnDiscarded=true) |
reg_t | allocateHunkEntry (const char *hunk_type, int size) |
void | freeHunkEntry (reg_t addr) |
byte * | getHunkPointer (reg_t addr) |
byte * | allocDynmem (int size, const char *description, reg_t *addr) |
bool | freeDynmem (reg_t addr) |
SegmentRef | dereference (reg_t pointer) |
byte * | derefBulkPtr (reg_t pointer, int entries) |
reg_t * | derefRegPtr (reg_t pointer, int entries) |
char * | derefString (reg_t pointer, int entries=0) |
Common::String | getString (reg_t pointer) |
void | strcpy_ (reg_t dest, reg_t src) |
void | strcpy_ (reg_t dest, const char *src) |
void | strncpy (reg_t dest, reg_t src, size_t n) |
void | strncpy (reg_t dest, const char *src, size_t n) |
void | memcpy (reg_t dest, reg_t src, size_t n) |
void | memcpy (reg_t dest, const byte *src, size_t n) |
void | memcpy (byte *dest, reg_t src, size_t n) |
size_t | strlen (reg_t str) |
SegmentId | findSegmentByType (int type) const |
SegmentObj * | getSegmentObj (SegmentId seg) const |
SegmentType | getSegmentType (SegmentId seg) const |
SegmentObj * | getSegment (SegmentId seg, SegmentType type) const |
Object * | getObject (reg_t pos) const |
bool | isObject (reg_t obj) const |
bool | isHeapObject (reg_t pos) const |
const char * | getObjectName (reg_t pos) |
Common::Array< reg_t > | findObjectsByName (const Common::String &name) |
reg_t | findObjectByName (const Common::String &name, int index=-1) |
Common::Array< reg_t > | findObjectsBySuperClass (const Common::String &superClassName) |
uint32 | classTableSize () const |
Class | getClass (int index) const |
void | setClassOffset (int index, reg_t offset) |
void | resizeClassTable (uint32 size) |
reg_t | getSaveDirPtr () const |
reg_t | getParserPtr () const |
const Common::Array< SegmentObj * > & | getSegments () const |
SegmentId | allocSegment (SegmentObj *mobj) |
Sci::SegManager::SegManager | ( | ResourceManager * | resMan, |
ScriptPatcher * | scriptPatcher | ||
) |
Initialize the segment manager.
|
override |
Deallocate all memory associated with the segment manager.
Script* Sci::SegManager::allocateScript | ( | int | script_nr, |
SegmentId & | seg_id | ||
) |
Allocate a script into the segment manager.
script_nr | The number of the script to load |
seg_id | The segment ID of the newly allocated segment. |
void Sci::SegManager::deallocateScript | ( | int | script_nr | ) |
Forcefully deallocate a previously allocated script.
script_nr | number of the script to deallocate |
void Sci::SegManager::reconstructStack | ( | EngineState * | s | ) |
Reconstructs the stack. Used when restoring saved games
SegmentId Sci::SegManager::getScriptSegment | ( | int | script_nr | ) | const |
Determines the segment occupied by a certain script, if any.
script_nr | Number of the script to look up |
SegmentId Sci::SegManager::getScriptSegment | ( | int | script_nr, |
ScriptLoadType | load, | ||
bool | applyScriptPatches = true |
||
) |
Determines the segment occupied by a certain script. Optionally load it, or load & lock it.
[in] | script_nr | Number of the script to look up |
[in] | load | Flag determining whether to load/lock the script |
[in] | applyScriptPatches | Apply patches for the script, if available |
int Sci::SegManager::instantiateScript | ( | int | script_nr, |
bool | applyScriptPatches = true |
||
) |
Makes sure that a script and its superclasses get loaded to the heap. If the script already has been loaded, only the number of lockers is increased. All scripts containing superclasses of this script are loaded recursively as well, unless 'recursive' is set to zero. The complementary function is "uninstantiateScript()" below.
[in] | script_nr | The script number to load |
[in] | applyScriptPatches | Apply patches for the script, if available |
void Sci::SegManager::uninstantiateScript | ( | int | script_nr | ) |
Decreases the numer of lockers of a script and unloads it if that number reaches zero. This function will recursively unload scripts containing its superclasses, if those aren't locked by other scripts as well.
[in] | script_nr | The script number that is requestet to be unloaded |
Script* Sci::SegManager::getScript | ( | SegmentId | seg | ) |
Script* Sci::SegManager::getScriptIfLoaded | ( | SegmentId | seg | ) | const |
Return a pointer to the specified script. If the id is invalid, does not refer to a script, or the script is not loaded, this will return NULL
seg | ID of the script segment to check for |
Allocate a fresh clone
addr | The offset of the freshly allocated clone |
void Sci::SegManager::reconstructClones | ( | ) |
Reconstructs clones. Used when restoring saved games
DataStack* Sci::SegManager::allocateStack | ( | int | size | ) |
Allocates a data stack
size | Number of stack entries to reserve |
void Sci::SegManager::initSysStrings | ( | ) |
Initializes the system string table.
Allocate a fresh list
[in] | addr | The offset of the freshly allocated list |
Allocate a fresh node
[in] | addr | The offset of the freshly allocated node |
Allocate and initialize a new list node.
[in] | value | The value to set the node to |
[in] | key | The key to set |
Resolves a list pointer to a list.
addr | The address to resolve |
Resolves an address into a list node.
addr | The address to resolve |
reg_t Sci::SegManager::allocateHunkEntry | ( | const char * | hunk_type, |
int | size | ||
) |
Allocate a fresh chunk of the hunk
[in] | size | Number of bytes to allocate for the hunk entry |
[in] | hunk_type | A descriptive string for the hunk entry, for debugging purposes |
void Sci::SegManager::freeHunkEntry | ( | reg_t | addr | ) |
Deallocates a hunk entry
[in] | addr | Offset of the hunk entry to delete |
byte* Sci::SegManager::getHunkPointer | ( | reg_t | addr | ) |
Gets a pointer to the hunk memory referenced by a specified handle
[in] | addr | Offset of the hunk entry |
byte* Sci::SegManager::allocDynmem | ( | int | size, |
const char * | description, | ||
reg_t * | addr | ||
) |
Allocate some dynamic memory
[in] | size | Number of bytes to allocate |
[in] | description | A descriptive string for debugging purposes |
[out] | addr | The offset of the freshly allocated X |
bool Sci::SegManager::freeDynmem | ( | reg_t | addr | ) |
Deallocates a piece of dynamic memory
[in] | addr | Offset of the dynmem chunk to free |
SegmentRef Sci::SegManager::dereference | ( | reg_t | pointer | ) |
Dereferences a raw memory pointer
[in] | reg | The reference to dereference |
byte* Sci::SegManager::derefBulkPtr | ( | reg_t | pointer, |
int | entries | ||
) |
Dereferences a heap pointer pointing to raw memory.
pointer | The pointer to dereference entries The number of values expected (for checkingO |
Dereferences a heap pointer pointing to a (list of) register(s). Ensures alignedness of data.
pointer | The pointer to dereference entries The number of values expected (for checking) |
char* Sci::SegManager::derefString | ( | reg_t | pointer, |
int | entries = 0 |
||
) |
Dereferences a heap pointer pointing to raw memory.
pointer | The pointer to dereference entries The number of values expected (for checking) |
Common::String Sci::SegManager::getString | ( | reg_t | pointer | ) |
Return the string referenced by pointer. pointer can point to either a raw or non-raw segment.
pointer | The pointer to dereference |
Copies a string from src to dest. src and dest can point to raw and non-raw segments. Conversion is performed as required.
void Sci::SegManager::strcpy_ | ( | reg_t | dest, |
const char * | src | ||
) |
Copies a string from src to dest. dest can point to a raw or non-raw segment. Conversion is performed as required.
Copies a string from src to dest. src and dest can point to raw and non-raw segments. Conversion is performed as required. At most n characters are copied. TODO: determine if dest should always be null-terminated.
void Sci::SegManager::strncpy | ( | reg_t | dest, |
const char * | src, | ||
size_t | n | ||
) |
Copies a string from src to dest. dest can point to a raw or non-raw segment. Conversion is performed as required. At most n characters are copied. TODO: determine if dest should always be null-terminated.
Copies n bytes of data from src to dest. src and dest can point to raw and non-raw segments. Conversion is performed as required.
void Sci::SegManager::memcpy | ( | reg_t | dest, |
const byte * | src, | ||
size_t | n | ||
) |
Copies n bytes of data from src to dest. dest can point to a raw or non-raw segment. Conversion is performed as required.
void Sci::SegManager::memcpy | ( | byte * | dest, |
reg_t | src, | ||
size_t | n | ||
) |
Copies n bytes of data from src to dest. src can point to raw and non-raw segments. Conversion is performed as required.
size_t Sci::SegManager::strlen | ( | reg_t | str | ) |
Determine length of string at str. str can point to a raw or non-raw segment.
SegmentId Sci::SegManager::findSegmentByType | ( | int | type | ) | const |
Finds a unique segment by type
type | The type of the segment to find |
Retrieves an object from the specified location
[in] | offset | Location (segment, offset) of the object |
|
inline |
Checks whether a heap address contains an object obj The address to check
const char* Sci::SegManager::getObjectName | ( | reg_t | pos | ) |
Determines the name of an object
[in] | pos | Location (segment, offset) of the object |
Common::Array<reg_t> Sci::SegManager::findObjectsByName | ( | const Common::String & | name | ) |
Finds the addresses of all objects with the given name.
reg_t Sci::SegManager::findObjectByName | ( | const Common::String & | name, |
int | index = -1 |
||
) |
Find the address of an object by its name. In case multiple objects with the same name occur, the optional index parameter can be used to distinguish between them. If index is -1, then if there is a unique object with the specified name, its address is returned; if there are multiple matches, or none, then NULL_REG is returned.
name | the name of the object we are looking for |
index | the index of the object in case there are multiple |
Common::Array<reg_t> Sci::SegManager::findObjectsBySuperClass | ( | const Common::String & | superClassName | ) |
Finds the addresses of all objects with the superclass of the given name.