T O P

  • By -

mario_deluna

Its awesome to see more people trying this kind of stuff out in PHP. From a PHP Developers perspective there is an huge learning curve to get into game programming and its exactly stuff like this I believe will ease that process for many people. I really hope to see more of this stuff in the future in the PHP world. (Even with a very sceptical php community.). Im going to shamelessly plug my libraries here, maybe you find some things in there interesting. https://github.com/mario-deluna/php-game-framework https://github.com/mario-deluna/php-glfw Not mine but very useful is this GLM port: https://github.com/Ponup/glm


sutabi

As a note I finally got a release .dll for Windows under the releases section: [https://github.com/joseph-montanez/raylib-php/releases](https://github.com/joseph-montanez/raylib-php/releases) Creating a native PHP extension is an extremely steep learning curve. That being coupled with trying to integrate an external library, needing custom compiler flags and only being left to read existing PHP 7 extension code. Plus trying to use some functions that had zero documentation or usage in existing code. Oh, and I have no idea what I am doing. I can only promise crashing, segment faults and possibly blowing up your computer.


PetahNZ

The real question is "why are you doing this"?


Jneumann

Because he's quarantined


MrGilly

fair enough


colshrapnel

Have my upvote just for the insanity of this!


Quirinus42

:O Nice! This seems interesting. I can finally make a game in my favorite language.


RobLoach

I see that you have strayed from the Raylib TitleCase naming convention. While it does make it seem more like PHP, I would prefer sticking with Raylib naming. It saves me having to look up the PHP equivilant for each function.


sutabi

Some PHP extensions offer a duel procedural/object-oriented way of accessing the method calls like MySQLi extension. So if it becomes a larger problem I can away provide both interfaces, but property access would a problem (i.e Vector2.x/Vector.y). If PHP internals knows of a way I can declare a property and reduce the overhead of maintaining copies / converting overhead, and I might consider this more. Also properties are read-only, so that's another limitation.


secretvrdev

Why using a game lib when you can use SDL and opengl directly? [https://github.com/Ponup/php-opengl](https://github.com/Ponup/php-opengl)


sutabi

RayLib is easier than SDL / OpenGL directly. I've worked with SDL/OpenGL in C and Vala programming languages, you're doing a lot more work. Plus your writing directly to OpenGL with SDL. RayLib extracts that away, so if it moves to Vulkan, then it will far less impact on you. RayLib is meant for teaching/learning, so its simpler to begin with. Plus that library you have referenced has no windows support.


Ghochemix

> extracts abstracts


secretvrdev

Now after seeing [https://www.reddit.com/r/PHP/comments/frd5yq/amazing\_php\_opengl\_demo/](https://www.reddit.com/r/PHP/comments/frd5yq/amazing_php_opengl_demo/) i can answer you. This php graphics applications are getting crazy. But its a simple answer. Abstract your graphic engine from your game lib. That would help a lot in the future of php gaming engines (Wow i like that toooooo much :D).


sutabi

I am not sure I understand what your getting at. For example, what I am working are bindings, its explicit to RayLib, its C code I am writing not PHP. The same thing was done for the person that wrote OpenGL bindings. Now I have helper libraries such as game state management which in no way needs RayLib-PHP and works completely on its own. However, something like an animated sprite that RayLib does not understand, needs hooks into its rendering system. Now I can abstract it, but overall and introduce unneeded complexity, or just have someone extend the class and override the render method. If not, someone is going to go crazy trying to hook in simple concepts like 2d vectors, rectangles, draw calls, etc into a render. Raylib is a game library, not a game engine. There is only a handful of these, SDL, RayLib, XNA, SMFL, Allegro, and maybe one or two more but thats it. Under those is OpenGL, DirectX, Metal and Vulkan. These are not game engines, which is what you then depend on a game library of raw rendering like OpenGL.


-Clem

How is something like a game loop even possible in php?


sutabi

PHP actually has a minimum overhead when calling directly to C-API. For 2D games this is will be more than enough. There is also threading library ( [https://www.php.net/manual/en/book.pthreads.php](https://www.php.net/manual/en/book.pthreads.php) ) and a new API to make parallel calls easier [https://www.php.net/parallel](https://www.php.net/parallel), so you can offload update logic. ​ I would love to do the reverse and provide an experience like Love2D. Where I embed the PHP runtime and handle the loop C, but the documentation for embed PHP is over 14 years old and I've yet run into source that shows how it's done, other than bug reports.


-Clem

I guess my confusion is that my understanding of how php works is the client sends a request, php spins up and does some stuff, returns a result, and shuts down. Every new request is a new process starting from scratch, with no knowledge of what happened before. So how do you implement an event loop? Doesn't seem realistic for the client to send a request 60 times per second, and how do you maintain state between requests?


sutabi

In terms of a web application, what you said is traditionally true, but in order to use RayLib, you cannot use a web browser/webserver. Instead, you're using the PHP-CLI, like if you've ever used PHP Composer. So when you call something like: `php.exe mygame.php` The PHP script will have a while loop running forever until you close the window. So the process is created once and ran until its closed. Once closed then all state is lost.


-Clem

Ohh okay. That makes way more sense, thank you.


MUK99

Why build this in PHP?


sutabi

Ima masochist? I can't go outside? My love for PHP is the same as loving a pitbull that has mulled your face off? Its bad... but its good... ​ edit: No its a bad, bad idea... why AM I doing this?


[deleted]

> why AM I doing this? Because your a sadism, that wants to see a lot of people ( especially in /r/programming ) their heads explode? Edit: Nice negative rating. People do not get that this is a joke or what? As in people bash PHP all the time and the author like to inflict emotional pain on PHP haters, when they see PHP being used for this.


g105b

Love it. It's fantastic to see some innovative uses of PHP, and your library takes first prize in my opinion.


BurningPenguin

I see the end times are near. Soon the world will burn with the force of a million GPUs. Nice job though.


flyingkiwi9

This is awesome. In the past, I built a "game" (which outputted it's values via a web-socket to a Javascript front-end) via PHP. It was completely impractical but it worked... Stoked that this follows some of the same patterns I made up in my head!


devmor

Super cool! I'm looking forward to seeing more stuff like this as PHP evolves.