From 246350568cc1b3982e81f6ef40f813c278e3be76 Mon Sep 17 00:00:00 2001 From: Roof Level Suite Date: Wed, 12 Oct 2016 12:01:37 +1100 Subject: [PATCH 01/25] finished the pull request --- .../ModAPI/Ingame/IMyOreDetector.cs | 19 +++++++++++++++++++ .../Game/Entities/Blocks/MyOreDetector.cs | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index 84b88e931..a7ee0cdf1 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using VRageMath; namespace Sandbox.ModAPI.Ingame { @@ -9,5 +10,23 @@ public interface IMyOreDetector : IMyFunctionalBlock { float Range {get;} bool BroadcastUsingAntennas {get;} + + /// + ///Returns a list of ore deposits. + ///Each ore deposit has a substance name and a location. + /// + List GetOreMarkers(); + } + + public struct OreDeposit + { + public readonly string substanceName; + public readonly Vector3D coordinates; + + public OreDeposit (string inputName, Vector3D inputCoords) + { + this.substanceName = inputName; + this.coordinates = inputCoords; + } } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index ab3bd438d..eb5c8edda 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -1,5 +1,7 @@ #region Using +using System.Collections.Generic; + using Sandbox.Common.ObjectBuilders; using Sandbox.Definitions; using Sandbox.Game.Gui; @@ -203,5 +205,22 @@ public bool BroadcastUsingAntennas bool ModAPI.Ingame.IMyOreDetector.BroadcastUsingAntennas { get { return m_oreDetectorComponent.BroadcastUsingAntennas; } } float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } + + public List GetOreMarkers() + { + List oreMarkers = new List (); + + foreach (MyEntityOreDeposit deposit in MyHud.OreMarkers) + { + List markers = deposit.Materials; + + for (int i = 0; i < markers.Count; i++) + { + string substanceName = markers[i].Material.MaterialTypeName; + oreMarkers.Add (new ModAPI.Ingame.OreDeposit (substanceName, markers[i].AverageLocalPosition)); + } + } + return oreMarkers; + } } } From 507bea421047f7dbb17f594b733a95fc78be8cf3 Mon Sep 17 00:00:00 2001 From: Roof Level Suite Date: Wed, 12 Oct 2016 12:13:20 +1100 Subject: [PATCH 02/25] Refined a couple names. --- .../Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index eb5c8edda..797eb6b51 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -210,14 +210,14 @@ public bool BroadcastUsingAntennas { List oreMarkers = new List (); - foreach (MyEntityOreDeposit deposit in MyHud.OreMarkers) + foreach (MyEntityOreDeposit cache in MyHud.OreMarkers) { - List markers = deposit.Materials; + List deposits = cache.Materials; - for (int i = 0; i < markers.Count; i++) + for (int i = 0; i < deposits.Count; i++) { - string substanceName = markers[i].Material.MaterialTypeName; - oreMarkers.Add (new ModAPI.Ingame.OreDeposit (substanceName, markers[i].AverageLocalPosition)); + string substanceName = deposits[i].Material.MaterialTypeName; + oreMarkers.Add (new ModAPI.Ingame.OreDeposit (substanceName, deposits[i].AverageLocalPosition)); } } return oreMarkers; From 2a6f5111e0fdf2ff3ac6fd5a0700c54268e36ba9 Mon Sep 17 00:00:00 2001 From: Roof Level Suite Date: Wed, 12 Oct 2016 12:17:52 +1100 Subject: [PATCH 03/25] refined a couple names. --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 6 +++--- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index a7ee0cdf1..d67c208b1 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -13,19 +13,19 @@ public interface IMyOreDetector : IMyFunctionalBlock /// ///Returns a list of ore deposits. - ///Each ore deposit has a substance name and a location. + ///Each ore deposit has an element name and a location. /// List GetOreMarkers(); } public struct OreDeposit { - public readonly string substanceName; + public readonly string elementName; public readonly Vector3D coordinates; public OreDeposit (string inputName, Vector3D inputCoords) { - this.substanceName = inputName; + this.elementName = inputName; this.coordinates = inputCoords; } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 797eb6b51..aeacaaf06 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -216,8 +216,8 @@ public bool BroadcastUsingAntennas for (int i = 0; i < deposits.Count; i++) { - string substanceName = deposits[i].Material.MaterialTypeName; - oreMarkers.Add (new ModAPI.Ingame.OreDeposit (substanceName, deposits[i].AverageLocalPosition)); + string elementName = deposits[i].Material.MaterialTypeName; + oreMarkers.Add (new ModAPI.Ingame.OreDeposit (elementName, deposits[i].AverageLocalPosition)); } } return oreMarkers; From 27334a6508adbb9d7d5053f2acb8152619261e03 Mon Sep 17 00:00:00 2001 From: Roof Level Suite Date: Wed, 12 Oct 2016 12:36:02 +1100 Subject: [PATCH 04/25] refined a couple names. --- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index aeacaaf06..8f17ea821 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -208,7 +208,7 @@ public bool BroadcastUsingAntennas public List GetOreMarkers() { - List oreMarkers = new List (); + List formattedMarkers = new List (); foreach (MyEntityOreDeposit cache in MyHud.OreMarkers) { @@ -217,10 +217,10 @@ public bool BroadcastUsingAntennas for (int i = 0; i < deposits.Count; i++) { string elementName = deposits[i].Material.MaterialTypeName; - oreMarkers.Add (new ModAPI.Ingame.OreDeposit (elementName, deposits[i].AverageLocalPosition)); + formattedMarkers.Add (new ModAPI.Ingame.OreDeposit (elementName, deposits[i].AverageLocalPosition)); } } - return oreMarkers; + return formattedMarkers; } } } From 79ef9a85f281361f3451fce8cb7ae6d8f8261de5 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Wed, 12 Oct 2016 13:37:02 +1100 Subject: [PATCH 05/25] changed struct name in order to follow the code design rules. --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 9 ++++----- .../Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index d67c208b1..3342996c7 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -12,18 +12,17 @@ public interface IMyOreDetector : IMyFunctionalBlock bool BroadcastUsingAntennas {get;} /// - ///Returns a list of ore deposits. - ///Each ore deposit has an element name and a location. + ///Returns a list of ore deposits. Each ore deposit has an element name and a location. /// - List GetOreMarkers(); + List GetOreMarkers(); } - public struct OreDeposit + public struct MyOreMarker { public readonly string elementName; public readonly Vector3D coordinates; - public OreDeposit (string inputName, Vector3D inputCoords) + public MyOreMarker (string inputName, Vector3D inputCoords) { this.elementName = inputName; this.coordinates = inputCoords; diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 8f17ea821..d96065722 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -206,9 +206,9 @@ public bool BroadcastUsingAntennas bool ModAPI.Ingame.IMyOreDetector.BroadcastUsingAntennas { get { return m_oreDetectorComponent.BroadcastUsingAntennas; } } float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } - public List GetOreMarkers() + public List GetOreMarkers() { - List formattedMarkers = new List (); + List formattedMarkers = new List (); foreach (MyEntityOreDeposit cache in MyHud.OreMarkers) { @@ -217,7 +217,7 @@ public bool BroadcastUsingAntennas for (int i = 0; i < deposits.Count; i++) { string elementName = deposits[i].Material.MaterialTypeName; - formattedMarkers.Add (new ModAPI.Ingame.OreDeposit (elementName, deposits[i].AverageLocalPosition)); + formattedMarkers.Add (new ModAPI.Ingame.MyOreMarker (elementName, deposits[i].AverageLocalPosition)); } } return formattedMarkers; From 1edb2741732fafe9821a68e72192bdeb949f6120 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Wed, 12 Oct 2016 16:32:40 +1100 Subject: [PATCH 06/25] refined some names. --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index 3342996c7..ce849f5e1 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -19,13 +19,13 @@ public interface IMyOreDetector : IMyFunctionalBlock public struct MyOreMarker { - public readonly string elementName; - public readonly Vector3D coordinates; + public readonly string ElementName; + public readonly Vector3D Location; public MyOreMarker (string inputName, Vector3D inputCoords) { - this.elementName = inputName; - this.coordinates = inputCoords; + this.ElementName = inputName; + this.Location = inputCoords; } } } From d424eb21e98af26321f15ceb296ddefeb78c6518 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Wed, 12 Oct 2016 21:57:21 +1100 Subject: [PATCH 07/25] Refactored slightly to maximize performance. --- .../Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 5 +++-- .../Game/Entities/Blocks/MyOreDetector.cs | 11 ++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index ce849f5e1..abcfc9176 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -12,9 +12,10 @@ public interface IMyOreDetector : IMyFunctionalBlock bool BroadcastUsingAntennas {get;} /// - ///Returns a list of ore deposits. Each ore deposit has an element name and a location. + ///Returns your own List filled with known ore markers. + ///Each marker has an element name and a location. /// - List GetOreMarkers(); + void GetOreMarkers (ref List outputList); } public struct MyOreMarker diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index d96065722..77445d3bc 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -206,21 +206,18 @@ public bool BroadcastUsingAntennas bool ModAPI.Ingame.IMyOreDetector.BroadcastUsingAntennas { get { return m_oreDetectorComponent.BroadcastUsingAntennas; } } float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } - public List GetOreMarkers() - { - List formattedMarkers = new List (); - + //using ref is a tiny bit cheaper than a return. this is because of number of list definitions. + public void GetOreMarkers (ref List usersList) //ref ensures userList will never be null. + { foreach (MyEntityOreDeposit cache in MyHud.OreMarkers) { List deposits = cache.Materials; for (int i = 0; i < deposits.Count; i++) { - string elementName = deposits[i].Material.MaterialTypeName; - formattedMarkers.Add (new ModAPI.Ingame.MyOreMarker (elementName, deposits[i].AverageLocalPosition)); + usersList.Add (new ModAPI.Ingame.MyOreMarker (deposits[i].Material.MaterialTypeName, deposits[i].AverageLocalPosition)); } } - return formattedMarkers; } } } From 10e04ad244ee588e43aface156e9faa4468fc745 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Wed, 12 Oct 2016 22:12:47 +1100 Subject: [PATCH 08/25] Checks for null and does its job anyway. --- .../Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 77445d3bc..eba96c52a 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -207,8 +207,13 @@ public bool BroadcastUsingAntennas float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } //using ref is a tiny bit cheaper than a return. this is because of number of list definitions. - public void GetOreMarkers (ref List usersList) //ref ensures userList will never be null. - { + public void GetOreMarkers (ref List usersList) + { + if (usersList == null) + { + usersList = new List (); + } + foreach (MyEntityOreDeposit cache in MyHud.OreMarkers) { List deposits = cache.Materials; From 95ec518b3d9b9e4fe5e86fbf35333a2b92ad2fdd Mon Sep 17 00:00:00 2001 From: haveachillday Date: Thu, 13 Oct 2016 10:10:23 +1100 Subject: [PATCH 09/25] Added more information to struct MyOreMarker and added more information to summary. --- .../ModAPI/Ingame/IMyOreDetector.cs | 8 ++++++-- .../Game/Entities/Blocks/MyOreDetector.cs | 20 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index abcfc9176..f5e926d84 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -13,7 +13,7 @@ public interface IMyOreDetector : IMyFunctionalBlock /// ///Returns your own List filled with known ore markers. - ///Each marker has an element name and a location. + ///This information is only available when owning player is in the world. /// void GetOreMarkers (ref List outputList); } @@ -21,11 +21,15 @@ public interface IMyOreDetector : IMyFunctionalBlock public struct MyOreMarker { public readonly string ElementName; + public readonly string TypeID; + public readonly bool IsRare; public readonly Vector3D Location; - public MyOreMarker (string inputName, Vector3D inputCoords) + public MyOreMarker (string inputName, string inputID, bool inputRarity, Vector3D inputCoords) { this.ElementName = inputName; + this.TypeID = inputID; + this.IsRare = inputRarity; this.Location = inputCoords; } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index eba96c52a..e8e214b41 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -208,19 +208,27 @@ public bool BroadcastUsingAntennas //using ref is a tiny bit cheaper than a return. this is because of number of list definitions. public void GetOreMarkers (ref List usersList) - { + { if (usersList == null) { usersList = new List (); } - - foreach (MyEntityOreDeposit cache in MyHud.OreMarkers) + + else + { + usersList.Clear(); + } + + foreach (MyEntityOreDeposit deposit in MyHud.OreMarkers) { - List deposits = cache.Materials; + List caches = deposit.Materials; - for (int i = 0; i < deposits.Count; i++) + for (int i = 0; i < caches.Count; i++) { - usersList.Add (new ModAPI.Ingame.MyOreMarker (deposits[i].Material.MaterialTypeName, deposits[i].AverageLocalPosition)); + usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, + caches[i].Material.Id..ToString(), //returns the name of this struct. + caches[i].Material.IsRare, + caches[i].AverageLocalPosition)); } } } From 855aa1d78c2752c83c04c6c8db2e14e5d3699089 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Thu, 13 Oct 2016 10:13:24 +1100 Subject: [PATCH 10/25] no message --- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index e8e214b41..e52294ba6 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -226,7 +226,7 @@ public void GetOreMarkers (ref List usersList) for (int i = 0; i < caches.Count; i++) { usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, - caches[i].Material.Id..ToString(), //returns the name of this struct. + caches[i].Material.Id.ToString(), //returns the name of this struct. caches[i].Material.IsRare, caches[i].AverageLocalPosition)); } From fd1bfdedea9c04108b01c2e51472637d14825943 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Thu, 13 Oct 2016 10:34:23 +1100 Subject: [PATCH 11/25] no message --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 8 ++++---- .../Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index f5e926d84..f344c5a06 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -21,14 +21,14 @@ public interface IMyOreDetector : IMyFunctionalBlock public struct MyOreMarker { public readonly string ElementName; - public readonly string TypeID; + public readonly string SubTypeName; public readonly bool IsRare; public readonly Vector3D Location; - public MyOreMarker (string inputName, string inputID, bool inputRarity, Vector3D inputCoords) + public MyOreMarker (string inputElement, string inputSubName, bool inputRarity, Vector3D inputCoords) { - this.ElementName = inputName; - this.TypeID = inputID; + this.ElementName = inputElement; + this.SubTypeName = inputSubName; this.IsRare = inputRarity; this.Location = inputCoords; } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index e52294ba6..b5a528ca2 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -226,7 +226,7 @@ public void GetOreMarkers (ref List usersList) for (int i = 0; i < caches.Count; i++) { usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, - caches[i].Material.Id.ToString(), //returns the name of this struct. + caches[i].Material.Id.SubtypeName, caches[i].Material.IsRare, caches[i].AverageLocalPosition)); } From 288ccee2a6b232e7f10ab52e58a688d30f973028 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Thu, 13 Oct 2016 10:36:58 +1100 Subject: [PATCH 12/25] no message --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 4 +--- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index f344c5a06..447e00d23 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -21,14 +21,12 @@ public interface IMyOreDetector : IMyFunctionalBlock public struct MyOreMarker { public readonly string ElementName; - public readonly string SubTypeName; public readonly bool IsRare; public readonly Vector3D Location; - public MyOreMarker (string inputElement, string inputSubName, bool inputRarity, Vector3D inputCoords) + public MyOreMarker (string inputElement, bool inputRarity, Vector3D inputCoords) { this.ElementName = inputElement; - this.SubTypeName = inputSubName; this.IsRare = inputRarity; this.Location = inputCoords; } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index b5a528ca2..3d404175d 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -225,8 +225,7 @@ public void GetOreMarkers (ref List usersList) for (int i = 0; i < caches.Count; i++) { - usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, - caches[i].Material.Id.SubtypeName, + usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, caches[i].Material.IsRare, caches[i].AverageLocalPosition)); } From fb0c9389bbbed17a8341255bfcd4295fda786cca Mon Sep 17 00:00:00 2001 From: haveachillday Date: Thu, 13 Oct 2016 17:20:08 +1100 Subject: [PATCH 13/25] exposed subtypeID due to request. --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 4 +++- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index 447e00d23..433097298 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -21,12 +21,14 @@ public interface IMyOreDetector : IMyFunctionalBlock public struct MyOreMarker { public readonly string ElementName; + public readonly string SubTypeID; public readonly bool IsRare; public readonly Vector3D Location; - public MyOreMarker (string inputElement, bool inputRarity, Vector3D inputCoords) + public MyOreMarker (string inputElement, string inputID, bool inputRarity, Vector3D inputCoords) { this.ElementName = inputElement; + this.SubTypeID = inputID; this.IsRare = inputRarity; this.Location = inputCoords; } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 3d404175d..5bdc5c7c7 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -225,7 +225,8 @@ public void GetOreMarkers (ref List usersList) for (int i = 0; i < caches.Count; i++) { - usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, + usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, + caches[i].Material.Id.SubtypeId.String, caches[i].Material.IsRare, caches[i].AverageLocalPosition)); } From c45256a781ced18eefee7c70c1eea4cedd64d49b Mon Sep 17 00:00:00 2001 From: haveachillday Date: Wed, 19 Oct 2016 11:30:52 +1100 Subject: [PATCH 14/25] Deposit unpacking method now matches the visible ore markers. --- .../ModAPI/Ingame/IMyOreDetector.cs | 11 +--- .../Game/Entities/Blocks/MyOreDetector.cs | 60 ++++++++++++------- .../Entities/Blocks/MyOreDetectorComponent.cs | 4 +- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index 433097298..07e501b94 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -12,24 +12,19 @@ public interface IMyOreDetector : IMyFunctionalBlock bool BroadcastUsingAntennas {get;} /// - ///Returns your own List filled with known ore markers. - ///This information is only available when owning player is in the world. + ///Returns your own List filled with visible ore markers. /// - void GetOreMarkers (ref List outputList); + void GetOreMarkers (List outputList); } public struct MyOreMarker { public readonly string ElementName; - public readonly string SubTypeID; - public readonly bool IsRare; public readonly Vector3D Location; - public MyOreMarker (string inputElement, string inputID, bool inputRarity, Vector3D inputCoords) + public MyOreMarker (string inputElement, Vector3D inputCoords) { this.ElementName = inputElement; - this.SubTypeID = inputID; - this.IsRare = inputRarity; this.Location = inputCoords; } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 5bdc5c7c7..0f9c7c294 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -206,31 +206,47 @@ public bool BroadcastUsingAntennas bool ModAPI.Ingame.IMyOreDetector.BroadcastUsingAntennas { get { return m_oreDetectorComponent.BroadcastUsingAntennas; } } float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } - //using ref is a tiny bit cheaper than a return. this is because of number of list definitions. - public void GetOreMarkers (ref List usersList) - { - if (usersList == null) - { - usersList = new List (); - } - - else - { - usersList.Clear(); - } + public void GetOreMarkers (List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. + { + usersList.Clear(); + Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); + m_oreDetectorComponent.Update (blockCoordinates, true); - foreach (MyEntityOreDeposit deposit in MyHud.OreMarkers) + foreach (MyEntityOreDeposit deposit in m_oreDetectorComponent.DetectedDeposits) { - List caches = deposit.Materials; - - for (int i = 0; i < caches.Count; i++) - { - usersList.Add (new ModAPI.Ingame.MyOreMarker (caches[i].Material.MaterialTypeName, - caches[i].Material.Id.SubtypeId.String, - caches[i].Material.IsRare, - caches[i].AverageLocalPosition)); + for (int i = 0; i < deposit.Materials.Count; i++) + { + MyEntityOreDeposit.Data depositData = deposit.Materials[i]; + Vector3D cachesPosition = new Vector3D(); + depositData.ComputeWorldPosition (deposit.VoxelMap, out cachesPosition); + string cachesElement = deposit.Materials[i].Material.MinedOre; + + if (m_nearestDetections.ContainsKey (cachesElement) == false) + { + m_nearestDetections.Add (cachesElement, cachesPosition); //I decided Dictionary was the best way to group nearest markers since all I need is two variables. + } + + else + { + Vector3D difference = blockCoordinates - cachesPosition; + Vector3D previousDifference = m_nearestDetections[cachesElement] - cachesPosition; + float distanceToCache = (float)difference.LengthSquared(); //explicitly converted in order to estimate the actual hud markers as close as possible. + float previousDistance = (float)previousDifference.LengthSquared(); + + if (distanceToCache < previousDistance) + { + m_nearestDetections[cachesElement] = cachesPosition; //I only want the nearest of each element. + } + } } } - } + + foreach (KeyValuePair marker in m_nearestDetections) + { + usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, + marker.Value)); + } + m_nearestDetections.Clear(); + } } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs index 9e60c98df..332dc8a8f 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs @@ -188,6 +188,7 @@ class MyOreDetectorComponent public bool BroadcastUsingAntennas { get; set; } private readonly Dictionary m_depositGroupsByEntity = new Dictionary(); + public HashSet DetectedDeposits { get; private set; } public MyOreDetectorComponent() { @@ -247,6 +248,7 @@ public void Update(Vector3D position, bool checkControl = true) if (deposit != null) { MyHud.OreMarkers.RegisterMarker(deposit); + DetectedDeposits.Add (deposit); } } } @@ -264,8 +266,8 @@ public void Clear() MyHud.OreMarkers.UnregisterMarker(deposit); } } + DetectedDeposits.Clear(); } - } /// From 3cbf20e2f24428ce2b22a98a5e31135d0acdd21d Mon Sep 17 00:00:00 2001 From: haveachillday Date: Sat, 22 Oct 2016 11:19:21 +1100 Subject: [PATCH 15/25] fixed a small compilation error. --- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 0f9c7c294..53d6c9422 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -26,6 +26,7 @@ namespace Sandbox.Game.Entities.Cube public class MyOreDetector : MyFunctionalBlock, IMyComponentOwner, IMyOreDetector { private MyOreDetectorDefinition m_definition; + private Dictionary m_nearestDetections = new Dictionary (); //I use the same collection to reduce heap allocations. MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent(); From 4fb7a9c1b31897cb9942c5e7d17ae678d4f3abd5 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Sat, 22 Oct 2016 11:38:17 +1100 Subject: [PATCH 16/25] fixed a null exception in my code. --- .../Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs index 332dc8a8f..fe5d2ccd3 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs @@ -195,6 +195,7 @@ public MyOreDetectorComponent() DetectionRadius = 50; SetRelayedRequest = false; BroadcastUsingAntennas = false; + DetectedDeposits = new HashSet (); } public bool SetRelayedRequest { get; set; } From cf6d8b3e908b3f19cb40c5c1cb9922025f1db615 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Sat, 22 Oct 2016 20:37:35 +1100 Subject: [PATCH 17/25] Finished, Polished, Tested. Major Change: GetOreMarkers() can now get updates without needing a radio antenna. --- .../Game/Entities/Blocks/MyOreDetector.cs | 85 ++++++++++--------- .../Entities/Blocks/MyOreDetectorComponent.cs | 70 +++++++++------ .../Game/Entities/Blocks/MyRadioAntenna.cs | 2 +- .../Game/Weapons/Guns/MyHandDrill.cs | 2 +- 4 files changed, 91 insertions(+), 68 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 53d6c9422..4e2ef1cb9 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -26,9 +26,9 @@ namespace Sandbox.Game.Entities.Cube public class MyOreDetector : MyFunctionalBlock, IMyComponentOwner, IMyOreDetector { private MyOreDetectorDefinition m_definition; - private Dictionary m_nearestDetections = new Dictionary (); //I use the same collection to reduce heap allocations. + private Dictionary m_closestEachElement = new Dictionary (); //I use the same collection to reduce heap allocations. - MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent(); + private MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent(); Sync m_broadcastUsingAntennas; @@ -157,8 +157,9 @@ public override void UpdateBeforeSimulation100() base.UpdateBeforeSimulation100(); if (HasLocalPlayerAccess()) { - m_oreDetectorComponent.Update(PositionComp.GetPosition()); + m_oreDetectorComponent.Update (PositionComp.GetPosition(), false); } + else { m_oreDetectorComponent.Clear(); @@ -208,46 +209,52 @@ public bool BroadcastUsingAntennas float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } public void GetOreMarkers (List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. - { - usersList.Clear(); - Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); - m_oreDetectorComponent.Update (blockCoordinates, true); - - foreach (MyEntityOreDeposit deposit in m_oreDetectorComponent.DetectedDeposits) - { - for (int i = 0; i < deposit.Materials.Count; i++) - { - MyEntityOreDeposit.Data depositData = deposit.Materials[i]; - Vector3D cachesPosition = new Vector3D(); - depositData.ComputeWorldPosition (deposit.VoxelMap, out cachesPosition); - string cachesElement = deposit.Materials[i].Material.MinedOre; - - if (m_nearestDetections.ContainsKey (cachesElement) == false) + { + if (base.IDModule != null) + { + if (base.IDModule.Owner != (long) MyRelationsBetweenPlayerAndBlock.NoOwnership) + { + usersList.Clear(); + Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); + m_oreDetectorComponent.Update (blockCoordinates, true); + + foreach (MyEntityOreDeposit deposit in m_oreDetectorComponent.DetectedDeposits) { - m_nearestDetections.Add (cachesElement, cachesPosition); //I decided Dictionary was the best way to group nearest markers since all I need is two variables. - } - - else - { - Vector3D difference = blockCoordinates - cachesPosition; - Vector3D previousDifference = m_nearestDetections[cachesElement] - cachesPosition; - float distanceToCache = (float)difference.LengthSquared(); //explicitly converted in order to estimate the actual hud markers as close as possible. - float previousDistance = (float)previousDifference.LengthSquared(); + for (int i = 0; i < deposit.Materials.Count; i++) + { + MyEntityOreDeposit.Data depositData = deposit.Materials[i]; + Vector3D cachesPosition = new Vector3D(); + depositData.ComputeWorldPosition (deposit.VoxelMap, out cachesPosition); + string cachesElement = deposit.Materials[i].Material.MinedOre; + + if (m_closestEachElement.ContainsKey (cachesElement) == false) + { + m_closestEachElement.Add (cachesElement, cachesPosition); //I decided Dictionary was the best way to group nearest markers since all I need is two variables. + } + + else + { + Vector3D difference = blockCoordinates - cachesPosition; + Vector3D previousDifference = m_closestEachElement[cachesElement] - cachesPosition; + float distanceToCache = (float) difference.LengthSquared(); //explicitly converted in order to estimate the actual hud markers as close as possible. + float previousDistance = (float) previousDifference.LengthSquared(); - if (distanceToCache < previousDistance) - { - m_nearestDetections[cachesElement] = cachesPosition; //I only want the nearest of each element. - } + if (distanceToCache < previousDistance) + { + m_closestEachElement[cachesElement] = cachesPosition; //I only want the nearest of each element. + } + } + } } - } - } - foreach (KeyValuePair marker in m_nearestDetections) - { - usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, - marker.Value)); + foreach (KeyValuePair marker in m_closestEachElement) + { + usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, + marker.Value)); + } + m_closestEachElement.Clear(); + } } - m_nearestDetections.Clear(); - } + } } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs index fe5d2ccd3..2e4b84950 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs @@ -180,6 +180,8 @@ class MyOreDetectorComponent private static readonly List m_inRangeCache = new List(); private static readonly List m_notInRangeCache = new List(); + public HashSet DetectedDeposits { get; private set; } + public delegate bool CheckControlDelegate(); public float DetectionRadius { get; set; } @@ -188,7 +190,6 @@ class MyOreDetectorComponent public bool BroadcastUsingAntennas { get; set; } private readonly Dictionary m_depositGroupsByEntity = new Dictionary(); - public HashSet DetectedDeposits { get; private set; } public MyOreDetectorComponent() { @@ -200,30 +201,36 @@ public MyOreDetectorComponent() public bool SetRelayedRequest { get; set; } - public void Update(Vector3D position, bool checkControl = true) - { - Clear(); - - if (!SetRelayedRequest && checkControl && !OnCheckControl()) + public void Update (Vector3D position, bool onlyUpdateMember, bool checkControl = true) + { + if (onlyUpdateMember == false) { - m_depositGroupsByEntity.Clear(); - return; - } - - SetRelayedRequest = false; + Clear(); //It should only clear hud markers if it's prepared to renew them. - var sphere = new BoundingSphereD(position, DetectionRadius); - MyGamePruningStructure.GetAllVoxelMapsInSphere(ref sphere, m_inRangeCache); + if (!SetRelayedRequest && checkControl && !OnCheckControl()) + { + //m_depositGroupsByEntity.Clear(); I commented this out because it, in some states, causes DetectedDeposits to ouput as empty. m_depositGroupsByEntity seems to take more than one method one to fully update. + return; + } + SetRelayedRequest = false; + } + + else + { + DetectedDeposits.Clear(); + } + var sphere = new BoundingSphereD (position, DetectionRadius); + MyGamePruningStructure.GetAllVoxelMapsInSphere (ref sphere, m_inRangeCache); { // Find voxel maps which went out of range and then remove them. foreach (var voxelMap in m_depositGroupsByEntity.Keys) { - if (!m_inRangeCache.Contains(voxelMap)) - m_notInRangeCache.Add(voxelMap); + if (!m_inRangeCache.Contains (voxelMap)) + m_notInRangeCache.Add (voxelMap); } foreach (var notInRange in m_notInRangeCache) { - m_depositGroupsByEntity.Remove(notInRange); + m_depositGroupsByEntity.Remove (notInRange); } m_notInRangeCache.Clear(); } @@ -231,8 +238,8 @@ public void Update(Vector3D position, bool checkControl = true) { // Add voxel maps which came into range. foreach (var voxelMap in m_inRangeCache) { - if (!m_depositGroupsByEntity.ContainsKey(voxelMap)) - m_depositGroupsByEntity.Add(voxelMap, new MyOreDepositGroup(voxelMap)); + if (!m_depositGroupsByEntity.ContainsKey (voxelMap)) + m_depositGroupsByEntity.Add (voxelMap, new MyOreDepositGroup(voxelMap)); } m_inRangeCache.Clear(); } @@ -242,19 +249,26 @@ public void Update(Vector3D position, bool checkControl = true) { var voxelMap = entry.Key; var group = entry.Value; - group.UpdateDeposits(ref sphere); + group.UpdateDeposits (ref sphere); foreach (var deposit in group.Deposits) { if (deposit != null) - { - MyHud.OreMarkers.RegisterMarker(deposit); - DetectedDeposits.Add (deposit); + { + switch (onlyUpdateMember) //the method has been divided into these two choices because previously, oremarkers could not be fetched without a radio antenna. + { + case true: + DetectedDeposits.Add (deposit); + break; + + case false: + MyHud.OreMarkers.RegisterMarker (deposit); + break; + } } } - } - - m_inRangeCache.Clear(); + } + m_inRangeCache.Clear(); } public void Clear() @@ -264,9 +278,11 @@ public void Clear() foreach (var deposit in group.Deposits) { if (deposit != null) - MyHud.OreMarkers.UnregisterMarker(deposit); + { + MyHud.OreMarkers.UnregisterMarker (deposit); + } } - } + } DetectedDeposits.Clear(); } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs index fca2e9404..aea6e1c9e 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs @@ -350,7 +350,7 @@ public override List GetHudParams(bool allowBlink) MyOreDetectorComponent oreDetector; if (oreDetectorOwner.GetComponent(out oreDetector) && oreDetector.BroadcastUsingAntennas) { - oreDetector.Update(terminalBlock.PositionComp.GetPosition(), false); + oreDetector.Update(terminalBlock.PositionComp.GetPosition(), false, false); oreDetector.SetRelayedRequest = true; } } diff --git a/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs b/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs index b8fcfdbf4..aafae78c1 100644 --- a/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs +++ b/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs @@ -391,7 +391,7 @@ public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); m_drillBase.UpdateSoundEmitter(); - m_oreDetectorBase.Update(PositionComp.GetPosition()); + m_oreDetectorBase.Update (PositionComp.GetPosition(), false); } public void UpdateSoundEmitter() From 2ef491cf473d5ccf282290e31f3248a1a61c61e5 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Sat, 22 Oct 2016 21:36:48 +1100 Subject: [PATCH 18/25] Realised I dont need to prevent access of an ore detector with no owner. --- .../Game/Entities/Blocks/MyOreDetector.cs | 76 +++++++++---------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 4e2ef1cb9..d0fe216aa 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -209,52 +209,46 @@ public bool BroadcastUsingAntennas float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } public void GetOreMarkers (List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. - { - if (base.IDModule != null) - { - if (base.IDModule.Owner != (long) MyRelationsBetweenPlayerAndBlock.NoOwnership) - { - usersList.Clear(); - Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); - m_oreDetectorComponent.Update (blockCoordinates, true); - - foreach (MyEntityOreDeposit deposit in m_oreDetectorComponent.DetectedDeposits) + { + usersList.Clear(); + Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); + m_oreDetectorComponent.Update (blockCoordinates, true); + + foreach (MyEntityOreDeposit deposit in m_oreDetectorComponent.DetectedDeposits) + { + for (int i = 0; i < deposit.Materials.Count; i++) + { + MyEntityOreDeposit.Data depositData = deposit.Materials[i]; + Vector3D cachesPosition = new Vector3D(); + depositData.ComputeWorldPosition (deposit.VoxelMap, out cachesPosition); + string cachesElement = deposit.Materials[i].Material.MinedOre; + + if (m_closestEachElement.ContainsKey (cachesElement) == false) { - for (int i = 0; i < deposit.Materials.Count; i++) - { - MyEntityOreDeposit.Data depositData = deposit.Materials[i]; - Vector3D cachesPosition = new Vector3D(); - depositData.ComputeWorldPosition (deposit.VoxelMap, out cachesPosition); - string cachesElement = deposit.Materials[i].Material.MinedOre; - - if (m_closestEachElement.ContainsKey (cachesElement) == false) - { - m_closestEachElement.Add (cachesElement, cachesPosition); //I decided Dictionary was the best way to group nearest markers since all I need is two variables. - } - - else - { - Vector3D difference = blockCoordinates - cachesPosition; - Vector3D previousDifference = m_closestEachElement[cachesElement] - cachesPosition; - float distanceToCache = (float) difference.LengthSquared(); //explicitly converted in order to estimate the actual hud markers as close as possible. - float previousDistance = (float) previousDifference.LengthSquared(); - - if (distanceToCache < previousDistance) - { - m_closestEachElement[cachesElement] = cachesPosition; //I only want the nearest of each element. - } - } - } + m_closestEachElement.Add (cachesElement, cachesPosition); //I decided Dictionary was the best way to group nearest markers since all I need is two variables. } - - foreach (KeyValuePair marker in m_closestEachElement) - { - usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, - marker.Value)); + + else + { + Vector3D difference = blockCoordinates - cachesPosition; + Vector3D previousDifference = m_closestEachElement[cachesElement] - cachesPosition; + float distanceToCache = (float) difference.LengthSquared(); //explicitly converted in order to estimate the actual hud markers as close as possible. + float previousDistance = (float) previousDifference.LengthSquared(); + + if (distanceToCache < previousDistance) + { + m_closestEachElement[cachesElement] = cachesPosition; //I only want the nearest of each element. + } } - m_closestEachElement.Clear(); } } + + foreach (KeyValuePair marker in m_closestEachElement) + { + usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, + marker.Value)); + } + m_closestEachElement.Clear(); } } } From ffebf735b71685cb1d249ad0a821ffd526a97dd8 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Sun, 23 Oct 2016 11:05:35 +1100 Subject: [PATCH 19/25] minor text change --- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index d0fe216aa..6926c3d78 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -245,8 +245,7 @@ public bool BroadcastUsingAntennas foreach (KeyValuePair marker in m_closestEachElement) { - usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, - marker.Value)); + usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, marker.Value)); } m_closestEachElement.Clear(); } From 75ac63c90cb6e3cf74d737f349ac22cc86d47ee5 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Wed, 26 Oct 2016 17:02:53 +1100 Subject: [PATCH 20/25] ref makes it clear to the user how exactly they will get their ore markers. --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 2 +- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index 07e501b94..6de5471a1 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -14,7 +14,7 @@ public interface IMyOreDetector : IMyFunctionalBlock /// ///Returns your own List filled with visible ore markers. /// - void GetOreMarkers (List outputList); + void GetOreMarkers (ref List outputList); } public struct MyOreMarker diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 6926c3d78..faad6fec0 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -208,7 +208,7 @@ public bool BroadcastUsingAntennas bool ModAPI.Ingame.IMyOreDetector.BroadcastUsingAntennas { get { return m_oreDetectorComponent.BroadcastUsingAntennas; } } float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } - public void GetOreMarkers (List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. + public void GetOreMarkers (ref List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. { usersList.Clear(); Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); From 16f934031aabcfd3e145a960d5c88e8fa820feb1 Mon Sep 17 00:00:00 2001 From: Roof Level Suite Date: Mon, 5 Dec 2016 07:26:38 +1100 Subject: [PATCH 21/25] GetOreMarkers() now prevents excessively fast runs. Removed duplicate variable but still needs to be tested. --- .../Game/Entities/Blocks/MyOreDetector.cs | 82 +++++++++++-------- .../Entities/Blocks/MyOreDetectorComponent.cs | 29 +++---- .../Game/Entities/Blocks/MyRadioAntenna.cs | 2 +- .../Game/Weapons/Guns/MyHandDrill.cs | 2 +- 4 files changed, 60 insertions(+), 55 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index faad6fec0..de155554e 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -7,6 +7,7 @@ using Sandbox.Game.Gui; using Sandbox.Game.Multiplayer; using System.Text; +using System.Diagnostics; using Sandbox.Game.EntityComponents; using VRageMath; using Sandbox.ModAPI; @@ -28,7 +29,8 @@ public class MyOreDetector : MyFunctionalBlock, IMyComponentOwner m_closestEachElement = new Dictionary (); //I use the same collection to reduce heap allocations. - private MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent(); + private MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent(); + int ticksSinceOreMarkersCalled = 0; Sync m_broadcastUsingAntennas; @@ -157,13 +159,18 @@ public override void UpdateBeforeSimulation100() base.UpdateBeforeSimulation100(); if (HasLocalPlayerAccess()) { - m_oreDetectorComponent.Update (PositionComp.GetPosition(), false); + m_oreDetectorComponent.Update (PositionComp.GetPosition()); } else { m_oreDetectorComponent.Clear(); } + + if (ticksSinceOreMarkersCalled < Stopwatch.Frequency) + { + ticksSinceOreMarkersCalled++; + } } bool OnCheckControl() @@ -184,8 +191,7 @@ public float Range { m_oreDetectorComponent.DetectionRadius = (value / 100f) * m_definition.MaximumRange; RaisePropertiesChanged(); - } - + } } } @@ -209,45 +215,49 @@ public bool BroadcastUsingAntennas float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } public void GetOreMarkers (ref List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. - { - usersList.Clear(); - Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); - m_oreDetectorComponent.Update (blockCoordinates, true); - - foreach (MyEntityOreDeposit deposit in m_oreDetectorComponent.DetectedDeposits) + { + if (ticksSinceOreMarkersCalled == Stopwatch.Frequency) //counter will stop so it can wait forever. { - for (int i = 0; i < deposit.Materials.Count; i++) - { - MyEntityOreDeposit.Data depositData = deposit.Materials[i]; - Vector3D cachesPosition = new Vector3D(); - depositData.ComputeWorldPosition (deposit.VoxelMap, out cachesPosition); - string cachesElement = deposit.Materials[i].Material.MinedOre; - - if (m_closestEachElement.ContainsKey (cachesElement) == false) - { - m_closestEachElement.Add (cachesElement, cachesPosition); //I decided Dictionary was the best way to group nearest markers since all I need is two variables. - } + ticksSinceOreMarkersCalled = 0; + usersList.Clear(); + Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); + m_oreDetectorComponent.Update (blockCoordinates, false); - else - { - Vector3D difference = blockCoordinates - cachesPosition; - Vector3D previousDifference = m_closestEachElement[cachesElement] - cachesPosition; - float distanceToCache = (float) difference.LengthSquared(); //explicitly converted in order to estimate the actual hud markers as close as possible. - float previousDistance = (float) previousDifference.LengthSquared(); + foreach (MyEntityOreDeposit deposit in m_oreDetectorComponent.DetectedDeposits) + { + for (int i = 0; i < deposit.Materials.Count; i++) + { + MyEntityOreDeposit.Data depositData = deposit.Materials[i]; + Vector3D cachesPosition = new Vector3D(); + depositData.ComputeWorldPosition (deposit.VoxelMap, out cachesPosition); + string cachesElement = deposit.Materials[i].Material.MinedOre; + + if (m_closestEachElement.ContainsKey (cachesElement) == false) + { + m_closestEachElement.Add (cachesElement, cachesPosition); //I decided Dictionary was the best way to group nearest markers since all I need is two variables. + } + + else + { + Vector3D difference = blockCoordinates - cachesPosition; + Vector3D previousDifference = m_closestEachElement[cachesElement] - cachesPosition; + float distanceToCache = (float) difference.LengthSquared(); //explicitly converted in order to estimate the actual hud markers as close as possible. + float previousDistance = (float) previousDifference.LengthSquared(); - if (distanceToCache < previousDistance) - { - m_closestEachElement[cachesElement] = cachesPosition; //I only want the nearest of each element. - } + if (distanceToCache < previousDistance) + { + m_closestEachElement[cachesElement] = cachesPosition; //I only want the nearest of each element. + } + } } } - } - foreach (KeyValuePair marker in m_closestEachElement) - { - usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, marker.Value)); + foreach (KeyValuePair marker in m_closestEachElement) + { + usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, marker.Value)); + } + m_closestEachElement.Clear(); } - m_closestEachElement.Clear(); } } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs index 2e4b84950..bfe45ceb0 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs @@ -201,24 +201,19 @@ public MyOreDetectorComponent() public bool SetRelayedRequest { get; set; } - public void Update (Vector3D position, bool onlyUpdateMember, bool checkControl = true) + public void Update (Vector3D position, bool checkControl = true) { - if (onlyUpdateMember == false) - { - Clear(); //It should only clear hud markers if it's prepared to renew them. - - if (!SetRelayedRequest && checkControl && !OnCheckControl()) - { - //m_depositGroupsByEntity.Clear(); I commented this out because it, in some states, causes DetectedDeposits to ouput as empty. m_depositGroupsByEntity seems to take more than one method one to fully update. - return; - } - SetRelayedRequest = false; - } + if (!SetRelayedRequest && checkControl && !OnCheckControl()) + { + //m_depositGroupsByEntity.Clear(); I commented this out because it, in some states, causes DetectedDeposits to ouput incorrectly as empty. m_depositGroupsByEntity seems to take more than one method run to fully update. + return; + } else { DetectedDeposits.Clear(); } + SetRelayedRequest = false; var sphere = new BoundingSphereD (position, DetectionRadius); MyGamePruningStructure.GetAllVoxelMapsInSphere (ref sphere, m_inRangeCache); @@ -239,7 +234,7 @@ public void Update (Vector3D position, bool onlyUpdateMember, bool checkControl foreach (var voxelMap in m_inRangeCache) { if (!m_depositGroupsByEntity.ContainsKey (voxelMap)) - m_depositGroupsByEntity.Add (voxelMap, new MyOreDepositGroup(voxelMap)); + m_depositGroupsByEntity.Add (voxelMap, new MyOreDepositGroup (voxelMap)); } m_inRangeCache.Clear(); } @@ -255,14 +250,14 @@ public void Update (Vector3D position, bool onlyUpdateMember, bool checkControl { if (deposit != null) { - switch (onlyUpdateMember) //the method has been divided into these two choices because previously, oremarkers could not be fetched without a radio antenna. + switch (checkControl) //the method has been divided into these two choices because previously, oremarkers could not be fetched without a radio antenna. { case true: - DetectedDeposits.Add (deposit); + MyHud.OreMarkers.RegisterMarker (deposit); break; - case false: - MyHud.OreMarkers.RegisterMarker (deposit); + case false: + DetectedDeposits.Add (deposit); break; } } diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs index aea6e1c9e..daa92f557 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyRadioAntenna.cs @@ -350,7 +350,7 @@ public override List GetHudParams(bool allowBlink) MyOreDetectorComponent oreDetector; if (oreDetectorOwner.GetComponent(out oreDetector) && oreDetector.BroadcastUsingAntennas) { - oreDetector.Update(terminalBlock.PositionComp.GetPosition(), false, false); + oreDetector.Update (terminalBlock.PositionComp.GetPosition(), false); oreDetector.SetRelayedRequest = true; } } diff --git a/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs b/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs index aafae78c1..6599253d5 100644 --- a/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs +++ b/Sources/Sandbox.Game/Game/Weapons/Guns/MyHandDrill.cs @@ -391,7 +391,7 @@ public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); m_drillBase.UpdateSoundEmitter(); - m_oreDetectorBase.Update (PositionComp.GetPosition(), false); + m_oreDetectorBase.Update (PositionComp.GetPosition()); } public void UpdateSoundEmitter() From 86cd57829e040cd255d49b6ea477ba0056a16e46 Mon Sep 17 00:00:00 2001 From: haveachillday Date: Mon, 5 Dec 2016 10:43:37 +1100 Subject: [PATCH 22/25] tweaked MyOreDetectorComponent.Update() to perform exactly the same as its previous version. --- .../Game/Entities/Blocks/MyOreDetector.cs | 10 ++++---- .../Entities/Blocks/MyOreDetectorComponent.cs | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index de155554e..83ae071be 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -30,7 +30,7 @@ public class MyOreDetector : MyFunctionalBlock, IMyComponentOwner m_closestEachElement = new Dictionary (); //I use the same collection to reduce heap allocations. private MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent(); - int ticksSinceOreMarkersCalled = 0; + int MethodCallRateCounter = 0; Sync m_broadcastUsingAntennas; @@ -167,9 +167,9 @@ public override void UpdateBeforeSimulation100() m_oreDetectorComponent.Clear(); } - if (ticksSinceOreMarkersCalled < Stopwatch.Frequency) + if (MethodCallRateCounter < Stopwatch.Frequency) { - ticksSinceOreMarkersCalled++; + MethodCallRateCounter++; } } @@ -216,9 +216,9 @@ public bool BroadcastUsingAntennas public void GetOreMarkers (ref List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. { - if (ticksSinceOreMarkersCalled == Stopwatch.Frequency) //counter will stop so it can wait forever. + if (MethodCallRateCounter == Stopwatch.Frequency) //counter will stop so it can wait forever. { - ticksSinceOreMarkersCalled = 0; + MethodCallRateCounter = 0; usersList.Clear(); Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); m_oreDetectorComponent.Update (blockCoordinates, false); diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs index bfe45ceb0..9b6d166c5 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs @@ -203,17 +203,22 @@ public MyOreDetectorComponent() public void Update (Vector3D position, bool checkControl = true) { - if (!SetRelayedRequest && checkControl && !OnCheckControl()) - { - //m_depositGroupsByEntity.Clear(); I commented this out because it, in some states, causes DetectedDeposits to ouput incorrectly as empty. m_depositGroupsByEntity seems to take more than one method run to fully update. - return; - } - + if (checkControl == true) + { + Clear(); + + if (!SetRelayedRequest && !OnCheckControl()) + { + //m_depositGroupsByEntity.Clear(); I commented this out because it, in some states, causes DetectedDeposits to ouput incorrectly as empty. m_depositGroupsByEntity seems to take more than one run to fully load. + return; + } + SetRelayedRequest = false; + } + else { - DetectedDeposits.Clear(); - } - SetRelayedRequest = false; + DetectedDeposits.Clear(); //Deposits needs to remove duplicates but also leave the HUD unchanged. + } var sphere = new BoundingSphereD (position, DetectionRadius); MyGamePruningStructure.GetAllVoxelMapsInSphere (ref sphere, m_inRangeCache); @@ -253,7 +258,7 @@ public void Update (Vector3D position, bool checkControl = true) switch (checkControl) //the method has been divided into these two choices because previously, oremarkers could not be fetched without a radio antenna. { case true: - MyHud.OreMarkers.RegisterMarker (deposit); + MyHud.OreMarkers.RegisterMarker (deposit); break; case false: From 84e8841438c138955c010819b161dad9bcf661d2 Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 8 Dec 2016 11:21:40 +1100 Subject: [PATCH 23/25] Made the rate the method can run at in line with simulation updates. --- .../Game/Entities/Blocks/MyOreDetector.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 83ae071be..042e6a129 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -30,12 +30,14 @@ public class MyOreDetector : MyFunctionalBlock, IMyComponentOwner m_closestEachElement = new Dictionary (); //I use the same collection to reduce heap allocations. private MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent(); - int MethodCallRateCounter = 0; + bool getOreRateLimited; Sync m_broadcastUsingAntennas; public MyOreDetector() { + getOreRateLimited = true; + #if XB1 // XB1_SYNC_NOREFLECTION m_broadcastUsingAntennas = SyncType.CreateAndAddProp(); #endif // XB1 @@ -156,6 +158,8 @@ public override void OnUnregisteredFromGridSystems() public override void UpdateBeforeSimulation100() { + getOreRateLimited = true; + base.UpdateBeforeSimulation100(); if (HasLocalPlayerAccess()) { @@ -166,11 +170,6 @@ public override void UpdateBeforeSimulation100() { m_oreDetectorComponent.Clear(); } - - if (MethodCallRateCounter < Stopwatch.Frequency) - { - MethodCallRateCounter++; - } } bool OnCheckControl() @@ -216,9 +215,9 @@ public bool BroadcastUsingAntennas public void GetOreMarkers (ref List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. { - if (MethodCallRateCounter == Stopwatch.Frequency) //counter will stop so it can wait forever. + if (getOreRateLimited) { - MethodCallRateCounter = 0; + getOreRateLimited = false; usersList.Clear(); Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); m_oreDetectorComponent.Update (blockCoordinates, false); From d92c5bf1095a15eb8862dd2fa201d5126ef32438 Mon Sep 17 00:00:00 2001 From: Pharap Date: Wed, 1 Mar 2017 01:57:35 +0000 Subject: [PATCH 24/25] Removed unnecessary ref List is a reference type anyway, the `ref` qualifier is useless unless you want to assign to the argument, which defeats the point of making it an argument and not a return value. --- Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs index 6de5471a1..07e501b94 100644 --- a/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs +++ b/Sources/Sandbox.Common/ModAPI/Ingame/IMyOreDetector.cs @@ -14,7 +14,7 @@ public interface IMyOreDetector : IMyFunctionalBlock /// ///Returns your own List filled with visible ore markers. /// - void GetOreMarkers (ref List outputList); + void GetOreMarkers (List outputList); } public struct MyOreMarker From a1feff638b217360b410c7283c94dc58067117f0 Mon Sep 17 00:00:00 2001 From: Pharap Date: Wed, 1 Mar 2017 01:57:37 +0000 Subject: [PATCH 25/25] Removed unnecessary ref List is a reference type anyway, the `ref` qualifier is useless unless you want to assign to the argument, which defeats the point of making it an argument and not a return value. --- Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs index 042e6a129..81cf9db72 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs @@ -213,12 +213,12 @@ public bool BroadcastUsingAntennas bool ModAPI.Ingame.IMyOreDetector.BroadcastUsingAntennas { get { return m_oreDetectorComponent.BroadcastUsingAntennas; } } float ModAPI.Ingame.IMyOreDetector.Range { get { return Range; } } - public void GetOreMarkers (ref List usersList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. + public void GetOreMarkers (List userList) //Imprinting on the reference parameter is cheaper than a return List due to heap allocations. { if (getOreRateLimited) { getOreRateLimited = false; - usersList.Clear(); + userList.Clear(); Vector3D blockCoordinates = new Vector3D (base.PositionComp.GetPosition()); m_oreDetectorComponent.Update (blockCoordinates, false); @@ -253,7 +253,7 @@ public bool BroadcastUsingAntennas foreach (KeyValuePair marker in m_closestEachElement) { - usersList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, marker.Value)); + userList.Add (new ModAPI.Ingame.MyOreMarker (marker.Key, marker.Value)); } m_closestEachElement.Clear(); }