User data

i don't know about you, but i think it would be really nice to have a user-data object on the spatial node…that would really help in connecting gamelogic objects with their graphical representation, for example when getting an object by picking…

You can use your own subclass of Node to do this easily (some "EntitiyNode" or similar). Adding user objects to all Spatials was rejected because of memory consumption.

making an own subclass is not fun…you miss out on all objects loaded through loaders for example…

memory consumption? a simple handle per spatial costs close to zero…

The method asked for on the forums was a hashmap per spatial which was could be expensive (perhaps not if done lazily, but at the time we had other things to do.)

ok…i was thinking only a "Object userData"…never mind, i'll hack my way around it :slight_smile:

renanse said:

The method asked for on the forums was a hashmap per spatial which was could be expensive (perhaps not if done lazily, but at the time we had other things to do.)


You can fined the discution here.

Hey MrCoder, why don't you take a look at MonkeyWorld3D



http://cvs.sourceforge.net/viewcvs.py/monkeyworld3d/monkeyworld3d/src/com/mw3d/core/entity/



Hope it helps.

thanks all…

why dont you use inheritance and add an interface, that way it becomes an adapter

i know many ways of doing it ok :wink:

the thing i was aiming at was being able to connect objects without hacking into every loader and object creator to create my own specialized spatial or node…

I am currently investigating extending the XMLloadable Interface, which, when finished, should remove the need to hack the loaders/writers for every new or user created class.

-> http://www.jmonkeyengine.com/jmeforum/index.php?topic=2836.0

I think I will be able to spit out something useful by tomorrow, watch that thread for updates.

if i understand correctly you want to be able to attach some Metadata object to Nodes. If jme would offer such a Metadata interface and a set/getMetadata for Nodes then the memory consumption would only depend on how clever you implement that interface.

or am i understanding something wrong abouth that "user data"? :expressionless:

you are understanding right, but i was pitching for an even simpler interface, namely the java base Object class :wink:

setUserData(Object userData)

Object getUserData()



and not on Node but on Spatial…but, no prob, end of story :slight_smile:

I'm just starting to explore jME and need the same thing as you, MrCoder, with support for simple Object reference in each Spatial. How did you solve your problem?

This is also known as "cookies". There's many ways to this though, most simply just make a mapping between your object and it's meta data, eg. with IdenityHashMap or WeakIdenityCache (included in jME, automatically removes mappings one the object is garbage collected).

the only problem i see with such a mapping is that you usually want to gcarry your "cookies" with your nodes and not access a (more or less) global cookie-object map.