jeroenjanssens / raylibr

R package that wraps Raylib, a simple and easy-to-use library to enjoy videogames programming
https://jeroenjanssens.github.io/raylibr/
Other
32 stars 5 forks source link

Included raylib source code in the project #7

Closed Gladius1 closed 1 year ago

Gladius1 commented 1 year ago

so it doesn't have to be provided externally.

All credit goes to https://github.com/eshom as I just copied the necessary parts from his project https://github.com/eshom/raylib.R.

jeroenjanssens commented 1 year ago

Thank you @Gladius1 (and @eshom); this is fantastic!

It's not working just yet, because it also needs raymath.h. Would you be so kind to add that from https://github.com/raysan5/raylib/blob/4.0.0/src/raymath.h? I have enabled workflows for you so that when you add another commit, GitHub Actions will try to install raylibr on Ubuntu and generate the website.

One question: where does the file inst/raylib-4.0.0-modified.tar.gz come from? If it doesn't come from Raylib itself, do you know what has been modified? We should be able to reproduce these steps for when we need to update the package for future versions of Raylib.

Thanks again!

Jeroen

Gladius1 commented 1 year ago

Hello Jeroen,

I added raymath.h. It was probably installed systemwide on my system because it compiled on my machine. Hopefully this is all that is missing.

As for the modifications. I think eshom did two things. Firstly he included a R c++ error handling library to allow better error handling. This involved changes to multiple files and is unfortunately over my head. But the good news are, this is not needed for raylib to compile and work. The other change is very trivial. It just involves changing line 56 in src/Makefile from RAYLIB_RELEASE_PATH ?= $(RAYLIB_SRC_PATH) to RAYLIB_RELEASE_PATH ?= ../lib.

This works with raylib 4.0.0, I already compiled it successfully. raylib 4.2.0 does not work out of the box because the extra libraries for e.g. physics or GUI have been separated. I guess they just need to be copied over but I haven't tested this.

jeroenjanssens commented 1 year ago

Thanks @Gladius1! Could you please try adding libxcursor-dev to line 34 of r.yml? That might fix the issue of missing X11/Xcursor/Xcursor.h.

I'll keep doing my best running the workflows as soon as you commit. Cheers.

eshom commented 1 year ago

Thank you @Gladius1 (and @eshom); this is fantastic!

It's not working just yet, because it also needs raymath.h. Would you be so kind to add that from https://github.com/raysan5/raylib/blob/4.0.0/src/raymath.h? I have enabled workflows for you so that when you add another commit, GitHub Actions will try to install raylibr on Ubuntu and generate the website.

One question: where does the file inst/raylib-4.0.0-modified.tar.gz come from? If it doesn't come from Raylib itself, do you know what has been modified? We should be able to reproduce these steps for when we need to update the package for future versions of Raylib.

Thanks again!

Jeroen

Hey! I'm glad you found the modified source code useful!

Unfortunately all of the changes I've done were manual, and so it's not easy to reproduce.

To know exactly what changed, you can clone repo, and follow my commits. git log --all --raw -- raylib-4.0.0-modified Or better, diff the modified src/ with the original raylib-4.0.0 source code src/ directory.

One if the important changes, I believe, was modifying Makefile to include R headers and changing the binary output directory: git diff 22fc60e33 e1b098bd8 -- raylib-4.0.0-modified/src/Makefile

Other changes, in general, included replacing printing functions, asserts and RNG functions from C standard libs to the R library. These changes are important for complying with CRAN's policy.

I think the following grep commands will find most, if not all of the changes I manually done.

grep -nr 'Rf_'
grep -nr 'Rprintf('

I've been thinking about updating the source code to raylib-4.2.0, and this time simplyfing and automating the code changes where possible using C macros with the compiler's -D option. And with sed otherwise. For example defining printf as Rprintf, and the following fun macro to prevent raylib from crashing the R interpreter: #define assert(x) do {if (!(x)) Rf_error("Assertion" #x "failed.");} while(0)

I've been busy with life stuff and haven't worked on my repo a while now, but I might try to at least update that.

jeroenjanssens commented 1 year ago

Thanks for your perseverance, Gladius1! Your two checks are successful, so I'm happy to merge this.