Browse Source

output_times is now database-specific.

pull/3/head
Jessica James 9 years ago
parent
commit
294f8a6a22
  1. BIN
      Release/Plugins/RenX.Core.lib
  2. 16
      RenX.Core/RenX_LadderDatabase.cpp
  3. 19
      RenX.Core/RenX_LadderDatabase.h
  4. 3
      RenX.Ladder.All-Time/RenX_Ladder_All_Time.cpp
  5. 3
      RenX.Ladder.Daily/RenX_Ladder_Daily.cpp
  6. 2
      RenX.Ladder.Daily/RenX_Ladder_Daily.h
  7. 3
      RenX.Ladder.Monthly/RenX_Ladder_Monthly.cpp
  8. 2
      RenX.Ladder.Monthly/RenX_Ladder_Monthly.h
  9. 3
      RenX.Ladder.Weekly/RenX_Ladder_Weekly.cpp
  10. 2
      RenX.Ladder.Weekly/RenX_Ladder_Weekly.h
  11. 3
      RenX.Ladder.Yearly/RenX_Ladder_Yearly.cpp
  12. 2
      RenX.Ladder.Yearly/RenX_Ladder_Yearly.h
  13. 3
      RenX.Ladder/RenX_Ladder.cpp
  14. 2
      RenX.Ladder/RenX_Ladder.h

BIN
Release/Plugins/RenX.Core.lib

Binary file not shown.

16
RenX.Core/RenX_LadderDatabase.cpp

