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
38 changes: 23 additions & 15 deletions Client/mods/deathmatch/logic/CClientEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -1015,18 +1015,22 @@ void CClientEntity::FindAllChildrenByTypeIndex(unsigned int uiTypeHash, lua_Stat
// Only streamed in elements?
if (!bStreamedIn || !IsStreamingCompatibleClass() || reinterpret_cast<CClientStreamElement*>(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);
}
}
}

// Call us on the children
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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -1456,12 +1460,16 @@ void CClientEntity::GetEntitiesFromRoot(unsigned int uiTypeHash, lua_State* luaV
// Only streamed in elements?
if (!bStreamedIn || !pEntity->IsStreamingCompatibleClass() || reinterpret_cast<CClientStreamElement*>(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);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Client/mods/deathmatch/logic/CClientEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(m_Children.size()); };

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -822,17 +823,21 @@ int CLuaElementDefs::GetElementsByType(lua_State* luaVM)
lua_pushboolean(luaVM, false);
return 1;
}

if (argStream.NextIsBool())
{
argStream.ReadBool(bStreamedIn);

if (argStream.NextIsBool())
argStream.ReadBool(bOnScreenOnly);
}
}

// Create a new table
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;
}
}
Expand Down
Loading