Expand description
§Bevy Fog of War Plugin
A comprehensive 2D fog of war implementation for the Bevy game engine. This plugin provides chunk-based fog processing with GPU compute shaders, multiple vision shapes, explored area tracking, and persistence functionality.
§Architecture
The plugin uses a chunk-based system where the world is divided into configurable chunks (default 256x256 units). Each chunk can be in different visibility states:
- Unexplored: Not yet discovered by any vision source
- Explored: Previously visible but currently out of sight
- Visible: Currently within range of an active vision source
§Memory Management
Chunks are dynamically managed between CPU and GPU memory based on visibility and camera view. This allows for efficient handling of large worlds while maintaining good performance.
§Core Systems
The plugin orchestrates several key systems in a specific order:
- UpdateChunkState: Updates chunk visibility based on vision sources and camera
- ManageEntities: Creates and manages chunk entities
- Persistence: Handles save/load operations
- PrepareTransfers: Manages CPU/GPU memory transfers
§Usage Example
use bevy::prelude::*;
use bevy_fog_of_war::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(FogOfWarPlugin)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
// Add camera with fog of war support
commands.spawn((Camera2d, FogOfWarCamera));
// Add entities with vision
commands.spawn((
Transform::from_xyz(0.0, 0.0, 0.0),
VisionSource::circle(200.0)
));
}Modules§
- persistence
- Fog of war persistence system for saving and loading fog exploration data. 战争迷雾持久化系统,用于保存和加载雾效探索数据
- persistence_
utils - Comprehensive persistence utility functions with multiple serialization formats and compression support. 包含多种序列化格式和压缩支持的全面持久化便利函数
- prelude
- Convenient re-exports for the bevy_fog_of_war crate. bevy_fog_of_war crate 的便捷重新导出
Structs§
- FogOf
WarPlugin - The main fog of war plugin for Bevy applications. 主要的Bevy应用程序雾效插件。
- Request
Chunk Snapshot - Event to request a snapshot for a specific chunk. 请求为特定区块生成快照的事件。
Enums§
- FogSystems
- System sets that define the execution order of fog of war systems. 定义雾效系统执行顺序的系统集。
Functions§
- manage_
chunk_ texture_ transfer - Orchestrates intelligent memory management between CPU and GPU for chunk textures. 协调区块纹理在CPU和GPU之间的智能内存管理。