Exemplo n.º 1
0
 protected void TriggerTaskAssignment(SimulationTime time, Phase phase, Crewman crewman, SimulationTask task = null)
 {
     if (this.OnTaskAssignment != null)
     {
         this.OnTaskAssignment(time, phase, crewman, task);
     }
 }
Exemplo n.º 2
0
        public override void AdvanceTime()
        {
            rtiAmbassador.EvokeMultipleCallbacks(0.01, 0.2);

            for (int i = 0; i < sendingPerIterations && sending < boidsManager.BoidsList.Count; i++)
            {
                Boid boid = boidsManager.BoidsList[sending];
                boid.FlushAttributeValues(null);
                sending++;
            }

            if (SimulationTime.CompareTo(nextRefreshTime) > 0)
            {
                nextRefreshTime = SimulationTime.Add(refreshInterval);
                if (sending >= boidsManager.BoidsList.Count)
                {
                    sendingPerIterations -= 1;
                    sending = 0;
                }
                else
                {
                    sendingPerIterations += 1;
                }

                /*
                 * federateAmbassador.DumpObjects();
                 *
                 * for (int i = 0; i < boidsManager.BoidsList.Count; i++)
                 * {
                 *  Boid boid = boidsManager.BoidsList[i];
                 *  boid.FlushAttributeValues(null);
                 * }
                 */
            }
        }
Exemplo n.º 3
0
 public void FireContact(SimulationTime simTime, Contact contact)
 {
     if (OnContact != null)
     {
         OnContact(simTime, contact);
     }
 }
Exemplo n.º 4
0
 public void Update(SimulationTime time)
 {
     for (int i = 0; i < Components.Count; i++)
     {
         components[i].Update(time);
     }
 }
Exemplo n.º 5
0
        public void Resolve(GameWinObserver gameWinObserver, GameBehaviour game, SimulationTime time)
        {
            _time        = time;
            _game        = game;
            _winObserver = gameWinObserver;

            _winObserver.WinnerFoundEvent += OnWinnerFound;
        }
Exemplo n.º 6
0
 public override void Update(SimulationTime time)
 {
     if (simMode == VesselSimulationMode.Simulate)
     {
         UpdateSimulation(time);
     }
     base.Update(time);
 }
Exemplo n.º 7
0
        public override SimulationTime TaskAssignment(SimulationTime time, Phase phase, SimulationTask task, Simulator.TasksInterruptedCallback tasksInterruptedCallback)
        {        //TODO: Implement multitasking
            Debug.Assert(task.IsAllowedTime(time), "Task assignment must be within allowed daily hours!");
            if (task.NumberOfCrewmenNeeded == 0)
            {
                base.TriggerTaskAssignment(time, phase, null, task);
                return(SimulationTime.MaxValue);
            }
            var priority = task.Priority;
            var scores   = new BinaryHeap <ScoreEntry>();

            foreach (var qualification in task.simulationCurrentQualifications)
            {
                var crewman            = qualification.Key;
                var qualificationLevel = qualification.Value;
                var currentPriority    = crewman.TasksAssigned.Count > 0 ? crewman.TasksAssigned[0].Priority : 0;               //No multitasking implemented: right now, each crewman has only 1 task at a time
                Debug.Assert(currentPriority <= 0 || crewman.TasksAssigned[0].simulationCrewmenAssigned.Any(cm => cm.Id == crewman.Id),
                             "If a crewman is assigned to a task, the symetric link should also be true, i.e. the task should be assigned to the same crewman!");
                if ((currentPriority == 0) || (priority / 100 > currentPriority / 100) || crewman.TasksAssigned.Contains(task))
                {
                    crewman.RefreshStatus(time);
                    var scoreEntry = new ScoreEntry((qualificationLevel * (int)AssignmentCoefficiant.Qualification) +
                                                    (crewman.CumulatedWorkTime.TotalHours * (int)AssignmentCoefficiant.CumulatedWorkHours), crewman);
                    if (task.NumberOfCrewmenNeeded > scores.Count)
                    {
                        scores.Add(scoreEntry);
                    }
                    else if (scores.Peek().score < scoreEntry.score)
                    {
                        scores.Remove();                                //Remove the current minimal score
                        scores.Add(scoreEntry);
                    }
                }
            }
            if (scores.Count < task.NumberOfCrewmenNeeded)
            {
                scores.Clear();
                return(SimulationTime.MinValue);                //The assignment was not successful
            }
            for (var i = scores.Count - 1; i >= 0; i--)
            {
                var scoreEntry = scores[i];
                var crewman    = scoreEntry.crewman;
                if (crewman.TasksAssigned.Count > 0)
                {
                    var currentTasks = crewman.TasksAssigned.ToList();
                    tasksInterruptedCallback(currentTasks, tryAssignmentAgainNow: true); //Do not clear the crew-members assigned before calling the interruption
                    crewman.DismissAllTasks(time, phase);                                //Currently not compatible with multitasking
                    Debug.Assert(!currentTasks.Any(t => t.simulationCrewmenAssigned.Count > 0), "Nobody should remain assigned to a task that has been interrupted!");
                }
                crewman.AssignTask(time, phase, task);
                task.simulationCrewmenAssigned.Add(crewman);
                base.TriggerTaskAssignment(time, phase, crewman, task);
            }
            scores.Clear();
            return(time + assignmentExpiry);
        }
