Imported r146 changes such as HeightMap generation
parent
a1c1842f64
commit
ecbb5404dc
|
@ -117,9 +117,13 @@ namespace Db40SimConfig
|
|||
blank.LandMap=(float[])world_result.Next();
|
||||
} else {
|
||||
ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - No heightmap found, generating new one");
|
||||
for(int i =0; i < 65536; i++) {
|
||||
blank.LandMap[i] = 21.4989f;
|
||||
}
|
||||
HeightmapGenHills hills = new HeightmapGenHills();
|
||||
blank.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false);
|
||||
/* blank.LandMap = new float[65536];
|
||||
for(int i = 0 ; i <65536; i++)
|
||||
{
|
||||
blank.LandMap[i] = 20.49f;
|
||||
}*/
|
||||
ServerConsole.MainConsole.Instance.WriteLine("Config.cs:LoadWorld() - Saving heightmap to local database");
|
||||
db.Set(blank.LandMap);
|
||||
db.Commit();
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="libsecondlife">
|
||||
<HintPath>..\..\Libsecond-dailys\libsl-03-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll</HintPath>
|
||||
<HintPath>..\..\Libsecond-dailys\libsl07-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace OpenSim.GridServers
|
|||
UUIDBlock RequestUUIDBlock();
|
||||
void RequestNeighbours(); //should return a array of neighbouring regions
|
||||
AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode);
|
||||
bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode);
|
||||
void SetServerInfo(string ServerUrl, string ServerKey);
|
||||
void AddNewSession(Login session); // only used by local version of grid server
|
||||
// and didn't use to be part of this interface until we put this in a dll
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
namespace OpenSim
|
||||
{
|
||||
public class HeightmapGenHills
|
||||
{
|
||||
private Random Rand = new Random();
|
||||
private int NumHills;
|
||||
private float HillMin;
|
||||
private float HillMax;
|
||||
private bool Island;
|
||||
private float[] heightmap;
|
||||
|
||||
public float[] GenerateHeightmap(int numHills, float hillMin, float hillMax, bool island)
|
||||
{
|
||||
NumHills = numHills;
|
||||
HillMin = hillMin;
|
||||
HillMax = hillMax;
|
||||
Island = island;
|
||||
|
||||
heightmap = new float[256 * 256];
|
||||
|
||||
for (int i = 0; i < numHills; i++)
|
||||
{
|
||||
AddHill();
|
||||
}
|
||||
|
||||
Normalize();
|
||||
|
||||
return heightmap;
|
||||
}
|
||||
|
||||
private void AddHill()
|
||||
{
|
||||
float x, y;
|
||||
float radius = RandomRange(HillMin, HillMax);
|
||||
|
||||
if (Island)
|
||||
{
|
||||
// Which direction from the center of the map the hill is placed
|
||||
float theta = RandomRange(0, 6.28f);
|
||||
|
||||
// How far from the center of the map to place the hill. The radius
|
||||
// is subtracted from the range to prevent any part of the hill from
|
||||
// reaching the edge of the map
|
||||
float distance = RandomRange(radius / 2.0f, 128.0f - radius);
|
||||
|
||||
x = 128.0f + (float)Math.Cos(theta) * distance;
|
||||
y = 128.0f + (float)Math.Sin(theta) * distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = RandomRange(-radius, 256.0f + radius);
|
||||
y = RandomRange(-radius, 256.0f + radius);
|
||||
}
|
||||
|
||||
float radiusSq = radius * radius;
|
||||
float distSq;
|
||||
float height;
|
||||
|
||||
int xMin = (int)(x - radius) - 1;
|
||||
int xMax = (int)(x + radius) + 1;
|
||||
if (xMin < 0) xMin = 0;
|
||||
if (xMax > 255) xMax = 255;
|
||||
|
||||
int yMin = (int)(y - radius) - 1;
|
||||
int yMax = (int)(y + radius) + 1;
|
||||
if (yMin < 0) yMin = 0;
|
||||
if (yMax > 255) yMax = 255;
|
||||
|
||||
// Loop through each affected cell and determine the height at that point
|
||||
for (int v = yMin; v <= yMax; ++v)
|
||||
{
|
||||
float fv = (float)v;
|
||||
|
||||
for (int h = xMin; h <= xMax; ++h)
|
||||
{
|
||||
float fh = (float)h;
|
||||
|
||||
// Determine how far from the center of this hill this point is
|
||||
distSq = (x - fh) * (x - fh) + (y - fv) * (y - fv);
|
||||
height = radiusSq - distSq;
|
||||
|
||||
// Don't add negative hill values
|
||||
if (height > 0.0f) heightmap[h + v * 256] += height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Normalize()
|
||||
{
|
||||
float min = heightmap[0];
|
||||
float max = heightmap[0];
|
||||
|
||||
for (int x = 0; x < 256; x++)
|
||||
{
|
||||
for (int y = 0; y < 256; y++)
|
||||
{
|
||||
if (heightmap[x + y * 256] < min) min = heightmap[x + y * 256];
|
||||
if (heightmap[x + y * 256] > max) max = heightmap[x + y * 256];
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid a rare divide by zero
|
||||
if (min != max)
|
||||
{
|
||||
for (int x = 0; x < 256; x++)
|
||||
{
|
||||
for (int y = 0; y < 256; y++)
|
||||
{
|
||||
heightmap[x + y * 256] = ((heightmap[x + y * 256] - min) / (max - min)) * (HillMax - HillMin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float RandomRange(float min, float max)
|
||||
{
|
||||
return (float)Rand.NextDouble() * (max - min) + min;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -144,6 +144,11 @@ namespace LocalGridServers
|
|||
return(user);
|
||||
}
|
||||
|
||||
public bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
|
||||
public UUIDBlock RequestUUIDBlock()
|
||||
{
|
||||
UUIDBlock uuidBlock = new UUIDBlock();
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="libsecondlife">
|
||||
<HintPath>..\..\..\Libsecond-dailys\libsl-03-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll</HintPath>
|
||||
<HintPath>..\..\..\Libsecond-dailys\libsl07-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
|
25
src/Main.cs
25
src/Main.cs
|
@ -77,7 +77,7 @@ namespace OpenSim
|
|||
[STAThread]
|
||||
public static void Main( string[] args )
|
||||
{
|
||||
//Console.WriteLine("OpenSim " + VersionInfo.Version + "\n");
|
||||
Console.WriteLine("OpenSim " + VersionInfo.Version + "\n");
|
||||
Console.WriteLine("Starting...\n");
|
||||
ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local,"",0);
|
||||
|
||||
|
@ -136,7 +136,7 @@ namespace OpenSim
|
|||
|
||||
// We check our local database first, then the grid for config options
|
||||
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration");
|
||||
cfg = this.LoadConfigDll();
|
||||
cfg = this.LoadConfigDll(this.ConfigDll);
|
||||
cfg.InitConfig();
|
||||
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Contacting gridserver");
|
||||
cfg.LoadFromGrid();
|
||||
|
@ -149,16 +149,17 @@ namespace OpenSim
|
|||
this.physManager.LoadPlugins();
|
||||
ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting up messaging system");
|
||||
local_world.PhysScene = this.physManager.GetPhysicsScene("PhysX"); //should be reading from the config file what physics engine to use
|
||||
OpenSim_Main.gridServers.AssetServer.SetServerInfo(OpenSim_Main.cfg.AssetURL, OpenSim_Main.cfg.AssetSendKey);
|
||||
local_world.PhysScene.SetTerrain(local_world.LandMap);
|
||||
OpenSim_Main.gridServers.AssetServer.SetServerInfo(OpenSim_Main.cfg.AssetURL, OpenSim_Main.cfg.AssetSendKey);
|
||||
OpenSim_Main.gridServers.GridServer.SetServerInfo(OpenSim_Main.cfg.GridURL, OpenSim_Main.cfg.GridSendKey);
|
||||
|
||||
MainServerListener();
|
||||
|
||||
}
|
||||
|
||||
private SimConfig LoadConfigDll()
|
||||
private SimConfig LoadConfigDll(string dllName)
|
||||
{
|
||||
Assembly pluginAssembly = Assembly.LoadFrom(this.ConfigDll);
|
||||
Assembly pluginAssembly = Assembly.LoadFrom(dllName);
|
||||
SimConfig config = null;
|
||||
|
||||
foreach (Type pluginType in pluginAssembly.GetTypes())
|
||||
|
@ -191,7 +192,7 @@ namespace OpenSim
|
|||
int numBytes = Server.EndReceiveFrom(result, ref epSender);
|
||||
int packetEnd = numBytes - 1;
|
||||
packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
|
||||
Console.Error.WriteLine(packet.ToString());
|
||||
//Console.Error.WriteLine(packet.ToString());
|
||||
|
||||
// This is either a new client or a packet to send to an old one
|
||||
if(ClientThreads.ContainsKey(epSender)) {
|
||||
|
@ -253,13 +254,13 @@ namespace OpenSim
|
|||
|
||||
public void LoadPlugins()
|
||||
{
|
||||
this.AssetServer =(IAssetServer) this.LoadAssetDll();
|
||||
this.GridServer =(IGridServer) this.LoadGridDll();
|
||||
this.AssetServer = this.LoadAssetDll(this.AssetDll);
|
||||
this.GridServer = this.LoadGridDll(this.GridDll);
|
||||
}
|
||||
|
||||
private IAssetServer LoadAssetDll()
|
||||
private IAssetServer LoadAssetDll(string dllName)
|
||||
{
|
||||
Assembly pluginAssembly = Assembly.LoadFrom(this.AssetDll);
|
||||
Assembly pluginAssembly = Assembly.LoadFrom(dllName);
|
||||
IAssetServer server = null;
|
||||
|
||||
foreach (Type pluginType in pluginAssembly.GetTypes())
|
||||
|
@ -285,9 +286,9 @@ namespace OpenSim
|
|||
return server;
|
||||
}
|
||||
|
||||
private IGridServer LoadGridDll()
|
||||
private IGridServer LoadGridDll(string dllName)
|
||||
{
|
||||
Assembly pluginAssembly = Assembly.LoadFrom(this.GridDll);
|
||||
Assembly pluginAssembly = Assembly.LoadFrom(dllName);
|
||||
IGridServer server = null;
|
||||
|
||||
foreach (Type pluginType in pluginAssembly.GetTypes())
|
||||
|
|
|
@ -99,6 +99,15 @@ namespace OpenSim
|
|||
case PacketType.AgentUpdate:
|
||||
ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack);
|
||||
break;
|
||||
case PacketType.LogoutRequest:
|
||||
ServerConsole.MainConsole.Instance.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got a logout request");
|
||||
lock(OpenSim_Main.local_world.Entities) {
|
||||
OpenSim_Main.local_world.Entities.Remove(this.AgentID);
|
||||
}
|
||||
//need to do other cleaning up here too
|
||||
OpenSim_Main.gridServers.GridServer.LogoutSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
|
||||
this.ClientThread.Abort();
|
||||
break;
|
||||
case PacketType.ChatFromViewer:
|
||||
ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
|
||||
if(Helpers.FieldToString(inchatpack.ChatData.Message)=="") break;
|
||||
|
|
|
@ -109,6 +109,18 @@ namespace RemoteGridServers
|
|||
return(user);
|
||||
}
|
||||
|
||||
public bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode)
|
||||
{
|
||||
WebRequest DeleteSession = WebRequest.Create(GridServerUrl + "/usersessions/" + GridSendKey + "/" + agentID.ToString() + circuitCode.ToString() + "/delete");
|
||||
WebResponse GridResponse = DeleteSession.GetResponse();
|
||||
StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
|
||||
String grTest = sr.ReadLine();
|
||||
sr.Close();
|
||||
GridResponse.Close();
|
||||
ServerConsole.MainConsole.Instance.WriteLine("DEBUG: " + grTest);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public UUIDBlock RequestUUIDBlock()
|
||||
{
|
||||
UUIDBlock uuidBlock = new UUIDBlock();
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="libsecondlife">
|
||||
<HintPath>..\..\..\Libsecond-dailys\libsl-03-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll</HintPath>
|
||||
<HintPath>..\..\..\Libsecond-dailys\libsl07-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="libsecondlife">
|
||||
<HintPath>..\Version0_2_myserver\OpenSim\bin\Debug\libsecondlife.dll</HintPath>
|
||||
<HintPath>..\Libsecond-dailys\libsl07-03\trunk\libsecondlife-cs\obj\Debug\libsecondlife.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
@ -65,11 +65,12 @@
|
|||
<Compile Include="world\ScriptEngine.cs" />
|
||||
<Compile Include="world\scripting\IScript.cs" />
|
||||
<Compile Include="world\SurfacePatch.cs" />
|
||||
<Compile Include="world\TerrainDecoder.cs" />
|
||||
<Compile Include="world\World.cs" />
|
||||
<Compile Include="GridServers\LoginServer.cs" />
|
||||
<Compile Include="Assets\AssetCache.cs" />
|
||||
<Compile Include="OpenSimConsole.cs" />
|
||||
<Compile Include="HeightMapGenHills.cs" />
|
||||
<Compile Include="VersionInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="GridServers" />
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Copyright (c) OpenSim project, http://osgrid.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;
|
||||
|
||||
namespace OpenSim
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public class VersionInfo
|
||||
{
|
||||
public static string Version = "0.0.1-*";
|
||||
}
|
||||
}
|
|
@ -70,6 +70,7 @@ namespace PhysXplugin
|
|||
public class PhysXScene :PhysicsScene
|
||||
{
|
||||
private List<PhysXActor> _actors = new List<PhysXActor>();
|
||||
private float[] _heightMap;
|
||||
|
||||
public PhysXScene()
|
||||
{
|
||||
|
@ -91,7 +92,8 @@ namespace PhysXplugin
|
|||
actor.Position.X = actor.Position.X + actor.Velocity.X * timeStep;
|
||||
actor.Position.Y = actor.Position.Y + actor.Velocity.Y * timeStep;
|
||||
actor.Position.Z = actor.Position.Z + actor.Velocity.Z * timeStep;
|
||||
if(actor.Position.X<0)
|
||||
actor.Position.Z = _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X]+1;
|
||||
if(actor.Position.X<0)
|
||||
{
|
||||
actor.Position.X = 0;
|
||||
actor.Velocity.X = 0;
|
||||
|
@ -129,7 +131,7 @@ namespace PhysXplugin
|
|||
|
||||
public override void SetTerrain(float[] heightMap)
|
||||
{
|
||||
|
||||
this._heightMap = heightMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenSim.types
|
||||
{
|
||||
/* New Method
|
||||
*
|
||||
* 1. Get all the individual bytes and their bitlength, put them in a dictionary
|
||||
* 2. Mash together when wanted.
|
||||
*
|
||||
* */
|
||||
public class Bits {
|
||||
public byte[] data;
|
||||
public int len;
|
||||
}
|
||||
|
||||
public class InverseBitPack
|
||||
{
|
||||
private List<Bits> bits;
|
||||
|
||||
public InverseBitPack()
|
||||
{
|
||||
bits = new List<Bits>();
|
||||
}
|
||||
}
|
||||
|
||||
public class BitPack
|
||||
{
|
||||
private const int MAX_BITS = 8;
|
||||
|
||||
private byte[] Data;
|
||||
private int bytePos;
|
||||
private int bitPos;
|
||||
|
||||
public BitPack(byte[] data, int pos) // For libsl compatibility
|
||||
{
|
||||
Data = data;
|
||||
bytePos = pos;
|
||||
}
|
||||
|
||||
public BitPack() // Encoding version
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void LoadData(byte[] data, int pos) {
|
||||
Data = data;
|
||||
bytePos = pos;
|
||||
bitPos = 0;
|
||||
}
|
||||
|
||||
private void PackBitsArray(byte[] bits, int bitLen)
|
||||
{
|
||||
int offset = bitPos % MAX_BITS;
|
||||
int i;
|
||||
byte temp1;
|
||||
byte temp2;
|
||||
|
||||
for (i = 0; i < bits.Length; i++)
|
||||
{
|
||||
int Byte = bits[i];
|
||||
Byte <<= offset;
|
||||
temp1 = (byte)(Byte & 0xFF);
|
||||
temp2 = (byte)((Byte >> 8) & 0xFF);
|
||||
|
||||
Data[Data.Length - 1] |= temp1;
|
||||
// Data
|
||||
|
||||
bitPos += bitLen;
|
||||
}
|
||||
}
|
||||
|
||||
public float UnpackFloat()
|
||||
{
|
||||
byte[] output = UnpackBitsArray(32);
|
||||
|
||||
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||
return BitConverter.ToSingle(output, 0);
|
||||
}
|
||||
|
||||
public int UnpackBits(int totalCount)
|
||||
{
|
||||
byte[] output = UnpackBitsArray(totalCount);
|
||||
|
||||
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||
return BitConverter.ToInt32(output, 0);
|
||||
}
|
||||
|
||||
private byte[] UnpackBitsArray(int totalCount)
|
||||
{
|
||||
int count = 0;
|
||||
byte[] output = new byte[4];
|
||||
int curBytePos = 0;
|
||||
int curBitPos = 0;
|
||||
|
||||
while (totalCount > 0)
|
||||
{
|
||||
if (totalCount > MAX_BITS)
|
||||
{
|
||||
count = MAX_BITS;
|
||||
totalCount -= MAX_BITS;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = totalCount;
|
||||
totalCount = 0;
|
||||
}
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
// Shift the previous bits
|
||||
output[curBytePos] <<= 1;
|
||||
|
||||
// Grab one bit
|
||||
if ((Data[bytePos] & (0x80 >> bitPos++)) != 0)
|
||||
++output[curBytePos];
|
||||
|
||||
--count;
|
||||
++curBitPos;
|
||||
|
||||
if (bitPos >= MAX_BITS)
|
||||
{
|
||||
bitPos = 0;
|
||||
++bytePos;
|
||||
}
|
||||
if (curBitPos >= MAX_BITS)
|
||||
{
|
||||
curBitPos = 0;
|
||||
++curBytePos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ namespace OpenSim.world
|
|||
private bool updateflag;
|
||||
private bool walking;
|
||||
private List<NewForce> forcesList = new List<NewForce>();
|
||||
private short _updateCount;
|
||||
|
||||
public Avatar(OpenSimClient TheClient) {
|
||||
ServerConsole.MainConsole.Instance.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
|
||||
|
@ -36,16 +37,23 @@ namespace OpenSim.world
|
|||
}
|
||||
public override void addFroces()
|
||||
{
|
||||
if(this.forcesList.Count>0)
|
||||
lock(this.forcesList)
|
||||
{
|
||||
for(int i=0 ; i < this.forcesList.Count; i++)
|
||||
if(this.forcesList.Count>0)
|
||||
{
|
||||
NewForce force = this.forcesList[i];
|
||||
PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
|
||||
this._physActor.Velocity = phyVector;
|
||||
this.updateflag = true;
|
||||
this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
|
||||
// but as we are setting the velocity (rather than using real forces) at the moment it is okay.
|
||||
for(int i=0 ; i < this.forcesList.Count; i++)
|
||||
{
|
||||
NewForce force = this.forcesList[i];
|
||||
PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
|
||||
this._physActor.Velocity = phyVector;
|
||||
this.updateflag = true;
|
||||
this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
|
||||
// but as we are setting the velocity (rather than using real forces) at the moment it is okay.
|
||||
}
|
||||
for(int i=0 ; i < this.forcesList.Count; i++)
|
||||
{
|
||||
this.forcesList.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +68,7 @@ namespace OpenSim.world
|
|||
ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
|
||||
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
|
||||
terse.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; // FIXME
|
||||
terse.RegionData.TimeDilation = 0;
|
||||
terse.RegionData.TimeDilation = 64096;
|
||||
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
|
||||
terse.ObjectData[0] = terseBlock;
|
||||
foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
|
||||
|
@ -68,6 +76,25 @@ namespace OpenSim.world
|
|||
}
|
||||
|
||||
updateflag =false;
|
||||
this._updateCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_updateCount++;
|
||||
if(_updateCount>5)
|
||||
{
|
||||
//It has been a while since last update was sent so lets send one.
|
||||
ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
|
||||
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
|
||||
terse.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; // FIXME
|
||||
terse.RegionData.TimeDilation = 64096;
|
||||
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
|
||||
terse.ObjectData[0] = terseBlock;
|
||||
foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
|
||||
client.OutPacket(terse);
|
||||
}
|
||||
_updateCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,13 +137,12 @@ namespace OpenSim.world
|
|||
mov.Data.Position = new LLVector3(100f, 100f, 23f);
|
||||
mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
|
||||
|
||||
ServerConsole.MainConsole.Instance.WriteLine("Sending AgentMovementComplete packet");
|
||||
ControllingClient.OutPacket(mov);
|
||||
}
|
||||
|
||||
public void SendInitialPosition() {
|
||||
|
||||
System.Text.Encoding _enc = System.Text.Encoding.ASCII;
|
||||
|
||||
//send a objectupdate packet with information about the clients avatar
|
||||
ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
|
||||
objupdate.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle;
|
||||
|
@ -243,6 +269,7 @@ namespace OpenSim.world
|
|||
libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
|
||||
|
||||
uint ID = this.localid;
|
||||
|
||||
bytes[i++] = (byte)(ID % 256);
|
||||
bytes[i++] = (byte)((ID >> 8) % 256);
|
||||
bytes[i++] = (byte)((ID >> 16) % 256);
|
||||
|
@ -259,6 +286,7 @@ namespace OpenSim.world
|
|||
ushort InternVelocityX;
|
||||
ushort InternVelocityY;
|
||||
ushort InternVelocityZ;
|
||||
|
||||
Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z);
|
||||
internDirec = internDirec /128.0f;
|
||||
internDirec.x += 1;
|
||||
|
@ -269,7 +297,6 @@ namespace OpenSim.world
|
|||
InternVelocityY = (ushort)(32768 * internDirec.y);
|
||||
InternVelocityZ = (ushort)(32768 * internDirec.z);
|
||||
|
||||
|
||||
ushort ac = 32767;
|
||||
bytes[i++] = (byte)(InternVelocityX % 256);
|
||||
bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
|
||||
|
|
|
@ -1,683 +0,0 @@
|
|||
/*
|
||||
* 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 libsecondlife;
|
||||
using libsecondlife.Packets;
|
||||
|
||||
namespace OpenSim
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of TerrainDecoder.
|
||||
/// </summary>
|
||||
public class TerrainDecode
|
||||
{
|
||||
|
||||
public enum LayerType : byte
|
||||
{
|
||||
Land = 0x4C,
|
||||
Water = 0x57,
|
||||
Wind = 0x37,
|
||||
Cloud = 0x38
|
||||
}
|
||||
|
||||
public struct GroupHeader
|
||||
{
|
||||
public int Stride;
|
||||
public int PatchSize;
|
||||
public LayerType Type;
|
||||
}
|
||||
|
||||
public struct PatchHeader
|
||||
{
|
||||
public float DCOffset;
|
||||
public int Range;
|
||||
public int QuantWBits;
|
||||
public int PatchIDs;
|
||||
public uint WordBits;
|
||||
}
|
||||
|
||||
public class Patch
|
||||
{
|
||||
public float[] Heightmap;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="simulator"></param>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="data"></param>
|
||||
// public delegate void LandPatchCallback(Simulator simulator, int x, int y, int width, float[] data);
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
//public event LandPatchCallback OnLandPatch;
|
||||
|
||||
private Random RandomClass = new Random();
|
||||
|
||||
private const byte END_OF_PATCHES = 97;
|
||||
private const int PATCHES_PER_EDGE = 16;
|
||||
private const float OO_SQRT2 = 0.7071067811865475244008443621049f;
|
||||
|
||||
//private SecondLife Client;
|
||||
private Dictionary<ulong, Patch[]> SimPatches = new Dictionary<ulong, Patch[]>();
|
||||
private float[] DequantizeTable16 = new float[16 * 16];
|
||||
private float[] DequantizeTable32 = new float[32 * 32];
|
||||
private float[] ICosineTable16 = new float[16 * 16];
|
||||
private float[] ICosineTable32 = new float[32 * 32];
|
||||
private int[] DeCopyMatrix16 = new int[16 * 16];
|
||||
private int[] DeCopyMatrix32 = new int[32 * 32];
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
public TerrainDecode()
|
||||
{
|
||||
|
||||
// Initialize the decompression tables
|
||||
BuildDequantizeTable16();
|
||||
BuildDequantizeTable32();
|
||||
SetupICosines16();
|
||||
SetupICosines32();
|
||||
BuildDecopyMatrix16();
|
||||
BuildDecopyMatrix32();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void BuildDequantizeTable16()
|
||||
{
|
||||
for (int j = 0; j < 16; j++)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
DequantizeTable16[j * 16 + i] = 1.0f + 2.0f * (float)(i + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildDequantizeTable32()
|
||||
{
|
||||
for (int j = 0; j < 32; j++)
|
||||
{
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
DequantizeTable32[j * 32 + i] = 1.0f + 2.0f * (float)(i + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupICosines16()
|
||||
{
|
||||
const float hposz = (float)Math.PI * 0.5f / 16.0f;
|
||||
|
||||
for (int u = 0; u < 16; u++)
|
||||
{
|
||||
for (int n = 0; n < 16; n++)
|
||||
{
|
||||
ICosineTable16[u * 16 + n] = (float)Math.Cos((2.0f * (float)n + 1.0f) * (float)u * hposz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupICosines32()
|
||||
{
|
||||
const float hposz = (float)Math.PI * 0.5f / 32.0f;
|
||||
|
||||
for (int u = 0; u < 32; u++)
|
||||
{
|
||||
for (int n = 0; n < 32; n++)
|
||||
{
|
||||
ICosineTable32[u * 32 + n] = (float)Math.Cos((2.0f * (float)n + 1.0f) * (float)u * hposz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildDecopyMatrix16()
|
||||
{
|
||||
bool diag = false;
|
||||
bool right = true;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int count = 0;
|
||||
|
||||
while (i < 16 && j < 16)
|
||||
{
|
||||
DeCopyMatrix16[j * 16 + i] = count++;
|
||||
|
||||
if (!diag)
|
||||
{
|
||||
if (right)
|
||||
{
|
||||
if (i < 16 - 1) i++;
|
||||
else j++;
|
||||
|
||||
right = false;
|
||||
diag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j < 16 - 1) j++;
|
||||
else i++;
|
||||
|
||||
right = true;
|
||||
diag = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (right)
|
||||
{
|
||||
i++;
|
||||
j--;
|
||||
if (i == 16 - 1 || j == 0) diag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
i--;
|
||||
j++;
|
||||
if (j == 16 - 1 || i == 0) diag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildDecopyMatrix32()
|
||||
{
|
||||
bool diag = false;
|
||||
bool right = true;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int count = 0;
|
||||
|
||||
while (i < 32 && j < 32)
|
||||
{
|
||||
DeCopyMatrix32[j * 32 + i] = count++;
|
||||
|
||||
if (!diag)
|
||||
{
|
||||
if (right)
|
||||
{
|
||||
if (i < 32 - 1) i++;
|
||||
else j++;
|
||||
|
||||
right = false;
|
||||
diag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j < 32 - 1) j++;
|
||||
else i++;
|
||||
|
||||
right = true;
|
||||
diag = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (right)
|
||||
{
|
||||
i++;
|
||||
j--;
|
||||
if (i == 32 - 1 || j == 0) diag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
i--;
|
||||
j++;
|
||||
if (j == 32 - 1 || i == 0) diag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EncodePatchHeader(BitPacker bitpack, PatchHeader header)
|
||||
{
|
||||
bitpack.PackBits(header.QuantWBits,8);
|
||||
|
||||
if (header.QuantWBits == END_OF_PATCHES)
|
||||
return;
|
||||
|
||||
bitpack.PackFloat(header.DCOffset);
|
||||
bitpack.PackBits(header.Range,16);
|
||||
bitpack.PackBits(header.PatchIDs,10);
|
||||
|
||||
}
|
||||
|
||||
public void DCTLine16(float[] In, float[] Out, int line)
|
||||
{
|
||||
int N =16;
|
||||
int lineSize = line * 16;
|
||||
|
||||
for(int k = 0; k < N;k++)
|
||||
{
|
||||
float sum = 0.0f;
|
||||
for(int n = 0; n < N; n++)
|
||||
{
|
||||
float num = (float)(Math.PI*k*(2.0f*n+1)/(2*N));
|
||||
float cosine = (float)Math.Cos(num);
|
||||
float product = In[lineSize +n] * cosine;
|
||||
sum += product;
|
||||
}
|
||||
|
||||
float alpha;
|
||||
if(k == 0)
|
||||
{
|
||||
alpha = (float)(1.0f/Math.Sqrt(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
alpha = 1;
|
||||
}
|
||||
Out[lineSize + k] =(float)( sum * alpha );
|
||||
|
||||
}
|
||||
}
|
||||
public void DCTColumn16(float[] In, float[] Out, int Column)
|
||||
{
|
||||
int N =16;
|
||||
int uSize;
|
||||
|
||||
for(int k = 0; k < N; k++){
|
||||
float sum = 0.0f;
|
||||
for(int n = 0; n < N; n++)
|
||||
{
|
||||
uSize = n * 16;
|
||||
float num = (float)(Math.PI*k*(2.0f*n+1)/(2*N));
|
||||
float cosine = (float)Math.Cos(num);
|
||||
float product = In[uSize + Column] * cosine;
|
||||
sum += product;
|
||||
}
|
||||
|
||||
float alpha;
|
||||
if(k == 0)
|
||||
{
|
||||
alpha = (float)(1.0f/Math.Sqrt(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
alpha = 1;
|
||||
}
|
||||
Out[16 * k + Column] = (float)( sum * alpha * (2.0f /N));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void EncodePatch(int[] patches, BitPacker bitpack, int size)
|
||||
{
|
||||
int lastnum =0;
|
||||
for(int n = 0; n < size * size; n++)
|
||||
{
|
||||
if(patches[n]!=0)
|
||||
lastnum=n;
|
||||
}
|
||||
for (int n = 0; n < lastnum+1; n++)
|
||||
{
|
||||
if(patches[n] != 0)
|
||||
{
|
||||
bitpack.PackBits(1,1); //value or EOB
|
||||
bitpack.PackBits(1,1); //value
|
||||
if(patches[n] > 0)
|
||||
{
|
||||
|
||||
bitpack.PackBits(0,1); // positive
|
||||
bitpack.PackBits(patches[n],13);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
bitpack.PackBits(1,1); // negative
|
||||
|
||||
int temp = patches[n] * -1;
|
||||
bitpack.PackBits(temp,13);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bitpack.PackBits(0,1); // no value
|
||||
}
|
||||
}
|
||||
|
||||
bitpack.PackBits(1,1); //value or EOB
|
||||
bitpack.PackBits(0,1); // EOB
|
||||
}
|
||||
|
||||
public int[] CompressPatch(float[] patches)
|
||||
{
|
||||
int size = 16;
|
||||
float[] block = new float[size * size];
|
||||
int[] output = new int[size * size];
|
||||
int prequant = (139 >> 4) + 2;
|
||||
int quantize = 1 << prequant;
|
||||
float ooq = 1.0f / (float)quantize;
|
||||
float mult = ooq * (float)1;
|
||||
float addval = mult * (float)(1 << (prequant - 1)) + 20.4989f;
|
||||
|
||||
if (size == 16)
|
||||
{
|
||||
for (int n = 0; n < 16 * 16; n++)
|
||||
{
|
||||
block[n] = (float)((patches[n] - addval)/ mult);
|
||||
}
|
||||
|
||||
float[] ftemp = new float[32 * 32];
|
||||
|
||||
for (int o = 0; o < 16; o++)
|
||||
this.DCTColumn16(block, ftemp, o);
|
||||
for (int o = 0; o < 16; o++)
|
||||
this.DCTLine16(ftemp, block, o);
|
||||
}
|
||||
|
||||
for (int j = 0; j < block.Length; j++)
|
||||
{
|
||||
output[DeCopyMatrix16[j]] = (int)(block[j] / DequantizeTable16[j]);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public Packet CreateLayerPacket(float[] heightmap, int minX, int minY, int maxX, int maxY)
|
||||
{
|
||||
//int minX = 0, maxX = 2, minY = 0, maxY = 1; //these should be passed to this function
|
||||
LayerDataPacket layer = new LayerDataPacket();
|
||||
byte[] Encoded = new byte[2048];
|
||||
layer.LayerID.Type = 76;
|
||||
GroupHeader header = new GroupHeader();
|
||||
header.Stride = 264;
|
||||
header.PatchSize = 16;
|
||||
header.Type = LayerType.Land;
|
||||
BitPacker newpack = new BitPacker(Encoded,0);
|
||||
newpack.PackBits(header.Stride,16);
|
||||
newpack.PackBits(header.PatchSize,8);
|
||||
newpack.PackBits((int)header.Type,8);
|
||||
|
||||
|
||||
float[] height;
|
||||
for(int y = minY; y< maxY; y++)
|
||||
{
|
||||
for(int x = minX ; x < maxX ; x++)
|
||||
{
|
||||
height = new float[256];
|
||||
Array.Copy(heightmap, (4096 *y) +(x *256), height, 0, 256);
|
||||
|
||||
this.CreatePatch(height, newpack, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
PatchHeader headers = new PatchHeader();
|
||||
headers.QuantWBits = END_OF_PATCHES;
|
||||
this.EncodePatchHeader(newpack, headers);
|
||||
|
||||
int lastused=0;
|
||||
for(int i = 0; i < 2048 ; i++)
|
||||
{
|
||||
if(Encoded[i] !=0)
|
||||
lastused = i;
|
||||
}
|
||||
|
||||
byte[] data = new byte[lastused+1];
|
||||
Array.Copy(Encoded, data, lastused+1);
|
||||
layer.LayerData.Data =data;
|
||||
|
||||
return(layer);
|
||||
}
|
||||
public void CreatePatch(float[] heightmap, BitPacker newpack, int x, int y)
|
||||
{
|
||||
PatchHeader header = new PatchHeader();
|
||||
header.DCOffset = 20.4989f;
|
||||
header.QuantWBits = 139;
|
||||
header.Range = 1;
|
||||
header.PatchIDs = (y & 0x1F);
|
||||
header.PatchIDs += x <<5 ;
|
||||
|
||||
this.EncodePatchHeader(newpack, header);
|
||||
|
||||
int[] newpatch = this.CompressPatch(heightmap);
|
||||
this.EncodePatch(newpatch, newpack, 16);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
public class BitPacker
|
||||
{
|
||||
private const int MAX_BITS = 8;
|
||||
|
||||
private byte[] Data;
|
||||
public int bytePos;
|
||||
public int bitPos;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor, initialize the bit packer / bit unpacker
|
||||
/// with a byte array and starting position
|
||||
/// </summary>
|
||||
/// <param name="data">Byte array to pack bits in to or unpack from</param>
|
||||
/// <param name="pos">Starting position in the byte array</param>
|
||||
public BitPacker(byte[] data, int pos)
|
||||
{
|
||||
Data = data;
|
||||
bytePos = pos;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pack a floating point value in to the data
|
||||
/// </summary>
|
||||
/// <param name="data">Floating point value to pack</param>
|
||||
public void PackFloat(float data)
|
||||
{
|
||||
byte[] input = BitConverter.GetBytes(data);
|
||||
PackBitArray(input, 32);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pack part or all of an integer in to the data
|
||||
/// </summary>
|
||||
/// <param name="data">Integer containing the data to pack</param>
|
||||
/// <param name="totalCount">Number of bits of the integer to pack</param>
|
||||
public void PackBits(int data, int totalCount)
|
||||
{
|
||||
byte[] input = BitConverter.GetBytes(data);
|
||||
PackBitArray(input, totalCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpacking a floating point value from the data
|
||||
/// </summary>
|
||||
/// <returns>Unpacked floating point value</returns>
|
||||
public float UnpackFloat()
|
||||
{
|
||||
byte[] output = UnpackBitsArray(32);
|
||||
|
||||
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||
return BitConverter.ToSingle(output, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpack a variable number of bits from the data in to integer format
|
||||
/// </summary>
|
||||
/// <param name="totalCount">Number of bits to unpack</param>
|
||||
/// <returns>An integer containing the unpacked bits</returns>
|
||||
/// <remarks>This function is only useful up to 32 bits</remarks>
|
||||
public int UnpackBits(int totalCount)
|
||||
{
|
||||
byte[] output = UnpackBitsArray(totalCount);
|
||||
|
||||
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||
return BitConverter.ToInt32(output, 0);
|
||||
}
|
||||
|
||||
private void PackBitArray(byte[] data, int totalCount)
|
||||
{
|
||||
int count = 0;
|
||||
int curBytePos = 0;
|
||||
int curBitPos = 0;
|
||||
|
||||
while (totalCount > 0)
|
||||
{
|
||||
if (totalCount > (MAX_BITS ))
|
||||
{
|
||||
count = MAX_BITS ;
|
||||
totalCount -= MAX_BITS ;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = totalCount;
|
||||
totalCount = 0;
|
||||
}
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
switch(count)
|
||||
{
|
||||
case 1:
|
||||
if ((data[curBytePos] & (0x01)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ((data[curBytePos] & (0x02)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if ((data[curBytePos] & (0x04)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if ((data[curBytePos] & (0x08)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if ((data[curBytePos] & (0x10)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if ((data[curBytePos] & (0x20)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if ((data[curBytePos] & (0x40)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if ((data[curBytePos] & (0x80)) != 0)
|
||||
{
|
||||
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
bitPos++;
|
||||
--count;
|
||||
++curBitPos;
|
||||
|
||||
if (bitPos >= MAX_BITS)
|
||||
{
|
||||
bitPos = 0;
|
||||
++bytePos;
|
||||
}
|
||||
if (curBitPos >= MAX_BITS)
|
||||
{
|
||||
curBitPos = 0;
|
||||
++curBytePos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] UnpackBitsArray(int totalCount)
|
||||
{
|
||||
int count = 0;
|
||||
byte[] output = new byte[4];
|
||||
int curBytePos = 0;
|
||||
int curBitPos = 0;
|
||||
|
||||
while (totalCount > 0)
|
||||
{
|
||||
if (totalCount > MAX_BITS)
|
||||
{
|
||||
count = MAX_BITS;
|
||||
totalCount -= MAX_BITS;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = totalCount;
|
||||
totalCount = 0;
|
||||
}
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
// Shift the previous bits
|
||||
output[curBytePos] <<= 1;
|
||||
|
||||
// Grab one bit
|
||||
if ((Data[bytePos] & (0x80 >> bitPos++)) != 0)
|
||||
++output[curBytePos];
|
||||
|
||||
--count;
|
||||
++curBitPos;
|
||||
|
||||
if (bitPos >= MAX_BITS)
|
||||
{
|
||||
bitPos = 0;
|
||||
++bytePos;
|
||||
}
|
||||
if (curBitPos >= MAX_BITS)
|
||||
{
|
||||
curBitPos = 0;
|
||||
++curBytePos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,10 +12,10 @@ namespace OpenSim.world
|
|||
public Dictionary<libsecondlife.LLUUID, Entity> Entities;
|
||||
public float[] LandMap;
|
||||
public ScriptEngine Scripts;
|
||||
public TerrainDecode terrainengine = new TerrainDecode();
|
||||
public uint _localNumber=0;
|
||||
private PhysicsScene phyScene;
|
||||
private float timeStep= 0.1f;
|
||||
private libsecondlife.TerrainManager TerrainManager;
|
||||
|
||||
private Random Rand = new Random();
|
||||
|
||||
|
@ -25,13 +25,11 @@ namespace OpenSim.world
|
|||
Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
|
||||
|
||||
ServerConsole.MainConsole.Instance.WriteLine("World.cs - creating LandMap");
|
||||
terrainengine = new TerrainDecode();
|
||||
LandMap = new float[65536];
|
||||
|
||||
|
||||
ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
|
||||
TerrainManager = new TerrainManager(new SecondLife());
|
||||
|
||||
// ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
|
||||
// Initialise this only after the world has loaded
|
||||
Scripts = new ScriptEngine(this);
|
||||
// Scripts = new ScriptEngine(this);
|
||||
}
|
||||
|
||||
public PhysicsScene PhysScene
|
||||
|
@ -40,6 +38,10 @@ namespace OpenSim.world
|
|||
{
|
||||
this.phyScene = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return(this.phyScene);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
|
@ -64,10 +66,21 @@ namespace OpenSim.world
|
|||
}
|
||||
|
||||
public void SendLayerData(OpenSimClient RemoteClient) {
|
||||
for(int x=0; x<16; x=x+4) for(int y=0; y<16; y++){
|
||||
Packet layerpack=this.terrainengine.CreateLayerPacket(LandMap, x,y,x+4,y+1);
|
||||
RemoteClient.OutPacket(layerpack);
|
||||
}
|
||||
int[] patches = new int[4];
|
||||
|
||||
for (int y = 0; y < 16; y++)
|
||||
{
|
||||
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;
|
||||
|
||||
Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches);
|
||||
RemoteClient.OutPacket(layerpack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddViewerAgent(OpenSimClient AgentClient) {
|
||||
|
|
Loading…
Reference in New Issue