CefRefPtr<CefResourceHandler> VTFSchemeHandlerFactory::Create(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& scheme_name, CefRefPtr<CefRequest> request) { CefRefPtr<CefResourceHandler> pResourceHandler = NULL; CefURLParts parts; CefParseURL(request->GetURL(), parts); std::string strVtfPath = CefString(&parts.path); char vtfPath[MAX_PATH]; V_snprintf( vtfPath, sizeof( vtfPath ), "materials/%s", strVtfPath.c_str() ); V_FixupPathName( vtfPath, sizeof( vtfPath ), vtfPath ); if (!filesystem->FileExists(vtfPath)) { Warning( "VTFSchemeHandlerFactory: invalid vtf %s\n", vtfPath ); return NULL; } CUtlBuffer imageDataBuffer( 0, filesystem->Size(vtfPath), 0 ); if( !filesystem->ReadFile( vtfPath, NULL, imageDataBuffer ) ) { Warning( "VTFSchemeHandlerFactory: failed to read vtf %s\n", vtfPath ); return NULL; } IVTFTexture *pVTFTexture = CreateVTFTexture(); if( pVTFTexture->Unserialize( imageDataBuffer ) ) { pVTFTexture->ConvertImageFormat( IMAGE_FORMAT_RGB888, false, false ); if( pVTFTexture->Format() == IMAGE_FORMAT_RGB888 ) { uint8 *pImageData = pVTFTexture->ImageData(); CUtlBuffer buf; VTFHandler_ConvertImageToJPG( buf, pImageData, pVTFTexture->Width(), pVTFTexture->Height() ); if( buf.Size() > 0 ) { CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData(static_cast<void*>(buf.Base()), buf.Size()); pResourceHandler = new CefStreamResourceHandler("image/jpeg", stream); } } else { Warning( "VTFSchemeHandlerFactory: unable to convert vtf %s to rgb format\n", vtfPath ); } } DestroyVTFTexture( pVTFTexture ); return pResourceHandler; }
bool CUDPSocket::RecvFrom( netadr_t& packet_from, CUtlBuffer& data ) { sockaddr from; int nFromLen = sizeof( from ); int nMaxBytesToRead = data.Size() - data.TellPut(); char *pBuffer = (char*)data.PeekPut(); int nBytesRead = recvfrom( m_Socket, pBuffer, nMaxBytesToRead, 0, &from, &nFromLen ); if ( nBytesRead == SOCKET_ERROR ) { int nError = WSAGetLastError(); if ( nError != WSAEWOULDBLOCK ) { Warning( "Socket error '%i'\n", nError ); } return false; } packet_from.SetFromSockadr( &from ); data.SeekPut( CUtlBuffer::SEEK_CURRENT, nBytesRead ); return true; }
//----------------------------------------------------------------------------- // Creates a collision model (based on the render geometry!) //----------------------------------------------------------------------------- void CVradStaticPropMgr::CreateCollisionModel( char const* pModelName ) { CUtlBuffer buf; CUtlBuffer bufvtx; CUtlBuffer bufphy; int i = m_StaticPropDict.AddToTail(); m_StaticPropDict[i].m_pModel = NULL; m_StaticPropDict[i].m_pStudioHdr = NULL; if ( !LoadStudioModel( pModelName, buf ) ) { VectorCopy( vec3_origin, m_StaticPropDict[i].m_Mins ); VectorCopy( vec3_origin, m_StaticPropDict[i].m_Maxs ); return; } studiohdr_t* pHdr = (studiohdr_t*)buf.Base(); // necessary for vertex access SetCurrentModel( pHdr ); VectorCopy( pHdr->hull_min, m_StaticPropDict[i].m_Mins ); VectorCopy( pHdr->hull_max, m_StaticPropDict[i].m_Maxs ); if ( LoadStudioCollisionModel( pModelName, bufphy ) ) { phyheader_t header; bufphy.Get( &header, sizeof(header) ); vcollide_t *pCollide = &m_StaticPropDict[i].m_loadedModel; s_pPhysCollision->VCollideLoad( pCollide, header.solidCount, (const char *)bufphy.PeekGet(), bufphy.TellPut() - bufphy.TellGet() ); m_StaticPropDict[i].m_pModel = m_StaticPropDict[i].m_loadedModel.solids[0]; /* static int propNum = 0; char tmp[128]; sprintf( tmp, "staticprop%03d.txt", propNum ); DumpCollideToGlView( pCollide, tmp ); ++propNum; */ } else { // mark this as unused m_StaticPropDict[i].m_loadedModel.solidCount = 0; // CPhysCollide* pPhys = CreatePhysCollide( pHdr, pVtxHdr ); m_StaticPropDict[i].m_pModel = ComputeConvexHull( pHdr ); } // clone it m_StaticPropDict[i].m_pStudioHdr = (studiohdr_t *)malloc( buf.Size() ); memcpy( m_StaticPropDict[i].m_pStudioHdr, (studiohdr_t*)buf.Base(), buf.Size() ); if ( !LoadVTXFile( pModelName, m_StaticPropDict[i].m_pStudioHdr, m_StaticPropDict[i].m_VtxBuf ) ) { // failed, leave state identified as disabled m_StaticPropDict[i].m_VtxBuf.Purge(); } }