Esempio n. 1
0
    // -------------------------------------------------------------------------------------------------------------------

    private void FixedUpdate()
    {
        // TODO: Temporary solution for co-existance of single/multi player
        if (m_state == State.RunningSinglePlayer)
        {
            if (m_commandQueueMine.Count > 0)
            {
                m_commandQueueMine.Dequeue().Execute();
            }

            UpdateSimulation();
            return;
        }
        else if (m_state == State.RunningMultiplayer)
        {
            if ((m_simulationCount % m_lockStepSize) == 0) // Time to perform lockstep (if ready)
            {
                // Do no simulation and do not update simulation count if we were not ready
                if (!m_confirmedCommands.ReadyForNextTurn(m_lockStepTurnId) ||
                    !m_pendingCommands.ReadyForNextTurn(m_lockStepTurnId))
                {
                    logger.Warning("Lockstep turn failed, too fast?");
                    return;
                }

                m_confirmedCommands.NewTurn();
                m_pendingCommands.NewTurn();

                if (m_lockStepTurnId >= 3)
                {
                    m_pendingCommands.ExecuteCurrentCommands();
                }

                m_lockStepTurnId++;
                logger.PopContext();
                logger.PushContext("T" + m_lockStepTurnId);

                HandleOneOfMyCommands();
            }

            UpdateSimulation();
        }
    }