Example #1
0
        public static void Update(DeltaTime dt)
        {
            if (updateQueue.Count > 0)
            {
                while (updateQueue.Count > 0)
                {
                    UpdateBuffer(updateQueue.Dequeue());
                }
                ApplyBufferUpdates();
            }

            foreach (UIItem item in uiItems[currentLayer])
            {
                item.Update(dt);
            }
        }
Example #2
0
        public override void Update(DeltaTime deltaTime)
        {
            /*
             * delay -= deltaTime.Seconds;
             *
             * if (delay <= 0) {
             *  delay = 2;
             *  index++;
             *  if (index >= grades.Length) index = 0;
             *  FinalizeScore();
             * }*/

            returnButton.Update(deltaTime);

            Draw();
        }
Example #3
0
        //Coulnd't get this to work with deltaTime. Since it's just a misc visual effect I don't think it's worth the time to fix it.
        private void UpdatePoint(int pointIndex, DeltaTime deltaTime)
        {
            float dif = WaterPoints[pointIndex].Y - line;
            float acc = -k * dif - (dampening * pointVel[pointIndex]);

            deltaHeight[pointIndex] += pointVel[pointIndex];
            pointVel[pointIndex]    += acc;

            if (pointIndex > 0)
            {
                pointVel[pointIndex - 1] += spread * (WaterPoints[pointIndex].Y - WaterPoints[pointIndex - 1].Y);
            }
            if (pointIndex < surfacePoints - 1)
            {
                pointVel[pointIndex + 1] += spread * (WaterPoints[pointIndex].Y - WaterPoints[pointIndex + 1].Y);
            }
        }
Example #4
0
        protected override void Update(DeltaTime delta)
        {
            if (Input.IsKeyReleased(InputKey.F1))
            {
                renderVisualizer = !renderVisualizer;
            }
            if (Input.IsKeyReleased(InputKey.F2))
            {
                string jsonData = SceneTree.SaveToJson(tree);
                File.WriteAllText("_Data/Scenes/SavedDebugScene.json", jsonData);
            }

            if (renderVisualizer)
            {
                visualizer.Update(delta);
            }
        }
Example #5
0
File: Button.cs Project: Etny/Flagr
        public override void Update(DeltaTime deltaTime)
        {
            Point mouse     = Program.Input.MouseLocation;
            bool  mouseDown = Program.Input.MouseDown;

            Hovered = (mouse.X >= origin.X && mouse.X <= origin.X + Size.Width) &&
                      (mouse.Y >= origin.Y && mouse.Y <= origin.Y + Size.Height);

            if (clickBuildup > 0)
            {
                clickBuildup -= clickBuildupDecrease * deltaTime.Seconds;
                if (clickBuildup < 0)
                {
                    clickBuildup = 0;
                }
            }

            if (Hovered)
            {
                if (mouseDown != lastDown && Selectable)
                {
                    if ((SelectMode == SelectMode.OnMouseUp && mouseDown == false) ||
                        (SelectMode == SelectMode.OnMouseDown && mouseDown == true))
                    {
                        Select();
                    }
                }

                if (Hoverable && hoverBuildup < hoverBuildupMax && clickBuildup == 0)
                {
                    hoverBuildup += hoverBuildupIncrease * deltaTime.Seconds;
                }
            }

            else if (hoverBuildup > 0)
            {
                hoverBuildup -= hoverBuildupDecrease * deltaTime.Seconds;
                if (hoverBuildup < 0)
                {
                    hoverBuildup = 0;
                }
            }

            lastDown = mouseDown;
        }
Example #6
0
        public override void Update(DeltaTime deltaTime)
        {
            if (currentFade <= 0)
            {
                return;
            }

            if (currentFadeDelay > 0)
            {
                currentFadeDelay -= deltaTime.Seconds;
            }
            else
            {
                currentFade -= deltaTime.Seconds;
            }

            currentBarWidth = (int)((currentFade / FadeTime) * BarWidth);
        }
Example #7
0
        public override void Update(DeltaTime deltaTime)
        {
            graphics.FillRectangle(Brushes.White, 0, 0, Program.Width, Program.Height);
            graphics.DrawImageUnscaled(flag.Image, 0, 0);
            graphics.DrawString(flag.Country, Form1.DefaultFont, Brushes.Black, 400, 400);

            x -= (int)deltaTime.Milliseconds;

            if (x <= 0)
            {
                x = 1000;
                //index = new Random().Next(0, Program.Flags.getFlags().Count-1);
                index++;
                flag = Program.Flags.GetFlags()[index];
            }

            Console.WriteLine(deltaTime.Milliseconds + " " + x);
        }
