Continuing to implement new steering, removed common.txt, inside functions have been moved to separate files
This commit is contained in:
parent
2f8c949776
commit
5c854e183b
@ -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
|
||||
1
koptilnya/libs/constants.txt
Normal file
1
koptilnya/libs/constants.txt
Normal file
@ -0,0 +1 @@
|
||||
NULL_ENTITY = entity(0)
|
||||
@ -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
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user