├── test ├── luaalloc │ ├── CMakeLists.txt │ ├── test.lua │ └── testluaalloc.cpp ├── CMakeLists.txt └── jps │ ├── build.sh │ ├── CMakeLists.txt │ ├── ScenarioLoader.cpp │ ├── ScenarioLoader.h │ ├── testjps1.cpp │ ├── testjps2.cpp │ └── maps │ ├── dao │ └── den011d.map │ └── den011d.map.scen ├── README.md ├── LICENSE ├── luaalloc.h ├── luaalloc.c └── jps.hh /test/luaalloc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(testluaalloc testluaalloc.cpp ../../luaalloc.c ../../luaalloc.h minilua.c) 2 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(tinypiletest) 3 | 4 | include_directories(..) 5 | 6 | add_subdirectory(luaalloc) 7 | add_subdirectory(jps) 8 | 9 | -------------------------------------------------------------------------------- /test/jps/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | c++ testjps1.cpp -I../../ -DNDEBUG -o testjps1 -O3 -pipe -Wall -pedantic 3 | c++ testjps2.cpp -I../../ ScenarioLoader.cpp -DNDEBUG -o testjps2 -O3 -pipe -Wall -pedantic 4 | -------------------------------------------------------------------------------- /test/luaalloc/test.lua: -------------------------------------------------------------------------------- 1 | local t, x, w = {}, {}, setmetatable({}, {__mode="kv"}) 2 | for i = 1, 3000000 do 3 | t[i] = i 4 | local p = newproxy() 5 | x = { { function() return p end }, ""..i } 6 | w[p] = x 7 | end 8 | -------------------------------------------------------------------------------- /test/jps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(scenarioloader ScenarioLoader.cpp ScenarioLoader.h) 2 | 3 | add_executable(testjps1 testjps1.cpp ../../jps.hh) 4 | add_executable(testjps2 testjps2.cpp ../../jps.hh) 5 | 6 | target_link_libraries(testjps2 scenarioloader) 7 | -------------------------------------------------------------------------------- /test/luaalloc/testluaalloc.cpp: -------------------------------------------------------------------------------- 1 | #include "luaalloc.h" 2 | 3 | typedef struct lua_Alloc lua_Alloc; 4 | extern "C" int runlua(int argc, const char*const*argv, void *alloc, void *ud); 5 | 6 | #include 7 | 8 | int main() 9 | { 10 | LuaAlloc *LA = luaalloc_create(0, 0); 11 | const char *fn[] = { "", "test.lua" }; 12 | int ret = runlua(2, fn, luaalloc, LA); 13 | 14 | const size_t *alive, *total, *blocks; 15 | unsigned step, n = luaalloc_getstats(LA, &alive, &total, &blocks, &step); 16 | if(n) 17 | { 18 | for(unsigned i = 0, a = 1, b = step; i < n-1; ++i, a = b+1, b += step) 19 | printf("%zu blocks of %u..%u bytes: %zu allocations alive, %zu done all-time\n", 20 | blocks[i], a, b, alive[i], total[i]); 21 | printf("large allocations: %zu alive, %zu done all-time\n", alive[n-1], total[n-1]); 22 | } 23 | luaalloc_delete(LA); 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tinypile 2 | 3 | Pile of various tiny (single- or two-file) libs. 4 | 5 | - [x] Cross-platform C/C++. 6 | - [x] Public Domain. 7 | - [X] Self-contained. 8 | - [x] No exceptions, no RTTI, full control over memory allocation. 9 | - [x] No build system, no hassle. 10 | 11 | |Thing|Files|Language|Summary|Status| 12 | |:------|:-------|:-----|:-----|:-----| 13 | |LuaAlloc|[.c](luaalloc.c) + [.h](luaalloc.h)|C99|Lua small block allocator| Stable. 14 | |JPS v2|[.hh](jps.hh)|C++98|2D Pathfinding: A*, Jump Point Search| Experimental, needs testing. 15 | 16 | My other tiny libs that reside in their own repos for historical reasons: 17 | 18 | |Thing|Language|Summary| 19 | |:------|:-------|:-----| 20 | |[JPS](https://github.com/fgenesis/jps) (old version)|C++03|Jump point search (2D Pathfinding)| 21 | |[minihttp](https://github.com/fgenesis/minihttp)|C++03|HTTP(S) client lib| 22 | 23 | 24 | 25 | 26 | ## Inspired by: 27 | 28 | - The infamous [nothings/stb](https://github.com/nothings/stb/) 29 | - [r-lyeh/tinybits](https://github.com/r-lyeh/tinybits) 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /test/jps/ScenarioLoader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * scenarioLoader.cpp 3 | * hog 4 | * 5 | * Created by Renee Jansen on 5/2/2006 6 | * 7 | */ 8 | 9 | #include 10 | using std::ifstream; 11 | using std::ofstream; 12 | 13 | #include "ScenarioLoader.h" 14 | #include 15 | 16 | /** 17 | * Loads the experiments from the scenario file. 18 | */ 19 | ScenarioLoader::ScenarioLoader(const char* fname) 20 | { 21 | ifstream sfile(fname,std::ios::in); 22 | 23 | float ver; 24 | string first; 25 | sfile>>first; 26 | 27 | // Check if a version number is given 28 | if(first != "version"){ 29 | ver = 0.0; 30 | sfile.seekg(0,std::ios::beg); 31 | } 32 | else{ 33 | sfile>>ver; 34 | } 35 | 36 | int sizeX = 0, sizeY = 0; 37 | int bucket; 38 | string map; 39 | int xs, ys, xg, yg; 40 | float dist; 41 | 42 | // Read in & store experiments 43 | if (ver==0.0){ 44 | while(sfile>>bucket>>map>>xs>>ys>>xg>>yg>>dist) { 45 | Experiment exp(xs,ys,xg,yg,bucket,dist,map); 46 | experiments.push_back(exp); 47 | } 48 | } 49 | else if(ver==1.0){ 50 | while(sfile>>bucket>>map>>sizeX>>sizeY>>xs>>ys>>xg>>yg>>dist){ 51 | Experiment exp(xs,ys,xg,yg,sizeX,sizeY,bucket,dist,map); 52 | experiments.push_back(exp); 53 | } 54 | } 55 | else{ 56 | printf("Invalid version number.\n"); 57 | //assert(0); 58 | } 59 | } 60 | 61 | void ScenarioLoader::Save(const char *fname) 62 | { 63 | // strncpy(scenName, fname, 1024); 64 | ofstream ofile(fname); 65 | 66 | float ver = 1.0; 67 | ofile<<"version "< 13 | #include 14 | #include 15 | #include 16 | using std::string; 17 | 18 | static const int kNoScaling = -1; 19 | 20 | /** 21 | * Experiments stored by the ScenarioLoader class. 22 | */ 23 | class ScenarioLoader; 24 | 25 | class Experiment { 26 | public: 27 | Experiment(int sx,int sy,int gx,int gy,int b, double d, string m) 28 | :startx(sx),starty(sy),goalx(gx),goaly(gy),scaleX(kNoScaling),scaleY(kNoScaling),bucket(b),distance(d),map(m){} 29 | Experiment(int sx,int sy,int gx,int gy,int sizeX, int sizeY,int b, double d, string m) 30 | :startx(sx),starty(sy),goalx(gx),goaly(gy),scaleX(sizeX),scaleY(sizeY),bucket(b),distance(d),map(m){} 31 | int GetStartX() const {return startx;} 32 | int GetStartY() const {return starty;} 33 | int GetGoalX() const {return goalx;} 34 | int GetGoalY() const {return goaly;} 35 | int GetBucket() const {return bucket;} 36 | double GetDistance() const {return distance;} 37 | //void GetMapName(char* mymap) const {strcpy(mymap,map.c_str());} 38 | const char *GetMapName() const { return map.c_str(); } 39 | int GetXScale() const {return scaleX;} 40 | int GetYScale() const {return scaleY;} 41 | 42 | private: 43 | friend class ScenarioLoader; 44 | int startx, starty, goalx, goaly; 45 | int scaleX; 46 | int scaleY; 47 | int bucket; 48 | double distance; 49 | string map; 50 | }; 51 | 52 | /** A class which loads and stores scenarios from files. 53 | * Versions currently handled: 0.0 and 1.0 (includes scale). 54 | */ 55 | 56 | class ScenarioLoader{ 57 | public: 58 | ScenarioLoader(const char *); 59 | void Save(const char *); 60 | unsigned GetNumExperiments() const {return (unsigned)experiments.size();} 61 | const Experiment& GetNthExperiment(unsigned which) const 62 | {return experiments[which];} 63 | void AddExperiment(Experiment which); 64 | private: 65 | std::vector experiments; 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /test/jps/testjps1.cpp: -------------------------------------------------------------------------------- 1 | #include "jps.hh" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static const char *data[] = 11 | { 12 | "##############################################", 13 | "# # # #", 14 | "# ### ## # #### #", 15 | "# ####### # ###### # #", 16 | "# # # # 2 # # #", 17 | "# # # # # #5 #", 18 | "# # # # ###### #", 19 | "# ############### # #", 20 | "# # 3# # #", 21 | "# # ############ #", 22 | "# # #### # # #", 23 | "# # ##### #####", 24 | "# # 1 #", 25 | "# # 4 #", 26 | "##############################################", 27 | NULL 28 | }; 29 | 30 | struct MyGrid 31 | { 32 | MyGrid(const char *d[]) 33 | : mapdata(d) 34 | { 35 | w = (unsigned)strlen(mapdata[0]); 36 | h = 0; 37 | for(h = 0; mapdata[h]; ++h) 38 | out.push_back(mapdata[h]); 39 | 40 | std::cout << "W: " << w << "; H: " << h << "; Total cells: " << (w*h) << std::endl; 41 | } 42 | 43 | // Called by JPS to figure out whether the tile at (x, y) is walkable 44 | inline unsigned operator()(unsigned x, unsigned y) const 45 | { 46 | unsigned canwalk = x < w && y < h; 47 | if(canwalk) 48 | { 49 | canwalk = mapdata[y][x] != '#'; 50 | out[y][x] = canwalk ? '.' : '@'; // also visualize which area was scanned 51 | } 52 | return canwalk; 53 | } 54 | 55 | unsigned w, h; 56 | const char **mapdata; 57 | mutable std::vector out; 58 | }; 59 | 60 | 61 | int main(int argc, char **argv) 62 | { 63 | MyGrid grid(data); 64 | 65 | // Collect waypoints from map 66 | JPS::PathVector waypoints; 67 | for(char a = '1'; a <= '9'; ++a) 68 | { 69 | for(unsigned y = 0; y < grid.h; ++y) 70 | { 71 | const char *sp = strchr(data[y], a); 72 | if(sp) 73 | { 74 | waypoints.push_back(JPS::Pos(JPS::PosType(sp - data[y]), y)); 75 | } 76 | } 77 | } 78 | 79 | unsigned step = argc > 1 ? atoi(argv[1]) : 0; 80 | std::cout << "Calculating path with step " << step << std::endl; 81 | 82 | JPS::PathVector path; 83 | JPS::Searcher search(grid); 84 | size_t totalsteps = 0, totalnodes = 0; 85 | for(size_t i = 1; i < waypoints.size(); ++i) 86 | { 87 | // Go from waypoint[i-1] to waypoint[i] 88 | bool found = search.findPath(path, waypoints[i-1], waypoints[i], step); 89 | if(!found) 90 | { 91 | std::cout << "Path not found!" << std::endl; 92 | break; 93 | } 94 | totalsteps += search.getStepsDone(); 95 | totalnodes += search.getNodesExpanded(); 96 | } 97 | 98 | // visualize path 99 | unsigned c = 0; 100 | for(JPS::PathVector::iterator it = path.begin(); it != path.end(); ++it) 101 | grid.out[it->y][it->x] = (c++ % 26) + 'a'; 102 | 103 | for(unsigned i = 0; i < grid.h; ++i) 104 | std::cout << grid.out[i] << std::endl; 105 | 106 | std::cout << std::endl; 107 | std::cout << "Search steps: " << totalsteps << std::endl; 108 | std::cout << "Nodes expanded: " << totalnodes << std::endl; 109 | std::cout << "Memory used: " << search.getTotalMemoryInUse() << " bytes" << std::endl; 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /test/jps/testjps2.cpp: -------------------------------------------------------------------------------- 1 | // How to use: 2 | // Set working directory to test/jps (= where this file resides), then run: 3 | // ./testjps maps/*.scen 4 | // for a quick benchmark and correctness test. 5 | 6 | #include "jps.hh" 7 | 8 | #include 9 | #include "ScenarioLoader.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | // Testing material from http://www.movingai.com/benchmarks/ 16 | 17 | static void die(const char *msg) 18 | { 19 | std::cerr << msg << std::endl; 20 | abort(); 21 | } 22 | 23 | struct MapGrid 24 | { 25 | MapGrid(const char *file) 26 | { 27 | std::ifstream in(file); 28 | if(!in) 29 | die(file); 30 | 31 | std::string s; 32 | std::getline(in, s); 33 | in >> s >> h; 34 | in >> s >> w; 35 | in >> s; 36 | 37 | while(in >> s) 38 | if(s.length() == w) 39 | lines.push_back(s); 40 | 41 | if(h != lines.size()) 42 | die("Wrong number of lines"); 43 | 44 | std::cout << "[" << file << "] W: " << w << "; H: " << h << "; Total cells: " << (w*h) << std::endl; 45 | } 46 | 47 | bool operator()(unsigned x, unsigned y) const 48 | { 49 | if(x < w && y < h) 50 | { 51 | const char c = lines[y][x]; 52 | switch(c) 53 | { 54 | case '.': 55 | case 'G': 56 | case 'S': 57 | return true; 58 | } 59 | } 60 | return false; 61 | } 62 | 63 | unsigned w, h; 64 | std::vector lines; 65 | }; 66 | 67 | static double pathcost(unsigned startx, unsigned starty, const JPS::PathVector& path) 68 | { 69 | unsigned lastx = startx; 70 | unsigned lasty = starty; 71 | double accu = 0; 72 | assert(path.empty() || path[0] != JPS::Pos(startx, starty)); 73 | for(size_t i = 0; i < path.size(); ++i) 74 | { 75 | unsigned x = path[i].x; 76 | unsigned y = path[i].y; 77 | 78 | int dx = int(x - lastx); 79 | int dy = int(y - lasty); 80 | 81 | accu += sqrt(double(dx*dx + dy*dy)); 82 | 83 | lastx = x; 84 | lasty = y; 85 | } 86 | return accu; 87 | } 88 | 89 | double runScenario(const char *file) 90 | { 91 | ScenarioLoader loader(file); 92 | if(!loader.GetNumExperiments()) 93 | die(file); 94 | MapGrid grid(loader.GetNthExperiment(0).GetMapName()); 95 | double sum = 0; 96 | JPS::PathVector path; 97 | JPS::Searcher search(grid); 98 | for(unsigned i = 0; i < loader.GetNumExperiments(); ++i) 99 | { 100 | const Experiment& ex = loader.GetNthExperiment(i); 101 | path.clear(); 102 | int runs = 0; 103 | 104 | // single-call 105 | //bool found = JPS::findPath(path, grid, ex.GetStartX(), ex.GetStartY(), ex.GetGoalX(), ex.GetGoalY(), 0, 0, &stepsDone, &nodesExpanded); 106 | 107 | // Testing incremental runs 108 | bool found = false; 109 | const JPS::Position startpos = JPS::Pos(ex.GetStartX(), ex.GetStartY()); 110 | const JPS::Position endpos = JPS::Pos(ex.GetGoalX(), ex.GetGoalY()); 111 | JPS_Result res = search.findPathInit(startpos, endpos); 112 | if(res == JPS_EMPTY_PATH) 113 | found = true; 114 | else 115 | { 116 | while(res == JPS_NEED_MORE_STEPS) 117 | { 118 | ++runs; 119 | res = search.findPathStep(10000); 120 | } 121 | found = (res == JPS_FOUND_PATH) && search.findPathFinish(path, 0); 122 | } 123 | 124 | if(!found) 125 | { 126 | printf("#### [%s:%d] PATH NOT FOUND: (%d, %d) -> (%d, %d)\n", 127 | file, i, ex.GetStartX(), ex.GetStartY(), ex.GetGoalX(), ex.GetGoalY()); 128 | die("Path not found!"); // all paths known to be valid, so this is bad 129 | continue; 130 | } 131 | 132 | assert((path.empty() && startpos == endpos) || path.back() == endpos); 133 | 134 | // Starting position is NOT included in vector 135 | double cost = pathcost(ex.GetStartX(), ex.GetStartY(), path); 136 | #if 0 137 | //if(cost > ex.GetDistance()+0.5f) 138 | printf("[%s] [%s:%d] Path len: %.3f (%.3f); Diff: %.3f; Steps: %u; Nodes: %u; Runs: %u\n", 139 | (cost > ex.GetDistance()+0.5f ? "##" : " "), file, i, cost, ex.GetDistance(), 140 | fabs(cost - ex.GetDistance()), (unsigned)search.getStepsDone(), (unsigned)search.getNodesExpanded(), runs); 141 | #else 142 | (void)runs; 143 | #endif 144 | 145 | sum += cost; 146 | } 147 | printf("Done. Req. memory: %u KB\n", (unsigned)search.getTotalMemoryInUse() / 1024); 148 | return sum; 149 | } 150 | 151 | int main(int argc, char **argv) 152 | { 153 | double sum = 0; 154 | for(int i = 1; i < argc; ++i) 155 | sum += runScenario(argv[i]); 156 | 157 | std::cout << "Total distance travelled: " << sum << std::endl; 158 | 159 | return 0; 160 | } 161 | 162 | -------------------------------------------------------------------------------- /luaalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Small and fast Lua allocator, compatible with Lua 5.1 and up. 3 | For more info and compile-time config, see luaalloc.c 4 | 5 | Usage: 6 | LuaAlloc *LA = luaalloc_create(NULL, NULL); 7 | lua_State *L = lua_newstate(luaalloc, LA); 8 | ... use L ... 9 | lua_close(L); 10 | luaalloc_delete(LA); 11 | */ 12 | 13 | #pragma once 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /* Opaque allocator type */ 20 | typedef struct LuaAlloc LuaAlloc; 21 | 22 | /* Main allocation callback. Lua will call this when it needs memory. 23 | 'ud' must be a valid LuaAlloc context passed as user pointer to lua_newstate(). */ 24 | void *luaalloc(void *ud, void *ptr, size_t osize, size_t nsize); 25 | 26 | /* Block requests and large allocations will be forwarded to the system allocator. 27 | If you don't provide one, a suitable one based on realloc()/free() will be used. 28 | Details below. */ 29 | typedef void *(*LuaSysAlloc)(void *ud, void *ptr, size_t osize, size_t nsize); 30 | 31 | /* Create allocator context. Pass custom system allocator if needed or NULL for the built-in default. 32 | Multiple Lua states can share a single LuaAlloc as long as they run on the same thread. */ 33 | LuaAlloc *luaalloc_create(LuaSysAlloc sysalloc, void *ud); 34 | 35 | /* Destroy allocator. Call after lua_close()ing each Lua state using the allocator. */ 36 | void luaalloc_delete(LuaAlloc*); 37 | 38 | /* Statistics tracking. Define LA_TRACK_STATS in luaalloc.c to use this. [Enabled by default in debug mode]. 39 | Provides pointers to internal stats area. Each element corresponds to an internal allocation bin. 40 | - alive: How many allocations of a bin size are currently in use. 41 | - total: How many allocations of a bin size were ever made. 42 | - blocks: How many blocks currently exist for a bin. 43 | With the default config, index 0 corresponds to all allocations of 1-4 bytes, index 1 to those of 5-8 bytes, and so on. 44 | The bin size increment is returned in pbinstep (default: 4). 45 | All output pointers can be NULL if you're not interested in the thing. 46 | Returns the total number of bins. 0 when stats tracking is disabled. 47 | The last valid index is not an actual bin -- instead, large allocations that bypass the allocator are collected there. 48 | The returned pointers are owned by the LuaAlloc instance and stay valid throughout its lifetime. 49 | To iterate over the size bins, you can do: 50 | 51 | const size_t *alive, *total, *blocks; 52 | unsigned step, n = luaalloc_getstats(LA, &alive, &total, &blocks, &step); 53 | if(n) 54 | { 55 | for(unsigned i = 0, a = 1, b = step; i < n-1; ++i, a = b+1, b += step) 56 | printf("%zu blocks of %u..%u bytes: %zu allocations alive, %zu done all-time\n", 57 | blocks[i], a, b, alive[i], total[i]); 58 | printf("large allocations: %zu alive, %zu done all-time\n", alive[n-1], total[n-1]); 59 | } 60 | */ 61 | unsigned luaalloc_getstats(const LuaAlloc*, const size_t **alive, const size_t **total, const size_t **blocks, unsigned *pbinstep); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | 68 | /* 69 | Details about the system allocator: 70 | 71 | typedef void *(*LuaSysAlloc)(void *ud, void *ptr, size_t osize, size_t nsize); 72 | 73 | Block requests and large Lua allocations will be forwarded to the system allocator. 74 | The function signature is (intentionally) the same as luaalloc() and the semantics are very similar. 75 | The caller knows the size of each allocation so you do not have to track this yourself. 76 | The system allocator must not fail shrink requests (same requirement as Lua). 77 | 78 | You must handle the following cases: 79 | if(!ptr && nsize) 80 | return malloc(nsize); (osize encodes the type of allocation, see below) 81 | else if(ptr && !nsize) 82 | free(ptr); (osize is the previously allocated size; the return value is ignored) 83 | else if(ptr && nsize) 84 | return realloc(ptr, nsize); (must not fail shrink requests. osize is the previously allocated size; osize != nsize guaranteed) 85 | // never called with (!ptr && !nsize), can ignore this case 86 | 87 | Types of allocations, in case (!ptr && nsize): 88 | switch(osize) 89 | { 90 | case LUAALLOC_TYPE_LARGELUA: 91 | passthrough/large Lua allocation (alloc'd/free'd/realloc'd incl. shrink requests) 92 | case LUAALLOC_TYPE_BLOCK: 93 | block allocation (alloc'd/free'd, but never realloc'd) 94 | case LUAALLOC_TYPE_INTERNAL: 95 | allocation of LuaAlloc-internal data (usually long-lived. alloc'd, realloc'd to enlarge, but never shrunk. free'd only in luaalloc_delete()) 96 | case 0: default: 97 | some other allocation (not used by LuaAlloc. Maybe some other code uses this allocator as well?) 98 | } 99 | 100 | Lua allocations may fail and Lua usually handles this gracefully by running an emergency GC; 101 | 5.2 and up do this out-of-the box and there is a patch for 5.1 as well. 102 | This block allocator is built to properly handle system allocator failures, 103 | and return a failed allocation back to Lua as appropriate. 104 | */ 105 | -------------------------------------------------------------------------------- /luaalloc.c: -------------------------------------------------------------------------------- 1 | /* Small and fast memory allocator tailored for Lua. 2 | 3 | License: 4 | Public domain, WTFPL, CC0 or your favorite permissive license; whatever is available in your country. 5 | 6 | Dependencies: 7 | libc by default, change defines below to use your own functions 8 | Compiles as C99 or C++ code. 9 | 10 | Thread safety: 11 | No global state. LuaAlloc instances are not thread-safe (same as Lua). 12 | 13 | Background: 14 | Lua tends to make tiny allocations (4, 8, 16, generally less than 100 bytes) most of the time. 15 | malloc() & friends tend to be rather slow and also add some bytes of overhead for bookkeeping (typically 8 or 16 bytes), 16 | so a large percentage of the actually allocated memory is wasted. 17 | This allocator groups allocations of the same (small) size into blocks and passes through larger allocations. 18 | Small allocations have an overhead of 1 bit plus some bookkeeping information for each block. 19 | This allocator is also rather fast; in the typical case a block known to contain free slots is cached, 20 | and inside of this block, finding a free slot is a tiny loop checking 32 slots at once, 21 | followed by a CTZ (count trailing zeros) to locate the exact slot out of the 32. 22 | Freeing is similar, first do a binary search to locate the block containing the pointer to be freed, 23 | then flip the bit for that slot to mark it as unused. (Bitmap position and bit index is computed from the address, no loop there.) 24 | Once a block for a given size bin is full, other blocks in this bin are filled. A new block is allocated from the system if there is no free block. 25 | Unused blocks are free()d as soon as they are completely empty. 26 | 27 | Origin: 28 | https://github.com/fgenesis/tinypile/blob/master/luaalloc.c 29 | 30 | Inspired by: 31 | http://dns.achurch.org/cgi-bin/hg/aquaria-psp/file/tip/PSP/src/lalloc.c 32 | http://wiki.luajit.org/New-Garbage-Collector#arenas (--> LuaJIT has its own allocator. Don't use this one for LuaJIT.) 33 | 34 | */ 35 | 36 | /* ---- Configuration begin ---- */ 37 | 38 | /* Track allocation stats to get an overview of your memory usage. By default disabled in release mode. */ 39 | #ifndef NDEBUG 40 | # define LA_TRACK_STATS 41 | #endif 42 | 43 | /* Internal consistency checks. By default disabled in release mode. */ 44 | #ifdef NDEBUG 45 | # define LA_ASSERT(x) 46 | #else 47 | # include 48 | # define LA_ASSERT(x) assert(x) 49 | #endif 50 | 51 | /* Required libc functions. Use your own if needed */ 52 | #include /* for memcpy, memmove, memset */ 53 | #define LA_MEMCPY(dst, src, n) memcpy((dst), (src), (n)) 54 | #define LA_MEMMOVE(dst, src, n) memmove((dst), (src), (n)) 55 | #define LA_MEMSET(dst, val, n) memset((dst), (val), (n)) 56 | 57 | /* If you want to turn off the internal default system allocator, comment out the next line. 58 | If the default sysalloc is disabled, symbols for realloc()/free() won't be pulled in. */ 59 | #define LA_ENABLE_DEFAULT_ALLOC 60 | 61 | /* Maximum size of allocations to handle. Any size beyond that will be redirected to the system allocator. 62 | Must be a multiple of LA_ALLOC_STEP */ 63 | #define LA_MAX_ALLOC 128 64 | 65 | /* Provide pools in increments of this size, up to LA_MAX_ALLOC. 4 or 8 are good values. */ 66 | /* E.g. A value of 4 will create pools for size 4, 8, 12, ... 128; which is 32 distinct sizes. */ 67 | #define LA_ALLOC_STEP 4 68 | 69 | /* Initial/Max. # of elements per block. Default growing behavior is to double the size for each full block until hitting LA_ELEMS_MAX. 70 | Note that each element requires 1 bit in the bitmap, the number of elements is rounded up so that no bit is unused, 71 | and the bitmap array is sized accordingly. Best is to use powers of 2. */ 72 | #define LA_ELEMS_MIN 64 73 | #define LA_ELEMS_MAX 2048 /* Stored in u16, don't go higher than 0x8000 */ 74 | #define LA_GROW_BLOCK_SIZE(n) (n * 2) 75 | 76 | typedef unsigned int u32; 77 | typedef unsigned short u16; 78 | 79 | /* Bitmap type. Default u32. If you want to use another unsigned type (e.g. uint64_t) 80 | you must provide a count-trailing-zeroes function. 81 | Note that the bitmap implicitly controls the data alignment -- the data area starts directly after the bitmap array, 82 | there is no explicit padding in between. */ 83 | typedef u32 ubitmap; 84 | 85 | /* CTZ for your bitmap type. */ 86 | #define bitmap_CTZ(x) ctz32(x) 87 | 88 | /* ---- Configuration end ---- */ 89 | 90 | 91 | #include "luaalloc.h" 92 | 93 | #include /* for size_t, ptrdiff_t */ 94 | #include /* for CHAR_BIT */ 95 | 96 | #ifdef LA_ENABLE_DEFAULT_ALLOC 97 | #include /* for realloc, free */ 98 | #endif 99 | 100 | /* ---- Intrinsics ---- */ 101 | 102 | #define LA_RESTRICT __restrict 103 | 104 | #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM)) 105 | # include 106 | # define HAS_BITSCANFORWARD 107 | #elif defined(__clang__) 108 | # if __has_builtin(__builtin_ctz) 109 | # define HAS_BUILTIN_CTZ 110 | # endif 111 | #elif defined(__GNUC__) 112 | # define HAS_BUILTIN_CTZ 113 | #endif 114 | 115 | inline static unsigned ctz32(u32 x) 116 | { 117 | #if defined(HAS_BUILTIN_CTZ) 118 | return __builtin_ctz(x); 119 | #elif defined(HAS_BITSCANFORWARD) 120 | unsigned long r = 0; 121 | _BitScanForward(&r, x); 122 | return r; 123 | #else /* bit magic */ 124 | x = (x & -x) - 1; 125 | /* begin popcount32 */ 126 | x -= ((x >> 1) & 0x55555555); 127 | x = (((x >> 2) & 0x33333333) + (x & 0x33333333)); 128 | x = (((x >> 4) + x) & 0x0f0f0f0f); 129 | x += (x >> 8); 130 | x += (x >> 16); 131 | x &= 0x0000003f; 132 | /* end popcount32 */ 133 | return x; 134 | #endif 135 | } 136 | 137 | /* ---- Structs for internal book-keeping ---- */ 138 | 139 | #define BLOCK_ARRAY_SIZE (LA_MAX_ALLOC / LA_ALLOC_STEP) 140 | 141 | typedef struct Block Block; 142 | 143 | struct Block 144 | { 145 | u16 elemsfree; /* dynamic */ 146 | u16 elemstotal; /* const */ 147 | u16 elemSize; /* const */ 148 | u16 bitmapInts; /* const */ 149 | Block *next; /* dynamic */ 150 | Block *prev; /* dynamic */ 151 | 152 | ubitmap bitmap[1]; 153 | /* bitmap area */ 154 | /* data area */ 155 | }; 156 | 157 | typedef struct LuaAlloc 158 | { 159 | Block *active[BLOCK_ARRAY_SIZE]; /* current work block for each size, that serves allocations until full */ 160 | Block *chain[BLOCK_ARRAY_SIZE]; /* newest allocated block for each size (follow ->prev to get older block) */ 161 | Block **all; /* All blocks in use, sorted by address */ 162 | size_t allnum; /* number of blocks in use */ 163 | size_t allcap; /* capacity of array */ 164 | LuaSysAlloc sysalloc; 165 | void *user; 166 | #ifdef LA_TRACK_STATS 167 | struct 168 | { 169 | /* Extra entry is for large allocations outside of this allocator */ 170 | size_t alive[BLOCK_ARRAY_SIZE + 1]; /* How many allocations of each size bin are currently in use */ 171 | size_t total[BLOCK_ARRAY_SIZE + 1]; /* How many allocations of each size bin were done in total */ 172 | size_t blocks_alive[BLOCK_ARRAY_SIZE + 1]; /* How many blocks for each size bin do currently exist */ 173 | } stats; 174 | #endif 175 | } LuaAlloc; 176 | 177 | /* ---- Helper functions ---- */ 178 | 179 | static const u16 BITMAP_ELEM_SIZE = sizeof(ubitmap) * CHAR_BIT; 180 | 181 | inline static ubitmap *getbitmap(Block *b) 182 | { 183 | return &b->bitmap[0]; 184 | } 185 | 186 | inline static void *getdata(Block *b) 187 | { 188 | return ((char*)getbitmap(b)) + (b->bitmapInts * sizeof(ubitmap)); 189 | } 190 | 191 | inline static void *getdataend(Block *b) 192 | { 193 | return ((char*)getdata(b)) + ((size_t)b->elemSize * b->elemstotal); 194 | } 195 | 196 | inline static unsigned sizeindex(u16 elemSize) 197 | { 198 | LA_ASSERT(elemSize && elemSize <= LA_MAX_ALLOC); 199 | return (elemSize - 1) / LA_ALLOC_STEP; 200 | } 201 | 202 | inline static unsigned bsizeindex(const Block *b) 203 | { 204 | return sizeindex(b->elemSize); 205 | } 206 | 207 | static int contains(Block * b, const void *p) 208 | { 209 | return getdata(b) <= p && p < getdataend(b); 210 | } 211 | 212 | inline static u16 roundToFullBitmap(u16 n) 213 | { 214 | #if CHAR_BIT == 8 215 | return (n + BITMAP_ELEM_SIZE - 1) & -BITMAP_ELEM_SIZE; /* Fast round if BITMAP_ELEM_SIZE is a power of 2 */ 216 | #else 217 | # error Weird hardware detected! CHAR_BIT != 8, does this mean BITMAP_ELEM_SIZE is not a power of 2? Check this, and CTZ function. 218 | #endif 219 | } 220 | 221 | inline static void checkblock(Block *b) 222 | { 223 | LA_ASSERT(b->elemSize && (b->elemSize % LA_ALLOC_STEP) == 0); 224 | LA_ASSERT(b->bitmapInts * BITMAP_ELEM_SIZE == b->elemstotal); 225 | LA_ASSERT(b->elemsfree <= b->elemstotal); 226 | LA_ASSERT(b->elemstotal >= LA_ELEMS_MIN); 227 | LA_ASSERT(b->elemstotal <= LA_ELEMS_MAX); 228 | } 229 | 230 | inline static size_t blocksize(Block *b) 231 | { 232 | return (char*)getdataend(b) - (char*)b; 233 | } 234 | 235 | inline static u16 nextblockelems(Block *b) 236 | { 237 | if(!b) 238 | return LA_ELEMS_MIN; 239 | u32 n = LA_GROW_BLOCK_SIZE(b->elemstotal); 240 | return (u16)(n < LA_ELEMS_MAX ? n : LA_ELEMS_MAX); 241 | } 242 | 243 | /* ---- System allocator interface ---- */ 244 | 245 | typedef enum 246 | { 247 | LA_TYPE_LARGELUA = 0, 248 | LA_TYPE_BLOCK = 1, 249 | LA_TYPE_INTERNAL = 2 250 | } AllocType; 251 | 252 | inline static void *sysmalloc(LuaAlloc *LA, AllocType osize, size_t nsize) 253 | { 254 | LA_ASSERT(nsize); 255 | return LA->sysalloc(LA->user, NULL, osize, nsize); 256 | } 257 | 258 | inline static void sysfree(LuaAlloc * LA_RESTRICT LA, void * LA_RESTRICT p, size_t osize) 259 | { 260 | LA_ASSERT(p && osize); 261 | LA->sysalloc(LA->user, p, osize, 0); /* ignore return value */ 262 | } 263 | 264 | inline static void *sysrealloc(LuaAlloc * LA_RESTRICT LA, void * LA_RESTRICT p, size_t osize, size_t nsize) 265 | { 266 | LA_ASSERT(osize && nsize); /* This assert is correct even if an AllocType enum value is passed as osize. */ 267 | return LA->sysalloc(LA->user, p, osize, nsize); 268 | } 269 | 270 | /* ---- Allocator internals ---- */ 271 | 272 | static Block *_allocblock(LuaAlloc *LA, u16 nelems, u16 elemsz) 273 | { 274 | elemsz = ((elemsz + LA_ALLOC_STEP-1) / LA_ALLOC_STEP) * LA_ALLOC_STEP; /* round up */ 275 | nelems = roundToFullBitmap(nelems); /* The bitmap array must not have any unused bits */ 276 | const u16 nbitmap = nelems / BITMAP_ELEM_SIZE; 277 | 278 | void *ptr = sysmalloc(LA, LA_TYPE_BLOCK, 279 | (sizeof(Block) - sizeof(ubitmap)) /* block header without bitmap[1] */ 280 | + (nbitmap * sizeof(ubitmap)) /* actual bitmap size */ 281 | + (nelems * (size_t)elemsz) /* data size */ 282 | ); 283 | 284 | if(!ptr) 285 | return NULL; 286 | 287 | Block *b = (Block*)ptr; 288 | b->elemsfree = nelems; 289 | b->elemstotal = nelems; 290 | b->elemSize = elemsz; 291 | b->bitmapInts = nbitmap; 292 | b->next = NULL; 293 | b->prev = NULL; 294 | LA_MEMSET(b->bitmap, -1, nbitmap * sizeof(ubitmap)); /* mark all as free */ 295 | 296 | return b; 297 | } 298 | 299 | /* Given the sorting order of LA->all, find the right spot to insert p that preserves the sorting order. 300 | Returns the address of the block that is <= p, or one past the end if no such block was found. 301 | Use cases: 302 | 1) Pass a block to get the address where this block is stored 303 | 2) Pass any other pointer to get ONE BLOCK PAST the address of the block that would contain it (this is not checked) 304 | */ 305 | static Block **findspot(LuaAlloc * LA_RESTRICT LA, void * LA_RESTRICT p) 306 | { 307 | Block **all = LA->all; 308 | 309 | /* Binary search to find leftmost element */ 310 | size_t L = 0; 311 | size_t R = LA->allnum; 312 | while(L < R) 313 | { 314 | size_t m = (L + R) / 2u; 315 | if((void*)all[m] < p) 316 | L = m + 1; 317 | else 318 | R = m; 319 | } 320 | return all + L; 321 | } 322 | 323 | static size_t enlarge(LuaAlloc *LA) 324 | { 325 | const size_t incr = (LA->allcap / 2) + 16; 326 | const size_t newcap = LA->allcap + incr; /* Rough guess */ 327 | Block **newall = (Block**)sysrealloc(LA, LA->all, LA->all ? LA->allcap : LA_TYPE_INTERNAL, sizeof(Block*) * newcap); 328 | if(newall) 329 | { 330 | LA->all = newall; 331 | LA->allcap = newcap; 332 | return newcap; 333 | } 334 | return 0; 335 | } 336 | 337 | static Block *insertblock(LuaAlloc * LA_RESTRICT LA, Block * LA_RESTRICT b) 338 | { 339 | /* Enlarge central block storage if necessary */ 340 | if(LA->allcap == LA->allnum && !enlarge(LA)) 341 | { 342 | sysfree(LA, b, blocksize(b)); /* Can't fit block, kill it and fail */ 343 | return NULL; 344 | } 345 | 346 | /* Find correct spot to insert */ 347 | /* Invariant: Array is already sorted */ 348 | Block **spot = findspot(LA, b); 349 | Block **end = LA->all + LA->allnum; 350 | 351 | /* inserting in the middle? Must preserve sort order */ 352 | if(spot < end) 353 | { 354 | /* move other pointers up */ 355 | LA_MEMMOVE(spot+1, spot, (end - spot) * sizeof(Block*)); 356 | } 357 | 358 | *spot = b; 359 | ++LA->allnum; 360 | 361 | /* Link in chain */ 362 | const unsigned si = bsizeindex(b); 363 | Block *top = LA->chain[si]; 364 | LA->chain[si] = b; 365 | if(top) 366 | { 367 | LA_ASSERT(!top->next); 368 | top->next = b; 369 | } 370 | b->prev = top; 371 | 372 | #ifdef LA_TRACK_STATS 373 | LA->stats.blocks_alive[si]++; 374 | #endif 375 | 376 | checkblock(b); 377 | 378 | return b; 379 | } 380 | 381 | static void freeblock(LuaAlloc * LA_RESTRICT LA, Block ** LA_RESTRICT spot) 382 | { 383 | LA_ASSERT(LA->allnum); 384 | Block *b = *spot; 385 | checkblock(b); 386 | 387 | /* Remove from central list */ 388 | Block **end = LA->all + LA->allnum; 389 | if(spot+1 < end) 390 | { 391 | /* Move other pointers down */ 392 | LA_MEMMOVE(spot, spot+1, (end - (spot+1)) * sizeof(Block*)); 393 | } 394 | --LA->allnum; 395 | /* Invariant: Array is still sorted after removing an element */ 396 | 397 | /* Remove from chain */ 398 | unsigned si = bsizeindex(b); 399 | if(LA->chain[si] == b) 400 | { 401 | LA_ASSERT(!b->next); 402 | LA->chain[si] = b->prev; 403 | } 404 | 405 | if(LA->active[si] == b) 406 | LA->active[si] = NULL; 407 | 408 | /* Unlink from linked list */ 409 | if(b->next) 410 | { 411 | LA_ASSERT(b->next->prev == b); 412 | b->next->prev = b->prev; 413 | } 414 | if(b->prev) 415 | { 416 | LA_ASSERT(b->prev->next == b); 417 | b->prev->next = b->next; 418 | } 419 | 420 | #ifdef LA_TRACK_STATS 421 | LA->stats.blocks_alive[si]--; 422 | #endif 423 | 424 | sysfree(LA, b, blocksize(b)); /* free it */ 425 | } 426 | 427 | static Block *newblock(LuaAlloc *LA, u16 nelems, u16 elemsz) 428 | { 429 | Block *b = _allocblock(LA, nelems, elemsz); 430 | return b ? insertblock(LA, b) : NULL; 431 | } 432 | 433 | static void *_Balloc(Block *b) 434 | { 435 | LA_ASSERT(b->elemsfree); 436 | ubitmap *bitmap = b->bitmap; 437 | unsigned i = 0, bm; 438 | for( ; !(bm = bitmap[i]); ++i) {} /* as soon as one isn't all zero, there's a free slot */ 439 | LA_ASSERT(i < b->bitmapInts); /* And there must've been a free slot because b->elemsfree != 0 */ 440 | ubitmap bitIdx = bitmap_CTZ(bm); /* Get exact location of free slot */ 441 | LA_ASSERT(bm & ((ubitmap)1 << bitIdx)); /* make sure this is '1' (= free) */ 442 | bm &= ~((ubitmap)1 << bitIdx); /* put '0' where '1' was (-> mark as non-free) */ 443 | bitmap[i] = bm; 444 | --b->elemsfree; 445 | const size_t where = (i * (size_t)BITMAP_ELEM_SIZE) + bitIdx; 446 | void *ret = ((char*)getdata(b)) + (where * b->elemSize); 447 | LA_ASSERT(contains(b, ret)); 448 | return ret; 449 | } 450 | 451 | static void _Bfree(Block * LA_RESTRICT b, void * LA_RESTRICT p) 452 | { 453 | LA_ASSERT(b->elemsfree < b->elemstotal); 454 | LA_ASSERT(contains(b, p)); 455 | const ptrdiff_t offs = (char*)p - (char*)getdata(b); 456 | LA_ASSERT(offs % b->elemSize == 0); 457 | const unsigned idx = (unsigned)(offs / b->elemSize); 458 | const unsigned bitmapIdx = idx / BITMAP_ELEM_SIZE; 459 | const ubitmap bitIdx = idx % BITMAP_ELEM_SIZE; 460 | LA_ASSERT(bitmapIdx < b->bitmapInts); 461 | LA_ASSERT(!(b->bitmap[bitmapIdx] & ((ubitmap)1 << bitIdx))); /* make sure this is '0' (= used) */ 462 | b->bitmap[bitmapIdx] |= ((ubitmap)1 << bitIdx); /* put '1' where '0' was (-> mark as free) */ 463 | ++b->elemsfree; 464 | } 465 | 466 | /* returns block with at least 1 free slot, NULL only in case of allocation fail */ 467 | static Block *getfreeblock(LuaAlloc *LA, u16 size) 468 | { 469 | unsigned si = sizeindex(size); 470 | Block *b = LA->active[si]; 471 | if(b && b->elemsfree) /* Good case: Currently active block is free, use that */ 472 | return b; 473 | 474 | /* Not-so-good case: Active block is full or doesn't exist, try an older block in the chain */ 475 | b = LA->chain[si]; 476 | while(b && !b->elemsfree) 477 | b = b->prev; 478 | 479 | /* Still no good? Allocate new block */ 480 | if(!b || !b->elemsfree) 481 | b = newblock(LA, nextblockelems(LA->chain[si]), size); /* Use newest block in chain to compute size */ 482 | 483 | /* Use this block for further allocation requests */ 484 | LA->active[si] = b; 485 | 486 | return b; 487 | } 488 | 489 | static void *_Alloc(LuaAlloc *LA, size_t size) 490 | { 491 | LA_ASSERT(size); 492 | 493 | if(size <= LA_MAX_ALLOC) 494 | { 495 | Block *b = getfreeblock(LA, (u16)size); 496 | if(b) 497 | { 498 | checkblock(b); 499 | void *p = _Balloc(b); 500 | LA_ASSERT(p); /* Can't fail -- block was known to be free */ 501 | 502 | #ifdef LA_TRACK_STATS 503 | unsigned si = bsizeindex(b); 504 | LA->stats.alive[si]++; 505 | LA->stats.total[si]++; 506 | #endif 507 | return p; 508 | } 509 | /* else try the alloc below */ 510 | } 511 | 512 | void *p = sysmalloc(LA, LA_TYPE_LARGELUA, size); /* large Lua allocation */ 513 | 514 | #ifdef LA_TRACK_STATS 515 | if(p) 516 | { 517 | LA->stats.alive[BLOCK_ARRAY_SIZE]++; 518 | LA->stats.total[BLOCK_ARRAY_SIZE]++; 519 | } 520 | #endif 521 | return p; 522 | } 523 | 524 | static void freefromspot(LuaAlloc * LA_RESTRICT LA, Block ** LA_RESTRICT spot, void *p) 525 | { 526 | Block *b = *spot; 527 | #ifdef LA_TRACK_STATS 528 | unsigned si = bsizeindex(b); 529 | LA->stats.alive[si]--; 530 | #endif 531 | if(b->elemsfree + 1 == b->elemstotal) 532 | freeblock(LA, spot); /* Freeing last element in the block -> just free the whole thing */ 533 | else 534 | _Bfree(b, p); 535 | } 536 | 537 | static void _Free(LuaAlloc * LA_RESTRICT LA , void * LA_RESTRICT p, size_t oldsize) 538 | { 539 | LA_ASSERT(p); 540 | 541 | if(oldsize <= LA_MAX_ALLOC) 542 | { 543 | Block **spot = findspot(LA, p); /* Here, spot might point one past the end */ 544 | spot -= (spot > LA->all); /* One back unless we're already at the front -- now spot is always valid */ 545 | Block *b = *spot; 546 | checkblock(b); 547 | if(contains(b, p)) 548 | { 549 | freefromspot(LA, spot, p); 550 | return; 551 | } 552 | /* else p is outside of any block area. This case is unlikely but possible: 553 | - alloc large size (falling through to system alloc), 554 | - then, try to shrink it to fit inside LA_MAX_ALLOC, 555 | - ... but there is no block free for that size... 556 | - try to alloc new block and fail (out of memory) 557 | - then _Realloc() uses the original, still valid pointer since by spec shrink requests must not fail 558 | - Lua sees the "reallocated" (actually the old) pointer and records the new, smaller size; 559 | - when this pointer is freed, we're here in this situation. 560 | Therefore fall through to free a large allocation. */ 561 | } 562 | 563 | #ifdef LA_TRACK_STATS 564 | LA->stats.alive[BLOCK_ARRAY_SIZE]--; 565 | #endif 566 | 567 | sysfree(LA, p, oldsize); /* large Lua free */ 568 | } 569 | 570 | static void *_Realloc(LuaAlloc * LA_RESTRICT LA, void * LA_RESTRICT p, size_t newsize, size_t oldsize) 571 | { 572 | LA_ASSERT(p); 573 | void *newptr = _Alloc(LA, newsize); 574 | 575 | /* If the new allocation failed, just re-use the old pointer if it was a shrink request. 576 | This also satisfies Lua, which assumes that shrink requests cannot fail */ 577 | if(!newptr) 578 | return newsize <= oldsize ? p : NULL; 579 | 580 | const size_t minsize = oldsize < newsize ? oldsize : newsize; 581 | LA_MEMCPY(newptr, p, minsize); 582 | _Free(LA, p, oldsize); 583 | return newptr; 584 | } 585 | 586 | /* ---- Public API ---- */ 587 | 588 | #ifdef __cplusplus 589 | extern "C" { 590 | #endif 591 | 592 | void *luaalloc(void * ud, void *ptr, size_t oldsize, size_t newsize) 593 | { 594 | LuaAlloc *LA = (LuaAlloc*)ud; 595 | if(ptr) 596 | { 597 | if(!newsize) 598 | _Free(LA, ptr, oldsize); 599 | else if(newsize != oldsize) 600 | return _Realloc(LA, ptr, newsize, oldsize); 601 | else 602 | return ptr; 603 | } 604 | else if(newsize) 605 | return _Alloc(LA, newsize); 606 | 607 | return NULL; 608 | } 609 | 610 | #ifdef LA_ENABLE_DEFAULT_ALLOC 611 | void *defaultalloc(void *user, void *ptr, size_t osize, size_t nsize) 612 | { 613 | (void)user; 614 | (void)osize; 615 | if(nsize) 616 | return realloc(ptr, nsize); 617 | free(ptr); 618 | return NULL; 619 | } 620 | #endif 621 | 622 | LuaAlloc * luaalloc_create(LuaSysAlloc sysalloc, void *user) 623 | { 624 | if(!sysalloc) 625 | { 626 | #ifdef LA_ENABLE_DEFAULT_ALLOC 627 | sysalloc = defaultalloc; 628 | #else 629 | LA_ASSERT(sysalloc); 630 | return NULL; 631 | #endif 632 | } 633 | 634 | LuaAlloc *LA = (LuaAlloc*)sysalloc(user, NULL, LA_TYPE_INTERNAL, sizeof(LuaAlloc)); 635 | if(LA) 636 | { 637 | LA_MEMSET(LA, 0, sizeof(LuaAlloc)); 638 | LA->sysalloc = sysalloc; 639 | LA->user = user; 640 | } 641 | return LA; 642 | } 643 | 644 | void luaalloc_delete(LuaAlloc *LA) 645 | { 646 | LA_ASSERT(LA->allnum == 0); /* If this fails the Lua state didn't GC everything, which is a bug */ 647 | if(LA->all) 648 | sysfree(LA, LA->all, LA->allcap * sizeof(Block*)); 649 | sysfree(LA, LA, sizeof(LuaAlloc)); /* free self */ 650 | } 651 | 652 | /* ---- Optional stats tracking ---- */ 653 | 654 | unsigned luaalloc_getstats(const LuaAlloc *LA, const size_t ** alive, const size_t ** total, const size_t ** blocks, unsigned *pbinstep) 655 | { 656 | if(pbinstep) 657 | *pbinstep = LA_ALLOC_STEP; 658 | 659 | #ifdef LA_TRACK_STATS 660 | if(alive) 661 | *alive = LA->stats.alive; 662 | if(total) 663 | *total = LA->stats.total; 664 | if(blocks) 665 | *blocks = LA->stats.blocks_alive; 666 | return BLOCK_ARRAY_SIZE + 1; 667 | #else 668 | if(alive) 669 | *alive = NULL; 670 | if(total) 671 | *total = NULL; 672 | if(blocks) 673 | *blocks = NULL; 674 | return 0; 675 | #endif 676 | } 677 | 678 | #ifdef __cplusplus 679 | } 680 | #endif 681 | -------------------------------------------------------------------------------- /test/jps/maps/dao/den011d.map: -------------------------------------------------------------------------------- 1 | type octile 2 | height 167 3 | width 247 4 | map 5 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTT..TTTTTTTTTTTTTTTTTTTT............TTTT....T....TT.TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@ 7 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTT..TTTT.......TTTTTTTTT............TTTT.........TT.TTTT....TT@@@@@@@@@@@@@@@@@@@@@@@@ 8 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTT...TT........TTTTTTT..TTTT...TTTT.........................TT@@@@@@@@@@@@@@@@@@@@@@@@ 9 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTT..............TTTTTT..TTT....TTTT..........................T@@@@@@@@@@@@@@@@@@@@@@@@ 10 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT...................TTT@T.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 11 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT....................TTTT.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 12 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.............................TTT.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 13 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.............................TTT.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 14 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@.............................TTT.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@TTT..........................TTT.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 16 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@T@T..........................TTT.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@T@T..........................TTTT......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@T@T..........................TTTT.....................................TT@@@@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@TTT..........................TTTT.....................................TT@@@@@@@@@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@TT............TTTTT..........TTTTT............TTTT............TTTT....TT@@@@@@@@@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@TTT...........TTTTTT........TTTTTT............TTTT...........TTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT.....TT.....TTTT.....TTTTTT.TT@@@@@@@@@@@@@@@@TTTTTT.TTTTTTTTTTT............TT@@@@@@@@@@@@@@@@TTT...........TTTTT.........TTTTTT............TTTT............TTTTTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@ 23 | @@@@@@TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT............TTTT.....TTTTTT.TT@@@@@@@@@@@@@@@@TTTTTT.TTTTTTTTTTT............TT@@@@@@@@@@@@@@@@TTT...........TTTT...........TTTTT............TTTT............TTTT....T@@@@@@TTT@@@@@@@@@@@@@@@@ 24 | @@@@@@T...............................................T...............TT......TTTTTT.TT@@@@@@@@@@@@@@@@TT......TTTTT..................T@@@@@@@@@@@@@@@@T@T..........................TTTTT....................................T@@@@@@TTT@@@@@@@@@@@@@@@@ 25 | @@@@@@T...............................................T...............TT..............T@@@@@@@@@@@@@@@@TT......TTTTTT.................T@@@@@@@@@@@@@@@@T@T............................TTT....................................T@@@@@@TTT@@@@@@@@@@@@@@@@ 26 | @@@@@@T...............................................T...............................T@@@@@@@@@@@@@@@@TT......TTT..................TTT@@@@@@@@@@@@@@@@T@T............................TT.....................................TTTTTTTT.T@@@@@@@@@@@@@@@@ 27 | @@@@@@TT.............................................TTT..............................T@@@@@@@@@@@@@@@@......T......................TTT@@@@@@@@@@@@@@@@TTT...........................TTT..............................................T@@@@@@@@@@@@@@@@ 28 | @@@@@@TT.............................................TTT..............................T@@@@@@@@@@@@@@@@.....TTTT....................TTT@@@@@@@@@@@@@@@@TT............................TTT..............................................T@@@@@@@@@@@@@@@@ 29 | @@@@@@T...............................................................................T@@@@@@@@@@@@@@@@....TTTTT....................TTT@@@@@@@@@@@@@@@@TTTT..........................TTT..............................................T@@@@@@@@@@@@@@@@ 30 | @@@@@@T...............................................................................T@@@@@@@@@@@@@@@@.....TTT.....................TTT@@@@@@@@@@@@@@@@TTTT..........................TTT..............................................T@@@@@@@@@@@@@@@@ 31 | @@@@@@TT.............................................TTT..............................T@@@@@@@@@@@@@@@@T.....TT.......................T@@@@@@@@@@@@@@@@TTTTTT........................TTT..............................................T@@@@@@@@@@@@@@@@ 32 | @@@@@@TT.............................................TTT..............................T@@@@@@@@@@@@@@@@T..............................T@@@@@@@@@@@@@@@@TTTTTTTT......................TTTT.............................................T@@@@@@@@@@@@@@@@ 33 | @@@@@@T...............................................T...............................T@@@@@@@@@@@@@@@@T..............................T@@@@@@@@@@@@@@@@TTTTTTTTT.....................TTTT.............................................T@@@@@@@@@@@@@@@@ 34 | @@@@@@T...............................................T..............................TT@@@@@@@@@@@@@@@@T..............................T@@@@@@@@@@@@@@@@TTTTTTTTT.....................TTTT............................................TT@@@@@@@@@@@@@@@@ 35 | @@@@@@T...............................................T..............................TT@@@@@@@@@@@@@@@@T..............................T@@@@@@@@@@@@@@@@TTTTTTTTT.....................TTTT............................................TT@@@@@@@@@@@@@@@@ 36 | @@@@@@TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT............TTTT............TT@@@@@@@@@@@@@@@@TT............TTTT............TT@@@@@@@@@@@@@@@@TTTTTTTTT.....TTTT...T...T....TTTT............TTTT............TTTT............TT@@@@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TTTT............TT@@@@@@@@@@@@@@@@TT............TTTT............TT@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTTTTTTTT...TTTTTTTTT............TTTT...........TTTTTTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT............TTTT............TTTTT.........TTTTTT............TTTT............TTTTTTTTTTTTTTTTTTTT............TTTTTT.T...T....TTTT............TTTT............TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT........@...TTTT............TTTT............TTTT............TTTT............TTTT.TTTTTTTTTT.TTTT............TTTTTT..........TTTT............TTTT............TTTT....TT@@@@@@@@@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT...........................................TTT............................TTT...TTTTTTTTTT.....................TT...........T......................................TT@@@@@@@@@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT............................................................................T...............................................T.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT............................................................................T...............................................T.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT............................................................................TTT..............................................T.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT...........................................................................TTT..............................................T.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT...........................................................................................................................TT......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTT..........................................................................................................................T.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT........................................................................TTT..............................................T.......................................T@@@@@@@@@@@@@@@@@@@@@@@@ 48 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTT.......................................................................TTT..............................................TTTTT...................................T@@@@@@@@@@@@@@@@@@@@@@@@ 49 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTT......................................................................TT...............................................TTTTT...................................T@@@@@@@@@@@@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTT............TTTTTTT..................TTT.............................TT...............................................TTTTT..................................TT@@@@@@@@@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTTT.........TTTTTTTT..................TTT..............................T...............................................TTTTTTTTTTTTTTT........................TT@@@@@@@@@@@@@@@@@@@@@@@@ 52 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTTTTTT...TTTTTTT..TTTTT.........TTTTTT.TTT...T....TTTT............TTTT............TTTT............TTTT............TTTTTTTTTTTTTTTTTTTT...T...T....TTTT....TT@@@@@@@@@@@@@@@@@@@@@@@@ 53 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT............TTTTTTTTTTTTTTTTTTTTTTTT...TTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@ 54 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT...T...T....TT@@@@@@@@@@@@@@@@TTTTTT@TTT@TTTTTTT.........T@@TTTT............TTTTT.........TTTTTT.T.T...T....TTTTTTTTTTTTTTTTTTTT.....T......TT 55 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTT@@@@TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@TTT@@T@@@T@T@TTTTT.........T@@TTTT............TTTT..........TTTTTT............TTTT...TTTTTTTTTTTTT............TT 56 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@TTT@@TT@@TTT@T.............T@@TT...............................................T.....TTTTTTTTTT................T 57 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@TTTTTTTTTTTTTT.............T@@TT...............................................T............................TTTT 58 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@...........................T@@TT...............................................T............................TTTT 59 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@...........................T@@TT...............................................TTTT.........................TTTT 60 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@........TTTTTTTTTTTTTT.....TT@TT...............................................TTTT.........................TTTT 61 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@........TTTTTTTTTTTTTT.....TT@TT...............................................TTTT.........................TTTT 62 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@.......TTTTTTTTTTTTTTTT....T@@TT...............................................TTTT.........................TTTT 63 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@........TTTTTTTTTTTTTT.....T@@TT...............................................TTTT.........................TTTT 64 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT...........T@@@@@@@@@@@@@@@@........TTTTTTTTTTTTTT.....TT@TT...............................................TTTT.........................TTTT 65 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT...........T@@@@@@@@@@@@@@@@........TTTTTTTTTTTTTT.....TT@TT...............................................TTTT.......TTTTTTTTTT........TTTT 66 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT.........TTT@@@@@@@@@@@@@@@@...........................T@@TT...............................................TTTT.......TTTTTTTTTT........TTTT 67 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT.........TTT@@@@@@@@@@@@@@@@...........................TT@TT...............................................TTTT.......TTTTTTTTTT........TTTT 68 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..........TT@@@@@@@@@@@@@@@@TT............TTTT.........TTTTTTT............TTTTT..TTTTT..TTTTTT............TTTTT.......TTTTTTTTTT..........TT 69 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..........TT@@@@@@@@@@@@@@@@TT............TTTT.........TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT............TTTT............TTTT............TT 70 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..........TT@@@@@@@@@@@@@@@@TT............TTTT............TTTT......TTTTTTTTTTTTT@TTT@TTTTTTTT............TTTT............TTTT............TT 71 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT.........TTT@@@@@@@@@@@@@@@@TT............TTTT............TTTTT.......TTTTTTTTT@@@T@@@T@@@TTTT............TTTT............TTTT............TT 72 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT........TTTT@@@@@@@@@@@@@@@@..............................TTTTT...............T@@@T@@@T@@@@T...............TT..............................T 73 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT........TTTT@@@@@@@@@@@@@@@@..................................................TTTTTTTTTTTTTT...............T..............................TT 74 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT...........T@@@@@@@@@@@@@@@@.............................................................TTT...............T..............................TT 75 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.............TT@@@@@@@@@@@@@@@@.......T..............T......................................TTT..............TTT..............................T 76 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.............TT@@@@@@@@@@@@@@@@.......T..............T......................................TTT..............TTT......................TT......T 77 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@.............................................................TTT.........................TT............TT......T 78 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@TTT..........................................................TTT.......................TTTT...........TTTTT....T 79 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.............TT@@@@@@@@@@@@@@@@TTT..........................................................TTT..............TTT......TTTTT..........TTTTT....T 80 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.............TT@@@@@@@@@@@@@@@@TTT..........................................................TTT..............TTT.......TTTT...........TT......T 81 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.............TTT@@@@@@@@@@@@@@@@TTT..........................................................TTTTT.............TT.......TTT............TTTT....T 82 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@............TTTT@@@@@@@@@@@@@@@@TTTT..........................TTT..............................TTT.............T.........TT.............TTT...TT 83 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.............TTT@@@@@@@@@@@@@@@@TTTTT............TTTTTTTTT....TTTTT............................TTT.............T..............................TT 84 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T....T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@TTTT.....TTTTTTTTTTTTTTTTT....TTTTT...........TTTT............TTTT............TTTT............TTTT.....T......TT 85 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT............TTTT....TT.TT.TTTTTT............TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 86 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT..TT...TT...TTTT...TTTTTT...TTTT............TTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TTTT....TT.T..TTTTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 87 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TTTT...TTTTTT...TTTT............TTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TTTT............TTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 88 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............TTT....TTTTTT....................T...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............................T...........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 89 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.....................TTTTTT....................T...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............................T...........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 90 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@................TT.............................T...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............................T...........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 91 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT.............................................TTT..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............................TTT..........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 92 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.....TT.............................................TTT..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.......TTT.T..................TTT..........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 93 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.....................................................................T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.......TTTT................................TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 94 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.....................................................................T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@......TTTT.................................TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 95 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..TT.............................................TTT..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@............T.................TTT..........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 96 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT.............................................TTT..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@........T.....................TTT..........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 97 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............................................T...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............................T...........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 98 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............TTT..............................T...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.................TTTTTTTTT.....T...........TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 99 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............TTT..............................T...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.................TTTTTTTTT.....T...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 100 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TTTTT.........TTTTTTT.........TTTTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTT....TTTTTTTTTT@T....TTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 101 | @@@@@@@TTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TTTTT.........TTTTTTT.........TTTTTT............TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 102 | @@@@@@@TTTT........TTTTTT......T.....TTTTT....T....TTTTTT............TTTTT.........TTTTTTT.........TTTTTT............TTTT....TT......TTTTTTTTTTTTTTTTTTTTTTTTTT......TTTT............TTTT............TTTT............TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 103 | @@@@@@TTT............TTTT............TTTTT...........TTTT............TTTT............TTTT..........TTTTTT............TTTT....TT......TTTTTTTTTTTTTTTTTTTTTTTTTT......TTTT............TTTT............TTTT............TTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 104 | @@@@@@@...............................T..............................TTT...........................TTTT......................TT..........TTTTTTTTTTTTTTTTTTTTTT..........................T...........................TTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 105 | @@@@@@@...............................T...............................................................T..................................TTTTTTTTTTTTTTTTTTTTTT.........................T...........................TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 106 | @@@@@@@...............................T..............................................................TT..................................TTTTTTTTTTTTTTTTTTTTTT.....................................................TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 107 | TTTTTTTT.............................TTT.............................................................TT.............................................................................................................TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 108 | T.....TT.............................TTT.............................................................TT.............................................................................................................TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 109 | T....................................................................................................TT.............................................................................................................TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 110 | T....................................................................................................TT............................................................................................................TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 111 | TTTT..TT.............................TTT.............................................................TT............................................................................................................TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 112 | TTTTTTTT.............................TTT.............................................................TT....TT......................................................................................................TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 113 | @@@@@@@TTTTT..........................T...............................................................TTTTTTTTT..........................TTTTTTTTTT...............................................................TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 114 | @@@@@@@TTTTT.....................TTTTTTTTTTT.........................TTT...........................TTTTTTTTTTTTTT........TTT.............TTTTTTTTTT...........................................................TT.TTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 115 | @@@@@@@TTTTT.....................TTTTTTTTTTT.........................TTT................TT..TTTTT..TTTTTTTTTTTTTTTT......TTT.............TTTTTTTTTTTTT............................TTT......................TTTTTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 116 | @@@@@@@TTTTT.........TTTT......T.TTTTTTTTTTT..T....TTTTTT............TTTT............TTTTT.TTTTTT..TTTTTTTTTTTTTTTTTTTTTTTTTT...T....TTTTTTTTTTTTTTTTTTTTT...........TTTT...T...T.TTTTTTT..TTT.......TTTTTTTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 117 | @@@@@@@TTTTT.........TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT............TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 118 | @@@@@@@TTTTT.........TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT...TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT...T....TTTT............TT@TTTT@@TTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 119 | @@@@@@@TTTTT.........TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT...TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT........TTTT............TT@@@@@@@@TTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 120 | @@@@@@@TTTTT..........T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT...........TTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT..........................T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 121 | @@@@@@@TTTTT..........T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T.............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT....................TT....T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 122 | @@@@@@@TTTTT..........T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT........................T..T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 123 | TTTTTTTT..............T@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT.............TTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT.......................TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 124 | T.....TT..............T@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT.............TT....TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT...................TTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 125 | T.....................T@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT....................T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT..........TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..................TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 126 | T.....................T@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT....................T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT..........TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@......................TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 127 | TTTT..TT..............T@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT.............TT..TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT...........T@T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.....................TTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 128 | TTTTTTTT..............T@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT.............TTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT...........T@T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.....................TTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 129 | @@@@@@@...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT...........T@T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.......................TTTTTTT@T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 130 | @@@@@@@............TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T..............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT.....TTTTT@T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT.....................TTTTTT@T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 131 | @@@@@@@............TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT...TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT....................TTTTTTT@T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 132 | @@@@@@@TTT....T....TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT...T...T....TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTT.TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT...........TTTT....TTTTTTT@TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 133 | @@@@@@@TTTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT...TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..........TTTT....TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 134 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.....T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT.........TTTT...TTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 135 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T....T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..........TTTT...TTTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 136 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT.....................TTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 137 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT......................TT.TTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 138 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............................TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 139 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............................TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 140 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............................TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 141 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.........................TTT..TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 142 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..........................TT..TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 143 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.......................TTTT...TT@@@@@TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 144 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T......................TTTTT..TT@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 145 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T......................TTTTT...T@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 146 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT.....................TT......T@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 147 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT................TTTT.TT......T@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 148 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT...T...T....TTTTTTTT.TT...TTTT@@@@@T....T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 149 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT...TTTTTTTTTTTTTTTTTTTTTTT@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 150 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTT...TTTTTTTTTT.......TTTTTTTTTTTT...TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 151 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT........@...TTTTT...........TTTT............TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 152 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT...........................................TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 153 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..........................................TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 154 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT..........................................TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 155 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT..........................................TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@ 156 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT.........................................TTTTTTT@TT@@@@@@@@@@@@@@@@@@@@@@@@@@ 157 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT.........................................TTTTTTT@TT@@@@@@@@@@@@@@@@@@@@@@@@@@ 158 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT.........................................TTTTTTT@TT@@@@@@@@@@@@@@@@@@@@@@@@@@ 159 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT.........................................TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@ 160 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT..........................................TTTTTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@ 161 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT...........................................TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 162 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TT............................TTTTT...........TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 163 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTT......TTTT....T............TTTTT...........TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 164 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTT....TTTTTTTTTTTT...T...T..TTTTTT...T...T..TTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 165 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTT..TTTTTTTTTTTTTTTTT...TTTTTTTTTTTTT...TTTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 166 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTTTTTTTTT@@@@@.....T@@@@@@@@@@.....T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 167 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTTTTTTT@@@@TT@@@@@T....T@@@@@@@@@@T....T@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 168 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 169 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 170 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@T...TT@@@@@@@@@@T...TT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 171 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TTTTTT@@@@@@@@@@TTTTTT@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 172 | -------------------------------------------------------------------------------- /test/jps/maps/den011d.map.scen: -------------------------------------------------------------------------------- 1 | version 1 2 | 0 maps/dao/den011d.map 247 167 103 39 102 37 2.41421 3 | 0 maps/dao/den011d.map 247 167 104 43 102 44 2.41421 4 | 0 maps/dao/den011d.map 247 167 104 99 106 99 2 5 | 0 maps/dao/den011d.map 247 167 105 20 108 20 3 6 | 0 maps/dao/den011d.map 247 167 106 45 109 45 3 7 | 0 maps/dao/den011d.map 247 167 106 86 106 83 3 8 | 0 maps/dao/den011d.map 247 167 107 106 108 105 1.41421 9 | 0 maps/dao/den011d.map 247 167 107 37 110 35 3.82843 10 | 0 maps/dao/den011d.map 247 167 108 27 111 27 3 11 | 0 maps/dao/den011d.map 247 167 108 85 108 86 1 12 | 1 maps/dao/den011d.map 247 167 10 100 14 103 5.24264 13 | 1 maps/dao/den011d.map 247 167 10 23 16 25 6.82843 14 | 1 maps/dao/den011d.map 247 167 100 100 98 107 7.82843 15 | 1 maps/dao/den011d.map 247 167 100 105 98 109 4.82843 16 | 1 maps/dao/den011d.map 247 167 100 106 98 100 6.82843 17 | 1 maps/dao/den011d.map 247 167 104 52 109 54 5.82843 18 | 1 maps/dao/den011d.map 247 167 104 83 108 89 7.65685 19 | 1 maps/dao/den011d.map 247 167 105 23 106 30 7.41421 20 | 1 maps/dao/den011d.map 247 167 105 79 107 84 5.82843 21 | 1 maps/dao/den011d.map 247 167 105 92 104 86 6.41421 22 | 2 maps/dao/den011d.map 247 167 100 41 106 33 10.4853 23 | 2 maps/dao/den011d.map 247 167 100 88 106 83 9.82843 24 | 2 maps/dao/den011d.map 247 167 101 42 107 36 8.48528 25 | 2 maps/dao/den011d.map 247 167 102 88 113 88 11 26 | 2 maps/dao/den011d.map 247 167 103 42 95 45 9.24264 27 | 2 maps/dao/den011d.map 247 167 104 70 105 80 10.4142 28 | 2 maps/dao/den011d.map 247 167 104 92 107 83 10.2426 29 | 2 maps/dao/den011d.map 247 167 105 104 113 96 11.3137 30 | 2 maps/dao/den011d.map 247 167 105 58 113 52 10.4853 31 | 2 maps/dao/den011d.map 247 167 105 70 114 63 11.8995 32 | 3 maps/dao/den011d.map 247 167 100 81 106 84 15.8284 33 | 3 maps/dao/den011d.map 247 167 100 88 105 79 13.4142 34 | 3 maps/dao/den011d.map 247 167 101 40 112 35 13.0711 35 | 3 maps/dao/den011d.map 247 167 101 41 90 45 12.6569 36 | 3 maps/dao/den011d.map 247 167 101 42 88 45 14.2426 37 | 3 maps/dao/den011d.map 247 167 101 93 89 92 12.4142 38 | 3 maps/dao/den011d.map 247 167 101 93 90 97 12.6569 39 | 3 maps/dao/den011d.map 247 167 102 36 116 35 14.4142 40 | 3 maps/dao/den011d.map 247 167 102 39 114 35 13.6569 41 | 3 maps/dao/den011d.map 247 167 103 22 112 32 13.7279 42 | 4 maps/dao/den011d.map 247 167 10 106 26 111 18.0711 43 | 4 maps/dao/den011d.map 247 167 100 107 83 100 19.8995 44 | 4 maps/dao/den011d.map 247 167 100 37 115 44 17.8995 45 | 4 maps/dao/den011d.map 247 167 100 86 87 99 19.5563 46 | 4 maps/dao/den011d.map 247 167 101 38 116 34 16.6569 47 | 4 maps/dao/den011d.map 247 167 101 41 118 37 18.6569 48 | 4 maps/dao/den011d.map 247 167 101 85 106 97 17.2426 49 | 4 maps/dao/den011d.map 247 167 101 94 113 90 18.8284 50 | 4 maps/dao/den011d.map 247 167 102 38 112 52 18.1421 51 | 4 maps/dao/den011d.map 247 167 103 100 121 104 19.6569 52 | 5 maps/dao/den011d.map 247 167 1 121 19 112 21.7279 53 | 5 maps/dao/den011d.map 247 167 10 119 28 109 22.1421 54 | 5 maps/dao/den011d.map 247 167 10 120 7 101 22.4853 55 | 5 maps/dao/den011d.map 247 167 10 19 31 20 21.4142 56 | 5 maps/dao/den011d.map 247 167 100 91 107 75 20.6569 57 | 5 maps/dao/den011d.map 247 167 101 37 113 53 20.9706 58 | 5 maps/dao/den011d.map 247 167 101 42 114 58 23.7279 59 | 5 maps/dao/den011d.map 247 167 101 43 79 43 22 60 | 5 maps/dao/den011d.map 247 167 102 37 114 53 20.9706 61 | 5 maps/dao/den011d.map 247 167 102 37 115 55 23.3848 62 | 6 maps/dao/den011d.map 247 167 10 103 34 106 25.2426 63 | 6 maps/dao/den011d.map 247 167 10 118 30 100 27.4558 64 | 6 maps/dao/den011d.map 247 167 10 20 34 22 24.8284 65 | 6 maps/dao/den011d.map 247 167 100 107 95 84 25.0711 66 | 6 maps/dao/den011d.map 247 167 100 34 105 53 24.9706 67 | 6 maps/dao/den011d.map 247 167 100 94 76 99 26.0711 68 | 6 maps/dao/den011d.map 247 167 101 43 124 32 27.5563 69 | 6 maps/dao/den011d.map 247 167 102 37 126 34 25.2426 70 | 6 maps/dao/den011d.map 247 167 102 40 78 33 26.8995 71 | 6 maps/dao/den011d.map 247 167 102 42 82 29 27.7279 72 | 7 maps/dao/den011d.map 247 167 100 105 113 91 31.4853 73 | 7 maps/dao/den011d.map 247 167 100 40 124 21 31.8701 74 | 7 maps/dao/den011d.map 247 167 100 40 129 39 29.4142 75 | 7 maps/dao/den011d.map 247 167 100 40 84 23 30.0711 76 | 7 maps/dao/den011d.map 247 167 100 82 81 101 30.3848 77 | 7 maps/dao/den011d.map 247 167 100 86 112 108 28.7279 78 | 7 maps/dao/den011d.map 247 167 100 91 70 90 30.4142 79 | 7 maps/dao/den011d.map 247 167 101 38 75 33 28.0711 80 | 7 maps/dao/den011d.map 247 167 102 38 123 15 31.6985 81 | 7 maps/dao/den011d.map 247 167 103 51 124 36 28.3848 82 | 8 maps/dao/den011d.map 247 167 10 127 2 104 32.0711 83 | 8 maps/dao/den011d.map 247 167 10 98 40 107 34.8995 84 | 8 maps/dao/den011d.map 247 167 100 101 74 84 33.0416 85 | 8 maps/dao/den011d.map 247 167 100 34 130 40 33.6569 86 | 8 maps/dao/den011d.map 247 167 100 37 80 20 33.4853 87 | 8 maps/dao/den011d.map 247 167 100 38 125 15 34.5269 88 | 8 maps/dao/den011d.map 247 167 100 39 120 14 35.2843 89 | 8 maps/dao/den011d.map 247 167 100 82 73 101 34.8701 90 | 8 maps/dao/den011d.map 247 167 100 85 116 64 35.9706 91 | 8 maps/dao/den011d.map 247 167 101 36 111 65 33.1421 92 | 9 maps/dao/den011d.map 247 167 10 124 35 100 37.2843 93 | 9 maps/dao/den011d.map 247 167 100 37 107 70 37.5563 94 | 9 maps/dao/den011d.map 247 167 100 37 76 18 37.1421 95 | 9 maps/dao/den011d.map 247 167 100 41 67 29 37.9706 96 | 9 maps/dao/den011d.map 247 167 101 100 112 103 36.1421 97 | 9 maps/dao/den011d.map 247 167 101 38 131 23 36.2132 98 | 9 maps/dao/den011d.map 247 167 101 39 129 19 36.2843 99 | 9 maps/dao/den011d.map 247 167 101 44 122 13 39.6985 100 | 9 maps/dao/den011d.map 247 167 103 100 107 64 38.2426 101 | 9 maps/dao/den011d.map 247 167 103 52 132 37 36.3848 102 | 10 maps/dao/den011d.map 247 167 10 100 50 100 43.3137 103 | 10 maps/dao/den011d.map 247 167 100 104 116 71 43.0416 104 | 10 maps/dao/den011d.map 247 167 100 105 67 86 40.8701 105 | 10 maps/dao/den011d.map 247 167 100 84 109 57 41.0711 106 | 10 maps/dao/den011d.map 247 167 100 88 115 55 41.5563 107 | 10 maps/dao/den011d.map 247 167 101 108 66 88 43.2843 108 | 10 maps/dao/den011d.map 247 167 101 41 112 78 43.3137 109 | 10 maps/dao/den011d.map 247 167 101 42 60 38 42.6569 110 | 10 maps/dao/den011d.map 247 167 102 36 131 9 40.1838 111 | 10 maps/dao/den011d.map 247 167 102 36 141 41 41.0711 112 | 11 maps/dao/den011d.map 247 167 10 127 40 107 45.2132 113 | 11 maps/dao/den011d.map 247 167 100 103 54 105 46.8284 114 | 11 maps/dao/den011d.map 247 167 100 41 115 78 46.1421 115 | 11 maps/dao/den011d.map 247 167 100 42 143 45 45.0711 116 | 11 maps/dao/den011d.map 247 167 100 45 64 18 47.1838 117 | 11 maps/dao/den011d.map 247 167 100 45 65 19 45.7696 118 | 11 maps/dao/den011d.map 247 167 100 81 134 100 45.9706 119 | 11 maps/dao/den011d.map 247 167 100 92 136 105 45.6274 120 | 11 maps/dao/den011d.map 247 167 100 94 110 55 44.8995 121 | 11 maps/dao/den011d.map 247 167 100 94 112 55 45.7279 122 | 12 maps/dao/den011d.map 247 167 100 35 109 83 51.7279 123 | 12 maps/dao/den011d.map 247 167 101 37 150 37 51.4853 124 | 12 maps/dao/den011d.map 247 167 102 39 105 84 49.5563 125 | 12 maps/dao/den011d.map 247 167 102 89 67 117 51.2843 126 | 12 maps/dao/den011d.map 247 167 103 54 128 16 49.5269 127 | 12 maps/dao/den011d.map 247 167 103 84 65 99 48.799 128 | 12 maps/dao/den011d.map 247 167 104 100 65 91 51.6569 129 | 12 maps/dao/den011d.map 247 167 104 106 80 109 50.1127 130 | 12 maps/dao/den011d.map 247 167 104 26 67 39 49.0711 131 | 12 maps/dao/den011d.map 247 167 104 40 152 36 49.6569 132 | 13 maps/dao/den011d.map 247 167 10 120 55 110 53.2843 133 | 13 maps/dao/den011d.map 247 167 100 42 116 85 52.5563 134 | 13 maps/dao/den011d.map 247 167 101 43 152 43 52.6569 135 | 13 maps/dao/den011d.map 247 167 101 84 144 103 54.6274 136 | 13 maps/dao/den011d.map 247 167 101 94 141 104 52.6274 137 | 13 maps/dao/den011d.map 247 167 101 94 54 109 53.2132 138 | 13 maps/dao/den011d.map 247 167 102 43 58 18 54.3553 139 | 13 maps/dao/den011d.map 247 167 103 104 66 86 55.4853 140 | 13 maps/dao/den011d.map 247 167 103 76 117 29 53.3848 141 | 13 maps/dao/den011d.map 247 167 103 94 58 100 55.9706 142 | 14 maps/dao/den011d.map 247 167 10 98 59 116 58.799 143 | 14 maps/dao/den011d.map 247 167 100 100 112 51 58.5563 144 | 14 maps/dao/den011d.map 247 167 100 104 131 110 56.3553 145 | 14 maps/dao/den011d.map 247 167 103 54 95 104 58.3848 146 | 14 maps/dao/den011d.map 247 167 103 57 66 41 58.5563 147 | 14 maps/dao/den011d.map 247 167 103 58 125 9 58.1127 148 | 14 maps/dao/den011d.map 247 167 103 88 102 37 56.9706 149 | 14 maps/dao/den011d.map 247 167 103 89 110 32 59.8995 150 | 14 maps/dao/den011d.map 247 167 103 93 66 118 59.1127 151 | 14 maps/dao/den011d.map 247 167 104 22 154 42 58.8701 152 | 15 maps/dao/den011d.map 247 167 10 102 62 118 60.3848 153 | 15 maps/dao/den011d.map 247 167 10 105 68 118 63.3848 154 | 15 maps/dao/den011d.map 247 167 10 30 66 19 60.5563 155 | 15 maps/dao/den011d.map 247 167 100 36 43 27 62.3848 156 | 15 maps/dao/den011d.map 247 167 100 43 159 42 60.2426 157 | 15 maps/dao/den011d.map 247 167 100 87 59 127 63.4264 158 | 15 maps/dao/den011d.map 247 167 101 108 135 101 61.6274 159 | 15 maps/dao/den011d.map 247 167 103 22 157 36 63.1127 160 | 15 maps/dao/den011d.map 247 167 103 39 110 100 63.8995 161 | 15 maps/dao/den011d.map 247 167 103 39 98 94 63.799 162 | 16 maps/dao/den011d.map 247 167 10 100 68 117 65.0416 163 | 16 maps/dao/den011d.map 247 167 10 104 65 87 64.3848 164 | 16 maps/dao/den011d.map 247 167 10 123 66 105 65.2132 165 | 16 maps/dao/den011d.map 247 167 10 20 62 39 64.5563 166 | 16 maps/dao/den011d.map 247 167 10 21 70 38 67.6274 167 | 16 maps/dao/den011d.map 247 167 100 36 99 91 64.6274 168 | 16 maps/dao/den011d.map 247 167 100 37 112 99 66.9706 169 | 16 maps/dao/den011d.map 247 167 100 84 63 128 64.0122 170 | 16 maps/dao/den011d.map 247 167 100 84 99 40 64.5563 171 | 16 maps/dao/den011d.map 247 167 100 85 111 32 65.8995 172 | 17 maps/dao/den011d.map 247 167 10 100 78 109 71.7279 173 | 17 maps/dao/den011d.map 247 167 10 103 77 101 68.6569 174 | 17 maps/dao/den011d.map 247 167 10 119 73 103 69.6274 175 | 17 maps/dao/den011d.map 247 167 10 99 72 90 69.8701 176 | 17 maps/dao/den011d.map 247 167 100 42 112 106 71.8995 177 | 17 maps/dao/den011d.map 247 167 101 108 123 122 68.7696 178 | 17 maps/dao/den011d.map 247 167 101 108 35 103 68.0711 179 | 17 maps/dao/den011d.map 247 167 101 108 37 108 70.2426 180 | 17 maps/dao/den011d.map 247 167 101 38 117 103 71.6274 181 | 17 maps/dao/den011d.map 247 167 102 36 112 102 70.1421 182 | 18 maps/dao/den011d.map 247 167 1 103 75 106 75.2426 183 | 18 maps/dao/den011d.map 247 167 10 122 59 127 75.1127 184 | 18 maps/dao/den011d.map 247 167 10 122 76 101 75.8701 185 | 18 maps/dao/den011d.map 247 167 10 28 81 25 72.2426 186 | 18 maps/dao/den011d.map 247 167 100 101 153 104 73.4558 187 | 18 maps/dao/den011d.map 247 167 100 101 30 101 72.4853 188 | 18 maps/dao/den011d.map 247 167 100 42 89 81 72.6274 189 | 18 maps/dao/den011d.map 247 167 100 43 35 21 74.1127 190 | 18 maps/dao/den011d.map 247 167 100 84 36 105 72.6985 191 | 18 maps/dao/den011d.map 247 167 100 92 166 105 75.6274 192 | 19 maps/dao/den011d.map 247 167 10 127 75 102 79.4558 193 | 19 maps/dao/den011d.map 247 167 100 102 99 38 76.4558 194 | 19 maps/dao/den011d.map 247 167 100 35 110 107 76.1421 195 | 19 maps/dao/den011d.map 247 167 100 35 26 24 78.5563 196 | 19 maps/dao/den011d.map 247 167 100 38 116 107 76.2132 197 | 19 maps/dao/den011d.map 247 167 101 100 156 107 78.2843 198 | 19 maps/dao/den011d.map 247 167 101 43 33 27 76.2843 199 | 19 maps/dao/den011d.map 247 167 102 40 80 88 77.5563 200 | 19 maps/dao/den011d.map 247 167 103 104 128 42 79.9706 201 | 19 maps/dao/den011d.map 247 167 103 23 50 19 77.0416 202 | 20 maps/dao/den011d.map 247 167 1 103 67 127 80.0416 203 | 20 maps/dao/den011d.map 247 167 100 100 20 102 82.4853 204 | 20 maps/dao/den011d.map 247 167 100 103 20 98 83.4853 205 | 20 maps/dao/den011d.map 247 167 100 45 167 55 83.1421 206 | 20 maps/dao/den011d.map 247 167 100 83 27 105 82.1127 207 | 20 maps/dao/den011d.map 247 167 100 84 26 105 82.6985 208 | 20 maps/dao/den011d.map 247 167 100 88 123 18 81.8701 209 | 20 maps/dao/den011d.map 247 167 100 93 109 17 83.9706 210 | 20 maps/dao/den011d.map 247 167 100 93 25 109 81.6274 211 | 20 maps/dao/den011d.map 247 167 101 36 127 104 82.2843 212 | 21 maps/dao/den011d.map 247 167 10 103 95 104 85.4142 213 | 21 maps/dao/den011d.map 247 167 10 122 88 103 87.0416 214 | 21 maps/dao/den011d.map 247 167 100 105 15 100 87.0711 215 | 21 maps/dao/den011d.map 247 167 100 34 129 102 85.8701 216 | 21 maps/dao/den011d.map 247 167 100 39 172 60 87.1421 217 | 21 maps/dao/den011d.map 247 167 100 41 134 105 87.4558 218 | 21 maps/dao/den011d.map 247 167 100 43 179 27 86.799 219 | 21 maps/dao/den011d.map 247 167 100 43 81 109 86.598 220 | 21 maps/dao/den011d.map 247 167 100 86 126 18 85.1127 221 | 21 maps/dao/den011d.map 247 167 100 86 72 44 87.8995 222 | 22 maps/dao/den011d.map 247 167 10 24 92 42 89.4558 223 | 22 maps/dao/den011d.map 247 167 100 103 84 41 91.2132 224 | 22 maps/dao/den011d.map 247 167 100 38 183 54 89.6274 225 | 22 maps/dao/den011d.map 247 167 100 45 175 23 89.9706 226 | 22 maps/dao/den011d.map 247 167 100 83 174 114 91.5269 227 | 22 maps/dao/den011d.map 247 167 100 93 128 16 90.3553 228 | 22 maps/dao/den011d.map 247 167 101 41 16 25 91.6274 229 | 22 maps/dao/den011d.map 247 167 101 41 185 57 90.6274 230 | 22 maps/dao/den011d.map 247 167 101 44 182 60 90.6985 231 | 22 maps/dao/den011d.map 247 167 101 92 16 105 90.3848 232 | 23 maps/dao/den011d.map 247 167 10 100 97 92 93.6274 233 | 23 maps/dao/den011d.map 247 167 10 122 94 100 94.2843 234 | 23 maps/dao/den011d.map 247 167 10 29 96 39 93.4558 235 | 23 maps/dao/den011d.map 247 167 100 102 10 101 92.0711 236 | 23 maps/dao/den011d.map 247 167 100 45 175 20 92.9706 237 | 23 maps/dao/den011d.map 247 167 100 83 129 13 94.3553 238 | 23 maps/dao/den011d.map 247 167 101 84 173 117 93.5269 239 | 23 maps/dao/den011d.map 247 167 101 84 82 23 94.8701 240 | 23 maps/dao/den011d.map 247 167 102 37 13 22 95.2132 241 | 23 maps/dao/den011d.map 247 167 102 41 68 100 94.1127 242 | 24 maps/dao/den011d.map 247 167 1 121 84 87 97.0833 243 | 24 maps/dao/den011d.map 247 167 100 103 9 122 99.4558 244 | 24 maps/dao/den011d.map 247 167 100 105 8 118 97.3848 245 | 24 maps/dao/den011d.map 247 167 100 106 14 124 98.9706 246 | 24 maps/dao/den011d.map 247 167 100 35 178 18 96.2132 247 | 24 maps/dao/den011d.map 247 167 100 35 8 26 96.5563 248 | 24 maps/dao/den011d.map 247 167 100 37 68 102 98.598 249 | 24 maps/dao/den011d.map 247 167 100 90 190 105 97.6274 250 | 24 maps/dao/den011d.map 247 167 102 44 169 12 98.799 251 | 24 maps/dao/den011d.map 247 167 103 105 79 31 97.6985 252 | 25 maps/dao/den011d.map 247 167 10 121 95 84 100.912 253 | 25 maps/dao/den011d.map 247 167 100 94 156 43 102.213 254 | 25 maps/dao/den011d.map 247 167 101 83 157 40 102.799 255 | 25 maps/dao/den011d.map 247 167 101 83 65 36 101.627 256 | 25 maps/dao/den011d.map 247 167 101 93 173 126 102.113 257 | 25 maps/dao/den011d.map 247 167 101 94 70 25 101.598 258 | 25 maps/dao/den011d.map 247 167 102 36 160 12 102.527 259 | 25 maps/dao/den011d.map 247 167 102 39 168 7 102.971 260 | 25 maps/dao/den011d.map 247 167 103 103 202 99 100.657 261 | 25 maps/dao/den011d.map 247 167 103 25 20 30 103.456 262 | 26 maps/dao/den011d.map 247 167 10 102 106 86 104.284 263 | 26 maps/dao/den011d.map 247 167 100 100 174 122 107.941 264 | 26 maps/dao/den011d.map 247 167 100 103 70 45 104.385 265 | 26 maps/dao/den011d.map 247 167 100 35 172 5 107.556 266 | 26 maps/dao/den011d.map 247 167 100 36 165 7 107.456 267 | 26 maps/dao/den011d.map 247 167 100 37 60 102 106.598 268 | 26 maps/dao/den011d.map 247 167 100 81 157 43 104.799 269 | 26 maps/dao/den011d.map 247 167 100 91 161 46 105.456 270 | 26 maps/dao/den011d.map 247 167 101 41 200 56 105.213 271 | 26 maps/dao/den011d.map 247 167 103 23 159 12 107.326 272 | 27 maps/dao/den011d.map 247 167 100 106 187 102 111.042 273 | 27 maps/dao/den011d.map 247 167 100 34 159 9 109.941 274 | 27 maps/dao/den011d.map 247 167 100 37 203 54 110.042 275 | 27 maps/dao/den011d.map 247 167 100 87 61 19 108.255 276 | 27 maps/dao/den011d.map 247 167 101 37 166 4 108.627 277 | 27 maps/dao/den011d.map 247 167 101 38 158 104 111.284 278 | 27 maps/dao/den011d.map 247 167 102 39 153 8 108.184 279 | 27 maps/dao/den011d.map 247 167 102 41 60 116 108.74 280 | 27 maps/dao/den011d.map 247 167 102 88 172 38 111.213 281 | 27 maps/dao/den011d.map 247 167 103 36 58 104 109.184 282 | 28 maps/dao/den011d.map 247 167 10 126 106 87 115.669 283 | 28 maps/dao/den011d.map 247 167 10 21 116 28 115.527 284 | 28 maps/dao/den011d.map 247 167 10 24 107 53 115.941 285 | 28 maps/dao/den011d.map 247 167 100 102 65 31 113.941 286 | 28 maps/dao/den011d.map 247 167 100 83 3 119 112.74 287 | 28 maps/dao/den011d.map 247 167 100 85 187 133 113.912 288 | 28 maps/dao/den011d.map 247 167 100 88 170 140 113.355 289 | 28 maps/dao/den011d.map 247 167 101 88 203 92 114.87 290 | 28 maps/dao/den011d.map 247 167 102 37 207 56 112.87 291 | 28 maps/dao/den011d.map 247 167 102 39 206 46 112.799 292 | 29 maps/dao/den011d.map 247 167 10 25 118 22 118.355 293 | 29 maps/dao/den011d.map 247 167 100 103 196 106 118.698 294 | 29 maps/dao/den011d.map 247 167 100 106 62 33 119.527 295 | 29 maps/dao/den011d.map 247 167 100 34 207 61 119.355 296 | 29 maps/dao/den011d.map 247 167 100 88 176 46 118.042 297 | 29 maps/dao/den011d.map 247 167 101 39 164 101 116.456 298 | 29 maps/dao/den011d.map 247 167 103 52 10 25 118.527 299 | 29 maps/dao/den011d.map 247 167 103 53 13 20 118.012 300 | 29 maps/dao/den011d.map 247 167 104 24 66 111 116.255 301 | 29 maps/dao/den011d.map 247 167 104 36 49 105 118.184 302 | 30 maps/dao/den011d.map 247 167 100 100 60 21 121.669 303 | 30 maps/dao/den011d.map 247 167 100 104 60 23 123.669 304 | 30 maps/dao/den011d.map 247 167 100 107 193 109 120.941 305 | 30 maps/dao/den011d.map 247 167 100 108 160 43 121.87 306 | 30 maps/dao/den011d.map 247 167 100 39 210 41 121.456 307 | 30 maps/dao/den011d.map 247 167 100 84 184 140 120.669 308 | 30 maps/dao/den011d.map 247 167 100 86 211 94 122.113 309 | 30 maps/dao/den011d.map 247 167 101 43 40 104 123.941 310 | 30 maps/dao/den011d.map 247 167 102 36 204 71 120.012 311 | 30 maps/dao/den011d.map 247 167 102 41 203 75 121.527 312 | 31 maps/dao/den011d.map 247 167 1 120 113 90 125.255 313 | 31 maps/dao/den011d.map 247 167 10 118 114 105 126.154 314 | 31 maps/dao/den011d.map 247 167 10 122 115 103 127.397 315 | 31 maps/dao/den011d.map 247 167 10 21 129 36 125.213 316 | 31 maps/dao/den011d.map 247 167 10 23 122 16 126.841 317 | 31 maps/dao/den011d.map 247 167 10 23 130 32 127.042 318 | 31 maps/dao/den011d.map 247 167 100 82 181 41 126.971 319 | 31 maps/dao/den011d.map 247 167 100 83 177 34 124.87 320 | 31 maps/dao/den011d.map 247 167 100 85 44 26 125.184 321 | 31 maps/dao/den011d.map 247 167 101 92 178 54 127.77 322 | 32 maps/dao/den011d.map 247 167 10 123 113 73 128.983 323 | 32 maps/dao/den011d.map 247 167 10 22 111 68 131.77 324 | 32 maps/dao/den011d.map 247 167 10 27 132 28 130.698 325 | 32 maps/dao/den011d.map 247 167 100 101 173 145 130.941 326 | 32 maps/dao/den011d.map 247 167 100 103 180 141 131.255 327 | 32 maps/dao/den011d.map 247 167 100 106 178 137 129.426 328 | 32 maps/dao/den011d.map 247 167 100 108 183 131 129.255 329 | 32 maps/dao/den011d.map 247 167 100 37 216 36 129.77 330 | 32 maps/dao/den011d.map 247 167 100 39 193 36 130.527 331 | 32 maps/dao/den011d.map 247 167 100 41 212 79 131.255 332 | 33 maps/dao/den011d.map 247 167 10 21 122 11 132.669 333 | 33 maps/dao/den011d.map 247 167 100 107 175 42 135.456 334 | 33 maps/dao/den011d.map 247 167 100 87 166 21 132.77 335 | 33 maps/dao/den011d.map 247 167 100 91 172 20 132.698 336 | 33 maps/dao/den011d.map 247 167 101 38 200 28 133.87 337 | 33 maps/dao/den011d.map 247 167 101 83 197 94 133.284 338 | 33 maps/dao/den011d.map 247 167 101 88 188 149 132.184 339 | 33 maps/dao/den011d.map 247 167 101 88 200 71 135.456 340 | 33 maps/dao/den011d.map 247 167 102 36 177 108 133.527 341 | 33 maps/dao/den011d.map 247 167 102 40 203 87 133.941 342 | 34 maps/dao/den011d.map 247 167 1 104 110 63 137.113 343 | 34 maps/dao/den011d.map 247 167 10 20 115 70 136.255 344 | 34 maps/dao/den011d.map 247 167 100 103 50 19 136.083 345 | 34 maps/dao/den011d.map 247 167 100 104 204 86 138.527 346 | 34 maps/dao/den011d.map 247 167 100 36 182 103 137.284 347 | 34 maps/dao/den011d.map 247 167 100 46 208 28 136.042 348 | 34 maps/dao/den011d.map 247 167 100 81 190 82 138.355 349 | 34 maps/dao/den011d.map 247 167 100 92 187 58 137.426 350 | 34 maps/dao/den011d.map 247 167 100 93 160 27 138.527 351 | 34 maps/dao/den011d.map 247 167 101 37 189 30 136.841 352 | 35 maps/dao/den011d.map 247 167 10 98 139 103 143.497 353 | 35 maps/dao/den011d.map 247 167 100 103 178 25 143.012 354 | 35 maps/dao/den011d.map 247 167 100 103 41 25 140.841 355 | 35 maps/dao/den011d.map 247 167 100 104 43 24 140.255 356 | 35 maps/dao/den011d.map 247 167 100 39 27 98 142.083 357 | 35 maps/dao/den011d.map 247 167 100 42 172 123 141.527 358 | 35 maps/dao/den011d.map 247 167 100 44 25 100 141.184 359 | 35 maps/dao/den011d.map 247 167 100 45 182 118 141.77 360 | 35 maps/dao/den011d.map 247 167 100 46 186 27 143.669 361 | 35 maps/dao/den011d.map 247 167 100 85 178 88 143.87 362 | 36 maps/dao/den011d.map 247 167 1 120 130 103 147.64 363 | 36 maps/dao/den011d.map 247 167 10 23 114 83 147.598 364 | 36 maps/dao/den011d.map 247 167 10 98 130 119 144.054 365 | 36 maps/dao/den011d.map 247 167 10 98 141 103 145.497 366 | 36 maps/dao/den011d.map 247 167 100 35 169 124 147.841 367 | 36 maps/dao/den011d.map 247 167 100 36 191 87 147.598 368 | 36 maps/dao/den011d.map 247 167 100 44 192 84 147.012 369 | 36 maps/dao/den011d.map 247 167 100 44 192 86 146.184 370 | 36 maps/dao/den011d.map 247 167 100 45 193 84 147.598 371 | 36 maps/dao/den011d.map 247 167 100 88 201 51 145.113 372 | 37 maps/dao/den011d.map 247 167 1 120 111 59 148.154 373 | 37 maps/dao/den011d.map 247 167 10 123 126 119 149.539 374 | 37 maps/dao/den011d.map 247 167 10 126 136 101 149.811 375 | 37 maps/dao/den011d.map 247 167 10 20 117 83 150.669 376 | 37 maps/dao/den011d.map 247 167 100 101 179 18 149.012 377 | 37 maps/dao/den011d.map 247 167 100 101 187 60 149.497 378 | 37 maps/dao/den011d.map 247 167 100 102 184 91 149.527 379 | 37 maps/dao/den011d.map 247 167 100 105 33 26 151.255 380 | 37 maps/dao/den011d.map 247 167 100 107 163 26 151.598 381 | 37 maps/dao/den011d.map 247 167 100 39 194 16 148.941 382 | 38 maps/dao/den011d.map 247 167 10 102 111 38 154.355 383 | 38 maps/dao/den011d.map 247 167 10 126 116 51 155.225 384 | 38 maps/dao/den011d.map 247 167 100 100 165 14 154.841 385 | 38 maps/dao/den011d.map 247 167 100 103 163 15 155.083 386 | 38 maps/dao/den011d.map 247 167 100 107 189 150 153.841 387 | 38 maps/dao/den011d.map 247 167 100 108 186 86 153.941 388 | 38 maps/dao/den011d.map 247 167 100 34 171 130 154.598 389 | 38 maps/dao/den011d.map 247 167 100 38 199 103 152.77 390 | 38 maps/dao/den011d.map 247 167 100 42 16 116 155.497 391 | 38 maps/dao/den011d.map 247 167 100 43 16 114 153.083 392 | 39 maps/dao/den011d.map 247 167 10 106 100 42 156.184 393 | 39 maps/dao/den011d.map 247 167 10 123 115 46 159.154 394 | 39 maps/dao/den011d.map 247 167 100 101 176 94 158.355 395 | 39 maps/dao/den011d.map 247 167 100 108 176 16 156.184 396 | 39 maps/dao/den011d.map 247 167 100 108 29 24 158.255 397 | 39 maps/dao/den011d.map 247 167 100 39 11 107 156.841 398 | 39 maps/dao/den011d.map 247 167 100 39 209 106 157.841 399 | 39 maps/dao/den011d.map 247 167 100 40 12 111 157.083 400 | 39 maps/dao/den011d.map 247 167 100 40 181 137 159.255 401 | 39 maps/dao/den011d.map 247 167 100 46 21 117 156.426 402 | 40 maps/dao/den011d.map 247 167 10 124 116 45 161.569 403 | 40 maps/dao/den011d.map 247 167 10 26 96 89 160.598 404 | 40 maps/dao/den011d.map 247 167 100 108 161 12 163.912 405 | 40 maps/dao/den011d.map 247 167 100 43 170 142 160.941 406 | 40 maps/dao/den011d.map 247 167 100 90 226 58 162.326 407 | 40 maps/dao/den011d.map 247 167 100 94 202 43 163.184 408 | 40 maps/dao/den011d.map 247 167 101 37 185 73 160.326 409 | 40 maps/dao/den011d.map 247 167 101 39 238 53 161.468 410 | 40 maps/dao/den011d.map 247 167 101 42 10 123 163.983 411 | 40 maps/dao/den011d.map 247 167 101 44 187 71 161.083 412 | 41 maps/dao/den011d.map 247 167 10 101 160 98 166.255 413 | 41 maps/dao/den011d.map 247 167 10 101 93 35 166.497 414 | 41 maps/dao/den011d.map 247 167 10 124 117 37 167.64 415 | 41 maps/dao/den011d.map 247 167 10 20 117 100 167.083 416 | 41 maps/dao/den011d.map 247 167 100 101 16 28 165.669 417 | 41 maps/dao/den011d.map 247 167 100 107 198 155 164.912 418 | 41 maps/dao/den011d.map 247 167 100 37 238 50 164.539 419 | 41 maps/dao/den011d.map 247 167 100 87 196 37 167.255 420 | 41 maps/dao/den011d.map 247 167 100 90 211 38 165.426 421 | 41 maps/dao/den011d.map 247 167 102 37 177 75 164.74 422 | 42 maps/dao/den011d.map 247 167 10 101 165 110 171.154 423 | 42 maps/dao/den011d.map 247 167 10 106 134 40 171.841 424 | 42 maps/dao/den011d.map 247 167 10 118 130 42 171.983 425 | 42 maps/dao/den011d.map 247 167 10 19 113 105 170.841 426 | 42 maps/dao/den011d.map 247 167 10 23 99 102 171.255 427 | 42 maps/dao/den011d.map 247 167 100 34 173 92 168.841 428 | 42 maps/dao/den011d.map 247 167 100 44 167 85 171.598 429 | 42 maps/dao/den011d.map 247 167 100 85 236 62 171.326 430 | 42 maps/dao/den011d.map 247 167 100 86 161 68 168.154 431 | 42 maps/dao/den011d.map 247 167 100 89 194 36 169.083 432 | 43 maps/dao/den011d.map 247 167 10 107 167 109 172.74 433 | 43 maps/dao/den011d.map 247 167 10 118 132 46 172.326 434 | 43 maps/dao/den011d.map 247 167 10 98 128 26 175.054 435 | 43 maps/dao/den011d.map 247 167 100 104 219 57 175.497 436 | 43 maps/dao/den011d.map 247 167 100 44 180 155 175.184 437 | 43 maps/dao/den011d.map 247 167 100 86 245 72 175.669 438 | 43 maps/dao/den011d.map 247 167 100 92 188 44 174.77 439 | 43 maps/dao/den011d.map 247 167 101 92 241 66 174.083 440 | 43 maps/dao/den011d.map 247 167 102 44 183 154 173.426 441 | 43 maps/dao/den011d.map 247 167 102 89 151 68 173.74 442 | 44 maps/dao/den011d.map 247 167 10 106 135 37 177.841 443 | 44 maps/dao/den011d.map 247 167 10 118 83 41 178.569 444 | 44 maps/dao/den011d.map 247 167 10 20 173 52 177.426 445 | 44 maps/dao/den011d.map 247 167 100 100 233 79 176.083 446 | 44 maps/dao/den011d.map 247 167 100 40 170 65 176.64 447 | 44 maps/dao/den011d.map 247 167 100 84 152 77 176.255 448 | 44 maps/dao/den011d.map 247 167 101 83 244 71 177.669 449 | 44 maps/dao/den011d.map 247 167 101 84 154 66 178.397 450 | 44 maps/dao/den011d.map 247 167 101 94 219 35 176.74 451 | 44 maps/dao/den011d.map 247 167 103 106 193 28 178.527 452 | 45 maps/dao/den011d.map 247 167 10 106 77 32 183.326 453 | 45 maps/dao/den011d.map 247 167 10 121 108 20 180.397 454 | 45 maps/dao/den011d.map 247 167 10 121 122 22 181.711 455 | 45 maps/dao/den011d.map 247 167 10 125 135 41 183.225 456 | 45 maps/dao/den011d.map 247 167 10 19 175 56 182.669 457 | 45 maps/dao/den011d.map 247 167 10 19 96 109 180.326 458 | 45 maps/dao/den011d.map 247 167 10 20 127 112 183.225 459 | 45 maps/dao/den011d.map 247 167 10 21 132 97 182.912 460 | 45 maps/dao/den011d.map 247 167 10 21 91 108 180.569 461 | 45 maps/dao/den011d.map 247 167 10 28 130 102 180.083 462 | 46 maps/dao/den011d.map 247 167 1 119 86 41 185.811 463 | 46 maps/dao/den011d.map 247 167 10 106 176 118 187.983 464 | 46 maps/dao/den011d.map 247 167 10 127 170 105 186.468 465 | 46 maps/dao/den011d.map 247 167 10 21 82 109 185.296 466 | 46 maps/dao/den011d.map 247 167 10 23 122 115 187.154 467 | 46 maps/dao/den011d.map 247 167 10 27 178 24 184.598 468 | 46 maps/dao/den011d.map 247 167 100 102 160 62 185.054 469 | 46 maps/dao/den011d.map 247 167 100 108 215 52 186.497 470 | 46 maps/dao/den011d.map 247 167 100 82 145 76 184.841 471 | 46 maps/dao/den011d.map 247 167 100 87 145 62 185.64 472 | 47 maps/dao/den011d.map 247 167 1 119 169 111 190.953 473 | 47 maps/dao/den011d.map 247 167 10 104 183 116 191.569 474 | 47 maps/dao/den011d.map 247 167 10 107 187 102 189.841 475 | 47 maps/dao/den011d.map 247 167 10 120 120 11 191.711 476 | 47 maps/dao/den011d.map 247 167 10 123 143 41 189.225 477 | 47 maps/dao/den011d.map 247 167 10 123 177 106 189.882 478 | 47 maps/dao/den011d.map 247 167 10 25 123 120 189.154 479 | 47 maps/dao/den011d.map 247 167 10 25 186 56 188.841 480 | 47 maps/dao/den011d.map 247 167 100 103 152 71 189.154 481 | 47 maps/dao/den011d.map 247 167 100 104 156 61 190.296 482 | 48 maps/dao/den011d.map 247 167 10 107 176 122 192.397 483 | 48 maps/dao/den011d.map 247 167 10 119 152 39 195.64 484 | 48 maps/dao/den011d.map 247 167 10 21 69 101 193.811 485 | 48 maps/dao/den011d.map 247 167 10 28 163 18 193.083 486 | 48 maps/dao/den011d.map 247 167 100 82 203 11 195.355 487 | 48 maps/dao/den011d.map 247 167 100 83 225 25 192.497 488 | 48 maps/dao/den011d.map 247 167 100 84 141 60 193.468 489 | 48 maps/dao/den011d.map 247 167 102 88 187 9 195.983 490 | 48 maps/dao/den011d.map 247 167 103 107 213 12 193.284 491 | 48 maps/dao/den011d.map 247 167 103 22 182 157 194.669 492 | 49 maps/dao/den011d.map 247 167 10 106 65 22 199.468 493 | 49 maps/dao/den011d.map 247 167 10 122 182 117 199.61 494 | 49 maps/dao/den011d.map 247 167 10 20 66 106 199.296 495 | 49 maps/dao/den011d.map 247 167 10 29 193 57 197.912 496 | 49 maps/dao/den011d.map 247 167 100 104 189 26 197.225 497 | 49 maps/dao/den011d.map 247 167 100 94 190 12 199.154 498 | 49 maps/dao/den011d.map 247 167 101 83 135 68 197.569 499 | 49 maps/dao/den011d.map 247 167 102 40 158 51 198.296 500 | 49 maps/dao/den011d.map 247 167 102 40 205 153 196.669 501 | 49 maps/dao/den011d.map 247 167 102 88 212 2 198.426 502 | 50 maps/dao/den011d.map 247 167 1 104 170 124 202.154 503 | 50 maps/dao/den011d.map 247 167 1 120 74 28 202.782 504 | 50 maps/dao/den011d.map 247 167 10 100 200 103 203.669 505 | 50 maps/dao/den011d.map 247 167 10 105 171 133 202.154 506 | 50 maps/dao/den011d.map 247 167 10 125 176 120 200.782 507 | 50 maps/dao/den011d.map 247 167 10 26 156 12 201.154 508 | 50 maps/dao/den011d.map 247 167 10 30 200 53 203.669 509 | 50 maps/dao/den011d.map 247 167 100 102 226 27 202.74 510 | 50 maps/dao/den011d.map 247 167 100 106 207 17 202.426 511 | 50 maps/dao/den011d.map 247 167 100 107 187 27 200.054 512 | 51 maps/dao/den011d.map 247 167 1 104 58 39 207.598 513 | 51 maps/dao/den011d.map 247 167 1 121 187 106 206.296 514 | 51 maps/dao/den011d.map 247 167 10 123 196 101 207.64 515 | 51 maps/dao/den011d.map 247 167 10 127 71 27 204.196 516 | 51 maps/dao/den011d.map 247 167 10 27 161 6 205.497 517 | 51 maps/dao/den011d.map 247 167 10 30 170 3 206.012 518 | 51 maps/dao/den011d.map 247 167 100 35 141 73 204.397 519 | 51 maps/dao/den011d.map 247 167 100 93 217 4 204.912 520 | 51 maps/dao/den011d.map 247 167 101 108 194 19 207.154 521 | 51 maps/dao/den011d.map 247 167 102 39 205 164 205.154 522 | 52 maps/dao/den011d.map 247 167 1 105 191 113 209.397 523 | 52 maps/dao/den011d.map 247 167 1 119 76 19 209.61 524 | 52 maps/dao/den011d.map 247 167 10 27 57 116 211.196 525 | 52 maps/dao/den011d.map 247 167 100 37 144 54 211.953 526 | 52 maps/dao/den011d.map 247 167 100 81 217 2 209.497 527 | 52 maps/dao/den011d.map 247 167 101 84 189 2 208.569 528 | 52 maps/dao/den011d.map 247 167 102 36 139 58 209.61 529 | 52 maps/dao/den011d.map 247 167 103 25 203 153 209.255 530 | 52 maps/dao/den011d.map 247 167 104 72 140 53 208.296 531 | 52 maps/dao/den011d.map 247 167 105 25 135 70 210.196 532 | 53 maps/dao/den011d.map 247 167 1 119 159 39 212.468 533 | 53 maps/dao/den011d.map 247 167 1 120 176 130 214.782 534 | 53 maps/dao/den011d.map 247 167 1 120 59 39 213.225 535 | 53 maps/dao/den011d.map 247 167 10 103 185 141 214.296 536 | 53 maps/dao/den011d.map 247 167 10 126 191 116 212.196 537 | 53 maps/dao/den011d.map 247 167 10 19 206 67 215.882 538 | 53 maps/dao/den011d.map 247 167 10 23 206 63 212.569 539 | 53 maps/dao/den011d.map 247 167 10 24 59 123 215.196 540 | 53 maps/dao/den011d.map 247 167 10 99 173 144 213.983 541 | 53 maps/dao/den011d.map 247 167 100 44 140 54 214.368 542 | 54 maps/dao/den011d.map 247 167 1 103 188 136 219.539 543 | 54 maps/dao/den011d.map 247 167 1 120 57 34 217.296 544 | 54 maps/dao/den011d.map 247 167 1 120 63 18 217.924 545 | 54 maps/dao/den011d.map 247 167 10 121 173 141 216.539 546 | 54 maps/dao/den011d.map 247 167 10 122 204 107 216.296 547 | 54 maps/dao/den011d.map 247 167 10 124 170 43 218.054 548 | 54 maps/dao/den011d.map 247 167 10 125 167 36 217.296 549 | 54 maps/dao/den011d.map 247 167 100 108 203 3 218.426 550 | 54 maps/dao/den011d.map 247 167 103 22 205 141 216.598 551 | 54 maps/dao/den011d.map 247 167 11 102 175 30 217.154 552 | 55 maps/dao/den011d.map 247 167 10 102 172 153 222.154 553 | 55 maps/dao/den011d.map 247 167 10 102 173 152 220.74 554 | 55 maps/dao/den011d.map 247 167 10 104 42 27 221.225 555 | 55 maps/dao/den011d.map 247 167 10 118 177 33 223.296 556 | 55 maps/dao/den011d.map 247 167 10 122 211 103 221.64 557 | 55 maps/dao/den011d.map 247 167 100 108 183 7 222.711 558 | 55 maps/dao/den011d.map 247 167 101 108 204 2 220.012 559 | 55 maps/dao/den011d.map 247 167 101 108 214 5 220.326 560 | 55 maps/dao/den011d.map 247 167 11 105 40 27 222.64 561 | 55 maps/dao/den011d.map 247 167 11 123 169 52 222.882 562 | 56 maps/dao/den011d.map 247 167 10 101 165 28 226.569 563 | 56 maps/dao/den011d.map 247 167 10 121 204 87 224.711 564 | 56 maps/dao/den011d.map 247 167 10 122 47 24 224.439 565 | 56 maps/dao/den011d.map 247 167 10 126 181 142 225.853 566 | 56 maps/dao/den011d.map 247 167 10 127 175 40 225.64 567 | 56 maps/dao/den011d.map 247 167 10 21 202 32 227.083 568 | 56 maps/dao/den011d.map 247 167 10 23 218 37 226.569 569 | 56 maps/dao/den011d.map 247 167 11 103 184 51 224.154 570 | 56 maps/dao/den011d.map 247 167 11 103 35 27 227.64 571 | 56 maps/dao/den011d.map 247 167 11 106 169 20 227.983 572 | 57 maps/dao/den011d.map 247 167 1 120 176 50 231.953 573 | 57 maps/dao/den011d.map 247 167 10 105 189 150 230.811 574 | 57 maps/dao/den011d.map 247 167 10 119 173 21 231.711 575 | 57 maps/dao/den011d.map 247 167 10 24 217 77 230.711 576 | 57 maps/dao/den011d.map 247 167 11 106 163 24 228.811 577 | 57 maps/dao/den011d.map 247 167 11 119 182 58 230.853 578 | 57 maps/dao/den011d.map 247 167 11 21 177 111 230.811 579 | 57 maps/dao/den011d.map 247 167 12 101 191 51 230.983 580 | 57 maps/dao/den011d.map 247 167 12 102 186 84 229.154 581 | 57 maps/dao/den011d.map 247 167 12 105 163 21 228.64 582 | 58 maps/dao/den011d.map 247 167 1 103 182 154 235.054 583 | 58 maps/dao/den011d.map 247 167 1 119 179 35 234.125 584 | 58 maps/dao/den011d.map 247 167 1 119 180 33 235.953 585 | 58 maps/dao/den011d.map 247 167 10 100 209 72 235.811 586 | 58 maps/dao/den011d.map 247 167 10 101 185 79 234.64 587 | 58 maps/dao/den011d.map 247 167 10 101 189 60 234.711 588 | 58 maps/dao/den011d.map 247 167 10 105 199 70 234.083 589 | 58 maps/dao/den011d.map 247 167 10 127 180 49 233.539 590 | 58 maps/dao/den011d.map 247 167 11 103 156 25 234.983 591 | 58 maps/dao/den011d.map 247 167 11 118 185 157 234.681 592 | 59 maps/dao/den011d.map 247 167 1 104 210 77 238.569 593 | 59 maps/dao/den011d.map 247 167 1 119 168 25 239.61 594 | 59 maps/dao/den011d.map 247 167 10 102 171 11 237.154 595 | 59 maps/dao/den011d.map 247 167 10 103 206 66 239.326 596 | 59 maps/dao/den011d.map 247 167 10 106 191 61 236.711 597 | 59 maps/dao/den011d.map 247 167 10 118 188 58 237.439 598 | 59 maps/dao/den011d.map 247 167 10 124 188 91 237.711 599 | 59 maps/dao/den011d.map 247 167 10 25 185 110 237.154 600 | 59 maps/dao/den011d.map 247 167 10 25 192 25 236.569 601 | 59 maps/dao/den011d.map 247 167 10 28 185 29 238.468 602 | 60 maps/dao/den011d.map 247 167 1 119 164 26 243.196 603 | 60 maps/dao/den011d.map 247 167 10 101 175 6 242.569 604 | 60 maps/dao/den011d.map 247 167 10 101 175 94 242.569 605 | 60 maps/dao/den011d.map 247 167 10 106 160 12 240.711 606 | 60 maps/dao/den011d.map 247 167 10 124 33 27 240.853 607 | 60 maps/dao/den011d.map 247 167 10 126 188 57 243.853 608 | 60 maps/dao/den011d.map 247 167 10 22 167 122 242.64 609 | 60 maps/dao/den011d.map 247 167 10 22 190 110 243.397 610 | 60 maps/dao/den011d.map 247 167 11 102 174 90 240.497 611 | 60 maps/dao/den011d.map 247 167 11 104 177 78 241.397 612 | 61 maps/dao/den011d.map 247 167 1 105 25 27 247.64 613 | 61 maps/dao/den011d.map 247 167 1 120 187 145 244.196 614 | 61 maps/dao/den011d.map 247 167 10 101 160 7 246.125 615 | 61 maps/dao/den011d.map 247 167 10 107 221 73 244.64 616 | 61 maps/dao/den011d.map 247 167 10 118 176 8 245.539 617 | 61 maps/dao/den011d.map 247 167 10 119 210 67 245.782 618 | 61 maps/dao/den011d.map 247 167 10 125 202 68 246.882 619 | 61 maps/dao/den011d.map 247 167 10 126 174 13 246.539 620 | 61 maps/dao/den011d.map 247 167 10 127 195 74 247.539 621 | 61 maps/dao/den011d.map 247 167 10 99 167 7 244.054 622 | 62 maps/dao/den011d.map 247 167 1 105 198 151 249.225 623 | 62 maps/dao/den011d.map 247 167 10 103 169 83 248.154 624 | 62 maps/dao/den011d.map 247 167 10 123 23 19 251.51 625 | 62 maps/dao/den011d.map 247 167 10 19 208 8 251.912 626 | 62 maps/dao/den011d.map 247 167 10 22 209 102 250.882 627 | 62 maps/dao/den011d.map 247 167 10 24 19 114 249.711 628 | 62 maps/dao/den011d.map 247 167 10 30 211 98 248.539 629 | 62 maps/dao/den011d.map 247 167 10 30 237 75 250.61 630 | 62 maps/dao/den011d.map 247 167 11 100 208 146 249.225 631 | 62 maps/dao/den011d.map 247 167 11 119 160 6 251.095 632 | 63 maps/dao/den011d.map 247 167 1 120 205 65 255.125 633 | 63 maps/dao/den011d.map 247 167 10 100 228 70 253.296 634 | 63 maps/dao/den011d.map 247 167 10 119 168 92 253.711 635 | 63 maps/dao/den011d.map 247 167 10 119 170 83 252.953 636 | 63 maps/dao/den011d.map 247 167 10 125 164 8 253.853 637 | 63 maps/dao/den011d.map 247 167 10 22 205 2 255.426 638 | 63 maps/dao/den011d.map 247 167 11 103 230 68 253.882 639 | 63 maps/dao/den011d.map 247 167 11 121 167 91 255.296 640 | 63 maps/dao/den011d.map 247 167 11 121 203 158 254.924 641 | 63 maps/dao/den011d.map 247 167 11 125 182 69 254.681 642 | 64 maps/dao/den011d.map 247 167 10 101 166 73 256.125 643 | 64 maps/dao/den011d.map 247 167 10 106 198 43 259.225 644 | 64 maps/dao/den011d.map 247 167 10 21 187 135 257.61 645 | 64 maps/dao/den011d.map 247 167 11 122 173 67 259.167 646 | 64 maps/dao/den011d.map 247 167 11 124 15 20 259.681 647 | 64 maps/dao/den011d.map 247 167 11 126 205 152 259.439 648 | 64 maps/dao/den011d.map 247 167 11 21 187 5 259.296 649 | 64 maps/dao/den011d.map 247 167 11 28 175 85 259.225 650 | 64 maps/dao/den011d.map 247 167 11 99 233 69 258.125 651 | 64 maps/dao/den011d.map 247 167 12 105 218 53 257.054 652 | 65 maps/dao/den011d.map 247 167 1 120 178 69 261.924 653 | 65 maps/dao/den011d.map 247 167 10 106 221 52 261.711 654 | 65 maps/dao/den011d.map 247 167 10 127 221 64 262.51 655 | 65 maps/dao/den011d.map 247 167 10 19 12 121 261.681 656 | 65 maps/dao/den011d.map 247 167 10 20 174 90 261.64 657 | 65 maps/dao/den011d.map 247 167 10 24 178 75 261.125 658 | 65 maps/dao/den011d.map 247 167 11 102 201 35 262.64 659 | 65 maps/dao/den011d.map 247 167 11 106 197 41 260.054 660 | 65 maps/dao/den011d.map 247 167 11 119 233 77 263.095 661 | 65 maps/dao/den011d.map 247 167 11 125 14 21 261.267 662 | 66 maps/dao/den011d.map 247 167 1 104 232 69 265.054 663 | 66 maps/dao/den011d.map 247 167 10 103 195 33 267.711 664 | 66 maps/dao/den011d.map 247 167 10 106 218 43 264.054 665 | 66 maps/dao/den011d.map 247 167 10 119 228 57 266.167 666 | 66 maps/dao/den011d.map 247 167 10 126 10 19 267.51 667 | 66 maps/dao/den011d.map 247 167 10 126 169 70 266.338 668 | 66 maps/dao/den011d.map 247 167 11 106 218 40 264.296 669 | 66 maps/dao/den011d.map 247 167 11 123 166 68 266.752 670 | 66 maps/dao/den011d.map 247 167 11 26 167 91 266.397 671 | 66 maps/dao/den011d.map 247 167 11 30 169 148 267.054 672 | 67 maps/dao/den011d.map 247 167 1 105 210 39 268.64 673 | 67 maps/dao/den011d.map 247 167 10 104 213 29 270.468 674 | 67 maps/dao/den011d.map 247 167 10 119 159 71 268.924 675 | 67 maps/dao/den011d.map 247 167 10 121 157 75 270.681 676 | 67 maps/dao/den011d.map 247 167 10 123 235 79 269.51 677 | 67 maps/dao/den011d.map 247 167 10 24 168 72 271.782 678 | 67 maps/dao/den011d.map 247 167 11 102 245 75 270.539 679 | 67 maps/dao/den011d.map 247 167 11 104 212 30 268.054 680 | 67 maps/dao/den011d.map 247 167 11 105 206 24 271.983 681 | 67 maps/dao/den011d.map 247 167 11 118 240 69 268.853 682 | 68 maps/dao/den011d.map 247 167 1 104 214 35 273.882 683 | 68 maps/dao/den011d.map 247 167 11 100 211 26 273.296 684 | 68 maps/dao/den011d.map 247 167 11 101 211 23 275.882 685 | 68 maps/dao/den011d.map 247 167 11 103 183 36 275.711 686 | 68 maps/dao/den011d.map 247 167 11 103 211 25 273.054 687 | 68 maps/dao/den011d.map 247 167 11 123 221 44 275.024 688 | 68 maps/dao/den011d.map 247 167 11 24 182 154 272.296 689 | 68 maps/dao/den011d.map 247 167 12 104 242 51 274.439 690 | 68 maps/dao/den011d.map 247 167 12 109 192 26 275.61 691 | 68 maps/dao/den011d.map 247 167 13 101 204 21 273.811 692 | 69 maps/dao/den011d.map 247 167 1 103 154 71 277.125 693 | 69 maps/dao/den011d.map 247 167 1 121 225 54 276.581 694 | 69 maps/dao/den011d.map 247 167 10 103 144 68 279.368 695 | 69 maps/dao/den011d.map 247 167 10 121 200 26 279.853 696 | 69 maps/dao/den011d.map 247 167 10 122 245 76 278.924 697 | 69 maps/dao/den011d.map 247 167 10 123 243 74 278.51 698 | 69 maps/dao/den011d.map 247 167 10 27 160 74 279.368 699 | 69 maps/dao/den011d.map 247 167 11 104 158 51 277.439 700 | 69 maps/dao/den011d.map 247 167 11 105 143 69 278.953 701 | 69 maps/dao/den011d.map 247 167 11 23 190 145 278.054 702 | 70 maps/dao/den011d.map 247 167 10 121 160 56 280.238 703 | 70 maps/dao/den011d.map 247 167 10 121 207 21 283.61 704 | 70 maps/dao/den011d.map 247 167 10 123 197 27 282.681 705 | 70 maps/dao/den011d.map 247 167 10 124 160 56 283.238 706 | 70 maps/dao/den011d.map 247 167 10 124 190 34 280.752 707 | 70 maps/dao/den011d.map 247 167 10 28 164 65 281.267 708 | 70 maps/dao/den011d.map 247 167 11 100 186 22 282.681 709 | 70 maps/dao/den011d.map 247 167 11 121 146 71 282.924 710 | 70 maps/dao/den011d.map 247 167 11 127 244 77 282.095 711 | 70 maps/dao/den011d.map 247 167 11 98 142 66 283.267 712 | 71 maps/dao/den011d.map 247 167 10 101 208 11 287.64 713 | 71 maps/dao/den011d.map 247 167 10 103 207 11 286.397 714 | 71 maps/dao/den011d.map 247 167 10 123 210 23 284.853 715 | 71 maps/dao/den011d.map 247 167 10 125 193 25 287.752 716 | 71 maps/dao/den011d.map 247 167 11 101 138 65 286.439 717 | 71 maps/dao/den011d.map 247 167 11 118 205 16 284.953 718 | 71 maps/dao/den011d.map 247 167 11 123 193 23 287.338 719 | 71 maps/dao/den011d.map 247 167 12 106 201 9 287.64 720 | 71 maps/dao/den011d.map 247 167 12 109 145 54 287.924 721 | 71 maps/dao/den011d.map 247 167 12 113 140 65 285.924 722 | 72 maps/dao/den011d.map 247 167 1 105 186 25 288.439 723 | 72 maps/dao/den011d.map 247 167 10 100 188 16 288.853 724 | 72 maps/dao/den011d.map 247 167 10 124 185 27 288.652 725 | 72 maps/dao/den011d.map 247 167 11 127 215 25 288.51 726 | 72 maps/dao/den011d.map 247 167 11 19 203 147 291.882 727 | 72 maps/dao/den011d.map 247 167 12 117 203 12 288.368 728 | 72 maps/dao/den011d.map 247 167 12 120 138 66 291.581 729 | 72 maps/dao/den011d.map 247 167 12 22 160 55 290.924 730 | 72 maps/dao/den011d.map 247 167 12 29 161 54 291.924 731 | 72 maps/dao/den011d.map 247 167 13 102 199 5 291.468 732 | 73 maps/dao/den011d.map 247 167 1 121 142 75 294.095 733 | 73 maps/dao/den011d.map 247 167 10 118 192 13 294.338 734 | 73 maps/dao/den011d.map 247 167 10 119 144 54 295.066 735 | 73 maps/dao/den011d.map 247 167 10 25 145 78 293.539 736 | 73 maps/dao/den011d.map 247 167 10 98 199 9 292.125 737 | 73 maps/dao/den011d.map 247 167 11 102 186 11 292.853 738 | 73 maps/dao/den011d.map 247 167 11 127 223 30 293.267 739 | 73 maps/dao/den011d.map 247 167 12 117 210 8 293.61 740 | 73 maps/dao/den011d.map 247 167 12 21 145 74 293.196 741 | 73 maps/dao/den011d.map 247 167 13 125 149 53 294.652 742 | 74 maps/dao/den011d.map 247 167 10 102 191 4 298.782 743 | 74 maps/dao/den011d.map 247 167 10 122 187 13 299.238 744 | 74 maps/dao/den011d.map 247 167 10 125 205 11 296.782 745 | 74 maps/dao/den011d.map 247 167 10 25 146 61 297.924 746 | 74 maps/dao/den011d.map 247 167 10 25 210 151 299.054 747 | 74 maps/dao/den011d.map 247 167 12 116 187 9 297.581 748 | 74 maps/dao/den011d.map 247 167 12 121 215 10 297.095 749 | 74 maps/dao/den011d.map 247 167 12 22 142 64 299.924 750 | 74 maps/dao/den011d.map 247 167 12 28 210 148 297.054 751 | 74 maps/dao/den011d.map 247 167 13 117 207 3 296.368 752 | 75 maps/dao/den011d.map 247 167 10 127 202 8 303.024 753 | 75 maps/dao/den011d.map 247 167 10 24 141 70 300.782 754 | 75 maps/dao/den011d.map 247 167 12 120 216 6 300.51 755 | 75 maps/dao/den011d.map 247 167 12 21 209 158 300.61 756 | 75 maps/dao/den011d.map 247 167 12 22 143 61 300.167 757 | 75 maps/dao/den011d.map 247 167 138 63 15 19 302.581 758 | 75 maps/dao/den011d.map 247 167 139 57 16 25 301.167 759 | 75 maps/dao/den011d.map 247 167 141 69 11 19 301.095 760 | 75 maps/dao/den011d.map 247 167 141 79 8 19 302.439 761 | 75 maps/dao/den011d.map 247 167 142 78 9 19 300.024 762 | 76 maps/dao/den011d.map 247 167 1 105 209 3 304.225 763 | 76 maps/dao/den011d.map 247 167 10 125 201 5 304.439 764 | 76 maps/dao/den011d.map 247 167 12 122 188 5 305.995 765 | 76 maps/dao/den011d.map 247 167 13 19 136 61 307.409 766 | 76 maps/dao/den011d.map 247 167 15 122 219 3 305.51 767 | 76 maps/dao/den011d.map 247 167 17 125 221 5 306.51 768 | 76 maps/dao/den011d.map 247 167 18 117 186 2 304.095 769 | 76 maps/dao/den011d.map 247 167 184 4 14 122 307.823 770 | 76 maps/dao/den011d.map 247 167 185 11 10 124 304.066 771 | 76 maps/dao/den011d.map 247 167 193 8 12 127 305.924 772 | 77 maps/dao/den011d.map 247 167 11 127 191 4 311.167 773 | 77 maps/dao/den011d.map 247 167 12 127 218 4 310.338 774 | 77 maps/dao/den011d.map 247 167 136 54 10 26 311.823 775 | 77 maps/dao/den011d.map 247 167 137 62 7 24 309.924 776 | 77 maps/dao/den011d.map 247 167 137 67 7 20 309.51 777 | 77 maps/dao/den011d.map 247 167 186 1 14 119 308.167 778 | 77 maps/dao/den011d.map 247 167 3 119 219 6 309.995 779 | 77 maps/dao/den011d.map 247 167 3 121 208 2 309.439 780 | 77 maps/dao/den011d.map 247 167 7 124 189 6 309.238 781 | 77 maps/dao/den011d.map 247 167 8 123 221 4 309.238 782 | 783 | -------------------------------------------------------------------------------- /jps.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | Public domain Jump Point Search implementation -- very fast pathfinding for uniform cost grids. 5 | Scroll down for compile config, usage tips, example code. 6 | 7 | License: 8 | Public domain, WTFPL, CC0 or your favorite permissive license; whatever is available in your country. 9 | 10 | Dependencies: 11 | libc (stdlib.h, math.h) by default, change defines below to use your own functions. (realloc(), free(), sqrt()) 12 | Compiles as C++98, does not require C++11 nor the STL. 13 | Does not throw exceptions, works without RTTI, does not contain any virtual methods. 14 | 15 | Thread safety: 16 | No global state. Searcher instances are not thread-safe. Grid template class is up to you. 17 | If your grid access is read-only while pathfinding you may have many threads compute paths at the same time, 18 | each with its own Searcher instance. 19 | 20 | Background: 21 | If you want to generate paths on a map with the following properties: 22 | - You have a 2D grid (exactly two dimensions!), where each tile has exactly 8 neighbors (up, down, left, right + diagonals) 23 | - There is no "cost" -- a tile is either walkable, or not. 24 | then you may want to avoid full fledged A* and go for Jump Point Search (this lib). 25 | JPS is usually much faster than plain old A*, as long as your tile traversability check function is fast. 26 | 27 | Origin: 28 | https://github.com/fgenesis/tinypile/blob/master/jps.hh 29 | 30 | Based on my older implementation: 31 | https://github.com/fgenesis/jps/blob/master/JPS.h 32 | (For changes compared to that version go to the end of this file) 33 | 34 | Inspired by: 35 | http://users.cecs.anu.edu.au/~dharabor/data/papers/harabor-grastien-aaai11.pdf (The original paper) 36 | https://github.com/Yonaba/Jumper 37 | https://github.com/qiao/PathFinding.js 38 | 39 | Usage: 40 | 41 | Define a class that overloads `operator()(x, y) const`, returning a value that can be treated as boolean. 42 | You are responsible for bounds checking! 43 | You want your operator() to be as fast and small as possible, as it will be called a LOT. 44 | Ask your compiler to force-inline it if possible. 45 | 46 | // --- Begin example code --- 47 | 48 | struct MyGrid 49 | { 50 | inline bool operator()(unsigned x, unsigned y) const // coordinates must be unsigned; method must be const 51 | { 52 | if(x < width && y < height) // Unsigned will wrap if < 0 53 | ... return true if terrain at (x, y) is walkable. 54 | // return false if terrain is not walkable or out-of-bounds. 55 | } 56 | unsigned width, height; 57 | }; 58 | 59 | // Then you can retrieve a path: 60 | 61 | MyGrid grid(... set grid width, height, map data, whatever); 62 | 63 | const unsigned step = 0; // 0 compresses the path as much as possible and only records waypoints. 64 | // Set this to 1 if you want a detailed single-step path 65 | // (e.g. if you plan to further mangle the path yourself), 66 | // or any other higher value to output every Nth position. 67 | // (Waypoints are always output regardless of the step size.) 68 | 69 | JPS::PathVector path; // The resulting path will go here. 70 | // You may also use std::vector or whatever, as long as your vector type 71 | // has push_back(), begin(), end(), resize() methods (same semantics as std::vector). 72 | // Note that the path will NOT include the starting position! 73 | // --> If called with start == end it will report that a path has been found, 74 | // but the resulting path vector will be empty! 75 | 76 | // Single-call interface: 77 | // (Further remarks about this function can be found near the bottom of this file.) 78 | // Note that the path vector is NOT cleared! New path points are appended at the end. 79 | bool found = JPS::findPath(path, grid, startx, starty, endx, endy, step); 80 | 81 | 82 | // --- Alternatively, if you want more control & efficiency for repeated pathfinding runs: --- 83 | 84 | // Use a Searcher instance (can be a class member, on the stack, ...) 85 | // Make sure the passed grid reference stays valid throughout the searcher's lifetime. 86 | // If you need control over memory allocation, you may pass an extra pointer that will be 87 | // forwarded to your own JPS_realloc & JPS_free if you've set those. Otherwise it's ignored. 88 | JPS::Searcher search(grid, userPtr = NULL); 89 | 90 | // build path incrementally from waypoints: 91 | JPS::Position a, b, c, d = <...>; // set some waypoints 92 | if (search.findPath(path, a, b) 93 | && search.findPath(path, b, c) 94 | && search.findPath(path, c, d)) 95 | { 96 | // found path: a->b->c->d 97 | } 98 | 99 | // keep re-using existing pathfinder instance 100 | while(whatever) 101 | { 102 | // Set startx, starty, endx, endy = <...> 103 | if(!search.findPath(path, JPS::Pos(startx, starty), JPS::Pos(endx, endy), step)) 104 | { 105 | // ...handle failure... 106 | } 107 | } 108 | 109 | // If necessary, you may free internal memory -- this is never required; neither for performance, nor for correct function. 110 | // If you do pathfinding after freeing memory, it'll allocate new memory. 111 | // Note that freeing memory aborts any incremental search currently ongoing. 112 | search.freeMemory(); 113 | 114 | // If you need to know how much memory is internally allocated by a searcher: 115 | unsigned bytes = search.getTotalMemoryInUse(); 116 | 117 | 118 | // ------------------------------- 119 | // --- Incremental pathfinding --- 120 | // ------------------------------- 121 | 122 | Calling JPS::findPath() or Searcher<>::findPath() always computes an entire path or returns failure. 123 | If the path is long or costly and you have a tight CPU budget per frame you may want to perform pathfinding incrementally, 124 | stretched over multiple frames. 125 | 126 | First, call 127 | ### JPS_Result res = search.findPathInit(Position start, Position end) ### 128 | Don't forget to check the return value, as it may return: 129 | - JPS_NO_PATH if one or both of the points are obstructed 130 | - JPS_EMPTY_PATH if the points are equal and not obstructed 131 | - JPS_FOUND_PATH if the initial greedy heuristic could find a path quickly. 132 | - JPS_OUT_OF_MEMORY if... well yeah. 133 | If it returns JPS_NEED_MORE_STEPS then the next part can start. 134 | 135 | Repeatedly call 136 | ### JPS_Result res = search.findPathStep(int limit) ### 137 | until it returns JPS_NO_PATH or JPS_FOUND_PATH, or JPS_OUT_OF_MEMORY. 138 | For consistency, you will want to ensure that the grid does not change between subsequent calls; 139 | if the grid changes, parts of the path may go through a now obstructed area or may be no longer optimal. 140 | If limit is 0, it will perform the pathfinding in one go. Values > 0 pause the search 141 | as soon as possible after the number of steps was exceeded, returning NEED_MORE_STEPS. 142 | Use search.getStepsDone() after some test runs to find a good value for the limit. 143 | 144 | After getting JPS_FOUND_PATH, generate the actual path points via 145 | ### JPS_Result res = search.findPathFinish(PathVector& path, unsigned step = 0) ### 146 | As described above, path points are appended, and granularity can be adjusted with the step parameter. 147 | Returns JPS_FOUND_PATH if the path was successfully built and appended to the path vector. 148 | Returns JPS_NO_PATH if the pathfinding did not finish or generating the path failed. 149 | May return JPS_OUT_OF_MEMORY if the path vector must be resized but fails to allocate. 150 | 151 | If findPathInit() or findPathStep() return JPS_OUT_OF_MEMORY, the current searcher progress becomes undefined. 152 | To recover, free some memory elsewhere and call findPathInit() to try again. 153 | 154 | If findPathFinish() returns out-of-memory but previous steps finished successfully, 155 | then the found path is still valid for generating the path vector. 156 | In that case you may call findPathFinish() again after making some memory available. 157 | 158 | If you do not worry about memory, treat JPS_OUT_OF_MEMORY as if JPS_NO_PATH was returned. 159 | 160 | You may pass JPS::PathVector, std::vector, or your own to findPathFinish(). 161 | Note that if the path vector type you pass throws exceptions in case of allocation failures (std::vector does, for example), 162 | you'll get that exception, and the path vector will be in whatever state it was in when the last element was successfully inserted. 163 | If no exception is thrown (ie. you used JPS::PathVector) then the failure cases do not modify the path vector. 164 | 165 | You may abort a search anytime by starting a new one via findPathInit(), calling freeMemory(), or by destroying the searcher instance. 166 | Aborting or starting a search resets the values returned by .getStepsDone() and .getNodesExpanded() to 0. 167 | 168 | */ 169 | 170 | // ============================ 171 | // ====== COMPILE CONFIG ====== 172 | // ============================ 173 | 174 | 175 | // If you want to avoid sqrt() or floats in general, define this. 176 | // Turns out in some testing this was ~12% faster, so it's the default. 177 | #define JPS_NO_FLOAT 178 | 179 | 180 | // ------------------------------------------------ 181 | 182 | #include // for size_t (needed for operator new) 183 | 184 | // Assertions 185 | #ifndef JPS_ASSERT 186 | # ifdef _DEBUG 187 | # include 188 | # define JPS_ASSERT(cond) assert(cond) 189 | # else 190 | # define JPS_ASSERT(cond) 191 | # endif 192 | #endif 193 | 194 | // The default allocator uses realloc(), free(). Change if necessary. 195 | // You will get the user pointer that you passed to findPath() or the Searcher ctor. 196 | #if !defined(JPS_realloc) || !defined(JPS_free) 197 | # include // for realloc, free 198 | # ifndef JPS_realloc 199 | # define JPS_realloc(p, newsize, oldsize, user) realloc(p, newsize) 200 | # endif 201 | # ifndef JPS_free 202 | # define JPS_free(p, oldsize, user) free(p) 203 | # endif 204 | #endif 205 | 206 | #ifdef JPS_NO_FLOAT 207 | #define JPS_HEURISTIC_ACCURATE(a, b) (Heuristic::Chebyshev(a, b)) 208 | #else 209 | # ifndef JPS_sqrt 210 | // for Euclidean heuristic. 211 | # include 212 | # define JPS_sqrt(x) sqrtf(float(x)) // float cast here avoids a warning about implicit int->float cast 213 | # endif 214 | #endif 215 | 216 | // Which heuristics to use. 217 | // Basic property: Distance estimate, returns values >= 0. Smaller is better. 218 | // The accurate heuristic should always return guesses less or equal than the estimate heuristic, 219 | // otherwise the resulting paths may not be optimal. 220 | // (The rule of thumb is that the estimate is fast but can overestimate) 221 | // For the implementation of heuristics, scroll down. 222 | #ifndef JPS_HEURISTIC_ACCURATE 223 | #define JPS_HEURISTIC_ACCURATE(a, b) (Heuristic::Euclidean(a, b)) 224 | #endif 225 | 226 | #ifndef JPS_HEURISTIC_ESTIMATE 227 | #define JPS_HEURISTIC_ESTIMATE(a, b) (Heuristic::Manhattan(a, b)) 228 | #endif 229 | 230 | 231 | // --- Data types --- 232 | namespace JPS { 233 | 234 | // unsigned integer type wide enough to store a position on one grid axis. 235 | // Note that on x86, u32 is actually faster than u16. 236 | typedef unsigned PosType; 237 | 238 | // Result of heuristics. can also be (unsigned) int but using float by default since that's what sqrtf() returns 239 | // and we don't need to cast float->int that way. Change if you use integer-only heuristics. 240 | // (Euclidean heuristic using sqrt() works fine even if cast to int. Your choice really.) 241 | #ifdef JPS_NO_FLOAT 242 | typedef int ScoreType; 243 | #else 244 | typedef float ScoreType; 245 | #endif 246 | 247 | // Size type; used internally for vectors and the like. You can set this to size_t if you want, but 32 bits is more than enough. 248 | typedef unsigned SizeT; 249 | 250 | } // end namespace JPS 251 | 252 | 253 | // ================================ 254 | // ====== COMPILE CONFIG END ====== 255 | // ================================ 256 | // ---------------------------------------------------------------------------------------- 257 | 258 | typedef unsigned JPS_Flags; 259 | enum JPS_Flags_ 260 | { 261 | // No special behavior 262 | JPS_Flag_Default = 0x00, 263 | 264 | // If this is defined, disable the greedy direct-short-path check that avoids the large area scanning that JPS does. 265 | // This is just a performance tweak. May save a lot of CPU when constantly re-planning short paths without obstacles 266 | // (e.g. an entity follows close behind another). 267 | // Does not change optimality of results. If you perform your own line-of-sight checks 268 | // before starting a pathfinding run you can disable greedy since checking twice isn't needed, 269 | // but otherwise it's better to leave it enabled. 270 | JPS_Flag_NoGreedy = 0x01, 271 | 272 | // If this is set, use standard A* instead of JPS (e.g. if you want to compare performance in your scenario). 273 | // In most cases this will be MUCH slower, but might be beneficial if your grid lookup 274 | // is slow (aka worse than O(1) or more than a few inlined instructions), 275 | // as it avoids the large area scans that the JPS algorithm does. 276 | // (Also increases memory usage as each checked position is expanded into a node.) 277 | JPS_Flag_AStarOnly = 0x02, 278 | 279 | // Don't check whether start position is walkable. 280 | // This makes the start position always walkable, even if the map data say otherwise. 281 | JPS_Flag_NoStartCheck = 0x04, 282 | 283 | // Don't check whether end position is walkable. 284 | JPS_Flag_NoEndCheck = 0x08, 285 | }; 286 | 287 | enum JPS_Result 288 | { 289 | JPS_NO_PATH, 290 | JPS_FOUND_PATH, 291 | JPS_NEED_MORE_STEPS, 292 | JPS_EMPTY_PATH, 293 | JPS_OUT_OF_MEMORY 294 | }; 295 | 296 | // operator new() without #include 297 | // Unfortunately the standard mandates the use of size_t, so we need stddef.h the very least. 298 | // Trick via https://github.com/ocornut/imgui 299 | // "Defining a custom placement new() with a dummy parameter allows us to bypass including 300 | // which on some platforms complains when user has disabled exceptions." 301 | struct JPS__NewDummy {}; 302 | inline void* operator new(size_t, JPS__NewDummy, void* ptr) { return ptr; } 303 | inline void operator delete(void*, JPS__NewDummy, void*) {} 304 | #define JPS_PLACEMENT_NEW(p) new(JPS__NewDummy(), p) 305 | 306 | 307 | namespace JPS { 308 | 309 | struct Position 310 | { 311 | PosType x, y; 312 | 313 | inline bool operator==(const Position& p) const 314 | { 315 | return x == p.x && y == p.y; 316 | } 317 | inline bool operator!=(const Position& p) const 318 | { 319 | return x != p.x || y != p.y; 320 | } 321 | 322 | inline bool isValid() const { return x != PosType(-1); } 323 | }; 324 | 325 | // The invalid position. Used internally to mark non-walkable points. 326 | static const Position npos = {PosType(-1), PosType(-1)}; 327 | static const SizeT noidx = SizeT(-1); 328 | 329 | // ctor function to keep Position a real POD struct. 330 | inline static Position Pos(PosType x, PosType y) 331 | { 332 | Position p; 333 | p.x = x; 334 | p.y = y; 335 | return p; 336 | } 337 | 338 | template inline static T Max(T a, T b) { return a < b ? b : a; } 339 | template inline static T Min(T a, T b) { return a < b ? a : b; } 340 | template inline static T Abs(T a) { return a < T(0) ? -a : a; } 341 | template inline static int Sgn(T val) { return (T(0) < val) - (val < T(0)); } 342 | 343 | 344 | // Heuristics. Add new ones if you need them. 345 | namespace Heuristic 346 | { 347 | inline ScoreType Manhattan(const Position& a, const Position& b) 348 | { 349 | const int dx = Abs(int(a.x - b.x)); 350 | const int dy = Abs(int(a.y - b.y)); 351 | return static_cast(dx + dy); 352 | } 353 | 354 | inline ScoreType Chebyshev(const Position& a, const Position& b) 355 | { 356 | const int dx = Abs(int(a.x - b.x)); 357 | const int dy = Abs(int(a.y - b.y)); 358 | return static_cast(Max(dx, dy)); 359 | } 360 | #ifdef JPS_sqrt 361 | inline ScoreType Euclidean(const Position& a, const Position& b) 362 | { 363 | const int dx = (int(a.x - b.x)); 364 | const int dy = (int(a.y - b.y)); 365 | return static_cast(JPS_sqrt(dx*dx + dy*dy)); 366 | } 367 | #endif 368 | } // end namespace heuristic 369 | 370 | 371 | 372 | // --- Begin infrastructure, data structures --- 373 | 374 | namespace Internal { 375 | 376 | // Never allocated outside of a PodVec --> All nodes are linearly adjacent in memory. 377 | struct Node 378 | { 379 | ScoreType f, g; // heuristic distances 380 | Position pos; 381 | int parentOffs; // no parent if 0 382 | unsigned _flags; 383 | 384 | inline int hasParent() const { return parentOffs; } 385 | inline void setOpen() { _flags |= 1; } 386 | inline void setClosed() { _flags |= 2; } 387 | inline unsigned isOpen() const { return _flags & 1; } 388 | inline unsigned isClosed() const { return _flags & 2; } 389 | 390 | // We know nodes are allocated sequentially in memory, so this is fine. 391 | inline Node& getParent() { JPS_ASSERT(parentOffs); return this[parentOffs]; } 392 | inline const Node& getParent() const { JPS_ASSERT(parentOffs); return this[parentOffs]; } 393 | inline const Node *getParentOpt() const { return parentOffs ? this + parentOffs : 0; } 394 | inline void setParent(const Node& p) { JPS_ASSERT(&p != this); parentOffs = static_cast(&p - this); } 395 | }; 396 | 397 | template 398 | class PodVec 399 | { 400 | public: 401 | PodVec(void *user = 0) 402 | : _data(0), used(0), cap(0), _user(user) 403 | {} 404 | ~PodVec() { dealloc(); } 405 | inline void clear() 406 | { 407 | used = 0; 408 | } 409 | void dealloc() 410 | { 411 | JPS_free(_data, cap * sizeof(T), _user); 412 | _data = 0; 413 | used = 0; 414 | cap = 0; 415 | } 416 | T *alloc() 417 | { 418 | T *e = 0; 419 | if(used < cap || _grow()) 420 | { 421 | e = _data + used; 422 | ++used; 423 | } 424 | return e; 425 | } 426 | inline void push_back(const T& e) 427 | { 428 | if(T *dst = alloc()) // yes, this silently fails when OOM. this is handled internally. 429 | *dst = e; 430 | } 431 | inline void pop_back() { JPS_ASSERT(used); --used; } 432 | inline T& back() { JPS_ASSERT(used); return _data[used-1]; } 433 | inline SizeT size() const { return used; } 434 | inline bool empty() const { return !used; } 435 | inline T *data() { return _data; } 436 | inline const T *data() const { return _data; } 437 | inline T& operator[](size_t idx) const { JPS_ASSERT(idx < used); return _data[idx]; } 438 | inline SizeT getindex(const T *e) const 439 | { 440 | JPS_ASSERT(e && _data <= e && e < _data + used); 441 | return static_cast(e - _data); 442 | } 443 | 444 | void *_reserve(SizeT newcap) // for internal use 445 | { 446 | return cap < newcap ? _grow(newcap) : _data; 447 | } 448 | void resize(SizeT sz) 449 | { 450 | if(_reserve(sz)) 451 | used = sz; 452 | } 453 | SizeT _getMemSize() const 454 | { 455 | return cap * sizeof(T); 456 | } 457 | 458 | // minimal iterator interface 459 | typedef T* iterator; 460 | typedef const T* const_iterator; 461 | typedef SizeT size_type; 462 | typedef T value_type; 463 | inline iterator begin() { return data(); } 464 | inline iterator end() { return data() + size(); } 465 | inline const_iterator cbegin() const { return data(); } 466 | inline const_iterator cend() const { return data() + size(); } 467 | 468 | private: 469 | void *_grow(SizeT newcap) 470 | { 471 | void *p = JPS_realloc(_data, newcap * sizeof(T), cap * sizeof(T), _user); 472 | if(p) 473 | { 474 | _data = (T*)p; 475 | cap = newcap; 476 | } 477 | return p; 478 | } 479 | void * _grow() 480 | { 481 | const SizeT newcap = cap + (cap / 2) + 32; 482 | return _grow(newcap); 483 | } 484 | T *_data; 485 | SizeT used, cap; 486 | 487 | public: 488 | void * const _user; 489 | 490 | private: 491 | // forbid ops 492 | PodVec& operator=(const PodVec&); 493 | PodVec(const PodVec&); 494 | }; 495 | 496 | template 497 | inline static void Swap(T& a, T& b) 498 | { 499 | const T tmp = a; 500 | a = b; 501 | b = tmp; 502 | } 503 | 504 | template 505 | inline static void Reverse(IT first, IT last) 506 | { 507 | while((first != last) && (first != --last)) 508 | { 509 | Swap(*first, *last); 510 | ++first; 511 | } 512 | } 513 | 514 | typedef PodVec Storage; 515 | 516 | 517 | class NodeMap 518 | { 519 | private: 520 | static const unsigned LOAD_FACTOR = 8; // estimate: {CPU cache line size (64)} / sizeof(HashLoc) 521 | static const unsigned INITIAL_BUCKETS = 16; // must be > 1 and power of 2 522 | 523 | struct HashLoc 524 | { 525 | unsigned hash2; // for early-out check only 526 | SizeT idx; // index in central storage 527 | }; 528 | typedef PodVec Bucket; 529 | 530 | // hash function to determine bucket. only uses lower few bits. should jumble lower bits nicely. 531 | static inline unsigned Hash(PosType x, PosType y) 532 | { 533 | return x ^ y; 534 | } 535 | 536 | // hash function designed to lose as little data as possible. for early-out checks. all bits used. 537 | static inline unsigned Hash2(PosType x, PosType y) 538 | { 539 | return (y << 16) ^ x; 540 | } 541 | 542 | public: 543 | 544 | NodeMap(Storage& storage) 545 | : _storageRef(storage), _buckets(storage._user) 546 | {} 547 | 548 | ~NodeMap() 549 | { 550 | dealloc(); 551 | } 552 | 553 | void dealloc() 554 | { 555 | for(SizeT i = 0; i < _buckets.size(); ++i) 556 | _buckets[i].~Bucket(); 557 | _buckets.dealloc(); 558 | } 559 | void clear() 560 | { 561 | // clear the buckets, but *not* the bucket vector 562 | for(SizeT i = 0; i < _buckets.size(); ++i) 563 | _buckets[i].clear(); 564 | } 565 | 566 | Node *operator()(PosType x, PosType y) 567 | { 568 | const unsigned h = Hash(x, y); 569 | const unsigned h2 = Hash2(x, y); 570 | const SizeT ksz = _buckets.size(); // known to be power-of-2 571 | Bucket *b = 0; // MSVC /W4 complains that this was uninitialized and used, so we init it... 572 | if (ksz) 573 | { 574 | b = &_buckets[h & (ksz - 1)]; 575 | const SizeT bsz = b->size(); 576 | const HashLoc * const bdata = b->data(); 577 | for (SizeT i = 0; i < bsz; ++i) 578 | { 579 | // this is the only place where HashLoc::hash2 is used; it *could*be removed, which means: 580 | // - twice as much space for indexes per cache line 581 | // - but also higher chances for a cache miss because for each entry in the bucket we still need to check the node's X/Y coords, 582 | // and we'll likely end up in a random location in RAM for each node. 583 | // Quick benchmarking showed that *with* the hash2 check it's almost immeasurably (less than 1%) faster. 584 | if (bdata[i].hash2 == h2) 585 | { 586 | Node &n = _storageRef[bdata[i].idx]; 587 | if(n.pos.x == x && n.pos.y == y) 588 | return &n; 589 | } 590 | } 591 | } 592 | 593 | // enlarge hashmap if necessary; fix bucket if so 594 | SizeT newbsz = _enlarge(); 595 | if(newbsz > 1) 596 | b = &_buckets[h & (newbsz - 1)]; 597 | else if(newbsz == 1) // error case 598 | return 0; 599 | 600 | HashLoc *loc = b->alloc(); // ... see above. b is always initialized here. when ksz==0, _enlarge() will do its initial allocation, so it can never return 0. 601 | 602 | if(!loc) 603 | return 0; 604 | 605 | loc->hash2 = h2; 606 | loc->idx = _storageRef.size(); 607 | 608 | // no node at (x, y), create new one 609 | Node *n = _storageRef.alloc(); 610 | if(n) 611 | { 612 | n->f = 0; 613 | n->g = 0; 614 | n->pos.x = x; 615 | n->pos.y = y; 616 | n->parentOffs = 0; 617 | n->_flags = 0; 618 | } 619 | return n; 620 | } 621 | 622 | SizeT _getMemSize() const 623 | { 624 | SizeT sum = _buckets._getMemSize(); 625 | for(Buckets::const_iterator it = _buckets.cbegin(); it != _buckets.cend(); ++it) 626 | sum += it->_getMemSize(); 627 | return sum; 628 | } 629 | 630 | private: 631 | 632 | // return values: 0 = nothing to do; 1 = error; >1: internal storage was enlarged to this many buckets 633 | SizeT _enlarge() 634 | { 635 | const SizeT n = _storageRef.size(); 636 | const SizeT oldsz = _buckets.size(); 637 | if (n < oldsz * LOAD_FACTOR) 638 | return 0; 639 | 640 | // pre-allocate bucket storage that we're going to use 641 | const SizeT newsz = oldsz ? oldsz * 2 : INITIAL_BUCKETS; // stays power of 2 642 | 643 | if(!_buckets._reserve(newsz)) 644 | return 0; // early out if realloc fails; this not a problem and we can continue. 645 | 646 | // forget everything 647 | for(SizeT i = 0; i < oldsz; ++i) 648 | _buckets[i].clear(); 649 | 650 | // resize and init 651 | for(SizeT i = oldsz; i < newsz; ++i) 652 | { 653 | void *p = _buckets.alloc(); // can't fail since the space was reserved 654 | JPS_PLACEMENT_NEW(p) PodVec(_buckets._user); 655 | } 656 | 657 | const SizeT mask = _buckets.size() - 1; 658 | for(SizeT i = 0; i < n; ++i) 659 | { 660 | const Position p = _storageRef[i].pos; 661 | HashLoc *loc = _buckets[Hash(p.x, p.y) & mask].alloc(); 662 | if(!loc) 663 | return 1; // error case 664 | 665 | loc->hash2 = Hash2(p.x, p.y); 666 | loc->idx = i; 667 | } 668 | return newsz; 669 | } 670 | 671 | Storage& _storageRef; 672 | typedef PodVec Buckets; 673 | Buckets _buckets; 674 | }; 675 | 676 | class OpenList 677 | { 678 | private: 679 | const Storage& _storageRef; 680 | PodVec idxHeap; 681 | 682 | public: 683 | 684 | OpenList(const Storage& storage) 685 | : _storageRef(storage), idxHeap(storage._user) 686 | {} 687 | 688 | 689 | inline void pushNode(Node *n) 690 | { 691 | _heapPushIdx(_storageRef.getindex(n)); 692 | } 693 | 694 | inline Node& popNode() 695 | { 696 | return _storageRef[_popIdx()]; 697 | } 698 | 699 | // re-heapify after node changed its order 700 | inline void fixNode(const Node& n) 701 | { 702 | const unsigned ni = _storageRef.getindex(&n); 703 | const unsigned sz = idxHeap.size(); 704 | unsigned *p = idxHeap.data(); 705 | for(unsigned i = 0; i < sz; ++i) // TODO: if this ever becomes a perf bottleneck: make it so that each node knows its heap index 706 | if(p[i] == ni) 707 | { 708 | _fixIdx(i); 709 | return; 710 | } 711 | JPS_ASSERT(false); // expect node to be found 712 | } 713 | 714 | inline void dealloc() { idxHeap.dealloc(); } 715 | inline void clear() { idxHeap.clear(); } 716 | inline bool empty() const { return idxHeap.empty(); } 717 | 718 | inline SizeT _getMemSize() const 719 | { 720 | return idxHeap._getMemSize(); 721 | } 722 | 723 | private: 724 | 725 | inline bool _heapLess(SizeT a, SizeT b) 726 | { 727 | return _storageRef[idxHeap[a]].f > _storageRef[idxHeap[b]].f; 728 | } 729 | 730 | inline bool _heapLessIdx(SizeT a, SizeT idx) 731 | { 732 | return _storageRef[idxHeap[a]].f > _storageRef[idx].f; 733 | } 734 | 735 | void _percolateUp(SizeT i) 736 | { 737 | const SizeT idx = idxHeap[i]; 738 | SizeT p; 739 | goto start; 740 | do 741 | { 742 | idxHeap[i] = idxHeap[p]; // parent is smaller, move it down 743 | i = p; // continue with parent 744 | start: 745 | p = (i - 1) >> 1; 746 | } 747 | while(i && _heapLessIdx(p, idx)); 748 | idxHeap[i] = idx; // found correct place for idx 749 | } 750 | 751 | void _percolateDown(SizeT i) 752 | { 753 | const SizeT idx = idxHeap[i]; 754 | const SizeT sz = idxHeap.size(); 755 | SizeT child; 756 | goto start; 757 | do 758 | { 759 | // pick right sibling if exists and larger or equal 760 | if(child + 1 < sz && !_heapLess(child+1, child)) 761 | ++child; 762 | idxHeap[i] = idxHeap[child]; 763 | i = child; 764 | start: 765 | child = (i << 1) + 1; 766 | } 767 | while(child < sz); 768 | idxHeap[i] = idx; 769 | _percolateUp(i); 770 | } 771 | 772 | void _heapPushIdx(SizeT idx) 773 | { 774 | SizeT i = idxHeap.size(); 775 | idxHeap.push_back(idx); 776 | _percolateUp(i); 777 | } 778 | 779 | SizeT _popIdx() 780 | { 781 | SizeT sz = idxHeap.size(); 782 | JPS_ASSERT(sz); 783 | const SizeT root = idxHeap[0]; 784 | idxHeap[0] = idxHeap[--sz]; 785 | idxHeap.pop_back(); 786 | if(sz > 1) 787 | _percolateDown(0); 788 | return root; 789 | } 790 | 791 | // re-heapify node at index i 792 | inline void _fixIdx(SizeT i) 793 | { 794 | _percolateDown(i); 795 | _percolateUp(i); 796 | } 797 | }; 798 | 799 | #undef JPS_PLACEMENT_NEW 800 | 801 | // --- End infrastructure, data structures --- 802 | 803 | // All those things that don't depend on template parameters... 804 | class SearcherBase 805 | { 806 | protected: 807 | Storage storage; 808 | OpenList open; 809 | NodeMap nodemap; 810 | 811 | Position endPos; 812 | SizeT endNodeIdx; 813 | JPS_Flags flags; 814 | int stepsRemain; 815 | SizeT stepsDone; 816 | 817 | 818 | SearcherBase(void *user) 819 | : storage(user) 820 | , open(storage) 821 | , nodemap(storage) 822 | , endPos(npos), endNodeIdx(noidx) 823 | , flags(0) 824 | , stepsRemain(0), stepsDone(0) 825 | {} 826 | 827 | void clear() 828 | { 829 | open.clear(); 830 | nodemap.clear(); 831 | storage.clear(); 832 | endNodeIdx = noidx; 833 | stepsDone = 0; 834 | } 835 | 836 | void _expandNode(const Position jp, Node& jn, const Node& parent) 837 | { 838 | JPS_ASSERT(jn.pos == jp); 839 | ScoreType extraG = JPS_HEURISTIC_ACCURATE(jp, parent.pos); 840 | ScoreType newG = parent.g + extraG; 841 | if(!jn.isOpen() || newG < jn.g) 842 | { 843 | jn.g = newG; 844 | jn.f = jn.g + JPS_HEURISTIC_ESTIMATE(jp, endPos); 845 | jn.setParent(parent); 846 | if(!jn.isOpen()) 847 | { 848 | open.pushNode(&jn); 849 | jn.setOpen(); 850 | } 851 | else 852 | open.fixNode(jn); 853 | } 854 | } 855 | 856 | public: 857 | 858 | template 859 | JPS_Result generatePath(PV& path, unsigned step) const; 860 | 861 | void freeMemory() 862 | { 863 | open.dealloc(); 864 | nodemap.dealloc(); 865 | storage.dealloc(); 866 | endNodeIdx = noidx; 867 | } 868 | 869 | // --- Statistics --- 870 | 871 | inline SizeT getStepsDone() const { return stepsDone; } 872 | inline SizeT getNodesExpanded() const { return storage.size(); } 873 | 874 | SizeT getTotalMemoryInUse() const 875 | { 876 | return storage._getMemSize() 877 | + nodemap._getMemSize() 878 | + open._getMemSize(); 879 | } 880 | }; 881 | 882 | template class Searcher : public SearcherBase 883 | { 884 | public: 885 | Searcher(const GRID& g, void *user = 0) 886 | : SearcherBase(user), grid(g) 887 | {} 888 | 889 | // single-call 890 | template 891 | bool findPath(PV& path, Position start, Position end, unsigned step, JPS_Flags flags = JPS_Flag_Default); 892 | 893 | // incremental pathfinding 894 | JPS_Result findPathInit(Position start, Position end, JPS_Flags flags = JPS_Flag_Default); 895 | JPS_Result findPathStep(int limit); 896 | // generate path after one was found 897 | template 898 | JPS_Result findPathFinish(PV& path, unsigned step) const; 899 | 900 | private: 901 | 902 | const GRID& grid; 903 | 904 | Node *getNode(const Position& pos); 905 | bool identifySuccessors(const Node& n); 906 | 907 | bool findPathGreedy(Node *start, Node *end); 908 | 909 | unsigned findNeighborsAStar(const Node& n, Position *wptr); 910 | 911 | unsigned findNeighborsJPS(const Node& n, Position *wptr) const; 912 | Position jumpP(const Position& p, const Position& src); 913 | Position jumpD(Position p, int dx, int dy); 914 | Position jumpX(Position p, int dx); 915 | Position jumpY(Position p, int dy); 916 | 917 | // forbid any ops 918 | Searcher& operator=(const Searcher&); 919 | Searcher(const Searcher&); 920 | }; 921 | 922 | 923 | // ----------------------------------------------------------------------- 924 | 925 | template JPS_Result SearcherBase::generatePath(PV& path, unsigned step) const 926 | { 927 | if(endNodeIdx == noidx) 928 | return JPS_NO_PATH; 929 | const SizeT offset = path.size(); 930 | SizeT added = 0; 931 | const Node& endNode = storage[endNodeIdx]; 932 | const Node *next = &endNode; 933 | if(!next->hasParent()) 934 | return JPS_NO_PATH; 935 | if(step) 936 | { 937 | const Node *prev = endNode.getParentOpt(); 938 | if(!prev) 939 | return JPS_NO_PATH; 940 | do 941 | { 942 | const unsigned x = next->pos.x, y = next->pos.y; 943 | int dx = int(prev->pos.x - x); 944 | int dy = int(prev->pos.y - y); 945 | const int adx = Abs(dx); 946 | const int ady = Abs(dy); 947 | JPS_ASSERT(!dx || !dy || adx == ady); // known to be straight, if diagonal 948 | const int steps = Max(adx, ady); 949 | dx = int(step) * Sgn(dx); 950 | dy = int(step) * Sgn(dy); 951 | int dxa = 0, dya = 0; 952 | for(int i = 0; i < steps; i += step) 953 | { 954 | path.push_back(Pos(x+dxa, y+dya)); 955 | ++added; 956 | dxa += dx; 957 | dya += dy; 958 | } 959 | next = prev; 960 | prev = prev->getParentOpt(); 961 | } 962 | while (prev); 963 | } 964 | else 965 | { 966 | do 967 | { 968 | JPS_ASSERT(next != &next->getParent()); 969 | path.push_back(next->pos); 970 | ++added; 971 | next = &next->getParent(); 972 | } 973 | while (next->hasParent()); 974 | } 975 | 976 | // JPS::PathVector silently discards push_back() when memory allocation fails; 977 | // detect that case and roll back. 978 | if(path.size() != offset + added) 979 | { 980 | path.resize(offset); 981 | return JPS_OUT_OF_MEMORY; 982 | } 983 | 984 | // Nodes were traversed backwards, fix that 985 | Reverse(path.begin() + offset, path.end()); 986 | return JPS_FOUND_PATH; 987 | } 988 | 989 | //----------------------------------------- 990 | 991 | template inline Node *Searcher::getNode(const Position& pos) 992 | { 993 | JPS_ASSERT(grid(pos.x, pos.y)); 994 | return nodemap(pos.x, pos.y); 995 | } 996 | 997 | template Position Searcher::jumpP(const Position &p, const Position& src) 998 | { 999 | JPS_ASSERT(grid(p.x, p.y)); 1000 | 1001 | int dx = int(p.x - src.x); 1002 | int dy = int(p.y - src.y); 1003 | JPS_ASSERT(dx || dy); 1004 | 1005 | if(dx && dy) 1006 | return jumpD(p, dx, dy); 1007 | else if(dx) 1008 | return jumpX(p, dx); 1009 | else if(dy) 1010 | return jumpY(p, dy); 1011 | 1012 | // not reached 1013 | JPS_ASSERT(false); 1014 | return npos; 1015 | } 1016 | 1017 | template Position Searcher::jumpD(Position p, int dx, int dy) 1018 | { 1019 | JPS_ASSERT(grid(p.x, p.y)); 1020 | JPS_ASSERT(dx && dy); 1021 | 1022 | const Position endpos = endPos; 1023 | unsigned steps = 0; 1024 | 1025 | while(true) 1026 | { 1027 | if(p == endpos) 1028 | break; 1029 | 1030 | ++steps; 1031 | const PosType x = p.x; 1032 | const PosType y = p.y; 1033 | 1034 | if( (grid(x-dx, y+dy) && !grid(x-dx, y)) || (grid(x+dx, y-dy) && !grid(x, y-dy)) ) 1035 | break; 1036 | 1037 | const bool gdx = !!grid(x+dx, y); 1038 | const bool gdy = !!grid(x, y+dy); 1039 | 1040 | if(gdx && jumpX(Pos(x+dx, y), dx).isValid()) 1041 | break; 1042 | 1043 | if(gdy && jumpY(Pos(x, y+dy), dy).isValid()) 1044 | break; 1045 | 1046 | if((gdx || gdy) && grid(x+dx, y+dy)) 1047 | { 1048 | p.x += dx; 1049 | p.y += dy; 1050 | } 1051 | else 1052 | { 1053 | p = npos; 1054 | break; 1055 | } 1056 | } 1057 | stepsDone += steps; 1058 | stepsRemain -= steps; 1059 | return p; 1060 | } 1061 | 1062 | template inline Position Searcher::jumpX(Position p, int dx) 1063 | { 1064 | JPS_ASSERT(dx); 1065 | JPS_ASSERT(grid(p.x, p.y)); 1066 | 1067 | const PosType y = p.y; 1068 | const Position endpos = endPos; 1069 | unsigned steps = 0; 1070 | 1071 | unsigned a = ~((!!grid(p.x, y+1)) | ((!!grid(p.x, y-1)) << 1)); 1072 | 1073 | while(true) 1074 | { 1075 | const unsigned xx = p.x + dx; 1076 | const unsigned b = (!!grid(xx, y+1)) | ((!!grid(xx, y-1)) << 1); 1077 | 1078 | if((b & a) || p == endpos) 1079 | break; 1080 | if(!grid(xx, y)) 1081 | { 1082 | p = npos; 1083 | break; 1084 | } 1085 | 1086 | p.x += dx; 1087 | a = ~b; 1088 | ++steps; 1089 | } 1090 | 1091 | stepsDone += steps; 1092 | stepsRemain -= steps; 1093 | return p; 1094 | } 1095 | 1096 | template inline Position Searcher::jumpY(Position p, int dy) 1097 | { 1098 | JPS_ASSERT(dy); 1099 | JPS_ASSERT(grid(p.x, p.y)); 1100 | 1101 | const PosType x = p.x; 1102 | const Position endpos = endPos; 1103 | unsigned steps = 0; 1104 | 1105 | unsigned a = ~((!!grid(x+1, p.y)) | ((!!grid(x-1, p.y)) << 1)); 1106 | 1107 | while(true) 1108 | { 1109 | const unsigned yy = p.y + dy; 1110 | const unsigned b = (!!grid(x+1, yy)) | ((!!grid(x-1, yy)) << 1); 1111 | 1112 | if((a & b) || p == endpos) 1113 | break; 1114 | if(!grid(x, yy)) 1115 | { 1116 | p = npos; 1117 | break; 1118 | } 1119 | 1120 | p.y += dy; 1121 | a = ~b; 1122 | ++steps; 1123 | } 1124 | 1125 | stepsDone += steps; 1126 | stepsRemain -= steps; 1127 | return p; 1128 | } 1129 | 1130 | #define JPS_CHECKGRID(dx, dy) (grid(x+(dx), y+(dy))) 1131 | #define JPS_ADDPOS(dx, dy) do { *w++ = Pos(x+(dx), y+(dy)); } while(0) 1132 | #define JPS_ADDPOS_CHECK(dx, dy) do { if(JPS_CHECKGRID(dx, dy)) JPS_ADDPOS(dx, dy); } while(0) 1133 | #define JPS_ADDPOS_NO_TUNNEL(dx, dy) do { if(grid(x+(dx),y) || grid(x,y+(dy))) JPS_ADDPOS_CHECK(dx, dy); } while(0) 1134 | 1135 | template unsigned Searcher::findNeighborsJPS(const Node& n, Position *wptr) const 1136 | { 1137 | Position *w = wptr; 1138 | const unsigned x = n.pos.x; 1139 | const unsigned y = n.pos.y; 1140 | 1141 | if(!n.hasParent()) 1142 | { 1143 | // straight moves 1144 | JPS_ADDPOS_CHECK(-1, 0); 1145 | JPS_ADDPOS_CHECK(0, -1); 1146 | JPS_ADDPOS_CHECK(0, 1); 1147 | JPS_ADDPOS_CHECK(1, 0); 1148 | 1149 | // diagonal moves + prevent tunneling 1150 | JPS_ADDPOS_NO_TUNNEL(-1, -1); 1151 | JPS_ADDPOS_NO_TUNNEL(-1, 1); 1152 | JPS_ADDPOS_NO_TUNNEL(1, -1); 1153 | JPS_ADDPOS_NO_TUNNEL(1, 1); 1154 | 1155 | return unsigned(w - wptr); 1156 | } 1157 | const Node& p = n.getParent(); 1158 | // jump directions (both -1, 0, or 1) 1159 | const int dx = Sgn(x - p.pos.x); 1160 | const int dy = Sgn(y - p.pos.y); 1161 | 1162 | if(dx && dy) 1163 | { 1164 | // diagonal 1165 | // natural neighbors 1166 | const bool walkX = !!grid(x+dx, y); 1167 | if(walkX) 1168 | *w++ = Pos(x+dx, y); 1169 | const bool walkY = !!grid(x, y+dy); 1170 | if(walkY) 1171 | *w++ = Pos(x, y+dy); 1172 | 1173 | if(walkX || walkY) 1174 | JPS_ADDPOS_CHECK(dx, dy); 1175 | 1176 | // forced neighbors 1177 | if(walkY && !JPS_CHECKGRID(-dx,0)) 1178 | JPS_ADDPOS_CHECK(-dx, dy); 1179 | 1180 | if(walkX && !JPS_CHECKGRID(0,-dy)) 1181 | JPS_ADDPOS_CHECK(dx, -dy); 1182 | } 1183 | else if(dx) 1184 | { 1185 | // along X axis 1186 | if(JPS_CHECKGRID(dx, 0)) 1187 | { 1188 | JPS_ADDPOS(dx, 0); 1189 | 1190 | // Forced neighbors (+ prevent tunneling) 1191 | if(!JPS_CHECKGRID(0, 1)) 1192 | JPS_ADDPOS_CHECK(dx, 1); 1193 | if(!JPS_CHECKGRID(0,-1)) 1194 | JPS_ADDPOS_CHECK(dx,-1); 1195 | } 1196 | } 1197 | else if(dy) 1198 | { 1199 | // along Y axis 1200 | if(JPS_CHECKGRID(0, dy)) 1201 | { 1202 | JPS_ADDPOS(0, dy); 1203 | 1204 | // Forced neighbors (+ prevent tunneling) 1205 | if(!JPS_CHECKGRID(1, 0)) 1206 | JPS_ADDPOS_CHECK(1, dy); 1207 | if(!JPS_CHECKGRID(-1, 0)) 1208 | JPS_ADDPOS_CHECK(-1,dy); 1209 | } 1210 | } 1211 | 1212 | return unsigned(w - wptr); 1213 | } 1214 | 1215 | //-------------- Plain old A* search ---------------- 1216 | template unsigned Searcher::findNeighborsAStar(const Node& n, Position *wptr) 1217 | { 1218 | Position *w = wptr; 1219 | const int x = n.pos.x; 1220 | const int y = n.pos.y; 1221 | const int d = 1; 1222 | JPS_ADDPOS_NO_TUNNEL(-d, -d); 1223 | JPS_ADDPOS_CHECK ( 0, -d); 1224 | JPS_ADDPOS_NO_TUNNEL(+d, -d); 1225 | JPS_ADDPOS_CHECK (-d, 0); 1226 | JPS_ADDPOS_CHECK (+d, 0); 1227 | JPS_ADDPOS_NO_TUNNEL(-d, +d); 1228 | JPS_ADDPOS_CHECK ( 0, +d); 1229 | JPS_ADDPOS_NO_TUNNEL(+d, +d); 1230 | stepsDone += 8; 1231 | return unsigned(w - wptr); 1232 | } 1233 | 1234 | //------------------------------------------------- 1235 | #undef JPS_ADDPOS 1236 | #undef JPS_ADDPOS_CHECK 1237 | #undef JPS_ADDPOS_NO_TUNNEL 1238 | #undef JPS_CHECKGRID 1239 | 1240 | 1241 | template bool Searcher::identifySuccessors(const Node& n_) 1242 | { 1243 | const SizeT nidx = storage.getindex(&n_); 1244 | const Position np = n_.pos; 1245 | Position buf[8]; 1246 | 1247 | const int num = (flags & JPS_Flag_AStarOnly) 1248 | ? findNeighborsAStar(n_, &buf[0]) 1249 | : findNeighborsJPS(n_, &buf[0]); 1250 | 1251 | for(int i = num-1; i >= 0; --i) 1252 | { 1253 | // Invariant: A node is only a valid neighbor if the corresponding grid position is walkable (asserted in jumpP) 1254 | Position jp; 1255 | if(flags & JPS_Flag_AStarOnly) 1256 | jp = buf[i]; 1257 | else 1258 | { 1259 | jp = jumpP(buf[i], np); 1260 | if(!jp.isValid()) 1261 | continue; 1262 | } 1263 | // Now that the grid position is definitely a valid jump point, we have to create the actual node. 1264 | Node *jn = getNode(jp); // this might realloc the storage 1265 | if(!jn) 1266 | return false; // out of memory 1267 | 1268 | Node& n = storage[nidx]; // get valid ref in case we realloc'd 1269 | JPS_ASSERT(jn != &n); 1270 | if(!jn->isClosed()) 1271 | _expandNode(jp, *jn, n); 1272 | } 1273 | return true; 1274 | } 1275 | 1276 | template template bool Searcher::findPath(PV& path, Position start, Position end, unsigned step, JPS_Flags flags) 1277 | { 1278 | JPS_Result res = findPathInit(start, end, flags); 1279 | 1280 | // If this is true, the resulting path is empty (findPathFinish() would fail, so this needs to be checked before) 1281 | if(res == JPS_EMPTY_PATH) 1282 | return true; 1283 | 1284 | while(true) 1285 | { 1286 | switch(res) 1287 | { 1288 | case JPS_NEED_MORE_STEPS: 1289 | res = findPathStep(0); 1290 | break; // the switch 1291 | 1292 | case JPS_FOUND_PATH: 1293 | return findPathFinish(path, step) == JPS_FOUND_PATH; 1294 | 1295 | case JPS_EMPTY_PATH: 1296 | JPS_ASSERT(false); // can't happen 1297 | // fall through 1298 | case JPS_NO_PATH: 1299 | case JPS_OUT_OF_MEMORY: 1300 | return false; 1301 | } 1302 | } 1303 | } 1304 | 1305 | template JPS_Result Searcher::findPathInit(Position start, Position end, JPS_Flags flags) 1306 | { 1307 | // This just resets a few counters; container memory isn't touched 1308 | this->clear(); 1309 | 1310 | this->flags = flags; 1311 | endPos = end; 1312 | 1313 | // FIXME: check this 1314 | if(start == end && !(flags & (JPS_Flag_NoStartCheck|JPS_Flag_NoEndCheck))) 1315 | { 1316 | // There is only a path if this single position is walkable. 1317 | // But since the starting position is omitted in the output, there is nothing to do here. 1318 | return grid(end.x, end.y) ? JPS_EMPTY_PATH : JPS_NO_PATH; 1319 | } 1320 | 1321 | if(!(flags & JPS_Flag_NoStartCheck)) 1322 | if(!grid(start.x, start.y)) 1323 | return JPS_NO_PATH; 1324 | 1325 | if(!(flags & JPS_Flag_NoEndCheck)) 1326 | if(!grid(end.x, end.y)) 1327 | return JPS_NO_PATH; 1328 | 1329 | Node *endNode = getNode(end); // this might realloc the internal storage... 1330 | if(!endNode) 1331 | return JPS_OUT_OF_MEMORY; 1332 | endNodeIdx = storage.getindex(endNode); // .. so we keep this for later 1333 | 1334 | Node *startNode = getNode(start); // this might also realloc 1335 | if(!startNode) 1336 | return JPS_OUT_OF_MEMORY; 1337 | endNode = &storage[endNodeIdx]; // startNode is valid, make sure that endNode is valid too in case we reallocated 1338 | 1339 | if(!(flags & JPS_Flag_NoGreedy)) 1340 | { 1341 | // Try the quick way out first 1342 | if(findPathGreedy(startNode, endNode)) 1343 | return JPS_FOUND_PATH; 1344 | } 1345 | 1346 | open.pushNode(startNode); 1347 | 1348 | return JPS_NEED_MORE_STEPS; 1349 | } 1350 | 1351 | template JPS_Result Searcher::findPathStep(int limit) 1352 | { 1353 | stepsRemain = limit; 1354 | do 1355 | { 1356 | if(open.empty()) 1357 | return JPS_NO_PATH; 1358 | Node& n = open.popNode(); 1359 | n.setClosed(); 1360 | if(n.pos == endPos) 1361 | return JPS_FOUND_PATH; 1362 | if(!identifySuccessors(n)) 1363 | return JPS_OUT_OF_MEMORY; 1364 | } 1365 | while(stepsRemain >= 0); 1366 | return JPS_NEED_MORE_STEPS; 1367 | } 1368 | 1369 | template template JPS_Result Searcher::findPathFinish(PV& path, unsigned step) const 1370 | { 1371 | return this->generatePath(path, step); 1372 | } 1373 | 1374 | template bool Searcher::findPathGreedy(Node *n, Node *endnode) 1375 | { 1376 | Position midpos = npos; 1377 | PosType x = n->pos.x; 1378 | PosType y = n->pos.y; 1379 | const Position endpos = endnode->pos; 1380 | 1381 | JPS_ASSERT(x != endpos.x || y != endpos.y); // must not be called when start==end 1382 | JPS_ASSERT(n != endnode); 1383 | 1384 | int dx = int(endpos.x - x); 1385 | int dy = int(endpos.y - y); 1386 | const int adx = Abs(dx); 1387 | const int ady = Abs(dy); 1388 | dx = Sgn(dx); 1389 | dy = Sgn(dy); 1390 | 1391 | // go diagonally first 1392 | if(x != endpos.x && y != endpos.y) 1393 | { 1394 | JPS_ASSERT(dx && dy); 1395 | const int minlen = Min(adx, ady); 1396 | const PosType tx = x + dx * minlen; 1397 | while(x != tx) 1398 | { 1399 | if(grid(x, y) && (grid(x+dx, y) || grid(x, y+dy))) // prevent tunneling as well 1400 | { 1401 | x += dx; 1402 | y += dy; 1403 | } 1404 | else 1405 | return false; 1406 | } 1407 | 1408 | if(!grid(x, y)) 1409 | return false; 1410 | 1411 | midpos = Pos(x, y); 1412 | } 1413 | 1414 | // at this point, we're aligned to at least one axis 1415 | JPS_ASSERT(x == endpos.x || y == endpos.y); 1416 | 1417 | if(!(x == endpos.x && y == endpos.y)) 1418 | { 1419 | while(x != endpos.x) 1420 | if(!grid(x += dx, y)) 1421 | return false; 1422 | 1423 | while(y != endpos.y) 1424 | if(!grid(x, y += dy)) 1425 | return false; 1426 | 1427 | JPS_ASSERT(x == endpos.x && y == endpos.y); 1428 | } 1429 | 1430 | if(midpos.isValid()) 1431 | { 1432 | const unsigned nidx = storage.getindex(n); 1433 | Node *mid = getNode(midpos); // this might invalidate n, endnode 1434 | if(!mid) 1435 | return false; 1436 | n = &storage[nidx]; // reload pointers 1437 | endnode = &storage[endNodeIdx]; 1438 | JPS_ASSERT(mid && mid != n); 1439 | mid->setParent(*n); 1440 | if(mid != endnode) 1441 | endnode->setParent(*mid); 1442 | } 1443 | else 1444 | endnode->setParent(*n); 1445 | 1446 | return true; 1447 | } 1448 | 1449 | #undef JPS_ASSERT 1450 | #undef JPS_realloc 1451 | #undef JPS_free 1452 | #undef JPS_sqrt 1453 | #undef JPS_HEURISTIC_ACCURATE 1454 | #undef JPS_HEURISTIC_ESTIMATE 1455 | 1456 | 1457 | } // end namespace Internal 1458 | 1459 | using Internal::Searcher; 1460 | 1461 | typedef Internal::PodVec PathVector; 1462 | 1463 | // Single-call convenience function. For efficiency, do NOT use this if you need to compute paths repeatedly. 1464 | // 1465 | // Returns: 0 if failed or no path could be found, otherwise number of steps taken. 1466 | // 1467 | // path: If the function returns success, the path is appended to this vector. 1468 | // The path does NOT contain the starting position, i.e. if start and end are the same, 1469 | // the resulting path has no elements. 1470 | // The vector does not have to be empty. The function does not clear it; 1471 | // instead, the new path positions are appended at the end. 1472 | // This allows building a path incrementally. 1473 | // 1474 | // grid: Functor, expected to overload operator()(x, y), return true if position is walkable, false if not. 1475 | // 1476 | // step: If 0, only return waypoints. 1477 | // If 1, create exhaustive step-by-step path. 1478 | // If N, put in one position for N blocks travelled, or when a waypoint is hit. 1479 | // All returned points are guaranteed to be on a straight line (vertically, horizontally, or diagonally), 1480 | // and there is no obstruction between any two consecutive points. 1481 | // Note that this parameter does NOT influence the pathfinding in any way; 1482 | // it only controls the coarseness of the output path. 1483 | template 1484 | SizeT findPath(PV& path, const GRID& grid, PosType startx, PosType starty, PosType endx, PosType endy, 1485 | unsigned step = 0, // optional 1486 | JPS_Flags flags = JPS_Flag_Default, 1487 | void *user = 0) // memory allocation userdata 1488 | { 1489 | Searcher search(grid, user); 1490 | if(!search.findPath(path, Pos(startx, starty), Pos(endx, endy), step, flags)) 1491 | return 0; 1492 | const SizeT done = search.getStepsDone(); 1493 | return done + !done; // report at least 1 step; as 0 would indicate failure 1494 | } 1495 | 1496 | } // end namespace JPS 1497 | 1498 | 1499 | /* 1500 | Changes compared to the older JPS.h at https://github.com/fgenesis/jps: 1501 | 1502 | - Explicitly freeing memory is no longer necessary. The freeMemory() method is still there 1503 | and does its thing (drop all internal storage), but you never have to call it explicitly. 1504 | Unlike the old version, there will be no performance degradation if you don't free memory every now and then. 1505 | Actually it'll be slightly slower if you free memory and pathfind again for the first time, 1506 | as it has to re-allocate internal data structures. 1507 | 1508 | - Searcher::getNodesExpanded() is now reset to 0 upon starting a search. 1509 | 1510 | - Added optional JPS_Flags parameter to pathfind (-init) functions to control search 1511 | behavior. Compile-time #defines are gone. 1512 | 1513 | - Removed skip parameter. Imho that one just added confusion and no real benefit. 1514 | If you want it back for some reason: poke me, open an issue, whatever. 1515 | 1516 | - Renamed JPS::Result to JPS_Result. Enum values gained JPS_ prefix, so JPS::NO_PATH is now JPS_NO_PATH, and so on. 1517 | 1518 | - Added one more JPS_Result value: JPS_OUT_OF_MEMORY. See info block at the top how to handle this. 1519 | 1520 | - Changed signature of Searcher<>::findPathFinish() to return JPS_Result (was bool). 1521 | This is more in line with the other 2 methods, as it can now return JPS_OUT_OF_MEMORY. 1522 | 1523 | - Changed signature of JPS::findPath(). Nonzero return is still success. Pointers to output stats are gone. 1524 | Use a Searcher instance if you need the details. 1525 | 1526 | - This version no longer depends on the C++ STL: , , , operator new(), all gone. 1527 | Makes things more memory- and cache-friendly, and quite a bit faster, too. 1528 | 1529 | - The canonical file name is now "jps.hh" instead of "JPS.h" 1530 | */ 1531 | 1532 | 1533 | /* 1534 | TODO: 1535 | - make int -> DirType 1536 | - make possible to call findPathStep()/findPathFinish() even when JPS_EMPTY_PATH was returned on init (simplifies switch-case) 1537 | - make node know its heap index 1538 | - optional diagonals (make runtime param) 1539 | */ 1540 | --------------------------------------------------------------------------------