Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 05:41
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AbrahamR, AndrewAMD), 1,278 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Local lag in Multiplayer #356075
01/30/11 19:59
01/30/11 19:59
Joined: Jul 2009
Posts: 1,198
Berlin, Germany
L
Liamissimo Offline OP
Serious User
Liamissimo  Offline OP
Serious User
L

Joined: Jul 2009
Posts: 1,198
Berlin, Germany
Hey Guys,

as everyone is doing online games I took a look in the system. It works so far, but I've got a lag in my local system. I start it as server/client, no lag. Than as client, when I am moving (the player or the camera) it is kinda like jumping around. I thought dplay_smooth could be my fault, but even with 0 it isn't working properly. I post you my code here, but everything should work.

Client has Latency of 9-15 and bps (not moving: 15, moving 70-80), fps are 60 (fps_max is used, otherwise up to 200).

Code:
Code:
#define speed_y skill1
#define speed_x skill2
#define health skill50

#include <acknex.h>
#include <default.c>
#include <mtlFx.c>
#include <windows.h>

function on_client_event() // terminate client when server disconnects
{ 
	if (event_type == EVENT_LEAVE) sys_exit("Disconnected!"); 
} 

function player_remove() // remove player when client disconnects
{ 
	if (event_type == EVENT_DISCONNECT) ent_remove(me); 
}
action playeract()
{	
	var speed_x_old;
	var speed_y_old;
	var skill3_old;
	my.event = player_remove;
	my.emask |= ENABLE_DISCONNECT;
	my.smask |= NOSEND_FRAME; // don't send animation
	my.health = 100;
	set(my,LIGHT);
	vec_set(my.blue,vector(0,0,255));
	VECTOR verttemp;
	VECTOR cpos;
	VECTOR shoot_there;
	set(my,NARROW|FAT);
	
	wait(1);
	
	c_setminmax(me);
	
	var vspeed_x,vspeed_y,vpan;
	vspeed_x = 0;
	vspeed_y = 0;
	vpan = my.pan;
	while(1)
	{
		if(my.client_id == dplay_id)
		{			
			vpan -= 4 * mouse_force.x;
			my.tilt += 4 * mouse_force.y;
			
			vec_set(cpos,vector(-150,0,50));
			vec_rotate(cpos,vector(my.pan,my.tilt,0));
			vec_add(cpos,my.x);
			vec_set(camera.x,cpos);
			
			vec_set(cpos,vector(0,0,16));
			vec_add(cpos,my.x);
			
			if(c_trace(cpos,camera.x,IGNORE_ME | USE_POLYGON))
			{
				vec_set(camera.x,target);
				vec_add(camera.x,hit.nx);
				vec_add(camera.x,hit.nx);
			}

			vec_set(cpos,my.x);
			cpos.z += 15;
			vec_sub(cpos,camera.x);
			vec_to_angle(camera.pan,cpos);
			my.pan = my.skill3;
			
			accelerate(vspeed_x,(key_w-key_s) * 25 * time_step,0.75);
			accelerate(vspeed_y,(key_a-key_d) * 25 * time_step,0.75);
			
			my.speed_x = vspeed_x;
			my.speed_y = vspeed_y;
			my.skill3 = vpan;
			if(my.speed_y != speed_y_old)
			{
				send_skill(my.speed_y,SEND_ALL|SEND_UNRELIABLE|SEND_RATE);
				speed_y_old = my.speed_y;
			}
			if(my.speed_x != speed_x_old)
			{
				send_skill(my.speed_x,SEND_ALL|SEND_UNRELIABLE|SEND_RATE);
				speed_x_old = my.speed_x;
			}
			if(my.skill3 != skill3_old)
			{
				send_skill(my.skill3,SEND_ALL|SEND_UNRELIABLE|SEND_RATE);
				skill3_old = my.skill3;
			}
		}
		else
		{
			if(connection & CONNECT_SERVER)
			{
				if(my.speed_y != skill1_old)
				{
					send_skill(my.speed_y,SEND_ALL|SEND_UNRELIABLE|SEND_RATE);
					skill1_old = my.speed_y;
				}
				if(my.speed_x != speed_x_old)
				{
					send_skill(my.speed_x,SEND_ALL|SEND_UNRELIABLE|SEND_RATE);
					speed_x_old = my.speed_x;
				}
				if(my.skill3 != skill3_old)
				{
					send_skill(my.skill3,SEND_ALL|SEND_UNRELIABLE|SEND_RATE);
					skill3_old = my.skill3;
				}
			}
			
			
		}	
		my.pan = my.skill3;
		c_move(me,vector(my.speed_x,my.speed_y,0), nullvector, GLIDE);
		wait(1);
	}
}
function main()
{
	wait(1);
	//sc_setup();
	do { wait(1); }
	while (dplay_status < 2); // wait until the session is opened or joined
	fps_max = 60;
	dplay_entrate = 4;  // 16 ticks/4 = 4 updates per second
	dplay_smooth = 0;
	dplay_localfunction = 2;
	vec_set(sun_pos,nullvector);
	sun_light = 0;
	level_load("teststadium.wmb");
	//sc_hdrRT = 4; 
	// 16/32/64/128 hdr bitdepth
	//sc_hdrBits = 32;
	//turn HDR on/off
	//sc_bHDR = 1;
	if (connection & CONNECT_SERVER) 
	{ // this instance of the game runs on the server
		ent_create ("player.mdl",vector(-256,32,128),playeract); // then create the red guard!
		return;
		
	} 
	else
	{ // Client
		ent_create ("player.mdl",vector(1300,-1296,128),playeract); // create the blue guard
		return;	
	}

}



