From 09dd4bd6834861791008e66652826a66724efa0e Mon Sep 17 00:00:00 2001 From: gareth Date: Tue, 27 Feb 2007 23:00:49 +0000 Subject: Brought in code from branches/gareth --- src/world/Avatar.cs | 70 ++++++++++++++++++++++++++++++++++++++++++ src/world/Entity.cs | 53 ++++++++++++++++++++++++++++++++ src/world/Primitive.cs | 33 ++++++++++++++++++++ src/world/ScriptEngine.cs | 18 +++++++++++ src/world/SurfacePatch.cs | 22 +++++++++++++ src/world/World.cs | 57 ++++++++++++++++++++++++++++++++++ src/world/scripting/IScript.cs | 16 ++++++++++ 7 files changed, 269 insertions(+) create mode 100644 src/world/Avatar.cs create mode 100644 src/world/Entity.cs create mode 100644 src/world/Primitive.cs create mode 100644 src/world/ScriptEngine.cs create mode 100644 src/world/SurfacePatch.cs create mode 100644 src/world/World.cs create mode 100644 src/world/scripting/IScript.cs (limited to 'src/world') diff --git a/src/world/Avatar.cs b/src/world/Avatar.cs new file mode 100644 index 0000000..863ce29 --- /dev/null +++ b/src/world/Avatar.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using libsecondlife.Packets; + +namespace OpenSim.world +{ + public class Avatar : Entity + { + public string firstname; + public string lastname; + public OpenSimClient ControllingClient; + + public Avatar(OpenSimClient TheClient) { + Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)"); + ControllingClient=TheClient; + } + + public void CompleteMovement(World RegionInfo) { + Console.WriteLine("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet"); + AgentMovementCompletePacket mov = new AgentMovementCompletePacket(); + mov.AgentData.SessionID = this.ControllingClient.SessionID; + mov.AgentData.AgentID = this.ControllingClient.AgentID; + mov.Data.RegionHandle = OpenSim_Main.cfg.RegionHandle; + // TODO - dynamicalise this stuff + mov.Data.Timestamp = 1169838966; + mov.Data.Position = new LLVector3(100f, 100f, 22f); + mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0); + + Console.WriteLine("Sending AgentMovementComplete packet"); + ControllingClient.OutPacket(mov); + } + + public void SendRegionHandshake(World RegionInfo) { + Console.WriteLine("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet"); + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + RegionHandshakePacket handshake = new RegionHandshakePacket(); + + Console.WriteLine("Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details"); + handshake.RegionInfo.BillableFactor = 0; + handshake.RegionInfo.IsEstateManager = false; + handshake.RegionInfo.TerrainHeightRange00 = 60; + handshake.RegionInfo.TerrainHeightRange01 = 60; + handshake.RegionInfo.TerrainHeightRange10 = 60; + handshake.RegionInfo.TerrainHeightRange11 = 60; + handshake.RegionInfo.TerrainStartHeight00 = 20; + handshake.RegionInfo.TerrainStartHeight01 = 20; + handshake.RegionInfo.TerrainStartHeight10 = 20; + handshake.RegionInfo.TerrainStartHeight11 = 20; + handshake.RegionInfo.SimAccess = 13; + handshake.RegionInfo.WaterHeight = 5; + handshake.RegionInfo.RegionFlags = 72458694; + handshake.RegionInfo.SimName = _enc.GetBytes(OpenSim_Main.cfg.RegionName + "\0"); + handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainBase0 = new LLUUID("b8d3965a-ad78-bf43-699b-bff8eca6c975"); + handshake.RegionInfo.TerrainBase1 = new LLUUID("abb783e6-3e93-26c0-248a-247666855da3"); + handshake.RegionInfo.TerrainBase2 = new LLUUID("179cdabd-398a-9b6b-1391-4dc333ba321f"); + handshake.RegionInfo.TerrainBase3 = new LLUUID("beb169c7-11ea-fff2-efe5-0f24dc881df2"); + handshake.RegionInfo.TerrainDetail0 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainDetail1 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainDetail2 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.TerrainDetail3 = new LLUUID("00000000-0000-0000-0000-000000000000"); + handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37"); + + Console.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet"); + this.ControllingClient.OutPacket(handshake); + } + } +} diff --git a/src/world/Entity.cs b/src/world/Entity.cs new file mode 100644 index 0000000..ab07fd6 --- /dev/null +++ b/src/world/Entity.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Axiom.MathLib; +using OpenSim.types; + +namespace OpenSim.world +{ + public class Entity + { + protected libsecondlife.LLUUID uuid; + protected Vector3 position; + protected Vector3 velocity; + protected Quaternion rotation; + protected string name; + protected List children; + + public Entity() + { + uuid = new libsecondlife.LLUUID(); + position = new Vector3(); + velocity = new Vector3(); + rotation = new Quaternion(); + name = "(basic entity)"; + children = new List(); + } + + public virtual void update() { + // Do any per-frame updates needed that are applicable to every type of entity + foreach (Entity child in children) + { + child.update(); + } + } + + public virtual string getName() + { + return name; + } + + public virtual Mesh getMesh() + { + Mesh mesh = new Mesh(); + + foreach (Entity child in children) + { + mesh += child.getMesh(); + } + + return mesh; + } + } +} diff --git a/src/world/Primitive.cs b/src/world/Primitive.cs new file mode 100644 index 0000000..143fa55 --- /dev/null +++ b/src/world/Primitive.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.types; + +namespace OpenSim.world +{ + public class Primitive : Entity + { + protected float mesh_cutbegin; + protected float mesh_cutend; + + public Primitive() + { + mesh_cutbegin = 0.0f; + mesh_cutend = 1.0f; + } + + public override Mesh getMesh() + { + Mesh mesh = new Mesh(); + Triangle tri = new Triangle( + new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f), + new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f), + new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f)); + + mesh.AddTri(tri); + mesh += base.getMesh(); + + return mesh; + } + } +} diff --git a/src/world/ScriptEngine.cs b/src/world/ScriptEngine.cs new file mode 100644 index 0000000..f20a08e --- /dev/null +++ b/src/world/ScriptEngine.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.world +{ + public class ScriptEngine + { + public ScriptEngine(World env) + { + } + + public void LoadScript() + { + + } + } +} diff --git a/src/world/SurfacePatch.cs b/src/world/SurfacePatch.cs new file mode 100644 index 0000000..71e4116 --- /dev/null +++ b/src/world/SurfacePatch.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.world +{ + public class SurfacePatch + { + public float[] HeightMap; + + public SurfacePatch() { + HeightMap = new float[16*16]; + + int xinc; + int yinc; + for(xinc=0; xinc<16; xinc++) for(yinc=0; yinc<16; yinc++) { + HeightMap[xinc+(yinc*16)]=100.0f; + } + + } + } +} diff --git a/src/world/World.cs b/src/world/World.cs new file mode 100644 index 0000000..cf337a8 --- /dev/null +++ b/src/world/World.cs @@ -0,0 +1,57 @@ +using System; +using libsecondlife; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.world +{ + public class World + { + public Dictionary Entities; + public SurfacePatch[] LandMap; + public ScriptEngine Scripts; + + public World() + { + Console.WriteLine("World.cs - creating new entitities instance"); + Entities = new Dictionary(); + + // We need a 16x16 array of 16m2 surface patches for a 256m2 sim + Console.WriteLine("World.cs - creating LandMap"); + LandMap = new SurfacePatch[16*16]; + int xinc; + int yinc; + for(xinc=0; xinc<16; xinc++) for(yinc=0; yinc<16; yinc++) { + LandMap[xinc+(yinc*16)]=new SurfacePatch(); + } + + Console.WriteLine("World.cs - Creating script engine instance"); + // Initialise this only after the world has loaded + Scripts = new ScriptEngine(this); + } + + public void Update() + { + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].update(); + } + } + + public void AddViewerAgent(OpenSimClient AgentClient) { + Console.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); + Avatar NewAvatar = new Avatar(AgentClient); + Console.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world"); + this.Entities.Add(AgentClient.AgentID, NewAvatar); + Console.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake "); + NewAvatar.SendRegionHandshake(this); + this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user + } + + public bool Backup() { + /* TODO: Save the current world entities state. */ + + return false; + } + } +} diff --git a/src/world/scripting/IScript.cs b/src/world/scripting/IScript.cs new file mode 100644 index 0000000..550594d --- /dev/null +++ b/src/world/scripting/IScript.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.world.scripting +{ + public interface IScriptHost { + bool Register(IScript iscript); + } + public interface IScript + { + string Name{get;set;} + IScriptHost Host{get;set;} + void Show(); + } +} -- cgit v1.1