Why does FPS calculation work?
#1

Код:
#include <a_samp>

new pDrunkLevelLast[MAX_PLAYERS];
new pFPS[MAX_PLAYERS];


public OnPlayerConnect(playerid)
{
    SetTimer("DisplayFPS",250,1);
    pDrunkLevelLast[playerid]   = 0;
    pFPS[playerid]          	= 0;
}

public OnPlayerUpdate(playerid)
{
    new drunknew = GetPlayerDrunkLevel(playerid);
    if(drunknew < 100)
	{
        SetPlayerDrunkLevel(playerid, 2000);
    }
	else
	{

        if(pDrunkLevelLast[playerid] != drunknew)
		{
            new wfps = pDrunkLevelLast[playerid] - drunknew;
            if((wfps > 0) && (wfps < 200))
			pFPS[playerid] = wfps;
  			pDrunkLevelLast[playerid] = drunknew;
        }

    }

}

forward DisplayFPS();
public DisplayFPS()
{
	for(new i, j = GetPlayerPoolSize(); i <= j; i++)
	{
		if(!IsPlayerConnected(i))continue;
		new string[128];
		format(string, sizeof(string), "%i", pFPS[i]);
		SendClientMessage(i, -1, string);
	}
}
Can somebody pls explain me: WHY does the FPS calculation work in OnPlayerUpdate? I mean I get the IDEA behind it, that we lose the amount on our drunklevel of our FPS, BUT:
Even when I make a timer where I receive the "fps result" every 0.5 seconds (should be HALF of my real FPS then logically)..EVEN THEN i do NOT get half of my fps as the result, but still the whole fps..but it seems unlogical to me why this works (also samp wiki says onplayerupdate gets called like 30times per second, which MEANS you calculate approx 30 times per second)

example:
Lets say Fraps says we have 100FPS constant:

drunknew = 2000
wfps = 0 - 2000 = -2000
pfps =-2000
pdrunklevellast = 2000

lets say 500ms passed which are then 50FPS so:
drunknew = 1950
wfps = 2000 - 1950 =50..so we found out the 'Frame per half a second' and we did NOT use a calculation to make this a whole second (50 * (1000/500)) with my calculation in brakets it would totally make sense, just that this was never done in the script..
then the question is, why does samp show me my real fps anyway
im too dumb to get it...we calculate the passed frame per seconds like 30times per second and we do NOT calculate the result to a WHOLE second, but i still get my exact FPS (per SECOND)...how? why?

Edit:
nevermind I just figured out that our drunklevel ONLY changes EXACTLY every second (EVEN when we check the drunklevel every millisecond it WILL be the same as before until EXACTLY one second has passed)..and this is WHY it works
Reply
#2

okay but by the way, u're looping this timer SetTimer("DisplayFPS",250,1);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)