Skip to content

Commit

Permalink
Merge pull request #2364 from o01eg/repeal-save-game-data-request
Browse files Browse the repository at this point in the history
Repeal save game data request
  • Loading branch information
geoffthemedio committed Feb 2, 2019
2 parents 456e939 + af1dfd9 commit 8a1903a
Show file tree
Hide file tree
Showing 31 changed files with 376 additions and 346 deletions.
9 changes: 5 additions & 4 deletions AI/AIInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using boost::python::str;
namespace {
const float DUMMY_FLOAT = 0.0f;
}

//////////////////////////////////
// AI Base //
//////////////////////////////////
Expand All @@ -61,7 +61,7 @@ void AIBase::StartNewGame()
void AIBase::ResumeLoadedGame(const std::string& save_state_string)
{}

const std::string& AIBase::GetSaveStateString() {
const std::string& AIBase::GetSaveStateString() const {
static std::string default_state_string("AIBase default save state string");
DebugLogger() << "AIBase::GetSaveStateString() returning: " << default_state_string;
return default_state_string;
Expand Down Expand Up @@ -377,7 +377,7 @@ namespace AIInterface {
ErrorLogger() << "IssueChangeProductionStockpileOrder : passed queue_index outside range of items on queue.";
return 0;
}

AIClientApp::GetApp()->Orders().IssueOrder(
std::make_shared<ProductionQueueOrder>(empire_id, queue_index, use_stockpile, DUMMY_FLOAT, DUMMY_FLOAT));

Expand Down Expand Up @@ -433,7 +433,8 @@ namespace AIInterface {

void DoneTurn() {
DebugLogger() << "AIInterface::DoneTurn()";
AIClientApp::GetApp()->StartTurn(); // encodes order sets and sends turn orders message. "done" the turn for the client, but "starts" the turn for the server
AIClientApp* app = AIClientApp::GetApp();
app->StartTurn(app->GetAI()->GetSaveStateString()); // encodes order sets and sends turn orders message. "done" the turn for the client, but "starts" the turn for the server
}

void LogOutput(const std::string& log_text)
Expand Down
2 changes: 1 addition & 1 deletion AI/AIInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class AIBase {
*
* @return The serialized state information of the game running.
*/
virtual const std::string& GetSaveStateString();
virtual const std::string& GetSaveStateString() const;

/** @brief Set the aggressiveness of this AI
*
Expand Down
8 changes: 7 additions & 1 deletion UI/FleetWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ bool FleetUIManager::CloseAll() {
m_active_fleet_wnd.reset();
ActiveFleetWndChangedSignal();

// send order changes could be made on fleets
HumanClientApp::GetApp()->SendPartialOrders();

return retval;
}

Expand All @@ -529,6 +532,9 @@ void FleetUIManager::FleetWndClosing(FleetWnd* fleet_wnd) {
m_active_fleet_wnd.reset();
ActiveFleetWndChangedSignal();
}

// send order changes could be made on this fleet
HumanClientApp::GetApp()->SendPartialOrders();
}

void FleetUIManager::FleetWndClicked(std::shared_ptr<FleetWnd> fleet_wnd) {
Expand Down Expand Up @@ -3491,7 +3497,7 @@ void FleetWnd::FleetRightClicked(GG::ListBox::iterator it, const GG::Pt& pt, con


auto popup = GG::Wnd::Create<CUIPopupMenu>(pt.x, pt.y);

// add a fleet popup command to send the fleet exploring, and stop it from exploring
if (system
&& !ClientUI::GetClientUI()->GetMapWnd()->IsFleetExploring(fleet->ID())
Expand Down
3 changes: 3 additions & 0 deletions UI/InGameMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ void InGameMenu::Save() {
return;
}

// send order changes could be made when player decide to save game
app->SendPartialOrders();

try {
// When saving in multiplayer, you cannot see the old saves or
// browse directories, only give a save file name.
Expand Down
13 changes: 11 additions & 2 deletions UI/MapWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5593,7 +5593,7 @@ std::vector<int> MapWnd::FleetIDsOfFleetButtonsOverlapping(int fleet_id) const {
int vis_turn = -1;
if (vis_turn_map.find(VIS_BASIC_VISIBILITY) != vis_turn_map.end())
vis_turn = vis_turn_map[VIS_BASIC_VISIBILITY];
ErrorLogger() << "Couldn't find a FleetButton for fleet " << fleet_id
ErrorLogger() << "Couldn't find a FleetButton for fleet " << fleet_id
<< " with last basic vis turn " << vis_turn;
return fleet_ids;
}
Expand Down Expand Up @@ -6133,7 +6133,14 @@ bool MapWnd::EndTurn() {
if (m_ready_turn) {
HumanClientApp::GetApp()->UnreadyTurn();
} else {
HumanClientApp::GetApp()->StartTurn();
ClientUI* cui = ClientUI::GetClientUI();
if (!cui) {
ErrorLogger() << "MapWnd::EndTurn: No client UI available";
return false;
}
SaveGameUIData ui_data;
cui->GetSaveGameUIData(ui_data);
HumanClientApp::GetApp()->StartTurn(ui_data);
}
return true;
}
Expand Down Expand Up @@ -6434,6 +6441,8 @@ void MapWnd::HideSidePanel() {
void MapWnd::RestoreSidePanel() {
if (m_sidepanel_open_before_showing_other)
ReselectLastSystem();
// send order changes could be made in research, production or other windows
HumanClientApp::GetApp()->SendPartialOrders();
}

void MapWnd::ShowResearch() {
Expand Down
2 changes: 1 addition & 1 deletion UI/MapWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class MapWnd : public GG::Wnd {
bool ShowGraphs();

void HideSidePanel();
void RestoreSidePanel();
void RestoreSidePanel(); //!< restores side panel, sends to server changes made in other windows

bool ToggleResearch();
void ShowResearch();
Expand Down
3 changes: 3 additions & 0 deletions UI/SidePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,9 @@ void SidePanel::PlanetPanelContainer::SelectPlanet(int planet_id) {
m_selected_planet_id = INVALID_OBJECT_ID;
//std::cout << " ... no planet with requested ID found" << std::endl;
}

// send order changes could be made on other planets
HumanClientApp::GetApp()->SendPartialOrders();
}
}

Expand Down
7 changes: 0 additions & 7 deletions client/AI/AIClientApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,6 @@ void AIClientApp::HandleMessage(const Message& msg) {
break;
}

case Message::SAVE_GAME_DATA_REQUEST: {
//DebugLogger() << "AIClientApp::HandleMessage Message::SAVE_GAME_DATA_REQUEST";
Networking().SendMessage(ClientSaveDataMessage(Orders(), m_AI->GetSaveStateString()));
//DebugLogger() << "AIClientApp::HandleMessage sent save data message";
break;
}

case Message::SAVE_GAME_COMPLETE:
break;

Expand Down
14 changes: 12 additions & 2 deletions client/ClientApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ void ClientApp::SetEmpireStatus(int empire_id, Message::PlayerStatus status) {
m_empire_status[empire_id] = status;
}

void ClientApp::StartTurn()
{ m_networking->SendMessage(TurnOrdersMessage(m_orders)); }
void ClientApp::StartTurn(const SaveGameUIData& ui_data)
{ m_networking->SendMessage(TurnOrdersMessage(m_orders, ui_data)); }

void ClientApp::StartTurn(const std::string& save_state_string)
{ m_networking->SendMessage(TurnOrdersMessage(m_orders, save_state_string)); }

void ClientApp::SendPartialOrders() {
auto changes = m_orders.ExtractChanges();
if (changes.first.empty() && changes.second.empty())
return;
m_networking->SendMessage(TurnPartialOrdersMessage(changes));
}

void ClientApp::HandleTurnPhaseUpdate(Message::TurnProgressPhase phase_id) {
switch (phase_id) {
Expand Down
10 changes: 8 additions & 2 deletions client/ClientApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,14 @@ class ClientApp : public IApp {
*/
std::string GetVisibleObjectName(std::shared_ptr<const UniverseObject> object) override;

/** @brief Send the OrderSet to the server and start a new turn */
virtual void StartTurn();
/** @brief Send the OrderSet and UI data to the server and start a new turn */
virtual void StartTurn(const SaveGameUIData& ui_data);

/** @brief Send the OrderSet and AI state to the server and start a new turn */
virtual void StartTurn(const std::string& save_state_string);

/** @brief Send turn orders updates to server without starting new turn */
void SendPartialOrders();

/** \brief Handle server acknowledgement of receipt of orders and clear
the orders. */
Expand Down
1 change: 0 additions & 1 deletion client/ClientFSMEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct MessageEventBase {
(HostID) \
(LobbyUpdate) \
(LobbyChat) \
(SaveGameDataRequest) \
(SaveGameComplete) \
(GameStart) \
(TurnUpdate) \
Expand Down
13 changes: 2 additions & 11 deletions client/human/HumanClientApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ void HumanClientApp::Reinitialize() {
float HumanClientApp::GLVersion() const
{ return GetGLVersion(); }

void HumanClientApp::StartTurn() {
void HumanClientApp::StartTurn(const SaveGameUIData& ui_data) {
DebugLogger() << "HumanClientApp::StartTurn";

if (const Empire* empire = GetEmpire(EmpireID())) {
Expand All @@ -930,7 +930,7 @@ void HumanClientApp::StartTurn() {
Autosave();
}

ClientApp::StartTurn();
ClientApp::StartTurn(ui_data);
m_fsm->process_event(TurnEnded());
}

Expand Down Expand Up @@ -975,7 +975,6 @@ void HumanClientApp::HandleMessage(Message& msg) {
case Message::JOIN_GAME: m_fsm->process_event(JoinGame(msg)); break;
case Message::HOST_ID: m_fsm->process_event(HostID(msg)); break;
case Message::LOBBY_UPDATE: m_fsm->process_event(LobbyUpdate(msg)); break;
case Message::SAVE_GAME_DATA_REQUEST: m_fsm->process_event(SaveGameDataRequest(msg)); break;
case Message::SAVE_GAME_COMPLETE: m_fsm->process_event(SaveGameComplete(msg)); break;
case Message::CHECKSUM: m_fsm->process_event(CheckSum(msg)); break;
case Message::GAME_START: m_fsm->process_event(GameStart(msg)); break;
Expand All @@ -999,14 +998,6 @@ void HumanClientApp::HandleMessage(Message& msg) {
}
}

void HumanClientApp::HandleSaveGameDataRequest() {
if (INSTRUMENT_MESSAGE_HANDLING)
std::cerr << "HumanClientApp::HandleSaveGameDataRequest(" << Message::SAVE_GAME_DATA_REQUEST << ")\n";
SaveGameUIData ui_data;
m_ui->GetSaveGameUIData(ui_data);
m_networking->SendMessage(ClientSaveDataMessage(Orders(), ui_data));
}

void HumanClientApp::UpdateCombatLogs(const Message& msg){
DebugLogger() << "HCL Update Combat Logs";

Expand Down
3 changes: 1 addition & 2 deletions client/human/HumanClientApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HumanClientApp :

/** \name Mutators */ //@{
void HandleTurnUpdate() override; ///< Handle background events that need starting when the turn updates
void StartTurn() override;
void StartTurn(const SaveGameUIData& ui_data) override;
void UnreadyTurn(); ///< Revoke ready state of turn orders.

/** \brief Handle UI and state updates with changes in turn phase. */
Expand Down Expand Up @@ -97,7 +97,6 @@ class HumanClientApp :
void Reinitialize();
float GLVersion() const;

void HandleSaveGameDataRequest();
void UpdateCombatLogs(const Message& msg);
/** Update any open SaveGameDialog with previews from the server. */
void HandleSaveGamePreviews(const Message& msg);
Expand Down
20 changes: 3 additions & 17 deletions client/human/HumanClientFSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,14 +876,6 @@ WaitingForTurnData::WaitingForTurnData(my_context ctx) :
WaitingForTurnData::~WaitingForTurnData()
{ TraceLogger(FSM) << "(HumanClientFSM) ~WaitingForTurnData"; }

boost::statechart::result WaitingForTurnData::react(const SaveGameDataRequest& msg) {
TraceLogger(FSM) << "(HumanClientFSM) WaitingForTurnData.SaveGameDataRequest";
DebugLogger(FSM) << "Sending Save Game Data to Server";
Client().GetClientUI().GetMessageWnd()->HandleGameStatusUpdate(UserString("SERVER_SAVE_INITIATE_ACK") + "\n");
Client().HandleSaveGameDataRequest();
return discard_event();
}

boost::statechart::result WaitingForTurnData::react(const SaveGameComplete& msg) {
TraceLogger(FSM) << "(HumanClientFSM) WaitingForTurnData.SaveGameComplete";

Expand Down Expand Up @@ -990,14 +982,6 @@ PlayingTurn::PlayingTurn(my_context ctx) :
PlayingTurn::~PlayingTurn()
{ TraceLogger(FSM) << "(HumanClientFSM) ~PlayingTurn"; }

boost::statechart::result PlayingTurn::react(const SaveGameDataRequest& msg) {
TraceLogger(FSM) << "(HumanClientFSM) PlayingTurn.SaveGameDataRequest";
DebugLogger(FSM) << "Sending Save Game Data to Server";
Client().GetClientUI().GetMessageWnd()->HandleGameStatusUpdate(UserString("SERVER_SAVE_INITIATE_ACK") + "\n");
Client().HandleSaveGameDataRequest();
return discard_event();
}

boost::statechart::result PlayingTurn::react(const SaveGameComplete& msg) {
TraceLogger(FSM) << "(HumanClientFSM) PlayingTurn.SaveGameComplete";

Expand All @@ -1023,7 +1007,9 @@ boost::statechart::result PlayingTurn::react(const SaveGameComplete& msg) {
}

boost::statechart::result PlayingTurn::react(const AdvanceTurn& d) {
Client().StartTurn();
SaveGameUIData ui_data;
Client().GetClientUI().GetSaveGameUIData(ui_data);
Client().StartTurn(ui_data);
return discard_event();
}

Expand Down
4 changes: 0 additions & 4 deletions client/human/HumanClientFSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ struct WaitingForTurnData : boost::statechart::state<WaitingForTurnData, Playing
typedef boost::statechart::state<WaitingForTurnData, PlayingGame> Base;

typedef boost::mpl::list<
boost::statechart::custom_reaction<SaveGameDataRequest>,
boost::statechart::custom_reaction<SaveGameComplete>,
boost::statechart::custom_reaction<TurnUpdate>,
boost::statechart::custom_reaction<TurnRevoked>,
Expand All @@ -325,7 +324,6 @@ struct WaitingForTurnData : boost::statechart::state<WaitingForTurnData, Playing
WaitingForTurnData(my_context ctx);
~WaitingForTurnData();

boost::statechart::result react(const SaveGameDataRequest& d);
boost::statechart::result react(const SaveGameComplete& d);
boost::statechart::result react(const TurnUpdate& msg);
boost::statechart::result react(const TurnRevoked& msg);
Expand All @@ -340,7 +338,6 @@ struct PlayingTurn : boost::statechart::state<PlayingTurn, PlayingGame> {
typedef boost::statechart::state<PlayingTurn, PlayingGame> Base;

typedef boost::mpl::list<
boost::statechart::custom_reaction<SaveGameDataRequest>,
boost::statechart::custom_reaction<SaveGameComplete>,
boost::statechart::custom_reaction<AdvanceTurn>,
boost::statechart::custom_reaction<TurnUpdate>,
Expand All @@ -352,7 +349,6 @@ struct PlayingTurn : boost::statechart::state<PlayingTurn, PlayingGame> {
PlayingTurn(my_context ctx);
~PlayingTurn();

boost::statechart::result react(const SaveGameDataRequest& d);
boost::statechart::result react(const SaveGameComplete& d);
boost::statechart::result react(const AdvanceTurn& d);
boost::statechart::result react(const TurnUpdate& msg);
Expand Down

0 comments on commit 8a1903a

Please sign in to comment.