void OnGLRestart() { test.Dispose(); entry = entries.Entries[testIndex]; test = entry.Construct(); OnGLResize(width, height); _min = long.MaxValue; _max = long.MinValue; NextGameTick = System.Environment.TickCount; }
public Main() { StartPosition = FormStartPosition.Manual; InitializeComponent(); Tao.FreeGlut.Glut.glutInit(); //OnGLResize(_glcontrol.Width, _glcontrol.Height); simulationThread = new Thread(SimulationLoop); Text = "Box2CS Testbed - Box2D version " + Box2DVersion.Version.ToString(); testIndex = b2Math.b2Clamp(testIndex, 0, entries.Entries.Count - 1); testSelection = testIndex; entry = entries.Entries[testIndex]; test = entry.Construct(); foreach (var e in entries.Entries) { comboBox1.Items.Add(e.Name); } comboBox1.SelectedIndex = 0; comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); numericUpDown1.Value = TestSettings.velocityIterations; numericUpDown2.Value = TestSettings.positionIterations; numericUpDown3.Value = (decimal)TestSettings.hz; renderWindow = new RenderWindow(panel1.Handle, new ContextSettings(32, 0, 12)); renderWindow.Resized += new EventHandler <SizeEventArgs>(render_Resized); renderWindow.MouseButtonPressed += new EventHandler <MouseButtonEventArgs>(renderWindow_MouseButtonPressed); renderWindow.MouseButtonReleased += new EventHandler <MouseButtonEventArgs>(renderWindow_MouseButtonReleased); renderWindow.MouseMoved += new EventHandler <MouseMoveEventArgs>(renderWindow_MouseMoved); renderWindow.KeyPressed += new EventHandler <SFML.Window.KeyEventArgs>(renderWindow_KeyPressed); renderWindow.KeyReleased += new EventHandler <SFML.Window.KeyEventArgs>(renderWindow_KeyReleased); renderWindow.Show(true); OnGLResize((int)renderWindow.Width, (int)renderWindow.Height); updateDraw = UpdateDraw; simulationThread.Start(); }
void Simulate() { if (test != null) { if (TestSettings.restart) { OnGLRestart(); TestSettings.restart = false; } sw.Reset(); TestSettings.hz = settingsHz; test.Step(); sw.Stop(); _ts = sw.ElapsedMilliseconds; if (_ts < _min) { _min = _ts; } if (_ts > _max) { _max = _ts; } _ts_b2 = b2world_getelapsed(); _ts_max_ = b2world_getmax(); _ts_min_ = b2world_getmin(); if (testSelection != testIndex) { testIndex = testSelection; entry = entries.Entries[testIndex]; test.Dispose(); test = entry.Construct(); viewZoom = 1.0f; viewCenter = new Vec2(0.0f, 20.0f); OnGLResize(width, height); } } }
void OnGLKeyboard(KeyCode key, int x, int y) { switch (key) { case KeyCode.Escape: Application.Exit(); break; // Press 'z' to zoom out. case KeyCode.Z: viewZoom = Math.Min(1.1f * viewZoom, 20.0f); OnGLResize(width, height); break; // Press 'x' to zoom in. case KeyCode.X: viewZoom = Math.Max(0.9f * viewZoom, 0.02f); OnGLResize(width, height); break; // Press 'r' to reset. case KeyCode.R: test.Dispose(); test = entry.Construct(); break; // Press space to launch a bomb. case KeyCode.Space: if (test != null) { test.LaunchBomb(); } break; case KeyCode.P: TestSettings.pause = !TestSettings.pause; break; // Press [ to prev test. case KeyCode.LBracket: --testSelection; if (testSelection < 0) { testSelection = entries.Entries.Count - 1; } break; // Press ] to next test. case KeyCode.RBracket: ++testSelection; if (testSelection == entries.Entries.Count) { testSelection = 0; } break; // Press left to pan left. case KeyCode.Left: viewCenter.X -= 0.5f; OnGLResize(width, height); break; // Press right to pan right. case KeyCode.Right: viewCenter.X += 0.5f; OnGLResize(width, height); break; // Press down to pan down. case KeyCode.Down: viewCenter.Y -= 0.5f; OnGLResize(width, height); break; // Press up to pan up. case KeyCode.Up: viewCenter.Y += 0.5f; OnGLResize(width, height); break; // Press home to reset the view. case KeyCode.Home: viewZoom = 1.0f; viewCenter = new Vec2(0.0f, 20.0f); OnGLResize(width, height); break; default: if (test != null) { test.Keyboard(key); } break; } }