|
|
Re: some multiplayer thoughts
[Re: Superku]
#400164
04/26/12 15:01
04/26/12 15:01
|
Joined: May 2009
Posts: 5,367 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,367
Caucasus
|
Thank you man! I got it  But still, there are three strange problems: * visual rotations are jerking, on the clientside (on the server side, they rotate but with lag) * plus there is a problem with X, Y, Z positions of the server: Originally he was created above the ground, no as on the screen. On the serverside, everything is ok, this happens only for clients. * adjusting positions, doesn't seems to work, cause positions are different sometimes. Here is how I've made script:
void player_interpolate_move()
{
VECTOR temp, move_vec;
proc_kill(5);
vec_diff(move_vec,my.dplay_x,my.x);
my.counter = 4;
while(my.counter > 0)
{
vec_set(temp,move_vec);
vec_normalize(temp,0.25*time_step);
c_move(my, nullvector, temp, IGNORE_SPRITES | IGNORE_MODELS | IGNORE_WORLD);
my.counter -= time_step;
wait(1);
}
}
void player_interpolate()
{
if(my.dplay_x || my.dplay_y || my.dplay_z) // you'd better use another skill here like my.dplay_do_interpolation or something like that and reset it after the function call below
{
player_interpolate_move();
vec_set(my.dplay_x,nullvector);
}
my.pan += ang(my.dplay_pan-my.pan)*0.5*time_step;
}
void player_input()
{
my.keys_x = (key_w - key_s);
my.keys_y = (key_a - key_d);
// change pan here, too
my.pan -= 0.3 * mickey.x;
}
void player_move()
{
my.dist_x = 10 * my.keys_x * time_step;
my.dist_y = 10 * my.keys_y * time_step;
my.dist_z = 0;
c_move(my, my.dist_x, nullvector, GLIDE);
// animate here as well
}
void player_update()
{
// send keys:
if(my.keys_x != my.old_keys_x)
{
my.old_keys_x = my.keys_x;
send_skill(my.keys_x, SEND_ALL);
}
if(my.keys_y != my.old_keys_y)
{
my.old_keys_y = my.keys_y;
send_skill(my.keys_y, SEND_ALL);
}
// send PAN:
my.pan_update = maxv(my.pan_update - time_step, 0);
if(!my.pan_update && abs(ang(my.dplay_pan - my.pan)) > 1)
{
my.pan_update = 2;
my.dplay_pan = my.pan;
send_skill(my.dplay_pan, SEND_ALL); // do not send my.pan here
}
// send positions:
my.pos_update = maxv(my.pos_update - time_step, 0);
if(!my.pos_update && vec_dist(my.x, my.dplay_x) > 8)
{
vec_set(my.dplay_x, my.x);
my.pos_update = 8;
send_skill(my.dplay_x, SEND_ALL | SEND_VEC);
}
}
action act_player()
{
wait(1);
c_setminmax(my);
while(my.client_id < 0) wait(1);
my.smask |= NOSEND_ALPHA | NOSEND_AMBIENT | NOSEND_ORIGIN | NOSEND_ANGLES | NOSEND_ATTACH | NOSEND_COLOR | NOSEND_FLAGS | NOSEND_FRAME | NOSEND_LIGHT | NOSEND_SCALE | NOSEND_SKIN | NOSEND_SOUND;
while(1)
{
if(my.client_id == dplay_id) player_input();
else player_interpolate();
player_move();
if(my.client_id == dplay_id || connection != 2) player_update();
wait(1);
}
}
And here is the download link to give it a try: download link
|
|
|
Re: some multiplayer thoughts
[Re: Superku]
#422796
05/17/13 07:04
05/17/13 07:04
|
Joined: Jul 2008
Posts: 168
82RJZAE
Member
|
Member
Joined: Jul 2008
Posts: 168
|
if(my.client_id == dplay_id || connection != 2) player_update(); Why exactly have you set this condition? Won't player_update(); be run on all machines anyways since my.client_id == dplay_id specifies for the client who made the entity and connection != 2 includes the server. In other words, why can't you just remove the if condition? Likewise, could you clarify what's going on in void player_update()? I still haven't been able to figure out the poor interpolation (leading to synchronization problems) I'm getting when I try to implement this code! The poor synchronization is especially a problem when slowly strafing into a corner leading to another room.
|
|
|
Re: some multiplayer thoughts
[Re: 82RJZAE]
#422809
05/17/13 11:12
05/17/13 11:12
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
OP
Senior Expert
|
OP
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
I really don't know a guideline for reasonable bps rates, I just try to keep them "as low as possible".
No, this condition is important, consider the following case:
1 server, 3 clients A,B,C, where A is the server (i.e. connection == 3). Now B and C have connection == 2, and one entity on client B's computer is controlled by client C. This entity gets interpolated and receives the updates from the server which itself receives them from client C, who thus both have to execute player_update. However, client B must not send those key and position updates to the server or this would confuse the whole simulation on the server and thus on all other clients.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|