Skip to content

Commit

Permalink
chore: adjust puffin usage
Browse files Browse the repository at this point in the history
  • Loading branch information
buxx committed Apr 2, 2024
1 parent 827f97e commit 1ae9a7c
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 22 deletions.
189 changes: 189 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "Server (standalone) map1 --profile",
"cargo": {
"args": [
"build",
"--bin=battle_server",
"--package=battle_server"
],
"filter": {
"name": "battle_server",
"kind": "bin"
}
},
"args": [
"map1",
"--rep-address",
"tcp://0.0.0.0:4255",
"--bind-address",
"tcp://0.0.0.0:4256",
"--profile"
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down Expand Up @@ -127,6 +155,47 @@
"RUST_LOG": "engage=DEBUG"
}
},
{
"type": "lldb",
"request": "launch",
"name": "Gui (server embedded) map1 --profile",
"cargo": {
"args": [
"build",
"--bin=battle_gui",
"--package=battle_gui"
],
"filter": {
"name": "battle_gui",
"kind": "bin"
}
},
"args": [
"map1",
"assets/map1_deployment.json",
"--embedded-server",
"--server-rep-address",
"tcp://0.0.0.0:4255",
"--server-bind-address",
"tcp://0.0.0.0:4256",
"--side",
"a",
"--side-a-control",
"W",
"--side-a-control",
"NW",
"--side-a-control",
"SW",
"--side-b-control",
"ALL",
"--profile"
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1",
"RUST_LOG": "engage=DEBUG"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down Expand Up @@ -209,6 +278,47 @@
"RUST_LOG": "DEBUG"
}
},
{
"type": "lldb",
"request": "launch",
"name": "Gui (server embedded) Demo1 --profile",
"cargo": {
"args": [
"build",
"--bin=battle_gui",
"--package=battle_gui"
],
"filter": {
"name": "battle_gui",
"kind": "bin"
}
},
"args": [
"Demo1",
"assets/demo1_deployment.json",
"--embedded-server",
"--server-rep-address",
"tcp://0.0.0.0:4255",
"--server-bind-address",
"tcp://0.0.0.0:4256",
"--side",
"a",
"--side-a-control",
"W",
"--side-a-control",
"NW",
"--side-a-control",
"SW",
"--side-b-control",
"ALL",
"--profile"
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1",
"RUST_LOG": "DEBUG"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down Expand Up @@ -250,6 +360,48 @@
"RUST_LOG": "DEBUG"
}
},
{
"type": "lldb",
"request": "launch",
"name": "Gui (server embedded) Demo2 (1) --release --profile",
"cargo": {
"args": [
"build",
"--bin=battle_gui",
"--package=battle_gui",
"--release"
],
"filter": {
"name": "battle_gui",
"kind": "bin"
}
},
"args": [
"Demo2",
"assets/demo2_deployment.json",
"--embedded-server",
"--server-rep-address",
"tcp://0.0.0.0:4255",
"--server-bind-address",
"tcp://0.0.0.0:4256",
"--side",
"a",
"--side-a-control",
"W",
"--side-a-control",
"NW",
"--side-a-control",
"SW",
"--side-b-control",
"ALL",
"--profile",
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1",
"RUST_LOG": "DEBUG"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down Expand Up @@ -447,6 +599,43 @@
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "Gui a map1 --profile",
"cargo": {
"args": [
"build",
"--bin=battle_gui",
"--package=battle_gui"
],
"filter": {
"name": "battle_gui",
"kind": "bin"
}
},
"args": [
"map1",
"assets/map1_deployment.json",
"--server-rep-address",
"tcp://0.0.0.0:4255",
"--server-bind-address",
"tcp://0.0.0.0:4256",
"--side",
"a",
"--side-a-control",
"W",
"--side-a-control",
"NW",
"--side-a-control",
"SW",
"--profile"
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down
47 changes: 42 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ Install [puffin_viewer](https://github.com/EmbarkStudios/puffin/tree/main/puffin

Start server or client with `--profile` flag. Example :

cargo run --bin battle_server -- --rep-address tcp://0.0.0.0:4255 --bind-address tcp://0.0.0.0:4256 --profile

Start puffin viewer :

puffin_viewer --url 127.0.0.1:8585
cargo run --bin battle_gui -- map1 assets/map1_deployment.json --embedded-server --server-rep-address tcp://0.0.0.0:4255 --server-bind-address tcp://0.0.0.0:4256 --side a --side-a-control W --side-a-control NW --side-a-control SW --side-b-control ALL --profile

Output will be like :

Expand Down
2 changes: 2 additions & 0 deletions battle_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ bincode = "1.3.3"
serde_json = "1.0.96"
thiserror = "1.0.39"
rstest = "0.18.1"
puffin_http = "0.16.0"
puffin = "0.19.0"
27 changes: 27 additions & 0 deletions battle_core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,30 @@ impl Rect {
}
}
}

pub fn start_puffin_server(address: String) {
puffin::set_scopes_on(true); // tell puffin to collect data

match puffin_http::Server::new(&address) {
Ok(puffin_server) => {
eprintln!(
"Run: cargo install puffin_viewer && puffin_viewer --url {}",
address
);

std::process::Command::new("puffin_viewer")
.arg("--url")
.arg(&address)
.spawn()
.ok();

// We can store the server if we want, but in this case we just want
// it to keep running. Dropping it closes the server, so let's not drop it!
#[allow(clippy::mem_forget)]
std::mem::forget(puffin_server);
}
Err(err) => {
eprintln!("Failed to start puffin server: {err}");
}
};
}
4 changes: 2 additions & 2 deletions battle_gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ strum = "0.24"
strum_macros = "0.24"
geo = "0.27.0"
ggegui = "0.3.7"
puffin_http = "0.11.1"
puffin = "0.14.2"
puffin_http = "0.16.0"
puffin = "0.19.0"
image = "0.24.5"
anyhow = "1.0.69"
thiserror = "1.0.39"
Expand Down
Loading

0 comments on commit 1ae9a7c

Please sign in to comment.