Identify the parent list and parent index of a ...

Blitz3D Forums/Blitz3D Beginners Area/Identify the parent list and parent index of a ...

RemiD(Posted 2016) [#1]
(the title on these forums is too limited in chars...)

Hello, :)

I have an idea on how to do it but i am just curious of how you would do it :
Let's say that i have several dim arrays with 1 dimension for the parent and 2 dimensions for the childs and 3 dimensions for the childs of the child, like that :


Ok, let's say that i get the reference of an item (after a linepick or after a collision), what method would you use to store and then get the index of the container (parent of the item) and the index of the room (parent of the container) ?
Because in order to update the state of this item, i need to be able to read/write its properties stored in the arrays, and for this is need to have the index of its parents (of the container, of the room)

For now i plan to put the names of the lists and the indexes of the instances in the entityname, something like that : "ROO68-CON15-ITE4"
After a collision/linepick, i will be able to get the entityname, and then i can split the string (separated by the symbol "-") in parts, and then i can analyze the chars of the stringparts to extract the names of the lists and the indexes of the instances.

Any other easier way ?

Thanks,


Flanker(Posted 2016) [#2]
You should use type handles, I think that's the most efficient.

For example 3 different types where you store the parent handle :
Type room
	Field mesh
End Type

Type container
	Field mesh
	Field roomHandle
End Type

Type item
	Field mesh
	Field containerHandle
End Type

Then when you create your objects, do something like that :
r.room = New room
r\mesh = LoadMesh("room.b3d")

For a = 1 To 20

	c.container = New container
	c\mesh = LoadMesh("container.b3d")
	c\roomHandle = Handle(r) ; store the container's parent handle (room handle)
	
	For b = 1 To 10
		i.item = New item
		i\mesh = LoadMesh("item.b3d")
		EntityPickMode i\mesh,2
		NameEntity i\mesh,Handle(i) ; <------------- link the mesh with its type
		i\containerHandle = Handle(c) ; store the item's parent handle (container handle)
	Next	
	
Next

And finally, let's say you use CameraPick for items, and want to retrieve its container, and the room of the container :
CameraPick camera,MouseX(),MouseY()

If PickedEntity()

	i.item = Object.item(EntityName(PickedEntity())) ; <------------- retrieve the handle of the mesh type by its name
	
	c.container = Object.container(i\containerHandle) ; retrieve the container from the handle stored in the item type
	
	r.room = Object.room(c\roomHandle) ; retrieve the room from the handle stored in the container type

EndIf

Then you can process what you want from the types you retrieved. It will save you unnecessary string processing, and probably memory as you don't need to declare an array that may not be filled.


RemiD(Posted 2016) [#3]
@Flanker>>Thanks, i will study this.


RemiD(Posted 2016) [#4]
The solution you show is a possible approach and i can do a similar approach with one dimension arrays (by adding a dim variable "parentindex"), but will not work with multi dimensions arrays.

Ok, i will decide what i will use. Thanks.


RemiD(Posted 2016) [#5]
Similar to what Flanker suggested, but with the possibility to find the parent handle/index and a child handle/index :


However it can be complicated to reorganize the entries in the arrays and in the indexes list once one entry has been deleted, so it is probably easier to use custom type for such a thing...


Flanker(Posted 2016) [#6]
However it can be complicated to reorganize the entries in the arrays and in the indexes list once one entry has been deleted, so it is probably easier to use custom type for such a thing...


Yes it's simpler to add a field in a type than reorganize a multi dimensionnal array. But sometimes arrays are easier to use, for example spatial distribution, something like "Dim chunk(x,y,z)", easy to access what you want in this case. It just depends of the situation. Eventually, someone can prefer to use arrays instead of lists because it suits better the way he thinks. I think there is no absolute answer on this one.


RemiD(Posted 2016) [#7]
After some tests, i will use the method described in post #1, because i find it easier to code this way and it is fast...

More infos for those who are interested about this :


I am surprised that my function SplitString(StringStr$,SpliterStr$) is so fast (0.023ms for such a split)

Very good, next !


Blitzplotter(Posted June) [#8]
Great stuff, will use soon ;)