I deleted not used code, this is all MP code. For better understanding of the "lag" a video from my client:
[video:youtube]http://www.youtube.com/watch?v=2dFvVFGMdcg[/video]

My Internet is very slow but I think that isn't the problem as my test is local.


"Ich weiss nicht genau, was Sie vorhaben, aber Sie können keine Triggerzonen durch Ihr Level kullern lassen."
-JCL, 2011
Re: Local lag in Multiplayer [Re: Liamissimo] #356227
01/31/11 18:06
01/31/11 18:06
Joined: Jul 2009
Posts: 1,198
Berlin, Germany
L
Liamissimo Offline OP
Serious User
Liamissimo  Offline OP
Serious User
L

Joined: Jul 2009
Posts: 1,198
Berlin, Germany
Alibaba helped me a bit but I am still laggy. Could it be because of the intern functions? I try it with A-Net, maybe this works better.

A-Net demo is perfectly smooth, this can't be. I have to buy Anet to get working Multiplayer?

Last edited by TheLiam; 01/31/11 18:18.

"Ich weiss nicht genau, was Sie vorhaben, aber Sie können keine Triggerzonen durch Ihr Level kullern lassen."
-JCL, 2011
Re: Local lag in Multiplayer [Re: Liamissimo] #356239
01/31/11 20:11
01/31/11 20:11
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
No, at least in movement, Anet has no advances over the native multiplayer, they both work pretty much the same. Native multiplayer sends regular updates on its own (depending on dplay_entrate), in Anet you have to do that yourself.

Its only a matter of how you code it. If you want it completely server-side but also lag free, you need to synchronize the time between client and server and send a timestamp with each update from the server. this way, you can avoid the lag if a packet takes longer than the previous.

Or you could do it as i did in survive and use client-side movement, meaning that the position of the local player is not corrected by the server (and is thus completly lag free) but corrects the view of the server. You'd have to set dplay_entrate to a very high value or disable it.

Re: Local lag in Multiplayer [Re: SchokoKeks] #356243
01/31/11 20:22
01/31/11 20:22
Joined: Jul 2009
Posts: 1,198
Berlin, Germany
L
Liamissimo Offline OP
Serious User
Liamissimo  Offline OP
Serious User
L

Joined: Jul 2009
Posts: 1,198
Berlin, Germany
Ah, okay. I try some NOSEND Flags now and also the thing with dplay, I don't got a good server so I do it right the way you do it.

Finally, I had to disable dplay_entrate. Thanks alot, I thought it is necessary to have this enabled!

Last edited by TheLiam; 01/31/11 20:26.

"Ich weiss nicht genau, was Sie vorhaben, aber Sie können keine Triggerzonen durch Ihr Level kullern lassen."
-JCL, 2011

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1