Page 1 of 1

How Are Map Systems Set Up In Databases?

Posted: Sun Jul 14, 2013 10:33 pm
by Verahta
How are map systems set up in the database? I know with abstraction between the DB and the front-end you can display it pretty much however you want, but how should one design/arrange a map system in the database?

What are some of the methods for different types of travel in games? My question is more for the point and click type of travel in a game map than a real-time environment.

Re: How Are Map Systems Set Up In Databases?

Posted: Sun Jul 14, 2013 11:50 pm
by Jackolantern
If it is tile-based 2D, a common way to store maps is in multidimensional arrays, like so:

Code: Select all

$map = array
  (
  array(0, 0, 1, 2, 0, 0, 3, 1, 2, 0, 0),
  array(0, 1, 2, 1, 0, 0, 1, 0, 0, 2, 0),
  array(1, 2, 0, 0, 1, 1, 0, 0, 0, 1, 2)
  ); 
Where each number represents a tile in your tilesheet. Obviously the numbers can go up much higher, and then run through letters, ASCII codes, etc. depending on how many tiles you have.

This can be altered to fit non-tilebased 2D maps as well.

Re: How Are Map Systems Set Up In Databases?

Posted: Mon Jul 15, 2013 6:47 am
by a_bertrand
All depends what you want to save, how and what you want to do with them.

Multiple options (will give only a few here):

1) As Jack stated a 2D grid (or 1D grid with width*height all in one long row) can be used, at the cost of having max 1 item / block / tile or whatever per cell, and the fact you can't have something not fully on the cell (like shifted a bit over 2 cells).
2) Same as 1) yet instead of storing all you compress it, like with a RLE (Run Lenght Encoding), which may saves you a lot of space (I did that for NEaB)
3) Same as 1, but have multiple layers, one for the tiles, one for the objects, one for monsters or effects etc...
4) If the map is not fully populated, use instead an array of location => object which would describe only what's there, that would allow you to store multiple things on the same location too as well have fractional positions
5) Voxel map data (for 3D worlds like minecraft), where the map is a 3D structure map[x][y][z] for example
6) If the world is mostly procedurally generated store only the difference between what's procedurally generated and what you want on it. That's what I use in cubicverse. That would allow you to have an infinite sized world, and yet do not crash your DB due to the size ;)

Should give you enough hints. Anyhow as always, you should describe more what YOU need such that we can help you more with what can fit your needs. What I use as map could be totally useless to you, as you may have something totally different in mind.

Re: How Are Map Systems Set Up In Databases?

Posted: Mon Jul 15, 2013 8:01 am
by Jackolantern
Kind of an expansion on #4 Bertrand mentioned, I believe there is a technique related to that (or it may even be what he meant) called an "offset map". This is where you can basically just set an image or color as the map background, and then you create an object or array that contains the actual coordinates of the element, and then what the element actually is. That is what I used for a map maker I made and released some years back here.

You can also combine that with the standard 2D array method and simply use the offset map for elements that don't line up with the tiles.

Re: How Are Map Systems Set Up In Databases?

Posted: Mon Jul 15, 2013 8:00 pm
by Verahta
Knowing what I need is part of the problem, I don't know yet how I want to do it. My game is going to have multiple locations, but you move differently depending what... part or 'layer' you are on. I'm not sure layer is a good word, but let me show you what I mean. My game takes place in space so this is what I currently have written down:

A universe with some galaxies. Now the galaxies are divided up into sections like this:

galaxy > quadrant > sectors/parsecs > systems/open space > grids, which are the bottom 'layer' of the map system within whatever piece of space or system you jumped/warped to.

Basically, you will be able to FTL/jump/warp long distances to get from a far away section to another, and this will be simply putting coordinates into your jump location (or by clicking down to where you want to go and clicking on the landing spot to automatically add the coordinates to your "jump computer" or whatever, I don't have a name for that yet). And you travel which will take a few minutes or something if it's a very long distance.

And the lowest 'level' of the map system, the grid, will be where you use sublight speed and you will move around with either arrows clicking or by clicking parallel/adjacent grids with your mouse. This is also where a radar (depending on what type/quality of your radar) will show friendly, neutral, and enemy ships or stations in nearby "squares" on the grid.

My game is not 3D or 2D, there already exists games like that (EVE, Dark Orbit, and a billion others) but rather it will be more like a cross between real-time and text based. For combat there will be icons on the radar/viewer and a list of ships in range, and by clicking on them it opens a smalls screen with the ships picture on it with info and actions (like attack, scan, etc).

Anyways I'm getting off-topic here. My point is I need to make a map system that is mouse click based for the lowest level/layer. I guess thinking about it now, the upper layers might not even exist except as abstraction layers basically, I just need them to simulate the idea of a vast universe to roam around in.

I don't know, I'm working on other parts of the game because I have no idea yet how to do my map system haha.

Re: How Are Map Systems Set Up In Databases?

Posted: Tue Jul 16, 2013 12:25 am
by Jackolantern
Sorry, I didn't necessarily mean your game being 2D or 3D, but your maps. Your map system sounds to me to be 2D. All the levels above grids are just groupings of larger sets of grids, right? If so, then it is 2D. Either arrays would work fine, or even just use db tables where the fields are Y and the rows are X of each different grid (if this is more of a PBBG and the db won't be getting over hit; if each player is changing grids every second or two, you would need to find a way to do it in memory).

Re: How Are Map Systems Set Up In Databases?

Posted: Tue Jul 16, 2013 12:57 am
by Verahta
Yes it will be a PBBG.

I was thinking of learning about Node and Socket because I do want people to move and do actions in "real-time" even if it's not a 3D game, but picture/text based. That said, I do want a "live" window with icons moving around that represent objects in the area. But I think that will be a type of "view screen" rather than the navigation/map.

Here are similar examples to what I plan to create for the "live" view screen, but obviously an original design/implementation. I need a window that live updates with icons that represent other players in the same map grid. I would need Node/Socket for this right?

Image

Image

Re: How Are Map Systems Set Up In Databases?

Posted: Tue Jul 16, 2013 1:02 am
by Jackolantern
You don't need it (it is doable in .NET, Java, Python, etc., but not really in PHP), but node makes it a lot easier to do real-time, to the point of almost being trivial ;)

Re: How Are Map Systems Set Up In Databases?

Posted: Tue Jul 16, 2013 1:38 am
by Verahta
I'm going to learn it then, as the languages I'm already focusing my efforts on are the standard web scripting and then PHP/MySQL, Python, and JS/Jquery. So it makes sense to throw in AJAX and then Node and Socket.

I was considering Java, but that would really just be for learning programming concepts and taking computer science courses so it can wait.

Re: How Are Map Systems Set Up In Databases?

Posted: Tue Jul 16, 2013 4:52 am
by Jackolantern
If you are going to college for computer science, you will probably be living, breathing and eating Java, so, yeah, you can hold off on that one :lol:

However, I will say that Java EE is an interesting route for web development. I think I am going to be studying it in school in the next semester or two, but I have had interest in it for a while. It is extremely different than most other web development platforms, but that difference is what makes it so appealing for enterprise development for making things like intranet websites and web-based tools that interface with hardware, such as web tools to control phone systems, etc. "Servlets" are basically like little programs that are run in Java to produce HTML output. There is a nice web socket platform for Java called jWebSocket that has fallbacks somewhat like Socket.io. But again, if you are only familiar with languages like PHP, Node, and others, Java Servlet programming will be very strange. But I think there is a lot of potential there. I just added the first Servlet-based PBBG engine I have ever seen to the big PBBG engine list the other day.