diff --git a/Nasal/lag_adjust.nas b/Nasal/lag_adjust.nas new file mode 100644 index 000000000..5bac505fa --- /dev/null +++ b/Nasal/lag_adjust.nas @@ -0,0 +1,89 @@ +var i = 0; +var net_raw = "false"; +var spectator = "false"; +var spectator_offset = 0.5; +var range = 3.0; +var offset = 0.0; +var apply_close = "false"; +var master = 0; +var close = 0; + +var mpCheck = func() { + var mpname = getprop("/ai/models/multiplayer["~i~"]/callsign"); + if (mpname != nil) { + if (spectator) { + setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 3); + setprop("/ai/models/multiplayer["~i~"]/controls/player-lag", -spectator_offset); + } else { + var server = getprop("/sim/multiplay/txhost"); + var lag = offset + } if (apply_close) { + var self = geo.aircraft_position(); + var x = getprop("/ai/models/multiplayer["~i~"]/position/global-x"); + var y = getprop("/ai/models/multiplayer["~i~"]/position/global-y"); + var z = getprop("/ai/models/multiplayer["~i~"]/position/global-z"); + var ac = geo.Coord.new().set_xyz(x, y, z); + var distance = self.distance_to(ac)*M2NM; + if ((distance > range)or(distance==nil)) { + setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 1); + } else { + setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 2); + setprop("/ai/models/multiplayer["~i~"]/controls/player-lag", lag); + }; + } else { + setprop("/ai/models/multiplayer["~i~"]/controls/compensate-lag", 1); + } + i += 1; + } else { + i = 0; + if (close) close = 0; + } + if ((master) or (close)) { + settimer(mpCheck, 1); + } +} + +var mpInit = func() { + print("initialising the mp lag system"); + var ls_spect = setlistener("/sim/multiplay/lag/spectator",func { spectator = getprop("/sim/multiplay/lag/spectator")}, 1); + var ls_spctoffset = setlistener("/sim/multiplay/lag/spectator-offset",func { spectator_offset = getprop("/sim/multiplay/lag/spectator-offset")}, 1); + var ls_range = setlistener("/sim/multiplay/lag/range",func { range = getprop("/sim/multiplay/lag/range")}, 1); + var ls_wingmen = setlistener("/sim/multiplay/lag/apply-to-wingmen",func { apply_to_wingmen = getprop("/sim/multiplay/lag/apply-to-wingmen")}, 1); + var ls_offset = setlistener("/sim/multiplay/lag/offset",func { offset = getprop("/sim/multiplay/lag/offset")}, 1); + var ls_close = setlistener("/sim/multiplay/lag/apply-close", func { apply_close = getprop("/sim/multiplay/lag/apply-close")}, 1); +} + +var mpClean = func() { + i = 0; + spectator = 0; + spectator_offset = 0.5; + range = 3.0; + apply_to_wingmen = 0; + apply_close = 0; + offset = 0.0; + close = 1; + master = 0; +} + +var mpStart = func() { + var test = getprop("/sim/multiplay/lag/master"); + if (test == nil) { + settimer(mpStart, 2); + } else { + mpInit(); + setlistener("/sim/multiplay/lag/master", masterSwitch,1); + } +} + +var masterSwitch = func() { + master = getprop("/sim/multiplay/lag/master"); + if (master) { + mpInit(); + mpCheck(); + } else { + mpClean(); + } +} + + +_setlistener("/sim/signals/nasal-dir-initialized", mpStart); diff --git a/Translations/en/menu.xml b/Translations/en/menu.xml index 410f56a3e..f5c37d243 100644 --- a/Translations/en/menu.xml +++ b/Translations/en/menu.xml @@ -83,6 +83,7 @@ Chat Menu Pilot List MPCarrier Selection + lag options Debug diff --git a/Translations/fr/menu.xml b/Translations/fr/menu.xml index 6f3cece82..2455d7448 100644 --- a/Translations/fr/menu.xml +++ b/Translations/fr/menu.xml @@ -97,7 +97,7 @@ Menu de clavardage Liste des pilotes Choix du porte-avions multijoueurs - + Correction de lag Débogage + + hbox + 1 + + + + + + 1 + + + + + + + + table + center + + + 0 + 0 + right + + + + 0 + 1 + 2 + left + master + /sim/multiplay/lag/master + + dialog-apply + master + + + + + 1 + 0 + right + + + + 1 + 1 + lag-adjustment + -0.1 + 0.15 + 0.001 + /sim/multiplay/lag/offset + + dialog-apply + lag-adjustment + + + + + 1 + 3 + left + + %.3f s + /sim/multiplay/lag/offset + true + + + + 2 + 0 + + right + + + 2 + 1 + 2 + left + apply-close + /sim/multiplay/lag/apply-close + + dialog-apply + apply-close + + + + 2 + 2 + Range + 1 + 15 + 0.1 + /sim/multiplay/lag/range + + dialog-apply + range + + + + + 2 + 3 + left + + %.1f nm + /sim/multiplay/lag/range + true + + + + 3 + 0 + + right + + + 3 + 1 + 2 + left + spectator + + /sim/multiplay/lag/spectator + + dialog-apply + spectator + + + + 3 + 2 + spectator-offset + 0 + 1 + 0.05 + /sim/multiplay/lag/spectator-offset + + dialog-apply + spectator-offset + + + + + 3 + 3 + left + + %.2f s + /sim/multiplay/lag/spectator-offset + true + + + + diff --git a/gui/menubar.xml b/gui/menubar.xml index 7589a3a2d..4a9fa63cf 100644 --- a/gui/menubar.xml +++ b/gui/menubar.xml @@ -547,6 +547,13 @@ + + lag-adjust + + dialog-show + lag-adjust + + diff --git a/preferences.xml b/preferences.xml index 5d9e60ecb..b5c5ca1be 100644 --- a/preferences.xml +++ b/preferences.xml @@ -772,6 +772,14 @@ Started September 2000 by David Megginson, david@megginson.com callsign + + 3.0 + 0 + 0 + 0 + 0 + 0 + Golf Foxtrot Sierra