Chicken-Scheme FFI Examples
I'm currently working on refactoring the FFI implementation for the Rebel Game Engine. It was previously written using the Bind chicken egg but I wanted to have more control over the implementation by using the low level foreign functions.
To help me better understand I made some examples that has the basic FFI implementations that I'll be needing for my project.
foreign-lambda example
Let's say we have a structure Vec3
and a function Vec3Create
that we want to access from chicken-scheme.
typedef struct Vec3 {
float x;
float y;
float z;
} Vec3;
Vec3* Vec3Create(float x, float y, float z)
{
Vec3* v = (Vec3*)malloc(sizeof(Vec3));
v->x = x;
v->y = y;
v->z = z;
return v;
}
We could use foreign-lambda
to bind to the function:
(define vec3_create
(foreign-lambda
(c-pointer (struct "Vec3")) ; Return type, a pointer to a struct object of Vec3
"Vec3Create" ; Name fo the function
float float float)) ; The …
#3 - Rebel Game Engine now works on different platforms
After finishing the integration of Chicken-scheme scripting for my custom game engine I decided I wanted to tackle another hard problem, and that is making it cross-platform. At the very least, my engine should be able to deploy to Linux, Windows, and MacOSX.
It might seem silly to be working on this while the engine is still in its early stages, but I think it is better to get this out of the way before the codebase becomes huge. With a small codebase I was able to easily identify the causes of the problems as I was porting them.
It still wasn't a walk in the park, however. Being inexperienced with developing C programs on other platforms (I've only done it mostly in Linux) I had to do research and do a lot of trial and error. I learned so much about cross-compilers, portable makefiles, and the quirks of different …
Making Unity beep after scripts finish reloading
Our latest game, HistoHunters, has grown into a really big project that compilation now takes a really long time. Longer than no sane programmer wants it to be. It has gotten so bad that changing a single file would take about a minute for recompilation!
Thankfully, I have managed to shorten this wait time through the use of assembly definitions. If you have a big Unity project and compile times are slow, this is the solution to that. Just for kicks I also purchased an SSD and that also helped reduce compile times (Not much as the assembly definitions though).
However, in spite of these changes compiling still takes a few seconds to reload scripts. This seems to be the lowest it could go. While this is definitely better, I can't help but feel that the seconds spent waiting is wasted.
I recently got the idea of having Unity inform …