Skip to content

Commit

Permalink
Cleanup after 3679 (#3713)
Browse files Browse the repository at this point in the history
  • Loading branch information
TracerDS authored Sep 14, 2024
1 parent 2fecd74 commit 866cd85
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 91 deletions.
141 changes: 67 additions & 74 deletions Client/game_sa/CEntitySA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,101 +606,94 @@ bool CEntitySA::GetBoneRotation(eBone boneId, float& yaw, float& pitch, float& r
bool CEntitySA::GetBoneRotationQuat(eBone boneId, float& x, float& y, float& z, float& w)
{
RpClump* clump = GetRpClump();
if (clump)
{
// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
CAnimBlendClumpDataSAInterface* clumpDataInterface = *pGame->GetClumpData(clump);
AnimBlendFrameData* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (frameData)
{
RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
x = boneOrientation->imag.x;
y = boneOrientation->imag.y;
z = boneOrientation->imag.z;
w = boneOrientation->real;
return true;
}
}
return false;
if (!clump)
return false;

// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
auto* clumpDataInterface = *pGame->GetClumpData(clump);
auto* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (!frameData)
return false;

RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
x = boneOrientation->imag.x;
y = boneOrientation->imag.y;
z = boneOrientation->imag.z;
w = boneOrientation->real;
return true;
}

bool CEntitySA::SetBoneRotation(eBone boneId, float yaw, float pitch, float roll)
{
RpClump* clump = GetRpClump();
if (clump)
{
// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
CAnimBlendClumpDataSAInterface* clumpDataInterface = *pGame->GetClumpData(clump);
AnimBlendFrameData* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (frameData)
{
RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
RwV3d angles = {yaw, roll, pitch};
BoneNode_cSAInterface::EulerToQuat(&angles, boneOrientation);
CEntitySAInterface* theInterface = GetInterface();
if (theInterface)
{
theInterface->bDontUpdateHierarchy = false;
}
return true;
}
}
return false;
if (!clump)
return false;

// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
auto* clumpDataInterface = *pGame->GetClumpData(clump);
auto* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (!frameData)
return false;

RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
RwV3d angles = { yaw, roll, pitch };
BoneNode_cSAInterface::EulerToQuat(&angles, boneOrientation);
CEntitySAInterface* theInterface = GetInterface();
if (theInterface)
theInterface->bDontUpdateHierarchy = false;

return true;
}

bool CEntitySA::SetBoneRotationQuat(eBone boneId, float x, float y, float z, float w)
{
RpClump* clump = GetRpClump();
if (clump)
{
// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
CAnimBlendClumpDataSAInterface* clumpDataInterface = *pGame->GetClumpData(clump);
AnimBlendFrameData* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (frameData)
{
RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
boneOrientation->imag.x = x;
boneOrientation->imag.y = y;
boneOrientation->imag.z = z;
boneOrientation->real = w;
CEntitySAInterface* theInterface = GetInterface();
if (theInterface)
{
theInterface->bDontUpdateHierarchy = false;
}
return true;
}
}
return false;
if (!clump)
return false;

// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
auto* clumpDataInterface = *pGame->GetClumpData(clump);
auto* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (!frameData)
return false;

RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
boneOrientation->imag.x = x;
boneOrientation->imag.y = y;
boneOrientation->imag.z = z;
boneOrientation->real = w;
CEntitySAInterface* theInterface = GetInterface();
if (theInterface)
theInterface->bDontUpdateHierarchy = false;

return true;
}

bool CEntitySA::GetBonePosition(eBone boneId, CVector& position)
{
RwMatrix* rwBoneMatrix = GetBoneRwMatrix(boneId);
if (rwBoneMatrix)
{
const RwV3d& pos = rwBoneMatrix->pos;
position = {pos.x, pos.y, pos.z};
return true;
}
return false;
if (!rwBoneMatrix)
return false;

const RwV3d& pos = rwBoneMatrix->pos;
position = {pos.x, pos.y, pos.z};
return true;
}

// NOTE: The position will be reset if UpdateElementRpHAnim is called after this.
bool CEntitySA::SetBonePosition(eBone boneId, const CVector& position)
{
RwMatrix* rwBoneMatrix = GetBoneRwMatrix(boneId);
if (rwBoneMatrix)
{
CMatrixSAInterface boneMatrix(rwBoneMatrix, false);
boneMatrix.SetTranslateOnly(position);
boneMatrix.UpdateRW();
return true;
}
return false;
if (!rwBoneMatrix)
return false;

CMatrixSAInterface boneMatrix(rwBoneMatrix, false);
boneMatrix.SetTranslateOnly(position);
boneMatrix.UpdateRW();
return true;
}

BYTE CEntitySA::GetAreaCode()
Expand Down
41 changes: 24 additions & 17 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,22 +1003,26 @@ int CLuaPedDefs::CanPedBeKnockedOffBike(lua_State* luaVM)
bool CLuaPedDefs::SetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CVector position)
{
CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBonePosition(static_cast<eBone>(boneId), position) : false;
if (!theEntity)
return false;
return theEntity->SetBonePosition(static_cast<eBone>(boneId), position);
}

bool CLuaPedDefs::SetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float yaw, float pitch, float roll)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");
throw LuaFunctionError("Invalid bone ID", false);

CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBoneRotation(static_cast<eBone>(boneId), yaw, pitch, roll) : false;
if (!theEntity)
return false;
return theEntity->SetBoneRotation(static_cast<eBone>(boneId), yaw, pitch, roll);
}

bool CLuaPedDefs::SetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float x, float y, float z, float w)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");
throw LuaFunctionError("Invalid bone ID", false);

CEntity* theEntity = entity->GetGameEntity();
return theEntity ? theEntity->SetBoneRotationQuat(static_cast<eBone>(boneId), x, y, z, w) : false;
Expand All @@ -1028,33 +1032,36 @@ std::variant<bool, CLuaMultiReturn<float, float, float>> CLuaPedDefs::GetElement
{
CEntity* theEntity = entity->GetGameEntity();
CVector position;
if (theEntity && theEntity->GetBonePosition(static_cast<eBone>(boneId), position))
return std::make_tuple(position.fX, position.fY, position.fZ);
return false;
if (!theEntity || !theEntity->GetBonePosition(static_cast<eBone>(boneId), position))
return false;

return std::make_tuple(position.fX, position.fY, position.fZ);
}

std::variant<bool, CLuaMultiReturn<float, float, float>> CLuaPedDefs::GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");
throw LuaFunctionError("Invalid bone ID", false);

float yaw = 0.0f, pitch = 0.0f, roll = 0.0f;
float yaw = 0.0f, pitch = 0.0f, roll = 0.0f;
CEntity* theEntity = entity->GetGameEntity();
if (theEntity && theEntity->GetBoneRotation(static_cast<eBone>(boneId), yaw, pitch, roll))
return std::make_tuple(yaw, pitch, roll);
return false;
if (!theEntity || !theEntity->GetBoneRotation(static_cast<eBone>(boneId), yaw, pitch, roll))
return false;

return std::make_tuple(yaw, pitch, roll);
}

std::variant<bool, CLuaMultiReturn<float, float, float, float>> CLuaPedDefs::GetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId)
{
if (boneId > BONE_RIGHTFOOT)
throw LuaFunctionError("Invalid bone ID");
throw LuaFunctionError("Invalid bone ID", false);

float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
CEntity* theEntity = entity->GetGameEntity();
if (theEntity && theEntity->GetBoneRotationQuat(static_cast<eBone>(boneId), x, y, z, w))
return std::make_tuple(x, y, z, w);
return false;
if (!theEntity || !theEntity->GetBoneRotationQuat(static_cast<eBone>(boneId), x, y, z, w))
return false;

return std::make_tuple(x, y, z, w);
}

bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CMatrix boneMatrix)
Expand Down

0 comments on commit 866cd85

Please sign in to comment.