Beispiel #1
0
void CLevel::ProcessGameEvents		()
{
	// Game events
	{
		NET_Packet			P;
		u32 svT				= timeServer()-NET_Latency;

		/*
		if (!game_events->queue.empty())	
			Msg("- d[%d],ts[%d] -- E[svT=%d],[evT=%d]",Device.dwTimeGlobal,timeServer(),svT,game_events->queue.begin()->timestamp);
		*/
#ifdef   SPAWN_ANTIFREEZE
		while (spawn_events->available(svT))
		{
			u16 ID, dest, type;
			spawn_events->get(ID, dest, type, P);
			game_events->insert(P);
		}
		u32 avail_time = 5;
		u32 elps = Device.frame_elapsed();
		if (elps < 30) avail_time = 33 - elps;
		u32 work_limit = elps + avail_time;

#endif
		while	(game_events->available(svT))
		{
			u16 ID,dest,type;
			game_events->get	(ID,dest,type,P);

#ifdef   SPAWN_ANTIFREEZE
			// не отправлять события не заспавненным объектам
			if (g_bootComplete && M_EVENT == ID && PostponedSpawn(dest))
			{
				spawn_events->insert(P);
				continue;
			}
			if (g_bootComplete && M_SPAWN == ID && Device.frame_elapsed() > work_limit) // alpet: позволит плавнее выводить объекты в онлайн, без заметных фризов
			{
				u16 parent_id;
				GetSpawnInfo(P, parent_id);
				//-------------------------------------------------				
				if (parent_id < 0xffff) // откладывать спавн только объектов в контейнеры
				{
					//if (!spawn_events->available(svT))
						//Msg("* ProcessGameEvents, spawn event postponed. Events rest = %d", game_events->queue.size());

					spawn_events->insert(P);
					continue;
				}
			}
#endif
			switch (ID)
			{
			case M_SPAWN:
				{
					u16 dummy16;
					P.r_begin(dummy16);
					cl_Process_Spawn(P);
				}break;
			case M_EVENT:
				{
					cl_Process_Event(dest, type, P);
				}break;
			case M_MOVE_PLAYERS:
				{
					u8 Count = P.r_u8();
					for (u8 i=0; i<Count; i++)
					{
						u16 ID = P.r_u16();					
						Fvector NewPos, NewDir;
						P.r_vec3(NewPos);
						P.r_vec3(NewDir);

						CActor*	OActor	= smart_cast<CActor*>(Objects.net_Find		(ID));
						if (0 == OActor)		break;
						OActor->MoveActor(NewPos, NewDir);
					};

					NET_Packet PRespond;
					PRespond.w_begin(M_MOVE_PLAYERS_RESPOND);
					Send(PRespond, net_flags(TRUE, TRUE));
				}break;
			case M_STATISTIC_UPDATE:
				{
					if (GameID() != eGameIDSingle)
						Game().m_WeaponUsageStatistic->OnUpdateRequest(&P);
				}break;
			case M_FILE_TRANSFER:
				{
					if (m_file_transfer)			//in case of net_Stop
						m_file_transfer->on_message(&P);
				}break;
			case M_GAMEMESSAGE:
				{
					Game().OnGameMessage(P);
				}break;
			default:
				{
					VERIFY(0);
				}break;
			}			
		}
	}
	if (OnServer() && GameID()!= eGameIDSingle)
		Game().m_WeaponUsageStatistic->Send_Check_Respond();
}
Beispiel #2
0
void CLevel::ProcessGameEvents		()
{
	// Game events
	{
		NET_Packet			P;
		u32 svT				= timeServer()-NET_Latency;

		/*
		if (!game_events->queue.empty())	
			Msg("- d[%d],ts[%d] -- E[svT=%d],[evT=%d]",Device.dwTimeGlobal,timeServer(),svT,game_events->queue.begin()->timestamp);
		*/			
#ifdef   SPAWN_ANTIFREEZE
		while (spawn_events->available(svT))
		{
			u16 ID,dest,type;			
			spawn_events->get	(ID,dest,type,P);
			game_events->insert (P);
		}
		u32 avail_time = 5;
		u32 elps = Device.frame_elapsed();
		if (elps < 30) avail_time = 33 - elps;
		u32 work_limit = elps + avail_time;

#endif
		while	(game_events->available(svT)) 
		{
			u16 ID,dest,type;
			game_events->get	(ID,dest,type,P);		
#ifdef   SPAWN_ANTIFREEZE
			// не отправлять события не заспавненным объектам
			if (g_bootComplete && M_EVENT == ID && PostponedSpawn(dest))
			{
				spawn_events->insert(P);
				continue;
			}
			if (g_bootComplete && M_SPAWN == ID && Device.frame_elapsed() > work_limit) // alpet: позволит плавнее выводить объекты в онлайн, без заметных фризов
			{
				u16 parent_id;
				GetSpawnInfo(P, parent_id);				
				//-------------------------------------------------				
				if (parent_id < 0xffff) // откладывать спавн только объектов в контейнеры
				{
					if (!spawn_events->available(svT))
						Msg("* ProcessGameEvents, spawn event postponed. Events rest = %d", game_events->queue.size());					
					
					spawn_events->insert(P);					
					continue;
				}				
			}
#endif

			switch (ID)
			{
			case M_SPAWN:
				{
					u16 dummy16;
					P.r_begin(dummy16);
					cl_Process_Spawn(P);
				}break;
			case M_EVENT:
				{					
					cl_Process_Event(dest, type, P);
				}break;
			default:
				{
					VERIFY(0);
				}break;
			}		

		}

		
	}
	if (OnServer() && GameID()!= GAME_SINGLE)
		Game().m_WeaponUsageStatistic->Send_Check_Respond();
}