private void bgwEngine_DoWork(object sender, DoWorkEventArgs e) { try { SLInterface.getInitialState(); DrawState(); totalStartTime = DateTime.UtcNow; while (!(sender as BackgroundWorker).CancellationPending) { frameCount++; totalFrameCount++; DateTime start = DateTime.UtcNow; bool clicked = false; int x = 0; int y = 0; if (mouseClicks.Count > 0) { clicked = true; x = mouseClicks.Peek().X; y = (800 - mouseClicks.Peek().Y); mouseClicks.Dequeue(); } else { x = cursorPosition.X; y = 800 - cursorPosition.Y; } foreach (string sound in SLInterface.getSounds(clicked, x, y, keyPresses)) { sounds.Enqueue(sound); } SLInterface.getNewState(clicked, x, y, keyPresses); if (!ImageUpdated) { DrawState(); } (sender as BackgroundWorker).ReportProgress(0); while (currentFPS > 0 && (DateTime.UtcNow - start).TotalMilliseconds < (1000.0 / currentFPS)) { Thread.SpinWait(1); } } e.Cancel = true; return; } catch (Exception exc) { MessageBox.Show(exc.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void DrawState() { bufferDraw = SLInterface.getImages(); ImageUpdated = true; }