From d44fd1ee4e89d1e957673ecad2070fd2c4263b22 Mon Sep 17 00:00:00 2001 From: Michael Cortez Date: Wed, 1 Nov 2006 20:33:15 +0000 Subject: [PATCH] + AvatarManager & ObjectManager no longer assume each avatar seen is a new avatar, at least for ObjectUpdatePackets -- the other object packets still need to check for existing avatars before adding new ones. + Added back in KakaduWrap because the jasper wrapper doesn't support TGA/TIFF to J2C (yet) -- so it's needed for uploads git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@461 52acb1d6-8a22-11de-b505-999d5b087335 --- libsecondlife-cs/AvatarManager.cs | 13 ++ libsecondlife-cs/ObjectManager.cs | 21 ++- .../examples/IA_ImageTool/IA_ImageTool.csproj | 2 +- .../examples/IA_ImageTool/ImageTool.cs | 2 + .../examples/IA_ImageTool/KakaduWrap.cs | 151 ++++++++++++++++++ 5 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 libsecondlife-cs/examples/IA_ImageTool/KakaduWrap.cs diff --git a/libsecondlife-cs/AvatarManager.cs b/libsecondlife-cs/AvatarManager.cs index 8f6a05a9..80b7e0b0 100644 --- a/libsecondlife-cs/AvatarManager.cs +++ b/libsecondlife-cs/AvatarManager.cs @@ -97,6 +97,19 @@ namespace libsecondlife return Avatars.ContainsKey(id); } + public Avatar GetAvatar(LLUUID id) + { + + if (Contains(id)) + { + return Avatars[id]; + } + else + { + return null; + } + } + /// /// This function will only check if the avatar name exists locally, /// it will not do any networking calls to fetch the name diff --git a/libsecondlife-cs/ObjectManager.cs b/libsecondlife-cs/ObjectManager.cs index 00f96e7f..06ded026 100644 --- a/libsecondlife-cs/ObjectManager.cs +++ b/libsecondlife-cs/ObjectManager.cs @@ -303,8 +303,18 @@ namespace libsecondlife } else if (block.ObjectData.Length == 76) { - // New avatar spotted - Avatar avatar = new Avatar(); + Avatar avatar; + + if (Client.Avatars.Contains(block.FullID)) + { + avatar = Client.Avatars.GetAvatar(block.FullID); + } + else + { + // New avatar spotted + avatar = new Avatar(); + } + string FirstName = ""; string LastName = ""; string GroupName = ""; @@ -335,7 +345,10 @@ namespace libsecondlife } else { - Client.Avatars.AddAvatar(avatar); + if (Client.Avatars.Contains(avatar.ID) == false) + { + Client.Avatars.AddAvatar(avatar); + } if (OnNewAvatar != null) { @@ -429,6 +442,8 @@ namespace libsecondlife Client.Self.Rotation = Rotation; } + //TODO: Should check Client.Avatars.Contains() to see if this avatar is already being tracked, and update as nessesary. + AvatarUpdate avupdate = new AvatarUpdate(); avupdate.LocalID = localid; avupdate.State = state; diff --git a/libsecondlife-cs/examples/IA_ImageTool/IA_ImageTool.csproj b/libsecondlife-cs/examples/IA_ImageTool/IA_ImageTool.csproj index 303cb348..7e8fb464 100644 --- a/libsecondlife-cs/examples/IA_ImageTool/IA_ImageTool.csproj +++ b/libsecondlife-cs/examples/IA_ImageTool/IA_ImageTool.csproj @@ -35,8 +35,8 @@ + - diff --git a/libsecondlife-cs/examples/IA_ImageTool/ImageTool.cs b/libsecondlife-cs/examples/IA_ImageTool/ImageTool.cs index fcd1b933..1f2df730 100644 --- a/libsecondlife-cs/examples/IA_ImageTool/ImageTool.cs +++ b/libsecondlife-cs/examples/IA_ImageTool/ImageTool.cs @@ -89,6 +89,8 @@ namespace IA_ImageTool { if (_Put) { + + Console.WriteLine("Reading: " + _FileName); byte[] j2cdata = KakaduWrap.ReadJ2CData(_FileName); diff --git a/libsecondlife-cs/examples/IA_ImageTool/KakaduWrap.cs b/libsecondlife-cs/examples/IA_ImageTool/KakaduWrap.cs new file mode 100644 index 00000000..444c8f3a --- /dev/null +++ b/libsecondlife-cs/examples/IA_ImageTool/KakaduWrap.cs @@ -0,0 +1,151 @@ +using System; +using System.IO; +using System.Diagnostics; + +namespace IA_ImageTool +{ + /// + /// Summary description for ImageTools. + /// + public class KakaduWrap + { + private KakaduWrap() + { + } + + public static bool Check4Tools() + { + bool status = true; + /* + if( File.Exists("kdu_expand.exe") == false ) + { + status = false; + Console.WriteLine("You need kdu_expand.exe to save SL images."); + } + */ + if( File.Exists("kdu_compress.exe") == false ) + { + status = false; + Console.WriteLine("You need kdu_compress.exe to load images into SL."); + } + + return status; + } + + public static void WriteJ2CToFile( string j2c_filename, byte[] J2CData ) + { + FileStream fs = System.IO.File.OpenWrite( j2c_filename ); + fs.Write(J2CData, 0, J2CData.Length); + fs.Close(); + } + + + public static void Convert2Tiff(string j2c_filename, string tif_filename) + { + if (File.Exists("kdu_expand.exe") == false) + { + throw new Exception("You must have kdu_expand.exe"); + } + + if (tif_filename.ToLower().EndsWith(".tif") == false) + { + tif_filename += ".tif"; + } + + string args = "-i " + j2c_filename + " -o " + tif_filename; + Console.WriteLine(args); + + Process p = new Process(); + p.StartInfo.UseShellExecute = false; + p.StartInfo.FileName = "kdu_expand.exe"; + p.StartInfo.Arguments = args; + p.Start(); + p.WaitForExit(); + } + + public static void Convert2Bmp(string j2c_filename, string bmp_filename) + { + if (File.Exists("kdu_expand.exe") == false) + { + throw new Exception("You must have kdu_expand.exe"); + } + + if (bmp_filename.ToLower().EndsWith(".bmp") == false) + { + bmp_filename += ".bmp"; + } + + string args = "-i " + j2c_filename + " -o " + bmp_filename; + Console.WriteLine(args); + + Process p = new Process(); + p.StartInfo.UseShellExecute = false; + p.StartInfo.FileName = "kdu_expand.exe"; + p.StartInfo.Arguments = args; + p.Start(); + p.WaitForExit(); + } + + public static void WriteJ2CAsTiff(string tif_filename, byte[] J2CData) + { + String tempname = tif_filename + ".j2c"; + WriteJ2CToFile( tempname, J2CData ); + Convert2Tiff( tempname, tif_filename ); + File.Delete( tempname ); + } + + public static void WriteJ2CAsBmp(string bmp_filename, byte[] J2CData) + { + String tempname = bmp_filename + ".j2c"; + WriteJ2CToFile(tempname, J2CData); + Convert2Bmp(tempname, bmp_filename); + File.Delete(tempname); + } + + /* + * kdu_compress -no_info -no_weights -no_palette -i TestTexture.tif -o TestTexture.J2C + */ + public static void Convert2J2C( string tif_filename, string j2c_filename ) + { + if( File.Exists("kdu_compress.exe") == false ) + { + throw new Exception("You must have kdu_compress.exe"); + } + + if( j2c_filename.ToLower().EndsWith(".j2c") == false ) + { + j2c_filename += ".j2c"; + } + + Process p = new Process(); + p.StartInfo.UseShellExecute = false; + p.StartInfo.FileName = "kdu_compress.exe"; + p.StartInfo.Arguments = "-no_info -no_weights -no_palette -i " + tif_filename + " -o " + j2c_filename; + p.Start(); + p.WaitForExit(); + } + + public static byte[] ReadJ2CData( string filename ) + { + if( (filename.ToLower().EndsWith(".j2c") == false) && (filename.ToLower().EndsWith(".tif") == true) ) + { + string tempname = filename + ".j2c"; + Convert2J2C( filename, tempname ); + filename = tempname; + } + + FileStream fs = File.OpenRead( filename ); + + byte[] data = new byte[fs.Length]; + + if( fs.Length > int.MaxValue ) + { + throw new Exception("AssetImage.cs: Bad stuff going to happen because length bigger then Max Integer"); + } + + fs.Read(data, 0, (int)fs.Length); + + return data; + } + } +}