cargo-web | A Cargo subcommand for the client-side Web | Binary Executable Format library
kandi X-RAY | cargo-web Summary
kandi X-RAY | cargo-web Summary
A Cargo subcommand for the client-side Web
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cargo-web
cargo-web Key Features
cargo-web Examples and Code Snippets
Community Discussions
Trending Discussions on cargo-web
QUESTION
I'm attempting to create a game in web assembly. I chose to prepare it in rust and compile it using cargo-web. I managed to get a working game loop, but I have a problem with adding MouseDownEvent listener due to rust borrowing mechanisms. I would very much prefer to write "safe" code (without using "unsafe" keyword)
At this moment the game simply moves a red box from (0,0) to (700,500) with speed depending on the distance. I would like to have the next step to use user click update the destination.
This is the simplified and working code of the game.
static/index.html
...ANSWER
Answered 2019-Aug-19 at 12:11In your example game_loop
owns game
, as it is moved into the loop. So anything that should change game needs to happen inside game_loop
. To fit event handling into this, you have multiple options:
Let the game_loop
poll for events.
You create a queue of events and your game_loop
will have some logic to get the first event and handle it.
You will have to deal with synchronization here, so I suggest that you read up on Mutex and Concurrency in general. But it should be a fairly easy task once you get the hang of it. Your loop gets one reference and each event handler gets one, all try to unlock the mutex and then access the queue (vector probably).
This will make your game_loop
the monolithic one truth of them all, which is a popular engine design because it is easy to reason about and start with.
But maybe you want to be less centralized.
Option 2Let events happen outside the loop
This idea would be a bigger refactor. You would put your Game
in a lazy_static
with a Mutex around it.
Every invocation of the game_loop
it will try to get the lock on said Mutex and then perform game calculations.
When an input event happens, that event also tries to get the Mutex on the Game
. This means while the game_loop
is processing, no input events are handled, but they will try to get in between ticks.
A challenge here would be to preserve input order and to make sure that inputs are processed quick enough. This might be a bigger challenge to get completely right. But the design will give you some possibilities.
A fleshed out version of this idea is Amethyst
, which is massively parallel and makes for a clean design. But they employ a quite more complex design behind their engine.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cargo-web
You can't have overlapping prepend-js keys. You can either define a single global prepend-js, or multiple per-target ones.
The link-args currently can't have any spaces in them.
The order in which cargo-web will process the Web.toml files from multiple crates is deterministic yet unspecified. This means that you shouldn't depend on this order in any way.
You can use the following script to download and install the latest cargo-web:.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page