WASM examples (+ backports of new official examples) (#344)
* chg: New build system that uses the officially distributed binaries, bumped version to 8.0.0, simplified git workflow, removed deprecated OpenGL 1.1 functionality. * chg: Modernize CI workflow, enable SourceLink - Bump workflow actions to latest majors (Node 24); drop deprecated softprops/action-gh-release@v1 - Trigger push builds on main instead of master - Create local nuget feed dir before pack (fixes NU1301) - Enable Microsoft.SourceLink.GitHub for debugging symbols (ref PR #340) * fix: centralized version data in Directory.build.props, and fixed various interop details that had incorrect function signatures * chore: updated readme * fix: version the native extract marker and chain download via DependsOnTargets The .extracted marker now includes the raylib package name, so bumping TargetRaylibTag re-extracts the new archive instead of silently keeping (and packing/copying) the previous version's files. _PrepareNativeLibrary and _StageWasmNative now depend directly on _DownloadAndExtractInternal instead of CallTarget-ing it; dependency targets run in the same project instance, so the resolved properties (RaylibPackageName etc.) propagate naturally. * fix: let the binding build for browser-wasm on both net8.0 and net10.0 The net8-era wasm workload (Microsoft.NET.Runtime.WebAssembly.Sdk 8.0.x, auto-imported for RID browser-wasm) treats every browser-wasm project as a wasm app: it forces OutputType=Exe after project evaluation (CS5001 for a classlib) and hooks its app-bundle build after Build, which errors because a library has no assemblies to bundle. Opt Raylib-cs out via DisableAutoWasmBuildApp (props time, before the workload defaults its trigger) and pin OutputType back to Library in Directory.Build.targets (evaluated after the workload props, so the assignment wins). net10's wasm SDK needs neither workaround. * chore: readme updated * chg: simplifying build logic - a simple line in the documentation should save us the code here * fix: Wrong signature of FrameBufferComplete * chore: readme update * feat: samples default to local project reference, and can optionally use the nuget package * feat: backporting existing raylib-cs examples and new official raylib examples to WASM, adopting raylib's original code style * chore: readme, gitignore, and targets backport. * fix: Examples.csproj runs the download task when building locally * feat: backporting existing raylib-cs examples and new official raylib examples to WASM, adopting raylib's original code style * chore: readme, gitignore, and targets backport. * chore: clean up linter warnings * feat: html harness focuses the example and allows quick navigation with J/K instead. * chore: readme mentions the property to use nuget vs. the local project reference * feat: replaced the J/K navigation with good old HTML buttons * chore: run dotnet format scoped default (was previously scoped to just 'style')
This commit is contained in:
parent
b207e633ae
commit
8c22e68c2a
236 changed files with 40405 additions and 10896 deletions
|
|
@ -15,114 +15,141 @@
|
|||
*
|
||||
********************************************************************************************/
|
||||
|
||||
using System.Numerics;
|
||||
|
||||
namespace Examples.Core;
|
||||
|
||||
using static Raylib_cs.Raylib;
|
||||
|
||||
public class DeltaTime
|
||||
public partial class DeltaTime : IExample
|
||||
{
|
||||
private const int screenWidth = 800;
|
||||
private const int screenHeight = 450;
|
||||
|
||||
// The speed applied to both circles
|
||||
private const float speed = 10.0f;
|
||||
private const float circleRadius = 32.0f;
|
||||
|
||||
private int currentFps;
|
||||
|
||||
// Store the position for the both of the circles
|
||||
private Vector2 deltaCircle;
|
||||
private Vector2 frameCircle;
|
||||
|
||||
public string Name => "Core / Delta Time";
|
||||
|
||||
public string Title => "raylib [core] example - delta time";
|
||||
|
||||
public void Init()
|
||||
{
|
||||
currentFps = 60;
|
||||
|
||||
// Store the position for the both of the circles
|
||||
deltaCircle = new Vector2(0, (float)screenHeight / 3.0f);
|
||||
frameCircle = new Vector2(0, (float)screenHeight * (2.0f / 3.0f));
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// Adjust the FPS target based on the mouse wheel
|
||||
var mouseWheel = GetMouseWheelMove();
|
||||
if (mouseWheel != 0)
|
||||
{
|
||||
currentFps += (int)mouseWheel;
|
||||
if (currentFps < 0)
|
||||
{
|
||||
currentFps = 0;
|
||||
}
|
||||
SetTargetFPS(currentFps);
|
||||
}
|
||||
|
||||
// GetFrameTime() returns the time it took to draw the last frame, in seconds (usually called delta time)
|
||||
// Uses the delta time to make the circle look like it's moving at a "consistent" speed regardless of FPS
|
||||
|
||||
// Multiply by 6.0 (an arbitrary value) in order to make the speed
|
||||
// visually closer to the other circle (at 60 fps), for comparison
|
||||
deltaCircle.X += GetFrameTime() * 6.0f * speed;
|
||||
// This circle can move faster or slower visually depending on the FPS
|
||||
frameCircle.X += 0.1f * speed;
|
||||
|
||||
// If either circle is off the screen, reset it back to the start
|
||||
if (deltaCircle.X > screenWidth)
|
||||
{
|
||||
deltaCircle.X = 0;
|
||||
}
|
||||
|
||||
if (frameCircle.X > screenWidth)
|
||||
{
|
||||
frameCircle.X = 0;
|
||||
}
|
||||
|
||||
// Reset both circles positions
|
||||
if (IsKeyPressed(KeyboardKey.R))
|
||||
{
|
||||
deltaCircle.X = 0;
|
||||
frameCircle.X = 0;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.RayWhite);
|
||||
|
||||
// Draw both circles to the screen
|
||||
DrawCircleV(deltaCircle, circleRadius, Color.Red);
|
||||
DrawCircleV(frameCircle, circleRadius, Color.Blue);
|
||||
|
||||
// Draw the help text
|
||||
// Determine what help text to show depending on the current FPS target
|
||||
var fpsText = "";
|
||||
if (currentFps <= 0)
|
||||
{
|
||||
fpsText = $"FPS: unlimited ({GetFPS()})";
|
||||
}
|
||||
else
|
||||
{
|
||||
fpsText = $"FPS: {GetFPS()} (target: {currentFps})";
|
||||
}
|
||||
DrawText(fpsText, 10, 10, 20, Color.DarkGray);
|
||||
DrawText($"Frame time: {GetFrameTime():F2} ms", 10, 30, 20, Color.DarkGray);
|
||||
DrawText("Use the scroll wheel to change the fps limit, r to reset", 10, 50, 20, Color.DarkGray);
|
||||
|
||||
// Draw the text above the circles
|
||||
DrawText("FUNC: x += GetFrameTime()*speed", 10, 90, 20, Color.Red);
|
||||
DrawText("FUNC: x += speed", 10, 240, 20, Color.Blue);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
}
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - delta time");
|
||||
|
||||
int currentFps = 60;
|
||||
|
||||
Vector2 deltaCircle = new Vector2(0, (float)screenHeight / 3.0f);
|
||||
Vector2 frameCircle = new Vector2(0, (float)screenHeight * (2.0f / 3.0f));
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
const float speed = 10.0f;
|
||||
const float circleRadius = 32.0f;
|
||||
var game = new DeltaTime();
|
||||
game.Init();
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// Adjust the FPS target based on the mouse wheel
|
||||
float mouseWheel = GetMouseWheelMove();
|
||||
if (mouseWheel != 0)
|
||||
{
|
||||
currentFps += (int)mouseWheel;
|
||||
if (currentFps < 0)
|
||||
{
|
||||
currentFps = 0;
|
||||
}
|
||||
SetTargetFPS(currentFps);
|
||||
}
|
||||
|
||||
// GetFrameTime() returns the time it took to draw the last frame, in seconds (usually called delta time)
|
||||
// Uses the delta time to make the circle look like it's moving at a "consistent" speed regardless of FPS
|
||||
|
||||
// Multiply by 6.0 (an arbitrary value) in order to make the speed
|
||||
// visually closer to the other circle (at 60 fps), for comparison
|
||||
deltaCircle.X += GetFrameTime() * 6.0f * speed;
|
||||
// This circle can move faster or slower visually depending on the FPS
|
||||
frameCircle.X += 0.1f * speed;
|
||||
|
||||
// If either circle is off the screen, reset it back to the start
|
||||
if (deltaCircle.X > screenWidth)
|
||||
{
|
||||
deltaCircle.X = 0;
|
||||
}
|
||||
|
||||
if (frameCircle.X > screenWidth)
|
||||
{
|
||||
frameCircle.X = 0;
|
||||
}
|
||||
|
||||
// Reset both circles positions
|
||||
if (IsKeyPressed(KeyboardKey.R))
|
||||
{
|
||||
deltaCircle.X = 0;
|
||||
frameCircle.X = 0;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.RayWhite);
|
||||
|
||||
// Draw both circles to the screen
|
||||
DrawCircleV(deltaCircle, circleRadius, Color.Red);
|
||||
DrawCircleV(frameCircle, circleRadius, Color.Blue);
|
||||
|
||||
// Draw the help text
|
||||
// Determine what help text to show depending on the current FPS target
|
||||
var fpsText = "";
|
||||
if (currentFps <= 0)
|
||||
{
|
||||
fpsText = $"FPS: unlimited ({GetFPS()})";
|
||||
}
|
||||
else
|
||||
{
|
||||
fpsText = $"FPS: {GetFPS()} (target: {currentFps})";
|
||||
}
|
||||
DrawText(fpsText, 10, 10, 20, Color.DarkGray);
|
||||
DrawText($"Frame time: {GetFrameTime():F2} ms", 10, 30, 20, Color.DarkGray);
|
||||
DrawText("Use the scroll wheel to change the fps limit, r to reset", 10, 50, 20, Color.DarkGray);
|
||||
|
||||
// Draw the text above the circles
|
||||
DrawText("FUNC: x += GetFrameTime()*speed", 10, 90, 20, Color.Red);
|
||||
DrawText("FUNC: x += speed", 10, 240, 20, Color.Blue);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
game.Update();
|
||||
}
|
||||
|
||||
game.Unload();
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow();
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue