Inheritance: MonoBehaviour
Exemple #1
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Jump game = new Jump())
     {
         game.Run();
     }
 }
	void Start()
	{
		jump = GetComponent<Jump> ();
		charge = GetComponent<Charge> ();
		anim = gameObject.GetComponent<Animator> ();
		score = GetComponent<PlayerScore>();
	}
 /// <summary>
 /// 	Get the basics components the player need
 /// </summary>
 void Awake()
 {
     moveEnnemy = GetComponent<Movement>();
     jumpEnnemy = GetComponent<Jump>();
     toHunt = Player.GetComponent<Rigidbody2D> ();
     myself = GetComponent<Rigidbody2D> ();
 }
Exemple #4
0
	// Use this for initialization
	void Awake ()
	{
		jumpScript = this.GetComponent<Jump> ();
		characterMoveScript = this.GetComponent<CharacterMove> ();
		characterMoveSpeed = characterMoveScript._Speed;
		jumpFallSpeed = jumpScript._FallSpeed;
	}
 // Use this for initialization
 void Start()
 {
     _animator = GetComponent<Animator>();
     _gravity = GetComponent<Gravity>();
     _playerMovement = GetComponent<PlayerMovement>();
     _jump = GetComponent<Jump>();
 }
Exemple #6
0
    public override void jump(){

        movement = new Jump();

        Console.Write("The cat ");
        movement.move();
    }
Exemple #7
0
        public Assignment(Board board, Jump jump)
        {
            Check.Require(board != null, "board is a required argument.");
            Check.Require(jump != null, "jump is a required argument.");

            Board = board;
            Jump = jump;
        }
Exemple #8
0
    void Start()
    {
        _jump = GetComponentInChildren<Jump>();
        ErrorLog.CheckComponentExist(this._jump, "Jump", this.name);

        _attribute = GetComponentInParent<PlayerAttirbute>();
        ErrorLog.CheckComponentExist(this._attribute, "Attribute", this.name);
    }
Exemple #9
0
 static public void AddJump(GameObject gameObject, ActionSequence sequence)
 {
     Jump action = new Jump();
     action.source = gameObject;
     action.force = 5f;
     action.duration = 0.5f;
     QueuePop(sequence,3);
     sequence.actions.Add(action);
 }
Exemple #10
0
        public void DifferentBoardsAreNotEquivalent()
        {
            Jump jump = new Jump(new[]{2,0}, new[]{1,0}, new[]{0,0});

            Board b1 = NewBoard();
            Board b2 = NewBoard().ExecuteJump(jump);

            Assert.AreEqual(false, b1.IsEquivalent(b2));
        }
Exemple #11
0
    void Awake()
    {
        controller = GetComponent<CharacterController>();
        changeScale = GetComponent<ChangeScale>();

        ground = GetComponent<Ground>();
        jump = GetComponent<Jump>();
        antigravityEffect = GetComponent<AntigravityEffect>();
    }
    // Use this for initialization
    void Start()
    {
        feedback = GameObject.Find("Feedback").GetComponent<Text>();

        player = GameObject.FindGameObjectWithTag("Player");

        movement = player.GetComponent<Movement>();
        run = player.GetComponent<Run>();
        jump = player.GetComponent<Jump>();
    }
Exemple #13
0
    // Use this for initialization
    void Start()
    {
        head = GameObject.FindGameObjectWithTag("Head");
        headRend = head.GetComponent<MeshRenderer>();

        movement = GetComponent<Movement>();
        jump = GetComponent<Jump>();
        flash = GetComponent<FlashPlayer>();

        isSquatting = false;
    }
 // Use this for initialization
 void Start()
 {
     player = GameObject.FindGameObjectWithTag("Player");
     movement = player.GetComponent<Movement>();
     flash = player.GetComponent<FlashPlayer>();
     squat = player.GetComponent<Squat>();
     jump = player.GetComponent<Jump>();
     hud = player.GetComponent<HUD>();
     bounds = new Bounds(new Vector3(transform.position.x, transform.position.y, transform.position.z),
                         new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z));
 }
 public override void Jump(Jump j, int rel32)
 {
     if (rel32 > 0)
     {
         @out.WriteLine("{0} EIP+{1:X}h", j, rel32);
     }
     else
     {
         @out.WriteLine("{0} EIP-{1:X}h", j, -rel32);
     }
 }
 public override void Jump(Jump j, sbyte rel8)
 {
     if (rel8 > 0)
     {
         @out.WriteLine("{0} EIP+{1:X}h", j, rel8);
     }
     else
     {
         @out.WriteLine("{0} EIP-{1:X}h", j, -rel8);
     }
 }
Exemple #17
0
        public void MovePegIsCorrect()
        {
            Board board = NewBoard();
            Jump move = new Jump(new []{0,2}, new[]{0,1}, new []{0,0});
            Board newBoard = board.ExecuteJump(move);

            Assert.AreEqual(false, newBoard[0, 2].HasPeg);
            Assert.AreEqual(false, newBoard[0, 1].HasPeg);
            Assert.AreEqual(true, newBoard[0, 0].HasPeg);
            Assert.AreEqual(true, board.IsEquivalent(NewBoard())); // ensure original board is the same

            Console.WriteLine(newBoard.ToString());
        }
 /// <summary>
 /// Moves the <see cref="Actor"/> instance
 /// to the <see cref="E:Destination"/>.
 /// </summary>
 public override void Execute()
 {
     Location manLocation = level.Actor.Location;
     if (manLocation.IsAdjacentLocation(Destination))
     {/* This is adjacent, hence we do not need to jump.
       * Instead we just move. */
         Direction direction = manLocation.GetDirection(Destination);
         Move move = new Move(direction);
         level.Actor.DoMove(move);
     }
     else
     {
         Jump jump = new Jump(Destination);
         level.Actor.DoMove(jump);
     }
 }
Exemple #19
0
    public void isCheck(string keyname)
    {
        KeyName = keyname;
        if (isChange)
        {
            print(KeyName);
            switch (KeyName)
            {
            case "MoveF":
                MoveB.GetComponentInChildren <Text>().text    = jt[0]["MoveB"].ToString();
                MoveU.GetComponentInChildren <Text>().text    = jt[0]["MoveU"].ToString();
                MoveD.GetComponentInChildren <Text>().text    = jt[0]["MoveD"].ToString();
                Jump.GetComponentInChildren <Text>().text     = jt[0]["Jump"].ToString();
                AtkKey.GetComponentInChildren <Text>().text   = jt[0]["AtkKey"].ToString();
                CheckKey.GetComponentInChildren <Text>().text = jt[0]["CheckKey"].ToString();
                break;

            case "MoveB":
                MoveF.GetComponentInChildren <Text>().text    = jt[0]["MoveF"].ToString();
                MoveU.GetComponentInChildren <Text>().text    = jt[0]["MoveU"].ToString();
                MoveD.GetComponentInChildren <Text>().text    = jt[0]["MoveD"].ToString();
                Jump.GetComponentInChildren <Text>().text     = jt[0]["Jump"].ToString();
                AtkKey.GetComponentInChildren <Text>().text   = jt[0]["AtkKey"].ToString();
                CheckKey.GetComponentInChildren <Text>().text = jt[0]["CheckKey"].ToString();
                break;

            case "MoveU":
                MoveB.GetComponentInChildren <Text>().text    = jt[0]["MoveB"].ToString();
                MoveD.GetComponentInChildren <Text>().text    = jt[0]["MoveD"].ToString();
                MoveF.GetComponentInChildren <Text>().text    = jt[0]["MoveF"].ToString();
                Jump.GetComponentInChildren <Text>().text     = jt[0]["Jump"].ToString();
                AtkKey.GetComponentInChildren <Text>().text   = jt[0]["AtkKey"].ToString();
                CheckKey.GetComponentInChildren <Text>().text = jt[0]["CheckKey"].ToString();
                break;

            case "MoveD":
                MoveB.GetComponentInChildren <Text>().text    = jt[0]["MoveB"].ToString();
                MoveU.GetComponentInChildren <Text>().text    = jt[0]["MoveU"].ToString();
                MoveF.GetComponentInChildren <Text>().text    = jt[0]["MoveF"].ToString();
                Jump.GetComponentInChildren <Text>().text     = jt[0]["Jump"].ToString();
                AtkKey.GetComponentInChildren <Text>().text   = jt[0]["AtkKey"].ToString();
                CheckKey.GetComponentInChildren <Text>().text = jt[0]["CheckKey"].ToString();
                break;

            case "Jump":
                MoveF.GetComponentInChildren <Text>().text    = jt[0]["MoveF"].ToString();
                MoveB.GetComponentInChildren <Text>().text    = jt[0]["MoveB"].ToString();
                MoveU.GetComponentInChildren <Text>().text    = jt[0]["MoveU"].ToString();
                MoveD.GetComponentInChildren <Text>().text    = jt[0]["MoveD"].ToString();
                AtkKey.GetComponentInChildren <Text>().text   = jt[0]["AtkKey"].ToString();
                CheckKey.GetComponentInChildren <Text>().text = jt[0]["CheckKey"].ToString();
                break;

            case "AtkKey":
                MoveF.GetComponentInChildren <Text>().text    = jt[0]["MoveF"].ToString();
                MoveB.GetComponentInChildren <Text>().text    = jt[0]["MoveB"].ToString();
                MoveU.GetComponentInChildren <Text>().text    = jt[0]["MoveU"].ToString();
                MoveD.GetComponentInChildren <Text>().text    = jt[0]["MoveD"].ToString();
                Jump.GetComponentInChildren <Text>().text     = jt[0]["Jump"].ToString();
                CheckKey.GetComponentInChildren <Text>().text = jt[0]["CheckKey"].ToString();
                break;

            case "CheckKey":
                MoveF.GetComponentInChildren <Text>().text  = jt[0]["MoveF"].ToString();
                MoveB.GetComponentInChildren <Text>().text  = jt[0]["MoveB"].ToString();
                MoveU.GetComponentInChildren <Text>().text  = jt[0]["MoveU"].ToString();
                MoveD.GetComponentInChildren <Text>().text  = jt[0]["MoveD"].ToString();
                Jump.GetComponentInChildren <Text>().text   = jt[0]["Jump"].ToString();
                AtkKey.GetComponentInChildren <Text>().text = jt[0]["AtkKey"].ToString();
                break;
            }
        }
        if (!isChange)
        {
            isChange = true;
        }
    }
Exemple #20
0
 public void ResetGame()
 {
     player = GameObject.FindGameObjectWithTag("Check").GetComponent<Jump>();
     player.Die ();
 }
Exemple #21
0
 public void UploadJumpAsync(Jump myTest, object userState)
 {
     if ((this.UploadJumpOperationCompleted == null)) {
         this.UploadJumpOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUploadJumpCompleted);
     }
     this.InvokeAsync("UploadJump", new object[] {
                 myTest}, this.UploadJumpOperationCompleted, userState);
 }
Exemple #22
0
 public int UploadJump(Jump myTest)
 {
     object[] results = this.Invoke("UploadJump", new object[] {
                 myTest});
     return ((int)(results[0]));
 }
Exemple #23
0
        private void Update(EvaluationContext context)
        {
            var startPosition = Position.GetValue(context);
            var limitRange    = MaxRange.GetValue(context);
            var seed          = Seed.GetValue(context);
            var jumpDistance  = JumpDistance.GetValue(context);

            _rate = Rate.GetValue(context);

            var reset = Reset.GetValue(context);
            var jump  = Jump.GetValue(context);

            if (!_initialized || reset || float.IsNaN(_offset.X) || float.IsNaN(_offset.Y) || seed != _seed)
            {
                _random      = new Random(seed);
                _seed        = seed;
                _offset      = Vector2.Zero;
                _initialized = true;
                jump         = true;
            }

            _beatTime = context.Playback.FxTimeInBars;

            if (UseRate)
            {
                var activationIndex = (int)(_beatTime * _rate);
                if (activationIndex != _lastActivationIndex)
                {
                    _lastActivationIndex = activationIndex;
                    jump = true;
                }
            }

            if (jump)
            {
                _jumpStartOffset  = _offset;
                _jumpTargetOffset = _offset + new Vector2(
                    (float)((_random.NextDouble() - 0.5f) * jumpDistance * 2f),
                    (float)((_random.NextDouble() - 0.5f) * jumpDistance * 2f));

                if (limitRange > 0.001f)
                {
                    var d = _jumpTargetOffset.Length();
                    if (d > limitRange)
                    {
                        var overshot            = Math.Min(d - limitRange, limitRange);
                        var random              = _random.NextDouble() * overshot;
                        var distanceWithinLimit = limitRange - (float)random;
                        var normalized          = _jumpTargetOffset / d;
                        _jumpTargetOffset = normalized * distanceWithinLimit;
                    }
                }

                _lastJumpTime = _beatTime;
            }

            var blending = Blending.GetValue(context);

            if (blending >= 0.001)
            {
                var t = (Fragment / blending).Clamp(0, 1);
                if (SmoothBlending.GetValue(context))
                {
                    t = MathUtils.SmootherStep(0, 1, t);
                }

                _offset = Vector2.Lerp(_jumpStartOffset, _jumpTargetOffset, t);
            }
            else
            {
                _offset = _jumpTargetOffset;
            }

            NewPosition.Value = _offset + startPosition;
        }
