Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Support #1243

Open
wants to merge 29 commits into
base: devel
Choose a base branch
from
Open

Web Support #1243

wants to merge 29 commits into from

Conversation

Vixeliz
Copy link
Contributor

@Vixeliz Vixeliz commented Aug 18, 2023

Ok here is one actually based on the branch here in the ggez repo lol.

I think we are getting close to this being ready to merge.

@Vixeliz Vixeliz requested a review from nobbele August 18, 2023 20:24
Copy link

@metiulekm metiulekm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at various Rust game engines and frameworks. I really liked ggez, but would like to target web, so I decided to test this PR. Here are some random comments 😃

sync::Arc,
task::{Poll, Waker},
};

use crate::{
graphics::{Drawable, Drawable3d},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Drawable3d import and an impl below will fail if feature 3d is off.

@@ -79,6 +82,8 @@ base64 = { version = "0.21.2", optional = true }
gltf = { version = "1.2.0", optional = true, default-features = false, features = ["utils"] }
obj-rs = { version = "0.7.1", optional = true }
num-traits = "0.2"
dyn-clone = "1.0.12"
ureq = "2.7.1"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to make ureq an optional dependency? I understand that it is only needed for HttpFS, and it depends transitively on ring which is somewhat hard to cross-compile.

Also I don't think ureq is used (or works at all) in WASM, so you could put it in [target.'cfg(not(target_arch = "wasm32"))'.dependencies] or something.

@Vixeliz
Copy link
Contributor Author

Vixeliz commented Oct 25, 2023

Nice catch I'll fix both of these up soon

@sampullman
Copy link

@Vixeliz I finally got around to testing and fixing some of the problems I had running this last year. Overall I think it's great work, and just needs a bit of cleanup and regression testing. I fixed the conflicts locally, as well as the comments from @metiulekm, and a few other minor build issues. Should I push directly to this branch, or is it easier if I merge a fork?

Here's a dump of some of my notes I haven't had a chance to address yet:

  • Resource loading wasn't totally clear to me, it should be documented that they need to be available at <web-server-root>/resources/
  • Audio throws console warnings and doesn't work for me, though it may be a problem on my end
  • I understand why it makes sense for ggez to control the canvas creation, but I assume most users would want to handle styling/layout themselves. It can be worked around, but might be better to allow passing in a canvas element ID on initialization, if possible.
  • Similar to wgpu examples, it would be nice to provide a complete example. Currently my procedure is:
cargo build --release --target wasm32-unknown-unknown
wasm-bindgen --out-dir ./web/wasm/ --target web ./target/wasm32-unknown-unknown/release/ggez-playground.wasm

In the web folder, I've installed Vite, and use it to run the following index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.png" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <title>Hello ggez!</title>
    <style>
      html, body {
        height: 100%;
        padding: 0;
        margin: 0;
        box-sizing: border-box;
      }
      #ggez-wrap {
        display: flex;
        width: 100%;
        height: 100%;
        justify-content: center;
        align-items: center;
      }
    </style>
  </head>
  <body>
    <div id="ggez-wrap">
    </div>
    <script type="module">
      import game from "./wasm/ggez-playground";
      try {
      await game();
      } catch(_e) {
        // wgpu throws an error on init for control flow?
      }

      // Move canvas to our own element
      const ggezWrap = document.getElementById('ggez-wrap')
      const ggezBody = document.getElementById('ggez-body')
      ggezWrap.appendChild(ggezBody)
    </script>
  </body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants