-
-
Notifications
You must be signed in to change notification settings - Fork 191
feat: add Vector3 and QAngle explicit casts to System.Numerics.Vector3 #943
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
Conversation
|
this change/idea may actually reduce the number of leaks, but developers would need to explicitly cast to the struct which doesn't help existing (but abandoned) plugins, also we would need a way to tell people to actually cast their params. I'm thinking about implicit casting that would be handled by the core, just people are already instantiating the vector classes when they call the I'm looking forward for CS# 2.0 |
|
Yeah I thought about implicit casting, but yes it wouldn't really help anyone either because people would still be instantiating CS# Vector class. The idea behind this isn't to fix old plugins, but allow an easier path forward for current Devs to write more performant code that would be more future proof. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds explicit cast operators to convert Vector3 and QAngle types to System.Numerics.Vector3, and introduces a new Teleport method overload that accepts Vector3 parameters to reduce memory leaks. The changes aim to provide a more memory-efficient alternative to the existing Vector-based Teleport method while maintaining backwards compatibility.
Key changes:
- Added explicit cast operators from Vector and QAngle to System.Numerics.Vector3
- Introduced Vector3-based Teleport method overload with unsafe pointer operations
- Updated exception message for consistency between Teleport overloads
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Vector.cs | Adds explicit cast operator to convert Vector to System.Numerics.Vector3 |
| QAngle.cs | Adds explicit cast operator to convert QAngle to System.Numerics.Vector3 and imports System.Numerics namespace |
| CBaseEntity.cs | Adds new Teleport overload accepting Vector3 parameters and updates exception message |
Since
Teleportis probably the biggest source of Vector based memory leaks, this adds a way to call the Teleport virtual method usingSystem.Numerics.Vector3while still maintaining backwards compatibility.To increase the ergonomics of modifying existing vectors coming out of the schema system (like with AbsOrigin), I've added explicit cast operators to allow you to easily convert to a numerics Vector3. This means the following code can be substituted to remove memory leak:
Before:
After:
Unfortunately to ultimately fix memory leaks with regards to the schema system, it will require breaking changes so this will need to be done in a breaking 2.0 release of CS# I imagine.