// Use this for initialization
    void Start()
    {
        ds               = GameObject.Find("GaudyBG").GetComponent <DataScript> ();
        BPValue1         = transform.Find("TMPInputField/BPValue1").GetComponent <TMP_InputField> ();
        BPValue2         = transform.Find("TMPInputField/BPValue2").GetComponent <TMP_InputField> ();
        pulseValue       = transform.Find("TMPInputField/PulseValue").GetComponent <TMP_InputField> ();
        temperatureValue = transform.Find("TMPInputField/TempValue").GetComponent <TMP_InputField> ();
        respirationValue = transform.Find("TMPInputField/RespValue").GetComponent <TMP_InputField> ();

        //Finds the tab this script belongs to
        Transform tempObj = this.transform;

        while (parentTab == null && tempObj != null)
        {
            if (tempObj.name.EndsWith("Tab"))
            {
                parentTab = tempObj;
                break;
            }
            else
            {
                if (tempObj.parent != null)
                {
                    tempObj = tempObj.parent;
                }
                else
                {
                    Debug.Log("Cannot access parent tab!");
                    return;
                }
            }
        }

        NextFrame.Function(CreateValues);
    }
Exemple #2
0
        public Frame Roll(uint pins)
        {
            if (IsFull)
            {
                if (NextFrame != null)
                {
                    return(NextFrame.Roll(pins));
                }

                return(null);
            }

            if (!IsValidRoll(pins))
            {
                throw new InvalidRollException($"Invalid roll > {MaxValidRoll}");
            }

            var roll = new Roll(pins);

            Rolls.Add(roll);

            if (IsFull)
            {
                return(NextFrame);
            }

            return(this);
        }
    public override void OnDeselect(BaseEventData eventData)
    {
        Transform suggestions      = transform.Find("Suggestions");
        Transform closeSuggestions = transform.Find("CloseSuggestions");

        /*if (suggestions.childCount > 0) {
         *              foreach (Transform t in suggestions.GetComponentsInChildren<Transform>()) {
         *                      if (!t.name.Equals (suggestions.name))
         *                              continue;//t.gameObject.SetActive (false);
         *              }
         *      }*/
        //image.sprite = spriteState.disabledSprite;

        NextFrame.Function(delegate {
            if (EventSystem.current.currentSelectedGameObject == null || !EventSystem.current.currentSelectedGameObject.transform.IsChildOf(gameObject.transform))
            {
                m_CaretVisible = false;
                suggestions.gameObject.SetActive(false);
                closeSuggestions?.gameObject.SetActive(false);
                GetComponentInParent <AutofillTMP>().ResetSelected();
                DeactivateInputField();
            }
            else
            {
                EventSystem.current.SetSelectedGameObject(gameObject);
            }
        });

        base.OnDeselect(eventData);
    }
    // Use this for initialization
    void Start()
    {
        var input = gameObject.GetComponent <TMP_InputField>();

        NextFrame.Function(
            delegate { input.onValueChanged.Invoke(input.text); });
    }
 void Start()
 {
     if (GetComponent <TMP_InputField>().characterValidation.Equals(TMP_InputField.CharacterValidation.None))
     {
         GetComponent <TMP_InputField>().onValidateInput += delegate(string input, int charIndex, char addedChar) { return(MyValidate(input, charIndex, addedChar)); };
     }
     NextFrame.Function(ResizeField);
 }
Exemple #6
0
 /// <summary>
 /// Must be called each frame
 /// </summary>
 public void Frame()
 {
     _frames++;
     if (Math.Abs(Environment.TickCount - _lastTickCount) > 1000)
     {
         _lastFrameRate = (float)_frames * 1000 / Math.Abs(Environment.TickCount - _lastTickCount);
         _lastTickCount = Environment.TickCount;
         _frames        = 0;
     }
     NextFrame?.Invoke(this, null);
 }
    // Use this for initialization
    void Start()
    {
        firstName = GlobalData.firstName;
        lastName  = GlobalData.lastName;
        NextFrame.Function(AssignName);

        /*charEditor = GameObject.Find ("Canvas").transform.Find ("CharacterEditorPanel").gameObject;
         * if (charEditor == null) {
         *      print ("HI");
         *      charEditor = GameObject.Find ("Canvas").transform.GetChild (0).gameObject;
         * }*/
    }
    void Start()
    {
        gData          = GameObject.Find("Canvas").GetComponent <GlobalDataScript> ();
        mySkin         = Resources.Load(gData.resourcesPath + "/CEStyle") as GUISkin;
        mainInputField = GetComponent <InputField> ();
        mainInputField.onValidateInput += delegate(string input, int charIndex, char addedChar) { return(MyValidate(input, charIndex, addedChar)); };

        if (!mainInputField.text.Equals(""))
        {
            NextFrame.Function(RelocateText);
        }
    }
Exemple #9
0
        protected virtual void InitializeSwipeParamaters()
        {
            SwipeParamater = new SwipeParameter();
            var corners = new Vector3[4];

            swipeBounds.GetWorldCorners(corners);
            SwipeParamater.StartPositionRange = new Rect(corners[0], corners[2] - corners[0]);
            NextFrame.Function(UpdateSwipeParameters);
            SwipeParamater.AngleRanges.Add(new AngleRange(-30, 30));
            SwipeParamater.AngleRanges.Add(new AngleRange(150, 210));
            SwipeParamater.OnSwipeStart  += SwipeStart;
            SwipeParamater.OnSwipeUpdate += SwipeUpdate;
            SwipeParamater.OnSwipeEnd    += SwipeEnd;
        }
Exemple #10
0
 /**
  * Used temporarily as a delay for the save confirmation message
  */
 private void Fade()
 {
     if (notification.GetComponent <CanvasGroup>().alpha > 0)
     {
         if (!fade)
         {
             return;
         }
         //t.color = new Color (t.color.r, t.color.g, t.color.b, t.color.a - Time.deltaTime / 6f);
         notification.GetComponent <CanvasGroup>().alpha = (notification.GetComponent <CanvasGroup>().alpha - Time.deltaTime / 3f);
         NextFrame.Function(Fade);
         return;
     }
     Destroy(notification);
 }
    /**
     * Loads the data into xmlDoc to use
     */
    public void LoadXML()
    {
        string text = ds.GetData(tm.getCurrentSection(), transform.name.Substring(0, transform.name.Length - 3));

        if (text == null)
        {
            Debug.Log("No Data to load");
            ds.newTabs.Add(this.transform);
            return;
        }
        Debug.Log("Loaded data: " + text);
        xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(text);
        //LoadXMLData();
        NextFrame.Function(LoadXMLData);
    }
