Lots of work on printbuffers

This commit is contained in:
2021-11-14 15:57:18 -05:00
parent c1c0b02926
commit f933f451ad
10 changed files with 229 additions and 108 deletions

View File

@@ -90,15 +90,16 @@ void Tangible::update_plane_item() {
void Tangible::serialize(StreamBuffer *sb) {
anim_queue_.serialize(sb);
id_player_pool_.serialize(sb);
print_buffer_.serialize(sb);
}
void Tangible::deserialize(StreamBuffer *sb) {
anim_queue_.deserialize(sb);
id_player_pool_.deserialize(sb);
print_buffer_.deserialize(sb);
update_plane_item();
}
Tangible *World::tangible_get(int64_t id) {
auto iter = tangibles_.find(id);
if (iter == tangibles_.end()) {
@@ -266,7 +267,7 @@ int64_t World::create_login_actor() {
LS.rawset(mt, "__index", classtab);
LS.result();
tan->configure_id_pool_for_actor();
tan->print_buffer_.reset(new PrintBuffer(world_type_));
tan->print_buffer_.clear();
assert(stack_is_clear());
return tan->id();
}
@@ -381,10 +382,7 @@ void World::invoke_flush_prints(int64_t actor_id, int64_t place_id, const std::s
if (tactor == nullptr) {
return;
}
if (tactor->print_buffer_ == nullptr) {
return;
}
tactor->print_buffer_->discard_upto(line);
tactor->print_buffer_.discard_upto(line);
assert(stack_is_clear());
}
@@ -628,7 +626,7 @@ int64_t World::alloc_id_predictable() {
const PrintBuffer *World::get_printbuffer(int64_t actor_id) {
Tangible *actor = tangible_get(actor_id);
if (actor != nullptr) {
return actor->print_buffer_.get();
return &actor->print_buffer_;
}
return nullptr;
}
@@ -658,13 +656,10 @@ void World::close_lthread_state() {
// send the output to std::cerr.
if (lthread_prints_ != nullptr) {
const std::string &output = lthread_prints_->str();
PrintBuffer *pbuffer = nullptr;
Tangible *actor = tangible_get(lthread_actor_id_);
if (actor != nullptr) {
pbuffer = actor->print_buffer_.get();
}
if (pbuffer != nullptr) {
pbuffer->add_string(output);
bool auth = util::world_type_authoritative(world_type_);
actor->print_buffer_.add_string(output, auth);
}
}
// Now clean up everything.