Browse files

HandeSelectCharacter now uses callback to ensure CmdStartScene is rec…

…ieved before objects are sent. Fixes for SequencedCallbacks.
  • Loading branch information...
1 parent fa55c3b commit daf7997bac310a29f64b6ef44aa97d5c7ccb51ff @dead1ock dead1ock committed Mar 6, 2013
View
31 src/swganh/network/soe/session.cc
@@ -116,8 +116,17 @@ void Session::Update() {
data_channel_payload,
max_data_channel_size);
- for_each(fragmented_message.begin(), fragmented_message.end(), [this, &callbacks] (ByteBuffer& fragment) {
- SendSequencedMessage_(&BuildFragmentedDataChannelHeader, move(fragment), callbacks);
+ uint16_t frag_list_size = fragmented_message.size();
+ for_each(fragmented_message.begin(), fragmented_message.end(), [this, &callbacks, &frag_list_size] (ByteBuffer& fragment) {
+
+ if(frag_list_size > 1) {
+ SendSequencedMessage_(&BuildFragmentedDataChannelHeader, move(fragment), SequencedCallbacks());
+ }
+ else
+ {
+ SendSequencedMessage_(&BuildFragmentedDataChannelHeader, move(fragment), callbacks);
+ }
+ frag_list_size--;
});
} else {
SendSequencedMessage_(&BuildDataChannelHeader, move(data_channel_payload), callbacks);
@@ -221,7 +230,7 @@ void Session::HandleProtocolMessageInternal(swganh::ByteBuffer message)
}
-void Session::SendSequencedMessage_(HeaderBuilder header_builder, ByteBuffer message, SequencedCallbacks callbacks) {
+void Session::SendSequencedMessage_(HeaderBuilder header_builder, ByteBuffer message, boost::optional<SequencedCallbacks> callbacks) {
// Get the next sequence number
uint16_t message_sequence = server_sequence_++;
@@ -233,8 +242,8 @@ void Session::SendSequencedMessage_(HeaderBuilder header_builder, ByteBuffer mes
// Send it over the wire
SendSoePacket_(data_channel_message);
-
- QueueSequencedCallback(message_sequence, callbacks);
+ if(callbacks.get().size() > 0)
+ QueueSequencedCallback(message_sequence, callbacks.get());
// Store it for resending later if necessary
sent_messages_.push_back(make_pair(message_sequence, move(data_channel_message)));
@@ -448,18 +457,20 @@ void Session::QueueSequencedCallback(uint16_t sequence, SequencedCallbacks callb
void Session::DequeueSequencedCallback(uint16_t sequence)
{
- for(auto& item : acknowledgement_callbacks_)
+ for(std::map<uint16_t, SequencedCallbacks>::iterator iter = acknowledgement_callbacks_.begin(); iter != acknowledgement_callbacks_.end(); iter++)
{
- if(item.first > sequence)
+ if((*iter).first > sequence)
break;
- for(auto& func : item.second)
+ for(auto& func : (*iter).second)
{
- func(sequence);
+ func((*iter).first);
}
}
auto iter = acknowledgement_callbacks_.find(sequence);
- if(iter != acknowledgement_callbacks_.end())
+ if(iter != acknowledgement_callbacks_.end()) {
acknowledgement_callbacks_.erase(acknowledgement_callbacks_.begin(), iter);
+ acknowledgement_callbacks_.erase(iter);
+ }
}
View
6 src/swganh/network/soe/session.h
@@ -113,11 +113,11 @@ class Session : public std::enable_shared_from_this<Session> {
* @param message The payload to send in the data channel message(s).
*/
template<typename T>
- void SendTo(const T& message) {
+ void SendTo(const T& message, boost::optional<SequencedCallback> callback = boost::optional<SequencedCallback>()) {
ByteBuffer message_buffer;
message.Serialize(message_buffer);
- outgoing_data_messages_.push(OutgoingMessage(std::move(message_buffer), boost::optional<SequencedCallback>()));
+ outgoing_data_messages_.push(OutgoingMessage(std::move(message_buffer), callback));
}
void HandleMessage(swganh::ByteBuffer message);
@@ -147,7 +147,7 @@ class Session : public std::enable_shared_from_this<Session> {
typedef swganh::ByteBuffer(*HeaderBuilder)(uint16_t);
- void SendSequencedMessage_(HeaderBuilder header_builder, ByteBuffer message, SequencedCallbacks callbacks);
+ void SendSequencedMessage_(HeaderBuilder header_builder, ByteBuffer message, boost::optional<SequencedCallbacks> callbacks = boost::optional<SequencedCallbacks>());
virtual void OnClose() {}
View
6 src/swganh_core/object/object.cc
@@ -844,7 +844,7 @@ void Object::CreateBaselines( std::shared_ptr<swganh::observer::ObserverInterfac
void Object::SendCreateByCrc(std::shared_ptr<swganh::observer::ObserverInterface> observer)
{
- DLOG(info) << "SEND " << GetObjectId() << " TO " << observer->GetId();
+ //DLOG(info) << "SEND " << GetObjectId() << " TO " << observer->GetId();
swganh::messages::SceneCreateObjectByCrc scene_object;
scene_object.object_id = GetObjectId();
@@ -866,7 +866,7 @@ void Object::SendUpdateContainmentMessage(std::shared_ptr<swganh::observer::Obse
if (GetContainer())
container_id = GetContainer()->GetObjectId();
- DLOG(info) << "CONTAINMENT " << GetObjectId() << " INTO " << container_id << " ARRANGEMENT " << arrangement_id_;
+ //DLOG(info) << "CONTAINMENT " << GetObjectId() << " INTO " << container_id << " ARRANGEMENT " << arrangement_id_;
UpdateContainmentMessage containment_message;
containment_message.container_id = container_id;
@@ -877,7 +877,7 @@ void Object::SendUpdateContainmentMessage(std::shared_ptr<swganh::observer::Obse
void Object::SendDestroy(std::shared_ptr<swganh::observer::ObserverInterface> observer)
{
- DLOG(info) << "DESTROY " << GetObjectId() << " FOR " << observer->GetId();
+ //DLOG(info) << "DESTROY " << GetObjectId() << " FOR " << observer->GetId();
swganh::messages::SceneDestroyObject scene_object;
scene_object.object_id = GetObjectId();
View
61 src/swganh_core/simulation/simulation_service.cc
@@ -268,6 +268,7 @@ class SimulationServiceImpl {
start_scene.galaxy_time = 0;
controller->Notify(&start_scene, [=](uint16_t sequence) {
+ std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!Attaching controller...." << std::endl;
// Reset Controller
obj->SetController(controller);
@@ -386,6 +387,8 @@ class SimulationServiceImpl {
throw std::runtime_error("Invalid scene selected for object");
}
+ object->SetCollidable(false);
+
// CmdStartScene
CmdStartScene start_scene;
start_scene.ignore_layout = 0;
@@ -395,37 +398,39 @@ class SimulationServiceImpl {
start_scene.position = object->GetPosition();
start_scene.shared_race_template = object->GetTemplate();
start_scene.galaxy_time = 0;
- client->SendTo(start_scene);
-
- object->SetCollidable(false);
-
- if(object->GetContainer() == nullptr)
- {
- scene->AddObject(object);
- }
- //Attach the controller
- StartControllingObject(object, client);
+ client->SendTo(start_scene, boost::optional<Session::SequencedCallback>(
+ [=](uint16_t sequence){
+ LOG(warning) << "here.";
+ if(object->GetContainer() == nullptr)
+ {
+ scene->AddObject(object);
+ }
- //Make sure the controller gets his awareness creates
- //regardless of the current state of awareness.
- auto controller = object->GetController();
- scene->ViewObjects(object, 0, true, [&] (std::shared_ptr<swganh::object::Object> aware) {
- if(aware->__HasAwareObject(object) && !aware->IsInSnapshot())
- {
- //Send create manually
- aware->Subscribe(controller);
- aware->SendCreateByCrc(controller);
- aware->CreateBaselines(controller);
- }
- else
- {
- aware->AddAwareObject(object);
- object->AddAwareObject(aware);
- }
- });
+ //Attach the controller
+ StartControllingObject(object, client);
- object->SetCollidable(true);
+ //Make sure the controller gets his awareness creates
+ //regardless of the current state of awareness.
+ auto controller = object->GetController();
+ scene->ViewObjects(object, 0, true, [&] (std::shared_ptr<swganh::object::Object> aware) {
+ if(aware->__HasAwareObject(object) && !aware->IsInSnapshot())
+ {
+ //Send create manually
+ aware->Subscribe(controller);
+ aware->SendCreateByCrc(controller);
+ aware->CreateBaselines(controller);
+ }
+ else
+ {
+ aware->AddAwareObject(object);
+ object->AddAwareObject(aware);
+ }
+ });
+
+
+ object->SetCollidable(true);
+ }));
}
void SendToAll(swganh::messages::BaseSwgMessage* message)

0 comments on commit daf7997

Please sign in to comment.