Exemple #1
0
//returns number of item chosen
int DoMenu() 
{
	int menu_choice[25];
	newmenu_item m[25];
	int num_options = 0;

	if ( Players[Player_num].callsign[0]==0 )	{
		RegisterPlayer();
		return 0;
	}
	
	if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM)) {
		do_option(MENU_START_SERIAL);
		return 0;
	}

	create_main_menu(m, menu_choice, &num_options);

	do {
		keyd_time_when_last_pressed = timer_get_fixed_seconds();		// .. 20 seconds from now!
		if (main_menu_choice < 0 )	main_menu_choice = 0;		
		Menu_draw_copyright = 1;
		main_menu_choice = newmenu_do2( "", NULL, num_options, m, autodemo_menu_check, main_menu_choice, Menu_pcx_name);
		if ( main_menu_choice > -1 ) do_option(menu_choice[main_menu_choice]);
		create_main_menu(m, menu_choice, &num_options);	//	may have to change, eg, maybe selected pilot and no save games.
	} while( Function_mode==FMODE_MENU );

//	if (main_menu_choice != -2)
//		do_auto_demo = 0;		// No more auto demos
	if ( Function_mode==FMODE_GAME )	
		gr_palette_fade_out( gr_palette, 32, 0 );

	return main_menu_choice;
}
Exemple #2
0
//returns number of item chosen
int DoMenu() 
{
	int menu_choice[25];
	newmenu_item m[25];
	int num_options = 0;

	if ( Players[Player_num].callsign[0]==0 )	{
		RegisterPlayer();
		return 0;
	}
	
	if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM)) {
		do_option(MENU_START_SERIAL);
		return 0;
	}

	create_main_menu(m, menu_choice, &num_options);

	do {
		keyd_time_when_last_pressed = timer_get_fixed_seconds();		// .. 20 seconds from now!
		if (main_menu_choice < 0 )	main_menu_choice = 0;		
		Menu_draw_copyright = 1;
                //added on 11/19/98 by Victor Rachels to add immediate join/start
                 if(start_net_immediately == 1){
					if ( gr_palette_faded_out )	{//fix black screen with -startnetgame
						gr_palette_fade_in( gr_palette, 32, 0 );
					}
                    do_option(MENU_START_NETGAME);
                    start_net_immediately = 0;
				 }
                 else if(start_net_immediately == 2)
                  {
                    do_option(MENU_JOIN_NETGAME);
                    start_net_immediately = 0;
                  }
                 else
                  {
                //end this section addition - VR
                   extern int Menu_Special;
                    Menu_Special = 1;
                    main_menu_choice = newmenu_do2(NULL, NULL, num_options, m, autodemo_menu_check, main_menu_choice, Menu_pcx_name);
                    if ( main_menu_choice > -1 ) do_option(menu_choice[main_menu_choice]);
                  }
		create_main_menu(m, menu_choice, &num_options);	//	may have to change, eg, maybe selected pilot and no save games.
	} while( Function_mode==FMODE_MENU );

