Exemple #1
0
void GameMode::HandleClientKeyInputs(const int clientIndex, float diff)
{
	//keep reading client inputs until the sum of all DT has exceeded server DT (->not allowed to move any more)
	Command* command = this->mNet->GetBall(clientIndex)->GetNextCommand();
	float duration = 0.0f;
	if(command != NULL)
	{
		duration = command->GetDuration();
		while(duration <=  diff && command != NULL)
		{
			this->mBalls[clientIndex]->SetForwardVector(command->GetForward());
			for(int c = 0; c < command->GetNumInputs(); c++)
			{
				this->ClientKeyPress(command->GetDuration(), clientIndex, command->GetInput(c));
			}
			this->mNet->GetBall(clientIndex)->SetExecTime(this->mNet->GetBall(clientIndex)->GetExecTime() + command->GetDuration());
			this->mNet->GetBall(clientIndex)->PopCommand();


			command = this->mNet->GetBall(clientIndex)->GetNextCommand();
			if(command != NULL)
				duration += command->GetDuration();
								
		}
		if(duration > diff && command != NULL)
		{
			this->mBalls[clientIndex]->SetForwardVector(command->GetForward());
			duration -= command->GetDuration();
									
			for(int c = 0; c < command->GetNumInputs(); c++)
			{
				//ADD A CHECK HERE SO THAT THE SAME KEY CANT APPEAR MORE THAN ONCE IN THE ARRAY (COULD CHEAT THE SYSTEM THIS WAY)
				
				this->ClientKeyPress((diff - duration), clientIndex, command->GetInput(c));
			}

			command->ModifyDuration(-(diff - duration));
								
			this->mNet->GetBall(clientIndex)->SetExecTime(this->mNet->GetBall(clientIndex)->GetExecTime() + (diff - duration));
		}
	}
}