blurite / rsprot

RSProt is an all-in-one networking package for RuneScape Private Servers, primarily targeted at the OldSchool scene.
MIT License
27 stars 5 forks source link

Java Value Class Compatibility #31

Closed Z-Kris closed 6 days ago

Z-Kris commented 6 days ago

This PR refactors a sizable chunk of the codebase where value classes were previously used, namely the areas which had public-facing value classes. We had to eliminate this because any function or constructor that uses a value class object is completely invisible to anyone trying to implement RSProt from a purely java server. The only way to get around this before was to make a few helper classes in Kotlin to bridge the gap.

In most cases, these public-facing value classes provided no measurable benefits anyhow and were just converted to a traditional class. In cases where it does matter, such as inventory updates, going from a primitive long to a boxed Long means increasing the memory consumption by 3x (8 bytes for long, 12 bytes for object header, 4 bytes for 8-byte padding). In cases like that, we had to switch over to using the primitive long in the public facing code, instead of the value class. For existing servers, however, there is no expected change necessary (other than maybe changing the return type from InventoryObject to long), as we created a fake constructor via operator fun invoke on the companion that mimics the old usage.