2015-12-13 21:01:32 +00:00
|
|
|
#include "ProjectManager.hpp"
|
2016-01-04 05:31:02 +00:00
|
|
|
#include "ViewManager.hpp"
|
|
|
|
#include "../DataSpecRegistry.hpp"
|
2015-12-13 21:01:32 +00:00
|
|
|
|
2016-03-05 00:03:41 +00:00
|
|
|
namespace urde
|
2015-12-13 21:01:32 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
static logvisor::Module Log("URDE::ProjectManager");
|
2016-04-14 21:42:47 +00:00
|
|
|
ProjectManager* ProjectManager::g_SharedManager = nullptr;
|
2016-01-04 05:31:02 +00:00
|
|
|
|
2016-04-11 03:59:54 +00:00
|
|
|
CToken ProjectResourcePool::GetObj(const char* name)
|
2016-04-05 01:51:25 +00:00
|
|
|
{
|
|
|
|
CToken ret = CSimplePool::GetObj(name);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
hecl::ProjectPath path(*m_parent.project(), name);
|
|
|
|
SObjectTag tag = static_cast<ProjectResourceFactoryBase&>(x30_factory).
|
|
|
|
TagFromPath(path, hecl::SharedBlenderToken);
|
|
|
|
if (tag)
|
|
|
|
return CSimplePool::GetObj(tag);
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2016-04-11 03:59:54 +00:00
|
|
|
CToken ProjectResourcePool::GetObj(const char* name, const CVParamTransfer& pvxfer)
|
2016-04-05 01:51:25 +00:00
|
|
|
{
|
|
|
|
CToken ret = CSimplePool::GetObj(name, pvxfer);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
hecl::ProjectPath path(*m_parent.project(), name);
|
|
|
|
SObjectTag tag = static_cast<ProjectResourceFactoryBase&>(x30_factory).
|
|
|
|
TagFromPath(path, hecl::SharedBlenderToken);
|
|
|
|
if (tag)
|
|
|
|
return CSimplePool::GetObj(tag, pvxfer);
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2016-01-04 05:31:02 +00:00
|
|
|
bool ProjectManager::m_registeredSpecs = false;
|
|
|
|
ProjectManager::ProjectManager(ViewManager &vm)
|
2016-04-05 01:51:25 +00:00
|
|
|
: m_vm(vm), m_clientProc(1), m_factoryMP1(m_clientProc), m_objStore(m_factoryMP1, *this)
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
|
|
|
if (!m_registeredSpecs)
|
|
|
|
{
|
|
|
|
HECLRegisterDataSpecs();
|
|
|
|
m_registeredSpecs = true;
|
|
|
|
}
|
2016-04-14 21:42:47 +00:00
|
|
|
g_SharedManager = this;
|
2016-01-04 05:31:02 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool ProjectManager::newProject(const hecl::SystemString& path)
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::ProjectRootPath projPath = hecl::SearchForProject(path);
|
2016-01-04 05:31:02 +00:00
|
|
|
if (projPath)
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
Log.report(logvisor::Warning, _S("project already exists at '%s'"), path.c_str());
|
2016-01-04 05:31:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::MakeDir(path.c_str());
|
|
|
|
m_proj.reset(new hecl::Database::Project(path));
|
2016-01-04 05:31:02 +00:00
|
|
|
if (!*m_proj)
|
|
|
|
{
|
|
|
|
m_proj.reset();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-07 03:12:32 +00:00
|
|
|
m_vm.ProjectChanged(*m_proj);
|
2016-01-05 00:01:02 +00:00
|
|
|
m_vm.SetupEditorView();
|
|
|
|
saveProject();
|
2016-03-07 03:12:32 +00:00
|
|
|
|
|
|
|
hecl::SystemString windowTitle(m_proj->getProjectRootPath().getLastComponent());
|
2016-08-05 03:21:19 +00:00
|
|
|
windowTitle += _S(" - URDE [") + hecl::SystemString(m_vm.platformName()) + _S("]");
|
2016-03-07 03:12:32 +00:00
|
|
|
m_vm.m_mainWindow->setTitle(windowTitle.c_str());
|
2016-01-05 00:01:02 +00:00
|
|
|
m_vm.DismissSplash();
|
|
|
|
m_vm.FadeInEditors();
|
|
|
|
|
2016-01-04 05:31:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool ProjectManager::openProject(const hecl::SystemString& path)
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::ProjectRootPath projPath = hecl::SearchForProject(path);
|
2016-01-04 05:31:02 +00:00
|
|
|
if (!projPath)
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
Log.report(logvisor::Warning, _S("project doesn't exist at '%s'"), path.c_str());
|
2016-01-04 05:31:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
m_proj.reset(new hecl::Database::Project(projPath));
|
2016-01-04 05:31:02 +00:00
|
|
|
if (!*m_proj)
|
|
|
|
{
|
|
|
|
m_proj.reset();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::ProjectPath urdeSpacesPath(*m_proj, _S(".hecl/urde_spaces.yaml"));
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileReader reader(urdeSpacesPath.getAbsolutePath());
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-04-15 20:42:40 +00:00
|
|
|
bool needsSave = false;
|
2016-03-04 23:04:53 +00:00
|
|
|
athena::io::YAMLDocReader r;
|
2016-08-22 03:47:48 +00:00
|
|
|
if (!reader.isOpen())
|
2016-04-15 20:42:40 +00:00
|
|
|
{
|
|
|
|
needsSave = true;
|
2016-04-15 20:58:49 +00:00
|
|
|
goto makeProj;
|
2016-04-15 20:42:40 +00:00
|
|
|
}
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-08-22 03:47:48 +00:00
|
|
|
yaml_parser_set_input(r.getParser(), (yaml_read_handler_t*)athena::io::YAMLAthenaReader, &reader);
|
2016-03-01 20:29:18 +00:00
|
|
|
if (!r.ValidateClassType("UrdeSpacesState"))
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
2016-04-15 20:42:40 +00:00
|
|
|
needsSave = true;
|
2016-04-15 20:58:49 +00:00
|
|
|
goto makeProj;
|
2016-01-05 00:01:02 +00:00
|
|
|
}
|
2016-01-04 05:31:02 +00:00
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
r.reset();
|
2016-08-22 03:47:48 +00:00
|
|
|
reader.seek(0, athena::Begin);
|
|
|
|
if (!r.parse(&reader))
|
2016-01-05 00:01:02 +00:00
|
|
|
{
|
2016-04-15 20:42:40 +00:00
|
|
|
needsSave = true;
|
2016-04-15 20:58:49 +00:00
|
|
|
goto makeProj;
|
2016-01-04 05:31:02 +00:00
|
|
|
}
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-04-15 20:58:49 +00:00
|
|
|
makeProj:
|
2016-03-07 03:12:32 +00:00
|
|
|
m_vm.ProjectChanged(*m_proj);
|
2016-04-15 20:58:49 +00:00
|
|
|
|
|
|
|
if (!needsSave)
|
|
|
|
m_vm.SetupEditorView(r);
|
|
|
|
else
|
|
|
|
m_vm.SetupEditorView();
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-03-26 00:51:59 +00:00
|
|
|
m_factoryMP1.IndexMP1Resources(*m_proj);
|
2016-09-14 05:54:09 +00:00
|
|
|
m_mainMP1.emplace(m_factoryMP1, m_objStore, m_vm.m_mainBooFactory,
|
|
|
|
m_vm.m_mainCommandQueue, m_vm.m_renderTex, *m_vm.m_amuseAllocWrapper);
|
2016-04-15 20:42:40 +00:00
|
|
|
m_vm.InitMP1(*m_mainMP1);
|
2016-02-16 05:50:41 +00:00
|
|
|
m_vm.BuildTestPART(m_objStore);
|
2016-03-07 03:12:32 +00:00
|
|
|
|
2016-04-15 20:42:40 +00:00
|
|
|
if (needsSave)
|
|
|
|
saveProject();
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-03-07 03:12:32 +00:00
|
|
|
{
|
|
|
|
hecl::SystemString windowTitle(m_proj->getProjectRootPath().getLastComponent());
|
2016-08-05 03:21:19 +00:00
|
|
|
windowTitle += _S(" - URDE [") + hecl::SystemString(m_vm.platformName()) + _S("]");
|
2016-03-07 03:12:32 +00:00
|
|
|
m_vm.m_mainWindow->setTitle(windowTitle.c_str());
|
|
|
|
}
|
2016-01-05 00:01:02 +00:00
|
|
|
m_vm.DismissSplash();
|
|
|
|
m_vm.FadeInEditors();
|
2016-04-15 20:42:40 +00:00
|
|
|
m_vm.pushRecentProject(m_proj->getProjectRootPath().getAbsolutePath());
|
2016-01-04 05:31:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool ProjectManager::extractGame(const hecl::SystemString& path)
|
2016-01-04 05:31:02 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-13 21:01:32 +00:00
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
bool ProjectManager::saveProject()
|
|
|
|
{
|
|
|
|
if (!m_proj)
|
|
|
|
return false;
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::ProjectPath oldSpacesPath(*m_proj, _S(".hecl/~urde_spaces.yaml"));
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileWriter writer(oldSpacesPath.getAbsolutePath());
|
|
|
|
if (!writer.isOpen())
|
2016-01-05 00:01:02 +00:00
|
|
|
return false;
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
athena::io::YAMLDocWriter w("UrdeSpacesState");
|
2016-01-05 00:01:02 +00:00
|
|
|
m_vm.SaveEditorView(w);
|
2016-08-22 03:47:48 +00:00
|
|
|
if (!w.finish(&writer))
|
2016-01-05 00:01:02 +00:00
|
|
|
return false;
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::ProjectPath newSpacesPath(*m_proj, _S(".hecl/urde_spaces.yaml"));
|
2016-01-05 00:01:02 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::Unlink(newSpacesPath.getAbsolutePath().c_str());
|
|
|
|
hecl::Rename(oldSpacesPath.getAbsolutePath().c_str(),
|
2016-01-05 00:01:02 +00:00
|
|
|
newSpacesPath.getAbsolutePath().c_str());
|
|
|
|
|
2016-01-16 03:58:11 +00:00
|
|
|
m_vm.pushRecentProject(m_proj->getProjectRootPath().getAbsolutePath());
|
|
|
|
|
2016-01-05 00:01:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-24 04:03:30 +00:00
|
|
|
void ProjectManager::mainUpdate()
|
|
|
|
{
|
|
|
|
if (m_mainMP1)
|
|
|
|
m_mainMP1->Proc();
|
|
|
|
}
|
|
|
|
|
2016-09-14 05:54:09 +00:00
|
|
|
void ProjectManager::mainDraw()
|
|
|
|
{
|
|
|
|
if (m_mainMP1)
|
|
|
|
m_mainMP1->Draw();
|
|
|
|
}
|
|
|
|
|
2016-04-24 04:03:30 +00:00
|
|
|
void ProjectManager::asyncIdle()
|
|
|
|
{
|
|
|
|
m_factoryMP1.AsyncIdle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectManager::shutdown()
|
|
|
|
{
|
|
|
|
if (m_mainMP1)
|
|
|
|
m_mainMP1->Shutdown();
|
|
|
|
m_clientProc.shutdown();
|
|
|
|
m_factoryMP1.Shutdown();
|
|
|
|
}
|
|
|
|
|
2015-12-13 21:01:32 +00:00
|
|
|
}
|