-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 97f1626
Showing
5 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
local socket = require("socket") | ||
local Triggers = require("dsxTriggerEnum") | ||
|
||
local M = {} | ||
|
||
local udp = socket.udp() | ||
|
||
local address = "127.0.0.1" | ||
local port = 6969 | ||
|
||
local state = { | ||
throttle = 0, | ||
brake = 0, | ||
isABSActive = false, | ||
airSpeedKmh = 0, | ||
beamDamage = 0, | ||
} | ||
|
||
local function packetToJson(packet) | ||
return jsonEncode(packet) | ||
end | ||
|
||
local function send(data) | ||
local jsonData = packetToJson(data) | ||
udp:sendto(jsonData, address, port) | ||
end | ||
|
||
-- modified lerp with bias toward 'a' | ||
function lerp(a, b, t) | ||
return a + (b - a) * 0.5 * t | ||
end | ||
|
||
function inverseLerp(a, b, v) | ||
if a ~= b then | ||
return (v - a) / (b - a) | ||
end | ||
return 0 | ||
end | ||
|
||
local function handleLeftTrigger() | ||
local startOfResistanceBrake = 1 * lerp(0.4, 1, state.brake) | ||
local startOfResistance = lerp(25, 175, startOfResistanceBrake) | ||
local airSpeed = math.min(100, inverseLerp(0, 100, state.airSpeedKmh)) | ||
local amountOfForceExcerted = math.min(255, lerp(50, 255, airSpeed)) | ||
|
||
if not state.isABSActive then | ||
return { | ||
type = Triggers.InstructionType.TriggerUpdate, | ||
parameters = { | ||
0, | ||
Triggers.Trigger.Left, | ||
Triggers.TriggerMode.CustomTriggerValue, | ||
Triggers.CustomTriggerValueMode.Rigid, | ||
startOfResistance, | ||
amountOfForceExcerted, | ||
255, | ||
0, | ||
0, | ||
0, | ||
0 | ||
} | ||
} | ||
else | ||
return { | ||
type = Triggers.InstructionType.TriggerUpdate, | ||
parameters = { | ||
0, | ||
Triggers.Trigger.Left, | ||
Triggers.TriggerMode.CustomTriggerValue, | ||
Triggers.CustomTriggerValueMode.VibrateResistanceAB, | ||
255, | ||
255, | ||
255, | ||
255, | ||
255, | ||
255, | ||
10 | ||
} | ||
} | ||
end | ||
end | ||
|
||
local function handleRightTrigger() | ||
local startOfResistanceThrottle = 1 * lerp(0.4, 1, state.throttle) | ||
local startOfResistance = lerp(50, 175, startOfResistanceThrottle) | ||
local totalForceExcerted = 25 | ||
|
||
return { | ||
type = Triggers.InstructionType.TriggerUpdate, | ||
parameters = { | ||
0, | ||
Triggers.Trigger.Right, | ||
Triggers.TriggerMode.CustomTriggerValue, | ||
Triggers.CustomTriggerValueMode.Rigid, | ||
startOfResistance, | ||
totalForceExcerted, | ||
255, | ||
0, | ||
0, | ||
0, | ||
0 | ||
} | ||
} | ||
end | ||
|
||
local function handleVehicleData() | ||
local instructions = {} | ||
|
||
table.insert(instructions, handleLeftTrigger()) | ||
table.insert(instructions, handleRightTrigger()) | ||
|
||
send( | ||
{ | ||
instructions = instructions | ||
} | ||
) | ||
end | ||
|
||
local function dsxAdvancedUpdate(throttle, brake, isABSActive, airSpeedKmh, beamDamage) | ||
state.throttle = throttle | ||
state.brake = brake | ||
state.isABSActive = isABSActive | ||
state.airSpeedKmh = airSpeedKmh | ||
state.beamDamage = beamDamage | ||
|
||
handleVehicleData() | ||
end | ||
|
||
M.dsxAdvancedUpdate = dsxAdvancedUpdate | ||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local Triggers = {} | ||
|
||
-- TriggerMode Enum | ||
Triggers.TriggerMode = { | ||
Normal = 0, | ||
GameCube = 1, | ||
VerySoft = 2, | ||
Soft = 3, | ||
Hard = 4, | ||
VeryHard = 5, | ||
Hardest = 6, | ||
Rigid = 7, | ||
VibrateTrigger = 8, | ||
Choppy = 9, | ||
Medium = 10, | ||
VibrateTriggerPulse = 11, | ||
CustomTriggerValue = 12, | ||
Resistance = 13, | ||
Bow = 14, | ||
Galloping = 15, | ||
SemiAutomaticGun = 16, | ||
AutomaticGun = 17, | ||
Machine = 18 | ||
} | ||
|
||
-- CustomTriggerValueMode Enum | ||
Triggers.CustomTriggerValueMode = { | ||
OFF = 0, | ||
Rigid = 1, | ||
RigidA = 2, | ||
RigidB = 3, | ||
RigidAB = 4, | ||
Pulse = 5, | ||
PulseA = 6, | ||
PulseB = 7, | ||
PulseAB = 8, | ||
VibrateResistance = 9, | ||
VibrateResistanceA = 10, | ||
VibrateResistanceB = 11, | ||
VibrateResistanceAB = 12, | ||
VibratePulse = 13, | ||
VibratePulseA = 14, | ||
VibratePulsB = 15, | ||
VibratePulseAB = 16 | ||
} | ||
|
||
-- Trigger Enum | ||
Triggers.Trigger = { | ||
Invalid = 0, | ||
Left = 1, | ||
Right = 2 | ||
} | ||
|
||
-- InstructionType Enum | ||
Triggers.InstructionType = { | ||
Invalid = 0, | ||
TriggerUpdate = 1, | ||
RGBUpdate = 2, | ||
PlayerLED = 3, | ||
TriggerThreshold = 4 | ||
} | ||
|
||
-- This is the representation of your enums in Lua tables | ||
return Triggers |
13 changes: 13 additions & 0 deletions
13
lua/vehicle/extensions/auto/dsxAdvancedHapticVehicleDispatcher.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
local M = {} | ||
|
||
local function updateGFX(dt) | ||
if not playerInfo.firstPlayerSeated then | ||
return | ||
end | ||
|
||
obj:queueGameEngineLua(string.format("extensions.hook('dsxAdvancedUpdate', %f, %f, %s, %f, %f)", input.state.throttle.val, input.state.brake.val, electrics.values.absActive == 1, electrics.values.airspeed * 3.6, beamstate.damage)) | ||
end | ||
|
||
M.updateGFX = updateGFX | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local Triggers = {} | ||
|
||
-- TriggerMode Enum | ||
Triggers.TriggerMode = { | ||
Normal = 0, | ||
GameCube = 1, | ||
VerySoft = 2, | ||
Soft = 3, | ||
Hard = 4, | ||
VeryHard = 5, | ||
Hardest = 6, | ||
Rigid = 7, | ||
VibrateTrigger = 8, | ||
Choppy = 9, | ||
Medium = 10, | ||
VibrateTriggerPulse = 11, | ||
CustomTriggerValue = 12, | ||
Resistance = 13, | ||
Bow = 14, | ||
Galloping = 15, | ||
SemiAutomaticGun = 16, | ||
AutomaticGun = 17, | ||
Machine = 18 | ||
} | ||
|
||
-- CustomTriggerValueMode Enum | ||
Triggers.CustomTriggerValueMode = { | ||
OFF = 0, | ||
Rigid = 1, | ||
RigidA = 2, | ||
RigidB = 3, | ||
RigidAB = 4, | ||
Pulse = 5, | ||
PulseA = 6, | ||
PulseB = 7, | ||
PulseAB = 8, | ||
VibrateResistance = 9, | ||
VibrateResistanceA = 10, | ||
VibrateResistanceB = 11, | ||
VibrateResistanceAB = 12, | ||
VibratePulse = 13, | ||
VibratePulseA = 14, | ||
VibratePulsB = 15, | ||
VibratePulseAB = 16 | ||
} | ||
|
||
-- Trigger Enum | ||
Triggers.Trigger = { | ||
Invalid = 0, | ||
Left = 1, | ||
Right = 2 | ||
} | ||
|
||
-- InstructionType Enum | ||
Triggers.InstructionType = { | ||
Invalid = 0, | ||
TriggerUpdate = 1, | ||
RGBUpdate = 2, | ||
PlayerLED = 3, | ||
TriggerThreshold = 4 | ||
} | ||
|
||
-- This is the representation of your enums in Lua tables | ||
return Triggers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
load("dsxAdvancedHaptic") | ||
registerCoreModule("dsxAdvancedHaptic") |