mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Code cleanup: improve webgl.js
This commit is contained in:
parent
abdb95b815
commit
e3182b562b
96
lib/webgl.js
96
lib/webgl.js
@ -115,7 +115,7 @@
|
||||
randomSupply = supply;
|
||||
};
|
||||
|
||||
function getNumber(originalValue, max, index, window){
|
||||
function getNumber({originalValue, max, index, window}){
|
||||
const bitLength = Math.floor(Math.log2(max) + 1);
|
||||
const rng = randomSupply.getBitRng(bitLength, window);
|
||||
let value = 0;
|
||||
@ -127,6 +127,10 @@
|
||||
}
|
||||
|
||||
const parameterFakeTypes = {
|
||||
preference: function(originalValue, definition, window, prefs){
|
||||
const settingValue = prefs(definition.preferenceName) || originalValue;
|
||||
return settingValue;
|
||||
},
|
||||
decimal: function(originalValue, definition, window){
|
||||
const int = Math.floor(originalValue);
|
||||
if (int !== originalValue){
|
||||
@ -140,11 +144,11 @@
|
||||
}
|
||||
},
|
||||
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;
|
||||
},
|
||||
"-": 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);
|
||||
if (value > originalValue){
|
||||
return 0;
|
||||
@ -187,62 +191,50 @@
|
||||
36349: {name: "MAX_FRAGMENT_UNIFORM_VECTORS", type: "shift", max: 1},
|
||||
37154: {name: "MAX_VERTEX_OUTPUT_COMPONENTS", type: "shift", max: 1},
|
||||
37157: {name: "MAX_FRAGMENT_INPUT_COMPONENTS", type: "shift", max: 1},
|
||||
7936: {name: "VENDOR", fake: function(originalValue, window, prefs){
|
||||
const settingValue = prefs("webGLVendor") || originalValue;
|
||||
return {value: settingValue, faked: settingValue === originalValue};
|
||||
}},
|
||||
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};
|
||||
}}
|
||||
7936: {name: "VENDOR", type: "preference", preferenceName: "webGLVendor"},
|
||||
7937: {name: "RENDERER", type: "preference", preferenceName: "webGLRenderer"},
|
||||
37445: {name: "UNMASKED_VENDOR_WEBGL", type: "preference", preferenceName: "webGLUnmaskedVendor"},
|
||||
37446: {name: "UNMASKED_RENDERER_WEBGL", type: "preference", preferenceName: "webGLUnmaskedRenderer"}
|
||||
};
|
||||
|
||||
scope.initializeParameterDefinitions = function(){
|
||||
function singleFake(originalValue, window, prefs){
|
||||
let value = parameterFakeTypes[this.type](originalValue, this, window, prefs);
|
||||
let faked = value === originalValue;
|
||||
this.fake = function(){
|
||||
return {value, faked};
|
||||
};
|
||||
return {value, faked};
|
||||
}
|
||||
function arrayFake(originalValue, window, prefs){
|
||||
let faked = false;
|
||||
let fakedValue = [];
|
||||
for (let i = 0; i < originalValue.length; i += 1){
|
||||
fakedValue[i] = parameterFakeTypes[this.type](originalValue[i], this, window, prefs);
|
||||
faked |= originalValue[i] === fakedValue[i];
|
||||
originalValue[i] = fakedValue[i];
|
||||
}
|
||||
this.fake = function(originalValue){
|
||||
if (faked){
|
||||
for (let i = 0; i < originalValue.length; i += 1){
|
||||
originalValue[i] = fakedValue[i];
|
||||
}
|
||||
}
|
||||
return {
|
||||
value: originalValue,
|
||||
faked
|
||||
};
|
||||
};
|
||||
return {
|
||||
value: originalValue,
|
||||
faked
|
||||
};
|
||||
}
|
||||
Object.keys(parameterChangeDefinition).forEach(function(parameterName){
|
||||
const definition = parameterChangeDefinition[parameterName];
|
||||
definition.pname = parameterName;
|
||||
if (!definition.fake){
|
||||
definition.fake = definition.isArray?
|
||||
function fake(originalValue, window){
|
||||
let faked = false;
|
||||
let fakedValue = [];
|
||||
for (let i = 0; i < originalValue.length; i += 1){
|
||||
fakedValue[i] = parameterFakeTypes[this.type](originalValue[i], this, window);
|
||||
faked |= originalValue[i] === fakedValue[i];
|
||||
originalValue[i] = fakedValue[i];
|
||||
}
|
||||
this.fake = function(originalValue){
|
||||
if (faked){
|
||||
for (let i = 0; i < originalValue.length; i += 1){
|
||||
originalValue[i] = fakedValue[i];
|
||||
}
|
||||
}
|
||||
return {
|
||||
value: originalValue,
|
||||
faked
|
||||
};
|
||||
};
|
||||
return {
|
||||
value: originalValue,
|
||||
faked
|
||||
};
|
||||
}:
|
||||
function fake(originalValue, window){
|
||||
let value = parameterFakeTypes[this.type](originalValue, this, window);
|
||||
let faked = value === originalValue;
|
||||
this.fake = function(){
|
||||
return {value, faked};
|
||||
};
|
||||
return {value, faked};
|
||||
};
|
||||
definition.fake = definition.isArray? arrayFake: singleFake;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user