-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rust to descriptions, include game list in metadata
- Loading branch information
Showing
7 changed files
with
90 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Play simple Lua games, host web games server | ||
Play simple Lua/Rust games, host web games server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
## AlexGames Rust games | ||
|
||
This is how I've been building (from project root): | ||
See [gem match](gem_match) and [reversi](reversi) for an example of how to implement a game. | ||
|
||
(cd src/rust_games/ && cargo build --target=wasm32-unknown-emscripten) && build/wasm/build.sh -- -j32 | ||
Your game should implement `AlexGamesApi` (defined in [`rust_game_api.rs`](rust_game_api.rs)), and it can call the `*const CCallbacksPtr` it is passed to draw on the game canvas, initialize UI elements, send multiplayer messages, etc. | ||
|
||
I think what I'm doing is mostly okay, once I figure out how to convert the generic | ||
GameState trait into the reversi state. | ||
When adding a new game, two changes need to be made to [`rust_game_handler.rs`](rust_game_handler.rs): | ||
* `get_rust_game_init_func`: need to match the `game_id` (string, e.g. `"reversi"` or `"gem_match`) to your game's implementation of `pub fn init(callbacks: *const rust_game_api::CCallbacksPtr) -> Box<dyn AlexGamesApi>`. | ||
* `handle_void_ptr_to_trait_ref`: need to match the `game_id` string to the right cast of the `*mut AlexGamesHandle` field `api` to your game struct, which should implement the `AlexGamesApi` trait. | ||
|
||
The `handle_void_ptr_to_trait_ref` step for each game could maybe be removed in the future by passing a struct of function pointers to C instead, or something like that. I think in C++ each object's vtable is referenced in a generic place on the object, but in Rust it seems to work differently, and you need to cast to your struct first before you can call the struct functions, even if all the structs implement the `AlexGamesApi` trait. |