Ok, so I have a working system that uses TMap to store pointers to Openb3d objects! But I have questions now for the gurus. :)
I am casting to Long and it seems to be ok, but should I use in my BytePtrToString function: Int if Max is 32 bit and Long if 64 bit? Is it bad practise to use Long on 32 bit for this purpose?
' maptest.bmx
Framework brl.retro
Import brl.map
Type TGlobal
Global ent:TEntity=New TEntity
Function BytePtrToString:String( instance:Byte Ptr )
Return Long(instance)
End Function
End Type
Type TEntity
Global entity_map:TMap=New TMap
Field instance:Byte Ptr
Method NewEntity:TEntity( inst:Byte Ptr )
Local ent:TEntity=New TEntity
entity_map.Insert( TGlobal.BytePtrToString(inst), ent )
ent.instance=inst
Return ent
End Method
Method DeleteEntity( inst:Byte Ptr )
entity_map.Remove( TGlobal.BytePtrToString(inst) )
End Method
Method EntityValue:TEntity( inst:Byte Ptr )
Return TEntity( entity_map.ValueForKey( TGlobal.BytePtrToString(inst) ) )
End Method
End Type
Local globals:TGlobal=New TGlobal
Local instance:Byte Ptr=globals ' 1st object
Local ent:TEntity=globals.ent.NewEntity( instance )
Local instance2:Byte Ptr=ent ' 2nd object
Local ent2:TEntity=globals.ent.NewEntity( instance2 )
Local test:TEntity=globals.ent.EntityValue( instance ) ' test map contents
Local test2:TEntity=globals.ent.EntityValue( instance2 )
DebugLog "globals:"+Long Byte Ptr globals
DebugLog "ent:"+Long Byte Ptr ent
DebugLog "test.instance:"+Long test.instance
DebugLog "test2.instance:"+Long test2.instance
|