コード例 #1
0
 public bool modifyList(IList <InterpolationState> list)
 {
     try
     {
         for (int i = 0; i < list.Count; i++)
         {
             InterpolationState IpS = dataEntities.InterpolationState.Where(x => x.ID == list[i].ID).FirstOrDefault();
             if (IpS == null)
             {
                 continue;
             }
             IpS.StartTime = list[i].StartTime;
             IpS.EndTime   = list[i].EndTime;
             IpS.Lvalue    = list[i].Lvalue;
             IpS.Rvalue    = list[i].Rvalue;
             IpS.Status    = list[i].Status;
         }
         dataEntities.SubmitChanges();
         return(true);
     }
     catch (Exception e)
     {
         log.write("Func:modifyList;" + e.StackTrace);
         return(false);
     }
 }
コード例 #2
0
    private float AdvanceLerpToPositionState(InterpolationState state, ref float movementDistanceAvailable)
    {
        movementChangedCounter = 0;

        Vector3 positionDiff = state.TargetPosition - this.transform.position;

        float clampedXPositionDiff = Mathf.Clamp(Mathf.Abs(positionDiff.x), 0, movementDistanceAvailable);
        float cappedXPositionDiff  = positionDiff.x > 0 ? clampedXPositionDiff : -clampedXPositionDiff;

        float clampedZPositionDiff = Mathf.Clamp(Mathf.Abs(positionDiff.z), 0, movementDistanceAvailable);
        float cappedZPositionDiff  = positionDiff.z > 0 ? clampedZPositionDiff : -clampedZPositionDiff;

        Vector3 position = new Vector3(this.transform.position.x + cappedXPositionDiff, 0f, this.transform.position.z + cappedZPositionDiff);

        movementDistanceAvailable -= clampedXPositionDiff > clampedZPositionDiff ? clampedXPositionDiff : clampedZPositionDiff;

        /*DIContainer.Logger.Debug(string.Format("AdvanceLerpToPositionState: frameDiffStartTarget: {0} frameDiffStartCurrent: {1} interpolant: {2} position: {3} CurrentFrame: {4} TargetFrame: {5}",
         *                                     frameDiffStartTarget, frameDiffStartCurrent, interpolant, position, currentFrame, state.TargetFrame));*/

        float positionChange = (this.transform.position - position).magnitude;

        this.transform.position = position;

        if ((this.transform.position - state.TargetPosition).magnitude <= 0.0001f)
        {
            CurrentStateToLerpTo = null;
        }

        return(positionChange);
    }
コード例 #3
0
        public IList <InterpolationState> queryIntersect(InterpolationState IpS)
        {
            var query = (from ips1 in dataEntities.InterpolationState where ips1.AnalogNo == IpS.AnalogNo && ips1.Status == 0 select ips1).Except(
                from ips2 in dataEntities.InterpolationState where ips2.AnalogNo == IpS.AnalogNo && ips2.Status == 0 &&
                (ips2.EndTime <IpS.StartTime.AddHours(-1) || ips2.StartTime> IpS.EndTime.AddHours(1)) select ips2);

            return(query.ToList());
        }
コード例 #4
0
    protected virtual void OnPositionRotationUpdate(MatchSimulationUnit.MovementProperties movementProperties)
    {
        InterpolationState stateToAdd = new InterpolationState(movementProperties.GetUnityPosition(), movementProperties.GetUnityRotation(),
                                                               (byte)MathHelper.Modulo(movementProperties.Frame + FrameDelay, byte.MaxValue));

        //DIContainer.Logger.Debug("OnUnitStateUpdate state: " + stateToAdd);

        interpolationQueue.Enqueue(stateToAdd);
    }
コード例 #5
0
 public void Reset(GameObject splineObject)
 {
     this.splineObject = splineObject;
     m_nodes.Clear();
     m_state = InterpolationState.RESET;
     m_currentIndex = 1;
     m_currentTime = 0;
     m_rotations = false;
 }
コード例 #6
0
        /*
         * 获取子测点与父测点的重合缺失区间,包括已填补和未填补
         * */
        public IList <InterpolationState> queryIntersectWithParent(InterpolationState fatherIps, int sonNo)
        {
            var query = (from ips1 in dataEntities.InterpolationState where ips1.AnalogNo == sonNo select ips1).Except(
                from ips2 in dataEntities.InterpolationState
                where ips2.AnalogNo == sonNo &&
                (ips2.EndTime <fatherIps.StartTime || ips2.StartTime> fatherIps.EndTime)
                select ips2);

            return(query.ToList());
        }
コード例 #7
0
 public Interpolator(
     T min,
     T max,
     Func <T, T, float, T> lerp)
 {
     this.maxValue = max;
     this.minValue = min;
     this.state    = InterpolationState.Min;
     this.lerp     = lerp;
 }
コード例 #8
0
 void BeginInterpolation()
 {
     m_InterpolationState = new InterpolationState()
     {
         PositionDelta        = netPosition.Value - m_Rigidbody.position,
         RotationDelta        = Quaternion.Inverse(m_Rigidbody.rotation) * netRotation.Value,
         VelocityDelta        = netVelocity.Value - m_Rigidbody.velocity,
         AngularVelocityDelta = netAngularVelocity.Value - m_Rigidbody.angularVelocity,
         TimeRemaining        = m_InterpolationTime,
         TotalTime            = m_InterpolationTime
     };
 }
コード例 #9
0
 public bool insert(InterpolationState IpS)
 {
     try
     {
         dataEntities.InterpolationState.InsertOnSubmit(IpS);
         dataEntities.SubmitChanges();
         return(true);
     }
     catch (Exception e)
     {
         log.write("Func:insert;" + e.StackTrace);
         return(false);
     }
 }
コード例 #10
0
    public void ToMin(float delay)
    {
        float time = Time.time;

        if (this.state == InterpolationState.Max)
        {
            this.startTime = time;
            this.stopTime  = time + delay;
            this.state     = InterpolationState.ToMin;
        }
        else if (this.state == InterpolationState.ToMax)
        {
            this.FlipTime(time, delay);
            this.state = InterpolationState.ToMin;
        }
    }
