Navigation:  AlienAPI Basics >

DynaLoading

Previous pageReturn to chapter overviewNext page

To allow it to handle very large sector maps, AstroSynthesis only keeps in memory the star system data it needs to be able to display the 3D map.  In practice, this means that at any given time, only the root body of a system is guaranteed to be loaded in memory.  If you want to access the contents of a system (planets, moons, and other child bodies), you must use the DynaLoad methods to tell AstroSynthesis to load the system data from the .sector file.

 

To do this, you can use the DynaLoad method of the Sector class.  Call this method by passing in the system's root body into the DynaLoad method.

                       

       sector = GetCurrentSector()

       b = sector.GetBody( 0)  'get the first body in the sector

       sector.DynaLoad( b)

 

 

You can also first test to see if a body is loaded or not before calling DynaLoad by checking the body's Loaded attribute.

 

       sector = GetCurrentSector()

       b = sector.GetBody( 0)  'get the first body in the sector

       If Not b.Loaded Then

               sector.DynaLoad( b)

       End If

 

 

After DynaLoading a system from the file, you may want to free that memory if you are done looking at that star system.  Otherwise, if you cycle through every system on the map and DynaLoad it, you may end up using a tremendous amount of RAM (or just running out of RAM).  To release the system from memory, call the Sector's DynaUnload method.

 

       sector = GetCurrentSector()

       b = sector.GetBody( 0)  'get the first body in the sector

       If Not b.Loaded Then

               sector.DynaLoad( b)

       End If

       

       '... do the rest of your script

 

       sector.DynaUnload( b)  'Only do this if you HAVE NOT made any changes to the system

 

 

It's important that you do not DynaUnload a system if you've made changes to it.  That is, if you added new bodies to the system, changed some names or populations, added custom fields, etc.  If you Unload a system that has changes, those changes will be lost.

 

A good practice is to only DynaUnload a body that you previously loaded in your script, and thus know for sure whether or not it has been changed.  You'd only unload systems you've loaded yourself in your script so that you do not accidentally unload a system that was modified by the user via the program's user interface.  To do this, use a script variable to track whether or not the body was loaded by your script and thus can be unloaded.  But remember - don't unload a system that you make any changes to.

       

       sector = GetCurrentSector()

       b = sector.GetBody( 0)  'get the first body in the sector

       

       bUnload = False

       If Not b.Loaded Then

               sector.DynaLoad b

               bUnload = True  'make a note that this body needs to be unloaded

       End If

       

       '... do the rest of your script

 

       'if your script had loaded the body, unload it

       If bUnload Then

               sector.DynaUnload b  'Only do this if you HAVE NOT made any changes to the system

       End If