//	if (main_menu_choice != -2)
//		do_auto_demo = 0;		// No more auto demos
	if ( Function_mode==FMODE_GAME )	
		gr_palette_fade_out( gr_palette, 32, 0 );

	return main_menu_choice;
}
Exemple #3
0
void WSServer::OnWebSocketMessage(ClientID client, const std::string& message)
{
	LOCK(m_mutex); // Only process 1 message at a time. 

	Player* player = nullptr;
	try 
	{
		if (const Input::MessagePtr pMsg = Input::CreateMessage(message))
		{
			if (auto pRegister = dynamic_cast<const Input::Register*>(pMsg.get()))
			{
				RegisterPlayer(client, Players::Get(pRegister->GetPlayerID()));
			}
			else
			{
				auto i = m_mapClientToPlayer.find(client);
				if (i != m_mapClientToPlayer.end())
				{
					player = i->second;
					m_controller.OnMessage(pMsg, *player);
				}
			}
		}
		else
			VERIFY_INPUT(false);
	}
	catch (Exception& e)
	{
		std::string error = GetErrorMessage(e.what(), client);
		std::cerr << error << std::endl;

		if (player)
		{
			if (const Game* game = player->GetCurrentGame())
			{
				m_controller.ClearQueuedMessages();
				//m_controller.SendUpdateGame(*game); // Uh oh! Can trigger exceptionception.
				m_controller.SendMessage(Output::AddLog(0, error), *game);
				m_controller.SendQueuedMessages();
			}
		}
	}

	if (player)
		SendMessage(Output::Response(), *player);
}
Exemple #4
0
//returns flag, true means quit menu
void do_option ( int select) 
{
	switch (select) {
		case MENU_NEW_GAME:
			do_new_game_menu();
			break;
		case MENU_GAME:
			break;
		case MENU_DEMO_PLAY:
			{ 
				char demo_file[16];
				if (newmenu_get_filename( TXT_SELECT_DEMO, "*.dem", demo_file, 1 ))	{
					newdemo_start_playback(demo_file);
				}
			}
			break;
		case MENU_LOAD_GAME:
#ifdef SHAREWARE
			do_load_game_menu();
#else
			state_restore_all(0);	
#endif
			break;
		#ifdef EDITOR
		case MENU_EDITOR:
			Function_mode = FMODE_EDITOR;
			init_cockpit();
			break;
		#endif
		case MENU_VIEW_SCORES:
			gr_palette_fade_out( gr_palette,32,0 );
			scores_view(-1);
			break;
		#ifdef SHAREWARE
		case MENU_ORDER_INFO:
			show_order_form();
			break;
		#endif
		case MENU_QUIT:
			#ifdef EDITOR
			if (! SafetyCheck()) break;
			#endif
			gr_palette_fade_out( gr_palette,32,0);
			Function_mode = FMODE_EXIT;
			break;
		case MENU_NEW_PLAYER:
			RegisterPlayer();		//1 == allow escape out of menu
			break;

		case MENU_HELP:
			do_show_help();
			break;

                #ifndef RELEASE

		case MENU_PLAY_SONG:	{
				int i;
				char * m[MAX_SONGS];

				for (i=0;i<MAX_SONGS;i++) {
					m[i] = Songs[i].filename;
				}
				i = newmenu_listbox( "Select Song", MAX_SONGS, m, 1, NULL );

				if ( i > -1 )	{
					songs_play_song( i, 0 );
				}
			}
			break;
		case MENU_LOAD_LEVEL: {
			newmenu_item m;
			char text[10]="";
			int new_level_num;

			m.type=NM_TYPE_INPUT; m.text_len = 10; m.text = text;

			newmenu_do( NULL, "Enter level to load", 1, &m, NULL );

			new_level_num = atoi(m.text);

			if (new_level_num!=0 && new_level_num>=Last_secret_level && new_level_num<=Last_level)	{
				gr_palette_fade_out( gr_palette, 32, 0 );
				StartNewGame(new_level_num);
			}

			break;
		}
                #endif


		case MENU_START_NETGAME:
#ifdef NETWORK
//temp!
#ifndef SHAREWARE
			load_mission(0);
#endif
                        read_player_file();
			network_start_game();
#endif
			break;
		case MENU_JOIN_NETGAME:
//temp!
#ifdef NETWORK
#ifndef SHAREWARE
			load_mission(0);
#endif
                        read_player_file();
			network_join_game();
#endif
			break;
#ifdef NETWORK
		case MENU_IPX_MULTIPLAYER:
			do_ipx_multi_player_menu();
			break;
		case MENU_KALI_MULTIPLAYER:
			do_kali_multi_player_menu();
			break;
#ifdef SUPPORTS_NET_IP
		case MENU_IP_MULTIPLAYER:
			do_ip_multi_player_menu();
			break;
		case MENU_IP_SERV_CONNECT:
			do_ip_serv_connect_menu();
			break;
		case MENU_MANUAL_IP_JOIN:
			do_ip_manual_join_menu();
			break;
#endif
		case MENU_START_SERIAL:
			com_main_menu();
			break;
		case MENU_MULTIPLAYER:
			do_multi_player_menu();
			break;
#endif //NETWORK
		case MENU_CONFIG:
			do_options_menu();
			break;
		case MENU_SHOW_CREDITS:
			gr_palette_fade_out( gr_palette,32,0);
			credits_show();	
			break;
		default:
			Error("Unknown option %d in do_option",select);
			break;
        }

}
void CLightsyncManager::DoPulse ()
{
    // The point of this method is to get all players that should receive right now the lightweight
    // sync from all the other players. To make this efficient, we are using a queue in what the
    // players at the front have are more inminent to receive this sync. As all players have the same
    // far sync rate, just taking the players from the front, processing them  and pushing them to the
    // back will keep the order of priority to be processed.
    //
    // We also want to perform delta sync on stuff like the health, but it would require to know the last
    // value synced from every player to every player, because we are getting players from the front and
    // sending them all the other players data. This would be crazily inefficient and would require a lot
    // of mainteinance, so we will leave special entries in the queue to mark in what moment a player
    // health changed. This way, we will force the health sync for that player until the queue cycle
    // reaches that special entry again. As there might be multiple changes in a complete queue cycle, we
    // are also storing the delta context in what it happened, so we only consider the health unchanged
    // when we find the marker with the same context value.

    if ( g_pBandwidthSettings->bLightSyncEnabled == false )
        return;

    // For counting stats
    long iPacketsSent = 0;
    long iBitsSent = 0;

    // For limiting light sync processing
    long iLimitCounter = Max < uint > ( 10, g_pGame->GetPlayerManager ()->Count () / 25 );
    int iLightsyncRate = g_TickRateSettings.iLightSync;
    long long llTickCountNow = GetTickCount64_ ();
    while ( m_Queue.size() > 0 && m_Queue.front().ullTime + iLightsyncRate <= llTickCountNow && iLimitCounter > 0 )
    {
        SEntry entry = m_Queue.front ();
        m_Queue.pop_front ();

        CPlayer* pPlayer = entry.pPlayer;
        CPlayer::SLightweightSyncData& data = pPlayer->GetLightweightSyncData ();

        switch ( entry.eType )
        {
            case SYNC_PLAYER:
            {
                CLightsyncPacket packet;

                // Use this players far list
                const SViewerMapType& farList = pPlayer->GetFarPlayerList ();

                // For each far player
                for ( SViewerMapType ::const_iterator it = farList.begin (); it != farList.end (); ++it )
                {
                    CPlayer* pCurrent = it->first;
                    dassert ( pPlayer != pCurrent );

                    // Only send if he isn't network troubled.
                    if ( pCurrent->UhOhNetworkTrouble ( ) == false )
                    {
                        CPlayer::SLightweightSyncData& currentData = pCurrent->GetLightweightSyncData ();
                        packet.AddPlayer ( pCurrent );

                        // Calculate the delta sync
                        if ( fabs(currentData.health.fLastHealth - pCurrent->GetHealth()) > LIGHTSYNC_HEALTH_THRESHOLD ||
                             fabs(currentData.health.fLastArmor - pCurrent->GetArmor()) > LIGHTSYNC_HEALTH_THRESHOLD )
                        {
                            currentData.health.fLastHealth = pCurrent->GetHealth ();
                            currentData.health.fLastArmor = pCurrent->GetArmor ();
                            currentData.health.bSync = true;
                            currentData.health.uiContext++;

                            // Generate the health marker
                            SEntry marker;
                            marker.ullTime = 0;
                            marker.pPlayer = pCurrent;
                            marker.eType = DELTA_MARKER_HEALTH;
                            marker.uiContext = currentData.health.uiContext;
                            m_Queue.push_back ( marker );
                        }

                        CVehicle* pVehicle = pCurrent->GetOccupiedVehicle ();
                        if ( pVehicle && pCurrent->GetOccupiedVehicleSeat() == 0 )
                        {
                            if ( currentData.vehicleHealth.lastVehicle != pVehicle ||
                                 fabs(currentData.vehicleHealth.fLastHealth - pVehicle->GetHealth ()) > LIGHTSYNC_VEHICLE_HEALTH_THRESHOLD )
                            {
                                currentData.vehicleHealth.fLastHealth = pVehicle->GetHealth ();
                                currentData.vehicleHealth.lastVehicle = pVehicle;
                                currentData.vehicleHealth.bSync = true;
                                currentData.vehicleHealth.uiContext++;

                                // Generate the vehicle health marker
                                SEntry marker;
                                marker.ullTime = 0;
                                marker.pPlayer = pCurrent;
                                marker.eType = DELTA_MARKER_VEHICLE_HEALTH;
                                marker.uiContext = currentData.vehicleHealth.uiContext;
                                m_Queue.push_back ( marker );
                            }
                        }

                        if ( packet.Count () == LIGHTSYNC_MAX_PLAYERS )
                        {
                            iBitsSent += pPlayer->Send ( packet );
                            iPacketsSent++;
                            packet.Reset ();
                        }
                    }
                }

                if ( packet.Count () > 0 )
                {
                    iBitsSent += pPlayer->Send ( packet );
                    iPacketsSent++;
                }

                RegisterPlayer ( pPlayer );
                iLimitCounter--;
                break;
            }

            case DELTA_MARKER_HEALTH:
            {
                if ( data.health.uiContext == entry.uiContext )
                    data.health.bSync = false;

                break;
            }

            case DELTA_MARKER_VEHICLE_HEALTH:
            {
                if ( data.vehicleHealth.uiContext == entry.uiContext )
                    data.vehicleHealth.bSync = false;

                break;
            }
        }
    }

    // Update stats
    g_pStats->lightsync.llLightSyncPacketsSent += iPacketsSent;
    g_pStats->lightsync.llLightSyncBytesSent += iBitsSent / 8;

    // Subtract lightsync usage from skipped accumulators
    g_pStats->lightsync.llSyncPacketsSkipped -= iPacketsSent;
    g_pStats->lightsync.llSyncBytesSkipped -= iBitsSent / 8;
}