Browse Source

Fix RandomGenerator:setSeed;

bjorn 3 years ago
parent
commit
7f771e82a2
2 changed files with 453 additions and 32 deletions
  1. 443 32
      api/init.lua
  2. 10 0
      api/lovr/math/RandomGenerator/setSeed.lua

+ 443 - 32
api/init.lua

@@ -4611,7 +4611,7 @@ return {
           examples = {
           examples = {
             {
             {
               description = "Apply a postprocessing effect (wave) using a Canvas and a fragment shader.",
               description = "Apply a postprocessing effect (wave) using a Canvas and a fragment shader.",
-              code = "function lovr.load()\n  lovr.graphics.setBackgroundColor(.1, .1, .1)\n  canvas = lovr.graphics.newCanvas(lovr.headset.getDisplayDimensions())\n\n  wave = lovr.graphics.newShader([[\n    vec4 lovrMain() {\n      return lovrRVertex;\n    }\n  ]], [[\n    uniform float time;\n    vec4 lovrMain() {\n      uv.x += sin(uv.y * 10 + time * 4) * .01;\n      uv.y += cos(uv.x * 10 + time * 4) * .01;\n      return lovrGraphicsColor * lovrDiffuseColor * lovrVertexColor * texture(lovrDiffuseTexture, lovrTexCoord);\n    }\n  ]])\nend\n\nfunction lovr.update(dt)\n  wave:send('time', lovr.timer.getTime())\nend\n\nfunction lovr.draw()\n  -- Render the scene to the canvas instead of the headset.\n  canvas:renderTo(function()\n    lovr.graphics.clear()\n    local size = 5\n    for i = 1, size do\n      for j = 1, size do\n        for k = 1, size do\n          lovr.graphics.setColor(i / size, j / size, k / size)\n          local x, y, z = i - size / 2, j - size / 2, k - size / 2\n          lovr.graphics.cube('fill', x, y, z, .5)\n        end\n      end\n    end\n  end)\n\n  -- Render the canvas to the headset using a shader.\n  lovr.graphics.setColor(1, 1, 1)\n  lovr.graphics.setShader(wave)\n  lovr.graphics.fill(canvas:getTexture())\n  lovr.graphics.setShader()\nend"
+              code = "function lovr.load()\n  lovr.graphics.setBackgroundColor(.1, .1, .1)\n  canvas = lovr.graphics.newCanvas(lovr.headset.getDisplayDimensions())\n\n  wave = lovr.graphics.newShader([[\n    vec4 position(mat4 projection, mat4 transform, vec4 vertex) {\n      return projection * transform * vertex;\n    }\n  ]], [[\n    uniform float time;\n    vec4 color(vec4 gcolor, sampler2D image, vec2 uv) {\n      uv.x += sin(uv.y * 10 + time * 4) * .01;\n      uv.y += cos(uv.x * 10 + time * 4) * .01;\n      return lovrGraphicsColor * lovrDiffuseColor * lovrVertexColor * texture(lovrDiffuseTexture, uv);\n    }\n  ]])\nend\n\nfunction lovr.update(dt)\n  wave:send('time', lovr.timer.getTime())\nend\n\nfunction lovr.draw()\n  -- Render the scene to the canvas instead of the headset.\n  canvas:renderTo(function()\n    lovr.graphics.clear()\n    local size = 5\n    for i = 1, size do\n      for j = 1, size do\n        for k = 1, size do\n          lovr.graphics.setColor(i / size, j / size, k / size)\n          local x, y, z = i - size / 2, j - size / 2, k - size / 2\n          lovr.graphics.cube('fill', x, y, z, .5)\n        end\n      end\n    end\n  end)\n\n  -- Render the canvas to the headset using a shader.\n  lovr.graphics.setColor(1, 1, 1)\n  lovr.graphics.setShader(wave)\n  lovr.graphics.fill(canvas:getTexture())\n  lovr.graphics.setShader()\nend"
             }
             }
           },
           },
           notes = "Up to four textures can be attached to a Canvas and anything rendered to the Canvas will be broadcast to all attached Textures.  If you want to do render different things to different textures, use the `multicanvas` shader flag when creating your shader and implement the `void colors` function instead of the usual `vec4 color` function.  You can then assign different output colors to `lovrCanvas[0]`, `lovrCanvas[1]`, etc. instead of returning a single color. Each color written to the array will end up in the corresponding texture attached to the Canvas.",
           notes = "Up to four textures can be attached to a Canvas and anything rendered to the Canvas will be broadcast to all attached Textures.  If you want to do render different things to different textures, use the `multicanvas` shader flag when creating your shader and implement the `void colors` function instead of the usual `vec4 color` function.  You can then assign different output colors to `lovrCanvas[0]`, `lovrCanvas[1]`, etc. instead of returning a single color. Each color written to the array will end up in the corresponding texture attached to the Canvas.",
@@ -16926,17 +16926,25 @@ return {
               variants = {
               variants = {
                 {
                 {
                   arguments = {
                   arguments = {
-                    low = {
+                    {
+                      name = "seed",
+                      type = "number",
+                      description = "The random seed."
+                    }
+                  },
+                  returns = {}
+                },
+                {
+                  arguments = {
+                    {
+                      name = "low",
                       type = "number",
                       type = "number",
                       description = "The lower 32 bits of the seed."
                       description = "The lower 32 bits of the seed."
                     },
                     },
-                    high = {
+                    {
+                      name = "high",
                       type = "number",
                       type = "number",
                       description = "The upper 32 bits of the seed."
                       description = "The upper 32 bits of the seed."
-                    },
-                    seed = {
-                      type = "number",
-                      description = "The random seed."
                     }
                     }
                   },
                   },
                   returns = {}
                   returns = {}
@@ -17013,7 +17021,13 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "A number to add to each component."
+                      description = "A value to add to x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to add to y component.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17051,6 +17065,27 @@ return {
                       description = "The distance to `u`."
                       description = "The distance to `u`."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to measure distance to."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to measure distance to."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "distance",
+                      type = "number",
+                      description = "The distance to `u`."
+                    }
+                  }
                 }
                 }
               }
               }
             },
             },
