Merged makomk's patch as per bug #61
Rescued my brain ready to implement animations and proper velocity encodingadam
parent
b29618fc3c
commit
572ab93936
|
@ -46,7 +46,7 @@ namespace OpenSim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OpenSim_Main
|
public class OpenSim_Main
|
||||||
{
|
{
|
||||||
private static OpenSim_Main sim;
|
public static OpenSim_Main sim;
|
||||||
public static SimConfig cfg;
|
public static SimConfig cfg;
|
||||||
public static World local_world;
|
public static World local_world;
|
||||||
private static Thread MainListener;
|
private static Thread MainListener;
|
||||||
|
@ -68,6 +68,7 @@ namespace OpenSim
|
||||||
sim.Startup();
|
sim.Startup();
|
||||||
while(true) {
|
while(true) {
|
||||||
local_world.DoStuff();
|
local_world.DoStuff();
|
||||||
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ namespace OpenSim
|
||||||
private const int MAX_APPENDED_ACKS = 10;
|
private const int MAX_APPENDED_ACKS = 10;
|
||||||
private const int RESEND_TIMEOUT = 4000;
|
private const int RESEND_TIMEOUT = 4000;
|
||||||
private const int MAX_SEQUENCE = 0xFFFFFF;
|
private const int MAX_SEQUENCE = 0xFFFFFF;
|
||||||
|
private Queue<uint> Inbox;
|
||||||
|
|
||||||
public void ack_pack(Packet Pack) {
|
public void ack_pack(Packet Pack) {
|
||||||
//libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket();
|
//libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket();
|
||||||
|
@ -152,16 +153,22 @@ namespace OpenSim
|
||||||
break;
|
break;
|
||||||
case PacketType.LogoutRequest:
|
case PacketType.LogoutRequest:
|
||||||
Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got a logout request");
|
Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got a logout request");
|
||||||
OpenSim_Main.local_world.Entities.Remove(this.AgentID);
|
lock(OpenSim_Main.local_world.Entities) {
|
||||||
|
OpenSim_Main.local_world.Entities.Remove(this.AgentID);
|
||||||
|
}
|
||||||
WebRequest DeleteSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + this.AgentID.ToString() + this.CircuitCode.ToString() + "/delete");
|
WebRequest DeleteSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + this.AgentID.ToString() + this.CircuitCode.ToString() + "/delete");
|
||||||
WebResponse GridResponse = DeleteSession.GetResponse();
|
WebResponse GridResponse = DeleteSession.GetResponse();
|
||||||
StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
|
StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
|
||||||
String grTest = sr.ReadLine();
|
String grTest = sr.ReadLine();
|
||||||
sr.Close();
|
sr.Close();
|
||||||
GridResponse.Close();
|
GridResponse.Close();
|
||||||
|
Console.WriteLine("DEBUG: " + grTest);
|
||||||
|
|
||||||
this.ClientThread.Abort();
|
this.ClientThread.Abort();
|
||||||
break;
|
break;
|
||||||
|
case PacketType.AgentUpdate:
|
||||||
|
ClientAvatar.HandleAgentUpdate((AgentUpdatePacket)Pack);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,6 +322,7 @@ namespace OpenSim
|
||||||
{
|
{
|
||||||
foreach (uint ack in NewPack.Header.AckList)
|
foreach (uint ack in NewPack.Header.AckList)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Got appended ack: "+ack);
|
||||||
NeedAck.Remove(ack);
|
NeedAck.Remove(ack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,6 +337,7 @@ namespace OpenSim
|
||||||
{
|
{
|
||||||
foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
|
foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Got PacketAck: "+block.ID);
|
||||||
NeedAck.Remove(block.ID);
|
NeedAck.Remove(block.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -398,6 +407,7 @@ namespace OpenSim
|
||||||
private void AuthUser() {
|
private void AuthUser() {
|
||||||
Console.WriteLine("OpenSimClient.cs:AuthUser() - Authenticating new user request with grid");
|
Console.WriteLine("OpenSimClient.cs:AuthUser() - Authenticating new user request with grid");
|
||||||
WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + cirpack.CircuitCode.ID.ToString() + "/" + cirpack.CircuitCode.Code.ToString() + "/exists");
|
WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + cirpack.CircuitCode.ID.ToString() + "/" + cirpack.CircuitCode.Code.ToString() + "/exists");
|
||||||
|
Console.WriteLine(OpenSim_Main.cfg.GridURL);
|
||||||
WebResponse GridResponse = CheckSession.GetResponse();
|
WebResponse GridResponse = CheckSession.GetResponse();
|
||||||
StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
|
StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
|
||||||
String grTest = sr.ReadLine();
|
String grTest = sr.ReadLine();
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using libsecondlife;
|
using libsecondlife;
|
||||||
using libsecondlife.Packets;
|
using libsecondlife.Packets;
|
||||||
|
using Axiom.MathLib;
|
||||||
|
|
||||||
namespace OpenSim.world
|
namespace OpenSim.world
|
||||||
{
|
{
|
||||||
|
@ -12,16 +13,37 @@ namespace OpenSim.world
|
||||||
public string firstname;
|
public string firstname;
|
||||||
public string lastname;
|
public string lastname;
|
||||||
public OpenSimClient ControllingClient;
|
public OpenSimClient ControllingClient;
|
||||||
|
public uint CurrentKeyMask;
|
||||||
|
|
||||||
private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
|
private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
|
||||||
|
|
||||||
public Avatar(OpenSimClient TheClient) {
|
public Avatar(OpenSimClient TheClient) {
|
||||||
Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
|
Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
|
||||||
ControllingClient=TheClient;
|
ControllingClient=TheClient;
|
||||||
SetupTemplate("avatar-template.dat");
|
SetupTemplate("avatar-template.dat");
|
||||||
|
|
||||||
|
position = new LLVector3(100.0f,100.0f,60.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public override void update() {
|
||||||
base.update();
|
lock(this) {
|
||||||
|
base.update();
|
||||||
|
|
||||||
|
Console.WriteLine("KeyMask: " + this.CurrentKeyMask);
|
||||||
|
|
||||||
|
if((this.CurrentKeyMask & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_POS) != 0) {
|
||||||
|
Vector3 tmpVelocity = this.rotation * new Vector3(1.0f,0.0f,0.0f);
|
||||||
|
tmpVelocity.Normalize(); tmpVelocity = tmpVelocity * 0.3f;
|
||||||
|
this.velocity.X = tmpVelocity.x;
|
||||||
|
this.velocity.Y = tmpVelocity.y;
|
||||||
|
this.velocity.Z = tmpVelocity.z;
|
||||||
|
Console.WriteLine("Walking at "+ this.velocity.ToString());
|
||||||
|
} else {
|
||||||
|
this.velocity.X=0;
|
||||||
|
this.velocity.Y=0;
|
||||||
|
this.velocity.Z=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupTemplate(string name)
|
private void SetupTemplate(string name)
|
||||||
|
@ -41,7 +63,7 @@ namespace OpenSim.world
|
||||||
System.Text.Encoding enc = System.Text.Encoding.ASCII;
|
System.Text.Encoding enc = System.Text.Encoding.ASCII;
|
||||||
libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
|
libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
|
||||||
pos.X = 100f;
|
pos.X = 100f;
|
||||||
objdata.ID = 8880000;
|
objdata.ID = this.localid;
|
||||||
objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
|
objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
|
||||||
libsecondlife.LLVector3 pos2 = new LLVector3(100f,100f,23f);
|
libsecondlife.LLVector3 pos2 = new LLVector3(100f,100f,23f);
|
||||||
//objdata.FullID=user.AgentID;
|
//objdata.FullID=user.AgentID;
|
||||||
|
@ -60,7 +82,7 @@ namespace OpenSim.world
|
||||||
mov.Data.RegionHandle = OpenSim_Main.cfg.RegionHandle;
|
mov.Data.RegionHandle = OpenSim_Main.cfg.RegionHandle;
|
||||||
// TODO - dynamicalise this stuff
|
// TODO - dynamicalise this stuff
|
||||||
mov.Data.Timestamp = 1172750370;
|
mov.Data.Timestamp = 1172750370;
|
||||||
mov.Data.Position = new LLVector3(100f, 100f, 23f);
|
mov.Data.Position = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
|
||||||
mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
|
mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
|
||||||
|
|
||||||
Console.WriteLine("Sending AgentMovementComplete packet");
|
Console.WriteLine("Sending AgentMovementComplete packet");
|
||||||
|
@ -79,12 +101,12 @@ namespace OpenSim.world
|
||||||
|
|
||||||
objupdate.ObjectData[0] = AvatarTemplate;
|
objupdate.ObjectData[0] = AvatarTemplate;
|
||||||
//give this avatar object a local id and assign the user a name
|
//give this avatar object a local id and assign the user a name
|
||||||
objupdate.ObjectData[0].ID = 8880000 + OpenSim_Main.local_world._localNumber;
|
objupdate.ObjectData[0].ID = this.localid;
|
||||||
//User_info.name="Test"+this.local_numer+" User";
|
//User_info.name="Test"+this.local_numer+" User";
|
||||||
objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
|
objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
|
||||||
objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
|
objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
|
||||||
|
|
||||||
libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100.0f, 23.0f);
|
libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
|
||||||
|
|
||||||
byte[] pb = pos2.GetBytes();
|
byte[] pb = pos2.GetBytes();
|
||||||
|
|
||||||
|
@ -92,6 +114,68 @@ namespace OpenSim.world
|
||||||
OpenSim_Main.local_world._localNumber++;
|
OpenSim_Main.local_world._localNumber++;
|
||||||
this.ControllingClient.OutPacket(objupdate);
|
this.ControllingClient.OutPacket(objupdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() {
|
||||||
|
byte[] bytes = new byte[60];
|
||||||
|
int i=0;
|
||||||
|
ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
|
||||||
|
|
||||||
|
dat.TextureEntry = AvatarTemplate.TextureEntry;
|
||||||
|
libsecondlife.LLVector3 pos2 = new LLVector3(this.position.X, this.position.Y, this.position.Z);
|
||||||
|
|
||||||
|
uint ID = this.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 = pos2.GetBytes();
|
||||||
|
Array.Copy(pb, 0, bytes, i, pb.Length);
|
||||||
|
i += 12;
|
||||||
|
|
||||||
|
ushort ac = 32767;
|
||||||
|
bytes[i++] = (byte)(ac % 256); // avatar.InternVelocityX
|
||||||
|
bytes[i++] = (byte)((ac>> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256); // avatar.InternVelocityY
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256); // avatar.InternVelocityZ
|
||||||
|
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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void SendInitialAppearance() {
|
public void SendInitialAppearance() {
|
||||||
AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
|
AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
|
||||||
|
@ -151,5 +235,16 @@ namespace OpenSim.world
|
||||||
Console.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
|
Console.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
|
||||||
this.ControllingClient.OutPacket(handshake);
|
this.ControllingClient.OutPacket(handshake);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HandleAgentUpdate(AgentUpdatePacket update) {
|
||||||
|
lock(this) {
|
||||||
|
// FIXME: shouldn't update these direction
|
||||||
|
this.rotation = new Quaternion(update.AgentData.BodyRotation.W, update.AgentData.BodyRotation.X, update.AgentData.BodyRotation.Y, update.AgentData.BodyRotation.Z);
|
||||||
|
|
||||||
|
this.CurrentKeyMask = update.AgentData.ControlFlags;
|
||||||
|
this.needupdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,18 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Axiom.MathLib;
|
using Axiom.MathLib;
|
||||||
|
using libsecondlife;
|
||||||
using OpenSim.types;
|
using OpenSim.types;
|
||||||
|
using libsecondlife.Packets;
|
||||||
|
|
||||||
namespace OpenSim.world
|
namespace OpenSim.world
|
||||||
{
|
{
|
||||||
public class Entity
|
public class Entity
|
||||||
{
|
{
|
||||||
protected libsecondlife.LLUUID uuid;
|
protected libsecondlife.LLUUID uuid;
|
||||||
protected Vector3 position;
|
protected uint localid;
|
||||||
protected Vector3 velocity;
|
public LLVector3 position;
|
||||||
|
public LLVector3 velocity;
|
||||||
protected Quaternion rotation;
|
protected Quaternion rotation;
|
||||||
protected string name;
|
protected string name;
|
||||||
protected List<Entity> children;
|
protected List<Entity> children;
|
||||||
|
@ -19,8 +22,9 @@ namespace OpenSim.world
|
||||||
public Entity()
|
public Entity()
|
||||||
{
|
{
|
||||||
uuid = new libsecondlife.LLUUID();
|
uuid = new libsecondlife.LLUUID();
|
||||||
position = new Vector3();
|
localid = 8880000 + (OpenSim_Main.local_world._localNumber++); // FIXME - race condition!
|
||||||
velocity = new Vector3();
|
position = new LLVector3();
|
||||||
|
velocity = new LLVector3();
|
||||||
rotation = new Quaternion();
|
rotation = new Quaternion();
|
||||||
name = "(basic entity)";
|
name = "(basic entity)";
|
||||||
children = new List<Entity>();
|
children = new List<Entity>();
|
||||||
|
@ -33,8 +37,14 @@ namespace OpenSim.world
|
||||||
if(child.needupdate)
|
if(child.needupdate)
|
||||||
child.update();
|
child.update();
|
||||||
}
|
}
|
||||||
|
this.needupdate=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual string getName()
|
public virtual string getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
|
|
|
@ -18,6 +18,14 @@ namespace OpenSim.world
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoStuff(World simworld) {
|
public void DoStuff(World simworld) {
|
||||||
|
foreach (libsecondlife.LLUUID UUID in simworld.Entities.Keys)
|
||||||
|
{
|
||||||
|
if( true /* simworld.Entities[UUID].needupdate */) { // FIXME!
|
||||||
|
simworld.Entities[UUID].position += simworld.Entities[UUID].velocity;
|
||||||
|
Console.WriteLine("Moving "+UUID.ToString()+ " to "+ simworld.Entities[UUID].position.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,17 @@ namespace OpenSim.world
|
||||||
if(Entities[UUID].needupdate) {
|
if(Entities[UUID].needupdate) {
|
||||||
Entities[UUID].update();
|
Entities[UUID].update();
|
||||||
}
|
}
|
||||||
|
if(Entities[UUID] is Avatar) { // FIXME: only send updates when avatar moves.
|
||||||
|
ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = Entities[UUID].CreateTerseBlock();
|
||||||
|
foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
|
||||||
|
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
|
||||||
|
terse.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; // FIXME
|
||||||
|
terse.RegionData.TimeDilation = 0;
|
||||||
|
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
|
||||||
|
terse.ObjectData[0] = terseBlock;
|
||||||
|
client.OutPacket(terse);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue