Skip to content

An online web app for playing around with Bevy in the browser (unofficial)

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

LiamGallagher737/learnbevy

Repository files navigation

Bevy Playground (for now)

An online web app for playing around with Bevy in the browser.

Why is it called learnbevy?

The end goal is to build challenge like tutorials for learning different aspects of the Bevy game engine. An example of one could be learning how to use run conditions. Currently the focus is on building a user friendly and featureful playground that will then be used for the challenges.

Here is a list of current and planned features

  • Code editor with syntax highlighting (highlight is stolen from the rust playground)
  • Visual window
  • Console that displays logs and build stderr
  • Selectable Bevy version and rust channel (nightly and stable)
  • Formatting code
  • Sharing code
  • Bevy example selector
  • Assets for testing with
  • Popular crates
  • Entity hierarchy
  • Entity inspector
  • Rust analyzer running in the browser (it's possible)

πŸ“‚ compile_api

This is the program than compiles the code to wasm.

How it works

Each request spins up a new podman container, see images for for infomation on them.

The http server in use is tide, I chose this due to its middleware which works quite well for this use case. Each stage is implmented as its own middleware.

To keep the service avaliable for everyone to use there is rate limiting which adds a 5 second deplay before another request can be made when the last one was successful but only 1 second if it was unsuccessful. There is also what I call "ip locking" which allows only a single concurrent request from each IP address.

Hosting

Currently it is running on a single 7950 VDS 1 from HostENOS in Salt Lake City. I chose this due to it's great single threaded performance which seems to be the most important for incrimental builds.

Metrics / Uptime

The server collects metrics about the number of requests, their statuses and how long they take. A public grafana dashboard is avaliable to view at https://metrics.learnbevy.com. I also have uptime messuarements using Better Stack, the public status page can be found at https://status.learnbevy.com.

Local Development

All the program needs to run is podman and the images for the versions and channels you want to use/test.

You can pull them like this.

podman pull ghcr.io/liamgallagher737/learnbevy-<version>-<channel>
podman pull ghcr.io/liamgallagher737/learnbevy-0.14-nightly # 0.14 on nightly
podman pull ghcr.io/liamgallagher737/learnbevy-main-stable # bevy main branch on stable

If you want to build them yourselve see the images section.

πŸ“‚ compile_server_os

This is the NixOS system config for the server(s) running the compile_api program.

You can install NixOS with the config on any achine you have root ssh access to using the following command.

nix run github:nix-community/nixos-anywhere -- --flake .#<server-type> root@<ip address>

The server-type is any of the outs from flake.nix. This is because parts of the config will depend on the server they are running on.

Once installed, any updates to the config can be activated by running the following command on the server via ssh.

nixos-rebuild switch --flake <URI to your flake>

Or if your cool and use NixOS you can rebuild it without needing to ssh into it with this command.

nixos-rebuild switch --flake .#<server-type> --target-host "root@<ip address>"

πŸ“‚ images

This is where the Dockfile is for the images used durning compiling. A single dockerfile is used taking both a Bevy version and Rust channel as arguments. The Cargo.toml files for each version are in the manifests directory, each version gets it's own file as the features change between versions.

Building

An image can be build like this, replace 0.14 and stable with options of your choice.

podman build --build-arg="version=0.14" --build-arg="channel=stable" --tag "ghcr.io/liamgallagher737/learnbevy-0.14-stable" .

πŸ“‚ rustfmt_api

This is the program that formats the code.

How it works

This is a very simple server using warp, just a single main.rs file. Each requests runs a new rustfmt process and pipes the users code into stdin. The formatted code is then read through stdout.

Hosting

There are three instances of this server running on fly.io's free tier. The machines being used are shared-cpu-1x@256MB as that is the maximum to stay in the free their while keeping them permanently up which is ideal to avoid cold starts. The three instances run in the following regions.

  • Dallas, Texas πŸ‡ΊπŸ‡Έ
  • Sydney, Australia πŸ‡¦πŸ‡Ί
  • Amsterdam, Netherlands πŸ‡³πŸ‡±

πŸ“‚ www

This is the website https://learnbevy.com.

How it works

It is a SvelteKit 4 app that uses tailwind for styling and shancn-svelte for the ui components.

Hosting

The website is hosted on Cloudflare Pages for free. The shares are stored in a Cloudlflare KV database which is also free.

The program can be built with the following command

Local Development

Most of the time a simple npm run dev will suffice however if you want to use the sharing functionality you will have to build the app and run it with wrangler, this is due to needing a database. The following command will do both.

npm run build && npx wrangler pages dev .svelte-kit/cloudflare

If you want the website to use a locally running compile server you can specify a url in your .env file.

PUBLIC_COMPILE_HOST=http://localhost:53740

If your running the compile server with ssl then most likely your browser will block the request when you try to compile due to an untrusted self-signed certificate. To trust it on Firefox you can go to https://localhost:53740/compile and click on the Advanced then Accept the Risk. Other browser should be very simular.

βš–οΈ License

All code in this repository is dual-licensed under either of the following license at your option.

The assets included in this repository are copied from the Bevy repository and typically fall under different open licenses. See CREDITS.md for the details of the licenses of those files.

About

An online web app for playing around with Bevy in the browser (unofficial)

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages