use ObjectJobEngine on ubOde mesh worker

This commit is contained in:
UbitUmarov
2021-01-08 14:40:14 +00:00
parent 172a915aac
commit ec216a3877

View File

@@ -4,7 +4,6 @@
using System;
using System.Collections.Concurrent;
using System.Threading;
using OpenSim.Framework;
using OpenSim.Region.PhysicsModules.SharedBase;
using log4net;
@@ -74,10 +73,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
public float MeshSculptphysicalLOD = 32;
public float MinSizeToMeshmerize = 0.1f;
private BlockingCollection<ODEPhysRepData> workQueue = new BlockingCollection<ODEPhysRepData>();
//private static ObjectJobEngine<ODEPhysRepData> workQueue;
private ObjectJobEngine workQueue;
private bool m_running;
private bool hasthread = false;
private readonly object m_threadLock = new object();
public ODEMeshWorker(ODEScene pScene, ILog pLog, IMesher pMesher, IConfig pConfig)
@@ -95,6 +94,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
}
m_running = true;
Util.FireAndForget(DoCacheExpire, null, "OdeCacheExpire", false);
lock(m_threadLock)
{
if(workQueue == null)
workQueue = new ObjectJobEngine(DoWork, "OdeMeshWorker");
}
}
private void DoCacheExpire(object o)
@@ -104,47 +108,26 @@ namespace OpenSim.Region.PhysicsModule.ubOde
private void Enqueue(ODEPhysRepData rep)
{
lock(m_threadLock)
{
if(!hasthread)
{
hasthread = true;
Util.FireAndForget(DoWork, null, "OdeMeshWorker", false);
}
}
workQueue.Add(rep);
workQueue.Enqueue(rep);
}
private void DoWork(object o)
private void DoWork(object rep)
{
while(m_running)
ODEPhysRepData nextRep = rep as ODEPhysRepData;
if (m_running && nextRep != null && m_scene.haveActor(nextRep.actor))
{
workQueue.TryTake(out ODEPhysRepData nextRep, 2000);
if(!m_running)
return;
if (nextRep == null)
switch (nextRep.comand)
{
lock(m_threadLock)
{
hasthread = false;
return;
}
}
if (m_scene.haveActor(nextRep.actor))
{
switch (nextRep.comand)
{
case meshWorkerCmnds.changefull:
case meshWorkerCmnds.changeshapetype:
case meshWorkerCmnds.changesize:
GetMesh(nextRep);
if (CreateActorPhysRep(nextRep) && m_scene.haveActor(nextRep.actor))
m_scene.AddChange(nextRep.actor, changes.PhysRepData, nextRep);
break;
case meshWorkerCmnds.getmesh:
DoRepDataGetMesh(nextRep);
break;
}
case meshWorkerCmnds.changefull:
case meshWorkerCmnds.changeshapetype:
case meshWorkerCmnds.changesize:
GetMesh(nextRep);
if (CreateActorPhysRep(nextRep) && m_scene.haveActor(nextRep.actor))
m_scene.AddChange(nextRep.actor, changes.PhysRepData, nextRep);
break;
case meshWorkerCmnds.getmesh:
DoRepDataGetMesh(nextRep);
break;
}
}
}
@@ -154,7 +137,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
try
{
m_running = false;
// workQueue.Dispose();
workQueue.Dispose();
workQueue = null;
}
catch
{