ais data feed functional, bb query is overshot, performance degraded

This commit is contained in:
geoffsee
2025-07-21 20:43:34 -04:00
parent b62035b8b4
commit 0413dacd63
5 changed files with 84 additions and 30 deletions

View File

@@ -3,6 +3,13 @@ name = "ais"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[[bin]]
name = "ais"
path = "src/main.rs"
[profile.dev]
debug = false
[dependencies] [dependencies]
tokio = { version = "1.0", features = ["full"] } tokio = { version = "1.0", features = ["full"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] } tokio-tungstenite = { version = "0.20", features = ["native-tls"] }

View File

@@ -1,12 +1,12 @@
use axum::{ use axum::{
extract::{ws::{WebSocket, Message as WsMessage}, Query, State, WebSocketUpgrade}, extract::{ws::{Message as WsMessage, WebSocket}, Query, State, WebSocketUpgrade},
http::StatusCode, http::StatusCode,
response::{Json, Response}, response::{Json, Response}
routing::get,
Router, ,
}; };
use base64::{engine::general_purpose::STANDARD, Engine as _}; use base64::{engine::general_purpose::STANDARD, Engine as _};
use futures_util::{stream::SplitSink, SinkExt, StreamExt}; use futures_util::{SinkExt, StreamExt};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use std::sync::Arc; use std::sync::Arc;
@@ -14,10 +14,9 @@ use tokio::{
sync::{broadcast, Mutex}, sync::{broadcast, Mutex},
task::JoinHandle, task::JoinHandle,
}; };
use tokio_util::sync::CancellationToken;
use tower_http::cors::CorsLayer;
use url::Url;
use tokio_tungstenite::{connect_async, tungstenite::protocol::Message}; use tokio_tungstenite::{connect_async, tungstenite::protocol::Message};
use tokio_util::sync::CancellationToken;
use url::Url;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@@ -716,9 +715,9 @@ pub async fn shutdown_signal() {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::create_router;
use axum_test::TestServer; use axum_test::TestServer;
use serde_json::json; use serde_json::json;
use tokio::sync::broadcast;
#[test] #[test]
fn test_get_ship_type_description() { fn test_get_ship_type_description() {

View File

@@ -2,27 +2,37 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use bevy::asset::AssetMetaCheck; use bevy::asset::AssetMetaCheck;
use bevy::ecs::spawn::SpawnableList;
use bevy::prelude::*; use bevy::prelude::*;
use bevy::window::PrimaryWindow; use bevy::window::PrimaryWindow;
use bevy::winit::WinitWindows; use bevy::winit::WinitWindows;
use bevy::DefaultPlugins; use bevy::DefaultPlugins;
use yachtpit::GamePlugin;
use std::io::Cursor; use std::io::Cursor;
use winit::window::Icon;
use tokio::process::Command; use tokio::process::Command;
use winit::window::Icon;
use yachtpit::GamePlugin;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use bevy_webview_wry::WebviewWryPlugin; #[tokio::main]
#[cfg(not(target_arch = "wasm32"))]
#[tokio::main(flavor = "multi_thread")]
async fn main() { async fn main() {
// Start AIS server in background
tokio::spawn(async {
info!("Starting AIS server...");
let mut cmd = Command::new("target/release/ais").spawn().unwrap();
match cmd.wait().await {
Ok(status) => info!("AIS server process exited with status: {}", status),
Err(e) => error!("Error waiting for AIS server process: {}", e),
}
});
launch_bevy(); launch_bevy();
} }
#[cfg(not(target_arch = "wasm32"))]
use bevy_webview_wry::WebviewWryPlugin;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
fn launch_bevy() { fn launch_bevy() {
App::new() App::new()
@@ -45,12 +55,15 @@ fn launch_bevy() {
}), }),
) )
.add_plugins(GamePlugin) .add_plugins(GamePlugin)
.add_systems(Startup, set_window_icon) .add_systems(Startup, set_window_icon) // Changed here
.add_systems(Update, start_ais_server)
.add_plugins(WebviewWryPlugin::default()) .add_plugins(WebviewWryPlugin::default())
.run(); .run();
} }
#[cfg(target_arch = "wasm32")]
async fn main() {
launch_bevy();
}
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
fn launch_bevy() { fn launch_bevy() {
@@ -87,18 +100,53 @@ fn launch_bevy() {
.run(); .run();
} }
} }
//
// fn start_ais_server() {
// static mut SERVER_STARTED: bool = false;
//
// unsafe {
// if SERVER_STARTED {
// return;
// }
// SERVER_STARTED = true;
// }
//
// let rt = tokio::runtime::Runtime::new().unwrap();
// rt.block_on(async {
// info!("Starting AIS server...");
// if let Ok(mut cmd) = Command::new("cargo")
// .current_dir("../ais")
// .arg("run").arg("--release")
// .spawn() {
// info!("AIS server process spawned");
// let status = cmd.wait().await;
// match status {
// Ok(exit_status) => match exit_status.code() {
// Some(code) => info!("AIS server exited with status code: {}", code),
// None => info!("AIS server terminated by signal"),
// },
// Err(e) => error!("AIS server failed: {}", e),
// }
// } else {
// error!("Failed to start AIS server - unable to spawn process");
// }
// });
// }
fn start_ais_server() { // fn start_ais_server() {
let rt = tokio::runtime::Runtime::new().unwrap(); // // This task will run on the Tokio runtime's thread pool without blocking Bevy
rt.block_on(async { // tokio::spawn(async {
if let Ok(mut cmd) = Command::new("cargo") // info!("Starting AIS server in the background...");
.current_dir("../ais-server") //
.arg("run").arg("--release").spawn() { //
let _ = cmd.wait().await; //
} // // This now waits on the background task, not the main Bevy thread
}); // match cmd.wait().await {
} // Ok(status) => info!("AIS server process exited with status: {}", status),
// Err(e) => error!("Error waiting for AIS server process: {}", e),
// }
// });
// }
// Sets the icon on windows and X11 // Sets the icon on windows and X11
fn set_window_icon( fn set_window_icon(

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB