diff --git a/Client/mods/deathmatch/logic/CClientEntity.cpp b/Client/mods/deathmatch/logic/CClientEntity.cpp index 1ae3455b25..f8a664feb7 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.cpp +++ b/Client/mods/deathmatch/logic/CClientEntity.cpp @@ -982,7 +982,7 @@ CClientEntity* CClientEntity::FindChildByTypeIndex(unsigned int uiTypeHash, unsi return NULL; } -void CClientEntity::FindAllChildrenByType(const char* szType, lua_State* luaVM, bool bStreamedIn) +void CClientEntity::FindAllChildrenByType(const char* szType, lua_State* luaVM, bool bStreamedIn, bool bOnScreenOnly) { assert(szType); assert(luaVM); @@ -993,15 +993,15 @@ void CClientEntity::FindAllChildrenByType(const char* szType, lua_State* luaVM, if (this == g_pClientGame->GetRootEntity()) { - GetEntitiesFromRoot(uiTypeHash, luaVM, bStreamedIn); + GetEntitiesFromRoot(uiTypeHash, luaVM, bStreamedIn, bOnScreenOnly); } else { - FindAllChildrenByTypeIndex(uiTypeHash, luaVM, uiIndex, bStreamedIn); + FindAllChildrenByTypeIndex(uiTypeHash, luaVM, uiIndex, bStreamedIn, bOnScreenOnly); } } -void CClientEntity::FindAllChildrenByTypeIndex(unsigned int uiTypeHash, lua_State* luaVM, unsigned int& uiIndex, bool bStreamedIn) +void CClientEntity::FindAllChildrenByTypeIndex(unsigned int uiTypeHash, lua_State* luaVM, unsigned int& uiIndex, bool bStreamedIn, bool bOnScreenOnly) { assert(luaVM); @@ -1015,10 +1015,14 @@ void CClientEntity::FindAllChildrenByTypeIndex(unsigned int uiTypeHash, lua_Stat // Only streamed in elements? if (!bStreamedIn || !IsStreamingCompatibleClass() || reinterpret_cast(this)->IsStreamedIn()) { - // Add it to the table - lua_pushnumber(luaVM, ++uiIndex); - lua_pushelement(luaVM, this); - lua_settable(luaVM, -3); + bool bVisibleOnScreen = false; + if (!bOnScreenOnly || (CStaticFunctionDefinitions::IsElementOnScreen(*this, bVisibleOnScreen) && bVisibleOnScreen)) + { + // Add it to the table + lua_pushnumber(luaVM, ++uiIndex); + lua_pushelement(luaVM, this); + lua_settable(luaVM, -3); + } } } @@ -1026,7 +1030,7 @@ void CClientEntity::FindAllChildrenByTypeIndex(unsigned int uiTypeHash, lua_Stat CChildListType ::const_iterator iter = m_Children.begin(); for (; iter != m_Children.end(); iter++) { - (*iter)->FindAllChildrenByTypeIndex(uiTypeHash, luaVM, uiIndex, bStreamedIn); + (*iter)->FindAllChildrenByTypeIndex(uiTypeHash, luaVM, uiIndex, bStreamedIn, bOnScreenOnly); } } @@ -1436,7 +1440,7 @@ void CClientEntity::RemoveEntityFromRoot(unsigned int uiTypeHash, CClientEntity* CClientEntity::RemoveEntityFromRoot((*iter)->GetTypeHash(), *iter); } -void CClientEntity::GetEntitiesFromRoot(unsigned int uiTypeHash, lua_State* luaVM, bool bStreamedIn) +void CClientEntity::GetEntitiesFromRoot(unsigned int uiTypeHash, lua_State* luaVM, bool bStreamedIn, bool bOnScreenOnly) { #if CHECK_ENTITIES_FROM_ROOT _CheckEntitiesFromRoot(uiTypeHash); @@ -1456,12 +1460,16 @@ void CClientEntity::GetEntitiesFromRoot(unsigned int uiTypeHash, lua_State* luaV // Only streamed in elements? if (!bStreamedIn || !pEntity->IsStreamingCompatibleClass() || reinterpret_cast(pEntity)->IsStreamedIn()) { - if (!pEntity->IsBeingDeleted()) + bool bVisibleOnScreen = false; + if (!bOnScreenOnly || (CStaticFunctionDefinitions::IsElementOnScreen(*pEntity, bVisibleOnScreen) && bVisibleOnScreen)) { - // Add it to the table - lua_pushnumber(luaVM, ++uiIndex); - lua_pushelement(luaVM, pEntity); - lua_settable(luaVM, -3); + if (!pEntity->IsBeingDeleted()) + { + // Add it to the table + lua_pushnumber(luaVM, ++uiIndex); + lua_pushelement(luaVM, pEntity); + lua_settable(luaVM, -3); + } } } } diff --git a/Client/mods/deathmatch/logic/CClientEntity.h b/Client/mods/deathmatch/logic/CClientEntity.h index ad2c6aa68e..504abf6520 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.h +++ b/Client/mods/deathmatch/logic/CClientEntity.h @@ -262,8 +262,8 @@ class CClientEntity : public CClientEntityBase CClientEntity* FindChildIndex(const char* szType, unsigned int uiIndex, unsigned int& uiCurrentIndex, bool bRecursive); CClientEntity* FindChildByType(const char* szType, unsigned int uiIndex, bool bRecursive); CClientEntity* FindChildByTypeIndex(unsigned int uiTypeHash, unsigned int uiIndex, unsigned int& uiCurrentIndex, bool bRecursive); - void FindAllChildrenByType(const char* szType, struct lua_State* luaVM, bool bStreamedIn = false); - void FindAllChildrenByTypeIndex(unsigned int uiTypeHash, lua_State* luaVM, unsigned int& uiIndex, bool bStreamedIn = false); + void FindAllChildrenByType(const char* szType, struct lua_State* luaVM, bool bStreamedIn = false, bool bOnScreenOnly = false); + void FindAllChildrenByTypeIndex(unsigned int uiTypeHash, lua_State* luaVM, unsigned int& uiIndex, bool bStreamedIn = false, bool bOnScreenOnly = false); unsigned int CountChildren() { return static_cast(m_Children.size()); }; @@ -388,7 +388,7 @@ class CClientEntity : public CClientEntityBase 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); + static void GetEntitiesFromRoot(unsigned int uiTypeHash, lua_State* luaVM, bool bStreamedIn, bool bOnScreenOnly); #if CHECK_ENTITIES_FROM_ROOT static void _CheckEntitiesFromRoot(unsigned int uiTypeHash); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 2fe3401fc7..078888217d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -809,6 +809,7 @@ int CLuaElementDefs::GetElementsByType(lua_State* luaVM) CClientEntity* pStartAt = m_pRootEntity; CClientEntity* pEntity = NULL; bool bStreamedIn = false; + bool bOnScreenOnly = false; if (argStream.NextIsUserData()) { @@ -822,9 +823,13 @@ int CLuaElementDefs::GetElementsByType(lua_State* luaVM) lua_pushboolean(luaVM, false); return 1; } + if (argStream.NextIsBool()) { argStream.ReadBool(bStreamedIn); + + if (argStream.NextIsBool()) + argStream.ReadBool(bOnScreenOnly); } } @@ -832,7 +837,7 @@ int CLuaElementDefs::GetElementsByType(lua_State* luaVM) lua_newtable(luaVM); // Add all the elements with a matching type to it - pStartAt->FindAllChildrenByType(strType.c_str(), luaVM, bStreamedIn); + pStartAt->FindAllChildrenByType(strType.c_str(), luaVM, bStreamedIn, bOnScreenOnly); return 1; } }