src/map.cpp
branchcpp_gui
changeset 6303 84c215fc8eb8
parent 6285 187e3ef04cc9
child 6308 646711c5feaa
child 6719 4cc327ad39d5
child 6987 b0f13039bda2
equal deleted inserted replaced
6302:bd80897189ba 6303:84c215fc8eb8
    20 uint _map_size_x;
    20 uint _map_size_x;
    21 uint _map_size_y;
    21 uint _map_size_y;
    22 uint _map_tile_mask;
    22 uint _map_tile_mask;
    23 uint _map_size;
    23 uint _map_size;
    24 
    24 
    25 Tile* _m = NULL;
    25 Tile *_m = NULL;
       
    26 TileExtended *_me = NULL;
    26 
    27 
    27 
    28 
    28 void AllocateMap(uint size_x, uint size_y)
    29 void AllocateMap(uint size_x, uint size_y)
    29 {
    30 {
    30 	/* Make sure that the map size is within the limits and that
    31 	/* Make sure that the map size is within the limits and that
    42 	_map_size_y = size_y;
    43 	_map_size_y = size_y;
    43 	_map_size = size_x * size_y;
    44 	_map_size = size_x * size_y;
    44 	_map_tile_mask = _map_size - 1;
    45 	_map_tile_mask = _map_size - 1;
    45 
    46 
    46 	free(_m);
    47 	free(_m);
       
    48 	free(_me);
       
    49 
    47 	_m = CallocT<Tile>(_map_size);
    50 	_m = CallocT<Tile>(_map_size);
    48 
    51  	_me = CallocT<TileExtended>(_map_size);
    49 	/* XXX TODO handle memory shortage more gracefully */
    52 
    50 	if (_m == NULL) error("Failed to allocate memory for the map");
    53  	/* XXX @todo handle memory shortage more gracefully
       
    54  	 * Maybe some attemps could be made to try with smaller maps down to 64x64
       
    55  	 * Maybe check for available memory before doing the calls, after all, we know how big
       
    56  	 * the map is */
       
    57 	if ((_m == NULL) || (_me == NULL)) error("Failed to allocate memory for the map");
    51 }
    58 }
    52 
    59 
    53 
    60 
    54 #ifdef _DEBUG
    61 #ifdef _DEBUG
    55 TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
    62 TileIndex TileAdd(TileIndex tile, TileIndexDiff add,