OSDN Git Service

コマンド受信時にタイミングによって落ちることがある不具合を修正
authorh2so5 <h2so5@git.sourceforge.jp>
Thu, 13 Sep 2012 14:59:56 +0000 (23:59 +0900)
committerh2so5 <h2so5@git.sourceforge.jp>
Thu, 13 Sep 2012 14:59:56 +0000 (23:59 +0900)
client/3d/PlayerCharacter.cpp
client/Client.cpp
client/Client.hpp
client/CommandManager.cpp

index ebcf617..c5eb660 100644 (file)
@@ -6,6 +6,7 @@
 #include "dx_vector.hpp"
 #include "BasicMotion.hpp"
 #include "MotionPlayer.hpp"
+#include "../Profiler.hpp"
 #include "../../common/Logger.hpp"
 
 
@@ -64,6 +65,7 @@ public:
 
     void Impl::Update()
     {
+               MMO_PROFILE_FUNCTION;
                static auto time_now = 0.0f;
                prev_target_pos_ = current_target_pos_;
         const auto current_target_pos = data_provider_.target_position();
index bd904ce..e202dc0 100644 (file)
@@ -247,12 +247,15 @@ void Client::Close()
 {
 }
 
-Command Client::PopCommand()
+std::shared_ptr<Command> Client::PopCommand()
 {
     boost::mutex::scoped_lock lock(mutex_);
-    Command command = command_queue_.front();
-    command_queue_.pop();
-    return command;
+       std::shared_ptr<Command> command;
+       if (!command_queue_.empty()) {
+               command = std::make_shared<Command>(command_queue_.front());
+               command_queue_.pop();
+       }
+       return command;
 }
 
 bool Client::command_empty()
index 23063ba..dab3fca 100644 (file)
@@ -68,7 +68,7 @@ namespace network {
            void WriteUDP(const Command&);
            void Close();
 
-           Command PopCommand();
+           std::shared_ptr<Command> Client::PopCommand();
            bool command_empty();
 
            unsigned int id() const;
index f4fbe41..2ae2a1b 100644 (file)
@@ -20,81 +20,84 @@ void CommandManager::Update()
 {
        MMO_PROFILE_FUNCTION;
 
-    if (client_ && !client_->command_empty())
+    if (client_)
     {
         auto command = client_->PopCommand();
-        unsigned int header =  command.header();
-
-        CardManagerPtr card_manager = manager_accessor_->card_manager().lock();
-        PlayerManagerPtr player_manager = manager_accessor_->player_manager().lock();
-        AccountManagerPtr account_manager = manager_accessor_->account_manager().lock();
-
-        Logger::Debug(_T("Receive: 0x%08x %d byte"), header, command.body().size());
-
-        switch (header) {
-        using namespace network::header;
-
-        // 暗号化通信を開始
-        case ClientStartEncryptedSession:
-        {
-            const std::string& data = account_manager->GetSerializedData();
-            if (data.size() > 0) {
-                client_->Write(network::ServerReceiveAccountInitializeData(data));
-            }
-        }
-            break;
-
-        case ClientReceiveJSON:
-        // case ClientReceiveChatLog:
-        {
-            std::string info_json, msg_json;
-            network::Utils::Deserialize(command.body(), &info_json, &msg_json);
-
-            Logger::Info(_T("Receive JSON: %s %s"), unicode::ToTString(info_json), unicode::ToTString(msg_json));
-
-            card_manager->OnReceiveJSON(info_json, msg_json);
-        }
-            break;
-
-        // プレイヤー位置更新
-        case ClientUpdatePlayerPosition:
-        {
-            PlayerPosition pos;
-            uint32_t user_id;
-            network::Utils::Deserialize(command.body(), &user_id, &pos.x, &pos.y, &pos.z, &pos.theta, &pos.vy);
-
-            player_manager->UpdatePlayerPosition(user_id, pos);
-        }
-            break;
-
-        case ClientReceiveAccountRevisionUpdateNotify:
-        {
-            uint32_t user_id;
-            uint32_t server_revision;
-            network::Utils::Deserialize(command.body(), &user_id, &server_revision);
-
-            auto current_revision = player_manager->GetCurrentUserRevision(user_id);
-
-            Logger::Info(_T("Receive account database update notify %d %d [%d]"), user_id, server_revision, current_revision);
-
-            if (server_revision > current_revision) {
-                client_->Write(network::ServerRequestedAccountRevisionPatch(user_id, current_revision));
-            }
-        }
-            break;
-
-        case ClientReceiveAccountRevisionPatch:
-        {
-            Logger::Info(_T("Receive account database update data"));
-            assert(command.body().size() > 0);
-            player_manager->ApplyRevisionPatch(command.body());
-        }
-            break;
-
-        default:
-            break;
-        }
-    }
+
+               if (command) {
+                       unsigned int header =  command->header();
+
+                       CardManagerPtr card_manager = manager_accessor_->card_manager().lock();
+                       PlayerManagerPtr player_manager = manager_accessor_->player_manager().lock();
+                       AccountManagerPtr account_manager = manager_accessor_->account_manager().lock();
+
+                       Logger::Debug(_T("Receive: 0x%08x %d byte"), header, command->body().size());
+
+                       switch (header) {
+                       using namespace network::header;
+
+                       // 暗号化通信を開始
+                       case ClientStartEncryptedSession:
+                       {
+                               const std::string& data = account_manager->GetSerializedData();
+                               if (data.size() > 0) {
+                                       client_->Write(network::ServerReceiveAccountInitializeData(data));
+                               }
+                       }
+                               break;
+
+                       case ClientReceiveJSON:
+                       // case ClientReceiveChatLog:
+                       {
+                               std::string info_json, msg_json;
+                               network::Utils::Deserialize(command->body(), &info_json, &msg_json);
+
+                               Logger::Info(_T("Receive JSON: %s %s"), unicode::ToTString(info_json), unicode::ToTString(msg_json));
+
+                               card_manager->OnReceiveJSON(info_json, msg_json);
+                       }
+                               break;
+
+                       // プレイヤー位置更新
+                       case ClientUpdatePlayerPosition:
+                       {
+                               PlayerPosition pos;
+                               uint32_t user_id;
+                               network::Utils::Deserialize(command->body(), &user_id, &pos.x, &pos.y, &pos.z, &pos.theta, &pos.vy);
+
+                               player_manager->UpdatePlayerPosition(user_id, pos);
+                       }
+                               break;
+
+                       case ClientReceiveAccountRevisionUpdateNotify:
+                       {
+                               uint32_t user_id;
+                               uint32_t server_revision;
+                               network::Utils::Deserialize(command->body(), &user_id, &server_revision);
+
+                               auto current_revision = player_manager->GetCurrentUserRevision(user_id);
+
+                               Logger::Info(_T("Receive account database update notify %d %d [%d]"), user_id, server_revision, current_revision);
+
+                               if (server_revision > current_revision) {
+                                       client_->Write(network::ServerRequestedAccountRevisionPatch(user_id, current_revision));
+                               }
+                       }
+                               break;
+
+                       case ClientReceiveAccountRevisionPatch:
+                       {
+                               Logger::Info(_T("Receive account database update data"));
+                               assert(command->body().size() > 0);
+                               player_manager->ApplyRevisionPatch(command->body());
+                       }
+                               break;
+
+                       default:
+                               break;
+                       }
+               }
+       }
 }
 
 void CommandManager::set_client(ClientUniqPtr client)