Skip to content
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

Fix Raylib 4.0 Building #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions examples/bunnymark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p align="center">
<img src="https://raw.githubusercontent.com/haxeui/raylib-haxe/main/examples/textures/screen.png"/>
</p>
10 changes: 10 additions & 0 deletions examples/bunnymark/Run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
cd bin
if "%1"=="debug" (
:: run debug
Main-Debug.exe
pause
) else (
:: run release
Main.exe
)
6 changes: 6 additions & 0 deletions examples/bunnymark/build.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-lib raylib-haxe

-cp src

-cpp bin
-main Main
53 changes: 53 additions & 0 deletions examples/bunnymark/bunnymark.hxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<project version="2">
<!-- Output SWF options -->
<output>
<movie outputType="Application" />
<movie input="" />
<movie path="bin" />
<movie fps="0" />
<movie width="0" />
<movie height="0" />
<movie version="0" />
<movie minorVersion="0" />
<movie platform="C++" />
<movie background="#FFFFFF" />
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
<class path="src" />
</classpaths>
<!-- Build options -->
<build>
<option directives="" />
<option flashStrict="False" />
<option noInlineOnDebug="False" />
<option mainClass="Main" />
<option enabledebug="False" />
<option additional="" />
</build>
<!-- haxelib libraries -->
<haxelib>
<library name="raylib-haxe" />
</haxelib>
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
<compile path="src\Main.hx" />
</compileTargets>
<!-- Paths to exclude from the Project Explorer tree -->
<hiddenPaths>
<hidden path="obj" />
</hiddenPaths>
<!-- Executed before build -->
<preBuildCommand />
<!-- Executed after build -->
<postBuildCommand alwaysRun="False" />
<!-- Other project options -->
<options>
<option showHiddenPaths="False" />
<option testMovie="Custom" />
<option testMovieCommand="run.bat $(BuildConfig)" />
</options>
<!-- Plugin storage -->
<storage />
</project>
Binary file added examples/bunnymark/screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions examples/bunnymark/src/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package;

import RayLib.*;
import RayLib.Colors.*;
import RayLib.Image;
import RayLib.Texture;
import RayLib.Vector2;
import RayLib.Vector2Ref;
import RayLib.Color;
import RayLib.ColorRef;
import RayLib.PixelFormat;
import cpp.NativeArray;
import haxe.io.Bytes;

typedef Bunny = {
position:Vector2,
speed:Vector2,
color:Color
};

class Main {
static final MAX_BUNNIES = 100000;
static final MAX_BATCH_ELEMENTS = 8192;

static function main() {
var screenWidth:Int = 800;
var screenHeight:Int = 450;

InitWindow(screenWidth, screenHeight, "RAYLIB HAXE!");

var texBunny = LoadTexture("wabbit_alpha.png");

var bunnies:Array<Bunny> = new Array<Bunny>();

SetTargetFPS(60);

while (!WindowShouldClose()) {
if (IsMouseButtonDown(RayLib.MouseButton.LEFT)) {
for (i in 0...100) {
if (bunnies.length < MAX_BUNNIES) {
var bunny:Bunny = {
position: GetMousePosition(),
speed: cast Vector2.create(GetRandomValue(-250, 250) / 60.0, GetRandomValue(-250, 250) / 60.0),
color: cast Color.create(GetRandomValue(50, 240), GetRandomValue(80, 240), GetRandomValue(100, 240), 255)
};
bunnies.push(bunny);
}
}
}

var halfBunnyWidth:Float = texBunny.width / 2;
var halfBunnyHeight:Float = texBunny.height / 2;

for (bunny in bunnies) {
var newPositionX = bunny.position.x + bunny.speed.x;
var newPositionY = bunny.position.y + bunny.speed.y;

var newSpeedX = bunny.speed.x;
var newSpeedY = bunny.speed.y;

if ((newPositionX + halfBunnyWidth > screenWidth) || (newPositionX - halfBunnyWidth < 0))
newSpeedX *= -1;

if ((newPositionY + halfBunnyHeight > screenHeight) || (newPositionY + halfBunnyHeight - 40 < 0))
newSpeedY *= -1;

bunny.position = cast Vector2.create(newPositionX, newPositionY);
bunny.speed = cast Vector2.create(newSpeedX, newSpeedY);
}


// Draw
BeginDrawing();
ClearBackground(RAYWHITE);


for (bunny in bunnies) {
DrawTexture(texBunny, Std.int(bunny.position.x), Std.int(bunny.position.y), bunny.color);
}

DrawRectangle(0, 0, screenWidth, 40, BLACK);
DrawText(Std.string("bunnies: " + bunnies.length), 120, 10, 20, GREEN);
DrawText(Std.string("batched draw calls: " + (1 + bunnies.length / MAX_BATCH_ELEMENTS)), 320, 10, 20, MAROON);
DrawFPS(10, 10);

EndDrawing();
}

CloseWindow();
}
}
Binary file added examples/bunnymark/wabbit_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion generator/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Main {
];

static function main() {
var source = "https://raw.githubusercontent.com/raysan5/raylib/master/parser/raylib_api.xml"; // must use xml version so function params are ordered
var source = "https://raw.githubusercontent.com/raysan5/raylib/4.0.0/parser/raylib_api.xml"; // must use xml version so function params are ordered
var output = "RayLib.hx";

log('building externs from "${source}"');
Expand Down