-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Electricity system #1371
Merged
Merged
Electricity system #1371
Conversation
This file contains 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
Ok. It's about ready for one of the coders to do a review on this. |
This comment was marked as outdated.
This comment was marked as outdated.
@cosmiccoincidence just waiting for Iamteapot final review before writing doc |
Closed
This reverts commit 2e92541.
iamteapot422
previously approved these changes
Dec 29, 2023
iamteapot422
approved these changes
Dec 29, 2023
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.
Summary
Provide a first implementation of the electricity system, mostly the foundation to build on it, but also provide a few implementation, including, working batteries, basic infinite energy generator, functionnal cables, light turning off and on based on power availability.
generator sound under CC0 found here : https://freesound.org/people/qubodup/sounds/189896/
PR checklist
Pictures/Videos)
Testing
Networking checklist
Changes
The electric system relies on the QuickGraph package, which allow to use some graph objects and apply some graph algorithms. It's relevant to decide what's connected to what. We're using an undirected graph since, at least in this first iteration, there's no sense of direction of the power, we only care if two things are connected, or not.
The graph represent the set of all circuits on the map. A vertice in the graph consists of coordinates, tilelayer and direction (so 4 elements) of a given electric thing (cable, lamp, generator).
An edge in the graph represents a connection between two electric things.
When adding a new electric element, the electric system uses some connector script from the tile system to decide if this element is connected to anything.
If it is, then it's going to add a new edge for each connection, expanding the graph.
If it's connected to nothing, it's still going to add a new vertice, representing the disconnected element.
A circuit consists of a set of relevant element all connected together. A single vertice with no edge is as such considered to be a circuit as well.
When changing anything in the disposition of electrical elements on the map, the graph update, and compute back all circuits.
Computing circuits is not that expensive, it's using a graph traversing algorithm, which execute in O(V+E) complexity, V for the number of vertices and E the number of edges. The complexity grows pretty much only linearly with the number of electric things, which should be very scalable.
Related issues/PRs
TODO