1
0
Fork 0

MP update function

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2020-12-14 00:59:29 +11:00
parent f0124e6e2a
commit fb145f401d

View file

@ -696,6 +696,87 @@ var canvas_livery = {
# canvas_livery_update
# =============================================================================
# Class for Canvas based liveries
#
var canvas_livery_update = {
init: func(liveriesdir, interval = 10.01, callback = nil, resolution=4096) {
var m = { parents: [canvas_livery_update, overlay_update.new()] };
m.parents[1].add(liveriesdir, "sim/model/livery/file", callback);
m.parents[1].interval = interval;
m.liveriesdir = liveriesdir;
m.resolution = resolution;
m.targets = {};
return m;
},
setResolution: func(resolution) {
},
createTarget: func(name, objects, property, resolution=4096) {
me.targets[name] = {
canvas: nil,
layers: {},
groups: {},
listener: nil,
resolution: resolution,
};
maxRes = getprop("/sim/model/livery/max-resolution");
if (resolution > maxRes) {
resolution = maxRes;
me.targets[name].resolution = maxRes;
}
# Make sure we never load too large textures
maxSupportedRes = getprop("/sim/rendering/max-texture-size");
if (resolution > maxSupportedRes) {
resolution = maxSupportedRes;
me.targets[name].resolution = maxSupportedRes;
}
me.targets[name].canvas = canvas.new({
"name": name,
"size": [resolution, resolution],
"view": [resolution, resolution],
"mipmapping": 1,
# "anisotropy": 1.0
});
foreach (var object; objects) {
me.targets[name].canvas.addPlacement({"node": object});
}
me.targets[name].groups["base"] = me.targets[name].canvas.createGroup("base");
resStr = findTexByRes(me.liveriesdir, getprop(property), resolution);
if (resStr == nil) {
return nil;
}
me.targets[name].layers["base"] = me.targets[name].groups["base"].createChild("image").setFile(me.liveriesdir ~ "/" ~ resStr ~ "/" ~ getprop(property)).setSize(resolution,resolution);
me.targets[name].listener = setlistener(property, func(property) {
resStr = findTexByRes(me.liveriesdir, property.getValue(), resolution);
if (resStr == nil) {
return nil;
}
me.targets[name].groups["base"].removeAllChildren();
me.targets[name].layers["base"] = me.targets[name].groups["base"].createChild("image").setFile(me.liveriesdir ~ "/" ~ resStr ~ "/" ~ property.getValue()).setSize(resolution,resolution);
});
},
addLayer: func(target, name, file) {
me.targets[target].groups[name] = me.targets[target].canvas.createGroup(name);
me.targets[target].layers[name] = me.targets[target].groups[name].createChild("image").setFile(file).setSize(me.targets[target].resolution, me.targets[target].resolution);
},
removeLayer: func(target, name) {
me.targets[target].layers[name].removeAllChildren();
me.targets[target].layers[name] = nil;
},
showLayer: func(target, name) {
me.targets[target].layers[name].show();
},
hideLayer: func(target, name) {
me.targets[target].layers[name].hide();
},
stop: func {
me.parents[1].stop();
},
};
# overlay_update
# =============================================================================
# Class for maintaining overlays in MP aircraft. It is used in Nasal code that's