### Launch RLViser with Custom UDP Ports in Bash Source: https://context7.com/virxec/rlviser/llms.txt Provides examples of launching the RLViser application from the command line with custom UDP port configurations. It shows the default port usage and how to specify custom primary and secondary ports. ```bash # Default ports: primary=34254, secondary=45243 ./rlviser # Custom primary port (receives from this port) ./rlviser 35000 # Custom primary and secondary ports (receives from primary, binds secondary) ./rlviser 35000 46000 ``` -------------------------------- ### Launch RLViser Programmatically in Rust Source: https://context7.com/virxec/rlviser/llms.txt Illustrates how to launch the RLViser executable from a Rust program with specified primary and secondary ports. This function uses `std::process::Command` to spawn the process and includes a short delay to allow the visualizer to initialize. ```rust use std::process::Command; fn launch_rlviser(primary_port: u16, secondary_port: u16) -> std::io::Result<()> { let mut child = Command::new("./rlviser") .arg(primary_port.to_string()) .arg(secondary_port.to_string()) .spawn()?; // Wait for visualizer to initialize std::thread::sleep(std::time::Duration::from_secs(1)); Ok(()) } // Usage launch_rlviser(34254, 45243).expect("Failed to launch RLViser"); ``` -------------------------------- ### Build RLViser from Source with Cargo Source: https://context7.com/virxec/rlviser/llms.txt Shows different `cargo build` commands for compiling RLViser from source, including debug, release, and custom profile builds. It also covers options for enabling features like `full_load` and `threaded` support during compilation. ```bash # Debug build with some optimizations cargo build # Release build with LTO and stripped symbols cargo build --release # Tiny build optimized for size cargo build --profile tiny # Release with debug symbols cargo build --profile release-with-debug # Build with full asset loading (higher quality materials) cargo build --release --features full_load # Build with multithreading support cargo build --release --features threaded ``` -------------------------------- ### Sending Game State Data Source: https://context7.com/virxec/rlviser/llms.txt This section explains how to establish a UDP connection and send game state information to RLViser. It covers serializing game state using FlatBuffers and sending it over UDP. ```APIDOC ## POST /udp/game_state ### Description Sends game state data to RLViser via UDP for real-time visualization. The data is serialized using FlatBuffers. ### Method UDP ### Endpoint `127.0.0.1:34254` (default RLViser receive address) ### Parameters #### Query Parameters None #### Request Body **Data Packet** (bytes) - Required - A FlatBuffers serialized `rocketsim::Packet` containing game state information. The packet length is prepended as a 64-bit big-endian integer. ### Request Example ```rust use std::net::{UdpSocket, SocketAddr, IpAddr, Ipv4Addr}; // Connect to RLViser on default ports let out_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 34254); let recv_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 45243); // Local receive address let socket = UdpSocket::bind(recv_addr).unwrap(); // Create a game state packet using FlatBuffers let mut builder = planus::Builder::with_capacity(1024); let game_state = rocketsim::GameState { tick_count: 120, tick_rate: 120.0, game_mode: rocketsim::GameMode::Soccar, ball: rocketsim::BallInfo { physics: rocketsim::Physics { pos: rocketsim::Vec3 { x: 0.0, y: 0.0, z: 1000.0 }, vel: rocketsim::Vec3 { x: 500.0, y: 0.0, z: 0.0 }, ang_vel: rocketsim::Vec3 { x: 0.0, y: 0.0, z: 0.0 }, rot_mat: rocketsim::Mat3::default(), }, ds_info: rocketsim::BallDsInfo { y_target_dir: 0.0 }, }, cars: Some(vec![]), pads: Some(vec![]), tiles: None, }; let packet = rocketsim::Packet { message: rocketsim::Message::GameState(Box::new(game_state)), }; // Serialize and send let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); ``` ### Response #### Success Response (200) RLViser acknowledges receipt by not returning an error. The response is typically empty for UDP. #### Response Example N/A ``` -------------------------------- ### Add and Remove Custom Debug Renders in Rust Source: https://context7.com/virxec/rlviser/llms.txt Demonstrates how to add and remove custom 3D debug renders (like lines and line strips) in RLViser using Rust. This involves creating render commands, packaging them into a `planus` packet, and sending it over UDP. Dependencies include `std::net::UdpSocket`, `planus`, and `rocketsim`. ```rust use std::net::UdpSocket; fn add_debug_render(socket: &UdpSocket, render_id: i32, out_addr: &SocketAddr) { let mut builder = planus::Builder::with_capacity(1024); // Create custom debug renders let renders = vec![ // 3D line from origin to ball rocketsim::Render::Line3D(rocketsim::Line3D { start: rocketsim::Vec3 { x: 0.0, y: 0.0, z: 0.0 }, end: rocketsim::Vec3 { x: 0.0, y: 0.0, z: 1000.0 }, color: rocketsim::Color { r: 1.0, g: 0.0, b: 0.0, a: 1.0 }, }), // 2D line strip for path prediction rocketsim::Render::LineStrip(rocketsim::LineStrip { positions: vec![ rocketsim::Vec3 { x: 0.0, y: 0.0, z: 100.0 }, rocketsim::Vec3 { x: 100.0, y: 0.0, z: 200.0 }, rocketsim::Vec3 { x: 200.0, y: 0.0, z: 300.0 }, ], color: rocketsim::Color { r: 0.0, g: 1.0, b: 0.0, a: 0.8 }, }), ]; let packet = rocketsim::Packet { message: rocketsim::Message::AddRender(Box::new(rocketsim::AddRender { id: render_id, commands: renders, })), }; let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); } // Remove a render group fn remove_debug_render(socket: &UdpSocket, render_id: i32, out_addr: &SocketAddr) { let mut builder = planus::Builder::with_capacity(256); let packet = rocketsim::Packet { message: rocketsim::Message::RemoveRender(Box::new(rocketsim::RemoveRender { id: render_id, })), }; let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); } ``` -------------------------------- ### RLViser Keyboard Controls and Camera Management Source: https://context7.com/virxec/rlviser/llms.txt Lists the keyboard controls available in the RLViser visualizer for camera management, game control, and mouse interaction. This includes switching camera modes, moving the free camera, controlling playback speed, and interacting with game objects. ```text # Camera Switching 1-8 - Follow specific car (1 through 8) 9 - Director camera (auto-switches to car nearest ball) 0 - Free spectator camera # Free Camera Movement (Mode 0) W - Move forward A - Move left S - Move backward D - Move right Space - Move up Left Ctrl - Move down Left Shift - Slow movement speed # Game Control Esc - Toggle menu (must be OFF for controls to work) P - Toggle pause/play + - Increase speed by 0.5x - - Decrease speed by 0.5x = - Reset speed to 1.0x R - Set ball towards goal # Mouse Interaction Left Click - Drag cars/ball (menu must be ON to free cursor) ``` -------------------------------- ### Generate FlatBuffers Schema Code in Rust Build Script Source: https://context7.com/virxec/rlviser/llms.txt This Rust code snippet, intended for a `build.rs` file, demonstrates how to automatically generate Rust code from FlatBuffers schema files (`.fbs`). It uses `planus_translation` to parse schema files and `planus_codegen` to produce Rust code, which is then written to `./src/flat.rs`. ```rust // build.rs - Generates ./src/flat.rs from ./spec/*.fbs files use std::path::PathBuf; fn main() { println!("cargo:rerun-if-changed=./spec"); let fbs_path = PathBuf::from("./spec").join("core.fbs"); let declarations = planus_translation::translate_files(&[fbs_path.as_path()]).unwrap(); let code = planus_codegen::generate_rust(&declarations).unwrap(); std::fs::write("./src/flat.rs", code).unwrap(); } ``` -------------------------------- ### Send RocketSim Game State via UDP using Rust Source: https://context7.com/virxec/rlviser/llms.txt This snippet demonstrates how to establish a UDP connection and send game state data to RLViser using FlatBuffers serialization in Rust. It defines the structure for game state, including tick count, game mode, ball physics, and car/pad information, before serializing and transmitting it over UDP. ```rust use std::net::{UdpSocket, SocketAddr, IpAddr, Ipv4Addr}; // Connect to RLViser on default ports let out_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 34254); let recv_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 45243); let socket = UdpSocket::bind(recv_addr).unwrap(); // Create a game state packet using FlatBuffers let mut builder = planus::Builder::with_capacity(1024); let game_state = rocketsim::GameState { tick_count: 120, tick_rate: 120.0, game_mode: rocketsim::GameMode::Soccar, ball: rocketsim::BallInfo { physics: rocketsim::Physics { pos: rocketsim::Vec3 { x: 0.0, y: 0.0, z: 1000.0 }, vel: rocketsim::Vec3 { x: 500.0, y: 0.0, z: 0.0 }, ang_vel: rocketsim::Vec3 { x: 0.0, y: 0.0, z: 0.0 }, rot_mat: rocketsim::Mat3::default(), }, ds_info: rocketsim::BallDsInfo { y_target_dir: 0.0 }, }, cars: Some(vec![]), pads: Some(vec![]), tiles: None, }; let packet = rocketsim::Packet { message: rocketsim::Message::GameState(Box::new(game_state)), }; // Serialize and send let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); ``` -------------------------------- ### Control RLViser Playback Speed and Pause State using Rust Source: https://context7.com/virxec/rlviser/llms.txt This snippet shows how to send commands to RLViser to control the simulation's playback speed and pause state. It defines separate functions for sending speed and pause commands, both utilizing FlatBuffers for serialization and UDP for transmission. The commands allow for adjusting simulation speed (e.g., 0.5x) and toggling the paused state. ```rust use std::net::UdpSocket; fn send_speed_command(socket: &UdpSocket, speed: f32, out_addr: &SocketAddr) { let mut builder = planus::Builder::with_capacity(256); let packet = rocketsim::Packet { message: rocketsim::Message::Speed(Box::new(rocketsim::Speed { speed })), }; let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); } fn send_pause_command(socket: &UdpSocket, paused: bool, out_addr: &SocketAddr) { let mut builder = planus::Builder::with_capacity(256); let packet = rocketsim::Packet { message: rocketsim::Message::Paused(Box::new(rocketsim::Paused { paused })), }; let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); } // Usage example let socket = UdpSocket::bind("0.0.0.0:45243").unwrap(); let out_addr = "127.0.0.1:34254".parse().unwrap(); send_speed_command(&socket, 0.5, &out_addr); // Set to 0.5x speed send_pause_command(&socket, true, &out_addr); // Pause simulation ``` -------------------------------- ### Controlling Game Speed and Pause State Source: https://context7.com/virxec/rlviser/llms.txt This section details how to send commands to RLViser to control the simulation's speed and pause state. These commands are also sent via UDP using FlatBuffers serialization. ```APIDOC ## POST /udp/control ### Description Sends control commands to RLViser to adjust simulation speed or pause the simulation. Commands are serialized using FlatBuffers and sent over UDP. ### Method UDP ### Endpoint `127.0.0.1:34254` (default RLViser receive address) ### Parameters #### Query Parameters None #### Request Body **Data Packet** (bytes) - Required - A FlatBuffers serialized `rocketsim::Packet` containing either a `Speed` or `Paused` message. The packet length is prepended as a 64-bit big-endian integer. **Speed Message** - **speed** (f32) - The desired simulation speed multiplier (e.g., 1.0 for normal speed, 0.5 for half speed). **Paused Message** - **paused** (bool) - `true` to pause the simulation, `false` to resume. ### Request Example ```rust use std::net::UdpSocket; use std::net::SocketAddr; fn send_speed_command(socket: &UdpSocket, speed: f32, out_addr: &SocketAddr) { let mut builder = planus::Builder::with_capacity(256); let packet = rocketsim::Packet { message: rocketsim::Message::Speed(Box::new(rocketsim::Speed { speed })), }; let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); } fn send_pause_command(socket: &UdpSocket, paused: bool, out_addr: &SocketAddr) { let mut builder = planus::Builder::with_capacity(256); let packet = rocketsim::Packet { message: rocketsim::Message::Paused(Box::new(rocketsim::Paused { paused })), }; let payload = builder.finish(packet, None); let data_len_bin = (payload.len() as u64).to_be_bytes(); let bytes = [&data_len_bin[..], payload].concat(); socket.send_to(&bytes, out_addr).unwrap(); } // Usage example let socket = UdpSocket::bind("0.0.0.0:45243").unwrap(); // Local receive address let out_addr: SocketAddr = "127.0.0.1:34254".parse().unwrap(); send_speed_command(&socket, 0.5, &out_addr); // Set to 0.5x speed send_pause_command(&socket, true, &out_addr); // Pause simulation ``` ### Response #### Success Response (200) RLViser acknowledges receipt by not returning an error. The response is typically empty for UDP. #### Response Example N/A ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.