Exemple #12
0
 private void DispatchNextFrame(object sender, EventArgs args)
 {
     // naive solution for skipping frames if previous execution takes to long
     // TODO: what happens if there are more than one coroutine running... maybe there should be a busy flag for each item in invocation list
     if (_busy)
     {
         return;
     }
     _busy = true;
     try
     {
         NextFrame?.Invoke();
     }
     finally
     {
         _busy = false;
     }
 }
Exemple #13
0
    public override int GetHashCode()
    {
        int hash = 1;

        if (CurrentFrame != 0)
        {
            hash ^= CurrentFrame.GetHashCode();
        }
        if (NextFrame != 0)
        {
            hash ^= NextFrame.GetHashCode();
        }
        hash ^= keys_.GetHashCode();
        if (_unknownFields != null)
        {
            hash ^= _unknownFields.GetHashCode();
        }
        return(hash);
    }
Exemple #14
0
    public void UpdateText()
    {
        if (!pastingLock)
        {
            NextFrame.Function(UpdateTextOnNextFrame);
            pastingLock = true;

            inputText.rectTransform.offsetMax = Vector2.zero;
            inputText.rectTransform.offsetMin = Vector2.zero;
            if (!inputCaret)
            {
                inputCaret = (RectTransform)inputText.rectTransform.parent.Find("CustomContentValue Input Caret").transform;
            }
            inputCaret.offsetMax = Vector2.zero;
            inputCaret.offsetMin = Vector2.zero;
        }

        return;
    }
 private void FramePump()
 {
     while (_continue)
     {
         if (_busy)
         {
             return;
         }
         _busy = true;
         try
         {
             NextFrame?.Invoke();
         }
         finally
         {
             _busy = false;
         }
         Thread.Sleep(_frameIntervalMs);
     }
 }
    public void ResizeField()
    {
        if (resizeLock)
        {
            return;
        }
        resizeLock = true;

        var inputField = GetComponent <TMP_InputField>();

        if (inputField)
        {
            var rectTrans = inputField.textComponent.GetComponent <RectTransform>();
            if (rectTrans)
            {
                rectTrans.offsetMax = new Vector2(0, 0);
                rectTrans.offsetMin = new Vector2(0, 0);
            }
        }

        NextFrame.Function(ActivateResizeTMP);
        NextFrame.Function(delegate { NextFrame.Function(ActivateResizeTMP); });
    }
Exemple #17
0
    /**
     * Use this to show a confirmation that the case was saved successfully
     */
    public void ShowMessage(string message, bool error)
    {
        if (transform.Find("ContentPanel") != null && transform.Find("ContentPanel").GetComponent <FilePickerScript>().levelName.Equals("CassReader"))
        {
            return;
        }
        Transform parentTransform = GameObject.Find("TopCanvas")?.transform;

        if (parentTransform == null)
        {
            parentTransform = GameObject.Find("GaudyBG").transform;
        }
        if (!error)
        {
            if (parentTransform.Find("NotificationPanel") == null)
            {
                Destroy(notification);
                notification      = Instantiate(Resources.Load("Writer/Prefabs/NotificationMessage") as GameObject, parentTransform);
                notification.name = "NotificationPanel";
            }
        }
        else if (parentTransform.Find("ErrorPanel") == null)
        {
            Destroy(notification);
            notification      = Instantiate(Resources.Load("Writer/Prefabs/ErrorMessage") as GameObject, parentTransform);
            notification.name = "ErrorPanel";
        }
        CancelInvoke("Fade");
        fade = false;
        notification.GetComponent <CanvasGroup>().alpha = 1;
        notification.SetActive(true);
        TextMeshProUGUI messageText = notification.transform.Find("BG/Message").GetComponent <TextMeshProUGUI>();

        messageText.text = message;
        Invoke("Fade", 5f);
        NextFrame.Function(delegate { fade = true; });
    }
    public override void OnDeselect(BaseEventData eventData)
    {
        Transform suggestions = transform.Find("Suggestions");

        /*if (suggestions.childCount > 0) {
         *      foreach (Transform t in suggestions.GetComponentsInChildren<Transform>()) {
         *              if (!t.name.Equals (suggestions.name))
         *                      continue;//t.gameObject.SetActive (false);
         *      }
         * }*/
        NextFrame.Function(delegate
        {
            if (EventSystem.current.currentSelectedGameObject == null || !EventSystem.current.currentSelectedGameObject.transform.IsChildOf(gameObject.transform))
            {
                m_CaretVisible = false;
                suggestions.gameObject.SetActive(false);
                this.DeactivateInputField();
            }
            else
            {
                EventSystem.current.SetSelectedGameObject(gameObject);
            }
        });
    }
    //-------------------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------

    void ChooseScenePopup()
    {
        GameObject confirm;

        //If there's a way to tell a user exited from a case, this code *should* work, but case object is null. Will return to
        if (GlobalData.caseObj != null)
        {
            print("You are from the " + GlobalData.resourcePath);
            GlobalData.caseObj = null;
            if (GlobalData.demo)
            {
                confirm = GameObject.Find("GaudyBG").transform.Find("ReaderWriterSelector").gameObject;
            }
            else
            {
                confirm = GameObject.Find("GaudyBG").transform.Find("LocalOrServerConfirmation").gameObject;
            }

            if (GlobalData.resourcePath.Equals("Writer"))
            {
                levelName = "Writer";
                GlobalData.resourcePath = "Writer";
                Application.backgroundLoadingPriority = ThreadPriority.Low;
                StartLoading();
                confirm.SetActive(false);
                return;
            }
            else if (GlobalData.resourcePath.Equals("Reader"))
            {
                levelName = "CassReader";
                GameObject.Find("GaudyBG").GetComponent <ServerControls>().DisableNewCase();
                //GameObject.Find("GaudyBG").GetComponent<ServerControls>().ChangeEditButtons();
                GlobalData.resourcePath = "Reader";
                Application.backgroundLoadingPriority = ThreadPriority.Low;
                StartLoading();
                return;
            }
        }


        Button serverButton;
        Button localButton;

        if (GlobalData.demo)
        {
            confirm      = GameObject.Find("GaudyBG").transform.Find("ReaderWriterSelector").gameObject;
            serverButton = confirm.transform.Find("CaseWriter").GetComponent <Button>();
            localButton  = confirm.transform.Find("CaseReader").GetComponent <Button>();
        }
        else
        {
            confirm = GameObject.Find("GaudyBG").transform.Find("LocalOrServerConfirmation").gameObject;
            confirm.transform.Find("ConfirmActionPanel/Content/Row0/ActionValue").GetComponent <Text>().text = "Use Reader or Writer?";
            serverButton = confirm.transform.Find("ConfirmActionPanel/Content/Row1/ServerButton").GetComponent <Button>();
            localButton  = confirm.transform.Find("ConfirmActionPanel/Content/Row1/LocalButton").GetComponent <Button>();
            Button bothButton = confirm.transform.Find("ConfirmActionPanel/Content/Row1/BothButton").GetComponent <Button>();
            bothButton.gameObject.SetActive(false);

            serverButton.onClick.RemoveAllListeners();
            localButton.onClick.RemoveAllListeners();
            bothButton.onClick.RemoveAllListeners();

            serverButton.GetComponentInChildren <Text>().text = "Writer";
            localButton.GetComponentInChildren <Text>().text  = "Reader";
        }

        serverButton.onClick.AddListener(delegate {
            print("writer");
            confirm.SetActive(false);
            levelName = "Writer";
            if (!GlobalData.demo)
            {
                serverButton.GetComponentInChildren <Text>().text = "Server";
                localButton.GetComponentInChildren <Text>().text  = "Local";
            }
            GlobalData.resourcePath = "Writer";
            Application.backgroundLoadingPriority = ThreadPriority.Low;
            NextFrame.Function(StartLoading);
        });

        localButton.onClick.AddListener(delegate {
            print("reader");
            confirm.SetActive(false);
            levelName = "CassReader";
            if (!GlobalData.demo)
            {
                serverButton.GetComponentInChildren <Text>().text = "Server";
                localButton.GetComponentInChildren <Text>().text  = "Local";
            }
            GameObject.Find("GaudyBG").GetComponent <ServerControls>().DisableNewCase();
            //GameObject.Find("GaudyBG").GetComponent<ServerControls>().ChangeEditButtons();
            GlobalData.resourcePath = "Reader";
            Application.backgroundLoadingPriority = ThreadPriority.Low;
            NextFrame.Function(StartLoading);
        });

        confirm.SetActive(true);
    }
