Entity access

Blitz3D Forums/Blitz3D Programming/Entity access

Naughty Alien(Posted 2008) [#1]
..okay..it may be dumb question, but please be gentle and provide some useful information if you have it..

let say i load some level geometry like this

Map=LoadAnimMesh("Level_01_part_01.B3D")

Map=LoadAnimMesh("Level_01_part_02.B3D")

..so..everything will be fine, level will be completely loaded and nice..now..how to access entities loaded with first Map handle? They all do have names already set in modelling program, but i would like to know is there any other way to access entities, rather than FindChild, wich is conditioned with use of handler name Map, in this case..obviously, all entities are in there, since i see them all and its all working fine..but How to access entities from first one after use of second one Map?


Ross C(Posted 2008) [#2]
Erm, maybe i don't get what your saying, but use map1 to load the second level part?

You can also use getchild(), along with countchildren() command.


Uncle(Posted 2008) [#3]
Why don't you just use a different variable name for each mesh? e.g.


MapOne=LoadAnimMesh("Level_01_part_01.B3D")

MapTwo=LoadAnimMesh("Level_01_part_02.B3D")


JA2(Posted 2008) [#4]
Why not set the EntityName of each mesh after loading it? Just loop through all the children in your map after loading it and add something to the EntityName i.e "Barrel" > "Map01Barrel" etc


Naughty Alien(Posted 2008) [#5]
..thats fine guys...I know that..but i was wondering is there any way to access every single entity on the scene, loaded on the way that both parts of level geometry are loaded under same name..I thought, it should be some way since objects are obviously on scene...I mean, practically is there a way to pass trough entities, regardless handler initially assigned during LoadAnimMesh?


El Gigante de Yeso(Posted 2008) [#6]
Naughty Alien, you can create a parent pivot for organizating the world into different categories as it's loaded, and use the GetChild method to search for it.





If this method doesn't suit well and you want something more "general" or "clean", you can store up your meshes in types so you can access them easily. Something of the like:



Usage example:


It doesn't look into the Submeshes names, but rather on the assigned name to the model file loaded. It's a clean way to do the job and keep track of your resources too.


Naughty Alien(Posted 2008) [#7]
..types..of course...slap me all guys... :)


Sledge(Posted 2008) [#8]
..thats fine guys...I know that..but i was wondering is there any way to access every single entity on the scene, loaded on the way that both parts of level geometry are loaded under same name..I thought, it should be some way since objects are obviously on scene...I mean, practically is there a way to pass trough entities, regardless handler initially assigned during LoadAnimMesh?
Nobody seems to have mentioned it but this is exactly what you don't do without garbage collection as it's how you create memory leaks. If you don't maintain at least one handle/reference to a mesh then there's no way to free it.


Rroff(Posted 2008) [#9]
What you need is an object system of some kind...


Terry B.(Posted 2008) [#10]

Nobody seems to have mentioned it but this is exactly what you don't do without garbage collection as it's how you create memory leaks. If you don't maintain at least one handle/reference to a mesh then there's no way to free it.


Wrong, Clearworld(). ;D.


OJay(Posted 2008) [#11]
maybe you'll also find this one useful: http://blitzbasic.com/codearcs/codearcs.php?code=2012


Sledge(Posted 2008) [#12]
Wrong, Clearworld(). ;D.

That strikes me as a horrible way to go about things but, ultimately, yes I guess you could nuke everything if you were sloppy enough to lose a reference. Does this definitely get you your memory back?


GfK(Posted 2008) [#13]
Wrong, Clearworld(). ;D.

That strikes me as a horrible way to go about things but, ultimately, yes I guess you could nuke everything if you were sloppy enough to lose a reference
Beware that ClearWorld() does not clear everything. It clears entities, brushes and textures only. If you ever work on the assumption that ClearWorld() clears types, sounds etc too, then you're setting yourself up for a colossal memory leak.


Sledge(Posted 2008) [#14]
Well I was really just talking about entities (as per the thread topic) but, yeah, that as well. Much as it's tempting to steam-roller ahead in B3D 'ad hoc', it's worth making provisions to free everything you create at the point you write the code to create it.


GfK(Posted 2008) [#15]
This is where Blitzmax batters Blitz3D to a bloody pulp. In Magicville I have one base object and everything else is created within that. That way all I have to do is Null the base object, and GC gets everything else for me because no other references exist to any of it.


Ross C(Posted 2008) [#16]
Plus you will still have all your references in your type objects, with values, that point no-where. You'll need to also delete or set to 0, all your entity handles on top of what gfk says.


SytzeZ(Posted 2008) [#17]

Plus you will still have all your references in your type objects, with values, that point no-where. You'll need to also delete or set to 0, all your entity handles on top of what gfk says.


Delete Each my_type