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

[WIP] Code generated FFI #32

Open
wants to merge 3 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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
},
"autoload": {
"psr-4": {
"Nawarian\\Raylib\\": "src/"
"Nawarian\\Raylib\\": "src/",
"Nawarian\\Raylib\\Generated\\": "generated/"
}
},
"autoload-dev": {
"psr-4": {
"Nawarian\\Tests\\Raylib\\": "tests/"
},
"files": ["src/generated-functions.php"]
}
},
"scripts": {
"phpunit": "phpunit",
"phpcs": "phpcs --standard=PSR12 -s src/ examples/",
"psalm": "psalm",
"checks": ["@psalm", "@phpcs", "@phpunit"],
"generate-functions": "Nawarian\\Raylib\\Utils\\Composer\\CommandHandler::generateFunctionsFile"
"build": "Nawarian\\Raylib\\Command\\GenerateRaylibWrappers::generate"
}
}
52 changes: 52 additions & 0 deletions generated/AudioStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Nawarian\Raylib\Generated;

class AudioStream
{
/**
* Pointer to internal data used by the audio system
*/
public FFI\CData $buffer;

/**
* Frequency (samples per second)
*/
public int $sampleRate;

/**
* Bit depth (bits per sample): 8, 16, 32 (24 not supported)
*/
public int $sampleSize;

/**
* Number of channels (1-mono, 2-stereo)
*/
public int $channels;

public function __construct(\FFI\CData $buffer, int $sampleRate, int $sampleSize, int $channels)
{
$this->buffer = $buffer;
$this->sampleRate = $sampleRate;
$this->sampleSize = $sampleSize;
$this->channels = $channels;
}

public function toCData(): \FFI\CData
{
global $raylib;
$type = $raylib->new('AudioStream');
$type->buffer = $this->buffer;
$type->sampleRate = $this->sampleRate;
$type->sampleSize = $this->sampleSize;
$type->channels = $this->channels;
return $type;
}

public static function fromCData(\FFI\CData $cdata): \Nawarian\Raylib\Generated\AudioStream
{
return new self($cdata->buffer, $cdata->sampleRate, $cdata->sampleSize, $cdata->channels);
}
}
38 changes: 38 additions & 0 deletions generated/BoneInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Nawarian\Raylib\Generated;

class BoneInfo
{
/**
* Bone name
*/
public array $name[32];

/**
* Bone parent
*/
public int $parent;

public function __construct(array $name[32], int $parent)
{
$this->name[32] = $name[32];
$this->parent = $parent;
}

public function toCData(): \FFI\CData
{
global $raylib;
$type = $raylib->new('BoneInfo');
$type->name[32] = $this->name[32];
$type->parent = $this->parent;
return $type;
}

public static function fromCData(\FFI\CData $cdata): \Nawarian\Raylib\Generated\BoneInfo
{
return new self($cdata->name[32], $cdata->parent);
}
}
38 changes: 38 additions & 0 deletions generated/BoundingBox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Nawarian\Raylib\Generated;

class BoundingBox
{
/**
* Minimum vertex box-corner
*/
public \Nawarian\Raylib\Generated\Vector3 $min;

/**
* Maximum vertex box-corner
*/
public \Nawarian\Raylib\Generated\Vector3 $max;

public function __construct(\Nawarian\Raylib\Generated\Vector3 $min, \Nawarian\Raylib\Generated\Vector3 $max)
{
$this->min = $min;
$this->max = $max;
}

public function toCData(): \FFI\CData
{
global $raylib;
$type = $raylib->new('BoundingBox');
$type->min = $this->min->toCData();
$type->max = $this->max->toCData();
return $type;
}

public static function fromCData(\FFI\CData $cdata): \Nawarian\Raylib\Generated\BoundingBox
{
return new self(\Nawarian\Raylib\Generated\Vector3::fromCData($cdata->min), \Nawarian\Raylib\Generated\Vector3::fromCData($cdata->max));
}
}
52 changes: 52 additions & 0 deletions generated/Camera2D.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Nawarian\Raylib\Generated;

