Map

From GPWiki

Files:GUITutorial_warn.gif The Game Programming Wiki has moved! Files:GUITutorial_warn.gif

The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server.

However, the GPWiki forums are still active! Come say hello.

There are two main definitions of Maps within Game Programming.

Contents

Map - Game Content

Maps are files used in games to define the layout of a playable area in a game program. These files contain the data defining the area/level in a custom data format. In real-time, the program will read the file and interpret its contents to get the number, positions, orientations and other data on objects within the game.

The advantage of this is that the data can be easily manipulated by a non-programmer using an external tool (whether by an artist during development or by modders after the product is released). It also makes the content easier to manage when it is not all hard-coded.

Map - Programming

A map in programming is a one-to-many key-value relationship between different objects. A map is an abstract data structure that can have any implementation. In essence, a map stores some values. These values can be any type of object.

The values are entered with a key. The key is then used to determine which value the Map should get when asked to retrieve a value. The key is often a string but can be any object. If the key is an object, the Map may compare the memory locations of the objects to see if they are the same or there may be a polymorphic reference to a compare method.

Common Functions of Maps

These are some common uses of Maps:-

Localisation
Instead of using strings when displaying words in a GUI, you can create a map that maps symbols (e.g. the string "STRING_ERROR_MESSAGE") to values that are strings. To use a string, you retrieve them from the map using the symbol as a key. by doing this you can create a map for each different language you want the program to support and load different maps depending on the currently selected language. This means coders can work on a program without being confused by different langauges and translaters can use external tools to modify the languages strings without knowing programming. Also the localisation data is kept in the one place rather than have strings sprinkled throughout the code.

Examples of Maps

These are some common uses of Maps:-

Python Dictionaries
These are a native implementation of Maps on Python to allow easy use of Maps with little fuss.