ScummVM API documentation
Sci::SegManager Class Reference
Inheritance diagram for Sci::SegManager:
Common::Serializable

Public Member Functions

 SegManager (ResourceManager *resMan, ScriptPatcher *scriptPatcher)
 
 ~SegManager () override
 
void resetSegMan ()
 
void saveLoadWithSerializer (Common::Serializer &ser) override
 
ScriptallocateScript (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)
 
ScriptgetScript (SegmentId seg)
 
ScriptgetScriptIfLoaded (SegmentId seg) const
 
CloneallocateClone (reg_t *addr)
 
void reconstructClones ()
 
DataStackallocateStack (int size)
 
void initSysStrings ()
 
ListallocateList (reg_t *addr)
 
NodeallocateNode (reg_t *addr)
 
reg_t newNode (reg_t value, reg_t key)
 
ListlookupList (reg_t addr)
 
NodelookupNode (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_tderefRegPtr (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
 
SegmentObjgetSegmentObj (SegmentId seg) const
 
SegmentType getSegmentType (SegmentId seg) const
 
SegmentObjgetSegment (SegmentId seg, SegmentType type) const
 
ObjectgetObject (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_tfindObjectsByName (const Common::String &name)
 
reg_t findObjectByName (const Common::String &name, int index=-1)
 
Common::Array< reg_tfindObjectsBySuperClass (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)
 

Constructor & Destructor Documentation

◆ SegManager()

Sci::SegManager::SegManager ( ResourceManager resMan,
ScriptPatcher scriptPatcher 
)

Initialize the segment manager.

◆ ~SegManager()

Sci::SegManager::~SegManager ( )
override

Deallocate all memory associated with the segment manager.

Member Function Documentation

◆ allocateScript()

Script* Sci::SegManager::allocateScript ( int  script_nr,
SegmentId &  seg_id 
)

Allocate a script into the segment manager.

Parameters
script_nrThe number of the script to load
seg_idThe segment ID of the newly allocated segment.
Returns
The script

◆ deallocateScript()

void Sci::SegManager::deallocateScript ( int  script_nr)

Forcefully deallocate a previously allocated script.

Parameters
script_nrnumber of the script to deallocate

◆ reconstructStack()

void Sci::SegManager::reconstructStack ( EngineState s)

Reconstructs the stack. Used when restoring saved games

◆ getScriptSegment() [1/2]

SegmentId Sci::SegManager::getScriptSegment ( int  script_nr) const

Determines the segment occupied by a certain script, if any.

Parameters
script_nrNumber of the script to look up
Returns
The script's segment ID, or 0 on failure

◆ getScriptSegment() [2/2]

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.

Parameters
[in]script_nrNumber of the script to look up
[in]loadFlag determining whether to load/lock the script
[in]applyScriptPatchesApply patches for the script, if available
Returns
The script's segment ID, or 0 on failure

◆ instantiateScript()

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.

Parameters
[in]script_nrThe script number to load
[in]applyScriptPatchesApply patches for the script, if available
Returns
The script's segment ID or 0 if out of heap

◆ uninstantiateScript()

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.

Parameters
[in]script_nrThe script number that is requestet to be unloaded

◆ getScript()

Script* Sci::SegManager::getScript ( SegmentId  seg)

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 invoke error().

Parameters
segID of the script segment to check for
Returns
A pointer to the Script object

◆ getScriptIfLoaded()

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

Parameters
segID of the script segment to check for
Returns
A pointer to the Script object, or NULL

◆ allocateClone()

Clone* Sci::SegManager::allocateClone ( reg_t addr)

Allocate a fresh clone

Parameters
addrThe offset of the freshly allocated clone
Returns
Reference to the memory allocated for the clone

◆ reconstructClones()

void Sci::SegManager::reconstructClones ( )

Reconstructs clones. Used when restoring saved games

◆ allocateStack()

DataStack* Sci::SegManager::allocateStack ( int  size)

Allocates a data stack

Parameters
sizeNumber of stack entries to reserve
Returns
The data stack

◆ initSysStrings()

void Sci::SegManager::initSysStrings ( )

Initializes the system string table.

◆ allocateList()

List* Sci::SegManager::allocateList ( reg_t addr)

Allocate a fresh list

Parameters
[in]addrThe offset of the freshly allocated list
Returns
Reference to the memory allocated for the list

◆ allocateNode()

Node* Sci::SegManager::allocateNode ( reg_t addr)

Allocate a fresh node

Parameters
[in]addrThe offset of the freshly allocated node
Returns
Reference to the memory allocated for the node

◆ newNode()

reg_t Sci::SegManager::newNode ( reg_t  value,
reg_t  key 
)

Allocate and initialize a new list node.

Parameters
[in]valueThe value to set the node to
[in]keyThe key to set
Returns
Pointer to the newly initialized list node

◆ lookupList()

List* Sci::SegManager::lookupList ( reg_t  addr)

Resolves a list pointer to a list.

Parameters
addrThe address to resolve
Returns
The list referenced, or NULL on error

◆ lookupNode()

Node* Sci::SegManager::lookupNode ( reg_t  addr,
bool  stopOnDiscarded = true 
)

Resolves an address into a list node.

Parameters
addrThe address to resolve
Returns
The list node referenced, or NULL on error

◆ allocateHunkEntry()

reg_t Sci::SegManager::allocateHunkEntry ( const char *  hunk_type,
int  size 
)

Allocate a fresh chunk of the hunk

Parameters
[in]sizeNumber of bytes to allocate for the hunk entry
[in]hunk_typeA descriptive string for the hunk entry, for debugging purposes
Returns
The offset of the freshly allocated hunk entry

◆ freeHunkEntry()

void Sci::SegManager::freeHunkEntry ( reg_t  addr)

Deallocates a hunk entry

Parameters
[in]addrOffset of the hunk entry to delete

◆ getHunkPointer()

byte* Sci::SegManager::getHunkPointer ( reg_t  addr)

Gets a pointer to the hunk memory referenced by a specified handle

Parameters
[in]addrOffset of the hunk entry

◆ allocDynmem()

byte* Sci::SegManager::allocDynmem ( int  size,
const char *  description,
reg_t addr 
)

Allocate some dynamic memory

Parameters
[in]sizeNumber of bytes to allocate
[in]descriptionA descriptive string for debugging purposes
[out]addrThe offset of the freshly allocated X
Returns
Raw pointer into the allocated dynamic memory

◆ freeDynmem()

bool Sci::SegManager::freeDynmem ( reg_t  addr)

Deallocates a piece of dynamic memory

Parameters
[in]addrOffset of the dynmem chunk to free

◆ dereference()

SegmentRef Sci::SegManager::dereference ( reg_t  pointer)

Dereferences a raw memory pointer

Parameters
[in]regThe reference to dereference
Returns
The data block referenced

◆ derefBulkPtr()

byte* Sci::SegManager::derefBulkPtr ( reg_t  pointer,
int  entries 
)

Dereferences a heap pointer pointing to raw memory.

Parameters
pointerThe pointer to dereference entries The number of values expected (for checkingO
Returns
A physical reference to the address pointed to, or NULL on error or if not enough entries were available.

◆ derefRegPtr()

reg_t* Sci::SegManager::derefRegPtr ( reg_t  pointer,
int  entries 
)

Dereferences a heap pointer pointing to a (list of) register(s). Ensures alignedness of data.

Parameters
pointerThe pointer to dereference entries The number of values expected (for checking)
Returns
A physical reference to the address pointed to, or NULL on error or if not enough entries were available.

◆ derefString()

char* Sci::SegManager::derefString ( reg_t  pointer,
int  entries = 0 
)

Dereferences a heap pointer pointing to raw memory.

Parameters
pointerThe pointer to dereference entries The number of values expected (for checking)
Returns
A physical reference to the address pointed to, or NULL on error or if not enough entries were available.

◆ getString()

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.

Parameters
pointerThe pointer to dereference
Returns
The string referenced, or an empty string if not enough entries were available.

◆ strcpy_() [1/2]

void Sci::SegManager::strcpy_ ( reg_t  dest,
reg_t  src 
)

Copies a string from src to dest. src and dest can point to raw and non-raw segments. Conversion is performed as required.

◆ strcpy_() [2/2]

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.

◆ strncpy() [1/2]

void Sci::SegManager::strncpy ( reg_t  dest,
reg_t  src,
size_t  n 
)

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.

◆ strncpy() [2/2]

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.

◆ memcpy() [1/3]

void Sci::SegManager::memcpy ( reg_t  dest,
reg_t  src,
size_t  n 
)

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.

◆ memcpy() [2/3]

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.

◆ memcpy() [3/3]

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.

◆ strlen()

size_t Sci::SegManager::strlen ( reg_t  str)

Determine length of string at str. str can point to a raw or non-raw segment.

◆ findSegmentByType()

SegmentId Sci::SegManager::findSegmentByType ( int  type) const

Finds a unique segment by type

Parameters
typeThe type of the segment to find
Returns
The segment number, or -1 if the segment wasn't found

◆ getObject()

Object* Sci::SegManager::getObject ( reg_t  pos) const

Retrieves an object from the specified location

Parameters
[in]offsetLocation (segment, offset) of the object
Returns
The object in question, or NULL if there is none

◆ isObject()

bool Sci::SegManager::isObject ( reg_t  obj) const
inline

Checks whether a heap address contains an object obj The address to check

Returns
True if it is an object, false otherwise

◆ getObjectName()

const char* Sci::SegManager::getObjectName ( reg_t  pos)

Determines the name of an object

Parameters
[in]posLocation (segment, offset) of the object
Returns
A name for that object, or a string describing an error that occurred while looking it up. The string is stored in a static buffer and need not be freed (neither may it be modified).

◆ findObjectsByName()

Common::Array<reg_t> Sci::SegManager::findObjectsByName ( const Common::String name)

Finds the addresses of all objects with the given name.

◆ findObjectByName()

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.

Parameters
namethe name of the object we are looking for
indexthe index of the object in case there are multiple
Returns
the address of the object, or NULL_REG

◆ findObjectsBySuperClass()

Common::Array<reg_t> Sci::SegManager::findObjectsBySuperClass ( const Common::String superClassName)

Finds the addresses of all objects with the superclass of the given name.


The documentation for this class was generated from the following file: