-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Energy Distribution Grid: Graph Representation #472
Comments
In the future we might use whatever comes out of bevyengine/bevy#3742. However, let's not get this blocked -> we might need custom implementation in the meantime. |
I aim to cover my progress, thoughts and discussion I have had privately with @Indy2222 around this system in this comment to allow open discussion of this very essential system. Most of the code I have at this stage is here: https://github.com/JackCrumpLeys/DE/tree/feat/energy/graph. These are not final decisions but rather prototype code. DataGraphThe graph contains every every unit as its nodes and edges between nearby units.
/// The power grid resource is used to store the power grid graph.
#[derive(Resource, Debug, Clone)]
pub(crate) struct PowerGrid {
/// The power grid graph.
graph: GraphMap<Entity, f64, Undirected>,
}
kdtreeThis kdtree contains all entities with
#[derive(Debug, Resource)]
pub struct EntityKdTree {
tree: KdTree<f32, u64, 2, 512, u32>,
entity_to_last_loc: HashMap<Entity, ([f32; 2])>,
}
ComponentsThe basic idea is that the /// The energy receiver component is used to mark an entity as an energy receiver.
#[derive(Component, Debug, Clone, Copy)]
pub struct EnergyReceiver;
/// The energy producer component is used to mark an entity as an energy producer.
#[derive(Component, Debug, Clone, Copy)]
pub struct EnergyProducer; systems to designnearby units componentUnits all have a nearby component (maybe a smallvec with some enum like transmitters, receivers or enemy units),
Graph updatesa system that builds/updates the graph for new entities and updated entities (
Energy processorA system that uses the graph to transfer energy. This system is solely responsible for using and interpreting the graph. This system ultimately decides where energy is needed and tries to get it there. (probably the most performance heavy system)
Video demo showing a visualization on my prototype branch |
Currently, only collider based spatial indexing is implemented. It allows reasonably fast spatial queries, for example ray casting or AABB search applied on each entity collider. It is the plan to extend `de_index` with point based indexing (as opposed to collider based indexing). Point based spatial queries have to potential to be much faster and yet sufficient for some important use-cases (i.e. energy grid graph construction). This PR reorganizes `de_index` so that we can add the alternative indexing alongside it. Relates to #472.
As a first step, lets make this extremely simple:
The text was updated successfully, but these errors were encountered: