-
Notifications
You must be signed in to change notification settings - Fork 4
Demo project refactor, Renderer memory cleanup #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dankelley2
wants to merge
5
commits into
master
Choose a base branch
from
ProjectRefactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27fdbb4
refactoring demo game and removing unneeded render activities
dankelley2 de9492c
Moving AnimatedBackground to demo games
dankelley2 5097694
removing some nasty drawing shape allocations from AI slop methods
dankelley2 25b80a5
Removing un needed code from renderer
dankelley2 578c144
Updating frame timing and background frame in renderer
dankelley2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # SharpPhysics Project Instructions | ||
|
|
||
| ## Project Overview | ||
|
|
||
| SharpPhysics is a 2D physics engine built with C# (.NET 9) and SFML.NET for rendering. It includes: | ||
|
|
||
| - **physics/** (`SharpPhysics.csproj`) - Core physics engine library | ||
| - **SharpPhysics.Demo/** - Demo games showcasing the engine | ||
| - **PoseIntegrator.Vision/** - YOLO-based pose detection for body tracking | ||
| - **PoseIntegrator.Demo/** - Standalone pose detection demo | ||
|
|
||
| ## Architecture Principles | ||
|
|
||
| ### Engine vs Game Separation | ||
|
|
||
| The `physics/` project is the **core engine** and should contain only: | ||
| - Physics simulation (`PhysicsSystem`, collision detection, constraints) | ||
| - Core rendering infrastructure (`Renderer`, primitive drawing) | ||
| - Input handling (`InputManager`) | ||
| - Game loop (`GameEngine`, `IGame` interface) | ||
| - Reusable UI components (`UiManager`, `UiButton`, `UiSlider`, etc.) | ||
| - Object templates for creating physics objects | ||
|
|
||
| **DO NOT** put game-specific code in the engine: | ||
| - Debug UIs specific to one game → put in Demo project | ||
| - Visual effects only used by demos → put in Demo project | ||
| - Game-specific scene builders → put in Demo project | ||
|
|
||
| ### Render Layers | ||
|
|
||
| Games implement `IGame` with these render methods: | ||
| 1. `RenderBackground(Renderer)` - Optional, renders behind physics objects | ||
| 2. `Render(Renderer)` - Required, renders in front of physics objects | ||
|
|
||
| The engine calls them in order: Background → Physics Objects → Foreground | ||
|
|
||
| ### Naming Conventions | ||
|
|
||
| - Be honest with names - don't call something a "ParticleSystem" if it's just floating circles | ||
| - Use descriptive names: `AnimatedBackground`, `SandboxDebugUI`, `DemoSceneBuilder` | ||
| - Prefix demo-specific classes appropriately | ||
|
|
||
| ## Code Style | ||
|
|
||
| ### General | ||
| - Use `#nullable enable` at the top of all files | ||
| - Use file-scoped namespaces (`namespace X;` not `namespace X { }`) | ||
| - Minimize comments - code should be self-documenting | ||
| - Remove commented-out code blocks | ||
|
|
||
| ### Fields and Properties | ||
| - Private fields: `_camelCase` | ||
| - Properties: `PascalCase` | ||
| - Constants: `PascalCase` or `UPPER_SNAKE_CASE` for true constants | ||
|
|
||
| ### Methods | ||
| - Keep methods focused and small | ||
| - Extract helper methods for clarity | ||
| - Group related functionality with `#region` sparingly | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| physics/Engine/ | ||
| ├── Core/ # GameEngine, IGame interface | ||
| ├── Rendering/ # Renderer, UI components | ||
| ├── Input/ # InputManager | ||
| ├── Objects/ # PhysicsObject | ||
| ├── Shapes/ # CirclePhysShape, PolygonPhysShape, etc. | ||
| ├── Shaders/ # SFML shader implementations | ||
| ├── Constraints/ # Physics constraints (Weld, Axis, Spring) | ||
| ├── Helpers/ # Math utilities, extensions | ||
| └── Classes/ # Templates, collision data | ||
|
|
||
| SharpPhysics.Demo/ | ||
| ├── DemoProps/ # Demo-specific components (SandboxDebugUI, DemoSceneBuilder) | ||
| ├── Helpers/ # Demo utilities (AnimatedBackground, SkeletonRenderer) | ||
| ├── Integration/ # PersonColliderBridge for pose tracking | ||
| ├── Designer/ # Prefab designer game | ||
| ├── Settings/ # GameSettings configuration | ||
| └── [Game].cs # Individual game implementations | ||
| ``` | ||
|
|
||
| ## Common Patterns | ||
|
|
||
| ### Creating a New Game | ||
|
|
||
| ```csharp | ||
| public class MyGame : IGame | ||
| { | ||
| private GameEngine _engine = null!; | ||
|
|
||
| public void Initialize(GameEngine engine) | ||
| { | ||
| _engine = engine; | ||
| // Setup code here | ||
| } | ||
|
|
||
| public void Update(float deltaTime, InputManager input) { } | ||
|
|
||
| public void RenderBackground(Renderer renderer) { } // Optional | ||
|
|
||
| public void Render(Renderer renderer) { } | ||
|
|
||
| public void Shutdown() { } | ||
| } | ||
| ``` | ||
|
|
||
| ### Debug UI (Game-Specific) | ||
|
|
||
| Debug/development UIs should be in the Demo project, not the engine: | ||
|
|
||
| ```csharp | ||
| // In SharpPhysics.Demo/DemoProps/ | ||
| public class MyGameDebugUI | ||
| { | ||
| private readonly UiManager _uiManager = new(); | ||
|
|
||
| public void Render(Renderer renderer) | ||
| { | ||
| renderer.Window.SetView(renderer.UiView); | ||
| _uiManager.Draw(renderer.Window); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Physics Object Creation | ||
|
|
||
| Use `ObjectTemplates` for creating physics objects: | ||
|
|
||
| ```csharp | ||
| var templates = new ObjectTemplates(engine.PhysicsSystem); | ||
| var ball = templates.CreateSmallBall(x, y); | ||
| var box = templates.CreateBox(position, width, height); | ||
| ``` | ||
|
|
||
| ### Constraints | ||
|
|
||
| ```csharp | ||
| engine.AddWeldConstraint(bodyA, bodyB, anchorA, anchorB); // Rigid | ||
| engine.AddAxisConstraint(bodyA, bodyB, anchorA, anchorB); // Rotating joint | ||
| engine.AddSpringConstraint(bodyA, bodyB); // Spring | ||
| ``` | ||
|
|
||
| ## Dependencies | ||
|
|
||
| - **SFML.NET** - Windowing and rendering | ||
| - **System.Numerics** - Vector math (use `Vector2` from this, not SFML's) | ||
| - **OpenCvSharp4** - Camera capture (PoseIntegrator.Vision) | ||
| - **Microsoft.ML.OnnxRuntime** - YOLO inference (PoseIntegrator.Vision) | ||
|
|
||
| ## Testing | ||
|
|
||
| Run `dotnet build` to verify changes compile. The solution includes `SharpPhysics.Tests` for unit tests. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a language to the fenced code block to satisfy MD040.
This block should specify a language (e.g.,
text) to avoid markdownlint warnings and keep formatting consistent.🔧 Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.20.0)
[warning] 63-63: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents