This looks awesome! My question, coming from a self-identified "C/C++ person" who works in realtime control systems and who's been feeling increasingly uncomfortable with C++'s inherent footguns, is how has your choice of language helped or hindered this project?
I had a nice comparison because I first tried to do a native implementation in C++ and - wanting to do some custom low-level "stuff" for my simulation actor system (related to allocation and networking) - I ran into so many footguns that it slowed me tremendously. As soon as I tried to do the same with Rust, it was a breeze and I was able to write a lot of unsafe code that does very particular things that I need, while exposing a completely safe API for the rest of the engine and game. Being then able to also use Rust in the browser quite seamlessly with WASM allowed me to have a super straightforward and high-perf communication channel between the simulation backend and browser UI. The only real Rust disadvantage that hurts a lot is compile times. Sometimes I do fight types/the borrow checker, but only when I try to do weird things, in general I perceive it as a huge help in scaffolding things.
Very nice, how did you decide on your simulation? did you build a generic simulation engine you can reuse, or is your simulation tightly coupled to the objects you are simulating? It's fun seeing this, I have been recently thinking of a simulation game and wondering if to use a generic simulation library such as SimPy
I build a simulation engine, based on a high performance distributed actor system library I wrote for just this purpose. It is generic, but a lot of the performance trade-offs are with Citybound's needs as the main driver.
Their actor implementation / event loop works on a higher level than mine. Mine is super simplistic intentionally to offer high performance. Being optimised for cache locality, processing similar actors in batches, using custom allocators and having encoding-free communication, it has many parallels to data-driven game engine design or even entity component systems.
First time I hear about compile times being an issue with Rust.
Is that a general problem with bigger projects or can you identify language features that add specifically to the problem?
First compilation is slow. After that it’s much better during development times. This can mean that ci can take a ton of time if you don’t do even the smallest bit of optimization.
Wow, I get frustrated and feel unproductive if my feedback loop is longer than 2-5 SECONDS. This must require a seriously different approach to trial and error exploration
A lot of that is done in a simulator on the computer, which usually builds very quick once you get the environment and simulation scripts written.
The full build to a bit file that can be loaded into hardware is an NP-hard optimization problem, so as your design approaches the limits of either the desired clock speed or the amount of space in the chip, it can become very slow.
I've heard that long warm compilation times can be mitigated by breaking up code into separate modules so it doesn't recompile e.g. the actor system every time you adjust a layout. Basically caching works best on the module boundary. Is this something you've explored?
Yes, I factored out quite a bit of generic parts of the engine into libraries and took some steps to cut down on number of generics being instanced (which was one of the main drivers of compile time). Now I'm left with pretty much the game core, which is highly interdependent and thus nearly impossible to break up into crates (they can't mutually depend on each other). And it's still kinda slow.
I've splitted a 20k+LOC Rust project into multiple crates and compilation time improved a lot (still slow compared to other languages) but it's now manageable.
I see there is a bit in there about the city economy. Are you interested in expanding that to supporting a full monetary economy with employment, commuting and the like?
That certainly interests me - particularly how the pathologies of an economy like that emerge from individual actions - and I’ve been looking at Elixir to generate the necessary actor simulation engine. Looks to me like you have that here in Rust.
How could I get involved in helping to add a more detailed economy to this sim?
> ...and I’ve been looking at Elixir to generate the necessary actor simulation engine. Looks to me like you have that here in Rust.
I will caution that Elixir's runtime performance, particularly with simulation type code, is abysmal. Also, last time I was using Elixir, the available profiling infrastructure was really terrible; I had to buy a new workstation with 64GiB of RAM just to be able to fit the profiling artifacts from one iteration of our small model in memory, which was required in order for it to complete in less than infinite time.
There is already a monetary economy with employment, commuting and purchases. One of the things I hope to do soon is to factor out some of the variables of the economy simulation to make it easier to mod without having to understand the full codebase. Then would be a great time for you to experiment with it.
One direction that I've seen a lot of game engines heading in lately is the Entity Component System model for a lot of the same performance reasons (cache locality of data being the big one) that you've landed on the Actor model.
I'd be curious to know if you'd looked into the ECS model at all, and if you have how you view the tradeoffs between that model and the Actor model proposed in the talk. At a gut level, I get the feeling that your model seems much better suited to the distributed nature that you accomplish in your talk, and that ECS might be slightly more effective at allowing composition in an effective way. You've got so much more experience with both, though, that I'd love to hear you take if you've got one.
Really nice talk! And thanks for this, the actors architecture really talks to me. I am trying to find a distributed architecture that would make sense for a collaborative project I have and this could actually solve many of my problems. I had not considered that message passing could actually be very fast when done right.
Do you have a document/presentation or even source code where you go a bit more into details about how you share the actors states between different computers?
Do you have a writeup of the traffic simulation rules that you're using? I peeked in the code and saw the intelligent driver model is being used for acceleration. I suppose you also have a lane-changing model and such, too.
Your architecture could be very useful in teaching.
Ah, I'd love to hear more about this! Getting traffic right is much tougher than we appreciated at first.
Disclaimer: Creator & lead developer of SimAirport.
I suppose we just did it "wrong" to begin with, and have since been stuck with the wrong graph / haven't put the time into fixing it yet -- but would be curious to hear high-level of how you're doing it.
Our issues are primarily that we did lanes as graph nodes instead of "node capacity" so our pathfinding prescribes precisely which lane to use; when stuck in traffic we can't intelligently find our way around it without pathfinding again, but then 'quality' ends up being correlated to how often we pathfind with node-occupancy info, which obviously is a poor (and poorly performing) solution.
Would love to hear your approach or if you'd be interested in talking shop at all, email is in profile! :)
First time I saw SimAirport, looks wonderfully antsy!
I'd love to discuss traffic with you on the Citybound subreddit, since I think there might be other people interested in such implementation details :)
Many universities in major urban areas have a school of housing and community development. They study planning, policy, design, economics, and other related disciplines.
Once trained with how to create new models in your system, academics could simulate the impact of ideas they are developing in research.
I just thought it might be nice if you did a breakdown of the physics of traffic and maybe how you coded that part.
As for teaching, I think it could be used to teach about like signal timing etc in a fun way.
Your statement says that you have actor-based simulation model that's inspired by erlang - is there a reason why you picked rust instead of a BEAM language for developing the backend? My guess would be performance, maybe?
Rust is interesting to me but honestly, I'm going to stick to elixir because I have high confidence I can train juniors to code safely on it, and I have no particular need for performance (most of my stuff is iO or network bound)
Write NIFs in Rust, or C if you want to stay on the BEAM, and still get performance if you need it. Elixir/Phoenix are the Ruby/Rails of today. I do like getting low-level within the same PL, so this has truly inspired me to dig more into Rust. I am still playing with Zig though.
I didn't play it enough (yet) to feel comfortable putting it there, compared to the other things I listed as inspiration. I feel like it deserves a more in-depth comment/comparison. I've only watched let's plays of it so far.
I like it as well a lot, but after several hours of playing with it I started focusing too much on some things that I consider core flaws of the game and now I'm not motivated very much anymore to keep playing... .
Examples:
- utility services: I keep having problems with e.g. ambulances or trash collectors that are spawned very very far from the area where they're actually needed, even if a hospital or incinerator is just around the corner.
- size of buildings: I don't like the approach of having tall buildings / high-rise in developed high-value zones by default. In my opinion the size of a building should mirror only the density of the population living in that particular area, so it should be possible to have as well tall buildings in low-value zones. As well the amount of people living in tall buildings is for my taste not a lot different from the one of med/low-buildings, taking into consideration the height of the building... => how tall is a building should be a function of the people inhabiting it and not related to the value of the zone.
- deaths/births waves: once my cities got big, I kept getting each time waves of people dying and later a lot of births. There is a plugin that fixes this, but this should really be part of the basic game.
- traffic: this is actually already working veeeery well on multiple levels (e.g. very nice/interesting to observe how queues generate - I can observe that for hours hehe) but I do miss a logic that says e.g. "if this section of street has during a certain timespan ~95% of space occupied by vehicles then assume that there is a queue => mark that section of street temporarily non-existing for non-involved vehicles so that other cars would start looking for alternative paths" or something similar.
All in all, even if Cities Skylines was already a giant leap compared to the classical Simcity-games (excluding the last one which was just horrible), I'd definitely like more "action=>reaction"/"cause=>effect" in a potential future "Cities Skylines 2" or in this case in "CityBound".
Cheers
EDIT: for more details search in this page for the post containing "Unfortunately, traffic management is the only part of the game that really holds up as a simulator" by "amyjess" - I just read it now and I think that I agree as well with all what's mentioned there about CS (but I honestly don't rememember anymore how Simcity4 worked...).
Kind of the same. Loved Cities: Skylines to death but the traffic AI killed it for me. It gets to the point where you're stuck building unrealistic designs to workaround the flawed AI pathfinding. It's true you can mod it but it requires a ton of extra manual work to reassign lane routing in each and every city intersection, on top of killing performance.
I'm just waiting for the sequel to the game where they may open up the traffic AI to modders more, or fix some of the stuff broken with the existing engine. That said, it's become kind of the gold standard for city sims so OP should definitely check it out.
The current iteration of the goto traffic manager mod is the presidential edition, https://steamcommunity.com/sharedfiles/filedetails/?id=58342.... It has some features like the dynamic lane selection and an alternative AI model (I think) that help even without manual work. But yes, assigning lanes at intersections, planning the number of lanes accordingly to have onboard lanes and in general avoiding that traffic collides takes some manual work. It can be fun though. I did not notice the performance going down too much.
I play City Skylines only to tune my roads with that mod. It's awesome, but in general I think the game has some annoying flaws, like that bringing dead people to graveyard is like a logistical problem, the blocky zoning makes neighborhoods boring, buildings are never that big, etc.
In CS the only way I found to have even moderately decent traffic flow was to make absolutely every street a one-way street. I don't claim to understand why that helps, but it seems to.
The downside is you have to be very careful where you place your emergency services as you can easily get zones which are too far for firefighters to reach.
So, one thing that's broken about traffic is the distribution of population in low-density vs. high-density areas.
The short version is that low-density areas are denser than they look, and high-density areas aren't dense enough. For example, if you click on a single-family home and look at the population, there will be over a dozen people living there (TBH, I forgot the exact numbers, but it's way more than a single family's worth of people)! But if you click on a giant skyscraper, there's nothing even close to what would fit in that building if it existed in real life.
This has two unfortunate effects:
* The suburbs need more public transit than you think they'll need. Once you hit 50k people or so, you'll be hurting for transit badly. "But I'm building low-density housing with a street hierarchy, it works fine in real life, so why are my roads clogged in the game?" Yeah but in real life you're not cramming a dozen people into every single-family home.
* On the other hand, you can get away with building dense downtown areas with much less transit than would be required in real life.
And yes, there are mods to realistically balance population. If you run these mods, you'll have something much more realistic: the suburbs don't really need transit, but if you build any high-density at all, you'll need to get a good transit network up and running ASAP.
I agree and I'd like to add that (not related to traffic nor density but just pure spread of population density), from what I saw, there doesn't seem to be in CS (Cities Skylines) any relation between low-density & high-density areas, meaning that I can start right away building high-density areas with no in/direct realtime/historical impact of any kind.
We can (proably should?) debate about how these mechanics should work, but I think that it must be true that any city needs in some percentage both areas (e.g. as well the extreme being built now "on demand" for the World Cup in Qatar - https://en.wikipedia.org/wiki/Lusail ) must need both, or maybe not if they modeled the city based on CS haha.
I think that I could have similar points as well for the "education" in CS - I never (still don't know) if the elementary schools that I place are a foundation for people that will then go later to College and/or University - I still place them because I personally believe in the scala Elementary=>maybe_College=>maybe_University, but who knows... . (ok, this boils down mainly to a lack of transparency/informations for the user, independently if what CS does is good or wrong from the point of view of the user)
So, according to the Cities: Skylines wiki [0], cims who move into high-density residential areas are younger and less likely to procreate than cims who move into low-density residential.
That's an interesting way to differentiate them, but it's also something that's very specific to present-day America. And middle-class America, at that.
Kind of odd that Skylines is developed by a Finnish company and published by a Swedish one, given how US-centric that model is.
I've also written elsewhere in this thread about how Skylines doesn't have a concept of class stratification, either, and that's a problem: the only way to create neighborhoods with distinct class implications (e.g. the ghetto) is to use the RICO mod and plop buildings directly.
There's no real concept of medium-density, either: the closest it comes is to zone high-density and put it in a district with the High Rise Ban ordinance. Or, again, use RICO. Oh, and growables are limited to no more than 4x4 tiles... if you want bigger buildings (e.g. a sprawling suburban apartment complex), your only option is RICO.
> Kind of odd that Skylines is developed by a Finnish company and published by a Swedish one, given how US-centric that model is.
I totally agree, and maybe there has been some discussions about this in the past (I forgot about those early webcasts) - but for a company to align to the US market (probably the largest & most uniform around) is usually probably the safest bet - I still admit of being a little bit sad :|
> There's no real concept of medium-density, either
Now that you say it, I think that (a realistic - see previous posts) medium-density would be absolutely important to model european cities.
> limited to no more than 4x4 tiles
You're right but personally I don't really care about this for the time being (meaning that the other problems have for me absolute priority compared to this) - maybe they just randomly put a safe limit for their first release to avoid indirect potential complications... - I would have most probably done the same, so I won't dig into this hehe.
> I've also written elsewhere in this thread about how Skylines doesn't have a concept of class stratification
I agree.
Summarizing after all these posts & remarks, I feel sad that the studio so far developed only add-ons that do not improve the core of the simulation but only add more distractions and/or superficial complexity around it :P
(E.g. I did buy "Mass Transit" but it didn't give me the feeling that it improved the game but just gave me a few more alternatives - and actually "mass transit" is in my opinion associated to trains & metro, therefore absolutely not fitting cablecars/blimps/ferry/etc...)
But maybe.... they be working on aggregating key-improvements for their next CS2? Who knows... :)
I agree about the expansions, they have been a disappointment in general. Mass Transit was the highlight, but didn't go nearly far enough and still concentrated on the eye candy. I do understand that they try to appeal to the larger market -- people running the game as a simulation is surely a minority.
That said, it's still currently the best city sim by far. Hoping that Citybound will change that at some point :)
> * The suburbs need more public transit than you think they'll need. Once you hit 50k people or so, you'll be hurting for transit badly. "But I'm building low-density housing with a street hierarchy, it works fine in real life, so why are my roads clogged in the game?" Yeah but in real life you're not cramming a dozen people into every single-family home.
One could argue some cities have low-density housing next to transit though (like Berlin, or Paris). It does have the disadvantage of making metros too easy though, so commuter rail is almost never done because it is too hard to integrate to a city.
My experience with C:S heavy rail transit is that it doesn't work well with the current simulation: it seems that the cims take the shortest route even if the slightly longer train would be much faster due to fewer stops abd less congestion.
These are all very valid points. Cities: Skylines ends up being kind of a "traffic sim" game once you get down to the nuts and bolts of it. Even though they have some very intelligent citizens, it's still not quite up to par for pathing.
I still think it's the best City Sim game made yet. The author here should really invest some time to learn about Skyline's failings so they can avoid those problems in their own sim.
Can you talk about the road building engine? Are you using splines to generate the smooth curves? This is a really amazing project, I can tell you have put a ton of work into it.
There's a lot of interesting stuff going on in there. First, for the curves itself, it does a kind of naive approximation optimisation and builds a curve out of line and arc segments that tries to follow the control points as closely as possible. Then it does an intersection step between all roads and procedurally generates correct connections between all incoming and outgoing lanes of each intersection, including (somewhat) reasonable traffic light timings for each "turn group"
Always thought it would be really cool to do a city based on no roads at all, but bike paths and public transport. Ever think this will get to the point where I can play around with that?
Thanks.
I assume you talk in terms of what constitutes an actor in the actor system: because cars on one strip of road interact highly locally, so processing them in one batch makes a lot of sense performance wise, vs. every car sending messages to every other car and having to maintain references to close-by cars.
Feel free to ask me any questions about the project!
I hope to learn to code. I just got my rejection letter from a coding school ("overwhelming demand -- we had to turn down many qualified candidates"). My backup plan is some free online coursework and probably finding a city-building game to mod or tinker with.
When you say open source, does that mean it would be okay for me to futz with it for myself like that?
I’m really hoping to get the project to a point soon where it is easily hack able even for people who are just starting out to code, or even for whom this will be the first contact to code. But I’m far from being there, right now it is a pretty large, pretty unusual and almost entirely undocumented codebase.
So by all means start teaching yourself to code by playful experimentation, but start with something much simpler first :)
If I will add scripting, I will probably use JS, since I already have interop with that in the browser UI. Gluon or Dyon are neat, but they are weird enough (in my opinion) that people might as well learn Rust instead of scripting.
Having a license that says you can go play with it doesn’t mean it will be straightforward as a newcomer to understand the code you find or to accomplish any particular goal with your fiddling.
I haven’t looked closely at this project, but I would recommend at least considering starting out fiddling with a simpler system, if you want to learn to code.
I don't know that I will even learn Rust. I have had a Python course recommended to me.
I just am trying to figure out what my options are. I've gotten serious push back at times for what I felt were innocent activities. Trying to ask the "dumb" questions in hopes of avoiding that.
Don’t worry if Rails is the right choice. You might love it or hate it, but regardless, you’ll learn things like writing tests and using version control.
I'm not affiliated with the author, but that is generally part of the definition of open source. Once you've downloaded the code, check the top of any source code file for more details about the specific license the author is using.
Interesting that you take factorio as inspiration. May I know what part of factorio that you want to add into, that seems lacking in other games of same genre like sim city?
On the other hand, how do you plan for in-game scale / limit? (Millions of population, etc) and whether you have any idea about multiplayer/server (I'm talking similar with clustertorio)
The thing that impresses me with factorio is how smoothly the game challenges scale with you learning and mastering one game aspect after the other. Basically, you learn something that solves all your current problems, but that directly creates new problems, which you then have to deal with using your newfound powers.
The actor architecture makes it very easy to scale the simulation across several machines and indeed run a simulation cluster that you connect to from a simple client. In fact it already almost works like that. And the only thing that's missing for multiplayer is some UI-level coordination for collaborative planning (basically preventing editing conflicts). Everything else is already "multiplayer ready".
Oh even just usage instructions. Like what are the navigation controls, etc. I zoned some things and laid down some road and wasn't sure what or when to expect it. Some of the bugs as well make me unsure if my expectations are wrong or if it's just a bug (e.g. vehicle traffic not appearing, roads and zoning going in weird shapes). Some of the links in the top-level readme are 404 as well.
All in all I'm sure I'll spend a ton of time playing the game itself and playing with the source.
Yeah I saw that but I'm still largely unsure about a lot of bits and pieces about the game play. Mostly it's a matter of determining what's intended behavior and what's not (e.g. the traffic jams for no apparent reason that may or may not have other cars passing them in the same lane), but also what things like those big arrows on the road (that persist sometimes).
Also, check out the main homepage at https://aeplay.org/citybound for a more player-centric intro