Raised This Month: $32 Target: $400
 8% 

[CSGO] Player distances in real time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
intellild
New Member
Join Date: Dec 2021
Old 12-12-2021 , 01:41   [CSGO] Player distances in real time
Reply With Quote #1

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.

Last edited by intellild; 12-12-2021 at 05:22.
intellild is offline
kiceqs
Junior Member
Join Date: Jun 2015
Old 12-13-2021 , 11:25   Re: [CSGO] Player distances in real time
Reply With Quote #2

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.
kiceqs is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:00.


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