internal void StartProcessAction() { repeat--; for (int i = 0; i < m_Raw.actions.Count; i++) { FillActionCache(i); ActionThread thread = new ActionThread(this, index, i, m_Raw.actions[i], m_ActionCache[i]); thread.ProcessAction(); if (!thread.isFinished) { mission.scenario.AddActionThread(thread); RegisterActionThreadEvent(thread); } } if (m_ThreadCounter != 0 && !multiThreaded) { // Disable Condition enabled = false; } }
internal void UnregisterActionThreadEvent(ActionThread thread) { m_ThreadCounter = System.Math.Max(0, m_ThreadCounter - 1); thread.onFinished -= OnActionThreadFinished; }
internal void RegisterActionThreadEvent(ActionThread thread) { m_ThreadCounter = System.Math.Min(0, m_ThreadCounter + 1); thread.onFinished += OnActionThreadFinished; }
internal void AddActionThread(ActionThread thread) { m_ActionThreads.Add(thread); }
/// <summary>Restore the scenario data from a opening stream</summary> public void Import(BinaryReader r) { int version = r.ReadInt32(); switch (version) { case 0x00000001: { m_Pause = true; int count = r.ReadInt32(); m_MaxMissionId = 0; for (int i = 0; i < count; i++) { int instId = r.ReadInt32(); int dataId = r.ReadInt32(); bool enabled = r.ReadBoolean(); if (!m_MissionRaws.ContainsKey(dataId)) { throw new System.Exception("Mission raw data of id [" + dataId.ToString() + "] is missing"); } Mission mis = new Mission(instId, m_MissionRaws[dataId], this); mis.Init(); int trg_cnt = r.ReadInt32(); if (trg_cnt != mis.triggers.Length) { throw new System.Exception("Trigger count is not correct"); } for (int j = 0; j < trg_cnt; j++) { mis.triggers[j].Import(r); } VarScope vs = Variables.CreateChild(); vs.Import(r); MissionVariables[mis] = vs; m_MissionInsts.Add(instId, mis); if (enabled) { //mis.Resume(); m_RunningMissions.Add(dataId, mis); } if (instId > m_MaxMissionId) { m_MaxMissionId = instId; } } Variables.Import(r); // restore action thread count = r.ReadInt32(); for (int i = 0; i < count; i++) { int instId = r.ReadInt32(); int dataId = r.ReadInt32(); int trigger_idx = r.ReadInt32(); int group = r.ReadInt32(); int cur_idx = r.ReadInt32(); if (!m_MissionRaws.ContainsKey(dataId)) { throw new System.Exception("Mission raw data of id [" + dataId.ToString() + "] is missing"); } if (!m_MissionInsts.ContainsKey(instId)) { throw new System.Exception("Mission instance of instId [" + dataId.ToString() + "] is missing"); } MissionRaw mis_raw = m_MissionRaws[dataId]; ActionThread thread = null; Mission mis = m_MissionInsts[instId]; mis.triggers[trigger_idx].FillActionCache(group); thread = new ActionThread(mis.triggers[trigger_idx], trigger_idx, group, mis_raw.triggers[trigger_idx].actions[group], mis.triggers[trigger_idx].GetActionCache(group), cur_idx); mis.triggers[trigger_idx].RegisterActionThreadEvent(thread); AddActionThread(thread); thread.CreateCurrAction(); if (thread.currAction != null) { thread.currAction.RestoreState(r); } } } break; } }