Safe to apply forces on same frame Entity is added to Space?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Safe to apply forces on same frame Entity is added to Space?

Post by BrianL »

In the latest source which I downloaded Friday evening, I'm noticing some weirdness when applying forces to an Entity after it's been added to the Space, but before the next Space.Update() call.

The linear component seems to be correctly applied. However, it appears as though no angular forces are being computed/applied. Just for testing purposes, I deferred the application of the force until after the next Space.Update() call after adding the entity, and that seems to work. Only problem though, is that doesn't play very nicely with the threaded Update/Render setup I'm running with.

Bottom line -- is it safe to apply forces to an Entity that has just been added to a Space and before the next Space.Update() call?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Safe to apply forces on same frame Entity is added to Sp

Post by Norbo »

Under normal circumstances, yes, it is perfectly safe to apply forces on the same frame. It's safe to do so any time when the space is not running with the entity in it (and there are still some safe spots during the update too).

The AngularMomentum/LinearMomentum and other state properties directly access and modify the entity's data, so setting them should have immediate effect no matter what state the entity is in.
Only problem though, is that doesn't play very nicely with the threaded Update/Render setup I'm running with.
Is the engine running asynchronously? The entity properties are not thread safe. If the engine is updating, there are no guarantees on what will happen (other than it will eventually fail). If this is the case, then the access to the properties can be moved onto the physics thread. Alternatively, the buffered properties can be used to get data, and the write buffer can be used to set data: http://bepuphysics.codeplex.com/wikipag ... umentation
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Re: Safe to apply forces on same frame Entity is added to Sp

Post by BrianL »

I may have spoken too soon. After watching it a bit more, it seems like there's a narrow angle (cone) where hits occur and don't seem to impart any angular force. Like you said, it doesn't appear to have anything to do with adding and then applying force on the same frame.

I'm going to play with it some more and see if I can narrow it down.

And to answer your question, spawned objects are queued up during the Update() loop and then added to the scene and/or Space at the end of the frame during the sync point between the Update/Render threads. I'm certain that's 100% safe.
Post Reply