예제 #1
0
 /**
  * @brief Registers an implementation of {@link ITrueSyncBehaviour} to be included in the simulation.
  *
  * @param trueSyncBehaviour Instance of an {@link ITrueSyncBehaviour}
  **/
 public static void RegisterITrueSyncBehaviour(ITrueSyncBehaviour trueSyncBehaviour)
 {
     if (instance != null && instance.lockstep != null)
     {
         instance.queuedBehaviours.Add(instance.NewManagedBehavior(trueSyncBehaviour));
     }
 }
        private TrueSyncManagedBehaviour NewManagedBehavior(ITrueSyncBehaviour trueSyncBehavior)
        {
            TrueSyncManagedBehaviour result = new TrueSyncManagedBehaviour(trueSyncBehavior);
            mapBehaviorToManagedBehavior[trueSyncBehavior] = result;

            return result;
        }
        // UTILS

        private TrueSyncManagedBehaviour NewManagedBehavior(ITrueSyncBehaviour i_TrueSyncBehavior)
        {
            TrueSyncManagedBehaviour result = new TrueSyncManagedBehaviour(i_TrueSyncBehavior);

            m_ManagedBehaviourMap[i_TrueSyncBehavior] = result;

            return(result);
        }
예제 #4
0
 public TrueSyncManagedBehaviour(ITrueSyncBehaviour trueSyncBehavior)
 {
     StateTracker.AddTracking(this);
     StateTracker.AddTracking(trueSyncBehavior);
     this.trueSyncBehavior = trueSyncBehavior;
 }
        private void OnStepUpdate(List <InputData> i_AllInputData)
        {
            // Sync time.

            if (m_TimeScaler != null)
            {
                m_TimeScaler.Sync();
            }

            // PRE SYNC UPDATE

            // Clear input.

            TrueSyncInput.SetAllInputs(null);

            // Synced pre update on general behaviours.

            for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index];

                if (tsmb == null || tsmb.disabled)
                {
                    continue;
                }

                tsmb.OnPreSyncedUpdate();
            }

            // Synced pre update on player behaviours.

            if (i_AllInputData != null)
            {
                for (int index = 0; index < i_AllInputData.Count; ++index)
                {
                    InputData inputData = i_AllInputData[index];

                    if (inputData == null)
                    {
                        continue;
                    }

                    List <TrueSyncManagedBehaviour> tsmbList = null;
                    if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList))
                    {
                        for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex)
                        {
                            TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex];

                            if (tsmb == null || tsmb.disabled)
                            {
                                continue;
                            }

                            tsmb.OnPreSyncedUpdate();
                        }
                    }
                }
            }

            // UPDATE

            // Set input.

            TrueSyncInput.SetAllInputs(i_AllInputData);

            TrueSyncInput.CurrentSimulationData = null;

            // Synced update on general behaviours.

            for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index];

                if (tsmb == null || tsmb.disabled)
                {
                    continue;
                }

                tsmb.OnSyncedUpdate();
            }

            // Synced update on player behaviours.

            if (i_AllInputData != null)
            {
                for (int index = 0; index < i_AllInputData.Count; ++index)
                {
                    InputData inputData = i_AllInputData[index];

                    if (inputData == null)
                    {
                        continue;
                    }

                    List <TrueSyncManagedBehaviour> tsmbList = null;
                    if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList))
                    {
                        TrueSyncInput.CurrentSimulationData = inputData;

                        for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex)
                        {
                            TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex];

                            if (tsmb == null || tsmb.disabled)
                            {
                                continue;
                            }

                            tsmb.OnSyncedUpdate();
                        }
                    }
                }

                TrueSyncInput.CurrentSimulationData = null;
            }

            // LATE UPDATE

            // Clear input.

            TrueSyncInput.SetAllInputs(null);

            // Synced late update on general behaviours.

            for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index];

                if (tsmb == null || tsmb.disabled)
                {
                    continue;
                }

                ITrueSyncBehaviour iTsb = tsmb.trueSyncBehavior;
                if (iTsb != null)
                {
                    if (iTsb is TrueSyncBehaviour)
                    {
                        TrueSyncBehaviour tsb = (TrueSyncBehaviour)iTsb;
                        tsb.OnLateSyncedUpdate();
                    }
                }
            }

            // Synced late update on player behaviours.

            if (i_AllInputData != null)
            {
                for (int index = 0; index < i_AllInputData.Count; ++index)
                {
                    InputData inputData = i_AllInputData[index];

                    if (inputData == null)
                    {
                        continue;
                    }

                    List <TrueSyncManagedBehaviour> tsmbList = null;
                    if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList))
                    {
                        for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex)
                        {
                            TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex];

                            if (tsmb == null || tsmb.disabled)
                            {
                                continue;
                            }

                            ITrueSyncBehaviour iTsb = tsmb.trueSyncBehavior;
                            if (iTsb != null)
                            {
                                if (iTsb is TrueSyncBehaviour)
                                {
                                    TrueSyncBehaviour tsb = (TrueSyncBehaviour)iTsb;
                                    tsb.OnLateSyncedUpdate();
                                }
                            }
                        }
                    }
                }
            }

            // Process queued behaviours.

            ProcessQueuedBehaviours();
        }