public void Calculate() { WinUtility win = Service.Resolve <WinUtility>(); CancellationToken token = Service.Resolve <CancellationToken>(); Clock timer = new Clock(); timer.Start(); int lastTime = timer.MsElapsed(); Genie.Yuk.Event _event = null; double fps; Action myAction = (Action)(async() => { while (!token.IsCancellationRequested) { int current = timer.MsElapsed(); int elapsed = current - lastTime; fps = timer.FPS(elapsed); Console.WriteLine(fps); try { _event = EventQueueClient.Dequeue(); Loop(_event); } catch (InvalidOperationException e) { //DoWhile = false; } try { await Task.Delay(500, token); } catch (TaskCanceledException) { System.Console.WriteLine("Request was cancelled"); }; lastTime = current; } timer.Stop(); }); win.OnUiThread(myAction); }
public void Start(EventManager events = null) { if (events == null) { m_Events = new EventManager(m_path); } else { m_Events = events; } EventQueueClient.Enqueue(new StartEvent()); m_Events.Start(); }
public void Stop() { EventQueueClient.Enqueue(new StopEvent()); }
public virtual Boolean Loop(Genie.Yuk.Event _event) { WinUtility win = Service.Resolve <WinUtility>(); GameGraphics gg = Service.Resolve <GameGraphics>(); CancellationToken token = Service.Resolve <CancellationToken>(); if (_event != null) { if (_event.GetType() == typeof(StartEvent)) { Action myAction0 = (Action)(() => { gg.Start(); }); Task taskA = Task.Run(myAction0); taskA.Wait(); Action myAction1 = (Action)(() => { while (!token.IsCancellationRequested) { gg.AlwaysRun(); } }); win.OnUiThread(myAction1); EventQueueClient.Enqueue(new GraphicsEvent()); } else if (_event.GetType() == typeof(GraphicsEvent)) { lock (WriteServer.balanceLock) { ComponentManager.Update(); gg.Run(token); System.Console.WriteLine("Draw Client"); } EventQueueClient.Enqueue(new GraphicsEvent()); } else if (_event.GetType() == typeof(JobEvent)) { JobEvent job = (JobEvent)_event; Boolean doLoop = true; while (doLoop) { try { Genie.Yuk.Event tmpEvent = job.Dequeue(); Loop(tmpEvent); } catch (InvalidOperationException e) { doLoop = false; } } } else if (_event.GetType() == typeof(StopEvent)) { System.Console.WriteLine("Stop"); return(false); } } return(true); }