From ded8d90bd5efa7a437690e585fbebcbb3746cb59 Mon Sep 17 00:00:00 2001 From: Serafim Date: Sat, 11 Apr 2020 03:07:48 +0300 Subject: [PATCH] Fix namespace (use PSR-4) and add full SDL 2.0.12 support --- .phpstorm.meta.php | 300 +------ README.md | 29 +- composer.json | 7 +- resources/SDLNativeApiAutocomplete.php | 52 +- resources/sdl-types.h | 35 +- resources/sdl.h | 39 +- resources/structures.php | 47 +- src/Exception/LibraryException.php | 2 +- src/Exception/SDLException.php | 2 +- src/Exception/VersionException.php | 2 +- src/Kernel/Assert/State.php | 4 +- src/Kernel/Audio/AllowChangeFlag.php | 2 +- src/Kernel/Audio/Format.php | 6 +- src/Kernel/Audio/Status.php | 2 +- src/Kernel/Boolean.php | 2 +- src/Kernel/Enums.php | 4 +- src/Kernel/Event/Action.php | 2 +- src/Kernel/Event/Type.php | 8 +- src/Kernel/GameController/Axis.php | 2 +- src/Kernel/GameController/BindType.php | 2 +- src/Kernel/GameController/Button.php | 2 +- src/Kernel/GameController/Type.php | 48 + src/Kernel/Hint/Name.php | 162 +++- src/Kernel/Hint/Priority.php | 2 +- src/Kernel/InitFlags.php | 4 +- src/Kernel/Joystick/Hat.php | 2 +- src/Kernel/Joystick/PowerLevel.php | 2 +- src/Kernel/Joystick/Type.php | 2 +- src/Kernel/Keyboard/EventState.php | 2 +- src/Kernel/Keyboard/Key.php | 2 +- src/Kernel/Keyboard/KeyMode.php | 2 +- src/Kernel/Keyboard/ScanCode.php | 2 +- src/Kernel/Log/Category.php | 2 +- src/Kernel/Log/Priority.php | 2 +- src/Kernel/MessageBox/ButtonFlags.php | 2 +- src/Kernel/MessageBox/ColorType.php | 2 +- src/Kernel/MessageBox/Flags.php | 2 +- src/Kernel/Mouse/Button.php | 2 +- src/Kernel/Mouse/SystemCursor.php | 2 +- src/Kernel/Mouse/WheelDirection.php | 2 +- src/Kernel/OpenGL/GLAttr.php | 6 +- src/Kernel/OpenGL/GLContextFlag.php | 2 +- src/Kernel/OpenGL/GLContextReleaseFlag.php | 2 +- .../OpenGL/GLContextResetNotification.php | 2 +- src/Kernel/OpenGL/GLProfile.php | 2 +- src/Kernel/OpenGL/GLSwapInterval.php | 2 +- src/Kernel/Power/State.php | 2 +- src/Kernel/RWops/SeekWhence.php | 4 +- src/Kernel/Sensor/Type.php | 2 +- src/Kernel/ThreadPriority.php | 4 +- src/Kernel/Touch/DeviceType.php | 2 +- src/Kernel/Video/ArrayOrder.php | 2 +- src/Kernel/Video/BitMapOrder.php | 2 +- src/Kernel/Video/BlendFactor.php | 2 +- src/Kernel/Video/BlendMode.php | 55 +- src/Kernel/Video/BlendOperation.php | 2 +- src/Kernel/Video/DisplayEvent.php | 2 +- src/Kernel/Video/DisplayOrientation.php | 2 +- src/Kernel/Video/HitTestResult.php | 2 +- src/Kernel/Video/PackedLayout.php | 2 +- src/Kernel/Video/PackedOrder.php | 2 +- src/Kernel/Video/PixelFormat.php | 2 +- src/Kernel/Video/PixelType.php | 2 +- src/Kernel/Video/RendererFlags.php | 2 +- src/Kernel/Video/RendererFlip.php | 2 +- src/Kernel/Video/ScaleMode.php | 58 ++ src/Kernel/Video/TextureAccess.php | 2 +- src/Kernel/Video/TextureModulate.php | 2 +- src/Kernel/Video/WindowEvent.php | 6 +- src/Kernel/Video/WindowFlags.php | 2 +- src/Kernel/Video/WindowPosition.php | 2 +- src/Kernel/Video/WindowShapeMode.php | 2 +- src/Kernel/Video/YuvConversionMode.php | 2 +- src/Library.php | 26 +- src/Loader/BitDepth.php | 83 -- src/Loader/LibraryInformation.php | 133 --- src/Loader/LibraryInterface.php | 48 - src/Loader/LibraryLoader.php | 219 ----- src/Loader/OperatingSystem.php | 144 --- src/Loader/PreProcessor.php | 348 ------- src/SDL.php | 848 ++---------------- src/Support/ProxyTrait.php | 157 ---- src/Support/SingletonTrait.php | 2 +- src/Support/VersionComparisonTrait.php | 21 +- tests/TestCase.php | 2 +- 85 files changed, 643 insertions(+), 2372 deletions(-) create mode 100644 src/Kernel/GameController/Type.php create mode 100644 src/Kernel/Video/ScaleMode.php delete mode 100644 src/Loader/BitDepth.php delete mode 100644 src/Loader/LibraryInformation.php delete mode 100644 src/Loader/LibraryInterface.php delete mode 100644 src/Loader/LibraryLoader.php delete mode 100644 src/Loader/OperatingSystem.php delete mode 100644 src/Loader/PreProcessor.php delete mode 100644 src/Support/ProxyTrait.php diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index 9341825..13351d4 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -72,7 +72,7 @@ "char **", ); - override(\SDL\SDL::new(), map([ + override(\Serafim\SDL\SDL::new(), map([ '' => '@', // mixed "void *" => \FFI\CScalar::class, @@ -137,301 +137,9 @@ "char *" => \FFI\CStringPtr::class, "char **" => \FFI\CStringPtrPtr::class, ])); - override(\SDL\Support\ProxyTrait::new(), map([ - '' => type(0), - // mixed - "void *" => \FFI\CScalar::class, - - // floats - "float" => \FFI\CFloat::class, - "float *" => \FFI\CFloatPtr::class, - "float **" => \FFI\CFloatPtrPtr::class, - - "double" => \FFI\CFloat::class, - "double *" => \FFI\CFloatPtr::class, - "double **" => \FFI\CFloatPtrPtr::class, - - "long double" => \FFI\CFloat::class, - "long double *" => \FFI\CFloatPtr::class, - "long double **" => \FFI\CFloatPtrPtr::class, - // integers - "int" => \FFI\CInt::class, - "int *" => \FFI\CIntPtr::class, - "int **" => \FFI\CIntPtrPtr::class, - "uint8_t" => \FFI\CInt::class, - "uint8_t *" => \FFI\CIntPtr::class, - "uint8_t **" => \FFI\CIntPtrPtr::class, - - "int8_t" => \FFI\CInt::class, - "int8_t*" => \FFI\CIntPtr::class, - "int8_t *" => \FFI\CIntPtr::class, - "int8_t**" => \FFI\CIntPtrPtr::class, - "int8_t **" => \FFI\CIntPtrPtr::class, - - "uint16_t" => \FFI\CInt::class, - "uint16_t *" => \FFI\CIntPtr::class, - "uint16_t **" => \FFI\CIntPtrPtr::class, - - "int16_t" => \FFI\CInt::class, - "int16_t *" => \FFI\CIntPtr::class, - "int16_t **" => \FFI\CIntPtrPtr::class, - - "uint32_t" => \FFI\CInt::class, - "uint32_t *" => \FFI\CIntPtr::class, - "uint32_t **" => \FFI\CIntPtrPtr::class, - - "int32_t" => \FFI\CInt::class, - "int32_t *" => \FFI\CIntPtr::class, - "int32_t **" => \FFI\CIntPtrPtr::class, - - "uint64_t" => \FFI\CInt::class, - "uint64_t *" => \FFI\CIntPtr::class, - "uint64_t **" => \FFI\CIntPtrPtr::class, - - "int64_t" => \FFI\CInt::class, - "int64_t *" => \FFI\CIntPtr::class, - "int64_t **" => \FFI\CIntPtrPtr::class, - - // bool - "bool" => \FFI\CBool::class, - "bool *" => \FFI\CBoolPtr::class, - "bool **" => \FFI\CBoolPtrPtr::class, - - // string - "char" => \FFI\CChar::class, - "char *" => \FFI\CStringPtr::class, - "char **" => \FFI\CStringPtrPtr::class, - ])); - - override(\SDL\SDL::addr(), map([ - '' => '@Ptr', - ])); - override(\SDL\Support\ProxyTrait::addr(), map([ - '' => '@Ptr', - ])); - - expectedArguments(\SDL\SDL::new(), 0, argumentsSet('ffiCType')); - expectedArguments(\SDL\Support\ProxyTrait::new(), 0, argumentsSet('ffiCType')); - - expectedArguments(\SDL\SDL::cast(), 0, argumentsSet('ffiCType')); - expectedArguments(\SDL\Support\ProxyTrait::cast(), 0, argumentsSet('ffiCType')); - -} - - -/** - * This file is part of SDL package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace PHPSTORM_META { - - registerArgumentsSet('ffiCType', - "void *", - // floats - "float", - "float *", - "float **", - - "double", - "double *", - "double **", - - "long double", - "long double *", - "long double **", - // integers - "int", - "int *", - "int **", - "uint8_t", - "uint8_t *", - "uint8_t **", - - "int8_t", - "int8_t*", - "int8_t *", - "int8_t**", - "int8_t **", - - "uint16_t", - "uint16_t *", - "uint16_t **", - - "int16_t", - "int16_t *", - "int16_t **", - - "uint32_t", - "uint32_t *", - "uint32_t **", - - "int32_t", - "int32_t *", - "int32_t **", - - "uint64_t", - "uint64_t *", - "uint64_t **", - - "int64_t", - "int64_t *", - "int64_t **", - - // bool - "bool", - "bool *", - "bool **", - - // string - "char", - "char *", - "char **", - ); - - override(\SDL\SDL::new(), map([ - '' => '@', - // mixed - "void *" => \FFI\CScalar::class, - - // floats - "float" => \FFI\CFloat::class, - "float *" => \FFI\CFloatPtr::class, - "float **" => \FFI\CFloatPtrPtr::class, - - "double" => \FFI\CFloat::class, - "double *" => \FFI\CFloatPtr::class, - "double **" => \FFI\CFloatPtrPtr::class, - - "long double" => \FFI\CFloat::class, - "long double *" => \FFI\CFloatPtr::class, - "long double **" => \FFI\CFloatPtrPtr::class, - // integers - "int" => \FFI\CInt::class, - "int *" => \FFI\CIntPtr::class, - "int **" => \FFI\CIntPtrPtr::class, - "uint8_t" => \FFI\CInt::class, - "uint8_t *" => \FFI\CIntPtr::class, - "uint8_t **" => \FFI\CIntPtrPtr::class, - - "int8_t" => \FFI\CInt::class, - "int8_t*" => \FFI\CIntPtr::class, - "int8_t *" => \FFI\CIntPtr::class, - "int8_t**" => \FFI\CIntPtrPtr::class, - "int8_t **" => \FFI\CIntPtrPtr::class, - - "uint16_t" => \FFI\CInt::class, - "uint16_t *" => \FFI\CIntPtr::class, - "uint16_t **" => \FFI\CIntPtrPtr::class, - - "int16_t" => \FFI\CInt::class, - "int16_t *" => \FFI\CIntPtr::class, - "int16_t **" => \FFI\CIntPtrPtr::class, - - "uint32_t" => \FFI\CInt::class, - "uint32_t *" => \FFI\CIntPtr::class, - "uint32_t **" => \FFI\CIntPtrPtr::class, - - "int32_t" => \FFI\CInt::class, - "int32_t *" => \FFI\CIntPtr::class, - "int32_t **" => \FFI\CIntPtrPtr::class, - - "uint64_t" => \FFI\CInt::class, - "uint64_t *" => \FFI\CIntPtr::class, - "uint64_t **" => \FFI\CIntPtrPtr::class, - - "int64_t" => \FFI\CInt::class, - "int64_t *" => \FFI\CIntPtr::class, - "int64_t **" => \FFI\CIntPtrPtr::class, - - // bool - "bool" => \FFI\CBool::class, - "bool *" => \FFI\CBoolPtr::class, - "bool **" => \FFI\CBoolPtrPtr::class, - - // string - "char" => \FFI\CChar::class, - "char *" => \FFI\CStringPtr::class, - "char **" => \FFI\CStringPtrPtr::class, - ])); - override(\SDL\Support\ProxyTrait::new(), map([ - '' => type(0), - // mixed - "void *" => \FFI\CScalar::class, - - // floats - "float" => \FFI\CFloat::class, - "float *" => \FFI\CFloatPtr::class, - "float **" => \FFI\CFloatPtrPtr::class, - - "double" => \FFI\CFloat::class, - "double *" => \FFI\CFloatPtr::class, - "double **" => \FFI\CFloatPtrPtr::class, - - "long double" => \FFI\CFloat::class, - "long double *" => \FFI\CFloatPtr::class, - "long double **" => \FFI\CFloatPtrPtr::class, - // integers - "int" => \FFI\CInt::class, - "int *" => \FFI\CIntPtr::class, - "int **" => \FFI\CIntPtrPtr::class, - "uint8_t" => \FFI\CInt::class, - "uint8_t *" => \FFI\CIntPtr::class, - "uint8_t **" => \FFI\CIntPtrPtr::class, - - "int8_t" => \FFI\CInt::class, - "int8_t*" => \FFI\CIntPtr::class, - "int8_t *" => \FFI\CIntPtr::class, - "int8_t**" => \FFI\CIntPtrPtr::class, - "int8_t **" => \FFI\CIntPtrPtr::class, - - "uint16_t" => \FFI\CInt::class, - "uint16_t *" => \FFI\CIntPtr::class, - "uint16_t **" => \FFI\CIntPtrPtr::class, - - "int16_t" => \FFI\CInt::class, - "int16_t *" => \FFI\CIntPtr::class, - "int16_t **" => \FFI\CIntPtrPtr::class, - - "uint32_t" => \FFI\CInt::class, - "uint32_t *" => \FFI\CIntPtr::class, - "uint32_t **" => \FFI\CIntPtrPtr::class, - - "int32_t" => \FFI\CInt::class, - "int32_t *" => \FFI\CIntPtr::class, - "int32_t **" => \FFI\CIntPtrPtr::class, - - "uint64_t" => \FFI\CInt::class, - "uint64_t *" => \FFI\CIntPtr::class, - "uint64_t **" => \FFI\CIntPtrPtr::class, - - "int64_t" => \FFI\CInt::class, - "int64_t *" => \FFI\CIntPtr::class, - "int64_t **" => \FFI\CIntPtrPtr::class, - - // bool - "bool" => \FFI\CBool::class, - "bool *" => \FFI\CBoolPtr::class, - "bool **" => \FFI\CBoolPtrPtr::class, - - // string - "char" => \FFI\CChar::class, - "char *" => \FFI\CStringPtr::class, - "char **" => \FFI\CStringPtrPtr::class, - ])); - - override(\SDL\SDL::addr(), map([ + override(\Serafim\SDL\SDL::addr(), map([ '' => '@Ptr', ])); - override(\SDL\Support\ProxyTrait::addr(), map([ - '' => '@Ptr', - ])); - - expectedArguments(\SDL\SDL::new(), 0, argumentsSet('ffiCType')); - expectedArguments(\SDL\Support\ProxyTrait::new(), 0, argumentsSet('ffiCType')); - - expectedArguments(\SDL\SDL::cast(), 0, argumentsSet('ffiCType')); - expectedArguments(\SDL\Support\ProxyTrait::cast(), 0, argumentsSet('ffiCType')); + expectedArguments(\Serafim\SDL\SDL::new(), 0, argumentsSet('ffiCType')); + expectedArguments(\Serafim\SDL\SDL::cast(), 0, argumentsSet('ffiCType')); } diff --git a/README.md b/README.md index e4e3246..868e562 100644 --- a/README.md +++ b/README.md @@ -50,22 +50,6 @@ The library API completely supports and repeats the analogue in the C language. - [SDL2 official documentation](https://wiki.libsdl.org/FrontPage) -To support autocomplete, please add a link to `\SDL\NativeApiAutocomplete`: - -```php -/** @var \SDL\SDLNativeApiAutocomplete $sdl */ -$sdl = new \SDL\SDL(); -``` - -In addition, the library contains functionality adapted for PHP. -- All methods are converted to the PSR style - - For example `$sdl->init(...)` instead of `$sdl->SDL_Init(...)`. -- In case of errors, methods throw exceptions. -- Removed passing arguments by reference during initialization - - For example `$sdl->getVersion()` instead of `$sdl->SDL_GetVersion($versionPointer)`. -- All arguments that accept a boolean in c-format (short int) are replaced by a boolean. -- Added default arguments in some methods - #### Notes - API not yet fully documented and may not work in places. @@ -74,11 +58,10 @@ In addition, the library contains functionality adapted for PHP. ## Example ```php -use SDL\SDL; -use SDL\Event; -use SDL\Kernel\Event\Type; +use Serafim\SDL\SDL; +use Serafim\SDL\Event; +use Serafim\SDL\Kernel\Event\Type; -/** @var SDL|\SDL\SDLNativeApiAutocomplete $sdl */ $sdl = new SDL(); $sdl->SDL_Init(SDL::SDL_INIT_VIDEO); @@ -97,10 +80,12 @@ if ($window === null) { } $event = $sdl->new(Event::class); +$running = true; -while($sdl->SDL_PollEvent(SDL::addr($event))) { +while ($running) { + $sdl->SDL_PollEvent(SDL::addr($event)); if ($event->type === Type::SDL_QUIT) { - break; + $running = false; } } diff --git a/composer.json b/composer.json index 073451d..0b18332 100644 --- a/composer.json +++ b/composer.json @@ -25,11 +25,12 @@ ], "require": { "php": ">=7.4", - "ext-ffi": "*" + "ext-ffi": "*", + "serafim/ffi-loader": "^1.0" }, "autoload": { "psr-4": { - "SDL\\": "src" + "Serafim\\SDL\\": "src" } }, "require-dev": { @@ -39,7 +40,7 @@ }, "autoload-dev": { "psr-4": { - "SDL\\Tests\\": "tests" + "Serafim\\SDL\\Tests\\": "tests" } }, "config": { diff --git a/resources/SDLNativeApiAutocomplete.php b/resources/SDLNativeApiAutocomplete.php index 3c51619..30f38c6 100644 --- a/resources/SDLNativeApiAutocomplete.php +++ b/resources/SDLNativeApiAutocomplete.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace SDL; +namespace Serafim\SDL; use FFI\CCharPtr; use FFI\CData; @@ -20,6 +20,7 @@ use FFI\CIntPtrPtr; use FFI\CPtr; use FFI\CPtrPtr; +use Serafim\SDL\Kernel\Video\ScaleMode; /** * @formatter:off @@ -134,36 +135,40 @@ * @method void SDL_GL_UnloadLibrary() * @method int SDL_GameControllerAddMapping(string $mappingString) * @method int SDL_GameControllerAddMappingsFromRW(RWopsPtr $rw, int $freerw) - * @method void SDL_GameControllerClose(GameControllerPtr $gamecontroller) + * @method void SDL_GameControllerClose(GameControllerPtr $gameController) * @method int SDL_GameControllerEventState(int $state) * @method GameControllerPtr SDL_GameControllerFromInstanceID(int|CIntPtr $joyid) - * @method int SDL_GameControllerGetAttached(GameControllerPtr $gamecontroller) - * @method int SDL_GameControllerGetAxis(GameControllerPtr $gamecontroller, int|CIntPtr $axis) + * @method GameControllerPtr SDL_GameControllerFromPlayerIndex(int $playerIndex) + * @method void SDL_GameControllerSetPlayerIndex(GameControllerPtr $gameController, int $playerIndex) + * @method int SDL_GameControllerGetAttached(GameControllerPtr $gameController) + * @method int SDL_GameControllerGetAxis(GameControllerPtr $gameController, int|CIntPtr $axis) * @method int|CIntPtr SDL_GameControllerGetAxisFromString(string $pchString) - * @method GameControllerButtonBind SDL_GameControllerGetBindForAxis(GameControllerPtr $gamecontroller, int|CIntPtr $axis) - * @method GameControllerButtonBind SDL_GameControllerGetBindForButton(GameControllerPtr $gamecontroller, int|CIntPtr $button) - * @method int SDL_GameControllerGetButton(GameControllerPtr $gamecontroller, int|CIntPtr $button) + * @method GameControllerButtonBind SDL_GameControllerGetBindForAxis(GameControllerPtr $gameController, int|CIntPtr $axis) + * @method GameControllerButtonBind SDL_GameControllerGetBindForButton(GameControllerPtr $gameController, int|CIntPtr $button) + * @method int SDL_GameControllerGetButton(GameControllerPtr $gameController, int|CIntPtr $button) * @method int|CIntPtr SDL_GameControllerGetButtonFromString(string $pchString) - * @method JoystickPtr SDL_GameControllerGetJoystick(GameControllerPtr $gamecontroller) - * @method int SDL_GameControllerGetPlayerIndex(GameControllerPtr $gamecontroller) - * @method int SDL_GameControllerGetProduct(GameControllerPtr $gamecontroller) - * @method int SDL_GameControllerGetProductVersion(GameControllerPtr $gamecontroller) + * @method JoystickPtr SDL_GameControllerGetJoystick(GameControllerPtr $gameController) + * @method int SDL_GameControllerGetPlayerIndex(GameControllerPtr $gameController) + * @method int SDL_GameControllerGetProduct(GameControllerPtr $gameController) + * @method int SDL_GameControllerGetProductVersion(GameControllerPtr $gameController) * @method string SDL_GameControllerGetStringForAxis(int|CIntPtr $axis) * @method string SDL_GameControllerGetStringForButton(int|CIntPtr $button) - * @method int SDL_GameControllerGetVendor(GameControllerPtr $gamecontroller) - * @method string SDL_GameControllerMapping(GameControllerPtr $gamecontroller) + * @method int SDL_GameControllerGetVendor(GameControllerPtr $gameController) + * @method string SDL_GameControllerMapping(GameControllerPtr $gameController) * @method string SDL_GameControllerMappingForDeviceIndex(int $joystick_index) * @method string SDL_GameControllerMappingForGUID(JoystickGUID $guid) * @method string SDL_GameControllerMappingForIndex(int $mapping_index) - * @method string SDL_GameControllerName(GameControllerPtr $gamecontroller) + * @method string SDL_GameControllerName(GameControllerPtr $gameController) * @method string SDL_GameControllerNameForIndex(int $joystick_index) * @method int SDL_GameControllerNumMappings() - * @method GameControllerPtr SDL_GameControllerOpen(int $joystick_index) - * @method int SDL_GameControllerRumble(GameControllerPtr $gamecontroller, int $low_frequency_rumble, int $high_frequency_rumble, int $duration_ms) + * @method GameControllerPtr SDL_GameControllerOpen(int $joystickIndex) + * @method int SDL_GameControllerRumble(GameControllerPtr $gameController, int $lowFrequencyRumble, int $highFrequencyRumble, int $duration) * @method void SDL_GameControllerUpdate() - * @method CData SDL_GetAssertionHandler(CPtrPtr $puserdata) + * @method int SDL_GameControllerTypeForIndex(int $joystickIndex) + * @method int SDL_GameControllerGetType(GameControllerPtr $gameController) + * @method CData SDL_GetAssertionHandler(CPtrPtr $userData) * @method AssertDataPtr SDL_GetAssertionReport() - * @method string SDL_GetAudioDeviceName(int $index, int $iscapture) + * @method string SDL_GetAudioDeviceName(int $index, int $isCapture) * @method int|CIntPtr SDL_GetAudioDeviceStatus(int|CIntPtr $dev) * @method string SDL_GetAudioDriver(int $index) * @method int|CIntPtr SDL_GetAudioStatus() @@ -241,6 +246,7 @@ * @method int SDL_GetTextureAlphaMod(TexturePtr $texture, int $alpha) * @method int SDL_GetTextureBlendMode(TexturePtr $texture, int|CIntPtr $blendMode) * @method int SDL_GetTextureColorMod(TexturePtr $texture, int $r, int $g, int $b) + * @method int SDL_GetTextureScaleMode(TexturePtr $texture, CIntPtr $scaleMode) * @method int SDL_GetThreadID(ThreadPtr $thread) * @method string|CCharPtr SDL_GetThreadName(ThreadPtr $thread) * @method int SDL_GetTicks() @@ -297,6 +303,7 @@ * @method int SDL_HapticUnpause(HapticPtr $haptic) * @method int SDL_HapticUpdateEffect(HapticPtr $haptic, int $effect, HapticEffectPtr $data) * @method int SDL_Has3DNow() + * @method int SDL_HasARMSIMD() * @method int SDL_HasAVX() * @method int SDL_HasAVX2() * @method int SDL_HasAVX512F() @@ -329,7 +336,9 @@ * @method void SDL_JoystickClose(JoystickPtr $joystick) * @method int|CIntPtr SDL_JoystickCurrentPowerLevel(JoystickPtr $joystick) * @method int SDL_JoystickEventState(int $state) - * @method JoystickPtr SDL_JoystickFromInstanceID(int|CIntPtr $joyid) + * @method JoystickPtr SDL_JoystickFromInstanceID(int $joyId) + * @method JoystickPtr SDL_JoystickFromPlayerIndex(int $playerIndex) + * @method void SDL_JoystickSetPlayerIndex(JoystickPtr $joy, int $playerIndex) * @method int SDL_JoystickGetAttached(JoystickPtr $joystick) * @method int SDL_JoystickGetAxis(JoystickPtr $joystick, int $axis) * @method int SDL_JoystickGetAxisInitialState(JoystickPtr $joystick, int $axis, int $state) @@ -375,6 +384,7 @@ * @method int SDL_LockMutex(mutexPtr $mutex) * @method int SDL_LockSurface(SurfacePtr $surface) * @method int SDL_LockTexture(TexturePtr $texture, RectPtr $rect, CPtrPtr $pixels, int $pitch) + * @method int SDL_LockTextureToSurface(TexturePtr $texture, RectPtr $rect, SurfacePtrPtr $surface) * @method void SDL_Log(string $fmt) * @method void SDL_LogCritical(int $category, string $fmt) * @method void SDL_LogDebug(int $category, string $fmt) @@ -533,6 +543,7 @@ * @method int SDL_SetTextureAlphaMod(TexturePtr $texture, float $alpha) * @method int SDL_SetTextureBlendMode(TexturePtr $texture, int|CIntPtr $blendMode) * @method int SDL_SetTextureColorMod(TexturePtr $texture, int $r, int $g, int $b) + * @method int SDL_SetTextureScaleMode(TexturePtr $texture, int $scaleMode) * @method int SDL_SetThreadPriority(int $priority) * @method void SDL_SetWindowBordered(WindowPtr $window, int $bordered) * @method int SDL_SetWindowBrightness(WindowPtr $window, float $brightness) @@ -597,6 +608,9 @@ * @method int SDL_WriteLE32(RWopsPtr $dst, int $value) * @method int SDL_WriteLE64(RWopsPtr $dst, int $value) * @method int SDL_WriteU8(RWopsPtr $dst, int $value) + * @method MetalView SDL_Metal_CreateView(WindowPtr $window) + * @method void SDL_Metal_DestroyView(MetalView $view) + * @method int SDL_GetAndroidSDKVersion() * @formatter:on */ interface SDLNativeApiAutocomplete diff --git a/resources/sdl-types.h b/resources/sdl-types.h index 4dd9760..206cd4d 100644 --- a/resources/sdl-types.h +++ b/resources/sdl-types.h @@ -312,6 +312,7 @@ typedef enum { SDL_BLENDMODE_BLEND = 0x00000001, SDL_BLENDMODE_ADD = 0x00000002, SDL_BLENDMODE_MOD = 0x00000004, + SDL_BLENDMODE_MUL = 0x00000008, SDL_BLENDMODE_INVALID = 0x7FFFFFFF } SDL_BlendMode; @@ -1381,6 +1382,9 @@ typedef struct SDL_TouchFingerEvent { float dx; float dy; float pressure; + #if __sdl_version__ >= 2.0.12 + Uint32 windowID; + #endif } SDL_TouchFingerEvent; typedef struct SDL_MultiGestureEvent { @@ -1763,7 +1767,7 @@ typedef void (* SDL_HintCallback)(void* userdata, const char* name, const char* // ===================================================================================================================== #if __sdl_version__ >= 2.0.1 - #ifdef __WIN32__ + #ifdef __windows__ typedef struct IDirect3DDevice9 IDirect3DDevice9; #endif #endif @@ -1776,7 +1780,7 @@ typedef void (* SDL_HintCallback)(void* userdata, const char* name, const char* // ===================================================================================================================== #if __sdl_version__ >= 2.0.4 - #ifdef __WIN32__ + #ifdef __windows__ typedef void (* SDL_WindowsMessageHook)(void* userdata, void* hWnd, unsigned int message, Uint64 wParam, Sint64 lParam); #endif #endif @@ -1826,3 +1830,30 @@ typedef void (* SDL_HintCallback)(void* userdata, const char* name, const char* SDL_SENSOR_GYRO } SDL_SensorType; #endif + +// ===================================================================================================================== +// SDL >= 2.0.12 +// +// https://discourse.libsdl.org/t/sdl-2-0-12-released/27318 +// ===================================================================================================================== + +#if __sdl_version__ >= 2.0.12 + typedef enum { + SDL_ScaleModeNearest, + SDL_ScaleModeLinear, + SDL_ScaleModeBest + } SDL_ScaleMode; + + typedef enum { + SDL_CONTROLLER_TYPE_UNKNOWN = 0, + SDL_CONTROLLER_TYPE_XBOX360, + SDL_CONTROLLER_TYPE_XBOXONE, + SDL_CONTROLLER_TYPE_PS3, + SDL_CONTROLLER_TYPE_PS4, + SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO + } SDL_GameControllerType; + + #ifdef __osx__ + typedef void *SDL_MetalView; + #endif +#endif diff --git a/resources/sdl.h b/resources/sdl.h index 654868d..b2c9fd2 100644 --- a/resources/sdl.h +++ b/resources/sdl.h @@ -462,7 +462,7 @@ extern void SDL_Quit(void); extern int SDL_GetSystemRAM(void); extern void SDL_GL_GetDrawableSize(SDL_Window* window, int* w, int* h); - #ifdef __WIN32__ + #ifdef __windows__ extern int SDL_Direct3D9GetAdapterIndex(int displayIndex); extern IDirect3DDevice9* SDL_RenderGetD3D9Device(SDL_Renderer* renderer); #endif @@ -491,7 +491,7 @@ extern void SDL_Quit(void); extern void* SDL_AtomicSetPtr(void **a, void* v); extern void* SDL_AtomicGetPtr(void **a); - #ifdef __WIN32__ + #ifdef __windows__ extern int SDL_RegisterApp(char* name, Uint32 style, void* hInst); extern void SDL_UnregisterApp(void); @@ -522,7 +522,7 @@ extern void SDL_Quit(void); extern SDL_GameController* SDL_GameControllerFromInstanceID(SDL_JoystickID joyid); extern int SDL_RenderIsClipEnabled(SDL_Renderer* renderer); - #ifdef __WIN32__ + #ifdef __windows__ extern void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void* userdata); #endif #endif @@ -729,3 +729,36 @@ extern void SDL_Quit(void); extern int SDL_RWclose(SDL_RWops* context); extern void* SDL_LoadFile(const char* file, size_t* datasize); #endif + + +// ===================================================================================================================== +// SDL >= 2.0.12 +// +// https://discourse.libsdl.org/t/sdl-2-0-12-released/27318 +// ===================================================================================================================== + +#if __sdl_version__ >= 2.0.12 + extern int SDL_GetTextureScaleMode(SDL_Texture* texture, SDL_ScaleMode* scaleMode); + extern int SDL_SetTextureScaleMode(SDL_Texture* texture, SDL_ScaleMode scaleMode); + extern int SDL_LockTextureToSurface(SDL_Texture* texture, const SDL_Rect* rect, SDL_Surface** surface); + + extern SDL_GameControllerType SDL_GameControllerTypeForIndex(int joystick_index); + extern SDL_GameControllerType SDL_GameControllerGetType(SDL_GameController *gamecontroller); + + extern SDL_GameController* SDL_GameControllerFromPlayerIndex(int player_index); + extern void SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index); + + extern SDL_Joystick* SDL_JoystickFromPlayerIndex(int player_index); + extern void SDL_JoystickSetPlayerIndex(SDL_Joystick* joystick, int player_index); + + extern int SDL_HasARMSIMD(void); + + #ifdef __osx__ + extern SDL_MetalView SDL_Metal_CreateView(SDL_Window* window); + extern void SDL_Metal_DestroyView(SDL_MetalView view); + #endif + + #ifdef __android__ + extern int SDL_GetAndroidSDKVersion(void); + #endif +#endif diff --git a/resources/structures.php b/resources/structures.php index d0dd532..bbdd4ae 100644 --- a/resources/structures.php +++ b/resources/structures.php @@ -9,15 +9,15 @@ declare(strict_types=1); -namespace SDL; +namespace Serafim\SDL; use FFI\CData; use FFI\CPtr; use FFI\CScalar; use FFI\CStruct; -use SDL\Kernel\Keyboard\Key; -use SDL\Kernel\Keyboard\KeyMode; -use SDL\Kernel\Keyboard\ScanCode; +use Serafim\SDL\Kernel\Keyboard\Key; +use Serafim\SDL\Kernel\Keyboard\KeyMode; +use Serafim\SDL\Kernel\Keyboard\ScanCode; /** * @@ -1722,7 +1722,7 @@ final class WindowsMessageHook extends CData } /** - * @since 2.0.1 + * @since SDL 2.0.1 */ final class IDirect3DDevice9 extends CData { @@ -1770,9 +1770,9 @@ final class Version extends CData } /** - * @since 2.0.6 - * * TODO Finish the description of this structure + * + * @since SDL 2.0.6 * @mixin CStruct */ final class VulkanInstance extends CData @@ -1780,15 +1780,24 @@ final class VulkanInstance extends CData } /** - * @since 2.0.6 - * * TODO Finish the description of this structure + * + * @since SDL 2.0.6 * @mixin CStruct */ final class VulkanSurface extends CData { } +/** + * TODO Finish the description of this structure + * @since SDL 2.0.12 + * @mixin CStruct + */ +final class MetalView extends CData +{ +} + // ============================================================================= // Pointers // ============================================================================= @@ -2114,6 +2123,26 @@ private function offsetSet(int $i, Surface $d): void } } +/** + * @mixin SurfacePtr + * @mixin CPtr + * @mixin CStruct + */ +final class SurfacePtrPtr extends CData +{ + private function __construct() + { + } + + private function offsetGet(int $i): SurfacePtr + { + } + + private function offsetSet(int $i, SurfacePtr $d): void + { + } +} + /** * @mixin DisplayMode * @mixin CPtr diff --git a/src/Exception/LibraryException.php b/src/Exception/LibraryException.php index 545e924..f550ef1 100644 --- a/src/Exception/LibraryException.php +++ b/src/Exception/LibraryException.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Exception; +namespace Serafim\SDL\Exception; /** * Class LibraryException diff --git a/src/Exception/SDLException.php b/src/Exception/SDLException.php index 05dea00..db6bada 100644 --- a/src/Exception/SDLException.php +++ b/src/Exception/SDLException.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Exception; +namespace Serafim\SDL\Exception; /** * Class SDLException diff --git a/src/Exception/VersionException.php b/src/Exception/VersionException.php index 3d7b06b..bbd116e 100644 --- a/src/Exception/VersionException.php +++ b/src/Exception/VersionException.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Exception; +namespace Serafim\SDL\Exception; /** * Class VersionException diff --git a/src/Kernel/Assert/State.php b/src/Kernel/Assert/State.php index d8b8407..2f4e740 100644 --- a/src/Kernel/Assert/State.php +++ b/src/Kernel/Assert/State.php @@ -9,9 +9,9 @@ declare(strict_types=1); -namespace SDL\Kernel\Assert; +namespace Serafim\SDL\Kernel\Assert; -use SDL\NativeApi; +use Serafim\SDL\NativeApi; /** * An enumeration of assertion handling states. diff --git a/src/Kernel/Audio/AllowChangeFlag.php b/src/Kernel/Audio/AllowChangeFlag.php index 846953c..100d998 100644 --- a/src/Kernel/Audio/AllowChangeFlag.php +++ b/src/Kernel/Audio/AllowChangeFlag.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Audio; +namespace Serafim\SDL\Kernel\Audio; /** * Allow change flags diff --git a/src/Kernel/Audio/Format.php b/src/Kernel/Audio/Format.php index 56aeddb..a61caed 100644 --- a/src/Kernel/Audio/Format.php +++ b/src/Kernel/Audio/Format.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Audio; +namespace Serafim\SDL\Kernel\Audio; /** * Audio format flags. @@ -50,7 +50,7 @@ interface Format /** * Unsigned 16-bit samples * - * @since 2.0.5 + * @since SDL 2.0.5 * @var int */ public const AUDIO_U16LSB = 0x0010; @@ -65,7 +65,7 @@ interface Format /** * As above, but big-endian byte order * - * @since 2.0.5 + * @since SDL 2.0.5 * @var int */ public const AUDIO_U16MSB = 0x1010; diff --git a/src/Kernel/Audio/Status.php b/src/Kernel/Audio/Status.php index 658c67e..f1fe4a7 100644 --- a/src/Kernel/Audio/Status.php +++ b/src/Kernel/Audio/Status.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Audio; +namespace Serafim\SDL\Kernel\Audio; /** * Interface AudioStatusInterface diff --git a/src/Kernel/Boolean.php b/src/Kernel/Boolean.php index 610f670..7dec089 100644 --- a/src/Kernel/Boolean.php +++ b/src/Kernel/Boolean.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel; +namespace Serafim\SDL\Kernel; /** * Basic bool data type diff --git a/src/Kernel/Enums.php b/src/Kernel/Enums.php index 09da598..65de529 100644 --- a/src/Kernel/Enums.php +++ b/src/Kernel/Enums.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel; +namespace Serafim\SDL\Kernel; /** * Interface EnumsInterface @@ -31,6 +31,7 @@ interface Enums extends GameController\Axis, GameController\BindType, GameController\Button, + GameController\Type, // Hint Hint\Name, Hint\Priority, @@ -85,6 +86,7 @@ interface Enums extends Video\TextureAccess, Video\TextureModulate, Video\RendererFlip, + Video\ScaleMode, Video\WindowShapeMode { diff --git a/src/Kernel/Event/Action.php b/src/Kernel/Event/Action.php index 6451729..bf18639 100644 --- a/src/Kernel/Event/Action.php +++ b/src/Kernel/Event/Action.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Event; +namespace Serafim\SDL\Kernel\Event; /** * Interface Action diff --git a/src/Kernel/Event/Type.php b/src/Kernel/Event/Type.php index c02f098..ff54f9f 100644 --- a/src/Kernel/Event/Type.php +++ b/src/Kernel/Event/Type.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Event; +namespace Serafim\SDL\Kernel\Event; /** * Interface Type @@ -25,7 +25,7 @@ interface Type public const SDL_APP_WILLENTERFOREGROUND = self::SDL_QUIT + 5; public const SDL_APP_DIDENTERFOREGROUND = self::SDL_QUIT + 6; /** - * @since 2.0.9 + * @since SDL 2.0.9 */ public const SDL_DISPLAYEVENT = 0x150; public const SDL_WINDOWEVENT = 0x200; @@ -67,11 +67,11 @@ interface Type public const SDL_AUDIODEVICEREMOVED = self::SDL_AUDIODEVICEADDED + 1; /** - * @since 2.0.9 + * @since SDL 2.0.9 */ public const SDL_SENSORUPDATE = 0x1200; /** - * @since 2.0.2 + * @since SDL 2.0.2 */ public const SDL_RENDER_TARGETS_RESET = 0x2000; public const SDL_RENDER_DEVICE_RESET = self::SDL_RENDER_TARGETS_RESET + 1; diff --git a/src/Kernel/GameController/Axis.php b/src/Kernel/GameController/Axis.php index 1f91113..b62b8b5 100644 --- a/src/Kernel/GameController/Axis.php +++ b/src/Kernel/GameController/Axis.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\GameController; +namespace Serafim\SDL\Kernel\GameController; /** * Interface Axis diff --git a/src/Kernel/GameController/BindType.php b/src/Kernel/GameController/BindType.php index 2484eb0..e293875 100644 --- a/src/Kernel/GameController/BindType.php +++ b/src/Kernel/GameController/BindType.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\GameController; +namespace Serafim\SDL\Kernel\GameController; /** * Interface GameControllerBindTypeInterface diff --git a/src/Kernel/GameController/Button.php b/src/Kernel/GameController/Button.php index 600575d..4f5ea4b 100644 --- a/src/Kernel/GameController/Button.php +++ b/src/Kernel/GameController/Button.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\GameController; +namespace Serafim\SDL\Kernel\GameController; /** * Interface GameControllerButtonInterface diff --git a/src/Kernel/GameController/Type.php b/src/Kernel/GameController/Type.php new file mode 100644 index 0000000..7278a19 --- /dev/null +++ b/src/Kernel/GameController/Type.php @@ -0,0 +1,48 @@ + + * dstRGBA = srcRGBA + * + * @var int + */ public const SDL_BLENDMODE_NONE = 0x00000000; + + /** + * Alpha blending + * + * dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)) + * dstA = srcA + (dstA * (1-srcA)) + * + * @var int + */ public const SDL_BLENDMODE_BLEND = 0x00000001; + + /** + * Additive blending + * + * dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)) + * dstA = srcA + (dstA * (1-srcA)) + * + * @var int + */ public const SDL_BLENDMODE_ADD = 0x00000002; + + /** + * Color modulate + * + * dstRGB = srcRGB * dstRGB + * dstA = dstA + * + * + * @var int + */ public const SDL_BLENDMODE_MOD = 0x00000004; + + /** + * Color multiply + * + * dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)) + * dstA = (srcA * dstA) + (dstA * (1-srcA)) + * + * @since SDL 2.0.12 + * @var int + */ + public const SDL_BLENDMODE_MUL = 0x00000008; + + /** + * @var int + */ public const SDL_BLENDMODE_INVALID = 0x7FFFFFFF; } diff --git a/src/Kernel/Video/BlendOperation.php b/src/Kernel/Video/BlendOperation.php index b0abe8b..e2a0c6b 100644 --- a/src/Kernel/Video/BlendOperation.php +++ b/src/Kernel/Video/BlendOperation.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface BlendOperationInterface diff --git a/src/Kernel/Video/DisplayEvent.php b/src/Kernel/Video/DisplayEvent.php index a5587e8..ef2374c 100644 --- a/src/Kernel/Video/DisplayEvent.php +++ b/src/Kernel/Video/DisplayEvent.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface DisplayEventInterface diff --git a/src/Kernel/Video/DisplayOrientation.php b/src/Kernel/Video/DisplayOrientation.php index f3eb171..31e3f44 100644 --- a/src/Kernel/Video/DisplayOrientation.php +++ b/src/Kernel/Video/DisplayOrientation.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface DisplayOrientationInterface diff --git a/src/Kernel/Video/HitTestResult.php b/src/Kernel/Video/HitTestResult.php index ee38b88..1dd9917 100644 --- a/src/Kernel/Video/HitTestResult.php +++ b/src/Kernel/Video/HitTestResult.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface HitTestResult diff --git a/src/Kernel/Video/PackedLayout.php b/src/Kernel/Video/PackedLayout.php index c7fbde3..8bb162e 100644 --- a/src/Kernel/Video/PackedLayout.php +++ b/src/Kernel/Video/PackedLayout.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface PackedLayoutInterface diff --git a/src/Kernel/Video/PackedOrder.php b/src/Kernel/Video/PackedOrder.php index 260dc94..af1d601 100644 --- a/src/Kernel/Video/PackedOrder.php +++ b/src/Kernel/Video/PackedOrder.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface PackedOrderInterface diff --git a/src/Kernel/Video/PixelFormat.php b/src/Kernel/Video/PixelFormat.php index f77b67a..0011089 100644 --- a/src/Kernel/Video/PixelFormat.php +++ b/src/Kernel/Video/PixelFormat.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface PixelFormat diff --git a/src/Kernel/Video/PixelType.php b/src/Kernel/Video/PixelType.php index 4f6cdf9..7878994 100644 --- a/src/Kernel/Video/PixelType.php +++ b/src/Kernel/Video/PixelType.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface PixelType diff --git a/src/Kernel/Video/RendererFlags.php b/src/Kernel/Video/RendererFlags.php index 219b508..e2bac7f 100644 --- a/src/Kernel/Video/RendererFlags.php +++ b/src/Kernel/Video/RendererFlags.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface RendererFlags diff --git a/src/Kernel/Video/RendererFlip.php b/src/Kernel/Video/RendererFlip.php index 6a2469e..743270d 100644 --- a/src/Kernel/Video/RendererFlip.php +++ b/src/Kernel/Video/RendererFlip.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface RendererFlipInterface diff --git a/src/Kernel/Video/ScaleMode.php b/src/Kernel/Video/ScaleMode.php new file mode 100644 index 0000000..06c03ab --- /dev/null +++ b/src/Kernel/Video/ScaleMode.php @@ -0,0 +1,58 @@ + + * typedef enum { + * SDL_ScaleModeNearest, + * SDL_ScaleModeLinear, + * SDL_ScaleModeBest + * } SDL_ScaleMode; + * + * @since SDL 2.0.12 + */ +interface ScaleMode +{ + /** + * @var int + * @deprecated Please use SDL_SCALE_MODE_NEAREST instead + */ + public const SDL_ScaleModeNearest = 0; + + /** + * @var int + * @deprecated Please use SDL_SCALE_MODE_LINEAR instead + */ + public const SDL_ScaleModeLinear = 1; + + /** + * @var int + * @deprecated Please use SDL_SCALE_MODE_BEST instead + */ + public const SDL_ScaleModeBest = 2; + + /** + * @var int + */ + public const SDL_SCALE_MODE_NEAREST = 0; + + /** + * @var int + */ + public const SDL_SCALE_MODE_LINEAR = 1; + + /** + * @var int + */ + public const SDL_SCALE_MODE_BEST = 2; +} diff --git a/src/Kernel/Video/TextureAccess.php b/src/Kernel/Video/TextureAccess.php index c90c689..685e766 100644 --- a/src/Kernel/Video/TextureAccess.php +++ b/src/Kernel/Video/TextureAccess.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface TextureAccessInterface diff --git a/src/Kernel/Video/TextureModulate.php b/src/Kernel/Video/TextureModulate.php index ce8e154..3be3ddc 100644 --- a/src/Kernel/Video/TextureModulate.php +++ b/src/Kernel/Video/TextureModulate.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface TextureModulateInterface diff --git a/src/Kernel/Video/WindowEvent.php b/src/Kernel/Video/WindowEvent.php index 8e89b0f..cef1d24 100644 --- a/src/Kernel/Video/WindowEvent.php +++ b/src/Kernel/Video/WindowEvent.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface WindowEventIdInterface @@ -32,12 +32,12 @@ interface WindowEvent public const SDL_WINDOWEVENT_FOCUS_LOST = 13; public const SDL_WINDOWEVENT_CLOSE = 14; /** - * @since 2.0.5 + * @since SDL 2.0.5 */ public const SDL_WINDOWEVENT_TAKE_FOCUS = 15; /** - * @since 2.0.5 + * @since SDL 2.0.5 */ public const SDL_WINDOWEVENT_HIT_TEST = 16; } diff --git a/src/Kernel/Video/WindowFlags.php b/src/Kernel/Video/WindowFlags.php index d91a771..0262b4f 100644 --- a/src/Kernel/Video/WindowFlags.php +++ b/src/Kernel/Video/WindowFlags.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface WindowFlagsInterface diff --git a/src/Kernel/Video/WindowPosition.php b/src/Kernel/Video/WindowPosition.php index e28718d..6c46e69 100644 --- a/src/Kernel/Video/WindowPosition.php +++ b/src/Kernel/Video/WindowPosition.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface WindowPosition diff --git a/src/Kernel/Video/WindowShapeMode.php b/src/Kernel/Video/WindowShapeMode.php index 152feaf..4ff27b6 100644 --- a/src/Kernel/Video/WindowShapeMode.php +++ b/src/Kernel/Video/WindowShapeMode.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface WindowShapeMode diff --git a/src/Kernel/Video/YuvConversionMode.php b/src/Kernel/Video/YuvConversionMode.php index cf6fd96..a7ae262 100644 --- a/src/Kernel/Video/YuvConversionMode.php +++ b/src/Kernel/Video/YuvConversionMode.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Kernel\Video; +namespace Serafim\SDL\Kernel\Video; /** * Interface YuvConversionModeInterface diff --git a/src/Library.php b/src/Library.php index 4ceb98e..bb0e19a 100644 --- a/src/Library.php +++ b/src/Library.php @@ -9,16 +9,16 @@ declare(strict_types=1); -namespace SDL; +namespace Serafim\SDL; -use SDL\Loader\BitDepth; -use SDL\Loader\LibraryInterface; -use SDL\Loader\OperatingSystem; +use Serafim\FFILoader\BitDepth; +use Serafim\FFILoader\Library as BaseLibrary; +use Serafim\FFILoader\OperatingSystem; /** * Class Library */ -class Library implements LibraryInterface +class Library extends BaseLibrary { /** * @var string @@ -75,14 +75,6 @@ public function getHeaders(): string return __DIR__ . '/../resources/sdl.h'; } - /** - * @return string - */ - public function getTypeHeaders(): string - { - return __DIR__ . '/../resources/sdl-types.h'; - } - /** * {@inheritDoc} */ @@ -141,4 +133,12 @@ public function suggest(OperatingSystem $os, BitDepth $bits): ?string return null; } + + /** + * @return string + */ + final public function getOutputDirectory(): string + { + return __DIR__ . '/../out'; + } } diff --git a/src/Loader/BitDepth.php b/src/Loader/BitDepth.php deleted file mode 100644 index 5bde874..0000000 --- a/src/Loader/BitDepth.php +++ /dev/null @@ -1,83 +0,0 @@ -bits = $intSize; - } - - /** - * @return static - */ - public static function current(): self - { - return new static(\PHP_INT_SIZE === 8 ? 64 : 32); - } - - /** - * @return string - */ - public function __toString(): string - { - return 'x' . $this->bits; - } - - /** - * @return int - */ - public function getBitDepth(): int - { - return $this->bits; - } - - /** - * @return bool - */ - public function is64BitDepth(): bool - { - return $this->bits === self::BIT_DEPTH_X64; - } - - /** - * @return bool - */ - public function is32BitDepth(): bool - { - return $this->bits === self::BIT_DEPTH_X86; - } -} diff --git a/src/Loader/LibraryInformation.php b/src/Loader/LibraryInformation.php deleted file mode 100644 index 5922598..0000000 --- a/src/Loader/LibraryInformation.php +++ /dev/null @@ -1,133 +0,0 @@ -ffi = $ffi; - $this->name = $name; - $this->headers = $headers; - $this->version = $version; - $this->lib = $lib; - $this->workingDirectory = \dirname($this->lib); - } - - /** - * @param \Closure $expr - * @return mixed - */ - public function chdir(\Closure $expr) - { - if (\PHP_OS_FAMILY !== 'Windows') { - return $expr(); - } - - if (\ZEND_THREAD_SAFE) { - @\trigger_error(self::WARN_ZTS_CHDIR); - return $this->chdirThreadSafe($expr); - } - - return $this->chdirNonThreadSafe($expr); - } - - /** - * @param \Closure $expr - * @return mixed - */ - private function chdirThreadSafe(\Closure $expr) - { - static $kernel32; - - if ($kernel32 === null) { - $kernel32 = \FFI::cdef(<<<'c' - typedef const char* LPCSTR; - typedef enum { false, true } BOOL; - - extern BOOL SetDllDirectoryA(LPCSTR lpPathName); - c, 'kernel32.dll'); - } - - $kernel32->SetDllDirectoryA($this->workingDirectory); - - return $expr(); - } - - /** - * @param \Closure $expr - * @return mixed - */ - private function chdirNonThreadSafe(\Closure $expr) - { - /** @var string $before */ - $before = \getcwd(); - - try { - \chdir($this->workingDirectory); - - return $expr(); - } finally { - \chdir($before); - } - } -} diff --git a/src/Loader/LibraryInterface.php b/src/Loader/LibraryInterface.php deleted file mode 100644 index 23d9f42..0000000 --- a/src/Loader/LibraryInterface.php +++ /dev/null @@ -1,48 +0,0 @@ -output = $output; - - $this->os = $os ?? OperatingSystem::current(); - $this->bits = $bits ?? BitDepth::current(); - } - - /** - * @param string $define - * @param string $value - * @return void - */ - public function define(string $define, string $value): void - { - $this->defines[$define] = $value; - } - - /** - * @param LibraryInterface $library - * @return LibraryInformation - */ - public function load(LibraryInterface $library): LibraryInformation - { - $from = $this->getRealLibrary($library); - - $version = $library->getVersion($from); - - $headers = $this->getRealHeaders($library, $version); - - try { - $ffi = \FFI::cdef(\file_get_contents($headers), $from); - } catch (ParserException $e) { - \unlink($headers); - - throw new LibraryException($e->getMessage()); - } - - return new LibraryInformation($ffi, $library->getName(), $headers, $version, $from); - } - - /** - * @param LibraryInterface $library - * @return string - */ - private function getRealLibrary(LibraryInterface $library): string - { - $from = $library->getLibrary($this->os, $this->bits); - - if ($from === null) { - throw new LibraryException(\sprintf(self::ERROR_LOCAL_LIBRARY, (string)$this->os, (string)$this->bits)); - } - - return $from; - } - - /** - * @param LibraryInterface $library - * @param string $version - * @return string - */ - private function getRealHeaders(LibraryInterface $library, string $version): string - { - try { - $headers = $this->getOutputPathname($library, $version); - - if (! \is_file($headers)) { - return $this->compile($library, $headers, $version); - } - } catch (Exception $e) { - throw new LibraryException($e->getMessage() . ': ' . $this->suggest($library)); - } - - return $headers; - } - - /** - * @param LibraryInterface $library - * @param string $version - * @return string - */ - private function getOutputPathname(LibraryInterface $library, string $version): string - { - return $this->output . '/' . $this->getOutputName($library, $version); - } - - /** - * @param LibraryInterface $library - * @param string $version - * @return string - */ - private function getOutputName(LibraryInterface $library, string $version): string - { - return \strtolower(\vsprintf(self::FILE_NAME_FORMAT, [ - $this->getNormalizedName($library), - $version, - $this->os->getFamily(), - $this->bits->getBitDepth(), - ])); - } - - /** - * @param LibraryInterface $library - * @return string - */ - private function getNormalizedName(LibraryInterface $library): string - { - return \str_replace(' ', '-', \strtolower($library->getName())); - } - - /** - * @param LibraryInterface $library - * @param string $output - * @param string $version - * @return string - */ - protected function compile(LibraryInterface $library, string $output, string $version): string - { - $result = $this->preprocessor($library, $version) - ->file($library->getHeaders()); - - \file_put_contents($output, $result); - - return $output; - } - - /** - * @param LibraryInterface $library - * @return string - */ - private function suggest(LibraryInterface $library): string - { - $suggest = $library->suggest($this->os, $this->bits); - - return $suggest ?? \sprintf(self::ERROR_SUGGEST, (string)$this->os, (string)$this->bits); - } - - /** - * @param LibraryInterface $library - * @param string $version - * @return PreProcessor - */ - protected function preprocessor(LibraryInterface $library, string $version): PreProcessor - { - $processor = new PreProcessor(); - $processor->define('__' . \strtolower(\str_replace(' ', '_', $library->getName())) . '__', $version); - - foreach ($this->defines as $define => $value) { - $processor->define($define, $value); - } - - return $processor; - } -} diff --git a/src/Loader/OperatingSystem.php b/src/Loader/OperatingSystem.php deleted file mode 100644 index dade4d9..0000000 --- a/src/Loader/OperatingSystem.php +++ /dev/null @@ -1,144 +0,0 @@ -family = $family; - } - - /** - * @return OperatingSystem - */ - public static function current(): OperatingSystem - { - return new static(\PHP_OS_FAMILY); - } - - /** - * @return string - */ - public function __toString(): string - { - return $this->getFamily(); - } - - /** - * @return string - */ - public function getFamily(): string - { - return $this->family; - } - - /** - * @return bool - */ - public function isWindows(): bool - { - return $this->getFamily() === self::OS_WINDOWS; - } - - /** - * @return bool - */ - public function isMac(): bool - { - return $this->getFamily() === self::OS_MAC; - } - - /** - * @return bool - */ - public function isUnix(): bool - { - return $this->getFamily() === self::OS_UNIX; - } - - /** - * @return bool - */ - public function isLinux(): bool - { - return $this->getFamily() === self::OS_LINUX; - } - - /** - * @return bool - */ - public function isSolaris(): bool - { - return $this->getFamily() === self::OS_SOLARIS; - } - - /** - * @return bool - */ - public function isKnown(): bool - { - return ! $this->isUnknown(); - } - - /** - * @return bool - */ - public function isUnknown(): bool - { - return $this->getFamily() === self::OS_UNKNOWN; - } -} - diff --git a/src/Loader/PreProcessor.php b/src/Loader/PreProcessor.php deleted file mode 100644 index 1b57293..0000000 --- a/src/Loader/PreProcessor.php +++ /dev/null @@ -1,348 +0,0 @@ -=]+)\\h*((?:\\\\s|[^\\n])+))(*MARK:T_IF))|' . - '(?:(?:[^\\n]+)(*MARK:T_SOURCE))|(?:(?:\\n+)(*MARK:T_NEW_LINE)))/Ssum'; - - /** - * @var array|string[] - */ - private array $defines = []; - - /** - * @var array|string[] - */ - private array $includes = []; - - /** - * PreProcessor constructor. - */ - public function __construct() - { - $this->bootDefaultDefines(); - $this->bootDefaultIncludeDirectory(); - } - - /** - * @return void - */ - private function bootDefaultIncludeDirectory(): void - { - $this->includes[] = __DIR__ . '/../../resources'; - } - - /** - * @param string $dir - * @return void - */ - public function addIncludeDirectory(string $dir): void - { - $this->includes[] = $dir; - } - - /** - * @param string $define - * @param string $value - * @return void - */ - private function defineWrapped(string $define, string $value): void - { - $this->define('_' . $define, $value); - $this->define('__' . $define, $value); - $this->define('__' . $define . '__', $value); - } - - /** - * @return void - */ - private function bootDefaultDefines(): void - { - $define = function (string ...$defines): void { - foreach ($defines as $def) { - $this->defineWrapped($def, '1'); - } - }; - - $define(\PHP_INT_SIZE === 8 ? 'amd64' : 'i386'); - - switch (\PHP_OS_FAMILY) { - case 'Windows': - $define('cygwin', 'mingw32', 'windows', 'win'); - $define(\PHP_INT_SIZE === 8 ? 'win64' : 'win32'); - break; - - case 'Linux': - $define('linux'); - break; - - case 'Darwin': - $define('osx', 'apple', 'macosx'); - break; - - case 'BSD': - $define('freebsd', 'freebsd_kernel', 'dragonfly', 'bsdi', 'openbsd'); - break; - - case 'Solaris': - $define('sun', 'svr4', 'solaris'); - break; - } - } - - /** - * @param string $define - * @param string $value - * @return void - */ - public function define(string $define, string $value): void - { - $this->defines[$define] = $value; - } - - /** - * @param string $define - * @return void - */ - public function undef(string $define): void - { - unset($this->defines[$define]); - } - - /** - * @param string $pathname - * @return string - * @throws \RuntimeException - */ - public function file(string $pathname): string - { - $source = @\file_get_contents($pathname = \trim($pathname)); - - if (! \is_string($source)) { - $last = \error_get_last(); - - throw new \RuntimeException('Error while reading file ' . $pathname . ': ' . $last['message']); - } - - return $this->source($source, \dirname($pathname)); - } - - /** - * @param string $source - * @param string|null $cwd - * @return string - * @throws \RuntimeException - */ - public function source(string $source, string $cwd = null): string - { - $result = ''; - - foreach ($this->execute($source, $cwd) as $value) { - $result .= $value; - } - - return $result; - } - - /** - * @param string $file - * @param string|null $cwd - * @return string - */ - private function lookup(string $file, string $cwd = null): string - { - if (\is_string($cwd) && \is_file($cwd . '/' . $file)) { - return $cwd . '/' . $file; - } - - foreach ($this->includes as $dir) { - if (\is_file($dir . '/' . $file)) { - return $dir . '/' . $file; - } - } - - return './' . $file; - } - - /** - * @param string $source - * @param string|null $dir - * @return \Traversable|string[] - */ - private function execute(string $source, string $dir = null): \Traversable - { - $assertions = []; - - $lexemes = $this->lex(\str_replace("\r", '', $source)); - - foreach ($lexemes as $name => $value) { - $prefix = \count($assertions) . ':'; - - switch ($name) { - case 'T_INCLUDE': - $file = \stripslashes(\trim(\trim($value[1]), '"<>')); - - yield $this->file($this->lookup($file, $dir)); - break; - - case 'T_IFNDEF': - $assertions[$prefix . $value[1]] = ! $this->assertIfDef($value[1]); - continue 2; - - case 'T_IFDEF': - $assertions[$prefix . $value[1]] = $this->assertIfDef($value[1]); - continue 2; - - case 'T_IF': - $assertions[$prefix . $value[0]] = $this->assertIf( - $this->preprocess($value[1]), - $this->preprocess($value[3]), - $value[2] - ); - continue 2; - - case 'T_ENDIF': - if (\count($assertions)) { - \array_pop($assertions); - continue 2; - } - break; - } - - if ($this->matchAllAssertions($assertions)) { - yield $this->preprocess($value[0]); - } - } - } - - /** - * @param string $sources - * @return iterable|array[] - */ - private function lex(string $sources): iterable - { - \preg_match_all(self::PCRE_PATTERN, $sources, $matches, \PREG_SET_ORDER); - - foreach ($matches as $match) { - yield $match['MARK'] => $match; - } - } - - /** - * @param string $source - * @return string - */ - private function preprocess(string $source): string - { - foreach ($this->defines as $from => $to) { - $pattern = \sprintf('/\b%s\b/sum', \preg_quote($from, '/')); - - $source = \preg_replace($pattern, $to, $source); - } - - return $source; - } - - /** - * @param string $def - * @return bool - */ - private function assertIfDef(string $def): bool - { - return isset($this->defines[$def]); - } - - /** - * @param string $a - * @param string $b - * @param string $operator - * @return bool - */ - private function assertIf(string $a, string $b, string $operator): bool - { - if (\preg_match(self::PATTERN_VER, $a) && \preg_match(self::PATTERN_VER, $b)) { - return $this->compare(\version_compare($a, $b), $operator); - } - - return $this->compare($a <=> $b, $operator); - } - - /** - * @param int $result - * @param string $operator - * @return bool - */ - private function compare(int $result, string $operator): bool - { - switch ($operator) { - case '>': - return $result > 0; - - case '<': - return $result < 0; - - case '>=': - return $result >= 0; - - case '<=': - return $result <= 0; - - case '=': - case '==': - case '===': - return $result === 0; - - case '<>': - case '!=': - case '!==': - return $result !== 0; - - default: - throw new \LogicException('Unsupported operator: ' . $operator); - } - } - - /** - * @param array $assertions - * @return bool - */ - private function matchAllAssertions(array $assertions): bool - { - foreach ($assertions as $assertion) { - if (! $assertion) { - return false; - } - } - - return true; - } -} diff --git a/src/SDL.php b/src/SDL.php index 120e550..6ce1d18 100644 --- a/src/SDL.php +++ b/src/SDL.php @@ -11,31 +11,26 @@ declare(strict_types=1); -namespace SDL; +namespace Serafim\SDL; -use FFI\CCharPtr; use FFI\CData; -use FFI\CFloat; -use FFI\CInt; use FFI\CPtr; -use SDL\Exception\SDLException; -use SDL\Exception\VersionException; -use SDL\Kernel\Enums; -use SDL\Kernel\OpenGL\GLAttr; -use SDL\Kernel\OpenGL\GLSwapInterval; -use SDL\Kernel\RWops\SeekWhence; -use SDL\Loader\LibraryInformation; -use SDL\Loader\LibraryLoader; -use SDL\Support\ProxyTrait; -use SDL\Support\SingletonTrait; -use SDL\Support\VersionComparisonTrait; +use FFI\CType; +use FFI\ParserException; +use Serafim\FFILoader\LibraryInformation; +use Serafim\FFILoader\LibraryInterface; +use Serafim\FFILoader\Loader; +use Serafim\FFILoader\Preprocessor; +use Serafim\SDL\Exception\SDLException; +use Serafim\SDL\Kernel\Enums; +use Serafim\SDL\Support\SingletonTrait; +use Serafim\SDL\Support\VersionComparisonTrait; /** - * Class SDL + * @mixin SDLNativeApiAutocomplete */ -class SDL implements Enums +final class SDL implements Enums { - use ProxyTrait; use SingletonTrait; use VersionComparisonTrait; @@ -47,7 +42,12 @@ class SDL implements Enums /** * @var \FFI|SDLNativeApiAutocomplete */ - protected \FFI $ffi; + private \FFI $ffi; + + /** + * @var Loader + */ + private Loader $loader; /** * SDL constructor. @@ -57,817 +57,161 @@ class SDL implements Enums */ public function __construct() { - $loader = new LibraryLoader(__DIR__ . '/../out/'); + $this->loader = $this->loader(); - $this->info = $loader->load(new Library()); + $this->info = $this->loadLibrary(new Library()); $this->ffi = $this->info->ffi; self::setInstance($this); } /** - * Use this function to get the version of SDL that is linked against your program. - * - * - * extern void SDL_GetVersion(SDL_Version* ver); - * - * - * @return Version - */ - public function getVersion(): CData - { - $version = $this->ffi->new('SDL_Version'); - - /** @var VersionPtr $ptr */ - $ptr = self::addr($version); - - $this->ffi->SDL_GetVersion($ptr); - - return $version; - } - - /** - * Use this function to prepare a read-only memory buffer for use with RWops. - * - * - * SDL_RWops* SDL_RWFromConstMem(const void* mem, int size); - * - * - * @see https://wiki.libsdl.org/SDL_RWFromConstMem - * @param CData|CPtr $memory - * @param int $size - * @return CData|RWopsPtr - * @throws SDLException - */ - public function rwFromConstMem(CData $memory, int $size): CData - { - if (($result = $this->ffi->SDL_RWFromConstMem($memory, $size)) === null) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; - } - - /** - * Creates an @see RWops::class structure from a standard I/O file pointer (stdio.h's FILE*). - * - * - * SDL_RWops* SDL_RWFromFP(void* fp, int autoclose); - * - * - * @see https://wiki.libsdl.org/SDL_RWFromFP - * @param CData|CPtr $file - * @param bool $autoClose - * @return CData|RWopsPtr - * @throws SDLException - */ - public function rwFromFilePointer(CData $file, bool $autoClose = true): CData - { - $close = $autoClose ? self::SDL_TRUE : self::SDL_FALSE; - - if (($result = $this->ffi->SDL_RWFromFP($file, $close)) === null) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; - } - - /** - * Creates an @see RWops::class structure from SplFileInfo object. - * - * @see SDL::rwFromFile() - * @param \SplFileInfo $file - * @param string $mode - * @return CData|RWopsPtr - * @throws SDLException - */ - public function rwFromSplFile(\SplFileInfo $file, string $mode = 'rb'): CData - { - return $this->rwFromFile($file->getPathname(), $mode); - } - - /** - * Use this function to create a new SDL_RWops structure for reading - * from and/or writing to a named file. - * - * - * SDL_RWops* SDL_RWFromFile(const char* file, const char* mode); - * - * - * @see https://wiki.libsdl.org/SDL_RWFromFile - * @param string|CCharPtr $file A UTF-8 string representing the filename to open. - * @param string|CCharPtr $mode An ASCII string representing the mode to be used for opening the file. See - * https://wiki.libsdl.org/SDL_RWFromFile#Remarks for details. - * @return CData|RWopsPtr - * @throws SDLException - */ - public function rwFromFile(string $file, string $mode = 'rb'): CData - { - if (($result = $this->ffi->SDL_RWFromFile($file, $mode)) === null) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; - } - - /** - * Use this function to prepare a read-write memory buffer for use - * with SDL_RWops. - * - * - * SDL_RWops* SDL_RWFromMem(void* mem, int size); - * - * - * @see https://wiki.libsdl.org/SDL_RWFromMem - * @param CData|CPtr $memory A pointer to a buffer to feed an SDL_RWops stream. - * @param int $size The buffer size, in bytes. - * @return CData|RWopsPtr - * @throws SDLException - */ - public function rwFromMemory(CData $memory, int $size): CData - { - if (($result = $this->ffi->SDL_RWFromMem($memory, $size)) === null) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; - } - - /** - * Use this function to close and free an allocated SDL_RWops structure. - * - * - * int SDL_RWclose(SDL_RWops* context); - * - * - * @see https://wiki.libsdl.org/SDL_RWclose - * @since 2.0.10 - * @param CData|RWopsPtr $context SDL_RWops structure to close. - * @throws SDLException - * @throws VersionException + * @return Loader */ - public function rwClose(CData $context): void + private function loader(): Loader { - $this->assertVersion('2.0.10'); + $loader = new Loader(); - if ($this->ffi->SDL_RWclose($context) !== 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - } + $pre = $loader->preprocessor(); + $pre->keepComments = false; + $pre->minify = true; + $pre->tolerant = false; - /** - * Use this function to read from a data source. - * - * - * size_t SDL_RWread(SDL_RWops* context, void* ptr, size_t size, size_t maxnum); - * - * - * @see https://wiki.libsdl.org/SDL_RWread - * @since 2.0.10 - * @param CData|RWopsPtr $context A pointer to an SDL_RWops structure. - * @param CData|CPtr $ptr A pointer to a buffer to read data into. - * @param int $size The size of each object to read, in bytes. - * @param int $maxNum The maximum number of objects to be read. - * @return void - * @throws SDLException - * @throws VersionException - */ - public function rwRead(CData $context, CData $ptr, int $size, int $maxNum): void - { - $this->assertVersion('2.0.10'); + $pre->includeFrom(__DIR__ . '/../resources'); - if ($this->ffi->SDL_RWRead($context, $ptr, $size, $maxNum) === 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } + return $loader; } /** - * Use this function to seek within an SDL_RWops data stream. - * - * - * Sint64 SDL_RWseek(SDL_RWops* context, Sint64 offset, int whence); - * - * - * @see https://wiki.libsdl.org/SDL_RWseek - * @since 2.0.10 - * @param CData|RWopsPtr $context A pointer to an SDL_RWops structure. - * @param int $offset An offset in bytes, relative to whence location; can be negative. - * @param int $whence Any of RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END; @see SeekWhence for details. - * @return int - * @throws SDLException - * @throws VersionException + * @param LibraryInterface $library + * @return LibraryInformation */ - public function rwSeek(CData $context, int $offset = 0, int $whence = SeekWhence::RW_SEEK_SET): int + public function loadLibrary(LibraryInterface $library): LibraryInformation { - $this->assertVersion('2.0.10'); - - if (($result = $this->ffi->SDL_RWseek($context, $offset, $whence)) <= -1) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; + return $this->loader->load($library); } /** - * Use this macro to get the size of the data stream in an SDL_RWops. - * - * - * Sint64 SDL_RWsize(SDL_RWops* context); - * - * - * @see https://wiki.libsdl.org/SDL_RWsize - * @since 2.0.10 - * @param CData|RWopsPtr $context A pointer to an SDL_RWops structure. - * @return int - * @throws SDLException - * @throws VersionException + * {@inheritDoc} */ - public function rwSize(CData $context): int + public function __call(string $name, array $arguments) { - $this->assertVersion('2.0.10'); - - if (($result = $this->ffi->SDL_RWsize($context)) <= -1) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; + return $this->info->ffi->$name(...$arguments); } /** - * Use this function to determine the current read/write offset in an - * SDL_RWops data stream. + * For PHPStorm autocomplete support * - * - * Sint64 SDL_RWtell(SDL_RWops* context); - * - * - * @see https://wiki.libsdl.org/SDL_RWtell - * @since 2.0.10 - * @param CData|RWopsPtr $context A pointer to an SDL_RWops structure. - * @return int - * @throws SDLException - * @throws VersionException + * @param CData|CPtr $type + * @return CPtr|CData|mixed */ - public function rwTell(CData $context): int + public static function addr(CData $type): CData { - $this->assertVersion('2.0.10'); - - if (($result = $this->ffi->SDL_RWtell($context)) <= -1) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; + return \FFI::addr($type); } /** - * Use this function to write to an SDL_RWops data stream. - * - * - * size_t SDL_RWwrite(SDL_RWops* context, const void* ptr, size_t size, size_t num); - * - * - * @see https://wiki.libsdl.org/SDL_RWwrite - * @since 2.0.10 - * @param CData|RWopsPtr $context A pointer to an SDL_RWops structure - * @param CData|Cptr $ptr A pointer to a buffer containing data to write - * @param int $size The size of an object to write, in bytes - * @param int $num The number of objects to write - * @return int - * @throws SDLException - * @throws VersionException + * @param string $type + * @param bool $owned + * @param bool $persistent + * @return CData */ - public function rwWrite(CData $context, CData $ptr, int $size, int $num): int + public function new(string $type, bool $owned = true, bool $persistent = false): CData { - $this->assertVersion('2.0.10'); + try { + /** @noinspection StaticInvocationViaThisInspection */ + return $this->info->ffi->new($this->nameToInternal($type), $owned, $persistent); + } catch (ParserException $e) { + $error = \sprintf('Structure "%s" not found. %s', $type, \ucfirst($e->getMessage())); - if (($result = $this->ffi->SDL_RWwrite($context, $ptr, $size, $num)) < $num) { - throw new SDLException($this->ffi->SDL_GetError()); + throw new SDLException($error); } - - return $result; } /** - * Use this function to allocate an empty, unpopulated @see RWops::class structure. - * - * - * SDL_RWops* SDL_AllocRW(void) - * - * - * @return RWopsPtr + * @param string $type + * @return string */ - public function allocRw(): CData + protected function nameToInternal(string $type): string { - if (($result = $this->ffi->SDL_AllocRW()) === null) { - throw new SDLException($this->ffi->SDL_GetError()); - } + $ptr = 0; - return $result; - } + $type = \str_replace(__NAMESPACE__, 'SDL', $type); - /** - * Bind the texture to the current OpenGL/ES/ES2 context for use with OpenGL instructions. - * - * - * int SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh); - * - * - * @see https://wiki.libsdl.org/SDL_GL_BindTexture - * @param CData|TexturePtr $texture The SDL texture to bind - * @return array|float[] - * @throws SDLException - */ - public function glBindTexture(CData $texture): array - { - /** - * @var CFloat $width - * @var CFloat $height - */ - [$width, $height] = [$this->ffi->new('float'), $this->ffi->new('float')]; - - if ($this->ffi->SDL_GL_BindTexture($texture, self::addr($width), self::addr($height)) < 0) { - throw new SDLException($this->ffi->SDL_GetError()); + while (\substr($type, -3) === 'Ptr') { + $type = \substr($type, 0, -3); + $ptr++; } - return [$width->cdata, $height->cdata]; + return \str_replace('\\', '_', $type) . \str_repeat('*', $ptr); } /** - * Create an OpenGL context for use with an OpenGL window, and make it current. - * - * - * SDL_GLContext SDL_GL_CreateContext(SDL_Window *window); - * - * - * @see https://wiki.libsdl.org/SDL_GL_CreateContext - * @see SDL::glDeleteContext() - * @param CData|WindowPtr $window - * @return GLContext - * @throws SDLException + * @param string|CType $type + * @param CData $ptr + * @return CData */ - public function glCreateContext(CData $window): CData + public function cast($type, CData $ptr): CData { - if (($result = $this->ffi->SDL_GL_CreateContext($window)) === null) { - throw new SDLException($this->ffi->SDL_GetError()); + if (\is_string($type)) { + $type = $this->nameToInternal($type); } - return $result; - } - - /** - * Delete an OpenGL context. - * - * - * void SDL_GL_DeleteContext(SDL_GLContext context); - * - * - * @see https://wiki.libsdl.org/SDL_GL_DeleteContext - * @param CData|GLContext $context - * @return void - */ - public function glDeleteContext(CData $context): void - { - $this->ffi->SDL_GL_DeleteContext($context); - } - - /** - * Use this function to check if an OpenGL extension is supported for the current context. - * - * - * int SDL_GL_ExtensionSupported(const char *extension); - * - * - * @see https://wiki.libsdl.org/SDL_GL_ExtensionSupported - * @param string $extension The name of the extension to check - * @return bool - * @throws SDLException - */ - public function glExtensionSupported(string $extension): bool - { - $result = $this->ffi->SDL_GL_ExtensionSupported($extension) > 0; + try { + /** @noinspection StaticInvocationViaThisInspection */ + return $this->info->ffi->cast($type, $ptr); + } catch (ParserException $e) { + $error = \sprintf('Structure "%s" not found. %s', $type, \ucfirst($e->getMessage())); - if ($error = $this->ffi->SDL_GetError()) { throw new SDLException($error); } - - return $result; } /** - * Get the actual value for an attribute from the current context. - * - * - * int SDL_GL_GetAttribute(SDL_GLattr attr, int *value); - * - * - * @see https://wiki.libsdl.org/SDL_GL_GetAttribute - * @param int|GLAttr $attr The GLAttr enum value - * @psalm-param GLAttr::* $attr - * @return int - * @throws SDLException + * @param string|CType $type + * @return CType */ - public function glGetAttribute(int $attr): int + public function type($type): CType { - /** @var CInt $value */ - $value = $this->ffi->new('int'); - - if ($this->ffi->SDL_GL_GetAttribute($attr, self::addr($value)) < 0) { - throw new SDLException($this->ffi->SDL_GetError()); + if (\is_string($type)) { + $type = $this->nameToInternal($type); } - return $value->cdata; - } - - /** - * Returns the currently active OpenGL context or null if the context does not exist. - * - * - * SDL_GLContext SDL_GL_GetCurrentContext(void); - * - * - * @see https://wiki.libsdl.org/SDL_GL_GetCurrentContext - * @return GLContext|null - * @throws SDLException - */ - public function glGetCurrentContext(): ?CData - { try { - return $this->ffi->SDL_GL_GetCurrentContext(); - } finally { - if ($error = $this->ffi->SDL_GetError()) { - throw new SDLException($error); - } - } - } + /** @noinspection StaticInvocationViaThisInspection */ + return $this->ffi->type($type); + } catch (ParserException $e) { + $error = \sprintf('Structure "%s" not found. %s', $type, \ucfirst($e->getMessage())); - /** - * Returns the currently active OpenGL window or null if the window does not exist. - * - * - * SDL_Window* SDL_GL_GetCurrentWindow(void); - * - * - * @see https://wiki.libsdl.org/SDL_GL_GetCurrentWindow - * @return CData|WindowPtr|null - * @throws SDLException - */ - public function glGetCurrentWindow(): ?CData - { - try { - return $this->ffi->SDL_GL_GetCurrentWindow(); - } finally { - if ($error = $this->ffi->SDL_GetError()) { - throw new SDLException($error); - } - } - } - - /** - * Use this function to get the size of a window's underlying drawable - * in pixels (for use with glViewport). - * - * - * void SDL_GL_GetDrawableSize(SDL_Window* window, int* w, int* h); - * - * - * @see https://wiki.libsdl.org/SDL_GL_GetDrawableSize - * @param CData|WindowPtr $window The window from which the drawable size should be queried. - * @return array|int[] - * @throws VersionException - * @since 2.0.1 - */ - public function glGetDrawableSize(CData $window): array - { - $this->assertVersion('2.0.1'); - - /** - * @var CInt $width - * @var CInt $height - */ - [$width, $height] = [$this->ffi->new('int'), $this->ffi->new('int')]; - - $this->ffi->SDL_GL_GetDrawableSize($window, self::addr($width), self::addr($height)); - - return [$width->cdata, $height->cdata]; - } - - /** - * Returns a pointer to the named OpenGL function. - * The returned pointer should be cast to the appropriate function signature. - * - * - * void* SDL_GL_GetProcAddress(const char* proc); - * - * - * @see https://wiki.libsdl.org/SDL_GL_GetProcAddress - * @param string $proc The name of an OpenGL function - * @return CPtr - */ - public function glGetProcAddress(string $proc): CData - { - return $this->ffi->SDL_GL_GetProcAddress($proc); - } - - /** - * Use this function to get the swap interval for the current OpenGL context. - * - * - * int SDL_GL_GetSwapInterval(void); - * - * - * @see https://wiki.libsdl.org/SDL_GL_GetSwapInterval - * @return int|GLSwapInterval - * @psalm-return GLSwapInterval::* - * @throws SDLException - */ - public function glGetSwapInterval(): int - { - try { - return $this->ffi->SDL_GL_GetSwapInterval(); - } finally { - if ($error = $this->ffi->SDL_GetError()) { - throw new SDLException($error); - } - } - } - - /** - * Use this function to dynamically load an OpenGL library. - * - * - * int SDL_GL_LoadLibrary(const char* path) - * - * - * @see https://wiki.libsdl.org/SDL_GL_LoadLibrary - * @param string $path The platform dependent OpenGL library name, or NULL to open the default OpenGL library - * @return void - * @throws SDLException - */ - public function glLoadLibrary(?string $path = null): void - { - if ($this->ffi->SDL_GL_LoadLibrary($path) !== 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - } - - /** - * Use this function to set up an OpenGL context for rendering into an OpenGL window. - * - * - * int SDL_GL_MakeCurrent(SDL_Window* window, SDL_GLContext context); - * - * - * @see https://wiki.libsdl.org/SDL_GL_MakeCurrent - * @param CData|WindowPtr $window The window to associate with the context - * @param CData|GLContext $context The OpenGL context to associate with the window - * @return void - * @throws SDLException - */ - public function glMakeCurrent(CData $window, CData $context): void - { - if ($this->ffi->SDL_GL_MakeCurrent($window, $context) !== 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - } - - /** - * Use this function to reset all previously set OpenGL context attributes to their default values. - * - * - * void SDL_GL_ResetAttributes(void); - * - * - * @see https://wiki.libsdl.org/SDL_GL_ResetAttributes - * @since 2.0.2 - * @return void - * @throws VersionException - */ - public function glResetAttributes(): void - { - $this->assertVersion('2.0.2'); - - $this->ffi->SDL_GL_ResetAttributes(); - } - - /** - * Use this function to set an OpenGL window attribute before window creation. - * - * - * int SDL_GL_SetAttribute(SDL_GLattr attr, int value); - * - * - * @see https://wiki.libsdl.org/SDL_GL_SetAttribute - * @param int|GLAttr $attr The OpenGL attribute to set. - * @psalm-param GLAttr::* $attr - * @param int $value The desired value for the attribute. - * @return void - * @throws SDLException - */ - public function glSetAttribute(int $attr, int $value): void - { - if ($this->ffi->SDL_GL_SetAttribute($attr, $value) < 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - } - - /** - * Use this function to set the swap interval for the current OpenGL context. - * - * - * int SDL_GL_SetSwapInterval(int interval); - * - * - * @see https://wiki.libsdl.org/SDL_GL_SetSwapInterval - * @param int|GLSwapInterval $interval 0 for immediate updates, 1 for updates synchronized with the vertical - * retrace, -1 for adaptive vsync - * @psalm-param GLSwapInterval::* $interval - * @return void - * @throws SDLException - */ - public function glSetSwapInterval(int $interval): void - { - if ($this->ffi->SDL_GL_SetSwapInterval($interval) < 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - } - - /** - * Use this function to update a window with OpenGL rendering. - * - * - * void SDL_GL_SwapWindow(SDL_Window* window); - * - * - * @see https://wiki.libsdl.org/SDL_GL_SwapWindow - * @param CData|WindowPtr $window - * @return void - */ - public function glSwapWindow(CData $window): void - { - $this->ffi->SDL_GL_SwapWindow($window); - } - - /** - * Use this function to unbind an OpenGL/ES/ES2 texture from the current context. - * - * - * int SDL_GL_UnbindTexture(SDL_Texture* texture); - * - * - * @see https://wiki.libsdl.org/SDL_GL_UnbindTexture - * @param CData|TexturePtr $texture The texture to unbind from the current OpenGL/ES/ES2 context - * @return void - * @throws SDLException - */ - public function glUnbindTexture(CData $texture): void - { - if ($this->ffi->SDL_GL_UnbindTexture($texture) < 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - } - - /** - * Use this function to unload the OpenGL library previously loaded by @see SDL::glLoadLibrary() - * - * - * void SDL_GL_UnloadLibrary(void) - * - * - * @see https://wiki.libsdl.org/SDL_GL_UnloadLibrary - * @return void - */ - public function glUnloadLibrary(): void - { - $this->ffi->SDL_GL_UnloadLibrary(); - } - - /** - * Use this function to load a BMP image from a seekable SDL data stream (memory or file). - * - * - * SDL_Surface* SDL_LoadBMP_RW(SDL_RWops* src, int freesrc); - * - * - * @see https://wiki.libsdl.org/SDL_LoadBMP_RW - * @param CData|RWopsPtr $src The data stream for the surface - * @param bool $autoClose The bool true value to close the stream after being read. - * @return SurfacePtr - * @throws SDLException - */ - public function loadBmpRw(CData $src, bool $autoClose = true): CData - { - if (($result = $this->ffi->SDL_LoadBMP_RW($src, (int)$autoClose)) === null) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; - } - - /** - * - * int SDL_SaveBMP_RW(SDL_Surface* surface, SDL_RWops* dst, int freedst); - * - * - * @see https://wiki.libsdl.org/SDL_SaveBMP_RW - * @param CData|SurfacePtr $surface The @see Surface::class structure containing the image to be saved. - * @param CData|RWopsPtr $dest A data stream to save to. - * @param bool $autoClose The bool true value to close the stream after being written. - * @return void - * @throws SDLException - */ - public function saveBmpRw(CData $surface, CData $dest, bool $autoClose = true): void - { - if ($this->ffi->SDL_SaveBMP_RW($surface, $dest, (int)$autoClose) < 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - } - - /** - * Use this function to create an identifier that is globally visible to all - * threads but refers to data that is thread-specific. - * - * - * unsigned int SDL_TLSCreate(void); - * - * - * @see https://wiki.libsdl.org/SDL_TLSCreate - * @return int - */ - public function tlsCreate(): int - { - if (($result = $this->ffi->SDL_TLSCreate()) === 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } - - return $result; - } - - /** - * Use this function to get the value associated with a thread local storage ID for the current thread. - * - * - * void* SDL_TLSGet(unsigned int id); - * - * - * @param int $id The thread local storage ID - * @return CPtr - */ - public function tlsGet(int $id): CData - { - if (($result = $this->ffi->SDL_TLSGet($id)) === null) { - throw new SDLException($this->ffi->SDL_GetError()); + throw new SDLException($error); } - - return $result; } /** - * Use this function to set the value associated with a thread local storage ID for the current thread. - * - * - * int SDL_TLSSet(unsigned int id, const void* value, void ( *destructor)(void *)); - * - * - * @see https://wiki.libsdl.org/SDL_TLSSet - * @param int $id The thread local storage ID - * @param CData|CPtr $value The value to associate with the ID for the current thread - * @param \Closure $destructor A function called when the thread exits, to free the value - * @return void + * {@inheritDoc} */ - public function tlsSet(int $id, CData $value, \Closure $destructor): void + public static function __callStatic(string $name, array $arguments) { - if ($this->ffi->SDL_TLSSet($id, $value, $destructor) !== 0) { - throw new SDLException($this->ffi->SDL_GetError()); - } + return \FFI::$name(...$arguments); } /** - * Use this function to get the size of a window's client area. - * - * - * - * - * @param WindowPtr|CData $window - * @return array|int[] + * @param string $name + * @return mixed */ - public function getWindowSize(CData $window): array + public function __get(string $name) { - /** - * @var CInt $width - * @var CInt $height - */ - [$width, $height] = [$this->ffi->new('int'), $this->ffi->new('int')]; - - $this->ffi->SDL_GetWindowSize($window, self::addr($width), self::addr($height)); - - return [$width->cdata, $height->cdata]; + return $this->ffi->$name; } /** - * @return LibraryInformation + * @param string $name + * @param mixed $value + * @return mixed + * @noinspection MagicMethodsValidityInspection */ - protected function getLibraryInformation(): LibraryInformation + public function __set(string $name, $value): void { - return $this->info; + $this->ffi->$name = $value; } } diff --git a/src/Support/ProxyTrait.php b/src/Support/ProxyTrait.php deleted file mode 100644 index dbd8b8a..0000000 --- a/src/Support/ProxyTrait.php +++ /dev/null @@ -1,157 +0,0 @@ -ffi->$name(...$arguments); - } - - /** - * For PHPStorm autocomplete support - * - * @param CData|CPtr $type - * @return CPtr|CData|mixed - */ - public static function addr(CData $type): CData - { - return \FFI::addr($type); - } - - /** - * @param string $type - * @return string - */ - protected function nameToInternal(string $type): string - { - $ptr = 0; - - while (\substr($type, -3) === 'Ptr') { - $type = \substr($type, 0, -3); - $ptr++; - } - - return \str_replace('\\', '_', $type) . \str_repeat('*', $ptr); - } - - /** - * @param string $type - * @param bool $owned - * @param bool $persistent - * @return CData - */ - public function new(string $type, bool $owned = true, bool $persistent = false): CData - { - return $this->proxyNew($type, $owned, $persistent); - } - - /** - * @param string $type - * @param bool $owned - * @param bool $persistent - * @return CData - */ - protected function proxyNew(string $type, bool $owned = true, bool $persistent = false): CData - { - try { - /** @noinspection StaticInvocationViaThisInspection */ - return $this->ffi->new($this->nameToInternal($type), $owned, $persistent); - } catch (ParserException $e) { - $error = \sprintf('Structure "%s" not found. %s', $type, \ucfirst($e->getMessage())); - - throw new SDLException($error); - } - } - - /** - * @param string|CType $type - * @param CData $ptr - * @return CData - */ - public function cast($type, CData $ptr): CData - { - if (\is_string($type)) { - $type = $this->nameToInternal($type); - } - - try { - /** @noinspection StaticInvocationViaThisInspection */ - return $this->ffi->cast($type, $ptr); - } catch (ParserException $e) { - $error = \sprintf('Structure "%s" not found. %s', $type, \ucfirst($e->getMessage())); - - throw new SDLException($error); - } - } - - /** - * @param string|CType $type - * @return CType - */ - public function type($type): CType - { - if (\is_string($type)) { - $type = $this->nameToInternal($type); - } - - try { - /** @noinspection StaticInvocationViaThisInspection */ - return $this->ffi->type($type); - } catch (ParserException $e) { - $error = \sprintf('Structure "%s" not found. %s', $type, \ucfirst($e->getMessage())); - - throw new SDLException($error); - } - } - - /** - * {@inheritDoc} - */ - public static function __callStatic(string $name, array $arguments) - { - return \FFI::$name(...$arguments); - } - - /** - * @param string $name - * @return mixed - */ - public function __get(string $name) - { - return $this->ffi->$name; - } - - /** - * @param string $name - * @param mixed $value - * @return mixed - * @noinspection MagicMethodsValidityInspection - */ - public function __set(string $name, $value): void - { - $this->ffi->$name = $value; - } -} diff --git a/src/Support/SingletonTrait.php b/src/Support/SingletonTrait.php index 3180be7..dcc0c37 100644 --- a/src/Support/SingletonTrait.php +++ b/src/Support/SingletonTrait.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Support; +namespace Serafim\SDL\Support; /** * Trait SingletonTrait diff --git a/src/Support/VersionComparisonTrait.php b/src/Support/VersionComparisonTrait.php index 189d020..ebae7cb 100644 --- a/src/Support/VersionComparisonTrait.php +++ b/src/Support/VersionComparisonTrait.php @@ -9,13 +9,13 @@ declare(strict_types=1); -namespace SDL\Support; +namespace Serafim\SDL\Support; -use SDL\Exception\VersionException; -use SDL\Loader\LibraryInformation; +use Serafim\SDL\Exception\VersionException; +use Serafim\FFILoader\LibraryInformation; /** - * Trait VersionComparisonTrait + * @property-read LibraryInformation $info */ trait VersionComparisonTrait { @@ -39,18 +39,13 @@ protected function assertVersion(string $version, ?string $method = null): void } } - /** - * @return LibraryInformation - */ - abstract protected function getLibraryInformation(): LibraryInformation; - /** * @param string $version * @return bool */ private function gteThan(string $version): bool { - return \version_compare($this->getLibraryInformation()->version, $version) >= 0; + return \version_compare($this->info->version, $version) >= 0; } /** @@ -60,14 +55,12 @@ private function gteThan(string $version): bool */ protected function getVersionErrorMessage(string $version, string $method): string { - $info = $this->getLibraryInformation(); - return \vsprintf('Method %s::%s() is available since %s >= %s, but %s is installed', [ static::class, $method, - $info->name, + $this->info->name, $version, - $info->version, + $this->info->version, ]); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 03deee1..e90a01b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,7 +9,7 @@ declare(strict_types=1); -namespace SDL\Tests; +namespace Serafim\SDL\Tests; use PHPUnit\Framework\TestCase as BaseTestCase;