Step() public method

Perform one simulation timestep; move the simulation forward by the timestep increment duration.
public Step ( ) : void
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Run one simulation.
        /// </summary>
        private void RunTrial()
        {
            // Ensure flag is reset before we enter the main trial loop.
            _simStopFlag = false;

            // Get local copy of black box pointer so that the same one is used throughout each individual simulation trial/run
            // (_box is being continually updated by the evolution algorithm update events). This is probably an atomic
            // operation and thus thread safe.
            IBlackBox box = _box;

            box.ResetState();

            // Create/init new simulation world.
            _simWorld = CreateSimulationWorld();
            _simWorld.SetDebugDraw(_debugDraw);
            _timestepDelayMs = (int)(1000f / (float)_simWorld.SimulationParameters._frameRate);

            // Initialise the viewport on the GUI thread.
            Invoke(new MethodInvoker(delegate()
            {
                SetView();
            }));

            // Run main simulation loop until a stop condition occurs.
            for (;;)
            {
                // Perform GUI operations on the GUI thread.
                Invoke(new MethodInvoker(delegate()
                {
                    // Clear viewport buffer.
                    Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

                    // Advance the simulation world forward by one timestep.
                    // The simulation world has callbacks to the debug drawer object,
                    // hence this call is made on the GUI thread.
                    _simWorld.Step();

                    // Draw the world in its new/current state.
                    openGlControl.Draw();
                }));

                // Invoke controller logic (if any).
                InvokeController();

                if (TestStopCondition())
                {
                    break;
                }

                // Slow simulation down to run it in real-time.
                Thread.Sleep(_timestepDelayMs);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Run one simulation.
        /// </summary>
        private void RunTrial()
        {
            // Ensure flag is reset before we enter the main trial loop.
            _simStopFlag = false;

            // Get local copy of black box pointer so that the same one is used throughout each individual simulation trial/run 
            // (_box is being continually updated by the evolution algorithm update events). This is probably an atomic
            // operation and thus thread safe.
            IBlackBox box = _box;
            box.ResetState();

            // Create/init new simulation world.
            _simWorld = CreateSimulationWorld();
            _simWorld.SetDebugDraw(_debugDraw);
            _timestepDelayMs = (int)(1000f / (float)_simWorld.SimulationParameters._frameRate);

            // Initialise the viewport on the GUI thread.
            Invoke(new MethodInvoker(delegate() 
            {   
                SetView(); 
            }));
            
            // Run main simulation loop until a stop condition occurs.
            for(;;)
            {
                // Perform GUI operations on the GUI thread.
                Invoke(new MethodInvoker(delegate() 
                {
                    // Clear viewport buffer.
			        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

                    // Advance the simulation world forward by one timestep.
                    // The simulation world has callbacks to the debug drawer object, 
                    // hence this call is made on the GUI thread.
                    _simWorld.Step();

                    // Draw the world in its new/current state.
			        openGlControl.Draw();
                }));

                // Invoke controller logic (if any).
                InvokeController();

                if(TestStopCondition()) {
                    break;
                }

                // Slow simulation down to run it in realtime.
                Thread.Sleep(_timestepDelayMs);
            }
        }