aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/world/World.cs
diff options
context:
space:
mode:
authorgareth2007-03-07 19:07:00 +0000
committergareth2007-03-07 19:07:00 +0000
commit2159b3079ec8df2a7337a9d4ea54810b7028c4e1 (patch)
tree5473123011f7a302e63f89ec6ccb4477032fd1db /src/world/World.cs
parentImported branch (diff)
downloadopensim-SC_OLD-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.zip
opensim-SC_OLD-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.tar.gz
opensim-SC_OLD-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.tar.bz2
opensim-SC_OLD-2159b3079ec8df2a7337a9d4ea54810b7028c4e1.tar.xz
fixed last screwup
Diffstat (limited to 'src/world/World.cs')
-rw-r--r--src/world/World.cs117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/world/World.cs b/src/world/World.cs
new file mode 100644
index 0000000..8427a38
--- /dev/null
+++ b/src/world/World.cs
@@ -0,0 +1,117 @@
1using System;
2using libsecondlife;
3using libsecondlife.Packets;
4using System.Collections.Generic;
5using System.Text;
6using PhysicsSystem;
7
8namespace 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}