Exemple #20
0
        public static InstructionCollection Parse(Stream input, long instructionsPosition)
        {
            var instructions = new SortedList <int, InstructionBase>();

            using (var helper = new InstructionParseHelper(input, instructionsPosition))
            {
                var reader = helper.GetReader();
                while (helper.CanParse(instructions))
                {
                    //now reader the instructions
                    var instructionPosition = helper.CurrentPosition;
                    var type             = reader.ReadByteAsEnum <InstructionType>();
                    var requireAlignment = InstructionAlignment.IsAligned(type);

                    if (requireAlignment)
                    {
                        reader.Align(4);
                    }

                    InstructionBase instruction = null;
                    var             parameters  = new List <Value>();

                    switch (type)
                    {
                    case InstructionType.ToNumber:
                        instruction = new ToNumber();
                        break;

                    case InstructionType.NextFrame:
                        instruction = new NextFrame();
                        break;

                    case InstructionType.Play:
                        instruction = new Play();
                        break;

                    case InstructionType.Stop:
                        instruction = new Stop();
                        break;

                    case InstructionType.Add:
                        instruction = new Add();
                        break;

                    case InstructionType.Subtract:
                        instruction = new Subtract();
                        break;

                    case InstructionType.Multiply:
                        instruction = new Multiply();
                        break;

                    case InstructionType.Divide:
                        instruction = new Divide();
                        break;

                    case InstructionType.Not:
                        instruction = new Not();
                        break;

                    case InstructionType.StringEquals:
                        instruction = new StringEquals();
                        break;

                    case InstructionType.Pop:
                        instruction = new Pop();
                        break;

                    case InstructionType.ToInteger:
                        instruction = new ToInteger();
                        break;

                    case InstructionType.GetVariable:
                        instruction = new GetVariable();
                        break;

                    case InstructionType.SetVariable:
                        instruction = new SetVariable();
                        break;

                    case InstructionType.StringConcat:
                        instruction = new StringConcat();
                        break;

                    case InstructionType.GetProperty:
                        instruction = new GetProperty();
                        break;

                    case InstructionType.SetProperty:
                        instruction = new SetProperty();
                        break;

                    case InstructionType.Trace:
                        instruction = new Trace();
                        break;

                    case InstructionType.Random:
                        instruction = new RandomNumber();
                        break;

                    case InstructionType.Delete:
                        instruction = new Delete();
                        break;

                    case InstructionType.Delete2:
                        instruction = new Delete2();
                        break;

                    case InstructionType.DefineLocal:
                        instruction = new DefineLocal();
                        break;

                    case InstructionType.CallFunction:
                        instruction = new CallFunction();
                        break;

                    case InstructionType.Return:
                        instruction = new Return();
                        break;

                    case InstructionType.Modulo:
                        instruction = new Modulo();
                        break;

                    case InstructionType.NewObject:
                        instruction = new NewObject();
                        break;

                    case InstructionType.InitArray:
                        instruction = new InitArray();
                        break;

                    case InstructionType.InitObject:
                        instruction = new InitObject();
                        break;

                    case InstructionType.TypeOf:
                        instruction = new TypeOf();
                        break;

                    case InstructionType.Add2:
                        instruction = new Add2();
                        break;

                    case InstructionType.LessThan2:
                        instruction = new LessThan2();
                        break;

                    case InstructionType.Equals2:
                        instruction = new Equals2();
                        break;

                    case InstructionType.ToString:
                        instruction = new ToString();
                        break;

                    case InstructionType.PushDuplicate:
                        instruction = new PushDuplicate();
                        break;

                    case InstructionType.GetMember:
                        instruction = new GetMember();
                        break;

                    case InstructionType.SetMember:
                        instruction = new SetMember();
                        break;

                    case InstructionType.Increment:
                        instruction = new Increment();
                        break;

                    case InstructionType.Decrement:
                        instruction = new Decrement();
                        break;

                    case InstructionType.CallMethod:
                        instruction = new CallMethod();
                        break;

                    case InstructionType.Enumerate2:
                        instruction = new Enumerate2();
                        break;

                    case InstructionType.EA_PushThis:
                        instruction = new PushThis();
                        break;

                    case InstructionType.EA_PushZero:
                        instruction = new PushZero();
                        break;

                    case InstructionType.EA_PushOne:
                        instruction = new PushOne();
                        break;

                    case InstructionType.EA_CallFunc:
                        instruction = new CallFunc();
                        break;

                    case InstructionType.EA_CallMethodPop:
                        instruction = new CallMethodPop();
                        break;

                    case InstructionType.BitwiseXOr:
                        instruction = new BitwiseXOr();
                        break;

                    case InstructionType.Greater:
                        instruction = new Greater();
                        break;

                    case InstructionType.EA_PushThisVar:
                        instruction = new PushThisVar();
                        break;

                    case InstructionType.EA_PushGlobalVar:
                        instruction = new PushGlobalVar();
                        break;

                    case InstructionType.EA_ZeroVar:
                        instruction = new ZeroVar();
                        break;

                    case InstructionType.EA_PushTrue:
                        instruction = new PushTrue();
                        break;

                    case InstructionType.EA_PushFalse:
                        instruction = new PushFalse();
                        break;

                    case InstructionType.EA_PushNull:
                        instruction = new PushNull();
                        break;

                    case InstructionType.EA_PushUndefined:
                        instruction = new PushUndefined();
                        break;

                    case InstructionType.GotoFrame:
                        instruction = new GotoFrame();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.GetURL:
                        instruction = new GetUrl();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.SetRegister:
                        instruction = new SetRegister();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.ConstantPool:
                    {
                        instruction = new ConstantPool();
                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.GotoLabel:
                        instruction = new GotoLabel();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.DefineFunction2:
                    {
                        instruction = new DefineFunction2();
                        var name       = reader.ReadStringAtOffset();
                        var nParams    = reader.ReadUInt32();
                        var nRegisters = reader.ReadByte();
                        var flags      = reader.ReadUInt24();

                        //list of parameter strings
                        var paramList = reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                            {
                                Register  = reader.ReadInt32(),
                                Parameter = reader.ReadStringAtOffset(),
                            }, nParams);

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger((int)nParams));
                        parameters.Add(Value.FromInteger((int)nRegisters));
                        parameters.Add(Value.FromInteger((int)flags));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromInteger(param.Register));
                            parameters.Add(Value.FromString(param.Parameter));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.PushData:
                    {
                        instruction = new PushData();

                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.BranchAlways:
                    {
                        instruction = new BranchAlways();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GetURL2:
                        instruction = new GetUrl2();
                        break;

                    case InstructionType.DefineFunction:
                    {
                        instruction = new DefineFunction();
                        var name = reader.ReadStringAtOffset();
                        //list of parameter strings
                        var paramList = reader.ReadListAtOffset <string>(() => reader.ReadStringAtOffset());

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger(paramList.Count));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromString(param));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.BranchIfTrue:
                    {
                        instruction = new BranchIfTrue();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GotoFrame2:
                        instruction = new GotoFrame2();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.EA_PushString:
                        instruction = new PushString();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushConstantByte:
                        instruction = new PushConstantByte();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetStringVar:
                        instruction = new GetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringVar:
                        instruction = new SetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_GetStringMember:
                        instruction = new GetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringMember:
                        instruction = new SetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushValueOfVar:
                        instruction = new PushValueOfVar();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetNamedMember:
                        instruction = new GetNamedMember();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFuncPop:
                        instruction = new CallNamedFuncPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFunc:
                        instruction = new CallNamedFunc();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedMethodPop:
                        instruction = new CallNamedMethodPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushFloat:
                        instruction = new PushFloat();
                        parameters.Add(Value.FromFloat(reader.ReadSingle()));
                        break;

                    case InstructionType.EA_PushByte:
                        instruction = new PushByte();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushShort:
                        instruction = new PushShort();
                        parameters.Add(Value.FromInteger(reader.ReadUInt16()));
                        break;

                    case InstructionType.End:
                        instruction = new End();
                        break;

                    case InstructionType.EA_CallNamedMethod:
                        instruction = new CallNamedMethod();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.Var:
                        instruction = new Var();
                        break;

                    case InstructionType.EA_PushRegister:
                        instruction = new PushRegister();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushConstantWord:
                        instruction = new PushConstantWord();
                        parameters.Add(Value.FromConstant(reader.ReadUInt16()));
                        break;

                    case InstructionType.EA_CallFuncPop:
                        instruction = new CallFunctionPop();
                        break;

                    case InstructionType.StrictEqual:
                        instruction = new StrictEquals();
                        break;

                    default:
                        throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                    }

                    if (instruction != null)
                    {
                        instruction.Parameters = parameters;
                        instructions.Add(instructionPosition, instruction);
                    }
                }
            }

            return(new InstructionCollection(instructions));
        }
 private void handleRawFrameRead(NextFrame rawFrame)
 {
     if (isValidChecksum(rawFrame.RawBytes))
     {
         Frame frame = FrameParser.FrameFromRawBytes(rawFrame.RawBytes);
         if (frame != null)
         {
             OnRecievedFrame(new ReceivedRemoteFrameEventArgs(frame));
         }
     }
     else
     {
         OnFrameDropped(new FrameDroppedByChecksumEventArgs(rawFrame.RawBytes));
     }
 }
Exemple #22
0
        public void Parse()
        {
            var current = _reader.BaseStream.Position;

            _reader.BaseStream.Seek(_offset, SeekOrigin.Begin);
            bool parsing     = true;
            bool branched    = false;
            int  branchBytes = 0;

            while (parsing)
            {
                //now reader the instructions
                var type    = _reader.ReadByteAsEnum <InstructionType>();
                var aligned = InstructionAlignment.IsAligned(type);

                if (aligned)
                {
                    var padding = _reader.Align(4);
                    if (padding > 0)
                    {
                        Items.Add(new Padding(padding));
                        if (branched)
                        {
                            branchBytes -= (int)padding;

                            if (branchBytes <= 0)
                            {
                                branched    = false;
                                branchBytes = 0;
                            }
                        }
                    }
                }

                InstructionBase instruction = null;
                List <Value>    parameters  = new List <Value>();

                switch (type)
                {
                case InstructionType.ToNumber:
                    instruction = new ToNumber();
                    break;

                case InstructionType.NextFrame:
                    instruction = new NextFrame();
                    break;

                case InstructionType.Play:
                    instruction = new Play();
                    break;

                case InstructionType.Stop:
                    instruction = new Stop();
                    break;

                case InstructionType.Add:
                    instruction = new Add();
                    break;

                case InstructionType.Subtract:
                    instruction = new Subtract();
                    break;

                case InstructionType.Multiply:
                    instruction = new Multiply();
                    break;

                case InstructionType.Divide:
                    instruction = new Divide();
                    break;

                case InstructionType.Not:
                    instruction = new Not();
                    break;

                case InstructionType.StringEquals:
                    instruction = new StringEquals();
                    break;

                case InstructionType.Pop:
                    instruction = new Pop();
                    break;

                case InstructionType.ToInteger:
                    instruction = new ToInteger();
                    break;

                case InstructionType.GetVariable:
                    instruction = new GetVariable();
                    break;

                case InstructionType.SetVariable:
                    instruction = new SetVariable();
                    break;

                case InstructionType.StringConcat:
                    instruction = new StringConcat();
                    break;

                case InstructionType.GetProperty:
                    instruction = new GetProperty();
                    break;

                case InstructionType.SetProperty:
                    instruction = new SetProperty();
                    break;

                case InstructionType.Trace:
                    instruction = new Trace();
                    break;

                case InstructionType.Delete:
                    instruction = new Delete();
                    break;

                case InstructionType.Delete2:
                    instruction = new Delete2();
                    break;

                case InstructionType.DefineLocal:
                    instruction = new DefineLocal();
                    break;

                case InstructionType.CallFunction:
                    instruction = new CallFunction();
                    break;

                case InstructionType.Return:
                    instruction = new Return();
                    break;

                case InstructionType.NewObject:
                    instruction = new NewObject();
                    break;

                case InstructionType.InitArray:
                    instruction = new InitArray();
                    break;

                case InstructionType.InitObject:
                    instruction = new InitObject();
                    break;

                case InstructionType.TypeOf:
                    instruction = new InitObject();
                    break;

                case InstructionType.Add2:
                    instruction = new Add2();
                    break;

                case InstructionType.LessThan2:
                    instruction = new LessThan2();
                    break;

                case InstructionType.Equals2:
                    instruction = new Equals2();
                    break;

                case InstructionType.ToString:
                    instruction = new ToString();
                    break;

                case InstructionType.PushDuplicate:
                    instruction = new PushDuplicate();
                    break;

                case InstructionType.GetMember:
                    instruction = new GetMember();
                    break;

                case InstructionType.SetMember:
                    instruction = new SetMember();
                    break;

                case InstructionType.Increment:
                    instruction = new Increment();
                    break;

                case InstructionType.Decrement:
                    instruction = new Decrement();
                    break;

                case InstructionType.CallMethod:
                    instruction = new CallMethod();
                    break;

                case InstructionType.Enumerate2:
                    instruction = new Enumerate2();
                    break;

                case InstructionType.EA_PushThis:
                    instruction = new PushThis();
                    break;

                case InstructionType.EA_PushZero:
                    instruction = new PushZero();
                    break;

                case InstructionType.EA_PushOne:
                    instruction = new PushOne();
                    break;

                case InstructionType.EA_CallFunc:
                    instruction = new CallFunc();
                    break;

                case InstructionType.EA_CallMethodPop:
                    instruction = new CallMethodPop();
                    break;

                case InstructionType.BitwiseXOr:
                    instruction = new BitwiseXOr();
                    break;

                case InstructionType.Greater:
                    instruction = new Greater();
                    break;

                case InstructionType.EA_PushThisVar:
                    instruction = new PushThisVar();
                    break;

                case InstructionType.EA_PushGlobalVar:
                    instruction = new PushGlobalVar();
                    break;

                case InstructionType.EA_ZeroVar:
                    instruction = new ZeroVar();
                    break;

                case InstructionType.EA_PushTrue:
                    instruction = new PushTrue();
                    break;

                case InstructionType.EA_PushFalse:
                    instruction = new PushFalse();
                    break;

                case InstructionType.EA_PushNull:
                    instruction = new PushNull();
                    break;

                case InstructionType.EA_PushUndefined:
                    instruction = new PushUndefined();
                    break;

                case InstructionType.GotoFrame:
                    instruction = new GotoFrame();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.GetURL:
                    instruction = new GetUrl();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.SetRegister:
                    instruction = new SetRegister();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.ConstantPool:
                {
                    instruction = new ConstantPool();
                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.GotoLabel:
                    instruction = new GotoLabel();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.DefineFunction2:
                {
                    instruction = new DefineFunction2();
                    var name       = _reader.ReadStringAtOffset();
                    var nParams    = _reader.ReadUInt32();
                    var nRegisters = _reader.ReadByte();
                    var flags      = _reader.ReadUInt24();

                    //list of parameter strings
                    var paramList = _reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                        {
                            Register  = _reader.ReadInt32(),
                            Parameter = _reader.ReadStringAtOffset(),
                        }, nParams);

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger((int)nParams));
                    parameters.Add(Value.FromInteger((int)nRegisters));
                    parameters.Add(Value.FromInteger((int)flags));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromInteger(param.Register));
                        parameters.Add(Value.FromString(param.Parameter));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.PushData:
                {
                    instruction = new PushData();

                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.BranchAlways:
                    instruction = new BranchAlways();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GetURL2:
                    instruction = new GetUrl2();
                    break;

                case InstructionType.DefineFunction:
                {
                    instruction = new DefineFunction();
                    var name = _reader.ReadStringAtOffset();
                    //list of parameter strings
                    var paramList = _reader.ReadListAtOffset <string>(() => _reader.ReadStringAtOffset());

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger(paramList.Count));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromString(param));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.BranchIfTrue:
                    instruction = new BranchIfTrue();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GotoFrame2:
                    instruction = new GotoFrame2();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushString:
                    instruction = new PushString();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushConstantByte:
                    instruction = new PushConstantByte();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetStringVar:
                    instruction = new GetStringVar();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringVar:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_GetStringMember:
                    instruction = new GetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringMember:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushValueOfVar:
                    instruction = new PushValueOfVar();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetNamedMember:
                    instruction = new GetNamedMember();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFuncPop:
                    instruction = new CallNamedFuncPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFunc:
                    instruction = new CallNamedFunc();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedMethodPop:
                    instruction = new CallNamedMethodPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushFloat:
                    instruction = new PushFloat();
                    parameters.Add(Value.FromFloat(_reader.ReadSingle()));
                    break;

                case InstructionType.EA_PushByte:
                    instruction = new PushByte();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushShort:
                    instruction = new PushShort();
                    parameters.Add(Value.FromInteger(_reader.ReadUInt16()));
                    break;

                case InstructionType.End:
                    instruction = new End();

                    if (!branched)
                    {
                        parsing = false;
                    }
                    break;

                case InstructionType.EA_CallNamedMethod:
                    instruction = new CallNamedMethod();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.Var:
                    instruction = new Var();

                    break;

                default:
                    throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                }

                if (instruction != null)
                {
                    instruction.Parameters = parameters;
                    Items.Add(instruction);
                }

                if (branched)
                {
                    branchBytes -= (int)instruction.Size + 1;

                    if (branchBytes <= 0)
                    {
                        branched = false;
                    }
                }
            }
            _reader.BaseStream.Seek(current, SeekOrigin.Begin);
        }
