slomal bahui
This commit is contained in:
@@ -18,7 +18,7 @@ function Differential:initialize(vehicle, name, config)
|
||||
if CLIENT then return end
|
||||
|
||||
self.wireOutputs = {
|
||||
Diff_Torque = 'number'
|
||||
[string.format('%s_Torque', self.name)] = 'number'
|
||||
}
|
||||
|
||||
self.finalDrive = config.FinalDrive or 4
|
||||
@@ -52,7 +52,7 @@ end
|
||||
function Differential:updateWireOutputs()
|
||||
PowertrainComponent.updateWireOutputs(self)
|
||||
|
||||
wire.ports.Diff_Torque = self.torque
|
||||
wire.ports[string.format('%s_Torque', self.name)] = self.torque
|
||||
|
||||
if self.outputA ~= nil then
|
||||
self.outputA:updateWireOutputs()
|
||||
@@ -110,8 +110,8 @@ function Differential:forwardStep(torque, inertia)
|
||||
self.slipTorque
|
||||
)
|
||||
|
||||
tqA = self.outputA:forwardStep(tqA, inertia * 0.5 * math.pow(self.finalDrive, 2) + aI) / self.finalDrive
|
||||
tqB = self.outputB:forwardStep(tqB, inertia * 0.5 * math.pow(self.finalDrive, 2) + bI) / self.finalDrive
|
||||
tqA = self.outputA:forwardStep(tqA, inertia * 0.5 * math.pow(self.finalDrive, 2) + aI)
|
||||
tqB = self.outputB:forwardStep(tqB, inertia * 0.5 * math.pow(self.finalDrive, 2) + bI)
|
||||
|
||||
-- // REFACTOR
|
||||
if self.steerLock ~= 0 then
|
||||
@@ -136,7 +136,7 @@ function Differential:forwardStep(torque, inertia)
|
||||
local maxMz = math.max(self.outputA.customWheel.mz + self.outputB.customWheel.mz)
|
||||
local minMz = math.min(self.outputA.customWheel.mz + self.outputB.customWheel.mz)
|
||||
|
||||
local steerTorque = mzDiff * -1 + inputTorque
|
||||
local steerTorque = mzDiff / 2 * -1 + inputTorque
|
||||
|
||||
local steerAngularAccel = steerTorque / steerInertia
|
||||
|
||||
@@ -157,7 +157,7 @@ function Differential:forwardStep(torque, inertia)
|
||||
self.outputB.customWheel.steerAngle = innerAngle
|
||||
end
|
||||
|
||||
return (tqA + tqB) / self.finalDrive
|
||||
return tqA + tqB
|
||||
end
|
||||
|
||||
function Differential:_openDiffTorqueSplit(tq, aW, bW, aI, bI, biasAB, preload, stiffness, powerRamp, coastRamp, slipTorque)
|
||||
@@ -165,17 +165,26 @@ function Differential:_openDiffTorqueSplit(tq, aW, bW, aI, bI, biasAB, preload,
|
||||
end
|
||||
|
||||
function Differential:_lockingDiffTorqueSplit(tq, aW, bW, aI, bI, biasAB, preload, stiffness, powerRamp, coastRamp, slipTorque)
|
||||
local sumI = aI + bI
|
||||
local w = aI / sumI * aW + bI / sumI * bW
|
||||
local aTqCorr = (w - aW) * aI -- / dt
|
||||
aTqCorr = aTqCorr * stiffness
|
||||
Ta = tq * (1 - biasAB);
|
||||
Tb = tq * biasAB;
|
||||
|
||||
local bTqCorr = (w - bW) * bI -- / dt
|
||||
bTqCorr = bTqCorr * stiffness
|
||||
local syncTorque = (aW - bW) * stiffness * (aI + bI) * 0.5 / TICK_INTERVAL;
|
||||
|
||||
local biasA = math.clamp(0.5 + (bW - aW) * 0.1 * stiffness, 0, 1)
|
||||
Ta = Ta - syncTorque;
|
||||
Tb = Tb + syncTorque;
|
||||
|
||||
return tq * biasA + aTqCorr, tq * (1 - biasA) * bTqCorr
|
||||
return Ta, Tb
|
||||
-- local sumI = aI + bI
|
||||
-- local w = aI / sumI * aW + bI / sumI * bW
|
||||
-- local aTqCorr = (w - aW) * aI -- / dt
|
||||
-- aTqCorr = aTqCorr * stiffness
|
||||
|
||||
-- local bTqCorr = (w - bW) * bI -- / dt
|
||||
-- bTqCorr = bTqCorr * stiffness
|
||||
|
||||
-- local biasA = math.clamp(0.5 + (bW - aW) * 0.1 * stiffness, 0, 1)
|
||||
|
||||
-- return tq * biasA + aTqCorr, tq * (1 - biasA) * bTqCorr
|
||||
end
|
||||
|
||||
function Differential:_VLSDTorqueSplit(tq, aW, bW, aI, bI, biasAB, preload, stiffness, powerRamp, coastRamp, slipTorque)
|
||||
|
||||
@@ -32,7 +32,6 @@ function Engine:initialize(vehicle, name, config)
|
||||
self.limiterDuration = config.LimiterDuration or 0.05
|
||||
self.torqueMap = config.TorqueMap or {}
|
||||
|
||||
self.rpmFrac = 0
|
||||
self.friction = 0
|
||||
self.masterThrottle = 0
|
||||
|
||||
@@ -93,7 +92,7 @@ function Engine:_generateTorque()
|
||||
return self.torque
|
||||
end
|
||||
|
||||
function Engine:forwardStep()
|
||||
function Engine:forwardStep(torque, inertia)
|
||||
if self.output == nil then
|
||||
local generatedTorque = self:_generateTorque()
|
||||
|
||||
@@ -108,7 +107,7 @@ function Engine:forwardStep()
|
||||
|
||||
local generatedTorque = self:_generateTorque()
|
||||
local reactTorque = (targetW - self.angularVelocity) * self.inertia / TICK_INTERVAL
|
||||
local returnedTorque = self.output:forwardStep(generatedTorque - reactTorque, self.inertia) -- ??? 0 -> self.inertia
|
||||
local returnedTorque = self.output:forwardStep(torque + generatedTorque - reactTorque, inertia + self.inertia)
|
||||
|
||||
self.reactTorque = reactTorque
|
||||
self.returnedTorque = returnedTorque
|
||||
@@ -120,6 +119,10 @@ function Engine:forwardStep()
|
||||
self.angularVelocity = self.angularVelocity + finalTorque / inertiaSum * TICK_INTERVAL
|
||||
self.angularVelocity = math.max(self.angularVelocity, 0)
|
||||
|
||||
net.start("ENGINE_RPM")
|
||||
net.writeFloat(self:getRPM() / self.maxRPM)
|
||||
net.send(self.vehicle.playersConnectedToHUD, true)
|
||||
|
||||
net.start("ENGINE_FULLRPM")
|
||||
net.writeUInt(self:getRPM(), 16)
|
||||
net.writeFloat(self.masterThrottle)
|
||||
|
||||
@@ -14,9 +14,9 @@ function Gearbox:initialize(vehicle, name, config)
|
||||
Downshift = 'number'
|
||||
}
|
||||
self.wireOutputs = {
|
||||
Gearbox_RPM = 'number',
|
||||
Gearbox_Torque = 'number',
|
||||
Gearbox_Ratio = 'number'
|
||||
[string.format('%s_RPM', self.name)] = 'number',
|
||||
[string.format('%s_Torque', self.name)] = 'number',
|
||||
[string.format('%s_Ratio', self.name)] = 'number'
|
||||
}
|
||||
|
||||
self.type = config.Type or 'MANUAL'
|
||||
@@ -28,9 +28,9 @@ end
|
||||
function Gearbox:updateWireOutputs()
|
||||
PowertrainComponent.updateWireOutputs(self)
|
||||
|
||||
wire.ports.Gearbox_RPM = self:getRPM()
|
||||
wire.ports.Gearbox_Torque = self.torque
|
||||
wire.ports.Gearbox_Ratio = self.ratio
|
||||
wire.ports[string.format('%s_RPM', self.name)] = self:getRPM()
|
||||
wire.ports[string.format('%s_Torque', self.name)] = self.torque
|
||||
wire.ports[string.format('%s_Ratio', self.name)] = self.ratio
|
||||
end
|
||||
|
||||
function Gearbox:queryInertia()
|
||||
@@ -52,18 +52,18 @@ function Gearbox:queryAngularVelocity(angularVelocity)
|
||||
end
|
||||
|
||||
function Gearbox:forwardStep(torque, inertia)
|
||||
self.torque = torque * self.ratio
|
||||
|
||||
if self.output == nil then
|
||||
return torque
|
||||
end
|
||||
|
||||
if self.ratio == 0 then
|
||||
self.output:forwardStep(0, self.inertia)
|
||||
self.output:forwardStep(0, self.inertia * 0.5)
|
||||
|
||||
return torque
|
||||
end
|
||||
|
||||
self.torque = torque * self.ratio
|
||||
|
||||
return self.output:forwardStep(self.torque, (inertia + self.inertia) * math.pow(self.ratio, 2)) / self.ratio
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
--@include /koptilnya/libs/watcher.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
--@include ./base.txt
|
||||
|
||||
local BaseGearbox = require('./base.txt')
|
||||
|
||||
require('/koptilnya/libs/watcher.txt')
|
||||
require('/koptilnya/libs/utils.txt')
|
||||
|
||||
local ManualGearbox = class('ManualGearbox', BaseGearbox)
|
||||
|
||||
@@ -13,7 +15,7 @@ function ManualGearbox:initialize(vehicle, name, config)
|
||||
if CLIENT then return end
|
||||
|
||||
table.merge(self.wireOutputs, {
|
||||
Gearbox_Gear = 'number'
|
||||
[string.format('%s_Gear', self.name)] = 'number'
|
||||
})
|
||||
|
||||
self.ratios = config.Ratios or { 3.6, 2.2, 1.5, 1.2, 1.0, 0.8}
|
||||
@@ -22,6 +24,8 @@ function ManualGearbox:initialize(vehicle, name, config)
|
||||
self.gear = 0
|
||||
|
||||
function shiftFunc()
|
||||
if wire.ports.Clutch == 0 then return 0 end
|
||||
|
||||
local upshift = wire.ports.Upshift or 0
|
||||
local downshift = wire.ports.Downshift or 0
|
||||
|
||||
@@ -40,13 +44,17 @@ end
|
||||
function ManualGearbox:updateWireOutputs()
|
||||
BaseGearbox.updateWireOutputs(self)
|
||||
|
||||
wire.ports.Gearbox_Gear = self.gear
|
||||
wire.ports[string.format('%s_Gear', self.name)] = self.gear
|
||||
end
|
||||
|
||||
function ManualGearbox:setGear(gear)
|
||||
if gear >= -1 and gear <= #self.ratios then
|
||||
self.gear = gear
|
||||
self:recalcRatio()
|
||||
|
||||
net.start('GEARBOX_GEAR')
|
||||
net.writeInt(gear, 5)
|
||||
net.send(self.vehicle.playersConnectedToHUD, true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,9 +73,9 @@ function ManualGearbox:shift(dir)
|
||||
end
|
||||
|
||||
function ManualGearbox:forwardStep(torque, inertia)
|
||||
local result = BaseGearbox.forwardStep(self, torque, inertia)
|
||||
|
||||
self.shiftWatcher()
|
||||
|
||||
local result = BaseGearbox.forwardStep(self, torque, inertia)
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
@@ -25,20 +25,21 @@ function PowertrainComponent:initialize(vehicle, name, config)
|
||||
self.angularVelocity = 0
|
||||
self.torque = 0
|
||||
|
||||
self.DEBUG_DATA = {}
|
||||
|
||||
if self.DEBUG then
|
||||
if CLIENT then
|
||||
self.DEBUG_DATA = {}
|
||||
|
||||
net.receive('DEBUG_' .. self.name, function()
|
||||
self.DEBUG_DATA = net.readTable()
|
||||
self:deserializeDebugData(self.DEBUG_DATA)
|
||||
end)
|
||||
end
|
||||
|
||||
self.DEBUG_SEND_DATA_DEBOUNCED = debounce(function()
|
||||
net.start("DEBUG_" .. self.name)
|
||||
net.writeTable(self.DEBUG_DATA)
|
||||
net.send(nil, true)
|
||||
end, TICK_INTERVAL * 20)
|
||||
self:serializeDebugData()
|
||||
net.send(self.vehicle.playersConnectedToHUD, true)
|
||||
end, 1 / 10)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,8 +91,14 @@ function PowertrainComponent:updateWireOutputs()
|
||||
WireComponent.updateWireOutputs(self)
|
||||
|
||||
if self.DEBUG then
|
||||
self.DEBUG_SEND_DATA_DEBOUNCED()
|
||||
-- self:DEBUG_SEND_DATA_DEBOUNCED()
|
||||
end
|
||||
end
|
||||
|
||||
function PowertrainComponent:serializeDebugData()
|
||||
end
|
||||
|
||||
function PowertrainComponent:deserializeDebugData(result)
|
||||
end
|
||||
|
||||
return PowertrainComponent
|
||||
|
||||
@@ -21,6 +21,9 @@ function Wheel:initialize(vehicle, name, config)
|
||||
local font = render.createFont("Roboto", 256, 400, true)
|
||||
local mat = render.createMaterial('models/debug/debugwhite')
|
||||
|
||||
local lerpLoad = 0
|
||||
local lerpForwardFrictionForce = 0
|
||||
local lerpSideFrictionForce = 0
|
||||
hook.add("PostDrawTranslucentRenderables", "DEBUG_RENDER_" .. self.name, function()
|
||||
if next(self.DEBUG_DATA) == nil then return end
|
||||
if not isValid(self.DEBUG_DATA.entity) then return end
|
||||
@@ -29,16 +32,19 @@ function Wheel:initialize(vehicle, name, config)
|
||||
|
||||
render.setMaterial(mat)
|
||||
render.setColor(Color(255, 0, 0, 200))
|
||||
render.draw3DBeam(pos, pos + (16 * self.DEBUG_DATA.forward), 1, 0, 0)
|
||||
lerpForwardFrictionForce = math.lerp(0.1, lerpForwardFrictionForce, self.DEBUG_DATA.forwardFrictionForce)
|
||||
render.draw3DBeam(pos, pos + ((lerpForwardFrictionForce / 500 + 16) * self.DEBUG_DATA.forward), 1, 0, 0)
|
||||
|
||||
render.setColor(Color(0, 255, 0, 255))
|
||||
render.draw3DBeam(pos, pos + (16 * self.DEBUG_DATA.right), 1, 0, 0)
|
||||
lerpSideFrictionForce = math.lerp(0.1, lerpSideFrictionForce, self.DEBUG_DATA.sideFrictionForce)
|
||||
render.draw3DBeam(pos, pos + ((lerpSideFrictionForce / 500 + 16) * self.DEBUG_DATA.right), 1, 0, 0)
|
||||
|
||||
render.setColor(Color(0, 0, 255, 200))
|
||||
render.draw3DBeam(pos, pos + (16 * self.DEBUG_DATA.up), 1, 0, 0)
|
||||
lerpLoad = math.lerp(0.1, lerpLoad, self.DEBUG_DATA.load)
|
||||
render.draw3DBeam(pos, pos + ((lerpLoad * 4 + 16) * self.DEBUG_DATA.up), 1, 0, 0)
|
||||
end)
|
||||
|
||||
if player() == owner() then
|
||||
if player() == owner() and not render.isHUDActive() then
|
||||
enableHud(nil, true)
|
||||
end
|
||||
|
||||
@@ -56,8 +62,7 @@ function Wheel:initialize(vehicle, name, config)
|
||||
}
|
||||
self.wireOutputs = {
|
||||
[string.format('%s_RPM', self.name)] = 'number',
|
||||
[string.format('%s_Mz', self.name)] = 'number',
|
||||
[string.format('%s_Fz', self.name)] = 'number',
|
||||
[string.format('%s_W', self.name)] = 'number'
|
||||
}
|
||||
|
||||
self.rot = 0
|
||||
@@ -79,10 +84,6 @@ function Wheel:initialize(vehicle, name, config)
|
||||
|
||||
self.holo = self:createHolo(self.entity)
|
||||
|
||||
if self.DEBUG then
|
||||
self.DEBUG_DATA.entity = self.entity
|
||||
end
|
||||
|
||||
if not config.Radius then
|
||||
self.customWheel.radius = self:getEntityRadius()
|
||||
end
|
||||
@@ -122,8 +123,7 @@ function Wheel:updateWireOutputs()
|
||||
PowertrainComponent.updateWireOutputs(self)
|
||||
|
||||
wire.ports[string.format('%s_RPM', self.name)] = self.customWheel:getRPM()
|
||||
wire.ports[string.format('%s_Mz', self.name)] = self.customWheel.mz
|
||||
wire.ports[string.format('%s_Fz', self.name)] = self.customWheel.load
|
||||
wire.ports[string.format('%s_W', self.name)] = self.customWheel.angularVelocity
|
||||
end
|
||||
|
||||
function Wheel:queryInertia()
|
||||
@@ -138,13 +138,13 @@ function Wheel:forwardStep(torque, inertia)
|
||||
if not isValid(self.customWheel) then
|
||||
return 0
|
||||
end
|
||||
|
||||
self.customWheel.motorTorque = torque * self.direction
|
||||
|
||||
self.customWheel.motorTorque = torque
|
||||
self.customWheel.brakeTorque = math.max(self.brakePower * self.vehicle.brake, self.handbrakePower * self.vehicle.handbrake)
|
||||
|
||||
self.customWheel:update()
|
||||
|
||||
self.angularVelocity = self.customWheel.angularVelocity * self.direction
|
||||
self.angularVelocity = self.customWheel.angularVelocity
|
||||
|
||||
if self.customWheel.hasHit and isValid(self.vehicle.basePhysObject) then
|
||||
local surfaceForceVector = self.customWheel.right * self.customWheel.sideFriction.force + self.customWheel.forward * self.customWheel.forwardFriction.force
|
||||
@@ -153,18 +153,12 @@ function Wheel:forwardStep(torque, inertia)
|
||||
end
|
||||
|
||||
if isValid(self.holo) then
|
||||
if self.DEBUG then
|
||||
self.DEBUG_DATA.forward = self.customWheel.forward
|
||||
self.DEBUG_DATA.right = self.customWheel.right
|
||||
self.DEBUG_DATA.up = self.customWheel.up
|
||||
end
|
||||
|
||||
local entityAngles = self.entity:getAngles()
|
||||
|
||||
self.rot = self.rot + self.angularVelocity * TICK_INTERVAL * self.direction
|
||||
self.rot = self.rot + self.angularVelocity * TICK_INTERVAL
|
||||
|
||||
local steerRotated = entityAngles:rotateAroundAxis(self.customWheel.up, nil, math.rad(-self.customWheel.steerAngle) + self.customWheel.toeAngle)
|
||||
local camberRotated = steerRotated:rotateAroundAxis(self.customWheel.forward, nil, -self.customWheel.camberAngle)
|
||||
local camberRotated = steerRotated:rotateAroundAxis(self.customWheel.forward, nil, -self.customWheel.camberAngle * self.direction)
|
||||
local angularVelocityRotated = camberRotated:rotateAroundAxis(self.customWheel.right, nil, self.rot)
|
||||
|
||||
self.holo:setAngles(angularVelocityRotated)
|
||||
@@ -173,4 +167,26 @@ function Wheel:forwardStep(torque, inertia)
|
||||
return self.customWheel.counterTorque
|
||||
end
|
||||
|
||||
function Wheel:serializeDebugData()
|
||||
net.writeEntity(self.entity)
|
||||
net.writeVector(self.customWheel.forward)
|
||||
net.writeVector(self.customWheel.right)
|
||||
net.writeVector(self.customWheel.up)
|
||||
net.writeFloat(self.customWheel.load)
|
||||
net.writeFloat(self.customWheel.forwardFriction.force)
|
||||
net.writeFloat(self.customWheel.sideFriction.force)
|
||||
end
|
||||
|
||||
function Wheel:deserializeDebugData(result)
|
||||
net.readEntity(function(ent)
|
||||
result.entity = ent
|
||||
end)
|
||||
result.forward = net.readVector()
|
||||
result.right = net.readVector()
|
||||
result.up = net.readVector()
|
||||
result.load = net.readFloat()
|
||||
result.forwardFrictionForce = net.readFloat()
|
||||
result.sideFrictionForce = net.readFloat()
|
||||
end
|
||||
|
||||
return Wheel
|
||||
|
||||
Reference in New Issue
Block a user