Fixed server serialization

This commit is contained in:
doterop 2020-03-04 19:06:27 +01:00 committed by bernat
parent 38d4c8d551
commit cbb0b711db
2 changed files with 15 additions and 18 deletions

View File

@ -155,24 +155,21 @@ static carla::Buffer FWorldObserver_Serialize(
float DeltaSeconds) float DeltaSeconds)
{ {
carla::log_warning("===== FWorldObserver_Serialize =====");
using Serializer = carla::sensor::s11n::EpisodeStateSerializer; using Serializer = carla::sensor::s11n::EpisodeStateSerializer;
using ActorDynamicState = carla::sensor::data::ActorDynamicState; using ActorDynamicState = carla::sensor::data::ActorDynamicState;
using ComponentDynamicState = carla::sensor::data::ComponentDynamicState; using ComponentDynamicState = carla::sensor::data::ComponentDynamicState;
const auto &Registry = Episode.GetActorRegistry(); const auto &Registry = Episode.GetActorRegistry();
auto size = sizeof(Serializer::Header) + sizeof(ActorDynamicState) * Registry.Num(); auto total_size = sizeof(Serializer::Header) + sizeof(ActorDynamicState) * Registry.Num();
auto current_size = 0;
// Set up buffer for writing. // Set up buffer for writing.
buffer.reset(size); buffer.reset(total_size);
auto begin = buffer.begin(); auto write_data = [&current_size, &buffer](const auto &data)
auto write_data = [&begin, &buffer, &size](const auto &data)
{ {
auto begin = buffer.begin() + current_size;
std::memcpy(begin, &data, sizeof(data)); std::memcpy(begin, &data, sizeof(data));
begin += sizeof(data); current_size += sizeof(data);
carla::log_warning("Writting...", sizeof(data), begin - buffer.begin());
}; };
// Write header. // Write header.
@ -203,14 +200,11 @@ static carla::Buffer FWorldObserver_Serialize(
FWorldObserver_GetActorComponentsState(View, Registry, ComponentsState); FWorldObserver_GetActorComponentsState(View, Registry, ComponentsState);
info.num_components = ComponentsState.Num(); info.num_components = ComponentsState.Num();
carla::log_warning("Actor", TCHAR_TO_UTF8(*View.GetActor()->GetName()), info.num_components);
write_data(info); write_data(info);
if(info.num_components > 0) { if(info.num_components > 0) {
size += info.num_components * sizeof(ComponentDynamicState); total_size += info.num_components * sizeof(ComponentDynamicState);
carla::log_warning("Num Components =", info.num_components,"(", size,")"); buffer.resize(total_size);
buffer.resize(size);
for(auto& CompState : ComponentsState) for(auto& CompState : ComponentsState)
{ {
@ -220,11 +214,9 @@ static carla::Buffer FWorldObserver_Serialize(
} }
// Shrink buffer // Shrink buffer
buffer.resize(size); buffer.resize(current_size);
check(begin == buffer.end()); check(buffer.size() == current_size);
carla::log_warning("====================================");
return std::move(buffer); return std::move(buffer);
} }

View File

@ -76,3 +76,8 @@ ATrafficLightGroup* UTrafficLightComponent::GetGroup()
{ {
return TrafficLightGroup; return TrafficLightGroup;
} }
UTrafficLightController* UTrafficLightComponent::GetController()
{
return TrafficLightController;
}