Exemplo n.º 8
0
        public void UpdateSea3(SimulationTime SimTime)
        {
            float HWave      = 1f;
            float LWave      = 25f;   // 15
            float CWave      = 4f;    // 4
            float LambdaWave = 13.5f; // 3.5

            Vector3[] v = new Vector3[mOptions.SizeX];

            float r = HWave / 2;
            float k = 2f * (float)Math.PI / LWave;
            float w = CWave * k;

            float dtWave = (float)SimTime.DeltaTime * 1000;

            tWave += 1f * dtWave;

            for (int i = 0; i < mOptions.SizeX; i++)
            {
                // Houle de Gerstner
                double t        = v[i].Y = 0 - r * (float)Math.Cos(k * (i - mOptions.SizeX / 2));
                double cambrure = LambdaWave * t * dtWave;
                v[i].X = i - mOptions.SizeX / 2 + r * (float)Math.Sin(k * (i - mOptions.SizeX / 2) + w * tWave + cambrure);
                v[i].Y = 0 - r * (float)Math.Cos(k * (i - mOptions.SizeX / 2) + w * tWave + cambrure);
                v[i].Z = i - mOptions.SizeX / 2;
            }
            Vector3[] n = new Vector3[mOptions.SizeX];

            for (int i = 1; i < mOptions.SizeX - 1; i++)
            {
                Vector3 v1 = v[i + 1];
                Vector3 v2 = v[i - 1];
                v2.Z = i + 1 - mOptions.SizeX / 2;

                v1   = v[i] - v1;
                v2   = v[i] - v2;
                n[i] = Vector3.Cross(v1, v2);
                n[i] = Vector3.Normalize(n[i]);
            }

            int index = 0;

            for (int i = 0; i < mOptions.SizeX; ++i)
            {
                for (int j = 0; j < mOptions.SizeZ; ++j)
                {
                    mVertex[index].X = v[i].X * mOptions.CellSpacing;
                    mVertex[index].Y = v[i].Y * mOptions.CellSpacing;
                    mVertex[index].Z = v[j].Z * mOptions.CellSpacing;
                    index++;
                }
            }
            //mVertexBuffer.SetData(mVertex);
            ComputeMinMax();
        }
