Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, u
m_pBuilding(nullptr),
m_usesCollision(true),
m_ucAlpha(255),
m_vecScale(1.0f, 1.0f, 1.0f),
m_pHighBuilding(nullptr),
m_pLowBuilding(nullptr)
{
Expand Down Expand Up @@ -155,6 +156,26 @@ void CClientBuilding::SetAlpha(unsigned char ucAlpha)
m_pBuilding->SetAlpha(ucAlpha);
}

void CClientBuilding::SetScale(const CVector& vecScale)
{
m_vecScale = vecScale;

if (m_vecScale.fX == 1.0f && m_vecScale.fY == 1.0f && m_vecScale.fZ == 1.0f)
m_pBuildingManager->RemoveFromScaledList(this);
else
m_pBuildingManager->AddToScaledList(this);

ApplyScale();
}

void CClientBuilding::ApplyScale()
{
if (!m_pBuilding)
return;

m_pBuilding->SetScaleInternal(m_vecScale);
}

void CClientBuilding::Create()
{
if (m_pBuilding)
Expand All @@ -181,6 +202,9 @@ void CClientBuilding::Create()
if (m_ucAlpha != 255)
m_pBuilding->SetAlpha(m_ucAlpha);

if (m_vecScale.fX != 1.0f || m_vecScale.fY != 1.0f || m_vecScale.fZ != 1.0f)
ApplyScale();

if (m_pHighBuilding)
{
m_pHighBuilding->GetBuildingEntity()->SetLod(m_pBuilding);
Expand Down
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuilding.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class CClientBuilding : public CClientEntity
unsigned char GetAlpha() const noexcept { return m_ucAlpha; }
void SetAlpha(unsigned char ucAlpha);

const CVector& GetScale() const noexcept { return m_vecScale; }
void SetScale(const CVector& vecScale);
void ApplyScale();

void Create();
void Destroy();

Expand Down Expand Up @@ -87,6 +91,7 @@ class CClientBuilding : public CClientEntity
uint8_t m_interior;
bool m_usesCollision;
unsigned char m_ucAlpha;
CVector m_vecScale;

CClientBuilding* m_pHighBuilding;
CClientBuilding* m_pLowBuilding;
Expand Down
20 changes: 20 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void CClientBuildingManager::RemoveAll()
}

m_List.clear();
m_ScaledBuildings.clear();

// Allow list removal again
m_bRemoveFromList = true;
Expand All @@ -63,6 +64,25 @@ void CClientBuildingManager::RemoveFromList(CClientBuilding* pBuilding)
{
m_List.remove(pBuilding);
}

RemoveFromScaledList(pBuilding);
}

void CClientBuildingManager::AddToScaledList(CClientBuilding* pBuilding)
{
if (std::find(m_ScaledBuildings.begin(), m_ScaledBuildings.end(), pBuilding) == m_ScaledBuildings.end())
m_ScaledBuildings.push_back(pBuilding);
}

void CClientBuildingManager::RemoveFromScaledList(CClientBuilding* pBuilding)
{
m_ScaledBuildings.remove(pBuilding);
}

void CClientBuildingManager::UpdateScaledBuildings()
{
for (CClientBuilding* pBuilding : m_ScaledBuildings)
pBuilding->ApplyScale();
}

bool CClientBuildingManager::IsValidModel(uint16_t modelId)
Expand Down
6 changes: 6 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuildingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class CClientBuildingManager
void RestoreDestroyed();
void RestoreDestroyedSafe();

void UpdateScaledBuildings();

private:
void AddToScaledList(CClientBuilding* pBuilding);
void RemoveFromScaledList(CClientBuilding* pBuilding);

bool DoPoolResize(size_t newCapacity);
void AddToList(CClientBuilding* pBuilding)
{
Expand All @@ -51,6 +56,7 @@ class CClientBuildingManager
void RemoveFromList(CClientBuilding* pBuilding);

std::list<CClientBuilding*> m_List;
std::list<CClientBuilding*> m_ScaledBuildings;
bool m_bRemoveFromList;
unsigned short m_usDimension{0};
};
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3959,6 +3959,9 @@ void CClientGame::PostWorldProcessHandler()

void CClientGame::PostWorldProcessPedsAfterPreRenderHandler()
{
if (CClientBuildingManager* pBuildingManager = m_pManager->GetBuildingManager())
pBuildingManager->UpdateScaledBuildings();

CLuaArguments Arguments;
m_pRootEntity->CallEvent("onClientPedsProcessed", Arguments, false);
}
Expand Down
10 changes: 10 additions & 0 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4218,10 +4218,20 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
modelId = 1700;

bitStream.Read(LowLodObjectID);

CVector vecScale(1.0f, 1.0f, 1.0f);
if (bitStream.Can(eBitStreamVersion::BuildingScale))
{
bitStream.Read(vecScale.fX);
bitStream.Read(vecScale.fY);
bitStream.Read(vecScale.fZ);
}

CClientBuilding* pBuilding = new CClientBuilding(g_pClientGame->m_pManager, EntityID, modelId, position.data.vecPosition,
rotationRadians.data.vecRotation, ucInterior);

pBuilding->SetUsesCollision(bCollisonsEnabled);
pBuilding->SetScale(vecScale);
pEntity = pBuilding;
break;
}
Expand Down
36 changes: 36 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ bool CStaticFunctionDefinitions::GetElementRotation(CClientEntity& Entity, CVect
return true;
}

bool CStaticFunctionDefinitions::GetElementScale(CClientEntity& Entity, CVector& vecScale)
{
if (IS_OBJECT(&Entity))
{
static_cast<CClientObject&>(Entity).GetScale(vecScale);
return true;
}

if (Entity.GetType() == CCLIENTBUILDING)
{
vecScale = static_cast<CClientBuilding&>(Entity).GetScale();
return true;
}

return false;
}

bool CStaticFunctionDefinitions::GetElementVelocity(CClientEntity& Entity, CVector& vecVelocity)
{
int iType = Entity.GetType();
Expand Down Expand Up @@ -1195,6 +1212,25 @@ bool CStaticFunctionDefinitions::SetElementRotation(CClientEntity& Entity, const
return true;
}

bool CStaticFunctionDefinitions::SetElementScale(CClientEntity& Entity, const CVector& vecScale)
{
RUN_CHILDREN(SetElementScale(**iter, vecScale))

if (IS_OBJECT(&Entity))
{
static_cast<CDeathmatchObject&>(Entity).SetScale(vecScale);
return true;
}

if (Entity.GetType() == CCLIENTBUILDING)
{
static_cast<CClientBuilding&>(Entity).SetScale(vecScale);
return true;
}

return false;
}

bool CStaticFunctionDefinitions::SetElementVelocity(CClientEntity& Entity, const CVector& vecVelocity)
{
RUN_CHILDREN(SetElementVelocity(**iter, vecVelocity))
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CStaticFunctionDefinitions
static bool GetElementMatrix(CClientEntity& Entity, CMatrix& matrix);
static bool GetElementPosition(CClientEntity& Entity, CVector& vecPosition);
static bool GetElementRotation(CClientEntity& Entity, CVector& vecRotation, eEulerRotationOrder rotationOrder);
static bool GetElementScale(CClientEntity& Entity, CVector& vecScale);
static bool GetElementVelocity(CClientEntity& Entity, CVector& vecVelocity);
static bool GetElementTurnVelocity(CClientEntity& Entity, CVector& vecTurnVelocity);
static bool GetElementInterior(CClientEntity& Entity, unsigned char& ucInterior);
Expand Down Expand Up @@ -91,6 +92,7 @@ class CStaticFunctionDefinitions
static bool SetElementMatrix(CClientEntity& Entity, const CMatrix& matrix);
static bool SetElementPosition(CClientEntity& Entity, const CVector& vecPosition, bool bWarp = true);
static bool SetElementRotation(CClientEntity& Entity, const CVector& vecRotation, eEulerRotationOrder rotationOrder, bool bNewWay);
static bool SetElementScale(CClientEntity& Entity, const CVector& vecScale);
static bool SetElementVelocity(CClientEntity& Element, const CVector& vecVelocity);
static bool SetElementAngularVelocity(CClientEntity& Element, const CVector& vecTurnVelocity);
static bool SetElementParent(CClientEntity& Element, CClientEntity& Parent, CLuaMain* pLuaMain);
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void CLuaBuildingDefs::AddClass(lua_State* luaVM)
lua_newclass(luaVM);

lua_classfunction(luaVM, "create", "createBuilding");
lua_classfunction(luaVM, "getScale", "getElementScale");
lua_classfunction(luaVM, "setScale", "setElementScale");

lua_registerclass(luaVM, "Building", "Element");
}
Expand Down
64 changes: 64 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void CLuaElementDefs::LoadFunctions()
{"getElementMatrix", GetElementMatrix},
{"getElementPosition", GetElementPosition},
{"getElementRotation", GetElementRotation},
{"getElementScale", GetElementScale},
{"getElementVelocity", GetElementVelocity},
{"getElementAngularVelocity", GetElementTurnVelocity},
{"getElementType", GetElementType},
Expand Down Expand Up @@ -82,6 +83,7 @@ void CLuaElementDefs::LoadFunctions()
{"setElementMatrix", SetElementMatrix},
{"setElementPosition", SetElementPosition},
{"setElementRotation", SetElementRotation},
{"setElementScale", SetElementScale},
{"setElementVelocity", SetElementVelocity},
{"setElementAngularVelocity", SetElementAngularVelocity},
{"setElementInterior", SetElementInterior},
Expand Down Expand Up @@ -549,6 +551,32 @@ int CLuaElementDefs::OOP_GetElementRotation(lua_State* luaVM)
return 1;
}

int CLuaElementDefs::GetElementScale(lua_State* luaVM)
{
// float, float, float getElementScale ( element theElement )
CClientEntity* pEntity = NULL;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pEntity);

