Home
/
Indie Game Developers
/
Re: cOg Mission
/
I Simulated 100K Birds to Create a Living Ecosystem

I Simulated 100K Birds to Create a Living Ecosystem

7 min
This is the story of implementing what I've learned into a gridless, interactive, world-building sandbox game called Minor Deity. Minor Deity on Steam: https://store.steampowered.com/app/3876240/Minor_Deity/ Minor Deity Discord Server: https://discord.gg/2NEb4HxwhF I’ve seen a few impressive ecosystem simulations over the years, and I’d always wanted to do something similar. It’s fascinating to see the different ways in which complex ecosystems evolve, even with only a few basic rules. The videos I’ve seen generally use a two-dimensional, ground-based world, so I thought: “Why not add another dimension and take it to the skies?” And since my game can already handle huge maps, I wanted to see if I could fill that world with enough animals to make it feel truly alive. My goal is to simulate a huge ecosystem in real time: 100,000 animals at over 60 frames per second. Over the next few videos, I’m planning to build an ecosystem with some edible plants and trees at the bottom of the food chain, feeding a few land-based and small flying species. In turn, these will provide food for larger species. And, of course, everything will need to reproduce to keep the species alive. I will need to implement a very performant system to allow large numbers of these animals to interact with each other in real-time. A few months ago, I implemented a basic flock and herd system in Minor Deity. It uses the famous boids algorithm to drive movement within the herd or flock. Without going into the details, the boids algorithm simulates movement in a flock by considering 3 basic concepts: Separation aims to avoid crowding local flock mates. Alignment aims to steer towards the average heading of local flock mates. Cohesion steers towards the average position, or center of mass, of local flock mates. Although there are still a few gremlins, the basics have been working well. Note that, naively, each member of a flock needs to compare itself with every other member, so the workload grows quadratically as the flock gets larger. If we offload the calculations to burst-compiled jobs, we can just about handle a few hundred flocks or herds, as long as each group doesn’t have more than a few hundred members. However, at this point there is still no interaction between groups. Each bird is only aware of its own flock, which isn’t much of an ecosystem. The naive approach will not be feasible if we want animals to interact with any other animal on the map. The way we organize and schedule the work becomes increasingly important as the number of flocks grows. So, we are going to require some creativity. In this video, we’ll lay the foundation by designing a system that allows 100,000 birds to interact with each other in real-time at over 60 frames per second. 00:00 Introduction 00:18 Take it to the Skies 01:05 Boids System 01:53 Performance Issues 03:12 Spatial Indexing 05:02 Burst-Jobs alone is not Enough 06:12 Future Interactions 06:47 The Journey Continues...