From bf2f3ea29ab045cf8fe1e8223adb176e11c14569 Mon Sep 17 00:00:00 2001
From: MW
Date: Sun, 15 Jul 2007 21:10:05 +0000
Subject: Hijacked simpleApp again (sorry lbsa71, guess I should create my own
simpleApp), to try out a basic test npc character(/class).
---
.../Environment/Scenes/Scene.PacketHandlers.cs | 3 +-
OpenSim/Region/Environment/Scenes/Scene.cs | 4 +-
OpenSim/Region/Environment/Scenes/ScenePresence.cs | 7 +-
.../Region/Examples/SimpleApp/MyNpcCharacter.cs | 174 +++++++++++++++++++++
OpenSim/Region/Examples/SimpleApp/MyWorld.cs | 27 +++-
OpenSim/Region/Examples/SimpleApp/Program.cs | 25 ++-
6 files changed, 225 insertions(+), 15 deletions(-)
create mode 100644 OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
index 1445edf..6431bc7 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
@@ -139,8 +139,7 @@ namespace OpenSim.Region.Environment.Scenes
///
public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
{
- // Console.WriteLine("Chat message");
- ScenePresence avatar = null;
+ ScenePresence avatar = null;
if (this.Avatars.ContainsKey(fromAgentID))
{
avatar = this.Avatars[fromAgentID];
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index a06679a..bb9fa61 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -55,8 +55,8 @@ namespace OpenSim.Region.Environment.Scenes
protected Timer m_heartbeatTimer = new Timer();
protected Dictionary Avatars;
protected Dictionary Prims;
- private PhysicsScene phyScene;
- private float timeStep = 0.1f;
+ protected PhysicsScene phyScene;
+ protected float timeStep = 0.1f;
private Random Rand = new Random();
private uint _primCount = 702000;
private System.Threading.Mutex _primAllocateMutex = new Mutex(false);
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index 6966989..3558ca3 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -57,7 +57,10 @@ namespace OpenSim.Region.Environment.Scenes
private byte[] visualParams;
private AvatarWearable[] Wearables;
private ulong m_regionHandle;
- private bool childAgent = false;
+
+ public bool childAgent = false;
+ public bool IsRestrictedToRegion = false;
+
private bool newForce = false;
private bool newAvatar = false;
private IScenePresenceBody m_body;
@@ -72,7 +75,7 @@ namespace OpenSim.Region.Environment.Scenes
DIR_CONTROL_FLAG_LEFT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_POS,
DIR_CONTROL_FLAG_RIGHT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_NEG,
DIR_CONTROL_FLAG_UP = MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS,
- DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG
+ DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG
}
///
/// Position at which a significant movement was made
diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
new file mode 100644
index 0000000..1c267c6
--- /dev/null
+++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
@@ -0,0 +1,174 @@
+using System.Collections.Generic;
+using System.Net;
+using System.Timers;
+using System;
+using System.Text;
+
+using libsecondlife;
+using libsecondlife.Packets;
+
+using OpenSim.Framework;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Types;
+using OpenSim.Framework.Data;
+using OpenSim.Framework.Utilities;
+
+namespace SimpleApp
+{
+ public class MyNpcCharacter : IClientAPI
+ {
+ private uint movementDirection = 0;
+ private bool fly = true;
+ private LLQuaternion bodyDirection = LLQuaternion.Identity;
+
+ public event ImprovedInstantMessage OnInstantMessage;
+ public event ChatFromViewer OnChatFromViewer;
+ public event RezObject OnRezObject;
+ public event ModifyTerrain OnModifyTerrain;
+ public event SetAppearance OnSetAppearance;
+ public event StartAnim OnStartAnim;
+ public event LinkObjects OnLinkObjects;
+ public event RequestMapBlocks OnRequestMapBlocks;
+ public event TeleportLocationRequest OnTeleportLocationRequest;
+
+ public event GenericCall4 OnDeRezObject;
+ public event GenericCall OnRegionHandShakeReply;
+ public event GenericCall OnRequestWearables;
+ public event GenericCall2 OnCompleteMovementToRegion;
+ public event UpdateAgent OnAgentUpdate;
+ public event GenericCall OnRequestAvatarsData;
+ public event AddNewPrim OnAddPrim;
+ public event ObjectDuplicate OnObjectDuplicate;
+ public event UpdateVector OnGrapObject;
+ public event ObjectSelect OnDeGrapObject;
+ public event MoveObject OnGrapUpdate;
+
+ public event UpdateShape OnUpdatePrimShape;
+ public event ObjectSelect OnObjectSelect;
+ public event GenericCall7 OnObjectDescription;
+ public event GenericCall7 OnObjectName;
+ public event UpdatePrimFlags OnUpdatePrimFlags;
+ public event UpdatePrimTexture OnUpdatePrimTexture;
+ public event UpdateVector OnUpdatePrimGroupPosition;
+ public event UpdateVector OnUpdatePrimSinglePosition;
+ public event UpdatePrimRotation OnUpdatePrimGroupRotation;
+ public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
+ public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
+ public event UpdateVector OnUpdatePrimScale;
+ public event StatusChange OnChildAgentStatus;
+ public event GenericCall2 OnStopMovement;
+ public event NewAvatar OnNewAvatar;
+ public event GenericCall6 OnRemoveAvatar;
+
+ public event UUIDNameRequest OnNameFromUUIDRequest;
+
+ public event ParcelPropertiesRequest OnParcelPropertiesRequest;
+ public event ParcelDivideRequest OnParcelDivideRequest;
+ public event ParcelJoinRequest OnParcelJoinRequest;
+ public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
+
+ public event ParcelSelectObjects OnParcelSelectObjects;
+
+ public event EstateOwnerMessageRequest OnEstateOwnerMessage;
+
+ private LLUUID myID = LLUUID.Random();
+ public MyNpcCharacter()
+ {
+
+ }
+
+ public virtual LLVector3 StartPos
+ {
+ get { return new LLVector3(128, 100, 2); }
+ set { }
+ }
+
+ public virtual LLUUID AgentId
+ {
+ get { return myID; }
+ }
+
+ public virtual string FirstName
+ {
+ get { return "Annoying"; }
+ }
+
+ public virtual string LastName
+ {
+ get { return "NPC"; }
+ }
+
+ public virtual void OutPacket(Packet newPack) { }
+ public virtual void SendWearables(AvatarWearable[] wearables) { }
+ public virtual void SendStartPingCheck(byte seq) { }
+ public virtual void SendKillObject(ulong regionHandle, uint avatarLocalID) { }
+ public virtual void SendAnimation(LLUUID animID, int seq, LLUUID sourceAgentId) { }
+ public virtual void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) { }
+ public virtual void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) { }
+ public virtual void SendInstantMessage(string message, LLUUID target, string fromName) { }
+ public virtual void SendLayerData(float[] map) { }
+ public virtual void SendLayerData(int px, int py, float[] map) { }
+ public virtual void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look) { }
+ public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint) { }
+ public virtual AgentCircuitData RequestClientInfo() { return new AgentCircuitData(); }
+ public virtual void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint newRegionExternalEndPoint) { }
+ public virtual void SendMapBlock(List mapBlocks) { }
+ public virtual void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags) { }
+ public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, uint locationID, uint flags) { }
+ public virtual void SendTeleportCancel() { }
+ public virtual void SendTeleportLocationStart() { }
+ public virtual void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance) { }
+
+ public virtual void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos, byte[] textureEntry) { }
+ public virtual void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLVector3 velocity) { }
+
+ public virtual void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint) { }
+ public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID textureID, uint flags) { }
+ public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLUUID textureID, uint flags) { }
+ public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, LLQuaternion rotation, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID) { }
+ public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID) { }
+ public virtual void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLQuaternion rotation) { }
+
+ public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List items) { }
+ public virtual void SendInventoryItemDetails(LLUUID ownerID, LLUUID folderID, InventoryItemBase item) { }
+ public virtual void SendNameReply(LLUUID profileId, string firstname, string lastname) { }
+
+ public virtual void SendRegionHandshake(RegionInfo regionInfo)
+ {
+ this.OnRegionHandShakeReply(this);
+ this.OnCompleteMovementToRegion();
+ this.StartMovement();
+ }
+
+ public void StartMovement()
+ {
+ Timer timer = new Timer();
+ timer.Enabled = true;
+ timer.Interval = 10000;
+ timer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
+ }
+
+ public void Heartbeat(object sender, EventArgs e)
+ {
+
+ Encoding enc = Encoding.ASCII;
+
+ this.OnAgentUpdate(this, movementDirection, bodyDirection);
+
+ if (this.fly)
+ {
+ movementDirection = (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY | (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG;
+ fly = false;
+ }
+ else
+ {
+ movementDirection = (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY | (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS;
+ fly = true;
+ }
+
+ this.OnChatFromViewer(enc.GetBytes("Kind of quiet around here isn't it! \0"), 2, new LLVector3(128, 128, 26), this.FirstName + " " + this.LastName, this.AgentId);
+
+
+ }
+ }
+}
diff --git a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs
index 777d4ae..29b255b 100644
--- a/OpenSim/Region/Examples/SimpleApp/MyWorld.cs
+++ b/OpenSim/Region/Examples/SimpleApp/MyWorld.cs
@@ -47,14 +47,15 @@ namespace SimpleApp
LLVector3 pos = new LLVector3(128, 128, 128);
client.OnRegionHandShakeReply += SendLayerData;
- client.OnChatFromViewer +=
+ /*client.OnChatFromViewer +=
delegate(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
{
// Echo it (so you know what you typed)
client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
client.SendChatMessage("Ready.", 1, pos, "System", LLUUID.Zero );
};
-
+ */
+ client.OnChatFromViewer += this.SimChat;
client.OnAddPrim += AddNewPrim;
client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition;
client.OnRequestMapBlocks += this.RequestMapBlocks;
@@ -70,9 +71,27 @@ namespace SimpleApp
client.SendRegionHandshake(m_regInfo);
ScenePresence avatar = CreateAndAddScenePresence(client);
- avatar.Pos = new LLVector3(128, 128, 26);
+ avatar.Pos = new LLVector3(128, 128, 26);
}
-
+
+ public override void Update()
+ {
+ foreach (LLUUID UUID in Entities.Keys)
+ {
+ Entities[UUID].updateMovement();
+ }
+
+ lock (this.m_syncRoot)
+ {
+ this.phyScene.Simulate(timeStep);
+ }
+
+ foreach (LLUUID UUID in Entities.Keys)
+ {
+ Entities[UUID].update();
+ }
+ }
+
#endregion
}
}
diff --git a/OpenSim/Region/Examples/SimpleApp/Program.cs b/OpenSim/Region/Examples/SimpleApp/Program.cs
index 82a62a3..0c688ba 100644
--- a/OpenSim/Region/Examples/SimpleApp/Program.cs
+++ b/OpenSim/Region/Examples/SimpleApp/Program.cs
@@ -15,6 +15,7 @@ using OpenSim.Region.Communications.Local;
using OpenSim.Region.GridInterfaces.Local;
using System.Timers;
using OpenSim.Region.Environment.Scenes;
+using OpenSim.Framework.Data;
namespace SimpleApp
{
@@ -25,6 +26,7 @@ namespace SimpleApp
uint m_localId;
public MyWorld world;
private SceneObject m_sceneObject;
+ public MyNpcCharacter m_character;
private void Run()
{
@@ -65,22 +67,35 @@ namespace SimpleApp
world.PhysScene = physManager.GetPhysicsScene("basicphysics"); //PhysicsScene.Null;
world.LoadWorldMap();
- world.ParcelManager.NoParcelDataFromStorage();
+ world.PhysScene.SetTerrain(world.Terrain.getHeights1D());
udpServer.LocalWorld = world;
httpServer.Start();
udpServer.ServerListener();
+ UserProfileData masterAvatar = communicationsManager.UserServer.SetupMasterUser("Test", "User", "test");
+ if (masterAvatar != null)
+ {
+ world.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.UUID;
+ world.ParcelManager.NoParcelDataFromStorage();
+ }
+
PrimitiveBaseShape shape = PrimitiveBaseShape.DefaultBox();
shape.Scale = new LLVector3(0.5f, 0.5f, 0.5f);
- LLVector3 pos = new LLVector3(129, 129, 27);
+ LLVector3 pos = new LLVector3(138, 129, 27);
+
+ m_sceneObject = new MySceneObject(world, world.EventManager, LLUUID.Zero, world.PrimIDAllocate(), pos, shape);
+ world.AddNewEntity(m_sceneObject);
+
+ m_character = new MyNpcCharacter();
+ world.AddNewClient(m_character, false);
+
+ world.StartTimer();
- m_sceneObject = new MySceneObject(world,world.EventManager, LLUUID.Zero, world.PrimIDAllocate(), pos, shape);
- world.AddNewEntity(m_sceneObject);
-
m_log.WriteLine(LogPriority.NORMAL, "Press enter to quit.");
m_log.ReadLine();
+
}
#region conscmd_callback Members
--
cgit v1.1