Primitive's shape and scale are now saved into database and reloaded.

New ServerConsole command: regenerate - will regenerate the terrain of the whole sim.
adam
MW 2007-03-08 18:07:53 +00:00
parent 8b9fcf064a
commit aa120266d7
8 changed files with 211 additions and 48 deletions

View File

@ -63,6 +63,8 @@ namespace OpenSim
public abstract void InitConfig();
public abstract void LoadFromGrid();
public abstract World LoadWorld();
public abstract void SaveMap();
}
public interface ISimConfig

View File

@ -129,6 +129,20 @@ namespace Db40SimConfig
return blank;
}
public override void SaveMap()
{
IObjectSet world_result = db.Get(typeof(MapStorage));
if(world_result.Count>0) {
ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - updating saved copy of heightmap in local database");
MapStorage map=(MapStorage)world_result.Next();
db.Delete(map);
}
MapStorage map1= new MapStorage();
map1.Map = OpenSim_Main.local_world.LandMap;
db.Set(map1);
db.Commit();
}
public override void LoadFromGrid() {
ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadFromGrid() - dummy function, DOING ABSOLUTELY NOTHING AT ALL!!!");
// TODO: Make this crap work

View File

@ -35,7 +35,7 @@ namespace GridInterfaces
/// </summary>
public interface ILocalStorage
{
void StorePrim(PrimStorage prim);
void StorePrim(PrimData prim);
void RemovePrim(LLUUID primID);
void LoadPrimitives(ILocalStorageReceiver receiver);
void ShutDown();
@ -43,23 +43,10 @@ namespace GridInterfaces
public interface ILocalStorageReceiver
{
void PrimFromStorage(PrimStorage prim);
void PrimFromStorage(PrimData prim);
}
public class PrimStorage
{
public PrimData Data;
public LLVector3 Position;
public LLQuaternion Rotation;
public uint LocalID;
public LLUUID FullID;
public PrimStorage()
{
}
}
public class PrimData
{
public LLUUID OwnerID;
@ -78,6 +65,18 @@ namespace GridInterfaces
public byte ProfileCurve;
public uint ParentID=0;
public byte ProfileHollow;
public sbyte PathRadiusOffset;
public byte PathRevolutions;
public sbyte PathTaperX;
public sbyte PathTaperY;
public sbyte PathTwist;
public sbyte PathTwistBegin;
//following only used during prim storage
public LLVector3 Position;
public LLQuaternion Rotation;
public uint LocalID;
public LLUUID FullID;
public PrimData()
{

View File

@ -55,23 +55,43 @@ namespace Db4LocalStorage
}
}
public void StorePrim(PrimStorage prim)
public void StorePrim(PrimData prim)
{
IObjectSet result = db.Query(new UUIDQuery(prim.FullID));
if(result.Count>0)
{
//prim already in storage
//so update it
PrimStorage found = (PrimStorage) result.Next();
found.Data = prim.Data;
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;
found.Position = prim.Position;
found.Rotation = prim.Rotation;
db.Set(found);
db.Commit();
}
else
{
//not in storage
db.Set(prim);
db.Commit();
}
}
@ -80,7 +100,7 @@ namespace Db4LocalStorage
IObjectSet result = db.Query(new UUIDQuery(primID));
if(result.Count>0)
{
PrimStorage found = (PrimStorage) result.Next();
PrimData found = (PrimData) result.Next();
db.Delete(found);
}
}
@ -88,9 +108,9 @@ namespace Db4LocalStorage
public void LoadPrimitives(ILocalStorageReceiver receiver)
{
IObjectSet result = db.Get(typeof(PrimStorage));
IObjectSet result = db.Get(typeof(PrimData));
ServerConsole.MainConsole.Instance.WriteLine("Db4LocalStorage.cs: LoadPrimitives() - number of prims in storages is "+result.Count);
foreach (PrimStorage prim in result) {
foreach (PrimData prim in result) {
receiver.PrimFromStorage(prim);
}
}
@ -110,7 +130,7 @@ namespace Db4LocalStorage
{
_findID = find;
}
public bool Match(PrimStorage prim)
public bool Match(PrimData prim)
{
return (prim.FullID == _findID);
}

View File

@ -104,6 +104,25 @@ namespace OpenSim
case PacketType.ObjectAdd:
OpenSim_Main.local_world.AddNewPrim((ObjectAddPacket)Pack, this);
break;
case PacketType.ObjectLink:
ServerConsole.MainConsole.Instance.WriteLine(Pack.ToString());
break;
case PacketType.ObjectScale:
ServerConsole.MainConsole.Instance.WriteLine(Pack.ToString());
break;
case PacketType.ObjectShape:
ObjectShapePacket shape = (ObjectShapePacket)Pack;
for(int i =0; i <shape.ObjectData.Length; i++)
{
foreach (Entity ent in OpenSim_Main.local_world.Entities.Values)
{
if(ent.localid == shape.ObjectData[i].ObjectLocalID)
{
((OpenSim.world.Primitive)ent).UpdateShape(shape.ObjectData[i]);
}
}
}
break;
case PacketType.MultipleObjectUpdate :
MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)Pack;
@ -135,6 +154,18 @@ namespace OpenSim
}
}
}
else if(multipleupdate.ObjectData[i].Type == 13 )//scale
{
libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[ i ].Data, 12 );
foreach (Entity ent in OpenSim_Main.local_world.Entities.Values)
{
if(ent.localid == multipleupdate.ObjectData[ i ].ObjectLocalID)
{
((OpenSim.world.Primitive)ent).Scale = scale;
}
}
}
}
break;
case PacketType.TransferRequest:

