コード例 #1
0
ファイル: workspace.cpp プロジェクト: LacusCon/behaviac
    void Workspace::LoadWorkspaceAbsolutePath()
    {
#if !BEHAVIAC_RELEASE

        if (Config::IsLoggingOrSocketing())
        {
            //relative to exe's current path
            const char* workspaceExportPath = this->GetFilePath();

            //workspaceExportPath is the path to the export:
            //like: ..\example\spaceship\data\bt\exported
            behaviac::string fullPath = StringUtils::CombineDir(workspaceExportPath, "behaviors.dbg.xml");
            behaviac::string workspaceFilePathRelative;
            bool bOk = LoadWorkspaceSetting(fullPath.c_str(), workspaceFilePathRelative);

            if (bOk)
            {
                //workspaceFilePathRelative stored in behaviors.dbg.xml is the path relative to export
                //convert it to the full path
                wchar_t* workspaceRootPath = this->m_workspace_file;
                workspaceRootPath[0] = '\0';

                if (behaviac::CFileManager::GetInstance()->PathIsRelative(workspaceExportPath))
                {
                    const behaviac::wstring currentWD = behaviac::CFileManager::GetInstance()->GetCurrentWorkingDirectory();
                    int len = currentWD.size();
                    BEHAVIAC_ASSERT(len + 1 < kMaxPath, "path is too long !");
                    wcscpy(workspaceRootPath, currentWD.c_str());
                    wchar_t last = workspaceRootPath[len - 1];

                    if (last != L'/' && last != L'\\')
                    {
                        workspaceRootPath[len] = L'/';
                        workspaceRootPath[len + 1] = L'\0';
                    }

                    m_workspaceExportPathAbs = workspaceRootPath;

                    //{
                    //    uint32_t p = m_workspaceExportPathAbs.find_last_of(STRING2WSTRING("Assets"));

                    //    if (p != (uint32_t)-1) {
                    //        m_workspaceExportPathAbs = m_workspaceExportPathAbs.substr(0, p);
                    //    }
                    //}

                    m_workspaceExportPathAbs = StringUtils::CombineDir(m_workspaceExportPathAbs.c_str(), STRING2WSTRING(workspaceExportPath).c_str());
                }
                else
                {
                    m_workspaceExportPathAbs = STRING2WSTRING(workspaceExportPath);
                }

                m_workspaceExportPathAbs = StringUtils::CombineDir(m_workspaceExportPathAbs.c_str(), STRING2WSTRING(workspaceFilePathRelative).c_str());

                //ms_workspace_file = m_workspaceExportPathAbs+workspaceFilePathRelative;
                wcscpy(m_workspace_file, m_workspaceExportPathAbs.c_str());
            }
            else
            {
            }
        }

#endif
    }
コード例 #2
0
ファイル: workspace.cpp プロジェクト: panyihua/behaviac
	bool Workspace::SetWorkspaceSettings(const char* workspaceExportPath, Workspace::EFileFormat format, float deltaTime, int deltaFrames)
	{
		ms_deltaTime = deltaTime;
		ms_deltaFrames = deltaFrames;
		ms_fileFormat = format;

		//debug to test bson
		//ms_fileFormat = EFF_bson;
		//a valid workspace file
		BEHAVIAC_ASSERT(workspaceExportPath && workspaceExportPath[0] != '\0');

		strcpy(ms_workspace_export_path, workspaceExportPath);

		{
			int len = strlen(ms_workspace_export_path);
			BEHAVIAC_ASSERT(len < kMaxPath - 1);
			if (ms_workspace_export_path[len - 1] != '/' && ms_workspace_export_path[len - 1] != '\\')
			{
				ms_workspace_export_path[len] = '/';
				ms_workspace_export_path[len + 1] = '\0';
			}
			else
			{
				//ended with '/'
				BEHAVIAC_ASSERT(ms_workspace_export_path[len - 1] == '\\' || ms_workspace_export_path[len - 1] == '/');
			}
		}

		//ms_workspace_root_path is the path to the export:
		//like: E:\WWWW\IEDDepot\ETC_Depot\tag\extension\behaviac\example\spaceship\data\bt\exported
		behaviac::string fullPath = ms_workspace_export_path;
		fullPath += "behaviors.dbg.xml";

		behaviac::string workspacePathRelative;
		bool bOk = LoadWorkspaceSetting(fullPath.c_str(), workspacePathRelative);
		if (bOk)
		{
			//workspacePath stored in behaviors.dbg.xml is the path relative to export
			//convert it to the full path
			wchar_t* workspaceRootPath = ms_workspace_file;
			workspaceRootPath[0] = '\0';

			if (CFileManager::GetInstance()->PathIsRelative(ms_workspace_export_path))
			{
				const behaviac::wstring currentWD = CFileManager::GetInstance()->GetCurrentWorkingDirectory().c_str();
				int len = currentWD.size();

				BEHAVIAC_ASSERT(len < kMaxPath);
				wcscpy(workspaceRootPath, currentWD.c_str());

				wchar_t last = workspaceRootPath[len - 1];
				if (last != L'/' && last != L'\\')
				{
					workspaceRootPath[len] = L'/';
					workspaceRootPath[len + 1] = L'\0';
				}
			}

			behaviac::wstring workspaceRootPathAbs = workspaceRootPath;

			//the first char is not the separator
			BEHAVIAC_ASSERT(ms_workspace_export_path[0] != '/' && ms_workspace_export_path[0] != '\\');

			workspaceRootPathAbs += STRING2WSTRING(ms_workspace_export_path);
			workspaceRootPathAbs += STRING2WSTRING(workspacePathRelative);

			wcscpy(ms_workspace_file, workspaceRootPathAbs.c_str());

			Socket::SendWorkspaceSettings();

			return true;
		}

		return false;
	}