Exemple #24
0
 // Use this for initialization
 void Start()
 {
     catJump = Cat.GetComponent<Jump> ();
 }
    private void on_jump_finished(object o, EventArgs args)
    {
        currentEventExecute.FakeButtonFinished.Clicked -= new EventHandler(on_jump_finished);

        if ( ! currentEventExecute.Cancel ) {
            currentJump = (Jump) currentEventExecute.EventDone;

            //move video file if exists
            Util.MoveTempVideo(currentSession.UniqueID, Constants.TestTypes.JUMP, currentJump.UniqueID);

            if(weightPercentPreferred)
                myTreeViewJumps.Add(currentPerson.Name, currentJump);
            else {
                Jump myJump = new Jump();
                myJump = currentJump;
                myJump.Weight = Util.WeightFromPercentToKg(currentJump.Weight, currentPersonSession.Weight);
                myTreeViewJumps.Add(currentPerson.Name, myJump);
            }

            //since 0.7.4.1 when test is done, treeview select it. action event button have to be shown
            showHideActionEventButtons(true, "Jump"); //show

            if(createdStatsWin) {
                showUpdateStatsAndHideData(true);
            }

            //unhide buttons for delete last jump
            sensitiveGuiYesEvent();
        }
        else if( currentEventExecute.ChronopicDisconnected ) {
            Log.WriteLine("DISCONNECTED gui/cj");
            createChronopicWindow(true);
        }

        lastJumpIsSimple = true;

        //unhide buttons that allow jumping
        sensitiveGuiEventDone();
    }
    // Use this for initialization
    void Start()
    {
        Cursor.visible = false;
        values = GameObject.FindGameObjectWithTag("Values");
        stored = values.GetComponent<StoredValues>();
        hud = gameObject.GetComponent<HUD>();
        run = GetComponent<Run>();
        squat = GetComponent<Squat>();
        jump = GetComponent<Jump>();
        screen = GameObject.FindGameObjectWithTag("ScreenOverlay");
        overlay = screen.GetComponent<ScreenOverlay>();
        finish = GameObject.FindGameObjectWithTag("Finish");

        rightBoundry = 0.4f;
        leftBoundry = -0.4f;
        moveSideways = 7.5f;

        moveForward = 0.0f;
        moveSpeed = 0.125f;
        combinedSpeed = 0.0f;

        // vertical normal vector for hip angle
        hipUp = new Vector3(0.0f, 1.0f, 0.0f);

        keepRunning = false;
        begin = false;
    }
    private void JumpInput()
    {
        float jumpFloat = Input.GetAxisRaw("Jump");

        Jump?.Invoke(jumpFloat);
    }
Exemple #28
0
 public void Jump(MovementState behaviorOnLanding, float jumpingSpeed, float gravity, float horizontalAirSpeed,
                  JumpingDirection direction)
 {
     this.jump = new Jump(behaviorOnLanding, jumpingSpeed, gravity, horizontalAirSpeed, direction);
 }