class Camera2D
{
/**
* Camera offset (displacement from target)
*/
public \Nawarian\Raylib\Generated\Vector2 $offset;

/**
* Camera target (rotation and zoom origin)
*/
public \Nawarian\Raylib\Generated\Vector2 $target;

/**
* Camera rotation in degrees
*/
public float $rotation;

/**
* Camera zoom (scaling), should be 1.0f by default
*/
public float $zoom;

public function __construct(\Nawarian\Raylib\Generated\Vector2 $offset, \Nawarian\Raylib\Generated\Vector2 $target, float $rotation, float $zoom)
{
$this->offset = $offset;
$this->target = $target;
$this->rotation = $rotation;
$this->zoom = $zoom;
}

public function toCData(): \FFI\CData
{
global $raylib;
$type = $raylib->new('Camera2D');
$type->offset = $this->offset->toCData();
$type->target = $this->target->toCData();
$type->rotation = $this->rotation;
$type->zoom = $this->zoom;
return $type;
}

public static function fromCData(\FFI\CData $cdata): \Nawarian\Raylib\Generated\Camera2D
{
return new self(\Nawarian\Raylib\Generated\Vector2::fromCData($cdata->offset), \Nawarian\Raylib\Generated\Vector2::fromCData($cdata->target), $cdata->rotation, $cdata->zoom);
}
}
60 changes: 60 additions & 0 deletions generated/Camera3D.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Nawarian\Raylib\Generated;

class Camera3D
{
/**
* Camera position
*/
public \Nawarian\Raylib\Generated\Vector3 $position;

/**
* Camera target it looks-at
*/
public \Nawarian\Raylib\Generated\Vector3 $target;

/**
* Camera up vector (rotation over its axis)
*/
public \Nawarian\Raylib\Generated\Vector3 $up;

/**
* Camera field-of-view apperture in Y (degrees) in perspective, used as near plane
* width in orthographic
*/
public float $fovy;

/**
* Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
*/
public int $projection;

public function __construct(\Nawarian\Raylib\Generated\Vector3 $position, \Nawarian\Raylib\Generated\Vector3 $target, \Nawarian\Raylib\Generated\Vector3 $up, float $fovy, int $projection)
{
$this->position = $position;
$this->target = $target;
$this->up = $up;
$this->fovy = $fovy;
$this->projection = $projection;
}

public function toCData(): \FFI\CData
{
global $raylib;
$type = $raylib->new('Camera3D');
$type->position = $this->position->toCData();
$type->target = $this->target->toCData();
$type->up = $this->up->toCData();
$type->fovy = $this->fovy;
$type->projection = $this->projection;
return $type;
}

public static function fromCData(\FFI\CData $cdata): \Nawarian\Raylib\Generated\Camera3D
{
return new self(\Nawarian\Raylib\Generated\Vector3::fromCData($cdata->position), \Nawarian\Raylib\Generated\Vector3::fromCData($cdata->target), \Nawarian\Raylib\Generated\Vector3::fromCData($cdata->up), $cdata->fovy, $cdata->projection);
}
}
59 changes: 59 additions & 0 deletions generated/CharInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Nawarian\Raylib\Generated;

class CharInfo
{
/**
* Character value (Unicode)
*/
public int $value;

/**
* Character offset X when drawing
*/
public int $offsetX;

/**
* Character offset Y when drawing
*/
public int $offsetY;

/**
* Character advance position X
*/
public int $advanceX;

/**
* Character image data
*/
public \Nawarian\Raylib\Generated\Image $image;

public function __construct(int $value, int $offsetX, int $offsetY, int $advanceX, \Nawarian\Raylib\Generated\Image $image)
{
$this->value = $value;
$this->offsetX = $offsetX;
$this->offsetY = $offsetY;
$this->advanceX = $advanceX;
$this->image = $image;
}

public function toCData(): \FFI\CData
{
global $raylib;
$type = $raylib->new('CharInfo');
$type->value = $this->value;
$type->offsetX = $this->offsetX;
$type->offsetY = $this->offsetY;
$type->advanceX = $this->advanceX;
$type->image = $this->image->toCData();
return $type;
}

public static function fromCData(\FFI\CData $cdata): \Nawarian\Raylib\Generated\CharInfo
{
return new self($cdata->value, $cdata->offsetX, $cdata->offsetY, $cdata->advanceX, \Nawarian\Raylib\Generated\Image::fromCData($cdata->image));
}
}
52 changes: 52 additions & 0 deletions generated/Color.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Nawarian\Raylib\Generated;

class Color
{
/**
* Color red value
*/
public int $r;

/**
* Color green value
*/
public int $g;

/**
* Color blue value
*/
public int $b;

/**
* Color alpha value
*/
public int $a;

public function __construct(int $r, int $g, int $b, int $a)
{
$this->r = $r;
$this->g = $g;
$this->b = $b;
$this->a = $a;
}

public function toCData(): \FFI\CData
{
global $raylib;
$type = $raylib->new('Color');
$type->r = $this->r;
$type->g = $this->g;
$type->b = $this->b;
$type->a = $this->a;
return $type;
}

public static function fromCData(\FFI\CData $cdata): \Nawarian\Raylib\Generated\Color
{
return new self($cdata->r, $cdata->g, $cdata->b, $cdata->a);
}
}
Loading