From 657cceb8847f94a9af0c8b2358124105d778486c Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Mon, 25 Oct 2010 09:41:08 -0700
Subject: Intermediate commit for backward compatability; does not compile yet

---
 OpenSim/Framework/AgentCircuitData.cs     | 65 ++++++++++++++--------------
 OpenSim/Framework/ChildAgentDataUpdate.cs | 70 ++++++++++++++++++-------------
 2 files changed, 73 insertions(+), 62 deletions(-)

diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs
index be98380..30a9548 100644
--- a/OpenSim/Framework/AgentCircuitData.cs
+++ b/OpenSim/Framework/AgentCircuitData.cs
@@ -206,16 +206,18 @@ namespace OpenSim.Framework
             
             args["service_session_id"] = OSD.FromString(ServiceSessionID);
             args["start_pos"] = OSD.FromString(startpos.ToString());
-            args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
             args["client_ip"] = OSD.FromString(IPAddress);
             args["viewer"] = OSD.FromString(Viewer);
             args["channel"] = OSD.FromString(Channel);
             args["mac"] = OSD.FromString(Mac);
             args["id0"] = OSD.FromString(Id0);
 
-/*
+            // Eventually this code should be deprecated, use full appearance
+            // packing in packed_appearance
             if (Appearance != null)
             {
+                args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
+
                 //System.Console.WriteLine("XXX Before packing Wearables");
                 if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0))
                 {
@@ -230,20 +232,19 @@ namespace OpenSim.Framework
                 }
 
                 //System.Console.WriteLine("XXX Before packing Attachments");
-                Dictionary<int, AvatarAttachment> attachments = Appearance.Attachments;
+                List<AvatarAttachment> attachments = Appearance.GetAttachments();
                 if ((attachments != null) && (attachments.Count > 0))
                 {
                     OSDArray attachs = new OSDArray(attachments.Count);
-                    foreach (KeyValuePair<int, AvatarAttachment> kvp in attachments)
+                    foreach (AvatarAttachment attach in attachments)
                     {
-                        AvatarAttachment adata = new AvatarAttachment(kvp.Value);
-                        attachs.Add(adata.Pack());
+                        attachs.Add(attach.Pack());
                         //System.Console.WriteLine("XXX att.pt=" + kvp.Key + "; itemID=" + kvp.Value[0] + "; assetID=" + kvp.Value[1]);
                     }
                     args["attachments"] = attachs;
                 }
             }
-*/
+
             if (Appearance != null)
             {
                 OSDMap appmap = Appearance.Pack();
@@ -339,27 +340,9 @@ namespace OpenSim.Framework
             try {
             // Unpack various appearance elements                                                                           
             Appearance = new AvatarAppearance(AgentID);
-            if (args["packed_appearance"] != null)
-            {
-                if (args["packed_appearance"].Type == OSDType.Map)
-                {
-                    Appearance.Unpack((OSDMap)args["packed_appearance"]);
-                    m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
-                }
-                else
-                    m_log.WarnFormat("[AGENTCIRCUITDATA] packed_appearance is not a map:\n{0}",args["packed_appearance"].ToString());
-            }
-// DEBUG ON
-            else
-                m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
-// DEBUG OFF
-            } catch (Exception e)
-            {
-                m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
-            }
-            
-            
-/*
+
+            // Eventually this code should be deprecated, use full appearance
+            // packing in packed_appearance
             if (args["appearance_serial"] != null)
                 Appearance.Serial = args["appearance_serial"].AsInteger();
 
@@ -376,18 +359,34 @@ namespace OpenSim.Framework
             if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
             {
                 OSDArray attachs = (OSDArray)(args["attachments"]);
-                AvatarAttachment[] attachments = new AvatarAttachment[attachs.Count];
-                int i = 0;
                 foreach (OSD o in attachs)
                 {
                     if (o.Type == OSDType.Map)
                     {
-                        attachments[i++] = new AvatarAttachment((OSDMap)o);
+                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                     }
                 }
-                Appearance.SetAttachments(attachments);
             }
-*/
+
+            if (args["packed_appearance"] != null)
+            {
+                if (args["packed_appearance"].Type == OSDType.Map)
+                {
+                    Appearance.Unpack((OSDMap)args["packed_appearance"]);
+                    m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
+                }
+                else
+                    m_log.WarnFormat("[AGENTCIRCUITDATA] packed_appearance is not a map:\n{0}",args["packed_appearance"].ToString());
+            }
+// DEBUG ON
+            else
+                m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
+// DEBUG OFF
+            } catch (Exception e)
+            {
+                m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
+            }
+            
             ServiceURLs = new Dictionary<string, object>();
             if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
             {
diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs
index fdebba3..d7a7d1e 100644
--- a/OpenSim/Framework/ChildAgentDataUpdate.cs
+++ b/OpenSim/Framework/ChildAgentDataUpdate.cs
@@ -387,31 +387,37 @@ namespace OpenSim.Framework
             //    args["agent_textures"] = textures;
             //}
 
-/*
-            if ((AgentTextures != null) && (AgentTextures.Length > 0))
-                args["texture_entry"] = OSD.FromBinary(AgentTextures);
+            // The code to pack textures, visuals, wearables and attachments
+            // should be removed; packed appearance contains the full appearance
+            // This is retained for backward compatibility only
+            if ((Appearance.Texture != null) && (Appearance.Texture.Length > 0))
+                args["texture_entry"] = OSD.FromBinary(Appearance.Texture);
 
-            if ((VisualParams != null) && (VisualParams.Length > 0))
-                args["visual_params"] = OSD.FromBinary(VisualParams);
+            if ((Appearance.VisualParams != null) && (Appearance.VisualParams.Length > 0))
+                args["visual_params"] = OSD.FromBinary(Appearance.VisualParams);
 
             // We might not pass this in all cases...
-            if ((Wearables != null) && (Wearables.Length > 0))
+            if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0))
             {
-                OSDArray wears = new OSDArray(Wearables.Length);
-                foreach (UUID uuid in Wearables)
-                    wears.Add(OSD.FromUUID(uuid));
+                OSDArray wears = new OSDArray(Appearance.Wearables.Length * 2);
+                foreach (AvatarWearable awear in Appearance.Wearables)
+                {
+                    wears.Add(OSD.FromUUID(awear.ItemID));
+                    wears.Add(OSD.FromUUID(awear.AssetID));
+                }
                 args["wearables"] = wears;
             }
 
-            
-            if ((Attachments != null) && (Attachments.Length > 0))
+            List<AvatarAttachments> attachments = Appearance.GetAttachments();
+            if ((attachments != null) && (attachments.Length > 0))
             {
-                OSDArray attachs = new OSDArray(Attachments.Length);
-                foreach (AvatarAttachment att in Attachments)
+                OSDArray attachs = new OSDArray(attachments.Length);
+                foreach (AvatarAttachment att in attachments)
                     attachs.Add(att.Pack());
                 args["attachments"] = attachs;
             }
-*/
+            // End of code to remove
+
             if ((Controllers != null) && (Controllers.Length > 0))
             {
                 OSDArray controls = new OSDArray(Controllers.Length);
@@ -547,41 +553,47 @@ namespace OpenSim.Framework
             //        AgentTextures[i++] = o.AsUUID();
             //}
 
-            if (args["packed_appearance"] != null)
-                Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]);
-            else
-                Appearance = new AvatarAppearance(AgentID);
-            
-/*
+
+            Appearance = new AvatarAppearance(AgentID);
+
+            // The code to pack textures, visuals, wearables and attachments
+            // should be removed; packed appearance contains the full appearance
+            // This is retained for backward compatibility only
             if (args["texture_entry"] != null)
-                AgentTextures = args["texture_entry"].AsBinary();
+                Appearance.SetTextureEntries(args["texture_entry"].AsBinary());
 
             if (args["visual_params"] != null)
-                VisualParams = args["visual_params"].AsBinary();
+                Appearance.SetVisualParams(args["visual_params"].AsBinary());
 
             if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
             {
                 OSDArray wears = (OSDArray)(args["wearables"]);
-                Wearables = new UUID[wears.Count];
-                int i = 0;
-                foreach (OSD o in wears)
-                    Wearables[i++] = o.AsUUID();
+                for (int i = 0; i < wears.Count / 2; i++) 
+                {
+                    Appearance.Wearables[i].ItemID = wears[i*2].AsUUID();
+                    Appearance.Wearables[i].AssetID = wears[(i*2)+1].AsUUID();
+                }
             }
 
             if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
             {
                 OSDArray attachs = (OSDArray)(args["attachments"]);
-                Attachments = new AvatarAttachment[attachs.Count];
+                AvatarAttachment[] attachments = new AvatarAttachment[attachs.Count];
                 int i = 0;
                 foreach (OSD o in attachs)
                 {
                     if (o.Type == OSDType.Map)
                     {
-                        Attachments[i++] = new AvatarAttachment((OSDMap)o);
+                        attachments[i++] = new AvatarAttachment((OSDMap)o);
                     }
                 }
+                Appearance.SetAttachments(attachments);
             }
-*/
+            // end of code to remove
+
+            if (args["packed_appearance"] != null)
+                Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]);
+
             if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
             {
                 OSDArray controls = (OSDArray)(args["controllers"]);
-- 
cgit v1.1