public void Update() { if (!Enabled) { return; } if (Time.TotalGameTime >= _nextTick) { CurrentIndex++; if (CurrentIndex <= ToIndex) { Callback?.Invoke(Self, CurrentIndex); } else if (!Loop) { Enabled = false; EndCallback?.Invoke(Self); return; } else { Reset(); Callback?.Invoke(Self, CurrentIndex); } _nextTick = Time.TotalGameTime.Add(ElapsePerFrame); } }
public CHSocketReader(Socket socket, EndCallback _endCB, CHSocket baseSocket) { endCB = _endCB; _socket = socket; parser = new CHPacketParser(baseSocket); BeginBackgroundRead(); }
public static void Increment(ref float t, EndCallback cb) { float oldT = t; Increment(ref t); if (oldT > 0 && t == 0) { cb(); } }
public static double CalcMinDistanceToAny(NodeBase nodeStart, EndCallback callback) { List <NodeBase> queue = new List <NodeBase>(); double minDistance = double.MaxValue; nodeStart.minDistance = 0; queue.Add(nodeStart); int iterCount = 0; while (queue.Count > 0) { iterCount += 1; //Get node var node = queue[0]; if (callback(node)) { //Check min distance if (node.minDistance < minDistance) { minDistance = node.minDistance; } //Don't proccess this node queue.RemoveAt(0); continue; } //Check children var children = node.getNodes(); foreach (var child in children) { //Check if we should branch down that path if (node.minDistance + child.travelDistance < child.minDistance) { //Add to queue child.minDistance = node.minDistance + child.travelDistance; queue.Add(child); } } //Remove this node queue.RemoveAt(0); } //Return min distance return(minDistance); }
private static extern void TessEndCallBack( IntPtr tesselationObject, CallbackName which, EndCallback callback);
public static void TessEndCallBack(IntPtr tess, EndCallback callback) { TessEndCallBack(tess, CallbackName.End, callback); }
/// <summary> /// 按指定对称密钥将输入流解密结果保存为输出流 /// </summary> /// <param name="inStream">输入流(可读)</param> /// <param name="outStream">输出流(可写)</param> /// <param name="alg">对称密钥</param> /// <param name="progressCallback">进度回调函数</param> /// <param name="endCallback">结束计算的回调函数</param> /// <param name="state">传递给回调的参数</param> public void DecryptData(Stream inStream, Stream outStream, SymmetricAlgorithm alg, ProgressCallback progressCallback, EndCallback endCallback, object state) { const int bufferSize = 100; _cancel = false; long bytesRead = 0L; long totalBytesLength = inStream.Length; var buffer = new byte[bufferSize]; using (var encStream = new CryptoStream(inStream, alg.CreateDecryptor(), CryptoStreamMode.Read)) { int num; do { num = encStream.Read(buffer, 0, bufferSize); outStream.Write(buffer, 0, num); if (progressCallback == null) { continue; } bytesRead += num; progressCallback(new I3ProgressState(bytesRead, totalBytesLength, state)); //进度回调 } while (num > 0 && !_cancel); if (endCallback != null) { endCallback(new I3EndState(_cancel, state)); //计算结束回调 } } }
/// <summary> /// 按指定对称密钥将输入文件解密结果保存为输出文件 /// </summary> /// <param name="inFileName">输入文件</param> /// <param name="outFileName">输出文件</param> /// <param name="alg">对称密钥</param> /// <param name="progressCallback">进度回调函数</param> /// <param name="endCallback">结束计算的回调函数</param> /// <param name="state">传递给回调的参数</param> public void DecryptData(string inFileName, string outFileName, SymmetricAlgorithm alg, ProgressCallback progressCallback, EndCallback endCallback, object state) { using (var infs = new FileStream(inFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var outfs = new FileStream(outFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) { DecryptData(infs, outfs, alg, progressCallback, endCallback, state); } } }
public void StartGame( Virus virus, PerformedMoveCallback callback, UpdatePiecesCallback piecesCallback, EndCallback end, string id, params VirusPlayer[] players) { Random rand = new Random(); PerformedMove = callback; UpdatePieces = piecesCallback; End = end; PlayerID = id; this.virus = virus; this.immediateAI = true; this.MouseClick += MouseClickHandler1; tileSize = 49; this.Size = new Size( virus.Size * tileSize + 17, virus.Size * tileSize + 55); int smallestSide = this.Size.Height < this.Size.Width ? this.Size.Height : this.Size.Width; tileSize = smallestSide / virus.Size; this.players.Add(new VirusPlayer("Player 0", "", Color.White)); this.players.AddRange(players); while (this.players.Count < virus.Players + 1) { this.players.Add(new VirusPlayer("BruteAI", "AI", Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)))); } //Save("Lalalafil"); agents = new Agent[this.players.Count]; int n = 1; for (byte i = 1; i < this.players.Count; i++) { String p = this.players[i].Name; switch (p) { case "AIQ": agents[i] = new QAgent(i); if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N")) { ((QAgent)agents[i]).Load("TrainingData"); ((QAgent)agents[i]).TurnOffExploration(); ((QAgent)agents[i]).TurnOffLearning(); } //this.players[i].Name = "AI " + n; n++; break; case "AIMQ": agents[i] = new MemoryQAgent(i); if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N")) { ((MemoryQAgent)agents[i]).Load("TrainingData"); ((MemoryQAgent)agents[i]).TurnOffExploration(); } //this.players[i].Name = "AI " + n; n++; break; case "AIMinimax": agents[i] = new MinimaxAgent(4, i); //this.players[i].Name = "AI " + n; n++; break; case "AIMiniMaxMix": if (File.Exists("TrainingData.Q")) { agents[i] = new MiniMaxMixAgent("TrainingData", 2, i); } else { agents[i] = new BruteForceAgent(i); } //this.players[i].Name = "AI " + n; n++; break; case "AIMixed": agents[i] = new MixedAgent(0.5, false, i); //this.players[i].Name = "AI " + n; n++; break; case "AIBrute": agents[i] = new BruteForceAgent(i); //this.players[i].Name = "AI " + n; n++; break; case "AIRandom": agents[i] = new RandomAgent(i); //this.players[i].Name = "AI " + n; n++; break; case "AISimple": agents[i] = new SimpleAgent(i); //this.players[i].Name = "AI " + n; n++; break; } } message = this.players[1].Name + "'s turn"; /*colors = new Color[virus.Players + 1]; * colors[0] = Color.White; * colors[1] = Color.FromArgb(128, 160, 255); * colors[2] = Color.FromArgb(96, 255, 96); * if(virus.Players > 2) * colors[3] = Color.FromArgb(255, 96, 96); * if(virus.Players > 3) * colors[4] = Color.FromArgb(255, 255, 64); * * for (int i = 5; i <= virus.Players; i++) * colors[i] = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));*/ }
private extern static void TessEndCallBack( IntPtr tesselationObject, CallbackName which, EndCallback callback);
public extern static void GluTessEndCallBack( IntPtr tesselationObject, GlCallbackName which, EndCallback callback);
// Used to Interrupt Logic Flow of GameManager When an Event That Causes and End of Session in the GUI is Triggered. public void SessionEndCallback(EndCallback Callback) { SessionLeaveCallback = Callback; }
/////////////////////////////////////////////////////////// // this method draws three big boxes at the top of the screen; // next & prev arrows, and a main text box /////////////////////////////////////////////////////////// public void DrawBoxes(string caption, string description, Texture imageLeftArrow, Texture imageRightArrow, EndCallback endCallback = null) { if (!ShowGUI) { return; } GUI.color = new Color(1, 1, 1, 1 * GlobalAlpha); float screenCenter = Screen.width / 2; GUILayout.BeginArea(new Rect(screenCenter - 400, 30, 800, 100)); // draw box for 'prev' button, if texture is provided if (imageLeftArrow != null) { GUI.Box(new Rect(30, 10, 80, 80), ""); } // draw big text background box GUI.Box(new Rect(120, 0, 560, 100), ""); GUI.color = new Color(1, 1, 1, m_TextAlpha); // draw text for (int v = 0; v < 3; v++) { GUILayout.BeginArea(new Rect(130, 10, 540, 80)); GUILayout.Label("--- " + caption.ToUpper() + " ---" + "\n" + description, LabelStyle); GUILayout.EndArea(); } GUI.color = new Color(1, 1, 1, 1 * GlobalAlpha); // draw box for 'next' button, if texture is provided if (imageRightArrow != null) { GUI.Box(new Rect(690, 10, 80, 80), ""); } // draw 'prev' arrow button, if texture is provided if (imageLeftArrow != null) { if (GUI.Button(new Rect(35, 15, 80, 80), imageLeftArrow, "Label")) { m_FadeToScreen = Mathf.Max(CurrentScreen - 1, 1); m_FadeState = FadeState.FadeOut; } } // handle arrow fade state if (Time.time < LastInputTime + 30) { m_BigArrowFadeAlpha = 1; } else { m_BigArrowFadeAlpha = 0.5f - Mathf.Sin((Time.time - 0.5f) * 6) * 1.0f; } GUI.color = new Color(1, 1, 1, m_BigArrowFadeAlpha * GlobalAlpha); // draw 'next' arrow button, if texture is provided, unless // a checkmark texture is provided ... if (imageRightArrow != null) { if (GUI.Button(new Rect(700, 15, 80, 80), imageRightArrow, "Label")) { if (endCallback == null) { m_FadeToScreen = CurrentScreen + 1; m_FadeState = FadeState.FadeOut; } else { endCallback(); } } } GUI.color = new Color(1, 1, 1, 1 * GlobalAlpha); GUILayout.EndArea(); GUI.color = new Color(1, 1, 1, m_TextAlpha * GlobalAlpha); }
public void StartGame( Virus virus, PerformedMoveCallback callback, UpdatePiecesCallback piecesCallback, EndCallback end, string id, params VirusPlayer[] players) { Random rand = new Random(); PerformedMove = callback; UpdatePieces = piecesCallback; End = end; PlayerID = id; this.virus = virus; this.immediateAI = true; this.MouseClick += MouseClickHandler1; tileSize = 49; this.Size = new Size( virus.Size * tileSize + 17, virus.Size * tileSize + 55); int smallestSide = this.Size.Height < this.Size.Width ? this.Size.Height : this.Size.Width; tileSize = smallestSide / virus.Size; this.players.Add(new VirusPlayer("Player 0", "", Color.White)); this.players.AddRange(players); while (this.players.Count < virus.Players + 1) { this.players.Add(new VirusPlayer("BruteAI","AI",Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)))); } //Save("Lalalafil"); agents = new Agent[this.players.Count]; int n = 1; for (byte i = 1; i < this.players.Count; i++) { String p = this.players[i].Name; switch (p) { case "AIQ": agents[i] = new QAgent(i); if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N")) { ((QAgent)agents[i]).Load("TrainingData"); ((QAgent)agents[i]).TurnOffExploration(); ((QAgent)agents[i]).TurnOffLearning(); } //this.players[i].Name = "AI " + n; n++; break; case "AIMQ": agents[i] = new MemoryQAgent(i); if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N")) { ((MemoryQAgent)agents[i]).Load("TrainingData"); ((MemoryQAgent)agents[i]).TurnOffExploration(); } //this.players[i].Name = "AI " + n; n++; break; case "AIMinimax": agents[i] = new MinimaxAgent(4,i); //this.players[i].Name = "AI " + n; n++; break; case "AIMiniMaxMix": if (File.Exists("TrainingData.Q")) agents[i] = new MiniMaxMixAgent("TrainingData", 2, i); else agents[i] = new BruteForceAgent(i); //this.players[i].Name = "AI " + n; n++; break; case "AIMixed": agents[i] = new MixedAgent(0.5,false,i); //this.players[i].Name = "AI " + n; n++; break; case "AIBrute": agents[i] = new BruteForceAgent(i); //this.players[i].Name = "AI " + n; n++; break; case "AIRandom": agents[i] = new RandomAgent(i); //this.players[i].Name = "AI " + n; n++; break; case "AISimple": agents[i] = new SimpleAgent(i); //this.players[i].Name = "AI " + n; n++; break; } } message = this.players[1].Name + "'s turn"; /*colors = new Color[virus.Players + 1]; colors[0] = Color.White; colors[1] = Color.FromArgb(128, 160, 255); colors[2] = Color.FromArgb(96, 255, 96); if(virus.Players > 2) colors[3] = Color.FromArgb(255, 96, 96); if(virus.Players > 3) colors[4] = Color.FromArgb(255, 255, 64); for (int i = 5; i <= virus.Players; i++) colors[i] = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));*/ }
/**************************************************************************************************/ /*! * \fn public void SetEndCallback(EndCallback callback) * 再生終了時(GameObjectを削除する時)のコールバックの登録 * \remarks これは再生時に引数指定をしないため、やりたい場合は再 Create 後にコールしてください * \param callback : コールバックメソッド * \date 2014.12.25(Thu) * \author Masayoshi.Matsuyama@Donuts */ /**************************************************************************************************/ public void SetEndCallback(EndCallback callback) { endCallbackFunc = callback; }
/// <summary> /// 按指定对称算法、键和向量将输入文件解密结果保存为输出文件 /// </summary> /// <param name="inFileName">输入文件</param> /// <param name="outFileName">输出文件</param> /// <param name="algName">对称算法名称</param> /// <param name="rgbKey">键</param> /// <param name="rgbIv">向量</param> /// <param name="progressCallback">进度回调函数</param> /// <param name="endCallback">结束计算的回调函数</param> /// <param name="state">传递给回调的参数</param> public void DecryptData(string inFileName, string outFileName, string algName, byte[] rgbKey, byte[] rgbIv, ProgressCallback progressCallback, EndCallback endCallback, object state) { var alg = SymmetricAlgorithm.Create(algName); alg.Key = rgbKey; alg.IV = rgbIv; DecryptData(inFileName, outFileName, alg, progressCallback, endCallback, state); }
/////////////////////////////////////////////////////////// // this method draws three big boxes at the top of the screen; // next & prev arrows, and a main text box /////////////////////////////////////////////////////////// public void DrawBoxes(string caption, string description, Texture imageLeftArrow, Texture imageRightArrow, EndCallback endCallback = null) { if(!ShowGUI) return; GUI.color = new Color(1, 1, 1, 1 * GlobalAlpha); float screenCenter = Screen.width / 2; GUILayout.BeginArea(new Rect(screenCenter - 400, 30, 800, 100)); // draw box for 'prev' button, if texture is provided if (imageLeftArrow != null) GUI.Box(new Rect(30, 10, 80, 80), ""); // draw big text background box GUI.Box(new Rect(120, 0, 560, 100), ""); GUI.color = new Color(1, 1, 1, m_TextAlpha); // draw text for (int v = 0; v < 3; v++) { GUILayout.BeginArea(new Rect(130, 10, 540, 80)); GUILayout.Label("--- " + caption.ToUpper() + " ---" + "\n" + description, LabelStyle); GUILayout.EndArea(); } GUI.color = new Color(1, 1, 1, 1 * GlobalAlpha); // draw box for 'next' button, if texture is provided if (imageRightArrow != null) GUI.Box(new Rect(690, 10, 80, 80), ""); // draw 'prev' arrow button, if texture is provided if (imageLeftArrow != null) { if (GUI.Button(new Rect(35, 15, 80, 80), imageLeftArrow, "Label")) { m_FadeToScreen = Mathf.Max(CurrentScreen - 1, 1); m_FadeState = FadeState.FadeOut; } } // handle arrow fade state if (Time.time < LastInputTime + 30) m_BigArrowFadeAlpha = 1; else m_BigArrowFadeAlpha = 0.5f - Mathf.Sin((Time.time - 0.5f) * 6) * 1.0f; GUI.color = new Color(1, 1, 1, m_BigArrowFadeAlpha * GlobalAlpha); // draw 'next' arrow button, if texture is provided, unless // a checkmark texture is provided ... if (imageRightArrow != null) { if (GUI.Button(new Rect(700, 15, 80, 80), imageRightArrow, "Label")) { if(endCallback == null) { m_FadeToScreen = CurrentScreen + 1; m_FadeState = FadeState.FadeOut; } else endCallback(); } } GUI.color = new Color(1, 1, 1, 1 * GlobalAlpha); GUILayout.EndArea(); GUI.color = new Color(1, 1, 1, m_TextAlpha * GlobalAlpha); }