82 lines
1.8 KiB
C++
82 lines
1.8 KiB
C++
|
#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;
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|