Exemplo n.º 9
0
        public void UpdateSea2(SimulationTime simTime)
        {
            //if (bSoliton) return;

            float HWave = 1f;
            float LWave = 10f;
            float CWave = 5f;

            int demi_sizeX = mOptions.SizeX / 2;
            int demi_sizeZ = mOptions.SizeZ / 2;

            float dtWave = (float)simTime.DeltaTime * 1000;

            UpdateSea2_Ld -= CWave * dtWave;
            UpdateSea2_Lf  = UpdateSea2_Ld - LWave;

            int     k = 0;
            float   t1, t2, h;
            Vector3 n;

            for (int x = 0; x != mOptions.SizeX; x++)
            {
                if (x >= UpdateSea2_Lf && x <= UpdateSea2_Ld)
                {
                    t1 = (UpdateSea2_Ld - x) * (float)Math.PI / LWave;
                    t2 = (float)Math.Sin(t1);
                    h  = HWave * t2;

                    n = new Vector3(-(float)Math.Cos(t1), t2, 0);
                }
                else
                {
                    h = 0f;
                    n = new Vector3(0, 1, 0);
                }

                for (int z = 0; z != mOptions.SizeZ; z++)
                {
                    mVertex[k].X = x - demi_sizeX;
                    mVertex[k].Z = z - demi_sizeZ;
                    mVertex[k].Y = h;
                    k++;
                }
            }

            if (UpdateSea2_Ld < 0)
            {
                gTypeOfSea    = 1;
                UpdateSea2_Ld = mOptions.SizeX;
            }

            //mVertexBuffer.SetData(mVertex);
            ComputeMinMax();
        }