Example #8
0
        private void Worker()
        {
            try
            {
                var stopwatch = new Stopwatch();
                var deltaTime = new DeltaTime();

                while (this.running)
                {
                    var elapsed = stopwatch.Elapsed;
                    stopwatch.Reset();
                    stopwatch.Start();

                    deltaTime.ElapsedTime = elapsed;
                    deltaTime.TotalTime  += elapsed;

                    try
                    {
                        this.DoUpdate(deltaTime);
                    }
                    catch (Exception exception)
                    {
                        this.OnUpdateError(exception);
                    }

                    var updateTime  = stopwatch.Elapsed;
                    var timeToSleep = (int)(this.updateInterval - updateTime).TotalMilliseconds;
                    if (timeToSleep < 1)
                    {
                        timeToSleep = 1;
                    }

                    this.Tracker?.AddValue(updateTime);

                    if (this.running)
                    {
                        this.workerThreadExitResetEvent?.WaitOne(timeToSleep);
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
        }
Example #9
0
 public void Update(DeltaTime dt)
 {
     if (!Animations[currentAnimation].Update(dt))
     {
         currentCallback?.Invoke(true);
         if (queuedAnimation != -1)
         {
             currentAnimation = queuedAnimation;
             currentCallback  = queuedCallback;
             queuedAnimation  = -1;
         }
         else
         {
             currentAnimation = idleAnimation;
             currentCallback  = null;
         }
         Animations[currentAnimation].Start( );
     }
 }
Example #10
0
 public void Update(DeltaTime delta)
 {
     if (Input.IsKeyPressed(InputKey.ArrowUp))
     {
         MoveUp();
     }
     else if (Input.IsKeyPressed(InputKey.ArrowDown))
     {
         MoveDown();
     }
     else if (Input.IsKeyPressed(InputKey.ArrowLeft))
     {
         MoveLeft();
     }
     else if (Input.IsKeyPressed(InputKey.ArrowRight))
     {
         MoveRight();
     }
 }
Example #11
0
        //-------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------
        public SpriteAnimationData UpdateCurrentAnimation(DeltaTime deltaTime)
        {
            SpriteAnimationData data = new SpriteAnimationData();

            if (m_currentAnimation != null && !Paused)
            {
                m_fTimeElapsedScinceLastFrame += deltaTime.ElapsedGameTime.TotalMilliseconds;

                if (m_fTimeElapsedScinceLastFrame >= m_fDesiredElapsedTime)
                {
                    data.m_currentFrame.X         = Direction == AnimationDirection.Forward ? m_currentFrame.X++ : m_currentFrame.X--;
                    m_fTimeElapsedScinceLastFrame = 0;
                }
                else
                {
                    data.m_currentFrame.X = m_currentFrame.X;
                }

                data.m_currentFrame.Y = m_currentFrame.Y;
                data.m_frameSize      = m_currentAnimation.m_frameSize;

                if ((m_currentFrame.X * m_currentAnimation.m_frameSize.X) >= m_currentAnimation.m_sheetSize.X)
                {
                    if (m_currentAnimation.m_bLooping)
                    {
                        m_currentFrame = Frame.Zero;
                    }
                    else
                    {
                        m_currentAnimation = null;
                    }
                }
            }
            //We need to do this if it is paused with an animation.
            else if (m_currentAnimation != null && Paused)
            {
                data.m_currentFrame = m_currentFrame;
                data.m_frameSize    = m_currentAnimation.m_frameSize;
            }

            return(data);
        }
Example #12
0
        public override void Update(DeltaTime deltaTime)
        {
            /*
             * ticks++;
             * if(timer.ElapsedMilliseconds >= 1000)
             * {
             *  Console.WriteLine("{0} tps", ticks);
             *  ticks = 0;
             *  timer.Restart();
             * }
             */

            if (freezeTime > 0)
            {
                SetFlagLocations();

                freezeTime -= deltaTime.Seconds;

                if (freezeTime <= 0)
                {
                    foreach (QuizButton b in buttons)
                    {
                        b.Selectable = true;
                        b.Hoverable  = true;
                    }

                    freezeTime = 0;

                    NextFlag();
                }
            }

            foreach (QuizButton b in buttons)
            {
                b.Update(deltaTime);
            }

            tracker.Update(deltaTime);
            scoreAddLabel.Update(deltaTime);

            Draw();
        }
Example #13
0
        public override void Update(DeltaTime deltaTime)
        {
            foreach (Button b in stateButtons)
            {
                b.Update(deltaTime);
            }

            if (selectedStartButtons >= 0)
            {
                foreach (Button b in startButtons[selectedStartButtons])
                {
                    if (b != null)
                    {
                        b.Update(deltaTime);
                    }
                }
            }

            Draw();
        }
        //-------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------
        public override void Draw(DeltaTime deltaTime)
        {
            CallRequestInfo(deltaTime);

            if (m_RenderInfoList.Count > 0)
            {
                if (EffectSettings != null)
                {
                    EffectSettings.m_fpUpdate(EffectSettings.m_effect, EffectSettings.m_effectSettings);
                }
                //This is a little ugly but ill work it out later
                if (Effect != null)
                {
                    m_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState, null, null, null, Effect);
                }
                else
                {
                    m_spriteBatch.Begin();
                }

                foreach (SpriteInfo spriteInfo in m_RenderInfoList)
                {
                    m_spriteBatch.Draw(spriteInfo.m_texture2D,
                                       spriteInfo.m_v2Position,
                                       new Rectangle((int)(((spriteInfo.m_animationData.m_frameSize.X) * spriteInfo.m_animationData.m_currentFrame.X)),
                                                     (int)(((spriteInfo.m_animationData.m_frameSize.Y) * spriteInfo.m_animationData.m_currentFrame.Y)),
                                                     spriteInfo.m_animationData.m_frameSize.X,
                                                     spriteInfo.m_animationData.m_frameSize.Y),
                                       spriteInfo.m_colour,
                                       spriteInfo.m_fRotation,
                                       spriteInfo.m_v2Origin,
                                       spriteInfo.m_v2ScaleFactor,
                                       spriteInfo.m_eSpriteEffects,
                                       spriteInfo.m_fDepth);
                }

                m_spriteBatch.End();
                m_RenderInfoList.Clear();
            }
            base.Draw(deltaTime);
        }
Example #15
0
    private void UpdateTblDelta(float curPosX, string fromFlag)
    {
        if (_deltaList == null)
        {
            return;
        }
        DeltaTime tblDeltaTime = new DeltaTime()
        {
            pos = curPosX, time = Time.time, flag = fromFlag
        };

        if (_deltaList.Count < TBL_DELTA_COUNT)
        {
            _deltaList.Add(tblDeltaTime);
        }
        else
        {
            _deltaList.RemoveAt(0);
            _deltaList.Add(tblDeltaTime);
        }
    }
Example #16
0
        public override void Update(DeltaTime deltaTime)
        {
            if (!loading)
            {
                loading = true;

                Font loadFont = new Font("Arial", 40, FontStyle.Bold);
                Size textSize = TextRenderer.MeasureText(loadingMessage, loadFont);

                graphics.FillRectangle(Brushes.Black, 0, 0, Program.Width, Program.Height);
                TextRenderer.DrawText(graphics, loadingMessage, loadFont, new Point(Program.Width / 2 - textSize.Width / 2, Program.Height / 2 - textSize.Height / 2), Color.White);

                base.Update(deltaTime);

                Program.Flags.Populate();
            }
            else
            {
                Program.SetCurrentState(Program.MainMenu);
            }
        }
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 private void GenerateParticles(DeltaTime deltaTime)
 {
     if (deltaTime.ElapsedGameTime.Milliseconds > ParticleController.GenerationTimer)
     {
         for (int nCounter = 0; nCounter < ParticleController.GenerationRate; ++nCounter)
         {
             if (m_freeParticleList.Count > 0)
             {
                 IParticle particle = m_freeParticleList.Dequeue();
                 particle.Scale = ParticleController.InitialScale;
                 ParticleController.InitializeParticle(ref particle, this);
                 particle.OnInitilized();
                 particle.Active = true;
             }
             else
             {
                 break;
             }
         }
     }
 }
Example #18
0
        //----------------------------------------------------------------------------
        //I have made this public so the consumer has the choice of running this multi-threaded or not.
        //----------------------------------------------------------------------------
        public void UpdateSimulation(DeltaTime deltaTime = default(DeltaTime))
        {
            PhysicsBody[] aBodies = null;

            lock (m_UpdateLock)
            {
                if (m_updateList.Count > 0)
                {
                    aBodies = m_updateList.ToArray();
                    m_updateList.Clear();
                }
            }

            if (aBodies == null)
            {
                return;
            }

            m_updateTime = deltaTime;
            Parallel.ForEach(aBodies, Simulate);
        }
Example #19
0
        public Node <INode> GetNode(string nodeName, IConstellationFileParser constellationFileParser)
        {
            switch (nodeName)
            {
            case DeltaTime.NAME:
                INode nodeDeltaTime = new DeltaTime() as INode;
                return(new Node <INode> (nodeDeltaTime));

            case ObjectParameter.NAME:
                INode nodeObjectAttribute = new ObjectParameter() as INode;
                return(new Node <INode> (nodeObjectAttribute));

            case Update.NAME:
                INode nodeUpdate = new Update() as INode;
                return(new Node <INode> (nodeUpdate));

            case LateUpdate.NAME:
                INode nodeLateUpdate = new LateUpdate() as INode;
                return(new Node <INode> (nodeLateUpdate));

            case PlayerPreferences.NAME:
                INode nodePlayerPref = new PlayerPreferences() as INode;
                return(new Node <INode> (nodePlayerPref));

            case LoadScene.NAME:
                INode nodeLoadScene = new LoadScene() as INode;
                return(new Node <INode> (nodeLoadScene));

            case Quit.NAME:
                INode quit = new Quit() as INode;
                return(new Node <INode> (quit));

            case AddConstellationBehaviourFromJSON.NAME:
                INode addConstellationBehaviourFromJSON = new AddConstellationBehaviourFromJSON() as INode;
                return(new Node <INode>(addConstellationBehaviourFromJSON));

            default:
                return(null);
            }
        }
Example #20
0
        public override int GetHashCode()
        {
            var hashCode = -1389298070;

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Name);

            hashCode = hashCode * -1521134295 + CameraFOV.GetHashCode();
            hashCode = hashCode * -1521134295 + CameraFOV.GetHashCode();
            hashCode = hashCode * -1521134295 + DeltaTime.GetHashCode();
            hashCode = hashCode * -1521134295 + Speed.GetHashCode();
            hashCode = hashCode * -1521134295 + G.GetHashCode();
            hashCode = hashCode * -1521134295 + Epoch.GetHashCode();
            hashCode = hashCode * -1521134295 + CollisionsType.GetHashCode();

            foreach (MaterialPoint body in Bodies)
            {
                hashCode = hashCode * -1521134295 + body.GetHashCode();
            }

            hashCode = hashCode * -1521134295 + EnableTracers.GetHashCode();
            return(hashCode);
        }
Example #21
0
        protected bool TryGetNext(out TSignal signal, DeltaTime deltaTime)
        {
            while (true)
            {
                if (this.basicQueue.TryDequeue(out var info))
                {
                    if (info.Delay != TimeSpan.Zero)
                    {
                        lock (this.syncRoot)
                        {
                            this.delayedQueue.Push(new DelayedSignalInfo(info.Signal, deltaTime.TotalTime.Add(info.Delay)));
                        }

                        continue;
                    }

                    signal = info.Signal;
                    return(true);
                }

                lock (this.syncRoot)
                {
                    if (this.delayedQueue.Count > 0)
                    {
                        var item = this.delayedQueue.Top;
                        if (item.TargetDeltaTime <= deltaTime.TotalTime)
                        {
                            this.delayedQueue.Pop();
                            signal = item.Signal;
                            return(true);
                        }
                    }
                }

                signal = default(TSignal);
                return(false);
            }
        }
Example #22
0
        private void UpdateNode(DeltaTime deltaTime, bool isFixedUpdate, ulong id, bool parentExecuting = true)
        {
            SceneNode node = allNodes[id];

            if (node.updatePolicy == NodeUpdatePolicy.AlwaysExecute ||
                (node.updatePolicy == NodeUpdatePolicy.FollowParent && parentExecuting))
            {
                if (isFixedUpdate)
                {
                    node.FixedUpdate(deltaTime);
                }
                else
                {
                    node.Update(deltaTime);
                }
                parentExecuting = true;
            }

            foreach (ulong childId in node.children)
            {
                UpdateNode(deltaTime, isFixedUpdate, childId, parentExecuting);
            }
        }
Example #23
0
        private List <TimeSpan> GetDeltas()
        {
            var delta    = DeltaTime.Get();
            var previous = dtFecha.SelectedDate;


            StartDate.Set(previous.GetValueOrDefault().Add(StartDate.Get().TimeOfDay));

            foreach (C1GridViewRow item in gridEstados.Rows)
            {
                var txt = item.FindControl("txtHoraEstado") as TextBox;

                if (txt != null)
                {
                    var time = GetHours(txt.Text, previous.GetValueOrDefault());
                    var ts   = time.Subtract(previous.GetValueOrDefault());

                    if (item.RowIndex == 0)
                    {
                        StartDate.Set(time);
                    }

                    previous = time;

                    if (ts == delta[item.RowIndex])
                    {
                        continue;
                    }

                    delta[item.RowIndex] = ts;
                }

                break;
            }

            return(delta);
        }
Example #24
0
        public override void Update(DeltaTime deltaTime)
        {
            if (Enabled && currentFade < maxFade)
            {
                currentFade += deltaTime.Seconds;
                if (currentFade > maxFade)
                {
                    currentFade = maxFade;
                }
            }
            else if (!Enabled && currentFade > 0)
            {
                currentFade -= deltaTime.Seconds;
                if (currentFade < 0)
                {
                    currentFade = 0;
                }
            }

            foreach (QuizButton b in Buttons)
            {
                b.Update(deltaTime);
            }
        }
Example #25
0
        /// <summary>
        /// Get the first DeltaTime Interval inside a DeltaTime to split into defined units
        /// </summary>
        /// <param name="delta">The DeltaTime to iterate</param>
        /// <returns>The first DeltaTime day interval</returns>
        public static DeltaTime First(this DeltaTime delta)
        {
            //Parse the interval to date for manage
            DateTime start = DateTime.Parse(delta.StartTime, null, System.Globalization.DateTimeStyles.RoundtripKind);

            //Same for end NOTE: Could be optimized using a clone of start
            DateTime end = DateTime.Parse(delta.StartTime, null, System.Globalization.DateTimeStyles.RoundtripKind);

            //Use add for set the end DateTime unit
            if (start.Hour == _morningStartHour)
            {
                end = end.AddHours(_morningEndHour - _morningStartHour);
            }
            if (start.Hour == _afternoonStartHour)
            {
                end = end.AddHours(_afternoonEndHour - _afternoonStartHour);
            }

            //Else Not clamped DeltaTime ERROR
            //Return the new DeltaTime having "o" (ISO 8601) DateTime string formatted
            return(new DeltaTime {
                StartTime = start.ToString("o"), EndTime = end.ToString("o")
            });
        }
Example #26
0
        /// <summary>
        /// Determinate if a Deltatime start is in the future compared to current time
        /// </summary>
        /// <param name="deltaTime">This item to check</param>
        /// <returns>Bool true : the start time is in the future</returns>
        public static bool IsFuture(this DeltaTime deltaTime)
        {
            var now = DateTime.Now.ToString("o");

            return(string.Compare(deltaTime.StartTime, now) > 0);
        }
Example #27
0
 public virtual void Update(DeltaTime deltaTime)
 {
 }
 /// <summary>
 /// Creates a new Derivative object.
 /// </summary>
 /// <param name="initialCondition">Initial value to set x</param>
 public Derivative(double initialCondition)
 {
     m_xPrev = initialCondition;
     m_dt = new DeltaTime();
 }
 /// <summary>
 /// New Integral.
 /// </summary>
 public Integral()
 {
     m_value = 0;
     m_dt = new DeltaTime();
 }
Example #30
0
 protected abstract void DoUpdate(DeltaTime deltaTime);
Example #31
0
 /// <summary>
 /// Validator for DeltaTime class
 /// <para>
 ///     Delta time valid definition is a delta time that has EndTime attribute
 ///     Bigger than StartTime attribute, the two values should be string "o" (ISO 8601) formatted DateTime classes
 /// </para>
 /// </summary>
 /// <param name="deltaTime">Target to validate</param>
 /// <returns>The bool that indicates the valid status</returns>
 public static bool IsValid(this DeltaTime deltaTime)
 => (string.Compare(deltaTime.StartTime, deltaTime.EndTime) < 0);
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 public void Draw(DeltaTime deltaTime, ICamera camera)
 {
     m_octreeRoot.Draw(deltaTime, camera);
 }