2007-03-08 13:21:24 +00:00
/ *
* Copyright ( c ) OpenSim project , http : //sim.opensecondlife.org/
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* * Neither the name of the < organization > nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY < copyright holder > ` ` AS IS ' ' AND ANY
* EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL < copyright holder > BE LIABLE FOR ANY
* DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
* ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
* LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*
* /
using System ;
using System.Collections.Generic ;
using Db4objects.Db4o ;
using Db4objects.Db4o.Query ;
using libsecondlife ;
2007-03-22 10:11:15 +00:00
using OpenSim.Framework.Interfaces ;
2007-04-25 13:03:48 +00:00
using OpenSim.Framework.Types ;
2007-04-02 10:46:59 +00:00
using OpenSim.Framework.Terrain ;
2007-03-08 13:21:24 +00:00
2007-03-22 10:11:15 +00:00
namespace OpenSim.Storage.LocalStorageDb4o
2007-03-08 13:21:24 +00:00
{
/// <summary>
///
/// </summary>
public class Db4LocalStorage : ILocalStorage
{
private IObjectContainer db ;
2007-04-27 21:11:02 +00:00
private string datastore ;
2007-03-08 13:21:24 +00:00
public Db4LocalStorage ( )
{
2007-04-27 21:11:02 +00:00
2007-03-08 13:21:24 +00:00
}
2007-04-27 21:11:02 +00:00
public void Initialise ( string dfile )
{
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "Db4LocalStorage Opening " + dfile ) ;
2007-04-27 21:11:02 +00:00
datastore = dfile ;
try
{
db = Db4oFactory . OpenFile ( datastore ) ;
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "Db4LocalStorage creation" ) ;
2007-04-27 21:11:02 +00:00
}
catch ( Exception e )
{
db . Close ( ) ;
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , "Db4LocalStorage :Constructor - Exception occured" ) ;
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . MEDIUM , e . ToString ( ) ) ;
2007-04-27 21:11:02 +00:00
}
}
2007-03-08 13:21:24 +00:00
2007-03-08 18:07:53 +00:00
public void StorePrim ( PrimData prim )
2007-03-08 13:21:24 +00:00
{
IObjectSet result = db . Query ( new UUIDQuery ( prim . FullID ) ) ;
if ( result . Count > 0 )
{
//prim already in storage
//so update it
2007-03-08 18:07:53 +00:00
PrimData found = ( PrimData ) result . Next ( ) ;
found . PathBegin = prim . PathBegin ;
found . PathCurve = prim . PathCurve ;
found . PathEnd = prim . PathEnd ;
found . PathRadiusOffset = prim . PathRadiusOffset ;
found . PathRevolutions = prim . PathRevolutions ;
found . PathScaleX = prim . PathScaleX ;
found . PathScaleY = prim . PathScaleY ;
found . PathShearX = prim . PathShearX ;
found . PathShearY = prim . PathShearY ;
found . PathSkew = prim . PathSkew ;
found . PathTaperX = prim . PathTaperX ;
found . PathTaperY = prim . PathTaperY ;
found . PathTwist = prim . PathTwist ;
found . PathTwistBegin = prim . PathTwistBegin ;
found . PCode = prim . PCode ;
found . ProfileBegin = prim . ProfileBegin ;
found . ProfileCurve = prim . ProfileCurve ;
found . ProfileEnd = prim . ProfileEnd ;
found . ProfileHollow = prim . ProfileHollow ;
2007-03-08 13:21:24 +00:00
found . Position = prim . Position ;
found . Rotation = prim . Rotation ;
2007-03-22 10:11:15 +00:00
found . Texture = prim . Texture ;
2007-03-08 13:21:24 +00:00
db . Set ( found ) ;
2007-03-08 18:07:53 +00:00
db . Commit ( ) ;
2007-03-08 13:21:24 +00:00
}
else
{
//not in storage
db . Set ( prim ) ;
2007-03-08 18:07:53 +00:00
db . Commit ( ) ;
2007-03-08 13:21:24 +00:00
}
}
public void RemovePrim ( LLUUID primID )
{
IObjectSet result = db . Query ( new UUIDQuery ( primID ) ) ;
if ( result . Count > 0 )
{
2007-03-08 18:07:53 +00:00
PrimData found = ( PrimData ) result . Next ( ) ;
2007-03-08 13:21:24 +00:00
db . Delete ( found ) ;
}
}
public void LoadPrimitives ( ILocalStorageReceiver receiver )
{
2007-03-08 18:07:53 +00:00
IObjectSet result = db . Get ( typeof ( PrimData ) ) ;
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "Db4LocalStorage.cs: LoadPrimitives() - number of prims in storages is " + result . Count ) ;
2007-03-08 18:07:53 +00:00
foreach ( PrimData prim in result ) {
2007-03-08 13:21:24 +00:00
receiver . PrimFromStorage ( prim ) ;
}
}
2007-04-02 10:46:59 +00:00
2007-04-11 05:19:27 +00:00
public float [ ] LoadWorld ( )
2007-04-02 10:46:59 +00:00
{
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "LoadWorld() - Loading world...." ) ;
2007-04-02 10:46:59 +00:00
//World blank = new World();
2007-04-11 05:19:27 +00:00
float [ ] heightmap = null ;
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "LoadWorld() - Looking for a heightmap in local DB" ) ;
2007-04-02 10:46:59 +00:00
IObjectSet world_result = db . Get ( typeof ( MapStorage ) ) ;
if ( world_result . Count > 0 )
{
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "LoadWorld() - Found a heightmap in local database, loading" ) ;
2007-04-02 10:46:59 +00:00
MapStorage map = ( MapStorage ) world_result . Next ( ) ;
//blank.LandMap = map.Map;
heightmap = map . Map ;
}
else
{
2007-04-06 19:25:29 +00:00
/ *
2007-04-02 10:46:59 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "LoadWorld() - No heightmap found, generating new one" ) ;
HeightmapGenHills hills = new HeightmapGenHills ( ) ;
// blank.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false);
2007-04-06 19:08:24 +00:00
// heightmap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false);
heightmap = new float [ 256 , 256 ] ;
2007-04-02 10:46:59 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( "LoadWorld() - Saving heightmap to local database" ) ;
MapStorage map = new MapStorage ( ) ;
map . Map = heightmap ; //blank.LandMap;
db . Set ( map ) ;
db . Commit ( ) ;
2007-04-06 19:25:29 +00:00
* /
2007-04-02 10:46:59 +00:00
}
return heightmap ;
}
2007-04-11 05:19:27 +00:00
public void SaveMap ( float [ ] heightmap )
2007-04-02 10:46:59 +00:00
{
IObjectSet world_result = db . Get ( typeof ( MapStorage ) ) ;
if ( world_result . Count > 0 )
{
2007-05-12 15:44:10 +00:00
OpenSim . Framework . Console . MainConsole . Instance . WriteLine ( OpenSim . Framework . Console . LogPriority . LOW , "SaveWorld() - updating saved copy of heightmap in local database" ) ;
2007-04-02 10:46:59 +00:00
MapStorage map = ( MapStorage ) world_result . Next ( ) ;
db . Delete ( map ) ;
}
MapStorage map1 = new MapStorage ( ) ;
map1 . Map = heightmap ; //OpenSim_Main.local_world.LandMap;
db . Set ( map1 ) ;
db . Commit ( ) ;
}
2007-03-08 13:21:24 +00:00
public void ShutDown ( )
{
db . Commit ( ) ;
db . Close ( ) ;
}
}
}