2007-03-07 18:49:20 +00:00
using System ;
using libsecondlife ;
using libsecondlife.Packets ;
using System.Collections.Generic ;
using System.Text ;
2007-03-08 13:21:24 +00:00
using System.Reflection ;
2007-03-07 20:18:20 +00:00
using System.IO ;
2007-04-22 18:51:03 +00:00
using System.Threading ;
2007-03-22 10:11:15 +00:00
using OpenSim.Physics.Manager ;
using OpenSim.Framework.Interfaces ;
2007-04-25 13:03:48 +00:00
using OpenSim.Framework.Types ;
2007-03-22 10:11:15 +00:00
using OpenSim.Framework.Terrain ;
2007-03-31 15:54:16 +00:00
using OpenSim.Framework.Inventory ;
using OpenSim.Assets ;
2007-04-25 13:03:48 +00:00
//using OpenSim.world.scripting;
2007-04-03 16:50:17 +00:00
using OpenSim.RegionServer.world.scripting ;
2007-04-06 18:48:23 +00:00
using OpenSim.Terrain ;
2007-03-07 18:49:20 +00:00
namespace OpenSim.world
{
2007-05-17 10:24:10 +00:00
public partial class World : WorldBase , ILocalStorageReceiver , IScriptAPI
2007-03-07 18:49:20 +00:00
{
2007-03-28 13:08:27 +00:00
public object LockPhysicsEngine = new object ( ) ;
2007-04-04 16:31:35 +00:00
public Dictionary < libsecondlife . LLUUID , Avatar > Avatars ;
public Dictionary < libsecondlife . LLUUID , Primitive > Prims ;
2007-04-25 13:03:48 +00:00
//public ScriptEngine Scripts;
2007-03-30 16:50:19 +00:00
public uint _localNumber = 0 ;
private PhysicsScene phyScene ;
private float timeStep = 0.1f ;
public ILocalStorage localStorage ;
private Random Rand = new Random ( ) ;
private uint _primCount = 702000 ;
private int storageCount ;
2007-04-03 16:50:17 +00:00
private Dictionary < LLUUID , ScriptHandler > m_scriptHandlers ;
2007-04-03 20:08:30 +00:00
private Dictionary < string , ScriptFactory > m_scripts ;
2007-04-22 18:51:03 +00:00
private Mutex updateLock ;
2007-04-27 21:11:02 +00:00
public string m_datastore ;
2007-05-17 10:24:10 +00:00
#region Properties
public PhysicsScene PhysScene
{
set
{
this . phyScene = value ;
}
get
{
return ( this . phyScene ) ;
}
}
# endregion
#region Constructors
2007-04-22 03:25:18 +00:00
/// <summary>
/// Creates a new World class, and a region to go with it.
/// </summary>
/// <param name="clientThreads">Dictionary to contain client threads</param>
/// <param name="regionHandle">Region Handle for this region</param>
/// <param name="regionName">Region Name for this region</param>
2007-05-21 16:06:58 +00:00
public World ( Dictionary < uint , ClientView > clientThreads , RegionInfo regInfo , ulong regionHandle , string regionName )
2007-04-03 20:08:30 +00:00
{
2007-04-22 03:15:22 +00:00
try
{
2007-04-22 18:51:03 +00:00
updateLock = new Mutex ( false ) ;
2007-04-22 03:15:22 +00:00
m_clientThreads = clientThreads ;
m_regionHandle = regionHandle ;
m_regionName = regionName ;
2007-05-13 12:25:08 +00:00
m_regInfo = regInfo ;
2007-04-22 03:15:22 +00:00
m_scriptHandlers = new Dictionary < LLUUID , ScriptHandler > ( ) ;
m_scripts = new Dictionary < string , ScriptFactory > ( ) ;
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs - creating new entitities instance" ) ;
2007-04-22 03:15:22 +00:00
Entities = new Dictionary < libsecondlife . LLUUID , Entity > ( ) ;
Avatars = new Dictionary < LLUUID , Avatar > ( ) ;
Prims = new Dictionary < LLUUID , Primitive > ( ) ;
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs - creating LandMap" ) ;
2007-04-22 03:15:22 +00:00
TerrainManager = new TerrainManager ( new SecondLife ( ) ) ;
Terrain = new TerrainEngine ( ) ;
2007-04-30 15:38:51 +00:00
Avatar . SetupTemplate ( "avatar-texture.dat" ) ;
2007-04-22 03:15:22 +00:00
// MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
// Initialise this only after the world has loaded
// Scripts = new ScriptEngine(this);
Avatar . LoadAnims ( ) ;
this . SetDefaultScripts ( ) ;
this . LoadScriptEngines ( ) ;
}
catch ( Exception e )
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . CRITICAL , "World.cs: Constructor failed with exception " + e . ToString ( ) ) ;
2007-04-22 03:15:22 +00:00
}
2007-03-30 16:50:19 +00:00
}
2007-05-17 10:24:10 +00:00
# endregion
2007-03-30 16:50:19 +00:00
2007-05-17 10:24:10 +00:00
#region Script Methods
2007-04-22 03:25:18 +00:00
/// <summary>
/// Loads a new script into the specified entity
/// </summary>
/// <param name="entity">Entity to be scripted</param>
/// <param name="script">The script to load</param>
2007-04-03 16:50:17 +00:00
public void AddScript ( Entity entity , Script script )
{
2007-04-22 03:15:22 +00:00
try
{
ScriptHandler scriptHandler = new ScriptHandler ( script , entity , this ) ;
m_scriptHandlers . Add ( scriptHandler . ScriptId , scriptHandler ) ;
}
catch ( Exception e )
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: AddScript() - Failed with exception " + e . ToString ( ) ) ;
2007-04-22 03:15:22 +00:00
}
2007-04-03 16:50:17 +00:00
}
2007-04-22 03:25:18 +00:00
/// <summary>
/// Loads a new script into the specified entity, using a script loaded from a string.
/// </summary>
/// <param name="entity">The entity to be scripted</param>
/// <param name="scriptData">The string containing the script</param>
2007-04-03 18:15:11 +00:00
public void AddScript ( Entity entity , string scriptData )
{
2007-04-22 03:15:22 +00:00
try
{
int scriptstart = 0 ;
int scriptend = 0 ;
string substring ;
scriptstart = scriptData . LastIndexOf ( "<Script>" ) ;
scriptend = scriptData . LastIndexOf ( "</Script>" ) ;
substring = scriptData . Substring ( scriptstart + 8 , scriptend - scriptstart - 8 ) ;
substring = substring . Trim ( ) ;
//Console.WriteLine("searching for script to add: " + substring);
ScriptFactory scriptFactory ;
//Console.WriteLine("script string is " + substring);
if ( substring . StartsWith ( "<ScriptEngine:" ) )
{
string substring1 = "" ;
string script = "" ;
// Console.WriteLine("searching for script engine");
substring1 = substring . Remove ( 0 , 14 ) ;
int dev = substring1 . IndexOf ( ',' ) ;
string sEngine = substring1 . Substring ( 0 , dev ) ;
substring1 = substring1 . Remove ( 0 , dev + 1 ) ;
int end = substring1 . IndexOf ( '>' ) ;
string sName = substring1 . Substring ( 0 , end ) ;
//Console.WriteLine(" script info : " + sEngine + " , " + sName);
int startscript = substring . IndexOf ( '>' ) ;
script = substring . Remove ( 0 , startscript + 1 ) ;
// Console.WriteLine("script data is " + script);
if ( this . scriptEngines . ContainsKey ( sEngine ) )
{
this . scriptEngines [ sEngine ] . LoadScript ( script , sName , entity . localid ) ;
}
}
else if ( this . m_scripts . TryGetValue ( substring , out scriptFactory ) )
2007-04-11 09:45:48 +00:00
{
2007-04-22 03:15:22 +00:00
//Console.WriteLine("added script");
this . AddScript ( entity , scriptFactory ( ) ) ;
2007-04-11 09:45:48 +00:00
}
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
2007-04-03 18:15:11 +00:00
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: AddScript() - Failed with exception " + e . ToString ( ) ) ;
2007-04-03 18:15:11 +00:00
}
}
2007-05-17 10:24:10 +00:00
# endregion
2007-03-30 16:50:19 +00:00
2007-05-17 10:24:10 +00:00
#region Update Methods
2007-04-22 03:25:18 +00:00
/// <summary>
/// Performs per-frame updates on the world, this should be the central world loop
/// </summary>
2007-05-17 10:24:10 +00:00
public override void Update ( )
2007-03-30 16:50:19 +00:00
{
2007-04-22 18:51:03 +00:00
updateLock . WaitOne ( ) ;
try
2007-03-30 16:50:19 +00:00
{
2007-04-22 18:51:03 +00:00
if ( this . phyScene . IsThreaded )
2007-04-22 03:15:22 +00:00
{
2007-04-22 18:51:03 +00:00
this . phyScene . GetResults ( ) ;
2007-03-30 16:50:19 +00:00
2007-04-22 18:51:03 +00:00
}
2007-03-30 16:50:19 +00:00
2007-04-22 18:51:03 +00:00
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
{
Entities [ UUID ] . addForces ( ) ;
}
2007-03-28 13:08:27 +00:00
2007-04-22 18:51:03 +00:00
lock ( this . LockPhysicsEngine )
{
this . phyScene . Simulate ( timeStep ) ;
}
2007-03-30 16:50:19 +00:00
2007-04-22 18:51:03 +00:00
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
{
Entities [ UUID ] . update ( ) ;
}
2007-03-30 16:50:19 +00:00
2007-04-22 18:51:03 +00:00
foreach ( ScriptHandler scriptHandler in m_scriptHandlers . Values )
{
scriptHandler . OnFrame ( ) ;
}
foreach ( IScriptEngine scripteng in this . scriptEngines . Values )
{
scripteng . OnFrame ( ) ;
2007-04-22 03:15:22 +00:00
}
2007-04-22 18:51:03 +00:00
//backup world data
this . storageCount + + ;
if ( storageCount > 1200 ) //set to how often you want to backup
2007-04-22 03:15:22 +00:00
{
2007-04-22 18:51:03 +00:00
this . Backup ( ) ;
storageCount = 0 ;
2007-04-22 03:15:22 +00:00
}
2007-04-11 09:45:48 +00:00
}
2007-04-22 18:51:03 +00:00
catch ( Exception e )
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: Update() - Failed with exception " + e . ToString ( ) ) ;
2007-04-22 18:51:03 +00:00
}
updateLock . ReleaseMutex ( ) ;
2007-03-30 16:50:19 +00:00
}
2007-05-17 10:24:10 +00:00
public bool Backup ( )
{
try
{
// Terrain backup routines
if ( Terrain . tainted > 0 )
{
Terrain . tainted = 0 ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: Backup() - Terrain tainted, saving." ) ;
localStorage . SaveMap ( Terrain . getHeights1D ( ) ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: Backup() - Terrain saved, informing Physics." ) ;
phyScene . SetTerrain ( Terrain . getHeights1D ( ) ) ;
}
// Primitive backup routines
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: Backup() - Backing up Primitives" ) ;
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
{
Entities [ UUID ] . BackUp ( ) ;
}
// Backup successful
return true ;
}
catch ( Exception e )
{
// Backup failed
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . HIGH , "World.cs: Backup() - Backup Failed with exception " + e . ToString ( ) ) ;
return false ;
}
}
# endregion
#region Setup Methods
2007-04-22 03:25:18 +00:00
/// <summary>
/// Loads a new storage subsystem from a named library
/// </summary>
/// <param name="dllName">Storage Library</param>
/// <returns>Successful or not</returns>
2007-03-30 16:50:19 +00:00
public bool LoadStorageDLL ( string dllName )
{
2007-04-22 03:15:22 +00:00
try
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
Assembly pluginAssembly = Assembly . LoadFrom ( dllName ) ;
ILocalStorage store = null ;
foreach ( Type pluginType in pluginAssembly . GetTypes ( ) )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
if ( pluginType . IsPublic )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
if ( ! pluginType . IsAbstract )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
Type typeInterface = pluginType . GetInterface ( "ILocalStorage" , true ) ;
if ( typeInterface ! = null )
{
ILocalStorage plug = ( ILocalStorage ) Activator . CreateInstance ( pluginAssembly . GetType ( pluginType . ToString ( ) ) ) ;
store = plug ;
2007-04-27 21:11:02 +00:00
store . Initialise ( this . m_datastore ) ;
2007-04-22 03:15:22 +00:00
break ;
}
2007-03-30 16:50:19 +00:00
2007-04-22 03:15:22 +00:00
typeInterface = null ;
}
2007-03-30 16:50:19 +00:00
}
}
2007-04-22 03:15:22 +00:00
pluginAssembly = null ;
this . localStorage = store ;
return ( store = = null ) ;
}
catch ( Exception e )
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: LoadStorageDLL() - Failed with exception " + e . ToString ( ) ) ;
2007-04-22 03:16:26 +00:00
return false ;
2007-03-30 16:50:19 +00:00
}
}
2007-03-28 13:08:27 +00:00
2007-05-17 10:24:10 +00:00
public void SetDefaultScripts ( )
{
this . m_scripts . Add ( "FollowRandomAvatar" , delegate ( )
{
return new OpenSim . RegionServer . world . scripting . FollowRandomAvatar ( ) ;
} ) ;
}
# endregion
2007-04-06 13:04:46 +00:00
#region Regenerate Terrain
2007-04-22 03:25:18 +00:00
/// <summary>
/// Rebuilds the terrain using a procedural algorithm
/// </summary>
2007-03-28 13:08:27 +00:00
public void RegenerateTerrain ( )
{
2007-04-22 03:15:22 +00:00
try
2007-03-28 13:08:27 +00:00
{
2007-04-22 03:15:22 +00:00
Terrain . hills ( ) ;
2007-03-28 13:08:27 +00:00
2007-04-22 03:15:22 +00:00
lock ( this . LockPhysicsEngine )
{
this . phyScene . SetTerrain ( Terrain . getHeights1D ( ) ) ;
}
this . localStorage . SaveMap ( this . Terrain . getHeights1D ( ) ) ;
2007-03-28 13:08:27 +00:00
2007-05-21 16:06:58 +00:00
foreach ( ClientView client in m_clientThreads . Values )
2007-04-22 03:15:22 +00:00
{
this . SendLayerData ( client ) ;
}
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
{
Entities [ UUID ] . LandRenegerated ( ) ;
}
}
catch ( Exception e )
2007-03-28 13:08:27 +00:00
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: RegenerateTerrain() - Failed with exception " + e . ToString ( ) ) ;
2007-03-28 13:08:27 +00:00
}
}
2007-04-22 03:25:18 +00:00
/// <summary>
/// Rebuilds the terrain using a 2D float array
/// </summary>
/// <param name="newMap">256,256 float array containing heights</param>
2007-04-06 18:48:23 +00:00
public void RegenerateTerrain ( float [ , ] newMap )
2007-03-28 13:08:27 +00:00
{
2007-04-22 03:15:22 +00:00
try
2007-03-28 13:08:27 +00:00
{
2007-04-22 03:15:22 +00:00
this . Terrain . setHeights2D ( newMap ) ;
lock ( this . LockPhysicsEngine )
{
this . phyScene . SetTerrain ( this . Terrain . getHeights1D ( ) ) ;
}
this . localStorage . SaveMap ( this . Terrain . getHeights1D ( ) ) ;
2007-03-28 13:08:27 +00:00
2007-05-21 16:06:58 +00:00
foreach ( ClientView client in m_clientThreads . Values )
2007-04-22 03:15:22 +00:00
{
this . SendLayerData ( client ) ;
}
2007-03-28 13:08:27 +00:00
2007-04-22 03:15:22 +00:00
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
{
Entities [ UUID ] . LandRenegerated ( ) ;
}
}
catch ( Exception e )
2007-03-28 13:08:27 +00:00
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: RegenerateTerrain() - Failed with exception " + e . ToString ( ) ) ;
2007-03-28 13:08:27 +00:00
}
}
2007-03-30 16:50:19 +00:00
2007-04-22 03:25:18 +00:00
/// <summary>
/// Rebuilds the terrain assuming changes occured at a specified point[?]
/// </summary>
/// <param name="changes">???</param>
/// <param name="pointx">???</param>
/// <param name="pointy">???</param>
2007-03-30 16:50:19 +00:00
public void RegenerateTerrain ( bool changes , int pointx , int pointy )
{
2007-04-22 03:15:22 +00:00
try
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
if ( changes )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
lock ( this . LockPhysicsEngine )
{
this . phyScene . SetTerrain ( this . Terrain . getHeights1D ( ) ) ;
}
this . localStorage . SaveMap ( this . Terrain . getHeights1D ( ) ) ;
2007-03-30 16:50:19 +00:00
2007-05-21 16:06:58 +00:00
foreach ( ClientView client in m_clientThreads . Values )
2007-04-22 03:15:22 +00:00
{
this . SendLayerData ( pointx , pointy , client ) ;
}
2007-03-30 16:50:19 +00:00
}
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: RegenerateTerrain() - Failed with exception " + e . ToString ( ) ) ;
2007-04-22 03:15:22 +00:00
}
2007-03-30 16:50:19 +00:00
}
2007-04-06 13:04:46 +00:00
# endregion
2007-05-17 10:24:10 +00:00
#region Load Terrain
2007-04-22 03:25:18 +00:00
/// <summary>
/// Loads the World heightmap
/// </summary>
2007-05-17 10:24:10 +00:00
public override void LoadWorldMap ( )
2007-04-02 10:46:59 +00:00
{
2007-04-22 03:15:22 +00:00
try
2007-04-06 19:25:29 +00:00
{
2007-04-22 03:15:22 +00:00
float [ ] map = this . localStorage . LoadWorld ( ) ;
if ( map = = null )
{
Console . WriteLine ( "creating new terrain" ) ;
this . Terrain . hills ( ) ;
2007-04-17 12:25:20 +00:00
2007-04-22 03:15:22 +00:00
this . localStorage . SaveMap ( this . Terrain . getHeights1D ( ) ) ;
}
else
{
this . Terrain . setHeights1D ( map ) ;
}
2007-04-06 19:25:29 +00:00
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
2007-04-06 19:25:29 +00:00
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: LoadWorldMap() - Failed with exception " + e . ToString ( ) ) ;
2007-04-06 19:25:29 +00:00
}
2007-04-02 10:46:59 +00:00
}
2007-05-17 10:24:10 +00:00
# endregion
#region Primitives Methods
/// <summary>
/// Sends prims to a client
/// </summary>
/// <param name="RemoteClient">Client to send to</param>
2007-05-21 16:06:58 +00:00
public void GetInitialPrims ( ClientView RemoteClient )
2007-05-17 10:24:10 +00:00
{
try
{
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
{
if ( Entities [ UUID ] is Primitive )
{
Primitive primitive = Entities [ UUID ] as Primitive ;
primitive . UpdateClient ( RemoteClient ) ;
}
}
}
catch ( Exception e )
{
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: GetInitialPrims() - Failed with exception " + e . ToString ( ) ) ;
}
}
2007-04-02 10:46:59 +00:00
2007-04-22 03:25:18 +00:00
/// <summary>
/// Loads the World's objects
/// </summary>
2007-03-30 16:50:19 +00:00
public void LoadPrimsFromStorage ( )
{
2007-04-22 03:15:22 +00:00
try
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: LoadPrimsFromStorage() - Loading primitives" ) ;
2007-04-22 03:15:22 +00:00
this . localStorage . LoadPrimitives ( this ) ;
}
catch ( Exception e )
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: LoadPrimsFromStorage() - Failed with exception " + e . ToString ( ) ) ;
2007-04-22 03:15:22 +00:00
}
2007-03-30 16:50:19 +00:00
}
2007-04-22 03:25:18 +00:00
/// <summary>
/// Loads a specific object from storage
/// </summary>
/// <param name="prim">The object to load</param>
2007-03-30 16:50:19 +00:00
public void PrimFromStorage ( PrimData prim )
{
2007-04-22 03:15:22 +00:00
try
{
if ( prim . LocalID > = this . _primCount )
{
_primCount = prim . LocalID + 1 ;
}
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: PrimFromStorage() - Reloading prim (localId " + prim . LocalID + " ) from storage" ) ;
2007-04-22 03:15:22 +00:00
Primitive nPrim = new Primitive ( m_clientThreads , m_regionHandle , this ) ;
nPrim . CreateFromStorage ( prim ) ;
this . Entities . Add ( nPrim . uuid , nPrim ) ;
}
catch ( Exception e )
2007-03-30 16:50:19 +00:00
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: PrimFromStorage() - Failed with exception " + e . ToString ( ) ) ;
2007-03-30 16:50:19 +00:00
}
}
2007-05-21 16:06:58 +00:00
public void AddNewPrim ( ObjectAddPacket addPacket , ClientView AgentClient )
2007-05-21 00:11:55 +00:00
{
AddNewPrim ( addPacket , AgentClient . AgentID ) ;
}
public void AddNewPrim ( ObjectAddPacket addPacket , LLUUID ownerID )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
try
2007-03-30 16:50:19 +00:00
{
2007-05-17 10:24:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: AddNewPrim() - Creating new prim" ) ;
Primitive prim = new Primitive ( m_clientThreads , m_regionHandle , this ) ;
2007-05-21 00:11:55 +00:00
prim . CreateFromPacket ( addPacket , ownerID , this . _primCount ) ;
2007-05-17 10:24:10 +00:00
PhysicsVector pVec = new PhysicsVector ( prim . Pos . X , prim . Pos . Y , prim . Pos . Z ) ;
PhysicsVector pSize = new PhysicsVector ( 0.255f , 0.255f , 0.255f ) ;
if ( OpenSim . world . Avatar . PhysicsEngineFlying )
2007-03-30 16:50:19 +00:00
{
2007-05-17 10:24:10 +00:00
lock ( this . LockPhysicsEngine )
2007-04-22 03:15:22 +00:00
{
2007-05-17 10:24:10 +00:00
prim . PhysActor = this . phyScene . AddPrim ( pVec , pSize ) ;
2007-04-22 03:15:22 +00:00
}
2007-03-30 16:50:19 +00:00
}
2007-04-22 03:15:22 +00:00
2007-05-17 10:24:10 +00:00
this . Entities . Add ( prim . uuid , prim ) ;
this . _primCount + + ;
2007-04-22 03:15:22 +00:00
}
catch ( Exception e )
{
2007-05-17 10:24:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: AddNewPrim() - Failed with exception " + e . ToString ( ) ) ;
2007-04-22 03:15:22 +00:00
}
2007-03-30 16:50:19 +00:00
}
2007-04-04 18:26:33 +00:00
2007-05-17 10:24:10 +00:00
# endregion
#region Add/Remove Avatar Methods
2007-03-30 16:50:19 +00:00
2007-05-21 16:06:58 +00:00
public override void AddViewerAgent ( ClientView agentClient )
2007-03-28 13:08:27 +00:00
{
2007-05-21 19:12:18 +00:00
//register for events
2007-05-21 16:06:58 +00:00
agentClient . OnChatFromViewer + = new ClientView . ChatFromViewer ( this . SimChat ) ;
2007-05-21 19:12:18 +00:00
agentClient . OnRezObject + = new ClientView . RezObject ( this . RezObject ) ;
agentClient . OnModifyTerrain + = new ClientView . ModifyTerrain ( this . ModifyTerrain ) ;
agentClient . OnRegionHandShakeReply + = new ClientView . GenericCall ( this . SendLayerData ) ;
agentClient . OnRequestWearables + = new ClientView . GenericCall ( this . GetInitialPrims ) ;
2007-05-22 11:25:34 +00:00
agentClient . OnRequestAvatarsData + = new ClientView . GenericCall ( this . SendAvatarsToClient ) ;
2007-04-22 03:15:22 +00:00
try
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent" ) ;
2007-04-25 18:12:06 +00:00
Avatar newAvatar = new Avatar ( agentClient , this , m_regionName , m_clientThreads , m_regionHandle , true , 20 ) ;
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs:AddViewerAgent() - Adding new avatar to world" ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs:AddViewerAgent() - Starting RegionHandshake " ) ;
2007-04-22 03:15:22 +00:00
newAvatar . SendRegionHandshake ( this ) ;
if ( ! agentClient . m_child )
2007-04-17 12:25:20 +00:00
{
2007-04-22 03:15:22 +00:00
PhysicsVector pVec = new PhysicsVector ( newAvatar . Pos . X , newAvatar . Pos . Y , newAvatar . Pos . Z ) ;
lock ( this . LockPhysicsEngine )
{
newAvatar . PhysActor = this . phyScene . AddAvatar ( pVec ) ;
}
}
lock ( Entities )
{
2007-05-14 19:31:05 +00:00
if ( ! Entities . ContainsKey ( agentClient . AgentID ) )
{
this . Entities . Add ( agentClient . AgentID , newAvatar ) ;
}
else
{
Entities [ agentClient . AgentID ] = newAvatar ;
}
2007-04-22 03:15:22 +00:00
}
lock ( Avatars )
{
2007-05-14 19:31:05 +00:00
if ( Avatars . ContainsKey ( agentClient . AgentID ) )
{
Avatars [ agentClient . AgentID ] = newAvatar ;
}
else
{
this . Avatars . Add ( agentClient . AgentID , newAvatar ) ;
}
2007-04-17 12:25:20 +00:00
}
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
2007-04-17 12:25:20 +00:00
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: AddViewerAgent() - Failed with exception " + e . ToString ( ) ) ;
2007-04-17 12:25:20 +00:00
}
2007-04-04 18:26:33 +00:00
}
2007-05-21 16:06:58 +00:00
public override void RemoveViewerAgent ( ClientView agentClient )
2007-04-04 18:26:33 +00:00
{
2007-04-22 03:15:22 +00:00
try
2007-04-04 18:26:33 +00:00
{
2007-04-22 03:15:22 +00:00
lock ( Entities )
{
Entities . Remove ( agentClient . AgentID ) ;
}
lock ( Avatars )
{
Avatars . Remove ( agentClient . AgentID ) ;
}
2007-05-15 21:26:10 +00:00
if ( agentClient . ClientAvatar . PhysActor ! = null )
{
2007-05-19 18:32:01 +00:00
//this.phyScene.RemoveAvatar(agentClient.ClientAvatar.PhysActor);
2007-05-15 21:26:10 +00:00
}
2007-04-04 18:26:33 +00:00
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
2007-04-04 18:26:33 +00:00
{
2007-05-21 00:11:55 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: RemoveViewerAgent() - Failed with exception " + e . ToString ( ) ) ;
2007-03-28 13:08:27 +00:00
}
2007-03-30 16:50:19 +00:00
}
2007-05-17 10:24:10 +00:00
# endregion
2007-03-30 16:50:19 +00:00
2007-05-21 16:06:58 +00:00
#region Request Avatars List Methods
//The idea is to have a group of method that return a list of avatars meeting some requirement
// ie it could be all Avatars within a certain range of the calling prim/avatar.
public List < Avatar > RequestAvatarList ( )
{
List < Avatar > result = new List < Avatar > ( ) ;
foreach ( Avatar avatar in Avatars . Values )
{
result . Add ( avatar ) ;
}
return result ;
}
# endregion
2007-05-17 10:24:10 +00:00
#region ShutDown
/// <summary>
/// Tidy before shutdown
/// </summary>
public override void Close ( )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
try
2007-04-21 05:51:10 +00:00
{
2007-05-17 10:24:10 +00:00
this . localStorage . ShutDown ( ) ;
2007-04-21 05:51:10 +00:00
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
2007-03-30 16:50:19 +00:00
{
2007-05-17 10:24:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . HIGH , "World.cs: Close() - Failed with exception " + e . ToString ( ) ) ;
2007-03-30 16:50:19 +00:00
}
2007-03-24 16:06:43 +00:00
}
2007-05-17 10:24:10 +00:00
# endregion
2007-04-03 18:15:11 +00:00
}
2007-03-07 18:49:20 +00:00
}