@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
62 lines (57 loc) • 1.88 kB
JavaScript
import { combine_hash } from "../../../../../../core/collection/array/combine_hash.js";
import { computeHashFloat } from "../../../../../../core/primitives/numbers/computeHashFloat.js";
import { computeStringHash } from "../../../../../../core/primitives/strings/computeStringHash.js";
import { ProgramValueSlotParameterType } from "./ProgramValueSlotParameterType.js";
/**
*
* @param {ProgramValueSlotParameterType} type
* @param value
*/
function computeValueHash(type, value) {
switch (type) {
case ProgramValueSlotParameterType.Boolean:
return value ? 0 : 1;
case ProgramValueSlotParameterType.UnsignedInteger:
return value;
case ProgramValueSlotParameterType.Float:
return computeHashFloat(value);
case ProgramValueSlotParameterType.FloatVector2:
case ProgramValueSlotParameterType.FloatVector3:
case ProgramValueSlotParameterType.FloatVector4:
return value.hash();
default:
throw new TypeError(`Unsupported value type '${type}'`);
}
}
export class ProgramValueSlotParameter {
/**
*
* @param {string} name
* @param {ProgramValueSlotParameterType} type
* @param {number|boolean|Vector2|Vector3|Vector4} value
*/
constructor({ name, type, value }) {
/**
*
* @type {string}
*/
this.name = name;
/**
*
* @type {ProgramValueSlotParameterType}
*/
this.type = type;
/**
*
* @type {number|boolean|Vector2|Vector3|Vector4}
*/
this.value = value;
}
hash() {
return combine_hash(
computeStringHash(this.name),
this.type,
computeValueHash(this.type, this.value)
);
}
}