Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

Lpsd
Copy link
Member

@Lpsd Lpsd commented Aug 14, 2022

Resolves #2695

Adds a new argument to resetWaterLevel, resetElements, allowing you to reset the level of one or more water elements

  • nil (default value) or false: 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 reset

Note: the GTA world water level is unaffected except for values of nil or false

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 to resetWaterLevel

  • 0: nil/none
  • 1: true
  • 2: single water element
  • 3: table of all water elements

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.

Allows all water elements level to be reset
@Lpsd Lpsd added the enhancement New feature or request label Aug 14, 2022
@Lpsd
Copy link
Member Author

Lpsd commented Aug 14, 2022

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 true to reset all water elements. See no reason not to do this.

@Lpsd
Copy link
Member Author

Lpsd commented Aug 14, 2022

I've implemented the above and updated the test resource.

@Lpsd Lpsd changed the title Add resetElements argument to setWaterLevel Add resetElements argument to resetWaterLevel Aug 27, 2022
@Fernando-A-Rocha
Copy link
Contributor

Nice! Code is ready now?

Lpsd and others added 3 commits June 17, 2024 22:51
Co-authored-by: Marek Kulik <[email protected]>
Co-authored-by: Marek Kulik <[email protected]>
@Lpsd
Copy link
Member Author

Lpsd commented Jun 17, 2024

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.

@Lpsd Lpsd requested a review from botder June 19, 2024 18:26
pWater->ResetLevel();
}

void CClientWaterManager::ResetElementWaterLevel(std::vector<CClientWater*>& vecWaterElements)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector can be const?

Comment on lines +107 to +112
bool CClientWaterManager::ResetAllElementWaterLevel()
{
for (CClientWater* pWater : m_List)
pWater->ResetLevel();
return true;
}
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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())
Copy link
Contributor

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())
Copy link
Contributor

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?

@lynconsix
Copy link

Bump?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make resetWaterLevel working with water elements
6 participants