diff --git a/src/Box2D.NET.Samples/Camera.cs b/src/Box2D.NET.Samples/Camera.cs index 6751e712..2140ad05 100644 --- a/src/Box2D.NET.Samples/Camera.cs +++ b/src/Box2D.NET.Samples/Camera.cs @@ -17,8 +17,8 @@ public class Camera public Camera() { - m_width = 1280; - m_height = 800; + m_width = 1920; + m_height = 1080; ResetView(); } diff --git a/src/Box2D.NET.Samples/Draw.cs b/src/Box2D.NET.Samples/Draw.cs index 41f6b510..d7d584e0 100644 --- a/src/Box2D.NET.Samples/Draw.cs +++ b/src/Box2D.NET.Samples/Draw.cs @@ -82,12 +82,11 @@ public Draw() m_regularFont = default; } - public void Create(SampleAppContext context) + public void Create(SampleContext context) { _camera = context.camera; _gl = context.gl; - m_background.Create(context); m_points.Create(context); m_lines.Create(context); @@ -181,7 +180,7 @@ public void DrawString(int x, int y, string message) //{ // return; // } - + ImGui.Begin("Overlay", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.AlwaysAutoResize | @@ -197,7 +196,7 @@ public void DrawString(B2Vec2 p, string message) { B2Vec2 ps = _camera.ConvertWorldToScreen(p); - + ImGui.Begin("Overlay", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar); @@ -221,18 +220,18 @@ public void DrawAABB(B2AABB aabb, B2HexColor c) public void Flush() { - m_solidCircles.Flush(); - m_solidCapsules.Flush(); - m_solidPolygons.Flush(); - m_circles.Flush(); - m_lines.Flush(); - m_points.Flush(); + m_solidCircles.Flush(_camera); + m_solidCapsules.Flush(_camera); + m_solidPolygons.Flush(_camera); + m_circles.Flush(_camera); + m_lines.Flush(_camera); + m_points.Flush(_camera); _gl.CheckOpenGL(); } public void DrawBackground() { - m_background.Draw(); + m_background.Draw(_camera); } public static void DrawPolygonFcn(ReadOnlySpan vertices, int vertexCount, B2HexColor color, object context) diff --git a/src/Box2D.NET.Samples/Graphics/GLBackground.cs b/src/Box2D.NET.Samples/Graphics/GLBackground.cs index 17dff447..c30ab373 100644 --- a/src/Box2D.NET.Samples/Graphics/GLBackground.cs +++ b/src/Box2D.NET.Samples/Graphics/GLBackground.cs @@ -10,10 +10,9 @@ namespace Box2D.NET.Samples.Graphics; public class GLBackground { - private Camera _camera; private Glfw _glfw; private GL _gl; - + private uint[] m_vaoId = new uint[1]; private uint[] m_vboId = new uint[1]; private uint m_programId; @@ -21,12 +20,11 @@ public class GLBackground private int m_resolutionUniform; private int m_baseColorUniform; - public void Create(SampleAppContext context) + public void Create(SampleContext context) { _glfw = context.glfw; _gl = context.gl; - _camera = context.camera; - + m_programId = _gl.CreateProgramFromFiles("data/background.vs", "data/background.fs"); m_timeUniform = _gl.GetUniformLocation(m_programId, "time"); m_resolutionUniform = _gl.GetUniformLocation(m_programId, "resolution"); @@ -71,7 +69,7 @@ public void Destroy() } } - public void Draw() + public void Draw(Camera camera) { _gl.UseProgram(m_programId); @@ -82,7 +80,7 @@ public void Draw() // time = fmodf(time, 100.0f); _gl.Uniform1(m_timeUniform, time); - _gl.Uniform2(m_resolutionUniform, _camera.m_width, _camera.m_height); + _gl.Uniform2(m_resolutionUniform, camera.m_width, camera.m_height); // struct RGBA8 c8 = RGBA8.MakeRGBA8( b2_colorGray2, 1.0f ); // B2GL.Shared.Gl.Uniform3(m_baseColorUniform, c8.r/255.0f, c8.g/255.0f, c8.b/255.0f); diff --git a/src/Box2D.NET.Samples/Graphics/GLCircles.cs b/src/Box2D.NET.Samples/Graphics/GLCircles.cs index 1540b89b..af3980d2 100644 --- a/src/Box2D.NET.Samples/Graphics/GLCircles.cs +++ b/src/Box2D.NET.Samples/Graphics/GLCircles.cs @@ -18,7 +18,6 @@ public class GLCircles public const int e_batchSize = 2048; private GL _gl; - private Camera _camera; private List m_circles = new List(); private uint[] m_vaoId = new uint[1]; @@ -27,9 +26,8 @@ public class GLCircles private int m_projectionUniform; private int m_pixelScaleUniform; - public void Create(SampleAppContext context) + public void Create(SampleContext context) { - _camera = context.camera; _gl = context.gl; m_programId = _gl.CreateProgramFromFiles("data/circle.vs", "data/circle.fs"); @@ -108,7 +106,7 @@ public void AddCircle(B2Vec2 center, float radius, B2HexColor color) m_circles.Add(new CircleData(center, radius, rgba)); } - public void Flush() + public void Flush(Camera camera) { int count = m_circles.Count; if (count == 0) @@ -121,10 +119,10 @@ public void Flush() B2FixedArray16 array16 = new B2FixedArray16(); Span proj = array16.AsSpan(); - _camera.BuildProjectionMatrix(proj, 0.2f); + camera.BuildProjectionMatrix(proj, 0.2f); _gl.UniformMatrix4(m_projectionUniform, 1, false, proj); - _gl.Uniform1(m_pixelScaleUniform, _camera.m_height / _camera.m_zoom); + _gl.Uniform1(m_pixelScaleUniform, camera.m_height / camera.m_zoom); _gl.BindVertexArray(m_vaoId[0]); diff --git a/src/Box2D.NET.Samples/Graphics/GLLines.cs b/src/Box2D.NET.Samples/Graphics/GLLines.cs index 17d3dc4a..c147c8c2 100644 --- a/src/Box2D.NET.Samples/Graphics/GLLines.cs +++ b/src/Box2D.NET.Samples/Graphics/GLLines.cs @@ -21,7 +21,6 @@ public class GLLines public const int e_batchSize = 2 * 2048; private GL _gl; - private Camera _camera; private List m_points = new(); private uint[] m_vaoId = new uint[1]; @@ -29,10 +28,9 @@ public class GLLines private uint m_programId; private int m_projectionUniform; - public void Create(SampleAppContext context) + public void Create(SampleContext context) { _gl = context.gl; - _camera = context.camera; string vs = "#version 330\n" + "uniform mat4 projectionMatrix;\n" @@ -105,7 +103,7 @@ public void AddLine(B2Vec2 p1, B2Vec2 p2, B2HexColor c) m_points.Add(new VertexData(p2, rgba)); } - public void Flush() + public void Flush(Camera camera) { int count = m_points.Count; if (count == 0) @@ -123,7 +121,7 @@ public void Flush() B2FixedArray16 array16 = new B2FixedArray16(); Span proj = array16.AsSpan(); - _camera.BuildProjectionMatrix(proj, 0.1f); + camera.BuildProjectionMatrix(proj, 0.1f); _gl.UniformMatrix4(m_projectionUniform, 1, false, proj); diff --git a/src/Box2D.NET.Samples/Graphics/GLPoints.cs b/src/Box2D.NET.Samples/Graphics/GLPoints.cs index 5b8d1052..d2827fc1 100644 --- a/src/Box2D.NET.Samples/Graphics/GLPoints.cs +++ b/src/Box2D.NET.Samples/Graphics/GLPoints.cs @@ -17,7 +17,6 @@ public class GLPoints public const int e_batchSize = 2048; private GL _gl; - private Camera _camera; private List m_points = new List(); private uint[] m_vaoId = new uint[1]; @@ -25,9 +24,8 @@ public class GLPoints private uint m_programId; private int m_projectionUniform; - public void Create(SampleAppContext context) + public void Create(SampleContext context) { - _camera = context.camera; _gl = context.gl; string vs = "#version 330\n" + @@ -108,7 +106,7 @@ public void AddPoint(B2Vec2 v, float size, B2HexColor c) m_points.Add(new PointData(v, size, rgba)); } - public void Flush() + public void Flush(Camera camera) { int count = m_points.Count; if (count == 0) @@ -120,8 +118,8 @@ public void Flush() B2FixedArray16 array16 = new B2FixedArray16(); Span proj = array16.AsSpan(); - - _camera.BuildProjectionMatrix(proj, 0.0f); + + camera.BuildProjectionMatrix(proj, 0.0f); _gl.UniformMatrix4(m_projectionUniform, 1, false, proj); _gl.BindVertexArray(m_vaoId[0]); diff --git a/src/Box2D.NET.Samples/Graphics/GLSolidCapsules.cs b/src/Box2D.NET.Samples/Graphics/GLSolidCapsules.cs index 939cc8de..49d2f31a 100644 --- a/src/Box2D.NET.Samples/Graphics/GLSolidCapsules.cs +++ b/src/Box2D.NET.Samples/Graphics/GLSolidCapsules.cs @@ -17,11 +17,10 @@ namespace Box2D.NET.Samples.Graphics; public class GLSolidCapsules { private static readonly ILogger Logger = Log.ForContext(); - + public const int e_batchSize = 2048; private GL _gl; - private Camera _camera; private List m_capsules = new List(); private uint[] m_vaoId = new uint[1]; @@ -30,9 +29,8 @@ public class GLSolidCapsules private int m_projectionUniform; private int m_pixelScaleUniform; - public void Create(SampleAppContext context) + public void Create(SampleContext context) { - _camera = context.camera; _gl = context.gl; m_programId = _gl.CreateProgramFromFiles("data/solid_capsule.vs", "data/solid_capsule.fs"); @@ -132,7 +130,7 @@ public void AddCapsule(B2Vec2 p1, B2Vec2 p2, float radius, B2HexColor c) m_capsules.Add(new CapsuleData(transform, radius, length, rgba)); } - public void Flush() + public void Flush(Camera camera) { int count = m_capsules.Count; if (count == 0) @@ -144,11 +142,11 @@ public void Flush() B2FixedArray16 array16 = new B2FixedArray16(); Span proj = array16.AsSpan(); - - _camera.BuildProjectionMatrix(proj, 0.2f); - + + camera.BuildProjectionMatrix(proj, 0.2f); + _gl.UniformMatrix4(m_projectionUniform, 1, false, proj); - _gl.Uniform1(m_pixelScaleUniform, _camera.m_height / _camera.m_zoom); + _gl.Uniform1(m_pixelScaleUniform, camera.m_height / camera.m_zoom); _gl.BindVertexArray(m_vaoId[0]); diff --git a/src/Box2D.NET.Samples/Graphics/GLSolidCircles.cs b/src/Box2D.NET.Samples/Graphics/GLSolidCircles.cs index a3561207..65eaefba 100644 --- a/src/Box2D.NET.Samples/Graphics/GLSolidCircles.cs +++ b/src/Box2D.NET.Samples/Graphics/GLSolidCircles.cs @@ -20,7 +20,6 @@ public class GLSolidCircles public const int e_batchSize = 2048; private GL _gl; - private Camera _camera; private List m_circles = new List(); private uint[] m_vaoId = new uint[1]; @@ -30,9 +29,8 @@ public class GLSolidCircles private int m_pixelScaleUniform; - public void Create(SampleAppContext context) + public void Create(SampleContext context) { - _camera = context.camera; _gl = context.gl; m_programId = _gl.CreateProgramFromFiles("data/solid_circle.vs", "data/solid_circle.fs"); @@ -113,7 +111,7 @@ public void AddCircle(ref B2Transform transform, float radius, B2HexColor color) m_circles.Add(new SolidCircleData(transform, radius, rgba)); } - public void Flush() + public void Flush(Camera camera) { int count = (int)m_circles.Count; if (count == 0) @@ -126,10 +124,10 @@ public void Flush() B2FixedArray16 array16 = new B2FixedArray16(); Span proj = array16.AsSpan(); - _camera.BuildProjectionMatrix(proj, 0.2f); + camera.BuildProjectionMatrix(proj, 0.2f); _gl.UniformMatrix4(m_projectionUniform, 1, false, proj); - _gl.Uniform1(m_pixelScaleUniform, _camera.m_height / _camera.m_zoom); + _gl.Uniform1(m_pixelScaleUniform, camera.m_height / camera.m_zoom); _gl.BindVertexArray(m_vaoId[0]); diff --git a/src/Box2D.NET.Samples/Graphics/GLSolidPolygons.cs b/src/Box2D.NET.Samples/Graphics/GLSolidPolygons.cs index ab7c75d4..a12a0199 100644 --- a/src/Box2D.NET.Samples/Graphics/GLSolidPolygons.cs +++ b/src/Box2D.NET.Samples/Graphics/GLSolidPolygons.cs @@ -18,7 +18,6 @@ public class GLSolidPolygons public const int e_batchSize = 512; private GL _gl; - private Camera _camera; private List m_polygons = new List(); private uint[] m_vaoId = new uint[1]; @@ -27,9 +26,8 @@ public class GLSolidPolygons private int m_projectionUniform; private int m_pixelScaleUniform; - public void Create(SampleAppContext context) + public void Create(SampleContext context) { - _camera = context.camera; _gl = context.gl; m_programId = _gl.CreateProgramFromFiles("data/solid_polygon.vs", "data/solid_polygon.fs"); @@ -140,7 +138,7 @@ public void AddPolygon(ref B2Transform transform, ReadOnlySpan points, i m_polygons.Add(data); } - public void Flush() + public void Flush(Camera camera) { int count = (int)m_polygons.Count; if (count == 0) @@ -153,11 +151,11 @@ public void Flush() B2FixedArray16 array16 = new B2FixedArray16(); Span proj = array16.AsSpan(); - - _camera.BuildProjectionMatrix(proj, 0.2f); - + + camera.BuildProjectionMatrix(proj, 0.2f); + _gl.UniformMatrix4(m_projectionUniform, 1, false, proj); - _gl.Uniform1(m_pixelScaleUniform, _camera.m_height / _camera.m_zoom); + _gl.Uniform1(m_pixelScaleUniform, camera.m_height / camera.m_zoom); _gl.BindVertexArray(m_vaoId[0]); _gl.BindBuffer(GLEnum.ArrayBuffer, m_vboIds[1]); diff --git a/src/Box2D.NET.Samples/Helpers/GlfwHelpers.cs b/src/Box2D.NET.Samples/Helpers/GlfwHelpers.cs index c346bb1b..004e4e65 100644 --- a/src/Box2D.NET.Samples/Helpers/GlfwHelpers.cs +++ b/src/Box2D.NET.Samples/Helpers/GlfwHelpers.cs @@ -8,12 +8,12 @@ namespace Box2D.NET.Samples.Helpers; public static class GlfwHelpers { - public static unsafe InputAction GetKey(SampleAppContext context, Keys key) + public static unsafe InputAction GetKey(SampleContext context, Keys key) { if (null == context.glfw) return InputAction.Release; - var state = context.glfw.GetKey(context.mainWindow, key); + var state = context.glfw.GetKey(context.window, key); switch (state) { case 0: return InputAction.Release; diff --git a/src/Box2D.NET.Samples/Primitives/SampleEntry.cs b/src/Box2D.NET.Samples/Primitives/SampleEntry.cs index bbf9da1c..1410d287 100644 --- a/src/Box2D.NET.Samples/Primitives/SampleEntry.cs +++ b/src/Box2D.NET.Samples/Primitives/SampleEntry.cs @@ -12,9 +12,9 @@ public class SampleEntry public readonly string Category; public readonly string Name; public readonly string Title; - public readonly Func CreateFcn; + public readonly Func CreateFcn; - public SampleEntry(string category, string name, Func createFcn) + public SampleEntry(string category, string name, Func createFcn) { Category = category; Name = name; diff --git a/src/Box2D.NET.Samples/SampleApp.cs b/src/Box2D.NET.Samples/SampleApp.cs index f6e0aff2..7c25cdd4 100644 --- a/src/Box2D.NET.Samples/SampleApp.cs +++ b/src/Box2D.NET.Samples/SampleApp.cs @@ -37,8 +37,7 @@ public class SampleApp private ImGuiController _imgui; private int s_selection = 0; private Sample s_sample = null; - private SampleAppContext _ctx; - private Settings s_settings; + private SampleContext _context; private bool s_rightMouseDown = false; private B2Vec2 s_clickPointWS = b2Vec2_zero; private float s_windowScale = 1.0f; @@ -47,8 +46,7 @@ public class SampleApp public SampleApp() { - s_settings = new Settings(); - _ctx = SampleAppContext.Create(); + _context = SampleContext.Create(); } public int Run(string[] args) @@ -57,35 +55,31 @@ public int Run(string[] args) b2SetAllocator(AllocFcn, FreeFcn); b2SetAssertFcn(AssertFcn); - s_settings.Load(); - s_settings.workerCount = b2MinInt(8, Environment.ProcessorCount / 2); + _context.settings.Load(); + _context.settings.workerCount = b2MinInt(8, Environment.ProcessorCount / 2); SampleFactory.Shared.LoadSamples(); SampleFactory.Shared.SortSamples(); Window.PrioritizeGlfw(); - - _ctx.glfw.SetErrorCallback(glfwErrorCallback); - - _ctx.camera.m_width = s_settings.windowWidth; - _ctx.camera.m_height = s_settings.windowHeight; + _context.glfw.SetErrorCallback(glfwErrorCallback); var options = WindowOptions.Default; options.ShouldSwapAutomatically = false; - if (!_ctx.glfw.Init()) + if (!_context.glfw.Init()) { Logger.Information("Failed to initialize GLFW"); return -1; } - _ctx.glfw.WindowHint(WindowHintInt.ContextVersionMajor, 3); - _ctx.glfw.WindowHint(WindowHintInt.ContextVersionMinor, 3); - _ctx.glfw.WindowHint(WindowHintBool.OpenGLForwardCompat, true); - _ctx.glfw.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core); + _context.glfw.WindowHint(WindowHintInt.ContextVersionMajor, 3); + _context.glfw.WindowHint(WindowHintInt.ContextVersionMinor, 3); + _context.glfw.WindowHint(WindowHintBool.OpenGLForwardCompat, true); + _context.glfw.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core); // MSAA - _ctx.glfw.WindowHint(WindowHintInt.Samples, 4); + _context.glfw.WindowHint(WindowHintInt.Samples, 4); options.Samples = 4; B2Version version = b2GetVersion(); @@ -93,16 +87,16 @@ public int Run(string[] args) unsafe { - Monitor* primaryMonitor = _ctx.glfw.GetPrimaryMonitor(); + Monitor* primaryMonitor = _context.glfw.GetPrimaryMonitor(); if (null != primaryMonitor) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - _ctx.glfw.GetMonitorContentScale(primaryMonitor, out s_framebufferScale, out s_framebufferScale); + _context.glfw.GetMonitorContentScale(primaryMonitor, out s_framebufferScale, out s_framebufferScale); } else { - _ctx.glfw.GetMonitorContentScale(primaryMonitor, out s_windowScale, out s_windowScale); + _context.glfw.GetMonitorContentScale(primaryMonitor, out s_windowScale, out s_windowScale); } } } @@ -116,7 +110,7 @@ public int Run(string[] args) } else { - options.Size = new Vector2D((int)(_ctx.camera.m_width * s_windowScale), (int)(_ctx.camera.m_height * s_windowScale)); + options.Size = new Vector2D((int)(_context.camera.m_width * s_windowScale), (int)(_context.camera.m_height * s_windowScale)); //_ctx.g_mainWindow = _ctx.g_glfw.CreateWindow((int)(_ctx.g_camera.m_width * s_windowScale), (int)(_ctx.g_camera.m_height * s_windowScale), buffer, null, null); } @@ -129,8 +123,8 @@ public int Run(string[] args) _window.Render += OnWindowRenderSafe; _window.Run(); - _ctx.glfw.Terminate(); - s_settings.Save(); + _context.glfw.Terminate(); + _context.settings.Save(); return 0; } @@ -151,7 +145,7 @@ private void OnWindowClosing() { s_sample?.Dispose(); s_sample = null; - _ctx.draw.Destroy(); + _context.draw.Destroy(); DestroyUI(); } @@ -159,16 +153,16 @@ private void OnWindowResize(Vector2D resize) { var width = resize.X; var height = resize.Y; - s_settings.windowWidth = (int)(width / s_windowScale); - s_settings.windowHeight = (int)(height / s_windowScale); + _context.settings.windowWidth = (int)(width / s_windowScale); + _context.settings.windowHeight = (int)(height / s_windowScale); - _ctx.camera.m_width = (int)(width / s_windowScale); - _ctx.camera.m_height = (int)(height / s_windowScale); + _context.camera.m_width = (int)(width / s_windowScale); + _context.camera.m_height = (int)(height / s_windowScale); } private void OnWindowFrameBufferResize(Vector2D resize) { - _ctx.gl.Viewport(0, 0, (uint)resize.X, (uint)resize.Y); + _context.gl.Viewport(0, 0, (uint)resize.X, (uint)resize.Y); } private void OnWindowLoadSafe() @@ -191,8 +185,8 @@ private void OnWindowLoad() unsafe { - _ctx.mainWindow = (WindowHandle*)_window.Handle; - if (_ctx.mainWindow == null) + _context.window = (WindowHandle*)_window.Handle; + if (_context.window == null) { Logger.Information("Failed to open GLFW _ctx.g_mainWindow."); return; @@ -207,21 +201,21 @@ private void OnWindowLoad() // _ctx.g_glfw.GetWindowContentScale(_ctx.g_mainWindow, out s_windowScale, out s_windowScale); // } - _ctx.glfw.MakeContextCurrent(_ctx.mainWindow); + _context.glfw.MakeContextCurrent(_context.window); } _input = _window.CreateInput(); // Load OpenGL functions using glad - _ctx.gl = _window.CreateOpenGL(); - if (null == _ctx.gl) + _context.gl = _window.CreateOpenGL(); + if (null == _context.gl) { Logger.Information("Failed to initialize glad"); return; } { - string glVersionString = _ctx.gl.GetStringS(GLEnum.Version); - string glslVersionString = _ctx.gl.GetStringS(GLEnum.ShadingLanguageVersion); + string glVersionString = _context.gl.GetStringS(GLEnum.Version); + string glslVersionString = _context.gl.GetStringS(GLEnum.ShadingLanguageVersion); Logger.Information($"OpenGL {glVersionString}, GLSL {glslVersionString}"); } @@ -229,22 +223,22 @@ private void OnWindowLoad() { // _ctx.glfw.SetWindowSizeCallback(_ctx.mainWindow, ResizeWindowCallback); // _ctx.glfw.SetFramebufferSizeCallback(_ctx.mainWindow, ResizeFramebufferCallback); - _ctx.glfw.SetKeyCallback(_ctx.mainWindow, KeyCallback); - _ctx.glfw.SetCharCallback(_ctx.mainWindow, CharCallback); - _ctx.glfw.SetMouseButtonCallback(_ctx.mainWindow, MouseButtonCallback); - _ctx.glfw.SetCursorPosCallback(_ctx.mainWindow, MouseMotionCallback); - _ctx.glfw.SetScrollCallback(_ctx.mainWindow, ScrollCallback); + _context.glfw.SetKeyCallback(_context.window, KeyCallback); + _context.glfw.SetCharCallback(_context.window, CharCallback); + _context.glfw.SetMouseButtonCallback(_context.window, MouseButtonCallback); + _context.glfw.SetCursorPosCallback(_context.window, MouseMotionCallback); + _context.glfw.SetScrollCallback(_context.window, ScrollCallback); } - _ctx.draw.Create(_ctx); + _context.draw.Create(_context); - s_settings.sampleIndex = b2ClampInt(s_settings.sampleIndex, 0, SampleFactory.Shared.SampleCount - 1); - s_selection = s_settings.sampleIndex; + _context.settings.sampleIndex = b2ClampInt(_context.settings.sampleIndex, 0, SampleFactory.Shared.SampleCount - 1); + s_selection = _context.settings.sampleIndex; - // todo put this in s_settings + // todo put this in _context.settings CreateUI(glslVersion); - _ctx.gl.ClearColor(0.2f, 0.2f, 0.2f, 1.0f); + _context.gl.ClearColor(0.2f, 0.2f, 0.2f, 1.0f); } private void OnWindowUpdateSafe(double dt) @@ -263,21 +257,21 @@ private void OnWindowUpdate(double dt) { unsafe { - if (_ctx.glfw.WindowShouldClose(_ctx.mainWindow)) + if (_context.glfw.WindowShouldClose(_context.window)) return; } - double time1 = _ctx.glfw.GetTime(); + double time1 = _context.glfw.GetTime(); - if (GlfwHelpers.GetKey(_ctx, Keys.Z) == InputAction.Press) + if (GlfwHelpers.GetKey(_context, Keys.Z) == InputAction.Press) { // Zoom out - _ctx.camera.m_zoom = b2MinFloat(1.005f * _ctx.camera.m_zoom, 100.0f); + _context.camera.m_zoom = b2MinFloat(1.005f * _context.camera.m_zoom, 100.0f); } - else if (GlfwHelpers.GetKey(_ctx, Keys.X) == InputAction.Press) + else if (GlfwHelpers.GetKey(_context, Keys.X) == InputAction.Press) { // Zoom in - _ctx.camera.m_zoom = b2MaxFloat(0.995f * _ctx.camera.m_zoom, 0.5f); + _context.camera.m_zoom = b2MaxFloat(0.995f * _context.camera.m_zoom, 0.5f); } int bufferWidth = 0; @@ -286,48 +280,48 @@ private void OnWindowUpdate(double dt) double cursorPosY = 0.0d; unsafe { - _ctx.glfw.GetFramebufferSize(_ctx.mainWindow, out bufferWidth, out bufferHeight); + _context.glfw.GetFramebufferSize(_context.window, out bufferWidth, out bufferHeight); // _ctx.draw.DrawBackground(); - _ctx.glfw.GetCursorPos(_ctx.mainWindow, out cursorPosX, out cursorPosY); + _context.glfw.GetCursorPos(_context.window, out cursorPosX, out cursorPosY); } // For the Tracy profiler //FrameMark; - if (s_selection != s_settings.sampleIndex) + if (s_selection != _context.settings.sampleIndex) { - _ctx.camera.ResetView(); - s_settings.sampleIndex = s_selection; + _context.camera.ResetView(); + _context.settings.sampleIndex = s_selection; // #todo restore all drawing settings that may have been overridden by a sample - s_settings.subStepCount = 4; - s_settings.drawJoints = true; - s_settings.useCameraBounds = false; + _context.settings.subStepCount = 4; + _context.settings.drawJoints = true; + _context.settings.useCameraBounds = false; s_sample?.Dispose(); s_sample = null; - s_sample = SampleFactory.Shared.Create(s_settings.sampleIndex, _ctx, s_settings); + s_sample = SampleFactory.Shared.Create(_context.settings.sampleIndex, _context); } if (s_sample == null) { // delayed creation because imgui doesn't create fonts until NewFrame() is called - s_sample = SampleFactory.Shared.Create(s_settings.sampleIndex, _ctx, s_settings); + s_sample = SampleFactory.Shared.Create(_context.settings.sampleIndex, _context); } - s_sample.Step(s_settings); + s_sample.Step(); - _ctx.glfw.PollEvents(); + _context.glfw.PollEvents(); // Limit frame rate to 60Hz - double time2 = _ctx.glfw.GetTime(); + double time2 = _context.glfw.GetTime(); double targetTime = time1 + 1.0 / 60.0; while (time2 < targetTime) { b2Yield(); - time2 = _ctx.glfw.GetTime(); + time2 = _context.glfw.GetTime(); } _frameTime = (float)(time2 - time1); @@ -339,8 +333,8 @@ private void OnWindowUpdate(double dt) if (null != _imgui) { var io = ImGui.GetIO(); - io.DisplaySize = new Vector2(_ctx.camera.m_width, _ctx.camera.m_height); - io.DisplayFramebufferScale = new Vector2(bufferWidth / (float)_ctx.camera.m_width, bufferHeight / (float)_ctx.camera.m_height); + io.DisplaySize = new Vector2(_context.camera.m_width, _context.camera.m_height); + io.DisplayFramebufferScale = new Vector2(bufferWidth / (float)_context.camera.m_width, bufferHeight / (float)_context.camera.m_height); io.DeltaTime = (float)dt; _imgui.Update((float)dt); } @@ -360,31 +354,31 @@ private void OnWindowRenderSafe(double dt) private void OnWindowRender(double dt) { - _ctx.gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + _context.gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); ImGui.SetNextWindowPos(new Vector2(0.0f, 0.0f)); - ImGui.SetNextWindowSize(new Vector2(_ctx.camera.m_width, _ctx.camera.m_height)); + ImGui.SetNextWindowSize(new Vector2(_context.camera.m_width, _context.camera.m_height)); ImGui.SetNextWindowBgAlpha(0.0f); ImGui.Begin("Overlay", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar); ImGui.End(); - if (_ctx.draw.m_showUI) + if (_context.draw.m_showUI) { - var title = SampleFactory.Shared.GetTitle(s_settings.sampleIndex); + var title = SampleFactory.Shared.GetTitle(_context.settings.sampleIndex); s_sample.DrawTitle(title); } - s_sample.Draw(s_settings); - _ctx.draw.Flush(); + s_sample.Draw(_context.settings); + _context.draw.Flush(); UpdateUI(); //ImGui.ShowDemoWindow(); - if (_ctx.draw.m_showUI) + if (_context.draw.m_showUI) { string buffer = $"{1000.0f * _frameTime:0.0} ms - step {s_sample.m_stepCount} - " + - $"camera ({_ctx.camera.m_center.X:G}, {_ctx.camera.m_center.Y:G}, {_ctx.camera.m_zoom:G})"; + $"camera ({_context.camera.m_center.X:G}, {_context.camera.m_center.Y:G}, {_context.camera.m_zoom:G})"; // snprintf(buffer, 128, "%.1f ms - step %d - camera (%g, %g, %g)", 1000.0f * _frameTime, s_sample.m_stepCount, // _ctx.g_camera.m_center.x, _ctx.g_camera.m_center.y, _ctx.g_camera.m_zoom); // snprintf( buffer, 128, "%.1f ms", 1000.0f * frameTime ); @@ -392,7 +386,7 @@ private void OnWindowRender(double dt) ImGui.Begin("Overlay", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoScrollbar); - ImGui.SetCursorPos(new Vector2(5.0f, _ctx.camera.m_height - 20.0f)); + ImGui.SetCursorPos(new Vector2(5.0f, _context.camera.m_height - 20.0f)); ImGui.TextColored(new Vector4(153, 230, 153, 255), buffer); ImGui.End(); } @@ -401,7 +395,7 @@ private void OnWindowRender(double dt) //ImGui_ImplOpenGL3_RenderDrawData(ImGui.GetDrawData()); unsafe { - _ctx.glfw.SwapBuffers(_ctx.mainWindow); + _context.glfw.SwapBuffers(_context.window); } } @@ -453,10 +447,10 @@ private void RestartSample() { s_sample?.Dispose(); s_sample = null; - s_settings.restart = true; + _context.settings.restart = true; - s_sample = SampleFactory.Shared.Create(s_settings.sampleIndex, _ctx, s_settings); - s_settings.restart = false; + s_sample = SampleFactory.Shared.Create(_context.settings.sampleIndex, _context); + _context.settings.restart = false; } private void CreateUI(string glslVersion) @@ -491,7 +485,7 @@ private void CreateUI(string glslVersion) // for windows : Microsoft Visual C++ Redistributable Package // link - https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist var imGuiFontConfig = new ImGuiFontConfig(fontPath, 15, null); - _imgui = new ImGuiController(_ctx.gl, _window, _input, imGuiFontConfig); + _imgui = new ImGuiController(_context.gl, _window, _input, imGuiFontConfig); //ImGui.GetStyle().ScaleAllSizes(2); //imGuiIo.FontGlobalScale = 2.0f; @@ -529,7 +523,7 @@ private unsafe void KeyCallback(WindowHandle* window, Keys key, int scancode, In { case Keys.Escape: // Quit - _ctx.glfw.SetWindowShouldClose(_ctx.mainWindow, true); + _context.glfw.SetWindowShouldClose(_context.window, true); break; case Keys.Left: @@ -541,7 +535,7 @@ private unsafe void KeyCallback(WindowHandle* window, Keys key, int scancode, In } else { - _ctx.camera.m_center.X -= 0.5f; + _context.camera.m_center.X -= 0.5f; } break; @@ -555,7 +549,7 @@ private unsafe void KeyCallback(WindowHandle* window, Keys key, int scancode, In } else { - _ctx.camera.m_center.X += 0.5f; + _context.camera.m_center.X += 0.5f; } break; @@ -569,7 +563,7 @@ private unsafe void KeyCallback(WindowHandle* window, Keys key, int scancode, In } else { - _ctx.camera.m_center.Y -= 0.5f; + _context.camera.m_center.Y -= 0.5f; } break; @@ -583,13 +577,13 @@ private unsafe void KeyCallback(WindowHandle* window, Keys key, int scancode, In } else { - _ctx.camera.m_center.Y += 0.5f; + _context.camera.m_center.Y += 0.5f; } break; case Keys.Home: - _ctx.camera.ResetView(); + _context.camera.ResetView(); break; case Keys.R: @@ -597,11 +591,11 @@ private unsafe void KeyCallback(WindowHandle* window, Keys key, int scancode, In break; case Keys.O: - s_settings.singleStep = true; + _context.settings.singleStep = true; break; case Keys.P: - s_settings.pause = !s_settings.pause; + _context.settings.pause = !_context.settings.pause; break; case Keys.LeftBracket: @@ -625,7 +619,7 @@ private unsafe void KeyCallback(WindowHandle* window, Keys key, int scancode, In break; case Keys.Tab: - _ctx.draw.m_showUI = !_ctx.draw.m_showUI; + _context.draw.m_showUI = !_context.draw.m_showUI; break; default: @@ -644,28 +638,24 @@ private unsafe void CharCallback(WindowHandle* window, uint c) //ImGui_ImplGlfw_CharCallback(window, c); } - private unsafe void MouseButtonCallback(WindowHandle* window, MouseButton button, InputAction action, KeyModifiers mods) + private unsafe void MouseButtonCallback(WindowHandle* window, MouseButton button, InputAction action, KeyModifiers modifiers) { - //ImGui_ImplGlfw_MouseButtonCallback(window, button, action, mods); - // var io = ImGui.GetIO(); - // io.AddMouseButtonEvent((float)xd, (float)yd); - if (ImGui.GetIO().WantCaptureMouse) { return; } double xd, yd; - _ctx.glfw.GetCursorPos(_ctx.mainWindow, out xd, out yd); + _context.glfw.GetCursorPos(_context.window, out xd, out yd); B2Vec2 ps = new B2Vec2((float)(xd / s_windowScale), (float)(yd / s_windowScale)); // Use the mouse to move things around. if (button == (int)MouseButton.Left) { - B2Vec2 pw = _ctx.camera.ConvertScreenToWorld(ps); + B2Vec2 pw = _context.camera.ConvertScreenToWorld(ps); if (action == InputAction.Press) { - s_sample.MouseDown(pw, button, mods); + s_sample.MouseDown(pw, button, modifiers); } if (action == InputAction.Release) @@ -677,7 +667,7 @@ private unsafe void MouseButtonCallback(WindowHandle* window, MouseButton button { if (action == InputAction.Press) { - s_clickPointWS = _ctx.camera.ConvertScreenToWorld(ps); + s_clickPointWS = _context.camera.ConvertScreenToWorld(ps); s_rightMouseDown = true; } @@ -694,15 +684,15 @@ private unsafe void MouseMotionCallback(WindowHandle* window, double xd, double //ImGui_ImplGlfw_CursorPosCallback(window, ps.x, ps.y); - B2Vec2 pw = _ctx.camera.ConvertScreenToWorld(ps); + B2Vec2 pw = _context.camera.ConvertScreenToWorld(ps); s_sample?.MouseMove(pw); if (s_rightMouseDown) { B2Vec2 diff = b2Sub(pw, s_clickPointWS); - _ctx.camera.m_center.X -= diff.X; - _ctx.camera.m_center.Y -= diff.Y; - s_clickPointWS = _ctx.camera.ConvertScreenToWorld(ps); + _context.camera.m_center.X -= diff.X; + _context.camera.m_center.Y -= diff.Y; + s_clickPointWS = _context.camera.ConvertScreenToWorld(ps); } } @@ -718,11 +708,11 @@ private unsafe void ScrollCallback(WindowHandle* window, double dx, double dy) if (dy > 0) { - _ctx.camera.m_zoom /= 1.1f; + _context.camera.m_zoom /= 1.1f; } else { - _ctx.camera.m_zoom *= 1.1f; + _context.camera.m_zoom *= 1.1f; } } @@ -731,24 +721,24 @@ private void UpdateUI() int maxWorkers = (int)(Environment.ProcessorCount * 1.5f); float menuWidth = 180.0f; - if (_ctx.draw.m_showUI) + if (_context.draw.m_showUI) { - ImGui.SetNextWindowPos(new Vector2(_ctx.camera.m_width - menuWidth - 10.0f, 10.0f)); - ImGui.SetNextWindowSize(new Vector2(menuWidth, _ctx.camera.m_height - 20.0f)); + ImGui.SetNextWindowPos(new Vector2(_context.camera.m_width - menuWidth - 10.0f, 10.0f)); + ImGui.SetNextWindowSize(new Vector2(menuWidth, _context.camera.m_height - 20.0f)); - ImGui.Begin("Tools", ref _ctx.draw.m_showUI, ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse); + ImGui.Begin("Tools", ref _context.draw.m_showUI, ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse); if (ImGui.BeginTabBar("ControlTabs", ImGuiTabBarFlags.None)) { if (ImGui.BeginTabItem("Controls")) { ImGui.PushItemWidth(100.0f); - ImGui.SliderInt("Sub-steps", ref s_settings.subStepCount, 1, 50); - ImGui.SliderFloat("Hertz", ref s_settings.hertz, 5.0f, 120.0f, "%.0f hz"); + ImGui.SliderInt("Sub-steps", ref _context.settings.subStepCount, 1, 50); + ImGui.SliderFloat("Hertz", ref _context.settings.hertz, 5.0f, 120.0f, "%.0f hz"); - if (ImGui.SliderInt("Workers", ref s_settings.workerCount, 1, maxWorkers)) + if (ImGui.SliderInt("Workers", ref _context.settings.workerCount, 1, maxWorkers)) { - s_settings.workerCount = b2ClampInt(s_settings.workerCount, 1, maxWorkers); + _context.settings.workerCount = b2ClampInt(_context.settings.workerCount, 1, maxWorkers); RestartSample(); } @@ -756,37 +746,37 @@ private void UpdateUI() ImGui.Separator(); - ImGui.Checkbox("Sleep", ref s_settings.enableSleep); - ImGui.Checkbox("Warm Starting", ref s_settings.enableWarmStarting); - ImGui.Checkbox("Continuous", ref s_settings.enableContinuous); + ImGui.Checkbox("Sleep", ref _context.settings.enableSleep); + ImGui.Checkbox("Warm Starting", ref _context.settings.enableWarmStarting); + ImGui.Checkbox("Continuous", ref _context.settings.enableContinuous); ImGui.Separator(); - ImGui.Checkbox("Shapes", ref s_settings.drawShapes); - ImGui.Checkbox("Joints", ref s_settings.drawJoints); - ImGui.Checkbox("Joint Extras", ref s_settings.drawJointExtras); - ImGui.Checkbox("Bounds", ref s_settings.drawBounds); - ImGui.Checkbox("Contact Points", ref s_settings.drawContactPoints); - ImGui.Checkbox("Contact Normals", ref s_settings.drawContactNormals); - ImGui.Checkbox("Contact Impulses", ref s_settings.drawContactImpulses); - ImGui.Checkbox("Contact Features", ref s_settings.drawContactFeatures); - ImGui.Checkbox("Friction Impulses", ref s_settings.drawFrictionImpulses); - ImGui.Checkbox("Mass", ref s_settings.drawMass); - ImGui.Checkbox("Body Names", ref s_settings.drawBodyNames); - ImGui.Checkbox("Graph Colors", ref s_settings.drawGraphColors); - ImGui.Checkbox("Islands", ref s_settings.drawIslands); - ImGui.Checkbox("Counters", ref s_settings.drawCounters); - ImGui.Checkbox("Profile", ref s_settings.drawProfile); + ImGui.Checkbox("Shapes", ref _context.settings.drawShapes); + ImGui.Checkbox("Joints", ref _context.settings.drawJoints); + ImGui.Checkbox("Joint Extras", ref _context.settings.drawJointExtras); + ImGui.Checkbox("Bounds", ref _context.settings.drawBounds); + ImGui.Checkbox("Contact Points", ref _context.settings.drawContactPoints); + ImGui.Checkbox("Contact Normals", ref _context.settings.drawContactNormals); + ImGui.Checkbox("Contact Impulses", ref _context.settings.drawContactImpulses); + ImGui.Checkbox("Contact Features", ref _context.settings.drawContactFeatures); + ImGui.Checkbox("Friction Impulses", ref _context.settings.drawFrictionImpulses); + ImGui.Checkbox("Mass", ref _context.settings.drawMass); + ImGui.Checkbox("Body Names", ref _context.settings.drawBodyNames); + ImGui.Checkbox("Graph Colors", ref _context.settings.drawGraphColors); + ImGui.Checkbox("Islands", ref _context.settings.drawIslands); + ImGui.Checkbox("Counters", ref _context.settings.drawCounters); + ImGui.Checkbox("Profile", ref _context.settings.drawProfile); Vector2 button_sz = new Vector2(-1, 0); if (ImGui.Button("Pause (P)", button_sz)) { - s_settings.pause = !s_settings.pause; + _context.settings.pause = !_context.settings.pause; } if (ImGui.Button("Single Step (O)", button_sz)) { - s_settings.singleStep = !s_settings.singleStep; + _context.settings.singleStep = !_context.settings.singleStep; } if (ImGui.Button("Dump Mem Stats", button_sz)) @@ -808,7 +798,7 @@ private void UpdateUI() { unsafe { - _ctx.glfw.SetWindowShouldClose(_ctx.mainWindow, true); + _context.glfw.SetWindowShouldClose(_context.window, true); } } @@ -827,7 +817,7 @@ private void UpdateUI() int i = 0; while (i < SampleFactory.Shared.SampleCount) { - bool categorySelected = category == SampleFactory.Shared.GetCategory(s_settings.sampleIndex); + bool categorySelected = category == SampleFactory.Shared.GetCategory(_context.settings.sampleIndex); ImGuiTreeNodeFlags nodeSelectionFlags = categorySelected ? ImGuiTreeNodeFlags.Selected : 0; bool nodeOpen = ImGui.TreeNodeEx(category, nodeFlags | nodeSelectionFlags); @@ -836,7 +826,7 @@ private void UpdateUI() while (i < SampleFactory.Shared.SampleCount && category == SampleFactory.Shared.GetCategory(i)) { ImGuiTreeNodeFlags selectionFlags = 0; - if (s_settings.sampleIndex == i) + if (_context.settings.sampleIndex == i) { selectionFlags = ImGuiTreeNodeFlags.Selected; } diff --git a/src/Box2D.NET.Samples/SampleAppContext.cs b/src/Box2D.NET.Samples/SampleContext.cs similarity index 63% rename from src/Box2D.NET.Samples/SampleAppContext.cs rename to src/Box2D.NET.Samples/SampleContext.cs index 2a8d2606..c6cb672b 100644 --- a/src/Box2D.NET.Samples/SampleAppContext.cs +++ b/src/Box2D.NET.Samples/SampleContext.cs @@ -9,24 +9,26 @@ namespace Box2D.NET.Samples; -public class SampleAppContext +public class SampleContext { // public readonly string Signature; public readonly Glfw glfw; public readonly Camera camera; public readonly Draw draw; - + + public readonly Settings settings; + // public GL gl; - public unsafe WindowHandle* mainWindow; + public unsafe WindowHandle* window; private static string CreateSignature(string member, string file, int line) { return $"{member}() {Path.GetFileName(file)}:{line}"; } - public static SampleAppContext Create([CallerMemberName] string member = "", [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) + public static SampleContext Create([CallerMemberName] string member = "", [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { // for windows - https://learn.microsoft.com/ko-kr/cpp/windows/latest-supported-vc-redist var glfw = Glfw.GetApi(); @@ -34,23 +36,24 @@ public static SampleAppContext Create([CallerMemberName] string member = "", [Ca return CreateFor(sig, glfw); } - public static SampleAppContext CreateWithoutGLFW([CallerMemberName] string member = "", [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) + public static SampleContext CreateWithoutGLFW([CallerMemberName] string member = "", [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { var sig = CreateSignature(member, file, line); return CreateFor(sig, null); } - public static SampleAppContext CreateFor(string sig, Glfw glfw) + public static SampleContext CreateFor(string sig, Glfw glfw) { - var context = new SampleAppContext(sig, glfw); + var context = new SampleContext(sig, glfw); return context; } - private SampleAppContext(string signature, Glfw glfw) + private SampleContext(string signature, Glfw glfw) { Signature = signature; this.glfw = glfw; camera = new Camera(); draw = new Draw(); + settings = new Settings(); } } diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkBarrel.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkBarrel.cs index 9c3d7bec..1ba52468 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkBarrel.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkBarrel.cs @@ -42,20 +42,20 @@ public enum ShapeType private ShapeType m_shapeType; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkBarrel(ctx, settings); + return new BenchmarkBarrel(context); } - public BenchmarkBarrel(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkBarrel(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(8.0f, 53.0f); m_context.camera.m_zoom = 25.0f * 2.35f; } - settings.drawJoints = false; + m_context.settings.drawJoints = false; { float gridSize = 1.0f; @@ -118,7 +118,7 @@ public BenchmarkBarrel(SampleAppContext ctx, Settings settings) : base(ctx, sett void CreateScene() { - g_seed = 42; + g_randomSeed = 42; for (int i = 0; i < e_maxRows * e_maxColumns; ++i) { diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCast.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCast.cs index 4ceaf4ec..aa6d309c 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCast.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCast.cs @@ -45,18 +45,18 @@ public class BenchmarkCast : Sample private int leafVisits = 0; private float ms = 0.0f; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkCast(ctx, settings); + return new BenchmarkCast(context); } - public BenchmarkCast(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkCast(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(500.0f, 500.0f); m_context.camera.m_zoom = 25.0f * 21.0f; - // settings.drawShapes = m_context.g_sampleDebug; + // m_context.settings.drawShapes = m_context.g_sampleDebug; } m_queryType = QueryType.e_circleCast; @@ -71,7 +71,7 @@ public BenchmarkCast(SampleAppContext ctx, Settings settings) : base(ctx, settin m_buildTime = 0.0f; m_radius = 0.1f; - g_seed = 1234; + g_randomSeed = 1234; sampleCount = m_isDebug ? 100 : 10000; m_origins.Resize(sampleCount); m_translations.Resize(sampleCount); @@ -92,7 +92,7 @@ public BenchmarkCast(SampleAppContext ctx, Settings settings) : base(ctx, settin void BuildScene() { - g_seed = 1234; + g_randomSeed = 1234; b2DestroyWorld(m_worldId); B2WorldDef worldDef = b2DefaultWorldDef(); m_worldId = b2CreateWorld(ref worldDef); @@ -186,9 +186,9 @@ static bool OverlapCallback(B2ShapeId shapeId, object context) } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); B2QueryFilter filter = b2DefaultQueryFilter(); filter.maskBits = 1; @@ -399,20 +399,20 @@ public override void Draw(Settings settings) { base.Draw(settings); - m_context.draw.DrawString(5, m_textLine, $"build time ms = {m_buildTime:g}"); - m_textLine += m_textIncrement; + DrawTextLine($"build time ms = {m_buildTime:g}"); + - m_context.draw.DrawString(5, m_textLine, $"hit count = {hitCount}, node visits = {nodeVisits}, leaf visits = {leafVisits}"); - m_textLine += m_textIncrement; + DrawTextLine($"hit count = {hitCount}, node visits = {nodeVisits}, leaf visits = {leafVisits}"); + - m_context.draw.DrawString(5, m_textLine, $"total ms = {ms:F3}"); - m_textLine += m_textIncrement; + DrawTextLine($"total ms = {ms:F3}"); + - m_context.draw.DrawString(5, m_textLine, $"min total ms = {m_minTime:F3}"); - m_textLine += m_textIncrement; + DrawTextLine($"min total ms = {m_minTime:F3}"); + float aveRayCost = 1000.0f * m_minTime / (float)sampleCount; - m_context.draw.DrawString(5, m_textLine, $"average us = {aveRayCost:F2}"); - m_textLine += m_textIncrement; + DrawTextLine($"average us = {aveRayCost:F2}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCompound.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCompound.cs index 1328b3f8..394b5521 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCompound.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCompound.cs @@ -14,14 +14,14 @@ public class BenchmarkCompound : Sample { private static readonly int SampleCompound = SampleFactory.Shared.RegisterSample("Benchmark", "Compound", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkCompound(ctx, settings); + return new BenchmarkCompound(context); } - public BenchmarkCompound(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkCompound(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(18.0f, 115.0f); m_context.camera.m_zoom = 25.0f * 5.5f; diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCreateDestroy.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCreateDestroy.cs index fe648d79..e24e00db 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCreateDestroy.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCreateDestroy.cs @@ -28,14 +28,14 @@ public class BenchmarkCreateDestroy : Sample private int m_iterations; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkCreateDestroy(ctx, settings); + return new BenchmarkCreateDestroy(context); } - public BenchmarkCreateDestroy(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkCreateDestroy(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 50.0f); m_context.camera.m_zoom = 25.0f * 2.2f; @@ -120,7 +120,7 @@ void CreateScene() b2World_Step(m_worldId, 1.0f / 60.0f, 4); } - public override void Step(Settings settings) + public override void Step() { m_createTime = 0.0f; m_destroyTime = 0.0f; @@ -131,7 +131,7 @@ public override void Step(Settings settings) } - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkJointGrid.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkJointGrid.cs index 60d7543e..f845f66e 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkJointGrid.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkJointGrid.cs @@ -10,18 +10,18 @@ public class BenchmarkJointGrid : Sample { private static readonly int BenchmarkJointGridIndex = SampleFactory.Shared.RegisterSample("Benchmark", "Joint Grid", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkJointGrid(ctx, settings); + return new BenchmarkJointGrid(context); } - public BenchmarkJointGrid(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkJointGrid(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(60.0f, -57.0f); m_context.camera.m_zoom = 25.0f * 2.5f; - settings.enableSleep = false; + m_context.settings.enableSleep = false; } CreateJointGrid(m_worldId); diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkKinematic.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkKinematic.cs index 596b92de..9eb89f32 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkKinematic.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkKinematic.cs @@ -14,14 +14,14 @@ public class BenchmarkKinematic : Sample { private static readonly int SampleKinematic = SampleFactory.Shared.RegisterSample("Benchmark", "Kinematic", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkKinematic(ctx, settings); + return new BenchmarkKinematic(context); } - public BenchmarkKinematic(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkKinematic(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 150.0f; diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkLargePyramid.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkLargePyramid.cs index b3f92071..30310602 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkLargePyramid.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkLargePyramid.cs @@ -10,18 +10,18 @@ public class BenchmarkLargePyramid : Sample { private static readonly int SampleBenchmarkLargePyramid = SampleFactory.Shared.RegisterSample("Benchmark", "Large Pyramid", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkLargePyramid(ctx, settings); + return new BenchmarkLargePyramid(context); } - public BenchmarkLargePyramid(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkLargePyramid(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 50.0f); m_context.camera.m_zoom = 25.0f * 2.2f; - settings.enableSleep = false; + m_context.settings.enableSleep = false; } CreateLargePyramid(m_worldId); diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyPyramids.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyPyramids.cs index c109d15b..c94b7d4d 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyPyramids.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyPyramids.cs @@ -10,18 +10,18 @@ public class BenchmarkManyPyramids : Sample { private static readonly int SampleBenchmarkManyPyramids = SampleFactory.Shared.RegisterSample("Benchmark", "Many Pyramids", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkManyPyramids(ctx, settings); + return new BenchmarkManyPyramids(context); } - public BenchmarkManyPyramids(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkManyPyramids(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(16.0f, 110.0f); m_context.camera.m_zoom = 25.0f * 5.0f; - settings.enableSleep = false; + m_context.settings.enableSleep = false; } CreateManyPyramids(m_worldId); diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyTumblers.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyTumblers.cs index f1abf983..6faff72b 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyTumblers.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyTumblers.cs @@ -34,18 +34,18 @@ public class BenchmarkManyTumblers : Sample private float m_angularSpeed; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkManyTumblers(ctx, settings); + return new BenchmarkManyTumblers(context); } - public BenchmarkManyTumblers(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkManyTumblers(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(1.0f, -5.5f); m_context.camera.m_zoom = 25.0f * 3.4f; - settings.drawJoints = false; + m_context.settings.drawJoints = false; } B2BodyDef bodyDef = b2DefaultBodyDef(); @@ -170,9 +170,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); if (m_bodyIndex < m_bodyCount && (m_stepCount & 0x7) == 0) { diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkRain.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkRain.cs index bee45aee..10ad1a6a 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkRain.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkRain.cs @@ -13,33 +13,33 @@ public class BenchmarkRain : Sample private RainData m_rainData; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkRain(ctx, settings); + return new BenchmarkRain(context); } - public BenchmarkRain(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkRain(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 110.0f); m_context.camera.m_zoom = 125.0f; - settings.enableSleep = true; + m_context.settings.enableSleep = true; } - settings.drawJoints = false; + m_context.settings.drawJoints = false; m_rainData = CreateRain(m_worldId); } - public override void Step(Settings settings) + public override void Step() { - if (settings.pause == false || settings.singleStep == true) + if (m_context.settings.pause == false || m_context.settings.singleStep == true) { StepRain(m_rainData, m_worldId, m_stepCount); } - base.Step(settings); + base.Step(); if (m_stepCount % 1000 == 0) { diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSensor.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSensor.cs index f27dfcb4..86bf777e 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSensor.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSensor.cs @@ -30,17 +30,17 @@ public class ShapeUserData private ShapeUserData m_activeSensor = new ShapeUserData(); private int m_lastStepCount; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkSensor(ctx, settings); + return new BenchmarkSensor(context); } - public BenchmarkSensor(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkSensor(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { - m_context.camera.m_center = new B2Vec2(0.0f, 110.0f); - m_context.camera.m_zoom = 115.0f; + m_context.camera.m_center = new B2Vec2(0.0f, 105.0f); + m_context.camera.m_zoom = 125.0f; } m_passiveSensor.shouldDestroyVisitors = false; @@ -67,7 +67,7 @@ public BenchmarkSensor(SampleAppContext ctx, Settings settings) : base(ctx, sett } } - g_seed = 42; + g_randomSeed = 42; { float shift = 5.0f; @@ -121,9 +121,9 @@ void CreateRow(float y) } } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); if (m_stepCount == m_lastStepCount) { diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkShapeDistance.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkShapeDistance.cs index 76590515..71b4ae5b 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkShapeDistance.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkShapeDistance.cs @@ -30,14 +30,14 @@ public class BenchmarkShapeDistance : Sample // for draw private int totalIterations = 0; - public static Sample Create(SampleAppContext ctx, Settings settings) + public static Sample Create(SampleContext context) { - return new BenchmarkShapeDistance(ctx, settings); + return new BenchmarkShapeDistance(context); } - public BenchmarkShapeDistance(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkShapeDistance(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 3.0f; @@ -78,7 +78,7 @@ public BenchmarkShapeDistance(SampleAppContext ctx, Settings settings) : base(ct m_transformBs = new B2Transform[m_count]; m_outputs = new B2DistanceOutput[m_count]; - g_seed = 42; + g_randomSeed = 42; for (int i = 0; i < m_count; ++i) { m_transformAs[i] = new B2Transform(RandomVec2(-0.1f, 0.1f), RandomRot()); @@ -110,9 +110,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - if (settings.pause == false || settings.singleStep == true) + if (m_context.settings.pause == false || m_context.settings.singleStep == true) { B2DistanceInput input = new B2DistanceInput(); input.proxyA = b2MakeProxy(m_polygonA.vertices.AsSpan(), m_polygonA.count, m_polygonA.radius); @@ -139,14 +139,14 @@ public override void Step(Settings settings) } - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) { base.Draw(settings); - if (settings.pause == false || settings.singleStep == true) + if (m_context.settings.pause == false || m_context.settings.singleStep == true) { DrawTextLine($"count = {m_count}"); DrawTextLine($"min cycles = {m_minCycles}"); diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSleep.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSleep.cs index d6bb86d1..51272a6d 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSleep.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSleep.cs @@ -30,15 +30,15 @@ public class BenchmarkSleep : Sample private bool m_awake; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkSleep(ctx, settings); + return new BenchmarkSleep(context); } - public BenchmarkSleep(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkSleep(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 50.0f); m_context.camera.m_zoom = 25.0f * 2.2f; @@ -121,7 +121,7 @@ void CreateScene() m_bodyCount = index; } - public override void Step(Settings settings) + public override void Step() { ulong ticks = b2GetTicks(); @@ -143,7 +143,7 @@ public override void Step(Settings settings) } - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) @@ -152,14 +152,14 @@ public override void Draw(Settings settings) if (m_wakeCount > 0) { - m_context.draw.DrawString(5, m_textLine, $"wake ave = {m_wakeTotal / m_wakeCount:g} ms"); - m_textLine += m_textIncrement; + DrawTextLine($"wake ave = {m_wakeTotal / m_wakeCount:g} ms"); + } if (m_sleepCount > 0) { - m_context.draw.DrawString(5, m_textLine, $"sleep ave = {m_sleepTotal / m_sleepCount:g} ms"); - m_textLine += m_textIncrement; + DrawTextLine($"sleep ave = {m_sleepTotal / m_sleepCount:g} ms"); + } } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSmash.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSmash.cs index cf2e6a42..270dfa17 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSmash.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSmash.cs @@ -21,14 +21,14 @@ public class BenchmarkSmash : Sample private const int MaxRowCount = 160; private const int MaxColumnCount = 1200; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkSmash(ctx, settings); + return new BenchmarkSmash(context); } - public BenchmarkSmash(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkSmash(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(60.0f, 6.0f); m_context.camera.m_zoom = 25.0f * 1.6f; diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSpinner.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSpinner.cs index 0e0a9a93..e0b1c630 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSpinner.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSpinner.cs @@ -11,14 +11,14 @@ public class BenchmarkSpinner : Sample { private static readonly int SampleBenchmarkSpinner = SampleFactory.Shared.RegisterSample("Benchmark", "Spinner", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkSpinner(ctx, settings); + return new BenchmarkSpinner(context); } - public BenchmarkSpinner(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkSpinner(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 32.0f); m_context.camera.m_zoom = 42.0f; @@ -30,16 +30,16 @@ public BenchmarkSpinner(SampleAppContext ctx, Settings settings) : base(ctx, set CreateSpinner(m_worldId); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); if (m_stepCount == 1000 && false) { // 0.1 : 46544, 25752 // 0.25 : 5745, 1947 // 0.5 : 2197, 660 - settings.pause = true; + m_context.settings.pause = true; } } diff --git a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkTumbler.cs b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkTumbler.cs index 4c767bd4..5b6e2903 100644 --- a/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkTumbler.cs +++ b/src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkTumbler.cs @@ -10,14 +10,14 @@ public class BenchmarkTumbler : Sample { private static readonly int SampleBenchmarkTumbler = SampleFactory.Shared.RegisterSample("Benchmark", "Tumbler", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BenchmarkTumbler(ctx, settings); + return new BenchmarkTumbler(context); } - public BenchmarkTumbler(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BenchmarkTumbler(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(1.5f, 10.0f); m_context.camera.m_zoom = 25.0f * 0.6f; diff --git a/src/Box2D.NET.Samples/Samples/Bodies/BadBody.cs b/src/Box2D.NET.Samples/Samples/Bodies/BadBody.cs index be26b5a1..236c738c 100644 --- a/src/Box2D.NET.Samples/Samples/Bodies/BadBody.cs +++ b/src/Box2D.NET.Samples/Samples/Bodies/BadBody.cs @@ -16,14 +16,14 @@ public class BadBody : Sample private static readonly int SampleBadBody = SampleFactory.Shared.RegisterSample("Bodies", "Bad", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BadBody(ctx, settings); + return new BadBody(context); } - public BadBody(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BadBody(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(2.3f, 10.0f); m_context.camera.m_zoom = 25.0f * 0.5f; @@ -73,9 +73,9 @@ public BadBody(SampleAppContext ctx, Settings settings) : base(ctx, settings) } } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); // For science @@ -85,11 +85,10 @@ public override void Step(Settings settings) public override void Draw(Settings setting) { base.Draw(setting); - - m_context.draw.DrawString(5, m_textLine, "A bad body is a dynamic body with no mass and behaves like a kinematic body."); - m_textLine += m_textIncrement; - m_context.draw.DrawString(5, m_textLine, "Bad bodies are considered invalid and a user bug. Behavior is not guaranteed."); - m_textLine += m_textIncrement; + DrawTextLine("A bad body is a dynamic body with no mass and behaves like a kinematic body."); + + + DrawTextLine("Bad bodies are considered invalid and a user bug. Behavior is not guaranteed."); } -} +} \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Bodies/BodyType.cs b/src/Box2D.NET.Samples/Samples/Bodies/BodyType.cs index ea28525f..d65ad7fc 100644 --- a/src/Box2D.NET.Samples/Samples/Bodies/BodyType.cs +++ b/src/Box2D.NET.Samples/Samples/Bodies/BodyType.cs @@ -28,14 +28,14 @@ public class BodyType : Sample private float m_speed; private bool m_isEnabled; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BodyType(ctx, settings); + return new BodyType(context); } - public BodyType(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BodyType(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.8f, 6.4f); m_context.camera.m_zoom = 25.0f * 0.4f; @@ -269,7 +269,7 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { // Drive the kinematic body. if (m_type == B2BodyType.b2_kinematicBody) @@ -284,6 +284,6 @@ public override void Step(Settings settings) } } - base.Step(settings); + base.Step(); } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Bodies/Kinematic.cs b/src/Box2D.NET.Samples/Samples/Bodies/Kinematic.cs index 207519c7..a5d51914 100644 --- a/src/Box2D.NET.Samples/Samples/Bodies/Kinematic.cs +++ b/src/Box2D.NET.Samples/Samples/Bodies/Kinematic.cs @@ -17,14 +17,14 @@ public class Kinematic : Sample private float m_time; private float m_timeStep; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Kinematic(ctx, settings); + return new Kinematic(context); } - public Kinematic(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Kinematic(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 4.0f; @@ -48,16 +48,16 @@ public Kinematic(SampleAppContext ctx, Settings settings) : base(ctx, settings) } - public override void Step(Settings settings) + public override void Step() { - m_timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f; - if (settings.pause && settings.singleStep == false) + m_timeStep = m_context.settings.hertz > 0.0f ? 1.0f / m_context.settings.hertz : 0.0f; + if (m_context.settings.pause && m_context.settings.singleStep == false) { m_timeStep = 0.0f; } - base.Step(settings); + base.Step(); m_time += m_timeStep; } diff --git a/src/Box2D.NET.Samples/Samples/Bodies/Pivot.cs b/src/Box2D.NET.Samples/Samples/Bodies/Pivot.cs index d9401f29..661c2f06 100644 --- a/src/Box2D.NET.Samples/Samples/Bodies/Pivot.cs +++ b/src/Box2D.NET.Samples/Samples/Bodies/Pivot.cs @@ -19,14 +19,14 @@ public class Pivot : Sample private B2BodyId m_bodyId; private float m_lever; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Pivot(ctx, settings); + return new Pivot(context); } - public Pivot(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Pivot(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.8f, 6.4f); m_context.camera.m_zoom = 25.0f * 0.4f; @@ -76,7 +76,7 @@ public override void Draw(Settings settings) B2Vec2 r = b2Body_GetWorldVector(m_bodyId, new B2Vec2(0.0f, -m_lever)); B2Vec2 vp = v + b2CrossSV(omega, r); - m_context.draw.DrawString(5, m_textLine, $"pivot velocity = ({vp.X:g}, {vp.Y:g})"); - m_textLine += m_textIncrement; + DrawTextLine($"pivot velocity = ({vp.X:g}, {vp.Y:g})"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Bodies/Sleep.cs b/src/Box2D.NET.Samples/Samples/Bodies/Sleep.cs index 7d73df36..8a0c657a 100644 --- a/src/Box2D.NET.Samples/Samples/Bodies/Sleep.cs +++ b/src/Box2D.NET.Samples/Samples/Bodies/Sleep.cs @@ -25,14 +25,14 @@ public class Sleep : Sample private B2ShapeId[] m_sensorIds = new B2ShapeId[2]; private bool[] m_sensorTouching = new bool[2]; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Sleep(ctx, settings); + return new Sleep(context); } - public Sleep(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Sleep(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(3.0f, 50.0f); m_context.camera.m_zoom = 25.0f * 2.2f; @@ -218,9 +218,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); // Detect sensors touching the ground B2SensorEvents sensorEvents = b2World_GetSensorEvents(m_worldId); @@ -264,8 +264,8 @@ public override void Draw(Settings settings) for (int i = 0; i < 2; ++i) { - m_context.draw.DrawString(5, m_textLine, $"sensor touch {i} = {m_sensorTouching[i]}"); - m_textLine += m_textIncrement; + DrawTextLine($"sensor touch {i} = {m_sensorTouching[i]}"); + } } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Bodies/Weeble.cs b/src/Box2D.NET.Samples/Samples/Bodies/Weeble.cs index 4dd54991..fb3d0668 100644 --- a/src/Box2D.NET.Samples/Samples/Bodies/Weeble.cs +++ b/src/Box2D.NET.Samples/Samples/Bodies/Weeble.cs @@ -23,14 +23,14 @@ public class Weeble : Sample private float m_explosionRadius; private float m_explosionMagnitude; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Weeble(ctx, settings); + return new Weeble(context); } - public Weeble(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Weeble(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(2.3f, 10.0f); m_context.camera.m_zoom = 25.0f * 0.5f; diff --git a/src/Box2D.NET.Samples/Samples/Characters/Mover.cs b/src/Box2D.NET.Samples/Samples/Characters/Mover.cs index 5117ed99..4ebbceed 100644 --- a/src/Box2D.NET.Samples/Samples/Characters/Mover.cs +++ b/src/Box2D.NET.Samples/Samples/Characters/Mover.cs @@ -95,9 +95,9 @@ public class CastResult private int m_deltaX; private int m_deltaY; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Mover(ctx, settings); + return new Mover(context); } private static float CastCallback(B2ShapeId shapeId, B2Vec2 point, B2Vec2 normal, float fraction, object context) @@ -111,15 +111,15 @@ private static float CastCallback(B2ShapeId shapeId, B2Vec2 point, B2Vec2 normal return fraction; } - public Mover(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Mover(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(20.0f, 9.0f); m_context.camera.m_zoom = 10.0f; } - settings.drawJoints = false; + m_context.settings.drawJoints = false; m_transform = new B2Transform(new B2Vec2(2.0f, 8.0f), b2Rot_identity); m_velocity = new B2Vec2(0.0f, 0.0f); m_capsule = new B2Capsule(new B2Vec2(0.0f, -0.5f * m_capsuleInteriorLength), new B2Vec2(0.0f, 0.5f * m_capsuleInteriorLength), m_capsuleInteriorLength); @@ -620,17 +620,17 @@ public override void Keyboard(Keys key) base.Keyboard(key); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); bool pause = false; - if (settings.pause) + if (m_context.settings.pause) { - pause = settings.singleStep != true; + pause = m_context.settings.singleStep != true; } - float timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f; + float timeStep = m_context.settings.hertz > 0.0f ? 1.0f / m_context.settings.hertz : 0.0f; if (pause) { timeStep = 0.0f; diff --git a/src/Box2D.NET.Samples/Samples/Collisions/CastWorld.cs b/src/Box2D.NET.Samples/Samples/Collisions/CastWorld.cs index b058f60a..404f9543 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/CastWorld.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/CastWorld.cs @@ -69,15 +69,15 @@ enum CastType private bool m_dragging; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new CastWorld(ctx, settings); + return new CastWorld(context); } - public CastWorld(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public CastWorld(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(2.0f, 14.0f); m_context.camera.m_zoom = 25.0f * 0.75f; @@ -368,9 +368,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); B2HexColor color1 = B2HexColor.b2_colorGreen; B2HexColor color2 = B2HexColor.b2_colorLightGray; @@ -504,36 +504,36 @@ public override void Draw(Settings settings) { base.Draw(settings); - m_context.draw.DrawString(5, m_textLine, "Click left mouse button and drag to modify ray cast"); - m_textLine += m_textIncrement; - m_context.draw.DrawString(5, m_textLine, "Shape 7 is intentionally ignored by the ray"); - m_textLine += m_textIncrement; + DrawTextLine("Click left mouse button and drag to modify ray cast"); + + DrawTextLine("Shape 7 is intentionally ignored by the ray"); + - m_textLine += m_textIncrement; + if (m_simple) { - m_context.draw.DrawString(5, m_textLine, "Simple closest point ray cast"); - m_textLine += m_textIncrement; + DrawTextLine("Simple closest point ray cast"); + } else { switch ((Mode)m_mode) { case Mode.e_any: - m_context.draw.DrawString(5, m_textLine, "Cast mode: any - check for obstruction - unsorted"); + DrawTextLine("Cast mode: any - check for obstruction - unsorted"); break; case Mode.e_closest: - m_context.draw.DrawString(5, m_textLine, "Cast mode: closest - find closest shape along the cast"); + DrawTextLine("Cast mode: closest - find closest shape along the cast"); break; case Mode.e_multiple: - m_context.draw.DrawString(5, m_textLine, "Cast mode: multiple - gather up to 3 shapes - unsorted"); + DrawTextLine("Cast mode: multiple - gather up to 3 shapes - unsorted"); break; case Mode.e_sorted: - m_context.draw.DrawString(5, m_textLine, "Cast mode: sorted - gather up to 3 shapes sorted by closeness"); + DrawTextLine("Cast mode: sorted - gather up to 3 shapes sorted by closeness"); break; default: @@ -541,7 +541,7 @@ public override void Draw(Settings settings) break; } - m_textLine += m_textIncrement; + } if (B2_IS_NON_NULL(m_bodyIds[m_ignoreIndex])) diff --git a/src/Box2D.NET.Samples/Samples/Collisions/DynamicTree.cs b/src/Box2D.NET.Samples/Samples/Collisions/DynamicTree.cs index d8e2445d..7f35e00c 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/DynamicTree.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/DynamicTree.cs @@ -67,15 +67,15 @@ static float RayCallback(ref B2RayCastInput input, int proxyId, ulong userData, } - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new DynamicTree(ctx, settings); + return new DynamicTree(context); } - public DynamicTree(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public DynamicTree(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(500.0f, 500.0f); m_context.camera.m_zoom = 25.0f * 21.0f; @@ -299,7 +299,7 @@ public override void MouseMove(B2Vec2 p) } - public override void Step(Settings settings) + public override void Step() { // m_startPoint = {-1.0f, 0.5f}; // m_endPoint = {7.0f, 0.5f}; @@ -447,30 +447,30 @@ public override void Draw(Settings settings) m_context.draw.DrawPoint(m_startPoint, 5.0f, B2HexColor.b2_colorGreen); m_context.draw.DrawPoint(m_endPoint, 5.0f, B2HexColor.b2_colorRed); - m_context.draw.DrawString(5, m_textLine, $"node visits = {result.nodeVisits}, leaf visits = {result.leafVisits}"); - m_textLine += m_textIncrement; + DrawTextLine($"node visits = {result.nodeVisits}, leaf visits = {result.leafVisits}"); + } switch ((UpdateType)m_updateType) { case UpdateType.Update_Incremental: { - m_context.draw.DrawString(5, m_textLine, $"incremental : {_ms:F3} ms"); - m_textLine += m_textIncrement; + DrawTextLine($"incremental : {_ms:F3} ms"); + } break; case UpdateType.Update_FullRebuild: { - m_context.draw.DrawString(5, m_textLine, $"full build {_boxCount} : {_ms:F3} ms"); - m_textLine += m_textIncrement; + DrawTextLine($"full build {_boxCount} : {_ms:F3} ms"); + } break; case UpdateType.Update_PartialRebuild: { - m_context.draw.DrawString(5, m_textLine, $"partial rebuild {_boxCount} : {_ms:F3} ms"); - m_textLine += m_textIncrement; + DrawTextLine($"partial rebuild {_boxCount} : {_ms:F3} ms"); + } break; @@ -483,7 +483,7 @@ public override void Draw(Settings settings) float areaRatio = b2DynamicTree_GetAreaRatio(m_tree); int hmin = (int)(MathF.Ceiling(MathF.Log((float)m_proxyCount) / MathF.Log(2.0f) - 1.0f)); - m_context.draw.DrawString(5, m_textLine, $"proxies = {m_proxyCount}, height = {height}, hmin = {hmin}, area ratio = {areaRatio:F1}"); - m_textLine += m_textIncrement; + DrawTextLine($"proxies = {m_proxyCount}, height = {height}, hmin = {hmin}, area ratio = {areaRatio:F1}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Collisions/Manifold.cs b/src/Box2D.NET.Samples/Samples/Collisions/Manifold.cs index df04b0a8..d6d4092d 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/Manifold.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/Manifold.cs @@ -43,14 +43,14 @@ public class Manifold : Sample private bool m_enableCaching; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Manifold(ctx, settings); + return new Manifold(context); } - public Manifold(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Manifold(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { // m_context.g_camera.m_center = {1.8f, 15.0f}; m_context.camera.m_center = new B2Vec2(1.8f, 0.0f); @@ -217,7 +217,7 @@ void DrawManifold(ref B2Manifold manifold, B2Vec2 origin1, B2Vec2 origin2) } } - public override void Step(Settings settings) + public override void Step() { B2Vec2 offset = new B2Vec2(-10.0f, -5.0f); B2Vec2 increment = new B2Vec2(4.0f, 0.0f); diff --git a/src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs b/src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs index 56d99814..feef6ba7 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs @@ -57,9 +57,9 @@ public class OverlapWorld : Sample private bool m_rotating; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new OverlapWorld(ctx, settings); + return new OverlapWorld(context); } @@ -85,9 +85,9 @@ static bool OverlapResultFcn(B2ShapeId shapeId, object context) return true; } - public OverlapWorld(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public OverlapWorld(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 10.0f); m_context.camera.m_zoom = 25.0f * 0.7f; @@ -331,9 +331,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); m_doomCount = 0; @@ -390,10 +390,10 @@ public override void Draw(Settings settings) { base.Draw(settings); - m_context.draw.DrawString(5, m_textLine, "left mouse button: drag query shape"); - m_textLine += m_textIncrement; - m_context.draw.DrawString(5, m_textLine, "left mouse button + shift: rotate query shape"); - m_textLine += m_textIncrement; + DrawTextLine("left mouse button: drag query shape"); + + DrawTextLine("left mouse button + shift: rotate query shape"); + if (B2_IS_NON_NULL(m_bodyIds[m_ignoreIndex])) { diff --git a/src/Box2D.NET.Samples/Samples/Collisions/RayCast.cs b/src/Box2D.NET.Samples/Samples/Collisions/RayCast.cs index 67901372..4a5fc7dd 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/RayCast.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/RayCast.cs @@ -38,14 +38,14 @@ public class RayCast : Sample private bool m_showFraction; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new RayCast(ctx, settings); + return new RayCast(context); } - public RayCast(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public RayCast(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 20.0f); m_context.camera.m_zoom = 17.5f; @@ -216,7 +216,7 @@ void DrawRay(ref B2CastOutput output) } } - public override void Step(Settings _) + public override void Step() { B2Vec2 offset = new B2Vec2(-20.0f, 20.0f); B2Vec2 increment = new B2Vec2(10.0f, 0.0f); diff --git a/src/Box2D.NET.Samples/Samples/Collisions/ShapeCast.cs b/src/Box2D.NET.Samples/Samples/Collisions/ShapeCast.cs index 0f28f31e..8b25a3b5 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/ShapeCast.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/ShapeCast.cs @@ -57,15 +57,15 @@ public enum ShapeType private B2Transform inputTransform; private B2DistanceOutput _distanceOutput; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ShapeCast(ctx, settings); + return new ShapeCast(context); } - public ShapeCast(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public ShapeCast(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(-0.0f, 0.25f); m_context.camera.m_zoom = 3.0f; @@ -338,9 +338,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); B2ShapeCastPairInput input = new B2ShapeCastPairInput(); input.proxyA = m_proxyA; diff --git a/src/Box2D.NET.Samples/Samples/Collisions/ShapeDistance.cs b/src/Box2D.NET.Samples/Samples/Collisions/ShapeDistance.cs index 9f69474a..c3d4f7ae 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/ShapeDistance.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/ShapeDistance.cs @@ -62,9 +62,9 @@ public class ShapeDistance : Sample public int _outputIterations; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ShapeDistance(ctx, settings); + return new ShapeDistance(context); } enum ShapeType @@ -75,10 +75,9 @@ enum ShapeType e_box }; - public ShapeDistance(SampleAppContext ctx, Settings settings) - : base(ctx, settings) + public ShapeDistance(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 3.0f; @@ -359,7 +358,7 @@ void ComputeSimplexWitnessPoints(ref B2Vec2 a, ref B2Vec2 b, ref B2Simplex s) } } - public override void Step(Settings _) + public override void Step() { B2DistanceInput input = new B2DistanceInput(); input.proxyA = m_proxyA; @@ -441,26 +440,26 @@ public override void Draw(Settings settings) } } - m_context.draw.DrawString(5, m_textLine, "mouse button 1: drag"); - m_textLine += m_textIncrement; - m_context.draw.DrawString(5, m_textLine, "mouse button 1 + shift: rotate"); - m_textLine += m_textIncrement; - m_context.draw.DrawString(5, m_textLine, $"distance = {_outputDistance:F2}, iterations = {_outputIterations}"); - m_textLine += m_textIncrement; + DrawTextLine("mouse button 1: drag"); + + DrawTextLine("mouse button 1 + shift: rotate"); + + DrawTextLine($"distance = {_outputDistance:F2}, iterations = {_outputIterations}"); + if (m_cache.count == 1) { - m_context.draw.DrawString(5, m_textLine, $"cache = {m_cache.indexA[0]}, {m_cache.indexB[0]}"); + DrawTextLine($"cache = {m_cache.indexA[0]}, {m_cache.indexB[0]}"); } else if (m_cache.count == 2) { - m_context.draw.DrawString(5, m_textLine, $"cache = {m_cache.indexA[0]}, {m_cache.indexA[1]}, {m_cache.indexB[0]}, {m_cache.indexB[1]}"); + DrawTextLine($"cache = {m_cache.indexA[0]}, {m_cache.indexA[1]}, {m_cache.indexB[0]}, {m_cache.indexB[1]}"); } else if (m_cache.count == 3) { - m_context.draw.DrawString(5, m_textLine, $"cache = {m_cache.indexA[0]}, {m_cache.indexA[1]}, {m_cache.indexA[2]}, {m_cache.indexB[0]}, {m_cache.indexB[1]}, {m_cache.indexB[2]}"); + DrawTextLine($"cache = {m_cache.indexA[0]}, {m_cache.indexA[1]}, {m_cache.indexA[2]}, {m_cache.indexB[0]}, {m_cache.indexB[1]}, {m_cache.indexB[2]}"); } - m_textLine += m_textIncrement; + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Collisions/SmoothManifold.cs b/src/Box2D.NET.Samples/Samples/Collisions/SmoothManifold.cs index 07c60519..35eabad4 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/SmoothManifold.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/SmoothManifold.cs @@ -40,14 +40,14 @@ private enum ShapeType private bool m_showAnchors; private bool m_showSeparation; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SmoothManifold(ctx, settings); + return new SmoothManifold(context); } - public SmoothManifold(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SmoothManifold(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(2.0f, 20.0f); m_context.camera.m_zoom = 21.0f; @@ -256,7 +256,7 @@ void DrawManifold(ref B2Manifold manifold) } } - public override void Step(Settings _) + public override void Step() { B2HexColor color1 = B2HexColor.b2_colorYellow; B2HexColor color2 = B2HexColor.b2_colorMagenta; diff --git a/src/Box2D.NET.Samples/Samples/Collisions/TimeOfImpact.cs b/src/Box2D.NET.Samples/Samples/Collisions/TimeOfImpact.cs index 3a8f6358..e90b4e79 100644 --- a/src/Box2D.NET.Samples/Samples/Collisions/TimeOfImpact.cs +++ b/src/Box2D.NET.Samples/Samples/Collisions/TimeOfImpact.cs @@ -26,14 +26,14 @@ public class TimeOfImpact : Sample private B2TOIInput _input; private B2TOIOutput _output; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new TimeOfImpact(ctx, settings); + return new TimeOfImpact(context); } - public TimeOfImpact(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public TimeOfImpact(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.6f, 2.0f); m_context.camera.m_center = new B2Vec2(-16, 45); @@ -45,9 +45,9 @@ public TimeOfImpact(SampleAppContext ctx, Settings settings) : base(ctx, setting } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); _sweepA = new B2Sweep(b2Vec2_zero, new B2Vec2(0.0f, 0.0f), new B2Vec2(0.0f, 0.0f), b2Rot_identity, b2Rot_identity); _sweepB = new B2Sweep( @@ -72,12 +72,10 @@ public override void Draw(Settings settings) { base.Draw(settings); - m_context.draw.DrawString(5, m_textLine, $"toi = {_output.fraction:g}"); - m_textLine += m_textIncrement; + DrawTextLine($"toi = {_output.fraction:g}"); + - // m_context.g_draw.DrawString(5, m_textLine, "max toi iters = %d, max root iters = %d", b2_toiMaxIters, - // b2_toiMaxRootIters); - m_textLine += m_textIncrement; + // DrawTextLine("max toi iters = %d, max root iters = %d", b2_toiMaxIters, b2_toiMaxRootIters); B2Vec2[] vertices = new B2Vec2[B2_MAX_POLYGON_VERTICES]; @@ -129,8 +127,8 @@ public override void Draw(Settings settings) distanceInput.useRadii = false; B2SimplexCache cache = new B2SimplexCache(); B2DistanceOutput distanceOutput = b2ShapeDistance(ref distanceInput, ref cache, null, 0); - m_context.draw.DrawString(5, m_textLine, $"distance = {distanceOutput.distance}:g"); - m_textLine += m_textIncrement; + DrawTextLine($"distance = {distanceOutput.distance}:g"); + } #if FALSE diff --git a/src/Box2D.NET.Samples/Samples/Continuous/BounceHouse.cs b/src/Box2D.NET.Samples/Samples/Continuous/BounceHouse.cs index 63058128..f62e01d7 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/BounceHouse.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/BounceHouse.cs @@ -31,14 +31,14 @@ enum ShapeType private ShapeType m_shapeType; private bool m_enableHitEvents; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BounceHouse(ctx, settings); + return new BounceHouse(context); } - public BounceHouse(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BounceHouse(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 25.0f * 0.45f; @@ -149,9 +149,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); B2ContactEvents events = b2World_GetContactEvents(m_worldId); for (int i = 0; i < events.hitCount; ++i) diff --git a/src/Box2D.NET.Samples/Samples/Continuous/BounceHumans.cs b/src/Box2D.NET.Samples/Samples/Continuous/BounceHumans.cs index 2e6737ae..90a0a9b4 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/BounceHumans.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/BounceHumans.cs @@ -26,13 +26,13 @@ public class BounceHumans : Sample private B2CosSin _cs1; private B2CosSin _cs2; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BounceHumans(ctx, settings); + return new BounceHumans(context); } - public BounceHumans(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BounceHumans(SampleContext context) : base(context) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 12.0f; @@ -75,7 +75,7 @@ public BounceHumans(SampleAppContext ctx, Settings settings) : base(ctx, setting } - public override void Step(Settings settings) + public override void Step() { if (m_humanCount < 5 && m_countDown <= 0.0f) { @@ -100,7 +100,7 @@ public override void Step(Settings settings) m_countDown -= timeStep; b2World_SetGravity(m_worldId, gravityVec); - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) diff --git a/src/Box2D.NET.Samples/Samples/Continuous/ChainDrop.cs b/src/Box2D.NET.Samples/Samples/Continuous/ChainDrop.cs index 7340f13d..27731316 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/ChainDrop.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/ChainDrop.cs @@ -21,14 +21,14 @@ public class ChainDrop : Sample private float m_yOffset; private float m_speed; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ChainDrop(ctx, settings); + return new ChainDrop(context); } - public ChainDrop(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public ChainDrop(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 25.0f * 0.35f; diff --git a/src/Box2D.NET.Samples/Samples/Continuous/ChainSlide.cs b/src/Box2D.NET.Samples/Samples/Continuous/ChainSlide.cs index 3f69e949..620d75b2 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/ChainSlide.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/ChainSlide.cs @@ -12,14 +12,14 @@ public class ChainSlide : Sample { private static readonly int SampleChainSlide = SampleFactory.Shared.RegisterSample("Continuous", "Chain Slide", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ChainSlide(ctx, settings); + return new ChainSlide(context); } - public ChainSlide(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public ChainSlide(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 10.0f); m_context.camera.m_zoom = 15.0f; @@ -87,6 +87,6 @@ public override void Draw(Settings settings) { base.Draw(settings); - // m_context.draw.DrawString(5, m_textLine, $"toi hits = {b2_toiHitCount}"); + // DrawTextLine($"toi hits = {b2_toiHitCount}"); } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Continuous/Drop.cs b/src/Box2D.NET.Samples/Samples/Continuous/Drop.cs index 00f4086a..80a9f2e3 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/Drop.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/Drop.cs @@ -27,19 +27,19 @@ public class Drop : Sample private bool m_continuous; private bool m_speculative; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Drop(ctx, settings); + return new Drop(context); } - public Drop(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Drop(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 1.5f); m_context.camera.m_zoom = 3.0f; - settings.enableSleep = false; - settings.drawJoints = false; + m_context.settings.enableSleep = false; + m_context.settings.drawJoints = false; } #if FALSE @@ -305,7 +305,7 @@ public override void Keyboard(Keys key) } } - public override void Step(Settings settings) + public override void Step() { #if FALSE ImGui.SetNextWindowPos( new Vector2( 0.0f, 0.0f ) ); @@ -331,22 +331,22 @@ public override void Step(Settings settings) //if (m_frameCount == 165) //{ - // settings.pause = true; + // m_context.settings.pause = true; // m_frameSkip = 30; //} - settings.enableContinuous = m_continuous; + m_context.settings.enableContinuous = m_continuous; - if ((m_frameSkip == 0 || m_frameCount % m_frameSkip == 0) && settings.pause == false) + if ((m_frameSkip == 0 || m_frameCount % m_frameSkip == 0) && m_context.settings.pause == false) { - base.Step(settings); + base.Step(); } else { - bool pause = settings.pause; - settings.pause = true; - base.Step(settings); - settings.pause = pause; + bool pause = m_context.settings.pause; + m_context.settings.pause = true; + base.Step(); + m_context.settings.pause = pause; } m_frameCount += 1; diff --git a/src/Box2D.NET.Samples/Samples/Continuous/GhostBumps.cs b/src/Box2D.NET.Samples/Samples/Continuous/GhostBumps.cs index abe4d05e..1d41df52 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/GhostBumps.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/GhostBumps.cs @@ -37,14 +37,14 @@ private enum ShapeType private bool m_useChain; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new GhostBumps(ctx, settings); + return new GhostBumps(context); } - public GhostBumps(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public GhostBumps(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(1.5f, 16.0f); m_context.camera.m_zoom = 25.0f * 0.8f; diff --git a/src/Box2D.NET.Samples/Samples/Continuous/Pinball.cs b/src/Box2D.NET.Samples/Samples/Continuous/Pinball.cs index c90721da..cc8c4a65 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/Pinball.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/Pinball.cs @@ -23,20 +23,20 @@ public class Pinball : Sample private B2JointId m_rightJointId; private B2BodyId m_ballId; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Pinball(ctx, settings); + return new Pinball(context); } - public Pinball(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Pinball(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 9.0f); m_context.camera.m_zoom = 25.0f * 0.5f; } - settings.drawJoints = false; + m_context.settings.drawJoints = false; // Ground body B2BodyId groundId = new B2BodyId(); @@ -169,9 +169,9 @@ public Pinball(SampleAppContext ctx, Settings settings) : base(ctx, settings) } } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); if (GetKey(Keys.Space) == InputAction.Press) { diff --git a/src/Box2D.NET.Samples/Samples/Continuous/PixelImperfect.cs b/src/Box2D.NET.Samples/Samples/Continuous/PixelImperfect.cs index b6c6e0a3..c46c0311 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/PixelImperfect.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/PixelImperfect.cs @@ -17,14 +17,14 @@ public class PixelImperfect : Sample private B2BodyId m_ballId; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new PixelImperfect(ctx, settings); + return new PixelImperfect(context); } - public PixelImperfect(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public PixelImperfect(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(7.0f, 5.0f); m_context.camera.m_zoom = 6.0f; @@ -62,12 +62,12 @@ public PixelImperfect(SampleAppContext ctx, Settings settings) : base(ctx, setti } } - public override void Step(Settings settings) + public override void Step() { Span data = stackalloc B2ContactData[1]; b2Body_GetContactData(m_ballId, data, data.Length); - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) @@ -76,7 +76,7 @@ public override void Draw(Settings settings) B2Vec2 p = b2Body_GetPosition(m_ballId); B2Vec2 v = b2Body_GetLinearVelocity(m_ballId); - m_context.draw.DrawString(5, m_textLine, $"p.x = {p.X:F9}, v.y = {v.Y:F9}"); - m_textLine += m_textIncrement; + DrawTextLine($"p.x = {p.X:F9}, v.y = {v.Y:F9}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Continuous/RestitutionThreshold.cs b/src/Box2D.NET.Samples/Samples/Continuous/RestitutionThreshold.cs index e2ea4ec7..fc33af64 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/RestitutionThreshold.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/RestitutionThreshold.cs @@ -18,14 +18,14 @@ public class RestitutionThreshold : Sample private B2BodyId m_ballId; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new RestitutionThreshold(ctx, settings); + return new RestitutionThreshold(context); } - public RestitutionThreshold(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public RestitutionThreshold(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(7.0f, 5.0f); m_context.camera.m_zoom = 6.0f; @@ -67,12 +67,12 @@ public RestitutionThreshold(SampleAppContext ctx, Settings settings) : base(ctx, } } - public override void Step(Settings settings) + public override void Step() { Span data = stackalloc B2ContactData[1]; b2Body_GetContactData(m_ballId, data, data.Length); - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) @@ -81,7 +81,7 @@ public override void Draw(Settings settings) B2Vec2 p = b2Body_GetPosition(m_ballId); B2Vec2 v = b2Body_GetLinearVelocity(m_ballId); - m_context.draw.DrawString(5, m_textLine, $"p.x = {p.X:F9}, v.y = {v.Y:F9}"); - m_textLine += m_textIncrement; + DrawTextLine($"p.x = {p.X:F9}, v.y = {v.Y:F9}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Continuous/SegmentSlide.cs b/src/Box2D.NET.Samples/Samples/Continuous/SegmentSlide.cs index 5f01d041..5004b05d 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/SegmentSlide.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/SegmentSlide.cs @@ -13,14 +13,14 @@ public class SegmentSlide : Sample { private static readonly int SampleSegmentSlide = SampleFactory.Shared.RegisterSample("Continuous", "Segment Slide", Create); - public static Sample Create(SampleAppContext ctx, Settings settings) + public static Sample Create(SampleContext context) { - return new SegmentSlide(ctx, settings); + return new SegmentSlide(context); } - public SegmentSlide(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SegmentSlide(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 10.0f); m_context.camera.m_zoom = 15.0f; diff --git a/src/Box2D.NET.Samples/Samples/Continuous/SkinnyBox.cs b/src/Box2D.NET.Samples/Samples/Continuous/SkinnyBox.cs index 8701a0de..e3b5fb5a 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/SkinnyBox.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/SkinnyBox.cs @@ -26,14 +26,14 @@ public class SkinnyBox : Sample private bool m_bullet; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SkinnyBox(ctx, settings); + return new SkinnyBox(context); } - public SkinnyBox(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SkinnyBox(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(1.0f, 5.0f); m_context.camera.m_zoom = 25.0f * 0.25f; @@ -133,9 +133,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); if (m_autoTest && m_stepCount % 60 == 0) { diff --git a/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeFallback.cs b/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeFallback.cs index 0f8e5139..1c0a3487 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeFallback.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeFallback.cs @@ -17,14 +17,14 @@ public class SpeculativeFallback : Sample { private static readonly int SampleSpeculativeFallback = SampleFactory.Shared.RegisterSample("Continuous", "Speculative Fallback", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SpeculativeFallback(ctx, settings); + return new SpeculativeFallback(context); } - public SpeculativeFallback(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SpeculativeFallback(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(1.0f, 5.0f); m_context.camera.m_zoom = 25.0f * 0.25f; diff --git a/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeGhost.cs b/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeGhost.cs index f74fe66a..c737f60a 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeGhost.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeGhost.cs @@ -15,14 +15,14 @@ public class SpeculativeGhost : Sample { private static readonly int SampleSpeculativeGhost = SampleFactory.Shared.RegisterSample("Continuous", "Speculative Ghost", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SpeculativeGhost(ctx, settings); + return new SpeculativeGhost(context); } - public SpeculativeGhost(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SpeculativeGhost(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 1.75f); m_context.camera.m_zoom = 2.0f; @@ -46,7 +46,7 @@ public SpeculativeGhost(SampleAppContext ctx, Settings settings) : base(ctx, set // The speculative distance is 0.02 meters, so this avoid it bodyDef.position = new B2Vec2(0.015f, 2.515f); - bodyDef.linearVelocity = new B2Vec2(0.1f * 1.25f * settings.hertz, -0.1f * 1.25f * settings.hertz); + bodyDef.linearVelocity = new B2Vec2(0.1f * 1.25f * m_context.settings.hertz, -0.1f * 1.25f * m_context.settings.hertz); bodyDef.gravityScale = 0.0f; B2BodyId bodyId = b2CreateBody(m_worldId, ref bodyDef); diff --git a/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeSliver.cs b/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeSliver.cs index c055a223..041893dc 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeSliver.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/SpeculativeSliver.cs @@ -14,14 +14,14 @@ public class SpeculativeSliver : Sample { private static readonly int sampleSpeculativeSliver = SampleFactory.Shared.RegisterSample("Continuous", "Speculative Sliver", Create); - public static Sample Create(SampleAppContext ctx, Settings settings) + public static Sample Create(SampleContext context) { - return new SpeculativeSliver(ctx, settings); + return new SpeculativeSliver(context); } - public SpeculativeSliver(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SpeculativeSliver(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 1.75f); m_context.camera.m_zoom = 2.5f; diff --git a/src/Box2D.NET.Samples/Samples/Continuous/Wedge.cs b/src/Box2D.NET.Samples/Samples/Continuous/Wedge.cs index 880c8f91..82fc78a7 100644 --- a/src/Box2D.NET.Samples/Samples/Continuous/Wedge.cs +++ b/src/Box2D.NET.Samples/Samples/Continuous/Wedge.cs @@ -14,14 +14,14 @@ public class Wedge : Sample { private static readonly int SampleWedge = SampleFactory.Shared.RegisterSample("Continuous", "Wedge", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Wedge(ctx, settings); + return new Wedge(context); } - public Wedge(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Wedge(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 5.5f); m_context.camera.m_zoom = 6.0f; diff --git a/src/Box2D.NET.Samples/Samples/Determinisms/FallingHinges.cs b/src/Box2D.NET.Samples/Samples/Determinisms/FallingHinges.cs index f1a2e0de..f17d874d 100644 --- a/src/Box2D.NET.Samples/Samples/Determinisms/FallingHinges.cs +++ b/src/Box2D.NET.Samples/Samples/Determinisms/FallingHinges.cs @@ -30,15 +30,15 @@ public class FallingHinges : Sample private FallingHingeData m_data; private bool m_done; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new FallingHinges(ctx, settings); + return new FallingHinges(context); } - public FallingHinges(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public FallingHinges(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 7.5f); m_context.camera.m_zoom = 10.0f; @@ -48,9 +48,9 @@ public FallingHinges(SampleAppContext ctx, Settings settings) : base(ctx, settin } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); if (m_done == false) { @@ -64,8 +64,8 @@ public override void Draw(Settings settings) if (m_done) { - m_context.draw.DrawString(5, m_textLine, $"sleep step = {m_data.sleepStep}, hash = 0x{m_data.hash:X8}"); - m_textLine += m_textIncrement; + DrawTextLine($"sleep step = {m_data.sleepStep}, hash = 0x{m_data.hash:X8}"); + } } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Events/BodyMove.cs b/src/Box2D.NET.Samples/Samples/Events/BodyMove.cs index f900c85c..ab99a49a 100644 --- a/src/Box2D.NET.Samples/Samples/Events/BodyMove.cs +++ b/src/Box2D.NET.Samples/Samples/Events/BodyMove.cs @@ -33,14 +33,14 @@ public class BodyMove : Sample private float m_explosionMagnitude; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BodyMove(ctx, settings); + return new BodyMove(context); } - public BodyMove(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BodyMove(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(2.0f, 8.0f); m_context.camera.m_zoom = 25.0f * 0.55f; @@ -124,14 +124,14 @@ void CreateBodies() } - public override void Step(Settings settings) + public override void Step() { - if (settings.pause == false && (m_stepCount & 15) == 15 && m_count < e_count) + if (m_context.settings.pause == false && (m_stepCount & 15) == 15 && m_count < e_count) { CreateBodies(); } - base.Step(settings); + base.Step(); // Process body events B2BodyEvents events = b2World_GetBodyEvents(m_worldId); @@ -200,7 +200,7 @@ public override void Draw(Settings settings) m_context.draw.DrawCircle(m_explosionPosition, m_explosionRadius, B2HexColor.b2_colorAzure); - m_context.draw.DrawString(5, m_textLine, $"sleep count: {m_sleepCount}"); - m_textLine += m_textIncrement; + DrawTextLine($"sleep count: {m_sleepCount}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Events/ContactEvent.cs b/src/Box2D.NET.Samples/Samples/Events/ContactEvent.cs index 90761085..5d02261d 100644 --- a/src/Box2D.NET.Samples/Samples/Events/ContactEvent.cs +++ b/src/Box2D.NET.Samples/Samples/Events/ContactEvent.cs @@ -35,15 +35,15 @@ public class ContactEvent : Sample private float m_force; private float m_wait; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ContactEvent(ctx, settings); + return new ContactEvent(context); } - public ContactEvent(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public ContactEvent(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 25.0f * 1.75f; @@ -158,7 +158,7 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { B2Vec2 position = b2Body_GetPosition(m_playerId); @@ -182,7 +182,7 @@ public override void Step(Settings settings) b2Body_ApplyForce(m_playerId, new B2Vec2(0.0f, -m_force), position, true); } - base.Step(settings); + base.Step(); // Discover rings that touch the bottom sensor int[] debrisToAttach = new int[e_count]; @@ -418,9 +418,9 @@ public override void Step(Settings settings) b2Body_ApplyMassFromShapes(m_playerId); } - if (settings.hertz > 0.0f && settings.pause == false) + if (m_context.settings.hertz > 0.0f && m_context.settings.pause == false) { - m_wait -= 1.0f / settings.hertz; + m_wait -= 1.0f / m_context.settings.hertz; if (m_wait < 0.0f) { SpawnDebris(); @@ -433,7 +433,7 @@ public override void Draw(Settings settings) { base.Draw(settings); - m_context.draw.DrawString(5, m_textLine, "move using WASD"); - m_textLine += m_textIncrement; + DrawTextLine("move using WASD"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Events/FootSensor.cs b/src/Box2D.NET.Samples/Samples/Events/FootSensor.cs index ed1b2b9c..6ce963da 100644 --- a/src/Box2D.NET.Samples/Samples/Events/FootSensor.cs +++ b/src/Box2D.NET.Samples/Samples/Events/FootSensor.cs @@ -32,15 +32,15 @@ public class FootSensor : Sample private List m_overlaps = new List(); private int m_overlapCount; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new FootSensor(ctx, settings); + return new FootSensor(context); } - public FootSensor(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public FootSensor(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 6.0f); m_context.camera.m_zoom = 7.5f; @@ -93,7 +93,7 @@ public FootSensor(SampleAppContext ctx, Settings settings) : base(ctx, settings) m_overlapCount = 0; } - public override void Step(Settings settings) + public override void Step() { if (GetKey(Keys.A) == InputAction.Press) { @@ -105,7 +105,7 @@ public override void Step(Settings settings) b2Body_ApplyForceToCenter(m_playerId, new B2Vec2(50.0f, 0.0f), true); } - base.Step(settings); + base.Step(); B2SensorEvents sensorEvents = b2World_GetSensorEvents(m_worldId); for (int i = 0; i < sensorEvents.beginCount; ++i) @@ -150,7 +150,7 @@ public override void Draw(Settings settings) m_context.draw.DrawPoint(point, 10.0f, B2HexColor.b2_colorWhite); } - m_context.draw.DrawString(5, m_textLine, $"count == {m_overlapCount}"); - m_textLine += m_textIncrement; + DrawTextLine($"count == {m_overlapCount}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Events/Platformer.cs b/src/Box2D.NET.Samples/Samples/Events/Platformer.cs index 83d85545..82b97ed5 100644 --- a/src/Box2D.NET.Samples/Samples/Events/Platformer.cs +++ b/src/Box2D.NET.Samples/Samples/Events/Platformer.cs @@ -35,14 +35,14 @@ public class Platformer : Sample // private bool m_canJump; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Platformer(ctx, settings); + return new Platformer(context); } - public Platformer(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Platformer(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.5f, 7.5f); m_context.camera.m_zoom = 25.0f * 0.4f; @@ -184,7 +184,7 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { m_canJump = false; B2Vec2 velocity = b2Body_GetLinearVelocity(m_playerId); @@ -253,12 +253,12 @@ public override void Step(Settings settings) m_jumping = false; } - base.Step(settings); + base.Step(); - if (settings.hertz > 0.0f) + if (m_context.settings.hertz > 0.0f) { - m_jumpDelay = b2MaxFloat(0.0f, m_jumpDelay - 1.0f / settings.hertz); + m_jumpDelay = b2MaxFloat(0.0f, m_jumpDelay - 1.0f / m_context.settings.hertz); } } @@ -269,15 +269,15 @@ public override void Draw(Settings settings) { Span contactData = stackalloc B2ContactData[1]; int contactCount = b2Body_GetContactData(m_movingPlatformId, contactData, contactData.Length); - m_context.draw.DrawString(5, m_textLine, $"Platform contact count = {contactCount}, point count = {contactData[0].manifold.pointCount}"); + DrawTextLine($"Platform contact count = {contactCount}, point count = {contactData[0].manifold.pointCount}"); } - m_textLine += m_textIncrement; + - m_context.draw.DrawString(5, m_textLine, "Movement: A/D/Space"); - m_textLine += m_textIncrement; + DrawTextLine("Movement: A/D/Space"); + - m_context.draw.DrawString(5, m_textLine, $"Can jump = {m_canJump}"); - m_textLine += m_textIncrement; + DrawTextLine($"Can jump = {m_canJump}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Events/SensorBookend.cs b/src/Box2D.NET.Samples/Samples/Events/SensorBookend.cs index 67abfd3a..dba195cc 100644 --- a/src/Box2D.NET.Samples/Samples/Events/SensorBookend.cs +++ b/src/Box2D.NET.Samples/Samples/Events/SensorBookend.cs @@ -32,14 +32,14 @@ public class SensorBookend : Sample private int m_sensorsOverlapCount; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SensorBookend(ctx, settings); + return new SensorBookend(context); } - public SensorBookend(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SensorBookend(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 6.0f); m_context.camera.m_zoom = 7.5f; @@ -249,9 +249,9 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); B2SensorEvents sensorEvents = b2World_GetSensorEvents(m_worldId); for (int i = 0; i < sensorEvents.beginCount; ++i) diff --git a/src/Box2D.NET.Samples/Samples/Events/SensorFunnel.cs b/src/Box2D.NET.Samples/Samples/Events/SensorFunnel.cs index ddabc56a..a0e32cdb 100644 --- a/src/Box2D.NET.Samples/Samples/Events/SensorFunnel.cs +++ b/src/Box2D.NET.Samples/Samples/Events/SensorFunnel.cs @@ -36,21 +36,21 @@ private enum ea private float m_wait; private float m_side; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SensorFunnel(ctx, settings); + return new SensorFunnel(context); } - public SensorFunnel(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SensorFunnel(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 25.0f * 1.333f; } - settings.drawJoints = false; + m_context.settings.drawJoints = false; { B2BodyDef bodyDef = b2DefaultBodyDef(); @@ -281,14 +281,14 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { if (m_stepCount == 832) { m_stepCount += 0; } - base.Step(settings); + base.Step(); // Discover rings that touch the bottom sensor bool[] deferredDestruction = new bool[(int)ea.e_count]; @@ -336,9 +336,9 @@ public override void Step(Settings settings) } } - if (settings.hertz > 0.0f && settings.pause == false) + if (m_context.settings.hertz > 0.0f && m_context.settings.pause == false) { - m_wait -= 1.0f / settings.hertz; + m_wait -= 1.0f / m_context.settings.hertz; if (m_wait < 0.0f) { CreateElement(); diff --git a/src/Box2D.NET.Samples/Samples/Events/SensorTypes.cs b/src/Box2D.NET.Samples/Samples/Events/SensorTypes.cs index 1949ee86..b4bfd2f3 100644 --- a/src/Box2D.NET.Samples/Samples/Events/SensorTypes.cs +++ b/src/Box2D.NET.Samples/Samples/Events/SensorTypes.cs @@ -32,14 +32,14 @@ public class SensorTypes : Sample private List m_overlaps = new List(); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SensorTypes(ctx, settings); + return new SensorTypes(context); } - public SensorTypes(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SensorTypes(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 3.0f); m_context.camera.m_zoom = 4.5f; @@ -172,7 +172,7 @@ void PrintOverlaps(B2ShapeId sensorShapeId, string prefix) DrawTextLine(builder.ToString()); } - public override void Step(Settings settings) + public override void Step() { B2Vec2 position = b2Body_GetPosition(m_kinematicBodyId); if (position.Y < 0.0f) @@ -185,7 +185,7 @@ public override void Step(Settings settings) b2Body_SetLinearVelocity(m_kinematicBodyId, new B2Vec2(0.0f, -1.0f)); } - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) diff --git a/src/Box2D.NET.Samples/Samples/Geometries/ConvexHull.cs b/src/Box2D.NET.Samples/Samples/Geometries/ConvexHull.cs index e23638cb..b34a6cf6 100644 --- a/src/Box2D.NET.Samples/Samples/Geometries/ConvexHull.cs +++ b/src/Box2D.NET.Samples/Samples/Geometries/ConvexHull.cs @@ -27,15 +27,15 @@ public class ConvexHull : Sample private float m_milliseconds = 0.0f; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ConvexHull(ctx, settings); + return new ConvexHull(context); } - public ConvexHull(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public ConvexHull(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.5f, 0.0f); m_context.camera.m_zoom = 25.0f * 0.3f; @@ -125,9 +125,9 @@ public override void Keyboard(Keys key) } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); m_hull = new B2Hull(); m_valid = false; @@ -190,27 +190,27 @@ public override void Draw(Settings settings) { base.Draw(settings); - m_context.draw.DrawString(5, m_textLine, "Options: generate(g), auto(a), bulk(b)"); - m_textLine += m_textIncrement; + DrawTextLine("Options: generate(g), auto(a), bulk(b)"); + if (m_valid == false) { - m_context.draw.DrawString(5, m_textLine, $"generation = {m_generation}, FAILED"); - m_textLine += m_textIncrement; + DrawTextLine($"generation = {m_generation}, FAILED"); + } else { - m_context.draw.DrawString(5, m_textLine, $"generation = {m_generation}, count = {m_hull.count}"); - m_textLine += m_textIncrement; + DrawTextLine($"generation = {m_generation}, count = {m_hull.count}"); + } if (m_milliseconds > 0.0f) { - m_context.draw.DrawString(5, m_textLine, $"milliseconds = {m_milliseconds:G}"); - m_textLine += m_textIncrement; + DrawTextLine($"milliseconds = {m_milliseconds:G}"); + } - m_textLine += m_textIncrement; + if (0 < m_hull.count) { diff --git a/src/Box2D.NET.Samples/Samples/Joints/BallAndChain.cs b/src/Box2D.NET.Samples/Samples/Joints/BallAndChain.cs index b0c2c11a..b509ab65 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/BallAndChain.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/BallAndChain.cs @@ -24,14 +24,14 @@ public class BallAndChain : Sample private float m_frictionTorque; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BallAndChain(ctx, settings); + return new BallAndChain(context); } - public BallAndChain(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BallAndChain(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, -8.0f); m_context.camera.m_zoom = 27.5f; diff --git a/src/Box2D.NET.Samples/Samples/Joints/BreakableJoint.cs b/src/Box2D.NET.Samples/Samples/Joints/BreakableJoint.cs index 3ac1fac5..032c4cd9 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/BreakableJoint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/BreakableJoint.cs @@ -26,14 +26,14 @@ public class BreakableJoint : Sample private B2JointId[] m_jointIds = new B2JointId[e_count]; private float m_breakForce; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new BreakableJoint(ctx, settings); + return new BreakableJoint(context); } - public BreakableJoint(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public BreakableJoint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 8.0f); m_context.camera.m_zoom = 25.0f * 0.7f; @@ -227,7 +227,7 @@ public override void UpdateGui() } - public override void Step(Settings settings) + public override void Step() { for (int i = 0; i < e_count; ++i) { @@ -244,7 +244,7 @@ public override void Step(Settings settings) } } - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) diff --git a/src/Box2D.NET.Samples/Samples/Joints/Bridge.cs b/src/Box2D.NET.Samples/Samples/Joints/Bridge.cs index f97e34be..9db12c8e 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/Bridge.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/Bridge.cs @@ -28,15 +28,15 @@ public class Bridge : Sample private float m_frictionTorque; private float m_gravityScale; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Bridge(ctx, settings); + return new Bridge(context); } - public Bridge(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Bridge(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_zoom = 25.0f * 2.5f; } diff --git a/src/Box2D.NET.Samples/Samples/Joints/Cantilever.cs b/src/Box2D.NET.Samples/Samples/Joints/Cantilever.cs index a5815892..f5bf83fc 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/Cantilever.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/Cantilever.cs @@ -32,15 +32,15 @@ public class Cantilever : Sample private bool m_collideConnected; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Cantilever(ctx, settings); + return new Cantilever(context); } - public Cantilever(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Cantilever(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.0f); m_context.camera.m_zoom = 25.0f * 0.35f; @@ -166,7 +166,7 @@ public override void Draw(Settings settings) base.Draw(settings); B2Vec2 tipPosition = b2Body_GetPosition(m_tipId); - m_context.draw.DrawString(5, m_textLine, $"tip-y = {tipPosition.Y:F2}"); - m_textLine += m_textIncrement; + DrawTextLine($"tip-y = {tipPosition.Y:F2}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Joints/DistanceJoint.cs b/src/Box2D.NET.Samples/Samples/Joints/DistanceJoint.cs index 98a74666..530e0b58 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/DistanceJoint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/DistanceJoint.cs @@ -32,14 +32,14 @@ public class DistanceJoint : Sample private bool m_enableSpring; private bool m_enableLimit; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new DistanceJoint(ctx, settings); + return new DistanceJoint(context); } - public DistanceJoint(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public DistanceJoint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 12.0f); m_context.camera.m_zoom = 25.0f * 0.35f; diff --git a/src/Box2D.NET.Samples/Samples/Joints/DoohickeyFarm.cs b/src/Box2D.NET.Samples/Samples/Joints/DoohickeyFarm.cs index 53c094b8..fa65bc98 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/DoohickeyFarm.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/DoohickeyFarm.cs @@ -14,14 +14,14 @@ public class DoohickeyFarm : Sample { private static readonly int SampleDoohickey = SampleFactory.Shared.RegisterSample("Joints", "Doohickey", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new DoohickeyFarm(ctx, settings); + return new DoohickeyFarm(context); } - public DoohickeyFarm(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public DoohickeyFarm(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); m_context.camera.m_zoom = 25.0f * 0.35f; diff --git a/src/Box2D.NET.Samples/Samples/Joints/Driving.cs b/src/Box2D.NET.Samples/Samples/Joints/Driving.cs index 6338c42c..76f2e78d 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/Driving.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/Driving.cs @@ -29,18 +29,18 @@ public class Driving : Sample private float m_speed; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Driving(ctx, settings); + return new Driving(context); } - public Driving(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Driving(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center.Y = 5.0f; m_context.camera.m_zoom = 25.0f * 0.4f; - settings.drawJoints = false; + m_context.settings.drawJoints = false; } B2BodyId groundId; @@ -214,7 +214,7 @@ public Driving(SampleAppContext ctx, Settings settings) : base(ctx, settings) public override void UpdateGui() { base.UpdateGui(); - + float height = 140.0f; ImGui.SetNextWindowPos(new Vector2(10.0f, m_context.camera.m_height - height - 50.0f), ImGuiCond.Once); ImGui.SetNextWindowSize(new Vector2(200.0f, height)); @@ -247,7 +247,7 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { if (GetKey(Keys.A) == InputAction.Press) { @@ -267,20 +267,20 @@ public override void Step(Settings settings) m_car.SetSpeed(-m_speed); } - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) { base.Draw(settings); + + DrawTextLine("Keys: left = a, brake = s, right = d"); - m_context.draw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d"); - m_textLine += m_textIncrement; B2Vec2 linearVelocity = b2Body_GetLinearVelocity(m_car.m_chassisId); float kph = linearVelocity.X * 3.6f; - m_context.draw.DrawString(5, m_textLine, $"speed in kph: {kph:G2}"); - m_textLine += m_textIncrement; + DrawTextLine($"speed in kph: {kph:G2}"); + B2Vec2 carPosition = b2Body_GetPosition(m_car.m_chassisId); m_context.camera.m_center.X = carPosition.X; diff --git a/src/Box2D.NET.Samples/Samples/Joints/FilterJoint.cs b/src/Box2D.NET.Samples/Samples/Joints/FilterJoint.cs index a51d1b45..f1944a95 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/FilterJoint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/FilterJoint.cs @@ -16,14 +16,14 @@ public class FilterJoint : Sample { private static readonly int SampleFilterJoint = SampleFactory.Shared.RegisterSample("Joints", "Filter Joint", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new FilterJoint(ctx, settings); + return new FilterJoint(context); } - public FilterJoint(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public FilterJoint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 7.0f); m_context.camera.m_zoom = 25.0f * 0.4f; diff --git a/src/Box2D.NET.Samples/Samples/Joints/FixedRotation.cs b/src/Box2D.NET.Samples/Samples/Joints/FixedRotation.cs index df32eb51..1c1b124a 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/FixedRotation.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/FixedRotation.cs @@ -26,14 +26,14 @@ public class FixedRotation : Sample private B2JointId[] m_jointIds = new B2JointId[e_count]; private bool m_fixedRotation; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new FixedRotation(ctx, settings); + return new FixedRotation(context); } - public FixedRotation(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public FixedRotation(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 8.0f); m_context.camera.m_zoom = 25.0f * 0.7f; diff --git a/src/Box2D.NET.Samples/Samples/Joints/GearLift.cs b/src/Box2D.NET.Samples/Samples/Joints/GearLift.cs index 896803ec..17d9a5a9 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/GearLift.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/GearLift.cs @@ -27,14 +27,14 @@ public class GearLift : Sample private float m_motorSpeed; private bool m_enableMotor; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new GearLift(ctx, settings); + return new GearLift(context); } - public GearLift(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public GearLift(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 6.0f); m_context.camera.m_zoom = 7.0f; @@ -319,7 +319,7 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { if (InputAction.Release == GetKey(Keys.A)) { @@ -335,6 +335,6 @@ public override void Step(Settings settings) b2Joint_WakeBodies(m_driverId); } - base.Step(settings); + base.Step(); } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Joints/MotorJoint.cs b/src/Box2D.NET.Samples/Samples/Joints/MotorJoint.cs index 0e7257dc..f9c2a84c 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/MotorJoint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/MotorJoint.cs @@ -34,15 +34,14 @@ public class MotorJoint : Sample private B2Transform _transform; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new MotorJoint(ctx, settings); + return new MotorJoint(context); } - public MotorJoint(SampleAppContext ctx, Settings settings) - : base(ctx, settings) + public MotorJoint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 7.0f); m_context.camera.m_zoom = 25.0f * 0.4f; @@ -126,11 +125,11 @@ public override void UpdateGui() } - public override void Step(Settings settings) + public override void Step() { - if (m_go && settings.hertz > 0.0f) + if (m_go && m_context.settings.hertz > 0.0f) { - m_time += 1.0f / settings.hertz; + m_time += 1.0f / m_context.settings.hertz; } B2Vec2 linearOffset; @@ -144,7 +143,7 @@ public override void Step(Settings settings) _transform = new B2Transform(linearOffset, b2MakeRot(angularOffset)); - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) @@ -154,8 +153,7 @@ public override void Draw(Settings settings) B2Vec2 force = b2Joint_GetConstraintForce(m_jointId); float torque = b2Joint_GetConstraintTorque(m_jointId); - m_context.draw.DrawString(5, m_textLine, $"force = {force.X:3,F0}, {force.Y:3,F0}, torque = {torque:3,F0}"); - m_textLine += 15; + DrawTextLine($"force = {force.X:3,F0}, {force.Y:3,F0}, torque = {torque:3,F0}"); m_context.draw.DrawTransform(_transform); } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Joints/PrismaticJoint.cs b/src/Box2D.NET.Samples/Samples/Joints/PrismaticJoint.cs index 5b90b744..59bfb88d 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/PrismaticJoint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/PrismaticJoint.cs @@ -27,14 +27,14 @@ public class PrismaticJoint : Sample private bool m_enableMotor; private bool m_enableLimit; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new PrismaticJoint(ctx, settings); + return new PrismaticJoint(context); } - public PrismaticJoint(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public PrismaticJoint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 8.0f); m_context.camera.m_zoom = 25.0f * 0.5f; @@ -153,15 +153,15 @@ public override void Draw(Settings settings) base.Draw(settings); float force = b2PrismaticJoint_GetMotorForce(m_jointId); - m_context.draw.DrawString(5, m_textLine, $"Motor Force = {force:4,F1}"); - m_textLine += m_textIncrement; + DrawTextLine($"Motor Force = {force:4,F1}"); + float translation = b2PrismaticJoint_GetTranslation(m_jointId); - m_context.draw.DrawString(5, m_textLine, $"Translation = {translation:4,F1}"); - m_textLine += m_textIncrement; + DrawTextLine($"Translation = {translation:4,F1}"); + float speed = b2PrismaticJoint_GetSpeed(m_jointId); - m_context.draw.DrawString(5, m_textLine, $"Speed = {speed:4,F8}"); - m_textLine += m_textIncrement; + DrawTextLine($"Speed = {speed:4,F8}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Joints/Ragdoll.cs b/src/Box2D.NET.Samples/Samples/Joints/Ragdoll.cs index dd0f6b21..dc36f35d 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/Ragdoll.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/Ragdoll.cs @@ -21,14 +21,14 @@ public class Ragdoll : Sample private float m_jointHertz; private float m_jointDampingRatio; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Ragdoll(ctx, settings); + return new Ragdoll(context); } - public Ragdoll(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Ragdoll(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 12.0f); m_context.camera.m_zoom = 16.0f; diff --git a/src/Box2D.NET.Samples/Samples/Joints/RevoluteJoint.cs b/src/Box2D.NET.Samples/Samples/Joints/RevoluteJoint.cs index 6b40b2e9..87f4cefe 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/RevoluteJoint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/RevoluteJoint.cs @@ -30,14 +30,14 @@ public class RevoluteJoint : Sample private bool m_enableMotor; private bool m_enableLimit; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new RevoluteJoint(ctx, settings); + return new RevoluteJoint(context); } - public RevoluteJoint(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public RevoluteJoint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 15.5f); m_context.camera.m_zoom = 25.0f * 0.7f; @@ -128,7 +128,7 @@ public RevoluteJoint(SampleAppContext ctx, Settings settings) : base(ctx, settin jointDef.localAnchorA = b2Body_GetLocalPoint(jointDef.bodyIdA, pivot); jointDef.localAnchorB = b2Body_GetLocalPoint(jointDef.bodyIdB, pivot); jointDef.lowerAngle = -0.25f * B2_PI; - jointDef.upperAngle = 0.5f * B2_PI; + jointDef.upperAngle = 0.1f * B2_PI; jointDef.enableLimit = true; jointDef.enableMotor = true; jointDef.motorSpeed = 0.0f; @@ -204,15 +204,15 @@ public override void Draw(Settings settings) base.Draw(settings); float angle1 = b2RevoluteJoint_GetAngle(m_jointId1); - m_context.draw.DrawString(5, m_textLine, $"Angle (Deg) 1 = {angle1:F1}"); - m_textLine += m_textIncrement; + DrawTextLine($"Angle (Deg) 1 = {angle1:F1}"); + float torque1 = b2RevoluteJoint_GetMotorTorque(m_jointId1); - m_context.draw.DrawString(5, m_textLine, $"Motor Torque 1 = {torque1:F1}"); - m_textLine += m_textIncrement; + DrawTextLine($"Motor Torque 1 = {torque1:F1}"); + float torque2 = b2RevoluteJoint_GetMotorTorque(m_jointId2); - m_context.draw.DrawString(5, m_textLine, $"Motor Torque 2 = {torque2:F1}"); - m_textLine += m_textIncrement; + DrawTextLine($"Motor Torque 2 = {torque2:F1}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Joints/ScissorLift.cs b/src/Box2D.NET.Samples/Samples/Joints/ScissorLift.cs index dee35da9..38adcee4 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/ScissorLift.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/ScissorLift.cs @@ -23,21 +23,21 @@ public class ScissorLift : Sample private float m_motorSpeed; private bool m_enableMotor; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ScissorLift(ctx, settings); + return new ScissorLift(context); } - public ScissorLift(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public ScissorLift(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 9.0f); m_context.camera.m_zoom = 25.0f * 0.4f; } // Need 8 sub-steps for smoother operation - settings.subStepCount = 8; + m_context.settings.subStepCount = 8; B2BodyId groundId; { diff --git a/src/Box2D.NET.Samples/Samples/Joints/SoftBody.cs b/src/Box2D.NET.Samples/Samples/Joints/SoftBody.cs index ffc66914..d387360b 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/SoftBody.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/SoftBody.cs @@ -14,14 +14,14 @@ public class SoftBody : Sample private Donut m_donut; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SoftBody(ctx, settings); + return new SoftBody(context); } - public SoftBody(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SoftBody(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); m_context.camera.m_zoom = 25.0f * 0.25f; diff --git a/src/Box2D.NET.Samples/Samples/Joints/UserConstraint.cs b/src/Box2D.NET.Samples/Samples/Joints/UserConstraint.cs index e619e2f1..bc284fcb 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/UserConstraint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/UserConstraint.cs @@ -18,14 +18,14 @@ public class UserConstraint : Sample private B2BodyId m_bodyId; private float[] m_impulses = new float[2]; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new UserConstraint(ctx, settings); + return new UserConstraint(context); } - public UserConstraint(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public UserConstraint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(3.0f, -1.0f); m_context.camera.m_zoom = 25.0f * 0.15f; @@ -48,19 +48,19 @@ public UserConstraint(SampleAppContext ctx, Settings settings) : base(ctx, setti m_impulses[1] = 0.0f; } - public override void Step(Settings settings) + public override void Step() { - base.Step(settings); + base.Step(); B2Transform axes = b2Transform_identity; m_context.draw.DrawTransform(axes); - if (settings.pause) + if (m_context.settings.pause) { return; } - float timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f; + float timeStep = m_context.settings.hertz > 0.0f ? 1.0f / m_context.settings.hertz : 0.0f; if (timeStep == 0.0f) { return; @@ -134,7 +134,7 @@ public override void Draw(Settings settings) base.Draw(settings); float invTimeStep = settings.hertz; - m_context.draw.DrawString(5, m_textLine, $"forces = {m_impulses[0] * invTimeStep:g}, {m_impulses[1] * invTimeStep:g}"); - m_textLine += m_textIncrement; + DrawTextLine($"forces = {m_impulses[0] * invTimeStep:g}, {m_impulses[1] * invTimeStep:g}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Joints/WheelJoint.cs b/src/Box2D.NET.Samples/Samples/Joints/WheelJoint.cs index 40c46a97..1ba9c3e9 100644 --- a/src/Box2D.NET.Samples/Samples/Joints/WheelJoint.cs +++ b/src/Box2D.NET.Samples/Samples/Joints/WheelJoint.cs @@ -26,14 +26,14 @@ public class WheelJoint : Sample private bool m_enableMotor; private bool m_enableLimit; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new WheelJoint(ctx, settings); + return new WheelJoint(context); } - public WheelJoint(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public WheelJoint(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 10.0f); m_context.camera.m_zoom = 25.0f * 0.15f; @@ -144,7 +144,7 @@ public override void Draw(Settings settings) base.Draw(settings); float torque = b2WheelJoint_GetMotorTorque(m_jointId); - m_context.draw.DrawString(5, m_textLine, $"Motor Torque = {torque,4:F1}"); - m_textLine += m_textIncrement; + DrawTextLine($"Motor Torque = {torque,4:F1}"); + } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio1.cs b/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio1.cs index 35930409..aeb5ad35 100644 --- a/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio1.cs +++ b/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio1.cs @@ -15,15 +15,15 @@ public class HighMassRatio1 : Sample { private static readonly int SampleIndex1 = SampleFactory.Shared.RegisterSample("Robustness", "HighMassRatio1", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new HighMassRatio1(ctx, settings); + return new HighMassRatio1(context); } - public HighMassRatio1(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public HighMassRatio1(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(3.0f, 14.0f); m_context.camera.m_zoom = 25.0f; diff --git a/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio2.cs b/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio2.cs index 423b2221..0a024ad1 100644 --- a/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio2.cs +++ b/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio2.cs @@ -15,14 +15,14 @@ public class HighMassRatio2 : Sample { private static readonly int SampleIndex2 = SampleFactory.Shared.RegisterSample("Robustness", "HighMassRatio2", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new HighMassRatio2(ctx, settings); + return new HighMassRatio2(context); } - public HighMassRatio2(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public HighMassRatio2(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 16.5f); m_context.camera.m_zoom = 25.0f; diff --git a/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio3.cs b/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio3.cs index 4d46b162..3e997f03 100644 --- a/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio3.cs +++ b/src/Box2D.NET.Samples/Samples/Robustness/HighMassRatio3.cs @@ -16,14 +16,14 @@ public class HighMassRatio3 : Sample { private static readonly int SampleIndex3 = SampleFactory.Shared.RegisterSample("Robustness", "HighMassRatio3", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new HighMassRatio3(ctx, settings); + return new HighMassRatio3(context); } - public HighMassRatio3(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public HighMassRatio3(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 16.5f); m_context.camera.m_zoom = 25.0f; diff --git a/src/Box2D.NET.Samples/Samples/Robustness/OverlapRecovery.cs b/src/Box2D.NET.Samples/Samples/Robustness/OverlapRecovery.cs index 737805f7..3c7c929f 100644 --- a/src/Box2D.NET.Samples/Samples/Robustness/OverlapRecovery.cs +++ b/src/Box2D.NET.Samples/Samples/Robustness/OverlapRecovery.cs @@ -26,14 +26,14 @@ public class OverlapRecovery : Sample private float m_hertz; private float m_dampingRatio; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new OverlapRecovery(ctx, settings); + return new OverlapRecovery(context); } - public OverlapRecovery(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public OverlapRecovery(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 2.5f); m_context.camera.m_zoom = 25.0f * 0.15f; diff --git a/src/Box2D.NET.Samples/Samples/Robustness/TinyPyramid.cs b/src/Box2D.NET.Samples/Samples/Robustness/TinyPyramid.cs index e14c501f..8a4c3055 100644 --- a/src/Box2D.NET.Samples/Samples/Robustness/TinyPyramid.cs +++ b/src/Box2D.NET.Samples/Samples/Robustness/TinyPyramid.cs @@ -16,14 +16,14 @@ public class TinyPyramid : Sample private float m_extent; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new TinyPyramid(ctx, settings); + return new TinyPyramid(context); } - public TinyPyramid(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public TinyPyramid(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 0.8f); m_context.camera.m_zoom = 1.0f; diff --git a/src/Box2D.NET.Samples/Samples/Sample.cs b/src/Box2D.NET.Samples/Samples/Sample.cs index 3c8e72a4..e2d7891e 100644 --- a/src/Box2D.NET.Samples/Samples/Sample.cs +++ b/src/Box2D.NET.Samples/Samples/Sample.cs @@ -34,8 +34,7 @@ public class Sample : IDisposable public const bool m_isDebug = false; #endif - protected SampleAppContext m_context; - protected Settings m_settings; + protected SampleContext m_context; protected TaskScheduler m_scheduler; protected SampleTask[] m_tasks; protected int m_taskCount; @@ -43,21 +42,20 @@ public class Sample : IDisposable protected B2BodyId m_groundBodyId; - // DestructionListener m_destructionListener; - protected int m_textLine; public B2WorldId m_worldId; - protected B2JointId m_mouseJointId; public int m_stepCount; - protected int m_textIncrement; + protected B2JointId m_mouseJointId; protected B2Profile m_maxProfile; protected B2Profile m_totalProfile; + + private int m_textLine; + private int m_textIncrement; - - public Sample(SampleAppContext ctx, Settings settings) + public Sample(SampleContext context) { - m_context = ctx; + m_context = context; m_scheduler = new TaskScheduler(); - m_scheduler.Initialize(settings.workerCount); + m_scheduler.Initialize(m_context.settings.workerCount); m_tasks = new SampleTask[m_maxTasks]; for (int i = 0; i < m_maxTasks; ++i) @@ -67,7 +65,7 @@ public Sample(SampleAppContext ctx, Settings settings) m_taskCount = 0; - m_threadCount = 1 + settings.workerCount; + m_threadCount = 1 + m_context.settings.workerCount; m_worldId = b2_nullWorldId; @@ -82,9 +80,7 @@ public Sample(SampleAppContext ctx, Settings settings) m_maxProfile = new B2Profile(); m_totalProfile = new B2Profile(); - g_seed = RAND_SEED; - - m_settings = settings; + g_randomSeed = RAND_SEED; CreateWorld(); TestMathCpp(); @@ -108,11 +104,11 @@ public void CreateWorld() } B2WorldDef worldDef = b2DefaultWorldDef(); - worldDef.workerCount = m_settings.workerCount; + worldDef.workerCount = m_context.settings.workerCount; worldDef.enqueueTask = EnqueueTask; worldDef.finishTask = FinishTask; worldDef.userTaskContext = this; - worldDef.enableSleep = m_settings.enableSleep; + worldDef.enableSleep = m_context.settings.enableSleep; m_worldId = b2CreateWorld(ref worldDef); } @@ -147,7 +143,7 @@ public void TestMathCpp() public virtual void UpdateGui() { - if (m_settings.drawProfile) + if (m_context.settings.drawProfile) { B2Profile p = b2World_GetProfile(m_worldId); @@ -353,7 +349,7 @@ public void DrawTextLine(string text) ImGui.TextColored(new Vector4(230, 153, 153, 255), text); ImGui.PopFont(); ImGui.End(); - + m_textLine += m_textIncrement; } @@ -364,15 +360,15 @@ public void ResetProfile() m_stepCount = 0; } - public virtual void Step(Settings settings) + public virtual void Step() { - float timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f; + float timeStep = m_context.settings.hertz > 0.0f ? 1.0f / m_context.settings.hertz : 0.0f; - if (settings.pause) + if (m_context.settings.pause) { - if (settings.singleStep) + if (m_context.settings.singleStep) { - settings.singleStep = false; + m_context.settings.singleStep = false; } else { @@ -380,13 +376,13 @@ public virtual void Step(Settings settings) } } - b2World_EnableSleeping(m_worldId, settings.enableSleep); - b2World_EnableWarmStarting(m_worldId, settings.enableWarmStarting); - b2World_EnableContinuous(m_worldId, settings.enableContinuous); + b2World_EnableSleeping(m_worldId, m_context.settings.enableSleep); + b2World_EnableWarmStarting(m_worldId, m_context.settings.enableWarmStarting); + b2World_EnableContinuous(m_worldId, m_context.settings.enableContinuous); for (int i = 0; i < 1; ++i) { - b2World_Step(m_worldId, timeStep, settings.subStepCount); + b2World_Step(m_worldId, timeStep, m_context.settings.subStepCount); m_taskCount = 0; } @@ -452,8 +448,8 @@ public virtual void Draw(Settings settings) { if (m_context.draw.m_showUI) { - m_context.draw.DrawString(5, m_textLine, "****PAUSED****"); - m_textLine += m_textIncrement; + DrawTextLine("****PAUSED****"); + } } diff --git a/src/Box2D.NET.Samples/Samples/SampleFactory.cs b/src/Box2D.NET.Samples/Samples/SampleFactory.cs index 14d79b79..16efaef8 100644 --- a/src/Box2D.NET.Samples/Samples/SampleFactory.cs +++ b/src/Box2D.NET.Samples/Samples/SampleFactory.cs @@ -26,7 +26,7 @@ private SampleFactory() _sampleEntries = new List(); } - public int RegisterSample(string category, string name, Func fcn) + public int RegisterSample(string category, string name, Func fcn) { int index = _sampleEntries.Count; var entry = new SampleEntry(category, name, fcn); @@ -34,10 +34,10 @@ public int RegisterSample(string category, string name, Func 0.0f ? 60.0f * B2_PI / 180.0f / settings.hertz : 0.0f; + m_referenceAngle += m_context.settings.hertz > 0.0f ? 60.0f * B2_PI / 180.0f / m_context.settings.hertz : 0.0f; m_referenceAngle = b2UnwindAngle(m_referenceAngle); int count = m_jointIds.Count; @@ -121,15 +120,15 @@ public override void Step(Settings settings) } } - base.Step(settings); + base.Step(); } public override void Draw(Settings settings) { base.Draw(settings); - m_context.draw.DrawString(5, m_textLine, $"reference angle = {m_referenceAngle:g}"); - m_textLine += m_textIncrement; + DrawTextLine($"reference angle = {m_referenceAngle:g}"); + m_context.draw.DrawCircle(b2Vec2_zero, m_radius + m_falloff, B2HexColor.b2_colorBox2DBlue); m_context.draw.DrawCircle(b2Vec2_zero, m_radius, B2HexColor.b2_colorBox2DYellow); diff --git a/src/Box2D.NET.Samples/Samples/Shapes/Friction.cs b/src/Box2D.NET.Samples/Samples/Shapes/Friction.cs index a4e08386..2be3ae59 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/Friction.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/Friction.cs @@ -14,14 +14,14 @@ public class Friction : Sample { private static readonly int SampleFriction = SampleFactory.Shared.RegisterSample("Shapes", "Friction", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Friction(ctx, settings); + return new Friction(context); } - public Friction(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Friction(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 14.0f); m_context.camera.m_zoom = 25.0f * 0.6f; diff --git a/src/Box2D.NET.Samples/Samples/Shapes/ModifyGeometry.cs b/src/Box2D.NET.Samples/Samples/Shapes/ModifyGeometry.cs index 89eed065..9d5dca11 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/ModifyGeometry.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/ModifyGeometry.cs @@ -26,19 +26,18 @@ public class ModifyGeometry : Sample private B2ShapeUnion m_us; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ModifyGeometry(ctx, settings); + return new ModifyGeometry(context); } private void SetCircle(B2Circle circle) { } - public ModifyGeometry(SampleAppContext ctx, Settings settings) - : base(ctx, settings) + public ModifyGeometry(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_zoom = 25.0f * 0.25f; m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); diff --git a/src/Box2D.NET.Samples/Samples/Shapes/OffsetShapes.cs b/src/Box2D.NET.Samples/Samples/Shapes/OffsetShapes.cs index 6c1b5f39..7f5f033a 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/OffsetShapes.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/OffsetShapes.cs @@ -14,14 +14,14 @@ public class OffsetShapes : Sample { private static readonly int SampleOffsetShapes = SampleFactory.Shared.RegisterSample("Shapes", "Offset", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new OffsetShapes(ctx, settings); + return new OffsetShapes(context); } - public OffsetShapes(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public OffsetShapes(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_zoom = 25.0f * 0.55f; m_context.camera.m_center = new B2Vec2(2.0f, 8.0f); diff --git a/src/Box2D.NET.Samples/Samples/Shapes/RecreateStatic.cs b/src/Box2D.NET.Samples/Samples/Shapes/RecreateStatic.cs index 486d7863..60bbdc26 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/RecreateStatic.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/RecreateStatic.cs @@ -17,14 +17,14 @@ public class RecreateStatic : Sample private B2BodyId m_groundId; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new RecreateStatic(ctx, settings); + return new RecreateStatic(context); } - public RecreateStatic(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public RecreateStatic(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 2.5f); m_context.camera.m_zoom = 3.5f; @@ -42,7 +42,7 @@ public RecreateStatic(SampleAppContext ctx, Settings settings) : base(ctx, setti m_groundId = new B2BodyId(); } - public override void Step(Settings settings) + public override void Step() { if (B2_IS_NON_NULL(m_groundId)) { @@ -62,6 +62,6 @@ public override void Step(Settings settings) B2Segment segment = new B2Segment(new B2Vec2(-10.0f, 0.0f), new B2Vec2(10.0f, 0.0f)); b2CreateSegmentShape(m_groundId, ref shapeDef, ref segment); - base.Step(settings); + base.Step(); } } diff --git a/src/Box2D.NET.Samples/Samples/Shapes/Restitution.cs b/src/Box2D.NET.Samples/Samples/Shapes/Restitution.cs index 334c20ab..cb56e626 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/Restitution.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/Restitution.cs @@ -28,14 +28,14 @@ enum ShapeType private B2BodyId[] m_bodyIds = new B2BodyId[m_count]; private ShapeType m_shapeType; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Restitution(ctx, settings); + return new Restitution(context); } - public Restitution(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Restitution(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(4.0f, 17.0f); m_context.camera.m_zoom = 27.5f; diff --git a/src/Box2D.NET.Samples/Samples/Shapes/RollingResistance.cs b/src/Box2D.NET.Samples/Samples/Shapes/RollingResistance.cs index b150ada2..62f7c3d0 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/RollingResistance.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/RollingResistance.cs @@ -17,14 +17,14 @@ public class RollingResistance : Sample private float m_resistScale; private float m_lift; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new RollingResistance(ctx, settings); + return new RollingResistance(context); } - public RollingResistance(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public RollingResistance(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(5.0f, 20.0f); m_context.camera.m_zoom = 27.5f; diff --git a/src/Box2D.NET.Samples/Samples/Shapes/RoundedShapes.cs b/src/Box2D.NET.Samples/Samples/Shapes/RoundedShapes.cs index 8c1521dd..307c126f 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/RoundedShapes.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/RoundedShapes.cs @@ -15,14 +15,14 @@ public class RoundedShapes : Sample { private static readonly int SampleRoundedShapes = SampleFactory.Shared.RegisterSample("Shapes", "Rounded", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new RoundedShapes(ctx, settings); + return new RoundedShapes(context); } - public RoundedShapes(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public RoundedShapes(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_zoom = 25.0f * 0.55f; m_context.camera.m_center = new B2Vec2(2.0f, 8.0f); diff --git a/src/Box2D.NET.Samples/Samples/Shapes/ShapeFilter.cs b/src/Box2D.NET.Samples/Samples/Shapes/ShapeFilter.cs index b1e81595..1e3eae4a 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/ShapeFilter.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/ShapeFilter.cs @@ -30,15 +30,15 @@ public class ShapeFilter : Sample B2ShapeId m_shape2Id; B2ShapeId m_shape3Id; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new ShapeFilter(ctx, settings); + return new ShapeFilter(context); } - public ShapeFilter(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public ShapeFilter(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_zoom = 25.0f * 0.5f; m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); diff --git a/src/Box2D.NET.Samples/Samples/Shapes/TangentSpeed.cs b/src/Box2D.NET.Samples/Samples/Shapes/TangentSpeed.cs index 841bc061..798bc90b 100644 --- a/src/Box2D.NET.Samples/Samples/Shapes/TangentSpeed.cs +++ b/src/Box2D.NET.Samples/Samples/Shapes/TangentSpeed.cs @@ -21,14 +21,14 @@ public class TangentSpeed : Sample private float m_friction; private float m_rollingResistance; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new TangentSpeed(ctx, settings); + return new TangentSpeed(context); } - public TangentSpeed(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public TangentSpeed(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(60.0f, -15.0f); m_context.camera.m_zoom = 38.0f; @@ -136,14 +136,14 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { - if (m_stepCount % 25 == 0 && m_bodyIds.Count < m_totalCount && settings.pause == false) + if (m_stepCount % 25 == 0 && m_bodyIds.Count < m_totalCount && m_context.settings.pause == false) { B2BodyId id = DropBall(); m_bodyIds.Add(id); } - base.Step(settings); + base.Step(); } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Stackings/Arch.cs b/src/Box2D.NET.Samples/Samples/Stackings/Arch.cs index 1dad01c3..5bd32261 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/Arch.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/Arch.cs @@ -15,14 +15,14 @@ public class Arch : Sample { private static readonly int SampleArch = SampleFactory.Shared.RegisterSample("Stacking", "Arch", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Arch(ctx, settings); + return new Arch(context); } - public Arch(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Arch(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 8.0f); m_context.camera.m_zoom = 25.0f * 0.35f; diff --git a/src/Box2D.NET.Samples/Samples/Stackings/CapsuleStack.cs b/src/Box2D.NET.Samples/Samples/Stackings/CapsuleStack.cs index 53ba22ba..68143346 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/CapsuleStack.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/CapsuleStack.cs @@ -18,14 +18,14 @@ struct Event int indexA, indexB; } - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new CapsuleStack(ctx, settings); + return new CapsuleStack(context); } - public CapsuleStack(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public CapsuleStack(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); m_context.camera.m_zoom = 6.0f; diff --git a/src/Box2D.NET.Samples/Samples/Stackings/CardHouse.cs b/src/Box2D.NET.Samples/Samples/Stackings/CardHouse.cs index 08a6e63d..f0df8155 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/CardHouse.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/CardHouse.cs @@ -15,14 +15,14 @@ public class CardHouse : Sample { private static readonly int SampleCardHouse = SampleFactory.Shared.RegisterSample("Stacking", "Card House", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new CardHouse(ctx, settings); + return new CardHouse(context); } - public CardHouse(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public CardHouse(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.75f, 0.9f); m_context.camera.m_zoom = 25.0f * 0.05f; diff --git a/src/Box2D.NET.Samples/Samples/Stackings/CircleStack.cs b/src/Box2D.NET.Samples/Samples/Stackings/CircleStack.cs index bca0b56f..b5d2b89d 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/CircleStack.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/CircleStack.cs @@ -16,9 +16,9 @@ public class CircleStack : Sample private static readonly int SampleCircleStack = SampleFactory.Shared.RegisterSample("Stacking", "Circle Stack", Create); private List m_events = new List(); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new CircleStack(ctx, settings); + return new CircleStack(context); } public struct Event @@ -32,9 +32,9 @@ public Event(int indexA, int indexB) } }; - public CircleStack(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public CircleStack(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); m_context.camera.m_zoom = 6.0f; @@ -109,8 +109,8 @@ public override void Draw(Settings settings) int eventCount = m_events.Count; for (int i = 0; i < eventCount; ++i) { - m_context.draw.DrawString(5, m_textLine, $"{m_events[i].indexA}, {m_events[i].indexB}"); - m_textLine += m_textIncrement; + DrawTextLine($"{m_events[i].indexA}, {m_events[i].indexB}"); + } } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Stackings/Cliff.cs b/src/Box2D.NET.Samples/Samples/Stackings/Cliff.cs index 60972a33..909609b9 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/Cliff.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/Cliff.cs @@ -20,15 +20,15 @@ public class Cliff : Sample private B2BodyId[] m_bodyIds = new B2BodyId[9]; private bool m_flip; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Cliff(ctx, settings); + return new Cliff(context); } - public Cliff(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Cliff(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_zoom = 25.0f * 0.5f; m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); diff --git a/src/Box2D.NET.Samples/Samples/Stackings/Confined.cs b/src/Box2D.NET.Samples/Samples/Stackings/Confined.cs index 271a770b..11ef2806 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/Confined.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/Confined.cs @@ -20,15 +20,15 @@ public class Confined : Sample int m_count; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new Confined(ctx, settings); + return new Confined(context); } - public Confined(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public Confined(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 10.0f); m_context.camera.m_zoom = 25.0f * 0.5f; diff --git a/src/Box2D.NET.Samples/Samples/Stackings/DoubleDomino.cs b/src/Box2D.NET.Samples/Samples/Stackings/DoubleDomino.cs index 7d007333..1206be24 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/DoubleDomino.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/DoubleDomino.cs @@ -13,14 +13,14 @@ public class DoubleDomino : Sample { private static readonly int SampleDoubleDomino = SampleFactory.Shared.RegisterSample("Stacking", "Double Domino", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new DoubleDomino(ctx, settings); + return new DoubleDomino(context); } - public DoubleDomino(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public DoubleDomino(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 4.0f); m_context.camera.m_zoom = 25.0f * 0.25f; diff --git a/src/Box2D.NET.Samples/Samples/Stackings/SingleBox.cs b/src/Box2D.NET.Samples/Samples/Stackings/SingleBox.cs index 29bef613..63e67178 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/SingleBox.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/SingleBox.cs @@ -15,14 +15,14 @@ public class SingleBox : Sample B2BodyId m_bodyId; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new SingleBox(ctx, settings); + return new SingleBox(context); } - public SingleBox(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public SingleBox(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 2.5f); m_context.camera.m_zoom = 3.5f; diff --git a/src/Box2D.NET.Samples/Samples/Stackings/TiltedStack.cs b/src/Box2D.NET.Samples/Samples/Stackings/TiltedStack.cs index 09c01421..9896c306 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/TiltedStack.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/TiltedStack.cs @@ -19,15 +19,15 @@ public class TiltedStack : Sample private B2BodyId[] m_bodies = new B2BodyId[m_rows * m_columns]; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new TiltedStack(ctx, settings); + return new TiltedStack(context); } - public TiltedStack(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public TiltedStack(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(7.5f, 7.5f); m_context.camera.m_zoom = 20.0f; diff --git a/src/Box2D.NET.Samples/Samples/Stackings/VerticalStack.cs b/src/Box2D.NET.Samples/Samples/Stackings/VerticalStack.cs index 8cab25e7..9af8d275 100644 --- a/src/Box2D.NET.Samples/Samples/Stackings/VerticalStack.cs +++ b/src/Box2D.NET.Samples/Samples/Stackings/VerticalStack.cs @@ -42,15 +42,15 @@ enum ShapeType private ShapeType m_shapeType; private ShapeType m_bulletType; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new VerticalStack(ctx, settings); + return new VerticalStack(context); } - public VerticalStack(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public VerticalStack(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(-7.0f, 9.0f); m_context.camera.m_zoom = 14.0f; diff --git a/src/Box2D.NET.Samples/Samples/Worlds/LargeWorld.cs b/src/Box2D.NET.Samples/Samples/Worlds/LargeWorld.cs index d9c4ee58..59795ad5 100644 --- a/src/Box2D.NET.Samples/Samples/Worlds/LargeWorld.cs +++ b/src/Box2D.NET.Samples/Samples/Worlds/LargeWorld.cs @@ -36,12 +36,12 @@ public class LargeWorld : Sample private bool m_followCar; - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new LargeWorld(ctx, settings); + return new LargeWorld(context); } - public LargeWorld(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public LargeWorld(SampleContext context) : base(context) { m_period = 40.0f; float omega = 2.0f * B2_PI / m_period; @@ -53,12 +53,12 @@ public LargeWorld(SampleAppContext ctx, Settings settings) : base(ctx, settings) m_viewPosition = new B2Vec2(xStart, 15.0f); - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = m_viewPosition; m_context.camera.m_zoom = 25.0f * 1.0f; - settings.drawJoints = false; - settings.useCameraBounds = true; + m_context.settings.drawJoints = false; + m_context.settings.useCameraBounds = true; } { @@ -190,12 +190,12 @@ public override void UpdateGui() ImGui.End(); } - public override void Step(Settings settings) + public override void Step() { float span = 0.5f * (m_period * m_cycleCount); - float timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f; + float timeStep = m_context.settings.hertz > 0.0f ? 1.0f / m_context.settings.hertz : 0.0f; - if (settings.pause) + if (m_context.settings.pause) { timeStep = 0.0f; } @@ -248,6 +248,6 @@ public override void Step(Settings settings) m_car.SetSpeed(-5.0f); } - base.Step(settings); + base.Step(); } } \ No newline at end of file diff --git a/src/Box2D.NET.Samples/Samples/Worlds/WorkbenchWorld.cs b/src/Box2D.NET.Samples/Samples/Worlds/WorkbenchWorld.cs index 33558b93..2e29b4a3 100644 --- a/src/Box2D.NET.Samples/Samples/Worlds/WorkbenchWorld.cs +++ b/src/Box2D.NET.Samples/Samples/Worlds/WorkbenchWorld.cs @@ -10,14 +10,14 @@ public class WorkbenchWorld : Sample { private static readonly int SampleLargeWorld = SampleFactory.Shared.RegisterSample("World", "Workbench World", Create); - private static Sample Create(SampleAppContext ctx, Settings settings) + private static Sample Create(SampleContext context) { - return new WorkbenchWorld(ctx, settings); + return new WorkbenchWorld(context); } - public WorkbenchWorld(SampleAppContext ctx, Settings settings) : base(ctx, settings) + public WorkbenchWorld(SampleContext context) : base(context) { - if (settings.restart == false) + if (m_context.settings.restart == false) { m_context.camera.m_center = new B2Vec2(0.0f, 5.0f); m_context.camera.m_zoom = 25.0f * 0.5f; diff --git a/src/Box2D.NET.Shared/RandomSupports.cs b/src/Box2D.NET.Shared/RandomSupports.cs index c7887119..e5736ccb 100644 --- a/src/Box2D.NET.Shared/RandomSupports.cs +++ b/src/Box2D.NET.Shared/RandomSupports.cs @@ -15,7 +15,7 @@ namespace Box2D.NET.Shared public static class RandomSupports { // Global seed for simple random number generator. - public static uint g_seed = RAND_SEED; + public static uint g_randomSeed = RAND_SEED; public const int RAND_LIMIT = 32767; public const int RAND_SEED = 12345; @@ -23,11 +23,11 @@ public static class RandomSupports public static int RandomInt() { // XorShift32 algorithm - uint x = g_seed; + uint x = g_randomSeed; x ^= x << 13; x ^= x >> 17; x ^= x << 5; - g_seed = x; + g_randomSeed = x; // Map the 32-bit value to the range 0 to RAND_LIMIT return (int)(x % (RAND_LIMIT + 1)); diff --git a/src/Box2D.NET/B2BoardPhases.cs b/src/Box2D.NET/B2BoardPhases.cs index 5608788c..7844d2ae 100644 --- a/src/Box2D.NET/B2BoardPhases.cs +++ b/src/Box2D.NET/B2BoardPhases.cs @@ -202,7 +202,7 @@ public static bool b2PairQueryCallback(int proxyId, ulong userData, ref B2QueryP // I had an optimization here to skip checking the move set if this is a query into // the static tree. The assumption is that the static proxies are never in the move set // so there is no risk of duplication. However, this is not true with - // b2ShapeDef::forceContactCreation, b2ShapeDef::isSensor, or when a static shape is modified. + // b2ShapeDef::invokeContactCreation or when a static shape is modified. // There can easily be scenarios where the static proxy is in the moveSet but the dynamic proxy is not. // I could have some flag to indicate that there are any static bodies in the moveSet. diff --git a/src/Box2D.NET/B2Bodies.cs b/src/Box2D.NET/B2Bodies.cs index f7039fb7..7e3b1089 100644 --- a/src/Box2D.NET/B2Bodies.cs +++ b/src/Box2D.NET/B2Bodies.cs @@ -818,6 +818,7 @@ public static void b2Body_SetAngularVelocity(B2BodyId bodyId, float angularVeloc /// Set the velocity to reach the given transform after a given time step. /// The result will be close but maybe not exact. This is meant for kinematic bodies. + /// The target is not applied if the velocity would be below the sleep threshold. /// This will automatically wake the body if asleep. public static void b2Body_SetTargetTransform(B2BodyId bodyId, B2Transform target, float timeStep) { @@ -847,8 +848,10 @@ public static void b2Body_SetTargetTransform(B2BodyId bodyId, B2Transform target angularVelocity = invTimeStep * deltaAngle; } - // Return if velocity would be zero - if (b2LengthSquared(linearVelocity) == 0.0f && b2AbsFloat(angularVelocity) == 0.0f) + float maxVelocity = b2Length(linearVelocity) + b2AbsFloat(angularVelocity) * sim.maxExtent; + + // Return if velocity would be sleepy + if (maxVelocity < body.sleepThreshold) { return; } diff --git a/src/Box2D.NET/B2Contacts.cs b/src/Box2D.NET/B2Contacts.cs index b9892341..1753cb74 100644 --- a/src/Box2D.NET/B2Contacts.cs +++ b/src/Box2D.NET/B2Contacts.cs @@ -404,9 +404,10 @@ public static void b2DestroyContact(B2World world, B2Contact contact, bool wakeB } else { - // contact is non-touching or is sleeping or is a sensor + // contact is non-touching or is sleeping B2_ASSERT(contact.setIndex != (int)B2SetType.b2_awakeSet || (contact.flags & (uint)B2ContactFlags.b2_contactTouchingFlag) == 0); B2SolverSet set = b2Array_Get(ref world.solverSets, contact.setIndex); + int movedIndex = b2Array_RemoveSwap(ref set.contactSims, contact.localIndex); if (movedIndex != B2_NULL_INDEX) { @@ -445,7 +446,7 @@ public static B2ContactSim b2GetContactSim(B2World world, B2Contact contact) } - // Update the contact manifold and touching status. Also updates sensor overlap. + // Update the contact manifold and touching status. // Note: do not assume the shape AABBs are overlapping or are valid. public static bool b2UpdateContact(B2World world, B2ContactSim contactSim, B2Shape shapeA, B2Transform transformA, B2Vec2 centerOffsetA, B2Shape shapeB, B2Transform transformB, B2Vec2 centerOffsetB) diff --git a/src/Box2D.NET/B2Cores.cs b/src/Box2D.NET/B2Cores.cs index b9e9d175..3a49eaee 100644 --- a/src/Box2D.NET/B2Cores.cs +++ b/src/Box2D.NET/B2Cores.cs @@ -130,7 +130,7 @@ public static void b2TracyCZoneNC(object object ctx, object name, object color, } public static void b2TracyCZoneEnd(object ctx) { - TracyCZoneEnd(ctx); + TracyCZoneEnd(context); } #else [Conditional("DEBUG")] diff --git a/src/Box2D.NET/B2Distances.cs b/src/Box2D.NET/B2Distances.cs index 11d689d7..79b11a5b 100644 --- a/src/Box2D.NET/B2Distances.cs +++ b/src/Box2D.NET/B2Distances.cs @@ -546,7 +546,8 @@ public static B2DistanceOutput b2ShapeDistance(ref B2DistanceInput input, ref B2 // If we have 3 points, then the origin is in the corresponding triangle. if (simplex.count == 3) { - break; + // Overlap + return output; } #if DEBUG diff --git a/src/Box2D.NET/B2Sensors.cs b/src/Box2D.NET/B2Sensors.cs index 9604bb49..a9ae45d8 100644 --- a/src/Box2D.NET/B2Sensors.cs +++ b/src/Box2D.NET/B2Sensors.cs @@ -164,8 +164,8 @@ public static void b2SensorTask(int startIndex, int endIndex, uint threadIndex, { world = world, taskContext = taskContext, - sensorShape = sensorShape, sensor = sensor, + sensorShape = sensorShape, transform = transform, }; diff --git a/src/Box2D.NET/B2Worlds.cs b/src/Box2D.NET/B2Worlds.cs index 5711029e..8e685caf 100644 --- a/src/Box2D.NET/B2Worlds.cs +++ b/src/Box2D.NET/B2Worlds.cs @@ -430,11 +430,11 @@ public static void b2CollideTask(int startIndex, int endIndex, uint threadIndex, B2Vec2 centerOffsetA = b2RotateVector(transformA.q, bodySimA.localCenter); B2Vec2 centerOffsetB = b2RotateVector(transformB.q, bodySimB.localCenter); - // This updates solid contacts and sensors + // This updates solid contacts bool touching = b2UpdateContact(world, contactSim, shapeA, transformA, centerOffsetA, shapeB, transformB, centerOffsetB); - // State changes that affect island connectivity. Also affects contact and sensor events. + // State changes that affect island connectivity. Also affects contact events. if (touching == true && wasTouching == false) { contactSim.simFlags |= (uint)B2ContactSimFlags.b2_simStartedTouching; @@ -649,7 +649,7 @@ public static void b2Collide(B2StepContext context) else if (0 != (simFlags & (uint)B2ContactSimFlags.b2_simStartedTouching)) { B2_ASSERT(contact.islandId == B2_NULL_INDEX); - // Contact is solid + if (0 != (flags & (uint)B2ContactFlags.b2_contactEnableContactEvents)) { B2ContactBeginTouchEvent @event = new B2ContactBeginTouchEvent(shapeIdA, shapeIdB, ref contactSim.manifold); @@ -681,8 +681,6 @@ public static void b2Collide(B2StepContext context) else if (0 != (simFlags & (uint)B2ContactSimFlags.b2_simStoppedTouching)) { contactSim.simFlags &= ~(uint)B2ContactSimFlags.b2_simStoppedTouching; - - // Contact is solid contact.flags &= ~(uint)B2ContactFlags.b2_contactTouchingFlag; if (0 != (contact.flags & (uint)B2ContactFlags.b2_contactEnableContactEvents)) @@ -3230,7 +3228,6 @@ public static void b2ValidateContacts(B2World world) if (setId == (int)B2SetType.b2_awakeSet) { - // If touching and not a sensor if (touching) { B2_ASSERT(0 <= contact.colorIndex && contact.colorIndex < B2_GRAPH_COLOR_COUNT); @@ -3247,7 +3244,7 @@ public static void b2ValidateContacts(B2World world) } else { - // Sleeping and non-touching contacts or sensor contacts belong in the disabled set + // Sleeping and non-touching contacts belong in the disabled set B2_ASSERT(touching == false && setId == (int)B2SetType.b2_disabledSet); } @@ -3256,7 +3253,6 @@ public static void b2ValidateContacts(B2World world) B2_ASSERT(contactSim.bodyIdA == contact.edges[0].bodyId); B2_ASSERT(contactSim.bodyIdB == contact.edges[1].bodyId); - // Sim touching is true for solid and sensor contacts bool simTouching = (contactSim.simFlags & (uint)B2ContactSimFlags.b2_simTouchingFlag) != 0; B2_ASSERT(touching == simTouching);