Exemple #29
0
    public override bool acceptMessageData(BinaryReader messageDataReader)
    {
        bool handled = true;

        PacketOpcode opcode = Util.readOpcode(messageDataReader);

        switch (opcode)
        {
        case PacketOpcode.Evt_Movement__PositionAndMovement:
        {
            PositionAndMovement message = PositionAndMovement.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__Jump_ID: {
            Jump message = Jump.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__MoveToState_ID: {
            MoveToState message = MoveToState.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__DoMovementCommand_ID: {
            DoMovementCommand message = DoMovementCommand.read(messageDataReader);
            break;
        }

        // TODO: PacketOpcode.Evt_Movement__TurnEvent_ID
        // TODO: PacketOpcode.Evt_Movement__TurnToEvent_ID
        case PacketOpcode.Evt_Movement__StopMovementCommand_ID: {
            StopMovementCommand message = StopMovementCommand.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__UpdatePosition_ID: {
            UpdatePosition message = UpdatePosition.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__MovementEvent_ID: {
            MovementEvent message = MovementEvent.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__AutonomyLevel_ID: {
            AutonomyLevel message = AutonomyLevel.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__AutonomousPosition_ID: {
            AutonomousPosition message = AutonomousPosition.read(messageDataReader);
            break;
        }

        case PacketOpcode.Evt_Movement__Jump_NonAutonomous_ID: {
            Jump_NonAutonomous message = Jump_NonAutonomous.read(messageDataReader);
            break;
        }

        default: {
            handled = false;
            break;
        }
        }

        return(handled);
    }
Exemple #30
0
        private void toString(ObjToIntMap printIds, System.Text.StringBuilder sb)
        {
            if (Token.printTrees)
            {
                sb.Append(Token.name(this.Type));
                if (this is StringNode)
                {
                    sb.Append(' ');
                    sb.Append(String);
                }
                else if (this is ScriptOrFnNode)
                {
                    ScriptOrFnNode sof = (ScriptOrFnNode)this;
                    if (this is FunctionNode)
                    {
                        FunctionNode fn = (FunctionNode)this;
                        sb.Append(' ');
                        sb.Append(fn.FunctionName);
                    }
                    sb.Append(" [source name: ");
                    sb.Append(sof.SourceName);
                    sb.Append("] [encoded source length: ");
                    sb.Append(sof.EncodedSourceEnd - sof.EncodedSourceStart);
                    sb.Append("] [base line: ");
                    sb.Append(sof.BaseLineno);
                    sb.Append("] [end line: ");
                    sb.Append(sof.EndLineno);
                    sb.Append(']');
                }
                else if (this is Jump)
                {
                    Jump jump = (Jump)this;
                    if (this.Type == Token.BREAK || this.Type == Token.CONTINUE)
                    {
                        sb.Append(" [label: ");
                        appendPrintId(jump.JumpStatement, printIds, sb);
                        sb.Append(']');
                    }
                    else if (this.Type == Token.TRY)
                    {
                        Node catchNode     = jump.target;
                        Node finallyTarget = jump.Finally;
                        if (catchNode != null)
                        {
                            sb.Append(" [catch: ");
                            appendPrintId(catchNode, printIds, sb);
                            sb.Append(']');
                        }
                        if (finallyTarget != null)
                        {
                            sb.Append(" [finally: ");
                            appendPrintId(finallyTarget, printIds, sb);
                            sb.Append(']');
                        }
                    }
                    else if (this.Type == Token.LABEL || this.Type == Token.LOOP || this.Type == Token.SWITCH)
                    {
                        sb.Append(" [break: ");
                        appendPrintId(jump.target, printIds, sb);
                        sb.Append(']');
                        if (this.Type == Token.LOOP)
                        {
                            sb.Append(" [continue: ");
                            appendPrintId(jump.Continue, printIds, sb);
                            sb.Append(']');
                        }
                    }
                    else
                    {
                        sb.Append(" [target: ");
                        appendPrintId(jump.target, printIds, sb);
                        sb.Append(']');
                    }
                }
                else if (this.Type == Token.NUMBER)
                {
                    sb.Append(' ');
                    sb.Append(Double);
                }
                else if (this.Type == Token.TARGET)
                {
                    sb.Append(' ');
                    appendPrintId(this, printIds, sb);
                }
                if (lineno != -1)
                {
                    sb.Append(' ');
                    sb.Append(lineno);
                }

                for (PropListItem x = propListHead; x != null; x = x.next)
                {
                    int Type = x.Type;
                    sb.Append(" [");
                    sb.Append(propToString(Type));
                    sb.Append(": ");
                    string value;
                    switch (Type)
                    {
                    case TARGETBLOCK_PROP:      // can't add this as it recurses
                        value = "target block property";
                        break;

                    case LOCAL_BLOCK_PROP:      // can't add this as it is dull
                        value = "last local block";
                        break;

                    case ISNUMBER_PROP:
                        switch (x.intValue)
                        {
                        case BOTH:
                            value = "both";
                            break;

                        case RIGHT:
                            value = "right";
                            break;

                        case LEFT:
                            value = "left";
                            break;

                        default:
                            throw Context.CodeBug();
                        }
                        break;

                    case SPECIALCALL_PROP:
                        switch (x.intValue)
                        {
                        case SPECIALCALL_EVAL:
                            value = "eval";
                            break;

                        case SPECIALCALL_WITH:
                            value = "with";
                            break;

                        default:
                            // NON_SPECIALCALL should not be stored
                            throw Context.CodeBug();
                        }
                        break;

                    default:
                        object obj = x.objectValue;
                        if (obj != null)
                        {
                            value = obj.ToString();
                        }
                        else
                        {
                            value = Convert.ToString(x.intValue);
                        }
                        break;
                    }
                    sb.Append(value);
                    sb.Append(']');
                }
            }
        }
Exemple #31
0
    public static double[] sample_candidate(int chain_index, int chain_num, double[] cr,
                                            int cr_index, int cr_num, int gen_index, int gen_num,
                                            double[] jumprate_table, int jumpstep, double[] limits, int pair_num,
                                            int par_num, double[] z)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SAMPLE_CANDIDATE generates candidate parameter samples.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 May 2013
    //
    //  Author:
    //
    //    Original FORTRAN90 version by Guannan Zhang.
    //    C++ version by John Burkardt.
    //
    //  Reference:
    //
    //    Jasper Vrugt, CJF ter Braak, CGH Diks, Bruce Robinson, James Hyman,
    //    Dave Higdon,
    //    Accelerating Markov Chain Monte Carlo Simulation by Differential
    //    Evolution with Self-Adaptive Randomized Subspace Sampling,
    //    International Journal of Nonlinear Sciences and Numerical Simulation,
    //    Volume 10, Number 3, March 2009, pages 271-288.
    //
    //  Parameters:
    //
    //    Input, int CHAIN_INDEX, the chain index.
    //    0 <= CHAIN_INDEX < CHAIN_NUM.
    //
    //    Input, int CHAIN_NUM, the total number of chains.
    //    3 <= CHAIN_NUM.
    //
    //    Input, double CR[CR_NUM], the CR values.
    //
    //    Input, int CR_INDEX, the index of the chosen CR value.
    //    0 <= CR_INDEX < CR_NUM.
    //
    //    Input, int CR_NUM, the total number of CR values.
    //    1 <= CR_NUM.
    //
    //    Input, int GEN_INDEX, the current generation.
    //    0 <= GEN_INDEX < GEN_NUM.
    //
    //    Input, int GEN_NUM, the total number of generations.
    //    2 <= GEN_NUM.
    //
    //    Input, double JUMPRATE_TABLE[PAR_NUM], the jumprate table.
    //
    //    Input, int JUMPSTEP, forces a "long jump" every
    //    JUMPSTEP generations.
    //
    //    Input, double LIMITS[2*PAR_NUM], limits for the parameters.
    //
    //    Input, int PAIR_NUM, the number of pairs of
    //    crossover chains.
    //    0 <= PAIR_NUM.
    //
    //    Input, int PAR_NUM, the total number of parameters.
    //    1 <= PAR_NUM.
    //
    //    Input, double Z[PAR_NUM*CHAIN_NUM*GEN_NUM], the Markov chain
    //    sample data.
    //
    //    Output, double SAMPLE_CANDIDATE[PAR_NUM], a candidate parameter sample.
    //
    //  Local parameters:
    //
    //    Input, int JUMP_DIM[JUMP_NUM], the dimensions in which
    //    a jump is to be made.
    //
    //    Local, int JUMP_NUM, the number of dimensions in which
    //    a jump will be made.  0 <= JUMP_NUM <= PAR_NUM.
    //
    //    Local, double JUMPRATE, the jump rate.
    //
    {
        int    i;
        int    jump_num = 0;
        double jumprate = 0;

        int[] pair = new int[2];
        //
        //  Used to calculate E following a uniform distribution on (-B,+B).
        //  Because B is currently zero, the noise term is suppressed.
        //
        const double b = 0.0;

        //
        //  Pick pairs of other chains for crossover.
        //
        int[] r = new int[2 * pair_num];

        for (i = 0; i < pair_num; i++)
        {
            while (true)
            {
                double r2 = PDF.r8_uniform_01_sample();
                pair[0] = (int)(r2 * chain_num);
                r2      = PDF.r8_uniform_01_sample();
                pair[1] = (int)(r2 * chain_num);

                if (pair[0] != pair[1] &&
                    pair[0] != chain_index &&
                    pair[1] != chain_index)
                {
                    break;
                }
            }

            r[0 + i * 2] = pair[0];
            r[1 + i * 2] = pair[1];
        }

        //
        //  Determine the jump rate.
        //
        int[] jump_dim = new int[par_num];

        Jump.jumprate_choose(cr, cr_index, cr_num, gen_index, jump_dim, ref jump_num,
                             ref jumprate, jumprate_table, jumpstep, par_num);
        //
        //  Calculate E in equation 4 of Vrugt.
        //
        double[] noise_e = new double[par_num];

        for (i = 0; i < par_num; i++)
        {
            noise_e[i] = b * (2.0 * PDF.r8_uniform_01_sample() - 1.0);
        }

        //
        //  Get epsilon value from multinormal distribution
        //
        double[] eps = new double[par_num];

        const double av = 0.0;
        const double sd = 1.0E-10;

        for (i = 0; i < par_num; i++)
        {
            eps[i] = PDF.r8_normal_sample(av, sd);
        }

        //
        //  Generate the candidate sample ZP based on equation 4 of Vrugt.
        //
        double[] diff = Diff.diff_compute(chain_num, gen_index, gen_num, jump_dim, jump_num,
                                          pair_num, par_num, r, z);

        double[] zp = new double[par_num];

        for (i = 0; i < par_num; i++)
        {
            zp[i] = z[i + chain_index * par_num + (gen_index - 1) * par_num * chain_num];
        }

        for (i = 0; i < par_num; i++)
        {
            zp[i] = zp[i] + (1.0 + noise_e[i]) * jumprate * diff[i] + eps[i];
        }

        //
        //  Enforce limits on the sample ZP.
        //
        sample_limits(limits, par_num, ref zp);
        return(zp);
    }
Exemple #32
0
        public void Convert(Function function, ILuaFunction luaFunc)
        {
            _symbolTable = function.SymbolTable;
            var luaFunction = (HavokLuaFunction)luaFunc;

            FunctionDebugInfo debugFunc = null;

            if (luaFunction.LuaFile is HavokLuaFileT7 ht7 && ht7.DebugFile != null)
            {
                var debugInfo = ht7.DebugFile.DebugInfo;
                debugFunc = debugInfo.Find(d => d.Id == function.Id);
                function.FunctionDebugInfo = debugFunc;
                function.ArgumentNames     = debugFunc.VariableNames.Where(v => v.Start == 0).Select(l => new Local()
                {
                    Name = l.Name, End = l.End, Start = l.Start
                }).ToList();
            }

            // Loop over all instructions
            for (int pos = 0; pos < luaFunction.Instructions.Count; pos++)
            {
                var i = (HavokInstruction)luaFunction.Instructions[pos];

                List <IInstruction> instrs = new List <IInstruction>();
                switch (i.HavokOpCode)
                {
                case LuaHavokOpCode.HKS_OPCODE_MOVE:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   RegisterReference(i.B)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LOADK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   ConvertLuaConstant(luaFunction.Constants[(int)i.Bx], (int)i.Bx)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LOADBOOL:
                    var assn = new Assignment(_symbolTable.GetRegister(i.A), new Constant(i.B == 1, -1));
                    instrs.Add(assn);
                    if (i.C > 0)
                    {
                        instrs.Add(new Jump(function.GetLabel((uint)(pos + 2))));
                    }
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LOADNIL:
                    var nlist = new List <IdentifierReference>();
                    for (int arg = (int)i.A; arg <= i.B; arg++)
                    {
                        nlist.Add(new IdentifierReference(_symbolTable.GetRegister((uint)arg)));
                    }
                    assn = new Assignment(nlist, new Constant(ValueType.Nil, -1));
                    instrs.Add(assn);
                    break;

                case LuaHavokOpCode.HKS_OPCODE_GETUPVAL:
                    Identifier up = function.UpvalueBindings[(int)i.B];
                    up.IsClosureBound = true;
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new IdentifierReference(up)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SETUPVAL:
                case LuaHavokOpCode.HKS_OPCODE_SETUPVAL_R1:
                    up = _symbolTable.GetUpValue(i.B, function.UpvalueBindings[(int)i.B].Name);
                    if (luaFunction.Upvalues.Any() && !up.UpValueResolved)
                    {
                        up.Name            = luaFunction.Upvalues[(int)i.B].Name;
                        up.UpValueResolved = true;
                    }
                    instrs.Add(new Assignment(up, new IdentifierReference(_symbolTable.GetRegister(i.A))));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_GETGLOBAL_MEM:
                case LuaHavokOpCode.HKS_OPCODE_GETGLOBAL:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new IdentifierReference(_symbolTable.GetGlobal(luaFunction.Constants[(int)i.Bx].ToString(), (int)i.Bx))
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SETGLOBAL:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetGlobal(luaFunction.Constants[(int)i.Bx].ToString(), (int)i.Bx),
                                   new IdentifierReference(_symbolTable.GetRegister(i.A))));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_GETTABLE_S:
                case LuaHavokOpCode.HKS_OPCODE_GETTABLE:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new IdentifierReference(_symbolTable.GetRegister(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit))
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_NEWTABLE:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new InitializerList()
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SELF:
                    var op = new Assignment(_symbolTable.GetRegister(i.A + 1), new IdentifierReference(_symbolTable.GetRegister(i.B)));
                    op.IsSelfAssignment = true;
                    instrs.Add(op);
                    op = new Assignment(_symbolTable.GetRegister(i.A), new IdentifierReference(_symbolTable.GetRegister(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit)));
                    op.IsSelfAssignment = true;
                    instrs.Add(op);
                    break;

                case LuaHavokOpCode.HKS_OPCODE_ADD:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpAdd)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_ADD_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpAdd)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SUB:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpSub)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SUB_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpSub)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_MUL:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpMul)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_MUL_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpMul)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_DIV:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpDiv)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_DIV_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpDiv)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_MOD:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpMod)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_MOD_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpMod)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_POW:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpPow)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_POW_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpPow)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_UNM:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new UnaryOp(new IdentifierReference(_symbolTable.GetRegister(i.B)), UnOperationType.OpNegate)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_NOT:
                case LuaHavokOpCode.HKS_OPCODE_NOT_R1:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new UnaryOp(new IdentifierReference(_symbolTable.GetRegister(i.B)), UnOperationType.OpNot)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LEN:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new UnaryOp(new IdentifierReference(_symbolTable.GetRegister(i.B)), UnOperationType.OpLength)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SHIFT_LEFT:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpShiftLeft)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SHIFT_LEFT_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpShiftLeft)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SHIFT_RIGHT:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpShiftRight)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SHIFT_RIGHT_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpShiftRight)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_BITWISE_AND:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpBAnd)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_BITWISE_AND_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpBAnd)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_BITWISE_OR:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), BinOperationType.OpBOr)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_BITWISE_OR_BK:
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), BinOperationType.OpBOr)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_CONCAT:
                    var args = new List <IExpression>();
                    for (int arg = (int)i.B; arg <= i.C; arg++)
                    {
                        args.Add(new IdentifierReference(_symbolTable.GetRegister((uint)arg)));
                    }
                    instrs.Add(new Assignment(
                                   _symbolTable.GetRegister(i.A),
                                   new Concat(args)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_JMP:
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 1 + i.SBx))));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_EQ:
                    var operation = BinOperationType.OpEqual;
                    if (i.A == 1)
                    {
                        operation = BinOperationType.OpNotEqual;
                    }
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 2)), new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), operation)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_EQ_BK:
                    operation = BinOperationType.OpEqual;
                    if (i.A == 1)
                    {
                        operation = BinOperationType.OpNotEqual;
                    }
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 2)), new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), operation)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LT:
                    operation = BinOperationType.OpLessThan;
                    if (i.A == 1)
                    {
                        operation = BinOperationType.OpGreaterEqual;
                    }
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 2)), new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), operation)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LT_BK:
                    operation = BinOperationType.OpLessThan;
                    if (i.A == 1)
                    {
                        operation = BinOperationType.OpGreaterEqual;
                    }
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 2)), new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), operation)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LE:
                    operation = BinOperationType.OpLessEqual;
                    if (i.A == 1)
                    {
                        operation = BinOperationType.OpGreaterThan;
                    }
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 2)), new BinOp(RegisterReference(i.B), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit), operation)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_LE_BK:
                    operation = BinOperationType.OpLessEqual;
                    if (i.A == 1)
                    {
                        operation = BinOperationType.OpGreaterThan;
                    }
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 2)), new BinOp(ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B), RegisterReference(i.C), operation)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_TEST:
                case LuaHavokOpCode.HKS_OPCODE_TEST_R1:
                    instrs.Add(i.C == 0
                            ? new Jump(function.GetLabel((uint)(pos + 2)), RegisterReference(i.A))
                            : new Jump(function.GetLabel((uint)(pos + 2)),
                                       new UnaryOp(RegisterReference(i.A), UnOperationType.OpNot)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_TESTSET:
                    instrs.Add(i.C == 0
                            ? new Jump(function.GetLabel((uint)(pos + 2)), RKIR(luaFunction, i.B))
                    {
                        TestsetType = BinOperationType.OpAnd, TestsetLocation = _symbolTable.GetRegister(i.A)
                    }
                            : new Jump(function.GetLabel((uint)(pos + 2)), RKIR(luaFunction, i.B))
                    {
                        TestsetType = BinOperationType.OpOr, TestsetLocation = _symbolTable.GetRegister(i.A)
                    });
                    instrs.Add(new Assignment(_symbolTable.GetRegister(i.A), new IdentifierReference(_symbolTable.GetRegister(i.B))));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SETTABLE:
                case LuaHavokOpCode.HKS_OPCODE_SETTABLE_S:
                    instrs.Add(new Assignment(
                                   new IdentifierReference(_symbolTable.GetRegister(i.A), RegisterReference(i.B)),
                                   GetConstantBitFix(luaFunction, i.C, i.ExtraCBit)
                                   ));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_TAILCALL:
                case LuaHavokOpCode.HKS_OPCODE_TAILCALL_I:
                case LuaHavokOpCode.HKS_OPCODE_TAILCALL_I_R1:
                    args = new List <IExpression>();
                    for (int arg = (int)i.A + 1; arg < i.A + i.B; arg++)
                    {
                        args.Add(new IdentifierReference(_symbolTable.GetRegister((uint)arg)));
                    }
                    var funCall = new FunctionCall(new IdentifierReference(_symbolTable.GetRegister(i.A)), args);
                    funCall.IsIndeterminateArgumentCount = (i.B == 0);
                    funCall.BeginArg = i.A + 1;
                    instrs.Add(new Return(funCall)
                    {
                        IsTailReturn = true
                    });
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SETTABLE_S_BK:
                    instrs.Add(new Assignment(
                                   new IdentifierReference(_symbolTable.GetRegister(i.A), ConvertLuaConstant(luaFunction.Constants[(int)i.B], (int)i.B)),
                                   GetConstantBitFix(luaFunction, i.C, i.ExtraCBit)));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_CALL_I:
                case LuaHavokOpCode.HKS_OPCODE_CALL_I_R1:
                case LuaHavokOpCode.HKS_OPCODE_CALL:
                    args = new List <IExpression>();
                    var rets = new List <IdentifierReference>();
                    for (int arg = (int)i.A + 1; arg < i.A + i.B; arg++)
                    {
                        args.Add(new IdentifierReference(_symbolTable.GetRegister((uint)arg)));
                    }
                    for (int r = (int)i.A + 1; r < i.A + i.C; r++)
                    {
                        rets.Add(new IdentifierReference(_symbolTable.GetRegister((uint)r - 1)));
                    }
                    if (i.C == 0)
                    {
                        rets.Add(new IdentifierReference(_symbolTable.GetRegister(i.A)));
                    }
                    funCall = new FunctionCall(new IdentifierReference(_symbolTable.GetRegister(i.A)), args);
                    funCall.IsIndeterminateArgumentCount = (i.B == 0);
                    funCall.IsIndeterminateReturnCount   = (i.C == 0);
                    funCall.BeginArg = i.A + 1;
                    assn             = new Assignment(rets, funCall);
                    instrs.Add(assn);
                    break;

                case LuaHavokOpCode.HKS_OPCODE_RETURN:
                    args = new List <IExpression>();
                    if (i.B != 0)
                    {
                        for (int arg = (int)i.A; arg < i.A + i.B - 1; arg++)
                        {
                            args.Add(new IdentifierReference(_symbolTable.GetRegister((uint)arg)));
                        }
                    }
                    var ret = new Return(args);
                    if (i.B == 0)
                    {
                        ret.BeginRet = i.A;
                        ret.IsIndeterminateReturnCount = true;
                    }
                    instrs.Add(ret);
                    break;

                case LuaHavokOpCode.HKS_OPCODE_FORLOOP:
                    instrs.Add(new Assignment(new IdentifierReference(_symbolTable.GetRegister(i.A)), new BinOp(new IdentifierReference(_symbolTable.GetRegister(i.A)),
                                                                                                                new IdentifierReference(_symbolTable.GetRegister(i.A + 2)), BinOperationType.OpAdd)));
                    var jmp = new Jump(function.GetLabel((uint)(pos + 1 + i.SBx)), new BinOp(new IdentifierReference(_symbolTable.GetRegister(i.A)),
                                                                                             new IdentifierReference(_symbolTable.GetRegister(i.A + 1)), BinOperationType.OpLoopCompare));
                    var pta = new Assignment(_symbolTable.GetRegister(i.A + 3), RegisterReference(i.A));
                    pta.PropagateAlways     = true;
                    jmp.PostTakenAssignment = pta;

                    if (debugFunc != null)
                    {
                        var indexVariable = debugFunc.VariableNames.Where(v => v.Start == pos + 1 + i.SBx).ToList();
                        if (indexVariable.Count == 1)
                        {
                            var forIndexIdentifier = _symbolTable.GetRegister(i.A);
                            for (int j = pos + i.SBx; j >= 0; j--)
                            {
                                var opCodeInstrs = function.Instructions.Where(ins => ins.OpLocation == j).ToList();
                                if (opCodeInstrs.Count == 1 && opCodeInstrs[0] is Assignment a && a.Left.Count == 1 && a.Left[0].Identifier == forIndexIdentifier)
                                {
                                    a.LocalAssignments = indexVariable;
                                    break;
                                }
                            }
                            var forStepIdentifier = _symbolTable.GetRegister(i.A + 2);
                            for (int j = pos + i.SBx; j >= 0; j--)
                            {
                                var opCodeInstrs = function.Instructions.Where(ins => ins.OpLocation == j).ToList();
                                if (opCodeInstrs.Count == 1 && opCodeInstrs[0] is Assignment a && a.Left.Count == 1 && a.Left[0].Identifier == forStepIdentifier && a.LocalAssignments.Count == 3)
                                {
                                    var forLimitIdentifier = _symbolTable.GetRegister(i.A + 1);
                                    for (int k = pos + i.SBx; k >= 0; k--)
                                    {
                                        var opLimitCodeInstrs = function.Instructions.Where(ins => ins.OpLocation == k).ToList();
                                        if (opLimitCodeInstrs.Count == 1 && opLimitCodeInstrs[0] is Assignment a2 && a2.Left.Count == 1 && a2.Left[0].Identifier == forLimitIdentifier)
                                        {
                                            a2.LocalAssignments = new List <Local>()
                                            {
                                                a.LocalAssignments[1]
                                            };
                                            break;
                                        }
                                    }
                                    a.LocalAssignments = new List <Local>()
                                    {
                                        a.LocalAssignments[2]
                                    };
                                    break;
                                }
                            }
                        }
                    }


                    instrs.Add(jmp);
                    break;

                case LuaHavokOpCode.HKS_OPCODE_TFORLOOP:
                    args = new List <IExpression>();
                    rets = new List <IdentifierReference>();
                    args.Add(new IdentifierReference(_symbolTable.GetRegister(i.A + 1)));
                    args.Add(new IdentifierReference(_symbolTable.GetRegister(i.A + 2)));
                    if (i.C == 0)
                    {
                        rets.Add(new IdentifierReference(_symbolTable.GetRegister(i.A + 3)));
                    }
                    else
                    {
                        for (int r = (int)i.A + 3; r <= i.A + i.C + 2; r++)
                        {
                            rets.Add(new IdentifierReference(_symbolTable.GetRegister((uint)r)));
                        }
                    }
                    var fCall = new FunctionCall(new IdentifierReference(_symbolTable.GetRegister(i.A)), args);
                    fCall.IsIndeterminateReturnCount = (i.C == 0);
                    assn = new Assignment(rets, fCall);

                    if (debugFunc != null)
                    {
                        var nextOp = ((HavokInstruction)luaFunction.Instructions[pos + 1]);
                        if (nextOp.HavokOpCode == LuaHavokOpCode.HKS_OPCODE_JMP)
                        {
                            assn.LocalAssignments = debugFunc.VariableNames
                                                    .Where(v => v.Start == pos + nextOp.SBx + 2).ToList();
                        }
                    }

                    instrs.Add(assn);
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 2)), new BinOp(RegisterReference(i.A + 3), new Constant(ValueType.Nil, -1), BinOperationType.OpEqual)));
                    instrs.Add(new Assignment(_symbolTable.GetRegister(i.A + 2), new IdentifierReference(_symbolTable.GetRegister(i.A + 3))));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_FORPREP:
                    // The VM technically does a subtract, but we don't actually emit it since it simplifies things to map better to the high level Lua
                    //instructions.Add(new IR.Assignment(new IR.IdentifierReference(SymbolTable.GetRegister(a)), new IR.BinOp(new IR.IdentifierReference(SymbolTable.GetRegister(a)),
                    //    new IR.IdentifierReference(SymbolTable.GetRegister(a + 2)), IR.BinOp.OperationType.OpSub)));
                    instrs.Add(new Jump(function.GetLabel((uint)(pos + 1 + i.SBx))));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SETLIST:
                    if (i.B == 0)
                    {
                        if (i.C == 1)
                        {
                            assn = new Assignment(_symbolTable.GetRegister(i.A), RegisterReference(i.A + 1))
                            {
                                VarargAssignmentReg = i.A, IsIndeterminateVararg = true
                            };
                            instrs.Add(assn);
                        }
                    }
                    else
                    {
                        for (int j = 1; j <= i.B; j++)
                        {
                            assn = new Assignment(new IdentifierReference(_symbolTable.GetRegister(i.A), new Constant((double)(i.C - 1) * 32 + j, -1)),
                                                  new IdentifierReference(_symbolTable.GetRegister(i.A + (uint)j)));
                            instrs.Add(assn);
                        }
                    }
                    break;

                case LuaHavokOpCode.HKS_OPCODE_CLOSURE:
                    instrs.Add(new Assignment(_symbolTable.GetRegister(i.A), new Closure(function.Closures[(int)i.Bx])));
                    break;

                case LuaHavokOpCode.HKS_OPCODE_GETFIELD:
                case LuaHavokOpCode.HKS_OPCODE_GETFIELD_R1:
                    assn = new Assignment(RegisterReference(i.A), new IdentifierReference(_symbolTable.GetRegister(i.B), new Constant(luaFunction.Constants[(int)i.C].ToString(), -1)));
                    instrs.Add(assn);
                    break;

                case LuaHavokOpCode.HKS_OPCODE_DATA:
                    if (i.A != 0)
                    {
                        Function closureFunc = null;
                        int      index       = pos;

                        while (index >= 0)
                        {
                            var instru = (HavokInstruction)luaFunction.Instructions[index];
                            if (instru.HavokOpCode == LuaHavokOpCode.HKS_OPCODE_CLOSURE)
                            {
                                closureFunc = function.Closures[(int)instru.Bx];
                                break;
                            }
                            index--;
                        }

                        if (closureFunc == null)
                        {
                            continue;
                        }

                        if (debugFunc != null && function.Instructions.Any() && function.Instructions.Last() is Assignment a && a.Right is Closure)
                        {
                            if (a.LocalAssignments == null)
                            {
                                a.LocalAssignments = new List <Local>();
                            }
                            a.LocalAssignments.AddRange(debugFunc.VariableNames.Where(v => v.Start == pos + 1).ToList());
                        }

                        if (i.A == 1)
                        {
                            closureFunc.UpvalueBindings.Add(_symbolTable.GetRegister(i.C));
                        }
                        else if (i.A == 2)
                        {
                            closureFunc.UpvalueBindings.Add(function.UpvalueBindings[(int)i.C]);
                        }
                    }
                    else
                    {
                        var dat = new Data(i);
                        if (debugFunc != null)
                        {
                            dat.Locals = debugFunc.VariableNames.Where(v => v.Start == pos + 1).ToList();
                        }
                        instrs.Add(dat);
                    }
                    break;

                case LuaHavokOpCode.HKS_OPCODE_SETFIELD:
                case LuaHavokOpCode.HKS_OPCODE_SETFIELD_R1:
                    assn = new Assignment(new IdentifierReference(_symbolTable.GetRegister(i.A), new Constant(luaFunction.Constants[(int)i.B].ToString(), (int)i.B)), GetConstantBitFix(luaFunction, i.C, i.ExtraCBit));
                    instrs.Add(assn);
                    break;

                case LuaHavokOpCode.HKS_OPCODE_VARARG:
                    var varArgs = new List <IdentifierReference>();
                    for (int arg = (int)i.A; arg <= i.A + i.B - 1; arg++)
                    {
                        varArgs.Add(new IdentifierReference(_symbolTable.GetRegister((uint)arg)));
                    }
                    if (i.B != 0)
                    {
                        assn = new Assignment(varArgs, new IdentifierReference(_symbolTable.GetVarargs()));
                    }
                    else
                    {
                        assn = new Assignment(_symbolTable.GetRegister(i.A), new IdentifierReference(_symbolTable.GetVarargs()));
                        assn.IsIndeterminateVararg = true;
                        assn.VarargAssignmentReg   = i.A;
                    }
                    instrs.Add(assn);
                    function.IsVarArgs = true;
                    break;

                case LuaHavokOpCode.HKS_OPCODE_CLOSE:
                    // LUA source : close all variables in the stack up to (>=) R(A)
                    // Let's ignore this for now, doesn't print anything and don't know if it affects SSA
                    instrs.Add(new Close());
                    break;

                default:
                    Console.WriteLine($@"Missing op: {i.HavokOpCode} {i.A} {i.B} {i.C}");
                    instrs.Add(new PlaceholderInstruction($@"{i.HavokOpCode} {i.A} {i.B} {i.C}"));
                    break;
                }

                foreach (var instr in instrs)
                {
                    if (debugFunc != null)
                    {
                        if (instr is Assignment a && a.LocalAssignments == null)
                        {
                            a.LocalAssignments = debugFunc.VariableNames.Where(v => v.Start == pos + 1).ToList();
                        }
                        if (debugFunc.InstructionLocations.Count >= pos)
                        {
                            instr.LineLocation = debugFunc.InstructionLocations[pos];
                        }
                    }

                    instr.OpLocation = pos;
                    function.Instructions.Add(instr);
                }
            }
        }
    /// <summary>
    /// Moves the character controller in local space
    /// </summary>
    /// <param name="a_fDeltaTime"></param>
    private void Move(float a_fDeltaTime)
    {
        // Get axes w/ weights
        m_v3Motion = new Vector3(m_AxisMoveX.AxisValue, 0, m_AxisMoveZ.AxisValue);
        // Ignore them if we are manipulating an object
        if (m_bPhysManipulation)
        {
            m_v3Motion = Vector3.zero;
        }

        // Normalise the vector if it is > 1
        if (m_v3Motion.sqrMagnitude > 1)
        {
            m_v3Motion.Normalize();
        }

        // Scale by speed - Component wise, post input scaling
        // Forwards
        m_v3Motion.z *= m_fCurrentSpeed;
        // Backwards
        if (m_v3Motion.z < 0)
        {
            m_v3Motion.z *= m_fReverseRatio;
        }
        // Strafe
        m_v3Motion.x *= m_fCurrentSpeed * m_fStrafeRatio;

        // Transform the vector into relative motion
        m_v3Motion = transform.TransformDirection(m_v3Motion);
        // Reduce input by ratio if airborne
        if (m_eJump != Jump.Grounded)
        {
            m_v3Motion *= m_fAirborneRatio;
        }

        // If jump pressed and jump hitbox is clear, jump.
        if ((m_BtnJump.CurrentState == ControllerButtonState.Down) && (m_eJump == Jump.Grounded) && m_canJump)
        {
            // Head butt things
            if (m_HeightJump.Colliding)
            {
                m_HeightJump.ForceOut(ForceMode.Impulse);
            }
            else // Jump with conditions
            {
                // Set jump speed if on a slope less that slope limit
                t_Vector3 = m_Anchor.transform.position - (transform.position + Vector3.up * (m_CharacterController.radius - m_CharacterController.skinWidth));

                // If collision tangent is < slope, we can jump
                m_fAnchorDot = Vector3.Dot(t_Vector3.normalized, -Vector3.up);
                if (m_fAnchorDot > Mathf.Cos(m_CharacterController.slopeLimit * RADIANS_TO_DEGREES))
                {
                    // Add jump speed to Y
                    m_fYVelocity = m_fJumpSpeed;

                    // Update state
                    m_eJump = Jump.Jumping;
                    // Scale jump if crouching...
                    if (m_ePose == Pose.Crouch)
                    {
                        m_fYVelocity *= m_fCrouchJumpRatio;
                    }
                    // .. or prone.
                    if (m_ePose == Pose.Prone)
                    {
                        m_fYVelocity *= m_fProneJumpRatio;
                    }
                    // Store the X/Z of projectile motion
                    m_v3LaunchVelocity   = m_CharacterController.velocity;
                    m_v3LaunchVelocity.y = 0.0f;
                }
            }
        }
        // else apply gravity
        else if (m_eJump != Jump.Grounded)
        {
            // Apply gravity
            m_fYVelocity = m_fYVelocity + m_fGravity * a_fDeltaTime;

            // Roof hit check
            if (m_fYVelocity > 0 && m_HeightJump.Colliding)
            {
                m_fYVelocity = 0;
                m_eJump      = Jump.InAir;
                m_HeightJump.ForceOut(ForceMode.Impulse);
            }
            // Check y speed and jump state to transition to in-air
            if (m_eJump == Jump.Jumping)
            {
                // Toggle from jump to falling
                if (m_fYVelocity <= 0)
                {
                    m_eJump = Jump.InAir;
                }
            }
        }
        else // Grounded
        {
            t_Vector3 = m_Anchor.transform.position - (transform.position + Vector3.up * (m_CharacterController.radius - m_CharacterController.skinWidth));
            // If collision tangent is < slope, we can 'stick' by wiping off velocity
            m_fAnchorDot = Vector3.Dot(t_Vector3.normalized, -Vector3.up);

            m_fAnchorDot = Mathf.Clamp(m_fAnchorDot, 0.0f, 1.0f);

            if (!(m_fAnchorDot > Mathf.Cos(m_CharacterController.slopeLimit * RADIANS_TO_DEGREES)))
            {
                // Becomes velocity down the slope
                m_fYVelocity = m_fYVelocity + m_fGravity * a_fDeltaTime * (1 - m_fAnchorDot);

                // Z/X Motion
                //t_Vector3 = m_Anchor.transform.position - transform.position;
                t_Vector3.y = 0;
                t_Vector3.Normalize();
                t_Vector3 *= m_fYVelocity * (m_fAnchorDot);

                // Wipe out motion into the surface...
                m_v3Motion -=
                    (m_Anchor.transform.position - transform.position).normalized *
                    Vector3.Dot((m_Anchor.transform.position - transform.position).normalized, m_v3Motion.normalized) *
                    m_v3Motion.magnitude;

                // Apply Reacrtion force
                m_v3Motion += t_Vector3;
                // Debug.Log(t_Vector3.ToString());
            }
            else // we walk around on a shallow. no slope
            {
                // Direction to the plane highside
                t_Vector3   = m_Anchor.transform.position - transform.position;
                t_Vector3.y = 0;
                t_Vector3.Normalize();

                float fMotionDot = Vector3.Dot(m_v3Motion.normalized, t_Vector3);
                // Rotate by 90 around Y
                float t = t_Vector3.x;
                t_Vector3.x = -t_Vector3.z;
                t_Vector3.z = t;

                // Rotate motion around t_Vector3 by acos(m_fAnchorDot), slightly into the surface
                if (fMotionDot < 0)
                {
                    m_v3Motion = Quaternion.AngleAxis(Mathf.Acos(m_fAnchorDot) / RADIANS_TO_DEGREES + ROTATION_PADDING, t_Vector3) * m_v3Motion;
                }
                else
                {
                    m_v3Motion = Quaternion.AngleAxis(Mathf.Acos(m_fAnchorDot) / RADIANS_TO_DEGREES - ROTATION_PADDING, t_Vector3) * m_v3Motion;
                }

                m_fYVelocity = m_v3Motion.y;
            }
        }

        // Assign from velocity
        m_v3Motion.y = m_fYVelocity;

        // If theres any motion, disable the anchor till next frame.
        if (m_v3Motion.magnitude > float.Epsilon)
        {
            if (m_Anchor.gameObject.activeInHierarchy)
            {
                m_Anchor.parent        = transform;
                m_Anchor.localPosition = Vector3.zero;
                m_Anchor.gameObject.SetActive(false);
            }
        }

        // Apply Motion
        m_CharacterController.Move(m_v3Motion * a_fDeltaTime);
    }
