serafim/ffi-sdl
Composer 安装命令:
composer require serafim/ffi-sdl
包简介
SDL FFI bindings for the PHP language
README 文档
README
A SDL FFI bindings for the PHP language.
Requirements
- PHP ^8.1
- ext-ffi
- Windows, Linux, BSD or MacOS
- Android, iOS or something else are not supported yet
- SDL >= 2.0
Installation
Library is available as composer repository and can be installed using the following command in a root of your project.
$ composer require serafim/ffi-sdl
Additional dependencies:
- Debian-based Linux:
sudo apt install libsdl2-2.0-0 -y - MacOS:
brew install sdl2 - Window: Can be downloaded from here
Extensions
Documentation
The library API completely supports and repeats the analogue in the C language.
-
API not yet fully documented and may not work in places.
-
Low level and inline functions (such as
SDL_mallocorSDL_memcpy) have been removed.
Initialization
To specify a library pathname explicitly, you can add the library argument to
the Serafim\SDL\SDL constructor.
By default, the library will try to resolve the binary's pathname automatically.
// Load library from pathname (it may be relative or part of system-dependent path) $sdl = new Serafim\SDL\SDL(library: __DIR__ . '/path/to/library.so'); // Try to automatically resolve library's pathname $sdl = new Serafim\SDL\SDL(library: null);
You can explicitly specify the platform (OS) that will be used as the basis for compiling headers.
By default, the library will try to resolve the platform automatically.
// Use Linux as compile-aware platform $sdl = new Serafim\SDL\SDL(platform: Serafim\SDL\Platform::LINUX); // Detect platform automatically $sdl = new Serafim\SDL\SDL(platform: null);
You can also specify the library version explicitly. Depending on this version, the corresponding functions of the SDL will be available.
By default, the library will try to resolve SDL version automatically.
// Use v2.28.2 from string $sdl = new Serafim\SDL\SDL(version: '2.28.2'); // Use v2.24.1 from predefined versions constant $sdl = new Serafim\SDL\SDL(version: \Serafim\SDL\Version::V2_24_1); // Use latest supported version $sdl = new Serafim\SDL\SDL(version: \Serafim\SDL\Version::LATEST);
To speed up the header compiler, you can use any PSR-16 compatible cache driver.
$sdl = new Serafim\SDL\SDL(cache: new Psr16Cache(...));
In addition, you can control other preprocessor directives explicitly:
$pre = new \FFI\Preprocessor\Preprocessor(); $pre->setLogger(new ExampleLogger()); $pre->define('__ANDROID__', '1'); $sdl = new Serafim\SDL\SDL(pre: $pre); $jni = $sdl->SDL_AndroidGetJNIEnv();
Example
use Serafim\SDL\SDL; use Serafim\SDL\Event\Type; $sdl = new SDL(); $sdl->SDL_Init(SDL::SDL_INIT_VIDEO); $window = $sdl->SDL_CreateWindow( 'An SDL2 window', SDL::SDL_WINDOWPOS_UNDEFINED, SDL::SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL::SDL_WINDOW_OPENGL ); if ($window === null) { throw new \Exception(sprintf('Could not create window: %s', $sdl->SDL_GetError())); } $event = $sdl->new('SDL_Event'); $running = true; while ($running) { $sdl->SDL_PollEvent(FFI::addr($event)); if ($event->type === Type::SDL_QUIT) { $running = false; } } $sdl->SDL_DestroyWindow($window); $sdl->SDL_Quit();
serafim/ffi-sdl 适用场景与选型建议
serafim/ffi-sdl 是一款 基于 C 开发的 Composer 扩展包,目前已累计 4.59k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2020 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「graphics」 「library」 「bindings」 「sdl」 「ffi」 「opengl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 serafim/ffi-sdl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 serafim/ffi-sdl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 serafim/ffi-sdl 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This library turns the Contao Core API into events.
Inbox pattern process implementation for your Laravel Applications
Image processing for PHP 5.3
Image processing for PHP 5.3
Core library that defines common interfaces used by the rest of the intahwebz..
Amqp classes
统计信息
- 总下载量: 4.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 33
- 点击次数: 9
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-23