DYTSrouce/src/workspace/WorkSpaceManager.cpp

95 lines
2.1 KiB
C++
Raw Normal View History

2025-01-04 04:12:51 +00:00
#include "workspace/WorkSpaceManager.h"
#include "workspace/WorkSpace.h"
#include "workspace/Timestep.h"
#include "common/SpdLogger.h"
#include<time.h>
template<> WorkSpaceManager* Singleton<WorkSpaceManager>::instance_ = nullptr;
WorkSpaceManager::WorkSpaceManager(QObject* parent)
: QObject(parent) {
}
WorkSpaceManager::~WorkSpaceManager() {
}
void WorkSpaceManager::OnDestory() {
}
bool WorkSpaceManager::Contains(const QString& name) const {
const auto itor = workSpaces_.find(name);
if (workSpaces_.end() != itor) {
return true;
}
return false;
}
2025-01-04 15:41:53 +00:00
bool WorkSpaceManager::Remove(const QString& name) {
auto itor = workSpaces_.find(name);
if (workSpaces_.end() == itor) {
return true;
}
WorkSpace* workspace = itor->second;
if (nullptr != workspace) {
workspace->deleteLater();
}
workSpaces_.erase(itor);
}
2025-01-04 04:12:51 +00:00
WorkSpace* WorkSpaceManager::LoadDyt(const QString& dyt, class OsgView* view) {
WorkSpace* workspace = new WorkSpace(view, this);
if (!workspace->Load(dyt)) {
LOG_WARN("load workspace failed");
workspace->deleteLater();
return nullptr;
}
workSpaces_[dyt] = workspace;
return workspace;
}
WorkSpace* WorkSpaceManager::GetOrCreate(const QString& path) {
const auto itor = workSpaces_.find(path);
if (workSpaces_.end() != itor) {
return itor->second;
}
LOG_INFO("create workspace name:{}", path.toStdString());
WorkSpace* workspace = new WorkSpace(path, this);
workSpaces_[path] = workspace;
return workspace;
}
void WorkSpaceManager::SetCurrent(WorkSpace* workspace) {
if (nullptr != current_) {
current_->End();
}
current_ = workspace;
lastTime_ = clock();
emit WorkSpaceChanged(current_);
}
void WorkSpaceManager::OnFrame() {
if (nullptr == current_) {
return;
}
constexpr double lockPreSecFre = 1.0 / CLOCKS_PER_SEC;
int64_t t = clock();
double dt = static_cast<double>(t - lastTime_) * lockPreSecFre;
Timestep* timeStep = current_->GetTimestep();
if (nullptr != timeStep) {
timeStep->Update(dt);
}
lastTime_ = t;
}