Exemple #34
0
 public void Jump(Jump jump)
 {
     this.jump = jump;
 }
Exemple #35
0
 // Use this for initialization
 void Start()
 {
     cam   = Camera.main;
     motor = GetComponent <PlayerMotor>();
     jump  = GetComponent <Jump>();
 }
    public int UploadJump(Jump myTest)
    {
        //store event uniqueID
        int temp = myTest.UniqueID;

        //change value for being inserted with new numeration in server
        myTest.UniqueID = -1;

        //insert
        int id = myTest.InsertAtDB(false, Constants.JumpTable);

        //roll back person unique id value
        myTest.UniqueID = temp;

        return id; //uniqueID of person at server
    }
Exemple #37
0
    //upload a test
    private static Constants.UploadCodes serverUploadTest(ChronojumpServer myServer, Constants.TestTypes type, string tableName, Event myTest)
    {
        Constants.UploadCodes uCode;

        if (myTest.Simulated == Constants.Simulated)
        {
            //Test is simulated, don't upload
            uCode = Constants.UploadCodes.SIMULATED;
        }
        else if (myTest.Simulated > 0)
        {
            //Test is already uploaded, don't upload
            uCode = Constants.UploadCodes.EXISTS;
        }
        else
        {
            int idAtServer = -1;
            switch (type)
            {
            case Constants.TestTypes.JUMP:
                Jump jump = (Jump)myTest;
                idAtServer = myServer.UploadJump(jump);
                break;

            case Constants.TestTypes.JUMP_RJ:
                JumpRj jumpRj = (JumpRj)myTest;
                idAtServer = myServer.UploadJumpRj(jumpRj);
                break;

            case Constants.TestTypes.RUN:
                Run run = (Run)myTest;
                idAtServer = myServer.UploadRun(run);
                break;

            case Constants.TestTypes.RUN_I:
                RunInterval runI = (RunInterval)myTest;
                idAtServer = myServer.UploadRunI(runI);
                break;

            case Constants.TestTypes.RT:
                ReactionTime rt = (ReactionTime)myTest;
                idAtServer = myServer.UploadRT(rt);
                break;

            case Constants.TestTypes.PULSE:
                Pulse pulse = (Pulse)myTest;
                idAtServer = myServer.UploadPulse(pulse);
                break;

            case Constants.TestTypes.MULTICHRONOPIC:
                MultiChronopic mc = (MultiChronopic)myTest;
                idAtServer = myServer.UploadMultiChronopic(mc);
                break;
            }


            //update test (simulated) on client database
            myTest.Simulated = idAtServer;
            SqliteEvent.UpdateSimulated(true, tableName, myTest.UniqueID, idAtServer);

            uCode = Constants.UploadCodes.OK;
        }
        return(uCode);
    }
