remove an Object from the World

Started by Melssj5, April 30, 2006, 03:58:36 AM

Previous topic - Next topic

Melssj5

How can I remove an object from its world without calling to World.removeObject ();

Object3D have a build method to be built without a world calling it from thee World, now I need something similar but to remove it. How can I do it. SUposse I have no acces to the World, only to the object3D and I need it to be removed.
Nada por ahora

Remo

You need access to the world! get the id of the object and get rid of it.

You do build the object by itself but removing is the contrary of addtoworld() not to build().

What I am doing to remove objects is send them to a pool of unused object (somewhat like in the car demo with the bullets) and when I need an object I get it from that pool.

Mr.Marbles

An alternative to removing the object is to simply hide it using setVisibility() on that object. This can be done without referencing the world.

Melssj5

but it will keep it on memory and that is resource consuming.
Nada por ahora

manumoi

it depends of what you need. If there are some object that will be frequently reused. I think it is better to keep it in memory instead of having to reload it (which is a very CPU consuming process if your object is complex).

I never tested the following proposition but i was thinking about it... Is the cost of cloning an object in term of CPU similar to the fact of creating a new one using the Loader class? I think cloning should be far more efficient but i never tested it. If so, you could create a set of frequently created objects (those object would not be linked to the world and would only be used to create cloned models that could be linked to the world). The CPU usage would be reduced but it would cost you some space in memory. Everything is a question of balance :P

I suppose if your Object3D is created without being linked to anything and you do not use it for a certain period, the garbage collector should destroy it... But maybe there is some kind of list in the JPCT architecture where all objects are referenced once they are created (which could explain the NO_OBJECT field)... I suppose only Egon can answer to this question.

EgonOlsen

Quote from: "manumoi"But maybe there is some kind of list in the JPCT architecture where all objects are referenced once they are created (which could explain the NO_OBJECT field)... I suppose only Egon can answer to this question.
No, there is no such thing. As long as you don't add it to the world, the object isn't referenced from inside of jPCT.

Melssj5

Well, My object is inside a World but I need to remove it from a method in another class where the World cant be referenced. Thats my problem, in anyway, I will continue with the rest of my game and let this topic to the end.
Nada por ahora

EgonOlsen

Then make the Object3D carry it's own world. Either by extending Object3D and keeping the reference in your extended class or by using the setUserObject() in Object3D.

Melssj5

ok, I will pass the World as a parameter but I didnt wanted to because I must change some other code. Its a suggestion to implement a Object3D.remove () method. Thanks in anyway.
Nada por ahora

EgonOlsen

Quote from: "Melssj5"Its a suggestion to implement a Object3D.remove () method. Thanks in anyway.
You can easily add this by making the derived YourObject3D class know an object's world (as mentioned above) and implementing the remove()-method.