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:
parent
abdb95b815
commit
e3182b562b
96
lib/webgl.js
96
lib/webgl.js
@ -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,62 +191,50 @@
|
|||||||
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(){
|
||||||
|
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){
|
Object.keys(parameterChangeDefinition).forEach(function(parameterName){
|
||||||
const definition = parameterChangeDefinition[parameterName];
|
const definition = parameterChangeDefinition[parameterName];
|
||||||
definition.pname = parameterName;
|
definition.pname = parameterName;
|
||||||
if (!definition.fake){
|
if (!definition.fake){
|
||||||
definition.fake = definition.isArray?
|
definition.fake = definition.isArray? arrayFake: singleFake;
|
||||||
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};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user