Exemple #38
0
    public static Jump SelectJumpData(int uniqueID, bool dbconOpened)
    {
        if(!dbconOpened)
            Sqlite.Open();

        dbcmd.CommandText = "SELECT * FROM jump WHERE uniqueID == " + uniqueID;

        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        SqliteDataReader reader;
        reader = dbcmd.ExecuteReader();
        reader.Read();

        Jump myJump = new Jump(DataReaderToStringArray(reader, 11));

        reader.Close();

        if(!dbconOpened)
            Sqlite.Close();

        return myJump;
    }
 public void Visit(Jump instruction)
 {
 }
    private void treeviewJumpsContextMenu(Jump myJump)
    {
        Menu myMenu = new Menu ();
        Gtk.MenuItem myItem;

        /*
        myItem = new MenuItem ( Catalog.GetString("Play Video") + " " +
                myJump.Type + " (" + myJump.PersonName + ")");
        if(File.Exists(Util.GetVideoFileName(currentSession.UniqueID,
                Constants.TestTypes.JUMP, myTreeViewJumps.EventSelectedID))) {
            myItem.Activated += on_video_play_selected_jump_clicked;
            myItem.Sensitive = true;
        } else
            myItem.Sensitive = false;
        myMenu.Attach( myItem, 0, 1, 0, 1 );
        */

        myItem = new MenuItem ( Catalog.GetString("Edit selected") + " " + myJump.Type + " (" + myJump.PersonName + ")");
        myItem.Activated += on_edit_selected_jump_clicked;
        myMenu.Attach( myItem, 0, 1, 0, 1 );

        Gtk.SeparatorMenuItem mySep = new SeparatorMenuItem();
        myMenu.Attach( mySep, 0, 1, 1, 2 );

        myItem = new MenuItem ( Catalog.GetString("Delete selected") + " " + myJump.Type + " (" + myJump.PersonName + ")");
        myItem.Activated += on_delete_selected_jump_clicked;
        myMenu.Attach( myItem, 0, 1, 2, 3 );

        myMenu.Popup();
        myMenu.ShowAll();
    }
