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

/JSIL.Libraries/Sources/XNA/XNA4.js

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

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