use gizmo_math::{Quat, Vec3};
use std::sync::Mutex;
#[derive(Debug, Clone)]
pub enum ScriptCommand {
SetPosition(u32, Vec3),
SetRotation(u32, Quat),
SetScale(u32, Vec3),
SetVelocity(u32, Vec3),
SetAngularVelocity(u32, Vec3),
ApplyForce(u32, Vec3),
ApplyImpulse(u32, Vec3),
AddRigidBody {
id: u32,
mass: f32,
restitution: f32,
friction: f32,
use_gravity: bool,
},
AddBoxCollider {
id: u32,
hx: f32,
hy: f32,
hz: f32,
},
AddSphereCollider {
id: u32,
radius: f32,
},
SetVehicleEngineForce(u32, f32),
SetVehicleSteering(u32, f32),
SetVehicleBrake(u32, f32),
SpawnEntity {
name: String,
position: Vec3,
},
SpawnPrefab {
name: String,
prefab_type: String,
position: Vec3,
},
DestroyEntity(u32),
PlaySound(String),
PlaySound3D(String, Vec3),
StopSound(String),
LoadScene(String),
SaveScene(String),
ShowDialogue {
speaker: String,
text: String,
duration: f32,
},
HideDialogue,
TriggerCutscene(String), EndCutscene,
StartRace,
AddCheckpoint {
id: u32,
position: Vec3,
radius: f32,
},
ActivateCheckpoint(u32),
FinishRace {
winner_name: String,
},
ResetRace,
SetCameraTarget(u32), SetCameraFov(f32),
SetEntityName(u32, String),
AddNavAgent(u32),
SetAiTarget(u32, Vec3),
ClearAiTarget(u32),
}
pub struct CommandQueue {
pub commands: Mutex<Vec<ScriptCommand>>,
}
impl CommandQueue {
pub fn new() -> Self {
Self {
commands: Mutex::new(Vec::new()),
}
}
pub fn push(&self, cmd: ScriptCommand) {
self.commands.lock().unwrap().push(cmd);
}
pub fn drain(&self) -> Vec<ScriptCommand> {
self.commands.lock().unwrap().drain(..).collect()
}
pub fn is_empty(&self) -> bool {
self.commands.lock().unwrap().is_empty()
}
pub fn len(&self) -> usize {
self.commands.lock().unwrap().len()
}
}
impl Default for CommandQueue {
fn default() -> Self {
Self::new()
}
}