pub trait GameSim<G: GameDef>: Sized {
Show 26 methods
// Required methods
fn new(cfg: &G::Config, engine_cfg: &EngineConfig) -> Self;
fn spawn_actor(
&mut self,
world: &mut PhysicsWorld,
events: &mut Vec<CoreEvent>,
game_id: u32,
model_name: &str,
team_id: u8,
x: f32,
y: f32,
angle_deg: f32,
) -> Result<(), String>;
fn remove_actor(&mut self, world: &mut PhysicsWorld, game_id: u32);
fn reset_actor(
&mut self,
world: &mut PhysicsWorld,
game_id: u32,
team_id: u8,
x: f32,
y: f32,
angle_deg: f32,
);
fn reset_all_vitals(&mut self, events: &mut Vec<CoreEvent>);
fn spawn_scripted_actor(
&mut self,
world: &mut PhysicsWorld,
rng: &mut Rng,
events: &mut Vec<CoreEvent>,
game_id: u32,
model_name: &str,
team_id: u8,
x: f32,
y: f32,
angle_deg: f32,
) -> Result<(), String>;
fn remove_scripted_actor(&mut self, world: &mut PhysicsWorld, game_id: u32);
fn apply_input(
&mut self,
game_id: u32,
seq: u32,
action: &str,
key_name: &str,
);
fn last_input_seq(&self, game_id: u32) -> u32;
fn is_alive(&self, game_id: u32) -> bool;
fn actor_position(
&self,
world: &PhysicsWorld,
game_id: u32,
) -> Option<[f32; 2]>;
fn prediction_state(
&self,
world: &PhysicsWorld,
game_id: u32,
) -> Option<([f32; 8], bool)>;
fn alive_players_flat(&self, world: &PhysicsWorld) -> Vec<f32>;
fn players_json(&self) -> String;
fn on_fixed_step(&mut self, ctx: &mut SimCtx<'_>, dt: f32);
fn on_contacts(
&mut self,
ctx: &mut SimCtx<'_>,
pairs: &[(ColliderHandle, ColliderHandle)],
);
fn on_before_destroy(
&mut self,
world: &PhysicsWorld,
handle: RigidBodyHandle,
);
fn on_ai_tick(&mut self, ctx: &mut SimCtx<'_>, dt: f32);
fn refresh_cached(&mut self, world: &PhysicsWorld);
fn build_snapshot_blocks(&mut self) -> (Vec<(String, Block)>, bool);
fn remove_players_and_shots(
&mut self,
world: &mut PhysicsWorld,
) -> Vec<String>;
fn clear(&mut self);
fn serialize(&self) -> Value;
fn deserialize(&mut self, value: Value) -> Result<(), String>;
fn rebuild_spatial_grid(
&self,
world: &PhysicsWorld,
spatial: &mut SpatialGrid,
);
// Provided method
fn apply_aim(
&mut self,
_game_id: u32,
_seq: u32,
_x: f32,
_y: f32,
_flags: u32,
) { ... }
}Expand description
Игровая симуляция поверх движкового каркаса: участники, оружие,
снапшот-блоки. Игровой конфиг (G::Config) передаётся только в new —
реализация хранит нужные ей куски сама (модели/оружие не меняются в
течение комнаты), поэтому остальные методы им не параметризованы.
Методы вне тика получают только то, что им реально нужно (не весь
SimCtx), тиковые callback’ы — SimCtx, т.к. в них нужен произвольный
набор движковых ресурсов одновременно.
Required Methods§
Sourcefn new(cfg: &G::Config, engine_cfg: &EngineConfig) -> Self
fn new(cfg: &G::Config, engine_cfg: &EngineConfig) -> Self
engine_cfg — доступен только на конструкторе (напр. time_step для
расчёта размера кольцевых буферов по времени жизни снарядов);
остальные методы движковый конфиг не получают — см. SimCtx::cfg.
fn spawn_actor( &mut self, world: &mut PhysicsWorld, events: &mut Vec<CoreEvent>, game_id: u32, model_name: &str, team_id: u8, x: f32, y: f32, angle_deg: f32, ) -> Result<(), String>
fn remove_actor(&mut self, world: &mut PhysicsWorld, game_id: u32)
fn reset_actor( &mut self, world: &mut PhysicsWorld, game_id: u32, team_id: u8, x: f32, y: f32, angle_deg: f32, )
fn reset_all_vitals(&mut self, events: &mut Vec<CoreEvent>)
fn spawn_scripted_actor( &mut self, world: &mut PhysicsWorld, rng: &mut Rng, events: &mut Vec<CoreEvent>, game_id: u32, model_name: &str, team_id: u8, x: f32, y: f32, angle_deg: f32, ) -> Result<(), String>
fn remove_scripted_actor(&mut self, world: &mut PhysicsWorld, game_id: u32)
fn apply_input(&mut self, game_id: u32, seq: u32, action: &str, key_name: &str)
fn last_input_seq(&self, game_id: u32) -> u32
fn is_alive(&self, game_id: u32) -> bool
fn actor_position(&self, world: &PhysicsWorld, game_id: u32) -> Option<[f32; 2]>
fn prediction_state( &self, world: &PhysicsWorld, game_id: u32, ) -> Option<([f32; 8], bool)>
fn alive_players_flat(&self, world: &PhysicsWorld) -> Vec<f32>
fn players_json(&self) -> String
Sourcefn on_fixed_step(&mut self, ctx: &mut SimCtx<'_>, dt: f32)
fn on_fixed_step(&mut self, ctx: &mut SimCtx<'_>, dt: f32)
Игровая логика фиксированного шага (движение, спавн снарядов, детонация по истечению времени) — до шага физики.
Sourcefn on_contacts(
&mut self,
ctx: &mut SimCtx<'_>,
pairs: &[(ColliderHandle, ColliderHandle)],
)
fn on_contacts( &mut self, ctx: &mut SimCtx<'_>, pairs: &[(ColliderHandle, ColliderHandle)], )
Контакты, начавшиеся на этом шаге физики (после world.step).
Sourcefn on_before_destroy(&mut self, world: &PhysicsWorld, handle: RigidBodyHandle)
fn on_before_destroy(&mut self, world: &PhysicsWorld, handle: RigidBodyHandle)
Движок зовёт перед удалением тела из очереди уничтожения — возможность прочитать тег и обновить свою бухгалтерию.
Sourcefn on_ai_tick(&mut self, ctx: &mut SimCtx<'_>, dt: f32)
fn on_ai_tick(&mut self, ctx: &mut SimCtx<'_>, dt: f32)
ИИ скриптовых участников; сама решает, есть ли для неё работа.
fn refresh_cached(&mut self, world: &PhysicsWorld)
Sourcefn build_snapshot_blocks(&mut self) -> (Vec<(String, Block)>, bool)
fn build_snapshot_blocks(&mut self) -> (Vec<(String, Block)>, bool)
Собирает игровые блоки снапшота (без динамики карты — её строит движок) и признак “были события” (для классификации канала WebRTC).
fn remove_players_and_shots(&mut self, world: &mut PhysicsWorld) -> Vec<String>
fn clear(&mut self)
fn serialize(&self) -> Value
fn deserialize(&mut self, value: Value) -> Result<(), String>
fn rebuild_spatial_grid(&self, world: &PhysicsWorld, spatial: &mut SpatialGrid)
Provided Methods§
Sourcefn apply_aim(&mut self, _game_id: u32, _seq: u32, _x: f32, _y: f32, _flags: u32)
fn apply_aim(&mut self, _game_id: u32, _seq: u32, _x: f32, _y: f32, _flags: u32)
Аналоговый ввод указателя (мышь/палец): мировая точка и биты состояния указателя — бит 0 «прижат», бит 1 «двойной тап». Дефолт пустой: игра, не знающая про указатель, ничего не замечает, а движок шлёт этот канал только если игра его объявила.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".