Skip to content

Commit

Permalink
Use the event values to update other clients and make statemachine co…
Browse files Browse the repository at this point in the history
…mpletely server sided.
  • Loading branch information
stijnwop committed Aug 17, 2019
1 parent e32e797 commit fbc2a24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/events/HeadlandModeChangedEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ function HeadlandModeChangedEvent:readStream(streamId, connection)
end

function HeadlandModeChangedEvent:run(connection)
local spec = self.vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")

self.vehicle:onHeadlandStateChanged(spec.headlandMode, spec.headlandActDistance)
self.vehicle:onHeadlandStateChanged(self.mode, self.distance)

-- Send from server to all clients
if not connection:getIsServer() then
Expand Down
27 changes: 16 additions & 11 deletions src/vehicles/GlobalPositioningSystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,10 @@ function GlobalPositioningSystem:onResetGuidanceData()
data.isCreated = false
data.snapDirection = { 0, 0, 0, 0 }

spec.stateMachine:reset()
if self.isServer then
spec.stateMachine:reset()
end

spec.lastInputValues.guidanceSteeringIsActive = false
Logger.info("onResetGuidanceData")
end
Expand All @@ -852,25 +855,27 @@ function GlobalPositioningSystem:onUpdateGuidanceData(guidanceData)
data.snapDirection = guidanceData.snapDirection
data.alphaRad = guidanceData.alphaRad

spec.stateMachine:reset()
if self.isServer then
spec.stateMachine:reset()
end
Logger.info("onUpdateGuidanceData")
end

function GlobalPositioningSystem:onSteeringStateChanged(isActive)
local spec = self:guidanceSteering_getSpecTable("globalPositioningSystem")

spec.stateMachine:reset()

if not self.isClient then
return
if self.isServer then
spec.stateMachine:reset()
end

local sample = spec.samples.activate
if not isActive then
sample = spec.samples.deactivate
end
if self.isClient then
local sample = spec.samples.activate
if not isActive then
sample = spec.samples.deactivate
end

g_soundManager:playSample(sample)
g_soundManager:playSample(sample)
end
end

---Called when headland mode or acting distance changed.
Expand Down

0 comments on commit fbc2a24

Please sign in to comment.