public void ResOpen(uint id) { // load resource ID into memory MemHandle memHandle = ResHandle(id); if (memHandle == null) { return; } if (memHandle.cond == MemMan.MEM_FREED) { // memory has been freed uint size = ResLength(id); _memMan.Alloc(memHandle, size); var clusFile = ResFile(id); Debug.Assert(clusFile != null); clusFile.Seek(ResOffset(id), SeekOrigin.Begin); clusFile.Read(memHandle.data, 0, (int)size); } else { _memMan.SetCondition(memHandle, MemMan.MEM_DONT_FREE); } memHandle.refCount++; if (memHandle.refCount > 20) { // TODO: debug(1, "%d references to id %d. Guess there's something wrong.", memHandle.refCount, id); } }
public byte[] CptResOpen(uint id) { #if SCUMM_BIG_ENDIAN openCptResourceBigEndian(id); #else OpenCptResourceLittleEndian(id); #endif MemHandle handle = ResHandle(id); return(handle?.data); }
public void SetCondition(MemHandle bsMem, ushort pCond) { if ((pCond == MEM_FREED) || (pCond > MEM_DONT_FREE)) throw new InvalidOperationException("MemMan::setCondition: program tried to set illegal memory condition"); if (bsMem.cond != pCond) { bsMem.cond = pCond; if (pCond == MEM_DONT_FREE) RemoveFromFreeList(bsMem); else if (pCond == MEM_CAN_FREE) AddToFreeList(bsMem); } }
void AddToFreeList(MemHandle bsMem) { if (bsMem.next != null || bsMem.prev != null) { // TODO: warning("addToFreeList: mem block is already in freeList"); return; } bsMem.prev = null; bsMem.next = _memListFree; if (bsMem.next != null) bsMem.next.prev = bsMem; _memListFree = bsMem; if (_memListFreeEnd == null) _memListFreeEnd = _memListFree; }
public void Alloc(MemHandle bsMem, uint pSize, ushort pCond = MEM_DONT_FREE) { _alloced += pSize; bsMem.data = new byte[pSize]; bsMem.cond = pCond; bsMem.size = pSize; if (pCond == MEM_CAN_FREE) { // TODO: warning("%d Bytes alloced as FREEABLE.", pSize); // why should one want to alloc mem if it can be freed? AddToFreeList(bsMem); } else if (bsMem.next != null || bsMem.prev != null) // it's in our _freeAble list, remove it from there RemoveFromFreeList(bsMem); CheckMemoryUsage(); }
public void Alloc(MemHandle bsMem, uint pSize, ushort pCond = MEM_DONT_FREE) { _alloced += pSize; bsMem.data = new byte[pSize]; bsMem.cond = pCond; bsMem.size = pSize; if (pCond == MEM_CAN_FREE) { // TODO: warning("%d Bytes alloced as FREEABLE.", pSize); // why should one want to alloc mem if it can be freed? AddToFreeList(bsMem); } else if (bsMem.next != null || bsMem.prev != null) // it's in our _freeAble list, remove it from there { RemoveFromFreeList(bsMem); } CheckMemoryUsage(); }
void AddToFreeList(MemHandle bsMem) { if (bsMem.next != null || bsMem.prev != null) { // TODO: warning("addToFreeList: mem block is already in freeList"); return; } bsMem.prev = null; bsMem.next = _memListFree; if (bsMem.next != null) { bsMem.next.prev = bsMem; } _memListFree = bsMem; if (_memListFreeEnd == null) { _memListFreeEnd = _memListFree; } }
public void SetCondition(MemHandle bsMem, ushort pCond) { if ((pCond == MEM_FREED) || (pCond > MEM_DONT_FREE)) { throw new InvalidOperationException("MemMan::setCondition: program tried to set illegal memory condition"); } if (bsMem.cond != pCond) { bsMem.cond = pCond; if (pCond == MEM_DONT_FREE) { RemoveFromFreeList(bsMem); } else if (pCond == MEM_CAN_FREE) { AddToFreeList(bsMem); } } }
void RemoveFromFreeList(MemHandle bsMem) { if (_memListFree == bsMem) { _memListFree = bsMem.next; } if (_memListFreeEnd == bsMem) { _memListFreeEnd = bsMem.prev; } if (bsMem.next != null) { bsMem.next.prev = bsMem.prev; } if (bsMem.prev != null) { bsMem.prev.next = bsMem.next; } bsMem.next = bsMem.prev = null; }
public void ResClose(uint id) { MemHandle handle = ResHandle(id); if (handle == null) { return; } if (handle.refCount == 0) { // TODO: warning("Resource Manager fail: unlocking object with refCount 0. Id: %d", id); } else { handle.refCount--; if (handle.refCount == 0) { _memMan.SetCondition(handle, MemMan.MEM_CAN_FREE); } } }
public void InitHandle(MemHandle bsMem) { // TODO: }
void RemoveFromFreeList(MemHandle bsMem) { if (_memListFree == bsMem) _memListFree = bsMem.next; if (_memListFreeEnd == bsMem) _memListFreeEnd = bsMem.prev; if (bsMem.next != null) bsMem.next.prev = bsMem.prev; if (bsMem.prev != null) bsMem.prev.next = bsMem.next; bsMem.next = bsMem.prev = null; }