|
UFO: Alien Invasion
|
Random map assembly code More info on map-assembly can be found at: http://ufoai.org/wiki/index.php/Mapping/Random_map_assembly. More...

Go to the source code of this file.
Data Structures | |
| class | Tile |
| Stores the parsed data for a map tile. (See *.ump files). More... | |
| class | TileSet |
| A list of tiles with the same size and neighbouring requirements to randomly pick from. More... | |
| class | Assembly |
| Stores the parsed data of an assembly definition. See *.ump files. More... | |
| struct | mToPlace_t |
| Defines a tile to place. More... | |
| struct | mPlaced_t |
| Defines a placed tile. More... | |
| class | MapInfo |
Macros | |
| #define | ASSEMBLE_THREADS 2 |
| #define | PRINT_RMA_PROGRESS 0 |
| print some debugging info | |
| #define | SORT_BY_SIZE 1 |
| place the biggest 'required' tiles first. Helps oriental a lot, but is bad for village. | |
| #define | RMA2_MAX_REC 64 |
| max # of recursions | |
| #define | RMA2_MAX_TILEPOS 1700 |
| max # of valid tile/position combinations | |
| #define | TCM 50 |
| tile code multiplier. For the various debug printfs we want a number that we can easily divide through (20, 50, 100,...) | |
| #define | GAPS 25 |
| the # of different tiles we can store for a gap | |
| #define | MAX_RANDOM_MAP_WIDTH 32 |
| #define | MAX_RANDOM_MAP_HEIGHT 32 |
| #define | MAX_MAPASSEMBLIES 32 |
| #define | MAX_TILETYPES 128 |
| #define | MAX_TILESETS 16 |
| #define | MAX_TILESETTILES 16 |
| #define | MAX_TILESIZE 16 |
| #define | MAX_FIXEDTILES 64 |
| #define | MAX_ASSEMBLY_SEEDS 32 |
| #define | ALL_TILES (0xfffffffeUL) |
| #define | IS_SOLID(x) |
| #define | ACW 6 /* ascii cell width */ |
| #define | ACH 3 /* ascii cell height */ |
| #define | MMW 13 /* map max width 13 means we support 12 */ |
| #define | MMH 13 /* map max height */ |
Functions | |
| static void | RandomList (const int n, short *list) |
Fills a list with random values between 0 and n. | |
| static unsigned long | tileMask (const char chr) |
| Convert to tile spec - normalize the characters. | |
| static void | SV_TileMaskToString (unsigned long m, char *str) |
| static void | SV_RmaPrintMap (const MapInfo *map) |
| static const TileSet * | SV_GetMapTileSet (const MapInfo *map, const char *tileSetName) |
| static const Tile * | SV_GetMapTile (const MapInfo *map, const char *tileName) |
| static bool | SV_ParseMapTileSet (const char *filename, const char **text, MapInfo *map, bool inherit) |
| Parsed a tileset definition out of the ump-files. | |
| static bool | SV_ParseMapTile (const char *filename, const char **text, MapInfo *map, bool inherit) |
| Parsed a tile definition out of the ump-files. | |
| static const char * | SV_GetCvarToken (const MapInfo *map, const Assembly *a, const char *token, const char *filename, const char **text, const char *errhead) |
| Tries to extract a tile name from a cvar - the cvar value must start with a '+'. | |
| static const char * | SV_GetTileFromTileSet (const MapInfo *map, const char *filename, const char **text, const Assembly *a) |
| static bool | SV_ParseAssemblySeeds (MapInfo *map, const char *filename, const char **text, Assembly *a) |
| Parses a list of working seeds to assemble this rma assembly. | |
| static void | SV_GetTilesFromTileSet (const MapInfo *map, const char *filename, const char **text, Assembly *a) |
| static bool | SV_ParseAssembly (MapInfo *map, const char *filename, const char **text, Assembly *a) |
| Parses an assembly block. | |
| static void | SV_CombineAlternatives (unsigned long *mapAlts, const unsigned long tileAlts) |
| Combines the alternatives/connection info of a map with a tile and sets the rating. | |
| static void | SV_ClearMap (MapInfo *map) |
| Reset the map to empty state. | |
| static bool | SV_FitTile (const MapInfo *map, const Tile *tile, const int x, const int y) |
| Checks if a given map-tile fits into the empty space (in a given location) of a map. | |
| static bool | SV_TestFilled (const MapInfo *map) |
| Checks if the map is completely filled. | |
| static void | SV_DumpPlaced (const MapInfo *map, int pl) |
| Debug function to dump the map location of a placed tile. | |
| static void | SV_AddTile (MapInfo *map, const Tile *tile, int x, int y, int idx, int pos) |
| Adds a new map-tile to an assembled map. Also adds the tile to the placed-tiles list. | |
| static void | SV_RemoveTile (MapInfo *map, int *idx, int *pos) |
| Rebuilds a assembled map up to the previous tile. | |
| static void | SV_BuildMapStrings (const MapInfo *map, char *asmTiles, char *asmPos, bool print) |
| Creates the mapstrings as known from the ufoconsole.log and optionally prints them. This can also be used to dump the progress of the RMA process. | |
| static unsigned long | SV_GapGetFlagsAtAbsPos (MapInfo *map, int tileCode, int mapW, int mapX, int mapY) |
| get the specs of a tile at map-x/y if it was placed where tileCode indicates | |
| static bool | SV_AddMissingTiles_r (MapInfo *map, int rec, int posListCnt, short myPosList[], const Tile *prevTile, int prevX, int prevY) |
| static bool | SV_GapListBuild (MapInfo *map, int tilePosListCnt) |
| Builds a list of map positions (gaps) and the tiles that can cover them. | |
| static bool | SV_GapCheckNeighbour (MapInfo *map, int tc1, int mapW, int mapH, int nx, int ny) |
| Find a tile that meets the requirements of tc1 at a given pos. | |
| static int | SV_GapListReduce (MapInfo *map) |
| Tries to find tiles that exclude all of their neighbours This is called only once, before recursion starts. So we can safely (ab)use the posTileList space for recursion 1. | |
| static bool | SV_AddMissingTiles (MapInfo *map) |
| Tries to fill the missing tiles of the current map. While the 2010 algo used a 'by chance'-algo, this algo does a full tree search. Example: After placing the fixed and required tiles on a 8x8 map, we have say 32 places not yet covered by tiles. If there are 10 different tiles for each gap, we can have up to have 10^32 constellations to try. That's about one fantastillion. Impossible. Fortunately, there are usually many solutions to this puzzle. And we only need to find one working solution. But on some maps eg. 'forest large' with it's little brook, there are fewer solutions, so the search can take longer. In order to complete the search in a reasonable time, this algo uses several strategies: | |
| static bool | SV_AddMapTiles (MapInfo *map) |
| Tries to build the map There are 3 categories of tiles: | |
| static void | SV_PrepareTilesToPlace (MapInfo *map) |
| Prepare the list of tiles to place. | |
| static int | SV_AssemblyThread (void *data) |
| The main function for the threads that try to create random map assemblies in parallel. | |
| static int | SV_ParallelSearch (MapInfo *map) |
| Spawn ASSEMBLE_THREADS threads to try and assemble a map. The first map complete gets returned. Allocates a new copy of the map for each thread, and frees it at the end. Uses a timeout (initially 5 seconds). If the spawned threads have not completed by the timeout, they are restarted, with double the timeout. | |
| static void | SV_ParseUMP (const char *name, char *entityString, MapInfo *map, bool inherit) |
| Parses an ump file that contains the random map definition. | |
| static int | cmpTileAreaSize (const void *a, const void *b) |
| static MapInfo * | SV_DoMapAssemble (MapInfo *map, const char *assembly, char *asmTiles, char *asmPos, const unsigned int seed, bool print) |
| static MapInfo * | SV_AssembleMap_ (const char *mapTheme, const char *assembly, char *asmTiles, char *asmPos, char *entityString, const unsigned int seed, bool print) |
| Assembles a "random" map and parses the *.ump files for assembling the "random" maps and places the 'fixed' tiles. For a more detailed description of the whole algorithm see SV_AddMapTiles. | |
| int | SV_AssembleMap (const char *mapTheme, const char *assembly, char *asmTiles, char *asmPos, char *entityString, const unsigned int seed, bool print) |
| int | SV_AssembleMapAndTitle (const char *mapTheme, const char *assembly, char *asmTiles, char *asmPos, char *entityString, const unsigned int seed, bool print, char *asmTitle) |
| void | SV_PrintAssemblyStats (const char *mapTheme, const char *asmName) |
Variables | |
| static short | posTileList [RMA2_MAX_REC][RMA2_MAX_TILEPOS] |
| array of working random tile positions, 50 recursions | |
| static short | gapList [MAX_RANDOM_MAP_HEIGHT][MAX_RANDOM_MAP_HEIGHT][GAPS+1] |
| for every x/y we can store the tiles that can cover that place here | |
| static int | minMissingSolids |
| static SDL_sem * | mapSem |
| static SDL_cond * | mapCond |
| static SDL_mutex * | mapLock |
| static Uint32 | threadID |
| static int | availableTiles [MAX_TILETYPES][2] |
| Select the next tile to place and place it (recursively). | |
Random map assembly code More info on map-assembly can be found at: http://ufoai.org/wiki/index.php/Mapping/Random_map_assembly.
Definition in file sv_rma.cpp.
| #define ACH 3 /* ascii cell height */ |
Definition at line 291 of file sv_rma.cpp.
Referenced by SV_RmaPrintMap().
| #define ACW 6 /* ascii cell width */ |
Definition at line 290 of file sv_rma.cpp.
Referenced by SV_RmaPrintMap().
| #define ALL_TILES (0xfffffffeUL) |
Definition at line 218 of file sv_rma.cpp.
Referenced by SV_ClearMap(), SV_CombineAlternatives(), SV_TileMaskToString(), and tileMask().
| #define ASSEMBLE_THREADS 2 |
Definition at line 37 of file sv_rma.cpp.
Referenced by SV_ParallelSearch().
| #define GAPS 25 |
the # of different tiles we can store for a gap
Definition at line 64 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles_r(), SV_GapCheckNeighbour(), SV_GapListBuild(), and SV_GapListReduce().
| #define IS_SOLID | ( | x | ) |
Definition at line 219 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles_r(), SV_CombineAlternatives(), SV_DumpPlaced(), SV_FitTile(), SV_GapCheckNeighbour(), SV_GapListBuild(), SV_ParseMapTile(), SV_RmaPrintMap(), and SV_TestFilled().
| #define MAX_ASSEMBLY_SEEDS 32 |
Definition at line 102 of file sv_rma.cpp.
| #define MAX_FIXEDTILES 64 |
Definition at line 83 of file sv_rma.cpp.
Referenced by SV_ParseAssembly().
| #define MAX_MAPASSEMBLIES 32 |
Definition at line 76 of file sv_rma.cpp.
Referenced by SV_ParseUMP().
| #define MAX_RANDOM_MAP_HEIGHT 32 |
Definition at line 66 of file sv_rma.cpp.
Referenced by SV_AddMapTiles(), SV_AddMissingTiles(), SV_AddTile(), SV_ClearMap(), SV_DoMapAssemble(), SV_ParseAssembly(), and SV_RemoveTile().
| #define MAX_RANDOM_MAP_WIDTH 32 |
Definition at line 65 of file sv_rma.cpp.
Referenced by SV_AddMapTiles(), SV_AddMissingTiles(), SV_AddTile(), SV_ClearMap(), SV_DoMapAssemble(), SV_FitTile(), SV_ParseAssembly(), and SV_RemoveTile().
| #define MAX_TILESETS 16 |
Definition at line 80 of file sv_rma.cpp.
Referenced by SV_ParseUMP().
| #define MAX_TILESETTILES 16 |
Definition at line 81 of file sv_rma.cpp.
Referenced by SV_ParseMapTileSet().
| #define MAX_TILESIZE 16 |
Definition at line 82 of file sv_rma.cpp.
Referenced by SV_FitTile(), and SV_ParseMapTile().
| #define MAX_TILETYPES 128 |
note: MAX_TILETYPES mostly limits the # of tiles that can be parsed. The # used in an assemly is roughly limited to RMA2_MAX_REC (+fixed + required tiles).
Definition at line 79 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles(), and SV_ParseUMP().
| #define MMH 13 /* map max height */ |
Definition at line 293 of file sv_rma.cpp.
Referenced by SV_RmaPrintMap().
| #define MMW 13 /* map max width 13 means we support 12 */ |
Definition at line 292 of file sv_rma.cpp.
Referenced by SV_RmaPrintMap().
| #define PRINT_RMA_PROGRESS 0 |
print some debugging info
Definition at line 39 of file sv_rma.cpp.
| #define RMA2_MAX_REC 64 |
| #define RMA2_MAX_TILEPOS 1700 |
max # of valid tile/position combinations
Definition at line 57 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles(), and SV_AddMissingTiles_r().
| #define SORT_BY_SIZE 1 |
place the biggest 'required' tiles first. Helps oriental a lot, but is bad for village.
Definition at line 41 of file sv_rma.cpp.
| #define TCM 50 |
tile code multiplier. For the various debug printfs we want a number that we can easily divide through (20, 50, 100,...)
Definition at line 59 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles(), SV_AddMissingTiles_r(), SV_GapGetFlagsAtAbsPos(), and SV_GapListBuild().
Definition at line 2050 of file sv_rma.cpp.
Referenced by SV_DoMapAssemble().
Fills a list with random values between 0 and n.
| [in] | n | Size of the list |
| [out] | list | The list to fill with random values |
Definition at line 203 of file sv_rma.cpp.
References i.
Referenced by SV_AddMapTiles(), and SV_AddMissingTiles().
|
static |
Tries to build the map There are 3 categories of tiles:
| map | All we know about the map to assemble |
Definition at line 1698 of file sv_rma.cpp.
References Com_Error(), Com_Printf(), Assembly::dx, Assembly::dy, ERR_DROP, MapInfo::getCurrentAssembly(), MapInfo::getName(), Assembly::id, mPlaced_t::idx, mapSem, mapStr, MAX_RANDOM_MAP_HEIGHT, MAX_RANDOM_MAP_WIDTH, MapInfo::mPlaced, MapInfo::mToPlace, MapInfo::numPlaced, Assembly::numSeeds, MapInfo::numToPlace, posStr, RandomList(), MapInfo::retryCnt, Assembly::size, SV_AddMissingTiles(), SV_AddTile(), SV_BuildMapStrings(), SV_FitTile(), SV_RemoveTile(), sv_rma, sv_rmadisplaythemap, SV_RmaPrintMap(), sv_threads, and Assembly::width.
Referenced by SV_AssemblyThread(), and SV_DoMapAssemble().
|
static |
Tries to fill the missing tiles of the current map. While the 2010 algo used a 'by chance'-algo, this algo does a full tree search. Example: After placing the fixed and required tiles on a 8x8 map, we have say 32 places not yet covered by tiles. If there are 10 different tiles for each gap, we can have up to have 10^32 constellations to try. That's about one fantastillion. Impossible. Fortunately, there are usually many solutions to this puzzle. And we only need to find one working solution. But on some maps eg. 'forest large' with it's little brook, there are fewer solutions, so the search can take longer. In order to complete the search in a reasonable time, this algo uses several strategies:
| map | All we know about the map to assemble |
false if the tiles does not fit, true if the map could be filled. build a list of all positions of the map and all the tiles that fit there
try to reduce the number of available options
Definition at line 1572 of file sv_rma.cpp.
References Com_Printf(), Assembly::dx, Assembly::dy, gapList, MapInfo::getCurrentAssembly(), Assembly::height, i, m, mapStr, MAX_RANDOM_MAP_HEIGHT, MAX_RANDOM_MAP_WIDTH, MAX_TILETYPES, minMissingSolids, MapInfo::mToPlace, MapInfo::numPlaced, MapInfo::numToPlace, posStr, posTileList, RandomList(), RMA2_MAX_TILEPOS, Assembly::size, SV_AddMissingTiles_r(), SV_BuildMapStrings(), SV_FitTile(), SV_GapListBuild(), SV_GapListReduce(), SV_TestFilled(), TCM, and Assembly::width.
Referenced by SV_AddMapTiles().
|
static |
calculate the area of the tile placed by the previous recursion
circle through the old list of available tile positions and store the remaining ones in the static array
try to reduce the # of calls to SV_FitTile by checking only those gaps affected by the placement of the previous tile
initialize the list of gaps
if the remaining tiles are simply not enough to cover the gaps, bail
check how well the remaining tiles can cover the gaps
if we find a gap that NO tile can cover, bail
if there is a gap that only ONE tile can cover, try that. If it doesn't work out, we're done.
if there is a gap that only TWO tiles can cover, try those two. If it doesn't work out, we're done. Then try with THREE and so on.
now try each of the remaining positions, that is, those that have more than GAPS alternatives. Rarely happens.
Definition at line 1186 of file sv_rma.cpp.
References Tile::area, availableTiles, mToPlace_t::cnt, Com_Printf(), MapInfo::curMap, gapList, GAPS, MapInfo::getCurrentAssembly(), Tile::h, Assembly::height, i, IS_SOLID, MapInfo::lineFlags, mToPlace_t::max, minMissingSolids, MapInfo::mToPlace, posTileList, RMA2_MAX_REC, RMA2_MAX_TILEPOS, Tile::spec, SV_AddMissingTiles_r(), SV_AddTile(), SV_FitTile(), SV_RemoveTile(), sv_rmadisplaythemap, SV_RmaPrintMap(), SV_TestFilled(), TCM, mToPlace_t::tile, Tile::w, and Assembly::width.
Referenced by SV_AddMissingTiles(), and SV_AddMissingTiles_r().
Adds a new map-tile to an assembled map. Also adds the tile to the placed-tiles list.
| [in,out] | map | The map that will get the tile. Modified in place. |
| [in] | tile | The tile to add to the map. |
| [in] | x,y | The position in the map where the tile should be placed. |
| [in] | idx | The index of the placement algorithm. |
| [in] | pos | The position of the placement algorithm. |
Definition at line 1028 of file sv_rma.cpp.
References mToPlace_t::cnt, Com_Error(), MapInfo::curMap, Assembly::dx, Assembly::dy, ERR_DROP, MapInfo::getCurrentAssembly(), Tile::h, mPlaced_t::idx, MAX_RANDOM_MAP_HEIGHT, MAX_RANDOM_MAP_WIDTH, MapInfo::mPlaced, MapInfo::mToPlace, MapInfo::numPlaced, mPlaced_t::pos, Tile::spec, SV_CombineAlternatives(), mPlaced_t::tile, Tile::w, mPlaced_t::x, and mPlaced_t::y.
Referenced by SV_AddMapTiles(), SV_AddMissingTiles_r(), and SV_DoMapAssemble().
| int SV_AssembleMap | ( | const char * | mapTheme, |
| const char * | assembly, | ||
| char * | asmTiles, | ||
| char * | asmPos, | ||
| char * | entityString, | ||
| const unsigned int | seed, | ||
| bool | print ) |
Definition at line 2212 of file sv_rma.cpp.
References Mem_Free, MapInfo::numPlaced, and SV_AssembleMap_().
Referenced by TEST_F(), TEST_F(), TEST_F(), and RandomMapAssemblyTest::testAssembly().
|
static |
Assembles a "random" map and parses the *.ump files for assembling the "random" maps and places the 'fixed' tiles. For a more detailed description of the whole algorithm see SV_AddMapTiles.
| [in] | mapTheme | The name of the map (ump) file to parse |
| [in] | assembly | The random map assembly that should be used from the given rma |
| [out] | asmTiles | The output string of the random map assembly that contains all the map tiles that should be assembled. The order is the same as in the asmPos string. Each of the map tiles in this string has a corresponding entry in the pos string, too. |
| [out] | asmPos | The pos string for the assembly. For each tile from the asmTiles string this string contains three coordinates for shifting the given tile names. |
| [out] | entityString | An entity string that is used for all map tiles. Parsed from the ump. |
| [in] | seed | random seed to use (for cunit tests). If 0, the called functions can use their own seed setting. |
| [in] | Whether or not extended output should be printed |
Definition at line 2167 of file sv_rma.cpp.
References MapInfo::asmIdx, MapInfo::assemblies, Com_DPrintf(), Com_Error(), Com_Printf(), DEBUG_SERVER, ERR_DROP, MapInfo::getName(), i, Assembly::id, Mem_AllocType, MapInfo::numAssemblies, MapInfo::numTiles, Q_streq, Q_strvalid, MapInfo::setName(), SV_DoMapAssemble(), and SV_ParseUMP().
Referenced by SV_AssembleMap(), and SV_AssembleMapAndTitle().
| int SV_AssembleMapAndTitle | ( | const char * | mapTheme, |
| const char * | assembly, | ||
| char * | asmTiles, | ||
| char * | asmPos, | ||
| char * | entityString, | ||
| const unsigned int | seed, | ||
| bool | print, | ||
| char * | asmTitle ) |
Definition at line 2220 of file sv_rma.cpp.
References MapInfo::getCurrentAssemblyTitle(), Mem_Free, MapInfo::numPlaced, and SV_AssembleMap_().
Referenced by SV_Map().
The main function for the threads that try to create random map assemblies in parallel.
| data | The MapInfo structure local to this thread. Should be initialized by memcpy-ing the actual map into new memory. Not thread-safe to read or write, this thread assumes that nobody else will access the given copy of the map before the thread ends. It is the responsibility of the caller to free the map, if needed, after the thread has died and been collected. |
mapSem semaphore, signaling that someone else has finished first, or timeout occurred. Definition at line 1835 of file sv_rma.cpp.
References Com_SetRandomSeed(), data, mapCond, mapLock, mapSem, MapInfo::retryCnt, SV_AddMapTiles(), and threadID.
Referenced by SV_ParallelSearch().
Creates the mapstrings as known from the ufoconsole.log and optionally prints them. This can also be used to dump the progress of the RMA process.
| [in] | map | All we know about the map to assemble |
| [out] | asmTiles | The output string of the random map assembly that contains all the map tiles that should be assembled. The order is the same as in the asmPos string. Each of the map tiles in this string has a corresponding entry in the pos string, too. |
| [out] | asmPos | The pos string for the assembly. For each tile from the asmTiles string asmPos contains three coordinates for shifting the given tile names. |
| [in] | Print out the mapStrings or not |
Definition at line 1126 of file sv_rma.cpp.
References Com_Printf(), MapInfo::getCurrentAssembly(), Assembly::height, i, Tile::id, MAX_TILESTRINGS, MAX_TOKEN_CHARS, MapInfo::mPlaced, MapInfo::numPlaced, Q_strcat(), sv_dumpmapassembly, SV_DumpPlaced(), mPlaced_t::tile, Assembly::width, mPlaced_t::x, and mPlaced_t::y.
Referenced by SV_AddMapTiles(), SV_AddMissingTiles(), and SV_DoMapAssemble().
Reset the map to empty state.
Definition at line 910 of file sv_rma.cpp.
References ALL_TILES, MapInfo::curMap, MAX_RANDOM_MAP_HEIGHT, and MAX_RANDOM_MAP_WIDTH.
Referenced by SV_DoMapAssemble(), and SV_RemoveTile().
Combines the alternatives/connection info of a map with a tile and sets the rating.
| [in,out] | mapAlts | Pointer to the alternatives info field of the map which will be updated. |
| [in] | tileAlts | Pointer to the alternatives info field of the tile. |
Definition at line 892 of file sv_rma.cpp.
References ALL_TILES, and IS_SOLID.
Referenced by SV_AddTile(), and SV_RemoveTile().
|
static |
Definition at line 2060 of file sv_rma.cpp.
References MapInfo::basePath, cmpTileAreaSize(), Com_DPrintf(), Com_Printf(), Com_SetRandomSeed(), Com_sprintf(), DEBUG_SERVER, Assembly::fT, Assembly::fX, Assembly::fY, MapInfo::getCurrentAssembly(), Assembly::height, i, Assembly::id, MAX_RANDOM_MAP_HEIGHT, MAX_RANDOM_MAP_WIDTH, Mem_Free, MapInfo::mTile, MapInfo::mToPlace, Assembly::numFixed, MapInfo::numPlaced, Assembly::numSeeds, MapInfo::numToPlace, MapInfo::retryCnt, Assembly::seeds, SV_AddMapTiles(), SV_AddTile(), SV_BuildMapStrings(), SV_ClearMap(), SV_DoMapAssemble(), SV_ParallelSearch(), SV_PrepareTilesToPlace(), sv_rma, sv_threads, and Assembly::width.
Referenced by SV_AssembleMap_(), and SV_DoMapAssemble().
Debug function to dump the map location of a placed tile.
Definition at line 992 of file sv_rma.cpp.
References Com_Printf(), MapInfo::getCurrentAssembly(), Assembly::height, Tile::id, IS_SOLID, MapInfo::mPlaced, Tile::spec, mPlaced_t::tile, Assembly::width, mPlaced_t::x, and mPlaced_t::y.
Referenced by SV_BuildMapStrings().
Checks if a given map-tile fits into the empty space (in a given location) of a map.
| [in,out] | map | All we know about the map to assemble |
| [in] | tile | The tile definition that should be fitted into the map. |
| [in] | x,y | The position in the map where the tile is supposed to be placed/checked. |
true if the tile fits, false if the tile does not fit or an error was encountered. Definition at line 926 of file sv_rma.cpp.
References MapInfo::curMap, Assembly::dx, Assembly::dy, MapInfo::getCurrentAssembly(), Tile::h, Assembly::height, IS_SOLID, m, MAX_RANDOM_MAP_WIDTH, MAX_TILESIZE, Tile::spec, Tile::w, and Assembly::width.
Referenced by SV_AddMapTiles(), SV_AddMissingTiles(), and SV_AddMissingTiles_r().
Find a tile that meets the requirements of tc1 at a given pos.
| map | All we know about the map to assemble |
| tc1 | encoded tile and position |
| mapW | width of the map. Needed to decode tc1 |
| mapH | height of the map. Needed to validate ny |
| nx | x of the absolute map position to investigate |
| ny | y of the absolute map position to investigate |
true if no matching tile was found circle through the tiles that cover this gap
Definition at line 1455 of file sv_rma.cpp.
References gapList, GAPS, IS_SOLID, and SV_GapGetFlagsAtAbsPos().
Referenced by SV_GapListReduce().
|
static |
get the specs of a tile at map-x/y if it was placed where tileCode indicates
| map | All we know about the map to assemble |
| tileCode | encoded tile and position |
| mapW | width of the map. Needed to decode tileCode |
| mapX | x of the gap |
| mapY | y of the gap |
Definition at line 1161 of file sv_rma.cpp.
References MapInfo::mToPlace, Tile::spec, TCM, and mToPlace_t::tile.
Referenced by SV_GapCheckNeighbour().
Builds a list of map positions (gaps) and the tiles that can cover them.
| map | All we know about the map to assemble |
| tilePosListCnt | The number of remaining possible tile positions |
initialize the list of gaps
if we find a gap that NO tile can cover, bail
Definition at line 1400 of file sv_rma.cpp.
References MapInfo::curMap, gapList, GAPS, MapInfo::getCurrentAssembly(), Tile::h, Assembly::height, i, IS_SOLID, MapInfo::mToPlace, posTileList, Tile::spec, TCM, mToPlace_t::tile, Tile::w, and Assembly::width.
Referenced by SV_AddMissingTiles().
Tries to find tiles that exclude all of their neighbours This is called only once, before recursion starts. So we can safely (ab)use the posTileList space for recursion 1.
| map | All we know about the map to assemble |
number of tiles marked for elinimation
if there is a tile that doesn't match ANY of the tiles available for the adjacent gap we can eliminate it.
Definition at line 1500 of file sv_rma.cpp.
References gapList, GAPS, MapInfo::getCurrentAssembly(), Assembly::height, posTileList, SV_GapCheckNeighbour(), and Assembly::width.
Referenced by SV_AddMissingTiles().
|
static |
Tries to extract a tile name from a cvar - the cvar value must start with a '+'.
| [in,out] | map | All we know about the map to assemble |
| a | the assembly | |
| token | The cvar name | |
| filename | The ump filename | |
| text | The text buffer | |
| errhead | Error header |
nullptr if file has invalid format, the tilename of the cvar otherwise. Definition at line 572 of file sv_rma.cpp.
References Com_DPrintf(), Com_EParse(), Com_Error(), Com_Printf(), Cvar_FindVar(), Cvar_Set(), DEBUG_SERVER, ERR_DROP, i, Assembly::id, Tile::id, MapInfo::mTile, cvar_t::name, MapInfo::numTiles, Q_strncasecmp, and cvar_t::string.
Referenced by SV_ParseAssembly().
Definition at line 414 of file sv_rma.cpp.
References i, Tile::id, MapInfo::mTile, MapInfo::numTiles, and Q_streq.
Referenced by SV_GetTilesFromTileSet(), SV_ParseAssembly(), and SV_ParseMapTileSet().
Definition at line 403 of file sv_rma.cpp.
References i, TileSet::id, MapInfo::numTileSets, Q_streq, and MapInfo::tileSets.
Referenced by SV_GetTileFromTileSet(), and SV_GetTilesFromTileSet().
|
static |
Definition at line 616 of file sv_rma.cpp.
References Com_EParse(), Com_Error(), ERR_DROP, Assembly::id, TileSet::numTiles, SV_GetMapTileSet(), and TileSet::tiles.
Referenced by SV_ParseAssembly().
|
static |
Definition at line 672 of file sv_rma.cpp.
References Com_EParse(), Com_Error(), ERR_DROP, i, Assembly::id, TileSet::id, Assembly::max, Assembly::min, MapInfo::mTile, TileSet::numTiles, SV_GetMapTile(), SV_GetMapTileSet(), and TileSet::tiles.
Referenced by SV_ParseAssembly().
Spawn ASSEMBLE_THREADS threads to try and assemble a map. The first map complete gets returned. Allocates a new copy of the map for each thread, and frees it at the end. Uses a timeout (initially 5 seconds). If the spawned threads have not completed by the timeout, they are restarted, with double the timeout.
mapSem, a lock mapLock, and a condition mapCond. The semaphore is initially 1 (and reset to 1 every time there is a restart). The first thread that finishes, grabs the semaphore, to tell all other threads to abort. All threads test the semaphore, if it is 0, they abort. After the timeout, the main thread grabs the semaphore, to make everybody conclude, and then restarts them. The lock is used to protect writes to the threadID global variable, that holds the ID of the thread which finished, if any. It is also used to protect the conditional mapCond, used by the finished thread to notify the main() thread, so it can collect all threads and copy the final map back to the caller. The lock is locked by main() at all times, unless it is waiting on the conditional (with timeout). When an assembler thread finishes, it grabs the lock (which means main() is still waiting), writes its ID to threadID, signals main() and releases the lock. main() gets the signal after the lock is released, since the signal is protected by the lock, so there can be no race between finishing assembly and signaling main() for the assembler threads. When a timeout occurs, main() exits the conditional by grabbing the lock again. This will prevent any thread from exiting, even if it finishes between the time that main() timed out and the time it tries to get the semaphore. So, main() checks the semaphore to see if it is taken, and if so doesn't restart, despite the timeout. Definition at line 1884 of file sv_rma.cpp.
References ASSEMBLE_THREADS, Com_CreateThread(), Com_Printf(), i, mapCond, mapLock, mapSem, Mem_AllocType, Mem_Free, SV_AssemblyThread(), sv_threads, and threadID.
Referenced by SV_DoMapAssemble().
|
static |
Parses an assembly block.
| [in,out] | map | All we know about the map to assemble |
| [in] | filename | The name of the .UMP file, used in error messages |
| [out] | a | Pointer to the assembly to be initialized, must be allocated. |
| [in] | text | The text of the ump file to parse |
true if it was parsed, false if not. Definition at line 727 of file sv_rma.cpp.
References Com_EParse(), Com_Error(), Assembly::dx, Assembly::dy, ERR_DROP, Assembly::fT, Assembly::fX, Assembly::fY, Assembly::height, i, Assembly::id, Tile::id, Assembly::max, MAX_FIXEDTILES, MAX_RANDOM_MAP_HEIGHT, MAX_RANDOM_MAP_WIDTH, Assembly::min, MapInfo::mTile, Assembly::numFixed, OBJZERO, Q_streq, Q_strncpyz(), Assembly::size, SV_GetCvarToken(), SV_GetMapTile(), SV_GetTileFromTileSet(), SV_GetTilesFromTileSet(), sv_maxclients, SV_ParseAssemblySeeds(), Assembly::title, and Assembly::width.
Referenced by SV_ParseUMP().
|
static |
Parses a list of working seeds to assemble this rma assembly.
| [in,out] | map | All we know about the map to assemble |
| [in] | filename | The name of the .UMP file, used in error messages |
| [out] | a | Pointer to the assembly to be initialized, must be allocated. |
| [in] | text | The text of the ump file to parse |
true if it was parsed, false if not. Definition at line 644 of file sv_rma.cpp.
References Com_EParse(), Com_Printf(), Assembly::id, lengthof, Assembly::numSeeds, and Assembly::seeds.
Referenced by SV_ParseAssembly().
|
static |
Parsed a tile definition out of the ump-files.
Definition at line 488 of file sv_rma.cpp.
References Tile::area, Com_EParse(), Com_Printf(), Com_sprintf(), Tile::h, i, Tile::id, MapInfo::inheritBasePath, IS_SOLID, MAX_TILESIZE, MapInfo::mTile, MapInfo::numTiles, OBJZERO, Q_strncpyz(), Tile::spec, tileMask(), and Tile::w.
Referenced by SV_ParseUMP().
|
static |
Parsed a tileset definition out of the ump-files.
Definition at line 429 of file sv_rma.cpp.
References Com_EParse(), Com_Error(), Com_Printf(), Com_sprintf(), ERR_DROP, TileSet::id, MapInfo::inheritBasePath, MAX_TILESETTILES, TileSet::numTiles, MapInfo::numTileSets, OBJZERO, Q_strncpyz(), SV_GetMapTile(), TileSet::tiles, and MapInfo::tileSets.
Referenced by SV_ParseUMP().
Parses an ump file that contains the random map definition.
| [in] | name | The basename of the ump file (without extension) |
| [out] | map | The data structure to store the parsed data in |
| [in] | inherit | When true, this is called to inherit tile definitions |
| [out] | entityString | An entity string that is used for all map tiles. Parsed from the ump. from another ump file (no assemblies) |
Definition at line 1965 of file sv_rma.cpp.
References MapInfo::assemblies, MapInfo::basePath, Com_Error(), Com_GetBlock(), Com_Parse(), Com_Printf(), Com_SkipBlock(), Com_sprintf(), CS_ENTITYSTRING, ERR_DROP, FS_FreeFile(), FS_LoadFile(), MapInfo::inheritBasePath, length, MapInfo::lineFlags, MAX_MAPASSEMBLIES, MAX_QPATH, MAX_TILESETS, MAX_TILETYPES, name, MapInfo::numAssemblies, MapInfo::numTiles, MapInfo::numTileSets, Q_streq, Q_strncpyz(), SV_GetConfigStringLength(), SV_ParseAssembly(), SV_ParseMapTile(), SV_ParseMapTileSet(), SV_ParseUMP(), and tileMask().
Referenced by SV_AssembleMap_(), SV_ParseUMP(), and SV_PrintAssemblyStats().
Prepare the list of tiles to place.
Definition at line 1808 of file sv_rma.cpp.
References MapInfo::getCurrentAssembly(), i, Assembly::max, mToPlace_t::max, Assembly::min, mToPlace_t::min, MapInfo::mTile, MapInfo::mToPlace, MapInfo::numTiles, MapInfo::numToPlace, OBJZERO, and mToPlace_t::tile.
Referenced by SV_DoMapAssemble(), and SV_PrintAssemblyStats().
| void SV_PrintAssemblyStats | ( | const char * | mapTheme, |
| const char * | asmName ) |
Definition at line 2229 of file sv_rma.cpp.
References Tile::area, MapInfo::asmIdx, MapInfo::assemblies, Com_Printf(), Com_sprintf(), MapInfo::getCurrentAssembly(), Assembly::id, mToPlace_t::max, Mem_AllocType, mToPlace_t::min, MapInfo::mToPlace, MapInfo::numAssemblies, Assembly::numSeeds, MapInfo::numTiles, MapInfo::numToPlace, Q_streq, Assembly::size, SV_ParseUMP(), SV_PrepareTilesToPlace(), and mToPlace_t::tile.
Referenced by TEST_F().
Rebuilds a assembled map up to the previous tile.
| [in,out] | map | All we know about the map to assemble |
| [out] | idx | Pointer to the location to store the index field of the removed tile |
| [out] | pos | Pointer to the location to store the position field of the removed tile |
Definition at line 1073 of file sv_rma.cpp.
References mToPlace_t::cnt, MapInfo::curMap, Tile::h, i, mPlaced_t::idx, index, MAX_RANDOM_MAP_HEIGHT, MAX_RANDOM_MAP_WIDTH, MapInfo::mPlaced, MapInfo::mToPlace, MapInfo::numPlaced, mPlaced_t::pos, Tile::spec, SV_ClearMap(), SV_CombineAlternatives(), mPlaced_t::tile, Tile::w, mPlaced_t::x, and mPlaced_t::y.
Referenced by SV_AddMapTiles(), and SV_AddMissingTiles_r().
Definition at line 294 of file sv_rma.cpp.
References ACH, ACW, Com_Printf(), MapInfo::curMap, MapInfo::getCurrentAssembly(), Tile::h, Assembly::height, i, Tile::id, IS_SOLID, MMH, MMW, MapInfo::mPlaced, MapInfo::numPlaced, OBJSET, Tile::spec, SV_TileMaskToString(), mPlaced_t::tile, Tile::w, Assembly::width, mPlaced_t::x, and mPlaced_t::y.
Referenced by SV_AddMapTiles(), and SV_AddMissingTiles_r().
|
static |
Checks if the map is completely filled.
true if the map is filled, false if the map has still empty fields Definition at line 976 of file sv_rma.cpp.
References MapInfo::curMap, MapInfo::getCurrentAssembly(), Assembly::height, IS_SOLID, and Assembly::width.
Referenced by SV_AddMissingTiles(), and SV_AddMissingTiles_r().
Definition at line 261 of file sv_rma.cpp.
References ALL_TILES, i, and m.
Referenced by SV_RmaPrintMap().
|
static |
Convert to tile spec - normalize the characters.
Definition at line 245 of file sv_rma.cpp.
References ALL_TILES, Com_Error(), and ERR_DROP.
Referenced by SV_ParseMapTile(), and SV_ParseUMP().
|
static |
Select the next tile to place and place it (recursively).
| map | All we know about the map to assemble |
| rec | The number of the current recursion |
| posListCnt | The number of remaining tile position (=options) |
| myPosList | The previous list of remaining tile position (=options) |
| prevTile | The tile placed by the previous recursion |
| prevX | x where it was placed |
| prevY | well, y |
false if the tiles do not fit, true if the map could be filled. Definition at line 1184 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles_r().
|
static |
for every x/y we can store the tiles that can cover that place here
Definition at line 68 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles(), SV_AddMissingTiles_r(), SV_GapCheckNeighbour(), SV_GapListBuild(), and SV_GapListReduce().
|
static |
Definition at line 72 of file sv_rma.cpp.
Referenced by SV_AssemblyThread(), and SV_ParallelSearch().
|
static |
Definition at line 73 of file sv_rma.cpp.
Referenced by SV_AssemblyThread(), and SV_ParallelSearch().
|
static |
Definition at line 71 of file sv_rma.cpp.
Referenced by SV_AddMapTiles(), SV_AssemblyThread(), and SV_ParallelSearch().
|
static |
Definition at line 70 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles(), and SV_AddMissingTiles_r().
|
static |
array of working random tile positions, 50 recursions
Definition at line 61 of file sv_rma.cpp.
Referenced by SV_AddMissingTiles(), SV_AddMissingTiles_r(), SV_GapListBuild(), and SV_GapListReduce().
|
static |
Definition at line 74 of file sv_rma.cpp.
Referenced by SV_AssemblyThread(), and SV_ParallelSearch().