@@ -49,19 +49,21 @@ GC_Player::GC_Player()
4949 SetEvents (GC_FLAG_OBJECT_EVENTS_TS_FIXED);
5050
5151
52+
5253 // select nick from the random_names table
5354 lua_getglobal (g_env.L , " random_name" ); // push function
5455 lua_call (g_env.L , 0 , 1 ); // call it
5556 SetNick (lua_tostring (g_env.L , -1 )); // get value
5657 lua_pop (g_env.L , 1 ); // pop result
5758
59+ // !! avoid using net_rand in constructor since it may cause sync error
5860
59- // select random class
61+ // select first available class
6062 int count = 0 ;
6163 lua_getglobal (g_env.L , " classes" );
6264 for ( lua_pushnil (g_env.L ); lua_next (g_env.L , -2 ); lua_pop (g_env.L , 1 ) )
6365 {
64- if ( 0 == g_level->net_rand () % ++count )
66+ // if( 0 == g_level->net_rand() % ++count )
6567 {
6668 SetClass (lua_tostring (g_env.L , -2 )); // get vehicle class
6769 }
@@ -414,12 +416,25 @@ IMPLEMENT_SELF_REGISTRATION(GC_PlayerLocal)
414416}
415417
416418GC_PlayerLocal::GC_PlayerLocal ()
419+ : _lastLightKeyState(false )
420+ , _lights(true )
421+ , _aimToMouse(false )
417422{
418423 new GC_Camera (WrapRawPtr (this ));
419- _lastLightKeyState = false ;
420- _lights = true ;
421- _aimToMouse = false ;
424+ SelectFreeProfile ();
425+ }
426+
427+ GC_PlayerLocal::GC_PlayerLocal (FromFile)
428+ : GC_Player(FromFile())
429+ {
430+ }
431+
432+ GC_PlayerLocal::~GC_PlayerLocal ()
433+ {
434+ }
422435
436+ void GC_PlayerLocal::SelectFreeProfile ()
437+ {
423438 // find first available profile that is not used by another player
424439 string_t profile;
425440
@@ -448,15 +463,6 @@ GC_PlayerLocal::GC_PlayerLocal()
448463 SetProfile (" " ); // there was no available profile found
449464}
450465
451- GC_PlayerLocal::GC_PlayerLocal (FromFile)
452- : GC_Player(FromFile())
453- {
454- }
455-
456- GC_PlayerLocal::~GC_PlayerLocal ()
457- {
458- }
459-
460466void GC_PlayerLocal::Serialize (SaveFile &f)
461467{
462468 GC_Player::Serialize (f);
@@ -500,7 +506,7 @@ void GC_PlayerLocal::TimeStepFixed(float dt)
500506 if ( g_client )
501507 {
502508 g_client->SendControl (cp);
503- g_level->GetControlPacket ();
509+ g_level->GetControlPacket (this );
504510 }
505511 }
506512 else
@@ -537,10 +543,29 @@ void GC_PlayerLocal::TimeStepFixed(float dt)
537543
538544 cp.fromvs (vs);
539545 g_client->SendControl (cp);
540- cp = g_level->GetControlPacket ();
546+ cp = g_level->GetControlPacket (this );
541547 cp.tovs (vs);
542-
543548 GetVehicle ()->SetState (vs);
549+
550+
551+ //
552+ // auto adjust latency
553+ //
554+
555+ if ( !g_server && g_conf->sv_autoLatency ->Get () && g_conf->sv_latency ->GetInt () < g_conf->sv_fps ->GetInt () )
556+ {
557+ if ( (cp.wControlState & MISC_YOUARETHELAST) && g_level->_dropedFrames > g_conf->sv_fps ->GetInt () )
558+ {
559+ g_level->_dropedFrames = 0 ;
560+ g_conf->sv_latency ->SetInt (g_conf->sv_latency ->GetInt () + 1 );
561+ TRACE (" conf.sv_latency is set to %d\n " , g_conf->sv_latency ->GetInt ());
562+
563+ if ( g_conf->sv_latency ->GetInt () >= g_conf->sv_fps ->GetInt () )
564+ {
565+ TRACE (" WARNING: latency is too high to play\n " , g_conf->sv_latency ->GetInt ());
566+ }
567+ }
568+ }
544569 }
545570 else
546571 {
@@ -581,6 +606,8 @@ void GC_PlayerLocal::SetProfile(const string_t &name)
581606 }
582607 else
583608 {
609+ TRACE (" WARNING: profile '%s' not found\n " , name);
610+
584611 _keyForward = 0 ;
585612 _keyBack = 0 ;
586613 _keyLeft = 0 ;
@@ -595,8 +622,6 @@ void GC_PlayerLocal::SetProfile(const string_t &name)
595622 _lights = true ;
596623 _aimToMouse = false ;
597624 _moveToMouse = false ;
598-
599- TRACE (" WARNING: profile '%s' not found\n " , name);
600625 }
601626}
602627
@@ -790,11 +815,11 @@ void GC_PlayerRemote::TimeStepFixed(float dt)
790815 _ASSERT (g_client);
791816 if ( IsVehicleDead () )
792817 {
793- g_level->GetControlPacket ();
818+ g_level->GetControlPacket (this );
794819 }
795820 else
796821 {
797- ControlPacket cp = g_level->GetControlPacket ();
822+ ControlPacket cp = g_level->GetControlPacket (this );
798823 VehicleState vs;
799824 cp.tovs (vs);
800825 GetVehicle ()->SetState (vs);
0 commit comments