@@ -17087,7 +17122,13 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "The number to divide each component by."
+                      description = "A value to divide x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to divide y component by.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17106,7 +17147,7 @@ return {
               description = "Returns the dot product between this vector and another one.",
               description = "Returns the dot product between this vector and another one.",
               key = "Vec2:dot",
               key = "Vec2:dot",
               module = "lovr.math",
               module = "lovr.math",
-              notes = "This is computed as:\n\n    dot = v.x * u.x + v.y * u.y + v.z * u.z\n\nThe vectors are not normalized before computing the dot product.",
+              notes = "This is computed as:\n\n    dot = v.x * u.x + v.y * u.y\n\nThe vectors are not normalized before computing the dot product.",
               variants = {
               variants = {
                 {
                 {
                   arguments = {
                   arguments = {
@@ -17123,6 +17164,27 @@ return {
                       description = "The dot product between `v` and `u`."
                       description = "The dot product between `v` and `u`."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute the dot product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute the dot product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "dot",
+                      type = "number",
+                      description = "The dot product between `v` and `u`."
+                    }
+                  }
                 }
                 }
               }
               }
             },
             },
@@ -17161,16 +17223,26 @@ return {
               },
               },
               variants = {
               variants = {
                 {
                 {
-                  arguments = {
+                  arguments = {},
+                  returns = {
                     {
                     {
-                      name = "u",
+                      name = "v",
                       type = "Vec2",
                       type = "Vec2",
-                      description = "The vector to lerp towards."
+                      description = "The original vector, containing the new lerped values."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to lerp towards."
                     },
                     },
                     {
                     {
-                      name = "t",
+                      name = "y",
                       type = "number",
                       type = "number",
-                      description = "The lerping parameter."
+                      description = "A value of y component to lerp towards."
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17216,7 +17288,13 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "The number to multiply each component by."
+                      description = "A value to multiply x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to multiply y component by.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17335,7 +17413,13 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "A number to subtract from each component."
+                      description = "A value to subtract from x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to subtract from y component.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17425,7 +17509,19 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "A number to add to each component."
+                      description = "A value to add to x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to add to y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to add to z component.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17461,6 +17557,32 @@ return {
                       description = "The original vector, with the cross product as its values."
                       description = "The original vector, with the cross product as its values."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute cross product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute cross product with."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to compute cross product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec3",
+                      description = "The original vector, with the cross product as its values."
+                    }
+                  }
                 }
                 }
               },
               },
               related = {
               related = {
@@ -17492,6 +17614,32 @@ return {
                       description = "The distance to `u`."
                       description = "The distance to `u`."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to measure distance to."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to measure distance to."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to measure distance to."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "distance",
+                      type = "number",
+                      description = "The distance to `u`."
+                    }
+                  }
                 }
                 }
               }
               }
             },
             },
@@ -17528,7 +17676,19 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "The number to divide each component by."
+                      description = "A value to divide x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to divide y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to divide z component by.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17564,6 +17724,32 @@ return {
                       description = "The dot product between `v` and `u`."
                       description = "The dot product between `v` and `u`."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute the dot product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute the dot product with."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to compute the dot product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "dot",
+                      type = "number",
+                      description = "The dot product between `v` and `u`."
+                    }
+                  }
                 }
                 }
               },
               },
               related = {
               related = {
@@ -17624,6 +17810,37 @@ return {
                       description = "The original vector, containing the new lerped values."
                       description = "The original vector, containing the new lerped values."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to lerp towards."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to lerp towards."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to lerp towards."
+                    },
+                    {
+                      name = "t",
+                      type = "number",
+                      description = "The lerping parameter."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec3",
+                      description = "The original vector, containing the new lerped values."
+                    }
+                  }
                 }
                 }
               }
               }
             },
             },
