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-03 20:08:30 +00:00
using OpenSim.RegionServer.world.scripting.Scripts ;
2007-04-06 18:48:23 +00:00
using OpenSim.Terrain ;
2007-03-07 18:49:20 +00:00
namespace OpenSim.world
{
2007-04-11 09:45:48 +00:00
public partial class World : ILocalStorageReceiver , IScriptAPI
2007-03-07 18:49:20 +00:00
{
2007-03-28 13:08:27 +00:00
public object LockPhysicsEngine = new object ( ) ;
2007-03-30 16:50:19 +00:00
public Dictionary < libsecondlife . LLUUID , Entity > Entities ;
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-04-06 18:48:23 +00:00
public TerrainEngine Terrain ; //TODO: Replace TerrainManager with this.
2007-03-30 16:50:19 +00:00
public uint _localNumber = 0 ;
private PhysicsScene phyScene ;
private float timeStep = 0.1f ;
2007-04-22 03:28:58 +00:00
private libsecondlife . TerrainManager TerrainManager ; // To be referenced via TerrainEngine
2007-03-30 16:50:19 +00:00
public ILocalStorage localStorage ;
private Random Rand = new Random ( ) ;
private uint _primCount = 702000 ;
private int storageCount ;
2007-03-28 13:08:27 +00:00
private Dictionary < uint , SimClient > m_clientThreads ;
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-03-28 13:08:27 +00:00
private ulong m_regionHandle ;
private string m_regionName ;
2007-03-31 15:54:16 +00:00
private InventoryCache _inventoryCache ;
private AssetCache _assetCache ;
2007-04-22 18:51:03 +00:00
private Mutex updateLock ;
2007-05-13 12:25:08 +00:00
private RegionInfo m_regInfo ;
2007-04-27 21:11:02 +00:00
public string m_datastore ;
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-13 12:25:08 +00:00
public World ( Dictionary < uint , SimClient > 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-12 15:32:04 +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-12 15:32:04 +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-12 15:32:04 +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-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-12 15:32:04 +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-12 15:32:04 +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-03-31 15:54:16 +00:00
public InventoryCache InventoryCache
{
set
{
this . _inventoryCache = value ;
}
}
public AssetCache AssetCache
{
set
{
this . _assetCache = value ;
}
}
2007-03-30 16:50:19 +00:00
public PhysicsScene PhysScene
{
set
{
this . phyScene = value ;
}
get
{
return ( this . phyScene ) ;
}
}
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-03-30 16:50:19 +00:00
public void Update ( )
{
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-12 15:32:04 +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-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-12 15:32:04 +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-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-04-22 03:15:22 +00:00
foreach ( SimClient client in m_clientThreads . Values )
{
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-12 15:32:04 +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-04-22 03:15:22 +00:00
foreach ( SimClient client in m_clientThreads . Values )
{
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-12 15:32:04 +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-04-22 03:15:22 +00:00
foreach ( SimClient client in m_clientThreads . Values )
{
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-12 15:32:04 +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-04-22 03:25:18 +00:00
/// <summary>
/// Loads the World heightmap
/// </summary>
2007-04-02 10:46:59 +00:00
public void LoadWorldMap ( )
{
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-12 15:32:04 +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-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-12 15:32:04 +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-12 15:32:04 +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-12 15:32:04 +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-12 15:32:04 +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-04-22 03:25:18 +00:00
/// <summary>
/// Tidy before shutdown
/// </summary>
2007-03-30 16:50:19 +00:00
public void Close ( )
{
2007-04-22 03:15:22 +00:00
try
{
this . localStorage . ShutDown ( ) ;
}
catch ( Exception e )
{
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . HIGH , "World.cs: Close() - 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>
/// Send the region heightmap to the client
/// </summary>
/// <param name="RemoteClient">Client to send to</param>
2007-03-30 16:50:19 +00:00
public void SendLayerData ( SimClient RemoteClient )
{
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
int [ ] patches = new int [ 4 ] ;
for ( int y = 0 ; y < 16 ; y + + )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
for ( int x = 0 ; x < 16 ; x = x + 4 )
{
patches [ 0 ] = x + 0 + y * 16 ;
patches [ 1 ] = x + 1 + y * 16 ;
patches [ 2 ] = x + 2 + y * 16 ;
patches [ 3 ] = x + 3 + y * 16 ;
2007-03-30 16:50:19 +00:00
2007-04-22 03:15:22 +00:00
Packet layerpack = TerrainManager . CreateLandPacket ( Terrain . getHeights1D ( ) , patches ) ;
RemoteClient . OutPacket ( layerpack ) ;
}
2007-03-30 16:50:19 +00:00
}
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
{
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: SendLayerData() - 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>
/// Sends a specified patch to a client
/// </summary>
/// <param name="px">Patch coordinate (x) 0..16</param>
/// <param name="py">Patch coordinate (y) 0..16</param>
/// <param name="RemoteClient">The client to send to</param>
2007-03-30 16:50:19 +00:00
public void SendLayerData ( int px , int py , SimClient RemoteClient )
{
2007-04-22 03:15:22 +00:00
try
{
int [ ] patches = new int [ 1 ] ;
int patchx , patchy ;
patchx = px / 16 ;
/ * if ( patchx > 12 )
{
patchx = 12 ;
} * /
patchy = py / 16 ;
patches [ 0 ] = patchx + 0 + patchy * 16 ;
//patches[1] = patchx + 1 + patchy * 16;
//patches[2] = patchx + 2 + patchy * 16;
//patches[3] = patchx + 3 + patchy * 16;
Packet layerpack = TerrainManager . CreateLandPacket ( Terrain . getHeights1D ( ) , patches ) ;
RemoteClient . OutPacket ( layerpack ) ;
}
catch ( Exception e )
{
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: SendLayerData() - 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-04-22 03:25:18 +00:00
/// <summary>
/// Sends prims to a client
/// </summary>
/// <param name="RemoteClient">Client to send to</param>
2007-03-30 16:50:19 +00:00
public void GetInitialPrims ( SimClient RemoteClient )
{
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
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
2007-03-30 16:50:19 +00:00
{
2007-04-22 03:15:22 +00:00
if ( Entities [ UUID ] is Primitive )
{
Primitive primitive = Entities [ UUID ] as Primitive ;
primitive . UpdateClient ( RemoteClient ) ;
}
2007-03-30 16:50:19 +00:00
}
}
2007-04-22 03:15:22 +00:00
catch ( Exception e )
{
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: GetInitialPrims() - 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
public void AddViewerAgent ( SimClient agentClient )
2007-03-28 13:08:27 +00:00
{
2007-04-22 03:15:22 +00:00
try
{
2007-05-12 15:32:04 +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-12 15:32:04 +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-12 15:32:04 +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
}
public void RemoveViewerAgent ( SimClient agentClient )
{
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 )
{
this . phyScene . RemoveAvatar ( agentClient . ClientAvatar . PhysActor ) ;
}
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-12 15:32:04 +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
}
public void AddNewPrim ( ObjectAddPacket addPacket , SimClient AgentClient )
{
2007-04-22 03:15:22 +00:00
try
{
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: AddNewPrim() - Creating new prim" ) ;
2007-04-22 03:15:22 +00:00
Primitive prim = new Primitive ( m_clientThreads , m_regionHandle , this ) ;
prim . CreateFromPacket ( addPacket , AgentClient . AgentID , this . _primCount ) ;
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-28 13:08:27 +00:00
{
2007-04-22 03:15:22 +00:00
lock ( this . LockPhysicsEngine )
{
prim . PhysActor = this . phyScene . AddPrim ( pVec , pSize ) ;
}
2007-03-28 13:08:27 +00:00
}
2007-04-03 20:08:30 +00:00
2007-04-22 03:15:22 +00:00
this . Entities . Add ( prim . uuid , prim ) ;
this . _primCount + + ;
}
catch ( Exception e )
{
2007-05-12 15:32:04 +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-03-24 16:06:43 +00:00
2007-03-30 16:50:19 +00:00
public bool Backup ( )
{
2007-04-22 03:15:22 +00:00
try
2007-04-21 05:51:10 +00:00
{
2007-04-22 03:15:22 +00:00
// Terrain backup routines
if ( Terrain . tainted > 0 )
{
Terrain . tainted = 0 ;
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: Backup() - Terrain tainted, saving." ) ;
2007-04-22 03:15:22 +00:00
localStorage . SaveMap ( Terrain . getHeights1D ( ) ) ;
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: Backup() - Terrain saved, informing Physics." ) ;
2007-04-22 03:15:22 +00:00
phyScene . SetTerrain ( Terrain . getHeights1D ( ) ) ;
}
// Primitive backup routines
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "World.cs: Backup() - Backing up Primitives" ) ;
2007-04-22 03:15:22 +00:00
foreach ( libsecondlife . LLUUID UUID in Entities . Keys )
{
Entities [ UUID ] . BackUp ( ) ;
}
// Backup successful
return true ;
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-04-22 03:15:22 +00:00
// Backup failed
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . HIGH , "World.cs: Backup() - Backup Failed with exception " + e . ToString ( ) ) ;
2007-04-22 03:15:22 +00:00
return false ;
2007-03-30 16:50:19 +00:00
}
2007-03-24 16:06:43 +00:00
}
2007-03-07 18:49:20 +00:00
2007-04-03 18:15:11 +00:00
public void SetDefaultScripts ( )
{
2007-05-16 17:51:28 +00:00
/ * try
2007-04-22 03:15:22 +00:00
{
this . m_scripts . Add ( "FollowRandomAvatar" , delegate ( )
{
return new FollowRandomAvatar ( ) ;
} ) ;
}
catch ( Exception e )
{
2007-05-12 15:32:04 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "World.cs: SetDefaultScripts() - Failed with exception " + e . ToString ( ) ) ;
2007-05-16 17:51:28 +00:00
} * /
2007-04-03 18:15:11 +00:00
}
}
2007-03-07 18:49:20 +00:00
}