daytime.nas
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[Nasal スクリプト集]]
* 概要 [#pf776953]
daytime.nas はスピードアップ状態 (a/A キーを押して1〜n倍...
* インストール方法 [#zd32fd28]
添付ファイルをダウンロードして、 ~/.fgfs/Nasal/daytime.na...
* 処理概要 [#t8297fd7]
settimer で 1 秒毎に Daytime.schedule を呼び出しています...
* ソース [#u781142e]
このソースは参考迄に表示しています。ダウンロードは下の添...
########################################################...
# daytime.nas by Tatsuhiro Nishioka
# - Clock that considers "warp" in FlightGear world, ext...
# some modification
# Copyright (C) 2008 Tatsuhiro Nishioka (tat dot fgmacos...
# This file is licensed under the GPL license version 2 ...
# $Id: air-racing.nas,v 1.2 2008/04/08 00:16:00 tat Exp $
#
########################################################...
var constant = {
HOURTOMINUTE : 60,
HOURTOSECOND : 3600,
MINUTETOSECOND : 60,
};
# ======
# SYSTEM
# ======
# for inheritance, the system must be the last of parents.
var System = {};
# not called by child classes !!!
System.new = func {
obj = { parents : [System],
SYSSEC : 0.0, #...
RELOCATIONFT : 0.0, #...
altseaft : 0.0,
noinstrument : {},
slave : {}
};
return obj;
};
System.init_ancestor = func( path ) {
obj = System.new();
me.SYSSEC = obj.SYSSEC;
me.RELOCATIONFT = obj.RELOCATIONFT;
me.altseaft = obj.altseaft;
me.noinstrument = obj.noinstrument;
me.slave = obj.slave;
me.loadtree( path ~ "/slave" );
me.loadprop( path ~ "/noinstrument" );
}
System.set_rate_ancestor = func( rates ) {
me.SYSSEC = rates;
me.RELOCATIONFT = constantaero.MAXFPM / ( constant.MI...
}
# property access is faster through its node, than parsi...
System.loadtree = func( path ) {
if( props.globals.getNode(path) != nil ) {
children = props.globals.getNode(path).getChildre...
foreach( c; children ) {
name = c.getName();
subchildren = c.getChildren();
# <slave>
# <engine>
# <component>/engines</component>
# <subcomponent>engine</subcomponent>
# </engine>
if( size(subchildren) > 0 ) {
component = c.getChild("component").getVal...
subcomponent = c.getChild("subcomponent")....
me.slave[name] = props.globals.getNode(com...
}
# <altimeter>/instrumentation/altimeter[0]</a...
# </slave>
else {
value = c.getValue();
me.slave[name] = props.globals.getNode(val...
}
}
}
}
System.loadprop = func( path ) {
if( props.globals.getNode(path) != nil ) {
children = props.globals.getNode(path).getChildre...
foreach( c; children ) {
name = c.getName();
subchildren = c.getChildren();
# <noinstrument>
# <cloud>
# <component>/environment/clouds</component>
# <subcomponent>layer</subcomponent>
# </cloud>
if( size(subchildren) > 0 ) {
component = c.getChild("component").getVal...
subcomponent = c.getChild("subcomponent")....
me.noinstrument[name] = props.globals.getN...
}
# <agl>/position/altitude-agl-ft</agl>
# </noinstrument>
else {
value = c.getValue();
me.noinstrument[name] = props.globals.getN...
}
}
}
}
System.is_moving = func {
# must exist in XML
aglft = me.noinstrument["agl"].getValue();
speedkt = me.noinstrument["airspeed"].getValue();
if( aglft >= constantaero.AGLTOUCHFT or speedkt >= c...
result = constant.TRUE;
}
else {
result = constant.FALSE;
}
return result;
}
System.is_relocating = func {
# must exist in XML
altft = me.noinstrument["altitude"].getValue();
# relocation in flight, or at another airport
variationftpm = altft - me.altseaft;
if( variationftpm < - me.RELOCATIONFT or variationftp...
result = constant.TRUE;
}
else {
result = constant.FALSE;
}
me.altseaft = altft;
return result;
}
#
# Daytime considering wrap
#
# =============
# SPEED UP TIME
# =============
var Daytime = {};
Daytime.new = func {
obj = { parents : [Daytime, System],
thesim : nil,
warpnode : nil,
SPEEDUPSEC : 1.0,
CLIMBFTPMIN : 3500, ...
MAXSTEPFT : 0.0, ...
lastft : 0.0
};
obj.init();
return obj;
}
Daytime.init = func {
climbftpsec = me.CLIMBFTPMIN / constant.MINUTETOSECO...
me.MAXSTEPFT = climbftpsec * me.SPEEDUPSEC;
me.thesim = props.globals.getNode("/sim");
me.warpnode = props.globals.getNode("/sim/time/warp");
me.init_ancestor("/instrumentation/clock");
}
Daytime.schedule = func {
# altitudeft = me.noinstrument["altitude"].getValue();
altitudeft = getprop("/position/altitude-ft");
speedup = me.thesim.getChild("speed-up").getValue();
if( speedup > 1 ) {
# accelerate day time
multiplier = speedup - 1;
offsetsec = me.SPEEDUPSEC * multiplier;
warp = me.warpnode.getValue() + offsetsec;
me.warpnode.setValue(warp);
# safety
stepft = me.MAXSTEPFT * speedup;
maxft = me.lastft + stepft;
minft = me.lastft - stepft;
# too fast
if( altitudeft > maxft or altitudeft < minft ) {
me.thesim.getChild("speed-up").setValue(1);
}
}
me.lastft = altitudeft;
}
var daytime = nil;
# called every second
var cron_1sec = func {
daytime.schedule();
settimer( func { cron_1sec(); }, 1);
}
# start the cron loop when FDM is initialized
_setlistener("/sim/signals/fdm-initialized", func {
if (getprop("/sim/aircraft") != "Concorde") {
daytime = Daytime.new();
cron_1sec();
}
});
終了行:
[[Nasal スクリプト集]]
* 概要 [#pf776953]
daytime.nas はスピードアップ状態 (a/A キーを押して1〜n倍...
* インストール方法 [#zd32fd28]
添付ファイルをダウンロードして、 ~/.fgfs/Nasal/daytime.na...
* 処理概要 [#t8297fd7]
settimer で 1 秒毎に Daytime.schedule を呼び出しています...
* ソース [#u781142e]
このソースは参考迄に表示しています。ダウンロードは下の添...
########################################################...
# daytime.nas by Tatsuhiro Nishioka
# - Clock that considers "warp" in FlightGear world, ext...
# some modification
# Copyright (C) 2008 Tatsuhiro Nishioka (tat dot fgmacos...
# This file is licensed under the GPL license version 2 ...
# $Id: air-racing.nas,v 1.2 2008/04/08 00:16:00 tat Exp $
#
########################################################...
var constant = {
HOURTOMINUTE : 60,
HOURTOSECOND : 3600,
MINUTETOSECOND : 60,
};
# ======
# SYSTEM
# ======
# for inheritance, the system must be the last of parents.
var System = {};
# not called by child classes !!!
System.new = func {
obj = { parents : [System],
SYSSEC : 0.0, #...
RELOCATIONFT : 0.0, #...
altseaft : 0.0,
noinstrument : {},
slave : {}
};
return obj;
};
System.init_ancestor = func( path ) {
obj = System.new();
me.SYSSEC = obj.SYSSEC;
me.RELOCATIONFT = obj.RELOCATIONFT;
me.altseaft = obj.altseaft;
me.noinstrument = obj.noinstrument;
me.slave = obj.slave;
me.loadtree( path ~ "/slave" );
me.loadprop( path ~ "/noinstrument" );
}
System.set_rate_ancestor = func( rates ) {
me.SYSSEC = rates;
me.RELOCATIONFT = constantaero.MAXFPM / ( constant.MI...
}
# property access is faster through its node, than parsi...
System.loadtree = func( path ) {
if( props.globals.getNode(path) != nil ) {
children = props.globals.getNode(path).getChildre...
foreach( c; children ) {
name = c.getName();
subchildren = c.getChildren();
# <slave>
# <engine>
# <component>/engines</component>
# <subcomponent>engine</subcomponent>
# </engine>
if( size(subchildren) > 0 ) {
component = c.getChild("component").getVal...
subcomponent = c.getChild("subcomponent")....
me.slave[name] = props.globals.getNode(com...
}
# <altimeter>/instrumentation/altimeter[0]</a...
# </slave>
else {
value = c.getValue();
me.slave[name] = props.globals.getNode(val...
}
}
}
}
System.loadprop = func( path ) {
if( props.globals.getNode(path) != nil ) {
children = props.globals.getNode(path).getChildre...
foreach( c; children ) {
name = c.getName();
subchildren = c.getChildren();
# <noinstrument>
# <cloud>
# <component>/environment/clouds</component>
# <subcomponent>layer</subcomponent>
# </cloud>
if( size(subchildren) > 0 ) {
component = c.getChild("component").getVal...
subcomponent = c.getChild("subcomponent")....
me.noinstrument[name] = props.globals.getN...
}
# <agl>/position/altitude-agl-ft</agl>
# </noinstrument>
else {
value = c.getValue();
me.noinstrument[name] = props.globals.getN...
}
}
}
}
System.is_moving = func {
# must exist in XML
aglft = me.noinstrument["agl"].getValue();
speedkt = me.noinstrument["airspeed"].getValue();
if( aglft >= constantaero.AGLTOUCHFT or speedkt >= c...
result = constant.TRUE;
}
else {
result = constant.FALSE;
}
return result;
}
System.is_relocating = func {
# must exist in XML
altft = me.noinstrument["altitude"].getValue();
# relocation in flight, or at another airport
variationftpm = altft - me.altseaft;
if( variationftpm < - me.RELOCATIONFT or variationftp...
result = constant.TRUE;
}
else {
result = constant.FALSE;
}
me.altseaft = altft;
return result;
}
#
# Daytime considering wrap
#
# =============
# SPEED UP TIME
# =============
var Daytime = {};
Daytime.new = func {
obj = { parents : [Daytime, System],
thesim : nil,
warpnode : nil,
SPEEDUPSEC : 1.0,
CLIMBFTPMIN : 3500, ...
MAXSTEPFT : 0.0, ...
lastft : 0.0
};
obj.init();
return obj;
}
Daytime.init = func {
climbftpsec = me.CLIMBFTPMIN / constant.MINUTETOSECO...
me.MAXSTEPFT = climbftpsec * me.SPEEDUPSEC;
me.thesim = props.globals.getNode("/sim");
me.warpnode = props.globals.getNode("/sim/time/warp");
me.init_ancestor("/instrumentation/clock");
}
Daytime.schedule = func {
# altitudeft = me.noinstrument["altitude"].getValue();
altitudeft = getprop("/position/altitude-ft");
speedup = me.thesim.getChild("speed-up").getValue();
if( speedup > 1 ) {
# accelerate day time
multiplier = speedup - 1;
offsetsec = me.SPEEDUPSEC * multiplier;
warp = me.warpnode.getValue() + offsetsec;
me.warpnode.setValue(warp);
# safety
stepft = me.MAXSTEPFT * speedup;
maxft = me.lastft + stepft;
minft = me.lastft - stepft;
# too fast
if( altitudeft > maxft or altitudeft < minft ) {
me.thesim.getChild("speed-up").setValue(1);
}
}
me.lastft = altitudeft;
}
var daytime = nil;
# called every second
var cron_1sec = func {
daytime.schedule();
settimer( func { cron_1sec(); }, 1);
}
# start the cron loop when FDM is initialized
_setlistener("/sim/signals/fdm-initialized", func {
if (getprop("/sim/aircraft") != "Concorde") {
daytime = Daytime.new();
cron_1sec();
}
});
ページ名: