Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Get Ore Markers in the Programmable Block #567

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

DoubleCouponDay
Copy link

@DoubleCouponDay DoubleCouponDay commented Oct 12, 2016

Adds a new method to IMyOreDetector which allows players to get, in code, the ores they see on their HUD. This revolutionizes the automated mining process.

It fills in the player's list with structs. Each struct has an ore element name and a Vector3D. Im sure people will appreciate this intuitive solution by mining straight to the deposit as opposed to clearing everything. Previous asteroid-detecting-sensor designs have now been made clunky, laggy, obsolete.

Ive tweaked the voxel updating method to get ore markers even when:

  • A player is not present,
  • there is no antenna making visible ore markers.

This is because a player should not have to be present for a drone to go about its tasks.

If you want to test this pull request, here's a programmable block script to get you up and running:
https://github.com/DoubleCouponDay/Ingame-Scipting-Collection/blob/master/SEScripting%20Collection/SEScripting%20Collection/OreDetectorSourceTest.cs

Copy link
Author

@DoubleCouponDay DoubleCouponDay left a comment

Choose a reason for hiding this comment

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

Still need to figure out how to return markers when no antenna is present.

@DoubleCouponDay
Copy link
Author

Its not quite ready for the public.

Major Change: GetOreMarkers() can now get updates without needing a radio antenna.
Copy link
Author

@DoubleCouponDay DoubleCouponDay left a comment

Choose a reason for hiding this comment

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

Its ready and passed my tests.

Had to prevent m_depositGroupsByEntity from emptying during run time. This ensures GetOreMarkers() will always return true amounts of information.

@spacebuilder2020
Copy link

Does this fix the memory leak on planets when a over-sized sensor range (500) is used.

Anyway, great work.

@DoubleCouponDay
Copy link
Author

No bug fix but removes the need to make that kind of lag :-)

@spacebuilder2020
Copy link

Nice, well now we just wait. :p

@kleshchevand
Copy link

kleshchevand commented Nov 12, 2016

I'm not sure, but isn't this too specific?
Detecting ore is good and all, but why limit code with ore? If you are giving access to HUD markers shouldn't it be all markers? Like, user specifies in script/function what block he wants to get markers from - if user passes ore scanner block to script/function, it will return markers from said scanner, if user passes antennae it will get all marks accessible to this specific antennae, non-broadcasting block - marker of said block if present ...
Examples of script that can use this functionality: "autiopilot" can use visible beacon/antennae markers to reach target or follow specific route, keep distance from ships in fleet. Another script can mark some damaged blocks (if they can be marked) to make drones approach and repair blocks.
Potential is immense...
Besides keeping code universal (even if only ore will be exposed to API) is a good practice.

@DoubleCouponDay
Copy link
Author

DoubleCouponDay commented Nov 13, 2016

@kleshchevand I agree on the usefulness of creating api hooks for all types of hud markers. I think its a glimpse of future ingame scripting. However, the hooks must be associated with a block ingame and this is the ore detector's one :]. Also i think a highly specific pull request has a higher chance of being accepted... maybe...

@kleshchevand
Copy link

I can see that all markers are entirely separate classes which is odd and prevents implementation of more universal system, but may be it still can benefit from something like this?
public interface IMyOreDetector : IMyFunctionalBlock, IMyMarkerProvider

P.S. Sorry if my English is a bit rough. Also I'm surprised how decentralized whole marker system is...

@DoubleCouponDay
Copy link
Author

DoubleCouponDay commented Nov 24, 2016

An interface would only make the code readable so we would know which blocks need marker methods in their component class. Theyve kindof already done this in a static way (ew whats that smell?). I am not brave enough to refactor that for them :D
https://github.com/KeenSoftwareHouse/SpaceEngineers/blob/e2b5b14e1e798b7e4579b1ee38a1a5a89ae556f0/Sources/Sandbox.Game/Game/GUI/MyHud.cs
https://github.com/KeenSoftwareHouse/SpaceEngineers/blob/0807af9557057a76f8724e6370cb3f440d8c0979/Sources/Sandbox.Game/Game/Screens/MyGuiScreenHudSpace.cs

I was hoping MyHud would be cleaner than it is but it's public ore List is not filtered at all; not even each seperate deposit is refined into one marker. They have decided to filter only under specific conditions: antenna on and owned, player present and friendly. The way I got this working was to not touch the HUD code yet copy its filtering method into MyOreDetector. Refactoring that would mean filtering every time an ore detector is switched on. Is that a good thing or a bad thing and which has the biggest performance cost? filtering twice under very specific conditions or filtering once under general conditions?

Think in terms of why they would design the marker system so decentralized. In their view, ore markers have a single purpose: to display on the hud. Therefore lets split that code in half so its only used when needed. Actually we could just leave the procession as is but make a new method which MyGuiScreenHudSpace and MyOreDetector have in common. I cant think of a class structure where that idea would mesh well but the more types of markers that need the same kind of filtering, the better.

@rexxar-tc
Copy link
Contributor

Oh man, I literally just finished an identical feature. There's a very serious problem with your implementation, though. There's no rate limiting, so the PB can spam the ore detector a thousand times every tick and ruin simspeed. Also, your changes to MyOreDetectorComponent weren't necessary, you can just pass Update(pos, false) and it will update fine.

@DoubleCouponDay
Copy link
Author

DoubleCouponDay commented Dec 4, 2016

Hmm ill revise it and get back to you.

@DoubleCouponDay
Copy link
Author

DoubleCouponDay commented Dec 4, 2016

I see what you mean about the duplicate variable. That method was a real headache to debug so I just wrapped all states I don't want to break into a single if block. I can do the same thing with bool checkControl no problem.

Thing is some changes are necessary to MyOreDetectorComponent in order to call for markers without presence of a player or antenna. However, if you guys are intending the opposite (for future ore detector API changes) then ill try to tailor it to your specifications.

{
ticksSinceOreMarkersCalled++;
MethodCallRateCounter++;
Copy link

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
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?

Copy link

@Pingger Pingger Dec 9, 2016

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

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

Pharap and others added 3 commits March 1, 2017 01:57
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.
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.
Removed unnecessary ref qualifiers.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants