Mikeemoo, on 28 March 2013 - 11:10 PM, said:
Good spot. Yeah, the sonic sensor seems to have its own range settings. I didn't make this particular sensor. Not sure if I should reduce the range on these to make it inline with the other block/tile sensors, or just update the wiki...
Hrmm.
My personal opinion would be to bring it in line with the other sensors...consistency is a good thing. There is also a performance cost to consider...scanning 2,197 blocks when all you want is short range data is rather wasteful, but scanning 117,649 blocks is kinda insane (especially since it isn't a simple lookup per block, but rather a raycast per block to simulate echo-location).
If the sonic sensor does keep its custom range(s), then I'd like you to consider adding either a method to check a single xyz coordinate (relative to the turtle) within the range of the sensor card or a method that lets you specify a range shorter than the range of the sensor card.
One way to implement the former would be to change getTargetDetails in PeripheralSensor.java. Currently, it calls getTargets every time getTargetDetails is invoked (which works, but is a smidgeon wasteful with a 49x49x49 range). If that were changed to only check the provided target, it would be quite useful. This would involve refactoring all of the existing sensors, but it should mostly be a matter of cut/paste:
- Add a new method to each sensor:
getTarget(...)
- Move the single-target code from each sensor's getTargets loop to getTarget
- Have getTargets call getTarget for each potential target
- Have getTargetDetails call getTarget instead of getTargets
Every sensor would benefit from this change, and it wouldn't change the existing API. The change should be completely transparent to the end-user's scripts.
Another way would be to use custom method, but is less graceful imho.
Implementing the latter would require a custom method, but doesn't involve any refactoring. It would also only affect the sonic sensor. It also doesn't break the API, but end-users would have to rewrite their scripts to take advantage of it (which happens with any new feature, so isn't really a consideration).