diff --git a/Common/OpenSim.Framework/Interfaces/IClientAPI.cs b/Common/OpenSim.Framework/Interfaces/IClientAPI.cs index feccf36433..cebfd9ac82 100644 --- a/Common/OpenSim.Framework/Interfaces/IClientAPI.cs +++ b/Common/OpenSim.Framework/Interfaces/IClientAPI.cs @@ -55,6 +55,7 @@ namespace OpenSim.Framework.Interfaces public delegate void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient); public delegate void StatusChange(bool status); public delegate void NewAvatar(IClientAPI remoteClient, LLUUID agentID, bool status); + public delegate void UpdateAgent(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation); public delegate void ParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id, bool snap_selection, IClientAPI remote_client); public delegate void ParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client); @@ -75,7 +76,7 @@ namespace OpenSim.Framework.Interfaces event GenericCall OnRegionHandShakeReply; event GenericCall OnRequestWearables; event GenericCall2 OnCompleteMovementToRegion; - event GenericCall3 OnAgentUpdate; + event UpdateAgent OnAgentUpdate; event GenericCall OnRequestAvatarsData; event GenericCall4 OnAddPrim; event UpdateShape OnUpdatePrimShape; @@ -125,10 +126,12 @@ namespace OpenSim.Framework.Interfaces void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID); void SendLayerData(float[] map); void MoveAgentIntoRegion(RegionInfo regInfo); - void SendAvatarData(RegionInfo regionInfo, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos); void InformClientOfNeighbour(ulong neighbourHandle, System.Net.IPAddress neighbourIP, ushort neighbourPort); AgentCircuitData RequestClientInfo(); + void SendAvatarData(RegionInfo regionInfo, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos); + void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLVector3 velocity); + void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint); void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID textureID); void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLUUID textureID); diff --git a/OpenSim/OpenSim.Region/Scenes/Avatar.Update.cs b/OpenSim/OpenSim.Region/Scenes/Avatar.Update.cs index d5c25f3b4d..3f87e10914 100644 --- a/OpenSim/OpenSim.Region/Scenes/Avatar.Update.cs +++ b/OpenSim/OpenSim.Region/Scenes/Avatar.Update.cs @@ -36,14 +36,26 @@ using OpenSim.Framework.Interfaces; namespace OpenSim.Region.Scenes { partial class Avatar - { + { /// /// /// public override void update() { - - + if (this.newForce) + { + this.SendTerseUpdateToALLClients(); + _updateCount = 0; + } + else if (movementflag != 0) + { + _updateCount++; + if (_updateCount > 3) + { + this.SendTerseUpdateToALLClients(); + _updateCount = 0; + } + } } /// @@ -116,15 +128,6 @@ namespace OpenSim.Region.Scenes } - /// - /// Very likely to be deleted soon! - /// - /// - public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() - { - return null; - } - /// /// /// diff --git a/OpenSim/OpenSim.Region/Scenes/Avatar.cs b/OpenSim/OpenSim.Region/Scenes/Avatar.cs index 6ae43190c7..17b243715f 100644 --- a/OpenSim/OpenSim.Region/Scenes/Avatar.cs +++ b/OpenSim/OpenSim.Region/Scenes/Avatar.cs @@ -61,6 +61,7 @@ namespace OpenSim.Region.Scenes private ulong m_regionHandle; private Dictionary m_clientThreads; private bool childAvatar = false; + private bool newForce = false; protected RegionInfo m_regionInfo; /// @@ -78,6 +79,7 @@ namespace OpenSim.Region.Scenes this.uuid = theClient.AgentId; m_regionInfo = reginfo; + m_regionHandle = reginfo.RegionHandle; OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Avatar.cs - Loading details from grid (DUMMY)"); ControllingClient = theClient; this.firstname = ControllingClient.FirstName; @@ -99,8 +101,8 @@ namespace OpenSim.Region.Scenes //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance); ControllingClient.OnCompleteMovementToRegion += new GenericCall2(this.CompleteMovement); ControllingClient.OnCompleteMovementToRegion += new GenericCall2(this.SendInitialPosition); - /* ControllingClient.OnAgentUpdate += new GenericCall3(this.HandleAgentUpdate); - ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack); + ControllingClient.OnAgentUpdate += new UpdateAgent(this.HandleAgentUpdate); + /* ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack); ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); */ @@ -135,32 +137,52 @@ namespace OpenSim.Region.Scenes /// public override void addForces() { - + lock (this.forcesList) + { + newForce = false; + if (this.forcesList.Count > 0) + { + for (int i = 0; i < this.forcesList.Count; i++) + { + NewForce force = this.forcesList[i]; + PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z); + lock (m_world.SyncRoot) + { + this._physActor.Velocity = phyVector; + } + this.updateflag = true; + this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this + // but as we are setting the velocity (rather than using real forces) at the moment it is okay. + this.newForce = true; + } + for (int i = 0; i < this.forcesList.Count; i++) + { + this.forcesList.RemoveAt(0); + } + } + } } - /// - /// likely to removed very soon - /// - /// - public static void SetupTemplate(string name) + public void SendTerseUpdateToClient(IClientAPI RemoteClient) { - - } - - /// - /// likely to removed very soon - /// - /// - protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata) - { - - - + RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.localid, new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z), new LLVector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z)); } /// /// /// + public void SendTerseUpdateToALLClients() + { + List avatars = this.m_world.RequestAvatarList(); + for (int i = 0; i < avatars.Count; i++) + { + this.SendTerseUpdateToClient(avatars[i].ControllingClient); + } + } + + /// + /// Complete Avatar's movement into the region + /// public void CompleteMovement() { this.ControllingClient.MoveAgentIntoRegion(m_regionInfo); @@ -187,9 +209,55 @@ namespace OpenSim.Region.Scenes /// /// /// - public void SendRegionHandshake() + /// + public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation) { + if ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0) + { + Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z); + if (((movementflag & 1) == 0) || (q != this.bodyRot)) + { + //we should add a new force to the list + // but for now we will deal with velocities + NewForce newVelocity = new NewForce(); + Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0); + Axiom.MathLib.Vector3 direc = q * v3; + direc.Normalize(); + + //work out velocity for sim physics system + direc = direc * ((0.03f) * 128f); + if (this._physActor.Flying) + direc *= 4; + + newVelocity.X = direc.x; + newVelocity.Y = direc.y; + newVelocity.Z = direc.z; + this.forcesList.Add(newVelocity); + movementflag = 1; + this.bodyRot = q; + } + } + else + { + if (movementflag == 16) + { + movementflag = 0; + } + if ((movementflag) != 0) + { + NewForce newVelocity = new NewForce(); + newVelocity.X = 0; + newVelocity.Y = 0; + newVelocity.Z = 0; + this.forcesList.Add(newVelocity); + movementflag = 0; + + this.movementflag = 16; + + } + } + } /// diff --git a/OpenSim/OpenSim.Region/Scenes/Scene.cs b/OpenSim/OpenSim.Region/Scenes/Scene.cs index 7c61c906c1..98f5027a62 100644 --- a/OpenSim/OpenSim.Region/Scenes/Scene.cs +++ b/OpenSim/OpenSim.Region/Scenes/Scene.cs @@ -123,14 +123,8 @@ namespace OpenSim.Region.Scenes OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs - creating LandMap"); TerrainManager = new TerrainManager(new SecondLife()); Terrain = new TerrainEngine(); - Avatar.SetupTemplate("avatar-texture.dat"); - + Avatar.LoadAnims(); - - //this.SetDefaultScripts(); - //this.LoadScriptEngines(); - - } catch (Exception e) { diff --git a/OpenSim/OpenSim.RegionServer/OpenSimNetworkHandler.cs b/OpenSim/OpenSim.RegionServer/ClientStackNetworkHandler.cs similarity index 95% rename from OpenSim/OpenSim.RegionServer/OpenSimNetworkHandler.cs rename to OpenSim/OpenSim.RegionServer/ClientStackNetworkHandler.cs index 382ba21c11..755219559a 100644 --- a/OpenSim/OpenSim.RegionServer/OpenSimNetworkHandler.cs +++ b/OpenSim/OpenSim.RegionServer/ClientStackNetworkHandler.cs @@ -36,7 +36,7 @@ using libsecondlife; namespace OpenSim { - public interface OpenSimNetworkHandler + public interface ClientStackNetworkHandler { void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode);// EndPoint packetSender); void RemoveClientCircuit(uint circuitcode); diff --git a/OpenSim/OpenSim.RegionServer/ClientView.API.cs b/OpenSim/OpenSim.RegionServer/ClientView.API.cs index 484ecc1cf7..33727c41a9 100644 --- a/OpenSim/OpenSim.RegionServer/ClientView.API.cs +++ b/OpenSim/OpenSim.RegionServer/ClientView.API.cs @@ -47,7 +47,7 @@ namespace OpenSim public event GenericCall OnRequestWearables; public event SetAppearance OnSetAppearance; public event GenericCall2 OnCompleteMovementToRegion; - public event GenericCall3 OnAgentUpdate; + public event UpdateAgent OnAgentUpdate; public event StartAnim OnStartAnim; public event GenericCall OnRequestAvatarsData; public event LinkObjects OnLinkObjects; @@ -393,6 +393,26 @@ namespace OpenSim } + /// + /// + /// + /// + /// + /// + /// + /// + public void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLVector3 velocity) + { + ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = this.CreateAvatarImprovedBlock(localID, position, velocity); + ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); + terse.RegionData.RegionHandle = regionHandle; + terse.RegionData.TimeDilation = timeDilation; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = terseBlock; + + this.OutPacket(terse); + } + #endregion #region Primitive Packet/data Sending Methods @@ -491,6 +511,83 @@ namespace OpenSim #region Helper Methods + protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, LLVector3 pos, LLVector3 velocity) + { + byte[] bytes = new byte[60]; + int i = 0; + ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); + + dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry; + + uint ID = localID; + + bytes[i++] = (byte)(ID % 256); + bytes[i++] = (byte)((ID >> 8) % 256); + bytes[i++] = (byte)((ID >> 16) % 256); + bytes[i++] = (byte)((ID >> 24) % 256); + bytes[i++] = 0; + bytes[i++] = 1; + i += 14; + bytes[i++] = 128; + bytes[i++] = 63; + + byte[] pb = pos.GetBytes(); + Array.Copy(pb, 0, bytes, i, pb.Length); + i += 12; + ushort InternVelocityX; + ushort InternVelocityY; + ushort InternVelocityZ; + Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0); + + internDirec = new Axiom.MathLib.Vector3(velocity.X, velocity.Y, velocity.Z); + + internDirec = internDirec / 128.0f; + internDirec.x += 1; + internDirec.y += 1; + internDirec.z += 1; + + InternVelocityX = (ushort)(32768 * internDirec.x); + InternVelocityY = (ushort)(32768 * internDirec.y); + InternVelocityZ = (ushort)(32768 * internDirec.z); + + ushort ac = 32767; + bytes[i++] = (byte)(InternVelocityX % 256); + bytes[i++] = (byte)((InternVelocityX >> 8) % 256); + bytes[i++] = (byte)(InternVelocityY % 256); + bytes[i++] = (byte)((InternVelocityY >> 8) % 256); + bytes[i++] = (byte)(InternVelocityZ % 256); + bytes[i++] = (byte)((InternVelocityZ >> 8) % 256); + + //accel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + //rot + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + //rotation vel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + dat.Data = bytes; + return (dat); + } + /// /// /// diff --git a/OpenSim/OpenSim.RegionServer/ClientView.ProcessPackets.cs b/OpenSim/OpenSim.RegionServer/ClientView.ProcessPackets.cs index dbe0bd9ba5..f8c7cdb13f 100644 --- a/OpenSim/OpenSim.RegionServer/ClientView.ProcessPackets.cs +++ b/OpenSim/OpenSim.RegionServer/ClientView.ProcessPackets.cs @@ -168,7 +168,8 @@ namespace OpenSim case PacketType.AgentUpdate: if (OnAgentUpdate != null) { - OnAgentUpdate(Pack); + AgentUpdatePacket agenUpdate = (AgentUpdatePacket) Pack; + OnAgentUpdate(this, agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotation ); } break; case PacketType.AgentAnimation: diff --git a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj index 4231f40f30..63eeb9cecc 100644 --- a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj +++ b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj @@ -130,6 +130,9 @@ + + Code + Code @@ -151,21 +154,15 @@ Code - - Code - Code - + Code Code - - Code - Code diff --git a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build index f5f8440865..23eca3acd7 100644 --- a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build +++ b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build @@ -11,6 +11,7 @@ + @@ -18,11 +19,9 @@ - - + - diff --git a/OpenSim/OpenSim.RegionServer/PacketServer.cs b/OpenSim/OpenSim.RegionServer/PacketServer.cs index f0bf44fe85..229570cfdd 100644 --- a/OpenSim/OpenSim.RegionServer/PacketServer.cs +++ b/OpenSim/OpenSim.RegionServer/PacketServer.cs @@ -40,13 +40,13 @@ namespace OpenSim { public class PacketServer { - private OpenSimNetworkHandler _networkHandler; + private ClientStackNetworkHandler _networkHandler; private IWorld _localWorld; public Dictionary ClientThreads = new Dictionary(); public Dictionary ClientAPIs = new Dictionary(); protected uint serverPort; - public PacketServer(OpenSimNetworkHandler networkHandler, uint port) + public PacketServer(ClientStackNetworkHandler networkHandler, uint port) { _networkHandler = networkHandler; this.serverPort = port; diff --git a/OpenSim/OpenSim.RegionServer/RegionServerBase.cs b/OpenSim/OpenSim.RegionServer/RegionApplicationBase.cs similarity index 92% rename from OpenSim/OpenSim.RegionServer/RegionServerBase.cs rename to OpenSim/OpenSim.RegionServer/RegionApplicationBase.cs index c059d7c636..8509dcc42a 100644 --- a/OpenSim/OpenSim.RegionServer/RegionServerBase.cs +++ b/OpenSim/OpenSim.RegionServer/RegionApplicationBase.cs @@ -52,7 +52,7 @@ using OpenSim.GenericConfig; namespace OpenSim { - public class RegionServerBase + public class RegionApplicationBase { protected IGenericConfig localConfig; protected PhysicsManager physManager; @@ -78,12 +78,12 @@ namespace OpenSim protected ConsoleBase m_console; - public RegionServerBase() + public RegionApplicationBase() { } - public RegionServerBase(bool sandBoxMode, bool startLoginServer, string physicsEngine, bool useConfigFile, bool silent, string configFile) + public RegionApplicationBase(bool sandBoxMode, bool startLoginServer, string physicsEngine, bool useConfigFile, bool silent, string configFile) { this.configFileSetup = useConfigFile; m_sandbox = sandBoxMode; diff --git a/OpenSim/OpenSim.RegionServer/UDPServer.cs b/OpenSim/OpenSim.RegionServer/UDPServer.cs index 090ed7d4cb..315cb2c91a 100644 --- a/OpenSim/OpenSim.RegionServer/UDPServer.cs +++ b/OpenSim/OpenSim.RegionServer/UDPServer.cs @@ -52,7 +52,7 @@ using OpenSim.GenericConfig; namespace OpenSim { - public class UDPServer : OpenSimNetworkHandler + public class UDPServer : ClientStackNetworkHandler { protected Dictionary clientCircuits = new Dictionary(); public Socket Server; diff --git a/OpenSim/OpenSim.RegionServer/UserConfigUtility.cs b/OpenSim/OpenSim.RegionServer/UserConfigUtility.cs deleted file mode 100644 index 2f04c0713b..0000000000 --- a/OpenSim/OpenSim.RegionServer/UserConfigUtility.cs +++ /dev/null @@ -1,37 +0,0 @@ -/* -* Copyright (c) Contributors, http://www.openmetaverse.org/ -* See CONTRIBUTORS.TXT for a full list of copyright holders. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* * Neither the name of the OpenSim Project nor the -* names of its contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY -* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim -{ - public class UserConfigUtility - { - } -} diff --git a/OpenSim/OpenSim/OpenSimMain.cs b/OpenSim/OpenSim/OpenSimMain.cs index ea713307da..9fe9581a38 100644 --- a/OpenSim/OpenSim/OpenSimMain.cs +++ b/OpenSim/OpenSim/OpenSimMain.cs @@ -57,7 +57,7 @@ using OpenGrid.Framework.Communications; namespace OpenSim { - public class OpenSimMain : RegionServerBase, conscmd_callback + public class OpenSimMain : RegionApplicationBase, conscmd_callback { private CheckSumServer checkServer; protected RegionServerCommsManager commsManager;