metaforce/Editor/ViewManager.cpp

308 lines
9.2 KiB
C++
Raw Normal View History

#include "ViewManager.hpp"
2016-03-04 15:04:53 -08:00
#include "specter/Control.hpp"
#include "specter/Space.hpp"
#include "specter/Menu.hpp"
2015-12-23 19:32:21 -08:00
#include "SplashScreen.hpp"
2015-12-30 19:20:52 -08:00
#include "locale/locale.hpp"
2016-01-06 16:40:27 -08:00
#include "ResourceBrowser.hpp"
2016-01-18 15:33:23 -08:00
#include "icons/icons.hpp"
2016-07-16 12:21:12 -07:00
#include "badging/Badging.hpp"
2016-02-16 21:20:34 -08:00
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Particle/CElectricDescription.hpp"
#include "Runtime/Particle/CSwooshDescription.hpp"
2016-03-04 15:04:53 -08:00
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
2016-04-09 16:19:17 -07:00
#include "Runtime/Character/CSkinRules.hpp"
2016-08-03 14:53:03 -07:00
#include "Graphics/CMetroidModelInstance.hpp"
2016-08-16 21:59:05 -07:00
#include "World/CWorldTransManager.hpp"
#include "Graphics/Shaders/CColoredQuadFilter.hpp"
#include "Graphics/Shaders/CTexturedQuadFilter.hpp"
#include "Audio/CStreamAudioManager.hpp"
2016-01-15 19:58:11 -08:00
#include <cstdio>
2016-03-04 15:04:53 -08:00
using YAMLNode = athena::io::YAMLNode;
2016-03-04 16:03:41 -08:00
namespace urde
{
void ViewManager::InitMP1(MP1::CMain& main)
{
main.Init(m_fileStoreManager, m_mainWindow.get(), m_voiceEngine.get(), *m_amuseAllocWrapper);
2017-11-11 21:14:57 -08:00
if (!m_noShaderWarmup)
main.WarmupShaders();
m_testGameView.reset(new TestGameView(*this, m_viewResources, *m_rootView));
2016-03-28 14:38:48 -07:00
m_rootView->accessContentViews().clear();
2017-01-22 13:26:58 -08:00
m_rootView->accessContentViews().push_back(m_testGameView.get());
m_rootView->updateSize();
}
2017-01-22 13:26:58 -08:00
void ViewManager::TestGameView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
2016-03-04 15:04:53 -08:00
specter::View::resized(root, sub);
urde::CGraphics::SetViewportResolution({sub.size[0], sub.size[1]});
}
void ViewManager::TestGameView::draw(boo::IGraphicsCommandQueue* gfxQ)
{
m_vm.m_projManager.mainDraw();
}
2016-03-04 15:04:53 -08:00
specter::View* ViewManager::BuildSpaceViews()
{
2016-01-10 18:17:08 -08:00
m_rootSpaceView = m_rootSpace->buildSpaceView(m_viewResources);
2016-01-04 16:01:02 -08:00
return m_rootSpaceView;
}
2016-03-04 15:04:53 -08:00
specter::RootView* ViewManager::SetupRootView()
{
2016-03-04 15:04:53 -08:00
m_rootView.reset(new specter::RootView(*this, m_viewResources, m_mainWindow.get()));
m_rootView->setBackground(zeus::CColor::skBlack);
2016-01-04 16:01:02 -08:00
return m_rootView.get();
2015-12-12 18:27:34 -08:00
}
2016-01-04 16:01:02 -08:00
SplashScreen* ViewManager::SetupSplashView()
2015-12-12 18:27:34 -08:00
{
m_splash.reset(new SplashScreen(*this, m_viewResources));
2016-01-04 16:01:02 -08:00
if (!m_showSplash)
m_splash->close(true);
return m_splash.get();
2015-12-12 18:27:34 -08:00
}
2016-03-04 15:04:53 -08:00
void ViewManager::RootSpaceViewBuilt(specter::View *view)
2016-01-10 18:17:08 -08:00
{
2016-03-04 15:04:53 -08:00
std::vector<specter::View*>& cViews = m_rootView->accessContentViews();
2016-01-10 18:17:08 -08:00
cViews.clear();
cViews.push_back(view);
cViews.push_back(m_splash.get());
m_rootView->updateSize();
}
2016-03-06 19:12:32 -08:00
void ViewManager::ProjectChanged(hecl::Database::Project& proj)
{
CDvdFile::Shutdown();
CDvdFile::Initialize(hecl::ProjectPath(proj.getProjectWorkingPath(), _S("out/MP1")));
}
2015-12-12 18:27:34 -08:00
void ViewManager::SetupEditorView()
{
m_rootSpace.reset(new RootSpace(*this));
2016-03-04 15:04:53 -08:00
SplitSpace* split = new SplitSpace(*this, nullptr, specter::SplitView::Axis::Horizontal);
m_rootSpace->setChild(std::unique_ptr<Space>(split));
split->setChildSlot(0, std::make_unique<ResourceBrowser>(*this, split));
split->setChildSlot(1, std::make_unique<ResourceBrowser>(*this, split));
2016-01-04 16:01:02 -08:00
2016-01-10 18:17:08 -08:00
BuildSpaceViews();
2016-01-03 21:31:02 -08:00
}
2016-01-04 16:01:02 -08:00
void ViewManager::SetupEditorView(ConfigReader& r)
2016-01-03 21:31:02 -08:00
{
m_rootSpace.reset(Space::NewRootSpaceFromConfigStream(*this, r));
2016-01-10 18:17:08 -08:00
BuildSpaceViews();
2016-01-04 16:01:02 -08:00
}
void ViewManager::SaveEditorView(ConfigWriter& w)
{
if (!m_rootSpace)
return;
m_rootSpace->saveState(w);
}
void ViewManager::DismissSplash()
{
if (!m_showSplash)
return;
2016-01-03 21:31:02 -08:00
m_showSplash = false;
2016-01-04 16:01:02 -08:00
m_splash->close();
}
2016-03-04 15:04:53 -08:00
ViewManager::ViewManager(hecl::Runtime::FileStoreManager& fileMgr, hecl::CVarManager& cvarMgr)
2016-01-03 21:31:02 -08:00
: m_fileStoreManager(fileMgr), m_cvarManager(cvarMgr), m_projManager(*this),
m_fontCache(fileMgr), m_translator(urde::SystemLocaleOrEnglish()),
2017-11-12 22:19:18 -08:00
m_recentProjectsPath(hecl::SysFormat(_S("%s/recent_projects.txt"), fileMgr.getStoreRoot().data())),
m_recentFilesPath(hecl::SysFormat(_S("%s/recent_files.txt"), fileMgr.getStoreRoot().data()))
2016-01-15 19:58:11 -08:00
{
2016-02-01 12:04:55 -08:00
Space::SpaceMenuNode::InitializeStrings(*this);
2016-01-15 19:58:11 -08:00
char path[2048];
2016-03-04 15:04:53 -08:00
hecl::Sstat theStat;
2016-01-15 19:58:11 -08:00
2016-03-04 15:04:53 -08:00
FILE* fp = hecl::Fopen(m_recentProjectsPath.c_str(), _S("r"), hecl::FileLockType::Read);
2016-01-15 19:58:11 -08:00
if (fp)
{
while (fgets(path, 2048, fp))
{
std::string pathStr(path);
pathStr.pop_back();
2017-11-12 22:19:18 -08:00
hecl::SystemStringConv pathStrView(pathStr);
2016-03-04 15:04:53 -08:00
if (!hecl::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode))
2017-11-12 22:19:18 -08:00
m_recentProjects.emplace_back(pathStrView.sys_str());
2016-01-15 19:58:11 -08:00
}
fclose(fp);
}
2016-03-04 15:04:53 -08:00
fp = hecl::Fopen(m_recentFilesPath.c_str(), _S("r"), hecl::FileLockType::Read);
2016-01-15 19:58:11 -08:00
if (fp)
{
while (fgets(path, 2048, fp))
{
std::string pathStr(path);
pathStr.pop_back();
2017-11-12 22:19:18 -08:00
hecl::SystemStringConv pathStrView(pathStr);
2016-03-04 15:04:53 -08:00
if (!hecl::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode))
2017-11-12 22:19:18 -08:00
m_recentFiles.emplace_back(pathStrView.sys_str());
2016-01-15 19:58:11 -08:00
}
fclose(fp);
}
}
2015-12-12 18:27:34 -08:00
ViewManager::~ViewManager() {}
2017-11-12 22:19:18 -08:00
void ViewManager::pushRecentProject(hecl::SystemStringView path)
2016-01-01 18:27:46 -08:00
{
2016-03-04 15:04:53 -08:00
for (hecl::SystemString& testPath : m_recentProjects)
2016-01-15 19:58:11 -08:00
{
if (path == testPath)
return;
}
2017-11-12 22:19:18 -08:00
m_recentProjects.emplace_back(path);
2016-03-04 15:04:53 -08:00
FILE* fp = hecl::Fopen(m_recentProjectsPath.c_str(), _S("w"), hecl::FileLockType::Write);
2016-01-15 19:58:11 -08:00
if (fp)
{
2016-03-04 15:04:53 -08:00
for (hecl::SystemString& pPath : m_recentProjects)
2017-11-12 22:19:18 -08:00
fprintf(fp, "%s\n", hecl::SystemUTF8Conv(pPath).c_str());
2016-01-15 19:58:11 -08:00
fclose(fp);
}
2016-01-01 18:27:46 -08:00
}
2017-11-12 22:19:18 -08:00
void ViewManager::pushRecentFile(hecl::SystemStringView path)
2016-01-01 18:27:46 -08:00
{
2016-03-04 15:04:53 -08:00
for (hecl::SystemString& testPath : m_recentFiles)
2016-01-15 19:58:11 -08:00
{
if (path == testPath)
return;
}
2017-11-12 22:19:18 -08:00
m_recentFiles.emplace_back(path);
2016-03-04 15:04:53 -08:00
FILE* fp = hecl::Fopen(m_recentFilesPath.c_str(), _S("w"), hecl::FileLockType::Write);
2016-01-15 19:58:11 -08:00
if (fp)
{
2016-03-04 15:04:53 -08:00
for (hecl::SystemString& pPath : m_recentFiles)
2017-11-12 22:19:18 -08:00
fprintf(fp, "%s\n", hecl::SystemUTF8Conv(pPath).c_str());
2016-01-15 19:58:11 -08:00
fclose(fp);
}}
2016-01-01 18:27:46 -08:00
void ViewManager::init(boo::IApplication* app)
{
2017-07-16 20:04:14 -07:00
m_mainWindow = app->newWindow(_S("URDE"), 1);
m_mainWindow->showWindow();
m_mainWindow->setWaitCursor(true);
2016-12-09 18:35:09 -08:00
float pixelFactor = m_mainWindow->getVirtualPixelFactor();
2016-04-15 13:42:40 -07:00
m_mainBooFactory = m_mainWindow->getMainContextDataFactory();
m_mainPlatformName = m_mainBooFactory->platformName();
m_mainWindow->setTitle(_S("URDE [") + hecl::SystemString(m_mainPlatformName) + _S("]"));
2016-04-15 13:42:40 -07:00
m_mainCommandQueue = m_mainWindow->getCommandQueue();
m_viewResources.init(m_mainBooFactory, &m_fontCache, &m_themeData, pixelFactor);
InitializeIcons(m_viewResources);
InitializeBadging(m_viewResources);
2015-12-12 18:27:34 -08:00
m_viewResources.prepFontCacheAsync(m_mainWindow.get());
2016-03-04 15:04:53 -08:00
specter::RootView* root = SetupRootView();
2016-01-04 16:01:02 -08:00
m_showSplash = true;
root->accessContentViews().push_back(SetupSplashView());
root->updateSize();
2016-04-15 13:42:40 -07:00
m_renderTex = root->renderTex();
m_mainWindow->setWaitCursor(false);
2016-03-23 17:05:56 -07:00
m_voiceEngine = boo::NewAudioVoiceEngine();
2017-12-20 19:19:54 -08:00
m_voiceEngine->setVolume(0.7f);
2016-09-13 22:54:09 -07:00
m_amuseAllocWrapper.emplace(*m_voiceEngine);
for (const auto& arg : app->getArgs())
{
2017-11-11 21:14:57 -08:00
if (m_deferedProject.empty() && hecl::SearchForProject(arg))
m_deferedProject = arg;
2017-11-11 21:14:57 -08:00
if (arg == _S("--no-shader-warmup"))
m_noShaderWarmup = true;
2017-12-20 19:19:54 -08:00
else if (arg == _S("--no-sound"))
m_voiceEngine->setVolume(0.f);
}
}
bool ViewManager::proc()
{
if (!m_deferedProject.empty() && m_viewResources.fontCacheReady())
{
m_projManager.openProject(m_deferedProject);
m_deferedProject.clear();
}
boo::IGraphicsCommandQueue* gfxQ = m_mainWindow->getCommandQueue();
if (m_rootView->isDestroyed())
return false;
2016-01-04 16:01:02 -08:00
2015-12-08 17:04:50 -08:00
if (m_updatePf)
{
m_viewResources.resetPixelFactor(m_reqPf);
2016-03-04 15:04:53 -08:00
specter::RootView* root = SetupRootView();
2016-01-04 16:01:02 -08:00
if (m_rootSpace)
2016-01-10 18:17:08 -08:00
BuildSpaceViews();
else
{
2016-03-04 15:04:53 -08:00
std::vector<specter::View*>& cViews = m_rootView->accessContentViews();
2016-01-10 18:17:08 -08:00
cViews.push_back(SetupSplashView());
}
2016-01-04 16:01:02 -08:00
root->updateSize();
2015-12-08 17:04:50 -08:00
m_updatePf = false;
}
2016-01-04 16:01:02 -08:00
m_rootView->dispatchEvents();
2016-01-30 17:08:31 -08:00
m_rootView->internalThink();
2016-01-04 16:01:02 -08:00
if (m_rootSpace)
m_rootSpace->think();
if (m_splash)
2015-12-12 18:27:34 -08:00
m_splash->think();
2016-01-04 16:01:02 -08:00
2016-01-10 18:17:08 -08:00
if (m_deferSplit)
{
2016-01-11 16:46:27 -08:00
SplitSpace* ss = static_cast<SplitSpace*>(m_deferSplit->spaceSplit(m_deferSplitAxis, m_deferSplitThisSlot));
m_rootView->startSplitDrag(ss->splitView(), m_deferSplitCoord);
2016-01-10 18:17:08 -08:00
m_deferSplit = nullptr;
}
2016-01-04 16:01:02 -08:00
++m_editorFrames;
if (m_rootSpaceView && m_editorFrames <= 30)
2016-03-04 15:04:53 -08:00
m_rootSpaceView->setMultiplyColor(zeus::CColor::lerp({1,1,1,0}, {1,1,1,1}, m_editorFrames / 30.0));
2016-01-04 16:01:02 -08:00
m_projManager.mainUpdate();
2016-04-15 13:42:40 -07:00
if (g_Renderer)
g_Renderer->BeginScene();
m_rootView->draw(gfxQ);
if (g_Renderer)
g_Renderer->EndScene();
gfxQ->execute();
if (g_ResFactory)
g_ResFactory->AsyncIdle();
m_mainWindow->waitForRetrace(m_voiceEngine.get());
2016-09-08 21:19:19 -07:00
CBooModel::ClearModelUniformCounters();
CGraphics::TickRenderTimings();
2017-12-11 18:06:19 -08:00
++logvisor::FrameIndex;
return true;
}
void ViewManager::stop()
{
2016-03-07 23:10:52 -08:00
m_videoVoice.reset();
m_projManager.shutdown();
CDvdFile::Shutdown();
DestroyIcons();
DestroyBadging();
2016-02-24 13:21:09 -08:00
m_viewResources.destroyResData();
m_fontCache.destroyAtlases();
m_mainWindow->getCommandQueue()->stopRenderer();
}
}