diff options
author | gareth | 2007-03-07 18:49:20 +0000 |
---|---|---|
committer | gareth | 2007-03-07 18:49:20 +0000 |
commit | 16476f06b867adf01fa0d17c6761f4a862fc17ad (patch) | |
tree | c3a1147578ae33d269812adfe8de5ece8c62d586 /ConvertToPlugins/src/world/World.cs | |
parent | Deleted old trunk code (diff) | |
download | opensim-SC_OLD-16476f06b867adf01fa0d17c6761f4a862fc17ad.zip opensim-SC_OLD-16476f06b867adf01fa0d17c6761f4a862fc17ad.tar.gz opensim-SC_OLD-16476f06b867adf01fa0d17c6761f4a862fc17ad.tar.bz2 opensim-SC_OLD-16476f06b867adf01fa0d17c6761f4a862fc17ad.tar.xz |
Imported branch
Diffstat (limited to 'ConvertToPlugins/src/world/World.cs')
-rw-r--r-- | ConvertToPlugins/src/world/World.cs | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/ConvertToPlugins/src/world/World.cs b/ConvertToPlugins/src/world/World.cs new file mode 100644 index 0000000..8427a38 --- /dev/null +++ b/ConvertToPlugins/src/world/World.cs | |||
@@ -0,0 +1,117 @@ | |||
1 | using System; | ||
2 | using libsecondlife; | ||
3 | using libsecondlife.Packets; | ||
4 | using System.Collections.Generic; | ||
5 | using System.Text; | ||
6 | using PhysicsSystem; | ||
7 | |||
8 | namespace OpenSim.world | ||
9 | { | ||
10 | public class World | ||
11 | { | ||
12 | public Dictionary<libsecondlife.LLUUID, Entity> Entities; | ||
13 | public float[] LandMap; | ||
14 | public ScriptEngine Scripts; | ||
15 | public uint _localNumber=0; | ||
16 | private PhysicsScene phyScene; | ||
17 | private float timeStep= 0.1f; | ||
18 | private libsecondlife.TerrainManager TerrainManager; | ||
19 | |||
20 | private Random Rand = new Random(); | ||
21 | private uint _primCount = 702000; | ||
22 | |||
23 | public World() | ||
24 | { | ||
25 | ServerConsole.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); | ||
26 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); | ||
27 | |||
28 | ServerConsole.MainConsole.Instance.WriteLine("World.cs - creating LandMap"); | ||
29 | TerrainManager = new TerrainManager(new SecondLife()); | ||
30 | |||
31 | // ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance"); | ||
32 | // Initialise this only after the world has loaded | ||
33 | // Scripts = new ScriptEngine(this); | ||
34 | } | ||
35 | |||
36 | public PhysicsScene PhysScene | ||
37 | { | ||
38 | set | ||
39 | { | ||
40 | this.phyScene = value; | ||
41 | } | ||
42 | get | ||
43 | { | ||
44 | return(this.phyScene); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | public void Update() | ||
49 | { | ||
50 | |||
51 | if(this.phyScene.IsThreaded) | ||
52 | { | ||
53 | this.phyScene.GetResults(); | ||
54 | |||
55 | } | ||
56 | |||
57 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
58 | { | ||
59 | Entities[UUID].addForces(); | ||
60 | } | ||
61 | |||
62 | this.phyScene.Simulate(timeStep); | ||
63 | |||
64 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
65 | { | ||
66 | Entities[UUID].update(); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | public void SendLayerData(OpenSimClient RemoteClient) { | ||
71 | int[] patches = new int[4]; | ||
72 | |||
73 | for (int y = 0; y < 16; y++) | ||
74 | { | ||
75 | for (int x = 0; x < 16; x = x + 4) | ||
76 | { | ||
77 | patches[0] = x + 0 + y * 16; | ||
78 | patches[1] = x + 1 + y * 16; | ||
79 | patches[2] = x + 2 + y * 16; | ||
80 | patches[3] = x + 3 + y * 16; | ||
81 | |||
82 | Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches); | ||
83 | RemoteClient.OutPacket(layerpack); | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | |||
88 | public void AddViewerAgent(OpenSimClient AgentClient) { | ||
89 | ServerConsole.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); | ||
90 | Avatar NewAvatar = new Avatar(AgentClient); | ||
91 | ServerConsole.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world"); | ||
92 | ServerConsole.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake "); | ||
93 | NewAvatar.SendRegionHandshake(this); | ||
94 | |||
95 | NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z)); | ||
96 | //this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user | ||
97 | this.Entities.Add(AgentClient.AgentID, NewAvatar); | ||
98 | } | ||
99 | |||
100 | public void AddNewPrim(ObjectAddPacket addPacket, OpenSimClient AgentClient) | ||
101 | { | ||
102 | ServerConsole.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Creating new prim"); | ||
103 | Primitive prim = new Primitive(); | ||
104 | prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount); | ||
105 | this.Entities.Add(prim.uuid, prim); | ||
106 | this._primCount++; | ||
107 | } | ||
108 | |||
109 | public bool Backup() { | ||
110 | /* TODO: Save the current world entities state. */ | ||
111 | |||
112 | return false; | ||
113 | } | ||
114 | |||
115 | |||
116 | } | ||
117 | } | ||