Invoking listener for every spatial modification

Hey,



we are trying to figure how to invoke a listener every time a spatial inside a scene has moved, if this happens we want to pass the modified spatial to our listener.



At first we tried to build a wrapper class for Spatials holding a Spatial and overwriting and extending spatials methods by a call of our listener. But because of setParent() being protected we can not attach our Wrapperclass  on a Node, so that we are not able to build the scene with our wrapper class objects accordingly.



Than we tried to use physics in order to find a place where our listener can be called, but we need the modified spatial every time it is modified, so we can`t use the PhysicsUpdateCallback, which does not provide information about the modified spatials in this frame.



Has anyone of you an idea how to solve this problem. We need a way to call our method

singletonclass.listen(Spatial modified_spatial,short flag);



We are trying hard for three weeks and do not know what to try next.





Thanks in advance,

Max

What you are describing is a classic case for the usage of Aspects. I recommend using AspectJ.



BEWARE: if you don't know aspects (in theory) and AspectJ, i recommend doing that first, or you might end up worse then before.



Create an Aspect and define a pointcut for access of whatever Vector3fs get changed. With an after() advice on this pointcut you can access all info needed (thisJoinPoint) and call your listener method.

Thanks for your fast reply, we discussed JAspects last week.



But we decided to find a solution with JPhysics or jme without using something from outside invoking our listener. We would like to use Jmonkey in a proper way, so that we won`t get trouble with side effects caused by not getting under control JAspect.



Is there JMonkey way to solve our problem?

KKADMM said:

Is there JMonkey way to solve our problem?


As far as I know, you can only achieve this by weaving in Aspects or modifying the JME source code (which I don't recommend).
fyi: Code in aspects are not really a call from "outside" your project, since the aspect code is woven into your .class files at compile time  ;) In a manner of speaking, the Aspect Weaver "inserts" code where you would put it anyway with inheritance but seemingly can't.

Can you explain a little more what you are trying to accomplish? What is the use case?

Hi!



KKADMM, I have almost solved your problem in my game. I needed to find the cell(s) containing the spatial to draw it correctly and to handle the collisions with it correctly. Each time a spatial is updated, it calls its own controller and the last one is mine, it allows to compare the previous location and the new one to know if this spatial has just moved and then to update the cell(s) containing it. As my solution is quite complicated, I rather advise you to override updateGeometricData(float time,boolean initiator) or to use a Controller (almost as I did). Good luck. If you don't understand, look at my source code, it is open :slight_smile:

nymon said:

Can you explain a little more what you are trying to accomplish? What is the use case?


Of course,

we are building a server which has to manage a scene for multiple online players.

Inside the server is a scenegraph managing a world by jme. The clients are runnig an instance of jme either.
Whenever something happens inside the scenegraph, the players must be informed, that the specific object has to be updated.
In case of player initiated modifications (due to keyboard input) this is quite easy. But whenever JPhysics does something inside the scene, we need to inform the clients too, this case is our problem.

I see. Have you looked at JGN written by darkfrog yet? It handles all the synchronization including physics. If you don’t decide to use it, at least it could be a good reference.