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

Add flatbuffers for base world state #7

Merged
merged 14 commits into from
May 9, 2020
Merged

Conversation

mingyli
Copy link
Owner

@mingyli mingyli commented May 8, 2020

This PR adds the base flatbuffers for use as the base world state.

Test Plan:

Run cargo run.

flatc is a tool to generate Rust code given a flatbuffers schema. In order to get this working with Github Actions, a build step must be added to install flatc.

@mingyli mingyli requested review from mluogh and yizzlez May 8, 2020 06:40
#[allow(dead_code, unused_imports, clippy::redundant_field_names)]
#[path = "../target/flatbuffers/world_generated.rs"]
mod world_generated;
pub use world_generated::tankrs::{get_root_as_world, World, WorldArgs};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need pub here.

namespace Tankrs;

table World {
width: uint16;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add comments for these fields (e.g. how wide the world is in number of blocks).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Additionally, I would like us to use id number for these schemas so we can order them logically.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Can you write an example for how an id number annotation looks?

Copy link
Collaborator

Choose a reason for hiding this comment

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

width: uint16 (id: 0);

However, this does look more cluttered. I don't know if the advantage of being able to logically group fields outweighs this.

server/build.rs Outdated

fn main() {
flatc_rust::run(flatc_rust::Args {
inputs: &[Path::new("schema/world.fbs")],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we glob **.fbs? That way we would not have to add to this every time we make a new flatb module.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good suggestion. Unfortunately the type specification is a slice of paths. We can dynamically generate a slice of paths in the future.

schema/world.fbs Outdated
Comment on lines 7 to 8
cell_width: uint16 = 40;
cell_height: uint16 = 40;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This constant will be determined on the frontend.

No part of the backend should need this.

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is not frontend. We will need these attributes in order to do projectile physics.

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. I am under the impression that this flatbuffer will only be generated to send through the wire. Nothing that the user does not need will not be here.

  2. We can do the projectile physics without a set pixel width for each cell. We will have an implicit coordinate system, mapping the coordinate system to actual pixels is only necessary to render, not do math.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Okay, then we don't need to have an explicit grid. Our coordinate system can be smooth


jobs:
flatbuffers:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you describe in the PR description why all of this is necessary?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

@@ -66,4 +145,5 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: clippy
args: --manifest-path=${{env.cargo-path}} -- -W clippy::all -W clippy::pedantic -D warnings
args: --manifest-path=${{env.cargo-path}}
# args: --manifest-path=${{env.cargo-path}} -- -W clippy::all -W clippy::pedantic -D warnings
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to keep all of these if possible.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Unfortunately the severities must be set elsewhere. If they are specified in flags, they will lint the generated Rust code by default.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this help?

rust-lang/rust-clippy#702

Copy link
Owner Author

Choose a reason for hiding this comment

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

Unfortunately it does not:
image

@mingyli
Copy link
Owner Author

mingyli commented May 9, 2020

@yizzlez PTAL

@mingyli mingyli merged commit db7f1f0 into master May 9, 2020
@mingyli mingyli deleted the ming/world-flatbuffers branch May 9, 2020 03:10
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.

2 participants