-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Add resetElements argument to resetWaterLevel #2711
base: master
Are you sure you want to change the base?
Conversation
Allows all water elements level to be reset
On second thoughts, it may be nice if you could also pass a specific element (maybe even a table of elements too) instead of just |
I've implemented the above and updated the test resource. |
Nice! Code is ready now? |
Co-authored-by: Marek Kulik <[email protected]>
Co-authored-by: Marek Kulik <[email protected]>
Co-authored-by: Marek Kulik <[email protected]>
As a note for the "caveat" mentioned in the initial PR message, this can be easily worked around by maintaining your own list/table of client water elements; so it's really a non-issue. |
pWater->ResetLevel(); | ||
} | ||
|
||
void CClientWaterManager::ResetElementWaterLevel(std::vector<CClientWater*>& vecWaterElements) |
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.
vector can be const?
bool CClientWaterManager::ResetAllElementWaterLevel() | ||
{ | ||
for (CClientWater* pWater : m_List) | ||
pWater->ResetLevel(); | ||
return true; | ||
} |
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.
Why is this function as a bool if it is unnecessary? The other functions are of type void and this one doesn't seem to need to return a value either
@@ -31,6 +31,9 @@ class CClientWaterManager | |||
bool SetPositionWaterLevel(const CVector& vecPosition, float fLevel, void* pChangeSource); | |||
bool SetWorldWaterLevel(float fLevel, void* pChangeSource, bool bIncludeWorldNonSeaLevel, bool bIncludeWorldSeaLevel, bool bIncludeOutsideWorldLevel); | |||
bool SetAllElementWaterLevel(float fLevel, void* pChangeSource); | |||
bool ResetAllElementWaterLevel(); | |||
void ResetElementWaterLevel(CClientWater* pWater); | |||
void ResetElementWaterLevel(std::vector<CClientWater*>& vecWaterElements); |
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.
vector can be const?
pWater->ResetLevel(); | ||
} | ||
|
||
void CWaterManager::ResetElementWaterLevel(std::vector<CWater*>& vecWaterElements) |
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.
vector can be const?
@@ -37,6 +37,9 @@ class CWaterManager | |||
void ResetWorldWaterLevel(); | |||
void SetElementWaterLevel(CWater* pWater, float fLevel); | |||
void SetAllElementWaterLevel(float fLevel); | |||
void ResetAllElementWaterLevel(); | |||
void ResetElementWaterLevel(CWater* pWater); | |||
void ResetElementWaterLevel(std::vector<CWater*>& vecWaterElements); |
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.
vector can be const?
@@ -167,11 +169,42 @@ int CLuaWaterDefs::SetWaterLevel(lua_State* luaVM) | |||
return 1; | |||
} | |||
|
|||
int CLuaWaterDefs::ResetWaterLevel(lua_State* luaVM) | |||
bool CLuaWaterDefs::ResetWaterLevel(std::variant<std::monostate, bool, std::vector<CWater*>, CWater*> resetElements) |
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.
resetElements can be const?
|
||
static bool ResetWaterLevel(std::variant<std::monostate, bool, std::vector<CWater*>, CWater*> resetElements); |
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.
resetElements can be const?
@@ -32,4 +31,6 @@ class CLuaWaterDefs : public CLuaDefs | |||
LUA_DECLARE(GetWaterLevel); | |||
LUA_DECLARE(IsWaterDrawnLast); | |||
LUA_DECLARE(GetWaterVertexPosition); | |||
|
|||
static bool ResetWaterLevel(std::variant<std::monostate, bool, std::vector<CClientWater*>, CClientWater*> resetElements); |
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.
resetElements can be const?
return 1; | ||
CClientWaterManager* pWaterManager = g_pClientGame->GetManager()->GetWaterManager(); | ||
|
||
switch (resetElements.index()) |
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.
What do you think about using std::holds_alternative
instead of an index here?
return 1; | ||
CWaterManager* pWaterManager = g_pGame->GetWaterManager(); | ||
|
||
switch (resetElements.index()) |
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.
What do you think about using std::holds_alternative
instead of an index here?
Bump? |
Resolves #2695
Adds a new argument to resetWaterLevel,
resetElements
, allowing you to reset the level of one or more water elementsnil
(default value) orfalse
: only the GTA world water level will be reset (previous/existing behaviour)true
: all water elements created via createWater will have their level reset.water-element
: specific water element level reset.table{water-elements}
: table of water element level resetNote: the GTA world water level is unaffected except for values of
nil
orfalse
The default level for a water element, is defined as the average of initial Z vertex positions upon creation.
Here's a test resource
Upon starting it spawns 2 small water squares next to each other (one on client, one on server) and teleports you to their position.
Use
/slevel <num>
(for server) or/clevel <num>
(for client) to set the water level.Use
/sreset <type>
or/creset <type>
to reset the water level for server or client.The
<type>
controls the arguments passed toresetWaterLevel
Feel free to add more water positions in the
waterPositions
table, the script works with it.The only caveat (with this test resource) is that when using
/creset
it will also reset the water level for server created water elements too (since water only has a "true" representation on the client regardless if created on server). But not vice versa (so using/sreset
won't reset client created water elements). You can obviously work around this in your own script by storing a list of the client specific water elements.