@@ -17660,7 +17877,19 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "The number to multiply each component by."
+                      description = "A value to multiply x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to multiply y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to multiply z component by.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17801,7 +18030,19 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "A number to subtract from each component."
+                      description = "A value to subtract from x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to subtract from y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to subtract from z component.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17896,7 +18137,25 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "A number to add to each component."
+                      description = "A value to add to x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to add to y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to add to z component.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to add to w component.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -17934,6 +18193,37 @@ return {
                       description = "The distance to `u`."
                       description = "The distance to `u`."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to measure distance to."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to measure distance to."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to measure distance to."
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value of w component to measure distance to."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "distance",
+                      type = "number",
+                      description = "The distance to `u`."
+                    }
+                  }
                 }
                 }
               }
               }
             },
             },
@@ -17970,7 +18260,25 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "The number to divide each component by."
+                      description = "A value to divide x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to divide y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to divide z component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to divide w component by.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -18006,6 +18314,37 @@ return {
                       description = "The dot product between `v` and `u`."
                       description = "The dot product between `v` and `u`."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to compute the dot product with."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to compute the dot product with."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to compute the dot product with."
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value of w component to compute the dot product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "dot",
+                      type = "number",
+                      description = "The dot product between `v` and `u`."
+                    }
+                  }
                 }
                 }
               }
               }
             },
             },
@@ -18063,6 +18402,42 @@ return {
                       description = "The original vector, containing the new lerped values."
                       description = "The original vector, containing the new lerped values."
                     }
                     }
                   }
                   }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A value of x component to lerp towards."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value of y component to lerp towards."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value of z component to lerp towards."
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value of w component to lerp towards."
+                    },
+                    {
+                      name = "t",
+                      type = "number",
+                      description = "The lerping parameter."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector, containing the new lerped values."
+                    }
+                  }
                 }
                 }
               }
               }
             },
             },
@@ -18099,7 +18474,25 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "The number to multiply each component by."
+                      description = "A value to multiply x component by."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to multiply y component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to multiply z component by.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to multiply w component by.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
@@ -18204,23 +18597,23 @@ return {
               key = "Vec4:sub",
               key = "Vec4:sub",
               module = "lovr.math",
               module = "lovr.math",
               related = {
               related = {
-                "Vec2:add",
-                "Vec2:mul",
-                "Vec2:div"
+                "Vec4:add",
+                "Vec4:mul",
+                "Vec4:div"
               },
               },
               variants = {
               variants = {
                 {
                 {
                   arguments = {
                   arguments = {
                     {
                     {
                       name = "u",
                       name = "u",
-                      type = "Vec2",
+                      type = "Vec4",
                       description = "The other vector."
                       description = "The other vector."
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
                     {
                     {
                       name = "v",
                       name = "v",
-                      type = "Vec2",
+                      type = "Vec4",
                       description = "The original vector."
                       description = "The original vector."
                     }
                     }
                   }
                   }
@@ -18230,13 +18623,31 @@ return {
                     {
                     {
                       name = "x",
                       name = "x",
                       type = "number",
                       type = "number",
-                      description = "A number to subtract from each component."
+                      description = "A value to subtract from x component."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "A value to subtract from y component.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "A value to subtract from z component.",
+                      default = "x"
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "A value to subtract from w component.",
+                      default = "x"
                     }
                     }
                   },
                   },
                   returns = {
                   returns = {
                     {
                     {
                       name = "v",
                       name = "v",
-                      type = "Vec2",
+                      type = "Vec4",
                       description = "The original vector."
                       description = "The original vector."
                     }
                     }
                   }
                   }
@@ -25254,7 +25665,7 @@ return {
               description = "The id of the key (ignores keyboard layout, may vary between keyboards)."
               description = "The id of the key (ignores keyboard layout, may vary between keyboards)."
             },
             },
             {
             {
-              name = "repeat",
+              name = "repeating",
               type = "boolean",
               type = "boolean",
               description = "Whether the event is the result of a key repeat instead of an actual press."
               description = "Whether the event is the result of a key repeat instead of an actual press."
             }
             }

+ 10 - 0
api/lovr/math/RandomGenerator/setSeed.lua

@@ -19,6 +19,16 @@ return {
     }
     }
   },
   },
   returns = {},
   returns = {},
+  variants = {
+    {
+      arguments = { 'seed' },
+      returns = {}
+    },
+    {
+      arguments = { 'low', 'high' },
+      returns = {}
+    }
+  },
   notes = [[
   notes = [[
     For precise 64 bit seeds, you should specify the lower and upper 32 bits of the seed separately.
     For precise 64 bit seeds, you should specify the lower and upper 32 bits of the seed separately.
     Otherwise, seeds larger than 2^53 will start to lose precision.
     Otherwise, seeds larger than 2^53 will start to lose precision.