Exemple #23
0
        /// <summary>
        /// This is a hot path. Runs at the completion interpolation, and attempts to find/reconstruct the next suitable frame for interpolation.
        /// </summary>
        public Frame DetermineAndPrepareNextFrame(bool svrWaitingForTeleportConfirm)
        {
            // buffer is empty, no point looking for any frames - we need to extrapolate the next frame
            if (validFrameMask <= 1)
            {
                DebugX.Log(!DebugX.logInfo ? "" :
                           //Debug.Log(
                           (Time.time + " NST " + nst.NstId + " " + nst.name + " <color=red><b> empty buffer, copying current frame to </b></color>" + NextFrame.frameid + " \n curr: " + currentFrame));

                ExtrapolateNextFrame(svrWaitingForTeleportConfirm);

                return(NextFrame);
            }

            extrapolationCount = 0;

            // First see if there is a future frame ready - ignoring late arrivles that may have backfilled behind the current frame
            Frame nextValid = GetFirstFutureValidFrame();

            // if not see if there is an older frame that arrived late, if so we will jump back to that as current
            if (nextValid == null)
            {
                nextValid = GetOldestPastValidFrame() ?? GetOldestValidFrame();

                // The only valid frames are only in the past, we need to jump back to the oldest to get our current frame in a better ballpark
                if (nextValid != null)
                {
                    DebugX.Log(!DebugX.logInfo ? "" :
                               //Debug.Log(
                               (Time.time + " NST " + nst.NstId + " " + nst.name + " <color=red><b> Skipping back to frame </b></color> " + nextValid.frameid + " from current frame " + CurrentIndex));

                    nextValid.CompletePosition(currentFrame);
                    return(nextValid);
                }
            }
            // Find out how far in the future the next valid frame is, need to know this for the reconstruction lerp.
            int stepsFromLast = CountFrames(CurrentIndex, nextValid.frameid);

            // The next frame is the next valid... not much thinking required... just use it.
            if (stepsFromLast == 1)
            {
                InvalidateOldFrames(NextFrame);                 // LIKELY UNEEDED
                NextFrame.CompletePosition(currentFrame);

                return(NextFrame);
            }

            // if next frame on the buffer is a couple ahead of current, jump forward
            if (stepsFromLast > jumpForwardThreshold)
            {
                //Debug.Log(
                DebugX.Log(!DebugX.logInfo ? "" :
                           ("<color=red><b>Jumping forward frame(s) </b></color>"));

                InvalidateOldFrames(nextValid);
                nextValid.CompletePosition(currentFrame);
                return(nextValid);
            }

            //All other cases we Reconstruct missing next frame using the current frame and a future frame
            Frame next = NextFrame;

            //Debug.Log(
            DebugX.Log(!DebugX.logInfo ? "" :
                       (Time.time + " NST:" + nst.NstId + " <color=black><b>Reconstructing missing packet " + next.frameid + " </b></color> \n" + currentFrame.compPos + "\n" + nextValid.compPos));

            next.state = currentFrame.state;

            float t = 1f / stepsFromLast;

            nextValid.CompletePosition(currentFrame);

            Vector3 lerpedPos = Vector3.Lerp(currentFrame.rootPos, nextValid.rootPos, t);

            float lerpedStartTime = Mathf.Lerp(currentFrame.packetArriveTime, nextValid.packetArriveTime, t);

            next.ModifyFrame(currentFrame.updateType, currentFrame.rootSendType, lerpedPos, GenericX.NULL, lerpedStartTime);

            DebugX.Log(!DebugX.logInfo ? "" :
                       (Time.time + "fid" + next.frameid + " <color=red><b> RECONSTRUCT ELEMENTS </b></color> " + next.RootRot + " " + currentFrame.RootRot + " " + nextValid.RootRot));

            // Notify all interested components that they need to reconstruct a missing frame (elements and such)
            foreach (INstOnReconstructMissing callbacks in nst.iNstOnReconstructMissing)
            {
                callbacks.OnReconstructMissing(next, currentFrame, nextValid, t, svrWaitingForTeleportConfirm);
            }

            return(next);
        }
