public bool ExecuteTask() { lock (mInstLock) { if (mIsHalted) { return(true); } if (WaitingInstances.Count > 0) { for (int i = 0; WaitingInstances.Count > 0; ++i) { var data = WaitingInstances.First(); ActiveInstances.Add(data); WaitingInstances.Remove(data); } if (Renderer.InstanceDataBuffer != null) { Renderer.InstanceDataBuffer.Dispose(); } int size = Marshal.SizeOf(typeof(Models.MDX.MdxInstanceData)); Renderer.InstanceDataBuffer = new VertexBuffer(Game.GameManager.GraphicsThread.GraphicsManager.Device, ActiveInstances.Count * size, Usage.WriteOnly, VertexFormat.Diffuse, Pool.Managed); DataStream strm = Renderer.InstanceDataBuffer.Lock(0, 0, LockFlags.None); Models.MDX.MdxInstanceData[] InstData = ActiveInstances.ToArray(); strm.WriteRange(InstData); Renderer.InstanceDataBuffer.Unlock(); Renderer.numInstances = ActiveInstances.Count; } } return(WaitingInstances.Count == 0); }
internal void UpdateVisibility() { lock (mInstLock) { if (mIsHalted) { return; } List <Models.MDX.MdxInstanceData> VisibleInstances = new List <Models.MDX.MdxInstanceData>(); List <Models.MDX.MdxInstanceData> TmpInvis = new List <Models.MDX.MdxInstanceData>(); bool changed = false; foreach (var inst in InvisibleInstances) { if (IsInstanceVisible(new Vector3(inst.ModelMatrix.M41, inst.ModelMatrix.M42, inst.ModelMatrix.M43))) { changed = true; VisibleInstances.Add(inst); } else { TmpInvis.Add(inst); } } foreach (var inst in ActiveInstances) { if (IsInstanceVisible(new Vector3(inst.ModelMatrix.M41, inst.ModelMatrix.M42, inst.ModelMatrix.M43))) { VisibleInstances.Add(inst); } else { changed = true; TmpInvis.Add(inst); } } ActiveInstances = VisibleInstances; InvisibleInstances = TmpInvis; Renderer.numInstances = ActiveInstances.Count; if (ActiveInstances.Count == 0) { return; } if (changed == false && mUpdateLists == false) { return; } if (Renderer.InstanceDataBuffer != null) { Renderer.InstanceDataBuffer.Dispose(); } int size = Marshal.SizeOf(typeof(Models.MDX.MdxInstanceData)); Renderer.InstanceDataBuffer = new VertexBuffer(Game.GameManager.GraphicsThread.GraphicsManager.Device, ActiveInstances.Count * size, Usage.WriteOnly, VertexFormat.Diffuse, Pool.Managed); DataStream strm = Renderer.InstanceDataBuffer.Lock(0, 0, LockFlags.None); Models.MDX.MdxInstanceData[] InstData = ActiveInstances.ToArray(); strm.WriteRange(InstData); Renderer.InstanceDataBuffer.Unlock(); Renderer.numInstances = ActiveInstances.Count; mUpdateLists = false; } }