Osiris_RestoreMemoryChunks Purpose: Restores the 'auto manage' from file, calls the EVT_MEMRESTORE
| 3031 | // Purpose: |
| 3032 | // Restores the 'auto manage' from file, calls the EVT_MEMRESTORE |
| 3033 | void Osiris_RestoreMemoryChunks(CFILE *file) { |
| 3034 | tOSIRISMEMNODE *curr; |
| 3035 | tOSIRISMEMNODE *memchunk; |
| 3036 | |
| 3037 | // Osiris_CloseMemoryManager(); We might not want to close this down...due to some objects don't get destroyed |
| 3038 | // Osiris_mem_root = NULL; |
| 3039 | curr = Osiris_mem_root; |
| 3040 | if (curr) { |
| 3041 | while (curr->next) { |
| 3042 | curr = curr->next; |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | bool done = false; |
| 3047 | while (!done) { |
| 3048 | int size = cf_ReadInt(file); |
| 3049 | if (size == 0) { |
| 3050 | // we're done |
| 3051 | done = true; |
| 3052 | } else { |
| 3053 | // handle this node |
| 3054 | memchunk = (tOSIRISMEMNODE *)mem_malloc(sizeof(tOSIRISMEMNODE)); |
| 3055 | if (!memchunk) { |
| 3056 | Error("Out of memory"); |
| 3057 | } |
| 3058 | |
| 3059 | memchunk->chunk_id.size = size; |
| 3060 | memchunk->chunk_id.my_id.type = (script_type)cf_ReadByte(file); |
| 3061 | switch (memchunk->chunk_id.my_id.type) { |
| 3062 | case OBJECT_SCRIPT: |
| 3063 | memchunk->chunk_id.my_id.objhandle = cf_ReadInt(file); |
| 3064 | break; |
| 3065 | case TRIGGER_SCRIPT: |
| 3066 | memchunk->chunk_id.my_id.triggernum = cf_ReadInt(file); |
| 3067 | break; |
| 3068 | case LEVEL_SCRIPT: |
| 3069 | break; |
| 3070 | } |
| 3071 | memchunk->chunk_id.id = cf_ReadInt(file); |
| 3072 | memchunk->memory = mem_malloc(memchunk->chunk_id.size); |
| 3073 | if (!memchunk->memory) { |
| 3074 | Error("Out of memory"); |
| 3075 | } |
| 3076 | cf_ReadBytes((uint8_t *)memchunk->memory, memchunk->chunk_id.size, file); |
| 3077 | memchunk->next = NULL; |
| 3078 | |
| 3079 | // ok, the node is setup, add it to the linked list |
| 3080 | if (!Osiris_mem_root) { |
| 3081 | Osiris_mem_root = curr = memchunk; |
| 3082 | } else { |
| 3083 | curr->next = memchunk; |
| 3084 | curr = curr->next; |
| 3085 | } |
| 3086 | |
| 3087 | tOSIRISEventInfo ei; |
| 3088 | ei.evt_memrestore.id = memchunk->chunk_id.id; |
| 3089 | ei.evt_memrestore.memory_ptr = memchunk->memory; |
| 3090 |
no test coverage detected