/// <summary> /// Default AchievementManager constructor. Hidden to enforce singleton pattern. /// </summary> private AchievementManager() { achis = new List<Achievement>(); state = ManagerState.Uninitialized; eventReg = new Dictionary<string,List<Achievement>>(); unregQueue = new List<Tuple<string,Achievement>>(); }
public void GoToAIPanel() { state = ManagerState.Menu; ManagerInterface.SelectedIndex = 0; GameControl.Content = null; quatroInterface = null; }
public Manager() { additionalCashier = 0; state = ManagerState.Thinking; //maxNumberCashier = Store.Get().StoreParams.MaximumServicePoints; Store.Get().SPS.RegisterObserver(this); //Manager needs to be registerd here too!! Thread t = new Thread(new ThreadStart(this.Begin)); //t.Priority = ThreadPriority.AboveNormal; t.Start(); }
public override void Start() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Start) return; _state = ManagerState.Start; this.Update(); } } }
public MainWindow() { InitializeComponent(); state = ManagerState.Menu; allAIs = getPossibleAIs(); player1AIs.ItemsSource = allAIs; player2AIs.ItemsSource = allAIs; StartGameButton.Click += StartGameButton_Click; }
private void OnListenerConnectionClosed(object sender, EventArgs args) { if (this.listenerConnection == null) { return; } this.isListener = false; this.listenerConnection.Disconnected -= this.OnListenerConnectionDisconnected; this.listenerConnection.Closed -= this.OnListenerConnectionClosed; this.listenerConnection.Dispose(); this.listenerConnection = null; this.ManagerState = ManagerState.Idle; }
public override void Stop() { this.Check(); lock (_lockObject) { if (this.State == ManagerState.Stop) { return; } _state = ManagerState.Stop; _connectionManager.Stop(); _coreManager.Stop(); } }
public override void Start() { if (_disposed) { throw new ObjectDisposedException(this.GetType().FullName); } using (DeadlockMonitor.Lock(this.ThisLock)) { if (this.State == ManagerState.Start) { return; } _state = ManagerState.Start; } }
public static ManagerState LoadManagerState(string _name) { string path = Path.Combine(Application.persistentDataPath, "ManagerStates"); string file = Path.Combine(path, _name + ".mstate"); FileInfo info = new FileInfo(file); if (info.Exists == false) { return(new ManagerState()); } BinaryFormatter bf = new BinaryFormatter(); FileStream stream = File.Open(file, FileMode.Open); ManagerState state = bf.Deserialize(stream) as ManagerState; stream.Close(); return(state); }
void OnConfirmationGUI() { // Show warning EditorGUILayout.HelpBox("Warning: This process is not reversible and modifies a lot of files.\n\nMake sure all scenes are saved (including the open scene) and you have an up to date backup in case anything gose wrong.", MessageType.Warning); // OK if (GUILayout.Button("Yes, I have a backup")) { ApplyLayerModifications(); } // Cancel if (GUILayout.Button("No, I'm not ready yet")) { m_State = ManagerState.Editing; } }
public override void Stop() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Stop) { return; } _state = ManagerState.Stop; } _watchThread.Join(); _watchThread = null; } }
// Update is called once per frame void FixedUpdate() { switch (_state) { case ManagerState.ADDCOLLECTIBLE: AddCollectibleBehaviour(); _state = ManagerState.IDLE; break; case ManagerState.RESET: StopAllCoroutines(); ResetBehaviour(); powerUpInfoManager.Clear(); _state = ManagerState.IDLE; break; } }
public void SetWaves(List <Wave> waves) { _waveQueue = new Queue <Wave>(); _enemyQueue = new Queue <EnemySchedule>(); _currentManagerState = ManagerState.Active; WaveCount = waves.Count; for (int i = 0; i < waves.Count; i++) { _waveQueue.Enqueue(waves[i]); } SetNextWave(); _currentManagerState = ManagerState.WaitForTowers; }
public void Startup() { State = ManagerState.Active; _httpClient = new HttpClient { BaseAddress = new Uri(baseUrl), DefaultRequestHeaders = { Accept = { new MediaTypeWithQualityHeaderValue("application/json") } }, Timeout = TimeSpan.FromSeconds(pollingInterval - 1f) }; _isPolling = true; PollAsync(); }
/** * Initializes the wave manager with the stage to process * @param stage The stage to process */ public void Init(Stage stage, Transform parent) { waveIndexes.Clear(); currentWaves.Clear(); timer = 0.0f; this.parent = parent; currenteStage = stage; managerState = ManagerState.ManagerBegin; int waveCount = currenteStage.StageWaves.Count; for (int nWave = 0; nWave < waveCount; ++nWave) { waveIndexes.Add(nWave); } }
internal virtual void Draw(RendererBatch batch) { State = ManagerState.ThrowError; C child; for (int i = 0; i < Children.Count; i++) { child = Children[i]; if (child.IsVisible) { child.DrawInternally(batch); } } State = ManagerState.Opened; }
internal virtual void Update(float deltaTime) { State = ManagerState.Queue; C child; for (int i = 0; i < Children.Count; i++) { child = Children[i]; if (child.IsActive) { child.UpdateInternally(deltaTime); } } State = ManagerState.Opened; }
IEnumerator ClosingManager() { state = ManagerState.CLOSING; bool closeCompleted = false; // 开始关闭 foreach (KeyValuePair <GameObject, Child> objChild in windowChilds) { CloseChild(objChild.Value); } foreach (KeyValuePair <GameObject, Child> objChild in panelsChilds) { CloseChild(objChild.Value); } // 检查是否全部关闭 while (!closeCompleted) { closeCompleted = true; foreach (KeyValuePair <GameObject, Child> objChild in windowChilds) { if (!IsChildClosed(objChild.Value)) { closeCompleted = false; break; } } foreach (KeyValuePair <GameObject, Child> objChild in panelsChilds) { if (!closeCompleted) { break; } if (!IsChildClosed(objChild.Value)) { closeCompleted = false; break; } } yield return(new WaitForEndOfFrame()); } state = ManagerState.CLOSED; this.gameObject.SetActive(false); }
private void SwitchManagerState(ManagerState state) { if (_generatingState == state) { return; } switch (_generatingState) { case ManagerState.NONE: ExitNoneState(); break; case ManagerState.GENERATING: ExitGeneratingState(); break; case ManagerState.SETTLEMENT: ExitSettlementState(); break; case ManagerState.HIDING: ExitHidingState(); break; } _generatingState = state; switch (_generatingState) { case ManagerState.NONE: InitNoneState(); break; case ManagerState.GENERATING: InitGeneratingState(); break; case ManagerState.SETTLEMENT: InitSettlementState(); break; case ManagerState.HIDING: InitHidingState(); break; } }
public override void Stop() { lock (_stateLock) { lock (this.ThisLock) { if (this.State == ManagerState.Stop) { return; } _state = ManagerState.Stop; } _watchTimer.Change(Timeout.Infinite); _uploadThread.Join(); _uploadThread = null; } }
public override void Start() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Start) { return; } _state = ManagerState.Start; _watchThread = new Thread(this.WatchThread); _watchThread.Priority = ThreadPriority.Lowest; _watchThread.Name = "TransfarLimitManager_WatchThread"; _watchThread.Start(); } } }
void select() { if (now_count < max_count)//開始分裂 { state = ManagerState.split; return; } if (batch_stack.Count > 0) { state = ManagerState.merge; return; } else { state = ManagerState.init; root_node.reset_is_click(); } }
private void Manager(ManagerState state) { switch (state) { case ManagerState.OFF: btnAdd.Enabled = false; btnCancel.Enabled = false; btnCheck.Enabled = false; btnNewUser.Enabled = false; btnRecharge.Enabled = false; radioAdmin.Enabled = false; radioOperation.Enabled = false; UID = null; break; case ManagerState.OPERATION: btnAdd.Enabled = false; btnCancel.Enabled = false; btnCheck.Enabled = false; btnNewUser.Enabled = false; btnRecharge.Enabled = false; radioAdmin.Enabled = true; radioOperation.Enabled = true; UID = null; break; case ManagerState.ADMIN: btnAdd.Enabled = false; btnCancel.Enabled = false; btnCheck.Enabled = true; btnNewUser.Enabled = true; btnRecharge.Enabled = true; radioAdmin.Enabled = true; radioOperation.Enabled = true; txtContact.Clear(); txtID.Clear(); txtName.Clear(); break; default: break; } }
private void LoadWaveEnemy() { switch (_currentManagerState) { case (ManagerState.Prep): return; case (ManagerState.Active): if ((Time.time - _spawntimedinterval) > delay) { EnemySchedule es = _enemyQueue.Dequeue(); SpawnEnemy(es.token); if (_enemyQueue.Count == 0) { SetNextWave(); } ResetTime(); } break; case (ManagerState.Done): return; case (ManagerState.WaitForPrevWave): if (GetActiveCount() == 0) { _currentManagerState = ManagerState.Active; _spawntimedinterval = Time.time; if (OnWaveStarted != null) { OnWaveStarted(); Debug.Log("wave triggered"); } } break; case (ManagerState.WaitForTowers): return; } }
void Initialise() { // Create & attach scriptable object (allows undos, etc) if (m_Data == null) { m_Data = CreateInstance <LayerManagerData>(); m_Data.Initialise(); } // Get fixed layers m_FixedLayers = new string[8]; for (int i = 0; i < 8; ++i) { m_FixedLayers[i] = LayerMask.LayerToName(i); } // Create reorderable list m_LayerList = new ReorderableList( m_Data.serializedObject, m_Data.layerMapProperty, true, true, false, false ); m_LayerList.drawHeaderCallback = DrawLayerMapHeader; m_LayerList.drawElementCallback = DrawLayerMapElement; m_LayerList.elementHeight = lineHeight * 2 + lineSpacing * 3; m_LayerList.onReorderCallback = OnLayerMapReorder; // Reset state m_State = ManagerState.Editing; // Reset reporting m_SceneCount = 0; m_PrefabCount = 0; m_ObjectCount = 0; m_ComponentCount = 0; m_AssetCount = 0; m_LayerMaskCount = 0; m_PhysicsMatrixCompleted = false; m_Physics2DMatrixCompleted = false; m_Errors.Clear(); m_CompletionReport = string.Empty; }
//Next action in queue public void NextAction() { //If there are still actions or agent hasn't reached the goal, get and start next action. Otherwise change state to COMPLETED plan if (actions.Count > 0) { IGroundAction action = actions.Dequeue(); currentAction = action; //Start action action.Start(this, agent.state); } else if (actions.Count == 0 || RuleMatcher.MatchCondition(agent.goalCondition, agent.state, agent.logicalOperator)) { state = ManagerState.EMPTY; currentAction = null; } }
public override void Start() { if (_disposed) { throw new ObjectDisposedException(this.GetType().FullName); } lock (_stateLock) { lock (this.ThisLock) { if (this.State == ManagerState.Start) { return; } _state = ManagerState.Start; _watchTimer.Change(0, 1000 * 10); } } }
public override void Stop() { lock (_stateLockObject) { lock (_lockObject) { if (this.State == ManagerState.Stop) { return; } _state = ManagerState.Stop; } _watchTimer.Stop(); _catharsisManager.Stop(); _tcpConnectionManager.Stop(); _i2pConnectionManager.Stop(); _customConnectionManager.Stop(); } }
public virtual void Stop() { if (_isDisposed) { throw new ObjectDisposedException(nameof(PortManager)); } lock (_stateLocker) { if (GetCurrentState() == ManagerState.Running) { Log.Info(nameof(PortManager), "Stop requested"); _managerState = ManagerState.Stopping; } } if (_runCancellationSource != null && !_runCancellationSource.IsCancellationRequested) { _runCancellationSource.Cancel(); } }
public override void Start() { lock (_stateLock) { lock (this.ThisLock) { if (this.State == ManagerState.Start) { return; } _state = ManagerState.Start; _watchTimer.Change(0, 1000 * 60 * 10); _uploadThread = new Thread(this.UploadThread); _uploadThread.Priority = ThreadPriority.Lowest; _uploadThread.Name = "UploadManager_UploadManagerThread"; _uploadThread.Start(); } } }
public override void Stop() { lock (_stateLockObject) { lock (_lockObject) { if (this.State == ManagerState.Stop) { return; } _state = ManagerState.Stop; } _downloadTaskManager.Stop(); foreach (var taskManager in _decodeTaskManagers) { taskManager.Stop(); } } }
public override void Start() { lock (_stateLockObject) { lock (_lockObject) { if (this.State == ManagerState.Start) { return; } _state = ManagerState.Start; _catharsisManager.Start(); _tcpConnectionManager.Start(); _i2pConnectionManager.Start(); _customConnectionManager.Start(); _watchTimer.Start(new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 30)); } } }
public Manager(Shop shop) { this.countOfBuyersFromAllStends = new List <Buyer>(); this.profit = 0; this.productName = new List <string>(); productName.Add("Шоколад"); productName.Add("Мороженное"); productName.Add("Напитки"); CountOfVisitedBuyers = 0; this.managerState = ManagerState.NotWork; this.stends = new List <Stand>(3); for (int i = 0; i < stends.Capacity; i++) { this.stends.Add(new Stand(this.productName[i], (i + 1) * 1.0M)); } foreach (Stand stend in this.stends) { stend.ReturnBuyerToManager += new ReturnBuyer(RizeVisitor); } this.stendsThread = new List <Thread>(this.stends.Count); for (int i = 0; i < this.stends.Count; i++) { this.stendsThread.Add(new Thread(this.stends[i].StartToWork)); this.stendsThread[i].Name = this.stends[i].ProductName + "Thread"; } this.managerState = ManagerState.NotWork; this.shop = shop; this.shop.RizeNewVisitor += new NewVisitor(RizeVisitor); foreach (Stand stend in this.stends) { stend.FinishedWork += new FinishedWorkStend(Stend_FinishedWork); } }
private void HandleKeyInput() { if (Input.GetKeyDown(KeyCode.R)) { Debug.Log("Re-Initialize histogram"); currentState = ManagerState.REINIT_HIST; } else if (Input.GetKeyDown(KeyCode.N)) { //Debug.Log( "Processing one frame" ); currentState = ManagerState.PROCESS_FRAME; } else if (Input.GetKeyDown(KeyCode.B)) { Debug.Log("Processing video"); currentState = ManagerState.PROCESS_VIDEO; } else if (Input.GetKeyDown(KeyCode.P)) { Debug.Log("Paused.."); } }
private void StartConnector(string url) { if (this.Manager.EnableMRC) { return; } StopConnector(); this.ManagerState = ManagerState.ConnectorStarting; this.connector = new Connector { ConnectionUrl = url }; if (this.connector != null) { this.connector.Started += this.OnConnectorStarted; this.connector.Connected += this.OnConnectorConnected; this.connector.Failed += this.OnConnectorFailed; this.connector.StartAsync(); } }
public void StartGame() { state = ManagerState.Playing; ManagerInterface.SelectedIndex = 1; //fecth selection int AI1 = player1AIs.SelectedIndex; int AI2 = player2AIs.SelectedIndex; //In case of unselected AI's, go with first one if (AI1 == -1) AI1 = 0; if (AI2 == -1) AI2 = 0; QuatroPlayer player1 = allAIs[AI1].creator(); QuatroPlayer player2 = allAIs[AI2].creator(); QuatroOptions options = new QuatroOptions(); switch(automaticComboBox.SelectedIndex) { case 0: options.automaticPlay = QuatroOptions.AutomaticPlay.StepAnalysis; break; case 1: options.automaticPlay = QuatroOptions.AutomaticPlay.Regular; break; case 2: options.automaticPlay = QuatroOptions.AutomaticPlay.Automatic; break; } options.turnSeconds = 10f; quatroInterface = new QuatroInterface(player1, player2, options); quatroInterface.Finished += GoToAIPanel; GameControl.Content = quatroInterface; }
public void EncodeStop() { lock (_encodeStateLock) { lock (_thisLock) { if (this.EncodeState == ManagerState.Stop) return; _encodeState = ManagerState.Stop; } { foreach (var thread in _encodeThreads) { thread.Join(); } _encodeThreads.Clear(); } } }
public override void Start() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Start) return; _state = ManagerState.Start; _watchThread = new Thread(this.WatchThread); _watchThread.Priority = ThreadPriority.Lowest; _watchThread.Name = "OverlayNetworkManager_WatchThread"; _watchThread.Start(); } } }
public override void Stop() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Stop) return; _state = ManagerState.Stop; } _watchThread.Join(); _watchThread = null; if (_samManager != null) _samManager.Dispose(); _samManager = null; lock (_thisLock) { if (_settings.I2pUri != null) { if (this.RemoveUri(_settings.I2pUri)) Log.Information(string.Format("Remove Node uri: {0}", _settings.I2pUri)); } _settings.I2pUri = null; } } }
public override void Start() { lock (_stateLock) { lock (this.ThisLock) { if (this.State == ManagerState.Start) return; _state = ManagerState.Start; _watchThread = new Thread(this.WatchThread); _watchThread.Priority = ThreadPriority.Lowest; _watchThread.Name = "TransfarLimitManager_WatchThread"; _watchThread.Start(); } } }
public override void Stop() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Stop) return; _state = ManagerState.Stop; } _encodeThread.Join(); _encodeThread = null; _watchTimer.Change(Timeout.Infinite); } }
/// <summary> /// 传入非空集合表示Agent想要碰。 /// Dealer需要判断碰是否合法(和当前的targetCard进行比对) /// </summary> public void AskForPengCallback(List<Card> pengCards, int agentIndex) { if (pengCards == null) { currentAgentIndex = GetNextIndex(agentIndex); } else { currentState = ManagerState.ASK_PLAY; } }
/// <summary> /// 不可传入空值,表示Agent打某张牌 /// </summary> public void AskForPlayCallback(Card playCard, int agentIndex) { currentState = ManagerState.ASK_DIAN_PAO; targetCard = playCard; agents[currentAgentIndex].cards.Remove(playCard); //agents[currentAgentIndex].playedCards.Add(playCard); agents[currentAgentIndex].cards.Sort(); currentAgentIndex = GetNextIndex(agentIndex); }
public override void Stop() { this.Check(); lock (this.ThisLock) { if (this.State == ManagerState.Stop) return; _state = ManagerState.Stop; _backgroundUploadManager.Stop(); _backgroundDownloadManager.Stop(); _uploadManager.Stop(); _downloadManager.Stop(); _connectionsManager.Stop(); _serverManager.Stop(); } }
private void ReadImpl() { List<IntPtr> dead = null, active = new List<IntPtr>(); List<ISocketCallback> activeCallbacks = new List<ISocketCallback>(); IntPtr[] readSockets = EmptyPointers, errorSockets = EmptyPointers; long lastHeartbeat = Environment.TickCount; SocketPair[] allSocketPairs = null; while (true) { managerState = ManagerState.CheckForHeartbeat; active.Clear(); activeCallbacks.Clear(); if (dead != null) dead.Clear(); // this check is actually a pace-maker; sometimes the Timer callback stalls for // extended periods of time, which can cause socket disconnect long now = Environment.TickCount; if (unchecked(now - lastHeartbeat) >= 15000) { managerState = ManagerState.ExecuteHeartbeat; lastHeartbeat = now; lock (socketLookup) { if (allSocketPairs == null || allSocketPairs.Length != socketLookup.Count) allSocketPairs = new SocketPair[socketLookup.Count]; socketLookup.Values.CopyTo(allSocketPairs, 0); } foreach (var pair in allSocketPairs) { var callback = pair.Callback; if (callback != null) try { callback.OnHeartbeat(); } catch { } } } managerState = ManagerState.LocateActiveSockets; lock (socketLookup) { if (isDisposed) return; if (socketLookup.Count == 0) { // if empty, give it a few seconds chance before exiting managerState = ManagerState.NoSocketsPause; Monitor.Wait(socketLookup, TimeSpan.FromSeconds(20)); if (socketLookup.Count == 0) return; // nothing new came in, so exit } managerState = ManagerState.PrepareActiveSockets; foreach (var pair in socketLookup) { var socket = pair.Value.Socket; if (socket.Handle == pair.Key && socket.Connected) if (pair.Value.Socket.Connected) { active.Add(pair.Key); activeCallbacks.Add(pair.Value.Callback); } else { (dead ?? (dead = new List<IntPtr>())).Add(pair.Key); } } if (dead != null && dead.Count != 0) { managerState = ManagerState.CullDeadSockets; foreach (var socket in dead) socketLookup.Remove(socket); } } int pollingSockets = active.Count; if (pollingSockets == 0) { // nobody had actual sockets; just sleep managerState = ManagerState.NoActiveSocketsPause; Thread.Sleep(10); continue; } if (readSockets.Length < active.Count + 1) { managerState = ManagerState.GrowingSocketArray; ConnectionMultiplexer.TraceWithoutContext("Resizing socket array for " + active.Count + " sockets"); readSockets = new IntPtr[active.Count + 6]; // leave so space for growth errorSockets = new IntPtr[active.Count + 6]; } managerState = ManagerState.CopyingPointersForSelect; readSockets[0] = errorSockets[0] = (IntPtr)active.Count; active.CopyTo(readSockets, 1); active.CopyTo(errorSockets, 1); int ready; try { var timeout = new TimeValue(1000); managerState = ManagerState.ExecuteSelect; ready = select(0, readSockets, null, errorSockets, ref timeout); managerState = ManagerState.ExecuteSelectComplete; if (ready <= 0) // -ve typically means a socket was disposed just before; just retry { bool hasWorkToDo = false; if (ready == 0) { managerState = ManagerState.CheckForStaleConnections; foreach (var s in activeCallbacks) { if (s.IsDataAvailable) { hasWorkToDo = true; } else { s.CheckForStaleConnection(); } } } else { lastErrorTicks = Environment.TickCount; } if (!hasWorkToDo) { continue; } } ConnectionMultiplexer.TraceWithoutContext((int)readSockets[0] != 0, "Read sockets: " + (int)readSockets[0]); ConnectionMultiplexer.TraceWithoutContext((int)errorSockets[0] != 0, "Error sockets: " + (int)errorSockets[0]); } catch (Exception ex) { // this typically means a socket was disposed just before; just retry Trace.WriteLine(ex.Message); continue; } bool haveWork = false; int queueCount = (int)readSockets[0]; if (queueCount != 0) { managerState = ManagerState.EnqueueRead; lock (readQueue) { for (int i = 1; i <= queueCount; i++) { var callback = GetCallback(readSockets[i]); if (callback != null) { readQueue.Enqueue(callback); haveWork = true; } } } } queueCount = (int)errorSockets[0]; if (queueCount != 0) { managerState = ManagerState.EnqueueError; lock (errorQueue) { for (int i = 1; i <= queueCount; i++) { var callback = GetCallback(errorSockets[i]); if (callback != null) { errorQueue.Enqueue(callback); haveWork = true; } } } } if(!haveWork) { // edge case: select is returning 0, but data could still be available managerState = ManagerState.EnqueueReadFallback; lock (readQueue) { foreach (var callback in activeCallbacks) { if(callback.IsDataAvailable) { readQueue.Enqueue(callback); } } } } if (ready >= 5) // number of sockets we should attempt to process by ourself before asking for help { // seek help, work in parallel, then synchronize var obj = new QueueDrainSyncLock(this); lock (obj) { managerState = ManagerState.RequestAssistance; ThreadPool.QueueUserWorkItem(HelpProcessItems, obj); managerState = ManagerState.ProcessQueues; ProcessItems(true); if (!obj.Consume()) { // then our worker arrived and picked up work; we need // to let it finish; note that if it *didn't* get that far // yet, the Consume() call will mean that it never tries Monitor.Wait(obj); } } } else { // just do it ourself managerState = ManagerState.ProcessQueues; ProcessItems(true); } } }
public override void Start() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Start) return; _state = ManagerState.Start; _encodeThread = new Thread(this.EncodeThread); _encodeThread.Priority = ThreadPriority.Lowest; _encodeThread.Name = "BackgroundUploadManager_EndocdeThread"; _encodeThread.Start(); _watchTimer.Change(0, 1000 * 60 * 10); } } }
public void DecodeStop() { this.Check(); lock (this.ThisLock) { if (this.DecodeState == ManagerState.Stop) return; _decodeState = ManagerState.Stop; _downloadManager.DecodeStop(); } }
public void EncodeStart() { lock (_encodeStateLock) { lock (_thisLock) { if (this.EncodeState == ManagerState.Start) return; _encodeState = ManagerState.Start; for (int i = 0; i < _threadCount; i++) { var thread = new Thread(this.EncodeThread); thread.Priority = ThreadPriority.BelowNormal; thread.Name = "UploadManager_EncodeThread"; thread.Start(); _encodeThreads.Add(thread); } } } }
public override void Stop() { if (_disposed) throw new ObjectDisposedException(this.GetType().FullName); lock (_stateLock) { lock (this.ThisLock) { if (this.State == ManagerState.Stop) return; _state = ManagerState.Stop; _watchTimer.Change(Timeout.Infinite); foreach (var tcpListener in _tcpListeners.Values) { tcpListener.Stop(); } _tcpListeners.Clear(); _oldListenUris.Clear(); } } }
public override void Start() { if (_disposed) throw new ObjectDisposedException(this.GetType().FullName); lock (_stateLock) { lock (this.ThisLock) { if (this.State == ManagerState.Start) return; _state = ManagerState.Start; _watchTimer.Change(0, 1000 * 10); } } }
public override void Stop() { lock (_stateLock) { lock (this.ThisLock) { if (this.State == ManagerState.Stop) return; _state = ManagerState.Stop; } } }
public override void Stop() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Stop) return; _state = ManagerState.Stop; } _watchThread.Join(); _watchThread = null; } }
public override void Start() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Start) return; _state = ManagerState.Start; _watchTimer.Change(0, 1000 * 60); } } }
public void ProcessSelf() { System.Threading.Thread.Sleep(10); switch (state) { case ManagerState.Thinking: //Think what to do if (Store.Get().open == false) { state = ManagerState.OpeningStore; } else //the case the store is already opened! { //if (Store.Get().CustomerPool.Count > 5) //{ state = ManagerState.ManagingCashier; //} //else if (Store.Get().CustomerPool.Count == 0) //{ // state = ManagerState.ClosingStore; //} } break; case ManagerState.TakingBreak: if (!Store.Get().StoreParams.ManagerCanBreak) { state = ManagerState.Thinking; break; } //Wait for Finding Item Program.Debug("Manager -> Breaking!!!"); System.Threading.Thread.Sleep(Store.Get().StoreParams.ManagerBreakTime); /////////////////////////////////// Program.Debug("Manager -> Not Breaking!!!"); state = ManagerState.Thinking; break; case ManagerState.OpeningStore: Store.Get().open = true; Program.Debug("Open up the Store"); System.Threading.Thread.Sleep(100); state = ManagerState.Thinking; break; case ManagerState.ClosingStore: //need to get rid of all of the customers. NOOOOOOOOOOOOOOOOOOOOOOOOO //need to not receive any more customers!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Store.Get().open = false; // Program.Debug("Store Closed"); // System.Threading.Thread.Sleep(15000); //sleep 50 sec // state = ManagerState.TakingBreak; state = ManagerState.Thinking; break; case ManagerState.ManagingCashier: AdjustNumberOfCashier(); System.Threading.Thread.Sleep(Store.Get().StoreParams.ManagerBreakTime); state = ManagerState.Thinking; break; } }
public void EncodeStop() { this.Check(); lock (this.ThisLock) { if (this.EncodeState == ManagerState.Stop) return; _encodeState = ManagerState.Stop; _uploadManager.EncodeStop(); } }
public void AskForAnGangCallback(List<Card> gangCards, int agentIndex) { if (gangCards == null) { currentState = ManagerState.ASK_PLAY; } else { currentState = ManagerState.ASK_PICK; } }
public override void Stop() { lock (_stateLock) { lock (_thisLock) { if (this.State == ManagerState.Stop) return; _state = ManagerState.Stop; } _watchTimer.Change(Timeout.Infinite); } }
public void AskForZiMoCallback(bool isHu, int agentIndex) { if (isHu) { End("自摸(" + agentIndex + ")"); } else { currentState = ManagerState.ASK_AN_GANG; } }
/// <summary> /// 传入非空集合表示Agent想要吃, /// 需要判断吃是否合法(和当前targetCard进行比对,并且需要和currentAgentIndex进行比对) /// 没有吃,下家抓牌。否则下家打牌 /// </summary> public void AskForChiCallback(List<Card> chiCards, int agentIndex) { if (chiCards == null) { currentState = ManagerState.ASK_PICK; currentAgentIndex = GetNextIndex(currentAgentIndex); } else { currentState = ManagerState.ASK_PLAY; currentAgentIndex = GetNextIndex(currentAgentIndex); } }
/// <summary> /// 牌局下一步 /// /// 在这个阶段,当前Agent已经抓过牌了。 /// 如果没抓过牌那是Manager的问题不是Agent的问题 /// /// *这里只考虑询问,不考虑响应* /// /// 另外,考虑再三,为了调试方便,还是采用了步进调试方式。 /// 待步进调试方式写好后,增加自动机 /// /// </summary> public void NextStep() { Agent currentAgent = agents[currentAgentIndex]; switch (currentState) { case ManagerState.ASK_PICK: // 如果deck的容量为0,表示所有的牌都抓没了,牌局结束 if (deck.Count == 0) { End("流局"); } else { agents[currentAgentIndex].PickCard(deck[0]); deck.RemoveAt(0); // 抓牌后立刻进入下一个状态,没有任何分支 currentState = ManagerState.ASK_ZI_MO; targetAgentIndex = currentAgentIndex; // 抓牌决定目标玩家 } break; case ManagerState.ASK_ZI_MO: currentAgent.AskForZiMo(); break; case ManagerState.ASK_AN_GANG: currentAgent.AskForAnGang(); break; case ManagerState.ASK_PLAY: currentAgent.AskForPlay(); break; case ManagerState.ASK_DIAN_PAO: if (targetCard != null) { // 在上一个Agent打出牌以后,就将currentAgentIndex+1了, // 是在Callback中操作的。所有这里如果出现了相等,就表明已经轮询了一圈 // 为了回避开自己,在进入碰的状态之前,currentAgentIndex +1 if (targetAgentIndex == currentAgentIndex) { currentAgentIndex = GetNextIndex(targetAgentIndex); currentState = ManagerState.ASK_PENG; NextStep(); } else { currentAgent.AskForHu(this.targetCard); } } break; case ManagerState.ASK_PENG: if (targetCard != null) { // 在进入碰的状态之前,currengAgentIndex = GetNextIndex(targetAgentIndex), if (targetAgentIndex == currentAgentIndex) { currentState = ManagerState.ASK_CHI; NextStep(); } else { currentAgent.AskForPeng(this.targetCard); } } break; case ManagerState.ASK_CHI: if (targetCard != null) { int nextIndex = GetNextIndex(currentAgentIndex); agents[nextIndex].AskForChi(targetCard); } break; } }