View File

@ -145,12 +145,17 @@ namespace OpenSim
case "help":
this.WriteLine("show users - show info about connected users");
this.WriteLine("shutdown - disconnect all clients and shutdown");
this.WriteLine("regenerate - regenerate the sim's terrain");
break;
case "show":
ShowCommands(cmdparams[0]);
break;
case "regenerate":
OpenSim_Main.local_world.RegenerateTerrain();
break;
case "shutdown":
OpenSim_Main.Shutdown();
break;

View File

@ -15,6 +15,7 @@ namespace OpenSim.world
protected PrimData primData;
protected bool newPrimFlag;
protected bool updateFlag;
protected bool dirtyFlag;
protected ObjectUpdatePacket OurPacket;
public bool UpdateFlag
@ -28,7 +29,18 @@ namespace OpenSim.world
updateFlag = value;
}
}
public LLVector3 Scale
{
set
{
this.primData.Scale = value;
this.dirtyFlag = true;
}
get
{
return this.primData.Scale;
}
}
public Primitive()
{
mesh_cutbegin = 0.0f;
@ -70,6 +82,13 @@ namespace OpenSim.world
}
this.updateFlag = false;
}
else if(this.dirtyFlag)
{
foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
UpdateClient(client);
}
this.dirtyFlag = false;
}
}
@ -77,9 +96,58 @@ namespace OpenSim.world
{
byte[] pb = this.position.GetBytes();
Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length);
OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID;
OurPacket.ObjectData[0].PCode = this.primData.PCode;
OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin;
OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd;
OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX;
OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY;
OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX;
OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY;
OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew;
OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
OurPacket.ObjectData[0].Scale = this.primData.Scale;
OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve;
OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
OurPacket.ObjectData[0].ParentID = 0;
OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
//finish off copying rest of shape data
OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX;
OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY;
OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist;
OurPacket.ObjectData[0].PathTwistBegin= this.primData.PathTwistBegin;
RemoteClient.OutPacket(OurPacket);
}
public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
{
this.primData.PathBegin = addPacket.PathBegin;
this.primData.PathEnd = addPacket.PathEnd;
this.primData.PathScaleX = addPacket.PathScaleX;
this.primData.PathScaleY = addPacket.PathScaleY;
this.primData.PathShearX = addPacket.PathShearX;
this.primData.PathShearY = addPacket.PathShearY;
this.primData.PathSkew = addPacket.PathSkew;
this.primData.ProfileBegin = addPacket.ProfileBegin;
this.primData.ProfileEnd = addPacket.ProfileEnd;
this.primData.PathCurve = addPacket.PathCurve;
this.primData.ProfileCurve = addPacket.ProfileCurve;
this.primData.ProfileHollow = addPacket.ProfileHollow;
this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
this.primData.PathRevolutions = addPacket.PathRevolutions;
this.primData.PathTaperX = addPacket.PathTaperX;
this.primData.PathTaperY = addPacket.PathTaperY;
this.primData.PathTwist = addPacket.PathTwist;
this.primData.PathTwistBegin =addPacket.PathTwistBegin;
this.dirtyFlag = true;
}
public void CreateFromPacket( ObjectAddPacket addPacket, LLUUID agentID, uint localID)
{
ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
@ -124,6 +192,13 @@ namespace OpenSim.world
PData.ParentID = objupdate.ObjectData[0].ParentID = 0;
PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow;
PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions;
PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX;
PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY;
PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist;
PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
//finish off copying rest of shape data
objupdate.ObjectData[0].ID = (uint)(localID);
@ -143,7 +218,7 @@ namespace OpenSim.world
this.OurPacket = objupdate;
}
public void CreateFromStorage(PrimStorage store)
public void CreateFromStorage(PrimData store)
{
//need to clean this up as it shares a lot of code with CreateFromPacket()
ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
@ -151,7 +226,7 @@ namespace OpenSim.world
objupdate.RegionData.TimeDilation = 64096;
objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
this.primData = store.Data;
this.primData = store;
objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
objupdate.ObjectData[0].PSBlock = new byte[0];
objupdate.ObjectData[0].ExtraParams = new byte[1];
@ -187,6 +262,12 @@ namespace OpenSim.world
objupdate.ObjectData[0].ParentID = 0;
objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
//finish off copying rest of shape data
objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX;
objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY;
objupdate.ObjectData[0].PathTwist = this.primData.PathTwist;
objupdate.ObjectData[0].PathTwistBegin= this.primData.PathTwistBegin;
objupdate.ObjectData[0].ID = (uint)store.LocalID;
objupdate.ObjectData[0].FullID = store.FullID;
@ -203,6 +284,7 @@ namespace OpenSim.world
this.localid = objupdate.ObjectData[0].ID;
this.position = pos1;
this.OurPacket = objupdate;
}
public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
{
@ -272,13 +354,12 @@ namespace OpenSim.world
public override void BackUp()
{
PrimStorage pStore = new PrimStorage();
pStore.Data = this.primData;
pStore.FullID = this.uuid;
pStore.LocalID = this.localid;
pStore.Position = this.position;
pStore.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z , this.rotation.w);
OpenSim_Main.local_world.localStorage.StorePrim(pStore);
this.primData.FullID = this.uuid;
this.primData.LocalID = this.localid;
this.primData.Position = this.position;
this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z , this.rotation.w);
OpenSim_Main.local_world.localStorage.StorePrim(this.primData);
}
}

View File

@ -71,7 +71,7 @@ namespace OpenSim.world
//backup world data
this.storageCount++;
if(storageCount> 1200) //set to how often you want to backup (currently set for about every 2 minutes)
if(storageCount> 300) //set to how often you want to backup
{
this.Backup();
storageCount =0;
@ -107,13 +107,24 @@ namespace OpenSim.world
return(store == null);
}
public void RegenerateTerrain()
{
HeightmapGenHills hills = new HeightmapGenHills();
this.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false);
this.phyScene.SetTerrain(this.LandMap);
OpenSim_Main.cfg.SaveMap();
foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
this.SendLayerData(client);
}
}
public void LoadPrimsFromStorage()
{
ServerConsole.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives");
this.localStorage.LoadPrimitives(this);
}
public void PrimFromStorage(PrimStorage prim)
public void PrimFromStorage(PrimData prim)
{
if(prim.LocalID >= this._primCount)
{