void PrintDetailedPlayerClassStats() { if ( !tf_DetailedStats.GetInt() ) return; IFileSystem *pFileSys = filesystem; FileHandle_t hFile = pFileSys->Open( "class_stats_detailed.txt", "wt", "LOGDIR" ); if ( hFile != FILESYSTEM_INVALID_HANDLE ) { // Print the header. for ( int i=TFCLASS_UNDECIDED+1; i < STATS_NUM_GROUPS; i++ ) { pFileSys->FPrintf( hFile, "%s dist\t%s dmg\t", GetGroupNameFor( i ), GetGroupNameFor( i ) ); } pFileSys->FPrintf( hFile, "\n" ); // Write out each column. int iterators[STATS_NUM_GROUPS]; for ( i=TFCLASS_UNDECIDED+1; i < STATS_NUM_GROUPS; i++ ) iterators[i] = g_ClassShotInfos[i].Head(); bool bWroteAnything; do { bWroteAnything = false; for ( int i=TFCLASS_UNDECIDED+1; i < STATS_NUM_GROUPS; i++ ) { if ( iterators[i] == g_ClassShotInfos[i].InvalidIndex() ) { pFileSys->FPrintf( hFile, "\t\t" ); } else { CShotInfo *pInfo = &g_ClassShotInfos[i][iterators[i]]; iterators[i] = g_ClassShotInfos[i].Next( iterators[i] ); pFileSys->FPrintf( hFile, "%.2f\t%d\t", pInfo->m_flDistance, pInfo->m_nDamage ); bWroteAnything = true; } } pFileSys->FPrintf( hFile, "\n" ); } while ( bWroteAnything ); pFileSys->Close( hFile ); } }
bool CMeshLoader::Load(const wchar* path, bool ignore_animation_data/*=false*/) { if (m_bLoaded) { Unload(); m_bLoaded = false; } IFileSystem* pFS = CEngine::instance()->mFilesystem(); unsigned int ltim = GetTickCount(); // open file wchar fspath[P3DMAX_PATH]; wsprintf(fspath, P3DMAX_PATH-1, _W("models/%s.rmesh"), path); FSFILE* fp = pFS->Open(fspath, _W("rb")); if (!fp) { CON(MSG_ERR, _W("MeshLoader: Can't find mesh file '%s'!"), fspath); return false; } if (fp->nLen<sizeof(sRMHeader)) { CON(MSG_ERR, _W("MeshLoader: Mesh file '%s' is corrupted!"), fspath); pFS->Close(fp); return false; } // load and check header m_rhead = new sRMHeader(); pFS->Read(m_rhead, sizeof(sRMHeader), 1, fp); if (m_rhead->magic[0]!='R' || m_rhead->magic[1]!='M') { CON(MSG_ERR, _W("MeshLoader: File '%s' is not valid RMesh!"), fspath); pFS->Close(fp); return false; } if (m_rhead->major!=RM_MAJOR) { CON(MSG_ERR, _W("MeshLoader: Mesh '%s' is version %d, but engine can load only %d!"), fspath, m_rhead->major, RM_MAJOR); pFS->Close(fp); return false; } if (m_rhead->minor!=RM_MINOR) { CON(MSG_DBG, _W("MeshLoader: Minor version warning. Mesh '%s' is minor version %d, engine can load %d."), fspath, m_rhead->minor, RM_MINOR); } m_bLoaded=true; // LOAD INFO --------------------------------------------------- m_rinfo = new sRMInfo(); pFS->Seek(fp, m_rhead->contents[RM_FILE_INFO].offset, SEEK_SET); pFS->Read(m_rinfo, sizeof(sRMInfo), 1, fp); // LOAD SUBSETS --------------------------------------------------- m_nSubsets = m_rhead->contents[RM_SUBSETS].length/sizeof(sRMSubset); m_rsubsets = new sRMSubset[m_nSubsets]; pFS->Seek(fp, m_rhead->contents[RM_SUBSETS].offset, SEEK_SET); pFS->Read(m_rsubsets, sizeof(sRMSubset), m_nSubsets, fp); // LOAD VERTICES --------------------------------------------------- m_nVerts = m_rhead->contents[RM_VERTICES].length/sizeof(sRMVertex); m_rverts = new sRMVertex[m_nVerts]; pFS->Seek(fp, m_rhead->contents[RM_VERTICES].offset, SEEK_SET); pFS->Read(m_rverts, sizeof(sRMVertex), m_nVerts, fp); // LOAD INDICES --------------------------------------------------- m_nInds = m_rhead->contents[RM_INDICES].length/sizeof(sRMIndex); m_rinds = new sRMIndex[m_nInds]; pFS->Seek(fp, m_rhead->contents[RM_INDICES].offset, SEEK_SET); pFS->Read(m_rinds, sizeof(sRMIndex), m_nInds, fp); // MAKE FACE GROUPS ----------------------------------------------- m_faceGroups = new unsigned int[m_nInds/3]; memset(m_faceGroups, 0, sizeof(unsigned int)*m_nInds/3); for (unsigned int s=0; s<m_nSubsets; s++) { // find faces which belongs to this subset unsigned int beginFace = m_rsubsets[s].firstindex/3; unsigned int endFace = (m_rsubsets[s].firstindex+m_rsubsets[s].numindices)/3; // assign face groups to this subset for (unsigned int f=beginFace; f<endFace; f++) m_faceGroups[f]=s; } // IF THIS FILE HAS ANIMATION AND IT IS LAODED MAKE SURE TO SET m_bAnimated TO TRUE m_bAnimated = false; if (!m_rinfo->idontimportanim) { // check if file contain animated content // TODO: } // close file pFS->Close(fp); ltim = GetTickCount() - ltim; if (ltim<1000) CON(MSG_INFO, _W("MeshLoader: Mesh '%s' loaded. Loading took %d miliseconds."), path, ltim); else CON(MSG_INFO, _W("MeshLoader: Mesh '%s' loaded. Loading took %d seconds."), path, ltim/1000); return true; }
void PrintPlayerClassStats() { IFileSystem *pFileSys = filesystem; FileHandle_t hFile = pFileSys->Open( "class_stats.txt", "wt", "LOGDIR" ); if ( hFile == FILESYSTEM_INVALID_HANDLE ) return; pFileSys->FPrintf( hFile, "Class\tPlayer Time (minutes)\tAvg Engagement Dist\t(OLD) Engagement Dist\n" ); for ( int i=TFCLASS_UNDECIDED+1; i < STATS_NUM_GROUPS; i++ ) { CPlayerClassStats *pStats = &g_PlayerClassStats[i]; // Figure out the average engagement distance across all classes. int j; double flAvgEngagementDist = 0; int nTotalEngagements = 0; double flTotalEngagementDist = 0; double flTotalNormalizedEngagementDist = 0; int nTotalNormalizedEngagements = 0; for ( j=TFCLASS_UNDECIDED+1; j < STATS_NUM_GROUPS; j++ ) { CInterClassStats *pInter = &g_PlayerClassStats[i].m_InterClassStats[j]; nTotalEngagements += pInter->m_nEngagements; flTotalEngagementDist += pInter->m_flTotalEngagementDist; nTotalNormalizedEngagements += pInter->m_nNormalizedEngagements; flTotalNormalizedEngagementDist += pInter->m_flTotalNormalizedEngagementDist; } flAvgEngagementDist = nTotalEngagements ? ( flTotalEngagementDist / nTotalEngagements ) : 0; double flAvgNormalizedEngagementDist = nTotalNormalizedEngagements ? (flTotalNormalizedEngagementDist / nTotalNormalizedEngagements) : 0; pFileSys->FPrintf( hFile, "%s", GetGroupNameFor( i ) ); pFileSys->FPrintf( hFile, "\t%.1f", (pStats->m_flPlayerTime / 60.0f) ); pFileSys->FPrintf( hFile, "\t%d", (int)flAvgNormalizedEngagementDist ); pFileSys->FPrintf( hFile, "\t%d", (int)flAvgEngagementDist ); pFileSys->FPrintf( hFile, "\n" ); } pFileSys->FPrintf( hFile, "\n" ); pFileSys->FPrintf( hFile, "\n" ); pFileSys->FPrintf( hFile, "Class\tTarget Class\tTotal Damage\tKills\tAvg Engagement Dist\t(OLD) Engagement Dist\n" ); for ( i=TFCLASS_UNDECIDED+1; i < STATS_NUM_GROUPS; i++ ) { CPlayerClassStats *pStats = &g_PlayerClassStats[i]; // Print the inter-class stats. for ( int j=TFCLASS_UNDECIDED+1; j < STATS_NUM_GROUPS; j++ ) { CInterClassStats *pInter = &pStats->m_InterClassStats[j]; pFileSys->FPrintf( hFile, "%s", GetGroupNameFor( i ) ); pFileSys->FPrintf( hFile, "\t%s", GetGroupNameFor( j ) ); pFileSys->FPrintf( hFile, "\t%d", (int)pInter->m_flTotalDamageInflicted ); pFileSys->FPrintf( hFile, "\t%d", pInter->m_nKills ); pFileSys->FPrintf( hFile, "\t%d", (int)(pInter->m_nNormalizedEngagements ? (pInter->m_flTotalNormalizedEngagementDist / pInter->m_nNormalizedEngagements) : 0) ); pFileSys->FPrintf( hFile, "\t%d", (int)(pInter->m_nEngagements ? (pInter->m_flTotalEngagementDist / pInter->m_nEngagements) : 0) ); pFileSys->FPrintf( hFile, "\n" ); } } pFileSys->Close( hFile ); }
bool CShaderHLSL::Create(P3D::sShaderDesc &desc) { const char *pData; ULONG fsize; IFileSystem* pFS = CRenderer::mEngine()->mFilesystem(); wchar path[P3DMAX_PATH]; wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get()); FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true); if (!fp) { CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get()); return false; } ID3D10Blob *pShaderBlob = NULL; ID3D10Blob *pErrors = NULL; UINT flags = D3D10_SHADER_DEBUG; //D3D10_SHADER_OPTIMIZATION_LEVEL3 char profile[128]; switch(desc.ShaderType) { case SHADERTYPE_VERTEX_SHADER: strcpy(profile, D3D10GetVertexShaderProfile(g_pD3ddev)); break; case SHADERTYPE_GEOMETRY_SHADER: strcpy(profile, D3D10GetGeometryShaderProfile(g_pD3ddev)); break; case SHADERTYPE_PIXEL_SHADER: strcpy(profile, D3D10GetPixelShaderProfile(g_pD3ddev)); break; default: CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given.")); return false; } CIncludeHandler includeHandler; D3D10_SHADER_MACRO Shader_Macros[] = { { "DX10", NULL }, { "SM4", NULL }, NULL }; if(!CheckHRResult(D3DX10CompileFromMemory( pData, fsize, NULL, Shader_Macros, &includeHandler, _W2A(desc.EntryFunction.Get()), profile, flags, 0, NULL, &pShaderBlob, &pErrors, NULL ))) { if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer())); else CON(MSG_ERR, _W("Error description not given")); CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get()); SAFE_RELEASE(pErrors); return false; } pFS->UnLoad(fp, (BYTE *)pData); //save to cache fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb")); const char* cs = (const char*)pShaderBlob->GetBufferPointer(); pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp); pFS->Close(fp); bool shaderCreated = false; switch(desc.ShaderType) { case SHADERTYPE_VERTEX_SHADER: shaderCreated = CheckHRResult(g_pD3ddev->CreateVertexShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pVS)); break; case SHADERTYPE_GEOMETRY_SHADER: shaderCreated = CheckHRResult(g_pD3ddev->CreateGeometryShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pGS)); break; case SHADERTYPE_PIXEL_SHADER: shaderCreated = CheckHRResult(g_pD3ddev->CreatePixelShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pPS)); break; } if(!shaderCreated) { CON(MSG_ERR, _W("Shader creation error")); return false; } //if(!CheckHRResult(D3DReflect((DWORD*)pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), __uuidof(ID3D10ShaderReflection), &m_pReflection))) if(!CheckHRResult(D3D10ReflectShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pReflection))) { CON(MSG_ERR, _W("Could not create a Shader reflection")); return false; } //HRESULT D3DReflect(LPCVOID pSrcData, SIZE_T SrcDataSize, REFIID pInterface, void **ppReflector); D3D10_SHADER_DESC shDesc; m_pReflection->GetDesc(&shDesc); m_numResources = shDesc.BoundResources; //not sure about this if(desc.ShaderType == SHADERTYPE_VERTEX_SHADER) m_pVertDecl = new CVertexDeclaration(CRenderer::cGraphicsManager()->GetVertexDescByID(desc.VertexDescID), pShaderBlob); SAFE_RELEASE(pShaderBlob); m_desc = desc; CON(MSG_INFO, _W("Shader '%s' created"), desc.ShaderFile); return true; }
bool CShaderHLSL::Create(P3D::sShaderDesc &desc) { const char *pData; ULONG fsize; IFileSystem* pFS = CRenderer::mEngine()->mFilesystem(); wchar path[P3DMAX_PATH]; wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get()); FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true); if (!fp) { CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get()); return false; } ID3DXBuffer *pShaderBlob = NULL; ID3DXBuffer *pErrors = NULL; DWORD flags = D3DXSHADER_DEBUG; //D3DXSHADER_OPTIMIZATION_LEVEL3 char profile[128]; switch(desc.ShaderType) { case SHADERTYPE_VERTEX_SHADER: strcpy(profile, D3DXGetVertexShaderProfile(g_pD3ddev)); break; case SHADERTYPE_PIXEL_SHADER: strcpy(profile, D3DXGetPixelShaderProfile(g_pD3ddev)); break; case SHADERTYPE_GEOMETRY_SHADER: CON(MSG_ERR, _W("DX9 does not support geometry shaders.")); return false; default: CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given.")); return false; } CIncludeHandler includeHandler; D3DXMACRO Shader_Macros[] = { { "DX9", NULL }, { "SM3", NULL }, NULL }; if(FAILED(D3DXCompileShader( pData, fsize, Shader_Macros, &includeHandler, _W2A(desc.EntryFunction.Get()), profile, flags, &pShaderBlob, &pErrors, &m_pConstTable ))) { if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer())); else CON(MSG_ERR, _W("Error description not given")); CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get()); SAFE_RELEASE(pErrors); return false; } pFS->UnLoad(fp, (BYTE *)pData); //save to cache fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb")); const char* cs = (const char*)pShaderBlob->GetBufferPointer(); pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp); pFS->Close(fp); bool shaderCreated = false; switch(desc.ShaderType) { case SHADERTYPE_VERTEX_SHADER: shaderCreated = SUCCEEDED(g_pD3ddev->CreateVertexShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pVS)); break; case SHADERTYPE_PIXEL_SHADER: shaderCreated = SUCCEEDED(g_pD3ddev->CreatePixelShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pPS)); break; } if(!shaderCreated) { CON(MSG_ERR, _W("Shader creation error")); return false; } //set constant to their default values m_pConstTable->SetDefaults(g_pD3ddev); //create vertex declaration if(desc.ShaderType == SHADERTYPE_VERTEX_SHADER) m_pVertDecl = new CVertexDeclaration(CRenderer::cGraphicsManager()->GetVertexDescByID(desc.VertexDescID), pShaderBlob); SAFE_RELEASE(pShaderBlob); m_desc = desc; CON(MSG_INFO, _W("Shader '%s' created"), desc.ShaderFile); return true; }
// ------------------------------------------------ bool CTextureLoader::Load(const wchar* path) { IFileSystem *fs = CRenderer::mEngine()->mFilesystem(); Unload(); //memset(&m_info, 0, sizeof(sRTInfo)); // make physical FS path wchar physPath[512]; wsprintf(physPath, 511, _W("textures/%s.rtex"), path); for (unsigned int i=0; i<wstrlen(physPath); i++) if (physPath[i]==',') physPath[i]='/'; FSFILE* fp; fp = fs->Open(physPath, _W("rb")); if (!fp) { return false; } m_dataLen = fp->nLen; if (m_dataLen < sizeof(sRTHeader)) { fs->Close(fp); return false; } // read header sRTHeader head; fs->Read(&head, 1, sizeof(sRTHeader), fp); // check header if (head.magic[0]!='R' || head.magic[1]!='T') { CON(MSG_ERR, _W("Texture %s is not valid rtex!"), path); fs->Close(fp); return false; } // load texture info fs->Seek(fp, head.contents[RT_FILE_INFO].offset, SEEK_SET); fs->Read(&m_info, 1, sizeof(sRTInfo), fp); // load texture data unsigned long rawDataLen = fp->nLen-head.contents[RT_IMAGE_SUBSET].offset-head.contents[RT_IMAGE_SUBSET].length; m_data = new BYTE[rawDataLen]; fs->Seek(fp, head.contents[RT_IMAGE_SUBSET].offset+head.contents[RT_IMAGE_SUBSET].length, SEEK_SET); fs->Read(m_data, 1, rawDataLen, fp); m_bLoaded=true; // load all subsets fs->Seek(fp, head.contents[RT_IMAGE_SUBSET].offset, SEEK_SET); unsigned int numSubs = head.contents[RT_IMAGE_SUBSET].length / sizeof(sRTImageSubset); for (unsigned int s = 0; s < numSubs; s++) { sImageData* ida = new sImageData(); fs->Read(&ida->subset, 1, sizeof(sRTImageSubset), fp); ida->size = ida->subset.len; ida->pData = &m_data[ida->subset.offset]; m_subs.push_back(ida); } fs->Close(fp); int i = 0; // debug return true; }