<commit_before>using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using libsecondlife;
using libsecondlife.Packets;
using Axiom.MathLib;

namespace OpenSim.world
{
    public class Avatar : Entity
    {
	public string firstname;
        public string lastname;
	public OpenSimClient ControllingClient;
	public LLVector3 oldvel;
	public LLVector3 oldpos;
	public uint CurrentKeyMask;
	public bool walking;

	private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;

        public Avatar(OpenSimClient TheClient) {
        	Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
		ControllingClient=TheClient;
		SetupTemplate("avatar-template.dat");

		position = new LLVector3(100.0f,100.0f,60.0f);
	}

	public override void update() {
		lock(this) {
			base.update();

			Console.WriteLine("KeyMask: " + this.CurrentKeyMask);
	
			oldvel=this.velocity;
			oldpos=this.position;
			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.5f;
				this.velocity.X = tmpVelocity.x;
				this.velocity.Y = tmpVelocity.y;
				this.velocity.Z = tmpVelocity.z;
				Console.WriteLine("Walking at "+ this.velocity.ToString());
				this.walking=true;
			} else {
				this.velocity.X=0;
				this.velocity.Y=0;
				this.velocity.Z=0;
				this.walking=false;
			}
		}
	}

	private void SetupTemplate(string name)
		{
			
			int i = 0;
			FileInfo fInfo = new FileInfo(name);
			long numBytes = fInfo.Length;
			FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
			BinaryReader br = new BinaryReader(fStream);
			byte [] data1 = br.ReadBytes((int)numBytes);
			br.Close();
			fStream.Close();
			
			libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
			
			System.Text.Encoding enc = System.Text.Encoding.ASCII;
			libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
			pos.X = 100f;
			objdata.ID = this.localid;
			objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
			libsecondlife.LLVector3 pos2 = new LLVector3(100f,100f,23f);
			//objdata.FullID=user.AgentID;
			byte[] pb = pos.GetBytes();			
			Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
			
			AvatarTemplate = objdata;
				
		}

	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 = 1172750370;
		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);
		
		Console.WriteLine("Sending AgentMovementComplete packet");
		ControllingClient.OutPacket(mov);
	}

	public void SendInitialPosition() {
		System.Text.Encoding _enc = System.Text.Encoding.ASCII;
		

		//send a objectupdate packet with information about the clients avatar
		ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
		objupdate.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle;
		objupdate.RegionData.TimeDilation = 64096;
		objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
			
		objupdate.ObjectData[0] = AvatarTemplate;
		//give this avatar object a local id and assign the user a name
		objupdate.ObjectData[0].ID = this.localid; 
		//User_info.name="Test"+this.local_numer+" User";
		objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
		objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
			
		libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
		
		byte[] pb = pos2.GetBytes();
						
		Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
		OpenSim_Main.local_world._localNumber++;
		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);<commit_msg>Added MW's fix for smooth movement<commit_after>using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using libsecondlife;
using libsecondlife.Packets;
using Axiom.MathLib;

namespace OpenSim.world
{
    public class Avatar : Entity
    {
	public string firstname;
        public string lastname;
	public OpenSimClient ControllingClient;
	public LLVector3 oldvel;
	public LLVector3 oldpos;
	public uint CurrentKeyMask;
	public bool walking;

	private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;

        public Avatar(OpenSimClient TheClient) {
        	Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
		ControllingClient=TheClient;
		SetupTemplate("avatar-template.dat");

		position = new LLVector3(100.0f,100.0f,60.0f);
	}

	public override void update() {
		lock(this) {
			base.update();

			Console.WriteLine("KeyMask: " + this.CurrentKeyMask);
	
			oldvel=this.velocity;
			oldpos=this.position;
			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.5f;
				this.velocity.X = tmpVelocity.x;
				this.velocity.Y = tmpVelocity.y;
				this.velocity.Z = tmpVelocity.z;
				Console.WriteLine("Walking at "+ this.velocity.ToString());
				this.walking=true;
			} else {
				this.velocity.X=0;
				this.velocity.Y=0;
				this.velocity.Z=0;
				this.walking=false;
			}
		}
	}

	private void SetupTemplate(string name)
		{
			
			int i = 0;
			FileInfo fInfo = new FileInfo(name);
			long numBytes = fInfo.Length;
			FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
			BinaryReader br = new BinaryReader(fStream);
			byte [] data1 = br.ReadBytes((int)numBytes);
			br.Close();
			fStream.Close();
			
			libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
			
			System.Text.Encoding enc = System.Text.Encoding.ASCII;
			libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
			pos.X = 100f;
			objdata.ID = this.localid;
			objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
			libsecondlife.LLVector3 pos2 = new LLVector3(100f,100f,23f);
			//objdata.FullID=user.AgentID;
			byte[] pb = pos.GetBytes();			
			Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
			
			AvatarTemplate = objdata;
				
		}

	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 = 1172750370;
		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);
		
		Console.WriteLine("Sending AgentMovementComplete packet");
		ControllingClient.OutPacket(mov);
	}

	public void SendInitialPosition() {
		System.Text.Encoding _enc = System.Text.Encoding.ASCII;
		

		//send a objectupdate packet with information about the clients avatar
		ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
		objupdate.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle;
		objupdate.RegionData.TimeDilation = 64096;
		objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
			
		objupdate.ObjectData[0] = AvatarTemplate;
		//give this avatar object a local id and assign the user a name
		objupdate.ObjectData[0].ID = this.localid; 
		//User_info.name="Test"+this.local_numer+" User";
		objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
		objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
			
		libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
		
		byte[] pb = pos2.GetBytes();
						
		Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
		OpenSim_Main.local_world._localNumber++;
		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)((ushort)(((this.velocity.X/128f)+1)*32767) % 256 );
                        bytes[i++] = (byte)(((ushort)(((this.velocity.X/128f)+1)*32767) >> 8) % 256);
                        bytes[i++] = (byte)((ushort)(((this.velocity.Y/128f)+1)*32767) % 256);
                        bytes[i++] = (byte)(((ushort)(((this.velocity.Y/128f)+1)*32767) >> 8) % 256);
                        bytes[i++] = (byte)((ushort)(((this.velocity.Z/128f)+1)*32767) % 256);
                        bytes[i++] = (byte)(((ushort)(((this.velocity.Z/128f)+1)*32767) >> 8) % 256);



			
			//accel
			bytes[i++] = (byte)(ac % 256);
			bytes[i++] = (byte)((ac >> 8) % 256);
			bytes[i++] = (byte)(ac % 256);
{'fraction_non_alphanumeric': 0.13959500215424386, 'fraction_numerical': 0.03291684618698837, 'mean_word_length': 3.8908554572271385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7107890', 'n_tokens_mistral': 4624, 'n_tokens_neox': 3879, 'n_words': 763}