Improve performance when hosting canvas with many objects
This commit is contained in:
parent
207e173c1a
commit
b2f2070f95
5 changed files with 28 additions and 30 deletions
|
|
@ -74,27 +74,22 @@ void DrawComponent::server_send_erase_set(MainServer& server, const std::unorder
|
|||
|
||||
void DrawComponent::server_send_update_temp(MainServer& server, ServerClientID id) {
|
||||
server.netServer->send_items_to_all_clients(UNRELIABLE_COMMAND_CHANNEL, CLIENT_UPDATE_COMPONENT, true, id, *this);
|
||||
tempServerUpdateTimer = std::chrono::steady_clock::now();
|
||||
serverIsTempUpdate = true;
|
||||
}
|
||||
|
||||
void DrawComponent::server_send_update_final(MainServer& server, ServerClientID id) {
|
||||
server.netServer->send_items_to_all_clients(RELIABLE_COMMAND_CHANNEL, CLIENT_UPDATE_COMPONENT, false, id, *this);
|
||||
serverIsTempUpdate = false;
|
||||
}
|
||||
|
||||
void DrawComponent::server_send_transform_many(MainServer& server, const std::vector<std::pair<ServerClientID, CoordSpaceHelper>>& transforms) {
|
||||
server.netServer->send_items_to_all_clients(RELIABLE_COMMAND_CHANNEL, CLIENT_TRANSFORM_MANY_COMPONENTS, transforms);
|
||||
}
|
||||
|
||||
void DrawComponent::server_update(MainServer& server, ServerClientID id) {
|
||||
if(serverIsTempUpdate) {
|
||||
float timeSince = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - tempServerUpdateTimer).count();
|
||||
if(timeSince >= 1.0f) {
|
||||
server_send_update_final(server, id);
|
||||
serverIsTempUpdate = false;
|
||||
}
|
||||
bool DrawComponent::server_update(MainServer& server, ServerClientID id, const std::chrono::time_point<std::chrono::steady_clock>& tempServerUpdateTimer) {
|
||||
if((std::chrono::steady_clock::now() - tempServerUpdateTimer) >= CLIENT_DRAWCOMP_DELAY_TIMER_DURATION) {
|
||||
server_send_update_final(server, id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DrawComponent::get_used_resources(std::unordered_set<ServerClientID>& v) const {
|
||||
|
|
@ -112,8 +107,7 @@ bool DrawComponent::bounds_draw_check(const DrawData& drawData) const {
|
|||
|
||||
void DrawComponent::check_timers(DrawingProgram& drawP) {
|
||||
if(delayedUpdatePtr) {
|
||||
float updateDur = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastUpdateTime).count();
|
||||
if(updateDur > CLIENT_DRAWCOMP_DELAY_TIMER_DURATION) {
|
||||
if(std::chrono::steady_clock::now() - lastUpdateTime > CLIENT_DRAWCOMP_DELAY_TIMER_DURATION) {
|
||||
update_from_delayed_ptr();
|
||||
delayedUpdatePtr = nullptr;
|
||||
final_update(drawP);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include <include/core/SkVertices.h>
|
||||
#endif
|
||||
|
||||
#define CLIENT_DRAWCOMP_DELAY_TIMER_DURATION 5.0f
|
||||
#define CLIENT_DRAWCOMP_DELAY_TIMER_DURATION std::chrono::seconds(6)
|
||||
|
||||
#define DRAWCOMP_MAX_SHIFT_BEFORE_DISAPPEAR 20
|
||||
#define DRAWCOMP_MIN_SHIFT_BEFORE_DISAPPEAR 11
|
||||
|
|
@ -71,18 +71,13 @@ class DrawComponent {
|
|||
void server_send_update_final(MainServer& server, ServerClientID id);
|
||||
static void server_send_transform_many(MainServer& server, const std::vector<std::pair<ServerClientID, CoordSpaceHelper>>& transforms);
|
||||
|
||||
std::chrono::time_point<std::chrono::steady_clock> tempServerUpdateTimer;
|
||||
bool serverIsTempUpdate = false;
|
||||
|
||||
std::weak_ptr<CollabListType::ObjectInfo> collabListInfo;
|
||||
std::weak_ptr<DrawingProgramCacheBVHNode> parentBvhNode;
|
||||
|
||||
void server_update(MainServer& server, ServerClientID id);
|
||||
bool server_update(MainServer& server, ServerClientID id, const std::chrono::time_point<std::chrono::steady_clock>& tempServerUpdateTimer);
|
||||
|
||||
#ifndef IS_SERVER
|
||||
std::chrono::time_point<std::chrono::steady_clock> lastTransformTime;
|
||||
std::chrono::time_point<std::chrono::steady_clock> lastUpdateTime;
|
||||
|
||||
std::shared_ptr<DrawComponent> delayedUpdatePtr = nullptr;
|
||||
|
||||
bool bounds_draw_check(const DrawData& drawData) const;
|
||||
|
|
|
|||
|
|
@ -76,8 +76,7 @@ void DrawingProgram::init_client_callbacks() {
|
|||
if(!objPtr)
|
||||
return;
|
||||
std::shared_ptr<DrawComponent>& comp = objPtr->obj;
|
||||
float dur = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - comp->lastUpdateTime).count();
|
||||
if(dur > CLIENT_DRAWCOMP_DELAY_TIMER_DURATION){
|
||||
if((std::chrono::steady_clock::now() - comp->lastUpdateTime) > CLIENT_DRAWCOMP_DELAY_TIMER_DURATION){
|
||||
comp->delayedUpdatePtr = nullptr;
|
||||
message(*comp);
|
||||
if(isTemp)
|
||||
|
|
|
|||
|
|
@ -197,16 +197,20 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
});
|
||||
netServer->add_recv_callback(SERVER_UPDATE_COMPONENT, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) {
|
||||
bool isTemp;
|
||||
ServerClientID idToTransform;
|
||||
message(isTemp, idToTransform);
|
||||
auto it = data.idToComponentMap.find(idToTransform);
|
||||
ServerClientID idToUpdate;
|
||||
message(isTemp, idToUpdate);
|
||||
auto it = data.idToComponentMap.find(idToUpdate);
|
||||
if(it != data.idToComponentMap.end()) {
|
||||
std::shared_ptr<DrawComponent>& comp = it->second;
|
||||
message(*comp);
|
||||
if(isTemp)
|
||||
comp->server_send_update_temp(*this, idToTransform);
|
||||
else
|
||||
comp->server_send_update_final(*this, idToTransform);
|
||||
if(isTemp) {
|
||||
comp->server_send_update_temp(*this, idToUpdate);
|
||||
data.updateComponentTimers[idToUpdate] = std::chrono::steady_clock::now();
|
||||
}
|
||||
else {
|
||||
comp->server_send_update_final(*this, idToUpdate);
|
||||
data.updateComponentTimers.erase(idToUpdate);
|
||||
}
|
||||
}
|
||||
});
|
||||
netServer->add_recv_callback(SERVER_RESOURCE_INIT, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) {
|
||||
|
|
@ -305,8 +309,13 @@ void MainServer::ensure_display_name_unique(std::string& displayName) {
|
|||
|
||||
void MainServer::update() {
|
||||
netServer->update();
|
||||
for(auto& c : data.components)
|
||||
c.second->server_update(*this, c.first);
|
||||
std::erase_if(data.updateComponentTimers, [&](auto& c) {
|
||||
auto& [id, timer] = c;
|
||||
auto it = data.idToComponentMap.find(id);
|
||||
if(it == data.idToComponentMap.end())
|
||||
return true;
|
||||
return it->second->server_update(*this, id, timer);
|
||||
});
|
||||
if(std::chrono::steady_clock::now() - lastKeepAliveSent > std::chrono::seconds(2)) {
|
||||
netServer->send_items_to_all_clients(UNRELIABLE_COMMAND_CHANNEL, CLIENT_KEEP_ALIVE);
|
||||
lastKeepAliveSent = std::chrono::steady_clock::now();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class ServerData {
|
|||
std::vector<std::pair<ServerClientID, std::shared_ptr<DrawComponent>>> components;
|
||||
std::unordered_map<ServerClientID, std::shared_ptr<DrawComponent>> idToComponentMap;
|
||||
std::unordered_map<ServerClientID, ResourceData> resources;
|
||||
std::unordered_map<ServerClientID, std::chrono::time_point<std::chrono::steady_clock>> updateComponentTimers;
|
||||
std::unordered_map<std::string, Bookmark> bookmarks;
|
||||
void save(cereal::PortableBinaryOutputArchive& a) const;
|
||||
void write_to_file(cereal::PortableBinaryOutputArchive& a) const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue