Merge pull request #1 from koptilnya/darksupah
Added base for new steering, added some extension methods
This commit is contained in:
commit
1aafe32376
3
koptilnya/libs/constants.txt
Normal file
3
koptilnya/libs/constants.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
NULL_ENTITY = entity(0)
|
||||||
|
CURRENT_PLAYER = player()
|
||||||
|
OWNER = owner()
|
||||||
@ -20,6 +20,31 @@ function table.chunk(tbl, size)
|
|||||||
return result
|
return result
|
||||||
end
|
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
|
||||||
|
|
||||||
function table.contains(tbl, ...)
|
function table.contains(tbl, ...)
|
||||||
local argCount = #arg
|
local argCount = #arg
|
||||||
|
|
||||||
|
|||||||
5
koptilnya/steering/input.txt
Normal file
5
koptilnya/steering/input.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Input = class("Input")
|
||||||
|
|
||||||
|
function Input:initialize(keyMap)
|
||||||
|
|
||||||
|
end
|
||||||
74
koptilnya/steering/main.txt
Normal file
74
koptilnya/steering/main.txt
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
-- @name Steering
|
||||||
|
-- @author DarkSupah
|
||||||
|
-- @server
|
||||||
|
-- @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,
|
||||||
|
CorrectionOn = 0.8,
|
||||||
|
CorrectionOff = 0.2
|
||||||
|
}
|
||||||
|
local rearConfig = {
|
||||||
|
Camber = -5,
|
||||||
|
Caster = -5,
|
||||||
|
Ackermann = 1.2,
|
||||||
|
Lock = 5,
|
||||||
|
CorrectionOn = 0.8,
|
||||||
|
CorrectionOff = 0.2
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 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 = {
|
||||||
|
SteerNormalized = "number",
|
||||||
|
Driver = "entity"
|
||||||
|
}
|
||||||
|
|
||||||
|
local _allInputs = table.merge(_inputs, _slaves)
|
||||||
|
|
||||||
|
wire.adjustPorts(_allInputs, _outputs)
|
||||||
|
|
||||||
|
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)
|
||||||
23
koptilnya/steering/steer_axle.txt
Normal file
23
koptilnya/steering/steer_axle.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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()
|
||||||
|
self:_updateSlave(self.leftWheel)
|
||||||
|
self:_updateSlave(self.rightWheel)
|
||||||
|
end
|
||||||
|
|
||||||
|
function SteerAxle:_updateSlave(slave)
|
||||||
|
if slave:isValid() and not slave:isPlayerHolding() then
|
||||||
|
slave:setAngles(base:localToWorldAngles(Angle(0, 0, 0)))
|
||||||
|
if not slave:isFrozen() then
|
||||||
|
slave:setFrozen()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
19
koptilnya/steering/steering_controller.txt
Normal file
19
koptilnya/steering/steering_controller.txt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
-- @include ../libs/constants.txt
|
||||||
|
require("../libs/constants.txt")
|
||||||
|
|
||||||
|
SteeringController = class("SteeringController")
|
||||||
|
|
||||||
|
function SteeringController:initialize(base)
|
||||||
|
self.seat = NULL_ENTITY
|
||||||
|
self.driver = NULL_ENTITY
|
||||||
|
|
||||||
|
self.base = base
|
||||||
|
end
|
||||||
|
|
||||||
|
function SteeringController:update()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function SteeringController:setDriver(ply)
|
||||||
|
self.driver = ply
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user