if (!argStream.HasErrors())
{
CVector vecScale;
if (CStaticFunctionDefinitions::GetElementScale(*pEntity, vecScale))
{
lua_pushnumber(luaVM, vecScale.fX);
lua_pushnumber(luaVM, vecScale.fY);
lua_pushnumber(luaVM, vecScale.fZ);
return 3;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaElementDefs::GetElementVelocity(lua_State* luaVM)
{
// Verify the argument
Expand Down Expand Up @@ -1978,6 +2006,42 @@ int CLuaElementDefs::OOP_SetElementRotation(lua_State* luaVM)
return 1;
}

int CLuaElementDefs::SetElementScale(lua_State* luaVM)
{
// bool setElementScale ( element theElement, float scale )
// bool setElementScale ( element theElement, float x, float y, float z )
CClientEntity* pEntity;
CVector vecScale;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pEntity);

if (argStream.NextIsVector3D())
{
argStream.ReadVector3D(vecScale);
}
else
{
argStream.ReadNumber(vecScale.fX);
argStream.ReadNumber(vecScale.fY, vecScale.fX);
argStream.ReadNumber(vecScale.fZ, vecScale.fX);
}

if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetElementScale(*pEntity, vecScale))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaElementDefs::SetElementVelocity(lua_State* luaVM)
{
CClientEntity* pEntity;
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CLuaElementDefs : public CLuaDefs
LUA_DECLARE_OOP(GetElementMatrix);
LUA_DECLARE_OOP(GetElementPosition);
LUA_DECLARE_OOP(GetElementRotation);
LUA_DECLARE(GetElementScale);
LUA_DECLARE_OOP(GetElementVelocity);
LUA_DECLARE_OOP(GetElementTurnVelocity);
LUA_DECLARE(GetElementType);
Expand Down Expand Up @@ -82,6 +83,7 @@ class CLuaElementDefs : public CLuaDefs
LUA_DECLARE(SetElementMatrix);
LUA_DECLARE(SetElementPosition);
LUA_DECLARE_OOP(SetElementRotation);
LUA_DECLARE(SetElementScale);
LUA_DECLARE(SetElementVelocity);
LUA_DECLARE(SetElementAngularVelocity);
LUA_DECLARE(SetElementParent);
Expand Down
6 changes: 3 additions & 3 deletions Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ int CLuaObjectDefs::StopObject(lua_State* luaVM)
int CLuaObjectDefs::SetObjectScale(lua_State* luaVM)
{
// bool setObjectScale ( object theObject, float scale )
CClientEntity* pEntity;
CClientObject* pObject;
CVector vecScale;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pEntity);
argStream.ReadUserData(pObject);

// Caz - This function looks totally wrong
// the function is designed to support the following syntaxes
Expand All @@ -462,7 +462,7 @@ int CLuaObjectDefs::SetObjectScale(lua_State* luaVM)
}
if (!argStream.HasErrors())
{
if (CStaticFunctionDefinitions::SetObjectScale(*pEntity, vecScale))
if (CStaticFunctionDefinitions::SetObjectScale(*pObject, vecScale))
{
lua_pushboolean(luaVM, true);
return 1;
Expand Down
26 changes: 26 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CObjectRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void CObjectRPCs::LoadFunctions()
AddHandler(MOVE_OBJECT, MoveObject, "MoveObject");
AddHandler(STOP_OBJECT, StopObject, "StopObject");
AddHandler(SET_OBJECT_SCALE, SetObjectScale, "SetObjectScale");
AddHandler(SET_ELEMENT_SCALE, SetElementScale, "SetElementScale");
AddHandler(SET_OBJECT_VISIBLE_IN_ALL_DIMENSIONS, SetObjectVisibleInAllDimensions, "SetObjectVisibleInAllDimensions");
AddHandler(SET_OBJECT_BREAKABLE, SetObjectBreakable, "SetObjectBreakable");
AddHandler(BREAK_OBJECT, BreakObject, "BreakObject");
Expand Down Expand Up @@ -116,6 +117,31 @@ void CObjectRPCs::SetObjectScale(CClientEntity* pSource, NetBitStreamInterface&
}
}

void CObjectRPCs::SetElementScale(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
CVector vecScale;

bitStream.Read(vecScale.fX);
vecScale.fY = vecScale.fX;
vecScale.fZ = vecScale.fX;

bitStream.Read(vecScale.fY);
bitStream.Read(vecScale.fZ);

if (pSource->GetType() == CCLIENTBUILDING)
{
static_cast<CClientBuilding*>(pSource)->SetScale(vecScale);
return;
}

CDeathmatchObject* pObject = static_cast<CDeathmatchObject*>(m_pObjectManager->Get(pSource->GetID()));

if (pObject)
{
pObject->SetScale(vecScale);
}
}

void CObjectRPCs::SetObjectVisibleInAllDimensions(CClientEntity* pSource, NetBitStreamInterface& bitStream)
{
CDeathmatchObject* pObject = static_cast<CDeathmatchObject*>(m_pObjectManager->Get(pSource->GetID()));
Expand Down
Loading
Loading