Energy Perception & Physics Stability#139
Merged
M1thieu merged 6 commits intoerematorg:mainfrom Dec 31, 2025
Merged
Conversation
Replace 343 lines of manual distance calculations with EntityTracker + PreyTracker components, demonstrating the refactored AI architecture. Changes: - Use EntityTracker to store tracked food entities - Use PreyTracker with evaluate_tracked_entities_with_decay() helper - Remove custom Perception component (use tracker system instead) - Remove altruistic behavior (too complex for basic example) - Remove concurrent actions toggle (unnecessary) - Simplify to 3 clear systems: track -> evaluate -> move Now properly showcases the tracker refactoring work and serves as a reference for using the AI system.
- Hash-based sparse spatial grid for infinite 2D worlds - O(N²) → O(N) optimization for neighbor queries - Cell-based partitioning with configurable cell size - get_neighbors(), get_entities_in_radius() APIs - Integrated into waves module for propagation - Comprehensive test coverage - Fix logo.png asset
Thermodynamics fixes and heat capacity implementation: - First Law: ΔT = Q/C with real heat capacity - Zeroth Law: Pure temperature equality for equilibrium - Third Law: TODO comment for absolute zero behavior (awaiting MPM) - HeatCapacity component with material helpers (water, air, iron, aluminum) - Fallback to C = 1 J/K for abstract objects Spatial grid optimization: - Incremental GridCell updates with Changed<Transform> (O(N²) -> O(N)) - Auto-attach GridCell component to new entities - move_entity() API for efficient cell transitions - Applied to both thermal and wave systems
Add `EntityPool` + centralize component registration for LP (Mind = ECS, Body = SoA) - Hard pool: strip on `release`, remove `Pooled` on `acquire` - Central `UtilsPlugin` for `GridCell` & `Pooled` registration - 13 tests passing, no deps added
- Clarified non-implemented physics: wave/EM energy ledger missing; EOS/phase/convection deferred; material responses (friction/contact/elastic/plastic) belong in matter/MPM; charge/mass/ang. momentum not conserved yet. - Added NaN/Inf guards and TODOs for work->energy ledger and thermal energy bookkeeping. - Added basic conservation/physics tests (momentum/KE, gravity symmetry/BH, ledger flux, thermal conduction/radiation) plus optional EnergyDriftMonitor diagnostic; minor cleanup in basic_save example.
Energy Module: - Add CFL stability check for thermal diffusion (dt <= C*dx²/α) - Implement wave damping energy accounting with ledger integration - Track energy loss from wave damping (E ∝ amplitude²) AI Systems: - Add ThermalSensor/ThermalTracker for temperature perception - Add ElectricSensor/ElectricTracker for electric field sensing - Integrate thermal comfort with homeostasis needs - MPM-safe design: trackers read components without owning solvers Forces Module: - Fix mutual gravitational attraction (resolve mutable aliasing) - Add symplectic Euler integration option - Add forces diagnostics plugin (momentum, kinetic energy tracking) - Add configurable integrator and gravity force modes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Add energy-aware AI perception and fix critical physics stability issues.
Been waiting for MPM to finish but wanted to get actual game features in. This adds temperature/electric field sensing for creatures plus some needed physics infrastructure that was blocking progress.
Implementation
1. AI Energy Perception (New)
Design: MPM-safe from the start. Trackers READ Temperature/ElectricField components that MPM will UPDATE later. No hardcoded physics, just perception layer.
2. Thermal Diffusion Stability (Critical Fix)
3. Wave Energy Conservation
4. Forces Improvements (Pre-existing work merged)
Visibility cleanup:
Testing
Physics verified:
Behavior:
No breaking changes to existing APIs.
Code Example
Adding thermal sensing to a creature:
Reading thermal state:
Technical Notes
MPM Integration Path:
Energy Conservation:
Limitations:
Future trackers planned: