Skip to content

Commit

Permalink
Replace all the connector num bits from the ManureSystemConnector con…
Browse files Browse the repository at this point in the history
…stant to the ManureSystemEventBits constant.
  • Loading branch information
stijnwop committed Mar 14, 2020
1 parent 1133b74 commit f71705f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/events/HoseAttachDetachEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end
function HoseAttachDetachEvent:readStream(streamId, connection)
self.object = NetworkUtil.readNodeObject(streamId)
self.id = streamReadUIntN(streamId, ManureSystemEventBits.GRAB_NODES_SEND_NUM_BITS) + 1
self.connectorId = streamReadUIntN(streamId, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS) + 1
self.connectorId = streamReadUIntN(streamId, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS) + 1
self.vehicle = NetworkUtil.readNodeObject(streamId)
self.state = streamReadBool(streamId)

Expand All @@ -42,7 +42,7 @@ end
function HoseAttachDetachEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.object)
streamWriteUIntN(streamId, self.id - 1, ManureSystemEventBits.GRAB_NODES_SEND_NUM_BITS)
streamWriteUIntN(streamId, self.connectorId - 1, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS)
streamWriteUIntN(streamId, self.connectorId - 1, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS)
NetworkUtil.writeNodeObject(streamId, self.vehicle)
streamWriteBool(streamId, self.state)
end
Expand Down
4 changes: 2 additions & 2 deletions src/events/ManureSystemConnectorIsConnectedEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end
function ManureSystemConnectorIsConnectedEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.vehicle)
streamWriteBool(streamId, self.isConnected)
streamWriteUIntN(streamId, self.connectorId - 1, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS)
streamWriteUIntN(streamId, self.connectorId - 1, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS)

if self.isConnected then
streamWriteUIntN(streamId, self.grabNodeId - 1, ManureSystemEventBits.GRAB_NODES_SEND_NUM_BITS)
Expand All @@ -46,7 +46,7 @@ end
function ManureSystemConnectorIsConnectedEvent:readStream(streamId, connection)
self.vehicle = NetworkUtil.readNodeObject(streamId)
self.isConnected = streamReadBool(streamId)
self.connectorId = streamReadUIntN(streamId, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS) + 1
self.connectorId = streamReadUIntN(streamId, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS) + 1

if self.isConnected then
self.grabNodeId = streamReadUIntN(streamId, ManureSystemEventBits.GRAB_NODES_SEND_NUM_BITS) + 1
Expand Down
4 changes: 2 additions & 2 deletions src/events/ManureSystemConnectorManureFlowEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ end

function ManureSystemConnectorManureFlowEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.vehicle)
streamWriteUIntN(streamId, self.connectorId - 1, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS)
streamWriteUIntN(streamId, self.connectorId - 1, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS)
streamWriteBool(streamId, self.hasOpenManureFlow)
streamWriteBool(streamId, self.isForced)
end

function ManureSystemConnectorManureFlowEvent:readStream(streamId, connection)
self.vehicle = NetworkUtil.readNodeObject(streamId)
self.connectorId = streamReadUIntN(streamId, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS) + 1
self.connectorId = streamReadUIntN(streamId, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS) + 1
self.hasOpenManureFlow = streamReadBool(streamId)
self.isForced = streamReadBool(streamId)

Expand Down
8 changes: 4 additions & 4 deletions src/hose/Hose.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function Hose:onReadStream(streamId, connection)
elseif self:isConnected(grabNode) then
if streamReadBool(streamId) then
local vehicleId = NetworkUtil.readNodeObjectId(streamId)
local connectorId = streamReadUIntN(streamId, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS) + 1
local connectorId = streamReadUIntN(streamId, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS) + 1
table.insert(spec.hosesToLoadFromNetwork, { vehicleId = vehicleId, connectorId = connectorId, grabNodeId = id })
end
end
Expand All @@ -254,7 +254,7 @@ function Hose:onWriteStream(streamId, connection)
streamWriteBool(streamId, desc ~= nil)
if desc ~= nil then
NetworkUtil.writeNodeObjectId(streamId, NetworkUtil.getObjectId(desc.vehicle))
streamWriteUIntN(streamId, desc.connectorId - 1, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS)
streamWriteUIntN(streamId, desc.connectorId - 1, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS)
end
end
end
Expand All @@ -266,7 +266,7 @@ function Hose:onReadUpdateStream(streamId, timestamp, connection)
if streamReadBool(streamId) then
local spec = self.spec_hose
spec.foundVehicleId = NetworkUtil.readNodeObjectId(streamId)
spec.foundConnectorId = streamReadUIntN(streamId, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS)
spec.foundConnectorId = streamReadUIntN(streamId, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS)
spec.foundConnectorIsConnected = streamReadBool(streamId)
spec.foundGrabNodeId = streamReadUIntN(streamId, ManureSystemEventBits.GRAB_NODES_SEND_NUM_BITS)
end
Expand All @@ -278,7 +278,7 @@ function Hose:onWriteUpdateStream(streamId, connection, dirtyMask)
local spec = self.spec_hose
if streamWriteBool(streamId, bitAND(dirtyMask, spec.dirtyFlag) ~= 0) then
NetworkUtil.writeNodeObjectId(streamId, spec.foundVehicleId)
streamWriteUIntN(streamId, spec.foundConnectorId, ManureSystemConnector.CONNECTORS_SEND_NUM_BITS) -- allow sync number 0
streamWriteUIntN(streamId, spec.foundConnectorId, ManureSystemEventBits.CONNECTORS_SEND_NUM_BITS) -- allow sync number 0
streamWriteBool(streamId, spec.foundConnectorIsConnected)
streamWriteUIntN(streamId, spec.foundGrabNodeId, ManureSystemEventBits.GRAB_NODES_SEND_NUM_BITS) -- allow sync number 0
end
Expand Down
2 changes: 0 additions & 2 deletions src/vehicles/ManureSystemConnector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
ManureSystemConnector = {}
ManureSystemConnector.MOD_NAME = g_currentModName

ManureSystemConnector.CONNECTORS_SEND_NUM_BITS = 4 -- 2 ^ 4

function ManureSystemConnector.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(FillUnit, specializations)
end
Expand Down

0 comments on commit f71705f

Please sign in to comment.