-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from PlayeRom/master
- Code review. - Optimization: reduce the number of listener calls to the minimum necessary - Remove startup flag for fdm-initialized listener because `undefined symbol: fdmInitListener` - Use _setlistener because removelistener doesn't work well with setlistener
- Loading branch information
Showing
8 changed files
with
248 additions
and
97 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
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 @@ | ||
<?xml version="1.0"?> | ||
|
||
<PropertyList> | ||
<addons> | ||
<by-id> | ||
<org.flightgear.addons.landing-rate> | ||
<addon-devel> | ||
<sharemp>0</sharemp> <!-- share and send mp message when land? 1: yes 0: no --> | ||
</addon-devel> | ||
</org.flightgear.addons.landing-rate> | ||
</by-id> | ||
</addons> | ||
</PropertyList> |
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,155 @@ | ||
var LOG_ALERT = 5; | ||
var COLOR_WHITE = { r: 1, g: 1, b: 1 }; | ||
var COLOR_RED = { r: 1, g: 0, b: 0 }; | ||
var COLOR_ORANGE = { r: 1, g: .65, b: 0 }; | ||
var COLOR_YELLOW = { r: 1, g: .95, b: 0 }; | ||
var COLOR_LIME = { r: .64, g: 1, b: 0 }; | ||
var COLOR_GREEN = { r: 0, g: 1, b: 0 }; | ||
|
||
var LANDING_RANK = [ | ||
{ | ||
name : "Bad", | ||
minFpm : 600, | ||
color : COLOR_RED, | ||
}, | ||
{ | ||
name : "Acceptable", | ||
minFpm : 400, | ||
color : COLOR_ORANGE, | ||
}, | ||
{ | ||
name : "Good", | ||
minFpm : 200, | ||
color : COLOR_YELLOW, | ||
}, | ||
{ | ||
name : "Very Good", | ||
minFpm : 100, | ||
color : COLOR_LIME, | ||
}, | ||
{ | ||
name : "Excellent", | ||
minFpm : 0, | ||
color : COLOR_GREEN, | ||
}, | ||
]; | ||
|
||
var window = screen.window.new(10, 10, 3, 10); # create new window object, x = 10, y = 10, maxlines = 3, autoscroll = 10 | ||
window.bg = [0, 0, 0, .5]; # black alpha .5 background | ||
var aglFt = 20; # agl trigger temporary 20. | ||
|
||
var initLandingRateTimer = func (addon) { | ||
var addonNodePath = addon.node.getPath(); | ||
|
||
var landingRateProps = [ # addon props array | ||
addonNodePath ~ "/addon-devel/rate-fpm", | ||
addonNodePath ~ "/addon-devel/rate-mts", | ||
addonNodePath ~ "/addon-devel/g-force", | ||
addonNodePath ~ "/addon-devel/landed", | ||
addonNodePath ~ "/addon-devel/altTrig", | ||
]; | ||
|
||
# init addon props array | ||
foreach (var prop; landingRateProps) { | ||
props.globals.initNode(prop, 0, nil); | ||
} | ||
|
||
var gearProps = [ # gear props array | ||
"/gear/gear[0]/wow", | ||
"/gear/gear[1]/wow", | ||
"/gear/gear[2]/wow", | ||
]; | ||
|
||
# set gear props listeners | ||
foreach (var prop; gearProps) { | ||
setlistener(prop, func (node) { | ||
var isLanded = node.getBoolValue() and !getprop(addonNodePath ~ "/addon-devel/landed"); | ||
setprop(addonNodePath ~ "/addon-devel/landed", isLanded); | ||
}, 0, 0); # startup = 0 (default), runtime = 0 (only when value change) | ||
} | ||
|
||
# setting up altTrigg timer | ||
var altTrigger = maketimer(1, func { | ||
if (getprop("/position/altitude-agl-ft") > aglFt) { | ||
setprop(addonNodePath ~ "/addon-devel/altTrig", 1); | ||
} | ||
}); | ||
altTrigger.start(); # starting alt trigg list | ||
|
||
# setting up message listener, send message when land | ||
setlistener(addonNodePath ~ "/addon-devel/landed", func (node) { | ||
if (node.getValue() and getprop(addonNodePath ~ "/addon-devel/altTrig")) { | ||
setprop(addonNodePath ~ "/addon-devel/altTrig", 0); | ||
|
||
sendLandingMessage( | ||
addon, | ||
getprop("/accelerations/pilot-gdamped"), | ||
getprop("/instrumentation/vertical-speed-indicator/indicated-speed-fpm"), | ||
getprop("/instrumentation/vertical-speed-indicator/indicated-speed-mps") | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
var sendLandingMessage = func (addon, g, fpm, mps) { | ||
var fpmAbsolute = math.abs(fpm); # get fpm with no minus sign | ||
|
||
# send message by landing rate, using LANDING_RANK table | ||
foreach (var rank; LANDING_RANK) { | ||
if (fpmAbsolute >= rank.minFpm) { | ||
printScreenMsg( | ||
addon, | ||
sprintf("%s Landing! Fpm: %.3f Mps: %.3f G-Force: %.1f", rank.name, fpm, mps, g), | ||
rank.color | ||
); | ||
|
||
break; | ||
} | ||
} | ||
}; | ||
|
||
var printScreenMsg = func (addon, msg, color) { | ||
window.write(msg, color.r, color.g, color.b); # print message with color arg. | ||
logprint(LOG_ALERT, "Last Land: ", msg); # print message in case user need it later | ||
|
||
# send mp message if allowed | ||
if (getprop(addon.node.getPath() ~ "/addon-devel/sharemp")) { | ||
setprop("/sim/multiplay/chat", "My landing rate was: " ~ msg); | ||
} | ||
}; | ||
|
||
var printPersistentScreenMsg = func (msg, color, time) { | ||
window.autoscroll = time; # setting message to be show for "time"" seconds | ||
window.write(msg, color.r, color.g, color.b); # print message with color arg. | ||
}; | ||
|
||
var checkCompatibility = func { | ||
# checking nil props | ||
if (getprop("/accelerations/pilot-gdamped") == nil or | ||
getprop("/instrumentation/vertical-speed-indicator/indicated-speed-fpm") == nil or | ||
getprop("/instrumentation/vertical-speed-indicator/indicated-speed-mps") == nil | ||
) { | ||
# prints persistent message, white, 30 sec | ||
printPersistentScreenMsg("Aircraft not compatible with Landing Rate addon. Sorry about that.", COLOR_WHITE, 30); | ||
|
||
# die addon, quit script with custom message. | ||
die("Landing Rate addon shutdown. Aircraft not compatible with Landing Rate addon. Sorry about that."); | ||
} | ||
|
||
printPersistentScreenMsg("Landing Rate Addon Loaded", COLOR_WHITE, 20); # success | ||
logprint(LOG_ALERT, "Landing Rate addon loaded."); # success | ||
}; | ||
|
||
var main = func (addon) { | ||
# Must be _setlistener because removelistener doesn't work well with setlistener | ||
var fdmInitListener = _setlistener("/sim/signals/fdm-initialized", func { | ||
if (getprop("/sim/signals/fdm-initialized")) { | ||
# checking compatibility, set agl trigger by current agl. | ||
checkCompatibility(); | ||
aglFt = getprop("/position/altitude-agl-ft") + 6; | ||
|
||
initLandingRateTimer(addon); # init addon | ||
removelistener(fdmInitListener); | ||
} | ||
}); | ||
}; |
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,75 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<PropertyList> | ||
<meta> | ||
<file-type type="string">FlightGear add-on metadata</file-type> | ||
<format-version type="int">1</format-version> | ||
</meta> | ||
|
||
<addon> | ||
<identifier type="string">org.flightgear.addons.landing-rate</identifier> | ||
<name type="string">Landing Rate</name> | ||
<version type="string">1.0.0</version> | ||
|
||
<authors> | ||
<author> | ||
<name type="string">BR-RVD</name> | ||
</author> | ||
</authors> | ||
|
||
<min-FG-version type="string">2018.1.0</min-FG-version> | ||
<max-FG-version type="string">none</max-FG-version> | ||
|
||
<short-description type="string">Show your landing stats</short-description> | ||
<long-description type="string"> | ||
This add-on, after landing, shows the rate of how softly you landed. | ||
</long-description> | ||
|
||
<localized> | ||
<pl> | ||
<short-description type="string"> | ||
Pokaż statystyki lądowania | ||
</short-description> | ||
|
||
<long-description type="string"> | ||
Ten dodatek po wylądowaniu pokazuje statystyki, jak miękko wylądowałeś. | ||
</long-description> | ||
</pl> | ||
</localized> | ||
|
||
<license> | ||
<designation type="string">GNU GPL version 3 or later</designation> | ||
|
||
<file type="string"> | ||
<!-- Use a relative, slash-separated path to a file under the add-on | ||
base directory that contains the add-on license text. --> | ||
LICENSE | ||
</file> | ||
|
||
<url type="string">https://www.gnu.org/licenses/gpl-3.0.html</url> | ||
</license> | ||
|
||
<urls> | ||
<home-page type="string"> | ||
https://github.com/RenanMsV/landing_rate | ||
</home-page> | ||
|
||
<download type="string"> | ||
https://github.com/RenanMsV/landing_rate | ||
</download> | ||
|
||
<support type="string"> | ||
https://github.com/RenanMsV/landing_rate | ||
</support> | ||
|
||
<code-repository type="string"> | ||
https://github.com/RenanMsV/landing_rate | ||
</code-repository> | ||
</urls> | ||
|
||
<tags> | ||
<tag type="string">landing</tag> | ||
<tag type="string">rate</tag> | ||
<tag type="string">stats</tag> | ||
</tags> | ||
</addon> | ||
</PropertyList> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.