@ -391,13 +391,13 @@ void RenX::LadderDatabase::sort_entries()
RenX::LadderDatabase::last_sort = std::chrono::steady_clock::now(); RenX::LadderDatabase::last_sort = std::chrono::steady_clock::now();
} }
void RenX::LadderDatabase::updateLadder(RenX::Server *server, const RenX::TeamType &team, bool output_times) void RenX::LadderDatabase::updateLadder(RenX::Server *server, const RenX::TeamType &team)
{ {
if (server->players.size() != server->getBotCount()) if (server->players.size() != server->getBotCount())
{ {
// call the PreUpdateLadder event // call the PreUpdateLadder event
if (this->OnPreUpdateLadder != nullptr) if (this->OnPreUpdateLadder != nullptr)
this->OnPreUpdateLadder(*this, server, team, output_times); this->OnPreUpdateLadder(*this, server, team);
// update player stats in memory // update player stats in memory
RenX::PlayerInfo *player; RenX::PlayerInfo *player;
@ -484,7 +484,7 @@ void RenX::LadderDatabase::updateLadder(RenX::Server *server, const RenX::TeamTy
RenX::LadderDatabase::write(this->getFilename()); RenX::LadderDatabase::write(this->getFilename());
std::chrono::steady_clock::duration write_duration = std::chrono::steady_clock::now() - start_time; std::chrono::steady_clock::duration write_duration = std::chrono::steady_clock::now() - start_time;
if (output_times) if (RenX::LadderDatabase::output_times)
{ {
Jupiter::StringS str = Jupiter::StringS::Format("Ladder: %u entries sorted in %f seconds; Database written in %f seconds." ENDL, Jupiter::StringS str = Jupiter::StringS::Format("Ladder: %u entries sorted in %f seconds; Database written in %f seconds." ENDL,
RenX::LadderDatabase::getEntries(), RenX::LadderDatabase::getEntries(),
@ -520,3 +520,13 @@ void RenX::LadderDatabase::setName(const Jupiter::ReadableString &in_name)
{ {
RenX::LadderDatabase::name = in_name; RenX::LadderDatabase::name = in_name;
} }
bool RenX::LadderDatabase::getOutputTimes() const
{
return RenX::LadderDatabase::output_times;
}
void RenX::LadderDatabase::setOutputTimes(bool in_output_times)
{
RenX::LadderDatabase::output_times = in_output_times;
}

19
RenX.Core/RenX_LadderDatabase.h

@ -168,7 +168,7 @@ namespace RenX
* @param team Team which just won * @param team Team which just won
* @param output_times True if the sort/write times should be output, false otherwise. * @param output_times True if the sort/write times should be output, false otherwise.
*/ */
void updateLadder(RenX::Server *server, const RenX::TeamType &team, bool output_times); void updateLadder(RenX::Server *server, const RenX::TeamType &team);
/** /**
* @brief Erases all entries in the database. * @brief Erases all entries in the database.
@ -185,6 +185,20 @@ namespace RenX
*/ */
void setName(const Jupiter::ReadableString &in_name); void setName(const Jupiter::ReadableString &in_name);
/**
* @brief Checks if this database outputs sort/write times when 'updateLadder' is called.
*
* @return True if output times get printed, false otherwise.
*/
bool getOutputTimes() const;
/**
* @brief Sets this database to output sort/write times, or to not output sort/write times.
*
* @param in_output_times True to output sort/write times, false otherwise.
*/
void setOutputTimes(bool in_output_times);
/** /**
* @brief Constructor for the LadderDatabase class * @brief Constructor for the LadderDatabase class
*/ */
@ -200,7 +214,7 @@ namespace RenX
*/ */
~LadderDatabase(); ~LadderDatabase();
typedef void PreUpdateLadderFunction(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); typedef void PreUpdateLadderFunction(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team);
PreUpdateLadderFunction *OnPreUpdateLadder = nullptr; PreUpdateLadderFunction *OnPreUpdateLadder = nullptr;
private: private:
@ -208,6 +222,7 @@ namespace RenX
const uint8_t write_version = 0; const uint8_t write_version = 0;
uint8_t read_version = write_version; uint8_t read_version = write_version;
bool output_times = false;
Jupiter::StringS name; Jupiter::StringS name;
std::chrono::steady_clock::time_point last_sort = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point last_sort = std::chrono::steady_clock::now();
size_t entries = 0; size_t entries = 0;

3
RenX.Ladder.All-Time/RenX_Ladder_All_Time.cpp

@ -27,9 +27,10 @@ RenX_Ladder_All_TimePlugin::RenX_Ladder_All_TimePlugin()
// Load database // Load database
this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.db"_jrs)); this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.db"_jrs));
this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "All-Time"_jrs)); this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "All-Time"_jrs));
this->database.setOutputTimes(Jupiter::IRC::Client::Config->getBool(this->getName(), "OutputTimes"_jrs, true));
// Force database to default, if desired // Force database to default, if desired
if (Jupiter::IRC::Client::Config->getBool(this->getName(), "ForceDefault"_jrs, false)) if (Jupiter::IRC::Client::Config->getBool(this->getName(), "ForceDefault"_jrs, true))
RenX::default_ladder_database = &this->database; RenX::default_ladder_database = &this->database;
} }

3
RenX.Ladder.Daily/RenX_Ladder_Daily.cpp

@ -28,6 +28,7 @@ RenX_Ladder_Daily_TimePlugin::RenX_Ladder_Daily_TimePlugin()
// Load database // Load database
this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Daily.db"_jrs)); this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Daily.db"_jrs));
this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Daily"_jrs)); this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Daily"_jrs));
this->database.setOutputTimes(Jupiter::IRC::Client::Config->getBool(this->getName(), "OutputTimes"_jrs, false));
this->last_sorted_day = gmtime(std::addressof<const time_t>(time(0)))->tm_wday; this->last_sorted_day = gmtime(std::addressof<const time_t>(time(0)))->tm_wday;
this->database.OnPreUpdateLadder = OnPreUpdateLadder; this->database.OnPreUpdateLadder = OnPreUpdateLadder;
@ -40,7 +41,7 @@ RenX_Ladder_Daily_TimePlugin::RenX_Ladder_Daily_TimePlugin()
// Plugin instantiation and entry point. // Plugin instantiation and entry point.
RenX_Ladder_Daily_TimePlugin pluginInstance; RenX_Ladder_Daily_TimePlugin pluginInstance;
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team)
{ {
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0))); tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
if (pluginInstance.last_sorted_day != tm_ptr->tm_wday) if (pluginInstance.last_sorted_day != tm_ptr->tm_wday)

