Only run update and check_timer functions on components that need it
This commit is contained in:
parent
f82e626686
commit
1c1f23d68d
2 changed files with 27 additions and 4 deletions
|
|
@ -57,9 +57,14 @@ DrawingProgram::DrawingProgram(World& initWorld):
|
||||||
};
|
};
|
||||||
components.clientInsertCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
components.clientInsertCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
||||||
compCache.add_component(c);
|
compCache.add_component(c);
|
||||||
|
DrawComponentType t = c->obj->get_type();
|
||||||
|
if(t == DRAWCOMPONENT_IMAGE || t == DRAWCOMPONENT_TEXTBOX)
|
||||||
|
updateableComponents.emplace(c->obj);
|
||||||
};
|
};
|
||||||
components.clientEraseCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
components.clientEraseCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
||||||
compCache.erase_component(c);
|
compCache.erase_component(c);
|
||||||
|
delayedUpdateTransformComponents.erase(c->obj);
|
||||||
|
updateableComponents.erase(c->obj);
|
||||||
};
|
};
|
||||||
components.clientServerLastPosShiftCallback = [&](uint64_t lastShiftPos) {
|
components.clientServerLastPosShiftCallback = [&](uint64_t lastShiftPos) {
|
||||||
compCache.invalidate_cache_before_pos(lastShiftPos);
|
compCache.invalidate_cache_before_pos(lastShiftPos);
|
||||||
|
|
@ -87,6 +92,7 @@ void DrawingProgram::init_client_callbacks() {
|
||||||
else {
|
else {
|
||||||
comp->delayedUpdatePtr = DrawComponent::allocate_comp_type(comp->get_type());
|
comp->delayedUpdatePtr = DrawComponent::allocate_comp_type(comp->get_type());
|
||||||
message(*comp->delayedUpdatePtr);
|
message(*comp->delayedUpdatePtr);
|
||||||
|
delayedUpdateTransformComponents.emplace(comp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
world.con.client_add_recv_callback(CLIENT_TRANSFORM_COMPONENT, [&](cereal::PortableBinaryInputArchive& message) {
|
world.con.client_add_recv_callback(CLIENT_TRANSFORM_COMPONENT, [&](cereal::PortableBinaryInputArchive& message) {
|
||||||
|
|
@ -107,6 +113,7 @@ void DrawingProgram::init_client_callbacks() {
|
||||||
else {
|
else {
|
||||||
comp->delayedCoordinateSpace = std::make_shared<CoordSpaceHelper>();
|
comp->delayedCoordinateSpace = std::make_shared<CoordSpaceHelper>();
|
||||||
message(*comp->delayedCoordinateSpace);
|
message(*comp->delayedCoordinateSpace);
|
||||||
|
delayedUpdateTransformComponents.emplace(comp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
world.con.client_add_recv_callback(CLIENT_PLACE_COMPONENT, [&](cereal::PortableBinaryInputArchive& message) {
|
world.con.client_add_recv_callback(CLIENT_PLACE_COMPONENT, [&](cereal::PortableBinaryInputArchive& message) {
|
||||||
|
|
@ -127,6 +134,18 @@ void DrawingProgram::init_client_callbacks() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawingProgram::check_delayed_update_transform_timers() {
|
||||||
|
std::erase_if(delayedUpdateTransformComponents, [&](auto& comp) {
|
||||||
|
comp->check_timers(*this);
|
||||||
|
return !comp->delayedUpdatePtr && !comp->delayedCoordinateSpace;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawingProgram::check_updateable_components() {
|
||||||
|
for(auto& comp : updateableComponents)
|
||||||
|
comp->update(*this);
|
||||||
|
}
|
||||||
|
|
||||||
void DrawingProgram::free_collider_memory() {
|
void DrawingProgram::free_collider_memory() {
|
||||||
for(auto& c : components.client_list())
|
for(auto& c : components.client_list())
|
||||||
c->obj->free_collider();
|
c->obj->free_collider();
|
||||||
|
|
@ -354,10 +373,8 @@ void DrawingProgram::update() {
|
||||||
if(controls.leftClickReleased)
|
if(controls.leftClickReleased)
|
||||||
controls.leftClickReleased = false;
|
controls.leftClickReleased = false;
|
||||||
|
|
||||||
for(auto& c : components.client_list()) {
|
check_delayed_update_transform_timers();
|
||||||
c->obj->check_timers(*this);
|
check_updateable_components();
|
||||||
c->obj->update(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
compCache.update();
|
compCache.update();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,15 @@ class DrawingProgram {
|
||||||
|
|
||||||
CollabListType components;
|
CollabListType components;
|
||||||
|
|
||||||
|
std::unordered_set<std::shared_ptr<DrawComponent>> updateableComponents;
|
||||||
|
std::unordered_set<std::shared_ptr<DrawComponent>> delayedUpdateTransformComponents;
|
||||||
|
|
||||||
Vector4f* get_foreground_color_ptr();
|
Vector4f* get_foreground_color_ptr();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void check_delayed_update_transform_timers();
|
||||||
|
void check_updateable_components();
|
||||||
|
|
||||||
std::atomic<bool> addFileInNextFrame = false;
|
std::atomic<bool> addFileInNextFrame = false;
|
||||||
std::pair<std::string, Vector2f> addFileInfo;
|
std::pair<std::string, Vector2f> addFileInfo;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue