Beispiel #1
0
  static void many_sub_pause_phases() {
    TimePartitions time_partitions;
    time_partitions.report_gc_phase_start("PausePhase", 2);

    time_partitions.report_gc_phase_start("SubPhase1", 3);
    time_partitions.report_gc_phase_end(4);
    time_partitions.report_gc_phase_start("SubPhase2", 5);
    time_partitions.report_gc_phase_end(6);
    time_partitions.report_gc_phase_start("SubPhase3", 7);
    time_partitions.report_gc_phase_end(8);
    time_partitions.report_gc_phase_start("SubPhase4", 9);
    time_partitions.report_gc_phase_end(10);

    time_partitions.report_gc_phase_end(11);

    TimePartitionPhasesIterator iter(&time_partitions);

    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 11);
    validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 4);
    validate_gc_phase(iter.next(), 1, "SubPhase2", 5, 6);
    validate_gc_phase(iter.next(), 1, "SubPhase3", 7, 8);
    validate_gc_phase(iter.next(), 1, "SubPhase4", 9, 10);

    assert(time_partitions.sum_of_pauses() == Ticks(9) - Ticks(0), "Incorrect");
    assert(time_partitions.longest_pause() == Ticks(9) - Ticks(0), "Incorrect");

    assert(!iter.has_next(), "Too many elements");
  }
Beispiel #2
0
void HumanClientApp::RequestSavePreviews(const std::string& directory, PreviewInformation& previews){
    std::string  generic_directory = fs::path(directory).generic_string();
    if(!m_networking.Connected()){
        DebugLogger() << "HumanClientApp::RequestSavePreviews: No game running. Start a server for savegame queries.";
        StartServer();

        DebugLogger() << "HumanClientApp::RequestSavePreviews Connecting to server";
        unsigned int start_time = Ticks();
        while (!m_networking.ConnectToLocalHostServer()) {
            if (SERVER_CONNECT_TIMEOUT < Ticks() - start_time) {
                ErrorLogger() << "HumanClientApp::LoadSinglePlayerGame() server connecting timed out";
                ClientUI::MessageBox(UserString("ERR_CONNECT_TIMED_OUT"), true);
                KillServer();
                return;
            }
        }
        m_connected = true;
    }
    DebugLogger() << "HumanClientApp::RequestSavePreviews Requesting previews for " << generic_directory;
    Message response;
    m_networking.SendSynchronousMessage(RequestSavePreviewsMessage(PlayerID(), generic_directory), response);
    if (response.Type() == Message::DISPATCH_SAVE_PREVIEWS){
        ExtractMessageData(response, previews);
        DebugLogger() << "HumanClientApp::RequestSavePreviews Got " << previews.previews.size() << " previews.";
    }else{
        ErrorLogger() << "HumanClientApp::RequestSavePreviews: Wrong response type from server: " << EnumToString(response.Type());
    }
}
Beispiel #3
0
void XWindow::Start()
{
  int64_t previous = Ticks();
  int64_t updateLag = 0;
  int64_t renderLag = 0;
  while (!m_asked_to_stop) {
    int64_t current = Ticks();
    int64_t elapsed = current - previous;
    previous = current;
    updateLag += elapsed;
    renderLag += elapsed;
    int64_t wait_time = std::min(TicksPerFrame() - renderLag, TicksPerUpdate() - updateLag);
    if (wait_time > 0) {
      int64_t wait_started = Ticks();
      while (Ticks() < wait_started + wait_time) {
        // active waiting
      }
    }
    while (updateLag >= TicksPerUpdate()) {
      Update();
      HandleInput();
      updateLag -= TicksPerUpdate();
    }
    if (renderLag >= TicksPerFrame()) {
      Render(1.0 * updateLag / TicksPerUpdate());
      XFlush(m_pDisplay);
      renderLag = 0;
    }
  }
}
Beispiel #4
0
  static void one_pause() {
    TimePartitions time_partitions;
    time_partitions.report_gc_phase_start("PausePhase", 2);
    time_partitions.report_gc_phase_end(8);

    TimePartitionPhasesIterator iter(&time_partitions);

    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 8);
    assert(time_partitions.sum_of_pauses() == Ticks(8) - Ticks(2), "Incorrect");
    assert(time_partitions.longest_pause() == Ticks(8) - Ticks(2), "Incorrect");

    assert(!iter.has_next(), "Too many elements");
  }
Beispiel #5
0
void HumanClientApp::MultiPlayerGame() {
    if (m_networking.Connected()) {
        ErrorLogger() << "HumanClientApp::MultiPlayerGame aborting because already connected to a server";
        return;
    }

    ServerConnectWnd server_connect_wnd;
    server_connect_wnd.Run();

    std::string server_name = server_connect_wnd.Result().second;

    if (server_name.empty())
        return;

    if (server_name == "HOST GAME SELECTED") {
        if (!GetOptionsDB().Get<bool>("force-external-server")) {
            try {
                StartServer();
                FreeServer();
            } catch (const std::runtime_error& err) {
                ErrorLogger() << "Couldn't start server.  Got error message: " << err.what();
                ClientUI::MessageBox(UserString("SERVER_WONT_START"), true);
                return;
            }
            server_name = "localhost";
        }
        server_name = GetOptionsDB().Get<std::string>("external-server-address");
    }

    unsigned int start_time = Ticks();
    while (!m_networking.ConnectToServer(server_name, boost::posix_time::seconds(2))) {
        if (SERVER_CONNECT_TIMEOUT < Ticks() - start_time) {
            ClientUI::MessageBox(UserString("ERR_CONNECT_TIMED_OUT"), true);
            if (server_connect_wnd.Result().second == "HOST GAME SELECTED")
                KillServer();
            return;
        }
    }

    if (server_connect_wnd.Result().second == "HOST GAME SELECTED") {
        m_networking.SendMessage(HostMPGameMessage(server_connect_wnd.Result().first));
        m_fsm->process_event(HostMPGameRequested());
    } else {
        m_networking.SendMessage(JoinGameMessage(server_connect_wnd.Result().first, Networking::CLIENT_TYPE_HUMAN_PLAYER));
        m_fsm->process_event(JoinMPGameRequested());
    }
    m_connected = true;
}
Beispiel #6
0
//******************************************************************************
void OSF1Timer::StopTimer()
{
    if(!getIsRunning())
        return;

    gettimeofday(&StopTime,NULL);

    setIsRunning(false);

    AddToCumulativeTime(Ticks());
}
Beispiel #7
0
  static void many_sub_pause_phases2() {
    TimePartitions time_partitions;
    time_partitions.report_gc_phase_start("PausePhase", 2);

    time_partitions.report_gc_phase_start("SubPhase1", 3);
    time_partitions.report_gc_phase_start("SubPhase11", 4);
    time_partitions.report_gc_phase_end(5);
    time_partitions.report_gc_phase_start("SubPhase12", 6);
    time_partitions.report_gc_phase_end(7);
    time_partitions.report_gc_phase_end(8);
    time_partitions.report_gc_phase_start("SubPhase2", 9);
    time_partitions.report_gc_phase_start("SubPhase21", 10);
    time_partitions.report_gc_phase_end(11);
    time_partitions.report_gc_phase_start("SubPhase22", 12);
    time_partitions.report_gc_phase_end(13);
    time_partitions.report_gc_phase_end(14);
    time_partitions.report_gc_phase_start("SubPhase3", 15);
    time_partitions.report_gc_phase_end(16);

    time_partitions.report_gc_phase_end(17);

    TimePartitionPhasesIterator iter(&time_partitions);

    validate_gc_phase(iter.next(), 0, "PausePhase", 2, 17);
    validate_gc_phase(iter.next(), 1, "SubPhase1", 3, 8);
    validate_gc_phase(iter.next(), 2, "SubPhase11", 4, 5);
    validate_gc_phase(iter.next(), 2, "SubPhase12", 6, 7);
    validate_gc_phase(iter.next(), 1, "SubPhase2", 9, 14);
    validate_gc_phase(iter.next(), 2, "SubPhase21", 10, 11);
    validate_gc_phase(iter.next(), 2, "SubPhase22", 12, 13);
    validate_gc_phase(iter.next(), 1, "SubPhase3", 15, 16);

    assert(time_partitions.sum_of_pauses() == Ticks(15) - Ticks(0), "Incorrect");
    assert(time_partitions.longest_pause() == Ticks(15) - Ticks(0), "Incorrect");

    assert(!iter.has_next(), "Too many elements");
  }
//*****************************************************************************
void PerformanceTimer::StreamTimer(ostream & stream) const
{

    //Downshift to double as HP can't stream a long double.  Should still provide
    //the necessary resolution (overflow is very unlikely)
    double Time = (double)(Ticks() / TicksPerSec());
    stream.width(12);
    stream << Time << " seconds" << "\t\t";
    Time = (double)(TotalTicks() / TicksPerSec());
    stream.width(12);
    stream << Time << " seconds (cumulative)" << "\t\t" << Invocations() << " Runs";
    if (getIsRunning())
    {
        stream << ",RUNNING";
    }

}
Beispiel #9
0
result_t console_base::timeEnd(const char *label)
{
    long t = (long) (Ticks() - s_timers[label]);

    s_timers.erase(label);

    std::string strBuffer;
    char numStr[64];

    sprintf(numStr, "%.3g", t / 1000.0);

    strBuffer.append(label);
    strBuffer.append(": ", 2);
    strBuffer.append(numStr);
    strBuffer.append("ms", 2);

    asyncLog(_INFO, strBuffer);
    return 0;
}
Beispiel #10
0
result_t console_base::timeEnd(exlib::string label)
{
    int64_t t = Ticks() - s_timers[label];

    s_timers.erase(label);

    exlib::string strBuffer;
    char numStr[64];

    sprintf(numStr, "%.10g", t / 1000.0);

    strBuffer.append(label);
    strBuffer.append(": ", 2);
    strBuffer.append(numStr);
    strBuffer.append("ms", 2);

    asyncLog(_INFO, strBuffer);
    return 0;
}
Beispiel #11
0
void CommandParser::start()
{

    Vector< String > args;
    help( args);
    char buf[2000];

    while (true)
    {
        printf("%s > ",FileSystem::path().data());
        String line(Terminal::readLine(buf));
        Vector< String > args = line.split(' ');
        if (args.isEmpty())
            continue;
        String command = args[0];

        if (command == String("time"))
            Ticks(args);
        else if (command == String("ram"))
            Ram(args);
        else if (command == String("cls"))
            ClearScreen(args);
        else if (command == String("ls"))
            ListOfFiles(args);
        else if (command == String("cd"))
            ChangeDirectory(args);
        else if (command == String("read"))
            ReadFile(args);
        else if (command == String("reboot"))
            reboot(args);
        else if (command == String("help"))
            help(args);
        else if (command == String("wait"))
            wait(args);
        else
            Unknown(args);
    }
}
Beispiel #12
0
void HumanClientApp::LoadSinglePlayerGame(std::string filename/* = ""*/) {
    DebugLogger() << "HumanClientApp::LoadSinglePlayerGame";

    if (!filename.empty()) {
        if (!exists(FilenameToPath(filename))) {
            std::string msg = "HumanClientApp::LoadSinglePlayerGame() given a nonexistent file \""
                            + filename + "\" to load; aborting.";
            DebugLogger() << msg;
            std::cerr << msg << '\n';
            abort();
        }
    } else {
        try {
            SaveFileDialog sfd(SP_SAVE_FILE_EXTENSION, true);
            sfd.Run();
            if (!sfd.Result().empty())
                filename = sfd.Result();
        } catch (const std::exception& e) {
            ClientUI::MessageBox(e.what(), true);
        }
    }

    if (filename.empty()) {
        DebugLogger() << "HumanClientApp::LoadSinglePlayerGame has empty filename. Aborting load.";
        return;
    }

    // end any currently-playing game before loading new one
    if (m_game_started) {
        EndGame();
        // delay to make sure old game is fully cleaned up before attempting to start a new one
        boost::this_thread::sleep(boost::posix_time::seconds(3));
    } else {
        DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() not already in a game, so don't need to end it";
    }

    if (!GetOptionsDB().Get<bool>("force-external-server")) {
        DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Starting server";
        StartServer();
        DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Server started";
    } else {
        DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() assuming external server will be available";
    }

    DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Connecting to server";
    unsigned int start_time = Ticks();
    while (!m_networking.ConnectToLocalHostServer()) {
        if (SERVER_CONNECT_TIMEOUT < Ticks() - start_time) {
            ErrorLogger() << "HumanClientApp::LoadSinglePlayerGame() server connecting timed out";
            ClientUI::MessageBox(UserString("ERR_CONNECT_TIMED_OUT"), true);
            KillServer();
            return;
        }
    }

    DebugLogger() << "HumanClientApp::LoadSinglePlayerGame() Connected to server";

    m_connected = true;
    m_networking.SetPlayerID(Networking::INVALID_PLAYER_ID);
    m_networking.SetHostPlayerID(Networking::INVALID_PLAYER_ID);
    SetEmpireID(ALL_EMPIRES);

    SinglePlayerSetupData setup_data;
    // leving GalaxySetupData information default / blank : not used when loading a game
    setup_data.m_new_game = false;
    setup_data.m_filename = filename;
    // leving setup_data.m_players empty : not specified when loading a game, as server will generate from save file


    m_networking.SendMessage(HostSPGameMessage(setup_data));
    m_fsm->process_event(HostSPGameRequested());
}
Beispiel #13
0
void HumanClientApp::NewSinglePlayerGame(bool quickstart) {
    if (!GetOptionsDB().Get<bool>("force-external-server")) {
        try {
            StartServer();
        } catch (const std::runtime_error& err) {
            ErrorLogger() << "HumanClientApp::NewSinglePlayerGame : Couldn't start server.  Got error message: " << err.what();
            ClientUI::MessageBox(UserString("SERVER_WONT_START"), true);
            return;
        }
    }

    bool ended_with_ok = false;
    if (!quickstart) {
        GalaxySetupWnd galaxy_wnd;
        galaxy_wnd.Run();
        ended_with_ok = galaxy_wnd.EndedWithOk();
    }

    bool failed = false;
    unsigned int start_time = Ticks();
    while (!m_networking.ConnectToLocalHostServer(boost::posix_time::seconds(2))) {
        if (SERVER_CONNECT_TIMEOUT < Ticks() - start_time) {
            ClientUI::MessageBox(UserString("ERR_CONNECT_TIMED_OUT"), true);
            failed = true;
            break;
        }
    }
    m_connected = !failed;
    if (!failed && (quickstart || ended_with_ok)) {
        DebugLogger() << "HumanClientApp::NewSinglePlayerGame : Connected to server";

        SinglePlayerSetupData setup_data;
        setup_data.m_new_game = true;
        setup_data.m_filename.clear();  // not used for new game

        // get values stored in options from previous time game was run or
        // from just having run GalaxySetupWnd

        // GalaxySetupData
        setup_data.m_seed =             GetOptionsDB().Get<std::string>("GameSetup.seed");
        setup_data.m_size =             GetOptionsDB().Get<int>("GameSetup.stars");
        setup_data.m_shape =            GetOptionsDB().Get<Shape>("GameSetup.galaxy-shape");
        setup_data.m_age =              GetOptionsDB().Get<GalaxySetupOption>("GameSetup.galaxy-age");
        setup_data.m_starlane_freq =    GetOptionsDB().Get<GalaxySetupOption>("GameSetup.starlane-frequency");
        setup_data.m_planet_density =   GetOptionsDB().Get<GalaxySetupOption>("GameSetup.planet-density");
        setup_data.m_specials_freq =    GetOptionsDB().Get<GalaxySetupOption>("GameSetup.specials-frequency");
        setup_data.m_monster_freq =     GetOptionsDB().Get<GalaxySetupOption>("GameSetup.monster-frequency");
        setup_data.m_native_freq =      GetOptionsDB().Get<GalaxySetupOption>("GameSetup.native-frequency");
        setup_data.m_ai_aggr =          GetOptionsDB().Get<Aggression>("GameSetup.ai-aggression");

        // SinglePlayerSetupData contains a map of PlayerSetupData, for
        // the human and AI players.  Need to compile this information
        // from the specified human options and number of requested AIs

        // Human player setup data first

        PlayerSetupData human_player_setup_data;
        human_player_setup_data.m_player_name = GetOptionsDB().Get<std::string>("GameSetup.player-name");
        human_player_setup_data.m_empire_name = GetOptionsDB().Get<std::string>("GameSetup.empire-name");

        // DB stores index into array of available colours, so need to get that array to look up value of index.
        // if stored value is invalid, use a default colour
        const std::vector<GG::Clr>& empire_colours = EmpireColors();
        int colour_index = GetOptionsDB().Get<int>("GameSetup.empire-color");
        if (colour_index >= 0 && colour_index < static_cast<int>(empire_colours.size()))
            human_player_setup_data.m_empire_color = empire_colours[colour_index];
        else
            human_player_setup_data.m_empire_color = GG::CLR_GREEN;

        human_player_setup_data.m_starting_species_name = GetOptionsDB().Get<std::string>("GameSetup.starting-species");
        if (human_player_setup_data.m_starting_species_name == "1")
            human_player_setup_data.m_starting_species_name = "SP_HUMAN";   // kludge / bug workaround for bug with options storage and retreival.  Empty-string options are stored, but read in as "true" boolean, and converted to string equal to "1"

        if (!GetSpecies(human_player_setup_data.m_starting_species_name)) {
            const SpeciesManager& sm = GetSpeciesManager();
            if (sm.NumPlayableSpecies() < 1)
                human_player_setup_data.m_starting_species_name.clear();
            else
                human_player_setup_data.m_starting_species_name = sm.playable_begin()->first;
            }

        human_player_setup_data.m_save_game_empire_id = ALL_EMPIRES; // not used for new games
        human_player_setup_data.m_client_type = Networking::CLIENT_TYPE_HUMAN_PLAYER;

        // add to setup data players
        setup_data.m_players.push_back(human_player_setup_data);

        // AI player setup data.  One entry for each requested AI

        int num_AIs = GetOptionsDB().Get<int>("GameSetup.ai-players");
        for (int ai_i = 1; ai_i <= num_AIs; ++ai_i) {
            PlayerSetupData ai_setup_data;

            ai_setup_data.m_player_name = "AI_" + boost::lexical_cast<std::string>(ai_i);
            ai_setup_data.m_empire_name.clear();                // leave blank, to be set by server in Universe::GenerateEmpires
            ai_setup_data.m_empire_color = GG::CLR_ZERO;        // to be set by server
            ai_setup_data.m_starting_species_name.clear();      // leave blank, to be set by server
            ai_setup_data.m_save_game_empire_id = ALL_EMPIRES;  // not used for new games
            ai_setup_data.m_client_type = Networking::CLIENT_TYPE_AI_PLAYER;

            setup_data.m_players.push_back(ai_setup_data);
        }

        m_networking.SendMessage(HostSPGameMessage(setup_data));
        m_fsm->process_event(HostSPGameRequested());
    } else {
        DebugLogger() << "HumanClientApp::NewSinglePlayerGame killing server due to canceled game or server connection failure";
        if (m_networking.Connected()) {
            DebugLogger() << "HumanClientApp::NewSinglePlayerGame Sending server shutdown message.";
            m_networking.SendMessage(ShutdownServerMessage(m_networking.PlayerID()));
            boost::this_thread::sleep(boost::posix_time::seconds(1));
            m_networking.DisconnectFromServer();
            if (!m_networking.Connected())
                DebugLogger() << "HumanClientApp::NewSinglePlayerGame Disconnected from server.";
            else
                ErrorLogger() << "HumanClientApp::NewSinglePlayerGame Unexpectedly still connected to server...?";
        }
        KillServer();
    }
}
Beispiel #14
0
/**
*  Restart the timer and return the elapsed ticks
*  @return The elapsed ticks
*/
int Timer::Restart(){
	int elapsedTicks = Ticks();
	Start();
	return elapsedTicks;
}
Beispiel #15
0
result_t console_base::time(const char *label)
{
    s_timers[std::string(label)] = Ticks();

    return 0;
}
Beispiel #16
0
result_t console_base::time(exlib::string label)
{
    s_timers[exlib::string(label)] = Ticks();

    return 0;
}