Hello everyone, I have two questions about using multisync and dark gdk together. I have the newest version of both, and i am successfully sending messages between the client and server exe. The first question When I start the server and then start the exe it connects and even says the client has joined. to make sure it was sending I sent it back to the player an positioned a cube in the inverse of the x and z position. When the server first starts it reacts very fast and the cube moves almost instantly after a couple of seconds the reaction time starts to increase to almost nothing what is wrong with it. My other question how do you have more than one client connect to a server and so that you can see each other. I have looked at the examples but they are in dbpro and there are somethings I do not know how to convert to gdk here is my server and client code
//client code
//player header
#include "DarkGDK.h"
#include "multisync.h"
float sendTimer = 0;
class Player
{
public:
Player(int playerObject,int camera)
{
newPlayerObject = playerObject;
newCamera = camera;
dbMakeObjectSphere(newPlayerObject,25,10,10);
dbMakeCamera(newCamera);
dbSetCurrentCamera(newCamera);
dbSetCameraRange(0.1,1000000);
NetPlayerJoined();
}
~Player() {}
float returnPlayerX() {return dbObjectPositionX(newPlayerObject);}
float returnPlayerY() {return dbObjectPositionY(newPlayerObject);}
float returnPlayerZ() {return dbObjectPositionZ(newPlayerObject);}
float returnPlayerAngle() {return dbObjectAngleY(newPlayerObject);}
void sendData()
{
sendTimer--;
if(sendTimer <=0) sendTimer = 0;
if(sendTimer<=0)
{
NetPutInt(newPlayerObject);
NetPutFloat(returnPlayerX());
NetPutFloat(returnPlayerY());
NetPutFloat(returnPlayerZ());
NetPutFloat(returnPlayerAngle());
NetSend(0);
sendTimer = 0.02;
}
}
void Update()
{
if(dbKeyState(17))
{
dbMoveObject(newPlayerObject,5);
}
if(dbKeyState(30))
{
dbMoveObjectLeft(newPlayerObject,5);
}
if(dbKeyState(31))
{
dbMoveObject(newPlayerObject,-5);
}
if(dbKeyState(32))
{
dbMoveObjectRight(newPlayerObject,5);
}
if((dbKeyState(25)))
{
dbWaitKey();
}
mouseX = dbWrapValue ( mouseX + dbMouseMoveY ( ) * 0.4f );
mouseY = dbWrapValue ( mouseY + dbMouseMoveX ( ) * 0.4f );
// rotate camera
dbXRotateObject (newPlayerObject, mouseX );
dbYRotateObject (newPlayerObject,mouseY );
dbRotateCamera(newCamera,dbObjectAngleX(newPlayerObject),dbObjectAngleY(newPlayerObject),0);
dbPositionCamera(newCamera,dbObjectPositionX(newPlayerObject),dbObjectPositionY(newPlayerObject),dbObjectPositionZ(newPlayerObject));
sendData();
}
private:
float newX;
float newY;
float newZ;
float mouseX;
float mouseY;
float newRotY;
int newPlayerObject;
int newCamera;
int Players;
};
//main file
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "multisync.h"
#include "World.H"
#include "Player.H"
char ip[16] = "108.204.240.210";
unsigned int port = 1000;
int obj;
int RX = 0;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbEntry();
World world(1);
dbMakeObjectCube(22,50);
NetSetPort(port);
while(!NetConnect(ip))
{
dbCLS();
dbText(0,0,"error");
dbSync();
}
if(NetConnect(ip))
{
dbText(10,10,"Connected");
}
int num;
float pX,pY,pZ, pA;
dbMakeObjectCube(2,50);
Player player(6,6);
dbWait(3);
// our main loop
while ( LoopGDK ( ) )
{
// update the screen
if(!NetConnected()) dbText(10,10,"Offline");
player.Update();
if(NetGetMessage())
{
num = NetGetInt();
pX = NetGetFloat();
pY = NetGetFloat();
pZ = NetGetFloat();
pA = NetGetFloat();
dbPositionObject(2,-pX,pY,-pZ);
dbYRotateObject(2,-pA);
}
dbSync ( );
}
// return back to windows
return;
}
//server
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "multisync.h"
char ip[16] = "192.168.1.50";
unsigned int port = 1000;
int Player = 1;
int sendTimer = 0;
int Max = 10;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
int newClient;
int playerNum;
NetSetPort(port);
while(!NetHost_IP(Max,ip))
{
dbCLS();
char error[100];
dbText(0,0,error);
dbSync();
}
float timer = 0;
int num;
float pX,pY,pZ, pA;
// our main loop
while ( LoopGDK ( ) )
{
// update the screen
newClient = NetPlayerJoined();
if(newClient >0)
{
dbText(10,25,"Player Joined");
}
timer--;
if(timer <=0) timer = 0;
if((NetGetMessage())&&(timer <=0))
{
NetPlayerJoined();
NetPlayerLeft();
playerNum = NetMessageFrom();
num = NetGetInt();
pX = NetGetFloat();
pY = NetGetFloat();
pZ = NetGetFloat();
pA = NetGetFloat();
dbText(10,10,"recieved Data ");
NetPutInt(num);
NetPutFloat(pX);
NetPutFloat(pY);
NetPutFloat(pZ);
NetPutFloat(pA);
NetSendAll();
timer = 0.02;
}
dbSync ( );
}
// return back to windows
return;
}