Skip to content
Draft
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
385 changes: 115 additions & 270 deletions .editorconfig

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copilot Instructions for RaylibSharp

## Project Overview

RaylibSharp is a C# binding for the [raylib](https://github.com/raysan5/raylib) graphics library. It provides safe, partially autogenerated interop with raylib, supporting desktop and WASM targets. The codebase is organized into several major components:

- **RaylibSharp/**: Core binding logic, marshalling, and shared utilities.
- **Examples/**, **Examples.Desktop/**, **Examples.Wasm/**: Example projects for different platforms, demonstrating usage patterns.
- **raylib/**: The native raylib source, included as a submodule/tagged clone.

## Key Patterns & Conventions

- **Interop/Marshalling**: Custom marshallers (e.g., `ModelMarshaller`) are used for safe conversion between managed and unmanaged types. See `RaylibSharp/Marshal/` for examples.
- **Icon Embedding**: To customize the app icon, add an `EmbeddedResource` for your icon in the project file. If omitted, a default icon is used.
```xml
<ItemGroup>
<EmbeddedResource Include="./Icon.png" />
</ItemGroup>
```
- **Autogenerated Bindings**: Some code is generated from raylib headers. See `RaylibSharp/gen/` and `RaylibSharpGenerator/` for generation logic.
- **Example Structure**: Example projects are organized by feature (e.g., `Audio/`, `Core/`, `Models/`). Each example is a standalone C# file.

## Build & Run Workflows

- **Desktop**: Standard .NET build and run:
```fish
dotnet build RaylibSharp.sln
dotnet run --project Examples.Desktop/Examples.Desktop.csproj
```
- **WASM**: Build and serve with:
```fish
dotnet publish Examples.Wasm/Examples.Wasm.csproj
dotnet serve --directory "./Examples.Wasm/bin/Debug/net8.0/browser-wasm/AppBundle/" -p 42069
```
- **Native raylib**: Clone the raylib repo at tag 5.5 into the `raylib/` directory:
```fish
git clone --depth=1 --branch 5.5 https://github.com/raysan5/raylib.git raylib
```

## External Dependencies

- **raylib**: Native C library, included as source.
- **.NET 8**: Target framework for all projects.
- **dotnet-serve**: Used for serving WASM builds locally.

## Notable Files & Directories

- `RaylibSharp/Marshal/`: Custom marshallers for interop.
- `RaylibSharpGenerator/`: Code generation logic for bindings.
- `Examples/`: Canonical usage patterns and feature demos.
- `Readme.md`: Project-level build and usage instructions.

## Tips for AI Agents

- Always use the provided marshallers for managed/unmanaged conversions.
- Follow the example structure for new demos.
- Reference the `Readme.md` for up-to-date build and run commands.
- When adding new bindings, update both the generator and the marshal logic as needed.

---

_If any section is unclear or missing important project-specific details, please provide feedback so this guide can be improved._
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

RaylibSharpGenerator/examples/**/*
Examples.Wasm/raylib.a
raylib/
38 changes: 0 additions & 38 deletions .vscode/launch.json

This file was deleted.

84 changes: 3 additions & 81 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,91 +10,13 @@
"--project",
"${workspaceFolder}/RaylibSharpGenerator/RaylibSharpGenerator.csproj"
],
"options": {
"cwd": "${workspaceFolder}/RaylibSharpGenerator/"
},
"runOptions": {
"runOn": "folderOpen"
},
"problemMatcher": []
},
{
"label": "Watch Examples.Desktop",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"--project",
"${workspaceFolder}/Examples.Desktop\\Examples.Desktop.csproj"
],
"problemMatcher": []
},
{
"label": "Build RaylibSharpGenerator",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/RaylibSharpGenerator\\RaylibSharpGenerator.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": [],
"group": "build",
"__autoGenerated__": true
},
{
"label": "Build Examples.Wasm",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Examples.Wasm\\Examples.Wasm.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": [],
"group": "build",
"__autoGenerated__": true
},
{
"label": "Build Examples.Desktop",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Examples.Desktop\\Examples.Desktop.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": [],
"group": "build",
"__autoGenerated__": true
},
{
"label": "Build RaylibSharp",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/RaylibSharp\\RaylibSharp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": [],
"group": "build",
"__autoGenerated__": true
},
{
"label": "Build CheatsheetGenerator",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/CheatsheetGenerator\\CheatsheetGenerator.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": [],
"group": "build",
"__autoGenerated__": true
}
]
}
16 changes: 16 additions & 0 deletions Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<StripSymbols>true</StripSymbols>
<PublishAot>true</PublishAot>

<ApplicationIcon>../Icon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../RaylibSharp/RaylibSharp.csproj" />
</ItemGroup>
</Project>
29 changes: 29 additions & 0 deletions Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Example;

using RaylibSharp;

public static class Program
{
private const int screenWidth = 800;
private const int screenHeight = 450;

public static void Main()
{
Raylib.InitWindow(screenWidth, screenHeight, "Hello, World!");

Raylib.SetTargetFPS(60);

while (!Raylib.WindowShouldClose())
{
Raylib.BeginDrawing();
{
Raylib.ClearBackground(Color.RayWhite);

Raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, Color.LightGray);
}
Raylib.EndDrawing();
}

Raylib.CloseWindow();
}
}
2 changes: 1 addition & 1 deletion Examples.Desktop/Examples.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<StripSymbols>true</StripSymbols>
Expand Down
24 changes: 12 additions & 12 deletions Examples.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace Examples.Desktop;
using System.IO;

public static class Program
{
public static void Main()
{

Directory.SetCurrentDirectory(System.AppContext.BaseDirectory);
ExamplePicker.Run();
}
}
namespace Examples.Desktop;
using System.IO;
public static class Program
{
public static void Main()
{
Directory.SetCurrentDirectory(System.AppContext.BaseDirectory);
ExamplePicker.Run();
}
}
2 changes: 1 addition & 1 deletion Examples.Wasm/Examples.Wasm.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
38 changes: 19 additions & 19 deletions Examples.Wasm/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
namespace Examples.Wasm;

using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Versioning;

[SupportedOSPlatform("browser")]
public static partial class Program
{
public static void Main()
{
ExamplePicker.Run();
}

[JSExport]
public static bool IsExample()
{
return ExamplePicker.IsExample;
}
}
namespace Examples.Wasm;
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Versioning;
[SupportedOSPlatform("browser")]
public static partial class Program
{
public static void Main()
{
ExamplePicker.Run();
}
[JSExport]
public static bool IsExample()
{
return ExamplePicker.IsExample;
}
}
6 changes: 6 additions & 0 deletions Examples/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*.cs]
dotnet_analyzer_diagnostic.severity = none
dotnet_diagnostic.IDE0011.severity = none
dotnet_diagnostic.CS0618.severity = none
Loading