Exemplo n.º 10
0
        ///<summary>
        /// Check if the current instance equals another instance of this class.
        ///</summary>
        ///<param name="obj">The instance to compare the current instance with.</param>
        ///<returns><code>true</code> if the instances are the same instance or have the same content.</returns>
        public override bool Equals(Object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            Event e = (Event)obj;

            if (!Description.Equals(e.Description))
            {
                return(false);
            }
            if (!Type.Equals(e.Type))
            {
                return(false);
            }
            if (!SimulationTime.Equals(e.SimulationTime))
            {
                return(false);
            }
            if (Sender != e.Sender)
            {
                return(false);
            }
            ICollection Keys  = _attributeTable.Keys;
            ICollection eKeys = e._attributeTable.Keys;

            if (Keys.Count != eKeys.Count)
            {
                return(false);
            }
            IEnumerator enumerator = Keys.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string key = (string)enumerator.Current;
                string val = (string)_attributeTable[key];

                if (!e._attributeTable.ContainsKey(key))
                {
                    return(false);
                }
                if (!e._attributeTable[key].Equals(val))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Dismiss a task and therefore release the different resources used (i.e. <see cref="Crewman"/>).
        /// </summary>
        /// <param name="time">The current simulation time</param>
        /// <param name="phase">The current phase of the scenario</param>
        /// <param name="task">The task dismissed</param>
        public virtual void TaskDismiss(SimulationTime time, Phase phase, SimulationTask task)
        {
            var trigger = this.OnTaskAssignment != null;

            foreach (var crewman in task.simulationCrewmenAssigned)
            {
                Debug.Assert(task.IsAllowedTime(time), "A task must not run outside allowed daily hours!");
                crewman.DismissTask(time, phase, task);
                if (trigger)
                {
                    this.OnTaskAssignment(time, phase, crewman);
                }
            }
            task.simulationCrewmenAssigned.Clear();
        }
Exemplo n.º 12
0
    public double InterpolateDailyConsumption(int day)
    {
        //Calculate first and last time on the day.
        double Starts, Ends, StartValue, EndValue;



        Starts = SimulationTime.GetFirstTimeOfDay(day);
        Ends   = SimulationTime.GetFirstTimeOfDay(day + 1);

        StartValue = InterpolateValueAt(Starts);
        EndValue   = InterpolateValueAt(Ends);

        return(EndValue - StartValue);
    }
Exemplo n.º 13
0
    public bool IsActive(double ts)
    {
        bool redletter = SimulationTime.IsRedLetterDay(ts);

        if (ExludeRedLetterDays && redletter)
        {
            return(false);
        }

        if (RedLetterDays && redletter)
        {
            return(true);
        }

        return(Weekdays.IsChecked(SimulationTime.GetDayOfWeek(ts)));
    }
Exemplo n.º 14
0
    double FindActiveDay(double ts, int searchdir)
    {
        //Will never be active.
        if (Weekdays.NoneSelected() && !(RedLetterDays && !ExludeRedLetterDays))
        {
            return(double.NaN);
        }

        //Work backwards until we find the last active day.
        while (!IsActive(ts))
        {
            ts += 24 * 60 * 60 * searchdir;
        }

        return(SimulationTime.GetTimestampForDay(ts));
    }
Exemplo n.º 15
0
        public override void PreUpdate(SimulationTime time)
        {
            Transform parentTransform = Parent?.Parent?.Transform;

            if (parentTransform != null)
            {
                this.worldPosition = parentTransform.WorldPosition + localPosition;
                this.worldRotation = parentTransform.WorldRotation * localRotation;
            }
            else
            {
                //For root entities we do not have a parent, therefore we treat the local space as our world space
                this.worldPosition = localPosition;
                this.worldRotation = localRotation;
            }
            base.Update(time);
        }
Exemplo n.º 16
0
        public void UpdateSimulation(SimulationTime time)
        {
            if (transform == null)
            {
                transform = GetComponent <Transform>();
            }
            //Rate of turn is in degrees minutes, let's convert it to radians per update
            double  rotRads      = rateOfTurn * (Math.PI / 180);
            double  stepRot      = rotRads / (60 * time.TrueUpdatePerSecond);
            double  newHeading   = Heading + stepRot;
            Vector3 newMovement  = new Vector3((float)Math.Cos(newHeading + Math.PI / 2) * (float)Speed, (float)Math.Sin(newHeading + Math.PI / 2) * (float)Speed, 0);
            Vector3 transformPos = transform.LocalPosition;
            Vector3 newPosition  = transformPos + newMovement;

            Debug.WriteLine("Speed: " + Speed + " New Pos:" + newPosition.X + " / " + newPosition.Y);
            transform.LocalPosition = transform.LocalPosition + newMovement;
            transform.RotateHeading(newHeading);
            Heading = newHeading;
        }
Exemplo n.º 17
0
        public void UpdateSea1(SimulationTime simTime)
        {
            int demi_width  = mOptions.SizeX / 2;
            int demi_height = mOptions.SizeZ / 2;

            int k = 0;

            for (int i = 0; i < mOptions.SizeX; i++)
            {
                for (int j = 0; j < mOptions.SizeZ; j++)
                {
                    mVertex[k].X = i - demi_width;
                    mVertex[k].Z = j - demi_height;
                    mVertex[k].Y = 0;
                    k++;
                }
            }
            ComputeMinMax();
            //bSoliton = false;
        }
Exemplo n.º 18
0
        public BlobsSpawner(EntityManager manager, BlobsSpawningSettings blobsSpawningSettings,
                            SimulationTime time)
        {
            _time         = time;
            _settings     = blobsSpawningSettings;
            _manager      = manager;
            _circlesQuery = _manager.CreateEntityQuery(typeof(CircleColliderComponent), typeof(Translation));

            _ballArchetype = _manager.CreateArchetype
                             (
                typeof(Translation),
                typeof(CircleColliderComponent),
                typeof(CollisionInfoElementData),
                typeof(SpeedComponent),
                typeof(MovementDirectionComponent),
                typeof(BlobPropertiesComponent),
                typeof(LocalToWorld),
                typeof(SpriteRenderComponent),
                typeof(Scale)
                             );
        }
Exemplo n.º 19
0
 public void UpdateTimePropterties()
 {
     Day            = SimulationTime.GetDayOfWeek(0);
     TimestampOfDay = SimulationTime.GetTimestampForDay(0);
 }
Exemplo n.º 20
0
        //static int collisionCount = 0;

        public void Update(SimulationTime simTime)
        {
            Game.Instance.SimulationThread.Profiler.BeginSection("collision_update");

            //long t1 = System.DateTime.Now.Ticks;

            Game.Instance.SimulationThread.Profiler.BeginSection("collision_detection");

            testList.BeginCollisionDetection();

            //long t2 = System.DateTime.Now.Ticks;

            foreach (CollisionThread t in threads)
            {
                t.Start();
            }

            //long t3 = System.DateTime.Now.Ticks;

            foreach (CollisionThread t in threads)
            {
                t.Join();
            }

            //long t4 = System.DateTime.Now.Ticks;

            testList.EndCollisionDetection();

            Game.Instance.SimulationThread.Profiler.EndSection("collision_detection");

            //long t5 = System.DateTime.Now.Ticks;

            Game.Instance.SimulationThread.Profiler.BeginSection("collision_response");

            foreach (CollisionThread t in threads)
            {
                //System.Console.WriteLine("collisions: " + t.ContactCount);

                for (int i = 0; i < t.ContactCount; ++i)
                {
                    Contact contact = t.GetContact(i);

                    //System.Console.WriteLine(contact.Count);
                    //if (
                    //    entry.EntityA.entity.HasString(CommonNames.Kind) && entry.EntityB.entity.HasString(CommonNames.Kind) &&(
                    //        entry.EntityA.entity.GetString(CommonNames.Kind) == "pillar" ||
                    //        entry.EntityB.entity.GetString(CommonNames.Kind) == "pillar" ||
                    //        (entry.EntityA.entity.GetString(CommonNames.Kind) == "island" && entry.EntityB.entity.GetString(CommonNames.Kind) == "island")
                    //    ))
                    //if ((contact.EntityA.HasString(CommonNames.Kind) && contact.EntityA.GetString(CommonNames.Kind) == "cave") ||
                    //    (contact.EntityB.HasString(CommonNames.Kind) && contact.EntityB.GetString(CommonNames.Kind) == "cave"))
                    //{
                    //    System.Console.WriteLine("Collision {0,4}: between {1} and {2}!", collisionCount, contact.EntityA.Name, contact.EntityB.Name);
                    //    ++collisionCount;
                    //}

                    CollisionProperty propertyA = contact.EntityA.HasProperty("collision") ? contact.EntityA.GetProperty <CollisionProperty>("collision") : null;
                    CollisionProperty propertyB = contact.EntityB.HasProperty("collision") ? contact.EntityB.GetProperty <CollisionProperty>("collision") : null;

                    if (propertyA != null && propertyB != null)
                    {
                        propertyA.FireContact(simTime, contact);
                        contact.Reverse();
                        propertyB.FireContact(simTime, contact);
                    }
                    else
                    {
                        if (propertyA == null && propertyB == null)
                        {
                            throw new System.Exception(string.Format(
                                                           "someone has illegaly removed the collision property from entity {0} and {1}!",
                                                           contact.EntityA.Name, contact.EntityB.Name
                                                           ));
                        }
                        else
                        {
                            throw new System.Exception(string.Format(
                                                           "someone has illegaly removed the collision property from entity {0}!",
                                                           propertyA == null ? contact.EntityA.Name : contact.EntityB.Name
                                                           ));
                        }
                    }
                }
            }

            Game.Instance.SimulationThread.Profiler.EndSection("collision_response");

            //long t6 = System.DateTime.Now.Ticks;

            //long dt1 = t2 - t1;
            //long dt2 = t3 - t2;
            //long dt3 = t4 - t3;
            //long dt4 = t5 - t4;
            //long dt5 = t6 - t5;

            //double ddt1 = (double)dt1 / 10000.0;
            //double ddt2 = (double)dt2 / 10000.0;
            //double ddt3 = (double)dt3 / 10000.0;
            //double ddt4 = (double)dt4 / 10000.0;
            //double ddt5 = (double)dt5 / 10000.0;

            //System.Console.WriteLine("collision detection timing: ");
            //System.Console.WriteLine("  dt1: {0:G}", ddt1);
            //System.Console.WriteLine("  dt2: {0:G}", ddt2);
            //System.Console.WriteLine("  dt3: {0:G}", ddt3);
            //System.Console.WriteLine("  dt4: {0:G}", ddt4);
            //System.Console.WriteLine("  dt5: {0:G} {1}", ddt5, ddt5>10.0?"***************************************************":"");

            Game.Instance.SimulationThread.Profiler.EndSection("collision_update");
        }
    override public bool UpdateSim(double time)
    {
        int index = CurrentIndex;

        CurrentIndex = GetIndex(time);



        //Nothing has hapended we are still at the same row in the buffer.
        if (CurrentIndex == index)
        {
            return(false);
        }

        //if (NodeName == "Electricity baseline") {
        //	print("Break");
        //}


        CurrentValues = GetCurrentValues();


        //Add keypoints
        if (SimulationTime != null)
        {
            if (Data.Count - 1 > CurrentIndex)
            {
                //Old version
                SimulationTime.AddKeypoint(Data [CurrentIndex + 1].Timestamp, this);

                //New version
                SetNext(Data [CurrentIndex + 1].Timestamp);
            }

            if (CurrentIndex >= 0)
            {
                SetPrev(Data [CurrentIndex].Timestamp);
            }
        }

        //Update previous and next.


        //Handle out of range
        if (CurrentIndex == -1)
        {
            CurrentTimestamp = double.NaN;
            CurrentDate      = "Out of range";


            TrimDatapoints();
            return(false);
        }

        //Update editor properties
        CurrentTimestamp = Data [CurrentIndex].Timestamp;
        CurrentDate      = SimulationTime.TimestampToDateTime(CurrentTimestamp).ToString("yyyy-MM-dd HH:mm:ss");


        //Send datapoint.
        if (Enabled == true)
        {
            //Copy
            DataPoint Point = Data [CurrentIndex].Clone();

            //Send
            base.UpdateAllTargets(Point);
        }

        TrimDatapoints();
        return(true);
    }
Exemplo n.º 22
0
        public static void Main(string[] args)
        {
            /*
             * XorShift160 lol = new XorShift160();
             * double runningSum = 0;
             *
             * while (!Console.KeyAvailable)
             * {
             *  Console.WriteLine(lol.NextDouble());
             * }
             * return;
             */

            IStateMatrix A = new StateMatrix(2, 2);

            A.SetValue(0, 0, 0);
            A.SetValue(0, 1, 1);
            A.SetValue(1, 0, 0);
            A.SetValue(1, 0, 0);

            /*
             * var c = new CompiledMatrix<IStateMatrix>(A);
             * c.Compile();
             */

            IInputMatrix B = new InputMatrix(2, 1);

            B.SetValue(0, 0, 0);
            B.SetValue(1, 0, 1);

            IOutputMatrix C = new OutputMatrix(2, 2);

            C.SetValue(0, 0, 1);
            C.SetValue(0, 1, 0);
            C.SetValue(1, 0, 0);
            C.SetValue(1, 1, 1);

            IFeedthroughMatrix D = new FeedthroughMatrix(2, 1);

            D.SetValue(0, 0, 0);
            D.SetValue(1, 0, 0);

            ControlVector u = new ControlVector(1);

            u.SetValue(0, 1);
            // TODO: Construct vectors and matrices by factory and let the simulation driver compile them after every external change

            IStateVector x = new StateVector(2);

            /*
             * IStateVector dx = new StateVector(x.Length);
             * IStateVector dxu = new StateVector(x.Length);
             * IOutputVector y = new OutputVector(C.Rows);
             * IOutputVector yu = new OutputVector(C.Rows);
             */

            CancellationTokenSource cts = new CancellationTokenSource();
            CancellationToken       ct  = cts.Token;

            Semaphore startCalculation = new Semaphore(0, 2);
            Semaphore calculationDone  = new Semaphore(0, 2);

            SimulationTime simulationTime = new SimulationTime();

            IStateVector dx           = new StateVector(x.Length);
            Task         inputToState = new Task(() =>
            {
                IStateVector dxu = new StateVector(x.Length);
                while (!ct.IsCancellationRequested)
                {
                    startCalculation.WaitOne();
                    Thread.MemoryBarrier();

                    A.Transform(x, ref dx);
                    B.Transform(u, ref dxu);                                  // TODO: TransformAndAdd()
                    dx.AddInPlace(dxu);

                    Thread.MemoryBarrier();
                    calculationDone.Release();
                }
            });

            IOutputVector y             = new OutputVector(C.Rows);
            Task          stateToOutput = new Task(() =>
            {
                IOutputVector yu = new OutputVector(C.Rows);
                while (!ct.IsCancellationRequested)
                {
                    startCalculation.WaitOne();
                    Thread.MemoryBarrier();

                    C.Transform(x, ref y);
                    D.Transform(u, ref yu);                                   // TODO: TransformAndAdd()
                    y.AddInPlace(yu);

                    Thread.MemoryBarrier();
                    calculationDone.Release();
                }
            });

            Task control = new Task(() =>
            {
                Stopwatch watch = Stopwatch.StartNew();
                int steps       = 0;

                while (!ct.IsCancellationRequested)
                {
                    // wait for a new u to be applied
                    // TODO: apply control vector
                    startCalculation.Release(2);

                    // wait for y
                    calculationDone.WaitOne();
                    calculationDone.WaitOne();
                    Thread.MemoryBarrier();

                    // wait for state vector to be changeable
                    // TODO: perform real transformation
                    x.AddInPlace(dx);                             // discrete integration, T=1

                    // video killed the radio star
                    if (steps % 1000 == 0)
                    {
                        var localY    = y;
                        double thingy = steps / watch.Elapsed.TotalSeconds;
                        Trace.WriteLine(simulationTime.Time + " Position: " + localY.GetValue(0) + ", Velocity: " + localY.GetValue(1) + ", Acceleration: " + u.GetValue(0) + ", throughput: " + thingy);
                    }

                    // cancel out acceleration
                    if (steps++ == 10)
                    {
                        u.SetValue(0, 0);
                    }

                    // advance simulation time
                    simulationTime.Add(TimeSpan.FromSeconds(1));
                }
            });

            inputToState.Start();
            stateToOutput.Start();
            control.Start();

            Console.ReadKey(true);
            cts.Cancel();

            /*
             * while (!Console.KeyAvailable)
             * {
             *  A.Transform(x, ref dx);
             *  B.Transform(u, ref dxu); // TODO: TransformAndAdd()
             *  dx.AddInPlace(dxu);
             *
             *  // TODO: perform transformation
             *  x.AddInPlace(dx); // discrete integration, T=1
             *
             *  C.Transform(x, ref y);
             *  D.Transform(u, ref yu); // TODO: TransformAndAdd()
             *  y.AddInPlace(yu);
             *
             *  // video killed the radio star
             *  if (steps%1000 == 0)
             *  {
             *      Trace.WriteLine("Position: " + y[0] + ", Velocity: " + y[1] + ", Acceleration: " + u[0] + ", throughput: " + steps/watch.Elapsed.TotalSeconds);
             *  }
             *
             *  // cancel out acceleration
             *  if (steps++ == 10)
             *  {
             *      u[0] = 0;
             *  }
             * }
             */
        }
Exemplo n.º 23
0
 public void Update(SimulationTime deltaTime, WaterMesh mesh)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
        public void UpdateSea4(SimulationTime simTime)
        {
            float dtWave = (float)simTime.DeltaTime * 1000;

            tWave += 1f * dtWave;

            int demi_width  = mOptions.SizeX / 2;
            int demi_height = mOptions.SizeZ / 2;

            float ddx, ddy;
            float attenuationNormal = 0.25f;

            float t1, t2;
            float d2, d3, d4, d5, d6, d7;

            int k = 0;

            for (int i = 0; i < mOptions.SizeX; i++)
            {
                for (int j = 0; j < mOptions.SizeZ; j++)
                {
                    mVertex[k].X = i - demi_width;
                    mVertex[k].Z = j - demi_height;
                    mVertex[k].Y = 0;

                    ddx = 0f;
                    ddy = 0f;

                    for (int w = 0; w < NBWAVES; w++)
                    {
                        t1 = Vector2.Dot(wave[w].Dir, new Vector2(i, j)) * wave[w].Freq + tWave * wave[w].Phase;

                        // Mod into range [-Pi..Pi]
                        t1 = MathHelper.WrapAngle(t1);

                        // Fonction Sinus réduite
                        d2 = t1 * t1;
                        d3 = d2 * t1;
                        d4 = d2 * d2;
                        d5 = d3 * d2;
                        d6 = d3 * d3;
                        d7 = d4 * d3;
                        float sin = t1 + d3 * SINCOEFF1 + d5 * SINCOEFF2 + d7 * SINCOEFF3;

                        // Houle de Gerstner
                        // wave.amp * sin(dot(wave.dir, position) * wave.freq + time * wave.phase)
                        mVertex[k].Y += wave[w].Amp * sin;

                        // Dérivée de la houle de Gerstner
                        // wave.freq * wave.amp * cos(dot(wave.dir, position) * wave.freq + time * wave.phase)
                        t2   = wave[w].Freq * wave[w].Amp * (1f - sin);
                        ddx += t2 * wave[w].Dir.X * attenuationNormal;
                        ddy += t2 * wave[w].Dir.Y * attenuationNormal;
                        //Vector3 B = new Vector3(1, ddx, 0);
                        //Vector3 T = new Vector3(0, ddy, 1);
                        //vertices[k].Normal = Vector3.Cross(B, -T);
                    }
                    mVertex[k] *= mOptions.CellSpacing;
                    k++;
                }
            }
            //mVertexBuffer.SetData(mVertex);
            ComputeMinMax();
        }
Exemplo n.º 25
0
 public SimulationTaskEvent(SimulationTask task, SimulationTime time, SubtypeType eventSubtype)
 {
     this.task    = task;
     this.time    = time;
     this.subtype = eventSubtype;
 }
Exemplo n.º 26
0
 public SimulationTaskEvent(SimulationTask task, TimeSpan time, SubtypeType eventSubtype)
     : this(task, SimulationTime.FromTimeSpan(time), eventSubtype)
 {
 }
Exemplo n.º 27
0
 public GameSaveSystem(SaveStorage storage, GameAreaBarrier barrier, SimulationTime time)
 {
     _time    = time;
     _barrier = barrier;
     _storage = storage;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Attempt to assign a task to the required number of crew-members, using a score to select the most fitted crew-members.
 /// </summary>
 /// <param name="time">The current simulation time</param>
 /// <param name="phase">The current phase of the scenario</param>
 /// <param name="task">The task assigned</param>
 /// <param name="tasksInterruptedCallback">A delegate method to call when having to interrupt tasks occupying the resource</param>
 /// <returns>A Simulation time at which the task assignment will not be valid anymore, or a negative value (e.g. SimulationTime.MinValue) if the task assignment was not successful</returns>
 public abstract SimulationTime TaskAssignment(SimulationTime time, Phase phase, SimulationTask task,
                                               Simulator.TasksInterruptedCallback tasksInterruptedCallback);
Exemplo n.º 29
0
 public virtual void PostUpdate(SimulationTime time)
 {
 }
Exemplo n.º 30
0
 public void Resolve(SimulationTime time)
 {
     _time = time;
 }