Exemple #41
0
        public Loopable Produce(Character caster, Skill skill, SkillId skillId, BaseEvent baseEvent,
                                SkillCastingSource skillCastingSource, TemplateArgs args)
        {
            BaseAction ba         = baseEvent.ShowAction();
            ActionType actionType = ba.ShowActionType();
            Loopable   loopable   = null;

            switch (actionType)
            {
            case ActionType.Camera:
                CameraAction        ca     = (CameraAction)ba;
                CameraAction.BaseFx bf     = ca.fx;
                CameraAction.FxType fxType = bf.ShowFxType();
                switch (fxType)
                {
                case CameraAction.FxType.Shake:
                    CameraAction.ShakeFx sf = (CameraAction.ShakeFx)bf;
                    loopable = new CameraShake(environment, sf);
                    break;

                case CameraAction.FxType.Fade:
                    loopable = new CameraFade(environment, baseEvent);
                    break;

                case CameraAction.FxType.CinematicZoomToSelf:
                    loopable = new CameraCinematicZoomToSelf(environment, baseEvent, caster);
                    break;

                case CameraAction.FxType.SlowMotion:
                    loopable = new CameraSlowMotion(environment, baseEvent);
                    break;

                case CameraAction.FxType.AddTarget:
                    loopable = new CameraAddTarget(environment, baseEvent, caster);
                    break;

                default:
                    throw new Exception("Missing logic to handle camera fx of type " + fxType);
                }
                break;

            case ActionType.Dash:
                Dash dash = new Dash(baseEvent, caster, skill.IgnoreMinSpeedOnAirForDashes(), skill, environment);
                loopable = dash;
                break;

            case ActionType.Jump:
                bool jumpOverDistance = true;
                if (args != null)
                {
                    bool found;
                    jumpOverDistance = args.TryGetEntry <bool>(TemplateArgsName.JumpSkill_JumpOverDistance, out found);
                    if (!found)
                    {
                        jumpOverDistance = true;
                    }
                }
                Jump jump = new Jump(baseEvent, caster, skill, environment, jumpOverDistance);
                loopable = jump;
                break;

            case ActionType.Vfx:
                Vfxs.Vfx vfx = new Vfxs.Vfx(
                    baseEvent, environment, caster, skillCastingSource, skill, args
                    );
                loopable = vfx;
                break;

            case ActionType.Modifier:
                ModifierAction     ma       = (ModifierAction)ba;
                BaseModifierConfig bmc      = ma.modifierConfig;
                ModifierInfo       mi       = modifierInfoFactory.CreateFrom(skill, bmc, environment);
                EntityReference    er       = caster.GameObject().GetComponent <EntityReference>();
                Modifier           modifier = DamageSystem.Instance.CreateModifier(
                    mi, er.Entity, er.Entity, caster.Position(),
                    caster.Position(), skill, skillId, 0
                    );
                if (modifier != null)
                {
                    caster.AddModifier(modifier);
                }
                loopable = new ModifierLoopable(modifier);
                break;

            case ActionType.Animation:
                loopable = new AnimationPlayback(baseEvent, caster);
                break;

            case ActionType.Teleport:
                TeleportAction          ta   = (TeleportAction)baseEvent.action;
                TeleportAction.ModeName mode = ta.mode.ShowModeName();
                switch (mode)
                {
                case TeleportAction.ModeName.PredefinedPositionOnMap:
                    new Teleport(baseEvent, caster, environment);
                    loopable = new ImmediatelyFinishedLoopable();
                    break;

                case TeleportAction.ModeName.KeepDistance:
                    TeleportAction.KeepDistanceMode kdm = (TeleportAction.KeepDistanceMode)ta.mode;
                    loopable = new TeleportKeepDistanceLogic(kdm, skill, environment, caster);
                    break;

                case TeleportAction.ModeName.AroundTarget:
                    TeleportAction.AroundTargetMode atm = (TeleportAction.AroundTargetMode)ta.mode;
                    loopable = new TeleportAroundTargetLogic(atm, caster, environment, skill);
                    break;

                case TeleportAction.ModeName.AroundTeamMate:
                    TeleportAction.AroundTeamMateMode atmm = (TeleportAction.AroundTeamMateMode)ta.mode;
                    loopable = new TeleportAroundTeamMate(atmm, caster, environment, skill);
                    break;

                default:
                    throw new Exception("Cannot create teleport of type " + mode);
                }
                break;

            case ActionType.FacingDirection:
                loopable = new FacingDirection(baseEvent, caster, environment);
                break;

            case ActionType.DashTowardTarget:
                DashTowardTarget dtt = new DashTowardTarget(baseEvent, caster, environment);
                loopable = dtt;
                break;

            case ActionType.JumpTowardTarget:
                loopable = new JumpTowardTarget(baseEvent, caster, environment);
                break;

            case ActionType.SpawnCharacter:
                SpawnCharacterAction sca = (SpawnCharacterAction)ba;
                loopable = new SpawnCharacter(sca, entitySpawner, caster, args, environment, skillId, hamc);
                break;

            case ActionType.Rotation:
                loopable = new Rotation(baseEvent, caster, environment);
                break;

            case ActionType.Timer:
                loopable = new Timer(baseEvent, skill);
                break;

            case ActionType.Sound:
                loopable = new AudioClipPlayback(baseEvent, environment);
                break;

            case ActionType.PassiveSkillOnOff:
                loopable = new PassiveSkillOnOff(baseEvent, caster);
                break;

            case ActionType.DistanceTracker:
                loopable = new DistanceTracker(baseEvent, skill, caster);
                break;

            case ActionType.SelfDamageDealing:
                loopable = new SelfDamageDealing(baseEvent, caster, skill, skillId);
                break;

            case ActionType.SwitchPhase:
                loopable = new SwitchPhase(skill);
                break;

            case ActionType.Movable:
                Entity        casterEntity  = caster.GameObject().GetComponent <EntityReference>().Entity;
                UserInput     userInput     = casterEntity.GetComponent <HeroStateMachineComponent>().UserInput;
                MovableAction movableAction = (MovableAction)ba;
                loopable = new Movable(movableAction, skill, caster.FacingDirection(), userInput, caster);
                break;

            case ActionType.Input:
                casterEntity = caster.GameObject().GetComponent <EntityReference>().Entity;
                userInput    = casterEntity.GetComponent <HeroStateMachineComponent>().UserInput;
                InputAction ia = (InputAction)ba;
                loopable = new InputSimulation(ia, (DefaultUserInput)userInput);
                break;

#if UNITY_EDITOR
            case ActionType.Macro:
                loopable = new Macro(baseEvent, caster);
                break;
#endif
            default:
                DLog.Log("Missing logic to handle action of type " + actionType);
                break;
            }

            return(loopable);
        }
 public override void visit(Jump node)
 {
     nextNode = node.getJumpToNode();
 }
Exemple #43
0
 void Start()
 {
     jmp = GetComponent <Jump>();
 }
Exemple #44
0
 public System.IAsyncResult BeginUploadJump(Jump myTest, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UploadJump", new object[] {
                 myTest}, callback, asyncState);
 }
Exemple #45
0
        public Task SetMovementState(MovementFlags movementFlags, int time, int fallTime, Jump jump)
        {
            VerifyExists();

            State.MoveFlags = movementFlags;
            State.MoveTime  = time;
            State.FallTime  = fallTime;

            if (jump != null)
            {
                State.Jump.Velocity    = jump.Velocity;
                State.Jump.SineAngle   = jump.SineAngle;
                State.Jump.CosineAngle = jump.CosineAngle;
                State.Jump.XYSpeed     = jump.XYSpeed;
            }
            else
            {
                State.Jump.Velocity = State.Jump.SineAngle = State.Jump.CosineAngle = State.Jump.XYSpeed = 0.0f;
            }

            IsMovementUpdated = true;

            return(WriteStateAsync());
        }
Exemple #46
0
 public void UploadJumpAsync(Jump myTest)
 {
     this.UploadJumpAsync(myTest, null);
 }
Exemple #47
0
 /// <summary>
 ///     Handles a change in PlayerKeyState.
 /// </summary>
 /// <param name="sender">Sender of the event.</param>
 /// <param name="e">Object containing information about the event.</param>
 public void Handle(object sender, KeyStateChangedEventArgs e)
 {
     if (Action != null && _check(e, Keys.Action))
     {
         Action.Handle(sender, e);
     }
     if (Crouch != null && _check(e, Keys.Crouch))
     {
         Crouch.Handle(sender, e);
     }
     if (Fire != null && _check(e, Keys.Fire))
     {
         Fire.Handle(sender, e);
     }
     if (Sprint != null && _check(e, Keys.Sprint))
     {
         Sprint.Handle(sender, e);
     }
     if (SecondaryAttack != null && _check(e, Keys.SecondaryAttack))
     {
         SecondaryAttack.Handle(sender, e);
     }
     if (Jump != null && _check(e, Keys.Jump))
     {
         Jump.Handle(sender, e);
     }
     if (LookRight != null && _check(e, Keys.LookRight))
     {
         LookRight.Handle(sender, e);
     }
     if (Handbrake != null && _check(e, Keys.Handbrake))
     {
         Handbrake.Handle(sender, e);
     }
     if (Aim != null && _check(e, Keys.Aim))
     {
         Aim.Handle(sender, e);
     }
     if (LookLeft != null && _check(e, Keys.LookLeft))
     {
         LookLeft.Handle(sender, e);
     }
     if (Submission != null && _check(e, Keys.Submission))
     {
         Submission.Handle(sender, e);
     }
     if (Walk != null && _check(e, Keys.Walk))
     {
         Walk.Handle(sender, e);
     }
     if (AnalogUp != null && _check(e, Keys.AnalogUp))
     {
         AnalogUp.Handle(sender, e);
     }
     if (AnalogDown != null && _check(e, Keys.AnalogDown))
     {
         AnalogDown.Handle(sender, e);
     }
     if (AnalogLeft != null && _check(e, Keys.AnalogLeft))
     {
         AnalogLeft.Handle(sender, e);
     }
     if (AnalogRight != null && _check(e, Keys.AnalogRight))
     {
         AnalogRight.Handle(sender, e);
     }
     if (Yes != null && _check(e, Keys.Yes))
     {
         Yes.Handle(sender, e);
     }
     if (No != null && _check(e, Keys.No))
     {
         No.Handle(sender, e);
     }
     if (CtrlBack != null && _check(e, Keys.CtrlBack))
     {
         CtrlBack.Handle(sender, e);
     }
 }
    protected override string [] getLineToStore(System.Object myObject)
    {
        Jump newJump = (Jump)myObject;

        string title = newJump.Type;

        if (newJump.Simulated == Constants.Simulated)
        {
            title += Constants.SimulatedTreeview;
        }

        string [] myData = new String [getColsNum()];
        int       count  = 0;

        //myData[count++] = newJump.Type;
        myData[count++] = title;
        myData[count++] = Util.TrimDecimals(newJump.Tc.ToString(), pDN);
        myData[count++] = Util.TrimDecimals(newJump.Tv.ToString(), pDN);

        //we calculate weightInKg again because can be changed in edit jump, and then treeview is no re-done
        //but we do not calculate again person weight, because if it changes treeview is created again
        //
        //Also this is needed on Add (where personWeight is passed using PersonWeight, but not weightInKg)
        weightInKg = Util.WeightFromPercentToKg(
            Convert.ToDouble(newJump.Weight.ToString()),
            personWeight);

        if (preferences.weightStatsPercent)
        {
            myData[count++] = Util.TrimDecimals(newJump.Weight.ToString(), pDN);
        }
        else
        {
            myData[count++] = Util.TrimDecimals(weightInKg.ToString(), pDN);
        }

        myData[count++] = Util.TrimDecimals(newJump.Fall.ToString(), pDN);
        myData[count++] = Util.TrimDecimals(Util.GetHeightInCentimeters(newJump.Tv.ToString()), pDN);



        if (preferences.showPower)
        {
            //takeoff has no tv. power should not be calculated
            //calculate jumps with tf
            if (newJump.Tv > 0)
            {
                if (newJump.Tc > 0)                     //if it's Dj (has tf, and tc)
                {
                    myData[count++] = Util.TrimDecimals(
                        Util.GetDjPower(newJump.Tc, newJump.Tv, (personWeight + weightInKg), newJump.Fall).ToString(), 1);
                }
                else                                    //it's a normal jump without tc
                {
                    myData[count++] = Util.TrimDecimals(
                        Util.GetPower(newJump.Tv, personWeight, weightInKg).ToString(), 1);
                }
            }
            else
            {
                myData[count++] = "0";
            }
        }
        if (preferences.showStiffness)
        {
            myData[count++] = Convert.ToInt32(newJump.Stiffness(personWeight, weightInKg)).ToString();
        }
        if (preferences.showInitialSpeed)
        {
            myData[count++] = Util.TrimDecimals(Util.GetInitialSpeed(newJump.Tv.ToString(), preferences.metersSecondsPreferred), pDN);
        }
        if (preferences.showAngle)
        {
            myData[count++] = Util.TrimDecimals(newJump.Angle.ToString(), pDN);
        }
        if (preferences.showQIndex)
        {
            myData[count++] = Util.TrimDecimals(Util.GetQIndex(newJump.Tv, newJump.Tc).ToString(), pDN);
        }
        if (preferences.showDjIndex)
        {
            myData[count++] = Util.TrimDecimals(Util.GetDjIndex(newJump.Tv, newJump.Tc).ToString(), pDN);
        }

        myData[count++] = newJump.Description;

        myData[count++] = newJump.UniqueID.ToString();
        return(myData);
    }
