* Moved TexturePipeline into libOpenMetaverse (still needs to be instantiated separately)
* Moved TextureCache into its own file * New version of Periscope, major improvements. Check the Simian.ini file for usage, and change the const values in Periscope.cs * Lots of miscellaneous cleanups and improvements in Simian git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@2383 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using ExtensionLoader;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.Imaging;
|
||||
using OpenMetaverse.Packets;
|
||||
|
||||
namespace Simian.Extensions
|
||||
@@ -14,14 +13,16 @@ namespace Simian.Extensions
|
||||
public const int IMAGE_PACKET_SIZE = 1000;
|
||||
|
||||
public AssetTexture Texture;
|
||||
public Agent Agent;
|
||||
public int DiscardLevel;
|
||||
public float Priority;
|
||||
public int CurrentPacket;
|
||||
public int StopPacket;
|
||||
|
||||
public ImageDownload(AssetTexture texture, int discardLevel, float priority, int packet)
|
||||
public ImageDownload(AssetTexture texture, Agent agent, int discardLevel, float priority, int packet)
|
||||
{
|
||||
Texture = texture;
|
||||
Agent = agent;
|
||||
Update(discardLevel, priority, packet);
|
||||
}
|
||||
|
||||
@@ -35,9 +36,28 @@ namespace Simian.Extensions
|
||||
public void Update(int discardLevel, float priority, int packet)
|
||||
{
|
||||
Priority = priority;
|
||||
DiscardLevel = Utils.Clamp(discardLevel, 0, Texture.LayerInfo.Length - 1);
|
||||
StopPacket = GetPacketForBytePosition(Texture.LayerInfo[(Texture.LayerInfo.Length - 1) - DiscardLevel].End);
|
||||
CurrentPacket = Utils.Clamp(packet, 1, TexturePacketCount());
|
||||
|
||||
if (Texture != null)
|
||||
{
|
||||
if (Texture.LayerInfo != null && Texture.LayerInfo.Length > 0)
|
||||
{
|
||||
DiscardLevel = Utils.Clamp(discardLevel, 0, Texture.LayerInfo.Length - 1);
|
||||
StopPacket = GetPacketForBytePosition(Texture.LayerInfo[(Texture.LayerInfo.Length - 1) - DiscardLevel].End);
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscardLevel = 0;
|
||||
StopPacket = GetPacketForBytePosition(Texture.AssetData.Length);
|
||||
}
|
||||
|
||||
CurrentPacket = Utils.Clamp(packet, 1, TexturePacketCount());
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscardLevel = discardLevel;
|
||||
Priority = priority;
|
||||
CurrentPacket = packet;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,7 +114,7 @@ namespace Simian.Extensions
|
||||
{
|
||||
this.server = server;
|
||||
|
||||
server.UDP.RegisterPacketCallback(PacketType.RequestImage, new PacketCallback(RequestImageHandler));
|
||||
server.UDP.RegisterPacketCallback(PacketType.RequestImage, RequestImageHandler);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -151,91 +171,7 @@ namespace Simian.Extensions
|
||||
Asset asset;
|
||||
if (server.Assets.TryGetAsset(block.Image, out asset) && asset is AssetTexture)
|
||||
{
|
||||
download = new ImageDownload((AssetTexture)asset, block.DiscardLevel, block.DownloadPriority,
|
||||
(int)block.Packet);
|
||||
|
||||
Logger.DebugLog(String.Format(
|
||||
"Starting new download for {0}, DiscardLevel: {1}, Priority: {2}, Start: {3}, End: {4}, Total: {5}",
|
||||
block.Image, block.DiscardLevel, block.DownloadPriority, download.CurrentPacket, download.StopPacket,
|
||||
download.TexturePacketCount()));
|
||||
|
||||
// Send initial data
|
||||
ImageDataPacket data = new ImageDataPacket();
|
||||
data.ImageID.Codec = (byte)ImageCodec.J2C;
|
||||
data.ImageID.ID = download.Texture.AssetID;
|
||||
data.ImageID.Packets = (ushort)download.TexturePacketCount();
|
||||
data.ImageID.Size = (uint)download.Texture.AssetData.Length;
|
||||
|
||||
// The first bytes of the image are always sent in the ImageData packet
|
||||
data.ImageData = new ImageDataPacket.ImageDataBlock();
|
||||
int imageDataSize = (download.Texture.AssetData.Length >= ImageDownload.FIRST_IMAGE_PACKET_SIZE) ?
|
||||
ImageDownload.FIRST_IMAGE_PACKET_SIZE : download.Texture.AssetData.Length;
|
||||
try
|
||||
{
|
||||
data.ImageData.Data = new byte[imageDataSize];
|
||||
Buffer.BlockCopy(download.Texture.AssetData, 0, data.ImageData.Data, 0, imageDataSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(String.Format("{0}: imageDataSize={1}", ex.Message, imageDataSize),
|
||||
Helpers.LogLevel.Error);
|
||||
}
|
||||
|
||||
server.UDP.SendPacket(agent.AgentID, data, PacketCategory.Texture);
|
||||
|
||||
// Check if ImagePacket packets need to be sent to complete this transfer
|
||||
if (download.CurrentPacket <= download.StopPacket)
|
||||
{
|
||||
// Insert this download into the dictionary
|
||||
lock (CurrentDownloads)
|
||||
CurrentDownloads[block.Image] = download;
|
||||
|
||||
// Send all of the remaining packets
|
||||
ThreadPool.QueueUserWorkItem(
|
||||
delegate(object obj)
|
||||
{
|
||||
while (download.CurrentPacket <= download.StopPacket)
|
||||
{
|
||||
if (download.Priority == 0.0f && download.DiscardLevel == -1)
|
||||
break;
|
||||
|
||||
lock (download)
|
||||
{
|
||||
int imagePacketSize = (download.CurrentPacket == download.TexturePacketCount() - 1) ?
|
||||
download.LastPacketSize() : ImageDownload.IMAGE_PACKET_SIZE;
|
||||
|
||||
ImagePacketPacket transfer = new ImagePacketPacket();
|
||||
transfer.ImageID.ID = block.Image;
|
||||
transfer.ImageID.Packet = (ushort)download.CurrentPacket;
|
||||
transfer.ImageData.Data = new byte[imagePacketSize];
|
||||
|
||||
try
|
||||
{
|
||||
Buffer.BlockCopy(download.Texture.AssetData, download.CurrentBytePosition(),
|
||||
transfer.ImageData.Data, 0, imagePacketSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(String.Format(
|
||||
"{0}: CurrentBytePosition()={1}, AssetData.Length={2} imagePacketSize={3}",
|
||||
ex.Message, download.CurrentBytePosition(), download.Texture.AssetData.Length,
|
||||
imagePacketSize), Helpers.LogLevel.Error);
|
||||
}
|
||||
|
||||
server.UDP.SendPacket(agent.AgentID, transfer, PacketCategory.Texture);
|
||||
|
||||
++download.CurrentPacket;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.DebugLog("Completed image transfer for " + block.Image.ToString());
|
||||
|
||||
// Transfer is complete, remove the reference
|
||||
lock (CurrentDownloads)
|
||||
CurrentDownloads.Remove(block.Image);
|
||||
}
|
||||
);
|
||||
}
|
||||
SendTexture(agent, (AssetTexture)asset, block.DiscardLevel, (int)block.Packet, block.DownloadPriority);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -248,5 +184,93 @@ namespace Simian.Extensions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SendTexture(Agent agent, AssetTexture texture, int discardLevel, int packet, float priority)
|
||||
{
|
||||
ImageDownload download = new ImageDownload(texture, agent, discardLevel, priority, packet);
|
||||
|
||||
Logger.DebugLog(String.Format(
|
||||
"Starting new download for {0}, DiscardLevel: {1}, Priority: {2}, Start: {3}, End: {4}, Total: {5}",
|
||||
texture.AssetID, discardLevel, priority, download.CurrentPacket, download.StopPacket,
|
||||
download.TexturePacketCount()));
|
||||
|
||||
// Send initial data
|
||||
ImageDataPacket data = new ImageDataPacket();
|
||||
data.ImageID.Codec = (byte)ImageCodec.J2C;
|
||||
data.ImageID.ID = download.Texture.AssetID;
|
||||
data.ImageID.Packets = (ushort)download.TexturePacketCount();
|
||||
data.ImageID.Size = (uint)download.Texture.AssetData.Length;
|
||||
|
||||
// The first bytes of the image are always sent in the ImageData packet
|
||||
data.ImageData = new ImageDataPacket.ImageDataBlock();
|
||||
int imageDataSize = (download.Texture.AssetData.Length >= ImageDownload.FIRST_IMAGE_PACKET_SIZE) ?
|
||||
ImageDownload.FIRST_IMAGE_PACKET_SIZE : download.Texture.AssetData.Length;
|
||||
try
|
||||
{
|
||||
data.ImageData.Data = new byte[imageDataSize];
|
||||
Buffer.BlockCopy(download.Texture.AssetData, 0, data.ImageData.Data, 0, imageDataSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(String.Format("{0}: imageDataSize={1}", ex.Message, imageDataSize),
|
||||
Helpers.LogLevel.Error);
|
||||
}
|
||||
|
||||
server.UDP.SendPacket(agent.AgentID, data, PacketCategory.Texture);
|
||||
|
||||
// Check if ImagePacket packets need to be sent to complete this transfer
|
||||
if (download.CurrentPacket <= download.StopPacket)
|
||||
{
|
||||
// Insert this download into the dictionary
|
||||
lock (CurrentDownloads)
|
||||
CurrentDownloads[texture.AssetID] = download;
|
||||
|
||||
// Send all of the remaining packets
|
||||
ThreadPool.QueueUserWorkItem(
|
||||
delegate(object obj)
|
||||
{
|
||||
while (download.CurrentPacket <= download.StopPacket)
|
||||
{
|
||||
if (download.Priority == 0.0f && download.DiscardLevel == -1)
|
||||
break;
|
||||
|
||||
lock (download)
|
||||
{
|
||||
int imagePacketSize = (download.CurrentPacket == download.TexturePacketCount() - 1) ?
|
||||
download.LastPacketSize() : ImageDownload.IMAGE_PACKET_SIZE;
|
||||
|
||||
ImagePacketPacket transfer = new ImagePacketPacket();
|
||||
transfer.ImageID.ID = texture.AssetID;
|
||||
transfer.ImageID.Packet = (ushort)download.CurrentPacket;
|
||||
transfer.ImageData.Data = new byte[imagePacketSize];
|
||||
|
||||
try
|
||||
{
|
||||
Buffer.BlockCopy(download.Texture.AssetData, download.CurrentBytePosition(),
|
||||
transfer.ImageData.Data, 0, imagePacketSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(String.Format(
|
||||
"{0}: CurrentBytePosition()={1}, AssetData.Length={2} imagePacketSize={3}",
|
||||
ex.Message, download.CurrentBytePosition(), download.Texture.AssetData.Length,
|
||||
imagePacketSize), Helpers.LogLevel.Error);
|
||||
}
|
||||
|
||||
server.UDP.SendPacket(agent.AgentID, transfer, PacketCategory.Texture);
|
||||
|
||||
++download.CurrentPacket;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.DebugLog("Completed image transfer for " + texture.AssetID.ToString());
|
||||
|
||||
// Transfer is complete, remove the reference
|
||||
lock (CurrentDownloads)
|
||||
CurrentDownloads.Remove(texture.AssetID);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user