View Single Post
Downtown1
Veteran Member
Join Date: Mar 2004
Old 01-06-2010 , 22:40   Re: [L4D2] Versus Water Break
Reply With Quote #8

Quote:
Originally Posted by AtomicStryker View Post
I included Frameskips and made it as easy to run as possible. Im quite certain you could run 100 instances of the plugin without slowing a server down
Well I am going to assume it's just not possible to do this without OnGameFrame. That being said your OnGameFrame has a lot of redundant checks.

PHP Code:
            if (!IsClientInGame(target)) continue;
            if (
GetClientTeam(target) != 2) continue;
            if (!
IsPlayerAlive(target)) continue; 
It loops from 1,MaxClients every time and skips all the "invalid" clients. However if we consider the typical situation of 4 alive survivors, 18 maxclients, that means you're skipping 66.66% of the time. Plus calling extra natives which is relatively expensive.

By doing something like this you can reclaim a 66% speedup.

PHP Code:
#define MAX_SUPPORTED_CLIENTS 32
new survivor_clients[MAX_SUPPORTED_CLIENTS];
new 
survivor_count 0;

FindSurvivorIdx(client)

  for(new 
0survivor_count; ++i
    if(
survivor_clients[i] == client) return i;
  return 
0;
}

SwapArrayElements(array[], ab)
{
  if(
== b) return;
  new 
tmp = array[a];
  array[
a] = array[b];
  array[
b] = tmp;
}

//call this when player connects AND hes a survivor AND hes alive
OnPlayerJoinSurvivors(client)
{
  if(!
FindSurvivorIdx(client))
    
survivor_clients[survivor_count++] = client;
}

//call this when a player disconnects OR hes not a survivor OR hes not alive
OnPlayerLeaveSurvivors(client)
{
  new 
idx FindSurvivorIdx(client);
  
//keep the array contiguous
  
if(idx
  {
    
SwapArrayElements(survivor_clientsidxsurvivor_count-1);
    
survivor_count--;
  }
}

////////////

public OnGameFrame()
{
  
//early out checks as before
  
for(new idx 0idx survivor_counti++)
  {
    new 
target survivor_clients[idx];
    
    new 
level GetEntData(targetWaterOffset1);
    
// etc rest of this is the same as before
  
}

Downtown1 is offline