MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / Osiris_UnloadLevelModule

Function Osiris_UnloadLevelModule

Descent3/OsirisLoadandBind.cpp:836–880  ·  view source on GitHub ↗

Osiris_UnloadLevelModule Purpose: Instead of saving the handle returned from Osiris_LoadLevelModule() and calling Osiris_UnloadModule() with that handle, you can just call this, instead of the call to Osiris_UnloadModule().

Source from the content-addressed store, hash-verified

834// Osiris_UnloadModule() with that handle, you can just call this, instead of the call
835// to Osiris_UnloadModule().
836void Osiris_UnloadLevelModule(void) {
837 Osiris_level_script_loaded = false;
838
839 if ((Game_mode & GM_MULTI) && (Netgame.local_role != LR_SERVER)) {
840 // no scripts for a client!
841 return;
842 }
843
844 // free allocated scripts (we can do this, because the root node will just become
845 // NULL and once the first call to allocate memory is used, it'll automatically work)
846 Osiris_CloseMemoryManager();
847
848 if (tOSIRISCurrentLevel.level_loaded) {
849 int dll_id = tOSIRISCurrentLevel.dll_id;
850
851 // free up all instances of trigger scripts still around
852 for (int i = 0; i < Num_triggers; i++) {
853 if (Triggers[i].osiris_script.script_instance) {
854 OSIRIS_loaded_modules[dll_id].DestroyInstance(Triggers[i].osiris_script.script_id,
855 Triggers[i].osiris_script.script_instance);
856 }
857 Triggers[i].osiris_script.script_id = -1;
858 Triggers[i].osiris_script.script_instance = NULL;
859 }
860
861 Osiris_UnloadModule(dll_id);
862 }
863
864 // go through the remaining modules and unload those with the OSIMF_NOUNLOAD set
865 for (int j = 0; j < MAX_LOADED_MODULES; j++) {
866
867 if (OSIRIS_loaded_modules[j].flags & OSIMF_INUSE && OSIRIS_loaded_modules[j].flags & OSIMF_NOUNLOAD) {
868 // unload this module
869 mprintf(0, "OSIRIS: Unloading static module (%s) due to level end\n", OSIRIS_loaded_modules[j].module_name);
870 Osiris_FreeModule(j);
871 }
872
873 if (OSIRIS_loaded_modules[j].flags & OSIMF_INUSE && (!(OSIRIS_loaded_modules[j].flags & OSIMF_DLLELSEWHERE))) {
874 // Please get Jeff
875 // We are done with the level and all modules should be unloaded at this point,
876 // however, this module is still in use....
877 Osiris_FreeModule(j);
878 }
879 }
880}
881
882// returns: -2 if not found
883// -1 if it is in data\scripts

Callers 1

FreeLevelScriptFunction · 0.85

Calls 3

Osiris_UnloadModuleFunction · 0.85
Osiris_FreeModuleFunction · 0.85

Tested by

no test coverage detected