Skip to content

Commit

Permalink
Add Spring.GetGroundDecalTextureParams/SetGroundDecalTextureParams to…
Browse files Browse the repository at this point in the history
… control parameters usually used only to draw tracks/footsteps, but can be useful for other purposes
  • Loading branch information
lhog committed Mar 29, 2024
1 parent 731f50a commit f9a23b0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions rts/Lua/LuaUnsyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ bool LuaUnsyncedCtrl::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(SetGroundDecalQuadPosAndHeight);
REGISTER_LUA_CFUNC(SetGroundDecalRotation);
REGISTER_LUA_CFUNC(SetGroundDecalTexture);
REGISTER_LUA_CFUNC(SetGroundDecalTextureParams);
REGISTER_LUA_CFUNC(SetGroundDecalAlpha);
REGISTER_LUA_CFUNC(SetGroundDecalNormal);
REGISTER_LUA_CFUNC(SetGroundDecalTint);
Expand Down Expand Up @@ -4600,6 +4601,29 @@ int LuaUnsyncedCtrl::SetGroundDecalTexture(lua_State* L)
return 1;
}

/***
*
* @function Spring.SetGroundDecalTextureParams
* @number decalID
* @number texWrapDistance[opt=currTexWrapDistance] if non-zero sets the mode to repeat the texture along the left-right direction of the decal every texWrapFactor elmos
* @number texTraveledDistance[opt=currTexTraveledDistance] shifts the texture repetition defined by texWrapFactor so the texture of a next line in the continuous multiline can start where the previous finished. For that it should collect all elmo lengths of the previously set multiline segments.
* @treturn nil|bool decalSet
*/
int LuaUnsyncedCtrl::SetGroundDecalTextureParams(lua_State* L)
{
auto* decal = groundDecals->GetDecalById(luaL_checkint(L, 1));
if (!decal) {
lua_pushboolean(L, false);
return 1;
}

decal->uvWrapDistance = luaL_optfloat(L, 2, decal->uvWrapDistance);
decal->uvTraveledDistance = luaL_optfloat(L, 3, decal->uvTraveledDistance);

lua_pushboolean(L, true);
return 1;
}


/***
*
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaUnsyncedCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class LuaUnsyncedCtrl {
static int SetGroundDecalQuadPosAndHeight(lua_State* L);
static int SetGroundDecalRotation(lua_State* L);
static int SetGroundDecalTexture(lua_State* L);
static int SetGroundDecalTextureParams(lua_State* L);
static int SetGroundDecalAlpha(lua_State* L);
static int SetGroundDecalNormal(lua_State* L);
static int SetGroundDecalTint(lua_State* L);
Expand Down
22 changes: 22 additions & 0 deletions rts/Lua/LuaUnsyncedRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ bool LuaUnsyncedRead::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(GetGroundDecalRotation);
REGISTER_LUA_CFUNC(GetGroundDecalTexture);
REGISTER_LUA_CFUNC(GetGroundDecalTextures);
REGISTER_LUA_CFUNC(GetGroundDecalTextureParams);
REGISTER_LUA_CFUNC(GetGroundDecalAlpha);
REGISTER_LUA_CFUNC(GetGroundDecalNormal);
REGISTER_LUA_CFUNC(GetGroundDecalTint);
Expand Down Expand Up @@ -4621,6 +4622,27 @@ int LuaUnsyncedRead::GetGroundDecalTextures(lua_State* L)
}


/***
*
* @function Spring.SetGroundDecalTextureParams
* @number decalID
* @treturn nil|number texWrapDistance if non-zero sets the mode to repeat the texture along the left-right direction of the decal every texWrapFactor elmos
* @treturn number texTraveledDistance shifts the texture repetition defined by texWrapFactor so the texture of a next line in the continuous multiline can start where the previous finished. For that it should collect all elmo lengths of the previously set multiline segments.
*/
int LuaUnsyncedRead::GetGroundDecalTextureParams(lua_State* L)
{
const auto* decal = groundDecals->GetDecalById(luaL_checkint(L, 1));
if (!decal) {
return 0;
}

lua_pushnumber(L, decal->uvWrapDistance);
lua_pushnumber(L, decal->uvTraveledDistance);

return 2;
}


/***
*
* @function Spring.GetGroundDecalAlpha
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaUnsyncedRead.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class LuaUnsyncedRead {
static int GetGroundDecalRotation(lua_State* L);
static int GetGroundDecalTexture(lua_State* L);
static int GetGroundDecalTextures(lua_State* L);
static int GetGroundDecalTextureParams(lua_State* L);
static int GetGroundDecalAlpha(lua_State* L);
static int GetGroundDecalNormal(lua_State* L);
static int GetGroundDecalTint(lua_State* L);
Expand Down

0 comments on commit f9a23b0

Please sign in to comment.