Skip to content
This repository was archived by the owner on Jan 6, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2463505
finished the pull request
DoubleCouponDay Oct 12, 2016
507bea4
Refined a couple names.
DoubleCouponDay Oct 12, 2016
2a6f511
refined a couple names.
DoubleCouponDay Oct 12, 2016
27334a6
refined a couple names.
DoubleCouponDay Oct 12, 2016
79ef9a8
changed struct name in order to follow the code design rules.
DoubleCouponDay Oct 12, 2016
1edb274
refined some names.
DoubleCouponDay Oct 12, 2016
d424eb2
Refactored slightly to maximize performance.
DoubleCouponDay Oct 12, 2016
10e04ad
Checks for null and does its job anyway.
DoubleCouponDay Oct 12, 2016
95ec518
Added more information to struct MyOreMarker and added more informati…
DoubleCouponDay Oct 12, 2016
855aa1d
no message
DoubleCouponDay Oct 12, 2016
fd1bfde
no message
DoubleCouponDay Oct 12, 2016
288ccee
no message
DoubleCouponDay Oct 12, 2016
fb0c938
exposed subtypeID due to request.
DoubleCouponDay Oct 13, 2016
c45256a
Deposit unpacking method now matches the visible ore markers.
DoubleCouponDay Oct 19, 2016
3cbf20e
fixed a small compilation error.
DoubleCouponDay Oct 22, 2016
4fb7a9c
fixed a null exception in my code.
DoubleCouponDay Oct 22, 2016
cf6d8b3
Finished, Polished, Tested.
DoubleCouponDay Oct 22, 2016
2ef491c
Realised I dont need to prevent access of an ore detector with no owner.
DoubleCouponDay Oct 22, 2016
ffebf73
minor text change
DoubleCouponDay Oct 23, 2016
75ac63c
ref makes it clear to the user how exactly they will get their ore ma…
DoubleCouponDay Oct 26, 2016
16f9340
GetOreMarkers() now prevents excessively fast runs. Removed duplicate…
DoubleCouponDay Dec 4, 2016
86cd578
tweaked MyOreDetectorComponent.Update() to perform exactly the same a…
DoubleCouponDay Dec 4, 2016
84e8841
Made the rate the method can run at in line with simulation updates.
DoubleCouponDay Dec 8, 2016
d92c5bf
Removed unnecessary ref
Pharap Mar 1, 2017
a1feff6
Removed unnecessary ref
Pharap Mar 1, 2017
c51dfcb
Merge pull request #1 from Pharap/GetOreMarkersInPB
DoubleCouponDay Mar 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MyOreDetector : MyFunctionalBlock, IMyComponentOwner<MyOreDetectorC
private Dictionary <string, Vector3D> m_closestEachElement = new Dictionary <string, Vector3D>(); //I use the same collection to reduce heap allocations.

private MyOreDetectorComponent m_oreDetectorComponent = new MyOreDetectorComponent();
int ticksSinceOreMarkersCalled = 0;
int MethodCallRateCounter = 0;

Sync<bool> m_broadcastUsingAntennas;

Expand Down Expand Up @@ -167,9 +167,9 @@ public override void UpdateBeforeSimulation100()
m_oreDetectorComponent.Clear();
}

if (ticksSinceOreMarkersCalled < Stopwatch.Frequency)
if (MethodCallRateCounter < Stopwatch.Frequency)
{
ticksSinceOreMarkersCalled++;
MethodCallRateCounter++;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't ++MethodCallRateCounter be better?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increment before viewing the number? why does it matter?

@Pingger Pingger Dec 9, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because than no duplicate of the variable is created which would be returned at this point.

Like this:
varType incrementBeforeReturn() { var = var +1; return var; }

varType incrementAfterReturn() { varType prev = var; var = var +1; return prev; }

incrementing before before return therefore reduces memory consumption and runtime

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler does this automaticly, no need to worry

}
}

Expand Down Expand Up @@ -216,9 +216,9 @@ public bool BroadcastUsingAntennas

public void GetOreMarkers (ref List <ModAPI.Ingame.MyOreMarker> usersList) //Imprinting on the reference parameter is cheaper than a return List<T> 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);
Expand Down
25 changes: 15 additions & 10 deletions Sources/Sandbox.Game/Game/Entities/Blocks/MyOreDetectorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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:
Expand Down