Compare commits
3 Commits
fef855d951
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| afff34fff4 | |||
|
|
b1f3d3be23 | ||
|
|
d737568b3e |
@@ -21,4 +21,4 @@ Pure Rust retro-aesthetic 3D game using SDL3 windowing, wgpu rendering, and rapi
|
|||||||
|
|
||||||
- [Structure](structure.md) — modules, types, data flow, dependencies
|
- [Structure](structure.md) — modules, types, data flow, dependencies
|
||||||
- [Guide](guide.md) — conventions, patterns, anti-patterns, testing
|
- [Guide](guide.md) — conventions, patterns, anti-patterns, testing
|
||||||
- [Changelog](changelog.md) — recent changes, active areas, stability
|
- [Changelog](changelog.md) — recent changes, active areas, stability
|
||||||
@@ -1,25 +1,32 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
*Last updated: Friday, April 3, 2026*
|
*Last updated: Tuesday, April 7, 2026*
|
||||||
|
|
||||||
## Active Areas
|
## Active Areas
|
||||||
|
|
||||||
| Area | Changes (30d) | Status |
|
| Area | Changes (30d) | Status |
|
||||||
|------|---|---|
|
|------|---|---|
|
||||||
| Main loop & systems | 9 churn | Active — intent-based architecture solidifying |
|
| Main loop & systems | 9 churn | Active — explicit storage parameters |
|
||||||
| Dialog system | 10 churn | Active — projectiles, camera, rendering |
|
| Dialog system | 10 churn | Active — projectiles, camera, rendering |
|
||||||
| Render core | 15 churn | Active — text pipeline, font atlas, globals |
|
| Render core | 15 churn | Active — text pipeline, font atlas, globals |
|
||||||
| World state | 8 churn | Active — intent storage, component management |
|
| World state | 8 churn | Active — intent storage, component management |
|
||||||
| Player mechanics | 6 churn | Stable — character bundle, player states |
|
| Player mechanics | 6 churn | Stable — character bundle, player states |
|
||||||
| Shader system | 4 churn | Active — gizmo lines, dissolve, snow light |
|
| Shader system | 4 churn | Active — gizmo lines, dissolve, snow light |
|
||||||
|
| Content pipeline | 1 churn | New — Blender export addon |
|
||||||
|
|
||||||
## Recent Changes
|
## Recent Changes
|
||||||
|
|
||||||
|
### System Signature Refactor (Major)
|
||||||
|
- **Completed**: All 16 systems refactored to take explicit `Storage<T>` parameters instead of `&World`/`&mut World`.
|
||||||
|
- **Pattern**: Functions receive only storages they need (e.g., `camera_follow_system` takes `&Storage<FollowComponent>`, `&Storage<CameraComponent>`, `&mut Storage<Transform>`).
|
||||||
|
- **Benefit**: Explicit data dependencies improve borrow checker clarity and code readability.
|
||||||
|
- **Main loop** (`src/main.rs`): Updated to pass individual storage fields at call sites rather than whole `World` reference.
|
||||||
|
- **Affected systems**: `camera_input_system`, `camera_intent_system`, `camera_follow_system`, `camera_noclip_system`, `camera_ground_clamp_system`, `dialog_camera_transition_system`, `dialog_camera_system`, `player_input_system`, `physics_sync_system`, `render_system`, `particle_intent_system`, `particle_update_system`, `trigger_system`, `dialog_system`, `dialog_projectile_system`, all state machines.
|
||||||
|
|
||||||
### Intent-Based Architecture
|
### Intent-Based Architecture
|
||||||
- **Completed major refactor** (3 weeks ago): Systems now communicate through one-frame `Storage<T>` intents instead of direct function calls.
|
- **Completed major refactor** (3 weeks ago): Systems communicate through one-frame `Storage<T>` intents instead of direct function calls.
|
||||||
- **Intent types**: `FollowPlayerIntent`, `StopFollowingIntent`, `CameraTransitionIntent`, `SpawnParticleIntent`
|
- **Intent types**: `FollowPlayerIntent`, `StopFollowingIntent`, `CameraTransitionIntent`, `SpawnParticleIntent`.
|
||||||
- **Consumer pattern**: Systems read intents from world storage, act on them, then remove them. Producers don't import consumer modules.
|
- **Consumer pattern**: Systems read intents from world storage, act on them, then remove them. Producers don't import consumer modules.
|
||||||
- **Documented pattern** in `docs/intent-based-architecture.md` with full execution order contract.
|
|
||||||
|
|
||||||
### Dialog System Suite
|
### Dialog System Suite
|
||||||
- **Dialog state machine**: Ink-based story progression with display timer, projectile phases, parry mechanics.
|
- **Dialog state machine**: Ink-based story progression with display timer, projectile phases, parry mechanics.
|
||||||
@@ -33,51 +40,58 @@
|
|||||||
- **Vertex-based text**: Custom `TextVertex` (position, UV) fed into dedicated text pipeline with view-proj uniform.
|
- **Vertex-based text**: Custom `TextVertex` (position, UV) fed into dedicated text pipeline with view-proj uniform.
|
||||||
|
|
||||||
### Particle System
|
### Particle System
|
||||||
- **Intent-driven spawning**: `SpawnParticleIntent` queues particle emissions; `particle_intent_system` transfers into persistent `ParticleBuffers`.
|
- **Intent-driven spawning**: `particle_intent_system` reads `spawn_particle_intents` Vec, transfers configs into persistent `ParticleBuffers`.
|
||||||
- **Configurable emitters**: Burst count, lifetime range, speed range, directional spread (cone), gravity, size range, color gradient.
|
- **Configurable emitters**: Burst count, lifetime range, speed range, directional spread (cone), gravity, size range, color gradient.
|
||||||
- **Snow particle integration**: Spawned continuously at camera position for screen-fill effect.
|
- **Snow particle integration**: Spawned continuously at camera position for screen-fill effect; `spawn_snow_particles` adds particles to `ParticleBuffers`.
|
||||||
|
|
||||||
### Render Pipeline
|
### Render Pipeline
|
||||||
- **Global renderer via thread-local**: `render::global` module centralizes `Device`/`Queue` access for loaders and systems; long-term goal is explicit `RenderContext` params.
|
- **Global renderer via thread-local**: `render::global` module centralizes `Device`/`Queue` access for loaders and systems.
|
||||||
- **Gizmo shader**: Fragment shader outputs world-normal as axis color (X=red, Y=green, Z=blue) for entity transform editing.
|
- **Draw call generation**: `render_system` reads `entities`, `transforms`, `meshes`, `dissolves` storages; generates `DrawCall` per visible entity.
|
||||||
- **Snow light accumulation**: Persistent texture tracking deformation; blue-noise dithering maps snow brightness into tile pattern (brightness > threshold → dither step).
|
- **Gizmo shader**: Fragment shader outputs world-normal as axis color (X=red, Y=green, Z=blue).
|
||||||
|
- **Snow light accumulation**: Persistent texture tracking deformation; blue-noise dithering maps snow brightness into tile pattern.
|
||||||
- **Dissolve shader**: Blue-noise masked alpha cutoff; controlled by `enable_dissolve` uniform.
|
- **Dissolve shader**: Blue-noise masked alpha cutoff; controlled by `enable_dissolve` uniform.
|
||||||
|
|
||||||
### Tree Occlusion & Instances
|
### Tree Occlusion & Instances
|
||||||
- **Tree dissolve system**: Per-instance dissolve amounts lerp toward targets at configurable speed.
|
- **Tree dissolve system**: Per-instance dissolve amounts lerp toward targets; updated via `tree_occlusion_system` which reads player transforms and cameras.
|
||||||
- **Occlusion detection**: Instances between camera and player dissolve based on perpendicular distance to camera-to-player ray.
|
- **Instance buffer sync**: `tree_instance_buffer_update_system` syncs dissolve state changes to GPU buffer after state updates.
|
||||||
- **Instance buffer sync**: Tree instances updated into GPU buffer after dissolve state changes.
|
|
||||||
|
|
||||||
### Trigger & Event Flow
|
### Trigger & Event Flow
|
||||||
- **Sphere-based triggers**: Continuous state tracking (Idle ↔ Inside); fires `TriggerEvent` with `Entered`/`Exited` kinds.
|
- **Sphere-based triggers**: `trigger_system` runs each fixed step; reads `triggers`, `transforms`, `player_tags` storages; fires `TriggerEvent` with `Entered`/`Exited` kinds.
|
||||||
- **Activation filtering**: `TriggerFilter::Player` specifies which entity types can activate.
|
- **Activation filtering**: `TriggerFilter::Player` specifies which entity types can activate.
|
||||||
- **Event queue**: Events collected in `world.trigger_events` and consumed by dialog system to spawn bubbles.
|
- **Event queue**: Events collected in `world.trigger_events` and consumed by `dialog_system` to spawn bubbles.
|
||||||
|
|
||||||
### Player State Machine
|
### Player State Machine
|
||||||
- **State hierarchy**: Idle, Walking, Jumping, Falling, Leaping (dash), Rolling.
|
- **State hierarchy**: Idle, Walking, Jumping, Falling, Leaping (dash), Rolling.
|
||||||
|
- **Physics per-state**: `state_machine_physics_system` applies damping on enter (Idle), horizontal input application (Walking), vertical velocity control (Jumping).
|
||||||
- **Transition logic**: Grounded checks, input presence, airtime duration.
|
- **Transition logic**: Grounded checks, input presence, airtime duration.
|
||||||
- **Physics per-state**: Damping on enter (Idle), horizontal input application (Walking), vertical velocity control (Jumping).
|
|
||||||
|
|
||||||
### Editor & Inspector
|
### Editor & Inspector
|
||||||
- **Dear ImGui integration**: Inspector window with player state display, entity transform gizmos.
|
- **Dear ImGui integration**: Inspector window with player state display, entity transform gizmos.
|
||||||
- **Entity selection**: Right-click picking; gizmo renders for selected entity when editor active.
|
- **Entity selection**: Right-click picking calls `picking::pick_entity` with ray; gizmo renders for selected entity when editor active.
|
||||||
- **UI mode gating**: Systems check `editor.wants_keyboard()`/`wants_mouse()` to suppress game input during inspector focus.
|
- **UI mode gating**: Systems check `editor.wants_keyboard()`/`wants_mouse()` to suppress game input during inspector focus.
|
||||||
|
|
||||||
|
### Blender Export Addon
|
||||||
|
- **Plugin**: `blender/addons/snow_trail_export.py` provides one-click glTF + EXR export from Blender 5.0.
|
||||||
|
- **glTF operator** (`SNOWTRAIL_OT_export_gltf`): Exports selected mesh objects to `assets/meshes/{blend_filename}.gltf` with configurable modifiers, vertex colors, materials.
|
||||||
|
- **Heightmap bake operator** (`SNOWTRAIL_OT_export_heightmap`): Calls `generate_heightmap.py` to bake terrain Z-position as 32-bit EXR to `assets/textures/terrain_heightmap.exr` (1024px default).
|
||||||
|
- **UI panel**: "Snow Trail" category in 3D viewport; auto-discovers project root by walking directory tree until `assets/` and `blender/` found.
|
||||||
|
|
||||||
## Stability
|
## Stability
|
||||||
|
|
||||||
| Area | Last Changed | Status |
|
| Area | Last Changed | Status |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Physics manager | 80+ days | Stable |
|
| Physics manager | 80+ days | Stable |
|
||||||
| Camera follow | 30 days | Stable — intent system reduced coupling |
|
| Camera follow | 30 days | Stable — now takes explicit storage params |
|
||||||
| Movement component | 30+ days | Stable |
|
| Movement component | 30+ days | Stable |
|
||||||
| Mesh loader | 30+ days | Stable |
|
| Mesh loader | 30+ days | Stable |
|
||||||
| Spotlight sync | 30 days | Stable |
|
| Spotlight sync | 30 days | Stable — explicit storage params applied |
|
||||||
| State machine physics | 30 days | Stable — core transitions unchanged |
|
| State machine physics | 30 days | Stable |
|
||||||
| Debug colliders | 30+ days | Stable |
|
| Debug colliders | 30+ days | Stable |
|
||||||
|
| System signatures | New | Stable — refactor complete, no behavioral changes |
|
||||||
|
|
||||||
## Open Threads
|
## Open Threads
|
||||||
|
|
||||||
- **Global renderer thread-local**: Marked for gradual migration to explicit `RenderContext` parameters on systems/loaders. Current implementation works; refactor is low-priority.
|
- **Global renderer thread-local**: Marked for gradual migration to explicit `RenderContext` parameters on systems/loaders.
|
||||||
- **Text rendering completeness**: Font atlas + text pipeline in place; scaling and color support functional. No known issues.
|
- **Dialog parry mechanics**: Gameplay tuning (PARRY_WINDOW_RADIUS, HIT_RADIUS) ongoing.
|
||||||
- **Dialog parry mechanics**: Projectile system complete; integration with Ink outcomes working. Gameplay tuning (PARRY_WINDOW_RADIUS, HIT_RADIUS) ongoing.
|
- **Tree occlusion performance**: Occlusion system runs every frame; no visibility culling yet. Scalability unknown for >100 trees.
|
||||||
- **Tree occlusion performance**: Occlusion system runs every frame; no visibility culling yet. Scalability unknown for >100 trees.
|
- **Heightmap bake normalization**: Exported EXR uses raw Z-coordinate; game may need per-level scale application.
|
||||||
@@ -42,16 +42,24 @@ pub struct CameraTransitionIntent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// systems/camera.rs - consumer
|
// systems/camera.rs - consumer
|
||||||
pub fn camera_intent_system(world: &mut World) {
|
pub fn camera_intent_system(
|
||||||
let transition_entities: Vec<EntityHandle> = world.camera_transition_intents.all();
|
follow_player_intents: &mut Storage<FollowPlayerIntent>,
|
||||||
|
stop_following_intents: &mut Storage<StopFollowingIntent>,
|
||||||
|
camera_transition_intents: &mut Storage<CameraTransitionIntent>,
|
||||||
|
follows: &mut Storage<FollowComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
camera_transitions: &mut Storage<CameraTransition>,
|
||||||
|
) {
|
||||||
|
let transition_entities: Vec<EntityHandle> = camera_transition_intents.all();
|
||||||
for entity in transition_entities {
|
for entity in transition_entities {
|
||||||
let duration = world
|
let duration = camera_transition_intents
|
||||||
.camera_transition_intents
|
|
||||||
.get(entity)
|
.get(entity)
|
||||||
.map(|i| i.duration)
|
.map(|i| i.duration)
|
||||||
.unwrap_or(0.5);
|
.unwrap_or(0.5);
|
||||||
start_camera_transition(world, entity, duration);
|
start_camera_transition(camera_transitions, transforms, cameras, entity, duration);
|
||||||
world.camera_transition_intents.remove(entity); // consumed
|
camera_transition_intents.remove(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -135,18 +143,17 @@ state_machine.add_transition::<IdleState, WalkingState>(move |world| {
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
// systems/spotlight_sync.rs
|
// systems/spotlight_sync.rs
|
||||||
pub fn spotlight_sync_system(world: &World) -> Vec<Spotlight> {
|
pub fn spotlight_sync_system(spotlights: &Storage<SpotlightComponent>, transforms: &Storage<Transform>) -> Vec<Spotlight> {
|
||||||
let mut spotlights = Vec::new();
|
let mut result = Vec::new();
|
||||||
for entity in world.spotlights.all() {
|
for entity in spotlights.all() {
|
||||||
// Closure captures immutably—safe to call multiple times
|
if let Some(spotlight_component) = spotlights.get(entity) {
|
||||||
if let Some(spotlight_component) = world.spotlights.get(entity) {
|
if let Some(transform) = transforms.get(entity) {
|
||||||
if let Some(transform) = world.transforms.get(entity) {
|
|
||||||
let position = transform.position + spotlight_component.offset;
|
let position = transform.position + spotlight_component.offset;
|
||||||
spotlights.push(Spotlight::new(position, ..));
|
result.push(Spotlight::new(position, ..));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spotlights
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
// With mutation
|
// With mutation
|
||||||
@@ -155,25 +162,46 @@ world.movements.with_mut(entity, |movement| {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### System Function Signature
|
### System Function Signature (Explicit Storage Parameters)
|
||||||
**Why**: Pass only the storages (or immutable `World`) that the system needs. Makes data dependencies explicit.
|
**Why**: Pass only the specific storages (or read-only `&World`) that the system needs. Makes data dependencies explicit for the reader and borrow checker. **This is the standard pattern—all systems follow this.**
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// Good: explicit dependencies
|
// Good: explicit dependencies
|
||||||
pub fn camera_follow_system(world: &mut World) {
|
pub fn camera_follow_system(
|
||||||
let camera_entities: Vec<_> = world.follows.all();
|
follows: &mut Storage<FollowComponent>,
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
) {
|
||||||
|
let camera_entities: Vec<_> = follows.all();
|
||||||
for camera_entity in camera_entities {
|
for camera_entity in camera_entities {
|
||||||
// Access what's needed
|
if let Some(follow) = follows.get(camera_entity) {
|
||||||
if let Some(follow) = world.follows.get(camera_entity) {
|
if let Some(camera) = cameras.get(camera_entity) {
|
||||||
world.transforms.with_mut(camera_entity, |t| {
|
transforms.with_mut(camera_entity, |t| {
|
||||||
t.position = target_position + new_offset;
|
t.position = follow.target_position + new_offset;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For read-only systems
|
// Read-only system
|
||||||
pub fn spotlight_sync_system(world: &World) -> Vec<Spotlight> { .. }
|
pub fn spotlight_sync_system(spotlights: &Storage<SpotlightComponent>, transforms: &Storage<Transform>) -> Vec<Spotlight> { .. }
|
||||||
|
|
||||||
|
// Dialog system example
|
||||||
|
pub fn dialog_system(
|
||||||
|
entities: &mut EntityManager,
|
||||||
|
trigger_events: &[TriggerEvent],
|
||||||
|
dialog_sources: &Storage<DialogSourceComponent>,
|
||||||
|
bubble_tags: &mut Storage<()>,
|
||||||
|
dialog_bubbles: &mut Storage<DialogBubbleComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
names: &mut Storage<String>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
projectile_tags: &mut Storage<()>,
|
||||||
|
dialog_projectiles: &mut Storage<DialogProjectileComponent>,
|
||||||
|
dialog_outcomes: &mut Vec<DialogOutcomeEvent>,
|
||||||
|
delta: f32,
|
||||||
|
) { .. }
|
||||||
```
|
```
|
||||||
|
|
||||||
### Default Trait for Configuration Components
|
### Default Trait for Configuration Components
|
||||||
@@ -227,14 +255,14 @@ fn system_a(world: &mut World) {
|
|||||||
**Do this instead:**
|
**Do this instead:**
|
||||||
```rust
|
```rust
|
||||||
// ✅ Good: intent in queue, flat pipeline
|
// ✅ Good: intent in queue, flat pipeline
|
||||||
pub fn system_a(world: &mut World) {
|
pub fn system_a(cameras: &mut Storage<CameraComponent>) {
|
||||||
world.some_intents.insert(entity, MyIntent { .. });
|
cameras.insert(entity, CameraTransitionIntent { .. });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn system_b(world: &mut World) {
|
pub fn system_b(camera_transitions: &mut Storage<CameraTransition>) {
|
||||||
for entity in world.some_intents.all() {
|
for entity in camera_transitions.all() {
|
||||||
// process
|
// process
|
||||||
world.some_intents.remove(entity);
|
camera_transitions.remove(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -273,46 +301,24 @@ use crate::physics::PhysicsManager;
|
|||||||
let velocity = *PhysicsManager::with_rigidbody_mut(..);
|
let velocity = *PhysicsManager::with_rigidbody_mut(..);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Global or Context-Based Component Queries
|
|
||||||
**Don't do this:**
|
|
||||||
```rust
|
|
||||||
// ❌ Bad: loses intent, repeats queries
|
|
||||||
for entity in world.meshes.all() {
|
|
||||||
if let Some(mesh) = world.meshes.get(entity) { .. }
|
|
||||||
}
|
|
||||||
for entity in world.meshes.all() {
|
|
||||||
if let Some(mesh) = world.meshes.get(entity) { .. }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Do this instead:**
|
|
||||||
```rust
|
|
||||||
// ✅ Good: query once, iterate clearly
|
|
||||||
let entities: Vec<_> = world.meshes.all();
|
|
||||||
for entity in entities {
|
|
||||||
if let Some(mesh_comp) = world.meshes.get(entity) {
|
|
||||||
// process
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Overly Generic (World/&mut World) Parameters
|
### Overly Generic (World/&mut World) Parameters
|
||||||
**Don't do this:**
|
**Don't do this:**
|
||||||
```rust
|
```rust
|
||||||
// ❌ Bad: implicit dependencies
|
// ❌ Bad: implicit dependencies, breaks borrow checker
|
||||||
fn update_position(world: &mut World, entity: EntityHandle) {
|
pub fn camera_follow_system(world: &mut World) {
|
||||||
// What do we actually need?
|
// What storages do we actually need?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Do this instead:**
|
**Do this instead:**
|
||||||
```rust
|
```rust
|
||||||
// ✅ Good: explicit dependencies
|
// ✅ Good: explicit, focused dependencies
|
||||||
fn update_position(
|
pub fn camera_follow_system(
|
||||||
|
follows: &mut Storage<FollowComponent>,
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
transforms: &mut Storage<Transform>,
|
transforms: &mut Storage<Transform>,
|
||||||
entity: EntityHandle,
|
|
||||||
) {
|
) {
|
||||||
transforms.with_mut(entity, |t| t.position.y += 1.0);
|
// Clear what data is needed
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -351,4 +357,6 @@ cargo test -- --nocapture # Show output
|
|||||||
- See **CLAUDE.md** in project root for authoritative style rules (no inline comments, doc comments for public APIs only)
|
- See **CLAUDE.md** in project root for authoritative style rules (no inline comments, doc comments for public APIs only)
|
||||||
- See **docs/self-gating-systems.md** for detailed intent-based pipeline patterns
|
- See **docs/self-gating-systems.md** for detailed intent-based pipeline patterns
|
||||||
- See `src/states/player_states.rs` for canonical State impl examples
|
- See `src/states/player_states.rs` for canonical State impl examples
|
||||||
- See `src/bundles/player.rs` for complete Bundle pattern with state machine setup
|
- See `src/bundles/player.rs` for complete Bundle pattern with state machine setup
|
||||||
|
- See `src/systems/camera.rs` for canonical system function signatures with explicit storage parameters
|
||||||
|
- See `src/systems/dialog_system.rs` for complex multi-storage system example
|
||||||
@@ -25,16 +25,16 @@ Component types define entity data. Key storages:
|
|||||||
Per-entity state machine: `StateMachine` holds current `TypeId`, registered state types, and transitions. `State` trait defines lifecycle (`on_enter`, `on_physics_update`, `on_exit`). Transitions are condition predicates checked each update. Player entity uses this for locomotion states.
|
Per-entity state machine: `StateMachine` holds current `TypeId`, registered state types, and transitions. `State` trait defines lifecycle (`on_enter`, `on_physics_update`, `on_exit`). Transitions are condition predicates checked each update. Player entity uses this for locomotion states.
|
||||||
|
|
||||||
### `src/systems/`
|
### `src/systems/`
|
||||||
Flat list of update functions called in main loop. No cross-system coupling; all communication via world state and intents.
|
Flat list of update functions called in main loop. Systems receive specific storage parameters (e.g., `&mut Storage<Transform>`, `&Storage<PhysicsComponent>`) instead of `&World`/`&mut World`. This makes data dependencies explicit for both borrow checker and reader. No cross-system coupling; all communication via world state and intents.
|
||||||
- **Camera**: `camera_input_system` → generates intents; `camera_intent_system` consumes them; `camera_follow_system` (follows player), `camera_noclip_system`, `camera_transition_system`, `camera_ground_clamp_system`
|
- **Camera**: `camera_input_system(cameras, follows, input_state)` → generates intents; `camera_intent_system(follow_player_intents, stop_following_intents, camera_transition_intents, ...)` consumes them; `camera_follow_system(follows, cameras, transforms)`, `camera_noclip_system(cameras, follows, transforms, input_state, delta)`, `camera_transition_system(camera_transitions, transforms, cameras, delta)`, `camera_ground_clamp_system(cameras, follows, transforms)`
|
||||||
- **Input**: `player_input_system` reads SDL3 `InputState`, writes `InputComponent`
|
- **Input**: `player_input_system(cameras, follows, player_tags, inputs, input_state)` reads SDL3 `InputState`, writes `InputComponent`
|
||||||
- **Physics**: `state_machine_physics_system` (fixed-step), `PhysicsManager::physics_step()`, `physics_sync_system` (copies rapier bodies back to transforms), `trigger_system` (AABB overlap → events)
|
- **Physics**: `state_machine_physics_system(&mut World, FIXED_TIMESTEP)` (fixed-step), `PhysicsManager::physics_step()`, `physics_sync_system(entities, physics, transforms)` copies rapier bodies back to transforms, `trigger_system(trigger_events, triggers, transforms, player_tags)` (AABB overlap → events)
|
||||||
- **Dialog**: `dialog_system` (ticks story state), `dialog_projectile_system` (moves projectiles), `dialog_camera_system` (focuses camera on speaker), `dialog_bubble_render_system` (generates billboard/text draw calls)
|
- **Dialog**: `dialog_system(entities, trigger_events, dialog_sources, bubble_tags, dialog_bubbles, transforms, names, player_tags, projectile_tags, dialog_projectiles, dialog_outcomes, delta)` ticks story state; `dialog_projectile_system(player_tags, transforms, projectile_tags, dialog_projectiles, spawn_particle_intents, dialog_outcomes, leaping_states, rolling_states, input_state)` moves projectiles; `dialog_camera_system(cameras, transforms, bubble_tags, player_pos, delta)` focuses camera on speaker; `dialog_bubble_render_system(transforms, dialog_bubbles, bubble_tags, camera_pos, view_proj)` generates billboard/text draw calls
|
||||||
- **Rendering**: `render_system` collects `DrawCall` from meshes/transforms; `spotlight_sync_system` syncs light positions to shader uniform
|
- **Rendering**: `render_system(entities, transforms, meshes, dissolves)` → `Vec<DrawCall>` from all meshes; snow layer adds clipmap draw calls; debug adds collider/gizmo calls; `spotlight_sync_system(spotlights, transforms)` syncs light positions to shader uniform
|
||||||
- **State machine**: `state_machine_system` (per-frame), `state_machine_physics_system` (fixed-step) tick state lifecycle
|
- **State machine**: `state_machine_system(&mut World, delta)` (per-frame), `state_machine_physics_system(&mut World, FIXED_TIMESTEP)` (fixed-step) tick state lifecycle
|
||||||
- **Trees**: `tree_occlusion_system` (culls trees behind camera), `tree_dissolve_update_system` (animates dissolve), `tree_instance_buffer_update_system` (writes GPU buffer)
|
- **Trees**: `tree_occlusion_system(player_tags, transforms, cameras, tree_instances)` culls trees behind camera; `tree_dissolve_update_system(tree_instances, delta)` animates dissolve; `tree_instance_buffer_update_system(tree_instances)` writes GPU buffer
|
||||||
- **Snow**: `snow_system` deforms snow layer at physics contacts; `particle_intent_system`/`particle_update_system` manage particle emitters
|
- **Snow**: `snow_system(cameras, transforms, player_tags, follows, snow_layer)` deforms snow layer at physics contacts; `particle_intent_system(particle_buffers, spawn_particle_intents)`/`particle_update_system(particle_buffers, delta)` manage particle emitters
|
||||||
- **Rotate**: `rotate_system` rotates entities by delta
|
- **Rotate**: `rotate_system(rotates, transforms, delta)` rotates entities by delta
|
||||||
|
|
||||||
### `src/bundles/`
|
### `src/bundles/`
|
||||||
Factory functions to spawn pre-configured entity groups:
|
Factory functions to spawn pre-configured entity groups:
|
||||||
@@ -90,26 +90,26 @@ Utility modules: ray casting for mouse pick, fullscreen blit/framebuffer downsam
|
|||||||
|
|
||||||
1. **Initialization** (`main.rs` `init()`): SDL3 window → wgpu renderer (Vulkan) → World creation → load scene (Space from glTF) → spawn bundles (player, terrain, camera, lights) → initialize physics
|
1. **Initialization** (`main.rs` `init()`): SDL3 window → wgpu renderer (Vulkan) → World creation → load scene (Space from glTF) → spawn bundles (player, terrain, camera, lights) → initialize physics
|
||||||
2. **Main loop** (`main.rs` `main()` with 60 Hz fixed physics + variable-rate graphics):
|
2. **Main loop** (`main.rs` `main()` with 60 Hz fixed physics + variable-rate graphics):
|
||||||
- **Per-frame** (delta): Input events → `player_input_system` (fills `InputComponent`) + `camera_input_system` (generates intents)
|
- **Per-frame** (delta): Input events → `player_input_system(cameras, follows, player_tags, inputs, input_state)` (fills `InputComponent`) + `camera_input_system(cameras, follows, input_state)` (generates intents)
|
||||||
- **Intent processing**: `camera_intent_system` consumes intents, updates `CameraComponent`/`CameraTransition`
|
- **Intent processing**: `camera_intent_system(follow_player_intents, stop_following_intents, camera_transition_intents, follows, transforms, cameras, player_tags, camera_transitions)` consumes intents, updates `CameraComponent`/`CameraTransition`
|
||||||
- **Camera systems**: follow player, noclip, transition, clamp to ground
|
- **Camera systems**: `camera_follow_system(follows, cameras, transforms)` follows player; `camera_noclip_system(cameras, follows, transforms, input_state, delta)` noclip mode; `camera_transition_system(camera_transitions, transforms, cameras, delta)` animated transitions; `camera_ground_clamp_system(cameras, follows, transforms)` clamps to ground
|
||||||
- **Fixed physics** (1/60s accumulator):
|
- **Fixed physics** (1/60s accumulator):
|
||||||
- `state_machine_physics_system`: tick state's `on_physics_update()`
|
- `state_machine_physics_system(&mut World, FIXED_TIMESTEP)`: tick state's `on_physics_update()`
|
||||||
- `PhysicsManager::physics_step()`: rapier integration
|
- `PhysicsManager::physics_step()`: rapier integration
|
||||||
- `physics_sync_system`: copy rigidbody poses to `Transform`
|
- `physics_sync_system(entities, physics, transforms)`: copy rigidbody poses to `Transform`
|
||||||
- `trigger_system`: detect collisions, emit events
|
- `trigger_system(trigger_events, triggers, transforms, player_tags)`: detect collisions, emit events
|
||||||
- `dialog_system`, `dialog_projectile_system`: Ink story tick, projectile movement
|
- `dialog_system(entities, trigger_events, dialog_sources, bubble_tags, dialog_bubbles, transforms, names, player_tags, projectile_tags, dialog_projectiles, dialog_outcomes, delta)` ticks story state; `dialog_projectile_system(player_tags, transforms, projectile_tags, dialog_projectiles, spawn_particle_intents, dialog_outcomes, leaping_states, rolling_states, input_state)` moves projectiles
|
||||||
- **Per-frame systems**: `state_machine_system` (non-physics update), rotate, particle, tree dissolve, snow deformation, spotlight sync
|
- **Per-frame systems**: `state_machine_system(&mut World, delta)` ticks state lifecycle; `rotate_system(rotates, transforms, delta)` rotates entities; `particle_intent_system(particle_buffers, spawn_particle_intents)`/`particle_update_system(particle_buffers, delta)` manage particles; `tree_occlusion_system(player_tags, transforms, cameras, tree_instances)` culls; `tree_dissolve_update_system(tree_instances, delta)`/`tree_instance_buffer_update_system(tree_instances)` updates dissolve; `snow_system(cameras, transforms, player_tags, follows, snow_layer)` deforms snow; `spotlight_sync_system(spotlights, transforms)` syncs lights
|
||||||
- **Render collection**: `render_system` → `Vec<DrawCall>` from all meshes; snow layer adds clipmap draw calls; debug adds collider/gizmo calls
|
- **Render collection**: `render_system(entities, transforms, meshes, dissolves)` → `Vec<DrawCall>` from all meshes; snow layer adds clipmap draw calls; debug adds collider/gizmo calls
|
||||||
- **Submission**: `submit_frame()` renders draw calls, dialog bubbles/text, particles to framebuffer; blit to screen; optional ImGui overlay
|
- **Submission**: `submit_frame()` renders draw calls, dialog bubbles/text, particles to framebuffer; blit to screen; optional ImGui overlay
|
||||||
3. **Frame cleanup**: `InputState::clear_just_pressed()` (flags reset for next frame)
|
3. **Frame cleanup**: `InputState::clear_just_pressed()` resets one-frame flags
|
||||||
|
|
||||||
## Key Types
|
## Key Types
|
||||||
|
|
||||||
| Type | Module | Description |
|
| Type | Module | Description |
|
||||||
|------|--------|-------------|
|
|------|--------|-------------|
|
||||||
| `EntityHandle` | entity | u64 opaque entity ID |
|
| `EntityHandle` | entity | u64 opaque entity ID |
|
||||||
| `Storage<T>` | world | HashMap storage for per-entity component data |
|
| `Storage<T>` | world | HashMap storage for per-entity component data; exposes `.get()`, `.get_mut()`, `.with_mut()`, `.all()` methods |
|
||||||
| `World` | world | ECS container: entities, 20+ storages, intent queues, singleton state |
|
| `World` | world | ECS container: entities, 20+ storages, intent queues, singleton state |
|
||||||
| `Transform` | utility/transform | Position (Vec3), rotation (Quat), scale (Vec3); matrix conversions |
|
| `Transform` | utility/transform | Position (Vec3), rotation (Quat), scale (Vec3); matrix conversions |
|
||||||
| `StateMachine` | states/state | Per-entity state machine: current state TypeId, registered states, transitions |
|
| `StateMachine` | states/state | Per-entity state machine: current state TypeId, registered states, transitions |
|
||||||
@@ -146,10 +146,10 @@ Utility modules: ray casting for mouse pick, fullscreen blit/framebuffer downsam
|
|||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
- **Engine**: wgpu (GPU), rapier3d (physics), glam (math), nalgebra (nalgebra for physics conversions), SDL3 (windowing/input)
|
- **Engine**: wgpu (GPU), rapier3d (physics), glam (math), nalgebra (physics conversions), SDL3 (windowing/input)
|
||||||
- **Content**: bladeink (Ink story scripting), image crate (EXR heightmaps), gltf (scene loading)
|
- **Content**: bladeink (Ink story scripting), image crate (EXR heightmaps), gltf (scene loading)
|
||||||
- **Editor**: Dear ImGui via imgui crate + SDL3 integration
|
- **Editor**: Dear ImGui via imgui crate + SDL3 integration
|
||||||
- **Internal**: All systems read/write `World`; systems are called in fixed sequence from main loop; no circular dependencies
|
- **Internal**: All systems take explicit storage parameters from `World`; systems are called in fixed sequence from main loop; no circular dependencies
|
||||||
- **Thread-local singletons**: `Renderer` (render/global.rs), `PhysicsManager` (physics.rs), `GLOBAL_RENDERER`, `GLOBAL_PHYSICS`
|
- **Thread-local singletons**: `Renderer` (render/global.rs), `PhysicsManager` (physics.rs), `GLOBAL_RENDERER`, `GLOBAL_PHYSICS`
|
||||||
|
|
||||||
## Initialization Order
|
## Initialization Order
|
||||||
|
|||||||
166
src/main.rs
166
src/main.rs
@@ -305,7 +305,11 @@ fn toggle_editor(game: &mut Game)
|
|||||||
|
|
||||||
fn handle_editor_pick(game: &mut Game, x: f32, y: f32)
|
fn handle_editor_pick(game: &mut Game, x: f32, y: f32)
|
||||||
{
|
{
|
||||||
let view = match camera_view_matrix(&game.world)
|
let view = match camera_view_matrix(
|
||||||
|
&game.world.cameras,
|
||||||
|
&game.world.transforms,
|
||||||
|
&game.world.follows,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return,
|
None => return,
|
||||||
@@ -340,7 +344,11 @@ fn submit_frame(
|
|||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let view = match camera_view_matrix(&game.world)
|
let view = match camera_view_matrix(
|
||||||
|
&game.world.cameras,
|
||||||
|
&game.world.transforms,
|
||||||
|
&game.world.follows,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return,
|
None => return,
|
||||||
@@ -350,8 +358,13 @@ fn submit_frame(
|
|||||||
let view_proj = projection * view;
|
let view_proj = projection * view;
|
||||||
let player_pos = game.world.player_position();
|
let player_pos = game.world.player_position();
|
||||||
|
|
||||||
let (billboard_calls, text_vertices) =
|
let (billboard_calls, text_vertices) = dialog_bubble_render_system(
|
||||||
dialog_bubble_render_system(&game.world, camera_transform.position, view_proj);
|
&game.world.transforms,
|
||||||
|
&game.world.dialog_bubbles,
|
||||||
|
&game.world.bubble_tags,
|
||||||
|
camera_transform.position,
|
||||||
|
view_proj,
|
||||||
|
);
|
||||||
|
|
||||||
let frame = render::render(
|
let frame = render::render(
|
||||||
&view,
|
&view,
|
||||||
@@ -414,17 +427,67 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- intent generation ---
|
// --- intent generation ---
|
||||||
camera_input_system(&mut game.world, &game.input_state);
|
camera_input_system(
|
||||||
player_input_system(&mut game.world, &game.input_state);
|
&mut game.world.cameras,
|
||||||
dialog_camera_transition_system(&mut game.world, game.camera_entity);
|
&game.world.follows,
|
||||||
|
&game.input_state,
|
||||||
|
);
|
||||||
|
player_input_system(
|
||||||
|
&game.world.cameras,
|
||||||
|
&game.world.follows,
|
||||||
|
&game.world.player_tags,
|
||||||
|
&mut game.world.inputs,
|
||||||
|
&game.input_state,
|
||||||
|
);
|
||||||
|
dialog_camera_transition_system(
|
||||||
|
&game.world.bubble_tags,
|
||||||
|
&mut game.world.camera_transition_intents,
|
||||||
|
&mut game.world.was_dialog_active,
|
||||||
|
game.camera_entity,
|
||||||
|
);
|
||||||
|
|
||||||
// --- intent processing + camera ---
|
// --- intent processing + camera ---
|
||||||
camera_intent_system(&mut game.world);
|
camera_intent_system(
|
||||||
camera_noclip_system(&mut game.world, &game.input_state, delta);
|
&mut game.world.follow_player_intents,
|
||||||
dialog_camera_system(&mut game.world, delta);
|
&mut game.world.stop_following_intents,
|
||||||
camera_follow_system(&mut game.world);
|
&mut game.world.camera_transition_intents,
|
||||||
camera_transition_system(&mut game.world, delta);
|
&mut game.world.follows,
|
||||||
camera_ground_clamp_system(&mut game.world);
|
&mut game.world.transforms,
|
||||||
|
&mut game.world.cameras,
|
||||||
|
&game.world.player_tags,
|
||||||
|
&mut game.world.camera_transitions,
|
||||||
|
);
|
||||||
|
camera_noclip_system(
|
||||||
|
&game.world.cameras,
|
||||||
|
&game.world.follows,
|
||||||
|
&mut game.world.transforms,
|
||||||
|
&game.input_state,
|
||||||
|
delta,
|
||||||
|
);
|
||||||
|
let player_pos = game.world.player_position();
|
||||||
|
dialog_camera_system(
|
||||||
|
&mut game.world.cameras,
|
||||||
|
&mut game.world.transforms,
|
||||||
|
&game.world.bubble_tags,
|
||||||
|
player_pos,
|
||||||
|
delta,
|
||||||
|
);
|
||||||
|
camera_follow_system(
|
||||||
|
&mut game.world.follows,
|
||||||
|
&game.world.cameras,
|
||||||
|
&mut game.world.transforms,
|
||||||
|
);
|
||||||
|
camera_transition_system(
|
||||||
|
&mut game.world.camera_transitions,
|
||||||
|
&mut game.world.transforms,
|
||||||
|
&mut game.world.cameras,
|
||||||
|
delta,
|
||||||
|
);
|
||||||
|
camera_ground_clamp_system(
|
||||||
|
&game.world.cameras,
|
||||||
|
&game.world.follows,
|
||||||
|
&mut game.world.transforms,
|
||||||
|
);
|
||||||
|
|
||||||
// --- editor overlay ---
|
// --- editor overlay ---
|
||||||
if game.editor.active
|
if game.editor.active
|
||||||
@@ -444,10 +507,42 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
|||||||
{
|
{
|
||||||
state_machine_physics_system(&mut game.world, FIXED_TIMESTEP);
|
state_machine_physics_system(&mut game.world, FIXED_TIMESTEP);
|
||||||
PhysicsManager::physics_step();
|
PhysicsManager::physics_step();
|
||||||
physics_sync_system(&mut game.world);
|
physics_sync_system(
|
||||||
trigger_system(&mut game.world);
|
&game.world.entities,
|
||||||
dialog_system(&mut game.world, FIXED_TIMESTEP);
|
&game.world.physics,
|
||||||
dialog_projectile_system(&mut game.world, &game.input_state);
|
&mut game.world.transforms,
|
||||||
|
);
|
||||||
|
trigger_system(
|
||||||
|
&mut game.world.trigger_events,
|
||||||
|
&mut game.world.triggers,
|
||||||
|
&game.world.transforms,
|
||||||
|
&game.world.player_tags,
|
||||||
|
);
|
||||||
|
dialog_system(
|
||||||
|
&mut game.world.entities,
|
||||||
|
&game.world.trigger_events,
|
||||||
|
&game.world.dialog_sources,
|
||||||
|
&mut game.world.bubble_tags,
|
||||||
|
&mut game.world.dialog_bubbles,
|
||||||
|
&mut game.world.transforms,
|
||||||
|
&mut game.world.names,
|
||||||
|
&game.world.player_tags,
|
||||||
|
&mut game.world.projectile_tags,
|
||||||
|
&mut game.world.dialog_projectiles,
|
||||||
|
&mut game.world.dialog_outcomes,
|
||||||
|
FIXED_TIMESTEP,
|
||||||
|
);
|
||||||
|
dialog_projectile_system(
|
||||||
|
&game.world.player_tags,
|
||||||
|
&mut game.world.transforms,
|
||||||
|
&mut game.world.projectile_tags,
|
||||||
|
&mut game.world.dialog_projectiles,
|
||||||
|
&mut game.world.spawn_particle_intents,
|
||||||
|
&mut game.world.dialog_outcomes,
|
||||||
|
&game.world.leaping_states,
|
||||||
|
&game.world.rolling_states,
|
||||||
|
&game.input_state,
|
||||||
|
);
|
||||||
game.physics_accumulator -= FIXED_TIMESTEP;
|
game.physics_accumulator -= FIXED_TIMESTEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,19 +550,33 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
|||||||
|
|
||||||
// --- per-frame systems ---
|
// --- per-frame systems ---
|
||||||
state_machine_system(&mut game.world, delta);
|
state_machine_system(&mut game.world, delta);
|
||||||
rotate_system(&mut game.world, delta);
|
rotate_system(&game.world.rotates, &mut game.world.transforms, delta);
|
||||||
|
|
||||||
tree_occlusion_system(&mut game.world);
|
tree_occlusion_system(
|
||||||
tree_dissolve_update_system(&mut game.world, delta);
|
&game.world.player_tags,
|
||||||
tree_instance_buffer_update_system(&mut game.world);
|
&game.world.transforms,
|
||||||
|
&game.world.cameras,
|
||||||
|
&mut game.world.tree_instances,
|
||||||
|
);
|
||||||
|
tree_dissolve_update_system(&mut game.world.tree_instances, delta);
|
||||||
|
tree_instance_buffer_update_system(&game.world.tree_instances);
|
||||||
|
|
||||||
let spotlights = spotlight_sync_system(&game.world);
|
let spotlights = spotlight_sync_system(&game.world.spotlights, &game.world.transforms);
|
||||||
render::update_spotlights(spotlights);
|
render::update_spotlights(spotlights);
|
||||||
|
|
||||||
snow_system(&mut game.world);
|
snow_system(
|
||||||
|
&game.world.cameras,
|
||||||
|
&game.world.transforms,
|
||||||
|
&game.world.player_tags,
|
||||||
|
&game.world.follows,
|
||||||
|
&mut game.world.snow_layer,
|
||||||
|
);
|
||||||
|
|
||||||
particle_intent_system(&mut game.world);
|
particle_intent_system(
|
||||||
particle_update_system(&mut game.world, delta);
|
&mut game.world.particle_buffers,
|
||||||
|
&mut game.world.spawn_particle_intents,
|
||||||
|
);
|
||||||
|
particle_update_system(&mut game.world.particle_buffers, delta);
|
||||||
let particle_cam_pos = game.world.active_camera_position();
|
let particle_cam_pos = game.world.active_camera_position();
|
||||||
if let Some(ref mut buffers) = game.world.particle_buffers
|
if let Some(ref mut buffers) = game.world.particle_buffers
|
||||||
{
|
{
|
||||||
@@ -475,7 +584,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- draw call collection ---
|
// --- draw call collection ---
|
||||||
let mut draw_calls = render_system(&game.world);
|
let mut draw_calls = render_system(
|
||||||
|
&game.world.entities,
|
||||||
|
&game.world.transforms,
|
||||||
|
&game.world.meshes,
|
||||||
|
&game.world.dissolves,
|
||||||
|
);
|
||||||
if let Some(ref snow_layer) = game.world.snow_layer
|
if let Some(ref snow_layer) = game.world.snow_layer
|
||||||
{
|
{
|
||||||
draw_calls.extend(snow_layer.get_draw_calls());
|
draw_calls.extend(snow_layer.get_draw_calls());
|
||||||
|
|||||||
@@ -1,22 +1,32 @@
|
|||||||
use glam::Vec3;
|
use glam::Vec3;
|
||||||
|
|
||||||
use crate::components::camera::CameraTransition;
|
use crate::components::camera::{CameraComponent, CameraTransition};
|
||||||
|
use crate::components::intent::{CameraTransitionIntent, FollowPlayerIntent, StopFollowingIntent};
|
||||||
use crate::components::FollowComponent;
|
use crate::components::FollowComponent;
|
||||||
use crate::entity::EntityHandle;
|
use crate::entity::EntityHandle;
|
||||||
use crate::physics::PhysicsManager;
|
use crate::physics::PhysicsManager;
|
||||||
use crate::utility::input::InputState;
|
use crate::utility::input::InputState;
|
||||||
use crate::world::{Transform, World};
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
const CAMERA_GROUND_OFFSET: f32 = 2.0;
|
const CAMERA_GROUND_OFFSET: f32 = 2.0;
|
||||||
|
|
||||||
pub fn camera_view_matrix(world: &World) -> Option<glam::Mat4>
|
pub fn camera_view_matrix(
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
transforms: &Storage<Transform>,
|
||||||
|
follows: &Storage<FollowComponent>,
|
||||||
|
) -> Option<glam::Mat4>
|
||||||
{
|
{
|
||||||
let (camera_entity, camera_component) = world.active_camera()?;
|
let (camera_entity, camera_component) = cameras
|
||||||
let camera_transform = world.transforms.get(camera_entity)?;
|
.components
|
||||||
|
.iter()
|
||||||
|
.find(|(_, cam)| cam.is_active)
|
||||||
|
.map(|(e, c)| (*e, c))?;
|
||||||
|
let camera_transform = transforms.get(camera_entity)?;
|
||||||
|
|
||||||
if let Some(follow) = world.follows.get(camera_entity)
|
if let Some(follow) = follows.get(camera_entity)
|
||||||
{
|
{
|
||||||
if let Some(target_transform) = world.transforms.get(follow.target)
|
if let Some(target_transform) = transforms.get(follow.target)
|
||||||
{
|
{
|
||||||
return Some(glam::Mat4::look_at_rh(
|
return Some(glam::Mat4::look_at_rh(
|
||||||
camera_transform.position,
|
camera_transform.position,
|
||||||
@@ -35,13 +45,17 @@ pub fn camera_view_matrix(world: &World) -> Option<glam::Mat4>
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn camera_input_system(world: &mut World, input_state: &InputState)
|
pub fn camera_input_system(
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
follows: &Storage<FollowComponent>,
|
||||||
|
input_state: &InputState,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let cameras: Vec<_> = world.cameras.all();
|
let camera_entities: Vec<_> = cameras.all();
|
||||||
|
|
||||||
for camera_entity in cameras
|
for camera_entity in camera_entities
|
||||||
{
|
{
|
||||||
if let Some(camera) = world.cameras.get_mut(camera_entity)
|
if let Some(camera) = cameras.get_mut(camera_entity)
|
||||||
{
|
{
|
||||||
if !camera.is_active
|
if !camera.is_active
|
||||||
{
|
{
|
||||||
@@ -50,7 +64,7 @@ pub fn camera_input_system(world: &mut World, input_state: &InputState)
|
|||||||
|
|
||||||
if input_state.mouse_delta.0.abs() > 0.0 || input_state.mouse_delta.1.abs() > 0.0
|
if input_state.mouse_delta.0.abs() > 0.0 || input_state.mouse_delta.1.abs() > 0.0
|
||||||
{
|
{
|
||||||
let is_following = world.follows.get(camera_entity).is_some();
|
let is_following = follows.get(camera_entity).is_some();
|
||||||
|
|
||||||
camera.yaw += input_state.mouse_delta.0 * 0.0008;
|
camera.yaw += input_state.mouse_delta.0 * 0.0008;
|
||||||
|
|
||||||
@@ -71,49 +85,61 @@ pub fn camera_input_system(world: &mut World, input_state: &InputState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn camera_intent_system(world: &mut World)
|
pub fn camera_intent_system(
|
||||||
|
follow_player_intents: &mut Storage<FollowPlayerIntent>,
|
||||||
|
stop_following_intents: &mut Storage<StopFollowingIntent>,
|
||||||
|
camera_transition_intents: &mut Storage<CameraTransitionIntent>,
|
||||||
|
follows: &mut Storage<FollowComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
camera_transitions: &mut Storage<CameraTransition>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let follow_entities: Vec<EntityHandle> = world.follow_player_intents.all();
|
let follow_entities: Vec<EntityHandle> = follow_player_intents.all();
|
||||||
for entity in follow_entities
|
for entity in follow_entities
|
||||||
{
|
{
|
||||||
start_camera_following(world, entity);
|
start_camera_following(follows, transforms, cameras, player_tags, entity);
|
||||||
world.follow_player_intents.remove(entity);
|
follow_player_intents.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
let stop_entities: Vec<EntityHandle> = world.stop_following_intents.all();
|
let stop_entities: Vec<EntityHandle> = stop_following_intents.all();
|
||||||
for entity in stop_entities
|
for entity in stop_entities
|
||||||
{
|
{
|
||||||
stop_camera_following(world, entity);
|
stop_camera_following(follows, transforms, cameras, entity);
|
||||||
world.stop_following_intents.remove(entity);
|
stop_following_intents.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
let transition_entities: Vec<EntityHandle> = world.camera_transition_intents.all();
|
let transition_entities: Vec<EntityHandle> = camera_transition_intents.all();
|
||||||
for entity in transition_entities
|
for entity in transition_entities
|
||||||
{
|
{
|
||||||
let duration = world
|
let duration = camera_transition_intents
|
||||||
.camera_transition_intents
|
|
||||||
.get(entity)
|
.get(entity)
|
||||||
.map(|i| i.duration)
|
.map(|i| i.duration)
|
||||||
.unwrap_or(0.5);
|
.unwrap_or(0.5);
|
||||||
start_camera_transition(world, entity, duration);
|
start_camera_transition(camera_transitions, transforms, cameras, entity, duration);
|
||||||
world.camera_transition_intents.remove(entity);
|
camera_transition_intents.remove(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn camera_follow_system(world: &mut World)
|
pub fn camera_follow_system(
|
||||||
|
follows: &mut Storage<FollowComponent>,
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let camera_entities: Vec<_> = world.follows.all();
|
let camera_entities: Vec<_> = follows.all();
|
||||||
|
|
||||||
for camera_entity in camera_entities
|
for camera_entity in camera_entities
|
||||||
{
|
{
|
||||||
if let Some(camera) = world.cameras.get(camera_entity)
|
if let Some(camera) = cameras.get(camera_entity)
|
||||||
{
|
{
|
||||||
if let Some(follow) = world.follows.get(camera_entity)
|
if let Some(follow) = follows.get(camera_entity)
|
||||||
{
|
{
|
||||||
let target_entity = follow.target;
|
let target_entity = follow.target;
|
||||||
let offset = follow.offset.position;
|
let offset = follow.offset.position;
|
||||||
|
|
||||||
if let Some(target_transform) = world.transforms.get(target_entity)
|
if let Some(target_transform) = transforms.get(target_entity)
|
||||||
{
|
{
|
||||||
let target_position = target_transform.position;
|
let target_position = target_transform.position;
|
||||||
let distance = offset.length();
|
let distance = offset.length();
|
||||||
@@ -126,13 +152,11 @@ pub fn camera_follow_system(world: &mut World)
|
|||||||
|
|
||||||
let new_offset = Vec3::new(offset_x, offset_y, offset_z);
|
let new_offset = Vec3::new(offset_x, offset_y, offset_z);
|
||||||
|
|
||||||
world
|
transforms.with_mut(camera_entity, |camera_transform| {
|
||||||
.transforms
|
camera_transform.position = target_position + new_offset;
|
||||||
.with_mut(camera_entity, |camera_transform| {
|
});
|
||||||
camera_transform.position = target_position + new_offset;
|
|
||||||
});
|
|
||||||
|
|
||||||
world.follows.components.get_mut(&camera_entity).map(|f| {
|
follows.components.get_mut(&camera_entity).map(|f| {
|
||||||
f.offset.position = new_offset;
|
f.offset.position = new_offset;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -141,23 +165,29 @@ pub fn camera_follow_system(world: &mut World)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn camera_noclip_system(world: &mut World, input_state: &InputState, delta: f32)
|
pub fn camera_noclip_system(
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
follows: &Storage<FollowComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
input_state: &InputState,
|
||||||
|
delta: f32,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if !input_state.mouse_captured
|
if !input_state.mouse_captured
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cameras: Vec<_> = world.cameras.all();
|
let camera_entities: Vec<_> = cameras.all();
|
||||||
|
|
||||||
for camera_entity in cameras
|
for camera_entity in camera_entities
|
||||||
{
|
{
|
||||||
if world.follows.get(camera_entity).is_some()
|
if follows.get(camera_entity).is_some()
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(camera) = world.cameras.get(camera_entity)
|
if let Some(camera) = cameras.get(camera_entity)
|
||||||
{
|
{
|
||||||
if !camera.is_active
|
if !camera.is_active
|
||||||
{
|
{
|
||||||
@@ -201,7 +231,7 @@ pub fn camera_noclip_system(world: &mut World, input_state: &InputState, delta:
|
|||||||
speed *= 10.0;
|
speed *= 10.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(camera_transform) = world.transforms.get_mut(camera_entity)
|
if let Some(camera_transform) = transforms.get_mut(camera_entity)
|
||||||
{
|
{
|
||||||
camera_transform.position += forward * input_vec.z * speed;
|
camera_transform.position += forward * input_vec.z * speed;
|
||||||
camera_transform.position += right * input_vec.x * speed;
|
camera_transform.position += right * input_vec.x * speed;
|
||||||
@@ -211,28 +241,34 @@ pub fn camera_noclip_system(world: &mut World, input_state: &InputState, delta:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_camera_following(world: &mut World, camera_entity: crate::entity::EntityHandle)
|
fn start_camera_following(
|
||||||
|
follows: &mut Storage<FollowComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
camera_entity: EntityHandle,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if let Some(camera_transform) = world.transforms.get(camera_entity)
|
if let Some(camera_transform) = transforms.get(camera_entity)
|
||||||
{
|
{
|
||||||
let player_entities = world.player_tags.all();
|
let player_entities = player_tags.all();
|
||||||
if let Some(&player_entity) = player_entities.first()
|
if let Some(&player_entity) = player_entities.first()
|
||||||
{
|
{
|
||||||
if let Some(target_transform) = world.transforms.get(player_entity)
|
if let Some(target_transform) = transforms.get(player_entity)
|
||||||
{
|
{
|
||||||
let offset = camera_transform.position - target_transform.position;
|
let offset = camera_transform.position - target_transform.position;
|
||||||
let distance = offset.length();
|
let distance = offset.length();
|
||||||
|
|
||||||
if distance > 0.0
|
if distance > 0.0
|
||||||
{
|
{
|
||||||
if let Some(camera) = world.cameras.get_mut(camera_entity)
|
if let Some(camera) = cameras.get_mut(camera_entity)
|
||||||
{
|
{
|
||||||
camera.pitch = (offset.y / distance).asin();
|
camera.pitch = (offset.y / distance).asin();
|
||||||
camera.yaw = offset.z.atan2(offset.x) + std::f32::consts::PI;
|
camera.yaw = offset.z.atan2(offset.x) + std::f32::consts::PI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
world.follows.insert(
|
follows.insert(
|
||||||
camera_entity,
|
camera_entity,
|
||||||
FollowComponent {
|
FollowComponent {
|
||||||
target: player_entity,
|
target: player_entity,
|
||||||
@@ -246,20 +282,25 @@ fn start_camera_following(world: &mut World, camera_entity: crate::entity::Entit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_camera_following(world: &mut World, camera_entity: crate::entity::EntityHandle)
|
fn stop_camera_following(
|
||||||
|
follows: &mut Storage<FollowComponent>,
|
||||||
|
transforms: &Storage<Transform>,
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
camera_entity: EntityHandle,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if let Some(follow) = world.follows.get(camera_entity)
|
if let Some(follow) = follows.get(camera_entity)
|
||||||
{
|
{
|
||||||
let target_entity = follow.target;
|
let target_entity = follow.target;
|
||||||
|
|
||||||
if let Some(camera_transform) = world.transforms.get(camera_entity)
|
if let Some(camera_transform) = transforms.get(camera_entity)
|
||||||
{
|
{
|
||||||
if let Some(target_transform) = world.transforms.get(target_entity)
|
if let Some(target_transform) = transforms.get(target_entity)
|
||||||
{
|
{
|
||||||
let look_direction =
|
let look_direction =
|
||||||
(target_transform.position - camera_transform.position).normalize();
|
(target_transform.position - camera_transform.position).normalize();
|
||||||
|
|
||||||
if let Some(camera) = world.cameras.get_mut(camera_entity)
|
if let Some(camera) = cameras.get_mut(camera_entity)
|
||||||
{
|
{
|
||||||
camera.yaw = look_direction.z.atan2(look_direction.x);
|
camera.yaw = look_direction.z.atan2(look_direction.x);
|
||||||
camera.pitch = look_direction.y.asin();
|
camera.pitch = look_direction.y.asin();
|
||||||
@@ -267,24 +308,34 @@ fn stop_camera_following(world: &mut World, camera_entity: crate::entity::Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
world.follows.remove(camera_entity);
|
follows.remove(camera_entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn camera_ground_clamp_system(world: &mut World)
|
pub fn camera_ground_clamp_system(
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
follows: &Storage<FollowComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let Some((camera_entity, _)) = world.active_camera()
|
let camera_entity = cameras
|
||||||
|
.components
|
||||||
|
.iter()
|
||||||
|
.find(|(_, cam)| cam.is_active)
|
||||||
|
.map(|(e, _)| *e);
|
||||||
|
|
||||||
|
let Some(camera_entity) = camera_entity
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if world.follows.get(camera_entity).is_none()
|
if follows.get(camera_entity).is_none()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
world.transforms.with_mut(camera_entity, |t| {
|
transforms.with_mut(camera_entity, |t| {
|
||||||
let ground_y =
|
let ground_y =
|
||||||
PhysicsManager::get_terrain_height_at(t.position.x, t.position.z).unwrap_or(0.0);
|
PhysicsManager::get_terrain_height_at(t.position.x, t.position.z).unwrap_or(0.0);
|
||||||
let min_y = ground_y + CAMERA_GROUND_OFFSET;
|
let min_y = ground_y + CAMERA_GROUND_OFFSET;
|
||||||
@@ -295,9 +346,15 @@ pub fn camera_ground_clamp_system(world: &mut World)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_camera_transition(world: &mut World, camera_entity: EntityHandle, duration: f32)
|
fn start_camera_transition(
|
||||||
|
camera_transitions: &mut Storage<CameraTransition>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
camera_entity: EntityHandle,
|
||||||
|
duration: f32,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let Some(camera) = world.cameras.get(camera_entity)
|
let Some(camera) = cameras.get(camera_entity)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -306,12 +363,11 @@ fn start_camera_transition(world: &mut World, camera_entity: EntityHandle, durat
|
|||||||
let source_yaw = camera.yaw;
|
let source_yaw = camera.yaw;
|
||||||
let source_pitch = camera.pitch;
|
let source_pitch = camera.pitch;
|
||||||
|
|
||||||
let source_position = world
|
let source_position = transforms
|
||||||
.transforms
|
|
||||||
.with(camera_entity, |t| t.position)
|
.with(camera_entity, |t| t.position)
|
||||||
.unwrap_or(Vec3::ZERO);
|
.unwrap_or(Vec3::ZERO);
|
||||||
|
|
||||||
world.camera_transitions.insert(
|
camera_transitions.insert(
|
||||||
camera_entity,
|
camera_entity,
|
||||||
CameraTransition {
|
CameraTransition {
|
||||||
source_position,
|
source_position,
|
||||||
@@ -323,14 +379,19 @@ fn start_camera_transition(world: &mut World, camera_entity: EntityHandle, durat
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn camera_transition_system(world: &mut World, delta: f32)
|
pub fn camera_transition_system(
|
||||||
|
camera_transitions: &mut Storage<CameraTransition>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
delta: f32,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let entities: Vec<EntityHandle> = world.camera_transitions.all();
|
let entities: Vec<EntityHandle> = camera_transitions.all();
|
||||||
|
|
||||||
for entity in entities
|
for entity in entities
|
||||||
{
|
{
|
||||||
let finished = {
|
let finished = {
|
||||||
let Some(transition) = world.camera_transitions.get_mut(entity)
|
let Some(transition) = camera_transitions.get_mut(entity)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -345,11 +406,11 @@ pub fn camera_transition_system(world: &mut World, delta: f32)
|
|||||||
let source_pitch = transition.source_pitch;
|
let source_pitch = transition.source_pitch;
|
||||||
let finished = t >= 1.0;
|
let finished = t >= 1.0;
|
||||||
|
|
||||||
world.transforms.with_mut(entity, |transform| {
|
transforms.with_mut(entity, |transform| {
|
||||||
transform.position = source_position.lerp(transform.position, t);
|
transform.position = source_position.lerp(transform.position, t);
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(camera) = world.cameras.get_mut(entity)
|
if let Some(camera) = cameras.get_mut(entity)
|
||||||
{
|
{
|
||||||
camera.yaw = lerp_angle(source_yaw, camera.yaw, t);
|
camera.yaw = lerp_angle(source_yaw, camera.yaw, t);
|
||||||
camera.pitch = source_pitch + (camera.pitch - source_pitch) * t;
|
camera.pitch = source_pitch + (camera.pitch - source_pitch) * t;
|
||||||
@@ -357,13 +418,12 @@ pub fn camera_transition_system(world: &mut World, delta: f32)
|
|||||||
|
|
||||||
if !finished
|
if !finished
|
||||||
{
|
{
|
||||||
if let Some(transition) = world.camera_transitions.get_mut(entity)
|
if let Some(transition) = camera_transitions.get_mut(entity)
|
||||||
{
|
{
|
||||||
let pos = world
|
let pos = transforms
|
||||||
.transforms
|
|
||||||
.with(entity, |tr| tr.position)
|
.with(entity, |tr| tr.position)
|
||||||
.unwrap_or(Vec3::ZERO);
|
.unwrap_or(Vec3::ZERO);
|
||||||
let cam = world.cameras.get(entity);
|
let cam = cameras.get(entity);
|
||||||
transition.source_position = pos;
|
transition.source_position = pos;
|
||||||
if let Some(cam) = cam
|
if let Some(cam) = cam
|
||||||
{
|
{
|
||||||
@@ -378,7 +438,7 @@ pub fn camera_transition_system(world: &mut World, delta: f32)
|
|||||||
|
|
||||||
if finished
|
if finished
|
||||||
{
|
{
|
||||||
world.camera_transitions.remove(entity);
|
camera_transitions.remove(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
use glam::Vec3;
|
use glam::Vec3;
|
||||||
|
|
||||||
|
use crate::components::camera::CameraComponent;
|
||||||
use crate::components::intent::CameraTransitionIntent;
|
use crate::components::intent::CameraTransitionIntent;
|
||||||
use crate::entity::EntityHandle;
|
use crate::entity::EntityHandle;
|
||||||
use crate::world::World;
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn dialog_camera_transition_system(world: &mut World, camera_entity: EntityHandle)
|
pub fn dialog_camera_transition_system(
|
||||||
|
bubble_tags: &Storage<()>,
|
||||||
|
camera_transition_intents: &mut Storage<CameraTransitionIntent>,
|
||||||
|
was_dialog_active: &mut bool,
|
||||||
|
camera_entity: EntityHandle,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let dialog_active = !world.bubble_tags.all().is_empty();
|
let dialog_active = !bubble_tags.all().is_empty();
|
||||||
if dialog_active != world.was_dialog_active
|
if dialog_active != *was_dialog_active
|
||||||
{
|
{
|
||||||
world
|
camera_transition_intents.insert(camera_entity, CameraTransitionIntent { duration: 0.8 });
|
||||||
.camera_transition_intents
|
*was_dialog_active = dialog_active;
|
||||||
.insert(camera_entity, CameraTransitionIntent { duration: 0.8 });
|
|
||||||
world.was_dialog_active = dialog_active;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,21 +26,30 @@ const VERTICAL_BIAS: f32 = 0.4;
|
|||||||
const MIN_DISTANCE: f32 = 8.0;
|
const MIN_DISTANCE: f32 = 8.0;
|
||||||
const MAX_DISTANCE: f32 = 24.0;
|
const MAX_DISTANCE: f32 = 24.0;
|
||||||
|
|
||||||
pub fn dialog_camera_system(world: &mut World, delta: f32)
|
pub fn dialog_camera_system(
|
||||||
|
cameras: &mut Storage<CameraComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
bubble_tags: &Storage<()>,
|
||||||
|
player_pos: Vec3,
|
||||||
|
delta: f32,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let Some((camera_entity, _)) = world.active_camera()
|
let camera_entity = cameras
|
||||||
|
.components
|
||||||
|
.iter()
|
||||||
|
.find(|(_, cam)| cam.is_active)
|
||||||
|
.map(|(e, _)| *e);
|
||||||
|
|
||||||
|
let Some(camera_entity) = camera_entity
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let player_pos = world.player_position();
|
let bubble_positions: Vec<Vec3> = bubble_tags
|
||||||
|
|
||||||
let bubble_positions: Vec<Vec3> = world
|
|
||||||
.bubble_tags
|
|
||||||
.all()
|
.all()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&bubble| world.transforms.with(bubble, |t| t.position))
|
.filter_map(|&bubble| transforms.with(bubble, |t| t.position))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if bubble_positions.is_empty()
|
if bubble_positions.is_empty()
|
||||||
@@ -63,20 +77,19 @@ pub fn dialog_camera_system(world: &mut World, delta: f32)
|
|||||||
let target_camera_pos =
|
let target_camera_pos =
|
||||||
centroid + camera_back_dir * camera_distance + Vec3::Y * camera_distance * VERTICAL_BIAS;
|
centroid + camera_back_dir * camera_distance + Vec3::Y * camera_distance * VERTICAL_BIAS;
|
||||||
|
|
||||||
let current_camera_pos = world
|
let current_camera_pos = transforms
|
||||||
.transforms
|
|
||||||
.with(camera_entity, |t| t.position)
|
.with(camera_entity, |t| t.position)
|
||||||
.unwrap_or(target_camera_pos);
|
.unwrap_or(target_camera_pos);
|
||||||
|
|
||||||
let smoothed = current_camera_pos.lerp(target_camera_pos, (CAMERA_LAG * delta).min(1.0));
|
let smoothed = current_camera_pos.lerp(target_camera_pos, (CAMERA_LAG * delta).min(1.0));
|
||||||
|
|
||||||
world.transforms.with_mut(camera_entity, |t| {
|
transforms.with_mut(camera_entity, |t| {
|
||||||
t.position = smoothed;
|
t.position = smoothed;
|
||||||
});
|
});
|
||||||
|
|
||||||
let look_target = centroid;
|
let look_target = centroid;
|
||||||
|
|
||||||
if let Some(camera) = world.cameras.get_mut(camera_entity)
|
if let Some(camera) = cameras.get_mut(camera_entity)
|
||||||
{
|
{
|
||||||
let look_dir = (look_target - smoothed).normalize_or(-Vec3::Z);
|
let look_dir = (look_target - smoothed).normalize_or(-Vec3::Z);
|
||||||
camera.yaw = look_dir.z.atan2(look_dir.x);
|
camera.yaw = look_dir.z.atan2(look_dir.x);
|
||||||
|
|||||||
@@ -2,39 +2,53 @@ use std::f32::consts::PI;
|
|||||||
|
|
||||||
use glam::Vec3;
|
use glam::Vec3;
|
||||||
|
|
||||||
use crate::components::dialog::{DialogOutcome, DialogOutcomeEvent, ParryButton};
|
use crate::components::dialog::{
|
||||||
|
DialogOutcome, DialogOutcomeEvent, DialogProjectileComponent, ParryButton,
|
||||||
|
};
|
||||||
use crate::components::particle::{ParticleEmitterConfig, SpawnParticleIntent};
|
use crate::components::particle::{ParticleEmitterConfig, SpawnParticleIntent};
|
||||||
|
use crate::components::player_states::{LeapingState, RollingState};
|
||||||
use crate::entity::EntityHandle;
|
use crate::entity::EntityHandle;
|
||||||
use crate::utility::input::InputState;
|
use crate::utility::input::InputState;
|
||||||
use crate::world::World;
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
const PROJECTILE_SPEED: f32 = 6.0;
|
const PROJECTILE_SPEED: f32 = 6.0;
|
||||||
const PARRY_WINDOW_RADIUS: f32 = 3.5;
|
const PARRY_WINDOW_RADIUS: f32 = 3.5;
|
||||||
const HIT_RADIUS: f32 = 1.2;
|
const HIT_RADIUS: f32 = 1.2;
|
||||||
|
|
||||||
pub fn dialog_projectile_system(world: &mut World, input_state: &InputState)
|
pub fn dialog_projectile_system(
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
projectile_tags: &mut Storage<()>,
|
||||||
|
dialog_projectiles: &mut Storage<DialogProjectileComponent>,
|
||||||
|
spawn_particle_intents: &mut Vec<SpawnParticleIntent>,
|
||||||
|
dialog_outcomes: &mut Vec<DialogOutcomeEvent>,
|
||||||
|
leaping_states: &Storage<LeapingState>,
|
||||||
|
rolling_states: &Storage<RollingState>,
|
||||||
|
input_state: &InputState,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let player_entity = world.player_tags.all().into_iter().next();
|
let player_entity = player_tags.all().into_iter().next();
|
||||||
let Some(player_entity) = player_entity
|
let Some(player_entity) = player_entity
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let player_pos = world
|
let player_pos = transforms
|
||||||
.transforms
|
|
||||||
.with(player_entity, |t| t.position)
|
.with(player_entity, |t| t.position)
|
||||||
.unwrap_or(Vec3::ZERO);
|
.unwrap_or(Vec3::ZERO);
|
||||||
|
|
||||||
let player_is_evading = is_player_evading(world, player_entity);
|
let player_is_evading =
|
||||||
|
leaping_states.get(player_entity).is_some() || rolling_states.get(player_entity).is_some();
|
||||||
|
|
||||||
let projectiles: Vec<EntityHandle> = world.projectile_tags.all();
|
let projectiles: Vec<EntityHandle> = projectile_tags.all();
|
||||||
let mut outcomes: Vec<DialogOutcomeEvent> = Vec::new();
|
let mut outcomes: Vec<DialogOutcomeEvent> = Vec::new();
|
||||||
let mut to_despawn: Vec<EntityHandle> = Vec::new();
|
let mut to_despawn: Vec<EntityHandle> = Vec::new();
|
||||||
|
|
||||||
for proj_entity in projectiles
|
for proj_entity in projectiles
|
||||||
{
|
{
|
||||||
let proj_pos = match world.transforms.with(proj_entity, |t| t.position)
|
let proj_pos = match transforms.with(proj_entity, |t| t.position)
|
||||||
{
|
{
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => continue,
|
None => continue,
|
||||||
@@ -43,17 +57,20 @@ pub fn dialog_projectile_system(world: &mut World, input_state: &InputState)
|
|||||||
let to_player = player_pos - proj_pos;
|
let to_player = player_pos - proj_pos;
|
||||||
let distance = to_player.length();
|
let distance = to_player.length();
|
||||||
|
|
||||||
let window_open = world
|
let window_open = dialog_projectiles
|
||||||
.dialog_projectiles
|
|
||||||
.with(proj_entity, |p| p.parry_window_open)
|
.with(proj_entity, |p| p.parry_window_open)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
if window_open
|
if window_open
|
||||||
{
|
{
|
||||||
if let Some(outcome) = resolve_parry(world, proj_entity, input_state, player_is_evading)
|
if let Some(outcome) = resolve_parry(
|
||||||
|
dialog_projectiles,
|
||||||
|
proj_entity,
|
||||||
|
input_state,
|
||||||
|
player_is_evading,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let bubble_entity = world
|
let bubble_entity = dialog_projectiles
|
||||||
.dialog_projectiles
|
|
||||||
.with(proj_entity, |p| p.bubble_entity)
|
.with(proj_entity, |p| p.bubble_entity)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
outcomes.push(DialogOutcomeEvent {
|
outcomes.push(DialogOutcomeEvent {
|
||||||
@@ -67,8 +84,7 @@ pub fn dialog_projectile_system(world: &mut World, input_state: &InputState)
|
|||||||
|
|
||||||
if distance < HIT_RADIUS
|
if distance < HIT_RADIUS
|
||||||
{
|
{
|
||||||
let bubble_entity = world
|
let bubble_entity = dialog_projectiles
|
||||||
.dialog_projectiles
|
|
||||||
.with(proj_entity, |p| p.bubble_entity)
|
.with(proj_entity, |p| p.bubble_entity)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let outcome = if player_is_evading
|
let outcome = if player_is_evading
|
||||||
@@ -89,7 +105,7 @@ pub fn dialog_projectile_system(world: &mut World, input_state: &InputState)
|
|||||||
|
|
||||||
if distance < PARRY_WINDOW_RADIUS
|
if distance < PARRY_WINDOW_RADIUS
|
||||||
{
|
{
|
||||||
world.dialog_projectiles.with_mut(proj_entity, |p| {
|
dialog_projectiles.with_mut(proj_entity, |p| {
|
||||||
p.parry_window_open = true;
|
p.parry_window_open = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -103,14 +119,14 @@ pub fn dialog_projectile_system(world: &mut World, input_state: &InputState)
|
|||||||
Vec3::ZERO
|
Vec3::ZERO
|
||||||
};
|
};
|
||||||
|
|
||||||
world.transforms.with_mut(proj_entity, |t| {
|
transforms.with_mut(proj_entity, |t| {
|
||||||
t.position += direction * PROJECTILE_SPEED * (1.0 / 60.0);
|
t.position += direction * PROJECTILE_SPEED * (1.0 / 60.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
let proj_pos = world.transforms.with(proj_entity, |t| t.position);
|
let proj_pos = transforms.with(proj_entity, |t| t.position);
|
||||||
if let Some(pos) = proj_pos
|
if let Some(pos) = proj_pos
|
||||||
{
|
{
|
||||||
world.spawn_particle_intents.push(SpawnParticleIntent {
|
spawn_particle_intents.push(SpawnParticleIntent {
|
||||||
origin: pos,
|
origin: pos,
|
||||||
config: projectile_swarm_config(),
|
config: projectile_swarm_config(),
|
||||||
});
|
});
|
||||||
@@ -119,14 +135,16 @@ pub fn dialog_projectile_system(world: &mut World, input_state: &InputState)
|
|||||||
|
|
||||||
for entity in to_despawn
|
for entity in to_despawn
|
||||||
{
|
{
|
||||||
world.despawn(entity);
|
transforms.remove(entity);
|
||||||
|
projectile_tags.remove(entity);
|
||||||
|
dialog_projectiles.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
world.dialog_outcomes.extend(outcomes);
|
dialog_outcomes.extend(outcomes);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_parry(
|
fn resolve_parry(
|
||||||
world: &World,
|
dialog_projectiles: &Storage<DialogProjectileComponent>,
|
||||||
proj_entity: EntityHandle,
|
proj_entity: EntityHandle,
|
||||||
input_state: &InputState,
|
input_state: &InputState,
|
||||||
player_is_evading: bool,
|
player_is_evading: bool,
|
||||||
@@ -137,9 +155,7 @@ fn resolve_parry(
|
|||||||
return Some(DialogOutcome::Evaded);
|
return Some(DialogOutcome::Evaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
let correct_parry = world
|
let correct_parry = dialog_projectiles.with(proj_entity, |p| p.correct_parry)?;
|
||||||
.dialog_projectiles
|
|
||||||
.with(proj_entity, |p| p.correct_parry)?;
|
|
||||||
|
|
||||||
if input_state.i_just_pressed
|
if input_state.i_just_pressed
|
||||||
{
|
{
|
||||||
@@ -200,9 +216,3 @@ fn projectile_swarm_config() -> ParticleEmitterConfig
|
|||||||
color_end: [0.2, 0.05, 0.0, 0.0],
|
color_end: [0.2, 0.05, 0.0, 0.0],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_player_evading(world: &World, player_entity: EntityHandle) -> bool
|
|
||||||
{
|
|
||||||
world.leaping_states.get(player_entity).is_some()
|
|
||||||
|| world.rolling_states.get(player_entity).is_some()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use glam::{Mat4, Vec3};
|
use glam::{Mat4, Vec3};
|
||||||
|
|
||||||
|
use crate::components::dialog::DialogBubbleComponent;
|
||||||
use crate::render::billboard::{BillboardDrawCall, BillboardVertex, BubbleUniforms};
|
use crate::render::billboard::{BillboardDrawCall, BillboardVertex, BubbleUniforms};
|
||||||
use crate::render::{with_font_atlas, TextVertex};
|
use crate::render::{with_font_atlas, TextVertex};
|
||||||
use crate::world::World;
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
const MAX_BUBBLE_WIDTH: f32 = 8.0;
|
const MAX_BUBBLE_WIDTH: f32 = 8.0;
|
||||||
const MIN_BUBBLE_WIDTH: f32 = 0.5;
|
const MIN_BUBBLE_WIDTH: f32 = 0.5;
|
||||||
@@ -19,7 +21,9 @@ const TEXT_PADDING: f32 = 0.06;
|
|||||||
const LINE_SPACING: f32 = 0.01;
|
const LINE_SPACING: f32 = 0.01;
|
||||||
|
|
||||||
pub fn dialog_bubble_render_system(
|
pub fn dialog_bubble_render_system(
|
||||||
world: &World,
|
transforms: &Storage<Transform>,
|
||||||
|
dialog_bubbles: &Storage<DialogBubbleComponent>,
|
||||||
|
bubble_tags: &Storage<()>,
|
||||||
camera_pos: Vec3,
|
camera_pos: Vec3,
|
||||||
view_proj: Mat4,
|
view_proj: Mat4,
|
||||||
) -> (Vec<BillboardDrawCall>, Vec<TextVertex>)
|
) -> (Vec<BillboardDrawCall>, Vec<TextVertex>)
|
||||||
@@ -27,17 +31,15 @@ pub fn dialog_bubble_render_system(
|
|||||||
let mut calls = Vec::new();
|
let mut calls = Vec::new();
|
||||||
let mut all_text: Vec<TextVertex> = Vec::new();
|
let mut all_text: Vec<TextVertex> = Vec::new();
|
||||||
|
|
||||||
for bubble_entity in world.bubble_tags.all()
|
for bubble_entity in bubble_tags.all()
|
||||||
{
|
{
|
||||||
let bubble_pos = match world.transforms.with(bubble_entity, |t| t.position)
|
let bubble_pos = match transforms.with(bubble_entity, |t| t.position)
|
||||||
{
|
{
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
let text = match world
|
let text = match dialog_bubbles.with(bubble_entity, |b| b.current_text.clone())
|
||||||
.dialog_bubbles
|
|
||||||
.with(bubble_entity, |b| b.current_text.clone())
|
|
||||||
{
|
{
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => continue,
|
None => continue,
|
||||||
@@ -57,7 +59,7 @@ pub fn dialog_bubble_render_system(
|
|||||||
// Compute body height analytically.
|
// Compute body height analytically.
|
||||||
// border_world = BORDER_W * body_height (body is the smaller dimension)
|
// border_world = BORDER_W * body_height (body is the smaller dimension)
|
||||||
// body_height = text_h + 2 * (border_world + TEXT_PADDING)
|
// body_height = text_h + 2 * (border_world + TEXT_PADDING)
|
||||||
// → body_height * (1 - 2*BORDER_W) = text_h + 2*TEXT_PADDING
|
// -> body_height * (1 - 2*BORDER_W) = text_h + 2*TEXT_PADDING
|
||||||
let text_h = n_lines as f32 * CHAR_WORLD_HEIGHT
|
let text_h = n_lines as f32 * CHAR_WORLD_HEIGHT
|
||||||
+ n_lines.saturating_sub(1) as f32 * LINE_SPACING;
|
+ n_lines.saturating_sub(1) as f32 * LINE_SPACING;
|
||||||
let body_height = (text_h + 2.0 * TEXT_PADDING) / (1.0 - 2.0 * BORDER_W);
|
let body_height = (text_h + 2.0 * TEXT_PADDING) / (1.0 - 2.0 * BORDER_W);
|
||||||
|
|||||||
@@ -2,30 +2,74 @@ use bladeink::story::Story;
|
|||||||
use glam::Vec3;
|
use glam::Vec3;
|
||||||
|
|
||||||
use crate::components::dialog::{
|
use crate::components::dialog::{
|
||||||
DialogBubbleComponent, DialogPhase, DialogProjectileComponent, ParryButton,
|
DialogBubbleComponent, DialogOutcomeEvent, DialogPhase, DialogProjectileComponent,
|
||||||
|
DialogSourceComponent, ParryButton,
|
||||||
};
|
};
|
||||||
use crate::components::trigger::TriggerEventKind;
|
use crate::components::trigger::{TriggerEvent, TriggerEventKind};
|
||||||
use crate::entity::EntityHandle;
|
use crate::entity::{EntityHandle, EntityManager};
|
||||||
use crate::world::{Transform, World};
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
const DEFAULT_DISPLAY_TIME: f32 = 3.0;
|
const DEFAULT_DISPLAY_TIME: f32 = 3.0;
|
||||||
const PARRY_TAG_PREFIX: &str = "parry:";
|
const PARRY_TAG_PREFIX: &str = "parry:";
|
||||||
const TIMER_TAG_PREFIX: &str = "timer:";
|
const TIMER_TAG_PREFIX: &str = "timer:";
|
||||||
|
|
||||||
pub fn dialog_system(world: &mut World, delta: f32)
|
pub fn dialog_system(
|
||||||
|
entities: &mut EntityManager,
|
||||||
|
trigger_events: &[TriggerEvent],
|
||||||
|
dialog_sources: &Storage<DialogSourceComponent>,
|
||||||
|
bubble_tags: &mut Storage<()>,
|
||||||
|
dialog_bubbles: &mut Storage<DialogBubbleComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
names: &mut Storage<String>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
projectile_tags: &mut Storage<()>,
|
||||||
|
dialog_projectiles: &mut Storage<DialogProjectileComponent>,
|
||||||
|
dialog_outcomes: &mut Vec<DialogOutcomeEvent>,
|
||||||
|
delta: f32,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
process_trigger_events(world);
|
process_trigger_events(
|
||||||
tick_displaying_bubbles(world, delta);
|
entities,
|
||||||
process_outcomes(world);
|
trigger_events,
|
||||||
|
dialog_sources,
|
||||||
|
bubble_tags,
|
||||||
|
dialog_bubbles,
|
||||||
|
transforms,
|
||||||
|
names,
|
||||||
|
projectile_tags,
|
||||||
|
dialog_projectiles,
|
||||||
|
);
|
||||||
|
tick_displaying_bubbles(
|
||||||
|
entities,
|
||||||
|
bubble_tags,
|
||||||
|
dialog_bubbles,
|
||||||
|
transforms,
|
||||||
|
player_tags,
|
||||||
|
projectile_tags,
|
||||||
|
dialog_projectiles,
|
||||||
|
delta,
|
||||||
|
);
|
||||||
|
process_outcomes(bubble_tags, dialog_bubbles, dialog_outcomes);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_trigger_events(world: &mut World)
|
fn process_trigger_events(
|
||||||
|
entities: &mut EntityManager,
|
||||||
|
trigger_events: &[TriggerEvent],
|
||||||
|
dialog_sources: &Storage<DialogSourceComponent>,
|
||||||
|
bubble_tags: &mut Storage<()>,
|
||||||
|
dialog_bubbles: &mut Storage<DialogBubbleComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
names: &mut Storage<String>,
|
||||||
|
projectile_tags: &mut Storage<()>,
|
||||||
|
dialog_projectiles: &mut Storage<DialogProjectileComponent>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let events: Vec<_> = world.trigger_events.iter().cloned().collect();
|
let events: Vec<_> = trigger_events.iter().cloned().collect();
|
||||||
|
|
||||||
for event in events
|
for event in events
|
||||||
{
|
{
|
||||||
let has_source = world.dialog_sources.get(event.trigger_entity).is_some();
|
let has_source = dialog_sources.get(event.trigger_entity).is_some();
|
||||||
if !has_source
|
if !has_source
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -35,9 +79,8 @@ fn process_trigger_events(world: &mut World)
|
|||||||
{
|
{
|
||||||
TriggerEventKind::Entered =>
|
TriggerEventKind::Entered =>
|
||||||
{
|
{
|
||||||
let already_active = world.bubble_tags.all().iter().any(|&b| {
|
let already_active = bubble_tags.all().iter().any(|&b| {
|
||||||
world
|
dialog_bubbles
|
||||||
.dialog_bubbles
|
|
||||||
.with(b, |db| db.character_entity == event.trigger_entity)
|
.with(b, |db| db.character_entity == event.trigger_entity)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
});
|
});
|
||||||
@@ -47,22 +90,43 @@ fn process_trigger_events(world: &mut World)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn_bubble(world, event.trigger_entity);
|
spawn_bubble(
|
||||||
|
entities,
|
||||||
|
dialog_sources,
|
||||||
|
bubble_tags,
|
||||||
|
dialog_bubbles,
|
||||||
|
transforms,
|
||||||
|
names,
|
||||||
|
event.trigger_entity,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerEventKind::Exited =>
|
TriggerEventKind::Exited =>
|
||||||
{
|
{
|
||||||
despawn_bubbles_for_character(world, event.trigger_entity);
|
despawn_bubbles_for_character(
|
||||||
|
bubble_tags,
|
||||||
|
dialog_bubbles,
|
||||||
|
transforms,
|
||||||
|
projectile_tags,
|
||||||
|
dialog_projectiles,
|
||||||
|
event.trigger_entity,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_bubble(world: &mut World, character_entity: EntityHandle)
|
fn spawn_bubble(
|
||||||
|
entities: &mut EntityManager,
|
||||||
|
dialog_sources: &Storage<DialogSourceComponent>,
|
||||||
|
bubble_tags: &mut Storage<()>,
|
||||||
|
dialog_bubbles: &mut Storage<DialogBubbleComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
names: &mut Storage<String>,
|
||||||
|
character_entity: EntityHandle,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let ink_json = match world
|
let ink_json = match dialog_sources.with(character_entity, |s| s.ink_json.clone())
|
||||||
.dialog_sources
|
|
||||||
.with(character_entity, |s| s.ink_json.clone())
|
|
||||||
{
|
{
|
||||||
Some(json) => json,
|
Some(json) => json,
|
||||||
None => return,
|
None => return,
|
||||||
@@ -80,21 +144,18 @@ fn spawn_bubble(world: &mut World, character_entity: EntityHandle)
|
|||||||
|
|
||||||
let (text, parry, display_time) = advance_story(&mut story);
|
let (text, parry, display_time) = advance_story(&mut story);
|
||||||
|
|
||||||
let character_pos = world
|
let character_pos = transforms
|
||||||
.transforms
|
|
||||||
.with(character_entity, |t| t.position)
|
.with(character_entity, |t| t.position)
|
||||||
.unwrap_or(Vec3::ZERO);
|
.unwrap_or(Vec3::ZERO);
|
||||||
|
|
||||||
let bubble_entity = world.spawn();
|
let bubble_entity = entities.spawn();
|
||||||
world.transforms.insert(
|
transforms.insert(
|
||||||
bubble_entity,
|
bubble_entity,
|
||||||
Transform::from_position(character_pos + Vec3::new(0.0, 8.0, 0.0)),
|
Transform::from_position(character_pos + Vec3::new(0.0, 8.0, 0.0)),
|
||||||
);
|
);
|
||||||
world
|
names.insert(bubble_entity, "DialogBubble".to_string());
|
||||||
.names
|
bubble_tags.insert(bubble_entity, ());
|
||||||
.insert(bubble_entity, "DialogBubble".to_string());
|
dialog_bubbles.insert(
|
||||||
world.bubble_tags.insert(bubble_entity, ());
|
|
||||||
world.dialog_bubbles.insert(
|
|
||||||
bubble_entity,
|
bubble_entity,
|
||||||
DialogBubbleComponent {
|
DialogBubbleComponent {
|
||||||
story,
|
story,
|
||||||
@@ -109,14 +170,20 @@ fn spawn_bubble(world: &mut World, character_entity: EntityHandle)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn despawn_bubbles_for_character(world: &mut World, character_entity: EntityHandle)
|
fn despawn_bubbles_for_character(
|
||||||
|
bubble_tags: &mut Storage<()>,
|
||||||
|
dialog_bubbles: &mut Storage<DialogBubbleComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
projectile_tags: &mut Storage<()>,
|
||||||
|
dialog_projectiles: &mut Storage<DialogProjectileComponent>,
|
||||||
|
character_entity: EntityHandle,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let bubbles: Vec<EntityHandle> = world.bubble_tags.all();
|
let bubbles: Vec<EntityHandle> = bubble_tags.all();
|
||||||
|
|
||||||
for bubble_entity in bubbles
|
for bubble_entity in bubbles
|
||||||
{
|
{
|
||||||
let matches = world
|
let matches = dialog_bubbles
|
||||||
.dialog_bubbles
|
|
||||||
.with(bubble_entity, |b| b.character_entity == character_entity)
|
.with(bubble_entity, |b| b.character_entity == character_entity)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
@@ -125,26 +192,38 @@ fn despawn_bubbles_for_character(world: &mut World, character_entity: EntityHand
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(bubble) = world.dialog_bubbles.get(bubble_entity)
|
if let Some(bubble) = dialog_bubbles.get(bubble_entity)
|
||||||
{
|
{
|
||||||
if let DialogPhase::ProjectileInFlight { projectile_entity } = bubble.phase
|
if let DialogPhase::ProjectileInFlight { projectile_entity } = bubble.phase
|
||||||
{
|
{
|
||||||
world.despawn(projectile_entity);
|
transforms.remove(projectile_entity);
|
||||||
|
projectile_tags.remove(projectile_entity);
|
||||||
|
dialog_projectiles.remove(projectile_entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
world.despawn(bubble_entity);
|
transforms.remove(bubble_entity);
|
||||||
|
bubble_tags.remove(bubble_entity);
|
||||||
|
dialog_bubbles.remove(bubble_entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tick_displaying_bubbles(world: &mut World, delta: f32)
|
fn tick_displaying_bubbles(
|
||||||
|
entities: &mut EntityManager,
|
||||||
|
bubble_tags: &mut Storage<()>,
|
||||||
|
dialog_bubbles: &mut Storage<DialogBubbleComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
projectile_tags: &mut Storage<()>,
|
||||||
|
dialog_projectiles: &mut Storage<DialogProjectileComponent>,
|
||||||
|
delta: f32,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let bubbles: Vec<EntityHandle> = world.bubble_tags.all();
|
let bubbles: Vec<EntityHandle> = bubble_tags.all();
|
||||||
|
|
||||||
for bubble_entity in bubbles
|
for bubble_entity in bubbles
|
||||||
{
|
{
|
||||||
let expired = world
|
let expired = dialog_bubbles
|
||||||
.dialog_bubbles
|
|
||||||
.with_mut(bubble_entity, |b| {
|
.with_mut(bubble_entity, |b| {
|
||||||
if let DialogPhase::Displaying { ref mut timer } = b.phase
|
if let DialogPhase::Displaying { ref mut timer } = b.phase
|
||||||
{
|
{
|
||||||
@@ -160,45 +239,37 @@ fn tick_displaying_bubbles(world: &mut World, delta: f32)
|
|||||||
|
|
||||||
if expired
|
if expired
|
||||||
{
|
{
|
||||||
let correct_parry = match world
|
let correct_parry = match dialog_bubbles.with(bubble_entity, |b| b.correct_parry)
|
||||||
.dialog_bubbles
|
|
||||||
.with(bubble_entity, |b| b.correct_parry)
|
|
||||||
{
|
{
|
||||||
Some(Some(p)) => p,
|
Some(Some(p)) => p,
|
||||||
_ =>
|
_ =>
|
||||||
{
|
{
|
||||||
world.despawn(bubble_entity);
|
transforms.remove(bubble_entity);
|
||||||
|
bubble_tags.remove(bubble_entity);
|
||||||
|
dialog_bubbles.remove(bubble_entity);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let bubble_pos = world
|
let bubble_pos = transforms
|
||||||
.transforms
|
|
||||||
.with(bubble_entity, |t| t.position)
|
.with(bubble_entity, |t| t.position)
|
||||||
.unwrap_or(Vec3::ZERO);
|
.unwrap_or(Vec3::ZERO);
|
||||||
|
|
||||||
let player_entity = world
|
let player_entity = player_tags
|
||||||
.player_tags
|
|
||||||
.all()
|
.all()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.expect("no player entity");
|
.expect("no player entity");
|
||||||
let player_pos = world
|
let player_pos = transforms
|
||||||
.transforms
|
|
||||||
.with(player_entity, |t| t.position)
|
.with(player_entity, |t| t.position)
|
||||||
.unwrap_or(Vec3::ZERO);
|
.unwrap_or(Vec3::ZERO);
|
||||||
|
|
||||||
let velocity = player_pos - bubble_pos;
|
let velocity = player_pos - bubble_pos;
|
||||||
|
|
||||||
let projectile_entity = world.spawn();
|
let projectile_entity = entities.spawn();
|
||||||
world
|
transforms.insert(projectile_entity, Transform::from_position(bubble_pos));
|
||||||
.transforms
|
projectile_tags.insert(projectile_entity, ());
|
||||||
.insert(projectile_entity, Transform::from_position(bubble_pos));
|
dialog_projectiles.insert(
|
||||||
world
|
|
||||||
.names
|
|
||||||
.insert(projectile_entity, "DialogProjectile".to_string());
|
|
||||||
world.projectile_tags.insert(projectile_entity, ());
|
|
||||||
world.dialog_projectiles.insert(
|
|
||||||
projectile_entity,
|
projectile_entity,
|
||||||
DialogProjectileComponent {
|
DialogProjectileComponent {
|
||||||
bubble_entity,
|
bubble_entity,
|
||||||
@@ -208,29 +279,33 @@ fn tick_displaying_bubbles(world: &mut World, delta: f32)
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
world.dialog_bubbles.with_mut(bubble_entity, |b| {
|
dialog_bubbles.with_mut(bubble_entity, |b| {
|
||||||
b.phase = DialogPhase::ProjectileInFlight { projectile_entity };
|
b.phase = DialogPhase::ProjectileInFlight { projectile_entity };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_outcomes(world: &mut World)
|
fn process_outcomes(
|
||||||
|
bubble_tags: &mut Storage<()>,
|
||||||
|
dialog_bubbles: &mut Storage<DialogBubbleComponent>,
|
||||||
|
dialog_outcomes: &mut Vec<DialogOutcomeEvent>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let outcomes: Vec<_> = world.dialog_outcomes.drain(..).collect();
|
let outcomes: Vec<_> = dialog_outcomes.drain(..).collect();
|
||||||
|
|
||||||
for event in outcomes
|
for event in outcomes
|
||||||
{
|
{
|
||||||
let bubble_entity = event.bubble_entity;
|
let bubble_entity = event.bubble_entity;
|
||||||
|
|
||||||
if world.dialog_bubbles.get(bubble_entity).is_none()
|
if dialog_bubbles.get(bubble_entity).is_none()
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let choice_tag = event.outcome.to_choice_tag();
|
let choice_tag = event.outcome.to_choice_tag();
|
||||||
|
|
||||||
let next = world.dialog_bubbles.with_mut(bubble_entity, |b| {
|
let next = dialog_bubbles.with_mut(bubble_entity, |b| {
|
||||||
let choices = b.story.get_current_choices();
|
let choices = b.story.get_current_choices();
|
||||||
let idx = choices
|
let idx = choices
|
||||||
.iter()
|
.iter()
|
||||||
@@ -264,7 +339,7 @@ fn process_outcomes(world: &mut World)
|
|||||||
{
|
{
|
||||||
Some(Some((text, parry, display_time))) =>
|
Some(Some((text, parry, display_time))) =>
|
||||||
{
|
{
|
||||||
world.dialog_bubbles.with_mut(bubble_entity, |b| {
|
dialog_bubbles.with_mut(bubble_entity, |b| {
|
||||||
b.current_text = text;
|
b.current_text = text;
|
||||||
b.correct_parry = parry;
|
b.correct_parry = parry;
|
||||||
b.display_time = display_time;
|
b.display_time = display_time;
|
||||||
@@ -276,7 +351,8 @@ fn process_outcomes(world: &mut World)
|
|||||||
|
|
||||||
Some(None) =>
|
Some(None) =>
|
||||||
{
|
{
|
||||||
world.despawn(bubble_entity);
|
bubble_tags.remove(bubble_entity);
|
||||||
|
dialog_bubbles.remove(bubble_entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
None =>
|
None =>
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
use crate::world::World;
|
use crate::components::FollowComponent;
|
||||||
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn follow_system(world: &mut World)
|
pub fn follow_system(follows: &mut Storage<FollowComponent>, transforms: &mut Storage<Transform>)
|
||||||
{
|
{
|
||||||
let following_entities: Vec<_> = world.follows.all();
|
let following_entities: Vec<_> = follows.all();
|
||||||
|
|
||||||
for entity in following_entities
|
for entity in following_entities
|
||||||
{
|
{
|
||||||
if let Some(follow) = world.follows.get(entity)
|
if let Some(follow) = follows.get(entity)
|
||||||
{
|
{
|
||||||
let target = follow.target;
|
let target = follow.target;
|
||||||
if let Some(target_transform) = world.transforms.get(target)
|
if let Some(target_transform) = transforms.get(target)
|
||||||
{
|
{
|
||||||
let target_pos = target_transform.position;
|
let target_pos = target_transform.position;
|
||||||
let target_rot = target_transform.rotation;
|
let target_rot = target_transform.rotation;
|
||||||
@@ -18,7 +20,7 @@ pub fn follow_system(world: &mut World)
|
|||||||
let inherit_rot = follow.inherit_rotation;
|
let inherit_rot = follow.inherit_rotation;
|
||||||
let inherit_scale = follow.inherit_scale;
|
let inherit_scale = follow.inherit_scale;
|
||||||
|
|
||||||
world.transforms.with_mut(entity, |transform| {
|
transforms.with_mut(entity, |transform| {
|
||||||
transform.position = target_pos;
|
transform.position = target_pos;
|
||||||
|
|
||||||
if inherit_rot
|
if inherit_rot
|
||||||
|
|||||||
@@ -1,29 +1,45 @@
|
|||||||
use glam::Vec3;
|
use glam::Vec3;
|
||||||
|
|
||||||
|
use crate::components::camera::CameraComponent;
|
||||||
|
use crate::components::FollowComponent;
|
||||||
|
use crate::components::InputComponent;
|
||||||
use crate::utility::input::InputState;
|
use crate::utility::input::InputState;
|
||||||
use crate::world::World;
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn player_input_system(world: &mut World, input_state: &InputState)
|
pub fn player_input_system(
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
follows: &Storage<FollowComponent>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
inputs: &mut Storage<InputComponent>,
|
||||||
|
input_state: &InputState,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if !world.camera_is_following()
|
let camera_is_following = cameras
|
||||||
|
.components
|
||||||
|
.iter()
|
||||||
|
.find(|(_, cam)| cam.is_active)
|
||||||
|
.map(|(e, _)| follows.get(*e).is_some())
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
if !camera_is_following
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some((_, camera)) = world.active_camera()
|
let (_, camera) = match cameras.components.iter().find(|(_, cam)| cam.is_active)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return;
|
Some((e, c)) => (*e, c),
|
||||||
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let forward = camera.get_forward_horizontal();
|
let forward = camera.get_forward_horizontal();
|
||||||
let right = camera.get_right_horizontal();
|
let right = camera.get_right_horizontal();
|
||||||
|
|
||||||
let players = world.player_tags.all();
|
let players = player_tags.all();
|
||||||
|
|
||||||
for player in players
|
for player in players
|
||||||
{
|
{
|
||||||
world.inputs.with_mut(player, |input_component| {
|
inputs.with_mut(player, |input_component| {
|
||||||
let mut local_input = Vec3::ZERO;
|
let mut local_input = Vec3::ZERO;
|
||||||
|
|
||||||
if input_state.w
|
if input_state.w
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use rand::Rng;
|
|||||||
|
|
||||||
use crate::components::particle::{ParticleEmitterConfig, SpawnParticleIntent};
|
use crate::components::particle::{ParticleEmitterConfig, SpawnParticleIntent};
|
||||||
use crate::render::particle_types::ParticleInstanceRaw;
|
use crate::render::particle_types::ParticleInstanceRaw;
|
||||||
use crate::world::World;
|
|
||||||
|
|
||||||
pub struct Particle
|
pub struct Particle
|
||||||
{
|
{
|
||||||
@@ -92,24 +91,27 @@ fn spawn_from_config(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn particle_intent_system(world: &mut World)
|
pub fn particle_intent_system(
|
||||||
|
particle_buffers: &mut Option<ParticleBuffers>,
|
||||||
|
spawn_particle_intents: &mut Vec<SpawnParticleIntent>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if world.particle_buffers.is_none()
|
if particle_buffers.is_none()
|
||||||
{
|
{
|
||||||
world.particle_buffers = Some(ParticleBuffers {
|
*particle_buffers = Some(ParticleBuffers {
|
||||||
particles: Vec::new(),
|
particles: Vec::new(),
|
||||||
instances: Vec::new(),
|
instances: Vec::new(),
|
||||||
emit_accumulator: 0.0,
|
emit_accumulator: 0.0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let intents: Vec<SpawnParticleIntent> = world.spawn_particle_intents.drain(..).collect();
|
let intents: Vec<SpawnParticleIntent> = spawn_particle_intents.drain(..).collect();
|
||||||
if intents.is_empty()
|
if intents.is_empty()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffers = world.particle_buffers.as_mut().unwrap();
|
let buffers = particle_buffers.as_mut().unwrap();
|
||||||
let mut rng = rand::rng();
|
let mut rng = rand::rng();
|
||||||
for intent in intents
|
for intent in intents
|
||||||
{
|
{
|
||||||
@@ -117,9 +119,9 @@ pub fn particle_intent_system(world: &mut World)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn particle_update_system(world: &mut World, delta: f32)
|
pub fn particle_update_system(particle_buffers: &mut Option<ParticleBuffers>, delta: f32)
|
||||||
{
|
{
|
||||||
let Some(ref mut buffers) = world.particle_buffers
|
let Some(ref mut buffers) = particle_buffers
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
|
use crate::components::PhysicsComponent;
|
||||||
|
use crate::entity::EntityManager;
|
||||||
use crate::physics::PhysicsManager;
|
use crate::physics::PhysicsManager;
|
||||||
use crate::utility::transform::Transform;
|
use crate::utility::transform::Transform;
|
||||||
use crate::world::World;
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn physics_sync_system(world: &mut World)
|
pub fn physics_sync_system(
|
||||||
|
entities: &EntityManager,
|
||||||
|
physics: &Storage<PhysicsComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let all_entities = world.entities.all_entities();
|
let all_entities = entities.all_entities();
|
||||||
|
|
||||||
for entity in all_entities
|
for entity in all_entities
|
||||||
{
|
{
|
||||||
if let Some(physics) = world.physics.get(entity)
|
if let Some(physics) = physics.get(entity)
|
||||||
{
|
{
|
||||||
if let Some(rigidbody_position) =
|
if let Some(rigidbody_position) =
|
||||||
PhysicsManager::get_rigidbody_position(physics.rigidbody)
|
PhysicsManager::get_rigidbody_position(physics.rigidbody)
|
||||||
{
|
{
|
||||||
let transform = Transform::from(rigidbody_position);
|
let transform = Transform::from(rigidbody_position);
|
||||||
|
|
||||||
world.transforms.with_mut(entity, |t| {
|
transforms.with_mut(entity, |t| {
|
||||||
*t = transform;
|
*t = transform;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
|
use crate::components::{DissolveComponent, MeshComponent};
|
||||||
|
use crate::entity::EntityManager;
|
||||||
use crate::loaders::mesh::InstanceRaw;
|
use crate::loaders::mesh::InstanceRaw;
|
||||||
use crate::render::DrawCall;
|
use crate::render::DrawCall;
|
||||||
use crate::world::World;
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
use bytemuck::cast_slice;
|
use bytemuck::cast_slice;
|
||||||
|
|
||||||
pub fn render_system(world: &World) -> Vec<DrawCall>
|
pub fn render_system(
|
||||||
|
entities: &EntityManager,
|
||||||
|
transforms: &Storage<Transform>,
|
||||||
|
meshes: &Storage<MeshComponent>,
|
||||||
|
dissolves: &Storage<DissolveComponent>,
|
||||||
|
) -> Vec<DrawCall>
|
||||||
{
|
{
|
||||||
let all_entities = world.entities.all_entities();
|
let all_entities = entities.all_entities();
|
||||||
|
|
||||||
all_entities
|
all_entities
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&entity| {
|
.filter_map(|&entity| {
|
||||||
let transform = world.transforms.get(entity)?;
|
let transform = transforms.get(entity)?;
|
||||||
let mesh_component = world.meshes.get(entity)?;
|
let mesh_component = meshes.get(entity)?;
|
||||||
|
|
||||||
let model_matrix = transform.to_matrix();
|
let model_matrix = transform.to_matrix();
|
||||||
|
|
||||||
@@ -22,7 +30,7 @@ pub fn render_system(world: &World) -> Vec<DrawCall>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let dissolve_amount = world.dissolves.get(entity).map(|d| d.amount).unwrap_or(0.0);
|
let dissolve_amount = dissolves.get(entity).map(|d| d.amount).unwrap_or(0.0);
|
||||||
|
|
||||||
let instance_data = InstanceRaw {
|
let instance_data = InstanceRaw {
|
||||||
model: model_matrix.to_cols_array_2d(),
|
model: model_matrix.to_cols_array_2d(),
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
use glam::Quat;
|
use glam::Quat;
|
||||||
|
|
||||||
use crate::world::World;
|
use crate::components::RotateComponent;
|
||||||
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn rotate_system(world: &mut World, delta: f32)
|
pub fn rotate_system(
|
||||||
|
rotates: &Storage<RotateComponent>,
|
||||||
|
transforms: &mut Storage<Transform>,
|
||||||
|
delta: f32,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let entities = world.rotates.all();
|
let entities = rotates.all();
|
||||||
|
|
||||||
for entity in entities
|
for entity in entities
|
||||||
{
|
{
|
||||||
if let Some(rotate) = world.rotates.get(entity)
|
if let Some(rotate) = rotates.get(entity)
|
||||||
{
|
{
|
||||||
let rotation_delta = Quat::from_axis_angle(rotate.axis, rotate.speed * delta);
|
let rotation_delta = Quat::from_axis_angle(rotate.axis, rotate.speed * delta);
|
||||||
|
|
||||||
world.transforms.with_mut(entity, |transform| {
|
transforms.with_mut(entity, |transform| {
|
||||||
transform.rotation = rotation_delta * transform.rotation;
|
transform.rotation = rotation_delta * transform.rotation;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,40 @@
|
|||||||
use crate::world::World;
|
use crate::components::camera::CameraComponent;
|
||||||
|
use crate::components::FollowComponent;
|
||||||
|
use crate::render::snow::SnowLayer;
|
||||||
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn snow_system(world: &mut World)
|
pub fn snow_system(
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
transforms: &Storage<Transform>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
follows: &Storage<FollowComponent>,
|
||||||
|
snow_layer: &mut Option<SnowLayer>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let camera_pos = world.active_camera_position();
|
let camera_pos = cameras
|
||||||
let player_pos = world.player_position();
|
.components
|
||||||
let is_following = world.camera_is_following();
|
.iter()
|
||||||
if let Some(ref mut snow_layer) = world.snow_layer
|
.find(|(_, cam)| cam.is_active)
|
||||||
|
.and_then(|(e, _)| transforms.get(*e))
|
||||||
|
.map(|t| t.position)
|
||||||
|
.unwrap_or(glam::Vec3::ZERO);
|
||||||
|
|
||||||
|
let player_pos = player_tags
|
||||||
|
.all()
|
||||||
|
.first()
|
||||||
|
.and_then(|e| transforms.get(*e))
|
||||||
|
.map(|t| t.position)
|
||||||
|
.unwrap_or(glam::Vec3::ZERO);
|
||||||
|
|
||||||
|
let is_following = cameras
|
||||||
|
.components
|
||||||
|
.iter()
|
||||||
|
.find(|(_, cam)| cam.is_active)
|
||||||
|
.map(|(e, _)| follows.get(*e).is_some())
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
if let Some(ref mut snow_layer) = snow_layer
|
||||||
{
|
{
|
||||||
if is_following
|
if is_following
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
|
use crate::components::lights::spot::SpotlightComponent;
|
||||||
use crate::render::Spotlight;
|
use crate::render::Spotlight;
|
||||||
use crate::world::World;
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn spotlight_sync_system(world: &World) -> Vec<Spotlight>
|
pub fn spotlight_sync_system(
|
||||||
|
spotlights: &Storage<SpotlightComponent>,
|
||||||
|
transforms: &Storage<Transform>,
|
||||||
|
) -> Vec<Spotlight>
|
||||||
{
|
{
|
||||||
let mut entities = world.spotlights.all();
|
let mut entities = spotlights.all();
|
||||||
entities.sort();
|
entities.sort();
|
||||||
|
|
||||||
let mut spotlights = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
|
||||||
for entity in entities
|
for entity in entities
|
||||||
{
|
{
|
||||||
if let Some(spotlight_component) = world.spotlights.get(entity)
|
if let Some(spotlight_component) = spotlights.get(entity)
|
||||||
{
|
{
|
||||||
if let Some(transform) = world.transforms.get(entity)
|
if let Some(transform) = transforms.get(entity)
|
||||||
{
|
{
|
||||||
let position = transform.position + spotlight_component.offset;
|
let position = transform.position + spotlight_component.offset;
|
||||||
let direction = transform.rotation * spotlight_component.direction;
|
let direction = transform.rotation * spotlight_component.direction;
|
||||||
|
|
||||||
spotlights.push(Spotlight::new(
|
result.push(Spotlight::new(
|
||||||
position,
|
position,
|
||||||
direction,
|
direction,
|
||||||
spotlight_component.inner_angle,
|
spotlight_component.inner_angle,
|
||||||
@@ -28,5 +33,5 @@ pub fn spotlight_sync_system(world: &World) -> Vec<Spotlight>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spotlights
|
result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
|
use crate::components::camera::CameraComponent;
|
||||||
|
use crate::components::tree_instances::TreeInstancesComponent;
|
||||||
use crate::loaders::mesh::InstanceRaw;
|
use crate::loaders::mesh::InstanceRaw;
|
||||||
use crate::world::World;
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
use bytemuck::cast_slice;
|
use bytemuck::cast_slice;
|
||||||
|
|
||||||
pub fn tree_dissolve_update_system(world: &mut World, delta: f32)
|
pub fn tree_dissolve_update_system(tree_instances: &mut Storage<TreeInstancesComponent>, delta: f32)
|
||||||
{
|
{
|
||||||
for entity in world.tree_instances.all()
|
for entity in tree_instances.all()
|
||||||
{
|
{
|
||||||
if let Some(tree_instances) = world.tree_instances.get_mut(entity)
|
if let Some(tree_instances) = tree_instances.get_mut(entity)
|
||||||
{
|
{
|
||||||
for i in 0..tree_instances.dissolve_amounts.len()
|
for i in 0..tree_instances.dissolve_amounts.len()
|
||||||
{
|
{
|
||||||
@@ -20,15 +23,24 @@ pub fn tree_dissolve_update_system(world: &mut World, delta: f32)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tree_occlusion_system(world: &mut World)
|
pub fn tree_occlusion_system(
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
transforms: &Storage<Transform>,
|
||||||
|
cameras: &Storage<CameraComponent>,
|
||||||
|
tree_instances: &mut Storage<TreeInstancesComponent>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
let player_entity = world.player_tags.all().first().copied();
|
let player_entity = player_tags.all().first().copied();
|
||||||
let player_pos = player_entity.and_then(|e| world.transforms.get(e).map(|t| t.position));
|
let player_pos = player_entity.and_then(|e| transforms.get(e).map(|t| t.position));
|
||||||
|
|
||||||
if let Some(player_pos) = player_pos
|
if let Some(player_pos) = player_pos
|
||||||
{
|
{
|
||||||
let camera_entity = world.active_camera().map(|(e, _)| e);
|
let camera_entity = cameras
|
||||||
let camera_pos = camera_entity.and_then(|e| world.transforms.get(e).map(|t| t.position));
|
.components
|
||||||
|
.iter()
|
||||||
|
.find(|(_, cam)| cam.is_active)
|
||||||
|
.map(|(e, _)| *e);
|
||||||
|
let camera_pos = camera_entity.and_then(|e| transforms.get(e).map(|t| t.position));
|
||||||
|
|
||||||
if let Some(camera_pos) = camera_pos
|
if let Some(camera_pos) = camera_pos
|
||||||
{
|
{
|
||||||
@@ -43,9 +55,9 @@ pub fn tree_occlusion_system(world: &mut World)
|
|||||||
let to_player_normalized = to_player.normalize();
|
let to_player_normalized = to_player.normalize();
|
||||||
let occlusion_radius = 10.0;
|
let occlusion_radius = 10.0;
|
||||||
|
|
||||||
for tree_entity in world.tree_instances.all()
|
for tree_entity in tree_instances.all()
|
||||||
{
|
{
|
||||||
if let Some(tree_instances) = world.tree_instances.get_mut(tree_entity)
|
if let Some(tree_instances) = tree_instances.get_mut(tree_entity)
|
||||||
{
|
{
|
||||||
for (idx, instance) in tree_instances.instances.iter().enumerate()
|
for (idx, instance) in tree_instances.instances.iter().enumerate()
|
||||||
{
|
{
|
||||||
@@ -81,11 +93,11 @@ pub fn tree_occlusion_system(world: &mut World)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tree_instance_buffer_update_system(world: &mut World)
|
pub fn tree_instance_buffer_update_system(tree_instances: &Storage<TreeInstancesComponent>)
|
||||||
{
|
{
|
||||||
for entity in world.tree_instances.all()
|
for entity in tree_instances.all()
|
||||||
{
|
{
|
||||||
if let Some(tree_instances) = world.tree_instances.get(entity)
|
if let Some(tree_instances) = tree_instances.get(entity)
|
||||||
{
|
{
|
||||||
let instance_data_vec: Vec<InstanceRaw> = tree_instances
|
let instance_data_vec: Vec<InstanceRaw> = tree_instances
|
||||||
.instances
|
.instances
|
||||||
|
|||||||
@@ -1,41 +1,47 @@
|
|||||||
use glam::Vec3;
|
use glam::Vec3;
|
||||||
|
|
||||||
use crate::components::trigger::{
|
use crate::components::trigger::{
|
||||||
TriggerEvent, TriggerEventKind, TriggerFilter, TriggerShape, TriggerState,
|
TriggerComponent, TriggerEvent, TriggerEventKind, TriggerFilter, TriggerShape, TriggerState,
|
||||||
};
|
};
|
||||||
use crate::entity::EntityHandle;
|
use crate::entity::EntityHandle;
|
||||||
use crate::world::World;
|
use crate::utility::transform::Transform;
|
||||||
|
use crate::world::Storage;
|
||||||
|
|
||||||
pub fn trigger_system(world: &mut World)
|
pub fn trigger_system(
|
||||||
|
trigger_events: &mut Vec<TriggerEvent>,
|
||||||
|
triggers: &mut Storage<TriggerComponent>,
|
||||||
|
transforms: &Storage<Transform>,
|
||||||
|
player_tags: &Storage<()>,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
world.trigger_events.clear();
|
trigger_events.clear();
|
||||||
|
|
||||||
let trigger_entities: Vec<EntityHandle> = world.triggers.all();
|
let trigger_entities: Vec<EntityHandle> = triggers.all();
|
||||||
let mut pending_events: Vec<TriggerEvent> = Vec::new();
|
let mut pending_events: Vec<TriggerEvent> = Vec::new();
|
||||||
|
|
||||||
for trigger_entity in trigger_entities
|
for trigger_entity in trigger_entities
|
||||||
{
|
{
|
||||||
let trigger_pos = match world.transforms.get(trigger_entity)
|
let trigger_pos = match transforms.get(trigger_entity)
|
||||||
{
|
{
|
||||||
Some(t) => t.position,
|
Some(t) => t.position,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
let candidate_entities: Vec<EntityHandle> = match world.triggers.get(trigger_entity)
|
let candidate_entities: Vec<EntityHandle> = match triggers.get(trigger_entity)
|
||||||
{
|
{
|
||||||
Some(trigger) => match &trigger.filter
|
Some(trigger) => match &trigger.filter
|
||||||
{
|
{
|
||||||
TriggerFilter::Player => world.player_tags.all(),
|
TriggerFilter::Player => player_tags.all(),
|
||||||
},
|
},
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
let activator_positions: Vec<(EntityHandle, Vec3)> = candidate_entities
|
let activator_positions: Vec<(EntityHandle, Vec3)> = candidate_entities
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|e| world.transforms.get(e).map(|t| (e, t.position)))
|
.filter_map(|e| transforms.get(e).map(|t| (e, t.position)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let overlapping = match world.triggers.get(trigger_entity)
|
let overlapping = match triggers.get(trigger_entity)
|
||||||
{
|
{
|
||||||
Some(trigger) => activator_positions
|
Some(trigger) => activator_positions
|
||||||
.iter()
|
.iter()
|
||||||
@@ -48,7 +54,7 @@ pub fn trigger_system(world: &mut World)
|
|||||||
|
|
||||||
let first_activator = activator_positions.first().map(|(e, _)| *e);
|
let first_activator = activator_positions.first().map(|(e, _)| *e);
|
||||||
|
|
||||||
if let Some(trigger) = world.triggers.get_mut(trigger_entity)
|
if let Some(trigger) = triggers.get_mut(trigger_entity)
|
||||||
{
|
{
|
||||||
match (&trigger.state, overlapping)
|
match (&trigger.state, overlapping)
|
||||||
{
|
{
|
||||||
@@ -82,5 +88,5 @@ pub fn trigger_system(world: &mut World)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
world.trigger_events.extend(pending_events);
|
trigger_events.extend(pending_events);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user