AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Extensions (https://forums.alliedmods.net/forumdisplay.php?f=134)
-   -   [CSGO] Player distances in real time (https://forums.alliedmods.net/showthread.php?t=335535)

intellild 12-12-2021 01:41

[CSGO] Player distances in real time
 
https://github.com/intellild/sm_exte...layer_distance
This extension computes player distance in real time and providers a simple rule extension for plugins depends on player distances to each other, for example,
hide teammates

This extension make use of SIMD features of the CPU to get best performance for computing player distances.
(Thanks to compilers, we don't need to write SIMD code by hand in most cases)

On my machine (3700x), the compute for 64 player is around 0.2ms(200000ns). So we can compute player distances every game frame.

kiceqs 12-13-2021 11:25

Re: [CSGO] Player distances in real time
 
PHP Code:

float dist[MAXPLAYERS 1][MAXPLAYERS 1];

void Distance1()
{
    
Profiler prof = new Profiler();
    
prof.Start();
    for (
int i 1<= MaxClients; ++i) {
        if (!
IsClientInGame(i)) {
            continue;
        }

        
float pos[3];
        
GetClientEyePosition(ipos);
        
        for (
int j 1<= MaxClients; ++j) {
            if (
== || !IsClientInGame(j)) {
                continue;
            }
            
            
float target[3];
            
GetClientEyePosition(jtarget);
            
dist[i][j] = GetVectorDistance(postarget);
        }
    }
    
prof.Stop();
    
PrintToServer("dist1 = %f"prof.Time);
}

void Distance2(bool squared false)
{
    
Profiler prof = new Profiler();
    
prof.Start();

    
bool validClient[MAXPLAYERS 1];
    
float pos[MAXPLAYERS 1][3];
    for (
int i 1<= MaxClients; ++i) {
        if (!
IsClientInGame(i)) {
            continue;
        }

        
validClient[i] = true;
        
GetClientEyePosition(ipos[i]);
    }

    for (
int i 1<= MaxClients; ++i) {
        if (!
validClient[i]) {
            continue;
        }

        for (
int j 1<= MaxClients; ++j) {
            if (
== || !validClient[j]) {
                continue;
            }
            
            
dist[i][j] = GetVectorDistance(pos[i], pos[j], squared);
        }
    }
    
prof.Stop();
    
PrintToServer("dist2 = %f (%s)"prof.Timesquared "squared" " ");


On my laptop: i7 10750H, win10, with srcds and csgo running, (and a lot of other junk), here is what i got, with 48 players in game

dist1 = 0.000151
dist2 = 0.000059 ( )
dist2 = 0.000054 (squared)

The profiler uses QueryPerformanceCounter, thus the result should be enough in this case.

I mean sourcemod JIT is not that bad, and the major overhead is expected to be brand prediction missing and cache missing, not the calculation itself.

Total float operation is 48*48*(3+3) = 13824 (let multiplication and addition be the same), which is not that much at all for a morden cpu.


All times are GMT -4. The time now is 10:16.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.