Haskell Ant Simulator Talk

Hello Haskell community,

I’ve created an agent-based ant foraging simulator in Haskell.

I also have a 40-minute talk about this project. I’ve already delivered the talk at my company, and it was well received. Now I want to deliver it again at a different venue related to Haskell or game development. Is there any interest here? (I hope so :slight_smile: ) Could someone please suggest venues where I can submit the talk?

Thank you!

20 Likes

How do you like using h-raylib? Did you try anything else first before selling on it?

I tried gloss at first, but I liked raylib better.

Is Haskell suitable for game development? :grin:

Not if you care about framerate. :slight_smile:

1 Like

Does it work for 20fps or lower?

I care about framerate and can push 4k@140fps without problem :thinking:

1 Like

What is the talk about?

The talk is basically a making of this project. It has elements that would be of interest to both the Haskell and the game dev community.

  • ECS systems as monoids
  • Ant movement, 1D vision, and navigation via pheromone trails
  • Neural network ant brains
  • A genetic algorithm to train the ant brains
  • Lessons learned while making a game in Haskell
2 Likes

What library are you using?

I’m using raylib and vector. Everything else is custom.

Oops, I see that question was intended for @wiz :smile: Indeed, what library are you using to get 140fps?

I tend to cap at 60fps, but every game I’ve made for Ludum Dare was an easy 60fps (even in ghci). One is gloss, most are using my bindings to grimfang’s SDL_gpu, and the most recent used Pixi.js and the wasm backend. When I played around with raylib it seemed like it would be fine for 60fps too.

Those aren’t huge but I’m confident I could do any game at 60fps with Haskell. There’s a lot of potential for type safe off heap stuff.

I didn’t even use the -xc non-moving collector. [1] This is all the default STW collector. The key is to not retain much in the heap. So compact things, use storable, etc for long lived things.

[1] I did use -xc when I ran my games in ghci (where I could do hot reloading and query/edit game state from ghci itself). ghci has a bigger heap full of loaded Stuff (now I wonder how much could be compacted?)

2 Likes

I’m working on something with Brillo (fork of Gloss) right now, and just putting 200 rectangles with text on the screen drastically drops my fps below 60, with more rectangles making it even slower. I assumed it was due to the immediate mode rendering because when I profiled it all the time was spent in the rendering code. But if you are drawing that many things at 60 maybe I’m doing something wrong.

That isn’t a brillo thing but rather a rectangle thing. It probably doesn’t let you do this, but you need to instance that rectangle. Draw it ONCE to a texture (gpu memory) and then you can put a bunch on the screen.

Do the same program but draw the rectangle as a png in GIMP and load it as a bitmap sprite. I bet the FPS improves!

I ran into this in a tech demo with sdl-gpu. It was because I kept calling the “draw a shape” primitive 100s of times per frame. When I drew it once to a texture, it was fine.

2 Likes

Also think from first principles. There isn’t heavy haskell there. A few hundred short lived objects is trivial for the Haskell GC. So haskell isn’t to blame. It’s the GPU usage.

This may actually be part of my problem. My ants are vector circles and lines, not textures. However, even when I turn off all drawing, I’m still seeing low framerates with only 100 ants. Granted there is a lot of computation going on under the hood to make the ants “see” the world and make decisions, and none of it is super optimized.

1 Like

Good gameplay doesn’t have to be computationally intensive.

vulkan-backed engine and a math library that together fight reallocations, pointer chasing, and redundant gpu traffic.
GC still happens, but most of the time the system has free frame budget to accommodate it.

(I also got into gamedev from rendering insects on gloss, although not to the level of detail.)

1 Like

That isn’t a brillo thing but rather a rectangle thing.

I would agree if brillo supported instancing :grinning_face_with_smiling_eyes:

1 Like