From 03f68e85e5cb1bc56dba70cc6ba33e4a436264a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=93=D1=80=D0=B0=D1=87=D1=91?= =?UTF-8?q?=D0=B2?= Date: Fri, 26 Mar 2021 22:05:35 +0500 Subject: [PATCH 1/5] Creating new steering --- koptilnya/steering/main.txt | 33 ++++++++++++++++++++++ koptilnya/steering/steer_axle.txt | 1 + koptilnya/steering/steering_controller.txt | 26 +++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 koptilnya/steering/main.txt create mode 100644 koptilnya/steering/steer_axle.txt create mode 100644 koptilnya/steering/steering_controller.txt diff --git a/koptilnya/steering/main.txt b/koptilnya/steering/main.txt new file mode 100644 index 0000000..923d457 --- /dev/null +++ b/koptilnya/steering/main.txt @@ -0,0 +1,33 @@ +-- @name Grip steering +-- @author DarkSupah +-- @server +local frontWheelsConfig = { + Camber = -5, + Caster = 5, + Ackermann = 1.1, + Lock = 50 +} + +local rearWheelsConfig = { + Camber = -5, + Caster = -5, + Ackermann = 1.2, + Lock = 5 +} + +local NULL_ENTITY = entity(0) + +local INPUTS = { + Seat = "entity" +} +local OUTPUTS = { + Steer = "number" +} + +wire.adjustPorts(INPUTS, OUTPUTS) + +local steeringController = SteeringController:new() + +hook.add("think", "steeringUpdate", function() + steeringController.steeringController:update() +end) diff --git a/koptilnya/steering/steer_axle.txt b/koptilnya/steering/steer_axle.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/koptilnya/steering/steer_axle.txt @@ -0,0 +1 @@ + diff --git a/koptilnya/steering/steering_controller.txt b/koptilnya/steering/steering_controller.txt new file mode 100644 index 0000000..cf5eb3e --- /dev/null +++ b/koptilnya/steering/steering_controller.txt @@ -0,0 +1,26 @@ +SteeringController = class("SteeringController") + +function SteeringController:initialize() + self.seat = NULL_ENTITY + self.driver = NULL_ENTITY + + hook.add("PlayerEnteredVehicle", "", function(ply, veh) + if veh == self.seat then + self.driver = ply + end + end) + + hook.add("PlayerLeaveVehicle", "", function(ply, veh) + if veh == self.seat then + self.driver = NULL_ENTITY + end + end) +end + +function SteeringController:update() + -- print() +end + +function SteeringController:setDriver(ply) + self.driver = ply +end From 2f8c9497767af7078efbc2507b07ad78d97789da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=93=D1=80=D0=B0=D1=87=D1=91?= =?UTF-8?q?=D0=B2?= Date: Fri, 26 Mar 2021 22:32:47 +0500 Subject: [PATCH 2/5] Added common file to store useful functions --- koptilnya/common.txt | 26 ++++++++++++++++++++++++++ koptilnya/libs/render.txt | 28 +++++++++++++++++++--------- 2 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 koptilnya/common.txt diff --git a/koptilnya/common.txt b/koptilnya/common.txt new file mode 100644 index 0000000..767ef59 --- /dev/null +++ b/koptilnya/common.txt @@ -0,0 +1,26 @@ +NULL_ENTITY = entity(0) + +function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy +end + +function table:merge(table1, table2) + local newTable = deepcopy(table1) + + for k, v in pairs(table2) do + newTable[k] = v + end + + return newTable +end diff --git a/koptilnya/libs/render.txt b/koptilnya/libs/render.txt index be32eff..e933bb3 100644 --- a/koptilnya/libs/render.txt +++ b/koptilnya/libs/render.txt @@ -44,16 +44,26 @@ function render.drawArc(x, y, ang, p, rad, seg) end function render.drawFilledCircle(x, y, radius, seg) - local cir = {} + local cir = {} - table.insert(cir, { x = x, y = y, u = 0.5, v = 0.5 }) - for i = 0, seg do - local a = math.rad(( i / seg ) * -360) - table.insert(cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 }) - end + table.insert(cir, { x = x, y = y, u = 0.5, v = 0.5 }) + for i = 0, seg do + local a = math.rad(( i / seg ) * -360) + table.insert(cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 }) + end - local a = math.rad(0) - table.insert(cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 }) + local a = math.rad(0) + table.insert(cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 }) - render.drawPoly(cir) + render.drawPoly(cir) +end + +function render.drawRotatedSimpleText(x, y, text, ang) + local m = Matrix() + m:translate(Vector(x, y, 0 )) + m:rotate(Angle(0, ang, 0)) + + render.pushMatrix(m) + render.drawSimpleText(0, 0, text) + render.popMatrix() end \ No newline at end of file From 5c854e183bf17ede4e324fe8b677352df3266019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=93=D1=80=D0=B0=D1=87=D1=91?= =?UTF-8?q?=D0=B2?= Date: Fri, 26 Mar 2021 22:42:51 +0500 Subject: [PATCH 3/5] Continuing to implement new steering, removed common.txt, inside functions have been moved to separate files --- koptilnya/common.txt | 26 ---------- koptilnya/libs/constants.txt | 1 + koptilnya/libs/table.txt | 25 ++++++++++ koptilnya/steering/main.txt | 57 ++++++++++++++++++---- koptilnya/steering/steer_axle.txt | 12 +++++ koptilnya/steering/steering_controller.txt | 19 +++----- 6 files changed, 91 insertions(+), 49 deletions(-) delete mode 100644 koptilnya/common.txt create mode 100644 koptilnya/libs/constants.txt diff --git a/koptilnya/common.txt b/koptilnya/common.txt deleted file mode 100644 index 767ef59..0000000 --- a/koptilnya/common.txt +++ /dev/null @@ -1,26 +0,0 @@ -NULL_ENTITY = entity(0) - -function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy -end - -function table:merge(table1, table2) - local newTable = deepcopy(table1) - - for k, v in pairs(table2) do - newTable[k] = v - end - - return newTable -end diff --git a/koptilnya/libs/constants.txt b/koptilnya/libs/constants.txt new file mode 100644 index 0000000..572a731 --- /dev/null +++ b/koptilnya/libs/constants.txt @@ -0,0 +1 @@ +NULL_ENTITY = entity(0) \ No newline at end of file diff --git a/koptilnya/libs/table.txt b/koptilnya/libs/table.txt index 6d41495..51179a6 100644 --- a/koptilnya/libs/table.txt +++ b/koptilnya/libs/table.txt @@ -17,3 +17,28 @@ function table.chunk(tbl, size) return result end + +function table.deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[table.deepcopy(orig_key)] = table.deepcopy(orig_value) + end + setmetatable(copy, table.deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy +end + +function table.merge(table1, table2) + local newTable = table.deepcopy(table1) + + for k, v in pairs(table2) do + newTable[k] = v + end + + return newTable +end \ No newline at end of file diff --git a/koptilnya/steering/main.txt b/koptilnya/steering/main.txt index 923d457..a9d7bd8 100644 --- a/koptilnya/steering/main.txt +++ b/koptilnya/steering/main.txt @@ -1,33 +1,70 @@ --- @name Grip steering +-- @name Steering -- @author DarkSupah -- @server -local frontWheelsConfig = { +-- @include ./steering_controller.txt +-- @include ./steer_axle.txt +-- @include ../libs/constants.txt +-- @include ../libs/table.txt +require("./steering_controller.txt") +require("./steer_axle.txt") +require("../libs/constants.txt") +require("../libs/table.txt") + +local frontConfig = { Camber = -5, Caster = 5, Ackermann = 1.1, Lock = 50 } - -local rearWheelsConfig = { +local rearConfig = { Camber = -5, Caster = -5, Ackermann = 1.2, Lock = 5 } -local NULL_ENTITY = entity(0) +-- Fucking slaves, get you ass back here +local SLAVES = { + E1 = "entity", + E2 = "entity", + E3 = "entity", + E4 = "entity" +} + +local AXLES = {SteerAxle:new(frontConfig, wire.ports.E1, wire.ports.E2), + SteerAxle:new(rearConfig, wire.ports.E3, wire.ports.E4)} local INPUTS = { + Base = "entity", Seat = "entity" } + local OUTPUTS = { - Steer = "number" + SteerNormalized = "number", + Driver = "entity" } -wire.adjustPorts(INPUTS, OUTPUTS) +local ALL_INPUTS = table.merge(INPUTS, SLAVES) -local steeringController = SteeringController:new() +wire.adjustPorts(ALL_INPUTS, OUTPUTS) -hook.add("think", "steeringUpdate", function() - steeringController.steeringController:update() +local steeringController = SteeringController:new(wire.ports.Base) + +hook.add("PlayerEnteredVehicle", "onEnter", function(ply, veh) + if veh == steeringController.seat then + steeringController:setDriver(ply) + end +end) + +hook.add("PlayerLeaveVehicle", "onLeave", function(ply, veh) + if veh == steeringController.seat then + steeringController:setDriver(NULL_ENTITY) + end +end) + +hook.add("think", "update", function() + steeringController.seat = wire.ports.Seat + wire.ports.Driver = steeringController.driver + + steeringController:update() end) diff --git a/koptilnya/steering/steer_axle.txt b/koptilnya/steering/steer_axle.txt index 8b13789..47e1abb 100644 --- a/koptilnya/steering/steer_axle.txt +++ b/koptilnya/steering/steer_axle.txt @@ -1 +1,13 @@ +SteerAxle = class("SteerAxle") +function SteerAxle:initialize(config, leftWheel, rightWheel) + self.steer = 0 + + self.config = config + self.leftWheel = leftWheel + self.rightWheel = rightWheel +end + +function SteerAxle:update() + +end diff --git a/koptilnya/steering/steering_controller.txt b/koptilnya/steering/steering_controller.txt index cf5eb3e..bcdd279 100644 --- a/koptilnya/steering/steering_controller.txt +++ b/koptilnya/steering/steering_controller.txt @@ -1,24 +1,17 @@ +-- @include ../libs/constants.txt +require("../libs/constants.txt") + SteeringController = class("SteeringController") -function SteeringController:initialize() +function SteeringController:initialize(base) self.seat = NULL_ENTITY self.driver = NULL_ENTITY - hook.add("PlayerEnteredVehicle", "", function(ply, veh) - if veh == self.seat then - self.driver = ply - end - end) - - hook.add("PlayerLeaveVehicle", "", function(ply, veh) - if veh == self.seat then - self.driver = NULL_ENTITY - end - end) + self.base = base end function SteeringController:update() - -- print() + end function SteeringController:setDriver(ply) From 191b13f6b4045380d17fc2f8353fde8c20545b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=93=D1=80=D0=B0=D1=87=D1=91?= =?UTF-8?q?=D0=B2?= Date: Sun, 28 Mar 2021 18:30:08 +0500 Subject: [PATCH 4/5] Moved engine to koptilnya folder --- koptilnya/engine_rework/constants.txt | 3 + koptilnya/engine_rework/controller.txt | 132 +++++++++++++++++++++++++ koptilnya/engine_rework/engine.txt | 121 +++++++++++++++++++++++ koptilnya/engine_rework/gearbox.txt | 13 +++ koptilnya/engine_rework/input.txt | 104 +++++++++++++++++++ koptilnya/engine_rework/math.txt | 13 +++ 6 files changed, 386 insertions(+) create mode 100644 koptilnya/engine_rework/constants.txt create mode 100644 koptilnya/engine_rework/controller.txt create mode 100644 koptilnya/engine_rework/engine.txt create mode 100644 koptilnya/engine_rework/gearbox.txt create mode 100644 koptilnya/engine_rework/input.txt create mode 100644 koptilnya/engine_rework/math.txt diff --git a/koptilnya/engine_rework/constants.txt b/koptilnya/engine_rework/constants.txt new file mode 100644 index 0000000..ab4dd5b --- /dev/null +++ b/koptilnya/engine_rework/constants.txt @@ -0,0 +1,3 @@ +NULL_ENTITY = entity(0) +CURRENT_PLAYER = player() +OWNER = owner() diff --git a/koptilnya/engine_rework/controller.txt b/koptilnya/engine_rework/controller.txt new file mode 100644 index 0000000..927b716 --- /dev/null +++ b/koptilnya/engine_rework/controller.txt @@ -0,0 +1,132 @@ +-- @name Engine +-- @author DarkSupah, Opti1337, .hemp +-- @shared +-- @include ./constants.txt +-- @include ./engine.txt +-- @include ./gearbox.txt +-- @include ./input.txt +require("./constants.txt") +require("./engine.txt") +require("./gearbox.txt") +require("./input.txt") + +local configPath = "engine/" + +local inputConfigPath = "input.json" +local engineConfigPath = "engine.json" +local gearboxConfigPath = "gearbox.json" + +Controller = class("Controller") + +function Controller:initialize(inputController, engine, gearbox, axles) + self.inputController = inputController + self.engine = engine + self.gearbox = gearbox + self.axles = axles + + if SERVER then + hook.add("PlayerEnteredVehicle", "enterHandler", function(ply, vehicle) + if (vehicle == wire.ports.Seat) then + self.inputController:setPlayer(ply) + hook.run("DriverChanged", ply) + end + end) + + hook.add("PlayerLeaveVehicle", "exitHandler", function(ply, vehicle) + if (vehicle == wire.ports.Seat) then + self.inputController:setPlayer(NULL_ENTITY) + hook.run("DriverChanged", NULL_ENTITY) + end + end) + + net.receive("serverConfigs", function() + local inputConfig = net.readTable() + local engineConfig = net.readTable() + local gearboxConfig = net.readTable() + + self.inputController:setConfig(inputConfig) + self.engine:setConfig(engineConfig) + self.gearbox:setConfig(gearboxConfig) + + net.start("clientConfigs") + net.writeTable(inputConfig) + net.writeTable(engineConfig) + net.writeTable(gearboxConfig) + net.send() + end) + end + + if CLIENT then + net.receive("clientConfigs", function() + self.inputController:setConfig(net.readTable()) + self.engine:setConfig(net.readTable()) + self.gearbox:setConfig(net.readTable()) + end) + end + +end + +function Controller:update() + self.inputController:update() + self.engine:update() + self.gearbox:update() + + self.engine:setThrottle(self.inputController.throttle.value) +end + +local inputController = InputController:new() + +local engine = Engine:new() +local gearbox = Gearbox:new() + +local controller = Controller:new(inputController, engine, gearbox) + +if SERVER then + wire.adjustPorts({ + Seat = "entity" + }, { + Input = "table", + Engine = "table" + }) + + if wire.ports.Seat:isValid() then + local possibleDriver = wire.ports.Seat:getDriver() + + if possibleDriver:isValid() then + controller.inputController:setPlayer(possibleDriver) + wire.ports.Driver = possibleDriver + end + end + + hook.add("DriverChanged", "driverChangeHandler", function(ply) + wire.ports.Driver = ply + end) + + hook.add("tick", "update", function() + controller:update() + + wire.ports.Engine = controller.engine + wire.ports.Input = controller.inputController + + end) + +end + +if CLIENT then + if CURRENT_PLAYER == OWNER then + local inputConfigFile = file.read(configPath .. inputConfigPath) + local inputConfig = json.decode(inputConfigFile) + + local engineConfigFile = file.read(configPath .. engineConfigPath) + local engineConfig = json.decode(engineConfigFile) + + local gearboxConfigFile = file.read(configPath .. gearboxConfigPath) + local gearboxConfig = json.decode(gearboxConfigFile) + + net.start("serverConfigs") + net.writeTable(inputConfig) + net.writeTable(engineConfig) + net.writeTable(gearboxConfig) + net.send() + end +end diff --git a/koptilnya/engine_rework/engine.txt b/koptilnya/engine_rework/engine.txt new file mode 100644 index 0000000..686de7c --- /dev/null +++ b/koptilnya/engine_rework/engine.txt @@ -0,0 +1,121 @@ +-- @include ./math.txt +require("./math.txt") + +Engine = class("Engine") + +function Engine:initialize() + self.config = {} + + if SERVER then + self.active = true + + self.desiredRPM = 0 + self.RPM = 0 + + self.throttle = 0 + + self.flywheelInertiaMoment = 0 + self.volume = 0 + self.peakTq = 0 + self.torque = 0 + self.power = 0 + + self.gearboxRPM = 0 + + self.torqueTable = {} + end +end + +if SERVER then + + function Engine:setThrottle(throttle) + self.throttle = throttle + end + + function Engine:update() + -- check if config table is not empty + if next(self.config) ~= nil then + local activeCoeff = self.active and 1 or 0 + + self.desiredRPM = self.throttle * self.config.maxRPM + self.config.idleRPM + + local masterThrottle = activeCoeff * self.RPM > self.config.maxRPM and 0 or 1 + + self.RPM = math.lerp(1 / (self.flywheelInertiaMoment * 100), self.RPM, self.desiredRPM * masterThrottle) + + self:calculateTorque() + end + + end + + function Engine:updateStats() + local bore = self.config.bore + local stroke = self.config.stroke + local flywheelMass = self.config.flywheelMass + local cylinders = self.config.cylinders + local BMEP = self.config.BMEP + + self.flywheelInertiaMoment = (stroke / 1000) * flywheelMass + + self.volume = math.floor((bore / 2) ^ 2 * stroke * cylinders * math.pi / 1000) + + self.peakTq = (stroke / bore) * self.volume * BMEP / 100 + + self.torqueTable = {} + + for i = 1, #self.config.curve do + table.insert(self.torqueTable, self:getTorqueValue(i / #self.config.curve)) + end + + print("Peak Torque: " .. math.ceil(self.peakTq) .. "nm") + end + + function Engine:calculateTorque() + local RPMfrac = math.min(1, self.RPM / self.config.maxRPM) + local tableCount = table.count(self.torqueTable) + + local lerpTo = math.ceil(RPMfrac * tableCount) + local lerpFrom = math.floor(RPMfrac * tableCount) + + local lerpToVal = self.torqueTable[lerpTo] or 0 + local lerpFromVal = self.torqueTable[lerpFrom] or 0 + + local frac = (RPMfrac * tableCount) % 1 + local minActiveThrottle = self.config.idleRPM / self.config.maxRPM + + local value = math.max(minActiveThrottle, self.throttle) * math.lerp(frac, lerpFromVal, lerpToVal) * self.peakTq + + local overdrive = math.clamp(1 - self.gearboxRPM / self.desiredRPM, -1, 0) + + local idleRPM = self.config.idleRPM + local maxRPM = self.config.maxRPM + local brakeTorqueCoeff = self.config.brakeTorqueCoeff + + local brakeTorque = -value * math.max(1 - self.throttle, idleRPM / maxRPM, -overdrive) * + (self.gearboxRPM / maxRPM) * brakeTorqueCoeff + + local RPMLimiter = math.clamp(1 - self.throttle * (self.gearboxRPM / self.desiredRPM), self.throttle, 1) + local netTq = value * math.max(self.throttle, idleRPM / maxRPM) * RPMLimiter + brakeTorque + + self.torque = netTq + end + + function Engine:getTorqueValue(num) + local torque = 0 + + for key, segment in pairs(self.config.curve) do + torque = torque + segment * polinom(key, table.count(self.config.curve), num) + end + + return torque + end + +end + +function Engine:setConfig(config) + self.config = config + + if SERVER then + self:updateStats() + end +end diff --git a/koptilnya/engine_rework/gearbox.txt b/koptilnya/engine_rework/gearbox.txt new file mode 100644 index 0000000..430644b --- /dev/null +++ b/koptilnya/engine_rework/gearbox.txt @@ -0,0 +1,13 @@ +Gearbox = class("Gearbox") + +function Gearbox:initialize() + self.config = {} +end + +function Gearbox:update() + +end + +function Gearbox:setConfig(config) + self.config = config +end diff --git a/koptilnya/engine_rework/input.txt b/koptilnya/engine_rework/input.txt new file mode 100644 index 0000000..36deb29 --- /dev/null +++ b/koptilnya/engine_rework/input.txt @@ -0,0 +1,104 @@ +-- @include ./constants.txt +require("./constants.txt") + +InputController = class("InputController") + +function InputController:initialize() + self.ply = NULL_ENTITY + + self.config = {} -- keys and pedal speed config + + if SERVER then + self.throttle = { + target = 0, + value = 0 + } + self.brake = { + target = 0, + value = 0 + } + self.clutch = { + target = 0, + value = 0 + } + self.start = { + target = 0, + value = 0, + type = "keyPress" + } + + net.receive("input", function() + local inputName = net.readString() + local target = net.readBool() + + if self[inputName] then + self[inputName].target = target and (self.config[inputName] and self.config[inputName].max or 1) or 0 + end + end) + end + + if CLIENT then + function setTargetInput(pressedKey, target) + local key = string.upper(input.getKeyName(pressedKey)) + + if self.keyToInputName[key] then + net.start("input") + net.writeString(self.keyToInputName[key].inputName) + net.writeBool(target) + net.send() + end + end + + hook.add("inputPressed", "inputPress", function(key) + if (self.ply ~= NULL_ENTITY and self.ply == CURRENT_PLAYER) then + setTargetInput(key, true) + end + end) + + hook.add("inputReleased", "inputRelease", function(key) + if (self.ply ~= NULL_ENTITY and self.ply == CURRENT_PLAYER) then + setTargetInput(key, false) + end + end) + + net.receive("changePlayer", function() + self.ply = net.readEntity() + end) + end + +end + +if SERVER then + function InputController:setPlayer(ply) + self.ply = ply + net.start("changePlayer") + net.writeEntity(ply or NULL_ENTITY) + net.send() + end + + function InputController:update() + for key in pairs(self.config) do + if self[key] then + local pressSpeed = self.config[key].press or 1 + local releaseSpeed = self.config[key].release or 1 + + self[key].value = math.lerp(self[key].target == 1 and pressSpeed or releaseSpeed, self[key].value, + self[key].target) + end + end + end +end + +function InputController:setConfig(config) + self.config = table.copy(config) + + local keyToInputName = {} + + for key, value in pairs(config) do + keyToInputName[string.upper(value.key)] = { + inputName = key + } + end + + self.keyToInputName = table.copy(keyToInputName) +end diff --git a/koptilnya/engine_rework/math.txt b/koptilnya/engine_rework/math.txt new file mode 100644 index 0000000..9043337 --- /dev/null +++ b/koptilnya/engine_rework/math.txt @@ -0,0 +1,13 @@ +function factorial(number) + local res = 1 + + for i = 1, number do + res = i * res + end + + return res +end + +function polinom(i, n, t) + return factorial(n) / (factorial(i) * factorial(n - i)) * (t ^ i) * (1 - t) ^ (n - i) +end From 3b287e5981af5f1f3ee2f3021441c087ee362566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=93=D1=80=D0=B0=D1=87=D1=91?= =?UTF-8?q?=D0=B2?= Date: Sun, 28 Mar 2021 19:28:45 +0500 Subject: [PATCH 5/5] Included missing engine files --- koptilnya/engine_rework/constants.txt | 3 --- koptilnya/engine_rework/controller.txt | 4 ++-- koptilnya/engine_rework/engine.txt | 7 ++----- koptilnya/engine_rework/input.txt | 4 ++-- koptilnya/libs/constants.txt | 4 +++- 5 files changed, 9 insertions(+), 13 deletions(-) delete mode 100644 koptilnya/engine_rework/constants.txt diff --git a/koptilnya/engine_rework/constants.txt b/koptilnya/engine_rework/constants.txt deleted file mode 100644 index ab4dd5b..0000000 --- a/koptilnya/engine_rework/constants.txt +++ /dev/null @@ -1,3 +0,0 @@ -NULL_ENTITY = entity(0) -CURRENT_PLAYER = player() -OWNER = owner() diff --git a/koptilnya/engine_rework/controller.txt b/koptilnya/engine_rework/controller.txt index 927b716..3c74605 100644 --- a/koptilnya/engine_rework/controller.txt +++ b/koptilnya/engine_rework/controller.txt @@ -1,11 +1,11 @@ -- @name Engine -- @author DarkSupah, Opti1337, .hemp -- @shared --- @include ./constants.txt +-- @include ../libs/constants.txt -- @include ./engine.txt -- @include ./gearbox.txt -- @include ./input.txt -require("./constants.txt") +require("../libs/constants.txt") require("./engine.txt") require("./gearbox.txt") require("./input.txt") diff --git a/koptilnya/engine_rework/engine.txt b/koptilnya/engine_rework/engine.txt index 686de7c..9dc9cec 100644 --- a/koptilnya/engine_rework/engine.txt +++ b/koptilnya/engine_rework/engine.txt @@ -83,7 +83,7 @@ if SERVER then local frac = (RPMfrac * tableCount) % 1 local minActiveThrottle = self.config.idleRPM / self.config.maxRPM - local value = math.max(minActiveThrottle, self.throttle) * math.lerp(frac, lerpFromVal, lerpToVal) * self.peakTq + local value = math.lerp(frac, lerpFromVal, lerpToVal) * self.peakTq local overdrive = math.clamp(1 - self.gearboxRPM / self.desiredRPM, -1, 0) @@ -91,11 +91,8 @@ if SERVER then local maxRPM = self.config.maxRPM local brakeTorqueCoeff = self.config.brakeTorqueCoeff - local brakeTorque = -value * math.max(1 - self.throttle, idleRPM / maxRPM, -overdrive) * - (self.gearboxRPM / maxRPM) * brakeTorqueCoeff - local RPMLimiter = math.clamp(1 - self.throttle * (self.gearboxRPM / self.desiredRPM), self.throttle, 1) - local netTq = value * math.max(self.throttle, idleRPM / maxRPM) * RPMLimiter + brakeTorque + local netTq = value * math.max(self.throttle, idleRPM / maxRPM) * RPMLimiter self.torque = netTq end diff --git a/koptilnya/engine_rework/input.txt b/koptilnya/engine_rework/input.txt index 36deb29..ba87b93 100644 --- a/koptilnya/engine_rework/input.txt +++ b/koptilnya/engine_rework/input.txt @@ -1,5 +1,5 @@ --- @include ./constants.txt -require("./constants.txt") +-- @include ../libs/constants.txt +require("../libs/constants.txt") InputController = class("InputController") diff --git a/koptilnya/libs/constants.txt b/koptilnya/libs/constants.txt index 572a731..fee1b0f 100644 --- a/koptilnya/libs/constants.txt +++ b/koptilnya/libs/constants.txt @@ -1 +1,3 @@ -NULL_ENTITY = entity(0) \ No newline at end of file +NULL_ENTITY = entity(0) +CURRENT_PLAYER = player() +OWNER = owner() \ No newline at end of file