From 7cb78d73eb007eddbefb647d56a0e140640a7a9e Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sat, 26 Apr 2008 20:49:38 +0000 Subject: Thank you Melanie for implementing llListSort() in linear and strided modes. --- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 37 +------------ OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 64 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 36 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 1a3b6ce..09be26a 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -2874,42 +2874,7 @@ namespace OpenSim.Region.ScriptEngine.Common public LSL_Types.list llListSort(LSL_Types.list src, int stride, int ascending) { m_host.AddScriptLPS(1); - // SortedList sorted = new SortedList(); - // Add chunks to an array - //int s = stride; - //if (s < 1) - // s = 1; - //int c = 0; - //LSL_Types.list chunk = new LSL_Types.list(); - //string chunkString = String.Empty; - //foreach (string element in src) - //{ - // c++; - // if (c > s) - // { - // sorted.Add(chunkString, chunk); - // chunkString = String.Empty; - // chunk = new LSL_Types.list(); - // c = 0; - // } - // chunk.Add(element); - // chunkString += element.ToString(); - //} - //if (chunk.Count > 0) - // sorted.Add(chunkString, chunk); - - //LSL_Types.list ret = new LSL_Types.list(); - //foreach (LSL_Types.list ls in sorted.Values) - //{ - // ret.AddRange(ls); - //} - - //if (ascending == LSL_BaseClass.TRUE) - // return ret; - //ret.Reverse(); - //return ret; - NotImplemented("llListSort"); - return new LSL_Types.list(); + return src.Sort(stride, ascending); } public int llGetListLength(LSL_Types.list src) diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index ec10157..aed591c 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs @@ -560,6 +560,70 @@ namespace OpenSim.Region.ScriptEngine.Common } } + public list Sort(int stride, int ascending) + { + if(Data.Length == 0) + return new list(); // Don't even bother + + if(stride == 1) // The simple case + { + Object[] ret=new Object[Data.Length]; + + Array.Copy(Data, 0, ret, 0, Data.Length); + + Array.Sort(ret); + + if(ascending == 0) + Array.Reverse(ret); + return new list(ret); + } + + int src=0; + + int len=(Data.Length+stride-1)/stride; + + string[] keys=new string[len]; + Object[][] vals=new Object[len][]; + + int i; + + while(src < Data.Length) + { + Object[] o=new Object[stride]; + + for(i=0;i