2
RenX.Ladder.Daily/RenX_Ladder_Daily.h

@ -37,6 +37,6 @@ private:
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Daily"); STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Daily");
}; };
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team);
#endif // _RENX_LADDER_ALL_TIME #endif // _RENX_LADDER_ALL_TIME

3
RenX.Ladder.Monthly/RenX_Ladder_Monthly.cpp

@ -28,6 +28,7 @@ RenX_Ladder_Monthly_TimePlugin::RenX_Ladder_Monthly_TimePlugin()
// Load database // Load database
this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Monthly.db"_jrs)); this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Monthly.db"_jrs));
this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Monthly"_jrs)); this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Monthly"_jrs));
this->database.setOutputTimes(Jupiter::IRC::Client::Config->getBool(this->getName(), "OutputTimes"_jrs, false));
this->last_sorted_month = gmtime(std::addressof<const time_t>(time(0)))->tm_mon; this->last_sorted_month = gmtime(std::addressof<const time_t>(time(0)))->tm_mon;
this->database.OnPreUpdateLadder = OnPreUpdateLadder; this->database.OnPreUpdateLadder = OnPreUpdateLadder;
@ -40,7 +41,7 @@ RenX_Ladder_Monthly_TimePlugin::RenX_Ladder_Monthly_TimePlugin()
// Plugin instantiation and entry point. // Plugin instantiation and entry point.
RenX_Ladder_Monthly_TimePlugin pluginInstance; RenX_Ladder_Monthly_TimePlugin pluginInstance;
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team)
{ {
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0))); tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
if (pluginInstance.last_sorted_month != tm_ptr->tm_mon) if (pluginInstance.last_sorted_month != tm_ptr->tm_mon)

2
RenX.Ladder.Monthly/RenX_Ladder_Monthly.h

@ -37,6 +37,6 @@ private:
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Monthly"); STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Monthly");
}; };
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team);
#endif // _RENX_LADDER_ALL_TIME #endif // _RENX_LADDER_ALL_TIME

3
RenX.Ladder.Weekly/RenX_Ladder_Weekly.cpp

@ -28,6 +28,7 @@ RenX_Ladder_Weekly_TimePlugin::RenX_Ladder_Weekly_TimePlugin()
// Load database // Load database
this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Weekly.db"_jrs)); this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Weekly.db"_jrs));
this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Weekly"_jrs)); this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Weekly"_jrs));
this->database.setOutputTimes(Jupiter::IRC::Client::Config->getBool(this->getName(), "OutputTimes"_jrs, false));
this->last_sorted_day = gmtime(std::addressof<const time_t>(time(0)))->tm_wday; this->last_sorted_day = gmtime(std::addressof<const time_t>(time(0)))->tm_wday;
this->reset_day = Jupiter::IRC::Client::Config->getInt(this->getName(), "ResetDay"_jrs); this->reset_day = Jupiter::IRC::Client::Config->getInt(this->getName(), "ResetDay"_jrs);
@ -41,7 +42,7 @@ RenX_Ladder_Weekly_TimePlugin::RenX_Ladder_Weekly_TimePlugin()
// Plugin instantiation and entry point. // Plugin instantiation and entry point.
RenX_Ladder_Weekly_TimePlugin pluginInstance; RenX_Ladder_Weekly_TimePlugin pluginInstance;
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team)
{ {
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0))); tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
if (pluginInstance.last_sorted_day != tm_ptr->tm_wday && tm_ptr->tm_wday == pluginInstance.reset_day) if (pluginInstance.last_sorted_day != tm_ptr->tm_wday && tm_ptr->tm_wday == pluginInstance.reset_day)

2
RenX.Ladder.Weekly/RenX_Ladder_Weekly.h

@ -38,6 +38,6 @@ private:
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Weekly"); STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Weekly");
}; };
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team);
#endif // _RENX_LADDER_ALL_TIME #endif // _RENX_LADDER_ALL_TIME

3
RenX.Ladder.Yearly/RenX_Ladder_Yearly.cpp

