aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/lscript/lscript_library
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/lscript/lscript_library')
-rw-r--r--linden/indra/lscript/lscript_library/lscript_alloc.cpp59
-rw-r--r--linden/indra/lscript/lscript_library/lscript_library.cpp2
-rw-r--r--linden/indra/lscript/lscript_library/lscript_library.vcproj6
3 files changed, 63 insertions, 4 deletions
diff --git a/linden/indra/lscript/lscript_library/lscript_alloc.cpp b/linden/indra/lscript/lscript_library/lscript_alloc.cpp
index 978d7f2..4636c0b 100644
--- a/linden/indra/lscript/lscript_library/lscript_alloc.cpp
+++ b/linden/indra/lscript/lscript_library/lscript_alloc.cpp
@@ -1119,3 +1119,62 @@ S32 lsa_postadd_lists(U8 *buffer, S32 offset1, LLScriptLibData *data, S32 heapsi
1119 return lsa_heap_add_data(buffer, list1, heapsize, TRUE); 1119 return lsa_heap_add_data(buffer, list1, heapsize, TRUE);
1120} 1120}
1121 1121
1122
1123LLScriptLibData* lsa_randomize(LLScriptLibData* src, S32 stride)
1124{
1125 S32 number = src->getListLength();
1126 if (number <= 0)
1127 {
1128 return NULL;
1129 }
1130 if (stride <= 0)
1131 {
1132 stride = 1;
1133 }
1134 if(number % stride)
1135 {
1136 LLScriptLibData* retval = src->mListp;
1137 src->mListp = NULL;
1138 return retval;
1139 }
1140 S32 buckets = number / stride;
1141
1142 // Copy everything into a special vector for sorting;
1143 std::vector<LLScriptLibData*> sort_array;
1144 sort_array.reserve(number);
1145 LLScriptLibData* temp = src->mListp;
1146 while(temp)
1147 {
1148 sort_array.push_back(temp);
1149 temp = temp->mListp;
1150 }
1151
1152 // We cannot simply call random_shuffle or similar algorithm since
1153 // we need to obey the stride. So, we iterate over what we have
1154 // and swap each with a random other segment.
1155 S32 index = 0;
1156 S32 ii = 0;
1157 for(; ii < number; ii += stride)
1158 {
1159 index = ll_rand(buckets) * stride;
1160 for(S32 jj = 0; jj < stride; ++jj)
1161 {
1162 std::swap(sort_array[ii + jj], sort_array[index + jj]);
1163 }
1164 }
1165
1166 // copy the pointers back out
1167 ii = 1;
1168 temp = sort_array[0];
1169 while (ii < number)
1170 {
1171 temp->mListp = sort_array[ii++];
1172 temp = temp->mListp;
1173 }
1174 temp->mListp = NULL;
1175
1176 src->mListp = NULL;
1177
1178 LLScriptLibData* ret_value = sort_array[0];
1179 return ret_value;
1180}
diff --git a/linden/indra/lscript/lscript_library/lscript_library.cpp b/linden/indra/lscript/lscript_library/lscript_library.cpp
index 098c836..1b92608 100644
--- a/linden/indra/lscript/lscript_library/lscript_library.cpp
+++ b/linden/indra/lscript/lscript_library/lscript_library.cpp
@@ -467,7 +467,7 @@ LLScriptLibraryFunction::~LLScriptLibraryFunction()
467 467
468void LLScriptLibrary::addFunction(LLScriptLibraryFunction *func) 468void LLScriptLibrary::addFunction(LLScriptLibraryFunction *func)
469{ 469{
470 LLScriptLibraryFunction **temp = (LLScriptLibraryFunction **)new U32[mNextNumber + 1]; 470 LLScriptLibraryFunction **temp = new LLScriptLibraryFunction*[mNextNumber + 1];
471 if (mNextNumber) 471 if (mNextNumber)
472 { 472 {
473 memcpy(temp, mFunctions, sizeof(LLScriptLibraryFunction *)*mNextNumber); 473 memcpy(temp, mFunctions, sizeof(LLScriptLibraryFunction *)*mNextNumber);
diff --git a/linden/indra/lscript/lscript_library/lscript_library.vcproj b/linden/indra/lscript/lscript_library/lscript_library.vcproj
index f4861c7..1a340da 100644
--- a/linden/indra/lscript/lscript_library/lscript_library.vcproj
+++ b/linden/indra/lscript/lscript_library/lscript_library.vcproj
@@ -19,7 +19,7 @@
19 <Tool 19 <Tool
20 Name="VCCLCompilerTool" 20 Name="VCCLCompilerTool"
21 Optimization="0" 21 Optimization="0"
22 AdditionalIncludeDirectories="..;..\..\llcommon;..\..\llmath" 22 AdditionalIncludeDirectories="..\;..\..\llmath;..\..\llcommon;&quot;..\..\..\libraries\i686-win32&quot;;..\..\..\libraries\include"
23 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;LL_DEBUG" 23 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;LL_DEBUG"
24 MinimalRebuild="TRUE" 24 MinimalRebuild="TRUE"
25 BasicRuntimeChecks="3" 25 BasicRuntimeChecks="3"
@@ -63,7 +63,7 @@
63 CharacterSet="1"> 63 CharacterSet="1">
64 <Tool 64 <Tool
65 Name="VCCLCompilerTool" 65 Name="VCCLCompilerTool"
66 AdditionalIncludeDirectories="..;..\..\llcommon;..\..\llmath" 66 AdditionalIncludeDirectories="..\;..\..\llmath;..\..\llcommon;&quot;..\..\..\libraries\i686-win32&quot;;..\..\..\libraries\include"
67 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE" 67 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE"
68 RuntimeLibrary="0" 68 RuntimeLibrary="0"
69 StructMemberAlignment="0" 69 StructMemberAlignment="0"
@@ -106,7 +106,7 @@
106 <Tool 106 <Tool
107 Name="VCCLCompilerTool" 107 Name="VCCLCompilerTool"
108 Optimization="0" 108 Optimization="0"
109 AdditionalIncludeDirectories="..;..\..\llcommon;..\..\llmath" 109 AdditionalIncludeDirectories="..\;..\..\llmath;..\..\llcommon;&quot;..\..\..\libraries\i686-win32&quot;;..\..\..\libraries\include"
110 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE" 110 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE"
111 RuntimeLibrary="0" 111 RuntimeLibrary="0"
112 StructMemberAlignment="0" 112 StructMemberAlignment="0"