aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/world
diff options
context:
space:
mode:
authorlbsa712007-04-03 20:08:30 +0000
committerlbsa712007-04-03 20:08:30 +0000
commitf12ceff6925236ca184c5a7a9c010b5e4bdb1b70 (patch)
tree9c83230be4bbdc19501e854df63084399cd742ba /OpenSim.RegionServer/world
parent* Extended Script API with GetRandomAvatar (diff)
downloadopensim-SC-f12ceff6925236ca184c5a7a9c010b5e4bdb1b70.zip
opensim-SC-f12ceff6925236ca184c5a7a9c010b5e4bdb1b70.tar.gz
opensim-SC-f12ceff6925236ca184c5a7a9c010b5e4bdb1b70.tar.bz2
opensim-SC-f12ceff6925236ca184c5a7a9c010b5e4bdb1b70.tar.xz
* The world can not contain ScriptFactories that creates unique instances of scripts for entities.
* Created Scripts folder to house trusted Scripts * The test script now lives in Scripts/FollowRandomAvatar.cs
Diffstat (limited to 'OpenSim.RegionServer/world')
-rw-r--r--OpenSim.RegionServer/world/World.cs49
-rw-r--r--OpenSim.RegionServer/world/scripting/ScriptFactory.cs8
-rw-r--r--OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs37
3 files changed, 64 insertions, 30 deletions
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs
index c775429..0799e38 100644
--- a/OpenSim.RegionServer/world/World.cs
+++ b/OpenSim.RegionServer/world/World.cs
@@ -13,6 +13,7 @@ using OpenSim.Framework.Inventory;
13using OpenSim.Assets; 13using OpenSim.Assets;
14using OpenSim.world.scripting; 14using OpenSim.world.scripting;
15using OpenSim.RegionServer.world.scripting; 15using OpenSim.RegionServer.world.scripting;
16using OpenSim.RegionServer.world.scripting.Scripts;
16 17
17namespace OpenSim.world 18namespace OpenSim.world
18{ 19{
@@ -32,20 +33,20 @@ namespace OpenSim.world
32 private int storageCount; 33 private int storageCount;
33 private Dictionary<uint, SimClient> m_clientThreads; 34 private Dictionary<uint, SimClient> m_clientThreads;
34 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; 35 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
35 private Dictionary<string, Script> m_scripts; 36 private Dictionary<string, ScriptFactory> m_scripts;
36 private ulong m_regionHandle; 37 private ulong m_regionHandle;
37 private string m_regionName; 38 private string m_regionName;
38 private InventoryCache _inventoryCache; 39 private InventoryCache _inventoryCache;
39 private AssetCache _assetCache; 40 private AssetCache _assetCache;
40 41
41 public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName) 42 public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName)
42 { 43 {
43 m_clientThreads = clientThreads; 44 m_clientThreads = clientThreads;
44 m_regionHandle = regionHandle; 45 m_regionHandle = regionHandle;
45 m_regionName = regionName; 46 m_regionName = regionName;
46 47
47 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); 48 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
48 m_scripts = new Dictionary<string, Script>(); 49 m_scripts = new Dictionary<string, ScriptFactory>();
49 50
50 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); 51 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
51 Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); 52 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
@@ -75,11 +76,17 @@ namespace OpenSim.world
75 scriptend = scriptData.LastIndexOf("</Script>"); 76 scriptend = scriptData.LastIndexOf("</Script>");
76 substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8); 77 substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8);
77 substring = substring.Trim(); 78 substring = substring.Trim();
78 Console.WriteLine("searching for script to add: " + substring); 79 Console.WriteLine("searching for script to add: " + substring);
79 if (this.m_scripts.ContainsKey(substring)) 80
81 ScriptFactory scriptFactory;
82
83 if (this.m_scripts.TryGetValue(substring, out scriptFactory ))
80 { 84 {
81 Console.WriteLine("added script"); 85 Console.WriteLine("added script");
82 this.AddScript(entity, this.m_scripts[substring]); 86
87
88
89 this.AddScript(entity, scriptFactory());
83 } 90 }
84 /*string delimStr = " "; 91 /*string delimStr = " ";
85 char[] delimiter = delimStr.ToCharArray(); 92 char[] delimiter = delimStr.ToCharArray();
@@ -357,7 +364,7 @@ namespace OpenSim.world
357 prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); 364 prim.PhysActor = this.phyScene.AddPrim(pVec, pSize);
358 } 365 }
359 } 366 }
360 367
361 this.Entities.Add(prim.uuid, prim); 368 this.Entities.Add(prim.uuid, prim);
362 this._primCount++; 369 this._primCount++;
363 } 370 }
@@ -557,31 +564,13 @@ namespace OpenSim.world
557 564
558 public void SetDefaultScripts() 565 public void SetDefaultScripts()
559 { 566 {
560 this.m_scripts.Add("Test", new TestScript1()); 567 this.m_scripts.Add("FollowRandomAvatar", delegate()
561 } 568 {
562 569 return new FollowRandomAvatar();
563 #endregion 570 });
564 }
565
566 public class TestScript1 : Script
567 {
568 int toggle = 0;
569
570 public TestScript1()
571 : base(LLUUID.Random())
572 {
573 OnFrame += MyOnFrame;
574 } 571 }
575 572
576 private void MyOnFrame(IScriptContext context)
577 {
578 toggle = 2 - toggle;
579 573
580 LLVector3 pos = context.GetPos(); 574 #endregion
581
582 pos.X += (toggle - 1);
583
584 context.MoveTo(pos);
585 }
586 } 575 }
587} 576}
diff --git a/OpenSim.RegionServer/world/scripting/ScriptFactory.cs b/OpenSim.RegionServer/world/scripting/ScriptFactory.cs
new file mode 100644
index 0000000..4c6d373
--- /dev/null
+++ b/OpenSim.RegionServer/world/scripting/ScriptFactory.cs
@@ -0,0 +1,8 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.RegionServer.world.scripting
6{
7 public delegate Script ScriptFactory();
8}
diff --git a/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs
new file mode 100644
index 0000000..388a95c
--- /dev/null
+++ b/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs
@@ -0,0 +1,37 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.RegionServer.world.scripting.Scripts
7{
8 public class FollowRandomAvatar : Script
9 {
10 public FollowRandomAvatar()
11 : base(LLUUID.Random())
12 {
13 OnFrame += MyOnFrame;
14 }
15
16 private void MyOnFrame(IScriptContext context)
17 {
18 LLVector3 pos = context.Entity.Pos;
19
20 IScriptReadonlyEntity avatar;
21
22 if (context.TryGetRandomAvatar(out avatar))
23 {
24 LLVector3 avatarPos = avatar.Pos;
25
26 float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
27 float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
28
29 LLVector3 newPos = new LLVector3(x, y, pos.Z);
30
31 context.Entity.Pos = newPos;
32 }
33 }
34 }
35
36
37}