Exemple #24
0
 // Use this for initialization
 void Start()
 {
     NextFrame.Function(ResetScroll);
 }
        /// <summary>
        /// This is a hot path. Runs at the completion interpolation, and attempts to find/reconstruct the next suitable frame for interpolation.
        /// </summary>
        public Frame DetermineAndPrepareNextFrame(bool svrWaitingForTeleportConfirm)
        {
            // buffer is empty, no point looking for any frames - we need to extrapolate the next frame
            if (validFrameMask == 0)
            {
                ExtrapolateNextFrame(svrWaitingForTeleportConfirm);

                XDebug.Log(!XDebug.logInfo ? null :
                           //Debug.Log(
                           (Time.time + " NST:" + nst.NstId + " <b> Empty buffer</b>, (likely packetloss) copying current frame to " + NextFrame.frameid + " " + nst.name +
                            "\nCurrentFrame: " + currentFrame.frameid + " scn:" + currentFrame.sceneIndex + " " + currentFrame.compPos + " " + currentFrame.rootPos +
                            "\nNextFrame: " + NextFrame.frameid + " scn:" + NextFrame.sceneIndex + " " + NextFrame.compPos + " " + NextFrame.rootPos));

                return(NextFrame);
            }

            extrapolationCount = 0;

            // First see if there is a future frame ready - ignoring late arrivles that may have backfilled behind the current frame
            Frame nextValid = GetFirstFutureValidFrame();

            // if not see if there is an older frame that arrived late, if so we will jump back to that as current
            if (nextValid == null)
            {
                nextValid = GetOldestPastValidFrame() ?? GetOldestValidFrame();

                // The only valid frames are only in the past, we need to jump back to the oldest to get our current frame in a better ballpark
                if (nextValid != null)
                {
                    nextValid.CompletePosition(currentFrame);
                    //Debug.Log(
                    XDebug.Log(!XDebug.logInfo ? null :
                               (Time.time + " NST:" + nst.NstId + " <b> Skipping back </b>(likely packetloss) to frame " + nextValid.frameid +
                                " from current frame " + CurrentIndex + " " + nst.name +
                                "\nOnly frames in buffer were in the past, so seems that we are getting ahead of the buffer. Should see these rarely." +
                                "\nCurrentFrame: " + currentFrame.frameid + " scn:" + currentFrame.sceneIndex + " " + currentFrame.compPos + " " + currentFrame.rootPos +
                                "\nNextValid: " + nextValid.frameid + " scn:" + nextValid.sceneIndex + " " + nextValid.compPos + " " + nextValid.rootPos));

                    return(nextValid);
                }
            }

            // Find out how far in the future the next valid frame is, need to know this for the reconstruction lerp.
            int stepsFromLast = CountFrames(CurrentIndex, nextValid.frameid);

            // The next frame is the next valid... not much thinking required... just use it.
            if (stepsFromLast == 1)
            {
                InvalidateOldFrames(NextFrame);                 // LIKELY UNEEDED
                NextFrame.CompletePosition(currentFrame);

                //Debug.Log(
                //XDebug.Log(!XDebug.logInfo ? null :
                //	(Time.time + " NST:" + nst.NstId + " <b>Normal Next</b> from " + CurrentIndex + " to " + NextFrame.frameid + "  (likely packetloss) from expected frame. " + nst.name +
                //	"\nCurrentFrame: " + currentFrame.frameid + " scn:" + currentFrame.sceneIndex + " " + currentFrame.compPos + " " + currentFrame.rootPos +
                //	"\nNextFrame: " + NextFrame.frameid + " scn:" + NextFrame.sceneIndex + " " + NextFrame.compPos + " " + NextFrame.rootPos));

                return(NextFrame);
            }

            // if next frame on the buffer is a couple ahead of current, jump forward
            if (stepsFromLast > jumpForwardThreshold)
            {
                //Debug.Log(
                XDebug.Log(!XDebug.logInfo ? null :
                           (Time.time + " NST:" + nst.NstId + " <b>Jumping forward</b> from " + CurrentIndex + " to " + nextValid.frameid + "  (likely packetloss) from expected frame. " + nst.name +
                            "\nCurrentFrame: " + currentFrame.frameid + " " + currentFrame.compPos + " " + currentFrame.rootPos +
                            "\nNextValidFrame: " + nextValid.frameid + " " + nextValid.compPos + " " + nextValid.rootPos));

                InvalidateOldFrames(nextValid);
                nextValid.CompletePosition(currentFrame);
                return(nextValid);
            }

            //All other cases we Reconstruct missing next frame using the current frame and a future frame

            NextFrame.state = currentFrame.state;

            float t = 1f / stepsFromLast;

            nextValid.CompletePosition(currentFrame);


            Vector3 lerpedPos = Vector3.Lerp(currentFrame.rootPos, nextValid.rootPos, t);

            float lerpedStartTime = Mathf.Lerp(currentFrame.packetArriveTime, nextValid.packetArriveTime, t);

            NextFrame.ModifyFrame(currentFrame.updateType, currentFrame.rootBitCullLevel, lerpedPos, GenericX.NULL, lerpedStartTime);

            //Debug.Log(
            XDebug.Log(!XDebug.logInfo ? null :
                       (Time.time + " NST:" + nst.NstId + " <b>Reconstructing frame " + NextFrame.frameid + "</b> (likely packetloss) from current frame and future frame "
                        + NextFrame.compPos + " <b>" + NextFrame.rootPos + "</b> " + nst.name +
                        "\nCurrentFrame: " + currentFrame.frameid + " scn:" + currentFrame.sceneIndex + " " + currentFrame.compPos + " " + currentFrame.rootPos +
                        "\nNextValidFrame: " + nextValid.frameid + " scn:" + nextValid.sceneIndex + " " + nextValid.compPos + " " + nextValid.rootPos) + " " + nextValid.rootBitCullLevel);


            //XDebug.Log(!XDebug.logInfo ? null :
            //	(Time.time + "fid" + NextFrame.frameid + " <color=red><b> RECONSTRUCT ELEMENTS </b></color> " + NextFrame.RootRot + " " + currentFrame.RootRot + " " + nextValid.RootRot));

            // Notify all interested components that they need to reconstruct a missing frame (elements and such)
            foreach (INstOnReconstructMissing callbacks in nst.iNstOnReconstructMissing)
            {
                callbacks.OnReconstructMissing(NextFrame, currentFrame, nextValid, t, svrWaitingForTeleportConfirm);
            }

            return(NextFrame);
        }
