Skip to content

6 comments

Hello, I'm developing Archapolis, a city builder game with an interior view of your customizable buildings. I'd like the player to have a more hands on approach to growing and managing their city. The game is still in early development (7 months in!).

This dev blog shows off the real time traffic simulation the game is capable of handling, as well as some progress on the art assets.

1 points

So are there 1M paths or are you using some sort of flow map? does each entity has its own different target?

1 points

I'm using a flow map, sort of. It's a bit more complicated than that.

The number of shortest paths (assuming all road tiles have the same weight/speed) can be derived from the sum of the binomial coefficient formula for each pair of nodes. So for a 40 x 40 grid there are over 27 sextillion possible paths between the top left corner and the bottom right corner. Recalculate for each node pair... (no thanks!).

Each entity has its own target (and in the video, once they reach their destination, they choose a new random target).

1 points

(cont) A simpler version of my algorithm would be a flow map for each destination, but that would only provide one shortest path between each set of nodes, which is why I steered away from that particular solution. (Essentially, it would be running Dijkstra's algorithm on every node and storing the results).

1 points

This is really cool. I love these kind of problems and trying to figure out how to solve them in a way that's both interesting for play (path preferences) and also doesn't strangle the processor.

I notice you said that's it's currently running on a single CPU only; have you considered offloading the path rebuilding to a background thread or process so it can take some of the load off the main thread?

Definitely looking forward to more updates! I've subbed to your channel!

1 points

Thanks! I appreciate it.

The current version is multi-threaded. Right now I use parallelization to generate / store the paths. This is pretty trivial since they are now stored in a vector (i.e. array)--each thread handles its own range of (contiguous) indexes, and the only writes are to the vector.

Moving units is done concurrently, though since I am using a hash table for collisions (as movement is tile based currently), there are data races that sometimes prevent the capacity updating within the the same tick (so gaps can appear, though this is only noticeable when the capacity is set to 1).

Im going to try to store the units in the graph's edges within a queue, then assign a thread_id to each edge. This should solve the problem (though I may need an extra step for units inside intersections).

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.