[web] How to store a grid map

Started by
1 comment, last by Wan 13 years, 11 months ago
I am thinking on starting a web based game where I want a large map like the one in travian.Basically it is a 400x400 grid where each cell can have different properties and stuff and only the 10x10 area around the player is displayed. What would be the best way to store this data? Is it feasible to store it in a mysql database,make a query to get the cells and draw them? Also I would like to hear which technology would be better for this kind of drawing. As far as I know travian is php+&#106avascript. Here is an image of what I want to achieve,this is from one of my pet projects but it was done with opengl.
Advertisement
Quote:Original post by Black Knight
Basically it is a 400x400 grid where each cell can have different properties and stuff and only the 10x10 area around the player is displayed. What would be the best way to store this data? Is it feasible to store it in a mysql database,make a query to get the cells and draw them?

It certainly is feasible. SELECT * FROM cells ORDER BY x,y. Stick a WHERE in there to filter down to the 10x10 area if you like. If performance is an issue then either cache the data in memory if you have an application server, or if you're using a script-per-URL system like PHP then maybe you could use memcache for the lookup instead, or a document-based database.

Quote:Also I would like to hear which technology would be better for this kind of drawing. As far as I know travian is php+&#106avascript.

Better than what? They're just images - you could do it with Flash, Silverlight, Java, &#106avascript, or img tags in a table. The &#111;nly real decision is whether you'll store the graphics as part of a plugin or whether to simply have them &#111;n the server as with a normal HTML page. If they're just images &#111;n the server then you have a flexible system that you can change at any point later.<br>
Quote:Original post by Black Knight
Is it feasible to store it in a mysql database,make a query to get the cells and draw them?

No problem, I have stored bigger maps than that without any problems. The table itself can be pretty lightweight (two coordinates and a tile type) and the (clustered) index on coordinates is trivial. I would store non static items in a different table with a foreign key to the map table (if the coordinates are continuous, the id can be y * map_width + x).

This topic is closed to new replies.

Advertisement