mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 09:45:47 +08:00
Merge branch 'avination' into careminster
Conflicts: OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs OpenSim/Region/Framework/Scenes/Scene.cs
This commit is contained in:
File diff suppressed because it is too large
Load Diff
671
OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs
Normal file
671
OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshCost.cs
Normal file
@@ -0,0 +1,671 @@
|
||||
// Proprietary code of Avination Virtual Limited
|
||||
// (c) 2012 Melanie Thielker, Leal Duarte
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.StructuredData;
|
||||
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Framework;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Framework.Capabilities;
|
||||
|
||||
using ComponentAce.Compression.Libs.zlib;
|
||||
|
||||
using OSDArray = OpenMetaverse.StructuredData.OSDArray;
|
||||
using OSDMap = OpenMetaverse.StructuredData.OSDMap;
|
||||
|
||||
namespace OpenSim.Region.ClientStack.Linden
|
||||
{
|
||||
public struct ModelPrimLimits
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ModelCost
|
||||
{
|
||||
|
||||
// upload fee defaults
|
||||
// fees are normalized to 1.0
|
||||
// this parameters scale them to basic cost ( so 1.0 translates to 10 )
|
||||
|
||||
public float ModelMeshCostFactor = 0.0f; // scale total cost relative to basic (excluding textures)
|
||||
public float ModelTextureCostFactor = 1.0f; // scale textures fee to basic.
|
||||
public float ModelMinCostFactor = 0.0f; // 0.5f; // minimum total model free excluding textures
|
||||
|
||||
// itens costs in normalized values
|
||||
// ie will be multiplied by basicCost and factors above
|
||||
public float primCreationCost = 0.002f; // extra cost for each prim creation overhead
|
||||
// weigthed size to normalized cost
|
||||
public float bytecost = 1e-5f;
|
||||
|
||||
// mesh upload fees based on compressed data sizes
|
||||
// several data sections are counted more that once
|
||||
// to promote user optimization
|
||||
// following parameters control how many extra times they are added
|
||||
// to global size.
|
||||
// LOD meshs
|
||||
const float medSizeWth = 1f; // 2x
|
||||
const float lowSizeWth = 1.5f; // 2.5x
|
||||
const float lowestSizeWth = 2f; // 3x
|
||||
// favor potencially physical optimized meshs versus automatic decomposition
|
||||
const float physMeshSizeWth = 6f; // counts 7x
|
||||
const float physHullSizeWth = 8f; // counts 9x
|
||||
|
||||
// stream cost area factors
|
||||
// more or less like SL
|
||||
const float highLodFactor = 17.36f;
|
||||
const float midLodFactor = 277.78f;
|
||||
const float lowLodFactor = 1111.11f;
|
||||
|
||||
// physics cost is below, identical to SL, assuming shape type convex
|
||||
// server cost is below identical to SL assuming non scripted non physical object
|
||||
|
||||
// internal
|
||||
const int bytesPerCoord = 6; // 3 coords, 2 bytes per each
|
||||
|
||||
// control prims dimensions
|
||||
public float PrimScaleMin = 0.001f;
|
||||
public float NonPhysicalPrimScaleMax = 256f;
|
||||
public float PhysicalPrimScaleMax = 10f;
|
||||
public int ObjectLinkedPartsMax = 512;
|
||||
|
||||
// storage for a single mesh asset cost parameters
|
||||
private class ameshCostParam
|
||||
{
|
||||
// LOD sizes for size dependent streaming cost
|
||||
public int highLODSize;
|
||||
public int medLODSize;
|
||||
public int lowLODSize;
|
||||
public int lowestLODSize;
|
||||
// normalized fee based on compressed data sizes
|
||||
public float costFee;
|
||||
// physics cost
|
||||
public float physicsCost;
|
||||
}
|
||||
|
||||
// calculates a mesh model costs
|
||||
// returns false on error, with a reason on parameter error
|
||||
// resources input LLSD request
|
||||
// basicCost input region assets upload cost
|
||||
// totalcost returns model total upload fee
|
||||
// meshcostdata returns detailed costs for viewer
|
||||
public bool MeshModelCost(LLSDAssetResource resources, int basicCost, out int totalcost,
|
||||
LLSDAssetUploadResponseData meshcostdata, out string error, ref string warning)
|
||||
{
|
||||
totalcost = 0;
|
||||
error = string.Empty;
|
||||
|
||||
if (resources == null ||
|
||||
resources.instance_list == null ||
|
||||
resources.instance_list.Array.Count == 0)
|
||||
{
|
||||
error = "missing model information.";
|
||||
return false;
|
||||
}
|
||||
|
||||
int numberInstances = resources.instance_list.Array.Count;
|
||||
|
||||
if( numberInstances > ObjectLinkedPartsMax )
|
||||
{
|
||||
error = "Model whould have more than " + ObjectLinkedPartsMax.ToString() + " linked prims";
|
||||
return false;
|
||||
}
|
||||
|
||||
meshcostdata.model_streaming_cost = 0.0;
|
||||
meshcostdata.simulation_cost = 0.0;
|
||||
meshcostdata.physics_cost = 0.0;
|
||||
meshcostdata.resource_cost = 0.0;
|
||||
|
||||
meshcostdata.upload_price_breakdown.mesh_instance = 0;
|
||||
meshcostdata.upload_price_breakdown.mesh_physics = 0;
|
||||
meshcostdata.upload_price_breakdown.mesh_streaming = 0;
|
||||
meshcostdata.upload_price_breakdown.model = 0;
|
||||
|
||||
int itmp;
|
||||
|
||||
// textures cost
|
||||
if (resources.texture_list != null && resources.texture_list.Array.Count > 0)
|
||||
{
|
||||
float textures_cost = (float)(resources.texture_list.Array.Count * basicCost);
|
||||
textures_cost *= ModelTextureCostFactor;
|
||||
|
||||
itmp = (int)(textures_cost + 0.5f); // round
|
||||
meshcostdata.upload_price_breakdown.texture = itmp;
|
||||
totalcost += itmp;
|
||||
}
|
||||
|
||||
// meshs assets cost
|
||||
float meshsfee = 0;
|
||||
int numberMeshs = 0;
|
||||
bool haveMeshs = false;
|
||||
List<ameshCostParam> meshsCosts = new List<ameshCostParam>();
|
||||
|
||||
if (resources.mesh_list != null && resources.mesh_list.Array.Count > 0)
|
||||
{
|
||||
numberMeshs = resources.mesh_list.Array.Count;
|
||||
|
||||
for (int i = 0; i < numberMeshs; i++)
|
||||
{
|
||||
ameshCostParam curCost = new ameshCostParam();
|
||||
byte[] data = (byte[])resources.mesh_list.Array[i];
|
||||
|
||||
if (!MeshCost(data, curCost, out error))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
meshsCosts.Add(curCost);
|
||||
meshsfee += curCost.costFee;
|
||||
}
|
||||
haveMeshs = true;
|
||||
}
|
||||
|
||||
// instances (prims) cost
|
||||
|
||||
|
||||
int mesh;
|
||||
int skipedSmall = 0;
|
||||
for (int i = 0; i < numberInstances; i++)
|
||||
{
|
||||
Hashtable inst = (Hashtable)resources.instance_list.Array[i];
|
||||
|
||||
ArrayList ascale = (ArrayList)inst["scale"];
|
||||
Vector3 scale;
|
||||
double tmp;
|
||||
tmp = (double)ascale[0];
|
||||
scale.X = (float)tmp;
|
||||
tmp = (double)ascale[1];
|
||||
scale.Y = (float)tmp;
|
||||
tmp = (double)ascale[2];
|
||||
scale.Z = (float)tmp;
|
||||
|
||||
if (scale.X < PrimScaleMin || scale.Y < PrimScaleMin || scale.Z < PrimScaleMin)
|
||||
{
|
||||
skipedSmall++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (scale.X > NonPhysicalPrimScaleMax || scale.Y > NonPhysicalPrimScaleMax || scale.Z > NonPhysicalPrimScaleMax)
|
||||
{
|
||||
error = "Model contains parts with sides larger than " + NonPhysicalPrimScaleMax.ToString() + "m. Please ajust scale";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (haveMeshs && inst.ContainsKey("mesh"))
|
||||
{
|
||||
mesh = (int)inst["mesh"];
|
||||
|
||||
if (mesh >= numberMeshs)
|
||||
{
|
||||
error = "Incoerent model information.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// streamming cost
|
||||
|
||||
float sqdiam = scale.LengthSquared();
|
||||
|
||||
ameshCostParam curCost = meshsCosts[mesh];
|
||||
float mesh_streaming = streamingCost(curCost, sqdiam);
|
||||
|
||||
meshcostdata.model_streaming_cost += mesh_streaming;
|
||||
meshcostdata.physics_cost += curCost.physicsCost;
|
||||
}
|
||||
else // instance as no mesh ??
|
||||
{
|
||||
// to do later if needed
|
||||
meshcostdata.model_streaming_cost += 0.5f;
|
||||
meshcostdata.physics_cost += 1.0f;
|
||||
}
|
||||
|
||||
// assume unscripted and static prim server cost
|
||||
meshcostdata.simulation_cost += 0.5f;
|
||||
// charge for prims creation
|
||||
meshsfee += primCreationCost;
|
||||
}
|
||||
|
||||
if (skipedSmall > 0)
|
||||
{
|
||||
if (skipedSmall > numberInstances / 2)
|
||||
{
|
||||
error = "Model contains too many prims smaller than " + PrimScaleMin.ToString() +
|
||||
"m minimum allowed size. Please check scalling";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
warning += skipedSmall.ToString() + " of the requested " +numberInstances.ToString() +
|
||||
" model prims will not upload because they are smaller than " + PrimScaleMin.ToString() +
|
||||
"m minimum allowed size. Please check scalling ";
|
||||
}
|
||||
|
||||
if (meshcostdata.physics_cost <= meshcostdata.model_streaming_cost)
|
||||
meshcostdata.resource_cost = meshcostdata.model_streaming_cost;
|
||||
else
|
||||
meshcostdata.resource_cost = meshcostdata.physics_cost;
|
||||
|
||||
if (meshcostdata.resource_cost < meshcostdata.simulation_cost)
|
||||
meshcostdata.resource_cost = meshcostdata.simulation_cost;
|
||||
|
||||
// scale cost
|
||||
// at this point a cost of 1.0 whould mean basic cost
|
||||
meshsfee *= ModelMeshCostFactor;
|
||||
|
||||
if (meshsfee < ModelMinCostFactor)
|
||||
meshsfee = ModelMinCostFactor;
|
||||
|
||||
// actually scale it to basic cost
|
||||
meshsfee *= (float)basicCost;
|
||||
|
||||
meshsfee += 0.5f; // rounding
|
||||
|
||||
totalcost += (int)meshsfee;
|
||||
|
||||
// breakdown prices
|
||||
// don't seem to be in use so removed code for now
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// single mesh asset cost
|
||||
private bool MeshCost(byte[] data, ameshCostParam cost, out string error)
|
||||
{
|
||||
cost.highLODSize = 0;
|
||||
cost.medLODSize = 0;
|
||||
cost.lowLODSize = 0;
|
||||
cost.lowestLODSize = 0;
|
||||
cost.physicsCost = 0.0f;
|
||||
cost.costFee = 0.0f;
|
||||
|
||||
error = string.Empty;
|
||||
|
||||
if (data == null || data.Length == 0)
|
||||
{
|
||||
error = "Missing model information.";
|
||||
return false;
|
||||
}
|
||||
|
||||
OSD meshOsd = null;
|
||||
int start = 0;
|
||||
|
||||
error = "Invalid model data";
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(data))
|
||||
{
|
||||
try
|
||||
{
|
||||
OSD osd = OSDParser.DeserializeLLSDBinary(ms);
|
||||
if (osd is OSDMap)
|
||||
meshOsd = (OSDMap)osd;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
start = (int)ms.Position;
|
||||
}
|
||||
|
||||
OSDMap map = (OSDMap)meshOsd;
|
||||
OSDMap tmpmap;
|
||||
|
||||
int highlod_size = 0;
|
||||
int medlod_size = 0;
|
||||
int lowlod_size = 0;
|
||||
int lowestlod_size = 0;
|
||||
int skin_size = 0;
|
||||
|
||||
int hulls_size = 0;
|
||||
int phys_nhulls;
|
||||
int phys_hullsvertices = 0;
|
||||
|
||||
int physmesh_size = 0;
|
||||
int phys_ntriangles = 0;
|
||||
|
||||
int submesh_offset = -1;
|
||||
|
||||
if (map.ContainsKey("physics_convex"))
|
||||
{
|
||||
tmpmap = (OSDMap)map["physics_convex"];
|
||||
if (tmpmap.ContainsKey("offset"))
|
||||
submesh_offset = tmpmap["offset"].AsInteger() + start;
|
||||
if (tmpmap.ContainsKey("size"))
|
||||
hulls_size = tmpmap["size"].AsInteger();
|
||||
}
|
||||
|
||||
if (submesh_offset < 0 || hulls_size == 0)
|
||||
{
|
||||
error = "Missing physics_convex block";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hulls(data, submesh_offset, hulls_size, out phys_hullsvertices, out phys_nhulls))
|
||||
{
|
||||
error = "Bad physics_convex block";
|
||||
return false;
|
||||
}
|
||||
|
||||
submesh_offset = -1;
|
||||
|
||||
// only look for LOD meshs sizes
|
||||
|
||||
if (map.ContainsKey("high_lod"))
|
||||
{
|
||||
tmpmap = (OSDMap)map["high_lod"];
|
||||
// see at least if there is a offset for this one
|
||||
if (tmpmap.ContainsKey("offset"))
|
||||
submesh_offset = tmpmap["offset"].AsInteger() + start;
|
||||
if (tmpmap.ContainsKey("size"))
|
||||
highlod_size = tmpmap["size"].AsInteger();
|
||||
}
|
||||
|
||||
if (submesh_offset < 0 || highlod_size <= 0)
|
||||
{
|
||||
error = "Missing high_lod block";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool haveprev = true;
|
||||
|
||||
if (map.ContainsKey("medium_lod"))
|
||||
{
|
||||
tmpmap = (OSDMap)map["medium_lod"];
|
||||
if (tmpmap.ContainsKey("size"))
|
||||
medlod_size = tmpmap["size"].AsInteger();
|
||||
else
|
||||
haveprev = false;
|
||||
}
|
||||
|
||||
if (haveprev && map.ContainsKey("low_lod"))
|
||||
{
|
||||
tmpmap = (OSDMap)map["low_lod"];
|
||||
if (tmpmap.ContainsKey("size"))
|
||||
lowlod_size = tmpmap["size"].AsInteger();
|
||||
else
|
||||
haveprev = false;
|
||||
}
|
||||
|
||||
if (haveprev && map.ContainsKey("lowest_lod"))
|
||||
{
|
||||
tmpmap = (OSDMap)map["lowest_lod"];
|
||||
if (tmpmap.ContainsKey("size"))
|
||||
lowestlod_size = tmpmap["size"].AsInteger();
|
||||
}
|
||||
|
||||
if (map.ContainsKey("skin"))
|
||||
{
|
||||
tmpmap = (OSDMap)map["skin"];
|
||||
if (tmpmap.ContainsKey("size"))
|
||||
skin_size = tmpmap["size"].AsInteger();
|
||||
}
|
||||
|
||||
cost.highLODSize = highlod_size;
|
||||
cost.medLODSize = medlod_size;
|
||||
cost.lowLODSize = lowlod_size;
|
||||
cost.lowestLODSize = lowestlod_size;
|
||||
|
||||
submesh_offset = -1;
|
||||
|
||||
tmpmap = null;
|
||||
if(map.ContainsKey("physics_mesh"))
|
||||
tmpmap = (OSDMap)map["physics_mesh"];
|
||||
else if (map.ContainsKey("physics_shape")) // old naming
|
||||
tmpmap = (OSDMap)map["physics_shape"];
|
||||
|
||||
if(tmpmap != null)
|
||||
{
|
||||
if (tmpmap.ContainsKey("offset"))
|
||||
submesh_offset = tmpmap["offset"].AsInteger() + start;
|
||||
if (tmpmap.ContainsKey("size"))
|
||||
physmesh_size = tmpmap["size"].AsInteger();
|
||||
|
||||
if (submesh_offset >= 0 || physmesh_size > 0)
|
||||
{
|
||||
|
||||
if (!submesh(data, submesh_offset, physmesh_size, out phys_ntriangles))
|
||||
{
|
||||
error = "Model data parsing error";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// upload is done in convex shape type so only one hull
|
||||
phys_hullsvertices++;
|
||||
cost.physicsCost = 0.04f * phys_hullsvertices;
|
||||
|
||||
float sfee;
|
||||
|
||||
sfee = data.Length; // start with total compressed data size
|
||||
|
||||
// penalize lod meshs that should be more builder optimized
|
||||
sfee += medSizeWth * medlod_size;
|
||||
sfee += lowSizeWth * lowlod_size;
|
||||
sfee += lowestSizeWth * lowlod_size;
|
||||
|
||||
// physics
|
||||
// favor potencial optimized meshs versus automatic decomposition
|
||||
if (physmesh_size != 0)
|
||||
sfee += physMeshSizeWth * (physmesh_size + hulls_size / 4); // reduce cost of mandatory convex hull
|
||||
else
|
||||
sfee += physHullSizeWth * hulls_size;
|
||||
|
||||
// bytes to money
|
||||
sfee *= bytecost;
|
||||
|
||||
cost.costFee = sfee;
|
||||
return true;
|
||||
}
|
||||
|
||||
// parses a LOD or physics mesh component
|
||||
private bool submesh(byte[] data, int offset, int size, out int ntriangles)
|
||||
{
|
||||
ntriangles = 0;
|
||||
|
||||
OSD decodedMeshOsd = new OSD();
|
||||
byte[] meshBytes = new byte[size];
|
||||
System.Buffer.BlockCopy(data, offset, meshBytes, 0, size);
|
||||
try
|
||||
{
|
||||
using (MemoryStream inMs = new MemoryStream(meshBytes))
|
||||
{
|
||||
using (MemoryStream outMs = new MemoryStream())
|
||||
{
|
||||
using (ZOutputStream zOut = new ZOutputStream(outMs))
|
||||
{
|
||||
byte[] readBuffer = new byte[4096];
|
||||
int readLen = 0;
|
||||
while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
|
||||
{
|
||||
zOut.Write(readBuffer, 0, readLen);
|
||||
}
|
||||
zOut.Flush();
|
||||
outMs.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
byte[] decompressedBuf = outMs.GetBuffer();
|
||||
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OSDArray decodedMeshOsdArray = null;
|
||||
if ((!decodedMeshOsd is OSDArray))
|
||||
return false;
|
||||
|
||||
byte[] dummy;
|
||||
|
||||
decodedMeshOsdArray = (OSDArray)decodedMeshOsd;
|
||||
foreach (OSD subMeshOsd in decodedMeshOsdArray)
|
||||
{
|
||||
if (subMeshOsd is OSDMap)
|
||||
{
|
||||
OSDMap subtmpmap = (OSDMap)subMeshOsd;
|
||||
if (subtmpmap.ContainsKey("NoGeometry") && ((OSDBoolean)subtmpmap["NoGeometry"]))
|
||||
continue;
|
||||
|
||||
if (!subtmpmap.ContainsKey("Position"))
|
||||
return false;
|
||||
|
||||
if (subtmpmap.ContainsKey("TriangleList"))
|
||||
{
|
||||
dummy = subtmpmap["TriangleList"].AsBinary();
|
||||
ntriangles += dummy.Length / bytesPerCoord;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// parses convex hulls component
|
||||
private bool hulls(byte[] data, int offset, int size, out int nvertices, out int nhulls)
|
||||
{
|
||||
nvertices = 0;
|
||||
nhulls = 1;
|
||||
|
||||
OSD decodedMeshOsd = new OSD();
|
||||
byte[] meshBytes = new byte[size];
|
||||
System.Buffer.BlockCopy(data, offset, meshBytes, 0, size);
|
||||
try
|
||||
{
|
||||
using (MemoryStream inMs = new MemoryStream(meshBytes))
|
||||
{
|
||||
using (MemoryStream outMs = new MemoryStream())
|
||||
{
|
||||
using (ZOutputStream zOut = new ZOutputStream(outMs))
|
||||
{
|
||||
byte[] readBuffer = new byte[4096];
|
||||
int readLen = 0;
|
||||
while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
|
||||
{
|
||||
zOut.Write(readBuffer, 0, readLen);
|
||||
}
|
||||
zOut.Flush();
|
||||
outMs.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
byte[] decompressedBuf = outMs.GetBuffer();
|
||||
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OSDMap cmap = (OSDMap)decodedMeshOsd;
|
||||
if (cmap == null)
|
||||
return false;
|
||||
|
||||
byte[] dummy;
|
||||
|
||||
// must have one of this
|
||||
if (cmap.ContainsKey("BoundingVerts"))
|
||||
{
|
||||
dummy = cmap["BoundingVerts"].AsBinary();
|
||||
nvertices = dummy.Length / bytesPerCoord;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
/* upload is done with convex shape type
|
||||
if (cmap.ContainsKey("HullList"))
|
||||
{
|
||||
dummy = cmap["HullList"].AsBinary();
|
||||
nhulls += dummy.Length;
|
||||
}
|
||||
|
||||
|
||||
if (cmap.ContainsKey("Positions"))
|
||||
{
|
||||
dummy = cmap["Positions"].AsBinary();
|
||||
nvertices = dummy.Length / bytesPerCoord;
|
||||
}
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns streaming cost from on mesh LODs sizes in curCost and square of prim size length
|
||||
private float streamingCost(ameshCostParam curCost, float sqdiam)
|
||||
{
|
||||
// compute efective areas
|
||||
float ma = 262144f;
|
||||
|
||||
float mh = sqdiam * highLodFactor;
|
||||
if (mh > ma)
|
||||
mh = ma;
|
||||
float mm = sqdiam * midLodFactor;
|
||||
if (mm > ma)
|
||||
mm = ma;
|
||||
|
||||
float ml = sqdiam * lowLodFactor;
|
||||
if (ml > ma)
|
||||
ml = ma;
|
||||
|
||||
float mlst = ma;
|
||||
|
||||
mlst -= ml;
|
||||
ml -= mm;
|
||||
mm -= mh;
|
||||
|
||||
if (mlst < 1.0f)
|
||||
mlst = 1.0f;
|
||||
if (ml < 1.0f)
|
||||
ml = 1.0f;
|
||||
if (mm < 1.0f)
|
||||
mm = 1.0f;
|
||||
if (mh < 1.0f)
|
||||
mh = 1.0f;
|
||||
|
||||
ma = mlst + ml + mm + mh;
|
||||
|
||||
// get LODs compressed sizes
|
||||
// giving 384 bytes bonus
|
||||
int lst = curCost.lowestLODSize - 384;
|
||||
int l = curCost.lowLODSize - 384;
|
||||
int m = curCost.medLODSize - 384;
|
||||
int h = curCost.highLODSize - 384;
|
||||
|
||||
// use previus higher LOD size on missing ones
|
||||
if (m <= 0)
|
||||
m = h;
|
||||
if (l <= 0)
|
||||
l = m;
|
||||
if (lst <= 0)
|
||||
lst = l;
|
||||
|
||||
// force minumum sizes
|
||||
if (lst < 16)
|
||||
lst = 16;
|
||||
if (l < 16)
|
||||
l = 16;
|
||||
if (m < 16)
|
||||
m = 16;
|
||||
if (h < 16)
|
||||
h = 16;
|
||||
|
||||
// compute cost weighted by relative effective areas
|
||||
float cost = (float)lst * mlst + (float)l * ml + (float)m * mm + (float)h * mh;
|
||||
cost /= ma;
|
||||
|
||||
cost *= 0.004f; // overall tunning parameter
|
||||
|
||||
return cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,7 +419,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
}
|
||||
}
|
||||
|
||||
public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request)
|
||||
public Hashtable GetEvents(UUID requestID, UUID pAgentId)
|
||||
{
|
||||
if (DebugLevel >= 2)
|
||||
m_log.DebugFormat("POLLED FOR EQ MESSAGES BY {0} in {1}", pAgentId, m_scene.RegionInfo.RegionName);
|
||||
|
||||
@@ -53,6 +53,14 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetTextureModule")]
|
||||
public class GetTextureModule : INonSharedRegionModule
|
||||
{
|
||||
|
||||
struct aPollRequest
|
||||
{
|
||||
public PollServiceTextureEventArgs thepoll;
|
||||
public UUID reqID;
|
||||
public Hashtable request;
|
||||
}
|
||||
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Scene m_scene;
|
||||
@@ -64,8 +72,8 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>();
|
||||
private static Thread[] m_workerThreads = null;
|
||||
|
||||
private static OpenMetaverse.BlockingQueue<PollServiceTextureEventArgs> m_queue =
|
||||
new OpenMetaverse.BlockingQueue<PollServiceTextureEventArgs>();
|
||||
private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue =
|
||||
new OpenMetaverse.BlockingQueue<aPollRequest>();
|
||||
|
||||
#region ISharedRegionModule Members
|
||||
|
||||
@@ -104,7 +112,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
String.Format("TextureWorkerThread{0}", i),
|
||||
ThreadPriority.Normal,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
int.MaxValue);
|
||||
}
|
||||
@@ -129,7 +137,8 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
~GetTextureModule()
|
||||
{
|
||||
foreach (Thread t in m_workerThreads)
|
||||
t.Abort();
|
||||
Watchdog.AbortThread(t.ManagedThreadId);
|
||||
|
||||
}
|
||||
|
||||
private class PollServiceTextureEventArgs : PollServiceEventArgs
|
||||
@@ -142,40 +151,50 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
private Scene m_scene;
|
||||
|
||||
public PollServiceTextureEventArgs(UUID pId, Scene scene) :
|
||||
base(null, null, null, null, pId, 30000)
|
||||
base(null, null, null, null, pId, int.MaxValue)
|
||||
{
|
||||
m_scene = scene;
|
||||
|
||||
HasEvents = (x, y) => { return this.responses.ContainsKey(x); };
|
||||
GetEvents = (x, y, s) =>
|
||||
HasEvents = (x, y) =>
|
||||
{
|
||||
try
|
||||
lock (responses)
|
||||
return responses.ContainsKey(x);
|
||||
};
|
||||
GetEvents = (x, y) =>
|
||||
{
|
||||
lock (responses)
|
||||
{
|
||||
return this.responses[x];
|
||||
}
|
||||
finally
|
||||
{
|
||||
responses.Remove(x);
|
||||
try
|
||||
{
|
||||
return responses[x];
|
||||
}
|
||||
finally
|
||||
{
|
||||
responses.Remove(x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Request = (x, y) =>
|
||||
{
|
||||
y["RequestID"] = x.ToString();
|
||||
lock (this.requests)
|
||||
this.requests.Add(y);
|
||||
aPollRequest reqinfo = new aPollRequest();
|
||||
reqinfo.thepoll = this;
|
||||
reqinfo.reqID = x;
|
||||
reqinfo.request = y;
|
||||
|
||||
m_queue.Enqueue(this);
|
||||
m_queue.Enqueue(reqinfo);
|
||||
};
|
||||
|
||||
// this should never happen except possible on shutdown
|
||||
NoEvents = (x, y) =>
|
||||
{
|
||||
lock (this.requests)
|
||||
/*
|
||||
lock (requests)
|
||||
{
|
||||
Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
|
||||
requests.Remove(request);
|
||||
}
|
||||
|
||||
*/
|
||||
Hashtable response = new Hashtable();
|
||||
|
||||
response["int_response_code"] = 500;
|
||||
@@ -188,25 +207,11 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
};
|
||||
}
|
||||
|
||||
public void Process()
|
||||
public void Process(aPollRequest requestinfo)
|
||||
{
|
||||
Hashtable response;
|
||||
Hashtable request = null;
|
||||
|
||||
try
|
||||
{
|
||||
lock (this.requests)
|
||||
{
|
||||
request = requests[0];
|
||||
requests.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UUID requestID = new UUID(request["RequestID"].ToString());
|
||||
UUID requestID = requestinfo.reqID;
|
||||
|
||||
// If the avatar is gone, don't bother to get the texture
|
||||
if (m_scene.GetScenePresence(Id) == null)
|
||||
@@ -219,13 +224,15 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
response["keepalive"] = false;
|
||||
response["reusecontext"] = false;
|
||||
|
||||
responses[requestID] = response;
|
||||
lock (responses)
|
||||
responses[requestID] = response;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
response = m_getTextureHandler.Handle(request);
|
||||
|
||||
responses[requestID] = response;
|
||||
response = m_getTextureHandler.Handle(requestinfo.request);
|
||||
lock (responses)
|
||||
responses[requestID] = response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,8 +240,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
{
|
||||
string capUrl = "/CAPS/" + UUID.Random() + "/";
|
||||
|
||||
// Register this as a poll service
|
||||
// absurd large timeout to tune later to make a bit less than viewer
|
||||
// Register this as a poll service
|
||||
PollServiceTextureEventArgs args = new PollServiceTextureEventArgs(agentID, m_scene);
|
||||
|
||||
args.Type = PollServiceEventArgs.EventType.Texture;
|
||||
@@ -270,11 +276,10 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
PollServiceTextureEventArgs args = m_queue.Dequeue();
|
||||
aPollRequest poolreq = m_queue.Dequeue();
|
||||
|
||||
args.Process();
|
||||
poolreq.thepoll.Process(poolreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -129,15 +129,15 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
// m_log.DebugFormat("[MESH UPLOAD FLAG MODULE]: MeshUploadFlag request");
|
||||
|
||||
OSDMap data = new OSDMap();
|
||||
ScenePresence sp = m_scene.GetScenePresence(m_agentID);
|
||||
data["username"] = sp.Firstname + "." + sp.Lastname;
|
||||
data["display_name_next_update"] = new OSDDate(DateTime.Now);
|
||||
data["legacy_first_name"] = sp.Firstname;
|
||||
// ScenePresence sp = m_scene.GetScenePresence(m_agentID);
|
||||
// data["username"] = sp.Firstname + "." + sp.Lastname;
|
||||
// data["display_name_next_update"] = new OSDDate(DateTime.Now);
|
||||
// data["legacy_first_name"] = sp.Firstname;
|
||||
data["mesh_upload_status"] = "valid";
|
||||
data["display_name"] = sp.Firstname + " " + sp.Lastname;
|
||||
data["legacy_last_name"] = sp.Lastname;
|
||||
data["id"] = m_agentID;
|
||||
data["is_display_name_default"] = true;
|
||||
// data["display_name"] = sp.Firstname + " " + sp.Lastname;
|
||||
// data["legacy_last_name"] = sp.Lastname;
|
||||
// data["id"] = m_agentID;
|
||||
// data["is_display_name_default"] = true;
|
||||
|
||||
//Send back data
|
||||
Hashtable responsedata = new Hashtable();
|
||||
|
||||
@@ -52,6 +52,13 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
|
||||
public class WebFetchInvDescModule : INonSharedRegionModule
|
||||
{
|
||||
struct aPollRequest
|
||||
{
|
||||
public PollServiceInventoryEventArgs thepoll;
|
||||
public UUID reqID;
|
||||
public Hashtable request;
|
||||
}
|
||||
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Scene m_scene;
|
||||
@@ -64,8 +71,8 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
private Dictionary<UUID, string> m_capsDict = new Dictionary<UUID, string>();
|
||||
private static Thread[] m_workerThreads = null;
|
||||
|
||||
private static OpenMetaverse.BlockingQueue<PollServiceInventoryEventArgs> m_queue =
|
||||
new OpenMetaverse.BlockingQueue<PollServiceInventoryEventArgs>();
|
||||
private static OpenMetaverse.BlockingQueue<aPollRequest> m_queue =
|
||||
new OpenMetaverse.BlockingQueue<aPollRequest>();
|
||||
|
||||
#region ISharedRegionModule Members
|
||||
|
||||
@@ -131,49 +138,52 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
~WebFetchInvDescModule()
|
||||
{
|
||||
foreach (Thread t in m_workerThreads)
|
||||
t.Abort();
|
||||
Watchdog.AbortThread(t.ManagedThreadId);
|
||||
}
|
||||
|
||||
private class PollServiceInventoryEventArgs : PollServiceEventArgs
|
||||
{
|
||||
private List<Hashtable> requests =
|
||||
new List<Hashtable>();
|
||||
private Dictionary<UUID, Hashtable> responses =
|
||||
new Dictionary<UUID, Hashtable>();
|
||||
|
||||
public PollServiceInventoryEventArgs(UUID pId) :
|
||||
base(null, null, null, null, pId, 30000)
|
||||
base(null, null, null, null, pId, int.MaxValue)
|
||||
{
|
||||
HasEvents = (x, y) => { return this.responses.ContainsKey(x); };
|
||||
GetEvents = (x, y, s) =>
|
||||
HasEvents = (x, y) => { lock (responses) return responses.ContainsKey(x); };
|
||||
GetEvents = (x, y) =>
|
||||
{
|
||||
try
|
||||
lock (responses)
|
||||
{
|
||||
return this.responses[x];
|
||||
}
|
||||
finally
|
||||
{
|
||||
responses.Remove(x);
|
||||
try
|
||||
{
|
||||
return responses[x];
|
||||
}
|
||||
finally
|
||||
{
|
||||
responses.Remove(x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Request = (x, y) =>
|
||||
{
|
||||
y["RequestID"] = x.ToString();
|
||||
lock (this.requests)
|
||||
this.requests.Add(y);
|
||||
aPollRequest reqinfo = new aPollRequest();
|
||||
reqinfo.thepoll = this;
|
||||
reqinfo.reqID = x;
|
||||
reqinfo.request = y;
|
||||
|
||||
m_queue.Enqueue(this);
|
||||
m_queue.Enqueue(reqinfo);
|
||||
};
|
||||
|
||||
NoEvents = (x, y) =>
|
||||
{
|
||||
lock (this.requests)
|
||||
/*
|
||||
lock (requests)
|
||||
{
|
||||
Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString());
|
||||
requests.Remove(request);
|
||||
}
|
||||
|
||||
*/
|
||||
Hashtable response = new Hashtable();
|
||||
|
||||
response["int_response_code"] = 500;
|
||||
@@ -186,24 +196,9 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
};
|
||||
}
|
||||
|
||||
public void Process()
|
||||
public void Process(aPollRequest requestinfo)
|
||||
{
|
||||
Hashtable request = null;
|
||||
|
||||
try
|
||||
{
|
||||
lock (this.requests)
|
||||
{
|
||||
request = requests[0];
|
||||
requests.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UUID requestID = new UUID(request["RequestID"].ToString());
|
||||
UUID requestID = requestinfo.reqID;
|
||||
|
||||
Hashtable response = new Hashtable();
|
||||
|
||||
@@ -212,9 +207,11 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
response["keepalive"] = false;
|
||||
response["reusecontext"] = false;
|
||||
|
||||
response["str_response_string"] = m_webFetchHandler.FetchInventoryDescendentsRequest(request["body"].ToString(), String.Empty, String.Empty, null, null);
|
||||
response["str_response_string"] = m_webFetchHandler.FetchInventoryDescendentsRequest(
|
||||
requestinfo.request["body"].ToString(), String.Empty, String.Empty, null, null);
|
||||
|
||||
responses[requestID] = response;
|
||||
lock (responses)
|
||||
responses[requestID] = response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,8 +219,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
{
|
||||
string capUrl = "/CAPS/" + UUID.Random() + "/";
|
||||
|
||||
// Register this as a poll service
|
||||
// absurd large timeout to tune later to make a bit less than viewer
|
||||
// Register this as a poll service
|
||||
PollServiceInventoryEventArgs args = new PollServiceInventoryEventArgs(agentID);
|
||||
|
||||
args.Type = PollServiceEventArgs.EventType.Inventory;
|
||||
@@ -259,9 +255,9 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
PollServiceInventoryEventArgs args = m_queue.Dequeue();
|
||||
aPollRequest poolreq = m_queue.Dequeue();
|
||||
|
||||
args.Process();
|
||||
poolreq.thepoll.Process(poolreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user