From 14a369918ccb2a65efa65de08f9955b2218f8709 Mon Sep 17 00:00:00 2001 From: Braedon Lewis Date: Thu, 13 Apr 2023 08:28:40 -0400 Subject: [PATCH] Remove todo --- .idea/.idea.raylib-beef/.idea/.gitignore | 1 + generator/Program.cs | 7 -- raylib-beef/example/BeefProj.toml | 1 - raylib-beef/example/src/Program.bf | 107 +++++++++++++++++++---- 4 files changed, 92 insertions(+), 24 deletions(-) diff --git a/.idea/.idea.raylib-beef/.idea/.gitignore b/.idea/.idea.raylib-beef/.idea/.gitignore index 1cea7bf..aa9c867 100644 --- a/.idea/.idea.raylib-beef/.idea/.gitignore +++ b/.idea/.idea.raylib-beef/.idea/.gitignore @@ -4,6 +4,7 @@ # Rider ignored files /projectSettingsUpdater.xml /modules.xml +/.idea.raylib-beef.iml /contentModel.xml # Editor-based HTTP Client requests /httpRequests/ diff --git a/generator/Program.cs b/generator/Program.cs index 45e5652..fccbba8 100644 --- a/generator/Program.cs +++ b/generator/Program.cs @@ -39,13 +39,6 @@ namespace RaylibBeefGenerator private static string Namespace = "Raylib"; #endregion - // TODO: - // Defines - // Enums - // Other things like RLGL and stuff. - // Output generated code to actual directory. - // Organize Beef project. - public static void Main(string[] args) { Console.WriteLine($"Generating files at {OutputDir}"); diff --git a/raylib-beef/example/BeefProj.toml b/raylib-beef/example/BeefProj.toml index b34e11c..4e4b53b 100644 --- a/raylib-beef/example/BeefProj.toml +++ b/raylib-beef/example/BeefProj.toml @@ -3,6 +3,5 @@ Dependencies = {corlib = "*", raylib-beef = "*"} [Project] Name = "example" -TargetType = "BeefGUIApplication" StartupObject = "raylib_test.Program" DefaultNamespace = "raylib_test" diff --git a/raylib-beef/example/src/Program.bf b/raylib-beef/example/src/Program.bf index 9d7a834..f253f0d 100644 --- a/raylib-beef/example/src/Program.bf +++ b/raylib-beef/example/src/Program.bf @@ -1,43 +1,118 @@ using System; +using System.Collections; using Raylib; namespace raylib_test; class Program { + struct Bunny + { + public Vector2 position; + public Vector2 speed; + public Color color; + } + + public static float Range(int min, int max) + { + var returnC = (float)GetRandomValue(0, max); + if (returnC < max / 2) + returnC = Raymath.Lerp(min, max, Raymath.Normalize(returnC, 0, 125)); + else + returnC = Raymath.Lerp(min, max, Raymath.Normalize(returnC, max / 2, 250)); + + // Console.WriteLine(returnC); + + return returnC; + } + public static int Main(String[] args) { - SetConfigFlags(4); - InitWindow(800, 600, "Raylib Beef 4.5"); + int screenWidth = 800; + int screenHeight = 600; + + SetConfigFlags((int)ConfigFlags.FLAG_VSYNC_HINT | (int)ConfigFlags.FLAG_WINDOW_RESIZABLE); + InitWindow(screenWidth, screenHeight, "Raylib Beef 4.5"); + + var texBunny = LoadTexture(@"C:\Users\Braedon\Downloads\wabbit_alpha.png"); + var bunnies = new List(); var beefMain = Color(165, 47, 78, 255); var beefOutline = Color(243, 157, 157, 255); while (!WindowShouldClose()) { + if (IsMouseButtonDown((int)MouseButton.MOUSE_BUTTON_LEFT)) + { + for (int i = 0; i < 100; i++) + { + if (bunnies.Count < 50000) + { + var newBunny = Bunny(); + newBunny.position = GetMousePosition(); + newBunny.speed.x = Range(-250, 250)/60.0f; + newBunny.speed.y = Range(-250, 250)/60.0f; + newBunny.color = Color((uint8)GetRandomValue(50, 240), (uint8)GetRandomValue(80, 240), (uint8)GetRandomValue(100, 240), 255); + bunnies.Add(newBunny); + } + } + + } + + for (int i = 0; i < bunnies.Count; i++) + { + /*if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) || + ((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1; + if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) || + ((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1;*/ + + if ( + (bunnies[i].position.x < 0) || + (bunnies[i].position.x > (GetScreenWidth() - 32)) || + (bunnies[i].position.y > GetScreenHeight() - 32) || + (bunnies[i].position.y < 0)) + { + bunnies.RemoveAtFast(i); + i--; + continue; + } + + + bunnies[i].position.x += bunnies[i].speed.x; + bunnies[i].position.y += bunnies[i].speed.y; + } + BeginDrawing(); - + ClearBackground(RAYWHITE); - DrawCircle(GetMouseX(), GetMouseY(), 20, beefOutline); - DrawRectangle(GetScreenWidth() / 2 - 128, GetScreenHeight() / 2 - 128, 256, 256, beefOutline); - DrawRectangle(GetScreenWidth() / 2 - 112, GetScreenHeight() / 2 - 112, 224, 224, beefMain); + for (int i = 0; i < bunnies.Count; i++) + { + // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), + // a draw call is launched and buffer starts being filled again; + // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... + // Process of sending data is costly and it could happen that GPU data has not been completely + // processed for drawing while new data is tried to be sent (updating current in-use buffers) + // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies + DrawTexture(texBunny, (int)bunnies[i].position.x, (int)bunnies[i].position.y, bunnies[i].color); + } - DrawCircle(GetMouseX(), GetMouseY(), 10, beefMain); + + DrawRectangle(0, 0, GetScreenWidth(), 40, BLACK); + DrawText(scope $"bunnies: {bunnies.Count}", 120, 10, 20, GREEN); + DrawText(scope $"batched draw calls: {1 + bunnies.Count / 50000}", 320, 10, 20, MAROON); - DrawText("raylib", GetScreenWidth() / 2 - 44, GetScreenHeight() / 2, 50, beefOutline); - DrawText("beef", GetScreenWidth() / 2 - 62, GetScreenHeight() / 2 + 46, 50, beefOutline); - - DrawRectangle(GetScreenWidth() / 2 + 54, GetScreenHeight() / 2 + 54, 42, 42, beefOutline); - DrawRectangle(GetScreenWidth() / 2 + 62, GetScreenHeight() / 2 + 62, 26, 26, RAYWHITE); - - DrawText(scope $"{Raymath.Lerp(0, 20, 10)}", 20, 60, 20, DARKGREEN); - - DrawFPS(20, 20); + DrawFPS(10, 10); EndDrawing(); } + + + delete bunnies; + + UnloadTexture(texBunny); + CloseWindow(); return 0;