diff options
Diffstat (limited to 'src/world')
-rw-r--r-- | src/world/Entity.cs | 5 | ||||
-rw-r--r-- | src/world/Primitive.cs | 110 | ||||
-rw-r--r-- | src/world/World.cs | 115 |
3 files changed, 184 insertions, 46 deletions
diff --git a/src/world/Entity.cs b/src/world/Entity.cs index 147478b..ee4b2e4 100644 --- a/src/world/Entity.cs +++ b/src/world/Entity.cs | |||
@@ -58,5 +58,10 @@ namespace OpenSim.world | |||
58 | 58 | ||
59 | return mesh; | 59 | return mesh; |
60 | } | 60 | } |
61 | |||
62 | public virtual void BackUp() | ||
63 | { | ||
64 | |||
65 | } | ||
61 | } | 66 | } |
62 | } | 67 | } |
diff --git a/src/world/Primitive.cs b/src/world/Primitive.cs index 1fb7142..6029f76 100644 --- a/src/world/Primitive.cs +++ b/src/world/Primitive.cs | |||
@@ -4,6 +4,7 @@ using System.Text; | |||
4 | using OpenSim.types; | 4 | using OpenSim.types; |
5 | using libsecondlife; | 5 | using libsecondlife; |
6 | using libsecondlife.Packets; | 6 | using libsecondlife.Packets; |
7 | using GridInterfaces; | ||
7 | 8 | ||
8 | namespace OpenSim.world | 9 | namespace OpenSim.world |
9 | { | 10 | { |
@@ -15,7 +16,7 @@ namespace OpenSim.world | |||
15 | protected bool newPrimFlag; | 16 | protected bool newPrimFlag; |
16 | protected bool updateFlag; | 17 | protected bool updateFlag; |
17 | protected ObjectUpdatePacket OurPacket; | 18 | protected ObjectUpdatePacket OurPacket; |
18 | 19 | ||
19 | public bool UpdateFlag | 20 | public bool UpdateFlag |
20 | { | 21 | { |
21 | get | 22 | get |
@@ -69,6 +70,14 @@ namespace OpenSim.world | |||
69 | } | 70 | } |
70 | this.updateFlag = false; | 71 | this.updateFlag = false; |
71 | } | 72 | } |
73 | |||
74 | } | ||
75 | |||
76 | public void UpdateClient(OpenSimClient RemoteClient) | ||
77 | { | ||
78 | byte[] pb = this.position.GetBytes(); | ||
79 | Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length); | ||
80 | RemoteClient.OutPacket(OurPacket); | ||
72 | } | 81 | } |
73 | 82 | ||
74 | public void CreateFromPacket( ObjectAddPacket addPacket, LLUUID agentID, uint localID) | 83 | public void CreateFromPacket( ObjectAddPacket addPacket, LLUUID agentID, uint localID) |
@@ -118,8 +127,7 @@ namespace OpenSim.world | |||
118 | //finish off copying rest of shape data | 127 | //finish off copying rest of shape data |
119 | 128 | ||
120 | objupdate.ObjectData[0].ID = (uint)(localID); | 129 | objupdate.ObjectData[0].ID = (uint)(localID); |
121 | objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efefda" + (localID- 702000).ToString("000")); | 130 | objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID- 702000).ToString("00000")); |
122 | |||
123 | objupdate.ObjectData[0].ObjectData = new byte[60]; | 131 | objupdate.ObjectData[0].ObjectData = new byte[60]; |
124 | objupdate.ObjectData[0].ObjectData[46] = 128; | 132 | objupdate.ObjectData[0].ObjectData[46] = 128; |
125 | objupdate.ObjectData[0].ObjectData[47] = 63; | 133 | objupdate.ObjectData[0].ObjectData[47] = 63; |
@@ -135,6 +143,67 @@ namespace OpenSim.world | |||
135 | this.OurPacket = objupdate; | 143 | this.OurPacket = objupdate; |
136 | } | 144 | } |
137 | 145 | ||
146 | public void CreateFromStorage(PrimStorage store) | ||
147 | { | ||
148 | //need to clean this up as it shares a lot of code with CreateFromPacket() | ||
149 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
150 | objupdate.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; | ||
151 | objupdate.RegionData.TimeDilation = 64096; | ||
152 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
153 | |||
154 | this.primData = store.Data; | ||
155 | objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock(); | ||
156 | objupdate.ObjectData[0].PSBlock = new byte[0]; | ||
157 | objupdate.ObjectData[0].ExtraParams = new byte[1]; | ||
158 | objupdate.ObjectData[0].MediaURL = new byte[0]; | ||
159 | objupdate.ObjectData[0].NameValue = new byte[0]; | ||
160 | objupdate.ObjectData[0].PSBlock = new byte[0]; | ||
161 | objupdate.ObjectData[0].Text = new byte[0]; | ||
162 | objupdate.ObjectData[0].TextColor = new byte[4]; | ||
163 | objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0,0,0); | ||
164 | objupdate.ObjectData[0].JointPivot = new LLVector3(0,0,0); | ||
165 | objupdate.ObjectData[0].Material = 3; | ||
166 | objupdate.ObjectData[0].UpdateFlags=32+65536+131072+256+4+8+2048+524288+268435456; | ||
167 | objupdate.ObjectData[0].TextureAnim = new byte[0]; | ||
168 | objupdate.ObjectData[0].Sound = LLUUID.Zero; | ||
169 | LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
170 | objupdate.ObjectData[0].TextureEntry = ntex.ToBytes(); | ||
171 | objupdate.ObjectData[0].State = 0; | ||
172 | objupdate.ObjectData[0].Data = new byte[0]; | ||
173 | objupdate.ObjectData[0].OwnerID = this.primData.OwnerID; | ||
174 | objupdate.ObjectData[0].PCode = this.primData.PCode; | ||
175 | objupdate.ObjectData[0].PathBegin = this.primData.PathBegin; | ||
176 | objupdate.ObjectData[0].PathEnd = this.primData.PathEnd; | ||
177 | objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX; | ||
178 | objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY; | ||
179 | objupdate.ObjectData[0].PathShearX = this.primData.PathShearX; | ||
180 | objupdate.ObjectData[0].PathShearY = this.primData.PathShearY; | ||
181 | objupdate.ObjectData[0].PathSkew = this.primData.PathSkew; | ||
182 | objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin; | ||
183 | objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd; | ||
184 | objupdate.ObjectData[0].Scale = this.primData.Scale; | ||
185 | objupdate.ObjectData[0].PathCurve = this.primData.PathCurve; | ||
186 | objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve; | ||
187 | objupdate.ObjectData[0].ParentID = 0; | ||
188 | objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow; | ||
189 | //finish off copying rest of shape data | ||
190 | |||
191 | objupdate.ObjectData[0].ID = (uint)store.LocalID; | ||
192 | objupdate.ObjectData[0].FullID = store.FullID; | ||
193 | |||
194 | objupdate.ObjectData[0].ObjectData = new byte[60]; | ||
195 | objupdate.ObjectData[0].ObjectData[46] = 128; | ||
196 | objupdate.ObjectData[0].ObjectData[47] = 63; | ||
197 | LLVector3 pos1= store.Position; | ||
198 | //update position | ||
199 | byte[] pb = pos1.GetBytes(); | ||
200 | Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); | ||
201 | |||
202 | this.uuid = objupdate.ObjectData[0].FullID; | ||
203 | this.localid = objupdate.ObjectData[0].ID; | ||
204 | this.position = pos1; | ||
205 | this.OurPacket = objupdate; | ||
206 | } | ||
138 | public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock() | 207 | public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock() |
139 | { | 208 | { |
140 | uint ID = this.localid; | 209 | uint ID = this.localid; |
@@ -200,30 +269,17 @@ namespace OpenSim.world | |||
200 | dat.Data=bytes; | 269 | dat.Data=bytes; |
201 | return dat; | 270 | return dat; |
202 | } | 271 | } |
272 | |||
273 | public override void BackUp() | ||
274 | { | ||
275 | PrimStorage pStore = new PrimStorage(); | ||
276 | pStore.Data = this.primData; | ||
277 | pStore.FullID = this.uuid; | ||
278 | pStore.LocalID = this.localid; | ||
279 | pStore.Position = this.position; | ||
280 | pStore.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z , this.rotation.w); | ||
281 | OpenSim_Main.local_world.localStorage.StorePrim(pStore); | ||
282 | } | ||
203 | } | 283 | } |
204 | 284 | ||
205 | public class PrimData | ||
206 | { | ||
207 | public LLUUID OwnerID; | ||
208 | public byte PCode; | ||
209 | public byte PathBegin; | ||
210 | public byte PathEnd; | ||
211 | public byte PathScaleX; | ||
212 | public byte PathScaleY; | ||
213 | public byte PathShearX; | ||
214 | public byte PathShearY; | ||
215 | public sbyte PathSkew; | ||
216 | public byte ProfileBegin; | ||
217 | public byte ProfileEnd; | ||
218 | public LLVector3 Scale; | ||
219 | public byte PathCurve; | ||
220 | public byte ProfileCurve; | ||
221 | public uint ParentID=0; | ||
222 | public byte ProfileHollow; | ||
223 | |||
224 | public PrimData() | ||
225 | { | ||
226 | |||
227 | } | ||
228 | } | ||
229 | } | 285 | } |
diff --git a/src/world/World.cs b/src/world/World.cs index f6f58c7..6be9dd2 100644 --- a/src/world/World.cs +++ b/src/world/World.cs | |||
@@ -3,12 +3,14 @@ using libsecondlife; | |||
3 | using libsecondlife.Packets; | 3 | using libsecondlife.Packets; |
4 | using System.Collections.Generic; | 4 | using System.Collections.Generic; |
5 | using System.Text; | 5 | using System.Text; |
6 | using System.Reflection; | ||
6 | using System.IO; | 7 | using System.IO; |
7 | using PhysicsSystem; | 8 | using PhysicsSystem; |
9 | using GridInterfaces; | ||
8 | 10 | ||
9 | namespace OpenSim.world | 11 | namespace OpenSim.world |
10 | { | 12 | { |
11 | public class World | 13 | public class World : ILocalStorageReceiver |
12 | { | 14 | { |
13 | public Dictionary<libsecondlife.LLUUID, Entity> Entities; | 15 | public Dictionary<libsecondlife.LLUUID, Entity> Entities; |
14 | public float[] LandMap; | 16 | public float[] LandMap; |
@@ -17,9 +19,10 @@ namespace OpenSim.world | |||
17 | private PhysicsScene phyScene; | 19 | private PhysicsScene phyScene; |
18 | private float timeStep= 0.1f; | 20 | private float timeStep= 0.1f; |
19 | private libsecondlife.TerrainManager TerrainManager; | 21 | private libsecondlife.TerrainManager TerrainManager; |
20 | 22 | public ILocalStorage localStorage; | |
21 | private Random Rand = new Random(); | 23 | private Random Rand = new Random(); |
22 | private uint _primCount = 702000; | 24 | private uint _primCount = 702000; |
25 | private int storageCount; | ||
23 | 26 | ||
24 | public World() | 27 | public World() |
25 | { | 28 | { |
@@ -48,8 +51,7 @@ namespace OpenSim.world | |||
48 | 51 | ||
49 | public void Update() | 52 | public void Update() |
50 | { | 53 | { |
51 | 54 | if(this.phyScene.IsThreaded) | |
52 | if(this.phyScene.IsThreaded) | ||
53 | { | 55 | { |
54 | this.phyScene.GetResults(); | 56 | this.phyScene.GetResults(); |
55 | 57 | ||
@@ -66,24 +68,95 @@ namespace OpenSim.world | |||
66 | { | 68 | { |
67 | Entities[UUID].update(); | 69 | Entities[UUID].update(); |
68 | } | 70 | } |
71 | |||
72 | //backup world data | ||
73 | this.storageCount++; | ||
74 | if(storageCount> 1200) //set to how often you want to backup (currently set for about every 2 minutes) | ||
75 | { | ||
76 | this.Backup(); | ||
77 | storageCount =0; | ||
78 | } | ||
69 | } | 79 | } |
70 | 80 | ||
81 | public bool LoadStorageDLL(string dllName) | ||
82 | { | ||
83 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||
84 | ILocalStorage store = null; | ||
85 | |||
86 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
87 | { | ||
88 | if (pluginType.IsPublic) | ||
89 | { | ||
90 | if (!pluginType.IsAbstract) | ||
91 | { | ||
92 | Type typeInterface = pluginType.GetInterface("ILocalStorage", true); | ||
93 | |||
94 | if (typeInterface != null) | ||
95 | { | ||
96 | ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
97 | store = plug; | ||
98 | break; | ||
99 | } | ||
100 | |||
101 | typeInterface = null; | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | pluginAssembly = null; | ||
106 | this.localStorage = store; | ||
107 | return(store == null); | ||
108 | } | ||
109 | |||
110 | public void LoadPrimsFromStorage() | ||
111 | { | ||
112 | ServerConsole.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives"); | ||
113 | this.localStorage.LoadPrimitives(this); | ||
114 | } | ||
115 | |||
116 | public void PrimFromStorage(PrimStorage prim) | ||
117 | { | ||
118 | if(prim.LocalID >= this._primCount) | ||
119 | { | ||
120 | _primCount = prim.LocalID + 1; | ||
121 | } | ||
122 | ServerConsole.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Reloading prim (localId "+ prim.LocalID+ " ) from storage"); | ||
123 | Primitive nPrim = new Primitive(); | ||
124 | nPrim.CreateFromStorage(prim); | ||
125 | this.Entities.Add(nPrim.uuid, nPrim); | ||
126 | } | ||
127 | |||
128 | public void Close() | ||
129 | { | ||
130 | this.localStorage.ShutDown(); | ||
131 | } | ||
132 | |||
71 | public void SendLayerData(OpenSimClient RemoteClient) { | 133 | public void SendLayerData(OpenSimClient RemoteClient) { |
72 | int[] patches = new int[4]; | 134 | int[] patches = new int[4]; |
73 | 135 | ||
74 | for (int y = 0; y < 16; y++) | 136 | for (int y = 0; y < 16; y++) |
75 | { | 137 | { |
76 | for (int x = 0; x < 16; x = x + 4) | 138 | for (int x = 0; x < 16; x = x + 4) |
77 | { | 139 | { |
78 | patches[0] = x + 0 + y * 16; | 140 | patches[0] = x + 0 + y * 16; |
79 | patches[1] = x + 1 + y * 16; | 141 | patches[1] = x + 1 + y * 16; |
80 | patches[2] = x + 2 + y * 16; | 142 | patches[2] = x + 2 + y * 16; |
81 | patches[3] = x + 3 + y * 16; | 143 | patches[3] = x + 3 + y * 16; |
82 | 144 | ||
83 | Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches); | 145 | Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches); |
84 | RemoteClient.OutPacket(layerpack); | 146 | RemoteClient.OutPacket(layerpack); |
85 | } | 147 | } |
86 | } | 148 | } |
149 | } | ||
150 | |||
151 | public void GetInitialPrims(OpenSimClient RemoteClient) | ||
152 | { | ||
153 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
154 | { | ||
155 | if(Entities[UUID].ToString()== "OpenSim.world.Primitive") | ||
156 | { | ||
157 | ((OpenSim.world.Primitive)Entities[UUID]).UpdateClient(RemoteClient); | ||
158 | } | ||
159 | } | ||
87 | } | 160 | } |
88 | 161 | ||
89 | public void AddViewerAgent(OpenSimClient AgentClient) { | 162 | public void AddViewerAgent(OpenSimClient AgentClient) { |
@@ -96,7 +169,7 @@ namespace OpenSim.world | |||
96 | NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z)); | 169 | NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z)); |
97 | //this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user | 170 | //this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user |
98 | this.Entities.Add(AgentClient.AgentID, NewAvatar); | 171 | this.Entities.Add(AgentClient.AgentID, NewAvatar); |
99 | } | 172 | } |
100 | 173 | ||
101 | public void AddNewPrim(ObjectAddPacket addPacket, OpenSimClient AgentClient) | 174 | public void AddNewPrim(ObjectAddPacket addPacket, OpenSimClient AgentClient) |
102 | { | 175 | { |
@@ -109,8 +182,12 @@ namespace OpenSim.world | |||
109 | 182 | ||
110 | public bool Backup() { | 183 | public bool Backup() { |
111 | /* TODO: Save the current world entities state. */ | 184 | /* TODO: Save the current world entities state. */ |
112 | 185 | ServerConsole.MainConsole.Instance.WriteLine("World.cs: Backup() - Backing up Primitives"); | |
113 | return false; | 186 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) |
187 | { | ||
188 | Entities[UUID].BackUp(); | ||
189 | } | ||
190 | return true; | ||
114 | } | 191 | } |
115 | 192 | ||
116 | } | 193 | } |