]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a versioning system for bot waypoint files: outdated links are now automatically...
authorterencehill <piuntn@gmail.com>
Sat, 19 Aug 2017 13:29:12 +0000 (15:29 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 19 Aug 2017 13:29:12 +0000 (15:29 +0200)
qcsrc/server/bot/default/waypoints.qc
qcsrc/server/bot/default/waypoints.qh

index 6e872d2bec418439f7b80bc9ba880eb4a7d78a16..18379340656e740a8d09beed04ed2bc17d989aaa 100644 (file)
@@ -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)
index 6eab8a4d5bffc14ab0f61c2b1d18ab9b52d22f6f..d3cb3a4e311fffcc5c3fe52ed57f4a16087d1be1 100644 (file)
@@ -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;