LagCompensation: small optimizations
This commit is contained in:
		
							parent
							
								
									8709e5b8d8
								
							
						
					
					
						commit
						48a6752a62
					
				@ -145,16 +145,17 @@ public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	g_bRoundEnded = true;
 | 
						g_bRoundEnded = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity)
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
		{
 | 
								continue;
 | 
				
			||||||
			LogMessage("[%d] round_end deleted: %d / %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity);
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		g_aEntityLagData[i].iEntity = 0;
 | 
							g_aEntityLagData[i].iEntity = 0;
 | 
				
			||||||
		g_iNumEntities--;
 | 
							g_iNumEntities--;
 | 
				
			||||||
 | 
							LogMessage("[%d] round_end deleted: %d / %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
 | 
					public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
 | 
				
			||||||
@ -187,8 +188,12 @@ public MRESReturn Detour_OnUTIL_Remove(Handle hParams)
 | 
				
			|||||||
	if(entity < 0 || entity > sizeof(g_bNoPhysics))
 | 
						if(entity < 0 || entity > sizeof(g_bNoPhysics))
 | 
				
			||||||
		return MRES_Ignored;
 | 
							return MRES_Ignored;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity != entity)
 | 
							if(g_aEntityLagData[i].iEntity != entity)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -234,9 +239,13 @@ public void OnClientPutInServer(int client)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public void OnRunThinkFunctions(bool simulating)
 | 
					public void OnRunThinkFunctions(bool simulating)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity == 0 || !g_aEntityLagData[i].bMoving)
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(!g_aEntityLagData[i].bMoving)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!IsValidEntity(g_aEntityLagData[i].iEntity))
 | 
							if(!IsValidEntity(g_aEntityLagData[i].iEntity))
 | 
				
			||||||
@ -258,6 +267,7 @@ public void OnRunThinkFunctions(bool simulating)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aEntityLagData[i].RestoreData);
 | 
							RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aEntityLagData[i].RestoreData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined DEBUG
 | 
					#if defined DEBUG
 | 
				
			||||||
		LogMessage("1 [%d] [%d] index %d, RECORD entity %d", GetGameTickCount(), i, simulating, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex);
 | 
							LogMessage("1 [%d] [%d] index %d, RECORD entity %d", GetGameTickCount(), i, simulating, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex);
 | 
				
			||||||
		LogMessage("%f %f %f",
 | 
							LogMessage("%f %f %f",
 | 
				
			||||||
@ -278,9 +288,13 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
 | 
				
			|||||||
	if(delta < 0)
 | 
						if(delta < 0)
 | 
				
			||||||
		delta = 0;
 | 
							delta = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity == 0 || !g_aEntityLagData[i].bMoving)
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(!g_aEntityLagData[i].bMoving)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(delta >= g_aEntityLagData[i].iNumRecords)
 | 
							if(delta >= g_aEntityLagData[i].iNumRecords)
 | 
				
			||||||
@ -318,9 +332,13 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public void OnPostPlayerThinkFunctions()
 | 
					public void OnPostPlayerThinkFunctions()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity == 0 || !g_aEntityLagData[i].bRestore)
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(!g_aEntityLagData[i].bRestore)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		RestoreEntityFromRecord(g_aEntityLagData[i].iEntity, 0, g_aEntityLagData[i].RestoreData);
 | 
							RestoreEntityFromRecord(g_aEntityLagData[i].iEntity, 0, g_aEntityLagData[i].RestoreData);
 | 
				
			||||||
@ -341,10 +359,11 @@ public void OnPostPlayerThinkFunctions()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public void OnRunThinkFunctionsPost(bool simulating)
 | 
					public void OnRunThinkFunctionsPost(bool simulating)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity == 0)
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(g_aEntityLagData[i].iDeleted)
 | 
							if(g_aEntityLagData[i].iDeleted)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@ -386,9 +405,7 @@ public void OnRunThinkFunctionsPost(bool simulating)
 | 
				
			|||||||
			g_aEntityLagData[i].iRecordIndex = 0;
 | 
								g_aEntityLagData[i].iRecordIndex = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(g_aEntityLagData[i].iNumRecords < MAX_RECORDS)
 | 
							if(g_aEntityLagData[i].iNumRecords < MAX_RECORDS)
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			g_aEntityLagData[i].iRecordsValid = ++g_aEntityLagData[i].iNumRecords;
 | 
								g_aEntityLagData[i].iRecordsValid = ++g_aEntityLagData[i].iNumRecords;
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex]);
 | 
							RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -423,15 +440,22 @@ void RestoreEntityFromRecord(int iEntity, int iFilter, LagRecord Record)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool AddEntityForLagCompensation(int iEntity)
 | 
					bool AddEntityForLagCompensation(int iEntity)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						if(g_iNumEntities == MAX_ENTITIES)
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity == iEntity)
 | 
							if(g_aEntityLagData[i].iEntity == iEntity)
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0; i < MAX_ENTITIES; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity != 0)
 | 
							if(g_aEntityLagData[i].iEntity)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		g_iNumEntities++;
 | 
							g_iNumEntities++;
 | 
				
			||||||
@ -454,7 +478,6 @@ bool AddEntityForLagCompensation(int iEntity)
 | 
				
			|||||||
			int iHammerID = GetEntProp(g_aEntityLagData[i].iEntity, Prop_Data, "m_iHammerID");
 | 
								int iHammerID = GetEntProp(g_aEntityLagData[i].iEntity, Prop_Data, "m_iHammerID");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			LogMessage("[%d] added entity %d (%s)\"%s\"(#%d) under index %d", GetGameTickCount(), iEntity, sClassname, sTargetname, iHammerID, i);
 | 
								LogMessage("[%d] added entity %d (%s)\"%s\"(#%d) under index %d", GetGameTickCount(), iEntity, sClassname, sTargetname, iHammerID, i);
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			float vecOrigin[3];
 | 
								float vecOrigin[3];
 | 
				
			||||||
			GetEntPropVector(iEntity, Prop_Data, "m_vecAbsOrigin", vecOrigin);
 | 
								GetEntPropVector(iEntity, Prop_Data, "m_vecAbsOrigin", vecOrigin);
 | 
				
			||||||
@ -463,8 +486,11 @@ bool AddEntityForLagCompensation(int iEntity)
 | 
				
			|||||||
				vecOrigin[1],
 | 
									vecOrigin[1],
 | 
				
			||||||
				vecOrigin[2]
 | 
									vecOrigin[2]
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -473,7 +499,7 @@ public void OnEntitySpawned(int entity, const char[] classname)
 | 
				
			|||||||
	if(entity < 0 || entity > sizeof(g_bNoPhysics))
 | 
						if(entity < 0 || entity > sizeof(g_bNoPhysics))
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(StrEqual(classname, "func_physbox"))
 | 
						if(!strncmp(classname, "func_physbox", 12))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		AddEntityForLagCompensation(entity);
 | 
							AddEntityForLagCompensation(entity);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
@ -492,7 +518,13 @@ public void OnEntitySpawned(int entity, const char[] classname)
 | 
				
			|||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		GetEntityClassname(iParent, sParentClassname, sizeof(sParentClassname));
 | 
							GetEntityClassname(iParent, sParentClassname, sizeof(sParentClassname));
 | 
				
			||||||
		if(StrEqual(sParentClassname, "func_movelinear") || StrEqual(sParentClassname, "func_door") || StrEqual(sParentClassname, "func_tracktrain") || StrEqual(sParentClassname, "func_physbox"))
 | 
							if(strncmp(sParentClassname, "func_", 5))
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(StrEqual(sParentClassname[5], "movelinear") ||
 | 
				
			||||||
 | 
								StrEqual(sParentClassname[5], "door") ||
 | 
				
			||||||
 | 
								StrEqual(sParentClassname[5], "tracktrain") ||
 | 
				
			||||||
 | 
								!strncmp(sParentClassname[5], "physbox", 7))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			bGoodParents = true;
 | 
								bGoodParents = true;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
@ -513,12 +545,6 @@ public void OnEntitySpawned(int entity, const char[] classname)
 | 
				
			|||||||
	if(!bGoodParents)
 | 
						if(!bGoodParents)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int SolidFlags = GetEntProp(iParent, Prop_Data, "m_usSolidFlags");
 | 
					 | 
				
			||||||
	LogMessage("SolidFlags: %d", SolidFlags);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if(!(SolidFlags & 0x0004) && false) // FSOLID_NOT_SOLID
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if(!AddEntityForLagCompensation(entity))
 | 
						if(!AddEntityForLagCompensation(entity))
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -534,14 +560,18 @@ public void OnEntityDestroyed(int entity)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	g_bNoPhysics[entity] = false;
 | 
						g_bNoPhysics[entity] = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(int i = 0; i < MAX_ENTITIES; i++)
 | 
						for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(g_aEntityLagData[i].iEntity == entity)
 | 
							if(!g_aEntityLagData[i].iEntity)
 | 
				
			||||||
		{
 | 
								continue;
 | 
				
			||||||
			LogMessage("[%d] normal deleted: %d / %d", GetGameTickCount(), i, entity);
 | 
							j--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(g_aEntityLagData[i].iEntity != entity)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		g_aEntityLagData[i].iEntity = 0;
 | 
							g_aEntityLagData[i].iEntity = 0;
 | 
				
			||||||
		g_iNumEntities--;
 | 
							g_iNumEntities--;
 | 
				
			||||||
 | 
							LogMessage("[%d] normal deleted: %d / %d", GetGameTickCount(), i, entity);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user