-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(net/client): Add state bag methods #2314
feat(net/client): Add state bag methods #2314
Conversation
The modifications in this pull request introduce two new natives along with supporting methods for state bags. STATE_BAG_HAS_VALUE: This native is designed to eliminate unnecessary deserialization of state bag values. It serves the purpose of determining whether a value exists for a specific key within the state bag without the need for full deserialization. GET_STATE_BAG_KEYS: This native expands the utility of state bags by enabling the construction of custom models around the state bag without the necessity to manually check each key for existence. This enhancement streamlines the process of working with state bags and facilitates the creation of more efficient and organized models.
Do you happen to have any more specific use cases for these two APIs, such as what you are trying to accomplish that makes you run into the need for this? For example:
I'm not too sure about the API design here either, most other state getters/setters are exposed more naturally in ScRTs, and aren't separate functions to be used directly. Also, having two separate APIs added in a single commit/PR is a bit undesirable as it might be the case only one of the two would be acceptable, and to some extent, both of them look like a solution looking for a problem at worst, or a case of an XY problem at best. ("I'm trying to accomplish X, I think I can do that by doing Y, so I'll try to solve Y and forget all about X") |
Thanks for the feedback. The ideas behind every feature:
const entity = Entity(someHandle)
if (!entity.metadataKey) { // why need to deserialize here, if I only want to know if the value is set?
entity.metadataKey = {...}
}
Also, I know a bunch of developers moving to FiveM from a different multiplayer, and these changes would make their server's migration easier, since the changes in this PR make working with state bags more similar to their old expirience. |
There is no problem for me to separate the features into two different PR's, if is required. |
Agree with the concern that it doesn't match the current state bag api, but there is no easy way to adjust the current api to support this without breaking changes or without changing it complete. So the change will be accepted and added until we have a new state bag api iteration. |
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.
Tested and works fine 👍
Wouldn't hasvalue also return true for keys whose values were set to null? that'd be weird. |
Yeah, because null values are also replicated. But there is no way to remove state bag values as well. So filtering nulls seems to make sense. Ok considering that the current system does not allow removing values by key there might be a long list of keys that are not really useful. |
With #2717 this change makes sense again, because null values will no longer exists inside the data. |
The modifications in this pull request introduce two new natives along with supporting methods for state bags.
Goal of this PR
STATE_BAG_HAS_VALUE
: This native is designed to eliminate unnecessary deserialization of state bag values. It serves the purpose of determining whether a value exists for a specific key within the state bag without the need for full deserialization.GET_STATE_BAG_KEYS
: This native expands the utility of state bags by enabling the construction of custom models around the state bag without the necessity to manually check each key for existence. This enhancement streamlines the process of working with state bags and facilitates the creation of more efficient and organized models.This PR applies to the following area(s)
FiveM, RedM, Server,
Successfully tested on
Game builds: 2944
Platforms: Windows, Linux
Checklist
Fixes issues