Plug-in Help

Hello all,

I just purchased AstroSynthesis last week and I am loving it so far. As a PhD Computer Science student I have had plenty of experience with programming, and although I am not familiar with VB I do program in C# so it is not too different. Because of this I have tried modifying 2 plug-ins for my purposes and I have run into a problem.

First I modified Alan Bartholet's Generate New Solar System Bodies so that it generates the system bodies in every system in the sector. It also checks and ensures that the generated system has a population > 1000000 or it does it again. This is working great although it is really slow.

The next plug-in I modified is NBOS's Mass Surface Map / Blazon Generator. I have changed it so that it generates fractal maps for ALL planets not just the most populated ones. I know this will take forever to run, but I have an I7 processor so I am having no problem working on other things while this runs. The problem is that if I don't restrict this I run out of memory (I have 4GB of RAM) which does not surprise me but when I try to restrict it to say 100 and then save it, close it and reload it, those 100 systems are gone. Now any idea why these systems are disappearing? I am also wondering if there is a way in the script to cache the changes so that I can generate all of this at once writing the changes to the disk every 100 or 1000 or so.

Anyway here is my code in case it helps:
#plugin Mass Surface Map / Blazon Generator
#author NBOS
#desc   Generates a surface map For the most populated planet in a system and Then assigns that as the system's blazon

'This example:
'- Finds the most populated planet in a star system
'- Generates a surface map for it
'- And then assigns that surface map as the blazon image for the parent star
'This script is an example of how to
'- iterate through all the systems on a sector map
'- dynamically load & unload a system's child data from file
'- generate a surface map via the FWE engine
'- set blazon properties
'- check to see if the Esc key was pressed (to cancel the script)
' On big maps it'll take a long time to generate all the surface maps, so 
' you may want to just start it up and go get lunch!

MaxPopBody = 0
Max = 100
Count = 0

Sub DoSetSurfaceBlazon()
	sAstroPath = AstroDirectory()
	sector = GetCurrentSector()
	j = sector.SystemCount

	'iterate through all the bodies on a map
	For i = 1 to j
		'check if Esc key pressed
		nKey = GetKey()	
		If nKey = 27 Then
			Exit For
		End If
		sector.RenderMessageBig = CStr( i) & " of " & CStr( j)

		o = sector.GetSystem( i-1)
		'is it a space station?
			sector.SetBlazonImage o, sAstroPath & "\textures\BlazonImages\Ships\ShipBlazon12.png"
			o.BlazonDisplay = true
			o.BlazonWrap = false
		End If

		'is it a fleet?
		If o.TypeID = BODY_TYPE_FLEET Then
			sector.SetBlazonImage o, sAstroPath & "\textures\BlazonImages\Ships\FleetBlazon.png"
			o.BlazonDisplay = true
			o.BlazonWrap = false
		End If
			bUnload = false
			If not o.Loaded Then
				bUnload = true
				sector.DynaLoad o
			End If
			MaxPopBody = o
			SetHighestSystemPop o
			FractalMap o, sector
			If MaxPopBody.Population > 0 Then
				'get the name of the surface map we just made (ie, the preview image) and
				'assign it as the blazon for the parent star
				sFile = MaxPopBody.PreviewImageFile
				sector.SetBlazonImage o, sFile
				o.BlazonDisplay = true
				o.BlazonWrap = true
				'dont dynaunload
			End If
		End If	
		If Count > Max Then
			Exit For
		End If
	sector.RenderMessageBig = ""
End Sub

'recursively generate each 
Sub FractalMap( b, sector)
	n = b.ChildrenCount()
	For k = 1 to n 
		c = b.GetChild(k-1)

		Sector.RenderMessageSmall = "Creating Surface Map for " & c.Name & " in system " & b.Name & ".  Press Esc to cancel"
		If Count > Max Then
			Exit For
		End If
		'generate the surface map

			'create a colorgroup object to use to tell the FWE engine what color settings we'll want
			'and tell astro to derive a default set of colors
			'these colors, of course, could be altered via the script as well
			fc = DefaultAstroColorGroup()
			DerivePlanetColors c, fc
			'make the map
			z = GenerateFWESurfaceMap( sector, c, false, fc)
			'free the color group object from memory
			FreeObject fc
			Count = Count + 1
		End If
		FractalMap c, sector
	Sector.RenderMessageSmall = ""
End Sub

'recursively finds the highest populated body in a system
Sub SetHighestSystemPop( b)

	n = b.ChildrenCount()
	For k = 1 to n 
		c = b.GetChild(k-1)
		If c.TypeID = 100 Then
			If c.Population > MaxPopBody.Population Then
				MaxPopBody = c
			End If
		End If
		SetHighestSystemPop( c)
End Sub


  • Hello Shalaska,
    From your code it looks like you aren't flagging the system as being modified, this will cause the problem of disappearing systems. After I make any changes to a system I do an UpdateRootBody and ModifySystem on the system object.

    Here is an example from my usual template.
    'Unload the body if there haven't been any changes made
    If unloadBody = TRUE Then
        sector.DynaUnload(body)    'Unload the body from memory
        body.UpdateRootBody()      'Update the root body
        body.ModifySystem()        'Flag the system as modified
    End If

    The sector object has a SaveToFile method that you could use to have it save every 100 systems or whatever. In theory this should free up the memory being used by AS but I've never played around with it so I don't know if it has any little idiosyncrasies.

    Also to speed up the time it takes to run don't do a RefreshScene on every object because it will take forever on large maps. I discovered this when I was writing my Jump Route plugin. I had it doing a RefreshScene on each system as I looped though them and it took several hours to run, after taking it out of the loop it ran almost instantly.

    Best Regards,
    Alan Bartholet

Leave a Comment