Search code examples
databasegame-developmentscalabilitynoise

How to store an infinite noise map into a database?


I'm thinking about designing a small 2D game where all players share the same map, generated with Perlin noise (for example), and which could be modified by players. Technically, it should be like a big, potentially infinite, r/place (Reddit event). For scalability reasons, the server running the game should be RESTful. So the map should be store in a database after each update. I wonder how to store such a map, with what type of database (Redis, postgres, cassandra?), and how to optimize the storage of the map (division into chunks?).


Solution

  • If it's generated with noise, use a seeded random number generator. Then you just need to store the seed and any changes made.

    You probably want a spatial indexing database rather than a relational database. A K-D tree, R-tree, or Oct-tree are probably more useful.

    The closest you'd find in 'normal' database terms is GIS (geographic Information Systems). PostGIS is a GIS system built onto Postgres and IIRC it allows for spatial queries.

    Also yeah, while REST is great for structured low-speed data, the overhead of JSON is non-zero, so may be an issue for realtime multiplayer. Maybe use it for communicating login/scores, bit I wouldn't suggest sending player motion data as JSON, and structuring endpoint in a restful way may not be optimal as each request is a different connection. Probably better to use webRTC or websockets for your real-time data (assuming you are browser based).