markers, and dump the persistant Lua data.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8839 c06c8d41-db1a-0410-9941-cceddc491573
6TAQWWURX3QF4XXV7YGJEL5VKFLFEB2HV2PGJ5ARYNNRRRNVTFUAC RNIAOCLZYEW5GB7I536HRPYJ7DSDEXITH5RZP5CPKJYHVUTWBKRQC 7Y5HSDFKA5TPLS2TWTRFMQVX6UXUDHXU5MUMXQSDFAIY4THQ3BIQC GQL5SIGBHLU3FMCE54XVGLRY5AZHRM6DUEB722REA2DPLGJSN6EQC WLX2RQMMOMP2PYPAGJRM4VFD2WTLJTOAZZPPY3MV76FU2EGEJ54QC K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC KOMZPTDEZP3P6EWBUECWDY7OWELOUTMAUKNEOJ7PWX5LJBTMRVQAC 6IHRQWBU55WYBVB7K5HDJSBISE3J3VILUCMQ6WYOBUZ43DLOQ6VQC NKONHW4JNY6HP2M63MNPM3H64ZWSUNUT5FX2STW4KTS4AMXJXXVQC SM6YRPYZS6LMDQA6X3VAOK2PGMUFKPD7JMWJISOQSMX2CBR4ISPAC X7MFMKQTNZ2IWBFVGS6WQV7NRNKJ3DWQAW2X7IQMFQQXW24AHPZQC 44YRMW5JNVUBYX3M6UFQOPENNHGO7G2CRZ7SGPIIUTQGYWTRWENAC W52PCSHX72WAMWKG6L4BPUBVMO6E72KYYBNKAA7554KNOTY6V7WQC }static void _debug_marker_scan(){std::vector<map_marker*> markers = env.markers.get_all();for (unsigned int i = 0; i < markers.size(); i++){map_marker* marker = markers[i];if (marker == NULL){mprf(MSGCH_ERROR, "Marker #%d is NULL", i);continue;}map_marker_type type = marker->get_type();if (type < MAT_FEATURE || type >= NUM_MAP_MARKER_TYPES)mprf(MSGCH_ERROR, "Makrer #%d at (%d, %d) has invalid type %d",i, marker->pos.x, marker->pos.y, (int) type);if (!in_bounds(marker->pos)){mprf(MSGCH_ERROR, "Marker #%d, type %d at (%d, %d) out of bounds",i, (int) type, marker->pos.x, marker->pos.y);continue;}bool found = false;std::vector<map_marker*> at_pos= env.markers.get_markers_at(marker->pos);for (unsigned int j = 0; j < at_pos.size(); j++){map_marker* tmp = at_pos[i];if (tmp == NULL)continue;if (tmp == marker){found = true;break;}}if (!found)mprf(MSGCH_ERROR, "Marker #%d, type %d at (%d, %d) unlinked",i, (int) type, marker->pos.x, marker->pos.y);}for (int x = MAPGEN_BORDER; x < (GXM - MAPGEN_BORDER - 1); x++)for (int y = MAPGEN_BORDER; y < (GYM - MAPGEN_BORDER - 1); y++){coord_def pos(x, y);std::vector<map_marker*> at_pos= env.markers.get_markers_at(pos);for (unsigned int i = 0; i < at_pos.size(); i++){map_marker *marker = at_pos[i];if (marker == NULL){mprf(MSGCH_ERROR, "Marker #%d at (%d, %d) NULL",i, x, y);continue;}if (marker->pos != pos){mprf(MSGCH_ERROR, "Marker #%d, type %d at (%d, %d) ""thinks it's at (%d, %d)",i, (int) marker->get_type(), x, y,marker->pos.x, marker->pos.y);if (!in_bounds(marker->pos))mpr("Further, it thinks it's out of bounds.",MSGCH_ERROR);}}}} // _debug_marker_scan()static void _debug_dump_markers(){std::vector<map_marker*> markers = env.markers.get_all();for (unsigned int i = 0; i < markers.size(); i++){map_marker* marker = markers[i];if (marker == NULL || marker->get_type() == MAT_LUA_MARKER)continue;mprf(MSGCH_DIAGNOSTICS, "Marker %d at (%d, %d): %s",i, marker->pos.x, marker->pos.y,marker->debug_describe().c_str());}} // _debug_dump_markers()static void _debug_dump_lua_markers(){std::vector<map_marker*> markers = env.markers.get_all();for (unsigned int i = 0; i < markers.size(); i++){map_marker* marker = markers[i];if (marker == NULL || marker->get_type() != MAT_LUA_MARKER)continue;map_lua_marker* lua_marker = dynamic_cast<map_lua_marker*>(marker);std::string result = lua_marker->debug_to_string();if (result.size() > 0 && result[result.size() - 1] == '\n')result = result.substr(0, result.size() - 1);mprf(MSGCH_DIAGNOSTICS, "Lua marker %d at (%d, %d):",i, marker->pos.x, marker->pos.y);mprf(MSGCH_DIAGNOSTICS, "{{{{");mprf(MSGCH_DIAGNOSTICS, result.c_str());mprf(MSGCH_DIAGNOSTICS, "}}}}");}
static void _debug_dump_lua_persist(){lua_stack_cleaner cln(dlua);std::string result;if (!dlua.callfn("persist_to_string", 0, 1))result = make_stringf("error (persist_to_string): %s",dlua.error.c_str());else if (lua_isstring(dlua, -1))result = lua_tostring(dlua, -1);elseresult = "persist_to_string() returned nothing";mprf(MSGCH_DIAGNOSTICS, "%s", result.c_str());}
// Dumping information on marker inconsistancy is unlikely to crash,// as is dumping the descriptions of non-Lua markers.fprintf(file, "Markers:" EOL);fprintf(file, "<<<<<<<<<<<<<<<<<<<<<<" EOL);_debug_marker_scan();_debug_dump_markers();fprintf(file, ">>>>>>>>>>>>>>>>>>>>>>" EOL);
// Lastly try to dump the Lua persistant data and the contents of the Lua// markers, since actually running Lua code has the greatest chance of// crashing.fprintf(file, "Lua persistant data:" EOL);fprintf(file, "<<<<<<<<<<<<<<<<<<<<<<" EOL);_debug_dump_lua_persist();fprintf(file, ">>>>>>>>>>>>>>>>>>>>>>" EOL EOL);fprintf(file, "Lua marker contents:" EOL);fprintf(file, "<<<<<<<<<<<<<<<<<<<<<<" EOL);_debug_dump_lua_markers();fprintf(file, ">>>>>>>>>>>>>>>>>>>>>>" EOL);
end
end-- Turn contents of a table into a human readable stringfunction table_to_string(table, depth)depth = depth or 0local indent = string.rep(" ", depth * 4)local str = ""for key, value in pairs(table) dostr = str .. indent .. key .. ": "if type(value) == "table" thenstr = str .. "\n" .. table_to_string(value, depth + 1)elseif type(value) == "function" thenstr = str .. "function"elsestr = str .. valueendstr = str .. "\n"endreturn strend