Skip to content

Commit 867319b

Browse files
authored
Merge pull request #1059 from Courseplay/1020-new-custom-fields-doesnt-get-detected-by-mods-vehicles
fix: field detection
2 parents d784fb9 + 1549597 commit 867319b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

scripts/field/FieldBoundaryDetector.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function FieldBoundaryDetector:init(x, z, vehicle)
2222
self.updates = 0
2323
local customField = g_customFieldManager:getCustomField(x, z)
2424
if customField and g_Courseplay.globalSettings.preferCustomFields:getValue() then
25-
self.logger:info( 'Found custom field %s at %.1f %.1f and custom fields are preferred',
25+
self.logger:info( 'Foun d custom field %s at %.1f %.1f and custom fields are preferred',
2626
customField:getName(), x, z)
2727
self:_useCustomField(customField)
2828
return
@@ -31,6 +31,7 @@ function FieldBoundaryDetector:init(x, z, vehicle)
3131
local fieldCourseSettings, implementData = FieldCourseSettings.generate(vehicle)
3232
self.courseField = FieldCourseField.generateAtPosition(x, z, fieldCourseSettings, function(courseField, success)
3333
if success then
34+
self.done = true
3435
self.logger:info('Field boundary detection successful after %d updates, %d boundary points and %d islands',
3536
self.updates, #courseField.fieldRootBoundary.boundaryLine, #courseField.islands)
3637
self.fieldPolygon = self:_getAsVertices(courseField.fieldRootBoundary.boundaryLine)
@@ -57,7 +58,10 @@ end
5758
---@return boolean true if still in progress, false when done
5859
function FieldBoundaryDetector:update(dt)
5960
-- when we use the custom field, we are done immediately
60-
if not self.useCustomField and self.courseField:update(dt, 0.00025) then
61+
-- FieldCourseField:update() returns true until it's state is FieldCourseDetectionState.FINISHED. Problem
62+
-- is, it may never go to the FINISHED state, and then our indication of done is that the callback is called with
63+
-- success == true, therefore use the self.done to indicate it.
64+
if not self.useCustomField and not self.done and self.courseField:update(dt, 0.00025) then
6165
self.updates = self.updates + 1
6266
return true
6367
else

0 commit comments

Comments
 (0)