Flint Particle System Forum - Run all actions multiple times between draw operations Mon, 12 Dec 2011 19:34:34 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Run all actions multiple times between draw operations http://flintparticles.org/forum/comments.php?DiscussionID=401&Focus=1374#Comment_1374 http://flintparticles.org/forum/comments.php?DiscussionID=401&Focus=1374#Comment_1374 Tue, 21 Sep 2010 16:36:35 +0100 Colin
I'm writing a custom action to implement the Lennard-Jones potential to simulate atoms interacting with one another. Unfortunately, this potential has very strong repulsion at short inter-particle separations, which always leads to the system blowing up. I've already tried using the epsilon approach used in MutualGravity, et. al and that kind of worked but it's still not great. Even using this approach, the particles gain energy constantly and the whole system speeds up over time. I'd prefer not to use SpeedLimit if possible.

My next thought is to try to run the simulation using a very short frame duration. However, this makes the system move very slowly. I could be wrong, but it seems to me that drawing the system is more computationally expensive than actually running the actions. So, I was thinking about trying to implement in Flint something I had done a couple of years ago in Java: using a very short time step for the calculations and only drawing the system every 10+ time steps. My naive first stab at this was to add a bunch of the same type of action to the emitter. However, they seem to get sorted by type. I had LennardJones, Move, and BoundingBox in that order multiple times. However, instead of executing in that order, the emitter ran LennardJones multiple times and then Move multiple times, etc. This made the system blow up super fast. Even if there is some method by which I could get this approach to work, it seems like there should be a more elegant approach.

I know you can use runAhead() to run your emitter's actions a bunch of times before you draw it for the first time. Is it possible to do this type of thing repeatedly? If so, how? Is this approach even worth pursuing?

Any input that people can offer would be much appreciated. Thanks! ]]>
Run all actions multiple times between draw operations http://flintparticles.org/forum/comments.php?DiscussionID=401&Focus=1375#Comment_1375 http://flintparticles.org/forum/comments.php?DiscussionID=401&Focus=1375#Comment_1375 Tue, 21 Sep 2010 17:03:46 +0100 Colin Run all actions multiple times between draw operations http://flintparticles.org/forum/comments.php?DiscussionID=401&Focus=1379#Comment_1379 http://flintparticles.org/forum/comments.php?DiscussionID=401&Focus=1379#Comment_1379 Thu, 23 Sep 2010 17:47:11 +0100 Richard
1. Override the Emitter class

class MyEmitter2D extends Emitter2D
{
override pubic function update( time:Number ) : void
{
var microtime:Number = time * 0.1;
for( var i:int = 0; i < 10; i++ )
{
super.update( microtime );
}
}
}


2. Take control of the update yourself

emitter.useInternalTick = false;
FrameUpdater.instance.addEventListener( UpdateEvent.UPDATE, updateParticles, false, 0, true );

private function updateParticles( event:UpdateEvent ):void
{
var microtime:Number = event.time * 0.1;
for( var i:int = 0; i < 10; i++ )
{
emitter.update( microtime );
}
}


P.S. I haven't tested this code so I apologise if it contains errors. ]]>