From a04602d9c136b882a6c72d4c3c09c3ca0d526c37 Mon Sep 17 00:00:00 2001 From: MW Date: Sat, 14 Jul 2007 13:18:02 +0000 Subject: [PATCH] Added AddPreCompiledScript method to ScriptManager. Done some work on lbsa71's simpleApp(hope he doesn't mind): now have the avatar showing up and the terrain and his pulsating box (well except its not a box, as there seems to be something wrong with our PrimitiveBaseShape..DefaultBox() settings). Also noticed a few other problems that I had to work around, so these need looking into. --- .../General/Types/PrimitiveBaseShape.cs | 2 + .../Scenes/Scene.PacketHandlers.cs | 1 + OpenSim/Region/Environment/Scenes/Scene.cs | 4 +- .../Environment/Scenes/ScenePresence.cs | 5 +- .../Scenes/scripting/ScriptManager.cs | 8 +++ OpenSim/Region/Examples/SimpleApp/MyWorld.cs | 50 +++++++++++++++++- OpenSim/Region/Examples/SimpleApp/Program.cs | 14 +++-- .../Region/Examples/SimpleApp/PulseScript.cs | 52 +++++++++++++++++++ prebuild.xml | 1 + 9 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 OpenSim/Region/Examples/SimpleApp/PulseScript.cs diff --git a/OpenSim/Framework/General/Types/PrimitiveBaseShape.cs b/OpenSim/Framework/General/Types/PrimitiveBaseShape.cs index 1844caa741..a085a446b1 100644 --- a/OpenSim/Framework/General/Types/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/General/Types/PrimitiveBaseShape.cs @@ -100,6 +100,8 @@ namespace OpenSim.Framework.Types primShape.PathTaperY = 0; primShape.PathTwist = 0; primShape.PathTwistBegin = 0; + LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-9999-000000000005")); + primShape.TextureEntry = ntex.ToBytes(); return primShape; } diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index f9b3145ecb..bf98b0dcf8 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -146,6 +146,7 @@ namespace OpenSim.Region.Environment.Scenes avatar = this.Avatars[fromAgentID]; fromPos = avatar.Pos; fromName = avatar.firstname + " " + avatar.lastname; + avatar = null; } m_clientManager.ForEachClient(delegate(IClientAPI client) diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 318b0251bd..737e8fe195 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -487,7 +487,7 @@ namespace OpenSim.Region.Environment.Scenes } - protected void CreateAndAddScenePresence(IClientAPI client) + protected ScenePresence CreateAndAddScenePresence(IClientAPI client) { ScenePresence newAvatar = null; @@ -524,6 +524,8 @@ namespace OpenSim.Region.Environment.Scenes this.Avatars.Add(client.AgentId, newAvatar); } } + newAvatar.OnSignificantClientMovement += parcelManager.handleSignificantClientMovement; + return newAvatar; } diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 8559caf196..6966989ca0 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -40,9 +40,6 @@ namespace OpenSim.Region.Environment.Scenes { public partial class ScenePresence : Entity { - - - public static bool PhysicsEngineFlying = false; public static AvatarAnimations Animations; public static byte[] DefaultTexture; @@ -151,7 +148,7 @@ namespace OpenSim.Region.Environment.Scenes // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack); // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); - OnSignificantClientMovement += new SignificantClientMovement(m_world.parcelManager.handleSignificantClientMovement); + Dir_Vectors[0] = new Vector3(1, 0, 0); //FOWARD Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK Dir_Vectors[2] = new Vector3(0, 1, 0); //LEFT diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs index 736d18b97f..7a0873582c 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs @@ -89,6 +89,14 @@ namespace OpenSim.Region.Scripting break; } } + + public void AddPreCompiledScript(IScript script) + { + MainLog.Instance.Verbose("Loading script " + script.getName()); + ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script. + script.Initialise(scriptInfo); + scripts.Add(script); + } } interface IScriptCompiler diff --git a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs index 39666fbac9..1f40052f14 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs @@ -7,12 +7,14 @@ using OpenSim.Framework.Servers; using OpenSim.Framework.Types; using OpenSim.Region.Caches; using OpenSim.Region.Environment.Scenes; +using OpenSim.Region.Terrain; using Avatar=OpenSim.Region.Environment.Scenes.ScenePresence; namespace SimpleApp { public class MyWorld : Scene { + private bool firstlogin = true; private List m_avatars; public MyWorld(ClientManager clientManager, RegionInfo regionInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, BaseHttpServer httpServer) @@ -21,6 +23,7 @@ namespace SimpleApp m_avatars = new List(); } + /* public override void SendLayerData(IClientAPI remoteClient) { float[] map = new float[65536]; @@ -34,6 +37,22 @@ namespace SimpleApp } remoteClient.SendLayerData(map); + }*/ + + public override void LoadWorldMap() + { + float[] map = new float[65536]; + + for (int i = 0; i < 65536; i++) + { + int x = i % 256; + int y = i / 256; + + map[i] = 25f; + } + + this.Terrain.setHeights1D(map); + this.CreateTerrainTexture(); } #region IWorld Members @@ -41,6 +60,8 @@ namespace SimpleApp override public void AddNewClient(IClientAPI client, bool child) { + NewLoggin(); + LLVector3 pos = new LLVector3(128, 128, 128); client.OnRegionHandShakeReply += SendLayerData; @@ -66,8 +87,33 @@ namespace SimpleApp client.SendRegionHandshake(m_regInfo); - CreateAndAddScenePresence(client); - + ScenePresence avatar =CreateAndAddScenePresence(client); + avatar.Pos = new LLVector3(128, 128, 26); + } + + public void NewLoggin() + { + if (firstlogin) + { + this.StartTimer(); + + scriptManager.AddPreCompiledScript(new PulseScript()); + + PrimitiveBaseShape shape = PrimitiveBaseShape.DefaultBox(); + shape.Scale = new LLVector3(0.5f, 0.5f, 0.5f); + LLVector3 pos1 = new LLVector3(129, 129, 27); + AddNewPrim(LLUUID.Random(), pos1, shape); + firstlogin = false; + } + } + + public override void Update() + { + foreach (LLUUID UUID in Entities.Keys) + { + Entities[UUID].update(); + } + eventManager.TriggerOnFrame(); } #endregion diff --git a/OpenSim/Region/Examples/SimpleApp/Program.cs b/OpenSim/Region/Examples/SimpleApp/Program.cs index e5e22349cf..3723c3d98e 100644 --- a/OpenSim/Region/Examples/SimpleApp/Program.cs +++ b/OpenSim/Region/Examples/SimpleApp/Program.cs @@ -21,6 +21,7 @@ namespace SimpleApp private LogBase m_log; AuthenticateSessionsBase m_circuitManager; uint m_localId; + public MyWorld world; private void Run() { @@ -57,8 +58,9 @@ namespace SimpleApp RegionInfo regionInfo = new RegionInfo( 1000, 1000, internalEndPoint, "127.0.0.1" ); - MyWorld world = new MyWorld(packetServer.ClientManager, regionInfo, m_circuitManager, communicationsManager, assetCache, httpServer); + world = new MyWorld(packetServer.ClientManager, regionInfo, m_circuitManager, communicationsManager, assetCache, httpServer); world.PhysScene = physManager.GetPhysicsScene("basicphysics"); //PhysicsScene.Null; + world.LoadWorldMap(); udpServer.LocalWorld = world; httpServer.Start(); @@ -66,13 +68,16 @@ namespace SimpleApp m_log.WriteLine( LogPriority.NORMAL, "Press enter to quit."); m_log.ReadLine(); + + /* PrimitiveBaseShape shape = PrimitiveBaseShape.DefaultBox(); - shape.Scale = new LLVector3(10, 10, 10); + shape.Scale = new LLVector3(0.5f, 0.5f, 0.5f); - LLVector3 pos = new LLVector3(128,128,72); + LLVector3 pos = new LLVector3(129,130,25); - world.AddNewPrim( LLUUID.Zero, pos, shape ); + world.AddNewPrim( LLUUID.Random(), pos, shape ); + */ } @@ -129,6 +134,7 @@ namespace SimpleApp Program app = new Program(); app.Run(); + } } } diff --git a/OpenSim/Region/Examples/SimpleApp/PulseScript.cs b/OpenSim/Region/Examples/SimpleApp/PulseScript.cs new file mode 100644 index 0000000000..01a9bda80e --- /dev/null +++ b/OpenSim/Region/Examples/SimpleApp/PulseScript.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Region.Scripting; +using OpenSim.Region.Environment.Scenes; +namespace SimpleApp +{ + public class PulseScript :IScript + { + ScriptInfo script; + + private libsecondlife.LLVector3 pulse = new libsecondlife.LLVector3(0.1f, 0.1f, 0.1f); + public string getName() + { + return "pulseScript 0.1"; + } + + public void Initialise(ScriptInfo scriptInfo) + { + script = scriptInfo; + script.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame); + script.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence); + } + + void events_OnNewPresence(ScenePresence presence) + { + script.logger.Verbose("Hello " + presence.firstname.ToString() + "!"); + } + + void events_OnFrame() + { + foreach(EntityBase ent in this.script.world.Entities.Values) + { + if (ent is SceneObject) + { + SceneObject prim = (SceneObject)ent; + if ((prim.rootPrimitive.Scale.X > 1) && (prim.rootPrimitive.Scale.Y > 1) && (prim.rootPrimitive.Scale.Z > 1)) + { + this.pulse = new libsecondlife.LLVector3(-0.1f, -0.1f, -0.1f); + } + else if ((prim.rootPrimitive.Scale.X < 0.2f) && (prim.rootPrimitive.Scale.Y < 0.2f) && (prim.rootPrimitive.Scale.Z < 0.2f)) + { + pulse = new libsecondlife.LLVector3(0.1f, 0.1f, 0.1f); + } + + prim.rootPrimitive.ResizeGoup( prim.rootPrimitive.Scale + pulse); + } + } + } + + } +} diff --git a/prebuild.xml b/prebuild.xml index 26d7b4289f..90eca77d64 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -726,6 +726,7 @@ +