Architecture and foreseeable problems
12 Nov 2023When I start thinking about how to make it, I can’t help be gravitate towards what are inevitably some pretty niche but interesting problems (interesting to me at least). Even if I don’t end up going any further with this project, I’ll be happy to have a place to brain dump some of this information so it can stop washing around in my noggin while I go on a cycle.
How do worlds get initialised
- World created at lat/long in the uk
- first randomly, later at poi
- use poisson disk sampling
- Lat long converted to geohash (6 characters)
- If geohash is new to the db then create a new geohash in the geohashes table, along with the bounding box
Updating worlds population
-
Have an updater process move forward one tick per second
- There is a datetime column in the world table which indicates next population growth time
- Once per second, the updater process scans the db for any worlds where next population growth time <= current time
- The updater process updates these worlds, and schedules the next update for current time + current population
- If the population has been updated to 10, then the next increment will be T+10
- this makes population growth slower and slower and encourages to player to use their armies sooner
How to send updates to the client on moving fleets
When a player decides to move a fleet from one planet to another
- create a new entry in the fleet table with estimated time of arrival, and trajectory
- For each geohash object that overlaps with the trajectory send an update on that geohash channel
- A new connecting client will need to query for the existing status, and subscribe to further updates
- These could be handled on the same webserver connection where the client can ask for all info related to a geohash, or just the updates
So what i need is
- A postgis database with the following tables
- Geohashes (or ares of interest)
- worlds
- Lat/lng, population, world type (player home or other), maybe description when theres POIs, owner_id
- fleets
- start time, end time, trajectory, size, owner_id
- players
- owner_id, name, password, etc
- An updater process where once per tick (i.e once per second)
- Update world population accounting to population growth rate
- For any fleets that have reached their destination, process that
- A server that
- Listens for fleet creation, sends those updates to client
- Updates client of population updates
- A client
- Player login
- Tracks player position, feeds home world position to server
- Lets players make fleets
The updater process and the server process need to communicate somehow, this can be done using postgres notify/listen
- https://gist.github.com/kissgyorgy/beccba1291de962702ea9c237a900c79
Mapbox has support for animating markers
- https://docs.mapbox.com/mapbox-gl-js/example/animate-marker/
- http://kuanbutts.com/2019/08/31/mbgl-vs-leaflet/