Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions .github/copilot-instructions.md
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
```
Comment on lines +63 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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
-```
+```text
 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
-```
+```
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```
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
```
🧰 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
In @.github/copilot-instructions.md around lines 63 - 82, The fenced directory
listing in .github/copilot-instructions.md is missing a language tag; update the
opening code fence for the block that starts with "physics/Engine/" to include a
language such as "text" (e.g., change ``` to ```text) so the block satisfies
MD040 and retain the trailing closing fence; no other content changes required.


## 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.
3 changes: 0 additions & 3 deletions SharpPhysics.Demo/BubblePopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public void Initialize(GameEngine engine)
_engine = engine;
_physics = engine.PhysicsSystem;

// Hide debug UI for cleaner game experience
_engine.Renderer.ShowDebugUI = false;

// Very light upward "gravity" for floating bubbles
_physics.Gravity = new Vector2(0, -2f);
_physics.GravityScale = 15f;
Expand Down
Loading