Primitives movement and rotation updates are now sent to all clients

adam
MW 2007-03-07 22:25:13 +00:00
parent 48b05c6784
commit 778e302133
4 changed files with 125 additions and 3 deletions

View File

@ -35,6 +35,7 @@ using System.IO;
using System.Threading; using System.Threading;
using System.Timers; using System.Timers;
using OpenSim.GridServers; using OpenSim.GridServers;
using OpenSim.world;
namespace OpenSim namespace OpenSim
{ {
@ -102,6 +103,39 @@ namespace OpenSim
case PacketType.ObjectAdd: case PacketType.ObjectAdd:
OpenSim_Main.local_world.AddNewPrim((ObjectAddPacket)Pack, this); OpenSim_Main.local_world.AddNewPrim((ObjectAddPacket)Pack, this);
break; break;
case PacketType.MultipleObjectUpdate :
MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)Pack;
for( int i = 0; i < multipleupdate.ObjectData.Length; i++ )
{
if( multipleupdate.ObjectData[ i ].Type == 9 ) //change position
{
libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[ i ].Data, 0 );
foreach (Entity ent in OpenSim_Main.local_world.Entities.Values)
{
if(ent.localid == multipleupdate.ObjectData[ i ].ObjectLocalID)
{
ent.position = pos;
((OpenSim.world.Primitive)ent).UpdateFlag = true;
}
}
//should update stored position of the prim
}
else if(multipleupdate.ObjectData[i].Type == 10 )//rotation
{
libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true);
foreach (Entity ent in OpenSim_Main.local_world.Entities.Values)
{
if(ent.localid == multipleupdate.ObjectData[ i ].ObjectLocalID)
{
ent.rotation = new Axiom.MathLib.Quaternion(rot.W, rot.X, rot.Y, rot.W);
((OpenSim.world.Primitive)ent).UpdateFlag = true;
}
}
}
}
break;
case PacketType.TransferRequest: case PacketType.TransferRequest:
//Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request"); //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request");
TransferRequestPacket transfer = (TransferRequestPacket)Pack; TransferRequestPacket transfer = (TransferRequestPacket)Pack;

View File

@ -104,7 +104,6 @@ namespace OpenSim.world
public static void SetupTemplate(string name) public static void SetupTemplate(string name)
{ {
int i = 0; int i = 0;
FileInfo fInfo = new FileInfo(name); FileInfo fInfo = new FileInfo(name);
long numBytes = fInfo.Length; long numBytes = fInfo.Length;
@ -127,7 +126,6 @@ namespace OpenSim.world
Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length); Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
Avatar.AvatarTemplate = objdata; Avatar.AvatarTemplate = objdata;
} }
public void CompleteMovement(World RegionInfo) { public void CompleteMovement(World RegionInfo) {

View File

@ -13,8 +13,21 @@ namespace OpenSim.world
protected float mesh_cutend; protected float mesh_cutend;
protected PrimData primData; protected PrimData primData;
protected bool newPrimFlag; protected bool newPrimFlag;
protected bool updateFlag;
protected ObjectUpdatePacket OurPacket; protected ObjectUpdatePacket OurPacket;
public bool UpdateFlag
{
get
{
return updateFlag;
}
set
{
updateFlag = value;
}
}
public Primitive() public Primitive()
{ {
mesh_cutbegin = 0.0f; mesh_cutbegin = 0.0f;
@ -44,6 +57,18 @@ namespace OpenSim.world
} }
this.newPrimFlag = false; this.newPrimFlag = false;
} }
else if(this.updateFlag)
{
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
terse.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; // FIXME
terse.RegionData.TimeDilation = 64096;
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
terse.ObjectData[0] = this.CreateImprovedBlock();
foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
client.OutPacket(terse);
}
this.updateFlag = false;
}
} }
public void CreateFromPacket( ObjectAddPacket addPacket, LLUUID agentID, uint localID) public void CreateFromPacket( ObjectAddPacket addPacket, LLUUID agentID, uint localID)
@ -109,6 +134,72 @@ namespace OpenSim.world
this.position = pos1; this.position = pos1;
this.OurPacket = objupdate; this.OurPacket = objupdate;
} }
public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
{
uint ID = this.localid;
byte[] bytes = new byte[60];
int i = 0;
ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry;
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++]= 0;
byte[] pb = this.position.GetBytes();
Array.Copy(pb, 0, bytes, i, pb.Length);
i += 12;
ushort ac = 32767;
//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);
//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);
ushort rw, rx,ry,rz;
rw = (ushort)(32768 * (this.rotation.w+1));
rx = (ushort)(32768 * (this.rotation.x+1));
ry = (ushort)(32768 * (this.rotation.y+1));
rz = (ushort)(32768 * (this.rotation.z+1));
//rot
bytes[i++] = (byte)(rx % 256);
bytes[i++] = (byte)((rx >> 8) % 256);
bytes[i++] = (byte)(ry % 256);
bytes[i++] = (byte)((ry >> 8) % 256);
bytes[i++] = (byte)(rz % 256);
bytes[i++] = (byte)((rz >> 8) % 256);
bytes[i++] = (byte)(rw % 256);
bytes[i++] = (byte)((rw >> 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;
}
} }
public class PrimData public class PrimData

View File

@ -29,7 +29,6 @@ namespace OpenSim.world
ServerConsole.MainConsole.Instance.WriteLine("World.cs - creating LandMap"); ServerConsole.MainConsole.Instance.WriteLine("World.cs - creating LandMap");
TerrainManager = new TerrainManager(new SecondLife()); TerrainManager = new TerrainManager(new SecondLife());
Avatar.SetupTemplate("avatar-template.dat"); Avatar.SetupTemplate("avatar-template.dat");
// ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance"); // ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
// Initialise this only after the world has loaded // Initialise this only after the world has loaded
// Scripts = new ScriptEngine(this); // Scripts = new ScriptEngine(this);