J'ai un petit probleme avec mon mmorpg...
Rien qu'en local j'obtient une trop grande latence...
Mais quand je met un serveur a distance la latence monte a 500ms...
Vuq ue j'utilise pour le moment seulement un rafraichissement des positions et non pas des vecteur et des actions pour les deplacement (fluide)
DWORD WINAPI SendData(void* param)
{
int copyOfTotal=0;
int l;
vector3df buff;
f32 x,y,z,t;
int action;
threadparam* paraM = (threadparam*)param;
char buffer[1024];
int Total = 0;
ref = clock();
UNIT my[5000];
while(1)
{
S("1");
R();
gcvt(paraM->object->getPosition().X, 8, buffer);
S(buffer);
R();
gcvt(paraM->object->getPosition().Y, 8, buffer);
S(buffer);
R();
gcvt(paraM->object->getPosition().Z, 8, buffer);
S(buffer);
R();
gcvt(paraM->object->getRotation().Y, 8, buffer);
S(buffer);
R();
itoa(paraM->action,buffer,1024);
S(buffer);
l = 0;
while(strcmp(R(), "LISTP") == 0)
{
S(".");
x = (f32)atof(R());
S(".");
y = (f32)atof(R());
S(".");
z = (f32)atof(R());
S(".");
t = (f32)atof(R());
S(".");
action = atoi(R());
S(".");
if(l >= Total){
if(my[l].Mnode)
{
my[l].Mnode->setVisible(true);
}
else{
my[l].hero = paraM->mydevice->getSceneManager()->getMesh("sydney.md2");
my[l].Mnode = paraM->mydevice->getSceneManager()->addAnimatedMeshSceneNode( my[l].hero );
if (my[l].Mnode)
{
my[l].Mnode->setMaterialFlag(EMF_LIGHTING, false);
my[l].Mnode->setMaterialTexture( 0, paraM->mydevice->getVideoDriver()->getTexture("sydney.bmp") );
my[l].Mnode->setScale(vector3df(1.3f,1.3f,1.3f));
my[l].Mnode->setMD2Animation ( scene::EMAT_STAND );
}
my[l].Mnode->setPosition(vector3df(x,y,z));
my[l].Mnode->setRotation(vector3df(0,t,0));
Total++;
}
}
else
{
my[l].Mnode->setPosition(vector3df(x,y,z));
my[l].Mnode->setRotation(vector3df(0,t,0));
}
copyOfTotal = Total;
l++;
}
while(l < copyOfTotal)
{
cout << l << endl;
my[l].Mnode->setVisible(false);
Total--;
l++;
}
Sleep(1);
}
return 0;
}
Le code de mon client au niveau reseau.
Et maintenant le code du serveur mais seulement la partie qui utilise le reseau.
#include "collision.h"
#include "serveur.h"
#include "ILogger.h"
#include <iostream>
#include <windows.h>
#include "playerHandler.h"
#include "include/pthread.h"
using namespace std;
pthread_mutex_t job_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
int id = 0;
PL mystruct[5000];
void player::game(MySQL Msql)
{
int myID = id;
int updatingTime = 0;
char buffer[1024], old[1024];
pthread_mutex_lock (&job_queue_mutex);
id++;
pthread_mutex_unlock (&job_queue_mutex);
while(1)
{
updatingTime++;
pthread_mutex_lock (&job_queue_mutex);
if(updatingTime == 3000)
{
Msql.execute("UPDATE account SET X='%s', Y='%s', Z='%s', Rot='%s',action='%s' WHERE nickname='%s'",PX,PY,PZ,RY,action,nick);
_Log("[Client # %d, %s]->Save Client",myID,nick);
updatingTime = 0;
}
strcpy(buffer,TCP_RECV(sock));
strcpy(mystruct[myID].action, buffer);
strcpy(old, buffer);
if(TCP_SEND(sock,".") == 0){break;}
strcpy(buffer,TCP_RECV(sock));
strcpy(mystruct[myID].PX, buffer);
if(strcmp(buffer, old) == 0){
pthread_mutex_unlock (&job_queue_mutex);
break;
}
if(TCP_SEND(sock,".") == 0){break;}
strcpy(buffer,TCP_RECV(sock));
strcpy(mystruct[myID].PY, buffer);
if(TCP_SEND(sock,".") == 0){break;}
strcpy(buffer,TCP_RECV(sock));
strcpy(mystruct[myID].PZ, buffer);
if(TCP_SEND(sock,".") == 0){break;}
strcpy(buffer,TCP_RECV(sock));
strcpy(mystruct[myID].RY, buffer);
if(TCP_SEND(sock,".") == 0){break;}
strcpy(buffer,TCP_RECV(sock));
strcpy(mystruct[myID].action, buffer);
pthread_mutex_unlock (&job_queue_mutex);
int ier = 0;
pthread_mutex_lock (&job_queue_mutex);
while(ier < id)
{
if(ier != myID)
{
TCP_SEND(sock,"LISTP");
TCP_RECV(sock);
TCP_SEND(sock,mystruct[ier].PX);
TCP_RECV(sock);
TCP_SEND(sock,mystruct[ier].PY);
TCP_RECV(sock);
TCP_SEND(sock,mystruct[ier].PZ);
TCP_RECV(sock);
TCP_SEND(sock,mystruct[ier].RY);
TCP_RECV(sock);
TCP_SEND(sock,mystruct[ier].action);
TCP_RECV(sock);
}
ier++;
}
pthread_mutex_unlock (&job_queue_mutex);
TCP_SEND(sock,"LISTD");
Sleep(1.5);
}
_Log("[Client # %d, %s]->Disconecting",myID,nick);
pthread_mutex_lock (&job_queue_mutex);
id--;
Msql.execute("UPDATE account SET online='0' WHERE nickname='%s'", nick);
pthread_mutex_unlock (&job_queue_mutex);
return;
}
Merci si quelqu'un poubvait voir d'ou vient le blem...