Пример #1
0
        public HumanPrefabMapping()
        {
            _helper = MonitorHelper.Instance;
            _data   = HumanMonitorData.Instance;

            _mapping = new PrefabMapping <uint>();
        }
        public HumanPrefabMapping()
        {
            _helper = MonitorHelper.Instance;
            _data = HumanMonitorData.Instance;

            _mapping = new PrefabMapping<uint>();
        }
Пример #3
0
        /*
         * Handles creation and removal of humans
         *
         * Note: Just because a human has been removed visually, it does not mean
         * it is removed as far as the game is concerned. The human is only truly removed
         * when the frame covers the human's id, and that's when we will remove the
         * human from our records.
         */
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            if (_terminated)
            {
                return;
            }

            if (!_helper.HumanMonitorSpinnable)
            {
                return;
            }

            try
            {
                if (!_initialized)
                {
                    _data = HumanMonitorData.Instance;

                    _mapping = new HumanPrefabMapping();

                    _paused = false;

                    _citizenManager = Singleton <CitizenManager> .instance;
                    _capacity       = _citizenManager.m_citizens.m_buffer.Length;

                    _id = (uint)_capacity;

                    for (int i = 0; i < _capacity; i++)
                    {
                        UpdateHuman((uint)i);
                    }

                    _lastProcessedFrame = GetFrame();

                    _initialized             = true;
                    _helper.HumanMonitorSpun = true;
                    _helper.HumanMonitor     = this;

                    Logger.Log("Human monitor initialized");
                }
                else if (!SimulationManager.instance.SimulationPaused)
                {
                    _data._HumansUpdated.Clear();
                    _data._HumansRemoved.Clear();

                    int end = GetFrame();

                    while (_lastProcessedFrame != end)
                    {
                        _lastProcessedFrame = GetFrame(_lastProcessedFrame + 1);

                        int[] boundaries = GetFrameBoundaries();
                        uint  id;

                        for (int i = boundaries[0]; i <= boundaries[1]; i++)
                        {
                            id = (uint)i;

                            if (UpdateHuman(id))
                            {
                                _data._HumansUpdated.Add(id);
                            }
                            else if (_data._Humans.Contains(id))
                            {
                                _data._HumansRemoved.Add(id);
                                RemoveHuman(id);
                            }
                        }
                    }
                }

                OutputDebugLog();
            }
            catch (Exception e)
            {
                string error = "Human monitor failed to initialize\r\n";
                error += String.Format("Error: {0}\r\n", e.Message);
                error += "\r\n";
                error += "==== STACK TRACE ====\r\n";
                error += e.StackTrace;

                Logger.Log(error);

                _terminated = true;
            }

            base.OnUpdate(realTimeDelta, simulationTimeDelta);
        }
        /*
         * Handles creation and removal of humans
         *
         * Note: Just because a human has been removed visually, it does not mean
         * it is removed as far as the game is concerned. The human is only truly removed
         * when the frame covers the human's id, and that's when we will remove the
         * human from our records.
         */
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            if (_terminated) return;

            if (!_helper.HumanMonitorSpinnable) return;

            try
            {
                if (!_initialized)
                {
                    _data = HumanMonitorData.Instance;

                    _mapping = new HumanPrefabMapping();

                    _paused = false;

                    _citizenManager = Singleton<CitizenManager>.instance;
                    _capacity = _citizenManager.m_citizens.m_buffer.Length;

                    _id = (uint)_capacity;

                    for (int i = 0; i < _capacity; i++)
                        UpdateHuman((uint)i);

                    _lastProcessedFrame = GetFrame();

                    _initialized = true;
                    _helper.HumanMonitorSpun = true;
                    _helper.HumanMonitor = this;

                    Logger.Log("Human monitor initialized");
                }
                else if (!SimulationManager.instance.SimulationPaused)
                {
                    _data._HumansUpdated.Clear();
                    _data._HumansRemoved.Clear();

                    int end = GetFrame();

                    while (_lastProcessedFrame != end)
                    {
                        _lastProcessedFrame = GetFrame(_lastProcessedFrame + 1);

                        int[] boundaries = GetFrameBoundaries();
                        uint id;

                        for (int i = boundaries[0]; i <= boundaries[1]; i++)
                        {
                            id = (uint)i;

                            if (UpdateHuman(id)) {
                                _data._HumansUpdated.Add(id);
                            } else if (_data._Humans.Contains(id)) {
                                _data._HumansRemoved.Add(id);
                                RemoveHuman(id);
                            }
                        }
                    }
                }

                OutputDebugLog();
            }
            catch (Exception e)
            {
                string error = "Human monitor failed to initialize\r\n";
                error += String.Format("Error: {0}\r\n", e.Message);
                error += "\r\n";
                error += "==== STACK TRACE ====\r\n";
                error += e.StackTrace;

                Logger.Log(error);

                _terminated = true;
            }

            base.OnUpdate(realTimeDelta, simulationTimeDelta);
        }