@ -28,6 +28,7 @@ RenX_Ladder_Yearly_TimePlugin::RenX_Ladder_Yearly_TimePlugin()
// Load database // Load database
this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Yearly.db"_jrs)); this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Yearly.db"_jrs));
this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Yearly"_jrs)); this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Yearly"_jrs));
this->database.setOutputTimes(Jupiter::IRC::Client::Config->getBool(this->getName(), "OutputTimes"_jrs, false));
this->last_sorted_year = gmtime(std::addressof<const time_t>(time(0)))->tm_year; this->last_sorted_year = gmtime(std::addressof<const time_t>(time(0)))->tm_year;
this->database.OnPreUpdateLadder = OnPreUpdateLadder; this->database.OnPreUpdateLadder = OnPreUpdateLadder;
@ -40,7 +41,7 @@ RenX_Ladder_Yearly_TimePlugin::RenX_Ladder_Yearly_TimePlugin()
// Plugin instantiation and entry point. // Plugin instantiation and entry point.
RenX_Ladder_Yearly_TimePlugin pluginInstance; RenX_Ladder_Yearly_TimePlugin pluginInstance;
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team)
{ {
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0))); tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
if (pluginInstance.last_sorted_year != tm_ptr->tm_year) if (pluginInstance.last_sorted_year != tm_ptr->tm_year)

2
RenX.Ladder.Yearly/RenX_Ladder_Yearly.h

@ -37,6 +37,6 @@ private:
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Yearly"); STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Yearly");
}; };
void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team);
#endif // _RENX_LADDER_ALL_TIME #endif // _RENX_LADDER_ALL_TIME

3
RenX.Ladder/RenX_Ladder.cpp

@ -29,7 +29,6 @@ using namespace Jupiter::literals;
RenX_LadderPlugin::RenX_LadderPlugin() RenX_LadderPlugin::RenX_LadderPlugin()
{ {
RenX_LadderPlugin::only_pure = Jupiter::IRC::Client::Config->getBool(this->getName(), "OnlyPure"_jrs, false); RenX_LadderPlugin::only_pure = Jupiter::IRC::Client::Config->getBool(this->getName(), "OnlyPure"_jrs, false);
RenX_LadderPlugin::output_times = Jupiter::IRC::Client::Config->getBool(this->getName(), "OutputTimes"_jrs, true);
int mlcpno = Jupiter::IRC::Client::Config->getInt(this->getName(), "MaxLadderCommandPartNameOutput"_jrs, 5); int mlcpno = Jupiter::IRC::Client::Config->getInt(this->getName(), "MaxLadderCommandPartNameOutput"_jrs, 5);
if (mlcpno < 0) if (mlcpno < 0)
RenX_LadderPlugin::max_ladder_command_part_name_output = 0; RenX_LadderPlugin::max_ladder_command_part_name_output = 0;
@ -59,7 +58,7 @@ void RenX_LadderPlugin::RenX_OnCommand(RenX::Server *server, const Jupiter::Read
server->varData.set(this->name, "w"_jrs, "0"_jrs); server->varData.set(this->name, "w"_jrs, "0"_jrs);
RenX::TeamType team = static_cast<RenX::TeamType>(server->varData.get(this->name, "t"_jrs, "\0"_jrs).get(0)); RenX::TeamType team = static_cast<RenX::TeamType>(server->varData.get(this->name, "t"_jrs, "\0"_jrs).get(0));
for (size_t index = 0; index != RenX::ladder_databases.size(); ++index) for (size_t index = 0; index != RenX::ladder_databases.size(); ++index)
RenX::ladder_databases.get(index)->updateLadder(server, team, RenX_LadderPlugin::output_times); RenX::ladder_databases.get(index)->updateLadder(server, team);
} }
} }
} }

2
RenX.Ladder/RenX_Ladder.h

@ -44,7 +44,7 @@ public:
private: private:
/** Configuration variables */ /** Configuration variables */
bool only_pure, output_times; bool only_pure;
size_t max_ladder_command_part_name_output; size_t max_ladder_command_part_name_output;
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder"); STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder");
}; };

Loading…
Cancel
Save