コード例 #11
0
        public IList <InterpolationData> Strategy(InterpolationState ips)
        {
            IList <InterpolationData> ipsList = new List <InterpolationData>();

            if (ips.Lvalue < 0.0 || ips.Rvalue < 0.0)
            {
                return(null);
            }
            if (ips.Status == 1)
            {
                //query from InterpolationData;
            }
            try
            {
                PointRelation pointRel = ser.Deserialize(redis.Get <byte[]>(ips.AnalogNo.ToString())) as PointRelation;
                IList <int>   sonList  = pointRel.SonList;
                if (sonList == null || sonList.Count == 0)
                {
                    //ipsList = Interpolate(ips);
                    return(ipsList);
                }
                for (int i = 0; i < sonList.Count; i++)
                {
                    IList <InterpolationState> sonIpsList = interpolationStateRepos.queryIntersectWithParent(ips, sonList[i]);
                    IList <InterpolationData>  sonIpdList = new List <InterpolationData>();
                    for (int j = 0; j < sonIpsList.Count; j++)
                    {
                        IList <InterpolationData> ipdList = Strategy(sonIpsList[i]);
                        if (ipsList == null)
                        {
                            return(null);
                        }
                        for (int k = 0; k < ipdList.Count; k++)
                        {
                            sonIpdList.Add(ipdList[k]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.write("Func:Strategy:" + ex.Message);
            }
            return(ipsList);
        }
コード例 #12
0
    private bool StartLerpingIfValid(byte currentFrame, ref float movementDistanceAvailable)
    {
        if (interpolationQueue.Count > 0 && ShouldLerpToState(interpolationQueue.Peek(), currentFrame))
        {
            CurrentStateToLerpTo         = interpolationQueue.Dequeue();
            modelRoot.transform.rotation = CurrentStateToLerpTo.TargetRotation;
            float positionChanged = AdvanceLerpToPositionState(CurrentStateToLerpTo, ref movementDistanceAvailable);

            if (positionChanged > 0.1f && animator != null)
            {
                animator.SetBool("Running", true);
            }

            return(true);
        }

        return(false);
    }
コード例 #13
0
    private bool ShouldLerpToState(InterpolationState state, byte currentFrame)
    {
        // is state in past or current frame? Should never happen.
        if (MatchSimulationUnit.IsFrameInFuture(currentFrame, state.TargetFrame) || currentFrame == state.TargetFrame)
        {
            return(true);
        }

        Vector3 positionDiff = state.TargetPosition - this.transform.position;
        byte    frameDiff    = MathHelper.GetFrameDiff(currentFrame, state.TargetFrame);
        byte    maxFramesForPositionChange = MathHelper.GetRoundedMaxFramesForPositionChange(positionDiff);
        bool    shouldLerp = (frameDiff - maxFramesForPositionChange) <= 1 || frameDiff == 0;

        /*DIContainer.Logger.Debug(string.Format("ShouldLerp: {0} PositionDiff: {1} FrameDiff: {2} FramesForPositionChange: {3} CurrentFrame: {4} TargetFrame: {5}",
         *                                     shouldLerp, positionDiff, frameDiff, maxFramesForPositionChange, currentFrame, state.TargetFrame));*/

        return(shouldLerp);
    }
コード例 #14
0
    // Client
    protected virtual void OnApplyServerState(ServerState state)
    {
        if (state.position != default(Vector3)) // if the pos. isnt default the rot. isnt too
        {
            for (int i = interpolationStateBuffer.Length - 1; i >= 1; i--)
            {
                interpolationStateBuffer[i] = interpolationStateBuffer[i - 1];
            }

            InterpolationState newState = new InterpolationState(state.position, state.rotation, state.timestamp);
            interpolationStateBuffer[0] = newState;

            timestampCount = Mathf.Min(timestampCount + 1, interpolationStateBuffer.Length);
            //for (int i = 0; i < timestampCount - 1; i++)
            //{
            //    if (interpolationStateBuffer[i].serverTimestamp < interpolationStateBuffer[i + 1].serverTimestamp)
            //        Debug.Log("Inconsistent state found, reshuffling...");
            //}
        }
    }
コード例 #15
0
    protected T GetValue()
    {
        float time = Time.time;
        float t    = 0.0f;

        if (this.state == InterpolationState.ToMax)
        {
            if (time > this.stopTime)
            {
                this.state = InterpolationState.Max;
            }
            else
            {
                t = Time.time - this.startTime;
            }
        }
        else if (this.state == InterpolationState.ToMin)
        {
            if (time > this.stopTime)
            {
                this.state = InterpolationState.Min;
            }
            else
            {
                t = this.stopTime - Time.time;
            }
        }

        if (this.state == InterpolationState.Min)
        {
            return(this.minValue);
        }
        else if (this.state == InterpolationState.Max)
        {
            return(this.maxValue);
        }

        t /= (this.stopTime - this.startTime);
        return
            (this.lerp(this.minValue, this.maxValue, t));
    }
コード例 #16
0
    // Use this for initialization
    void Start()
    {
        globalTrace = new GameObject("Global trace");
        filter = globalTrace.AddComponent<MeshFilter>();

        state = GetComponentInParent<InterpolationState>();
        lastVersion0 = state.interpolateFrom.version;
        lastVersion1 = state.interpolateTo.version;

        filter.mesh = new Mesh(); ;

        globalTrace.AddComponent<MeshRenderer>().material = material;

        last = InterpolationState.interpolationAt;
        lastAt = transform.position;

        if (colorMap == null)
        {
            colorMap = new Texture2D(256, 2);
            Color[] image = new Color[colorMap.width*2];
            for (int i = 0; i < colorMap.width; i++)
            {
                //image[i].g = (float)i / (colorMap.width - 1);
                Color c = new Color(0.2f,0.7f,1f);

                //c *= (-Mathf.Cos(Mathf.Repeat((float)i / 64f, 1f) * Mathf.PI)) * 0.25f + 0.75f;

                if ((i / 64) % 2 != 0)
                    c *= 0.75f;
                image[i] = c;

                Color gray = new Color(c.grayscale,c.grayscale,c.grayscale);
                image[i + colorMap.width] = (c - gray) * 0.15f + gray;
                image[i + colorMap.width].a = 1f;
            }
            colorMap.SetPixels(image);
            colorMap.wrapMode = TextureWrapMode.Clamp;
            colorMap.Apply();
            material.mainTexture = colorMap;
        }
    }
コード例 #17
0
 public void ForceMin()
 {
     this.state = InterpolationState.Min;
 }
コード例 #18
0
 public void ForceMax()
 {
     this.state = InterpolationState.Max;
 }
コード例 #19
0
ファイル: WorldManager.cs プロジェクト: tuita520/heroesrpg
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool HasInterpolatedLocalEntityState(int id) => IsLocalSnapshotBuffered() && InterpolationState.ContainsGameObjectState(id);
コード例 #20
0
    private void Update()
    {
        if (m_state == InterpolationState.RESET || m_state == InterpolationState.STOPPED || splineObject == null || m_nodes.Count < 4)
            return;

        m_currentTime += Time.deltaTime;

        // We advance to next point in the path
        if (m_currentTime >= m_nodes[m_currentIndex + 1].Time)
        {
            if (m_currentIndex < m_nodes.Count - 3)
            {
                m_currentIndex++;
                m_nodes[m_currentIndex].gameObject.SendMessage("OnSplinePointReached", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                //Destroy(this.gameObject);
                m_state = InterpolationState.STOPPED;

                // We stop right in the end point
                splineObject.transform.position = m_nodes[m_nodes.Count - 2].Point;

                if (m_rotations)
                    splineObject.transform.rotation = m_nodes[m_nodes.Count - 2].Rot;

                // We call back to inform that we are ended
                if (mOnEndCallback != null)
                    mOnEndCallback();
            }
        }

        if (m_state != InterpolationState.STOPPED)
        {
            // Calculates the t param between 0 and 1
            float param = (m_currentTime - m_nodes[m_currentIndex].Time) / (m_nodes[m_currentIndex + 1].Time - m_nodes[m_currentIndex].Time);

            // Smooth the param
            param = MathUtils.Ease(param, m_nodes[m_currentIndex].EaseIO.x, m_nodes[m_currentIndex].EaseIO.y);

            splineObject.transform.position = GetHermiteInternal(m_currentIndex, param);

            if (m_rotations)
            {
                splineObject.transform.rotation = GetSquad(m_currentIndex, param);
            }
        }
    }
コード例 #21
0
 // Use this for initialization
 void Start()
 {
     source = GetComponentInParent <InterpolationState>();
 }
コード例 #22
0
    public void StartInterpolation(OnEndCallback endCallback, bool bRotations)
    {
        if (m_state != InterpolationState.RESET)
            throw new System.Exception("First reset, add points and then call here");

        m_state = InterpolationState.ONCE;
        m_rotations = bRotations;
        mOnEndCallback = endCallback;

        SetInput();
    }
コード例 #23
0
 // Use this for initialization
 void Start()
 {
     source = GetComponentInParent<InterpolationState>();
 }
コード例 #24
0
ファイル: WorldManager.cs プロジェクト: tuita520/heroesrpg
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public LocalEntityState GetInterpolatedEntityState(int id) => InterpolationState.GetGameObjectState(id);
コード例 #25
0
        void scanMissingGap(IList <AnalogHistoryHour> hourList)
        {
            try
            {
                int l = -1;
                int r = -1;
                IList <InterpolationState> gapList = new List <InterpolationState>();//保存缺失区间
                //Console.WriteLine("小时时间序列扫描:"+hourList.Count);
                //扫描连续缺失区间
                for (int i = 0; i < hourList.Count; i++)
                {
                    //获取缺失起点
                    if (hourList[i].AHH_Value == 0.0 && (i == 0 || hourList[i - 1].AHH_Value > 0.0))
                    {
                        l = i;
                    }
                    //获取缺失终点
                    else if (hourList[i].AHH_Value > 0.0 && i > 0 && hourList[i - 1].AHH_Value == 0.0)
                    {
                        r = i;
                    }
                    if (l != -1 && r != -1 || (l != -1 && i == hourList.Count - 1))
                    {
                        if (r == -1)
                        {
                            r = hourList.Count - 1;
                        }
                        InterpolationState IpS = new InterpolationState();
                        IpS.AnalogNo  = hourList[l].AHH_AnalogNo;
                        IpS.StartTime = hourList[l].AHH_HTime;
                        IpS.EndTime   = hourList[r].AHH_HTime;
                        IpS.Status    = 0;
                        IpS.Lvalue    = -100.0;//若边界缺失,置为负数,此处置为-100.0
                        IpS.Rvalue    = -100.0;
                        if (l != 0)
                        {
                            IpS.Lvalue    = hourList[l - 1].AHH_Value;
                            IpS.StartTime = hourList[l - 1].AHH_HTime;
                        }
                        if (r != hourList.Count - 1)
                        {
                            IpS.Rvalue  = hourList[r + 1].AHH_Value;
                            IpS.EndTime = hourList[r + 1].AHH_HTime;
                        }
                        gapList.Add(IpS);
                        l = -1;
                        r = -1;
                    }
                }
                for (int i = 0; i < gapList.Count; i++)
                {
                    IList <InterpolationState> ipsList = iplStateRepos.queryIntersect(gapList[i]);

                    /*Console.WriteLine("AnalogNo:" + gapList[i].AnalogNo+" gap:" + gapList[i].StartTime + " " + gapList[i].EndTime);
                     * for(int j = 0; j < ipsList.Count; j++)
                     * {
                     *  Console.WriteLine("interSect Gap:" + ipsList[j].StartTime + " " + ipsList[j].EndTime);
                     * }*/
                    //如果没有与当前缺失区间相交的区间,那么直接插入数据库
                    if (ipsList.Count == 0)
                    {
                        //iplStateRepos.insert(gapList[i]);
                    }
                    else
                    {
                        //将所有缺失区间合并成一个
                        for (int j = 0; j < ipsList.Count; j++)
                        {
                            if (gapList[i].StartTime > ipsList[j].StartTime)
                            {
                                gapList[i].StartTime = ipsList[j].StartTime;
                                gapList[i].Lvalue    = ipsList[j].Lvalue;
                            }
                            if (gapList[i].EndTime < ipsList[j].EndTime)
                            {
                                gapList[i].EndTime = ipsList[j].EndTime;
                                gapList[i].Rvalue  = ipsList[j].Rvalue;
                            }
                            //将已有缺失区间作废
                            ipsList[j].Status = -1;
                        }
                        //为节省存储,将已存在的第一个缺失区间回收
                        ipsList[0].StartTime = gapList[i].StartTime;
                        ipsList[0].EndTime   = gapList[i].EndTime;
                        ipsList[0].Lvalue    = gapList[i].Lvalue;
                        ipsList[0].Rvalue    = gapList[i].Rvalue;
                        ipsList[0].Status    = gapList[i].Status;
                        //iplStateRepos.modifyList(ipsList);
                    }
                }
            }
            catch (Exception ex)
            {
                log.write("Func:scanMissingData:" + ex.StackTrace);
            }
        }