Skip to content

Major Netcode Refactor #180

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

Merged
merged 1 commit into from
Aug 10, 2025
Merged

Major Netcode Refactor #180

merged 1 commit into from
Aug 10, 2025

Conversation

valkyrienyanko
Copy link
Contributor

@valkyrienyanko valkyrienyanko commented Aug 9, 2025

Notes

The reflection code in PacketRegistry will be kept as it completely removes the need to manually register each individual packet class. Maybe in the future a source generator could handle this task so the reflection cost on startup is completely removed.

Changelog

Performance

  • Reflection code to lookup properties via NetSend attribute are cached by type rather than instance. In other words property reflection code was ran every time a new instance of the same packet was created. Imagine if 1000 position packets were sent, that's 1000 calls with reflection. Now since properties are cached by type the reflection only happens once per type.
  • Packet types are cached in their constructors so GetOpcode() does not need to retrieve them on every lookup
  • Assembly.GetExecutingAssembly().GetTypes() in PacketRegistry is now cached for single lookup
  • MapPackets<T> now uses an array instead of a List
  • IgnoredPackets now uses a HashSet instead of List

Readability

  • All packet registration code has been moved to PacketRegistry
  • Godot netcode has been separated from ENet netcode by adding new classes GodotServer GodotClient
  • All of the coding guidelines have been enforced

Usability

  • An example scene has been provided in res://Framework/GodotUtils/Netcode/Sandbox/TopDown/
  • Client and server factory classes are no longer required to be created for setup code
  • NetControlPanelLow now requires its extending class to implement ENetOptions Options and all the UI button nodes
  • All netcode has been wrapped with NETCODE_ENABLED which can easily be disabled by removing the constant from .csproj

Bug Fixes

  • The server and client are now properly stopped when the main menu button is pressed in the game popup menu
  • Server port is no longer fixed to default port and is fetched from the front end ui
  • Fixed ToFormattedString(this object v) in GodotUtils returning extra blank lines
  • Packets are now disposed of even when a System.IO.EndOfStreamException is thrown
  • Server and client host will now be disposed of even if an exception is thrown
  • Logger.Update() now only runs if NETCODE_ENABLED constant exists
  • Added missing DEBUG define wrapped around Visualize using causing non-debug release builds to fail
  • ValdiateResourceFile(...) in OptionsManager now also detects resource files with empty script paths caused by projects being ran in exported release mode

@valkyrienyanko valkyrienyanko self-assigned this Aug 9, 2025
@valkyrienyanko valkyrienyanko merged commit 5ca3574 into main Aug 10, 2025
@valkyrienyanko valkyrienyanko deleted the netcode-refactor branch August 10, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant