Noticias:

SMF - Just Installed!

Menú principal

SHOW PING AND FPS - kayito/takumi12

Publicado por Dakosmu, Mar 03, 2025, 01:11 AM

Tema anterior - Siguiente tema

Dakosmu

SHOW PING AND FPS - kayito/takumi12

Los visitantes no pueden visualizar imágenes en los mensajes, por favor Regístrate o Inicia Sesión

Buenas, con tal de mejorar el post recopilé lo posteado por takumi12 sobre ping y fps.

Los visitantes no pueden visualizar imágenes en los mensajes, por favor Regístrate o Inicia Sesión


GAMESERVER

Protocol.h

void GCSendPing(int aIndex);
Protocol.cpp

Adentro de ProtocolCore, después del último case ... : ... break;

case 0xFF:
GCSendPing(aIndex);
break;

Al final del archivo, abajo de todo:

struct PMSG_PING
{
PBMSG_HEAD h; // C1:71
};

void GCSendPing(int aIndex)
{
PMSG_PING pMsgPing;
pMsgPing.h.set(0xFF,sizeof(pMsgPing));
DataSend(aIndex,(BYTE*)&pMsgPing,sizeof(pMsgPing));
}

MAIN.DLL

Protocol.cpp

En el ProtocolCoreEx, después del último case ... : ... break;

#include "Interface.h"
...
...
case 0xFF:
gInterface.DrawPing();
break;

Interface.h

#include "Protocol.h"

struct PMSG_PING
{
PBMSG_HEAD h;
};

Adentro de Class Interface:

//PING:
int iniciador;
int msPing;
int lastSend;
int validar;
char ServerPing[20];
char ultimoping[30];
int ultimo_ping;
void DrawPing();
void SendPingRecv();

//FPS:
int lastReport;
int frameCount;
int frameRate;
char FPS_REAL[30];
void UPDATE_FPS();

//Interfaz Barra Negra
void guiMonitore();

Interface.cpp

#include "Protocol.h"

Adentro de Load():

//Ping
gInterface.iniciador = 1;
//FPS
gInterface.lastReport = GetTickCount();
gInterface.frameCount = 0;

Adentro de Work():

//Interfaz Barra Negra
gInterface.guiMonitore();
//FPS
gInterface.UPDATE_FPS();
//Ping
gInterface.SendPingRecv();

Al final del archivo, abajo de todo:

//Interfaz Barra Negra
void Interface::guiMonitore(){
if (this->MiniMapCheck())
{
return;
}
pSetBlend(true);
glColor4f((GLfloat)0.0, (GLfloat)0.0, (GLfloat)0.0, (float)0.8);
pDrawBarForm(495.0, 0.0, 150.0, 20.0, 0.0f, 0);
pGLSwitchBlend();
}

//FPS
void Interface::UPDATE_FPS(){
gInterface.frameCount++;
if (GetTickCount() - gInterface.lastReport >= 1000)
{
gInterface.frameRate = gInterface.frameCount / ((GetTickCount() - gInterface.lastReport) / 1000);
sprintf(gInterface.FPS_REAL, "FPS: %d", gInterface.frameRate);
gInterface.lastReport = GetTickCount();
gInterface.frameCount = 0;
}

Copiar
// ======================================================================
if (this->MiniMapCheck() || this->CombinedChecks())
{
    return;
}
this->DrawFormat(eGold, 600, 5, 80, 1, gInterface.FPS_REAL);
}

//Ping recibido desde protocol, respuesta del gameserver
void Interface::DrawPing()
{
gInterface.msPing = GetTickCount() - gInterface.lastSend;
gInterface.iniciador = 3;
}

//Ping
void Interface::SendPingRecv()
{
if(gInterface.iniciador == 1){
PMSG_PING pMsgPing;
pMsgPing.h.set(0xFF,sizeof(pMsgPing));
gInterface.lastSend = GetTickCount();
DataSend((BYTE*)&pMsgPing,sizeof(pMsgPing));
gInterface.iniciador=2;
}
else if(gInterface.iniciador == 3){
if (GetTickCount() >= gInterface.lastSend + 1000){
PMSG_PING pMsgPing;
pMsgPing.h.set(0xFF,sizeof(pMsgPing));
gInterface.lastSend = GetTickCount();
DataSend((BYTE*)&pMsgPing,sizeof(pMsgPing));
gInterface.iniciador=2;
}
}

Copiar
if (this->MiniMapCheck() || this->CombinedChecks())
{
    return;
}
sprintf(gInterface.ServerPing, "RTT: %d ms", gInterface.msPing);
// ----
gInterface.validar=0;
if(gInterface.msPing>0){
    //----
    this->DrawFormat(eGold, 545, 5, 120, 1, gInterface.ServerPing);
    sprintf(gInterface.ultimoping,gInterface.ServerPing);
    gInterface.ultimo_ping = gInterface.msPing;
    gInterface.validar=1;
}

if(gInterface.validar==0){
    if(gInterface.ultimo_ping > 0){
        this->DrawFormat(eGold, 545, 5, 80, 1, gInterface.ultimoping);
    }else{
        this->DrawFormat(eGold, 545, 5, 120, 1, gInterface.ServerPing);
    }
}
}

Créditos:

-kayito

-takumi12
Bon Dia

🡱 🡳