Exemple #26
0
    /**
     * Run every frame. Determins the world position of the entry being held as well as the placeholder's location
     */
    void Update()
    {
        if (drag)
        {
            //container.GetComponent<LayoutElement> ().ignoreLayout = true;
            //Check how far down the list of sibling entrys that this entry physically is
            rt.position = new Vector3(rt.position.x, Input.mousePosition.y - dMPos, 0f);
            int pos = 0;
            foreach (Transform entry in entries)
            {
                if (entry.transform.localPosition.y > container.localPosition.y)
                {
                    pos++;
                }
            }
            placeholder.transform.SetSiblingIndex(pos); //Set the placeholder index to match

            //This is used for scrolling when held at the top/bottom of the scroll area.
            //Adjust the .01f to change the speed of the scrolling (.01 means 1% per frame as far as I can tell)
            Vector3[] corners = new Vector3[4];
            scrollRectTransform.GetWorldCorners(corners);
            if (transform.position.y > corners[1].y - 40 && scrollScrollRect.verticalNormalizedPosition < 1.0f)
            {
                scrollScrollRect.verticalNormalizedPosition += .01f;
            }
            else if (transform.position.y < corners[0].y + 40 && scrollScrollRect.verticalNormalizedPosition > 0.0f)
            {
                scrollScrollRect.verticalNormalizedPosition -= .01f;
            }

            //If the user let go
            if (!Input.GetMouseButton(0))
            {
                drag = false;
                GetComponentInParent <DragOverrideScript>().enabled = true;
                foreach (Transform t in entries)
                {
                    t.GetComponent <ReaderMoveableObjectCursorScript>().enabled = true;
                }
                container.GetComponent <CanvasGroup>().alpha          = 1.0f;
                container.GetComponent <LayoutElement>().ignoreLayout = false;
                //Destroy (placeholder);
                //placeholder = null;

                //Double check the position
                pos = 0;
                foreach (Transform entry in entries)
                {
                    if (entry.parent == container.parent)
                    {
                        //Debug.Log ("dropped: " + container.localPosition.y + ", entry: " + entry.transform.localPosition.y);
                        if (container.localPosition.y < entry.transform.localPosition.y)
                        {
                            pos++;
                        }
                    }
                }

                //Destroy the placeholder and set the entry to the correct new location
                Destroy(placeholder);
                placeholder = null;
                hm.MoveTo(container.gameObject, pos, transformIndex);
                if (!EventSystem.current.IsPointerOverGameObject())
                {
                    OnPointerExit(null);
                }

                if (GetComponentInParent <DiagnosisCountScript>() != null)
                {
                    GetComponentInParent <DiagnosisCountScript>().ReorderEntries();
                }

                //Adjust the mouse icon accordingly
                if (!hover && cursor)
                {
                    cursor.sprite = null;
                    cursor.sprite = cursorPicture;
                }

                //Set the color if color feedback is enabled
                if (applyFeedbackColor)
                {
                    NextFrame.Function(ApplyFeedbackToEntries);
                }
            }
        }
    }
 public void RecieveText(InputField newText)
 {
     mainInputField.text = newText.text;
     NextFrame.Function(RelocateText);
 }
 public void OpenDemoScene(string fileName)
 {
     GlobalData.fileName = fileName;
     GlobalData.filePath = Application.streamingAssetsPath + "/DemoCases/Cases/";
     NextFrame.Function(ActivateScene);
 }
