Skip to content

Commit

Permalink
Network: consistent frame_time
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@3627 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Dwachs committed Aug 7, 2010
1 parent f043fbf commit 684ec55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions simworld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,7 @@ karte_t::karte_t() : convoi_array(0), ausflugsziele(16), stadt(0), marker(0,0)
step_mode = PAUSE_FLAG;
time_multiplier = 16;
next_step_time = last_step_time = 0;
fix_ratio_frame_time = 200;

for( uint i=0; i<MAX_PLAYER_COUNT; i++ ) {
werkzeug[i] = werkzeug_t::general_tool[WKZ_ABFRAGE];
Expand Down Expand Up @@ -4612,8 +4613,9 @@ void karte_t::reset_timer()
}
else if(step_mode==FIX_RATIO) {
last_frame_idx = 0;
next_step_time = last_tick_sync+( 1000/clamp(einstellungen->get_frames_per_second(),5,100) );
set_frame_time( 1000/clamp(einstellungen->get_frames_per_second(),5,100) );
fix_ratio_frame_time = 1000/clamp(einstellungen->get_frames_per_second(),5,100);
next_step_time = last_tick_sync + fix_ratio_frame_time;
set_frame_time( fix_ratio_frame_time );
intr_disable();
// other stuff needed to synchronize
tile_counter = 0;
Expand Down Expand Up @@ -5133,8 +5135,8 @@ void karte_t::network_game_set_pause(bool pause_, uint32 syncsteps_)
while( dr_time()<ms ) {
dr_sleep ( 10 );
}
reset_timer();
}
reset_timer();
}
}
else {
Expand Down Expand Up @@ -5170,7 +5172,6 @@ bool karte_t::interactive(uint32 quit_month)

// only needed for network
uint32 next_command_step = 0xFFFFFFFFu;
const uint32 frame_time = 1000/clamp(einstellungen->get_frames_per_second(),5,100);
sint32 ms_difference = 0;
reset_timer();

Expand Down Expand Up @@ -5281,7 +5282,7 @@ bool karte_t::interactive(uint32 quit_month)
nwc_check_t* nwcheck = (nwc_check_t*)nwc;
// are we on time?
ms_difference = 0;
sint64 difftime = ((sint64)next_step_time-(sint64)(dr_time())) + ((sint64)(nwcheck->server_sync_step)-(sint64)sync_steps-umgebung_t::server_frames_ahead)*frame_time - umgebung_t::server_ms_ahead;
sint64 difftime = ((sint64)next_step_time-(sint64)(dr_time())) + ((sint64)(nwcheck->server_sync_step)-(sint64)sync_steps-umgebung_t::server_frames_ahead)*fix_ratio_frame_time - umgebung_t::server_ms_ahead;
if( difftime < 0) {
// running ahead
next_step_time -= difftime;
Expand Down Expand Up @@ -5373,7 +5374,7 @@ bool karte_t::interactive(uint32 quit_month)
clear_random_mode( STEP_RANDOM );
}
else if( step_mode==FIX_RATIO ) {
next_step_time += frame_time;
next_step_time += fix_ratio_frame_time;
if( ms_difference>5 ) {
next_step_time -= 5;
ms_difference -= 5;
Expand All @@ -5382,7 +5383,7 @@ bool karte_t::interactive(uint32 quit_month)
next_step_time += 5;
ms_difference += 5;
}
sync_step( frame_time, true, true );
sync_step( fix_ratio_frame_time, true, true );
if( ++network_frame_count==einstellungen->get_frames_per_step() ) {
// ever fourth frame
set_random_mode( STEP_RANDOM );
Expand Down
1 change: 1 addition & 0 deletions simworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class karte_t
// Variables used in interactive()
uint32 sync_steps;
uint8 network_frame_count;
uint32 fix_ratio_frame_time; // set in reset_timer()

/**
* fuer performancevergleiche
Expand Down

0 comments on commit 684ec55

Please sign in to comment.