From 2af7c81d54428a9468dbb8292fb06093fd901246 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Thu, 30 Nov 2017 19:46:47 +0100 Subject: [PATCH 01/19] Make possible to use string as second argument --- .../logic/luadefs/CLuaElementDefs.cpp | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index c728e884677..2aff68878d7 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -2156,24 +2156,49 @@ int CLuaElementDefs::SetElementCollisionsEnabled ( lua_State* luaVM ) int CLuaElementDefs::SetElementCollidableWith ( lua_State* luaVM ) { CClientEntity* pEntity = NULL; - CClientEntity* pWithEntity = NULL; bool bCanCollide = true; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pEntity ); - argStream.ReadUserData ( pWithEntity ); - argStream.ReadBool ( bCanCollide ); + // bool setElementCollidableWith ( element theElement, element withElement, bool enabled ) + if ( argStream.NextIsUserData() ) + { + CClientEntity* pWithEntity = NULL; + argStream.ReadUserData ( pWithEntity ); + argStream.ReadBool ( bCanCollide ); - // Verify the arguments - if ( !argStream.HasErrors () ) + // Verify the arguments + if ( !argStream.HasErrors () ) + { + if ( CStaticFunctionDefinitions::SetElementCollidableWith ( *pEntity, *pWithEntity, bCanCollide ) ) + { + lua_pushboolean ( luaVM, true ); + return 1; + } + } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + } + // bool setElementCollidableWith ( element theElement, string withType, bool enabled ) + else { - if ( CStaticFunctionDefinitions::SetElementCollidableWith ( *pEntity, *pWithEntity, bCanCollide ) ) + SString strType; + bool bOnlyCreated; + argStream.ReadString ( strType ); + argStream.ReadBool ( bCanCollide ); + argStream.ReadBool ( bOnlyCreated, false ); + + // Verify the arguments + if ( !argStream.HasErrors () ) { - lua_pushboolean ( luaVM, true ); - return 1; + if ( CStaticFunctionDefinitions::SetElementCollidableWith ( *pEntity, strType.c_str (), bCanCollide, bOnlyCreated ) ) + { + lua_pushboolean ( luaVM, true ); + return 1; + } } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } - else - m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; From 1e2f0409524c2f07c39e99cfc9d79a205a769eb9 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Thu, 30 Nov 2017 19:53:31 +0100 Subject: [PATCH 02/19] Add a easy way to get entities by type from root as a list. --- .../mods/deathmatch/logic/CClientEntity.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Client/mods/deathmatch/logic/CClientEntity.cpp b/Client/mods/deathmatch/logic/CClientEntity.cpp index b4054429d5a..1f695624c2c 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.cpp +++ b/Client/mods/deathmatch/logic/CClientEntity.cpp @@ -1455,6 +1455,41 @@ void CClientEntity::RemoveEntityFromRoot ( unsigned int uiTypeHash, CClientEntit CClientEntity::RemoveEntityFromRoot ( (*iter)->GetTypeHash (), *iter ); } + +CFastList < CClientEntity* > CClientEntity::GetEntitiesFromRoot ( unsigned int uiTypeHash, bool bStreamedIn ) +{ + CFastList < CClientEntity* > entities; + + t_mapEntitiesFromRoot::iterator find = ms_mapEntitiesFromRoot.find ( uiTypeHash ); + if ( find != ms_mapEntitiesFromRoot.end () ) + { + CFromRootListType& listEntities = find->second; + CClientEntity* pEntity; + unsigned int uiIndex = 0; + + for ( CFromRootListType::reverse_iterator i = listEntities.rbegin (); + i != listEntities.rend (); + ++i ) + { + pEntity = *i; + + // Only streamed in elements? + if ( !bStreamedIn || !pEntity->IsStreamingCompatibleClass () || + reinterpret_cast < CClientStreamElement* > ( pEntity )->IsStreamedIn () ) + { + if ( !pEntity->IsBeingDeleted () ) + { + // Add it to the table + entities.push_back ( pEntity ); + } + } + } + } + + return entities; +} + + void CClientEntity::GetEntitiesFromRoot ( unsigned int uiTypeHash, lua_State* luaVM, bool bStreamedIn ) { #if CHECK_ENTITIES_FROM_ROOT From 4803763af54835b2b79fe32fabdc9349c91ab55a Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Thu, 30 Nov 2017 19:53:57 +0100 Subject: [PATCH 03/19] Add GetEntitiesFromRoot to easily get a list of entities by type from root. --- Client/mods/deathmatch/logic/CClientEntity.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Client/mods/deathmatch/logic/CClientEntity.h b/Client/mods/deathmatch/logic/CClientEntity.h index ba5a97454d9..b53c3d03911 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.h +++ b/Client/mods/deathmatch/logic/CClientEntity.h @@ -373,11 +373,13 @@ class CClientEntity : public CClientEntityBase public: // Optimization for getElementsByType starting at root static void StartupEntitiesFromRoot ( ); + static CFastList < CClientEntity* > GetEntitiesFromRoot ( unsigned int uiTypeHash, bool bStreamedIn ); private: static bool IsFromRoot ( CClientEntity* pEntity ); static void AddEntityFromRoot ( unsigned int uiTypeHash, CClientEntity* pEntity, bool bDebugCheck = true ); static void RemoveEntityFromRoot ( unsigned int uiTypeHash, CClientEntity* pEntity ); static void GetEntitiesFromRoot ( unsigned int uiTypeHash, lua_State* luaVM, bool bStreamedIn ); + #if CHECK_ENTITIES_FROM_ROOT static void _CheckEntitiesFromRoot ( unsigned int uiTypeHash ); From 9d6ebf7ec3729e3cd1e39f25e373f0b427e666ba Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Thu, 30 Nov 2017 19:54:27 +0100 Subject: [PATCH 04/19] Add our setElementCollidableWith with type as second argument --- .../logic/CStaticFunctionDefinitions.cpp | 41 +++++++++++++++++++ .../logic/CStaticFunctionDefinitions.h | 1 + 2 files changed, 42 insertions(+) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 916be2528d5..ce0f340401c 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3603,6 +3603,47 @@ bool CStaticFunctionDefinitions::SetElementCollidableWith ( CClientEntity & Enti } +bool CStaticFunctionDefinitions::SetElementCollidableWith ( CClientEntity & Entity, const char* szTypeName, bool bCanCollide, bool bOnlyCreated ) +{ + switch ( Entity.GetType () ) + { + case CCLIENTPLAYER: + case CCLIENTPED: + case CCLIENTOBJECT: + case CCLIENTVEHICLE: + { + switch ( CClientEntity::GetTypeID ( szTypeName ) ) + { + case CCLIENTPLAYER: + case CCLIENTPED: + case CCLIENTOBJECT: + case CCLIENTVEHICLE: + { + CFastList < CClientEntity* > entities = CClientEntity::GetEntitiesFromRoot ( HashString ( szTypeName ), false ); + + CChildListType::const_iterator iter = entities.begin (); + for ( ; iter != entities.end (); iter++ ) + { + CClientEntity* pEntity = *iter; + Entity.SetCollidableWith ( pEntity, bCanCollide ); + } + + if ( !bOnlyCreated ) + { + + } + + return true; + } + default: break; + } + } + } + + return false; +} + + bool CStaticFunctionDefinitions::SetElementFrozen ( CClientEntity& Entity, bool bFrozen ) { switch ( Entity.GetType () ) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 4756c722e10..433d738c9aa 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -108,6 +108,7 @@ class CStaticFunctionDefinitions static bool SetElementModel ( CClientEntity& Entity, unsigned short usModel ); static bool SetElementCollisionsEnabled ( CClientEntity& Entity, bool bEnabled ); static bool SetElementCollidableWith ( CClientEntity& Entity, CClientEntity& ThisEntity, bool bCanCollide ); + static bool SetElementCollidableWith ( CClientEntity& Entity, const char* szTypeName, bool bCanCollide, bool bOnlyCreated ); static bool SetElementFrozen ( CClientEntity& Entity, bool bFrozen ); static bool SetLowLodElement ( CClientEntity& Entity, CClientEntity* pLowLodEntity ); static bool SetElementCallPropagationEnabled ( CClientEntity& Entity, bool bEnabled ); From adc134c6cf52e17134da1c8647e43a47a3a6f9da Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:01:16 +0100 Subject: [PATCH 05/19] Create setElementCollidableWithType --- .../logic/CStaticFunctionDefinitions.cpp | 38 ++++++++-- .../logic/CStaticFunctionDefinitions.h | 2 +- .../logic/luadefs/CLuaElementDefs.cpp | 72 ++++++++++--------- .../logic/luadefs/CLuaElementDefs.h | 1 + 4 files changed, 74 insertions(+), 39 deletions(-) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index ce0f340401c..387ff179aa6 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3603,7 +3603,7 @@ bool CStaticFunctionDefinitions::SetElementCollidableWith ( CClientEntity & Enti } -bool CStaticFunctionDefinitions::SetElementCollidableWith ( CClientEntity & Entity, const char* szTypeName, bool bCanCollide, bool bOnlyCreated ) +bool CStaticFunctionDefinitions::SetElementCollidableWithType ( CClientEntity & Entity, const char* szTypeName, bool bCanCollide, bool bOnlyWithCreated ) { switch ( Entity.GetType () ) { @@ -3612,13 +3612,16 @@ bool CStaticFunctionDefinitions::SetElementCollidableWith ( CClientEntity & Enti case CCLIENTOBJECT: case CCLIENTVEHICLE: { - switch ( CClientEntity::GetTypeID ( szTypeName ) ) + unsigned int uiType = CClientEntity::GetTypeID ( szTypeName ); + + switch ( uiType ) { case CCLIENTPLAYER: case CCLIENTPED: case CCLIENTOBJECT: case CCLIENTVEHICLE: { + // Change CollidableWith for all elements of this type on the server CFastList < CClientEntity* > entities = CClientEntity::GetEntitiesFromRoot ( HashString ( szTypeName ), false ); CChildListType::const_iterator iter = entities.begin (); @@ -3628,9 +3631,36 @@ bool CStaticFunctionDefinitions::SetElementCollidableWith ( CClientEntity & Enti Entity.SetCollidableWith ( pEntity, bCanCollide ); } - if ( !bOnlyCreated ) + // Save it so new created elements also have to consider CollidableWith + if ( !bOnlyWithCreated ) { - + switch ( uiType ) + { + case CCLIENTPLAYER: + if ( bCanCollide ) + CClientPlayer::m_DisabledCollisions.remove ( &Entity ); + else + CClientPlayer::m_DisabledCollisions.push_back ( &Entity ); + break; + case CCLIENTPED: + if ( bCanCollide ) + CClientPed::m_DisabledCollisions.remove ( &Entity ); + else + CClientPed::m_DisabledCollisions.push_back ( &Entity ); + break; + case CCLIENTOBJECT: + if ( bCanCollide ) + CClientObject::m_DisabledCollisions.remove ( &Entity ); + else + CClientObject::m_DisabledCollisions.push_back ( &Entity ); + break; + case CCLIENTVEHICLE: + if ( bCanCollide ) + CClientVehicle::m_DisabledCollisions.remove ( &Entity ); + else + CClientVehicle::m_DisabledCollisions.push_back ( &Entity ); + break; + } } return true; diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 433d738c9aa..e7becb47e04 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -108,7 +108,7 @@ class CStaticFunctionDefinitions static bool SetElementModel ( CClientEntity& Entity, unsigned short usModel ); static bool SetElementCollisionsEnabled ( CClientEntity& Entity, bool bEnabled ); static bool SetElementCollidableWith ( CClientEntity& Entity, CClientEntity& ThisEntity, bool bCanCollide ); - static bool SetElementCollidableWith ( CClientEntity& Entity, const char* szTypeName, bool bCanCollide, bool bOnlyCreated ); + static bool SetElementCollidableWithType ( CClientEntity& Entity, const char* szTypeName, bool bCanCollide, bool bOnlyWithCreated ); static bool SetElementFrozen ( CClientEntity& Entity, bool bFrozen ); static bool SetLowLodElement ( CClientEntity& Entity, CClientEntity* pLowLodEntity ); static bool SetElementCallPropagationEnabled ( CClientEntity& Entity, bool bEnabled ); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 2aff68878d7..51094cc4778 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -85,6 +85,7 @@ void CLuaElementDefs::LoadFunctions ( void ) CLuaCFunctions::AddFunction ( "setElementStreamable", SetElementStreamable ); CLuaCFunctions::AddFunction ( "setElementCollisionsEnabled", SetElementCollisionsEnabled ); CLuaCFunctions::AddFunction ( "setElementCollidableWith", SetElementCollidableWith ); + CLuaCFunctions::AddFunction ( "setElementCollidableWithType", SetElementCollidableWithType ); CLuaCFunctions::AddFunction ( "setElementDoubleSided", SetElementDoubleSided ); CLuaCFunctions::AddFunction ( "setElementFrozen", SetElementFrozen ); CLuaCFunctions::AddFunction ( "setLowLODElement", SetLowLodElement ); @@ -167,6 +168,7 @@ void CLuaElementDefs::AddClass ( lua_State* luaVM ) lua_classfunction ( luaVM, "setModel", "setElementModel" ); lua_classfunction ( luaVM, "setCollisionsEnabled", "setElementCollisionsEnabled" ); lua_classfunction ( luaVM, "setCollidableWith", "setElementCollidableWith" ); + lua_classfunction ( luaVM, "setCollidableWithType", "setElementCollidableWithType" ); lua_classfunction ( luaVM, "setFrozen", "setElementFrozen" ); lua_classfunction ( luaVM, "setLowLOD", "setLowLODElement" ); lua_classfunction ( luaVM, "setCallPropagationEnabled", "setElementCallPropagationEnabled" ); @@ -2156,55 +2158,57 @@ int CLuaElementDefs::SetElementCollisionsEnabled ( lua_State* luaVM ) int CLuaElementDefs::SetElementCollidableWith ( lua_State* luaVM ) { CClientEntity* pEntity = NULL; + CClientEntity* pWithEntity = NULL; bool bCanCollide = true; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pEntity ); - // bool setElementCollidableWith ( element theElement, element withElement, bool enabled ) - if ( argStream.NextIsUserData() ) - { - CClientEntity* pWithEntity = NULL; - argStream.ReadUserData ( pWithEntity ); - argStream.ReadBool ( bCanCollide ); + argStream.ReadUserData ( pWithEntity ); + argStream.ReadBool ( bCanCollide ); - // Verify the arguments - if ( !argStream.HasErrors () ) + // Verify the arguments + if ( !argStream.HasErrors () ) + { + if ( CStaticFunctionDefinitions::SetElementCollidableWith ( *pEntity, *pWithEntity, bCanCollide ) ) { - if ( CStaticFunctionDefinitions::SetElementCollidableWith ( *pEntity, *pWithEntity, bCanCollide ) ) - { - lua_pushboolean ( luaVM, true ); - return 1; - } + lua_pushboolean ( luaVM, true ); + return 1; } - else - m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } - // bool setElementCollidableWith ( element theElement, string withType, bool enabled ) - else - { - SString strType; - bool bOnlyCreated; - argStream.ReadString ( strType ); - argStream.ReadBool ( bCanCollide ); - argStream.ReadBool ( bOnlyCreated, false ); + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + + lua_pushboolean ( luaVM, false ); + return 1; +} + - // Verify the arguments - if ( !argStream.HasErrors () ) +int CLuaElementDefs::SetElementCollidableWithType ( lua_State* luaVM ) { + // bool SetElementCollidableWithType ( element theElement, string withType, bool enabled, bool onlyWithCreated = false ) + CClientEntity* pEntity = NULL; + SString strType; + bool bCanCollide = true; + bool bOnlyWithCreated = false; + CScriptArgReader argStream ( luaVM ); + argStream.ReadUserData ( pEntity ); + argStream.ReadString ( strType ); + argStream.ReadBool ( bCanCollide ); + argStream.ReadBool ( bOnlyWithCreated, false ); + + // Verify the arguments + if ( !argStream.HasErrors () ) + { + if ( CStaticFunctionDefinitions::SetElementCollidableWithType ( *pEntity, strType.c_str (), bCanCollide, bOnlyWithCreated ) ) { - if ( CStaticFunctionDefinitions::SetElementCollidableWith ( *pEntity, strType.c_str (), bCanCollide, bOnlyCreated ) ) - { - lua_pushboolean ( luaVM, true ); - return 1; - } + lua_pushboolean ( luaVM, true ); + return 1; } - else - m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } - + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; } - int CLuaElementDefs::SetElementDoubleSided ( lua_State* luaVM ) { CClientEntity* pEntity; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h index 9951d75b080..dacee692dc6 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.h @@ -88,6 +88,7 @@ class CLuaElementDefs : public CLuaDefs LUA_DECLARE ( SetElementStreamable ); LUA_DECLARE ( SetElementModel ); LUA_DECLARE ( SetElementCollidableWith ); + LUA_DECLARE ( SetElementCollidableWithType ); LUA_DECLARE ( SetElementDoubleSided ); LUA_DECLARE ( SetElementFrozen ); LUA_DECLARE ( SetLowLodElement ); From 0432dfb045f8e9ef7b6b690a3049c4ab0d33f297 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:04:50 +0100 Subject: [PATCH 06/19] Remove from DisableCollisions lists if entity gets destroyed --- Client/mods/deathmatch/logic/CClientEntity.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Client/mods/deathmatch/logic/CClientEntity.cpp b/Client/mods/deathmatch/logic/CClientEntity.cpp index 1f695624c2c..d113ca8d0ec 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.cpp +++ b/Client/mods/deathmatch/logic/CClientEntity.cpp @@ -173,6 +173,12 @@ CClientEntity::~CClientEntity ( void ) SAFE_RELEASE( m_pChildrenListSnapshot ); g_pCore->GetGraphics ()->GetRenderItemManager ()->RemoveClientEntityRefs ( this ); g_pCore->UpdateDummyProgress(); + + // Remove from m_DisabledCollisions + CClientPlayer::m_DisabledCollisions.remove ( this ); + CClientPed::m_DisabledCollisions.remove ( this ); + CClientObject::m_DisabledCollisions.remove ( this ); + CClientVehicle::m_DisabledCollisions.remove ( this ); } @@ -1648,6 +1654,7 @@ void CClientEntity::SetCollidableWith ( CClientEntity * pEntity, bool bCanCollid } // Set in the other entity as well pEntity->SetCollidableWith ( this, bCanCollide ); + g_pCore->GetConsole ()->Printf ( "Collision toggle: ", bCanCollide ); } From 862fadc0e1882015d1407a33de103523df5e3cb7 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:05:14 +0100 Subject: [PATCH 07/19] Only remove from lists when it's a valid type (for better performance) --- Client/mods/deathmatch/logic/CClientEntity.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientEntity.cpp b/Client/mods/deathmatch/logic/CClientEntity.cpp index d113ca8d0ec..8448107bf00 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.cpp +++ b/Client/mods/deathmatch/logic/CClientEntity.cpp @@ -175,10 +175,19 @@ CClientEntity::~CClientEntity ( void ) g_pCore->UpdateDummyProgress(); // Remove from m_DisabledCollisions - CClientPlayer::m_DisabledCollisions.remove ( this ); - CClientPed::m_DisabledCollisions.remove ( this ); - CClientObject::m_DisabledCollisions.remove ( this ); - CClientVehicle::m_DisabledCollisions.remove ( this ); + switch ( this->GetType () ) + { + case CCLIENTPLAYER: + case CCLIENTPED: + case CCLIENTOBJECT: + case CCLIENTVEHICLE: + CClientPlayer::m_DisabledCollisions.remove ( this ); + CClientPed::m_DisabledCollisions.remove ( this ); + CClientObject::m_DisabledCollisions.remove ( this ); + CClientVehicle::m_DisabledCollisions.remove ( this ); + break; + default: break; + } } @@ -1654,7 +1663,6 @@ void CClientEntity::SetCollidableWith ( CClientEntity * pEntity, bool bCanCollid } // Set in the other entity as well pEntity->SetCollidableWith ( this, bCanCollide ); - g_pCore->GetConsole ()->Printf ( "Collision toggle: ", bCanCollide ); } From f1ad96d69d0af1b08009f11e5a158918c04c4604 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:06:05 +0100 Subject: [PATCH 08/19] Add DisableCollisions list and use it set CollidableWith to false after creation. --- Client/mods/deathmatch/logic/CClientObject.cpp | 14 ++++++++++++++ Client/mods/deathmatch/logic/CClientObject.h | 1 + Client/mods/deathmatch/logic/CClientPed.cpp | 11 +++++++++++ Client/mods/deathmatch/logic/CClientPed.h | 2 ++ Client/mods/deathmatch/logic/CClientPlayer.cpp | 14 ++++++++++++++ Client/mods/deathmatch/logic/CClientPlayer.h | 1 + Client/mods/deathmatch/logic/CClientVehicle.cpp | 11 +++++++++++ Client/mods/deathmatch/logic/CClientVehicle.h | 1 + 8 files changed, 55 insertions(+) diff --git a/Client/mods/deathmatch/logic/CClientObject.cpp b/Client/mods/deathmatch/logic/CClientObject.cpp index 091a512b5c6..51472964758 100644 --- a/Client/mods/deathmatch/logic/CClientObject.cpp +++ b/Client/mods/deathmatch/logic/CClientObject.cpp @@ -21,6 +21,10 @@ #define M_PI 3.14159265358979323846 #endif +using std::list; + +list < CClientEntity* > CClientObject::m_DisabledCollisions; + CClientObject::CClientObject ( CClientManager* pManager, ElementID ID, unsigned short usModel, bool bLowLod ) : ClassInit ( this ) , CClientStreamElement ( bLowLod ? pManager->GetObjectLodStreamer () : pManager->GetObjectStreamer (), ID ) @@ -54,6 +58,16 @@ CClientObject::CClientObject ( CClientManager* pManager, ElementID ID, unsigned if ( m_bIsLowLod ) m_pManager->OnLowLODElementCreated (); + + // Check DisableCollisions // + if ( !m_DisabledCollisions.empty () ) + { + std::list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); + for ( ; iter != m_DisabledCollisions.end (); iter++ ) + { + SetCollidableWith ( *iter, false ); + } + } } diff --git a/Client/mods/deathmatch/logic/CClientObject.h b/Client/mods/deathmatch/logic/CClientObject.h index 922d95c523a..2a37d4038a6 100644 --- a/Client/mods/deathmatch/logic/CClientObject.h +++ b/Client/mods/deathmatch/logic/CClientObject.h @@ -153,6 +153,7 @@ class CClientObject : public CClientStreamElement public: CObject* m_pObject; SLastSyncedObjectData m_LastSyncedData; + static std::list < CClientEntity * > m_DisabledCollisions; }; #endif diff --git a/Client/mods/deathmatch/logic/CClientPed.cpp b/Client/mods/deathmatch/logic/CClientPed.cpp index 3c8836bbae4..ca58152d051 100644 --- a/Client/mods/deathmatch/logic/CClientPed.cpp +++ b/Client/mods/deathmatch/logic/CClientPed.cpp @@ -20,6 +20,7 @@ using std::list; using std::vector; extern CClientGame* g_pClientGame; +list < CClientEntity* > CClientPed::m_DisabledCollisions; #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -242,6 +243,16 @@ void CClientPed::Init ( CClientManager* pManager, unsigned long ulModelID, bool SetArmor ( 0.0f ); } + + // Check DisableCollisions // + if ( !m_DisabledCollisions.empty () ) + { + list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); + for ( ; iter != m_DisabledCollisions.end (); iter++ ) + { + SetCollidableWith ( *iter, false ); + } + } } diff --git a/Client/mods/deathmatch/logic/CClientPed.h b/Client/mods/deathmatch/logic/CClientPed.h index 75bec4283ef..b97970704c2 100644 --- a/Client/mods/deathmatch/logic/CClientPed.h +++ b/Client/mods/deathmatch/logic/CClientPed.h @@ -646,6 +646,8 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule CVector m_vecPrevTargetPosition; uint m_uiForceLocalCounter; + + static std::list < CClientEntity * > m_DisabledCollisions; }; #endif diff --git a/Client/mods/deathmatch/logic/CClientPlayer.cpp b/Client/mods/deathmatch/logic/CClientPlayer.cpp index 23b3b5d2f10..b0020e5952d 100644 --- a/Client/mods/deathmatch/logic/CClientPlayer.cpp +++ b/Client/mods/deathmatch/logic/CClientPlayer.cpp @@ -16,9 +16,13 @@ *****************************************************************************/ #include + +using std::list; + int g_iDamageEventLimit = -1; extern float g_fApplyDamageLastAmount; extern CClientPed* g_pApplyDamageLastDamagedPed; +list < CClientEntity* > CClientPlayer::m_DisabledCollisions; CClientPlayer::CClientPlayer ( CClientManager* pManager, ElementID ID, bool bIsLocalPlayer ) : ClassInit ( this ), CClientPed ( pManager, 0, ID, bIsLocalPlayer ) { @@ -88,6 +92,16 @@ CClientPlayer::CClientPlayer ( CClientManager* pManager, ElementID ID, bool bIsL // Add us to the player list m_pManager->GetPlayerManager ()->AddToList ( this ); + // Check DisableCollisions // + if ( !m_DisabledCollisions.empty () ) + { + std::list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); + for ( ; iter != m_DisabledCollisions.end (); iter++ ) + { + SetCollidableWith ( *iter, false ); + } + } + #ifdef MTA_DEBUG m_bShowingWepdata = false; #endif diff --git a/Client/mods/deathmatch/logic/CClientPlayer.h b/Client/mods/deathmatch/logic/CClientPlayer.h index baea56691e2..cf8205e2f48 100644 --- a/Client/mods/deathmatch/logic/CClientPlayer.h +++ b/Client/mods/deathmatch/logic/CClientPlayer.h @@ -120,6 +120,7 @@ class CClientPlayer : public CClientPed CVector m_vecPrevBulletSyncStart; CVector m_vecPrevBulletSyncEnd; uchar m_ucPrevBulletSyncOrderCounter; + static std::list < CClientEntity * > m_DisabledCollisions; private: bool m_bIsLocalPlayer; SString m_strNick; diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 07feaef35fb..7cdbcaf8514 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -25,6 +25,7 @@ using std::list; extern CClientGame* g_pClientGame; std::set < const CClientEntity* > ms_AttachedVehiclesToIgnore; +std::list < CClientEntity* > CClientVehicle::m_DisabledCollisions; // To hide the ugly "pointer truncation from DWORD* to unsigned long warning #pragma warning(disable:4311) @@ -179,6 +180,16 @@ CClientVehicle::CClientVehicle ( CClientManager* pManager, ElementID ID, unsigne // We've not yet been streamed in m_bJustStreamedIn = false; + + // Check DisableCollisions // + if ( !m_DisabledCollisions.empty () ) + { + list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); + for ( ; iter != m_DisabledCollisions.end (); iter++ ) + { + SetCollidableWith ( *iter, false ); + } + } } diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index 5dd98790618..5de17ea5649 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -686,6 +686,7 @@ class CClientVehicle : public CClientStreamElement SSirenInfo m_tSirenBeaconInfo; std::map m_ComponentData; bool m_bAsyncLoadingDisabled; + static std::list < CClientEntity * > m_DisabledCollisions; }; From eff16bca18936060f5c48df92d97b98b09d10d55 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:08:02 +0100 Subject: [PATCH 09/19] Remove useless line --- Client/mods/deathmatch/logic/CClientEntity.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientEntity.h b/Client/mods/deathmatch/logic/CClientEntity.h index b53c3d03911..4fded85c601 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.h +++ b/Client/mods/deathmatch/logic/CClientEntity.h @@ -379,7 +379,6 @@ class CClientEntity : public CClientEntityBase static void AddEntityFromRoot ( unsigned int uiTypeHash, CClientEntity* pEntity, bool bDebugCheck = true ); static void RemoveEntityFromRoot ( unsigned int uiTypeHash, CClientEntity* pEntity ); static void GetEntitiesFromRoot ( unsigned int uiTypeHash, lua_State* luaVM, bool bStreamedIn ); - #if CHECK_ENTITIES_FROM_ROOT static void _CheckEntitiesFromRoot ( unsigned int uiTypeHash ); From 98a8b2ba4d0c7acb71b79ea3affd852b0fbbd8c0 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:22:40 +0100 Subject: [PATCH 10/19] Remove std:: when already used "using" --- Client/mods/deathmatch/logic/CClientPlayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientPlayer.cpp b/Client/mods/deathmatch/logic/CClientPlayer.cpp index b0020e5952d..56b4569ff8e 100644 --- a/Client/mods/deathmatch/logic/CClientPlayer.cpp +++ b/Client/mods/deathmatch/logic/CClientPlayer.cpp @@ -95,7 +95,7 @@ CClientPlayer::CClientPlayer ( CClientManager* pManager, ElementID ID, bool bIsL // Check DisableCollisions // if ( !m_DisabledCollisions.empty () ) { - std::list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); + list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); for ( ; iter != m_DisabledCollisions.end (); iter++ ) { SetCollidableWith ( *iter, false ); From 688fd7a0e8354654809afbe308971471f2b5130d Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:26:26 +0100 Subject: [PATCH 11/19] Use ranged-for instead of iterator --- Client/mods/deathmatch/logic/CClientObject.cpp | 8 ++------ Client/mods/deathmatch/logic/CClientPed.cpp | 8 ++------ Client/mods/deathmatch/logic/CClientPlayer.cpp | 8 ++------ Client/mods/deathmatch/logic/CClientVehicle.cpp | 8 ++------ 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientObject.cpp b/Client/mods/deathmatch/logic/CClientObject.cpp index 51472964758..6e020bd5a09 100644 --- a/Client/mods/deathmatch/logic/CClientObject.cpp +++ b/Client/mods/deathmatch/logic/CClientObject.cpp @@ -60,13 +60,9 @@ CClientObject::CClientObject ( CClientManager* pManager, ElementID ID, unsigned m_pManager->OnLowLODElementCreated (); // Check DisableCollisions // - if ( !m_DisabledCollisions.empty () ) + for ( CClientEntity * entity : m_DisabledCollisions ) { - std::list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); - for ( ; iter != m_DisabledCollisions.end (); iter++ ) - { - SetCollidableWith ( *iter, false ); - } + SetCollidableWith ( entity, false ); } } diff --git a/Client/mods/deathmatch/logic/CClientPed.cpp b/Client/mods/deathmatch/logic/CClientPed.cpp index ca58152d051..102be91da7f 100644 --- a/Client/mods/deathmatch/logic/CClientPed.cpp +++ b/Client/mods/deathmatch/logic/CClientPed.cpp @@ -245,13 +245,9 @@ void CClientPed::Init ( CClientManager* pManager, unsigned long ulModelID, bool } // Check DisableCollisions // - if ( !m_DisabledCollisions.empty () ) + for ( CClientEntity * entity : m_DisabledCollisions ) { - list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); - for ( ; iter != m_DisabledCollisions.end (); iter++ ) - { - SetCollidableWith ( *iter, false ); - } + SetCollidableWith ( entity, false ); } } diff --git a/Client/mods/deathmatch/logic/CClientPlayer.cpp b/Client/mods/deathmatch/logic/CClientPlayer.cpp index 56b4569ff8e..599e9af2933 100644 --- a/Client/mods/deathmatch/logic/CClientPlayer.cpp +++ b/Client/mods/deathmatch/logic/CClientPlayer.cpp @@ -93,13 +93,9 @@ CClientPlayer::CClientPlayer ( CClientManager* pManager, ElementID ID, bool bIsL m_pManager->GetPlayerManager ()->AddToList ( this ); // Check DisableCollisions // - if ( !m_DisabledCollisions.empty () ) + for ( CClientEntity * entity : m_DisabledCollisions ) { - list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); - for ( ; iter != m_DisabledCollisions.end (); iter++ ) - { - SetCollidableWith ( *iter, false ); - } + SetCollidableWith ( entity, false ); } #ifdef MTA_DEBUG diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 7cdbcaf8514..808e0ea72d1 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -182,13 +182,9 @@ CClientVehicle::CClientVehicle ( CClientManager* pManager, ElementID ID, unsigne m_bJustStreamedIn = false; // Check DisableCollisions // - if ( !m_DisabledCollisions.empty () ) + for ( CClientEntity * entity : m_DisabledCollisions ) { - list < CClientEntity * > ::iterator iter = m_DisabledCollisions.begin (); - for ( ; iter != m_DisabledCollisions.end (); iter++ ) - { - SetCollidableWith ( *iter, false ); - } + SetCollidableWith ( entity, false ); } } From 2c395a27e34e5a4736369d320c1fe61634b565a5 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:28:01 +0100 Subject: [PATCH 12/19] Remove the useless usings, use std::list for the one line. --- Client/mods/deathmatch/logic/CClientObject.cpp | 4 +--- Client/mods/deathmatch/logic/CClientPed.cpp | 3 +-- Client/mods/deathmatch/logic/CClientPlayer.cpp | 4 +--- Client/mods/deathmatch/logic/CClientVehicle.cpp | 2 -- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientObject.cpp b/Client/mods/deathmatch/logic/CClientObject.cpp index 6e020bd5a09..f0e4e3255d5 100644 --- a/Client/mods/deathmatch/logic/CClientObject.cpp +++ b/Client/mods/deathmatch/logic/CClientObject.cpp @@ -21,9 +21,7 @@ #define M_PI 3.14159265358979323846 #endif -using std::list; - -list < CClientEntity* > CClientObject::m_DisabledCollisions; +std::list < CClientEntity* > CClientObject::m_DisabledCollisions; CClientObject::CClientObject ( CClientManager* pManager, ElementID ID, unsigned short usModel, bool bLowLod ) : ClassInit ( this ) diff --git a/Client/mods/deathmatch/logic/CClientPed.cpp b/Client/mods/deathmatch/logic/CClientPed.cpp index 102be91da7f..8b0c04b0a72 100644 --- a/Client/mods/deathmatch/logic/CClientPed.cpp +++ b/Client/mods/deathmatch/logic/CClientPed.cpp @@ -16,11 +16,10 @@ #include "StdInc.h" -using std::list; using std::vector; extern CClientGame* g_pClientGame; -list < CClientEntity* > CClientPed::m_DisabledCollisions; +std::list < CClientEntity* > CClientPed::m_DisabledCollisions; #ifndef M_PI #define M_PI 3.14159265358979323846 diff --git a/Client/mods/deathmatch/logic/CClientPlayer.cpp b/Client/mods/deathmatch/logic/CClientPlayer.cpp index 599e9af2933..bf524393233 100644 --- a/Client/mods/deathmatch/logic/CClientPlayer.cpp +++ b/Client/mods/deathmatch/logic/CClientPlayer.cpp @@ -17,12 +17,10 @@ #include -using std::list; - int g_iDamageEventLimit = -1; extern float g_fApplyDamageLastAmount; extern CClientPed* g_pApplyDamageLastDamagedPed; -list < CClientEntity* > CClientPlayer::m_DisabledCollisions; +std::list < CClientEntity* > CClientPlayer::m_DisabledCollisions; CClientPlayer::CClientPlayer ( CClientManager* pManager, ElementID ID, bool bIsLocalPlayer ) : ClassInit ( this ), CClientPed ( pManager, 0, ID, bIsLocalPlayer ) { diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 808e0ea72d1..fe98ea6c8c0 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -21,8 +21,6 @@ #include "StdInc.h" -using std::list; - extern CClientGame* g_pClientGame; std::set < const CClientEntity* > ms_AttachedVehiclesToIgnore; std::list < CClientEntity* > CClientVehicle::m_DisabledCollisions; From e09465ee6481862e60689470a17e0392749cc62b Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:29:03 +0100 Subject: [PATCH 13/19] Improve comments --- Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 51094cc4778..9de1215d5de 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -2183,7 +2183,7 @@ int CLuaElementDefs::SetElementCollidableWith ( lua_State* luaVM ) int CLuaElementDefs::SetElementCollidableWithType ( lua_State* luaVM ) { - // bool SetElementCollidableWithType ( element theElement, string withType, bool enabled, bool onlyWithCreated = false ) + // bool SetElementCollidableWithType ( element theElement, string withType, bool enabled[, bool onlyWithCreated = false] ) CClientEntity* pEntity = NULL; SString strType; bool bCanCollide = true; @@ -2194,7 +2194,6 @@ int CLuaElementDefs::SetElementCollidableWithType ( lua_State* luaVM ) { argStream.ReadBool ( bCanCollide ); argStream.ReadBool ( bOnlyWithCreated, false ); - // Verify the arguments if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetElementCollidableWithType ( *pEntity, strType.c_str (), bCanCollide, bOnlyWithCreated ) ) From 4b7f3030f9e8b0ca0651325d07d2801cd1ab5016 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:29:37 +0100 Subject: [PATCH 14/19] Start function syntax with lower-case --- Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 9de1215d5de..8f830925a70 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -2183,7 +2183,7 @@ int CLuaElementDefs::SetElementCollidableWith ( lua_State* luaVM ) int CLuaElementDefs::SetElementCollidableWithType ( lua_State* luaVM ) { - // bool SetElementCollidableWithType ( element theElement, string withType, bool enabled[, bool onlyWithCreated = false] ) + // bool setElementCollidableWithType ( element theElement, string withType, bool enabled[, bool onlyWithCreated = false] ) CClientEntity* pEntity = NULL; SString strType; bool bCanCollide = true; From 742b70f0d542015db7c16ac7dd24e8866f0372c9 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:31:08 +0100 Subject: [PATCH 15/19] Use nullptr instead of NULL --- Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 8f830925a70..6be7ef3cc84 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -2184,7 +2184,7 @@ int CLuaElementDefs::SetElementCollidableWith ( lua_State* luaVM ) int CLuaElementDefs::SetElementCollidableWithType ( lua_State* luaVM ) { // bool setElementCollidableWithType ( element theElement, string withType, bool enabled[, bool onlyWithCreated = false] ) - CClientEntity* pEntity = NULL; + CClientEntity* pEntity = nullptr; SString strType; bool bCanCollide = true; bool bOnlyWithCreated = false; From cc491df421f4b5f6160ad354f08b674e8b28b093 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:39:20 +0100 Subject: [PATCH 16/19] Get rid of nested code block. --- .../logic/CStaticFunctionDefinitions.cpp | 105 +++++++++--------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 387ff179aa6..032452ae338 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3611,66 +3611,65 @@ bool CStaticFunctionDefinitions::SetElementCollidableWithType ( CClientEntity & case CCLIENTPED: case CCLIENTOBJECT: case CCLIENTVEHICLE: - { - unsigned int uiType = CClientEntity::GetTypeID ( szTypeName ); + break; + default: return; + } - switch ( uiType ) - { - case CCLIENTPLAYER: - case CCLIENTPED: - case CCLIENTOBJECT: - case CCLIENTVEHICLE: - { - // Change CollidableWith for all elements of this type on the server - CFastList < CClientEntity* > entities = CClientEntity::GetEntitiesFromRoot ( HashString ( szTypeName ), false ); + unsigned int uiType = CClientEntity::GetTypeID ( szTypeName ); - CChildListType::const_iterator iter = entities.begin (); - for ( ; iter != entities.end (); iter++ ) - { - CClientEntity* pEntity = *iter; - Entity.SetCollidableWith ( pEntity, bCanCollide ); - } + switch ( uiType ) + { + case CCLIENTPLAYER: + case CCLIENTPED: + case CCLIENTOBJECT: + case CCLIENTVEHICLE: + break; + default: return; + } - // Save it so new created elements also have to consider CollidableWith - if ( !bOnlyWithCreated ) - { - switch ( uiType ) - { - case CCLIENTPLAYER: - if ( bCanCollide ) - CClientPlayer::m_DisabledCollisions.remove ( &Entity ); - else - CClientPlayer::m_DisabledCollisions.push_back ( &Entity ); - break; - case CCLIENTPED: - if ( bCanCollide ) - CClientPed::m_DisabledCollisions.remove ( &Entity ); - else - CClientPed::m_DisabledCollisions.push_back ( &Entity ); - break; - case CCLIENTOBJECT: - if ( bCanCollide ) - CClientObject::m_DisabledCollisions.remove ( &Entity ); - else - CClientObject::m_DisabledCollisions.push_back ( &Entity ); - break; - case CCLIENTVEHICLE: - if ( bCanCollide ) - CClientVehicle::m_DisabledCollisions.remove ( &Entity ); - else - CClientVehicle::m_DisabledCollisions.push_back ( &Entity ); - break; - } - } + // Change CollidableWith for all elements of this type on the server + CFastList < CClientEntity* > entities = CClientEntity::GetEntitiesFromRoot ( HashString ( szTypeName ), false ); - return true; - } - default: break; - } + CChildListType::const_iterator iter = entities.begin (); + for ( ; iter != entities.end (); iter++ ) + { + CClientEntity* pEntity = *iter; + Entity.SetCollidableWith ( pEntity, bCanCollide ); + } + + // Save it so new created elements also have to consider CollidableWith + if ( !bOnlyWithCreated ) + { + switch ( uiType ) + { + case CCLIENTPLAYER: + if ( bCanCollide ) + CClientPlayer::m_DisabledCollisions.remove ( &Entity ); + else + CClientPlayer::m_DisabledCollisions.push_back ( &Entity ); + break; + case CCLIENTPED: + if ( bCanCollide ) + CClientPed::m_DisabledCollisions.remove ( &Entity ); + else + CClientPed::m_DisabledCollisions.push_back ( &Entity ); + break; + case CCLIENTOBJECT: + if ( bCanCollide ) + CClientObject::m_DisabledCollisions.remove ( &Entity ); + else + CClientObject::m_DisabledCollisions.push_back ( &Entity ); + break; + case CCLIENTVEHICLE: + if ( bCanCollide ) + CClientVehicle::m_DisabledCollisions.remove ( &Entity ); + else + CClientVehicle::m_DisabledCollisions.push_back ( &Entity ); + break; } } - return false; + return true; } From cd27b500b9cd580832a4c78d7aed2d0cc21fa091 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Fri, 1 Dec 2017 21:39:59 +0100 Subject: [PATCH 17/19] Return false --- Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 032452ae338..0bd3c911f65 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3612,7 +3612,7 @@ bool CStaticFunctionDefinitions::SetElementCollidableWithType ( CClientEntity & case CCLIENTOBJECT: case CCLIENTVEHICLE: break; - default: return; + default: return false; } unsigned int uiType = CClientEntity::GetTypeID ( szTypeName ); @@ -3624,7 +3624,7 @@ bool CStaticFunctionDefinitions::SetElementCollidableWithType ( CClientEntity & case CCLIENTOBJECT: case CCLIENTVEHICLE: break; - default: return; + default: return false; } // Change CollidableWith for all elements of this type on the server From bbcc8a8179eb0fbea9a3701116e4e226bea8f086 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Sat, 2 Dec 2017 00:06:13 +0100 Subject: [PATCH 18/19] Add using std::list again where it is actually used ... --- Client/mods/deathmatch/logic/CClientPed.cpp | 3 ++- Client/mods/deathmatch/logic/CClientVehicle.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientPed.cpp b/Client/mods/deathmatch/logic/CClientPed.cpp index 8b0c04b0a72..4b4ea895600 100644 --- a/Client/mods/deathmatch/logic/CClientPed.cpp +++ b/Client/mods/deathmatch/logic/CClientPed.cpp @@ -17,9 +17,10 @@ #include "StdInc.h" using std::vector; +using std::list; extern CClientGame* g_pClientGame; -std::list < CClientEntity* > CClientPed::m_DisabledCollisions; +list < CClientEntity* > CClientPed::m_DisabledCollisions; #ifndef M_PI #define M_PI 3.14159265358979323846 diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index fe98ea6c8c0..228c35889c5 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -21,9 +21,11 @@ #include "StdInc.h" +using std::list; + extern CClientGame* g_pClientGame; std::set < const CClientEntity* > ms_AttachedVehiclesToIgnore; -std::list < CClientEntity* > CClientVehicle::m_DisabledCollisions; +list < CClientEntity* > CClientVehicle::m_DisabledCollisions; // To hide the ugly "pointer truncation from DWORD* to unsigned long warning #pragma warning(disable:4311) From 281236d37a27b093a050e35203f5ab960685aff5 Mon Sep 17 00:00:00 2001 From: Emre Kara Date: Sat, 2 Dec 2017 01:20:45 +0100 Subject: [PATCH 19/19] Remove GetType() in destructor (else LNK2019 error) --- Client/mods/deathmatch/logic/CClientEntity.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientEntity.cpp b/Client/mods/deathmatch/logic/CClientEntity.cpp index 8448107bf00..524d7520e61 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.cpp +++ b/Client/mods/deathmatch/logic/CClientEntity.cpp @@ -175,19 +175,10 @@ CClientEntity::~CClientEntity ( void ) g_pCore->UpdateDummyProgress(); // Remove from m_DisabledCollisions - switch ( this->GetType () ) - { - case CCLIENTPLAYER: - case CCLIENTPED: - case CCLIENTOBJECT: - case CCLIENTVEHICLE: - CClientPlayer::m_DisabledCollisions.remove ( this ); - CClientPed::m_DisabledCollisions.remove ( this ); - CClientObject::m_DisabledCollisions.remove ( this ); - CClientVehicle::m_DisabledCollisions.remove ( this ); - break; - default: break; - } + CClientPlayer::m_DisabledCollisions.remove ( this ); + CClientPed::m_DisabledCollisions.remove ( this ); + CClientObject::m_DisabledCollisions.remove ( this ); + CClientVehicle::m_DisabledCollisions.remove ( this ); }