aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/EntityManager.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-11-24 12:58:41 +0000
committerAdam Frisby2008-11-24 12:58:41 +0000
commiteb8650fc14c960520848bc3e215eb90d74f2041d (patch)
tree1abf96ffc135f88a7f4f1c4ad304d71e356a2b61 /OpenSim/Region/Environment/Scenes/EntityManager.cs
parentSome refactoring from about a week ago that I forgot to commit, of AssetTrans... (diff)
downloadopensim-SC_OLD-eb8650fc14c960520848bc3e215eb90d74f2041d.zip
opensim-SC_OLD-eb8650fc14c960520848bc3e215eb90d74f2041d.tar.gz
opensim-SC_OLD-eb8650fc14c960520848bc3e215eb90d74f2041d.tar.bz2
opensim-SC_OLD-eb8650fc14c960520848bc3e215eb90d74f2041d.tar.xz
* Adding EntityManager.cs
* Not referenced anywhere yet. * Designed to replace Dictionary<UUID,EntityBase> within SceneGraph.Entities * Allows indexed access and better handling of locks. * Someone needs to implement IEnumerable on this before we can switch it over.
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/EntityManager.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/EntityManager.cs148
1 files changed, 148 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/EntityManager.cs b/OpenSim/Region/Environment/Scenes/EntityManager.cs
new file mode 100644
index 0000000..f515cba
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/EntityManager.cs
@@ -0,0 +1,148 @@
1using System;
2using System.Collections.Generic;
3using OpenMetaverse;
4
5namespace OpenSim.Region.Environment.Scenes
6{
7 public class EntityManager
8 {
9 private readonly Dictionary<UUID,EntityBase> m_eb_uuid = new Dictionary<UUID, EntityBase>();
10 private readonly Dictionary<uint, EntityBase> m_eb_localID = new Dictionary<uint, EntityBase>();
11 private readonly Object m_lock = new Object();
12
13 [Obsolete("Use Add() instead.")]
14 public void Add(UUID id, EntityBase eb)
15 {
16 Add(eb);
17 }
18
19 public void Add(EntityBase entity)
20 {
21 lock(m_lock)
22 {
23 m_eb_uuid.Add(entity.UUID, entity);
24 m_eb_localID.Add(entity.LocalId, entity);
25 }
26 }
27
28 public void InsertOrReplace(EntityBase entity)
29 {
30 lock(m_lock)
31 {
32 m_eb_uuid[entity.UUID] = entity;
33 m_eb_localID[entity.LocalId] = entity;
34 }
35 }
36
37 public void Clear()
38 {
39 lock (m_lock)
40 {
41 m_eb_uuid.Clear();
42 m_eb_localID.Clear();
43 }
44 }
45
46 public int Count
47 {
48 get
49 {
50 lock (m_lock)
51 {
52 return m_eb_uuid.Count;
53 }
54 }
55 }
56
57 public bool ContainsKey(UUID id)
58 {
59 lock(m_lock)
60 {
61 return m_eb_uuid.ContainsKey(id);
62 }
63 }
64
65 public bool ContainsKey(uint localID)
66 {
67 lock (m_lock)
68 {
69 return m_eb_localID.ContainsKey(localID);
70 }
71 }
72
73 public void Remove(uint localID)
74 {
75 lock(m_lock)
76 {
77 m_eb_uuid.Remove(m_eb_localID[localID].UUID);
78 m_eb_localID.Remove(localID);
79 }
80 }
81
82 public void Remove(UUID id)
83 {
84 lock(m_lock)
85 {
86 m_eb_localID.Remove(m_eb_uuid[id].LocalId);
87 m_eb_uuid.Remove(id);
88 }
89 }
90
91 public List<EntityBase> GetAllByType<T>()
92 {
93 List<EntityBase> tmp = new List<EntityBase>();
94
95 lock(m_lock)
96 {
97 foreach (KeyValuePair<UUID, EntityBase> pair in m_eb_uuid)
98 {
99 if(pair.Value is T)
100 {
101 tmp.Add(pair.Value);
102 }
103 }
104 }
105
106 return tmp;
107 }
108
109 [Obsolete("Please used indexed access to this instead. Indexes can be accessed via EntitiesManager[index]. LocalID and UUID are supported.")]
110 public List<EntityBase> GetEntities()
111 {
112 lock (m_lock)
113 {
114 return new List<EntityBase>(m_eb_uuid.Values);
115 }
116 }
117
118 public EntityBase this[UUID id]
119 {
120 get
121 {
122 lock (m_lock)
123 {
124 return m_eb_uuid[id];
125 }
126 }
127 set
128 {
129 InsertOrReplace(value);
130 }
131 }
132
133 public EntityBase this[uint localID]
134 {
135 get
136 {
137 lock (m_lock)
138 {
139 return m_eb_localID[localID];
140 }
141 }
142 set
143 {
144 InsertOrReplace(value);
145 }
146 }
147 }
148}