diff --git a/Programs/examples/PlexView/api/UserMod.cs b/Programs/examples/PlexView/api/UserMod.cs index c9464c6..258c13e 100644 --- a/Programs/examples/PlexView/api/UserMod.cs +++ b/Programs/examples/PlexView/api/UserMod.cs @@ -51,9 +51,6 @@ namespace PlexView msg.Add("sessionID", logout.sessionID); return msg; } - - - }; } } diff --git a/Programs/examples/PlexView/modules/NearbyAvatarTracker.cs b/Programs/examples/PlexView/modules/NearbyAvatarTracker.cs new file mode 100644 index 0000000..fc6dd84 --- /dev/null +++ b/Programs/examples/PlexView/modules/NearbyAvatarTracker.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using OpenMetaverse; + +namespace PlexView +{ + public class NearbyAvatarTracker + { + private User user; + private Dictionary nearbyAvatars = new Dictionary(); + + public NearbyAvatarTracker(User user) + { + this.user = user; + this.user.Objects.AvatarUpdate += new EventHandler(Objects_AvatarUpdate); + this.user.Objects.KillObject += new EventHandler(Objects_KillObject); + this.user.Self.TeleportProgress += new EventHandler(Self_TeleportProgress); + this.user.Objects.ObjectUpdate += new EventHandler(Objects_ObjectUpdate); + } + + public Dictionary GetNearbyAvatars() + { + return nearbyAvatars; + } + + #region eventHandlers + + void Self_TeleportProgress(object sender, TeleportEventArgs e) + { + if (e.Status == TeleportStatus.Finished) + { + this.nearbyAvatars.Clear(); + } + } + + void Objects_AvatarUpdate(object sender, AvatarUpdateEventArgs e) + { + // Check if we already know about this avatar. If not, add it and announce the callback. + // Otherwise just update the cache with the new information (e.g. changed position) + if (!this.nearbyAvatars.ContainsKey(e.Avatar.LocalID)) + { + lock(this.nearbyAvatars) this.nearbyAvatars.Add(e.Avatar.LocalID, e.Avatar); + //@todo trigger avatar added event + } + else + { + lock(this.nearbyAvatars) this.nearbyAvatars[e.Avatar.LocalID] = e.Avatar; + } + } + + void Objects_ObjectUpdate(object sender, PrimEventArgs e) + { + // If we know of this avatar, update its position and rotation, and send an AvatarUpdated callback. + if (this.nearbyAvatars.ContainsKey(e.Prim.LocalID)) + { + Avatar avatar; + lock (this.nearbyAvatars) avatar = this.nearbyAvatars[e.Prim.LocalID]; + avatar.Position = e.Prim.Position; + avatar.Rotation = e.Prim.Rotation; + } + } + + void Objects_KillObject(object sender, KillObjectEventArgs e) + { + // If we know of this avatar, remove it and announce its loss. + lock (this.nearbyAvatars) + { + if (nearbyAvatars.ContainsKey(e.ObjectLocalID)) + { + Avatar avatar = this.nearbyAvatars[e.ObjectLocalID]; + this.nearbyAvatars.Remove(e.ObjectLocalID); + //@todo trigger avatar removed event + } + } + } + + #endregion + } +} + diff --git a/Programs/examples/PlexView/types/User.cs b/Programs/examples/PlexView/types/User.cs index 2bc49f8..70224c2 100644 --- a/Programs/examples/PlexView/types/User.cs +++ b/Programs/examples/PlexView/types/User.cs @@ -40,6 +40,10 @@ namespace PlexView public readonly Guid sessionID; public readonly Creds creds; + private bool m_loggedIn = false; + + private NearbyAvatarTracker tracker; + //@todo Instances of the client class should only be created by the ClientMgr public User(Creds creds) { @@ -61,6 +65,7 @@ namespace PlexView sessionID = Guid.NewGuid(); Settings.LOGIN_SERVER = creds.gridURL; this.creds = creds; + tracker = new NearbyAvatarTracker(this); } public void BeginLogin() { @@ -71,6 +76,7 @@ namespace PlexView { //@todo login successfull Console.WriteLine ("Login Success for user "+GetAvatarName()); + this.m_loggedIn = true; //send e.Message } else if (e.Status == LoginStatus.Failed) @@ -78,6 +84,7 @@ namespace PlexView //@todo login failure Console.WriteLine ("Login Failure"); //send e.FailReason + this.m_loggedIn = false; } }; @@ -103,8 +110,9 @@ namespace PlexView } } -// public bool IsLoggedIn() -// { -// } + public bool IsLoggedIn() + { + return m_loggedIn; + } } }