/Libraries/JSIL.XNA.Core.js
JavaScript | 2048 lines | 1678 code | 343 blank | 27 comment | 140 complexity | eb80c9f3abd6e822017a5f1f4cb3a7a3 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
Large files files are truncated, but you can click here to view the full file
- "use strict";
- if (typeof (JSIL) === "undefined") throw new Error("JSIL.Core required");
- var $drawDebugRects = false, $drawDebugBoxes = false;
- var $useTextCaching = true, $textCachingSupported = true;
- var $jsilxna = JSIL.DeclareAssembly("JSIL.XNA");
- $jsilxna.allowWebGL = true;
- $jsilxna.testedWebGL = false;
- $jsilxna.workingWebGL = false;
- var $sig = new JSIL.MethodSignatureCache();
- var $xnaasms = new JSIL.AssemblyCollection({
- corlib: "mscorlib",
- xna: "Microsoft.Xna.Framework",
- xnaGraphics: "Microsoft.Xna.Framework.Graphics",
- xnaGame: "Microsoft.Xna.Framework.Game",
- xnaStorage: "Microsoft.Xna.Framework.Storage",
- 0: "Microsoft.Xna.Framework",
- 1: "Microsoft.Xna.Framework.Game",
- 2: "Microsoft.Xna.Framework.GamerServices",
- 5: "mscorlib",
- 11: "System.Drawing",
- 15: "System.Windows.Forms",
- 18: "Microsoft.Xna.Framework.Xact",
- });
- var getXnaGraphics = function () {
- return $xnaasms.xnaGraphics || $xnaasms.xna;
- };
- var getXnaStorage = function () {
- return $xnaasms.xnaStorage || $xnaasms.xna;
- };
- $jsilxna.colorRef = function () {
- var graphicsAsm = JSIL.GetAssembly("Microsoft.Xna.Framework.Graphics", true);
- if (graphicsAsm !== null)
- return $xnaasms.xna.TypeRef("Microsoft.Xna.Framework.Color");
- else
- return $xnaasms.xna.TypeRef("Microsoft.Xna.Framework.Graphics.Color");
- };
- $jsilxna.graphicsRef = function (name) {
- var graphicsAsm = JSIL.GetAssembly("Microsoft.Xna.Framework.Graphics", true);
- if (graphicsAsm !== null)
- return graphicsAsm.TypeRef(name);
- else
- return $xnaasms.xna.TypeRef(name);
- };
- JSIL.MakeClass($jsilcore.System.Object, "HTML5Asset", true, [], function ($) {
- $.RawMethod(false, ".ctor", function (assetName) {
- this.name = assetName;
- });
- $.RawMethod(false, "toString", function () {
- return "<XNA Asset '" + this.name + "'>";
- });
- });
- JSIL.MakeClass("HTML5Asset", "HTML5ImageAsset", true, [], function ($) {
- $.RawMethod(false, ".ctor", function (assetName, image) {
- HTML5Asset.prototype._ctor.call(this, assetName);
- image.assetName = assetName;
- this.image = image;
- });
-
- $.RawMethod(false, "ReadAsset",
- function HTML5ImageAsset_ReadAsset (type) {
- var tTexture = Microsoft.Xna.Framework.Graphics.Texture2D.__Type__;
- return JSIL.CreateInstanceOfType(tTexture, "$fromImage", [null, this.image]);
- }
- );
- });
- JSIL.MakeClass("HTML5Asset", "SoundAssetBase", true, [], function ($) {
- $.Method({Static:false, Public:true }, "Play",
- (new JSIL.MethodSignature($.Boolean, [], [])),
- function Play () {
- return this.Play(1, 0, 0);
- }
- );
- $.Method({Static:false, Public:true }, "Play",
- (new JSIL.MethodSignature($.Boolean, [$.Single, $.Single, $.Single], [])),
- function Play (volume, pitch, pan) {
- var instance = this.$newInstance();
- instance.volume = volume;
- // FIXME: No pitch or pan
- instance.play();
- return true;
- }
- );
- $.Method({Static:false, Public:true }, "CreateInstance",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Audio.SoundEffectInstance"), [], [])),
- function CreateInstance () {
- return new Microsoft.Xna.Framework.Audio.SoundEffectInstance(this, false);
- }
- );
- });
- JSIL.MakeClass("SoundAssetBase", "CallbackSoundAsset", true, [], function ($) {
- $.RawMethod(false, ".ctor", function (assetName, createInstance) {
- HTML5Asset.prototype._ctor.call(this, assetName);
- this.$createInstance = createInstance;
- this.freeInstances = [];
- });
- $.RawMethod(false, "$newInstance", function () {
- if (this.freeInstances.length > 0) {
- return this.freeInstances.pop();
- } else {
- return this.$createInstance(0);
- }
- });
- });
- JSIL.MakeClass("HTML5Asset", "RawXNBAsset", true, [], function ($) {
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [], []), function (assetName, rawBytes) {
- if (JSIL.GetAssembly("JSIL.IO", true) === null) {
- throw new Error("JSIL.IO is required");
- }
- HTML5Asset.prototype._ctor.call(this, assetName);
- this.bytes = rawBytes;
- this.contentManager = null;
- });
- $.Method({
- Static: false,
- Public: true
- }, "ReadAsset", new JSIL.MethodSignature(null, [], []), function RawXNBAsset_ReadAsset (type) {
- var memoryStream = new System.IO.MemoryStream(this.bytes, false);
- var tContentReader = JSIL.GetTypeFromAssembly(
- $xnaasms.xna, "Microsoft.Xna.Framework.Content.ContentReader", [], true
- );
- var contentReader = $sig.get("newCr").Construct(
- tContentReader, this.contentManager, memoryStream, this.name, null, 0
- );
- contentReader.ReadHeader();
- var sharedResourceCount = contentReader.Read7BitEncodedInt();
- var sharedResources = new Array(sharedResourceCount);
- var mainObject = contentReader.ReadObject$b1(type)();
- for (var i = 0; i < sharedResourceCount; i++)
- sharedResources[i] = content.ReadObject$b1(System.Object)();
- return mainObject;
- });
- });
- JSIL.MakeClass("RawXNBAsset", "SpriteFontAsset", true, [], function ($) {
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [], []), function (assetName, rawBytes) {
- RawXNBAsset.prototype._ctor.call(this, assetName, rawBytes);
- });
- });
- JSIL.MakeClass("RawXNBAsset", "Texture2DAsset", true, [], function ($) {
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [], []), function (assetName, rawBytes) {
- RawXNBAsset.prototype._ctor.call(this, assetName, rawBytes);
- });
- });
- var vectorUtil = {
- makeOperatorCore: function (name, tVector, body, argCount, leftScalar, rightScalar) {
- var js = body.join("\r\n");
- var typeName = String(tVector.typeName);
- var suffixedName;
- if (argCount < 1) {
- suffixedName = name;
- } else {
- suffixedName = name + "[";
- if (argCount == 1) {
- suffixedName += (leftScalar ? "float" : "vec");
- } else if (argCount == 2) {
- suffixedName += (leftScalar ? "float" : "vec") + "," +
- (rightScalar ? "float" : "vec");
- }
- suffixedName += "]";
- }
- var functionName = typeName + "." + suffixedName;
- switch (argCount) {
- case 0:
- return JSIL.CreateNamedFunction(
- functionName,
- [],
- js
- );
- case 1:
- return JSIL.CreateNamedFunction(
- functionName,
- ["value"],
- js
- );
- case 2:
- return JSIL.CreateNamedFunction(
- functionName,
- ["lhs", "rhs"],
- js
- );
- case 3:
- return JSIL.CreateNamedFunction(
- functionName,
- ["lhs", "rhs", "amount"],
- js
- );
- default:
- throw new Error("Invalid argument count");
- }
- },
- bindToPrototype: function (fn, typeRef) {
- var state = {
- resolvedType: null,
- typeRef: typeRef
- };
- JSIL.SetLazyValueProperty(
- state, "create",
- function VectorMethod_GetCreator () {
- if (state.resolvedType === null)
- state.resolvedType = state.typeRef.get();
-
- var create = Object.create;
- var proto = state.resolvedType.prototype;
- return create.bind(Object, proto);
- }
- );
- return fn.bind(state);
- },
- makeArithmeticOperator: function ($, name, staticMethodName, operator, dataMembers, tLeft, tRight, tResult) {
- var leftScalar = (tLeft !== tResult);
- var rightScalar = (tRight !== tResult);
- if (leftScalar && rightScalar)
- throw new Error("Invalid type combination");
- var body = [];
- body.push("var result = this.create();");
- for (var i = 0; i < dataMembers.length; i++) {
- var dataMember = dataMembers[i];
- var line = "result." + dataMember + " = ";
- if (leftScalar)
- line += "lhs ";
- else
- line += "lhs." + dataMember + " ";
- line += operator;
- if (rightScalar)
- line += " rhs;";
- else
- line += " rhs." + dataMember + ";";
- body.push(line);
- }
- body.push("return result;")
- var fn = vectorUtil.makeOperatorCore(name, tResult, body, 2, leftScalar, rightScalar);
- fn = vectorUtil.bindToPrototype(fn, tResult);
- $.Method({Static: true , Public: true }, name,
- new JSIL.MethodSignature(tResult, [tLeft, tRight], []),
- fn
- );
- $.Method({Static: true , Public: true }, staticMethodName,
- new JSIL.MethodSignature(tResult, [tLeft, tRight], []),
- fn
- );
- var makeRef = function (t) {
- return $jsilcore.TypeRef("JSIL.Reference", [t]);
- };
- var wrapper;
- if (leftScalar) {
- wrapper = function VectorOperator_Scalar_Ref (lhs, rhs, result) {
- result.value = fn(lhs, rhs.value);
- }
- } else if (rightScalar) {
- wrapper = function VectorOperator_Ref_Scalar (lhs, rhs, result) {
- result.value = fn(lhs.value, rhs);
- }
- } else {
- wrapper = function VectorOperator_Ref_Ref (lhs, rhs, result) {
- result.value = fn(lhs.value, rhs.value);
- }
- }
- $.Method({Static: true , Public: true }, staticMethodName,
- new JSIL.MethodSignature(null, [
- leftScalar ? tLeft : makeRef(tLeft),
- rightScalar ? tRight : makeRef(tRight),
- makeRef(tResult)
- ], []),
- wrapper
- );
- },
- makeLogicOperator: function ($, name, operator, bindingOperator, dataMembers, tVector) {
- var body = [];
- body.push("return (");
- for (var i = 0; i < dataMembers.length; i++) {
- var dataMember = dataMembers[i];
- var line = " (lhs." + dataMember + " ";
- line += operator;
- line += " rhs." + dataMember + ") ";
- if (i < dataMembers.length - 1)
- line += bindingOperator;
- body.push(line);
- }
- body.push(");")
- var fn = vectorUtil.makeOperatorCore(name, tVector, body, 2, false, false);
- $.Method({Static: true , Public: true }, name,
- new JSIL.MethodSignature($.Boolean, [tVector, tVector], []),
- fn
- );
- },
- makeNegationOperator: function ($, dataMembers, tVector) {
- var body = [];
- body.push("var result = this.create();");
- for (var i = 0; i < dataMembers.length; i++) {
- var dataMember = dataMembers[i];
- var line = "result." + dataMember + " = -value." + dataMember + ";";
- body.push(line);
- }
- body.push("return result;");
- var fn = vectorUtil.makeOperatorCore("op_UnaryNegation", tVector, body, 1, false, false);
- fn = vectorUtil.bindToPrototype(fn, tVector);
- $.Method({Static: true , Public: true }, "op_UnaryNegation",
- new JSIL.MethodSignature(tVector, [tVector], []),
- fn
- );
- },
- makeLengthGetter: function ($, name, isSquared, dataMembers, tVector) {
- var body = [];
- body.push("return " + (isSquared ? "(" : "Math.sqrt("));
- for (var i = 0; i < dataMembers.length; i++) {
- var dataMember = dataMembers[i];
- var line = " (this." + dataMember + " * this." + dataMember + ")";
- if (i < dataMembers.length - 1)
- line += " + ";
- body.push(line);
- }
- body.push(");");
- var fn = vectorUtil.makeOperatorCore(name, tVector, body, 0);
- $.Method({Static: false, Public: true }, name,
- new JSIL.MethodSignature($.Single, [], []),
- fn
- );
- },
- makeDistanceFunction: function ($, name, isSquared, dataMembers, tVector) {
- var body = [];
- body.push("var result = 0, current;");
- for (var i = 0; i < dataMembers.length; i++) {
- var dataMember = dataMembers[i];
- body.push("current = (rhs." + dataMember + " - lhs." + dataMember + ");");
- body.push("result += (current * current);");
- }
- if (isSquared)
- body.push("return result;");
- else
- body.push("return Math.sqrt(result);");
- var fn = vectorUtil.makeOperatorCore(name, tVector, body, 2);
- $.Method({Static: true, Public: true }, name,
- new JSIL.MethodSignature($.Single, [tVector, tVector], []),
- fn
- );
- },
- makeNormalizer: function ($, dataMembers, tVector) {
- var body = [];
- body.push("var factor = 1.0 / this.Length();");
- for (var i = 0; i < dataMembers.length; i++) {
- var dataMember = dataMembers[i];
- var line = "this." + dataMember + " *= factor;";
- body.push(line);
- }
- var fn = vectorUtil.makeOperatorCore("Normalize", tVector, body, 0);
- $.Method({Static: false, Public: true }, "Normalize",
- new JSIL.MethodSignature(null, [], []),
- fn
- );
- $.Method({Static: true , Public: true }, "Normalize",
- new JSIL.MethodSignature(tVector, [tVector], []),
- function (v) {
- fn.call(v);
- return v;
- }
- );
- },
- makeLengthMethods: function ($, dataMembers, tVector) {
- vectorUtil.makeLengthGetter($, "LengthSquared", true, dataMembers, tVector);
- vectorUtil.makeLengthGetter($, "Length", false, dataMembers, tVector);
- vectorUtil.makeDistanceFunction($, "DistanceSquared", true, dataMembers, tVector);
- vectorUtil.makeDistanceFunction($, "Distance", false, dataMembers, tVector);
- vectorUtil.makeNormalizer($, dataMembers, tVector);
- },
- makeLerpMethod: function ($, dataMembers, tVector) {
- var name = "Lerp";
- var body = [];
- body.push("var result = lhs.MemberwiseClone();");
- for (var i = 0; i < dataMembers.length; i++) {
- var dataMember = dataMembers[i];
- body.push("result." + dataMember + " += (rhs." + dataMember + " - lhs." + dataMember + ") * amount;");
- }
- body.push("return result;");
- var fn = vectorUtil.makeOperatorCore(name, tVector, body, 3);
- $.Method({Static: true, Public: true }, name,
- new JSIL.MethodSignature(tVector, [tVector, tVector, $.Single], []),
- fn
- );
- },
- makeOperators: function ($, dataMembers, tVector) {
- var operators = [
- ["op_Addition", "+", false, "Add"],
- ["op_Subtraction", "-", false, "Subtract"],
- ["op_Division", "/", true, "Divide"],
- ["op_Multiply", "*", true, "Multiply"]
- ];
- for (var i = 0; i < operators.length; i++) {
- var name = operators[i][0];
- var operator = operators[i][1];
- var withScalar = operators[i][2];
- var staticMethodName = operators[i][3];
- vectorUtil.makeArithmeticOperator($, name, staticMethodName, operator, dataMembers, tVector, tVector, tVector);
- if (withScalar) {
- var nameSuffixed = name + "Scalar";
- var staticMethodNameSuffixed = staticMethodName + "Scalar";
- vectorUtil.makeArithmeticOperator($, nameSuffixed, staticMethodNameSuffixed, operator, dataMembers, tVector, $.Single, tVector);
- var nameSuffixed2 = nameSuffixed + "Left";
- var staticMethodNameSuffixed2 = staticMethodNameSuffixed + "Left";
- vectorUtil.makeArithmeticOperator($, nameSuffixed2, staticMethodNameSuffixed2, operator, dataMembers, $.Single, tVector, tVector);
- }
- }
- vectorUtil.makeNegationOperator($, dataMembers, tVector);
- vectorUtil.makeLogicOperator($, "op_Equality", "===", "&&", dataMembers, tVector);
- vectorUtil.makeLogicOperator($, "op_Inequality", "!==", "||", dataMembers, tVector);
- vectorUtil.makeLengthMethods($, dataMembers, tVector);
- vectorUtil.makeLerpMethod($, dataMembers, tVector);
- },
- makeConstants: function ($, tVector, constants) {
- var makeGetter = function (values) {
- var state = null;
- return function () {
- if (state === null)
- state = JSIL.CreateInstanceOfType(
- tVector.get().__Type__, values
- );
- return state;
- }
- };
- for (var k in constants) {
- var values = constants[k];
- var getter = makeGetter(values);
- $.Method({Static: true , Public: true}, "get_" + k,
- new JSIL.MethodSignature(tVector, [], []),
- getter
- );
- }
- }
- };
- JSIL.ImplementExternals("Microsoft.Xna.Framework.Vector2", function ($) {
- vectorUtil.makeConstants(
- $, $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), {
- "UnitX": [1, 0],
- "UnitY": [0, 1],
- "Zero": [0, 0],
- "One": [1, 1]
- }
- );
- vectorUtil.makeOperators(
- $, ["X", "Y"], $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2")
- );
- $.Method({Static:true , Public:true }, "Transform",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
- function Transform (position, matrix) {
- var result = Object.create(Microsoft.Xna.Framework.Vector2.prototype);
- result.X = (position.X * matrix.xScale) + matrix.xTranslation;
- result.Y = (position.Y * matrix.yScale) + matrix.yTranslation;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "Dot",
- (new JSIL.MethodSignature($.Single, [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2")], [])),
- function Dot (vector1, vector2) {
- return vector1.X * vector2.X + vector1.Y * vector2.Y;
- }
- );
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [$.Single, $.Single], []), function Vector2_ctor (x, y) {
- this.X = x;
- this.Y = y;
- });
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [$.Single], []), function Vector2_ctor (value) {
- this.X = this.Y = value;
- });
- });
- JSIL.ImplementExternals("Microsoft.Xna.Framework.Vector3", function ($) {
- vectorUtil.makeConstants(
- $, $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), {
- "Backward": [0, 0, 1],
- "Forward": [0, 0, -1],
- "Left": [-1, 0, 0],
- "Right": [1, 0, 0],
- "Up": [0, 1, 0],
- "Down": [0, -1, 0],
- "UnitX": [1, 0, 0],
- "UnitY": [0, 1, 0],
- "UnitZ": [0, 0, 1],
- "Zero": [0, 0, 0],
- "One": [1, 1, 1]
- }
- );
- vectorUtil.makeOperators(
- $, ["X", "Y", "Z"], $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")
- );
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [$.Single, $.Single, $.Single], []), function Vector3_ctor (x, y, z) {
- this.X = x;
- this.Y = y;
- this.Z = z;
- });
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [$.Single], []), function Vector3_ctor (value) {
- this.X = this.Y = this.Z = value;
- });
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [], []), function Vector3_ctor (xy, z) {
- this.X = xy.X;
- this.Y = xy.Y;
- this.Z = z;
- });
- $.Method({Static:true , Public:true }, "Transform",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
- function Transform (position, matrix) {
- var result = Object.create(Microsoft.Xna.Framework.Vector3.prototype);
- result.X = (position.X * matrix.xScale) + matrix.xTranslation;
- result.Y = (position.Y * matrix.yScale) + matrix.yTranslation;
- result.Z = (position.Z * matrix.zScale) + matrix.zTranslation;
- return result;
- }
- );
- });
- JSIL.ImplementExternals("Microsoft.Xna.Framework.Vector4", function ($) {
- vectorUtil.makeConstants(
- $, $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4"), {
- "Zero": [0, 0, 0, 0],
- "One": [1, 1, 1, 1]
- }
- );
- vectorUtil.makeOperators(
- $, ["X", "Y", "Z", "W"], $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4")
- );
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [$.Single, $.Single, $.Single, $.Single], []), function Vector4_ctor (x, y, z, w) {
- this.X = x;
- this.Y = y;
- this.Z = z;
- this.W = w;
- });
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [], []), function Vector4_ctor (xy, z, w) {
- this.X = xy.X;
- this.Y = xy.Y;
- this.Z = z;
- this.W = w;
- });
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [], []), function Vector4_ctor (xyz, w) {
- this.X = xyz.X;
- this.Y = xyz.Y;
- this.Z = xyz.Z;
- this.W = w;
- });
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [$.Single], []), function Vector4_ctor (value) {
- this.X = this.Y = this.Z = this.W = value;
- });
- $.Method({Static:true , Public:true }, "Transform",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
- function Transform (position, matrix) {
- var result = Object.create(Microsoft.Xna.Framework.Vector4.prototype);
- result.X = (position.X * matrix.xScale) + matrix.xTranslation;
- result.Y = (position.Y * matrix.yScale) + matrix.yTranslation;
- result.Z = (position.Z * matrix.zScale) + matrix.zTranslation;
- result.W = (position.W * matrix.wScale) + matrix.wTranslation;
- return result;
- }
- );
- });
- JSIL.ImplementExternals("Microsoft.Xna.Framework.Matrix", function ($) {
- var matrix = $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix");
- $.Method({
- Static: true,
- Public: true
- }, ".cctor2", new JSIL.MethodSignature(null, [], []), function () {
- // FIXME
- var identity = Microsoft.Xna.Framework.Matrix._identity = new Microsoft.Xna.Framework.Matrix();
- identity.xTranslation = identity.yTranslation = identity.zTranslation = 0;
- identity.xRotation = identity.yRotation = identity.zRotation = 0;
- identity.xScale = identity.yScale = identity.zScale = 1;
- });
- $.RawMethod(false, "__CopyMembers__",
- function Matrix_CopyMembers (source, target) {
- target.xScale = source.xScale || 0;
- target.yScale = source.yScale || 0;
- target.zScale = source.zScale || 0;
- target.xTranslation = source.xTranslation || 0;
- target.yTranslation = source.yTranslation || 0;
- target.zTranslation = source.zTranslation || 0;
- target.xRotation = source.xRotation || 0;
- target.yRotation = source.yRotation || 0;
- target.zRotation = source.zRotation || 0;
- }
- );
- $.Method({Static:true , Public:true }, "get_Identity",
- (new JSIL.MethodSignature(matrix, [], [])),
- function get_Identity () {
- return Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreateLookAt",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"),
- $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")
- ], [])),
- function CreateLookAt (cameraPosition, cameraTarget, cameraUpVector) {
- // FIXME
- return Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreateLookAt",
- (new JSIL.MethodSignature(null, [
- $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")]), $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")]),
- $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")]), $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
- ], [])),
- function CreateLookAt (/* ref */ cameraPosition, /* ref */ cameraTarget, /* ref */ cameraUpVector, /* ref */ result) {
- // FIXME
- result.value = Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreateOrthographic",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $.Single, $.Single,
- $.Single, $.Single
- ], [])),
- function CreateOrthographic (width, height, zNearPlane, zFarPlane) {
- // FIXME
- return Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreateOrthographic",
- (new JSIL.MethodSignature(null, [
- $.Single, $.Single,
- $.Single, $.Single,
- $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
- ], [])),
- function CreateOrthographic (width, height, zNearPlane, zFarPlane, /* ref */ result) {
- // FIXME
- result.value = Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreateOrthographicOffCenter",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $.Single, $.Single,
- $.Single, $.Single,
- $.Single, $.Single
- ], [])),
- function CreateOrthographicOffCenter (left, right, bottom, top, zNearPlane, zFarPlane) {
- // FIXME
- return Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreateOrthographicOffCenter",
- (new JSIL.MethodSignature(null, [
- $.Single, $.Single,
- $.Single, $.Single,
- $.Single, $.Single,
- $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
- ], [])),
- function CreateOrthographicOffCenter (left, right, bottom, top, zNearPlane, zFarPlane, /* ref */ result) {
- // FIXME
- result.value = Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreatePerspective",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $.Single, $.Single,
- $.Single, $.Single
- ], [])),
- function CreatePerspective (width, height, nearPlaneDistance, farPlaneDistance) {
- // FIXME
- return Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreatePerspective",
- (new JSIL.MethodSignature(null, [
- $.Single, $.Single,
- $.Single, $.Single,
- $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
- ], [])),
- function CreatePerspective (width, height, nearPlaneDistance, farPlaneDistance, /* ref */ result) {
- // FIXME
- result.value = Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreatePerspectiveFieldOfView",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $.Single, $.Single,
- $.Single, $.Single
- ], [])),
- function CreatePerspectiveFieldOfView (fieldOfView, aspectRatio, nearPlaneDistance, farPlaneDistance) {
- // FIXME
- return Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreatePerspectiveFieldOfView",
- (new JSIL.MethodSignature(null, [
- $.Single, $.Single,
- $.Single, $.Single,
- $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
- ], [])),
- function CreatePerspectiveFieldOfView (fieldOfView, aspectRatio, nearPlaneDistance, farPlaneDistance, /* ref */ result) {
- // FIXME
- result.value = Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreatePerspectiveOffCenter",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $.Single, $.Single,
- $.Single, $.Single,
- $.Single, $.Single
- ], [])),
- function CreatePerspectiveOffCenter (left, right, bottom, top, nearPlaneDistance, farPlaneDistance) {
- // FIXME
- return Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreatePerspectiveOffCenter",
- (new JSIL.MethodSignature(null, [
- $.Single, $.Single,
- $.Single, $.Single,
- $.Single, $.Single,
- $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
- ], [])),
- function CreatePerspectiveOffCenter (left, right, bottom, top, nearPlaneDistance, farPlaneDistance, /* ref */ result) {
- // FIXME
- result.value = Microsoft.Xna.Framework.Matrix._identity;
- }
- );
- $.Method({Static:true , Public:true }, "CreateRotationX",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
- function CreateRotationX (radians) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xRotation = radians;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "CreateRotationY",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
- function CreateRotationY (radians) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.yRotation = radians;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "CreateRotationZ",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
- function CreateRotationZ (radians) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.zRotation = radians;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "CreateScale",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")], [])),
- function CreateScale (scales) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xScale = scales.X;
- result.yScale = scales.Y;
- result.zScale = scales.Z;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "CreateScale",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
- function CreateScale (scale) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xScale = scale;
- result.yScale = scale;
- result.zScale = scale;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "CreateScale",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $.Single, $.Single,
- $.Single
- ], [])),
- function CreateScale (xScale, yScale, zScale) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xScale = xScale;
- result.yScale = yScale;
- result.zScale = zScale;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "CreateTranslation",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")], [])),
- function CreateTranslation (position) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xTranslation = position.X;
- result.yTranslation = position.Y;
- result.zTranslation = position.Z;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "CreateTranslation",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
- $.Single, $.Single,
- $.Single
- ], [])),
- function CreateTranslation (xPosition, yPosition, zPosition) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xTranslation = xPosition;
- result.yTranslation = yPosition;
- result.zTranslation = zPosition;
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "Invert",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
- function Invert (matrix) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xTranslation = -matrix.xTranslation;
- result.yTranslation = -matrix.yTranslation;
- result.zTranslation = -matrix.zTranslation;
- result.xScale = 1 / (matrix.xScale + 0.000001);
- result.yScale = 1 / (matrix.yScale + 0.000001);
- result.zScale = 1 / (matrix.zScale + 0.000001);
- return result;
- }
- );
- $.Method({Static:true , Public:true }, "op_Multiply",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
- function Multiply (matrix1, matrix2) {
- // FIXME
- var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
- result.xTranslation = matrix1.xTranslation + matrix2.xTranslation;
- result.yTranslation = matrix1.yTranslation + matrix2.yTranslation;
- result.zTranslation = matrix1.zTranslation + matrix2.zTranslation;
- result.xScale = matrix1.xScale * matrix2.xScale;
- result.yScale = matrix1.yScale * matrix2.yScale;
- result.zScale = matrix1.zScale * matrix2.zScale;
- return result;
- }
- );
- });
- JSIL.ImplementExternals("Microsoft.Xna.Framework.GameServiceContainer", function ($) {
- $.Method({
- Static: false,
- Public: true
- }, ".ctor", new JSIL.MethodSignature(null, [], []), function () {});
- });
- JSIL.ImplementExternals("Microsoft.Xna.Framework.GameComponentCollection", function ($) {
- $.RawMethod(false, "$internalCtor", function (game) {
- this._game = game;
- this._ctor();
- });
- $.RawMethod(false, "$OnItemAdded", function (item) {
- if (this._game.initialized) {
- if (typeof (item.Initialize) === "function")
- item.Initialize();
- }
- });
- });
- JSIL.ImplementExternals("Microsoft.Xna.Framework.Game", function ($) {
- $.Method({Static: false, Public: true}, "ForceQuit",
- new JSIL.MethodSignature(null, [], []),
- function () {
- Microsoft.Xna.Framework.Game._QuitForced = true;
- }
- );
- $.Method({Static:false, Public:true }, ".ctor",
- (new JSIL.MethodSignature(null, [], [])),
- function _ctor () {
- var tContentManager = JSIL.GetTypeFromAssembly(
- $xnaasms.xna, "Microsoft.Xna.Framework.Content.ContentManager", [], true
- );
- var tGameTime = JSIL.GetTypeFromAssembly(
- $xnaasms.xnaGame, "Microsoft.Xna.Framework.GameTime", [], true
- );
- this.gameServices = new Microsoft.Xna.Framework.GameServiceContainer();
- this.content = JSIL.CreateInstanceOfType(tContentManager, [this.gameServices]);
- this.components = JSIL.CreateInstanceOfType(
- Microsoft.Xna.Framework.GameComponentCollection.__Type__, "$internalCtor", [this]
- );
- this.targetElapsedTime = System.TimeSpan.FromTicks(System.Int64.FromInt32(166667));
- this.isFixedTimeStep = true;
- this.forceElapsedTimeToZero = true;
- this._isDead = false;
- this.initialized = false;
- if (typeof (Date.now) === "function") {
- Object.defineProperty(this, "_GetNow", {
- configurable: true,
- enumerable: true,
- value: Date.now
- });
- }
- this._runHandle = null;
- this._gameTime = JSIL.CreateInstanceOfType(tGameTime, null);
- this._lastFrame = this._nextFrame = this._started = 0;
- }
- );
- $.Method({Static:false, Public:true }, "get_Components",
- (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameComponentCollection"), [], [])),
- function get_Components () {
- return this.components;
- }
- );
- $.Method({Static:false, Public:true }, "get_Content",
- (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Content.ContentManager"), [], [])),
- function get_Content () {
- return this.content;
- }
- );
- $.Method({Static:false, Public:true }, "get_GraphicsDevice",
- (new JSIL.MethodSignature($jsilxna.graphicsRef("Microsoft.Xna.Framework.Graphics.GraphicsDevice"), [], [])),
- function get_GraphicsDevice () {
- return this.graphicsDeviceService.GraphicsDevice;
- }
- );
- $.Method({Static:false, Public:true }, "get_IsActive",
- (new JSIL.MethodSignature($.Boolean, [], [])),
- function get_IsActive () {
- return JSIL.Host.isPageVisible() && !Microsoft.Xna.Framework.Game._QuitForced && !this._isDead;
- }
- );
- $.Method({Static:false, Public:true }, "get_IsFixedTimeStep",
- (new JSIL.MethodSignature($.Boolean, [], [])),
- function get_IsFixedTimeStep () {
- return this.isFixedTimeStep;
- }
- );
- $.Method({Static:false, Public:true }, "get_TargetElapsedTime",
- (new JSIL.MethodSignature($xnaasms[5].TypeRef("System.TimeSpan"), [], [])),
- function get_TargetElapsedTime () {
- return this.targetElapsedTime;
- }
- );
- $.Method({Static:false, Public:true }, "get_Services",
- (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameServiceContainer"), [], [])),
- function get_Services () {
- return this.gameServices;
- }
- );
- $.Method({Static:false, Public:true }, "get_Window",
- (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameWindow"), [], [])),
- function get_Window () {
- // FIXME
- if (!this._window)
- this._window = new Microsoft.Xna.Framework.GameWindow();
- return this._window;
- }
- );
- $.Method({Static:false, Public:false}, "get_IsMouseVisible",
- (new JSIL.MethodSignature($.Boolean, [], [])),
- function get_IsMouseVisible () {
- var oc = this.graphicsDeviceService.GraphicsDevice.originalCanvas;
- return (oc.style.cursor !== "none");
- }
- );
- $.Method({Static:false, Public:true }, "set_IsMouseVisible",
- (new JSIL.MethodSignature(null, [$.Boolean], [])),
- function set_IsMouseVisible (value) {
- var oc = this.graphicsDeviceService.GraphicsDevice.originalCanvas;
- oc.style.cursor = value ? "default" : "none";
- }
- );
- $.Method({Static:false, Public:true }, "set_IsFixedTimeStep",
- (new JSIL.MethodSignature(null, [$.Boolean], [])),
- function set_IsFixedTimeStep (value) {
- this.isFixedTimeStep = value;
- }
- );
- $.Method({Static:false, Public:true }, "set_TargetElapsedTime",
- (new JSIL.MethodSignature(null, [$xnaasms[5].TypeRef("System.TimeSpan")], [])),
- function set_TargetElapsedTime (value) {
- this.targetElapsedTime = value;
- }
- );
- $.Method({
- Static: false,
- Public: true
- }, "Initialize", new JSIL.MethodSignature(null, [], []), function () {
- this.initialized = true;
- for (var i = 0, l = this.components._size; i < l; i++) {
- var component = this.components._items[i];
- component.Initialize();
- }
- this.LoadContent();
- });
- $.Method({
- Static: false,
- Public: true
- }, "LoadContent", new JSIL.MethodSignature(null, [], []), function () {
- });
- $.Method({
- Static: false,
- Public: true
- }, "UnloadContent", new JSIL.MethodSignature(null, [], []), function () {
- });
- $.Method({
- Static: false,
- Public: true
- }, "ResetElapsedTime", new JSIL.MethodSignature(null, [], []), function () {
- this.forceElapsedTimeToZero = true;
- });
- $.RawMethod(false, "$ComponentsOfType", function (type) {
- var result = new Array();
- for (var i = 0, l = this.components._size; i < l; i++) {
- var item = this.components._items[i];
- if (type.$Is(item))
- result.push(item);
- }
- return result;
- });
- var cmp = function (lhs, rhs) {
- if (lhs > rhs)
- return 1;
- else if (rhs > lhs)
- return -1;
- else
- return 0;
- };
- $.Method({Static:false, Public:false}, "Draw",
- (new JSIL.MethodSignature(null, [$xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameTime")], [])),
- function Game_Draw (gameTime) {
- if (Microsoft.Xna.Framework.Game._QuitForced || this._isDead)
- return;
- var drawableComponents = this.$ComponentsOfType(Microsoft.Xna.Framework.IDrawable.__Type__);
- drawableComponents.sort(function (lhs, rhs) {
- return cmp(lhs.get_DrawOrder(), rhs.get_DrawOrder());
- });
- for (var i = 0, l = drawableComponents.length; i < l; i++) {
- var drawable = drawableComponents[i];
- if (drawable.Visible)
- drawable.Draw(gameTime);
- }
- }
- );
- $.Method({Static:false, Public:false}, "Update",
- (new JSIL.MethodSignature(null, [$xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameTime")], [])),
- function Game_Update (gameTime) {
- if (Microsoft.Xna.Framework.Game._QuitForced || this._isDead)
- return;
- var updateableComponents = this.$ComponentsOfType(Microsoft.Xna.Framework.IUpdateable.__Type__);
- updateableComponents.sort(function (lhs, rhs) {
- return cmp(lhs.get_UpdateOrder(), rhs.get_UpdateOrder());
- });
- for (var i = 0, l = updateableComponents.length; i < l; i++) {
- var updateable = updateableComponents[i];
- if (updateable.Enabled)
- updateable.Update(gameTime);
- }
- }
- );
- $.Method({
- Static: false,
- Public: true
- }, "Run", new JSIL.MethodSignature(null, [], []), function () {
- this._profilingMode = (document.location.search.indexOf("profile") >= 0);
- this._balanceFPSCheckbox = (document.getElementById("balanceFramerate") || null);
- if (this._balanceFPSCheckbox)
- this._balanceFPSCheckbox.checked = !this._profilingMode;
- Microsoft.Xna.Framework.Game._QuitForced = false;
- this.Initialize();
- this._QueueStep();
- });
- $.RawMethod(false, "_GetNow", function Game_GetNow () {
- return (new Date()).getTime();
- });
- $.RawMethod(false, "_DeferCall", function Game_DeferCall (callback, lng) {
- setTimeout(callback, 0);
- });
- $.RawMethod(false, "_QueueStep", function Game_EnqueueTick () {
- if (Microsoft.Xna.Framework.Game._QuitForced || this._isDead)
- return;
- var self = this;
- var stepCallback = self._Step.bind(self);
- var forceSetTimeout = false ||
- (document.location.search.indexOf("forceSetTimeout") >= 0);
- var requestAnimationFrame = window.requestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.msRequestAnimationFrame ||
- window.oRequestAnimationFrame;
- if (requestAnimationFrame && !forceSetTimeout) {
- requestAnimationFrame(stepCallback);
- } else {
- var shouldStepCallback = function ShouldStep () {
- var now = self._GetNow();
- var delay = self._nextFrame - now;
- if (delay <= 0)
- stepCallback();
- else
- self._DeferCall(shouldStepCallback, delay >= 3);
- };
- // It's important that we use setTimeout at least once after every frame in order to let the browser pump messages
- this._DeferCall(shouldStepCallback, true);
- }
- });
- $.RawMethod(false, "_TimedUpdate", function Game_TimedUpdate (longFrame) {
- var updateStarted = this._GetNow();
- this.Update(this._gameTime);
- var updateEnded = this._GetNow();
- // Detect long updates and suppress frameskip.
- if ((updateEnded - updateStarted) > longFrame) {
- this.suppressFrameskip = true;
- }
-
- this._updateCount += 1;
- });
- $.RawMethod(false, "_ReportFPS", function Game_ReportFPS (now) {
- this._lastSecond = now;
-
- if (typeof (JSIL.Host.reportFps) === "function") {
- var isWebGL = this.graphicsDeviceService.GraphicsDevice.context.isWebGL || false;
- var cacheBytes = ($jsilxna.imageChannelCache.countBytes + $jsilxna.textCache.countBytes);
- JSIL.Host.reportFps(
- this._drawCount, this._updateCount,
- cacheBytes, isWebGL
- );
- }
- this._updateCount = this._drawCount = 0;
- });
- $.RawMethod(false, "_FixedTimeStep", function Game_FixedTimeStep (
- elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame
- ) {
- var tInt64 = $jsilcore.System.Int64;
- var frameLength64 = tInt64.FromNumber(frameDelay * millisecondInTicks);
- this._gameTime.elapsedGameTime._ticks = frameLength64;
- this._gameTime.elapsedGameTime.$invalidate();
- elapsed += this._extraTime;
- this._extraTime = 0;
- if (elapsed > maxElapsedTimeMs)
- elapsed = maxElapsedTimeMs;
- var numFrames = Math.floor(elapsed / frameDelay);
- if (numFrames < 1) {
- numFrames = 1;
- this._extraTime = elapsed - frameDelay;
- } else {
- this._extraTime = elapsed - (numFrames * frameDelay);
- }
- for (var i = 0; i < numFrames; i++) {
- this._gameTime.totalGameTime._ticks = tInt64.op_Addition(
- this._gameTime.totalGameTime._ticks, frameLength64, this._gameTime.totalGameTime._ticks
- );
- this._gameTime.totalGameTime.$invalidate();
- this._TimedUpdate(longFrame);
- }
- });
- $.RawMethod(false, "_VariableTimeStep", function Game_VariableTimeStep (
- elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame
- ) {
- this._extraTime = 0;
- this.suppressFrameskip = false;
- if (elapsed > maxElapsedTimeMs)
- elapsed = maxElapsedTimeMs;
- var tInt64 = $jsilcore.System.Int64;
- var elapsed64 = tInt64.FromNumber(elapsed * millisecondInTicks);
- this._gameTime.elapsedGameTime._ticks = elapsed64;
- this._gameTime.elapsedGameTime.$invalidate();
- this._gameTime.totalGameTime._ticks = tInt64.op_Addition(
- this._gameTime.totalGameTime._ticks, elapsed64, this._gameTime.totalGameTime._ticks
- );
- this._gameTime.totalGameTime.$invalidate();
- this._TimedUpdate(longFrame);
- });
- $.RawMethod(false, "_RenderAFrame", function Game_RenderAFrame () {
- var device = this.get_GraphicsDevice();
- device.$UpdateViewport();
- device.$Clear();
- this.Draw(this._gameTime);
- this._drawCount += 1;
- });
- $.RawMethod(false, "_Step", function Game_Step () {
- var now = this._GetNow();
- var frameDelay = this.targetElapsedTime.get_TotalMilliseconds();
- if (frameDelay <= 0)
- throw new Error("Game frame duration must be a positive, nonzero number!");
- if (this._lastFrame === 0) {
- var elapsed = frameDelay;
- var total = 0;
- this._started = now;
- this._lastSecond = now;
- this._updateCount = this._drawCount = 0;
- this._extraTime = 0;
- this.suppressFrameskip = true;
- } else {
- var elapsed = now - this._lastFrame;
- var total = now - this._started;
- }
- if ((now - this._lastSecond) > 1000) {
- this._ReportFPS(now);
- $jsilxna.imageChannelCache.maybeEvictItems();
- $jsilxna.textCache.maybeEvictItems();
- }
- if (this.forceElapsedTimeToZero) {
- this.forceElapsedTimeToZero = false;
- this._extraTime = 0;
- elapsed = 0;
- }
- this._lastFrame = now;
- this._nextFrame = now + frameDelay;
- var millisecondInTicks = 10000;
- var maxElapsedTimeMs = frameDelay * 4;
- var longFrame = frameDelay * 3;
- this._profilingMode = (document.location.search.indexOf("profile") >= 0);
- if (this._balanceFPSCheckbox)
- this._profilingMode = !this._balanceFPSCheckbox.checked;
- var failed = true;
- try {
- if (this.isFixedTimeStep && !this.suppressFrameskip && !this._profilingMode) {
- this._FixedTimeStep(elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame);
- } else {
- this._VariableTimeStep(elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame);
- }
- this._RenderAFrame();
- failed = false;
- } finally {
- if (failed || Microsoft.Xna.Framework.Game._QuitForced)
- this.Exit();
- else
- this._QueueStep();
- }
- });
- $.Method({
- Static: false,
- Public: true
- }, "Exit", new JSIL.MethodSignature(null, [], []), function () {
- this.Dispose();
- });
- $.Method({
- Static: false,
- Public: true
- }, "Dispose", new JSIL.MethodSignature(null, [], []), function () {
- if (this._runHandle !== null)
- window.clearInterval(this._runHandle);
- this._runHandle = null;
- this.UnloadContent();
- this._isDead = true;
- try {
- var canvas = JSIL.Host.getCanvas();
- var ctx = canvas.getContext("2d") || canvas.getContext("webgl-2d");
- ctx.setTransform(1, 0, 0, 1, 0, 0);
- ctx.globalAlpha = 1;
- ctx.globalCompositeOperation = "source-over";
- ctx.fillStyle = "black";
- ctx.fillRect(0, 0, 99999, 99999);
- var fsb = document.getElementById("fullscreenButton");
- if (fsb)
- fsb.style.display = "none";
- var stats = document.getElementById("stats");
- if (stats)
- stats.style.display = "none";
- } catch (exc) {
- }
- });
- });
- JSIL.ImplementExternals("Microsoft.Xna.Framework.GameComponent", function ($) {
- $.Method({Static:false, Public:true }, ".ctor",
- (new JSIL.MethodSignature(null, [$xnaasms[1].TypeRef("Microsoft.Xna.Framework.Game")], [])),
- function _ctor (game) {
- this.enabled = true;
- this.initialized = false;
- this.game = game;
- }
- );
- $.Method({Static:false, Public:true }, "get_UpdateOrder",
- (new JSIL.MethodSignature($.Int32, [], [])),
- function get_UpdateOrder () {
- return 0;
- }
- );
- $.Method({Static:false, Public:true }, "get_Enabled",
- (new JSIL.MethodSignature($.Boolean, [], [])),
- function get_Enabled () {
- return this.enabled;
- }
- );
- $.Method({Static:false, Public:true }, "get_Game",
- (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.Game"), [], [])),
- function get_Game () {
- return this.game;
- }
- );
- $.Method({Static:false, Public:true }, "set_Enabled",
- (new JSIL.MethodSignature(null, [$.Boolean], [])),
- function set_Enabled (value) {
- this.enabled = value;
- }
- );
- $.Method({Static:false, Public:true }, "Initialize",
- (new JSIL.MethodSignature(null, [], [])),
- function Initialize () {
- if (this.ini…
Large files files are truncated, but you can click here to view the full file