Exemplo n.º 1
0
    bool Workspace::TryInit()
    {
        if (this->m_bInited)
        {
            return true;
        }

        this->m_bInited = true;

        bool bOk = TryStart();

        if (!bOk)
        {
            return false;
        }

        if (this->GetFileFormat() == EFF_cpp || this->GetFileFormat() == EFF_default)
        {
            GenerationManager::RegisterBehaviors();
        }

        const char* szWorkspaceExportPath = this->GetFilePath();

        if (StringUtils::IsNullOrEmpty(szWorkspaceExportPath))
        {
            LogManager::GetInstance()->Error("No 'WorkspaceExportPath' is specified!");
            BEHAVIAC_ASSERT(false);

            return false;
        }

        BEHAVIAC_LOGINFO("'WorkspaceExportPath' is '%s'\n", szWorkspaceExportPath);

        //BEHAVIAC_ASSERT(!StringUtils::EndsWith(szWorkspaceExportPath, "\\"), "use '/' instead of '\\'");

        LoadWorkspaceAbsolutePath();

#if BEHAVIAC_ENABLE_HOTRELOAD
		if (behaviac::Config::IsHotReload())
		{
			behaviac::wstring dir = behaviac::StringUtils::Char2Wide(szWorkspaceExportPath);
			CFileSystem::StartMonitoringDirectory(dir.c_str());
		}
#endif//BEHAVIAC_ENABLE_HOTRELOAD

        //////////////////////////////////////////////////////////
        //this->RegisterStuff();
        AgentProperties::RegisterCustomizedTypes();

        AgentProperties::Load();

#if !BEHAVIAC_RELEASE
        LogWorkspaceInfo();
#endif

        return true;
    }
    bool Workspace::TryInit()
    {
        if (this->m_bInited)
        {
            return true;
        }

        this->m_bInited = true;

        bool bOk = TryStart();

        if (!bOk)
        {
            return false;
        }

        if (this->GetFileFormat() == EFF_cpp || this->GetFileFormat() == EFF_default)
        {
            GenerationManager::RegisterBehaviors();
        }

        const char* szWorkspaceExportPath = this->GetFilePath();

        if (StringUtils::IsNullOrEmpty(szWorkspaceExportPath))
        {
            LogManager::GetInstance()->Error("No 'WorkspaceExportPath' is specified!");
            BEHAVIAC_ASSERT(false);

            return false;
        }

        BEHAVIAC_LOGINFO("'WorkspaceExportPath' is '%s'\n", szWorkspaceExportPath);

        //BEHAVIAC_ASSERT(!StringUtils::EndsWith(szWorkspaceExportPath, "\\"), "use '/' instead of '\\'");

        LoadWorkspaceAbsolutePath();

		m_deltaTime = 0.0167f;
        m_deltaFrames = 1;

#if BEHAVIAC_ENABLE_HOTRELOAD
        behaviac::wstring dir = behaviac::StringUtils::Char2Wide(szWorkspaceExportPath);
        CFileSystem::StartMonitoringDirectory(dir.c_str());
#endif//BEHAVIAC_ENABLE_HOTRELOAD

        //////////////////////////////////////////////////////////
        //this->RegisterStuff();
        AgentProperties::RegisterCustomizedTypes();

        AgentProperties::Load();

#if !BEHAVIAC_RELEASE
#if BEHAVIAC_HOTRELOAD

        // set the file watcher
        if (Config.IsDesktop)
        {
            if (this->GetFileFormat() != EFF_cs)
            {
                if (m_DirectoryMonitor == null)
                {
                    m_DirectoryMonitor = new DirectoryMonitor();
                    m_DirectoryMonitor.Changed += new DirectoryMonitor.FileSystemEvent(OnFileChanged);
                }

                string filter = "*.*";

                if (this->GetFileFormat() == EFF_xml)
                {
                    filter = "*.xml";

                }
                else if (this->GetFileFormat() == EFF_bson)
                {
                    filter = "*.bson.bytes";
                }

                m_DirectoryMonitor.Start(this->WorkspaceExportPath, filter);
            }
        }