Advertisement
Guest User

Seeded RNG Extension GDevelop

a guest
May 21st, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 11.10 KB | None | 0 0
  1. {
  2.   "author": "Arthur Pacaud (arthuro555)",
  3.   "description": "This Random Number Generator (RNG) is first created using a seed. If the seed is random, this generator will be too. But if you (for example) generate terrain using this as randomness source, you can reuse the same seed to get the exact same result again. \nUsage: If you use the same seed, idependent of the computer you will get the same numbers. \nExample: If the seed 66 returns with the first call 0,78948 and on the second call 0,3628, if you re set the seed to 66 and call it 2 times again, you will get on the first call 0,78948 and on the second call 0,3628 again.\nIf you now set the seed to 67, you will have another random output.",
  4.   "extensionNamespace": "",
  5.   "fullName": "Seeded RNG",
  6.   "name": "SeededRandom",
  7.   "shortDescription": "This Seeded Random Number Generator permits to generate always the same numbers out of one seed. Useful for recreating a random event.",
  8.   "tags": "RNG, Seed, Random, World Generation",
  9.   "version": "1.0.0",
  10.   "eventsFunctions": [
  11.     {
  12.       "description": "",
  13.       "fullName": "",
  14.       "functionType": "Action",
  15.       "name": "onFirstSceneLoaded",
  16.       "sentence": "",
  17.       "events": [
  18.         {
  19.           "disabled": false,
  20.           "folded": false,
  21.           "type": "BuiltinCommonInstructions::Comment",
  22.           "color": {
  23.             "b": 109,
  24.             "g": 230,
  25.             "r": 255,
  26.             "textB": 0,
  27.             "textG": 0,
  28.             "textR": 0
  29.           },
  30.           "comment": "Create the table of RNGs",
  31.           "comment2": ""
  32.         },
  33.         {
  34.           "disabled": false,
  35.           "folded": false,
  36.           "type": "BuiltinCommonInstructions::JsCode",
  37.           "inlineCode": "runtimeScene.rng = new Hashtable();\nruntimeScene.rng.getNewRNG = function(a, b, c, d) { return function() { var t = b << 9, r = a * 5; r = (r << 7 | r >>> 25) * 9; c ^= a; d ^= b; b ^= c; a ^= d; c ^= t; d = d << 11 | d >>> 21; return (r >>> 0) / 4294967296; } }\nruntimeScene.rng.getRNG = function(name) {\n    if(!this.containsKey(name))\n      this.put(name, new this.RNGClass());\n    return this.get(name);\n};\nruntimeScene.rng.RNGClass = function() {};\nruntimeScene.rng.RNGClass.prototype.random = function() {return Math.random()}; // In case the user forgot to give a seed fallback to Math.random\nruntimeScene.rng.RNGClass.prototype.setSeed = function(str) { for(var i = 0, h = 1779033703 ^ str.length; i < str.length; i++) h = Math.imul(h ^ str.charCodeAt(i), 3432918353), h = h << 13 | h >>> 19; this.seed = function() { h = Math.imul(h ^ h >>> 16, 2246822507); h = Math.imul(h ^ h >>> 13, 3266489909); return (h ^= h >>> 16) >>> 0; }; this.random = runtimeScene.rng.getNewRNG(this.seed(), this.seed(), this.seed(), this.seed()); };\n",
  38.           "parameterObjects": "",
  39.           "useStrict": true
  40.         }
  41.       ],
  42.       "parameters": [],
  43.       "objectGroups": []
  44.     },
  45.     {
  46.       "description": "Creates a new seeded random number generator. Resets it if it already exists.",
  47.       "fullName": "Create a Seeded RNG",
  48.       "functionType": "Action",
  49.       "name": "createGenerator",
  50.       "sentence": "Create RNG with name _PARAM1_ and seed _PARAM2_",
  51.       "events": [
  52.         {
  53.           "disabled": false,
  54.           "folded": false,
  55.           "type": "BuiltinCommonInstructions::Comment",
  56.           "color": {
  57.             "b": 109,
  58.             "g": 230,
  59.             "r": 255,
  60.             "textB": 0,
  61.             "textG": 0,
  62.             "textR": 0
  63.           },
  64.           "comment": "Gets a new or old generator and set it's seed.",
  65.           "comment2": ""
  66.         },
  67.         {
  68.           "disabled": false,
  69.           "folded": false,
  70.           "type": "BuiltinCommonInstructions::JsCode",
  71.           "inlineCode": "runtimeScene.rng.getRNG(eventsFunctionContext.getArgument(\"rngname\")).setSeed(eventsFunctionContext.getArgument(\"rngseed\"));\r\n",
  72.           "parameterObjects": "",
  73.           "useStrict": true
  74.         }
  75.       ],
  76.       "parameters": [
  77.         {
  78.           "codeOnly": false,
  79.           "defaultValue": "",
  80.           "description": "The RNG's name",
  81.           "longDescription": "",
  82.           "name": "rngname",
  83.           "optional": false,
  84.           "supplementaryInformation": "",
  85.           "type": "string"
  86.         },
  87.         {
  88.           "codeOnly": false,
  89.           "defaultValue": "",
  90.           "description": "The RNG's seed",
  91.           "longDescription": "",
  92.           "name": "rngseed",
  93.           "optional": false,
  94.           "supplementaryInformation": "",
  95.           "type": "string"
  96.         }
  97.       ],
  98.       "objectGroups": []
  99.     },
  100.     {
  101.       "description": "Same as Random() but seeded.",
  102.       "fullName": "Get Random seeded number",
  103.       "functionType": "Expression",
  104.       "name": "Random",
  105.       "sentence": "",
  106.       "events": [
  107.         {
  108.           "disabled": false,
  109.           "folded": false,
  110.           "type": "BuiltinCommonInstructions::Comment",
  111.           "color": {
  112.             "b": 109,
  113.             "g": 230,
  114.             "r": 255,
  115.             "textB": 0,
  116.             "textG": 0,
  117.             "textR": 0
  118.           },
  119.           "comment": "Random function from gd.js adapted",
  120.           "comment2": ""
  121.         },
  122.         {
  123.           "disabled": false,
  124.           "folded": false,
  125.           "type": "BuiltinCommonInstructions::JsCode",
  126.           "inlineCode": "let max = eventsFunctionContext.getArgument(\"max\");\nif (max <= 0) {\n    eventsFunctionContext.returnValue = 0;\n    return;\n}\neventsFunctionContext.returnValue = Math.floor(runtimeScene.rng.getRNG(eventsFunctionContext.getArgument(\"rngname\")).random() * (max + 1));\n",
  127.           "parameterObjects": "",
  128.           "useStrict": true
  129.         }
  130.       ],
  131.       "parameters": [
  132.         {
  133.           "codeOnly": false,
  134.           "defaultValue": "",
  135.           "description": "Name of the generator",
  136.           "longDescription": "",
  137.           "name": "rngname",
  138.           "optional": false,
  139.           "supplementaryInformation": "",
  140.           "type": "string"
  141.         },
  142.         {
  143.           "codeOnly": false,
  144.           "defaultValue": "",
  145.           "description": "Maximum",
  146.           "longDescription": "",
  147.           "name": "max",
  148.           "optional": false,
  149.           "supplementaryInformation": "",
  150.           "type": "expression"
  151.         }
  152.       ],
  153.       "objectGroups": []
  154.     },
  155.     {
  156.       "description": "Returns a random number between minimum and maximum. Same as RnadomIn Range.",
  157.       "fullName": "Seeded Random in Range",
  158.       "functionType": "Expression",
  159.       "name": "RandomInRange",
  160.       "sentence": "",
  161.       "events": [
  162.         {
  163.           "disabled": false,
  164.           "folded": false,
  165.           "type": "BuiltinCommonInstructions::Comment",
  166.           "color": {
  167.             "b": 109,
  168.             "g": 230,
  169.             "r": 255,
  170.             "textB": 0,
  171.             "textG": 0,
  172.             "textR": 0
  173.           },
  174.           "comment": "gdjs.randomInRange adapted for seeded generators",
  175.           "comment2": ""
  176.         },
  177.         {
  178.           "disabled": false,
  179.           "folded": false,
  180.           "type": "BuiltinCommonInstructions::JsCode",
  181.           "inlineCode": "function random(max) {\n    let max = eventsFunctionContext.getArgument(\"max\");\n    if (max <= 0) {\n        return 0;\n    }\n    return Math.floor(runtimeScene.rng.getRNG(eventsFunctionContext.getArgument(\"rngname\")).random() * (max + 1));\n}\n\neventsFunctionContext.returnValue = min + random(max - min); // return min if min >= max\n",
  182.           "parameterObjects": "",
  183.           "useStrict": true
  184.         }
  185.       ],
  186.       "parameters": [
  187.         {
  188.           "codeOnly": false,
  189.           "defaultValue": "",
  190.           "description": "The Generator's Name",
  191.           "longDescription": "",
  192.           "name": "rngname",
  193.           "optional": false,
  194.           "supplementaryInformation": "",
  195.           "type": "string"
  196.         },
  197.         {
  198.           "codeOnly": false,
  199.           "defaultValue": "",
  200.           "description": "Minimum value",
  201.           "longDescription": "",
  202.           "name": "min",
  203.           "optional": false,
  204.           "supplementaryInformation": "",
  205.           "type": "expression"
  206.         },
  207.         {
  208.           "codeOnly": false,
  209.           "defaultValue": "",
  210.           "description": "Maximum value",
  211.           "longDescription": "",
  212.           "name": "max",
  213.           "optional": false,
  214.           "supplementaryInformation": "",
  215.           "type": "expression"
  216.         }
  217.       ],
  218.       "objectGroups": []
  219.     },
  220.     {
  221.       "description": "",
  222.       "fullName": "UNIMPLEMENTED PLACEHOLDER",
  223.       "functionType": "Expression",
  224.       "name": "RandomWithStep",
  225.       "sentence": "",
  226.       "events": [
  227.         {
  228.           "disabled": false,
  229.           "folded": false,
  230.           "type": "BuiltinCommonInstructions::Comment",
  231.           "color": {
  232.             "b": 109,
  233.             "g": 230,
  234.             "r": 255,
  235.             "textB": 0,
  236.             "textG": 0,
  237.             "textR": 0
  238.           },
  239.           "comment": "UNIMPLEMENTED PLACEHOLDER",
  240.           "comment2": ""
  241.         }
  242.       ],
  243.       "parameters": [],
  244.       "objectGroups": []
  245.     },
  246.     {
  247.       "description": "",
  248.       "fullName": "UNIMPLEMENTED PLACEHOLDER",
  249.       "functionType": "Expression",
  250.       "name": "RandomFloat",
  251.       "sentence": "",
  252.       "events": [
  253.         {
  254.           "disabled": false,
  255.           "folded": false,
  256.           "type": "BuiltinCommonInstructions::Comment",
  257.           "color": {
  258.             "b": 109,
  259.             "g": 230,
  260.             "r": 255,
  261.             "textB": 0,
  262.             "textG": 0,
  263.             "textR": 0
  264.           },
  265.           "comment": "UNIMPLEMENTED PLACEHOLDER",
  266.           "comment2": ""
  267.         }
  268.       ],
  269.       "parameters": [],
  270.       "objectGroups": []
  271.     },
  272.     {
  273.       "description": "",
  274.       "fullName": "UNIMPLEMENTED PLACEHOLDER",
  275.       "functionType": "Expression",
  276.       "name": "RandomFloatInRange",
  277.       "sentence": "",
  278.       "events": [
  279.         {
  280.           "disabled": false,
  281.           "folded": false,
  282.           "type": "BuiltinCommonInstructions::Comment",
  283.           "color": {
  284.             "b": 109,
  285.             "g": 230,
  286.             "r": 255,
  287.             "textB": 0,
  288.             "textG": 0,
  289.             "textR": 0
  290.           },
  291.           "comment": "UNIMPLEMENTED PLACEHOLDER",
  292.           "comment2": ""
  293.         }
  294.       ],
  295.       "parameters": [],
  296.       "objectGroups": []
  297.     },
  298.     {
  299.       "description": "",
  300.       "fullName": "UNIMPLEMENTED PLACEHOLDER",
  301.       "functionType": "Expression",
  302.       "name": "RandomFloatWithStep",
  303.       "sentence": "",
  304.       "events": [
  305.         {
  306.           "disabled": false,
  307.           "folded": false,
  308.           "type": "BuiltinCommonInstructions::Comment",
  309.           "color": {
  310.             "b": 109,
  311.             "g": 230,
  312.             "r": 255,
  313.             "textB": 0,
  314.             "textG": 0,
  315.             "textR": 0
  316.           },
  317.           "comment": "UNIMPLEMENTED PLACEHOLDER",
  318.           "comment2": ""
  319.         }
  320.       ],
  321.       "parameters": [],
  322.       "objectGroups": []
  323.     }
  324.   ],
  325.   "eventsBasedBehaviors": []
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement