]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Check for negative values returned by search_begin searching for waypoints frames
authorterencehill <piuntn@gmail.com>
Tue, 22 Mar 2011 18:30:55 +0000 (19:30 +0100)
committerterencehill <piuntn@gmail.com>
Tue, 22 Mar 2011 18:30:55 +0000 (19:30 +0100)
Also add a function to load waypoints frames of a specific extension to avoid code duplication

Actually, previous code is changed with the addition of the check for dh and of the variable ext_len

qcsrc/client/waypointsprites.qc

index 8ecadaeb857f72f4745a33b2cd3d2748e774a388..bcd8c433e07b185d3eb997f60d976daee526b2d2 100644 (file)
@@ -406,6 +406,29 @@ void Ent_WaypointSprite()
        self.entremove = Ent_RemoveWaypointSprite;
 }
 
+void WaypointSprite_Load_Frames(string ext)
+{
+       float dh, n, i, o, f;
+       string s, sname, sframes;
+       dh = search_begin(strcat("models/sprites/*_frame*", ext), FALSE, FALSE);
+       if (dh < 0)
+                return;
+       float ext_len = strlen(ext);
+       n = search_getsize(dh);
+       for(i = 0; i < n; ++i)
+       {
+               s = search_getfilename(dh, i);
+               s = substring(s, 15, strlen(s) - 15 - ext_len); // strip models/sprites/ and extension
+
+               o = strstrofs(s, "_frame", 0);
+               sname = strcat("/spriteframes/", substring(s, 0, o));
+               sframes = substring(s, o + 6, strlen(s) - o - 6);
+               f = stof(sframes) + 1;
+               db_put(tempdb, sname, ftos(max(f, stof(db_get(tempdb, sname)))));
+       }
+       search_end(dh);
+}
+
 void WaypointSprite_Load()
 {
        waypointsprite_fadedistance = vlen(mi_scale);
@@ -428,38 +451,8 @@ void WaypointSprite_Load()
 
        if(!waypointsprite_initialized)
        {
-               float dh, n, i, o, f;
-               string s, sname, sframes;
-
-               dh = search_begin("models/sprites/*_frame*.tga", FALSE, FALSE);
-               n = search_getsize(dh);
-               for(i = 0; i < n; ++i)
-               {
-                       s = search_getfilename(dh, i);
-                       s = substring(s, 15, strlen(s) - 15 - 4); // strip models/sprites/ and .tga
-
-                       o = strstrofs(s, "_frame", 0);
-                       sname = strcat("/spriteframes/", substring(s, 0, o));
-                       sframes = substring(s, o + 6, strlen(s) - o - 6);
-                       f = stof(sframes) + 1;
-                       db_put(tempdb, sname, ftos(max(f, stof(db_get(tempdb, sname)))));
-               }
-               search_end(dh);
-
-               dh = search_begin("models/sprites/*_frame*.jpg", FALSE, FALSE);
-               n = search_getsize(dh);
-               for(i = 0; i < n; ++i)
-               {
-                       s = search_getfilename(dh, i);
-                       s = substring(s, 15, strlen(s) - 15 - 4); // strip models/sprites/ and .jpg
-
-                       o = strstrofs(s, "_frame", 0);
-                       sname = strcat("/spriteframes/", substring(s, 0, o));
-                       sframes = substring(s, o + 6, strlen(s) - o - 6);
-                       f = stof(sframes) + 1;
-                       db_put(tempdb, sname, ftos(max(f, stof(db_get(tempdb, sname)))));
-               }
-               search_end(dh);
+               WaypointSprite_Load_Frames(".tga");
+               WaypointSprite_Load_Frames(".jpg");
                waypointsprite_initialized = true;
        }
 }