PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/Libraries/JSIL.XNA.Core.js

http://github.com/kevingadd/JSIL
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

  1. "use strict";
  2. if (typeof (JSIL) === "undefined") throw new Error("JSIL.Core required");
  3. var $drawDebugRects = false, $drawDebugBoxes = false;
  4. var $useTextCaching = true, $textCachingSupported = true;
  5. var $jsilxna = JSIL.DeclareAssembly("JSIL.XNA");
  6. $jsilxna.allowWebGL = true;
  7. $jsilxna.testedWebGL = false;
  8. $jsilxna.workingWebGL = false;
  9. var $sig = new JSIL.MethodSignatureCache();
  10. var $xnaasms = new JSIL.AssemblyCollection({
  11. corlib: "mscorlib",
  12. xna: "Microsoft.Xna.Framework",
  13. xnaGraphics: "Microsoft.Xna.Framework.Graphics",
  14. xnaGame: "Microsoft.Xna.Framework.Game",
  15. xnaStorage: "Microsoft.Xna.Framework.Storage",
  16. 0: "Microsoft.Xna.Framework",
  17. 1: "Microsoft.Xna.Framework.Game",
  18. 2: "Microsoft.Xna.Framework.GamerServices",
  19. 5: "mscorlib",
  20. 11: "System.Drawing",
  21. 15: "System.Windows.Forms",
  22. 18: "Microsoft.Xna.Framework.Xact",
  23. });
  24. var getXnaGraphics = function () {
  25. return $xnaasms.xnaGraphics || $xnaasms.xna;
  26. };
  27. var getXnaStorage = function () {
  28. return $xnaasms.xnaStorage || $xnaasms.xna;
  29. };
  30. $jsilxna.colorRef = function () {
  31. var graphicsAsm = JSIL.GetAssembly("Microsoft.Xna.Framework.Graphics", true);
  32. if (graphicsAsm !== null)
  33. return $xnaasms.xna.TypeRef("Microsoft.Xna.Framework.Color");
  34. else
  35. return $xnaasms.xna.TypeRef("Microsoft.Xna.Framework.Graphics.Color");
  36. };
  37. $jsilxna.graphicsRef = function (name) {
  38. var graphicsAsm = JSIL.GetAssembly("Microsoft.Xna.Framework.Graphics", true);
  39. if (graphicsAsm !== null)
  40. return graphicsAsm.TypeRef(name);
  41. else
  42. return $xnaasms.xna.TypeRef(name);
  43. };
  44. JSIL.MakeClass($jsilcore.System.Object, "HTML5Asset", true, [], function ($) {
  45. $.RawMethod(false, ".ctor", function (assetName) {
  46. this.name = assetName;
  47. });
  48. $.RawMethod(false, "toString", function () {
  49. return "<XNA Asset '" + this.name + "'>";
  50. });
  51. });
  52. JSIL.MakeClass("HTML5Asset", "HTML5ImageAsset", true, [], function ($) {
  53. $.RawMethod(false, ".ctor", function (assetName, image) {
  54. HTML5Asset.prototype._ctor.call(this, assetName);
  55. image.assetName = assetName;
  56. this.image = image;
  57. });
  58. $.RawMethod(false, "ReadAsset",
  59. function HTML5ImageAsset_ReadAsset (type) {
  60. var tTexture = Microsoft.Xna.Framework.Graphics.Texture2D.__Type__;
  61. return JSIL.CreateInstanceOfType(tTexture, "$fromImage", [null, this.image]);
  62. }
  63. );
  64. });
  65. JSIL.MakeClass("HTML5Asset", "SoundAssetBase", true, [], function ($) {
  66. $.Method({Static:false, Public:true }, "Play",
  67. (new JSIL.MethodSignature($.Boolean, [], [])),
  68. function Play () {
  69. return this.Play(1, 0, 0);
  70. }
  71. );
  72. $.Method({Static:false, Public:true }, "Play",
  73. (new JSIL.MethodSignature($.Boolean, [$.Single, $.Single, $.Single], [])),
  74. function Play (volume, pitch, pan) {
  75. var instance = this.$newInstance();
  76. instance.volume = volume;
  77. // FIXME: No pitch or pan
  78. instance.play();
  79. return true;
  80. }
  81. );
  82. $.Method({Static:false, Public:true }, "CreateInstance",
  83. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Audio.SoundEffectInstance"), [], [])),
  84. function CreateInstance () {
  85. return new Microsoft.Xna.Framework.Audio.SoundEffectInstance(this, false);
  86. }
  87. );
  88. });
  89. JSIL.MakeClass("SoundAssetBase", "CallbackSoundAsset", true, [], function ($) {
  90. $.RawMethod(false, ".ctor", function (assetName, createInstance) {
  91. HTML5Asset.prototype._ctor.call(this, assetName);
  92. this.$createInstance = createInstance;
  93. this.freeInstances = [];
  94. });
  95. $.RawMethod(false, "$newInstance", function () {
  96. if (this.freeInstances.length > 0) {
  97. return this.freeInstances.pop();
  98. } else {
  99. return this.$createInstance(0);
  100. }
  101. });
  102. });
  103. JSIL.MakeClass("HTML5Asset", "RawXNBAsset", true, [], function ($) {
  104. $.Method({
  105. Static: false,
  106. Public: true
  107. }, ".ctor", new JSIL.MethodSignature(null, [], []), function (assetName, rawBytes) {
  108. if (JSIL.GetAssembly("JSIL.IO", true) === null) {
  109. throw new Error("JSIL.IO is required");
  110. }
  111. HTML5Asset.prototype._ctor.call(this, assetName);
  112. this.bytes = rawBytes;
  113. this.contentManager = null;
  114. });
  115. $.Method({
  116. Static: false,
  117. Public: true
  118. }, "ReadAsset", new JSIL.MethodSignature(null, [], []), function RawXNBAsset_ReadAsset (type) {
  119. var memoryStream = new System.IO.MemoryStream(this.bytes, false);
  120. var tContentReader = JSIL.GetTypeFromAssembly(
  121. $xnaasms.xna, "Microsoft.Xna.Framework.Content.ContentReader", [], true
  122. );
  123. var contentReader = $sig.get("newCr").Construct(
  124. tContentReader, this.contentManager, memoryStream, this.name, null, 0
  125. );
  126. contentReader.ReadHeader();
  127. var sharedResourceCount = contentReader.Read7BitEncodedInt();
  128. var sharedResources = new Array(sharedResourceCount);
  129. var mainObject = contentReader.ReadObject$b1(type)();
  130. for (var i = 0; i < sharedResourceCount; i++)
  131. sharedResources[i] = content.ReadObject$b1(System.Object)();
  132. return mainObject;
  133. });
  134. });
  135. JSIL.MakeClass("RawXNBAsset", "SpriteFontAsset", true, [], function ($) {
  136. $.Method({
  137. Static: false,
  138. Public: true
  139. }, ".ctor", new JSIL.MethodSignature(null, [], []), function (assetName, rawBytes) {
  140. RawXNBAsset.prototype._ctor.call(this, assetName, rawBytes);
  141. });
  142. });
  143. JSIL.MakeClass("RawXNBAsset", "Texture2DAsset", true, [], function ($) {
  144. $.Method({
  145. Static: false,
  146. Public: true
  147. }, ".ctor", new JSIL.MethodSignature(null, [], []), function (assetName, rawBytes) {
  148. RawXNBAsset.prototype._ctor.call(this, assetName, rawBytes);
  149. });
  150. });
  151. var vectorUtil = {
  152. makeOperatorCore: function (name, tVector, body, argCount, leftScalar, rightScalar) {
  153. var js = body.join("\r\n");
  154. var typeName = String(tVector.typeName);
  155. var suffixedName;
  156. if (argCount < 1) {
  157. suffixedName = name;
  158. } else {
  159. suffixedName = name + "[";
  160. if (argCount == 1) {
  161. suffixedName += (leftScalar ? "float" : "vec");
  162. } else if (argCount == 2) {
  163. suffixedName += (leftScalar ? "float" : "vec") + "," +
  164. (rightScalar ? "float" : "vec");
  165. }
  166. suffixedName += "]";
  167. }
  168. var functionName = typeName + "." + suffixedName;
  169. switch (argCount) {
  170. case 0:
  171. return JSIL.CreateNamedFunction(
  172. functionName,
  173. [],
  174. js
  175. );
  176. case 1:
  177. return JSIL.CreateNamedFunction(
  178. functionName,
  179. ["value"],
  180. js
  181. );
  182. case 2:
  183. return JSIL.CreateNamedFunction(
  184. functionName,
  185. ["lhs", "rhs"],
  186. js
  187. );
  188. case 3:
  189. return JSIL.CreateNamedFunction(
  190. functionName,
  191. ["lhs", "rhs", "amount"],
  192. js
  193. );
  194. default:
  195. throw new Error("Invalid argument count");
  196. }
  197. },
  198. bindToPrototype: function (fn, typeRef) {
  199. var state = {
  200. resolvedType: null,
  201. typeRef: typeRef
  202. };
  203. JSIL.SetLazyValueProperty(
  204. state, "create",
  205. function VectorMethod_GetCreator () {
  206. if (state.resolvedType === null)
  207. state.resolvedType = state.typeRef.get();
  208. var create = Object.create;
  209. var proto = state.resolvedType.prototype;
  210. return create.bind(Object, proto);
  211. }
  212. );
  213. return fn.bind(state);
  214. },
  215. makeArithmeticOperator: function ($, name, staticMethodName, operator, dataMembers, tLeft, tRight, tResult) {
  216. var leftScalar = (tLeft !== tResult);
  217. var rightScalar = (tRight !== tResult);
  218. if (leftScalar && rightScalar)
  219. throw new Error("Invalid type combination");
  220. var body = [];
  221. body.push("var result = this.create();");
  222. for (var i = 0; i < dataMembers.length; i++) {
  223. var dataMember = dataMembers[i];
  224. var line = "result." + dataMember + " = ";
  225. if (leftScalar)
  226. line += "lhs ";
  227. else
  228. line += "lhs." + dataMember + " ";
  229. line += operator;
  230. if (rightScalar)
  231. line += " rhs;";
  232. else
  233. line += " rhs." + dataMember + ";";
  234. body.push(line);
  235. }
  236. body.push("return result;")
  237. var fn = vectorUtil.makeOperatorCore(name, tResult, body, 2, leftScalar, rightScalar);
  238. fn = vectorUtil.bindToPrototype(fn, tResult);
  239. $.Method({Static: true , Public: true }, name,
  240. new JSIL.MethodSignature(tResult, [tLeft, tRight], []),
  241. fn
  242. );
  243. $.Method({Static: true , Public: true }, staticMethodName,
  244. new JSIL.MethodSignature(tResult, [tLeft, tRight], []),
  245. fn
  246. );
  247. var makeRef = function (t) {
  248. return $jsilcore.TypeRef("JSIL.Reference", [t]);
  249. };
  250. var wrapper;
  251. if (leftScalar) {
  252. wrapper = function VectorOperator_Scalar_Ref (lhs, rhs, result) {
  253. result.value = fn(lhs, rhs.value);
  254. }
  255. } else if (rightScalar) {
  256. wrapper = function VectorOperator_Ref_Scalar (lhs, rhs, result) {
  257. result.value = fn(lhs.value, rhs);
  258. }
  259. } else {
  260. wrapper = function VectorOperator_Ref_Ref (lhs, rhs, result) {
  261. result.value = fn(lhs.value, rhs.value);
  262. }
  263. }
  264. $.Method({Static: true , Public: true }, staticMethodName,
  265. new JSIL.MethodSignature(null, [
  266. leftScalar ? tLeft : makeRef(tLeft),
  267. rightScalar ? tRight : makeRef(tRight),
  268. makeRef(tResult)
  269. ], []),
  270. wrapper
  271. );
  272. },
  273. makeLogicOperator: function ($, name, operator, bindingOperator, dataMembers, tVector) {
  274. var body = [];
  275. body.push("return (");
  276. for (var i = 0; i < dataMembers.length; i++) {
  277. var dataMember = dataMembers[i];
  278. var line = " (lhs." + dataMember + " ";
  279. line += operator;
  280. line += " rhs." + dataMember + ") ";
  281. if (i < dataMembers.length - 1)
  282. line += bindingOperator;
  283. body.push(line);
  284. }
  285. body.push(");")
  286. var fn = vectorUtil.makeOperatorCore(name, tVector, body, 2, false, false);
  287. $.Method({Static: true , Public: true }, name,
  288. new JSIL.MethodSignature($.Boolean, [tVector, tVector], []),
  289. fn
  290. );
  291. },
  292. makeNegationOperator: function ($, dataMembers, tVector) {
  293. var body = [];
  294. body.push("var result = this.create();");
  295. for (var i = 0; i < dataMembers.length; i++) {
  296. var dataMember = dataMembers[i];
  297. var line = "result." + dataMember + " = -value." + dataMember + ";";
  298. body.push(line);
  299. }
  300. body.push("return result;");
  301. var fn = vectorUtil.makeOperatorCore("op_UnaryNegation", tVector, body, 1, false, false);
  302. fn = vectorUtil.bindToPrototype(fn, tVector);
  303. $.Method({Static: true , Public: true }, "op_UnaryNegation",
  304. new JSIL.MethodSignature(tVector, [tVector], []),
  305. fn
  306. );
  307. },
  308. makeLengthGetter: function ($, name, isSquared, dataMembers, tVector) {
  309. var body = [];
  310. body.push("return " + (isSquared ? "(" : "Math.sqrt("));
  311. for (var i = 0; i < dataMembers.length; i++) {
  312. var dataMember = dataMembers[i];
  313. var line = " (this." + dataMember + " * this." + dataMember + ")";
  314. if (i < dataMembers.length - 1)
  315. line += " + ";
  316. body.push(line);
  317. }
  318. body.push(");");
  319. var fn = vectorUtil.makeOperatorCore(name, tVector, body, 0);
  320. $.Method({Static: false, Public: true }, name,
  321. new JSIL.MethodSignature($.Single, [], []),
  322. fn
  323. );
  324. },
  325. makeDistanceFunction: function ($, name, isSquared, dataMembers, tVector) {
  326. var body = [];
  327. body.push("var result = 0, current;");
  328. for (var i = 0; i < dataMembers.length; i++) {
  329. var dataMember = dataMembers[i];
  330. body.push("current = (rhs." + dataMember + " - lhs." + dataMember + ");");
  331. body.push("result += (current * current);");
  332. }
  333. if (isSquared)
  334. body.push("return result;");
  335. else
  336. body.push("return Math.sqrt(result);");
  337. var fn = vectorUtil.makeOperatorCore(name, tVector, body, 2);
  338. $.Method({Static: true, Public: true }, name,
  339. new JSIL.MethodSignature($.Single, [tVector, tVector], []),
  340. fn
  341. );
  342. },
  343. makeNormalizer: function ($, dataMembers, tVector) {
  344. var body = [];
  345. body.push("var factor = 1.0 / this.Length();");
  346. for (var i = 0; i < dataMembers.length; i++) {
  347. var dataMember = dataMembers[i];
  348. var line = "this." + dataMember + " *= factor;";
  349. body.push(line);
  350. }
  351. var fn = vectorUtil.makeOperatorCore("Normalize", tVector, body, 0);
  352. $.Method({Static: false, Public: true }, "Normalize",
  353. new JSIL.MethodSignature(null, [], []),
  354. fn
  355. );
  356. $.Method({Static: true , Public: true }, "Normalize",
  357. new JSIL.MethodSignature(tVector, [tVector], []),
  358. function (v) {
  359. fn.call(v);
  360. return v;
  361. }
  362. );
  363. },
  364. makeLengthMethods: function ($, dataMembers, tVector) {
  365. vectorUtil.makeLengthGetter($, "LengthSquared", true, dataMembers, tVector);
  366. vectorUtil.makeLengthGetter($, "Length", false, dataMembers, tVector);
  367. vectorUtil.makeDistanceFunction($, "DistanceSquared", true, dataMembers, tVector);
  368. vectorUtil.makeDistanceFunction($, "Distance", false, dataMembers, tVector);
  369. vectorUtil.makeNormalizer($, dataMembers, tVector);
  370. },
  371. makeLerpMethod: function ($, dataMembers, tVector) {
  372. var name = "Lerp";
  373. var body = [];
  374. body.push("var result = lhs.MemberwiseClone();");
  375. for (var i = 0; i < dataMembers.length; i++) {
  376. var dataMember = dataMembers[i];
  377. body.push("result." + dataMember + " += (rhs." + dataMember + " - lhs." + dataMember + ") * amount;");
  378. }
  379. body.push("return result;");
  380. var fn = vectorUtil.makeOperatorCore(name, tVector, body, 3);
  381. $.Method({Static: true, Public: true }, name,
  382. new JSIL.MethodSignature(tVector, [tVector, tVector, $.Single], []),
  383. fn
  384. );
  385. },
  386. makeOperators: function ($, dataMembers, tVector) {
  387. var operators = [
  388. ["op_Addition", "+", false, "Add"],
  389. ["op_Subtraction", "-", false, "Subtract"],
  390. ["op_Division", "/", true, "Divide"],
  391. ["op_Multiply", "*", true, "Multiply"]
  392. ];
  393. for (var i = 0; i < operators.length; i++) {
  394. var name = operators[i][0];
  395. var operator = operators[i][1];
  396. var withScalar = operators[i][2];
  397. var staticMethodName = operators[i][3];
  398. vectorUtil.makeArithmeticOperator($, name, staticMethodName, operator, dataMembers, tVector, tVector, tVector);
  399. if (withScalar) {
  400. var nameSuffixed = name + "Scalar";
  401. var staticMethodNameSuffixed = staticMethodName + "Scalar";
  402. vectorUtil.makeArithmeticOperator($, nameSuffixed, staticMethodNameSuffixed, operator, dataMembers, tVector, $.Single, tVector);
  403. var nameSuffixed2 = nameSuffixed + "Left";
  404. var staticMethodNameSuffixed2 = staticMethodNameSuffixed + "Left";
  405. vectorUtil.makeArithmeticOperator($, nameSuffixed2, staticMethodNameSuffixed2, operator, dataMembers, $.Single, tVector, tVector);
  406. }
  407. }
  408. vectorUtil.makeNegationOperator($, dataMembers, tVector);
  409. vectorUtil.makeLogicOperator($, "op_Equality", "===", "&&", dataMembers, tVector);
  410. vectorUtil.makeLogicOperator($, "op_Inequality", "!==", "||", dataMembers, tVector);
  411. vectorUtil.makeLengthMethods($, dataMembers, tVector);
  412. vectorUtil.makeLerpMethod($, dataMembers, tVector);
  413. },
  414. makeConstants: function ($, tVector, constants) {
  415. var makeGetter = function (values) {
  416. var state = null;
  417. return function () {
  418. if (state === null)
  419. state = JSIL.CreateInstanceOfType(
  420. tVector.get().__Type__, values
  421. );
  422. return state;
  423. }
  424. };
  425. for (var k in constants) {
  426. var values = constants[k];
  427. var getter = makeGetter(values);
  428. $.Method({Static: true , Public: true}, "get_" + k,
  429. new JSIL.MethodSignature(tVector, [], []),
  430. getter
  431. );
  432. }
  433. }
  434. };
  435. JSIL.ImplementExternals("Microsoft.Xna.Framework.Vector2", function ($) {
  436. vectorUtil.makeConstants(
  437. $, $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), {
  438. "UnitX": [1, 0],
  439. "UnitY": [0, 1],
  440. "Zero": [0, 0],
  441. "One": [1, 1]
  442. }
  443. );
  444. vectorUtil.makeOperators(
  445. $, ["X", "Y"], $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2")
  446. );
  447. $.Method({Static:true , Public:true }, "Transform",
  448. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
  449. function Transform (position, matrix) {
  450. var result = Object.create(Microsoft.Xna.Framework.Vector2.prototype);
  451. result.X = (position.X * matrix.xScale) + matrix.xTranslation;
  452. result.Y = (position.Y * matrix.yScale) + matrix.yTranslation;
  453. return result;
  454. }
  455. );
  456. $.Method({Static:true , Public:true }, "Dot",
  457. (new JSIL.MethodSignature($.Single, [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector2")], [])),
  458. function Dot (vector1, vector2) {
  459. return vector1.X * vector2.X + vector1.Y * vector2.Y;
  460. }
  461. );
  462. $.Method({
  463. Static: false,
  464. Public: true
  465. }, ".ctor", new JSIL.MethodSignature(null, [$.Single, $.Single], []), function Vector2_ctor (x, y) {
  466. this.X = x;
  467. this.Y = y;
  468. });
  469. $.Method({
  470. Static: false,
  471. Public: true
  472. }, ".ctor", new JSIL.MethodSignature(null, [$.Single], []), function Vector2_ctor (value) {
  473. this.X = this.Y = value;
  474. });
  475. });
  476. JSIL.ImplementExternals("Microsoft.Xna.Framework.Vector3", function ($) {
  477. vectorUtil.makeConstants(
  478. $, $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), {
  479. "Backward": [0, 0, 1],
  480. "Forward": [0, 0, -1],
  481. "Left": [-1, 0, 0],
  482. "Right": [1, 0, 0],
  483. "Up": [0, 1, 0],
  484. "Down": [0, -1, 0],
  485. "UnitX": [1, 0, 0],
  486. "UnitY": [0, 1, 0],
  487. "UnitZ": [0, 0, 1],
  488. "Zero": [0, 0, 0],
  489. "One": [1, 1, 1]
  490. }
  491. );
  492. vectorUtil.makeOperators(
  493. $, ["X", "Y", "Z"], $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")
  494. );
  495. $.Method({
  496. Static: false,
  497. Public: true
  498. }, ".ctor", new JSIL.MethodSignature(null, [$.Single, $.Single, $.Single], []), function Vector3_ctor (x, y, z) {
  499. this.X = x;
  500. this.Y = y;
  501. this.Z = z;
  502. });
  503. $.Method({
  504. Static: false,
  505. Public: true
  506. }, ".ctor", new JSIL.MethodSignature(null, [$.Single], []), function Vector3_ctor (value) {
  507. this.X = this.Y = this.Z = value;
  508. });
  509. $.Method({
  510. Static: false,
  511. Public: true
  512. }, ".ctor", new JSIL.MethodSignature(null, [], []), function Vector3_ctor (xy, z) {
  513. this.X = xy.X;
  514. this.Y = xy.Y;
  515. this.Z = z;
  516. });
  517. $.Method({Static:true , Public:true }, "Transform",
  518. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
  519. function Transform (position, matrix) {
  520. var result = Object.create(Microsoft.Xna.Framework.Vector3.prototype);
  521. result.X = (position.X * matrix.xScale) + matrix.xTranslation;
  522. result.Y = (position.Y * matrix.yScale) + matrix.yTranslation;
  523. result.Z = (position.Z * matrix.zScale) + matrix.zTranslation;
  524. return result;
  525. }
  526. );
  527. });
  528. JSIL.ImplementExternals("Microsoft.Xna.Framework.Vector4", function ($) {
  529. vectorUtil.makeConstants(
  530. $, $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4"), {
  531. "Zero": [0, 0, 0, 0],
  532. "One": [1, 1, 1, 1]
  533. }
  534. );
  535. vectorUtil.makeOperators(
  536. $, ["X", "Y", "Z", "W"], $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4")
  537. );
  538. $.Method({
  539. Static: false,
  540. Public: true
  541. }, ".ctor", new JSIL.MethodSignature(null, [$.Single, $.Single, $.Single, $.Single], []), function Vector4_ctor (x, y, z, w) {
  542. this.X = x;
  543. this.Y = y;
  544. this.Z = z;
  545. this.W = w;
  546. });
  547. $.Method({
  548. Static: false,
  549. Public: true
  550. }, ".ctor", new JSIL.MethodSignature(null, [], []), function Vector4_ctor (xy, z, w) {
  551. this.X = xy.X;
  552. this.Y = xy.Y;
  553. this.Z = z;
  554. this.W = w;
  555. });
  556. $.Method({
  557. Static: false,
  558. Public: true
  559. }, ".ctor", new JSIL.MethodSignature(null, [], []), function Vector4_ctor (xyz, w) {
  560. this.X = xyz.X;
  561. this.Y = xyz.Y;
  562. this.Z = xyz.Z;
  563. this.W = w;
  564. });
  565. $.Method({
  566. Static: false,
  567. Public: true
  568. }, ".ctor", new JSIL.MethodSignature(null, [$.Single], []), function Vector4_ctor (value) {
  569. this.X = this.Y = this.Z = this.W = value;
  570. });
  571. $.Method({Static:true , Public:true }, "Transform",
  572. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector4"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
  573. function Transform (position, matrix) {
  574. var result = Object.create(Microsoft.Xna.Framework.Vector4.prototype);
  575. result.X = (position.X * matrix.xScale) + matrix.xTranslation;
  576. result.Y = (position.Y * matrix.yScale) + matrix.yTranslation;
  577. result.Z = (position.Z * matrix.zScale) + matrix.zTranslation;
  578. result.W = (position.W * matrix.wScale) + matrix.wTranslation;
  579. return result;
  580. }
  581. );
  582. });
  583. JSIL.ImplementExternals("Microsoft.Xna.Framework.Matrix", function ($) {
  584. var matrix = $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix");
  585. $.Method({
  586. Static: true,
  587. Public: true
  588. }, ".cctor2", new JSIL.MethodSignature(null, [], []), function () {
  589. // FIXME
  590. var identity = Microsoft.Xna.Framework.Matrix._identity = new Microsoft.Xna.Framework.Matrix();
  591. identity.xTranslation = identity.yTranslation = identity.zTranslation = 0;
  592. identity.xRotation = identity.yRotation = identity.zRotation = 0;
  593. identity.xScale = identity.yScale = identity.zScale = 1;
  594. });
  595. $.RawMethod(false, "__CopyMembers__",
  596. function Matrix_CopyMembers (source, target) {
  597. target.xScale = source.xScale || 0;
  598. target.yScale = source.yScale || 0;
  599. target.zScale = source.zScale || 0;
  600. target.xTranslation = source.xTranslation || 0;
  601. target.yTranslation = source.yTranslation || 0;
  602. target.zTranslation = source.zTranslation || 0;
  603. target.xRotation = source.xRotation || 0;
  604. target.yRotation = source.yRotation || 0;
  605. target.zRotation = source.zRotation || 0;
  606. }
  607. );
  608. $.Method({Static:true , Public:true }, "get_Identity",
  609. (new JSIL.MethodSignature(matrix, [], [])),
  610. function get_Identity () {
  611. return Microsoft.Xna.Framework.Matrix._identity;
  612. }
  613. );
  614. $.Method({Static:true , Public:true }, "CreateLookAt",
  615. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  616. $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3"),
  617. $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")
  618. ], [])),
  619. function CreateLookAt (cameraPosition, cameraTarget, cameraUpVector) {
  620. // FIXME
  621. return Microsoft.Xna.Framework.Matrix._identity;
  622. }
  623. );
  624. $.Method({Static:true , Public:true }, "CreateLookAt",
  625. (new JSIL.MethodSignature(null, [
  626. $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")]), $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")]),
  627. $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")]), $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
  628. ], [])),
  629. function CreateLookAt (/* ref */ cameraPosition, /* ref */ cameraTarget, /* ref */ cameraUpVector, /* ref */ result) {
  630. // FIXME
  631. result.value = Microsoft.Xna.Framework.Matrix._identity;
  632. }
  633. );
  634. $.Method({Static:true , Public:true }, "CreateOrthographic",
  635. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  636. $.Single, $.Single,
  637. $.Single, $.Single
  638. ], [])),
  639. function CreateOrthographic (width, height, zNearPlane, zFarPlane) {
  640. // FIXME
  641. return Microsoft.Xna.Framework.Matrix._identity;
  642. }
  643. );
  644. $.Method({Static:true , Public:true }, "CreateOrthographic",
  645. (new JSIL.MethodSignature(null, [
  646. $.Single, $.Single,
  647. $.Single, $.Single,
  648. $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
  649. ], [])),
  650. function CreateOrthographic (width, height, zNearPlane, zFarPlane, /* ref */ result) {
  651. // FIXME
  652. result.value = Microsoft.Xna.Framework.Matrix._identity;
  653. }
  654. );
  655. $.Method({Static:true , Public:true }, "CreateOrthographicOffCenter",
  656. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  657. $.Single, $.Single,
  658. $.Single, $.Single,
  659. $.Single, $.Single
  660. ], [])),
  661. function CreateOrthographicOffCenter (left, right, bottom, top, zNearPlane, zFarPlane) {
  662. // FIXME
  663. return Microsoft.Xna.Framework.Matrix._identity;
  664. }
  665. );
  666. $.Method({Static:true , Public:true }, "CreateOrthographicOffCenter",
  667. (new JSIL.MethodSignature(null, [
  668. $.Single, $.Single,
  669. $.Single, $.Single,
  670. $.Single, $.Single,
  671. $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
  672. ], [])),
  673. function CreateOrthographicOffCenter (left, right, bottom, top, zNearPlane, zFarPlane, /* ref */ result) {
  674. // FIXME
  675. result.value = Microsoft.Xna.Framework.Matrix._identity;
  676. }
  677. );
  678. $.Method({Static:true , Public:true }, "CreatePerspective",
  679. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  680. $.Single, $.Single,
  681. $.Single, $.Single
  682. ], [])),
  683. function CreatePerspective (width, height, nearPlaneDistance, farPlaneDistance) {
  684. // FIXME
  685. return Microsoft.Xna.Framework.Matrix._identity;
  686. }
  687. );
  688. $.Method({Static:true , Public:true }, "CreatePerspective",
  689. (new JSIL.MethodSignature(null, [
  690. $.Single, $.Single,
  691. $.Single, $.Single,
  692. $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
  693. ], [])),
  694. function CreatePerspective (width, height, nearPlaneDistance, farPlaneDistance, /* ref */ result) {
  695. // FIXME
  696. result.value = Microsoft.Xna.Framework.Matrix._identity;
  697. }
  698. );
  699. $.Method({Static:true , Public:true }, "CreatePerspectiveFieldOfView",
  700. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  701. $.Single, $.Single,
  702. $.Single, $.Single
  703. ], [])),
  704. function CreatePerspectiveFieldOfView (fieldOfView, aspectRatio, nearPlaneDistance, farPlaneDistance) {
  705. // FIXME
  706. return Microsoft.Xna.Framework.Matrix._identity;
  707. }
  708. );
  709. $.Method({Static:true , Public:true }, "CreatePerspectiveFieldOfView",
  710. (new JSIL.MethodSignature(null, [
  711. $.Single, $.Single,
  712. $.Single, $.Single,
  713. $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
  714. ], [])),
  715. function CreatePerspectiveFieldOfView (fieldOfView, aspectRatio, nearPlaneDistance, farPlaneDistance, /* ref */ result) {
  716. // FIXME
  717. result.value = Microsoft.Xna.Framework.Matrix._identity;
  718. }
  719. );
  720. $.Method({Static:true , Public:true }, "CreatePerspectiveOffCenter",
  721. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  722. $.Single, $.Single,
  723. $.Single, $.Single,
  724. $.Single, $.Single
  725. ], [])),
  726. function CreatePerspectiveOffCenter (left, right, bottom, top, nearPlaneDistance, farPlaneDistance) {
  727. // FIXME
  728. return Microsoft.Xna.Framework.Matrix._identity;
  729. }
  730. );
  731. $.Method({Static:true , Public:true }, "CreatePerspectiveOffCenter",
  732. (new JSIL.MethodSignature(null, [
  733. $.Single, $.Single,
  734. $.Single, $.Single,
  735. $.Single, $.Single,
  736. $jsilcore.TypeRef("JSIL.Reference", [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")])
  737. ], [])),
  738. function CreatePerspectiveOffCenter (left, right, bottom, top, nearPlaneDistance, farPlaneDistance, /* ref */ result) {
  739. // FIXME
  740. result.value = Microsoft.Xna.Framework.Matrix._identity;
  741. }
  742. );
  743. $.Method({Static:true , Public:true }, "CreateRotationX",
  744. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
  745. function CreateRotationX (radians) {
  746. // FIXME
  747. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  748. result.xRotation = radians;
  749. return result;
  750. }
  751. );
  752. $.Method({Static:true , Public:true }, "CreateRotationY",
  753. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
  754. function CreateRotationY (radians) {
  755. // FIXME
  756. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  757. result.yRotation = radians;
  758. return result;
  759. }
  760. );
  761. $.Method({Static:true , Public:true }, "CreateRotationZ",
  762. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
  763. function CreateRotationZ (radians) {
  764. // FIXME
  765. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  766. result.zRotation = radians;
  767. return result;
  768. }
  769. );
  770. $.Method({Static:true , Public:true }, "CreateScale",
  771. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")], [])),
  772. function CreateScale (scales) {
  773. // FIXME
  774. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  775. result.xScale = scales.X;
  776. result.yScale = scales.Y;
  777. result.zScale = scales.Z;
  778. return result;
  779. }
  780. );
  781. $.Method({Static:true , Public:true }, "CreateScale",
  782. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$.Single], [])),
  783. function CreateScale (scale) {
  784. // FIXME
  785. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  786. result.xScale = scale;
  787. result.yScale = scale;
  788. result.zScale = scale;
  789. return result;
  790. }
  791. );
  792. $.Method({Static:true , Public:true }, "CreateScale",
  793. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  794. $.Single, $.Single,
  795. $.Single
  796. ], [])),
  797. function CreateScale (xScale, yScale, zScale) {
  798. // FIXME
  799. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  800. result.xScale = xScale;
  801. result.yScale = yScale;
  802. result.zScale = zScale;
  803. return result;
  804. }
  805. );
  806. $.Method({Static:true , Public:true }, "CreateTranslation",
  807. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Vector3")], [])),
  808. function CreateTranslation (position) {
  809. // FIXME
  810. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  811. result.xTranslation = position.X;
  812. result.yTranslation = position.Y;
  813. result.zTranslation = position.Z;
  814. return result;
  815. }
  816. );
  817. $.Method({Static:true , Public:true }, "CreateTranslation",
  818. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [
  819. $.Single, $.Single,
  820. $.Single
  821. ], [])),
  822. function CreateTranslation (xPosition, yPosition, zPosition) {
  823. // FIXME
  824. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  825. result.xTranslation = xPosition;
  826. result.yTranslation = yPosition;
  827. result.zTranslation = zPosition;
  828. return result;
  829. }
  830. );
  831. $.Method({Static:true , Public:true }, "Invert",
  832. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
  833. function Invert (matrix) {
  834. // FIXME
  835. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  836. result.xTranslation = -matrix.xTranslation;
  837. result.yTranslation = -matrix.yTranslation;
  838. result.zTranslation = -matrix.zTranslation;
  839. result.xScale = 1 / (matrix.xScale + 0.000001);
  840. result.yScale = 1 / (matrix.yScale + 0.000001);
  841. result.zScale = 1 / (matrix.zScale + 0.000001);
  842. return result;
  843. }
  844. );
  845. $.Method({Static:true , Public:true }, "op_Multiply",
  846. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), [$xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix"), $xnaasms[0].TypeRef("Microsoft.Xna.Framework.Matrix")], [])),
  847. function Multiply (matrix1, matrix2) {
  848. // FIXME
  849. var result = Microsoft.Xna.Framework.Matrix._identity.MemberwiseClone();
  850. result.xTranslation = matrix1.xTranslation + matrix2.xTranslation;
  851. result.yTranslation = matrix1.yTranslation + matrix2.yTranslation;
  852. result.zTranslation = matrix1.zTranslation + matrix2.zTranslation;
  853. result.xScale = matrix1.xScale * matrix2.xScale;
  854. result.yScale = matrix1.yScale * matrix2.yScale;
  855. result.zScale = matrix1.zScale * matrix2.zScale;
  856. return result;
  857. }
  858. );
  859. });
  860. JSIL.ImplementExternals("Microsoft.Xna.Framework.GameServiceContainer", function ($) {
  861. $.Method({
  862. Static: false,
  863. Public: true
  864. }, ".ctor", new JSIL.MethodSignature(null, [], []), function () {});
  865. });
  866. JSIL.ImplementExternals("Microsoft.Xna.Framework.GameComponentCollection", function ($) {
  867. $.RawMethod(false, "$internalCtor", function (game) {
  868. this._game = game;
  869. this._ctor();
  870. });
  871. $.RawMethod(false, "$OnItemAdded", function (item) {
  872. if (this._game.initialized) {
  873. if (typeof (item.Initialize) === "function")
  874. item.Initialize();
  875. }
  876. });
  877. });
  878. JSIL.ImplementExternals("Microsoft.Xna.Framework.Game", function ($) {
  879. $.Method({Static: false, Public: true}, "ForceQuit",
  880. new JSIL.MethodSignature(null, [], []),
  881. function () {
  882. Microsoft.Xna.Framework.Game._QuitForced = true;
  883. }
  884. );
  885. $.Method({Static:false, Public:true }, ".ctor",
  886. (new JSIL.MethodSignature(null, [], [])),
  887. function _ctor () {
  888. var tContentManager = JSIL.GetTypeFromAssembly(
  889. $xnaasms.xna, "Microsoft.Xna.Framework.Content.ContentManager", [], true
  890. );
  891. var tGameTime = JSIL.GetTypeFromAssembly(
  892. $xnaasms.xnaGame, "Microsoft.Xna.Framework.GameTime", [], true
  893. );
  894. this.gameServices = new Microsoft.Xna.Framework.GameServiceContainer();
  895. this.content = JSIL.CreateInstanceOfType(tContentManager, [this.gameServices]);
  896. this.components = JSIL.CreateInstanceOfType(
  897. Microsoft.Xna.Framework.GameComponentCollection.__Type__, "$internalCtor", [this]
  898. );
  899. this.targetElapsedTime = System.TimeSpan.FromTicks(System.Int64.FromInt32(166667));
  900. this.isFixedTimeStep = true;
  901. this.forceElapsedTimeToZero = true;
  902. this._isDead = false;
  903. this.initialized = false;
  904. if (typeof (Date.now) === "function") {
  905. Object.defineProperty(this, "_GetNow", {
  906. configurable: true,
  907. enumerable: true,
  908. value: Date.now
  909. });
  910. }
  911. this._runHandle = null;
  912. this._gameTime = JSIL.CreateInstanceOfType(tGameTime, null);
  913. this._lastFrame = this._nextFrame = this._started = 0;
  914. }
  915. );
  916. $.Method({Static:false, Public:true }, "get_Components",
  917. (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameComponentCollection"), [], [])),
  918. function get_Components () {
  919. return this.components;
  920. }
  921. );
  922. $.Method({Static:false, Public:true }, "get_Content",
  923. (new JSIL.MethodSignature($xnaasms[0].TypeRef("Microsoft.Xna.Framework.Content.ContentManager"), [], [])),
  924. function get_Content () {
  925. return this.content;
  926. }
  927. );
  928. $.Method({Static:false, Public:true }, "get_GraphicsDevice",
  929. (new JSIL.MethodSignature($jsilxna.graphicsRef("Microsoft.Xna.Framework.Graphics.GraphicsDevice"), [], [])),
  930. function get_GraphicsDevice () {
  931. return this.graphicsDeviceService.GraphicsDevice;
  932. }
  933. );
  934. $.Method({Static:false, Public:true }, "get_IsActive",
  935. (new JSIL.MethodSignature($.Boolean, [], [])),
  936. function get_IsActive () {
  937. return JSIL.Host.isPageVisible() && !Microsoft.Xna.Framework.Game._QuitForced && !this._isDead;
  938. }
  939. );
  940. $.Method({Static:false, Public:true }, "get_IsFixedTimeStep",
  941. (new JSIL.MethodSignature($.Boolean, [], [])),
  942. function get_IsFixedTimeStep () {
  943. return this.isFixedTimeStep;
  944. }
  945. );
  946. $.Method({Static:false, Public:true }, "get_TargetElapsedTime",
  947. (new JSIL.MethodSignature($xnaasms[5].TypeRef("System.TimeSpan"), [], [])),
  948. function get_TargetElapsedTime () {
  949. return this.targetElapsedTime;
  950. }
  951. );
  952. $.Method({Static:false, Public:true }, "get_Services",
  953. (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameServiceContainer"), [], [])),
  954. function get_Services () {
  955. return this.gameServices;
  956. }
  957. );
  958. $.Method({Static:false, Public:true }, "get_Window",
  959. (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameWindow"), [], [])),
  960. function get_Window () {
  961. // FIXME
  962. if (!this._window)
  963. this._window = new Microsoft.Xna.Framework.GameWindow();
  964. return this._window;
  965. }
  966. );
  967. $.Method({Static:false, Public:false}, "get_IsMouseVisible",
  968. (new JSIL.MethodSignature($.Boolean, [], [])),
  969. function get_IsMouseVisible () {
  970. var oc = this.graphicsDeviceService.GraphicsDevice.originalCanvas;
  971. return (oc.style.cursor !== "none");
  972. }
  973. );
  974. $.Method({Static:false, Public:true }, "set_IsMouseVisible",
  975. (new JSIL.MethodSignature(null, [$.Boolean], [])),
  976. function set_IsMouseVisible (value) {
  977. var oc = this.graphicsDeviceService.GraphicsDevice.originalCanvas;
  978. oc.style.cursor = value ? "default" : "none";
  979. }
  980. );
  981. $.Method({Static:false, Public:true }, "set_IsFixedTimeStep",
  982. (new JSIL.MethodSignature(null, [$.Boolean], [])),
  983. function set_IsFixedTimeStep (value) {
  984. this.isFixedTimeStep = value;
  985. }
  986. );
  987. $.Method({Static:false, Public:true }, "set_TargetElapsedTime",
  988. (new JSIL.MethodSignature(null, [$xnaasms[5].TypeRef("System.TimeSpan")], [])),
  989. function set_TargetElapsedTime (value) {
  990. this.targetElapsedTime = value;
  991. }
  992. );
  993. $.Method({
  994. Static: false,
  995. Public: true
  996. }, "Initialize", new JSIL.MethodSignature(null, [], []), function () {
  997. this.initialized = true;
  998. for (var i = 0, l = this.components._size; i < l; i++) {
  999. var component = this.components._items[i];
  1000. component.Initialize();
  1001. }
  1002. this.LoadContent();
  1003. });
  1004. $.Method({
  1005. Static: false,
  1006. Public: true
  1007. }, "LoadContent", new JSIL.MethodSignature(null, [], []), function () {
  1008. });
  1009. $.Method({
  1010. Static: false,
  1011. Public: true
  1012. }, "UnloadContent", new JSIL.MethodSignature(null, [], []), function () {
  1013. });
  1014. $.Method({
  1015. Static: false,
  1016. Public: true
  1017. }, "ResetElapsedTime", new JSIL.MethodSignature(null, [], []), function () {
  1018. this.forceElapsedTimeToZero = true;
  1019. });
  1020. $.RawMethod(false, "$ComponentsOfType", function (type) {
  1021. var result = new Array();
  1022. for (var i = 0, l = this.components._size; i < l; i++) {
  1023. var item = this.components._items[i];
  1024. if (type.$Is(item))
  1025. result.push(item);
  1026. }
  1027. return result;
  1028. });
  1029. var cmp = function (lhs, rhs) {
  1030. if (lhs > rhs)
  1031. return 1;
  1032. else if (rhs > lhs)
  1033. return -1;
  1034. else
  1035. return 0;
  1036. };
  1037. $.Method({Static:false, Public:false}, "Draw",
  1038. (new JSIL.MethodSignature(null, [$xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameTime")], [])),
  1039. function Game_Draw (gameTime) {
  1040. if (Microsoft.Xna.Framework.Game._QuitForced || this._isDead)
  1041. return;
  1042. var drawableComponents = this.$ComponentsOfType(Microsoft.Xna.Framework.IDrawable.__Type__);
  1043. drawableComponents.sort(function (lhs, rhs) {
  1044. return cmp(lhs.get_DrawOrder(), rhs.get_DrawOrder());
  1045. });
  1046. for (var i = 0, l = drawableComponents.length; i < l; i++) {
  1047. var drawable = drawableComponents[i];
  1048. if (drawable.Visible)
  1049. drawable.Draw(gameTime);
  1050. }
  1051. }
  1052. );
  1053. $.Method({Static:false, Public:false}, "Update",
  1054. (new JSIL.MethodSignature(null, [$xnaasms[1].TypeRef("Microsoft.Xna.Framework.GameTime")], [])),
  1055. function Game_Update (gameTime) {
  1056. if (Microsoft.Xna.Framework.Game._QuitForced || this._isDead)
  1057. return;
  1058. var updateableComponents = this.$ComponentsOfType(Microsoft.Xna.Framework.IUpdateable.__Type__);
  1059. updateableComponents.sort(function (lhs, rhs) {
  1060. return cmp(lhs.get_UpdateOrder(), rhs.get_UpdateOrder());
  1061. });
  1062. for (var i = 0, l = updateableComponents.length; i < l; i++) {
  1063. var updateable = updateableComponents[i];
  1064. if (updateable.Enabled)
  1065. updateable.Update(gameTime);
  1066. }
  1067. }
  1068. );
  1069. $.Method({
  1070. Static: false,
  1071. Public: true
  1072. }, "Run", new JSIL.MethodSignature(null, [], []), function () {
  1073. this._profilingMode = (document.location.search.indexOf("profile") >= 0);
  1074. this._balanceFPSCheckbox = (document.getElementById("balanceFramerate") || null);
  1075. if (this._balanceFPSCheckbox)
  1076. this._balanceFPSCheckbox.checked = !this._profilingMode;
  1077. Microsoft.Xna.Framework.Game._QuitForced = false;
  1078. this.Initialize();
  1079. this._QueueStep();
  1080. });
  1081. $.RawMethod(false, "_GetNow", function Game_GetNow () {
  1082. return (new Date()).getTime();
  1083. });
  1084. $.RawMethod(false, "_DeferCall", function Game_DeferCall (callback, lng) {
  1085. setTimeout(callback, 0);
  1086. });
  1087. $.RawMethod(false, "_QueueStep", function Game_EnqueueTick () {
  1088. if (Microsoft.Xna.Framework.Game._QuitForced || this._isDead)
  1089. return;
  1090. var self = this;
  1091. var stepCallback = self._Step.bind(self);
  1092. var forceSetTimeout = false ||
  1093. (document.location.search.indexOf("forceSetTimeout") >= 0);
  1094. var requestAnimationFrame = window.requestAnimationFrame ||
  1095. window.mozRequestAnimationFrame ||
  1096. window.webkitRequestAnimationFrame ||
  1097. window.msRequestAnimationFrame ||
  1098. window.oRequestAnimationFrame;
  1099. if (requestAnimationFrame && !forceSetTimeout) {
  1100. requestAnimationFrame(stepCallback);
  1101. } else {
  1102. var shouldStepCallback = function ShouldStep () {
  1103. var now = self._GetNow();
  1104. var delay = self._nextFrame - now;
  1105. if (delay <= 0)
  1106. stepCallback();
  1107. else
  1108. self._DeferCall(shouldStepCallback, delay >= 3);
  1109. };
  1110. // It's important that we use setTimeout at least once after every frame in order to let the browser pump messages
  1111. this._DeferCall(shouldStepCallback, true);
  1112. }
  1113. });
  1114. $.RawMethod(false, "_TimedUpdate", function Game_TimedUpdate (longFrame) {
  1115. var updateStarted = this._GetNow();
  1116. this.Update(this._gameTime);
  1117. var updateEnded = this._GetNow();
  1118. // Detect long updates and suppress frameskip.
  1119. if ((updateEnded - updateStarted) > longFrame) {
  1120. this.suppressFrameskip = true;
  1121. }
  1122. this._updateCount += 1;
  1123. });
  1124. $.RawMethod(false, "_ReportFPS", function Game_ReportFPS (now) {
  1125. this._lastSecond = now;
  1126. if (typeof (JSIL.Host.reportFps) === "function") {
  1127. var isWebGL = this.graphicsDeviceService.GraphicsDevice.context.isWebGL || false;
  1128. var cacheBytes = ($jsilxna.imageChannelCache.countBytes + $jsilxna.textCache.countBytes);
  1129. JSIL.Host.reportFps(
  1130. this._drawCount, this._updateCount,
  1131. cacheBytes, isWebGL
  1132. );
  1133. }
  1134. this._updateCount = this._drawCount = 0;
  1135. });
  1136. $.RawMethod(false, "_FixedTimeStep", function Game_FixedTimeStep (
  1137. elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame
  1138. ) {
  1139. var tInt64 = $jsilcore.System.Int64;
  1140. var frameLength64 = tInt64.FromNumber(frameDelay * millisecondInTicks);
  1141. this._gameTime.elapsedGameTime._ticks = frameLength64;
  1142. this._gameTime.elapsedGameTime.$invalidate();
  1143. elapsed += this._extraTime;
  1144. this._extraTime = 0;
  1145. if (elapsed > maxElapsedTimeMs)
  1146. elapsed = maxElapsedTimeMs;
  1147. var numFrames = Math.floor(elapsed / frameDelay);
  1148. if (numFrames < 1) {
  1149. numFrames = 1;
  1150. this._extraTime = elapsed - frameDelay;
  1151. } else {
  1152. this._extraTime = elapsed - (numFrames * frameDelay);
  1153. }
  1154. for (var i = 0; i < numFrames; i++) {
  1155. this._gameTime.totalGameTime._ticks = tInt64.op_Addition(
  1156. this._gameTime.totalGameTime._ticks, frameLength64, this._gameTime.totalGameTime._ticks
  1157. );
  1158. this._gameTime.totalGameTime.$invalidate();
  1159. this._TimedUpdate(longFrame);
  1160. }
  1161. });
  1162. $.RawMethod(false, "_VariableTimeStep", function Game_VariableTimeStep (
  1163. elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame
  1164. ) {
  1165. this._extraTime = 0;
  1166. this.suppressFrameskip = false;
  1167. if (elapsed > maxElapsedTimeMs)
  1168. elapsed = maxElapsedTimeMs;
  1169. var tInt64 = $jsilcore.System.Int64;
  1170. var elapsed64 = tInt64.FromNumber(elapsed * millisecondInTicks);
  1171. this._gameTime.elapsedGameTime._ticks = elapsed64;
  1172. this._gameTime.elapsedGameTime.$invalidate();
  1173. this._gameTime.totalGameTime._ticks = tInt64.op_Addition(
  1174. this._gameTime.totalGameTime._ticks, elapsed64, this._gameTime.totalGameTime._ticks
  1175. );
  1176. this._gameTime.totalGameTime.$invalidate();
  1177. this._TimedUpdate(longFrame);
  1178. });
  1179. $.RawMethod(false, "_RenderAFrame", function Game_RenderAFrame () {
  1180. var device = this.get_GraphicsDevice();
  1181. device.$UpdateViewport();
  1182. device.$Clear();
  1183. this.Draw(this._gameTime);
  1184. this._drawCount += 1;
  1185. });
  1186. $.RawMethod(false, "_Step", function Game_Step () {
  1187. var now = this._GetNow();
  1188. var frameDelay = this.targetElapsedTime.get_TotalMilliseconds();
  1189. if (frameDelay <= 0)
  1190. throw new Error("Game frame duration must be a positive, nonzero number!");
  1191. if (this._lastFrame === 0) {
  1192. var elapsed = frameDelay;
  1193. var total = 0;
  1194. this._started = now;
  1195. this._lastSecond = now;
  1196. this._updateCount = this._drawCount = 0;
  1197. this._extraTime = 0;
  1198. this.suppressFrameskip = true;
  1199. } else {
  1200. var elapsed = now - this._lastFrame;
  1201. var total = now - this._started;
  1202. }
  1203. if ((now - this._lastSecond) > 1000) {
  1204. this._ReportFPS(now);
  1205. $jsilxna.imageChannelCache.maybeEvictItems();
  1206. $jsilxna.textCache.maybeEvictItems();
  1207. }
  1208. if (this.forceElapsedTimeToZero) {
  1209. this.forceElapsedTimeToZero = false;
  1210. this._extraTime = 0;
  1211. elapsed = 0;
  1212. }
  1213. this._lastFrame = now;
  1214. this._nextFrame = now + frameDelay;
  1215. var millisecondInTicks = 10000;
  1216. var maxElapsedTimeMs = frameDelay * 4;
  1217. var longFrame = frameDelay * 3;
  1218. this._profilingMode = (document.location.search.indexOf("profile") >= 0);
  1219. if (this._balanceFPSCheckbox)
  1220. this._profilingMode = !this._balanceFPSCheckbox.checked;
  1221. var failed = true;
  1222. try {
  1223. if (this.isFixedTimeStep && !this.suppressFrameskip && !this._profilingMode) {
  1224. this._FixedTimeStep(elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame);
  1225. } else {
  1226. this._VariableTimeStep(elapsed, frameDelay, millisecondInTicks, maxElapsedTimeMs, longFrame);
  1227. }
  1228. this._RenderAFrame();
  1229. failed = false;
  1230. } finally {
  1231. if (failed || Microsoft.Xna.Framework.Game._QuitForced)
  1232. this.Exit();
  1233. else
  1234. this._QueueStep();
  1235. }
  1236. });
  1237. $.Method({
  1238. Static: false,
  1239. Public: true
  1240. }, "Exit", new JSIL.MethodSignature(null, [], []), function () {
  1241. this.Dispose();
  1242. });
  1243. $.Method({
  1244. Static: false,
  1245. Public: true
  1246. }, "Dispose", new JSIL.MethodSignature(null, [], []), function () {
  1247. if (this._runHandle !== null)
  1248. window.clearInterval(this._runHandle);
  1249. this._runHandle = null;
  1250. this.UnloadContent();
  1251. this._isDead = true;
  1252. try {
  1253. var canvas = JSIL.Host.getCanvas();
  1254. var ctx = canvas.getContext("2d") || canvas.getContext("webgl-2d");
  1255. ctx.setTransform(1, 0, 0, 1, 0, 0);
  1256. ctx.globalAlpha = 1;
  1257. ctx.globalCompositeOperation = "source-over";
  1258. ctx.fillStyle = "black";
  1259. ctx.fillRect(0, 0, 99999, 99999);
  1260. var fsb = document.getElementById("fullscreenButton");
  1261. if (fsb)
  1262. fsb.style.display = "none";
  1263. var stats = document.getElementById("stats");
  1264. if (stats)
  1265. stats.style.display = "none";
  1266. } catch (exc) {
  1267. }
  1268. });
  1269. });
  1270. JSIL.ImplementExternals("Microsoft.Xna.Framework.GameComponent", function ($) {
  1271. $.Method({Static:false, Public:true }, ".ctor",
  1272. (new JSIL.MethodSignature(null, [$xnaasms[1].TypeRef("Microsoft.Xna.Framework.Game")], [])),
  1273. function _ctor (game) {
  1274. this.enabled = true;
  1275. this.initialized = false;
  1276. this.game = game;
  1277. }
  1278. );
  1279. $.Method({Static:false, Public:true }, "get_UpdateOrder",
  1280. (new JSIL.MethodSignature($.Int32, [], [])),
  1281. function get_UpdateOrder () {
  1282. return 0;
  1283. }
  1284. );
  1285. $.Method({Static:false, Public:true }, "get_Enabled",
  1286. (new JSIL.MethodSignature($.Boolean, [], [])),
  1287. function get_Enabled () {
  1288. return this.enabled;
  1289. }
  1290. );
  1291. $.Method({Static:false, Public:true }, "get_Game",
  1292. (new JSIL.MethodSignature($xnaasms[1].TypeRef("Microsoft.Xna.Framework.Game"), [], [])),
  1293. function get_Game () {
  1294. return this.game;
  1295. }
  1296. );
  1297. $.Method({Static:false, Public:true }, "set_Enabled",
  1298. (new JSIL.MethodSignature(null, [$.Boolean], [])),
  1299. function set_Enabled (value) {
  1300. this.enabled = value;
  1301. }
  1302. );
  1303. $.Method({Static:false, Public:true }, "Initialize",
  1304. (new JSIL.MethodSignature(null, [], [])),
  1305. function Initialize () {
  1306. if (this.ini

Large files files are truncated, but you can click here to view the full file