1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

Code cleanup: improve webgl.js

This commit is contained in:
kkapsner 2019-12-29 00:45:20 +01:00
parent abdb95b815
commit e3182b562b

View File

@ -115,7 +115,7 @@
randomSupply = supply; randomSupply = supply;
}; };
function getNumber(originalValue, max, index, window){ function getNumber({originalValue, max, index, window}){
const bitLength = Math.floor(Math.log2(max) + 1); const bitLength = Math.floor(Math.log2(max) + 1);
const rng = randomSupply.getBitRng(bitLength, window); const rng = randomSupply.getBitRng(bitLength, window);
let value = 0; let value = 0;
@ -127,6 +127,10 @@
} }
const parameterFakeTypes = { const parameterFakeTypes = {
preference: function(originalValue, definition, window, prefs){
const settingValue = prefs(definition.preferenceName) || originalValue;
return settingValue;
},
decimal: function(originalValue, definition, window){ decimal: function(originalValue, definition, window){
const int = Math.floor(originalValue); const int = Math.floor(originalValue);
if (int !== originalValue){ if (int !== originalValue){
@ -140,11 +144,11 @@
} }
}, },
shift: function(originalValue, definition, window){ shift: function(originalValue, definition, window){
const value = getNumber(originalValue, definition.max, definition.pname, window); const value = getNumber({originalValue, max: definition.max, index: definition.pname, window});
return originalValue >>> value; return originalValue >>> value;
}, },
"-": function(originalValue, definition, window){ "-": function(originalValue, definition, window){
const value = getNumber(originalValue, definition.max, definition.pname, window) * const value = getNumber({originalValue, max: definition.max, index: definition.pname, window}) *
(definition.factor || 1); (definition.factor || 1);
if (value > originalValue){ if (value > originalValue){
return 0; return 0;
@ -187,35 +191,26 @@
36349: {name: "MAX_FRAGMENT_UNIFORM_VECTORS", type: "shift", max: 1}, 36349: {name: "MAX_FRAGMENT_UNIFORM_VECTORS", type: "shift", max: 1},
37154: {name: "MAX_VERTEX_OUTPUT_COMPONENTS", type: "shift", max: 1}, 37154: {name: "MAX_VERTEX_OUTPUT_COMPONENTS", type: "shift", max: 1},
37157: {name: "MAX_FRAGMENT_INPUT_COMPONENTS", type: "shift", max: 1}, 37157: {name: "MAX_FRAGMENT_INPUT_COMPONENTS", type: "shift", max: 1},
7936: {name: "VENDOR", fake: function(originalValue, window, prefs){ 7936: {name: "VENDOR", type: "preference", preferenceName: "webGLVendor"},
const settingValue = prefs("webGLVendor") || originalValue; 7937: {name: "RENDERER", type: "preference", preferenceName: "webGLRenderer"},
return {value: settingValue, faked: settingValue === originalValue}; 37445: {name: "UNMASKED_VENDOR_WEBGL", type: "preference", preferenceName: "webGLUnmaskedVendor"},
}}, 37446: {name: "UNMASKED_RENDERER_WEBGL", type: "preference", preferenceName: "webGLUnmaskedRenderer"}
7937: {name: "RENDERER", fake: function(originalValue, window, prefs){
const settingValue = prefs("webGLRenderer") || originalValue;
return {value: settingValue, faked: settingValue === originalValue};
}},
37445: {name: "UNMASKED_VENDOR_WEBGL", fake: function(originalValue, window, prefs){
const settingValue = prefs("webGLUnmaskedVendor") || originalValue;
return {value: settingValue, faked: settingValue === originalValue};
}},
37446: {name: "UNMASKED_RENDERER_WEBGL", fake: function(originalValue, window, prefs){
const settingValue = prefs("webGLUnmaskedRenderer") || originalValue;
return {value: settingValue, faked: settingValue === originalValue};
}}
}; };
scope.initializeParameterDefinitions = function(){ scope.initializeParameterDefinitions = function(){
Object.keys(parameterChangeDefinition).forEach(function(parameterName){ function singleFake(originalValue, window, prefs){
const definition = parameterChangeDefinition[parameterName]; let value = parameterFakeTypes[this.type](originalValue, this, window, prefs);
definition.pname = parameterName; let faked = value === originalValue;
if (!definition.fake){ this.fake = function(){
definition.fake = definition.isArray? return {value, faked};
function fake(originalValue, window){ };
return {value, faked};
}
function arrayFake(originalValue, window, prefs){
let faked = false; let faked = false;
let fakedValue = []; let fakedValue = [];
for (let i = 0; i < originalValue.length; i += 1){ for (let i = 0; i < originalValue.length; i += 1){
fakedValue[i] = parameterFakeTypes[this.type](originalValue[i], this, window); fakedValue[i] = parameterFakeTypes[this.type](originalValue[i], this, window, prefs);
faked |= originalValue[i] === fakedValue[i]; faked |= originalValue[i] === fakedValue[i];
originalValue[i] = fakedValue[i]; originalValue[i] = fakedValue[i];
} }
@ -234,15 +229,12 @@
value: originalValue, value: originalValue,
faked faked
}; };
}: }
function fake(originalValue, window){ Object.keys(parameterChangeDefinition).forEach(function(parameterName){
let value = parameterFakeTypes[this.type](originalValue, this, window); const definition = parameterChangeDefinition[parameterName];
let faked = value === originalValue; definition.pname = parameterName;
this.fake = function(){ if (!definition.fake){
return {value, faked}; definition.fake = definition.isArray? arrayFake: singleFake;
};
return {value, faked};
};
} }
}); });
}; };