mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
updated the client prediction. a bit smoother now
This commit is contained in:
parent
3f4587ede8
commit
632debf46a
|
@ -189,6 +189,7 @@ static void client_send_error(const char *error)
|
|||
*/
|
||||
}
|
||||
|
||||
|
||||
static void client_send_input()
|
||||
{
|
||||
msg_pack_start_system(NETMSG_INPUT, 0);
|
||||
|
@ -597,7 +598,10 @@ static void client_process_packet(NETPACKET *packet)
|
|||
if(inputs[k].tick == input_predtick)
|
||||
{
|
||||
float wanted_latency = inputs[k].latency - time_left/1000.0f + 0.01f;
|
||||
prediction_latency = prediction_latency*0.95f + wanted_latency*0.05f;
|
||||
if(wanted_latency > prediction_latency)
|
||||
prediction_latency = prediction_latency*0.90f + wanted_latency*0.10f;
|
||||
else
|
||||
prediction_latency = prediction_latency*0.95f + wanted_latency*0.05f;
|
||||
//dbg_msg("DEBUG", "predlatency=%f", prediction_latency);
|
||||
break;
|
||||
}
|
||||
|
@ -890,7 +894,18 @@ static void client_run(const char *direct_connect_server)
|
|||
intratick = (now - prevtick_start) / (float)(curtick_start-prevtick_start);
|
||||
|
||||
// 25 frames ahead
|
||||
int new_predtick = current_tick+prediction_latency*SERVER_TICK_SPEED;
|
||||
int64 last_pred_game_time = 0;
|
||||
int64 predicted_game_time = (now - game_start_time) + (int64)(time_freq()*prediction_latency);
|
||||
if(predicted_game_time < last_pred_game_time)
|
||||
predicted_game_time = last_pred_game_time;
|
||||
last_pred_game_time = predicted_game_time;
|
||||
|
||||
//int64 predictiontime = game_start_time + time_freq()+ prediction_latency*SERVER_TICK_SPEED
|
||||
int new_predtick = (predicted_game_time*SERVER_TICK_SPEED) / time_freq();
|
||||
|
||||
int64 predtick_start_time = (new_predtick*time_freq())/SERVER_TICK_SPEED;
|
||||
intrapredtick = (predicted_game_time - predtick_start_time)*SERVER_TICK_SPEED/(float)time_freq();
|
||||
|
||||
if(new_predtick > current_predtick)
|
||||
{
|
||||
//dbg_msg("")
|
||||
|
@ -902,6 +917,8 @@ static void client_run(const char *direct_connect_server)
|
|||
}
|
||||
}
|
||||
|
||||
//intrapredtick = current_predtick
|
||||
|
||||
if(repredict)
|
||||
modc_predict();
|
||||
}
|
||||
|
|
|
@ -1148,6 +1148,8 @@ static void render_player(const obj_player *prev_obj, const obj_player *player_o
|
|||
prev = *prev_obj;
|
||||
player = *player_obj;
|
||||
|
||||
float intratick = client_intratick();
|
||||
|
||||
if(player.health < 0) // dont render dead players
|
||||
return;
|
||||
|
||||
|
@ -1156,6 +1158,7 @@ static void render_player(const obj_player *prev_obj, const obj_player *player_o
|
|||
// apply predicted results
|
||||
predicted_player.write(&player);
|
||||
predicted_prev_player.write(&prev);
|
||||
intratick = client_intrapredtick();
|
||||
}
|
||||
|
||||
int skin = charids[player.clientid];
|
||||
|
@ -1165,7 +1168,7 @@ static void render_player(const obj_player *prev_obj, const obj_player *player_o
|
|||
|
||||
vec2 direction = get_direction(player.angle);
|
||||
float angle = player.angle/256.0f;
|
||||
vec2 position = mix(vec2(prev.x, prev.y), vec2(player.x, player.y), client_intratick());
|
||||
vec2 position = mix(vec2(prev.x, prev.y), vec2(player.x, player.y), intratick);
|
||||
|
||||
if(prev.health < 0) // Don't flicker from previous position
|
||||
position = vec2(player.x, player.y);
|
||||
|
@ -1187,12 +1190,12 @@ static void render_player(const obj_player *prev_obj, const obj_player *player_o
|
|||
|
||||
if (player.weapon == WEAPON_HAMMER)
|
||||
{
|
||||
float a = clamp((client_tick()-player.attacktick+client_intratick())/10.0f, 0.0f, 1.0f);
|
||||
float a = clamp((client_tick()-player.attacktick+intratick)/10.0f, 0.0f, 1.0f);
|
||||
anim_eval_add(&state, &data->animations[ANIM_HAMMER_SWING], a, 1.0f);
|
||||
}
|
||||
if (player.weapon == WEAPON_NINJA)
|
||||
{
|
||||
float a = clamp((client_tick()-player.attacktick+client_intratick())/40.0f, 0.0f, 1.0f);
|
||||
float a = clamp((client_tick()-player.attacktick+intratick)/40.0f, 0.0f, 1.0f);
|
||||
anim_eval_add(&state, &data->animations[ANIM_NINJA_SWING], a, 1.0f);
|
||||
}
|
||||
|
||||
|
@ -1204,7 +1207,7 @@ static void render_player(const obj_player *prev_obj, const obj_player *player_o
|
|||
//gfx_quads_begin();
|
||||
|
||||
vec2 pos = position;
|
||||
vec2 hook_pos = mix(vec2(prev.hook_x, prev.hook_y), vec2(player.hook_x, player.hook_y), client_intratick());
|
||||
vec2 hook_pos = mix(vec2(prev.hook_x, prev.hook_y), vec2(player.hook_x, player.hook_y), intratick);
|
||||
|
||||
float d = distance(pos, hook_pos);
|
||||
vec2 dir = normalize(pos-hook_pos);
|
||||
|
@ -1302,7 +1305,7 @@ static void render_player(const obj_player *prev_obj, const obj_player *player_o
|
|||
{
|
||||
// TODO: should be an animation
|
||||
recoil = 0;
|
||||
float a = (client_tick()-player.attacktick+client_intratick())/5.0f;
|
||||
float a = (client_tick()-player.attacktick+intratick)/5.0f;
|
||||
if(a < 1)
|
||||
recoil = sinf(a*pi);
|
||||
p = position + dir * data->weapons[iw].offsetx - dir*recoil*10.0f;
|
||||
|
@ -1319,7 +1322,6 @@ static void render_player(const obj_player *prev_obj, const obj_player *player_o
|
|||
int phase1tick = (client_tick() - player.attacktick);
|
||||
if (phase1tick < (data->weapons[iw].muzzleduration + 3))
|
||||
{
|
||||
float intratick = client_intratick();
|
||||
float t = ((((float)phase1tick) + intratick)/(float)data->weapons[iw].muzzleduration);
|
||||
alpha = LERP(2.0, 0.0f, min(1.0f,max(0.0f,t)));
|
||||
}
|
||||
|
@ -1818,7 +1820,7 @@ void render_game()
|
|||
}
|
||||
}
|
||||
|
||||
local_player_pos = mix(predicted_prev_player.pos, predicted_player.pos, client_intratick());
|
||||
local_player_pos = mix(predicted_prev_player.pos, predicted_player.pos, client_intrapredtick());
|
||||
//local_player_pos = predicted_player.pos;
|
||||
|
||||
// everything updated, do events
|
||||
|
|
Loading…
Reference in a new issue