コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public byte[] CptResOpen(uint id)
        {
#if SCUMM_BIG_ENDIAN
            openCptResourceBigEndian(id);
#else
            OpenCptResourceLittleEndian(id);
#endif
            MemHandle handle = ResHandle(id);
            return(handle?.data);
        }
コード例 #3
0
ファイル: MemMan.cs プロジェクト: scemino/nscumm
 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);
     }
 }
コード例 #4
0
ファイル: MemMan.cs プロジェクト: scemino/nscumm
 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;
 }
コード例 #5
0
ファイル: MemMan.cs プロジェクト: scemino/nscumm
 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();
 }
コード例 #6
0
 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();
 }
コード例 #7
0
 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;
     }
 }
コード例 #8
0
 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);
         }
     }
 }
コード例 #9
0
        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;
        }
コード例 #10
0
        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);
                }
            }
        }
コード例 #11
0
 public void InitHandle(MemHandle bsMem)
 {
     // TODO:
 }
コード例 #12
0
ファイル: MemMan.cs プロジェクト: scemino/nscumm
        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;
        }
コード例 #13
0
ファイル: MemMan.cs プロジェクト: scemino/nscumm
 public void InitHandle(MemHandle bsMem)
 {
     // TODO:
 }