konsumer / raylib-wasm

Ideas around a wasm runtime for raylib (to make raylib games in js & browser)
https://konsumer.js.org/raylib-wasm/
MIT License
23 stars 2 forks source link

Missing `this` in raylib.js #5

Closed Filyus closed 4 months ago

Filyus commented 5 months ago
  // Get cull plane distance near: rlGetCullDistanceNear() => double
  const _rlGetCullDistanceNear = mod.cwrap('rlGetCullDistanceNear', 'number', ['pointer'])
  raylib.rlGetCullDistanceNear = () => _rlGetCullDistanceNear(._address)

  // Get cull plane distance far: rlGetCullDistanceFar() => double
  const _rlGetCullDistanceFar = mod.cwrap('rlGetCullDistanceFar', 'number', ['pointer'])
  raylib.rlGetCullDistanceFar = () => _rlGetCullDistanceFar(._address)

probably must be

  // Get cull plane distance near: rlGetCullDistanceNear() => double
  const _rlGetCullDistanceNear = mod.cwrap('rlGetCullDistanceNear', 'number', ['pointer'])
  raylib.rlGetCullDistanceNear = () => _rlGetCullDistanceNear(this._address)

  // Get cull plane distance far: rlGetCullDistanceFar() => double
  const _rlGetCullDistanceFar = mod.cwrap('rlGetCullDistanceFar', 'number', ['pointer'])
  raylib.rlGetCullDistanceFar = () => _rlGetCullDistanceFar(this._address)
konsumer commented 5 months ago

I don't see rlGetCullDistanceNear in the current js/wasm I am building. Is this some later-version raylib fork of raylib-wasm?

Filyus commented 5 months ago

These functions are inside of the /src/raylib.js file. In the repository file I don't see the problem with this, but when building the file changes and this disappears. image

PS: Maybe this is better to rename it to /src/main.js to prevent confusion with /build/raylib.js.

Filyus commented 5 months ago

Maybe this is because of wrong tools/api/rlgl.json:

    {
      "name": "rlGetCullDistanceNear",
      "description": "Get cull plane distance near",
      "returnType": "double",
      "params": [
        {
          "type": "",
          "name": ""
        }
      ]
    },
    {
      "name": "rlGetCullDistanceFar",
      "description": "Get cull plane distance far",
      "returnType": "double",
      "params": [
        {
          "type": "",
          "name": ""
        }
      ]
    },

In the source rlgl.h file there no parameters at all:

// Get cull plane distance near
double rlGetCullDistanceNear(void)
{
    return rlCullDistanceNear;
}

// Get cull plane distance far
double rlGetCullDistanceFar(void)
{
    return rlCullDistanceFar;
}
konsumer commented 5 months ago

If I search the js generated by my current code, I don't see rlGetCullDistanceNear, which makes me think your js (and tools/api/rlgl.json) are generated from some other version of raylib.

You can see here it's not in any of my code.

I see it here which is not in 4.5, which is what I use. If you want to PR to update this repo to use 5, go for it, but last time I tried it was a bit complicated, and I could not get it working.

Filyus commented 5 months ago

Maybe you need to add versions at git clone in tools/build.sh to make the code stable.

konsumer commented 5 months ago

You are welcome to PR for it. Considering your other issue, as well, I am a bit confused why you even need to build it, at all. if you use the version I built, it works fine.

Filyus commented 5 months ago

The reason is simple - the build folder is in .gitignore: https://github.com/konsumer/raylib-wasm/blob/18785588e6b900671924e7d1f48e51f546bc0d44/.gitignore#L7

konsumer commented 4 months ago

The reason is simple - the build folder is in .gitignore:

No, that is where output and downloaded files, created/collected in the build-process go. It is intentionally ignored.

Again, if you want to PR for the 1 line in build.sh line to set the tag to 4.5, I will accept it. I still recommend just using the prebuilt wasm/js, though, unless you are actually working on making changes to raylib-wasm.

If you want to get raylib-wasm working with raylib 5, that would also be great. I didn't have the time to get it updated myself, and there are a lot of changes, but it'd be great if it was up to date.

The short answer to the original issue "Missing this in raylib.js" is to use raylib 4.5, if you are trying to build, or just use the prebuilt.

konsumer commented 4 months ago

I am going to close this, in favor of #7 The this problem is trying to use raylib 5 with this repo, and we just don't have support for that, yet.

konsumer commented 4 months ago

I locked in versions for raygui and raylib, and also included the built-files in repo (so people who just want to work on web stuff don't need all the build things.)