Track logged in state and nearby avatars

This commit is contained in:
Blake Bourque
2015-06-24 23:39:41 -04:00
parent 929b374df9
commit fe33131322
3 changed files with 91 additions and 6 deletions
@@ -51,9 +51,6 @@ namespace PlexView
msg.Add("sessionID", logout.sessionID);
return msg;
}
};
}
}
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using OpenMetaverse;
namespace PlexView
{
public class NearbyAvatarTracker
{
private User user;
private Dictionary<uint, Avatar> nearbyAvatars = new Dictionary<uint, Avatar>();
public NearbyAvatarTracker(User user)
{
this.user = user;
this.user.Objects.AvatarUpdate += new EventHandler<AvatarUpdateEventArgs>(Objects_AvatarUpdate);
this.user.Objects.KillObject += new EventHandler<KillObjectEventArgs>(Objects_KillObject);
this.user.Self.TeleportProgress += new EventHandler<TeleportEventArgs>(Self_TeleportProgress);
this.user.Objects.ObjectUpdate += new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
}
public Dictionary<uint, Avatar> 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
}
}
+11 -3
View File
@@ -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;
}
}
}