r6060 - in trunk/data/qcsrc: common server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Mar 6 08:21:14 EST 2009
Author: div0
Date: 2009-03-06 08:21:12 -0500 (Fri, 06 Mar 2009)
New Revision: 6060
Modified:
trunk/data/qcsrc/common/gamecommand.qc
trunk/data/qcsrc/common/util.qc
trunk/data/qcsrc/common/util.qh
trunk/data/qcsrc/server/g_world.qc
Log:
use less temp strings for shuffling, should work safely again
Modified: trunk/data/qcsrc/common/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/common/gamecommand.qc 2009-03-06 11:45:27 UTC (rev 6059)
+++ trunk/data/qcsrc/common/gamecommand.qc 2009-03-06 13:21:12 UTC (rev 6060)
@@ -80,6 +80,7 @@
print(" maplist add map\n");
print(" maplist remove map\n");
print(" maplist shuffle\n");
+ print(" maplist cleanup\n");
return TRUE;
}
@@ -107,22 +108,14 @@
s2 = "";
for(i = 0; i < n; ++i)
if(argv(i) != s)
- {
s2 = strcat(s2, " ", argv(i));
- }
s2 = substring(s2, 1, strlen(s2) - 1);
cvar_set("g_maplist", s2);
return TRUE;
}
else if(argv(1) == "shuffle" && argc == 2)
{
- n = tokenizebyseparator(cvar_string("g_maplist"), " ");
- shufflearray_build(n);
- s2 = "";
- for(i = 0; i < n; ++i)
- s2 = strcat(s2, " ", argv(shufflearray[i]));
- s = substring(s2, 1, strlen(s2) - 1);
- cvar_set("g_maplist", s);
+ cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
return TRUE;
}
else if(argv(1) == "cleanup")
Modified: trunk/data/qcsrc/common/util.qc
===================================================================
--- trunk/data/qcsrc/common/util.qc 2009-03-06 11:45:27 UTC (rev 6059)
+++ trunk/data/qcsrc/common/util.qc 2009-03-06 13:21:12 UTC (rev 6060)
@@ -1515,26 +1515,40 @@
// q.e.d.
j = floor(random() * (i + 1));
if(j != i)
- swap(i, j);
+ swap(j, i);
}
}
-void shufflearray_init(float n)
+string substring_range(string s, float b, float e)
{
- float i;
- for(i = 0; i < n; ++i)
- shufflearray[i] = i;
+ return substring(s, b, e - b);
}
-void shufflearray_swap(float i, float j)
+
+string swapwords(string str, float i, float j)
{
- float h;
- h = shufflearray[i];
- shufflearray[i] = shufflearray[j];
- shufflearray[j] = h;
+ float n;
+ string s1, s2, s3, s4, s5;
+ n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle"
+ s1 = substring_range(str, argv_start_index(0), argv_start_index(i));
+ s2 = substring_range(str, argv_start_index(i), argv_end_index(i));
+ s3 = substring_range(str, argv_end_index(i), argv_start_index(j));
+ s4 = substring_range(str, argv_start_index(j), argv_end_index(j));
+ s5 = substring_range(str, argv_end_index(j), argv_end_index(n));
+ return strcat(s1, s4, s3, s2, s5);
}
-void shufflearray_build(float n)
+string _shufflewords_str;
+void _shufflewords_swapfunc(float i, float j)
{
- shufflearray_init(n);
- shuffle(n, shufflearray_swap);
+ _shufflewords_str = swapwords(_shufflewords_str, i, j);
}
+string shufflewords(string str)
+{
+ float n;
+ _shufflewords_str = str;
+ n = tokenizebyseparator(str, " ");
+ shuffle(n, _shufflewords_swapfunc);
+ str = _shufflewords_str;
+ _shufflewords_str = string_null;
+ return str;
+}
Modified: trunk/data/qcsrc/common/util.qh
===================================================================
--- trunk/data/qcsrc/common/util.qh 2009-03-06 11:45:27 UTC (rev 6059)
+++ trunk/data/qcsrc/common/util.qh 2009-03-06 13:21:12 UTC (rev 6060)
@@ -153,8 +153,10 @@
float isGametypeInFilter(float gt, float tp, string pattern);
-typedef void(float i1, float i2) shuffle_swapfunc_t;
+typedef void(float i1, float i2) shuffle_swapfunc_t; // is only ever called for i1 < i2
void shuffle(float n, shuffle_swapfunc_t swap);
-float shufflearray[1024];
-void shufflearray_build(float n);
+string swapwords(string str, float i, float j);
+string shufflewords(string str);
+
+string substring_range(string s, float b, float e);
Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc 2009-03-06 11:45:27 UTC (rev 6059)
+++ trunk/data/qcsrc/server/g_world.qc 2009-03-06 13:21:12 UTC (rev 6060)
@@ -1625,16 +1625,7 @@
void ShuffleMaplist()
{
- float n, i;
- string s, s2;
-
- n = tokenizebyseparator(cvar_string("g_maplist"), " ");
- shufflearray_build(n);
- s2 = "";
- for(i = 0; i < n; ++i)
- s2 = strcat(s2, " ", argv(shufflearray[i]));
- s = substring(s2, 1, strlen(s2) - 1);
- cvar_set("g_maplist", s);
+ cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
}
float leaderfrags;
More information about the nexuiz-commits
mailing list