map.h
author tron
Fri, 07 Jan 2005 17:40:23 +0000
changeset 927 28f45a22a564
parent 926 bd4312619522
child 955 25bc5b97e3e2
permissions -rw-r--r--
(svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
Now the whole source except map.c is independent of TILE_[XY]_BITS!
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     1
#ifndef MAP_H
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     2
#define MAP_H
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     3
927
28f45a22a564 (svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents: 926
diff changeset
     4
#define TILE_FROM_XY(x,y) (int)((((y) >> 4) << MapLogX()) + ((x) >> 4))
28f45a22a564 (svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents: 926
diff changeset
     5
#define TILE_XY(x,y) (int)(((y) << MapLogX()) + (x))
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     6
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
     7
#define TILE_MASK(x) (int)((x) & ((1 << (MapLogX() + MapLogY())) - 1))
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
     8
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
     9
extern byte   _map_type_and_height[];
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    10
extern byte   _map5[];
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    11
extern byte   _map3_lo[];
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    12
extern byte   _map3_hi[];
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    13
extern byte   _map_owner[];
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    14
extern uint16 _map2[];
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    15
extern byte   _map_extra_bits[];
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
    16
689
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    17
// binary logarithm of the map size, try to avoid using this one
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    18
static inline uint MapLogX(void)  { extern uint _map_log_x; return _map_log_x; }
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    19
static inline uint MapLogY(void)  { extern uint _map_log_y; return _map_log_y; }
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    20
/* The size of the map */
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    21
static inline uint MapSizeX(void) { return 1 << MapLogX(); }
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    22
static inline uint MapSizeY(void) { return 1 << MapLogY(); }
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    23
/* The maximum coordinates */
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    24
static inline uint MapMaxX(void) { return MapSizeX() - 1; }
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    25
static inline uint MapMaxY(void) { return MapSizeY() - 1; }
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    26
/* The number of tiles in the map */
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    27
static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); }
1412bc834a8d (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    28
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    29
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    30
typedef uint16 TileIndex;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    31
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    32
static inline uint TileX(TileIndex tile)
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    33
{
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    34
	return tile & MapMaxX();
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    35
}
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    36
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    37
static inline uint TileY(TileIndex tile)
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    38
{
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    39
	return tile >> MapLogX();
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    40
}
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    41
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
    42
900
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    43
typedef int16 TileIndexDiff;
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    44
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    45
typedef struct TileIndexDiffC {
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    46
	int16 x;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    47
	int16 y;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    48
} TileIndexDiffC;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    49
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    50
static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    51
{
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    52
	return (tidc.y << MapLogX()) + tidc.x;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    53
}
900
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    54
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    55
static inline TileIndexDiff TileOffsByDir(uint dir)
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    56
{
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    57
	extern const TileIndexDiffC _tileoffs_by_dir[4];
900
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    58
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    59
	assert(dir < lengthof(_tileoffs_by_dir));
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    60
	return ToTileIndexDiff(_tileoffs_by_dir[dir]);
900
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    61
}
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    62
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
    63
#endif