Skip to content

Commit

Permalink
AddEntityToPVS works :D, start cleaning up and fix the others
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Jul 14, 2024
1 parent b310b93 commit 85f0d01
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 50 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,20 @@ We don't validate if the passed cluster id is valid!
#### bool pvs.CheckBoxInPVS(Vector mins, Vector maxs)
Returns whether or not the given box is inside the PVS.

#### pvs.AddEntityToPVS(number entIndex)
#### pvs.AddEntityToPVS(Entity ent)
Adds the given entity index to the PVS

#### pvs.OverrideStateFlag(number entIndex, number flags)
#### pvs.OverrideStateFlags(Entity ent, number flags, bool force)
bool force - Allows you to set the flags directly. It won't make sure that the value is correct!
Overrides the StateFlag for this Snapshot.
The value will be reset in the next one.

#### pvs.SetStateFlag(number entIndex, number flags)
#### pvs.SetStateFlags(Entity ent, number flags, bool force)
bool force - Allows you to set the flags directly. It won't make sure that the value is correct!
Sets the State flag for this entity.
Unlike `OverrideStateFlag`, this won't be reset after the snapshot.

#### number pvs.GetStateFlag(Entity ent)
#### number pvs.GetStateFlags(Entity ent)
Returns the state flags for this entity.

### Enums
Expand Down
122 changes: 76 additions & 46 deletions source/modules/pvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ static void hook_CServerGameEnts_CheckTransmit(void* gameents, CCheckTransmitInf
{
for (edict_t* ent : g_pAddEntityToPVS)
{
Msg("Adding ent(%i) to snapshot\n", ent->m_EdictIndex);
//pInfo->m_pTransmitEdict->Set(ent->m_EdictIndex);
//if(pInfo->m_pTransmitAlways)
// pInfo->m_pTransmitAlways->Set(ent->m_EdictIndex);
servergameents->EdictToBaseEntity(ent)->SetTransmit(pInfo, true);
}

Expand Down Expand Up @@ -196,82 +192,116 @@ LUA_FUNCTION_STATIC(pvs_AddEntityToPVS)
return 0;
}

LUA_FUNCTION_STATIC(pvs_OverrideStateFlag)
#define LUA_FL_EDICT_DONTSEND 1 << 1
#define LUA_FL_EDICT_ALWAYS 1 << 2
#define LUA_FL_EDICT_PVSCHECK 1 << 3
#define LUA_FL_EDICT_FULLCHECK 1 << 4
LUA_FUNCTION_STATIC(pvs_OverrideStateFlags)
{
CBaseEntity* ent = Get_Entity(1);
if (!ent)
LUA->ThrowError("Tried to use a NULL Entity!");

int flag = LUA->CheckNumber(2);

edict_t* edict = GetEdictOfEnt(ent);
if (edict)
g_pOverrideStateFlag[GetEdictOfEnt(ent)] = flag;
else
if (!edict)
LUA->ThrowError("Failed to get edict?");

int flags = LUA->CheckNumber(2);
bool force = LUA->GetBool(3);
int newFlags = flags;
if (!force)
{
newFlags = edict->m_fStateFlags;
newFlags = newFlags & ~FL_EDICT_DONTSEND;
newFlags = newFlags & ~FL_EDICT_ALWAYS;
newFlags = newFlags & ~FL_EDICT_PVSCHECK;
newFlags = newFlags & ~FL_EDICT_FULLCHECK;

if (flags & LUA_FL_EDICT_DONTSEND)
newFlags |= FL_EDICT_DONTSEND;

if (flags & LUA_FL_EDICT_ALWAYS)
newFlags |= FL_EDICT_ALWAYS;

if (flags & LUA_FL_EDICT_PVSCHECK)
newFlags |= FL_EDICT_PVSCHECK;

if (flags & LUA_FL_EDICT_FULLCHECK)
newFlags |= FL_EDICT_FULLCHECK;
}

g_pOverrideStateFlag[edict] = newFlags;

return 0;
}

#define LUA_FL_EDICT_DONTSEND 1 << 1
#define LUA_FL_EDICT_ALWAYS 1 << 2
#define LUA_FL_EDICT_PVSCHECK 1 << 3
#define LUA_FL_EDICT_FULLCHECK 1 << 4
LUA_FUNCTION_STATIC(pvs_SetStateFlag)
LUA_FUNCTION_STATIC(pvs_SetStateFlags)
{
CBaseEntity* ent = Get_Entity(1);
if (!ent)
LUA->ThrowError("Tried to use a NULL Entity!");

edict_t* edict = GetEdictOfEnt(ent);
if (!edict)
LUA->ThrowError("Failed to get edict?");

int flags = LUA->CheckNumber(2);
bool force = LUA->GetBool(3);
int newFlags = flags;
if (!force)
{
newFlags = edict->m_fStateFlags;
newFlags = newFlags & ~FL_EDICT_DONTSEND;
newFlags = newFlags & ~FL_EDICT_ALWAYS;
newFlags = newFlags & ~FL_EDICT_PVSCHECK;
newFlags = newFlags & ~FL_EDICT_FULLCHECK;

int newFlags = 0;
if (flags & LUA_FL_EDICT_DONTSEND)
newFlags |= FL_EDICT_DONTSEND;
if (flags & LUA_FL_EDICT_DONTSEND)
newFlags |= FL_EDICT_DONTSEND;

if (flags & LUA_FL_EDICT_ALWAYS)
newFlags |= FL_EDICT_ALWAYS;
if (flags & LUA_FL_EDICT_ALWAYS)
newFlags |= FL_EDICT_ALWAYS;

if (flags & LUA_FL_EDICT_PVSCHECK)
newFlags |= FL_EDICT_PVSCHECK;
if (flags & LUA_FL_EDICT_PVSCHECK)
newFlags |= FL_EDICT_PVSCHECK;

if (flags & LUA_FL_EDICT_FULLCHECK)
newFlags |= FL_EDICT_FULLCHECK;
if (flags & LUA_FL_EDICT_FULLCHECK)
newFlags |= FL_EDICT_FULLCHECK;
}

edict_t* edict = GetEdictOfEnt(ent);
if (edict)
edict->m_fStateFlags = newFlags;
else
LUA->ThrowError("Failed to get edict?");
edict->m_fStateFlags = newFlags;

return 0;
}

LUA_FUNCTION_STATIC(pvs_GetStateFlag)
LUA_FUNCTION_STATIC(pvs_GetStateFlags)
{
CBaseEntity* ent = Get_Entity(1);
if (!ent)
LUA->ThrowError("Tried to use a NULL Entity!");

int flags = 0;
edict_t* edict = GetEdictOfEnt(ent);
if (edict)
flags = edict->m_fStateFlags;
else
if (!edict)
LUA->ThrowError("Failed to get edict?");

int newFlags = 0;
if (flags & FL_EDICT_DONTSEND)
newFlags |= LUA_FL_EDICT_DONTSEND;
int flags = edict->m_fStateFlags;
int newFlags = flags;
bool force = LUA->GetBool(3);
if (!force)
{
newFlags = 0;
if (flags & FL_EDICT_DONTSEND)
newFlags |= LUA_FL_EDICT_DONTSEND;

if (flags & FL_EDICT_ALWAYS)
newFlags |= LUA_FL_EDICT_ALWAYS;
if (flags & FL_EDICT_ALWAYS)
newFlags |= LUA_FL_EDICT_ALWAYS;

if (flags & FL_EDICT_PVSCHECK)
newFlags |= LUA_FL_EDICT_PVSCHECK;
if (flags & FL_EDICT_PVSCHECK)
newFlags |= LUA_FL_EDICT_PVSCHECK;

if (flags & FL_EDICT_FULLCHECK)
newFlags |= LUA_FL_EDICT_FULLCHECK;
if (flags & FL_EDICT_FULLCHECK)
newFlags |= LUA_FL_EDICT_FULLCHECK;
}

LUA->PushNumber(newFlags);

Expand Down Expand Up @@ -304,9 +334,9 @@ void CPVSModule::LuaInit(bool bServerInit)
Util::AddFunc(pvs_GetPVSForCluster, "GetPVSForCluster");
Util::AddFunc(pvs_CheckBoxInPVS, "CheckBoxInPVS");
Util::AddFunc(pvs_AddEntityToPVS, "AddEntityToPVS");
Util::AddFunc(pvs_OverrideStateFlag, "OverrideStateFlag");
Util::AddFunc(pvs_SetStateFlag, "SetStateFlag");
Util::AddFunc(pvs_GetStateFlag, "GetStateFlag");
Util::AddFunc(pvs_OverrideStateFlags, "OverrideStateFlags");
Util::AddFunc(pvs_SetStateFlags, "SetStateFlags");
Util::AddFunc(pvs_GetStateFlags, "GetStateFlags");

g_Lua->PushNumber(LUA_FL_EDICT_DONTSEND);
g_Lua->SetField(-2, "FL_EDICT_DONTSEND");
Expand Down

0 comments on commit 85f0d01

Please sign in to comment.