diff --git a/Mafia2Libs/Rendering/Core/InstanceGizmo.cs b/Mafia2Libs/Rendering/Core/InstanceGizmo.cs index 2a0daa1e..55eb9f37 100644 --- a/Mafia2Libs/Rendering/Core/InstanceGizmo.cs +++ b/Mafia2Libs/Rendering/Core/InstanceGizmo.cs @@ -11,7 +11,7 @@ namespace Rendering.Core { public class InstanceGizmo { - private float ModelScale = 0.015f; + private Vector3 ModelScale = new Vector3(0.015f); // Variable for rendering public RenderModel InstanceModel; @@ -45,7 +45,7 @@ public ID3D11ShaderResourceView LoadTexture(ID3D11Device d3d, ID3D11DeviceContex public void UpdateInstanceBuffer(Instance instance, ID3D11Device d3d) { - Matrix4x4 newtransform = MatrixUtils.SetMatrix(instance.Quaternion, new Vector3(ModelScale), instance.Position); + Matrix4x4 newtransform = MatrixUtils.SetMatrix(instance.Quaternion, ModelScale, instance.Position); if (!InstanceModel.InstanceTransforms.ContainsKey(instance.RefID)) { diff --git a/Mafia2Libs/Rendering/Graphics/GraphicsClass.cs b/Mafia2Libs/Rendering/Graphics/GraphicsClass.cs index eeb62048..3ac1fac6 100644 --- a/Mafia2Libs/Rendering/Graphics/GraphicsClass.cs +++ b/Mafia2Libs/Rendering/Graphics/GraphicsClass.cs @@ -57,8 +57,7 @@ public class GraphicsClass private PrimitiveBatch LineBatch = null; private PrimitiveBatch BBoxBatch = null; private int NumBVHToBuild = 0; - private int NumBVHToBuilt = 0; - private int MaxBVHBuildingTasks = 4; // We should detect how many threads the computer has on boot and assign the max task count based on that. + private int NumBVHBuilt = 0; private List BVHBuildingTasks = new(); public PrimitiveManager OurPrimitiveManager { get; private set; } @@ -73,8 +72,6 @@ public GraphicsClass() navigationGrids = new SpatialGrid[0]; OurPrimitiveManager = new PrimitiveManager(); - UpdateMaxBVHTasks(); - OnSelectedObjectUpdated += OnSelectedObjectHasUpdated; // Create bespoke batches for any lines or boxes passed in via the construct stack @@ -149,12 +146,7 @@ public bool InitScene(int width, int height) sky.DoRender = WorldSettings.RenderSky; clouds.InitBuffers(D3D.Device, D3D.DeviceContext); InstanceGizmo.InitBuffers(D3D.Device, D3D.DeviceContext); - var task = InstanceGizmo.InstanceModel.GetBVHBuildingTask(); // Maybe this function should be added to the IRenderer class instead? probably - - if (task != null) - { - BVHBuildingTasks.Add(task); - } + InstanceGizmo.InstanceModel.GetBVHBuildingTask(); // Maybe this function should be added to the IRenderer class instead? probably Input = new InputClass(); Input.Init(); @@ -393,8 +385,10 @@ public bool UpdateInput() public bool Render() { - // Clear completed BVH tasks - NumBVHToBuilt += BVHBuildingTasks.RemoveAll(t => t.IsCompleted); + if (NumBVHBuilt < NumBVHToBuild) + { + UpdateBVHQueue(); + } D3D.BeginScene(0.0f, 0f, 0f, 1.0f); Camera.Render(); @@ -408,17 +402,6 @@ public bool Render() { RenderEntry.UpdateBuffers(D3D.Device, D3D.DeviceContext); RenderEntry.Render(D3D.Device, D3D.DeviceContext, Camera); - - // A status bar will be added to the map editor later to indicate when it is building BVH structures - if (RenderEntry is RenderModel mesh && BVHBuildingTasks.Count < MaxBVHBuildingTasks) - { - var task = mesh.GetBVHBuildingTask(); // Maybe this function should be added to the IRenderer class instead? - - if (task != null) - { - BVHBuildingTasks.Add(task); - } - } } //navigationGrids[0].Render(D3D.Device, D3D.DeviceContext, Camera); @@ -449,11 +432,6 @@ public bool Render() private void ClearRenderStack() { - if (InitObjectStack.Count > 0) - { - NumBVHToBuild = 0; - } - foreach (KeyValuePair asset in InitObjectStack) { asset.Value.InitBuffers(D3D.Device, D3D.DeviceContext); @@ -468,7 +446,9 @@ private void ClearRenderStack() } else if (asset.Value is RenderModel) { + BVHBuildingTasks.Add(((RenderModel)asset.Value).GetBVHBuildingTask()); NumBVHToBuild++; + Assets.Add(asset.Key, asset.Value); } else @@ -480,6 +460,12 @@ private void ClearRenderStack() InitObjectStack.Clear(); } + private void UpdateBVHQueue() + { + // Clear completed BVH tasks + NumBVHBuilt += BVHBuildingTasks.RemoveAll(t => t.IsCompleted); + } + public void SelectEntry(int id) { IRenderer NewObject = GetAsset(id); @@ -681,20 +667,7 @@ public string GetStatusBarText() } //return Utils.Language.Language.GetString("$BUILDING_BVH"); //Keeps printing missing text in debug build and slowing things down - return $"Building BVH: {NumBVHToBuilt}/{NumBVHToBuild}"; - } - - private void UpdateMaxBVHTasks() - { - int processorCount = Environment.ProcessorCount; - - if (processorCount <= 3) - { - MaxBVHBuildingTasks = 1; - return; - } - - MaxBVHBuildingTasks = processorCount - 2; + return $"Building BVH: {NumBVHBuilt}/{NumBVHToBuild}"; } public ID3D11Device GetId3D11Device()