Simian:
* Added IAssetProvider interface, converted AssetManager to new interface * Some prep work to get ready for proper image delivery git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@2206 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
@@ -7,9 +7,10 @@ using OpenMetaverse.Packets;
|
||||
|
||||
namespace Simian.Extensions
|
||||
{
|
||||
public class AssetManager : ISimianExtension
|
||||
public class AssetManager : ISimianExtension, IAssetProvider
|
||||
{
|
||||
Simian Server;
|
||||
public Dictionary<UUID, Asset> AssetStore = new Dictionary<UUID, Asset>();
|
||||
Dictionary<ulong, Asset> CurrentUploads = new Dictionary<ulong, Asset>();
|
||||
|
||||
public AssetManager(Simian server)
|
||||
@@ -31,6 +32,39 @@ namespace Simian.Extensions
|
||||
{
|
||||
}
|
||||
|
||||
public void StoreAsset(Asset asset)
|
||||
{
|
||||
if (asset.Decode())
|
||||
{
|
||||
lock (AssetStore)
|
||||
AssetStore[asset.AssetID] = asset;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log(String.Format("Failed to decode {0} asset {1}", asset.AssetType, asset.AssetID),
|
||||
Helpers.LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
public void StoreTexture(AssetTexture texture)
|
||||
{
|
||||
if (texture.DecodeLayerBoundaries())
|
||||
{
|
||||
lock (AssetStore)
|
||||
AssetStore[texture.AssetID] = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log(String.Format("Failed to decoded layer boundaries on texture {0}", texture.AssetID),
|
||||
Helpers.LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetAsset(UUID id, out Asset asset)
|
||||
{
|
||||
return AssetStore.TryGetValue(id, out asset);
|
||||
}
|
||||
|
||||
#region Xfer System
|
||||
|
||||
void AssetUploadRequestHandler(Packet packet, Agent agent)
|
||||
@@ -51,8 +85,7 @@ namespace Simian.Extensions
|
||||
Logger.DebugLog(String.Format("Storing uploaded asset {0} ({1})", assetID, asset.AssetType));
|
||||
|
||||
// Store the asset
|
||||
lock (Server.AssetStore)
|
||||
Server.AssetStore[assetID] = asset;
|
||||
StoreAsset(asset);
|
||||
|
||||
// Send a success response
|
||||
AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
|
||||
@@ -135,8 +168,7 @@ namespace Simian.Extensions
|
||||
lock (CurrentUploads)
|
||||
CurrentUploads.Remove(xfer.XferID.ID);
|
||||
|
||||
lock (Server.AssetStore)
|
||||
Server.AssetStore[asset.AssetID] = asset;
|
||||
StoreAsset(asset);
|
||||
|
||||
AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
|
||||
complete.AssetBlock.Success = true;
|
||||
@@ -207,7 +239,7 @@ namespace Simian.Extensions
|
||||
|
||||
// Check if we have this asset
|
||||
Asset asset;
|
||||
if (Server.AssetStore.TryGetValue(assetID, out asset))
|
||||
if (AssetStore.TryGetValue(assetID, out asset))
|
||||
{
|
||||
if (asset.AssetType == type)
|
||||
{
|
||||
@@ -358,25 +390,22 @@ namespace Simian.Extensions
|
||||
for (int i = 0; i < textures.Length; i++)
|
||||
{
|
||||
UUID assetID = ParseUUIDFromFilename(textures[i]);
|
||||
AssetTexture item = new AssetTexture(assetID, File.ReadAllBytes(textures[i]));
|
||||
Server.AssetStore[assetID] = item;
|
||||
StoreTexture(new AssetTexture(assetID, File.ReadAllBytes(textures[i])));
|
||||
}
|
||||
|
||||
for (int i = 0; i < clothing.Length; i++)
|
||||
{
|
||||
UUID assetID = ParseUUIDFromFilename(clothing[i]);
|
||||
AssetClothing item = new AssetClothing(assetID, File.ReadAllBytes(clothing[i]));
|
||||
item.Decode();
|
||||
Server.AssetStore[assetID] = item;
|
||||
StoreAsset(new AssetClothing(assetID, File.ReadAllBytes(clothing[i])));
|
||||
}
|
||||
|
||||
for (int i = 0; i < bodyparts.Length; i++)
|
||||
{
|
||||
UUID assetID = ParseUUIDFromFilename(bodyparts[i]);
|
||||
AssetBodypart item = new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i]));
|
||||
item.Decode();
|
||||
Server.AssetStore[assetID] = item;
|
||||
StoreAsset(new AssetBodypart(assetID, File.ReadAllBytes(bodyparts[i])));
|
||||
}
|
||||
|
||||
Logger.DebugLog(String.Format("Loaded {0} assets", AssetStore.Count));
|
||||
}
|
||||
|
||||
static UUID ParseUUIDFromFilename(string filename)
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Simian.Extensions
|
||||
public class ImageDelivery : ISimianExtension
|
||||
{
|
||||
Simian Server;
|
||||
byte[] DefaultJP2;
|
||||
byte[] DefaultBakedJP2;
|
||||
AssetTexture defaultJP2;
|
||||
AssetTexture defaultBakedJP2;
|
||||
|
||||
public ImageDelivery(Simian server)
|
||||
{
|
||||
@@ -22,6 +22,7 @@ namespace Simian.Extensions
|
||||
{
|
||||
Server.UDP.RegisterPacketCallback(PacketType.RequestImage, new PacketCallback(RequestImageHandler));
|
||||
|
||||
// Create default textures for missing images and missing bakes
|
||||
Bitmap defaultImage = new Bitmap(32, 32);
|
||||
Graphics gfx = Graphics.FromImage(defaultImage);
|
||||
gfx.Clear(Color.White);
|
||||
@@ -36,8 +37,8 @@ namespace Simian.Extensions
|
||||
defaultBaked.Alpha = defaultBaked.Red;
|
||||
defaultBaked.Bump = defaultBaked.Red;
|
||||
|
||||
DefaultJP2 = OpenJPEG.Encode(defaultManaged, true);
|
||||
DefaultBakedJP2 = OpenJPEG.Encode(defaultBaked, true);
|
||||
defaultJP2 = new AssetTexture(UUID.Zero, OpenJPEG.Encode(defaultManaged, true));
|
||||
defaultBakedJP2 = new AssetTexture(UUID.Zero, OpenJPEG.Encode(defaultBaked, true));
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -60,12 +61,12 @@ namespace Simian.Extensions
|
||||
if (bake)
|
||||
{
|
||||
Logger.DebugLog(String.Format("Sending default bake texture for {0}", block.Image));
|
||||
imageData.ImageData.Data = DefaultBakedJP2;
|
||||
imageData.ImageData.Data = defaultBakedJP2.AssetData;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.DebugLog(String.Format("Sending default texture for {0}", block.Image));
|
||||
imageData.ImageData.Data = DefaultJP2;
|
||||
imageData.ImageData.Data = defaultJP2.AssetData;
|
||||
}
|
||||
imageData.ImageID.Size = (uint)imageData.ImageData.Data.Length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user