Exemple #29
0
 BallState Update(BallState state, NextFrame msg)
 {
     state.position += speed * Time.deltaTime;
     return(state);
 }
Exemple #30
0
        public Frame DetermineNextFrame()
        {
            // buffer is empty, no point looking for any frames
            if (validFrameMask <= 1)
            {
                DebugX.Log(Time.time + " NST " + nst.NstId + " " + nst.name + " <color=red><b> empty buffer, copying current frame </b></color>" + NextFrame.packetid);
                ExtrapolateNextFrame();
                return(NextFrame);
            }

            // First see if there is a future frame ready
            Frame nextValid = GetFirstFutureValidFrame();

            // if not see if there is an older frame that arrived late, if so we will jump back to that as current
            if (nextValid == null)
            {
                nextValid = GetOldestPastValidFrame();

                // Valid frames are only in the past, we need to jump back to that packetindex
                if (nextValid != null)
                {
                    DebugX.Log(Time.time + " NST " + nst.NstId + " " + nst.name + " <color=red><b> Skipping back to older frame </b></color> " + nextValid.packetid);
                    nextValid.CompletePosition(currentFrame);
                    return(nextValid);
                }
                // No future or past frames found - Look everywhere as a last ditch check in case we are way out of sync

                nextValid = GetOldestValidFrame();
                if (nextValid != null)
                {
                    DebugX.Log(Time.time + " NST " + nst.NstId + " " + nst.name + " <color=red><b> Skipping to out of sequence frame </b></color> " + nextValid.packetid);
                    nextValid.CompletePosition(currentFrame);                     // of questionable value for a frame this out of sequence, but better than 0 position.
                    return(nextValid);
                }
            }

            // Find out how far in the future the next valid frame is, need to know this for the reconstruction lerp.
            int stepsFromLast = CountFrames(CurrentIndex, nextValid.packetid);

            // The next frame is the next valid... not much thinking required... just use it.
            if (stepsFromLast == 1)
            {
                InvalidateOldFrames(NextFrame);
                NextFrame.CompletePosition(currentFrame);
                return(NextFrame);
            }

            if (stepsFromLast > 2)             // arbitrary number... should refine this
            {
                InvalidateOldFrames(nextValid);
                nextValid.CompletePosition(currentFrame);
                return(nextValid);
            }

            //All other cases we Reconstruct missing next frame
            Frame next = NextFrame;

            DebugX.Log(Time.time + " NST:" + nst.NstId + " <color=black><b>Reconstructing missing packet " + next.packetid + " </b></color>");

            float t = 1f / stepsFromLast;

            nextValid.CompletePosition(currentFrame);
            CompressedElement lerpedCompPos = Vector3.Lerp(currentFrame.pos, nextValid.pos, t).CompressPos();             // TODO: should this be v3 lerps instead to avoid the rounding error?
            // TEST
            //CompressedPos lerpedCompPos = nextValid.compPos; // TODO: should this be v3 lerps instead to avoid the rounding error?

            float lerpedStartTime = Mathf.Lerp(currentFrame.packetArriveTime, nextValid.packetArriveTime, t);

            next.ModifyFrame(currentFrame.msgType, lerpedCompPos, lerpedCompPos.Decompress(), lerpedStartTime);

            // Reconstruct missing Position Element
            for (int i = 0; i < next.positions.Count; i++)
            {
                GenericX currentTargetX = nst.positionElements[i].target;

                if (BitTools.GetBitInMask(nextValid.positionsMask, i))
                {
                    next.positions[i] = (Vector3.Lerp(currentTargetX, nextValid.positions[i], t));
                    i.SetBitInMask(ref next.positionsMask, true);
                }
                else
                {
                    next.positions[i] = currentTargetX;
                    i.SetBitInMask(ref next.rotationsMask, false);
                }
            }

            // Reconstruct missing Rotation Element
            for (int i = 0; i < next.rotations.Count; i++)
            {
                GenericX currentTargetX = nst.rotationElements[i].target;

                if (BitTools.GetBitInMask(nextValid.rotationsMask, i))
                {
                    if (currentTargetX.type == XType.NULL)
                    {
                        Debug.LogError(nst.name + "  Cloning NULL GenX element " + i + "  " + currentTargetX + " - which should never happen, this would be a bug.");
                    }

                    next.rotations[i] = (Quaternion.Slerp(currentTargetX, nextValid.rotations[i], t));

                    //TEST
                    next.rotations[i] = currentTargetX;
                    i.SetBitInMask(ref next.rotationsMask, true);
                }
                else
                {
                    next.rotations[i] = nst.rotationElements[i].target;                     // maybe unneeded
                    i.SetBitInMask(ref next.rotationsMask, false);
                }
            }

            return(next);
        }
 protected virtual void SetAccordionToTweenNextFrame() => NextFrame.Function(SetAccordionToTweenTransition);