Exemple #49
0
 public ActionResult LoginJump(Jump model)
 {
     return(View(model));
 }
Exemple #50
0
    private static void on_server_upload_session_started()
    {
        int evalSID = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID"));

        try {
            ChronojumpServer myServer = new ChronojumpServer();
            LogB.Information(myServer.ConnectDatabase());

            int state = (int)Constants.ServerSessionStates.UPLOADINGSESSION;
            //create ServerSession based on Session currentSession
            ServerSession serverSession = new ServerSession(currentSession, evalSID, progName + " " + progVersion,
                                                            UtilAll.GetOS(), DateTime.Now, state);

            //if uploading session for first time
            if (currentSession.ServerUniqueID == Constants.ServerUndefinedID)
            {
                //upload ServerSession
                int idAtServer = myServer.UploadSession(serverSession);

                //update session currentSession (serverUniqueID) on client database
                currentSession.ServerUniqueID = idAtServer;
                SqliteSession.UpdateServerUniqueID(currentSession.UniqueID, currentSession.ServerUniqueID);
            }

            state = (int)Constants.ServerSessionStates.UPLOADINGDATA;
            myServer.UpdateSession(currentSession.ServerUniqueID, state);

            sessionUploadPersonData.testTypes = "";
            string testTypesSeparator = "";
            sessionUploadPersonData.sports = "";
            string sportsSeparator = "";

            //upload persons (updating also person.serverUniqueID locally)
            ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(
                serverSession.UniqueID,
                false);                         //means: do not returnPersonAndPSlist

            Constants.UploadCodes uCode;
            ArrayList             notToUpload = SqlitePersonSessionNotUpload.SelectAll(currentSession.UniqueID);

            //store in variable for updating progressBar from other thread
            progressBarPersonsNum = persons.Count - notToUpload.Count;

            foreach (Person p in persons)
            {
                Person person = p;

                //do not continue with this person if has been banned to upload
                if (Util.FoundInArrayList(notToUpload, person.UniqueID.ToString()))
                {
                    continue;
                }

                PersonSession ps = SqlitePersonSession.Select(person.UniqueID, currentSession.UniqueID);

                //check person if exists
                if (person.ServerUniqueID != Constants.ServerUndefinedID)
                {
                    uCode = Constants.UploadCodes.EXISTS;
                }
                else
                {
                    uCode = Constants.UploadCodes.OK;

                    person = serverUploadPerson(myServer, person, serverSession.UniqueID);
                }

                //if sport is user defined, upload it
                //and when upload the person, do it with new sportID
                Sport sport = SqliteSport.Select(false, ps.SportID);
                //but record old sport ID because locally will be a change in serverUniqueID
                //(with slite update)
                //but local sport has not to be changed
                int sportUserDefinedLocal = -1;

                if (sport.UserDefined)
                {
                    sportUserDefinedLocal = sport.UniqueID;

                    //this will be uploaded
                    int newSport = myServer.UploadSport(sport);
                    if (newSport != -1)
                    {
                        ps.SportID = newSport;
                        sessionUploadPersonData.sports += sportsSeparator + sport.Name;
                        sportsSeparator = ", ";
                    }
                }

                //a person can be in the database for one session,
                //but maybe now we add jumps from another session and we should add an entry at personsession
                serverUploadPersonSessionIfNeeded(myServer, person.ServerUniqueID,
                                                  currentSession.ServerUniqueID, ps, sportUserDefinedLocal);

                //other thread updates the gui:
                sessionUploadPersonData.person     = person;
                sessionUploadPersonData.personCode = uCode;

                //upload jumps
                int countU = 0;
                int countE = 0;
                int countS = 0;

                string [] jumps = SqliteJump.SelectJumps(false, currentSession.UniqueID, person.UniqueID, "", "",
                                                         Sqlite.Orders_by.DEFAULT, -1);
                Sqlite.Open();
                foreach (string myJump in jumps)
                {
                    string [] js = myJump.Split(new char[] { ':' });
                    //select jump
                    Jump test = SqliteJump.SelectJumpData(Convert.ToInt32(js[1]), true);                     //uniqueID
                    //fix it to server person, session keys
                    test.PersonID  = person.ServerUniqueID;
                    test.SessionID = currentSession.ServerUniqueID;

                    //if test is not simulated and has not been uploaded,
                    //see if it's type is not predefined and is not in the database
                    //then upload it first
                    if (test.Simulated == 0)
                    {
                        //upload jumpType if is user defined and doesn't exists in server database
                        //JumpType type = new JumpType(test.Type);
                        JumpType type = SqliteJumpType.SelectAndReturnJumpType(test.Type, true);
                        if (!type.IsPredefined)
                        {
                            //Console.WriteLine("USER DEFINED TEST: " + test.Type);
                            //
                            //this uploads the new type, as it's user created, it will be like this
                            //eg: for user defined jumpType: "supra" of evaluatorServerID: 9
                            //at server will be "supra-9"
                            //then two problems get solved:
                            //1.- every evaluator that uploads a type will have a different name
                            //than other evaluator uploading a type that is named the same but could be different
                            //(one can think that "supra" is another thing
                            //2- when the same evaluator upload some supra's, only a new type is created

                            //test.Type = myServer.UploadJumpType(type, evalSID);
                            //int testType = (int) Constants.TestTypes.JUMP;
                            //string insertedType = myServer.UploadTestType(Constants.TestTypes.JUMP, type, evalSID);
                            //string insertedType = myServer.UploadTestType(testType, type, evalSID);
                            string insertedType = myServer.UploadJumpType(type, evalSID);
                            if (insertedType != "-1")
                            {
                                //record type in test (with the "-7" if it's done by evaluator 7)
                                test.Type = insertedType;

                                //show user uploaded type (without the "-7")
                                sessionUploadPersonData.testTypes += testTypesSeparator + type.Name;
                                testTypesSeparator = ", ";
                            }

                            //test.Type in the server will have the correct name "supra-9"
                        }
                    }

                    //upload... (if not because of simulated or uploaded before, report also the user)
                    uCode = serverUploadTest(myServer, Constants.TestTypes.JUMP, Constants.JumpTable, test);

                    if (uCode == Constants.UploadCodes.OK)
                    {
                        countU++;
                    }
                    else if (uCode == Constants.UploadCodes.EXISTS)
                    {
                        countE++;
                    }
                    else                     //SIMULATED
                    {
                        countS++;
                    }
                }
                Sqlite.Close();

                //other thread updates the gui:
                sessionUploadPersonData.jumpsU = countU;
                sessionUploadPersonData.jumpsE = countE;
                sessionUploadPersonData.jumpsS = countS;

                //upload jumpsRj
                countU = 0;
                countE = 0;
                countS = 0;

                string [] jumpsRj = SqliteJumpRj.SelectJumps(false, currentSession.UniqueID, person.UniqueID, "", "");
                Sqlite.Open();
                foreach (string myJump in jumpsRj)
                {
                    string [] js = myJump.Split(new char[] { ':' });
                    //select jump
                    JumpRj test = SqliteJumpRj.SelectJumpData(Constants.JumpRjTable, Convert.ToInt32(js[1]), true);                     //uniqueID
                    //fix it to server person, session keys
                    test.PersonID  = person.ServerUniqueID;
                    test.SessionID = currentSession.ServerUniqueID;

                    if (test.Simulated == 0)
                    {
                        JumpType type = SqliteJumpType.SelectAndReturnJumpRjType(test.Type, true);
                        if (!type.IsPredefined)
                        {
                            string insertedType = myServer.UploadJumpRjType(type, evalSID);
                            if (insertedType != "-1")
                            {
                                test.Type = insertedType;
                                sessionUploadPersonData.testTypes += testTypesSeparator + type.Name;
                                testTypesSeparator = ", ";
                            }
                        }
                    }

                    //upload...
                    uCode = serverUploadTest(myServer, Constants.TestTypes.JUMP_RJ, Constants.JumpRjTable, test);

                    if (uCode == Constants.UploadCodes.OK)
                    {
                        countU++;
                    }
                    else if (uCode == Constants.UploadCodes.EXISTS)
                    {
                        countE++;
                    }
                    else                     //SIMULATED
                    {
                        countS++;
                    }
                }
                Sqlite.Close();

                //other thread updates the gui:
                sessionUploadPersonData.jumpsRjU = countU;
                sessionUploadPersonData.jumpsRjE = countE;
                sessionUploadPersonData.jumpsRjS = countS;

                //upload runs
                countU = 0;
                countE = 0;
                countS = 0;

                string [] runs = SqliteRun.SelectRuns(false, currentSession.UniqueID, person.UniqueID, "",
                                                      Sqlite.Orders_by.DEFAULT, -1);

                Sqlite.Open();
                foreach (string myRun in runs)
                {
                    string [] js = myRun.Split(new char[] { ':' });
                    //select run
                    Run test = SqliteRun.SelectRunData(Convert.ToInt32(js[1]), true);                     //uniqueID
                    //fix it to server person, session keys
                    test.PersonID  = person.ServerUniqueID;
                    test.SessionID = currentSession.ServerUniqueID;

                    if (test.Simulated == 0)
                    {
                        RunType type = SqliteRunType.SelectAndReturnRunType(test.Type, true);
                        if (!type.IsPredefined)
                        {
                            string insertedType = myServer.UploadRunType(type, evalSID);
                            if (insertedType != "-1")
                            {
                                test.Type = insertedType;
                                sessionUploadPersonData.testTypes += testTypesSeparator + type.Name;
                                testTypesSeparator = ", ";
                            }
                        }
                    }

                    //upload...
                    uCode = serverUploadTest(myServer, Constants.TestTypes.RUN, Constants.RunTable, test);

                    if (uCode == Constants.UploadCodes.OK)
                    {
                        countU++;
                    }
                    else if (uCode == Constants.UploadCodes.EXISTS)
                    {
                        countE++;
                    }
                    else                     //SIMULATED
                    {
                        countS++;
                    }
                }
                Sqlite.Close();

                //other thread updates the gui:
                sessionUploadPersonData.runsU = countU;
                sessionUploadPersonData.runsE = countE;
                sessionUploadPersonData.runsS = countS;

                //upload runs intervallic
                countU = 0;
                countE = 0;
                countS = 0;

                string [] runsI = SqliteRunInterval.SelectRuns(false, currentSession.UniqueID, person.UniqueID, "");
                Sqlite.Open();
                foreach (string myRun in runsI)
                {
                    string [] js = myRun.Split(new char[] { ':' });
                    //select run
                    RunInterval test = SqliteRunInterval.SelectRunData(Constants.RunIntervalTable, Convert.ToInt32(js[1]), true);                     //uniqueID
                    //fix it to server person, session keys
                    test.PersonID  = person.ServerUniqueID;
                    test.SessionID = currentSession.ServerUniqueID;

                    if (test.Simulated == 0)
                    {
                        RunType type = SqliteRunIntervalType.SelectAndReturnRunIntervalType(test.Type, true);
                        if (!type.IsPredefined)
                        {
                            string insertedType = myServer.UploadRunIntervalType(type, evalSID);
                            if (insertedType != "-1")
                            {
                                test.Type = insertedType;
                                sessionUploadPersonData.testTypes += testTypesSeparator + type.Name;
                                testTypesSeparator = ", ";
                            }
                        }
                    }
                    //upload...
                    uCode = serverUploadTest(myServer, Constants.TestTypes.RUN_I, Constants.RunIntervalTable, test);

                    if (uCode == Constants.UploadCodes.OK)
                    {
                        countU++;
                    }
                    else if (uCode == Constants.UploadCodes.EXISTS)
                    {
                        countE++;
                    }
                    else                     //SIMULATED
                    {
                        countS++;
                    }
                }
                Sqlite.Close();

                //other thread updates the gui:
                sessionUploadPersonData.runsIU = countU;
                sessionUploadPersonData.runsIE = countE;
                sessionUploadPersonData.runsIS = countS;

                //upload reaction times
                countU = 0;
                countE = 0;
                countS = 0;

                string [] rts = SqliteReactionTime.SelectReactionTimes(false, currentSession.UniqueID, person.UniqueID, "",
                                                                       Sqlite.Orders_by.DEFAULT, -1);

                Sqlite.Open();
                foreach (string myRt in rts)
                {
                    string [] js = myRt.Split(new char[] { ':' });
                    //select rt
                    ReactionTime test = SqliteReactionTime.SelectReactionTimeData(Convert.ToInt32(js[1]), true);                     //uniqueID
                    //fix it to server person, session keys
                    test.PersonID  = person.ServerUniqueID;
                    test.SessionID = currentSession.ServerUniqueID;
                    //upload...
                    uCode = serverUploadTest(myServer, Constants.TestTypes.RT, Constants.ReactionTimeTable, test);

                    if (uCode == Constants.UploadCodes.OK)
                    {
                        countU++;
                    }
                    else if (uCode == Constants.UploadCodes.EXISTS)
                    {
                        countE++;
                    }
                    else                     //SIMULATED
                    {
                        countS++;
                    }
                }
                Sqlite.Close();

                //other thread updates the gui:
                sessionUploadPersonData.rtsU = countU;
                sessionUploadPersonData.rtsE = countE;
                sessionUploadPersonData.rtsS = countS;

                //upload pulses
                countU = 0;
                countE = 0;
                countS = 0;

                string [] pulses = SqlitePulse.SelectPulses(false, currentSession.UniqueID, person.UniqueID);
                Sqlite.Open();
                foreach (string myPulse in pulses)
                {
                    string [] js = myPulse.Split(new char[] { ':' });
                    //select pulse
                    Pulse test = SqlitePulse.SelectPulseData(Convert.ToInt32(js[1]), true);                     //uniqueID
                    //fix it to server person, session keys
                    test.PersonID  = person.ServerUniqueID;
                    test.SessionID = currentSession.ServerUniqueID;
                    //upload...
                    uCode = serverUploadTest(myServer, Constants.TestTypes.PULSE, Constants.PulseTable, test);

                    if (uCode == Constants.UploadCodes.OK)
                    {
                        countU++;
                    }
                    else if (uCode == Constants.UploadCodes.EXISTS)
                    {
                        countE++;
                    }
                    else                     //SIMULATED
                    {
                        countS++;
                    }
                }
                Sqlite.Close();

                //other thread updates the gui:
                sessionUploadPersonData.pulsesU = countU;
                sessionUploadPersonData.pulsesE = countE;
                sessionUploadPersonData.pulsesS = countS;

                //upload multiChronopic
                countU = 0;
                countE = 0;
                countS = 0;

                string [] mcs = SqliteMultiChronopic.SelectTests(false, currentSession.UniqueID, person.UniqueID);
                Sqlite.Open();
                foreach (string mc in mcs)
                {
                    string [] js = mc.Split(new char[] { ':' });
                    //select mc
                    MultiChronopic test = SqliteMultiChronopic.SelectMultiChronopicData(Convert.ToInt32(js[1]), true);                     //uniqueID
                    //fix it to server person, session keys
                    test.PersonID  = person.ServerUniqueID;
                    test.SessionID = currentSession.ServerUniqueID;
                    //upload...
                    uCode = serverUploadTest(myServer, Constants.TestTypes.MULTICHRONOPIC, Constants.MultiChronopicTable, test);

                    if (uCode == Constants.UploadCodes.OK)
                    {
                        countU++;
                    }
                    else if (uCode == Constants.UploadCodes.EXISTS)
                    {
                        countE++;
                    }
                    else                     //SIMULATED
                    {
                        countS++;
                    }
                }
                Sqlite.Close();

                //other thread updates the gui:
                sessionUploadPersonData.mcsU = countU;
                sessionUploadPersonData.mcsE = countE;
                sessionUploadPersonData.mcsS = countS;

                needUpdateServerSession = true;
                while (needUpdateServerSession)
                {
                    //wait until data is printed on the other thread
                }
            }

            state = (int)Constants.ServerSessionStates.DONE;
            //myServer.UpdateSession(currentSession.ServerUniqueID, (ServerSessionStates)  Constants.ServerSessionStates.DONE);
            myServer.UpdateSession(currentSession.ServerUniqueID, state);

            LogB.Information(myServer.DisConnectDatabase());
        } catch {
            //other thread updates the gui:
            serverSessionError = true;
        }
    }
        public StateController <CharacterState, CharacterContext> BuildCharacterControllerImpl(StateControllerBuilder <CharacterState, CharacterContext> builder)
        {
            Builder = builder;
            InjectState(this);

            // Ground Attacks
            new [] { Idle, Walk, CrouchStart, Crouch, CrouchEnd }
            // Smash Attacks
            .AddTransitions <CharacterState, CharacterContext>(context => {
                var input = context.Input;
                if (!input.Attack.WasPressed)
                {
                    return(null);
                }
                switch (input.Smash.Direction)
                {
                case Direction.Right:
                case Direction.Left:
                    return(SmashSide.Charge);

                case Direction.Up:
                    return(SmashUp.Charge);

                case Direction.Down:
                    return(SmashDown.Charge);
                }
                return(null);
            })
            // Tilt Attacks
            .AddTransitions <CharacterState, CharacterContext>(context => {
                var input = context.Input;
                if (!input.Attack.WasPressed)
                {
                    return(null);
                }
                switch (input.Movement.Direction)
                {
                case Direction.Right:
                case Direction.Left:
                    return(TiltSide);

                case Direction.Up:
                    return(TiltUp);

                case Direction.Down:
                    return(TiltDown);
                }
                return(Neutral);
            });
            SmashUp.Charge.AddTransitionTo(SmashUp.Attack);
            SmashDown.Charge.AddTransitionTo(SmashDown.Attack);
            SmashSide.Charge.AddTransitionTo(SmashSide.Attack);
            TiltDown.AddTransitionTo(Crouch, Input(i => i.Movement.Direction == Direction.Down));
            new[] { Neutral, TiltUp, TiltDown, TiltSide, SmashUp.Attack, SmashDown.Attack, SmashSide.Attack }
            .AddTransitionTo(Idle);

            new [] { Fall, Jump, JumpAerial }
            .AddTransitions(Land, ctx => ctx.IsGrounded)
            // Aerial Attacks
            .AddTransitions <CharacterState, CharacterContext>(context => {
                var input = context.Input;
                if (!input.Attack.WasPressed)
                {
                    return(null);
                }
                switch (input.Movement.Direction)
                {
                case Direction.Right:
                    return(context.Direction >= 0f ? AerialForward : AerialBackward);

                case Direction.Left:
                    return(context.Direction >= 0f ? AerialBackward : AerialForward);

                case Direction.Up:
                    return(AerialUp);

                case Direction.Down:
                    return(AerialDown);
                }
                return(AerialNeutral);
            });
            new[] { AerialForward, AerialBackward, AerialDown, AerialUp, AerialNeutral }
            .AddTransitions(AerialAttackLand, ctx => ctx.IsGrounded)
            .AddTransitionTo(Fall);
            AerialAttackLand.AddTransitionTo(Idle);

            // Aerial Movement
            new [] { Idle, Walk, Dash, Run, RunTurn, RunBrake, CrouchStart, Crouch, CrouchEnd, Shield.Main }
            .AddTransitions(JumpStart, ctx => ctx.Input.Jump.WasPressed && ctx.CanJump);
            new[] { JumpStart, JumpAerial }.AddTransitionTo(Jump);
            new[] { Jump, Fall }.AddTransitions(JumpAerial, ctx => ctx.Input.Jump.WasPressed && ctx.CanJump)
            .AddTransitions(EscapeAir, Input(i => i.Shield.WasPressed));
            Jump.AddTransition(Idle, ctx => ctx.NormalizedStateTime >= 1.0f && ctx.IsGrounded)
            .AddTransition(Fall, ctx => ctx.NormalizedStateTime >= 1.0f && !ctx.IsGrounded);
            EscapeAir.AddTransitionTo(FallHelpless);
            new[] { Fall, FallHelpless, EscapeAir }.AddTransitions(Land, ctx => ctx.IsGrounded);
            Land.AddTransitionTo(Idle);

            Func <Func <PlayerInputContext, DirectionalInput>, Func <CharacterContext, bool> >
            movementContext = func => {
                var downMove        = DirectionInput(Direction.Down);
                var lateralMovement = Input(i => Mathf.Abs(func(i).Value.x) > DirectionalInput.DeadZone);
                return(ctx => !downMove(ctx) && lateralMovement(ctx));
            };

            // Running States
            Idle.AddTransition(Dash, movementContext(i => i.Smash));
            Dash.AddTransitionTo(Idle, DirectionInput(Direction.Neutral));
            new[] { Dash, RunTurn }.AddTransitionTo(Run);
            Run.AddTransition(RunBrake, DirectionInput(Direction.Neutral));
            Run.AddTransition(RunTurn,
                              ctx => !Mathf.Approximately(Mathf.Sign(ctx.Input.Movement.Value.x), Mathf.Sign(ctx.Direction)));
            RunBrake.AddTransitionTo(Idle);

            // Ground Movement
            new[] { Idle, Walk, Run }
            .AddTransitions(CrouchStart, DirectionInput(Direction.Down))
            .AddTransitions(Fall, ctx => !ctx.IsGrounded);

            Idle.AddTransition(Walk, movementContext(i => i.Movement));
            Walk.AddTransition(Idle, DirectionInput(Direction.Neutral));

            // Crouching States
            CrouchStart.AddTransitionTo(Crouch);
            CrouchEnd.AddTransitionTo(Idle);
            new[] { CrouchStart, Crouch, CrouchEnd }.AddTransitions(Fall, ctx => !ctx.IsGrounded);
            Crouch.AddTransition(CrouchEnd, Input(i => i.Movement.Direction != Direction.Down));

            // Ledge States
            new[] { Idle, Fall, FallHelpless }.AddTransitions(LedgeGrab, ctx => ctx.State.IsGrabbingLedge);
            LedgeGrab.AddTransitionTo(LedgeIdle);
            LedgeIdle.AddTransition(LedgeRelease, ctx => !ctx.State.IsGrabbingLedge)
            .AddTransition(LedgeClimb, DirectionInput(Direction.Up))
            .AddTransition(LedgeJump, ctx => ctx.Input.Jump.WasPressed && ctx.CanJump)
            .AddTransition(LedgeAttack, Attack());
            LedgeJump.AddTransitionTo(Jump);
            new[] { LedgeRelease, LedgeClimb, LedgeEscape, LedgeAttack }
            .AddTransitions(Idle, ctx => ctx.NormalizedStateTime >= 1.0f && ctx.IsGrounded)
            .AddTransitions(Fall, ctx => ctx.NormalizedStateTime >= 1.0f && !ctx.IsGrounded);

            // Shielding
            Idle.AddTransition(Shield.On, Input(i => i.Shield.Current));
            Shield.On.AddTransition(Shield.Perfect, ctx => ctx.State.IsHit)
            .AddTransitionTo(Shield.Main);
            Shield.Main.AddTransition(Shield.Broken, ctx => ctx.ShieldBroken)
            .AddTransition(Shield.Off, Input(i => !i.Shield.Current));
            Shield.Off.AddTransitionTo(Idle);
            new[] { Shield.Broken, Shield.Stunned, Idle }.Chain();

            // Rolls/Sidesteps
            var leftSmash  = DirectionalSmash(Direction.Left);
            var rightSmash = DirectionalSmash(Direction.Right);

            Shield.Main
            .AddTransition(EscapeForward, ctx => {
                if (ctx.Direction > 0f)
                {
                    return(rightSmash(ctx));
                }
                else
                {
                    return(leftSmash(ctx));
                }
            })
            .AddTransition(EscapeBackward, ctx => {
                if (ctx.Direction > 0f)
                {
                    return(leftSmash(ctx));
                }
                else
                {
                    return(rightSmash(ctx));
                }
            })
            .AddTransition(Escape, DirectionInput(Direction.Down));
            new[] { Escape, EscapeForward, EscapeBackward }.AddTransitionTo(Shield.Main);

            Builder.WithDefaultState(Idle);
            BuildCharacterController();
            return(Builder.Build());
        }