Esempio n. 1
0
        private void ProcessIncomingPackets(int dt)
        {
            // TODO(pyoung): dispose input during delay.

            List <NetworkPacket> incommingPackets = this.Network.GetIncommingPackets();

            foreach (NetworkPacket packet in incommingPackets)
            {
                int               turn     = packet.Turn;
                string            uuid     = packet.uuid;
                TurnData.TurnData turnData = packet.TurnData;
                this.TurnDataMgr[turn].Add(uuid, turnData);

                if (this.State == E_STATE.DELAYED)
                {
                    if (TryAdvanceTurn())
                    {
                        this._accumulatedSubTurn = 0;
                        this._currentTurn       += 1;
                    }
                    else
                    {
                        this.State = E_STATE.DELAYED;
                    }
                }
            }
        }
Esempio n. 2
0
        private void SendOutgoingPackets(int dt)
        {
            this._accumulatedMillisec += dt;

            while (this._accumulatedMillisec > this.Config.MillisecPerSubTurn)
            {
                this._accumulatedMillisec -= this.Config.MillisecPerSubTurn;

                // ## Subturn.
                this._accumulatedSubTurn += 1;

                if (this._accumulatedSubTurn >= this.Config.SubTurnsPerTurn)
                {
                    // ## Stepping Turn.
                    {
                        int steppedTurn = this._currentTurn + this.Config.TurnGap;
                        List <IInputCommand> commands = this.Input.FlushCommands();

                        TurnData.TurnData turnData = new TurnData.TurnData(this.uuid, commands);

                        NetworkPacket packet =
                            new NetworkPacket(NetworkPacket.E_TYPE.TURN, steppedTurn, this.uuid, turnData);

                        this.Network.Send(packet);
                    }

                    if (this._currentTurn < 0)
                    {
                        this._accumulatedSubTurn = 0;
                        this._currentTurn       += 1;
                    }
                    else
                    {
                        if (TryAdvanceTurn())
                        {
                            this._accumulatedSubTurn = 0;
                            this._currentTurn       += 1;
                        }
                        else
                        {
                            this.State = E_STATE.DELAYED;
                        }
                    }

                    break;
                }
            }
        }