Object "Instancing"

BlitzMax Forums/BlitzMax Beginners Area/Object "Instancing"

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

When I say instancing, I mean in the sense of making an object pointer which changes when the object does ( the object, not the data within, which of course is updated automatically. )

Something like this demonstrates the problem :

SuperStrict

Type pImage
	
	Field Width:Int
	Field Height:Int
	Field Data:Byte[]
	
End Type



Type pGhost
	
	Field Img:pImage
	
End Type



Global AnImage:pImage=New pImage
AnImage.Width=100
AnImage.Height=200
Global AGhost:pGhost=New pGhost
AGhost.Img=AnImage
AnImage=New pImage
AnImage.Width=99
AnImage.Height=199


' RESTORE THE GHOST IMAGE HERE
'/RESTORE THE GHOST IMAGE HERE


DebugLog AGhost.Img.Width


AnImage is now a different object, but AGhost still points to the old image. Obviously it's not an example I would use, but it's simpler to read than a real world example. A real world example ( to show why I need this ) would be when the user changes resolution mid-way through a game. I don't want to destroy all my game objects ( Ghosts ) but I have to reload all the images when the res changes. So I need to restore all the ghosts ( and other game objects ) so they refer to valid image objects.

I'd prefer not to do something unwieldy like maintaining lists of every game object which uses each image object, though this would work, I suppose.

I think it's my old nemesis, the pointer, doing my head in again.