int P4ClientApi::FormatSpec( const char * type, int table ) { if ( !specMgr.HaveSpecDef( type ) ) { StrBuf m; m = "No spec definition for "; m.Append( type ); m.Append( " objects." ); return Except( "P4#format_spec", m.Text() ); } // Got a specdef so now we can attempt to convert. StrBuf buf; Error e; specMgr.SpecToString( type, table, buf, &e ); if( !e.Test() ) { lua_pushstring( L, buf.Text() ); return 1; } StrBuf m; m = "Error converting hash to a string."; if( e.Test() ) e.Fmt( m, EF_PLAIN ); return Except( "P4#format_spec", m.Text() ); }
int P4ClientAPI::SetCharset( const char *c ) { if( P4LUADEBUG_COMMANDS ) fprintf( stderr, "[P4] Setting charset: %s\n", c ); CharSetApi::CharSet cs = CharSetApi::NOCONV; if ( strlen(c) > 0 ) { cs = CharSetApi::Lookup( c ); if( cs < 0 ) { if( exceptionLevel ) { StrBuf m; m = "Unknown or unsupported charset: "; m.Append( c ); return Except( "P4.charset", m.Text() ); } return 0; } } if( CharSetApi::Granularity( cs ) != 1 ) { return Except( "P4.charset", "P4Lua does not support a wide charset!"); } client.SetCharset(c); client.SetTrans( cs, cs, cs, cs ); return 1; }
//-------------------------------------------------------------------------------------------------------------- //创建二维纹理 Texture* D3D9TextureManager::CreateTexture( UINT nWidth, UINT nHeight, PixelFormat ePixelFormat, TextureUsage Type, int nNumLevels ) { //如果为压缩纹理格式 if( ePixelFormat & PF_COMPRESS_MASK ) { //检测指定纹理压缩格式是否可用 if( !CheckCompressFormat( ePixelFormat ) ) Except( Exception::ERR_INTERNAL_ERROR, "硬件不支持指定的纹理压缩格式,无法创建纹理。" ); if( !IsPow2( nWidth ) || !IsPow2( nHeight ) ) Except( Exception::ERR_INTERNAL_ERROR, "无法创建非 2 次幂尺寸的压缩纹理。" ); } //获取最佳的纹理尺寸 UINT texWidth = 0; UINT texHeight = 0; GetBestSize( nWidth, nHeight, texWidth, texHeight ); nNumLevels = (UINT)( ( nNumLevels == -1 ) ? mDefTexLevels : nNumLevels ); Texture* pTex = new D3D9Texture( texWidth, texHeight, ePixelFormat, nNumLevels, Type ); *mTextureList.Push() = pTex; ++mNumTextures; return pTex; }
int P4ClientAPI::Run( const char *cmd, int argc, char * const *argv ) { // Save the entire command string for our error messages. Makes it // easy to see where a script has gone wrong. StrBuf cmdString; cmdString << "\"p4 " << cmd; for( int i = 0; i < argc; i++ ) cmdString << " " << argv[ i ]; cmdString << "\""; if ( P4LUADEBUG_COMMANDS ) fprintf( stderr, "[P4] Executing %s\n", cmdString.Text() ); if ( depth ) { lua_pushboolean( L, false ); lua_pushstring( L, "Can't execute nested Perforce commands." ); return 2; } // Clear out any results from the previous command ui.Reset(); // Tell the UI which command we're running. ui.SetCommand( cmd ); if ( ! IsConnected() && exceptionLevel ) { Except( "P4.run()", "not connected." ); return 0; } if ( ! IsConnected() ) { lua_pushboolean( L, false ); return 1; } depth++; RunCmd( cmd, &ui, argc, argv ); depth--; if( ui.GetHandler() != LUA_NOREF ) { if( client.Dropped() && ! ui.IsAlive() ) { Disconnect(); ConnectOrReconnect(); } } P4Result &results = ui.GetResults(); if ( results.ErrorCount() && exceptionLevel ) return Except( "P4:run", "Errors during command execution", cmdString.Text() ); if ( results.WarningCount() && exceptionLevel > 1 ) return Except( "P4:run", "Warnings during command execution",cmdString.Text()); lua_rawgeti( L, LUA_REGISTRYINDEX, results.GetOutput() ); return 1; }
//-------------------------------------------------------------------------------------------------------------- TextSurface::TextSurface( ZOrderType eZType, OverlaySurface* pZRefOverlay, FontFace* pFont, LPCWSTR szText, int nX, int nY, int nLineWidth, int nMaxChars, DWORD dwColor, TextureFilterType eFilterType ) :OverlaySurface ( eZType, pZRefOverlay, eFilterType ) ,mpFont (pFont) , mpText (NULL) , mNumChars (0) , mX (nX) , mY (nY) , mLineWidth (nLineWidth) , mTextColor (dwColor) { if( nX + mpFont->mnMaxWidth > nLineWidth ) Except( Exception::ERR_INVALIDPARAMS, "指定平面文字行宽度过小。" ); //计算字符串长度 int nNumChars = 0; wchar_t* pChar = (wchar_t*)szText; while( *pChar != 0 ) { ++pChar; ++nNumChars; } //如果未指定最大字符数量则使用当前字符串字符数量 if( nMaxChars == 0 ) mMaxChars = nNumChars; else if( nMaxChars < nNumChars ) Except( Exception::ERR_INVALIDPARAMS, "指定的最大字符数量小于当前文字字符数量。" ); else mMaxChars = nMaxChars; mNumChars = nNumChars; //分配内存 size_t nStrLen = sizeof(wchar_t) * ( mMaxChars + 1 ); size_t nDrawLen = sizeof(FontFace::GlyphDraw) * mMaxChars; BYTE* pMem = (BYTE*)malloc( nStrLen + nDrawLen + sizeof(OverlayVertex)*6*mMaxChars ); //复制字符串 mpText = (wchar_t*)pMem; memcpy( mpText, szText, sizeof(wchar_t) * ( mNumChars + 1 ) ); //分配字形数据缓存 mpGlyphDraw = (FontFace::GlyphDraw*)( pMem + nStrLen ); memset( mpGlyphDraw, 0, nDrawLen ); //分配顶点数据缓存 mpVertexData = (OverlayVertex*)( pMem + nStrLen + nDrawLen ); mpVertexPtr = mpVertexData; mNumVertex = 0; //更新文字数据 _UpdateText(); }
float CNProbeSet::getIntensityContrast(double dK) { if ((m_fAMedianIntensity + m_fBMedianIntensity) == 0) { throw(Except("Zero median intensities found. CEL file may be corrupted.")); } float fContrast = (float)(sinh(dK * (m_fAMedianIntensity - m_fBMedianIntensity) / (m_fAMedianIntensity + m_fBMedianIntensity)) / sinh(dK)); if (fabs(fContrast) > 1) { throw(Except("Can't have abs(contrast) > 1.")); } return fContrast; }
float CNProbeSet::getSignalContrast(double dK) { if ((m_fAAlleleSignal + m_fBAlleleSignal) == 0) { throw(Except("Zero median signals found. CEL file may be corrupted.")); } float fContrast = (float)(sinh(dK * (m_fAAlleleSignal - m_fBAlleleSignal) / (m_fAAlleleSignal + m_fBAlleleSignal)) / sinh(dK)); if (fabs(fContrast) > 1) { throw(Except("Can't have abs(contrast) > 1.")); } return fContrast; }
//-------------------------------------------------------------------------------------------------------------- //创建纹理状态 TextureState* Material::CreateTextureState( UINT nStage ) { if( mppTextureState[nStage] != NULL ) Except( Exception::ERR_INVALIDPARAMS, "指定的纹理状态已经存在,无法重复创建。" ); if( nStage >= RenderSystem::mpSingleton->mMaxTextureNum ) Except( Exception::ERR_INTERNAL_ERROR, "无法超过支持的纹理状态最大限,创建纹理状态失败。" ); mppTextureState[nStage] = new TextureState; return mppTextureState[nStage]; }
//-------------------------------------------------------------------------------------------------------------- //读取文件数据 void BaseFile::Read( void* pBuf, DWORD dwLen ) { //如果最后进行的缓存操作不是读取操作 if( mLastBuffedOp != BOT_Read ) _SyncOperation(); BYTE* pDstBuf = (BYTE*)pBuf; while( dwLen != 0 ) { //如果缓存中已存在数据 if( mdwCachedLen != 0 ) { //读取缓存中的剩余数据 DWORD dwCopyLen = ( dwLen < mdwCachedLen ) ? dwLen : mdwCachedLen; memcpy( pBuf, mpCachePtr, dwCopyLen ); mdwCachedLen -= dwCopyLen; mpCachePtr += dwCopyLen; dwLen -= dwCopyLen; pDstBuf += dwCopyLen; } //如果缓存中已不存在数据且读取长度大于等于缓存长度 else if( dwLen >= mCacheLen ) { //直接从文件中读取数据 if( dwLen != _InternalRead( pDstBuf, dwLen ) ) Except( Exception::ERR_CANNOT_READ_FILE, STR_ERR_READ_LEN ); break; } //如果缓存中已不存在数据且读取长度小于缓存长度 else { //从文件中读取数据填充缓存 DWORD dwReadLen = _InternalRead( mpCache, mCacheLen ); if( dwReadLen < dwLen ) Except( Exception::ERR_CANNOT_READ_FILE, STR_ERR_READ_LEN ); //从缓存中读取指定长度的数据 memcpy( pDstBuf, mpCache, dwLen ); mpCachePtr = mpCache + dwLen; mdwCachedLen = dwReadLen - dwLen; break; } } //记录最后的缓存操作类型 mLastBuffedOp = BOT_Read; mPosition += dwLen; }
/** * @brief Run the copy number ratio engine. The copy number ratio engine will inturn call the copy number engine. * @param CopyNumberOptions* - The options to run with. * @return int - 0 if successful else 1 */ void CNReferenceEngine::runImp() { try { m_data.setEngine(m_pEngine); uint64_t memAvail = ::getDouble(m_pEngine->getOpt("free-mem-at-start")); if (memAvail >= (2000 * MEGABYTE)) { m_pEngine->setOpt("mem-usage", "2000"); } else { int iMemUsage = (memAvail / MEGABYTE); m_pEngine->setOpt("mem-usage", ::getInt(iMemUsage)); } m_data.loadAnnotation(true); m_iProbeSetCount = m_data.getProbeSets()->getCount(); m_iExperimentCount = m_data.loadExperiments(m_pEngine->getOpt("expr-summary-file")); if (m_iExperimentCount == 0) {throw(Except("No experiments to process."));} if (m_iProbeSetCount == 0) {throw(Except("No probesets to process."));} if (!determineMemoryUsage()) {return;} if (!processData()) {return;} m_pEngine->setOpt("sample-count", ::getInt(m_iExperimentCount)); if (!m_data.writeModelFile(m_pEngine->getOpt("reference-file"))) {return;} if (m_pEngine->isOptDefined("wave-correction-reference-method")) { if ((m_pEngine->getOpt("wave-correction-reference-method") != "none") && (m_pEngine->getOpt("wave-correction-reference-method") != "")) { CNAnalysisMethodFactory amFactory; CNAnalysisMethod* am = NULL; am = amFactory.CNAnalysisMethodForString(m_pEngine->getOpt("wave-correction-reference-method")); am->setEngine(m_pEngine); am->run(); delete am; } } if ((m_pEngine->isOptDefined("temp-reference-file")) && (m_pEngine->getOpt("temp-reference-file") != "")) { Fs::rm(m_pEngine->getOpt("temp-reference-file")); } clear(); } catch(...) {m_data.clear(); throw;} }
int P4ClientAPI::Except( const char *func, Error *e ) { StrBuf m; e->Fmt( &m ); return Except( func, m.Text() ); }
int P4ClientAPI::ConnectOrReconnect() { if( IsTrackMode() ) client.SetProtocol( "track", "" ); Error e; ResetFlags(); client.Init( &e ); if ( e.Test() && exceptionLevel ) { return Except( "P4:connect()", &e ); } if ( e.Test() ) return 0; // If an iterator is defined, reset the break functionality // for the KeepAlive function if( ui.GetHandler() != LUA_NOREF ) { client.SetBreak( &ui ); } SetConnected(); lua_pushboolean( L, true ); return 1; }
//-------------------------------------------------------------------------------------------------------------- //建立新二叉树分割面 void BSPGenerator::_BuildNewPlane3( WORD pVerIndex[4], int nNumVer, BSPPlaneList* pNewPlane3List ) { //根据顶点数量判断建立的三角面数量 switch (nNumVer) { case 3: { *pNewPlane3List->Push() = mpPlane3Buf + mNumFace; mpPlane3Buf[ mNumFace++ ].SetFromPoints( mpVertexBuf, pVerIndex[0], pVerIndex[1], pVerIndex[2] ); break; } case 4: { *pNewPlane3List->Push() = mpPlane3Buf + mNumFace; mpPlane3Buf[ mNumFace++ ].SetFromPoints( mpVertexBuf, pVerIndex[0], pVerIndex[1], pVerIndex[2] ); *pNewPlane3List->Push() = mpPlane3Buf + mNumFace; mpPlane3Buf[ mNumFace++ ].SetFromPoints( mpVertexBuf, pVerIndex[0], pVerIndex[2], pVerIndex[3] ); break; } default: Except( Exception::ERR_INTERNAL_ERROR, "三角形分割后生成的新顶点数量错误。" ); } }
float CNProbeSet::getIntensityStrength() { if ((m_fAMedianIntensity + m_fBMedianIntensity) == 0) { throw(Except("Zero median intensities found. CEL file may be corrupted.")); } return log2(m_fAMedianIntensity + m_fBMedianIntensity); }
float CNProbeSet::getSignalStrength() { if ((m_fAAlleleSignal + m_fBAlleleSignal) == 0) { throw(Except("Zero median signals found. CEL file may be corrupted.")); } return log2(m_fAAlleleSignal + m_fBAlleleSignal); }
/** * Guesstimate the maximum number of probe sets we can load for all experiments. * Guesstimate the maximum number of experiments we can load for all probe sets. * @return bool - true if successful */ bool CNReferenceEngine::determineMemoryUsage() { int iMemUsage = m_pEngine->getOptInt("mem-usage"); int iMBUsedForProbeSetList = (int)((77 * m_iProbeSetCount) / 1000000.0); int iMBUsedForExperimentList = (int)((58 * m_iExperimentCount) / 1000000.0); m_iProbeSetsToProcess = (int)((((iMemUsage - iMBUsedForProbeSetList - iMBUsedForExperimentList) * 1000000.0) / 9.0) / m_iExperimentCount); if (m_iProbeSetsToProcess <= 0) {throw(Except("Not enough memory to run application. ProbeSetsToProcess = " + ::getInt(m_iProbeSetsToProcess)));} if (m_iProbeSetsToProcess > m_iProbeSetCount) {m_iProbeSetsToProcess = m_iProbeSetCount;} m_iExperimentsToProcess = (int)((((iMemUsage - iMBUsedForProbeSetList - iMBUsedForExperimentList) * 1000000.0) / 9.0) / m_iProbeSetCount); if (m_iExperimentsToProcess <= 0) {throw(Except("Not enough memory to run application. ExperimentsToProcess = " + ::getInt(m_iExperimentsToProcess)));} if (m_iExperimentsToProcess > m_iExperimentCount) {m_iExperimentsToProcess = m_iExperimentCount;} return true; }
//----------------------------------------------------------------------- SubEntity* Entity::getSubEntity(unsigned int index) { if (index >= mSubEntityList.size()) Except(Exception::ERR_INVALIDPARAMS, "Index out of bounds.", "Entity::getSubEntity"); return mSubEntityList[index]; }
Dbms* dbms() { if (isclient()) { if (! tls().thedbms) { if (Fibers::inMain()) tls().thedbms = dbms_remote(server_ip); else { try { tls().thedbms = dbms_remote_async(server_ip); } catch (const Except& e) { throw Except(e, "thread failed to connect to db server: " + e.gcstr()); } tls().thedbms->auth(Fibers::main_dbms()->token()); } } return tls().thedbms; } else { static Dbms* local = dbms_local(); return local; } }
// Will do is IsTypeOf T before getting and throw if types dont match T GetCheckVal() const { if(IsTypeOf<T>()) return GetVal(); else throw Except(String("GetCheckVal expected ")+typeid(T).name()); }
static void throw_exception (void) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) throw exception\n"))); throw Except (); }
//-------------------------------------------------------------------------------------------------------------- //设置动画信息 void AnimControl::SetAnimationInfo( UINT nNumKey, float fIntervalTime ) { if( nNumKey == 0 || fIntervalTime == 0.0f ) Except( Exception::ERR_INVALIDPARAMS, "错误的动画帧数或帧停顿时间。" ); mNumKey = nNumKey; mIntervalTime = fIntervalTime; }
//-------------------------------------------------------------------------------------------------------------- //初始化输入系统 void DI8InputSystem::Initialize() { //创建 DirectInput8 对象 HRESULT result = DirectInput8Create( (HINSTANCE)GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&mpDirectInput8, NULL ); if( FAILED( result ) ) Except( Exception::ERR_INTERNAL_ERROR, "创建 DirectInput8 对象错误。" ); }
//-------------------------------------------------------------------------------------------------------------- //获取文件长度 DWORD BaseFile::GetLength() { DWORD dwLength = GetFileSize( mFileHandle, NULL ); if( dwLength == INVALID_FILE_SIZE ) Except( Exception::ERR_WINAPI_ERROR, "获取文件长度失败。" ); return dwLength; }
//-------------------------------------------------------------------------------------------------------------- //将缓存数据写入文件 void BaseFile::Flush() { if( mLastBuffedOp != BOT_Write ) Except( Exception::ERR_INVALIDPARAMS, "上次进行的缓存操作并不是写入操作,因此无法执行将缓存数据写入文件的命令。" ); if( mdwCachedLen == 0 ) return; if( mdwCachedLen != _InternalWrite( mpCache, mdwCachedLen ) ) Except( Exception::ERR_CANNOT_WRITE_FILE, STR_ERR_WRITE_LEN ); mpCachePtr = mpCache; mdwCachedLen = 0; mLastBuffedOp = BOT_None; }
//-------------------------------------------------------------------------------------------------------------- //设置当前读写位置为文件结尾 void BaseFile::SetEndOfFile() { //同步读写操作 _SyncOperation(); if( FALSE == ::SetEndOfFile( mFileHandle ) ) Except( Exception::ERR_WINAPI_ERROR, "设置文件结尾失败。" ); }
int P4ClientAPI::Except( const char *func, const char *msg, const char *cmd ) { StrBuf m; m << msg; m << "( " << cmd << " )"; return Except( func, m.Text() ); }
//-------------------------------------------------------------------------------------------------------------- //载入 FreeType 字体 FT_Face FontManager::_LoadFontFace( LPCSTR szFontFile, UINT nFaceIndex ) { //创建字体 FT_Face pFontFace = NULL; FT_Error error = FT_New_Face( mFreeTypeLib, szFontFile, nFaceIndex, &pFontFace ); if( error != 0 ) { if( error == FT_Err_Cannot_Open_Resource ) Except( Exception::ERR_INVALIDPARAMS, (String)"找不到指定的字体文件 '" + szFontFile + "'。" ); else if( error == FT_Err_Unknown_File_Format ) Except( Exception::ERR_INVALIDPARAMS, "字体文件格式错误,无法创建字体。" ); else Except( Exception::ERR_INTERNAL_ERROR, "创建字体失败。" ); } return pFontFace; }
//-------------------------------------------------------------------------------------------------------------- //设置/获取材质名称 void Material::SetName( const char* pName ) { size_t nStrLen = strlen( pName ); if( nStrLen >= 32 ) Except( Exception::ERR_NAME_TOO_LONG, "指定的材质名称过长。" ); memcpy( mName, pName, nStrLen + 1 ); }
//-------------------------------------------------------------------------------------------------------------- //生成二叉树 void BSPGenerator::_GenerateBSPTree( BSPNode* pBSPNode, const BSPPlaneList* pBSPPlaneList ) { ++mNumNode; //如果是凸多边形集合则生成叶节点 if( _IsConvexSet( pBSPPlaneList ) ) { //生成分割后的面片数据 return; } //选择分割面 BSPPlane* pDivPlane3 = _ChooseDivPlane3( pBSPPlaneList ); pBSPNode->mpDivPlane3 = pDivPlane3; UINT nNumInputPlane3 = pBSPPlaneList->Size(); BSPPlaneList sPosPlane3List; BSPPlaneList sNegPlane3List; sPosPlane3List.Initialize( nNumInputPlane3, nNumInputPlane3 ); sNegPlane3List.Initialize( nNumInputPlane3, nNumInputPlane3 ); //循环集合中的每个多边形 BSPPlaneList::Iterator it = pBSPPlaneList->Begin(); BSPPlaneList::Iterator end = pBSPPlaneList->End(); for(; it!=end; ++it ) { BSPPlane* pPlane3 = *it; //判断该面在分割面哪一边 SpaceRelation eSR = pDivPlane3->GetSide( *pPlane3 ); if( eSR == SR_POSITIVE || eSR == SR_COINCIDING ) { *sPosPlane3List.Push() = pPlane3; } else if( eSR == SR_NEGATIVE ) { *sNegPlane3List.Push() = pPlane3; } else { //将跨过分割面的三角形分割 _SplitPlane3( pPlane3, pDivPlane3, &sPosPlane3List, &sNegPlane3List ); } } if( sPosPlane3List.Size() == 0 || sNegPlane3List.Size() == 0 ) Except( Exception::ERR_INTERNAL_ERROR, "该二叉树节点不是凸多边形集合,但是却无法正确地进行空间分割。" ); //创建前子节点 pBSPNode->mpPosNode = new BSPNode; _GenerateBSPTree( pBSPNode->mpPosNode, &sPosPlane3List ); //创建后子节点 pBSPNode->mpNegNode = new BSPNode; _GenerateBSPTree( pBSPNode->mpNegNode, &sNegPlane3List ); }
//-------------------------------------------------------------------------------------------------------------- //解锁纹理 void D3D9CubeTexture::UnlockRect( CubeFace eFace, UINT nLevel ) { HRESULT result = reinterpret_cast< IDirect3DCubeTexture9* >( mpD3D9Texture )->UnlockRect( (D3DCUBEMAP_FACES)eFace, nLevel ); if( FAILED( result ) ) Except( Exception::ERR_INVALIDPARAMS, (String)"解锁 Direct3D 9 立方纹理错误。\nD3D9 错误描述:" + DXGetErrorDescription9(result) ); }