From: terencehill Date: Sat, 19 Aug 2017 13:29:12 +0000 (+0200) Subject: Add a versioning system for bot waypoint files: outdated links are now automatically... X-Git-Tag: xonotic-v0.8.5~2378^2~81 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d7268cf0a27efc50a4cab0717a9a3a4969c38c11;p=xonotic%2Fxonotic-data.pk3dir.git Add a versioning system for bot waypoint files: outdated links are now automatically updated and saved on map start --- diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 6e872d2be..183793406 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -701,8 +701,27 @@ bool waypoint_load_links() return false; } + bool parse_comments = true; + float ver = 0; + while ((s = fgets(file))) { + if(parse_comments) + { + if(substring(s, 0, 2) == "//") + { + if(substring(s, 2, 8) == "VERSION ") + ver = stof(substring(s, 10, -1)); + continue; + } + else + { + if(ver < WAYPOINT_VERSION) + return false; + parse_comments = false; + } + } + tokens = tokenizebyseparator(s, "*"); if (tokens!=2) @@ -925,6 +944,8 @@ void waypoint_save_links() return; } + fputs(file, strcat("//", "VERSION ", ftos_decimals(WAYPOINT_VERSION, 2), "\n")); + int c = 0; IL_EACH(g_waypoints, true, { @@ -961,6 +982,12 @@ void waypoint_saveall() return; } + // add 3 comments to not break compatibility with older Xonotic versions + // (they are read as a waypoint with origin '0 0 0' and flag 0 though) + fputs(file, strcat("//", "VERSION ", ftos_decimals(WAYPOINT_VERSION, 2), "\n")); + fputs(file, strcat("//", "\n")); + fputs(file, strcat("//", "\n")); + int c = 0; IL_EACH(g_waypoints, true, { @@ -995,6 +1022,9 @@ float waypoint_loadall() filename = strcat(filename, ".waypoints"); file = fopen(filename, FILE_READ); + bool parse_comments = true; + float ver = 0; + if (file < 0) { LOG_TRACE("waypoint load from ", filename, " failed"); @@ -1003,6 +1033,21 @@ float waypoint_loadall() while ((s = fgets(file))) { + if(parse_comments) + { + if(substring(s, 0, 2) == "//") + { + if(substring(s, 2, 8) == "VERSION ") + ver = stof(substring(s, 10, -1)); + continue; + } + else + { + if(floor(ver) < floor(WAYPOINT_VERSION)) + LOG_TRACE("waypoints for this map are outdated"); + parse_comments = false; + } + } m1 = stov(s); s = fgets(file); if (!s) diff --git a/qcsrc/server/bot/default/waypoints.qh b/qcsrc/server/bot/default/waypoints.qh index 6eab8a4d5..d3cb3a4e3 100644 --- a/qcsrc/server/bot/default/waypoints.qh +++ b/qcsrc/server/bot/default/waypoints.qh @@ -3,6 +3,11 @@ * Globals and Fields */ +// increase by 0.01 when changes require only waypoint relinking +// increase by 1 when changes require to manually edit waypoints +// max 2 decimal places, always specified +#define WAYPOINT_VERSION 1.00 + // fields you can query using prvm_global server to get some statistics about waypoint linking culling float relink_total, relink_walkculled, relink_pvsculled, relink_lengthculled;