Skip to content
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 96 commits into from
Dec 29, 2023
Merged

Electricity system #1371

merged 96 commits into from
Dec 29, 2023

Conversation

stilnat
Copy link
Contributor

@stilnat stilnat commented Dec 2, 2023

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

  • The game builds properly without errors.
  • No unrelated changes are present.
  • No "trash" files are committed.
  • Relevant code is documented.
  • Update the related GitBook document, or create a new one if needed.

Pictures/Videos)

Testing

Networking checklist

  • Works from host in host mode.
  • Works from server in server mode.
  • Works on server in client mode.
  • Works and is syncronized across different clients.
  • Is persistent.

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

  • lights don't turn off when disconnected from circuits.
  • not sure why but garbage circuits are created.
  • Update circuits only upon some changes in them, not every frame.
  • random reorder of elements to power random devices when power is struggling but not zero.
  • Replace cubes with actual generator and battery.

@cosmiccoincidence
Copy link
Member

Ok. It's about ready for one of the coders to do a review on this.

@cosmiccoincidence

This comment was marked as outdated.

@stilnat
Copy link
Contributor Author

stilnat commented Dec 22, 2023

@cosmiccoincidence just waiting for Iamteapot final review before writing doc

@iamteapot422 iamteapot422 mentioned this pull request Dec 25, 2023
iamteapot422
iamteapot422 previously approved these changes Dec 29, 2023
@iamteapot422 iamteapot422 merged commit a67b12c into RE-SS3D:develop Dec 29, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Electricity Tasks related to the electrical system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants