Skip to content

Commit c1ea215

Browse files
committed
repo: do some cleanups
1 parent e2163ba commit c1ea215

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

source/lua/CLuaInterface.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ void Lua::CloseLuaInterface(GarrysMod::Lua::ILuaInterface* LuaInterface)
261261
// =================================
262262
// ILuaBase / CBaseLuaInterface implementation
263263
// =================================
264-
265264
CLuaInterface::~CLuaInterface()
266265
{
267266
if (state != nullptr)
@@ -1059,10 +1058,10 @@ void CLuaInterface::CallInternal(int args, int rets)
10591058
if (!ThreadInMainThread())
10601059
Error("Calling Lua function in a thread other than main!");
10611060

1062-
if (rets > 4)
1061+
if (rets > LUA_MAX_RETURN_OBJECTS)
10631062
Error("[CLuaInterface::Call] Expecting more returns than possible\n");
10641063

1065-
for (int i=0; i<3; ++i)
1064+
for (int i=0; i<LUA_MAX_RETURN_OBJECTS; ++i)
10661065
m_ProtectedFunctionReturns[i] = nullptr;
10671066

10681067
if (IsType(-(args + 1), GarrysMod::Lua::Type::Function))
@@ -1205,7 +1204,7 @@ GarrysMod::Lua::ILuaObject* CLuaInterface::GetReturn(int iStackPos)
12051204
LuaDebugPrint(2, "CLuaInterface::GetReturn\n");
12061205

12071206
int idx = abs(iStackPos);
1208-
if (idx >= 0 && idx < 4)
1207+
if (idx >= 0 && idx < LUA_MAX_RETURN_OBJECTS)
12091208
{
12101209
if ( m_ProtectedFunctionReturns[idx] == nullptr )
12111210
{

source/lua/CLuaInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class CLuaInterface : public GarrysMod::Lua::ILuaInterface
190190
int m_nLuaErrorReporter = -1; // Always 1 since it's always the first registry reference.
191191
CUtlStack<Path> m_CurrentPaths;
192192
std::list<GarrysMod::Lua::ILuaThreadedCall*> m_pThreadedCalls;
193-
GarrysMod::Lua::ILuaObject* m_ProtectedFunctionReturns[4] = {nullptr};
193+
GarrysMod::Lua::ILuaObject* m_ProtectedFunctionReturns[LUA_MAX_RETURN_OBJECTS] = {nullptr};
194194
GarrysMod::Lua::ILuaObject* m_TempObjects[LUA_MAX_TEMP_OBJECTS] = {nullptr};
195195
unsigned char m_iRealm = (unsigned char)2; // CLIENT = 0, SERVER = 1, MENU = 2
196196
GarrysMod::Lua::ILuaGameCallback* m_pGameCallback = nullptr;

source/lua/ILuaInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Bootil
1616
}
1717

1818
#define LUA_MAX_TEMP_OBJECTS 32
19+
#define LUA_MAX_RETURN_OBJECTS 4
1920

2021
class CLuaInterface;
2122
struct lua_State;

source/modules/networking.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@
1010
#include "dt.h"
1111
#include "edict.h"
1212
#include "eiface.h"
13-
#define protected public // Need access to CBasePlayer::m_hViewModel
14-
#define private public // Need access to CBaseViewModel::m_hScreens
15-
#include "player.h"
16-
#include "vguiscreen.h"
17-
#undef protected
18-
#undef private
1913
#include "baseclient.h"
2014
#include <bitset>
2115
#include <unordered_set>
2216
#include <datacache/imdlcache.h>
2317
#include <cmodel_private.h>
2418
#include "server.h"
2519
#include "hltvserver.h"
20+
#define protected public
21+
#include "player.h"
22+
#undef protected
2623
#include "SkyCamera.h"
2724
#include "sourcesdk/GameEventManager.h"
2825

@@ -1172,7 +1169,7 @@ struct EntityTransmitCache // Well.... Still kinda acts as a tick-based cache, t
11721169

11731170
// We do -1 since nArea 0 is not actually an valid area
11741171
AreaCache& pArea = nAreaEntities[nArea-1];
1175-
if (pArea.nCount >= 512)
1172+
if (pArea.nCount >= nMaxEntitiesPerArea)
11761173
{
11771174
pPVSEntityList[++nPVSEdictCount] = pEntity;
11781175
return;
@@ -1223,7 +1220,7 @@ struct EntityTransmitCache // Well.... Still kinda acts as a tick-based cache, t
12231220
{
12241221
// We do -1 since nArea 0 is not actually an valid area and we shifted all by 1
12251222
AreaCache& pArea = nAreaEntities[areaNum-1];
1226-
if (pArea.nCount >= 512)
1223+
if (pArea.nCount >= nMaxEntitiesPerArea)
12271224
{
12281225
pPVSEntityList[++nPVSEdictCount] = pEntity;
12291226
return;
@@ -1261,11 +1258,12 @@ struct EntityTransmitCache // Well.... Still kinda acts as a tick-based cache, t
12611258
12621259
ToDo: Think about if we should move Areas with 1-2 entities into the nPVSEntityList simply because its probably quicker to do a PVS check than area? (verify)
12631260
*/
1261+
static constexpr int nMaxEntitiesPerArea = 512; // Max entities per area before we move them to PVS checks
12641262
struct AreaCache
12651263
{
12661264
// Not preincremented - use < in for loops
12671265
int nCount = 0;
1268-
CBaseEntity* pEntities[512];
1266+
CBaseEntity* pEntities[nMaxEntitiesPerArea];
12691267
};
12701268

12711269
AreaCache nAreaEntities[MAX_MAP_AREAS-1]; // -1 since Area 0 is not a valid one so we save some bytes

0 commit comments

Comments
 (0)