Defold + Biosim4


I recently watched the great video on biosim4 here and was fascinated by the evolution approach taken.

Ive always been interested in ALife type programs and have tinkered and made many myself. I thought it would be an interesting exercise to turn biosim4 into a little native extension. And with the help of the great drawpixels native extension from @AGulev it was in and working.

Heres the project - Im going to add imgui so you can modify and tune the simulation runs how you want.

And a little video showing a few generations run. Make sure you run as release - Debug is about 5-10x slower, although its just as pleasing :slight_smile:
Thanks to David Miller for creating this great application and making an excellent video as well.

If you want to make your own biosim4.ini edit the one in the data folder (make a backup first) and you should see the changes. Mutli-threading is not supported properly yet (I couldnt get it stable enough) but everything else seems to work ok.

13 Likes


Added imgui. Will add a graph and histograms too. Very fun to play around with. :slight_smile:

10 Likes

Looks interesting! Looking forward to the progress here `:)

1 Like


Added graphs and histogram. This run you can see the diversity starting to shrink each generation.
The properties are all working and overall its pretty stable. Probably wont do too much more. I think I will use the sim in some games/apps though - might be interesting to drive some ai characters in a world.
Hope people have enjoyed this one. :slight_smile:

3 Likes

Note. Just found a bug - a memory leak in the texture setting code. Will patch tomorrow.

EDIT Memory issue fixed. Ran for 500 generations and a nice and stable 70MB for the whole run.

2 Likes


Added a little node viewer. Quite an interesting little app to muck around with :slight_smile:

5 Likes

How do I try this thing out? I naively downloaded the Git project, but I’m hit with a wall of errors when I run it.

Maybe I’m jumping the gun trying to test it out now? The video looks so cool!

error.txt (10.0 KB)

Hi @totebo - first make sure you have fetched the native extensions.
In the menu on Defold: Project → Fetch Libraries.
Then try a build. This will likely only build on Desktop platforms - have tried on Windows and Linux. I’ll give OSX a try on the weekend to make sure thats ok (there might need to be some adjustments).
I’ll put up some release packages here on the weekend so people can just download and use.
Thanks for having a look at it.

1 Like

Hey, yeah the extensions are all there, but getting the same errors for some reason. I’m on macOS, which probably explains it. Thank YOU for making this in the first place, it’s really quite fascinating.

Ahh looking at the errors, its making some sense. Looks like the OSX clang needs to have some extensions set for it to support some of the conventions in the code. Specifically: “-Wc++11-extensions”.
Kinda odd, since enums (what its complaining about) is a C89 thing shouldnt really need C++11 extensions. Will try some things out in the morning. Should have a quick solve for you tomorrow.

1 Like

That is done at project startup in the editor.

1 Like

The error mentions scoped enums, not regular enums:
” scoped enumerations are a C++11”

2 Likes

Sorry. yes you are right on @Mathias_Westerdahl, its a enum class which I dont think needs to be implemented that way in any case. The code from the library isnt overly complicated, so I might just refactor it anyway - could be an easy fix. Im also trying it out in html, which is helping cleanup some of these sorts of things too.

@totebo I have removed the enum Class. I still havent tested on OSX yet (will do tomorrow).
See if that works any better for you. Im trying to build html5, if that works, I’ll put it up on itch and people will be able to try it out at least.

1 Like

Thanks, just had a quick try, but there are still errors. No worries though, just hope to test this thing out at some point. HTML5 sounds like a good option.

Welp this has turned out to be more interesting that I thought :slight_smile:
Building on Win seems to be quite different. OSX and Linux (when I examined some of the output) have some issues when building the code. There is quite a bit of C++11 type code in the two libs included - mostly in the biosim4 code.
Additionally, with the current threaded setup (so it doesnt block Defold) there are problems building a html solution as well . Im going to clean out this code - I tend to prefer more C like code anyway, and the end code will probably get a 2-4x perf increase anyway, so its probably worth it.
The result, is I suspect this might be a few days to changeover. Im hoping by Wednesday it should be complete. Will post here about progress.

2 Likes

Note that we don’t use threads on html5.

1 Like

@Mathias_Westerdahl - yeah thanks. I was getting errors related to that. I sorta expected that to be the case too.

I have made another change. And Im not sure if Im being crazy, or just stupid :slight_smile: … Ive started converting to Lua. I looked at some of the main routines, and I actually think lua will out perform the C++. There is heavy use of maps and dual vector lists - which are both memory hungry std obejcts and also quite slow :slight_smile: … Hash tables however, on the lua side should be comparable if not slightly faster especially for how they are doing lookup - there are lots of calls to find, which is real slow.

Anyway, about 20% in, and I think I’ll call it a night. I think the timeline will be roughly the same as doing it in C, and more importantly, it will be full cross platform which is nice.

3 Likes

Ok. The conversion is done :slight_smile:
Now just sorting through all my bugs. Probably a day or so more. I suspect without jit on html it might be a bit slow - will see. Its all in a branch in the current git project - biosim4-lua if people are inquisitive :slight_smile:

3 Likes