D3DTexture::D3DTexture(D3DSystem *curSystem, CTSTR lpFile, D3DXIMAGE_INFO &imageInfo, BOOL bBuildMipMaps) { traceIn(D3DTexture::D3DTexture(2)); DWORD dwMipLevels; if(bBuildMipMaps) { switch(imageInfo.ImageFileFormat) { case D3DXIFF_DDS: dwMipLevels = D3DX_FROM_FILE; break; default: dwMipLevels = D3DX_DEFAULT; } } else dwMipLevels = 1; d3d = curSystem; bHasMipMaps = bBuildMipMaps; bNeedsBlending = 0; mipLevel = 0; dwFormat = -1; switch(imageInfo.Format) { case D3DFMT_DXT1: dwFormat = GS_DXT1; break; case D3DFMT_DXT3: dwFormat = GS_DXT3; break; case D3DFMT_DXT5: dwFormat = GS_DXT5; break; case D3DFMT_R8G8B8: dwFormat = GS_RGB; break; case D3DFMT_A8R8G8B8: dwFormat = GS_RGBA; } bDynamic = FALSE; dwTexType = D3DTEXTURE_STANDARD_BUFFER; DWORD dwDefaultSize = bBuildMipMaps ? D3DX_DEFAULT : D3DX_DEFAULT_NONPOW2; //D3DXCreateTextureFromFile(d3d->d3dDevice, lpFile, &d3dTex); if(!SUCCEEDED(D3DXCreateTextureFromFileEx(d3d->d3dDevice, lpFile, dwDefaultSize, dwDefaultSize, dwMipLevels, 0, D3DFMT_FROM_FILE, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, NULL, NULL, &GetTex()))) ErrOut(TEXT("Could not load file %s"), lpFile); D3DSURFACE_DESC sDesc; GetTex()->GetLevelDesc(0, &sDesc); texWidth = sDesc.Width; texHeight = sDesc.Height; traceOut; }
/*! \brief Save all account */ void cAccounts::SaveAccounts( void ) { ACCOUNT_LIST::iterator iter_account( this->acctlist.begin() ), iter_account_end( this->acctlist.end() ); std::string line ; FILE* F = fopen("config/accounts.adm", "wt") ; if (F == NULL) { ErrOut("Can't open config/accounts.adm for writing\n"); return; } unsigned int maxacctnumb = 0; // Saving the number of loaded accounts for (; iter_account != iter_account_end; ++iter_account ) { fprintf(F, "SECTION ACCOUNT %d\n{\nNAME %s\nPASS %s\n", iter_account->second.number, iter_account->second.name.c_str(), iter_account->second.pass.c_str() ); if (iter_account->second.lastlogin) fprintf(F,"LASTLOGIN %lu\n",iter_account->second.lastlogin); if (iter_account->second.lastip.s_addr) fprintf(F,"LASTIP %s\n",inet_ntoa(iter_account->second.lastip)); if (iter_account->second.ban) fprintf(F, "BAN\n"); if (iter_account->second.ras) fprintf(F, "REMOTEADMIN\n"); fprintf(F, "}\n\n"); } fprintf(F, "\n\n// Note: Last used Account Number was: %d\nEOF\n" , maxacctnumb ); fclose(F); unsavedaccounts = 0; }
bool RenderDocument(BaseEngine *engine, const WCHAR *renderPath, float zoom=1.f, bool silent=false) { if (!CheckRenderPath(renderPath)) return false; if (str::EndsWithI(renderPath, L".txt")) { str::Str<WCHAR> text(1024); for (int pageNo = 1; pageNo <= engine->PageCount(); pageNo++) text.AppendAndFree(engine->ExtractPageText(pageNo, L"\r\n", NULL, Target_Export)); if (silent) return true; ScopedMem<WCHAR> txtFilePath(str::Format(renderPath, 0)); ScopedMem<char> textUTF8(str::conv::ToUtf8(text.Get())); ScopedMem<char> textUTF8BOM(str::Join(UTF8_BOM, textUTF8)); return file::WriteAll(txtFilePath, textUTF8BOM, str::Len(textUTF8BOM)); } if (str::EndsWithI(renderPath, L".pdf")) { if (silent) return false; ScopedMem<WCHAR> pdfFilePath(str::Format(renderPath, 0)); return engine->SaveFileAsPDF(pdfFilePath, true) || PdfCreator::RenderToFile(pdfFilePath, engine); } bool success = true; for (int pageNo = 1; pageNo <= engine->PageCount(); pageNo++) { RenderedBitmap *bmp = engine->RenderBitmap(pageNo, zoom, 0); success &= bmp != NULL; if (!bmp && !silent) ErrOut("Error: Failed to render page %d for %s!", pageNo, engine->FileName()); if (!bmp || silent) { delete bmp; continue; } ScopedMem<WCHAR> pageBmpPath(str::Format(renderPath, pageNo)); if (str::EndsWithI(pageBmpPath, L".png")) { Bitmap gbmp(bmp->GetBitmap(), NULL); CLSID pngEncId = GetEncoderClsid(L"image/png"); gbmp.Save(pageBmpPath, &pngEncId); } else if (str::EndsWithI(pageBmpPath, L".bmp")) { size_t bmpDataLen; ScopedMem<char> bmpData((char *)SerializeBitmap(bmp->GetBitmap(), &bmpDataLen)); if (bmpData) file::WriteAll(pageBmpPath, bmpData, bmpDataLen); } else { // render as TGA for all other file extensions size_t tgaDataLen; ScopedMem<unsigned char> tgaData(tga::SerializeBitmap(bmp->GetBitmap(), &tgaDataLen)); if (tgaData) file::WriteAll(pageBmpPath, tgaData, tgaDataLen); } delete bmp; } return success; }
void cItem::explode(NXWSOCKET s) { if (s < 0 || s > now) return; //Luxor unsigned int dmg=0,len=0; P_CHAR pc_current=MAKE_CHAR_REF(currchar[s]); VALIDATEPC(pc_current); if(!isInWorld()) return; type=0; //needed for recursive explosion //Luxor - recursive explosions!! :DD NxwItemWrapper si; si.fillItemsNearXYZ( getPosition(), 5, true ); for( si.rewind(); !si.isEmpty(); si++ ) { P_ITEM p_nearbie=si.getItem(); if(ISVALIDPI(p_nearbie) && p_nearbie->type == ITYPE_POTION && p_nearbie->morey == 3) { //It's an explosion potion! p_nearbie->explode(s); } } //End Luxor recursive explosions staticeffect2(this, 0x36, 0xB0, 0x10, 0x80, 0x00); soundeffect3(this, 0x0207); len=morex/250; //4 square max damage at 100 alchemy switch (morez) { case 1:dmg=RandomNum( 5,10) ;break; case 2:dmg=RandomNum(10,20) ;break; case 3:dmg=RandomNum(20,40) ;break; default: ErrOut("Switch fallout. NoX-Wizard.cpp, explodeitem()\n"); //Morrolan dmg=RandomNum(5,10); } if (dmg<5) dmg=RandomNum(5,10); // 5 points minimum damage if (len<2) len=2; // 2 square min damage range NxwCharWrapper sc; sc.fillCharsNearXYZ( getPosition(), len, true ); for( sc.rewind(); !sc.isEmpty(); sc++ ) { P_CHAR pc=sc.getChar(); if( ISVALIDPC(pc) ) { pc->damage( dmg+(2-pc->distFrom(this)), DAMAGE_FIRE ); } } Delete(); }
bool CheckRenderPath(const WCHAR *path) { CrashIf(!path); bool hasArg = false; const WCHAR *p = path - 1; while ((p = str::FindChar(p + 1, '%')) != NULL) { p++; if (*p == '%') continue; if (*p == '0' && '1' <= *(p + 1) && *(p + 1) <= '9') p += 2; if (hasArg || *p != 'd') { ErrOut("Error: Render path may contain '%%d' only once, other '%%' signs must be doubled!"); return false; } hasArg = true; } return true; }
Effect::Effect(GraphicsSystem *curSystem, CTSTR lpEffectFile) { traceIn(Effect::Effect); system = curSystem; String strEffectFile = lpEffectFile; strEffectFile.FindReplace(TEXT("\\"), TEXT("/")); strEffectDir = GetPathDirectory(strEffectFile); effectPath = strEffectFile; XFile chi; if(!chi.Open(strEffectFile, XFILE_READ, XFILE_OPENEXISTING)) ErrOut(TEXT("Could not open effect file '%s'"), strEffectFile.Array()); String strFile; chi.ReadFileToString(strFile); chi.Close(); String errors; bProcessing = TRUE; system->curProcessingEffect = this; EffectProcessor test; if(!test.ProcessEffect(this, GetPathFileName(strEffectFile, TRUE), strFile, errors)) ProgramBreak(); bProcessing = FALSE; system->curProcessingEffect = NULL; hViewProj = GetParameterByName(TEXT("ViewProj")); hWorld = GetParameterByName(TEXT("World")); hScale = GetParameterByName(TEXT("World")); traceOut; }
int ParallelProgram::Run() { // FunctionEntry("NAME"): Updates the user-defined stack and // the program profiles with timing information. The placement // of FunctionEntry and FunctionExit calls is at the developer's // discretion. FunctionEntry("Run"); int myid = _communicator.Rank(); int nproc = _communicator.Size(); bool use_file = !output_name.empty(); // Put out a quick blurb about number of procs just // to give the user confidence we are actually running // in parallel. Note that when using the "StdOut" method // that it automatically does output only on rank 0. If // the developer wants asyncrhonous output, then they // have to revert to using standard streams. std::ostringstream RepStr; if(verblevel > 1) RepStr << "Running on " << nproc << " processors." << std::endl; StdOut(RepStr.str()); _communicator.Barrier(); if(verblevel > 1) StdOut("All procesors ready.\n"); // Open the specified output file for writing on rank 0 if(use_file && !myid){ Ouf.open(output_name.c_str(),std::ios::app); if(!Ouf){ // If the output file failed to open, notify // to error stream and return non-zero std::ostringstream Ostr; Ostr << "Error: Unable to open output file, " << output_name << "."; ErrOut(Ostr.str()); // In parallel, we don't return right away since // this part of the code is only done on proc 0. // Instead, the error value is set in the communicator // which will indicate to all processors that there // has been some error. _communicator.SetExit(1); } } // Check to see if an error condition was set // in the file open block above. If so, then // return with an error code. if(_communicator.Check()){ // don't forget to tell the profiler/stacker the // function is exiting. FunctionExit("Run"); return(1); } // Correct value of PI to several places double PIVAL = 3.141592653589793238462643383; // All processors should already have this as it // came from the command line - but just in case, // we broadcast it here to make sure. FunctionEntry("Broadcast"); _communicator.BroadCast(ndiv,0); FunctionExit("Broadcast"); // This block partitions the // domain [0,1] with ndiv // intervals among nproc processors int nper = ndiv/nproc; int nvol = nper*nproc; int leftover = ndiv - nvol; int myn = nper; if(myid < leftover) myn++; int mystart = 0; for(int i = 0; i < myid;i++){ mystart += nper; if(i < leftover) mystart++; } // If there are less divisions than processors, then // just forget about domain decomposition and do everything // on processor 0. if(nper == 0){ if(myid == 0) myn = ndiv; else myn = 0; } // Use the results from domain decomposition to // set the domain [a,b] for this processor and get the // stepsize. double h = 1.0/(static_cast<double>(ndiv)); double a = h*mystart; double b = a + h*myn; // Integrate f on this processor's subdomain using trapezoid quadrature FunctionEntry("TrapezoidMethod"); double my_tpi = 0.0; if(myn > 0){ // if there are points in this processor's domain try { FunctionEntry("TrapezoidQuadrature"); my_tpi = GridConversion::TrapezoidQuadrature(f,a,b,myn); FunctionExit("TrapezoidQuadrature"); } catch (...){ StdOut("Numerical limits of GridConversion::TrapezoidQuadrature exceeded."); my_tpi = 0.0; } } double tpi = 0.0; // Sum up the contributions from each processor and store the results on // processor 0 in "tpi". FunctionEntry("Reduce"); // time the communication _communicator.Reduce(my_tpi, tpi,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP, 0); FunctionExit("Reduce"); // end of the communication FunctionExit("TrapezoidMethod"); // Integrate f on this processor's subdomain using midpoint quadrature FunctionEntry("MidPointMethod"); double my_mppi = 0.0; if(myn > 0) { // if there are points in this processor's domain try{ FunctionEntry("MidPointQuadrature"); my_mppi = GridConversion::MidPointQuadrature(f,a,b,myn); FunctionExit("MidPointQuadrature"); } catch (...){ StdOut("Numerical limits of GridConversion::MidPointQuadrature exceeded."); my_mppi = 0.0; } } double mppi = 0.0; // Sum up the contributions from each processor and store the results on // processor 0 in "mppi". FunctionEntry("Reduce"); // time the communication _communicator.Reduce(my_mppi, mppi,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP, 0); FunctionExit("Reduce"); // end of the communication FunctionExit("MidPointMethod"); // Report the results to stdout or to file if one was specified. FunctionEntry("IO"); if (!myid) { if(use_file){ Ouf << ndiv << " " << std::setprecision(16) << tpi << " " << std::setprecision(4) << std::fabs(tpi-PIVAL) << " " << std::setprecision(16) << mppi << " " << std::setprecision(4) << std::fabs(mppi-PIVAL) << " " << std::endl; Ouf.close(); } else if(verblevel) { std::ostringstream Ostr; Ostr << "With " << ndiv << " divisions, PI was calculated:" << std::endl << "MidPointQuadrature: " << std::setprecision(16) << mppi << "\t\t" << std::setprecision(4) << std::fabs(mppi - PIVAL) << std::endl << "TrapezoidQuadrature: " << std::setprecision(16) << tpi << "\t\t" << std::setprecision(4) << std::fabs(tpi - PIVAL) << std::endl; StdOut(Ostr.str()); } } FunctionExit("IO"); // // ---------- Program End ---------------- // Update the stacker/profiler that we are exiting // this function. FunctionExit("Run"); // return 0 for success return(0); };
int SerialProgram::Run() { // FunctionEntry("NAME"): Updates the user-defined stack and // the program profiles with timing information. The placement // of FunctionEntry and FunctionExit calls is at the developer's // discretion. FunctionEntry("Run"); // ---------- The Program ----------------- // This program just "copies" the input file // to the output file. // // Open the specified input file for reading Inf.open(input_name.c_str()); if(!Inf){ // If the input file failed to open, notify to // the error stream and return non-zero std::ostringstream Ostr; Ostr << "SerialProgram:Run: Error: Could not output input file, " << input_name << "."; ErrOut(Ostr.str()); // don't forget to tell the profiler/stacker the // function is exiting. FunctionExit("Run"); return(1); } // Open the specified output file for writing bool use_outfile = false; if(!output_name.empty()){ use_outfile = true; Ouf.open(output_name.c_str()); if(!Ouf){ // If the output file failed to open, notify // to error stream and return non-zero std::ostringstream Ostr; Ostr << "SerialProgram:Run: Error: Unable to open output file, " << output_name << "."; ErrOut(Ostr.str()); // don't forget to tell the profiler/stacker the // function is exiting. FunctionExit("Run"); return(1); } } // Read lines from the input file and repeat them // to the output file. std::string line; while(std::getline(Inf,line)){ if(use_outfile) Ouf << line << std::endl; else StdOut(line+"\n"); } // Close both files Ouf.close(); Inf.close(); // // ---------- Program End ----------------- // Update the stacker/profiler that we are exiting // this function. FunctionExit("Run"); // return 0 for success return(0); };
int main(int argc, char **argv) { setlocale(LC_ALL, "C"); DisableDataExecution(); WStrVec argList; ParseCmdLine(GetCommandLine(), argList); if (argList.Count() < 2) { Usage: ErrOut("%s <filename> [-pwd <password>][-full][-alt][-render <path-%%d.tga>]\n", path::GetBaseName(argList.At(0))); return 0; } ScopedMem<WCHAR> filePath; WIN32_FIND_DATA fdata; HANDLE hfind = FindFirstFile(argList.At(1), &fdata); if (INVALID_HANDLE_VALUE != hfind) { ScopedMem<WCHAR> dir(path::GetDir(argList.At(1))); filePath.Set(path::Join(dir, fdata.cFileName)); FindClose(hfind); } else { // embedded documents are referred to by an invalid path // containing more information after a colon (e.g. "C:\file.pdf:3:0") filePath.Set(str::Dup(argList.At(1))); } bool fullDump = false; WCHAR *password = NULL; WCHAR *renderPath = NULL; bool useAlternateHandlers = false; bool loadOnly = false; int breakAlloc = 0; for (size_t i = 2; i < argList.Count(); i++) { if (str::Eq(argList.At(i), L"-full")) fullDump = true; else if (str::Eq(argList.At(i), L"-pwd") && i + 1 < argList.Count()) password = argList.At(++i); else if (str::Eq(argList.At(i), L"-render") && i + 1 < argList.Count()) renderPath = argList.At(++i); else if (str::Eq(argList.At(i), L"-alt")) useAlternateHandlers = true; else if (str::Eq(argList.At(i), L"-loadonly")) loadOnly = true; #ifdef DEBUG else if (str::Eq(argList.At(i), L"-breakalloc") && i + 1 < argList.Count()) breakAlloc = _wtoi(argList.At(++i)); #endif else goto Usage; } #ifdef DEBUG if (breakAlloc) { _CrtSetBreakAlloc(breakAlloc); if (!IsDebuggerPresent()) MessageBox(NULL, L"Keep your debugger ready for the allocation breakpoint...", L"EngineDump", MB_ICONINFORMATION); } #endif // optionally use GDI+ rendering for PDF/XPS and the original ChmEngine for CHM DebugGdiPlusDevice(useAlternateHandlers); DebugAlternateChmEngine(!useAlternateHandlers); ScopedGdiPlus gdiPlus; DocType engineType; PasswordHolder pwdUI(password); BaseEngine *engine = EngineManager::CreateEngine(true, filePath, &pwdUI, &engineType); if (!engine) { ErrOut("Error: Couldn't create an engine for %s!\n", path::GetBaseName(filePath)); return 1; } if (!loadOnly) DumpData(engine, fullDump); if (renderPath) RenderDocument(engine, renderPath); delete engine; #ifdef DEBUG // report memory leaks on stderr for engines that shouldn't leak if (engineType != Engine_DjVu) { _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); } #endif return 0; }
int SerialProgram::WriteOutput(){ std::ostringstream Ostr; std::stringstream ss; // Open the specified output file for writing bool use_outfile = false; if(!output_name.empty()){ use_outfile = true; Ouf.open(output_name.c_str()); if(!Ouf){ // If the output file failed to open, notify // to error stream and return non-zero std::ostringstream ErrOstr; ErrOstr << "Error: Unable to open output file, " << output_name << "."; StdOut(Ostr.str()); Ostr.str(""); ErrOut(ErrOstr.str()); ErrOstr.str(""); // don't forget to tell the profiler/stacker the // function is exiting. FunctionExit("Run"); return(1); } } // Write mesh info to output file or screen ss.clear(); ss.str(""); //Write Patran packet 25 Intro (unused) ss << "unused line" << std::endl; ss << "unused line" << std::endl; //Write Patran packet 26 ss << "26 1 1 1 " << numNodes << " " << numElems << " 1 1 1" << std::endl; ss << "unused line" << std::endl; unsigned int ePos, expPos; std::stringstream numSS; std::string output, exponent; //Write Patran packet 1 node coordinates for(int i=0; i < numNodes; i++){ ss << "1 " << i+1 << std::endl; if(fabs(nodes[3*i+0]) > 1.0e-10 || nodes[3*i+0] == 0.0){ numSS << std::setprecision(9) << std::scientific << nodes[3*i + 0]; ePos = numSS.str().find("e"); expPos = numSS.str().find_last_of("0"); //std::cout << "numSS.str() = " << numSS.str() << std::endl; //std::cout << "expPos = " << expPos << std::endl; //std::cout << "numSS.str().size() = " << numSS.str().size() << std::endl; if(expPos == numSS.str().size()-1) exponent = "0"; else exponent = numSS.str().substr(expPos+1,numSS.str().size()); output = numSS.str().substr(0,ePos+2) + exponent; } else{//we have to be careful with numbers that have two digit exponents //in scientific notation because Rocfrac expects all numbers to take a //specific number of columns. if(nodes[3*i+0] < 0.0) numSS << std::setprecision(8) << std::scientific << nodes[3*i + 0]; else numSS << std::setprecision(9) << std::scientific << nodes[3*i + 0]; output = numSS.str(); } ss << std::setw(16) << output; numSS.str(""); numSS.clear(); if(fabs(nodes[3*i+1]) > 1.0e-10 || nodes[3*i+1] == 0.0){ numSS << std::setprecision(9) << std::scientific << nodes[3*i + 1]; ePos = numSS.str().find("e"); expPos = numSS.str().find_last_of("0"); //std::cout << "numSS.str() = " << numSS.str() << std::endl; //std::cout << "expPos = " << expPos << std::endl; //std::cout << "numSS.str().size() = " << numSS.str().size() << std::endl; if(expPos == numSS.str().size()-1) exponent = "0"; else exponent = numSS.str().substr(expPos+1,numSS.str().size()); output = numSS.str().substr(0,ePos+2) + exponent; } else{//we have to be careful with numbers that have two digit exponents //in scientific notation because Rocfrac expects all numbers to take a //specific number of columns. if(nodes[3*i+1] < 0.0) numSS << std::setprecision(8) << std::scientific << nodes[3*i + 1]; else numSS << std::setprecision(9) << std::scientific << nodes[3*i + 1]; output = numSS.str(); } ss << std::setw(16) << output; numSS.str(""); numSS.clear(); if(fabs(nodes[3*i+2]) > 1.0e-10 || nodes[3*i+2] == 0.0){ numSS << std::setprecision(9) << std::scientific << nodes[3*i + 2]; ePos = numSS.str().find("e"); expPos = numSS.str().find_last_of("0"); //std::cout << "numSS.str() = " << numSS.str() << std::endl; //std::cout << "expPos = " << expPos << std::endl; //std::cout << "numSS.str().size() = " << numSS.str().size() << std::endl; if(expPos == numSS.str().size()-1) exponent = "0"; else exponent = numSS.str().substr(expPos+1,numSS.str().size()); output = numSS.str().substr(0,ePos+2) + exponent; } else{//we have to be careful with numbers that have two digit exponents //in scientific notation because Rocfrac expects all numbers to take a //specific number of columns. if(nodes[3*i+2] < 0.0) numSS << std::setprecision(8) << std::scientific << nodes[3*i + 2]; else numSS << std::setprecision(9) << std::scientific << nodes[3*i + 2]; output = numSS.str(); } ss << std::setw(16) << output << std::endl; numSS.str(""); numSS.clear(); ss << "unused line" << std::endl; } //Write Patran packet 2 element connectivities for(int i=0; i < numElems; i++){ ss << "2 " << i+1 << " " << elemShape << std::endl << " " << numNodesPerElem << " 0" << " 0" << std::endl; for(int j=0; j < numNodesPerElem; j++){ ss << elems[i*numNodesPerElem + j] << " "; } ss << std::endl; } //Write Patran packet 8 (all nodes with this boundary type) for(int i=0; i < numNodes; i++){ for(int k=0; k < nodeBCs[i].size(); k++){ if(nodeBCs[i][k] == 8){ ss << "8 " << i+1 << " 1 2" << std::endl; ss << " 0"; for(int j=0; j < 3; j++) ss << int(nodeBCValues[i][k][j]); ss << "000" << std::endl; for(int j=3; j < 6; j++){ if(nodeBCValues[i][k][j-3] != 0) ss << " " << nodeBCValues[i][k][j]; } ss << std::endl; } } } //Write Patran packet 6 (all elements with this boundary type) //loop over all the elements //std::cout << "bcs of type 6: " << std::endl; for(int i=0; i < numElems; i++){ //std::cout << "elem " << i+1 << ": " << std::endl; //loop over the domains for that element (we only want //to print one domain's bcs for the element at a time for(int doms=0; doms < elemsToDomains[i].size(); doms++){ int domain=elemsToDomains[i][doms]-1; //std::cout << "domain " << domain+1 << std::endl; //loop over the boundary flags for that domain for(int j=0; j < domainBCs[domain].size(); j++){ int bcCount=0; if(domainBCs[domain][j] == 6){ //std::cout << "bc " << j+1 << ": " << std::endl; ss << "6 " << i+1 << " 1 2 0 0 0 0 0" << std::endl; ss << "111100000"; //loop over the nodes for that element for(int k=0; k < numNodesPerElem; k++){ bool onBC=false; int node = elems[i*numNodesPerElem + k]-1; //std::cout << "node " << k+1 << " (" << node+1 << ")" << std::endl; //loop over the bc flags for that node for(int l=0; l < nodeBCs[node].size(); l++){ if(nodeBCs[node][l] == 6){ //check if the bcs have the same values for(int m=0; m < nodeBCValues[node][l].size(); m++){ if(nodeBCValues[node][l][m] != domainBCValues[domain][j][m]) break; else if(m == nodeBCValues[node][l].size()-1){ onBC=true; bcCount++; //std::cout << "has bc" << std::endl; } } } }//loop over node bcs if(onBC){ //now check that the node is on that domain int domCount; for(domCount=0; domCount < nodesToDomains[node].size(); domCount++){ if(nodesToDomains[node][domCount] == domain+1){ //std::cout << "node on domain (writing it)" << std::endl; ss << "1"; break; } } if(domCount == nodesToDomains[node].size()) ss << "0"; } else ss << "0"; }//loop over nodes for the element //Fill in with 0's at the end if we are using tet elements if(numNodesPerElem == 4) ss << "0000"; ss << std::endl; for(int m=0; m < domainBCValues[domain][j].size(); m++) ss << domainBCValues[domain][j][m] << " "; ss << std::endl; }//if it is bc type 6 }//loop over bc flags for domain }//loop over the domains for the element }//loop over all elements ss << "99 0 0 1"; if(use_outfile){ Ouf << ss.str(); } else StdOut(ss.str()); // Close output file Ouf.close(); StdOut(Ostr.str()); Ostr.str(""); return 0; } //ReadOutput function
void newbieitems(P_CHAR pc) { VALIDATEPC(pc); NXWCLIENT ps=pc->getClient(); if(ps==NULL) return; int first, second, third, storeval, itemaddperskill, loopexit = 0; char sect[512]; char whichsect[105]; cScpIterator* iter = NULL; first = bestskill(pc); second = nextbestskill(pc, first); third = nextbestskill(pc, second); if (pc->baseskill[third] < 190) third = 46; for (itemaddperskill = 1; itemaddperskill <= 5; itemaddperskill++) { switch (itemaddperskill) { // first of all the general section with the backpack, else where we put items? case 1: strcpy(whichsect, "SECTION ALLNEWBIES"); break; case 2: if ( (pc->getId() == BODY_MALE) && (pc->getOldId() == BODY_MALE) ) strcpy(whichsect, "SECTION MALENEWBIES"); else strcpy(whichsect, "SECTION FEMALENEWBIES"); break; case 3: sprintf(whichsect, "SECTION BESTSKILL %i", first); break; case 4: sprintf(whichsect, "SECTION BESTSKILL %i", second); break; case 5: sprintf(whichsect, "SECTION BESTSKILL %i", third); break; default: ErrOut("Switch fallout. newbie.cpp, newbieitems()/n"); // Morrolan } sprintf(sect, whichsect); char script1[1000], script2[1000]; safedelete(iter); iter = Scripts::Newbie->getNewIterator(sect); if (iter==NULL) return; do { iter->parseLine(script1,script2); if (script1[0] == '@') pc->loadEventFromScript(script1, script2); // Sparhawk: Huh loading character events // from newbie item scripts???? if (script1[0] != '}') { if (!(strcmp("PACKITEM", script1))) { std::string itemnum, amount; splitLine( script2, itemnum, amount ); int amt = ( amount != "" )? str2num( amount ) : INVALID; //ndEndy defined amount P_ITEM pi_n = item::CreateFromScript( str2num( itemnum ), pc->getBackpack(), amt ); if (ISVALIDPI(pi_n)) { pi_n->priv |= 0x02; // Mark as a newbie item } strcpy(script1, "DUMMY"); } else if (!strcmp("BANKITEM", script1)) { std::string itemnum, amount; splitLine( script2, itemnum, amount ); int amt= (amount!="")? str2num( amount ) : INVALID; P_ITEM pi = item::CreateFromScript( str2num( itemnum ), pc->GetBankBox(), amt ); if (ISVALIDPI(pi)) { pi->priv |= 0x02; // Mark as a newbie item } strcpy(script1, "DUMMY"); } else if (!strcmp("EQUIPITEM", script1)) { P_ITEM pi = item::CreateFromScript( script2 ); if (ISVALIDPI(pi)) { pi->priv |= 0x02; // Mark as a newbie item pi->setCont(pc); storeval = pi->getScriptID(); } strcpy(script1, "DUMMY"); } } } while ((script1[0] != '}') &&(++loopexit < MAXLOOPS)); safedelete(iter); } // Give the character some gold if ( goldamount > 0 ) { item::CreateFromScript( "$item_gold_coin", pc->getBackpack(), goldamount ); } }
/*! \author Zippy \brief Build an house Triggered by double clicking a deed-> the deed's morex is read for the house section in house.cpp. Extra items can be added using HOUSE ITEM, (this includes all doors!) and locked "LOCK" Space around the house with SPACEX/Y and CHAR offset CHARX/Y/Z \todo Remove temp variable */ void buildhouse( pClient client, pTarget t ) { int i = t->buffer[2]; char temp[TEMP_STR_SIZE]; //xan -> this overrides the global temp var int loopexit=0;//where they click, and the house/key items uint32_t k, sx = 0, sy = 0, icount=0; uint16_t x, y, id_tile; int16_t z; int hitem[100];//extra "house items" (up to 100) char sect[512]; //file reading char itemsdecay = 0; // set to 1 to make stuff decay in houses static int looptimes=0; //for targeting int cx=0,cy=0,cz=8; //where the char is moved to when they place the house (Inside, on the steps.. etc...)(Offset) int boat=0;//Boats int hdeed=0;//deed id # int norealmulti=0,nokey=0,othername=0; char name[512]; pChar pc = client->currChar(); if ( ! pc ) return; sLocation charpos= pc->getPosition(); int16_t id = INVALID; //house ID hitem[0]=0;//avoid problems if there are no HOUSE_ITEMs by initializing the first one as 0 if (i) { cScpIterator* iter = NULL; char script1[1024]; char script2[1024]; sprintf(sect, "SECTION HOUSE %d", i);//and BTW, .find() adds SECTION on there for you.... iter = Scripts::House->getNewIterator(sect); if (iter==NULL) return; do { iter->parseLine(script1, script2); if ((script1[0]!='}')&&(script1[0]!='{')) { if (!(strcmp(script1,"ID"))) { id = hex2num(script2); } else if (!(strcmp(script1,"SPACEX"))) { sx=str2num(script2)+1; } else if (!(strcmp(script1,"SPACEY"))) { sy=str2num(script2)+1; } else if (!(strcmp(script1,"CHARX"))) { cx=str2num(script2); } else if (!(strcmp(script1,"CHARY"))) { cy=str2num(script2); } else if (!(strcmp(script1,"CHARZ"))) { cz=str2num(script2); } else if( !(strcmp(script1, "ITEMSDECAY" ))) { itemsdecay = str2num( script2 ); } else if (!(strcmp(script1,"HOUSE_ITEM"))) { hitem[icount]=str2num(script2); icount++; } else if (!(strcmp(script1, "HOUSE_DEED"))) { hdeed=str2num(script2); } else if (!(strcmp(script1, "BOAT"))) boat=1;//Boats else if (!(strcmp(script1, "NOREALMULTI"))) norealmulti=1; // LB bugfix for pentas crashing client else if (!(strcmp(script1, "NOKEY"))) nokey=1; else if (!(strcmp(script1, "NAME"))) { strcpy(name,script2); othername=1; } } } while ( (strcmp(script1,"}")) && (++loopexit < MAXLOOPS) ); safedelete(iter); if (!id) { ErrOut("Bad house script # %i!\n",i); return; } } if(!looptimes) { if (i) { if (norealmulti) { pTarget targ = clientInfo[s]->newTarget( new cLocationTarget() ); targ->code_callback=buildhouse; ShortToCharPtr(0x4064, t->buffer); targ->send( ps ); ps->sysmsg( "Select a place for your structure: "); } else client->sysmessage("Select location for building."); nPackets::Sent::TargetMulti pk(0x00010000/*serial*/, id -0x4000/*model*/); client->sendPacket(&pk); } else { client->sysmessage("Select location for building."); nPackets::Sent::TargetMulti pk(0x00010000/*serial*/, ShortFromCharPtr(t->buffer) -0x4000/*model*/); client->sendPacket(&pk); } looptimes++;//for when we come back after they target something return; } if(looptimes) { looptimes=0; if(!pc->IsGM() && SrvParms->houseintown==0) { if ((region[pc->region].priv & rgnFlagGuarded) && itemById::IsHouse(id) ) // popy { client->sysmessage(" You cannot build houses in town!"); return; } } x = ShortFromCharPtr(buffer[s] +11); //where they targeted y = ShortFromCharPtr(buffer[s] +13); z = ShortFromCharPtr(buffer[s] +15); id_tile = ShortFromCharPtr(buffer[s] +17); z += tileHeight(id_tile); //XAN : House placing fix :) if ( (( x<XBORDER || y <YBORDER ) || ( x>(uint32_t)((map_width*8)-XBORDER) || y >(uint32_t)((map_height*8)-YBORDER) )) ) { client->sysmessage("You cannot build your structure there!"); return; } /* if (ishouse(id1, id2)) // strict checking only for houses ! LB { if(!(CheckBuildSite(x,y,z,sx,sy))) { client->sysmessage("Can not build a house at that location (CBS)!"); return; } }*/ for (k=0;k<sx;k++)//check the SPACEX and SPACEY to make sure they are valid locations.... { for (uint32_t l=0;l<sy;l++) { sLocation loc; loc.x=x+k; loc.y=y+l; loc.z=z; sLocation newpos = sLocation( x+k, y+l, z ); if ( (isWalkable( newpos ) == illegal_z ) && ((charpos.x != x+k)&&(charpos.y != y+l)) ) /*This will take the char making the house out of the space check, be careful you don't build a house on top of your self..... this had to be done So you could extra space around houses, (12+) and they would still be buildable.*/ { client->sysmessage("You cannot build your stucture there."); return; //ConOut("Invalid %i,%i [%i,%i]\n",k,l,x+k,y+l); } //else ConOut("DEBUG: Valid at %i,%i [%i,%i]\n",k,l,x+k,y+l); if ( !norealmulti && cMulti::getAt(loc) ) { client->sysmessage("You cant build structures inside structures"); return; } } } if((id % 256)>=18) sprintf(temp,"%s's house",pc->getCurrentName().c_str());//This will make the little deed item you see when you have showhs on say the person's name, thought it might be helpful for GMs. else strcpy(temp, "a mast"); if(norealmulti) strcpy(temp, name); //--^ if (othername) strcpy(temp,name); if (id == INVALID) return; pItem pHouse = item::CreateFromScript( "$item_hardcoded" ); if ( !pHouse ) return; pHouse->setId( id ); pHouse->setCurrentName( temp ); pc->making=0; pHouse->setPosition(x, y, z); pHouse->setDecay( false ); pHouse->setNewbie( false ); pHouse->setDispellable( false ); pHouse->more4 = itemsdecay; // set to 1 to make items in houses decay pHouse->morex=hdeed; // crackerjack 8/9/99 - for converting back *into* deeds pHouse->setOwner(pc); if (pHouse->isInWorld()) { mapRegions->add(pHouse); } if (!hitem[0] && !boat) { pc->teleport(); return;//If there's no extra items, we don't really need a key, or anything else do we? ;-) } if(boat) { if(!Build(s,pHouse, id%256/*id2*/)) { pHouse->Delete(); return; } } if (i) { pItem pFx1 = MAKE_ITEM_REF( pc->fx1 ); if ( pFx1 != 0 ) pFx1->Delete(); // this will del the deed no matter where it is } pc->fx1=-1; //reset fx1 so it does not interfere // bugfix LB ... was too early reseted pItem pKey=NULL; pItem pKey2=NULL; pItem pBackPack = pc->getBackpack(); //Key... //Altered key naming to include pc's name. Integrated backpack and bankbox handling (Sparhawk) if ((id%256 >=0x70) && (id%256 <=0x73)) { sprintf(temp,"%s's tent key",pc->getCurrentName().c_str()); pKey = item::CreateFromScript( "$item_iron_key", pBackPack ); //iron key for tents pKey2= item::CreateFromScript( "$item_iron_key", pBackPack ); } else if(id%256 <=0x18) { sprintf(temp,"%s's ship key",pc->getCurrentName().c_str()); pKey= item::CreateFromScript( "$item_bronze_key", pBackPack ); //Boats -Rusty Iron Key pKey2= item::CreateFromScript( "$item_bronze_key", pBackPack ); } else { sprintf(temp,"%s's house key",pc->getCurrentName().c_str()); pKey= item::CreateFromScript( "$item_gold_key", pBackPack ); //gold key for everything else; pKey2= item::CreateFromScript( "$item_gold_key", pBackPack ); } if ( ! pKey || ! pKey2 ) return; pKey->Refresh(); pKey2->Refresh(); pHouse->st = pKey->getSerial(); // Create link from house to housekeys to allow easy renaming of pHouse->st2= pKey2->getSerial(); // house, housesign and housekeys without having to loop trough // all world items (Sparhawk) pKey->more = pHouse->getSerial(); //use the house's serial for the more on the key to keep it unique pKey->type=ITYPE_KEY; pKey->setNewbie(); pKey2->more = pHouse->getSerial(); //use the house's serial for the more on the key to keep it unique pKey2->type=ITYPE_KEY; pKey2->setNewbie(); pItem bankbox = pc->GetBankBox(); if(bankbox!=NULL) // we sould add a key in bankbox only if the player has a bankbox =) { pItem p_key3=item::CreateFromScript( "$item_gold_key" ); if ( ! p_key3 ) return; p_key3->setCurrentName( "a house key" ); p_key3->more = pHouse->getSerial(); p_key3->type=ITYPE_KEY; p_key3->setNewbie(); bankbox->AddItem(p_key3); } if(nokey) { pKey->Delete(); // No key for .. nokey items pKey2->Delete(); // No key for .. nokey items } for (k=0;k<icount;k++)//Loop through the HOUSE_ITEMs { cScpIterator* iter = NULL; char script1[1024]; char script2[1024]; sprintf(sect,"SECTION HOUSE ITEM %i",hitem[k]); iter = Scripts::House->getNewIterator(sect); if (iter!=NULL) { pItem pi_l=NULL; loopexit=0; do { iter->parseLine(script1, script2); if (script1[0]!='}') { if (!(strcmp(script1,"ITEM"))) { pi_l=item::CreateScriptItem(s,str2num(script2),0);//This opens the item script... so we gotta keep track of where we are with the other script. if(pi_l) { pi_l->magic=2;//Non-Movebale by default pi_l->setDecay( false ); //since even things in houses decay, no-decay by default pi_l->setNewbie( false ); pi_l->setDispellable( false ); pi_l->setPosition(x, y, z); pi_l->setOwner(pc); // SPARHAWK 2001-01-28 Added House sign naming if (pi_l->IsSign()) if ((id%256 >=0x70) && (id%256<=0x73)) pi_l->setCurrentName("%s's tent",pc->getCurrentName().c_str()); else if (id%256<=0x18) pi_l->setCurrentName("%s's ship",pc->getCurrentName().c_str()); else pi_l->setCurrentName("%s's house",pc->getCurrentName().c_str()); } } if (!(strcmp(script1,"DECAY"))) { if (pi_l) pi_l->setDecay(); } if (!(strcmp(script1,"NODECAY"))) { if (pi_l) pi_l->setDecay( false ); } if (!(strcmp(script1,"PACK")))//put the item in the Builder's Backpack { if (pi_l) pi_l->setContainer(pc->getBackpack()); if (pi_l) pi_l->setPosition("x", rand()%90+31); if (pi_l) pi_l->setPosition("y", rand()%90+31); if (pi_l) pi_l->setPosition("z", 9); } if (!(strcmp(script1,"MOVEABLE"))) { if (pi_l) pi_l->magic=1; } if (!(strcmp(script1,"LOCK")))//lock it with the house key { if (pi_l) pi_l->more = pHouse->getSerial(); } if (!(strcmp(script1,"X")))//offset + or - from the center of the house: { if (pi_l) pi_l->setPosition("x", x+str2num(script2)); } if (!(strcmp(script1,"Y"))) { if (pi_l) pi_l->setPosition("y", y+str2num(script2)); } if (!(strcmp(script1,"Z"))) { if (pi_l) pi_l->setPosition("z", z+str2num(script2)); } } } while ( (strcmp(script1,"}")) && (++loopexit < MAXLOOPS) ); if (pi_l) if (pi_l->isInWorld()) { mapRegions->add(pi_l); } safedelete(iter); } } NxwSocketWrapper sw; sw.fillOnline( pc, false ); for( sw.rewind(); !sw.isEmpty(); sw++ ) { pClient ps_i = sw.getClient(); if(ps_i==NULL) continue; pChar pc_i=ps_i->currChar(); if(pc_i) pc_i->teleport(); } //</Luxor> if (!(norealmulti)) { charpos.x= x+cx; //move char inside house charpos.y= y+cy; charpos.dispz= charpos.z= z+cz; pc->setPosition( charpos ); //ConOut("Z: %i Offset: %i Char: %i Total: %i\n",z,cz,chars[currchar[s]].z,z+cz); pc->teleport(); } } }
int ENGINEAPI EngineMain(TSTR *lp, int c) { int exitcode=0; dwIconID = IDI_GAME; //ugh. //CoInitializeEx(NULL, 0); if(InitBase(TEXT("Game"))) { DWORD newWidth, newHeight, newFreq; BOOL bUseFullscreen = AppConfig->GetInt(TEXT("Display"), TEXT("Fullscreen")); if(!bUseFullscreen) { DisplayMode currentMode; OSGetDisplaySettings(¤tMode); if(currentMode.dwBitsPerPixel != 32) ErrOut(TEXT("Your display settings must be set to 32bit mode.")); } SS->SetEffectsVol(AppConfig->GetFloat(TEXT("Sound"), TEXT("EffectsVolume"), 1.0f)); MM->SetVolume(AppConfig->GetFloat(TEXT("Sound"), TEXT("MusicVolume"), 1.0f)); List<DisplayMode> DisplayModes; zero(&DisplayModes, 8); OSEnumDisplayModes(DisplayModes); newWidth = AppConfig->GetInt(TEXT("Display"), TEXT("Width")); newHeight = AppConfig->GetInt(TEXT("Display"), TEXT("Height")); newFreq = AppConfig->GetInt(TEXT("Display"), TEXT("Frequency")); BOOL bFoundDisplayMode = FALSE; DisplayMode mode; for(int i=0; i<DisplayModes.Num(); i++) { if( (DisplayModes[i].dwHeight == newHeight) && (DisplayModes[i].dwWidth == newWidth) ) { if(DisplayModes[i].dwFrequency == newFreq) { bFoundDisplayMode = TRUE; mcpy(&mode, &DisplayModes[i], sizeof(DisplayMode)); break; } } } mode.dwBitsPerPixel = 32; if(!bFoundDisplayMode) { mode.dwFrequency = 60; mode.dwWidth = 640; mode.dwHeight = 480; Log(TEXT("Monitor does not support %dx%d resolution or doesn't support %d frequency"), newHeight, newWidth, newFreq); } SetResolution(mode, TRUE); if(bUseFullscreen) ToggleFullScreen(); DisplayModes.Clear(); float gamma = AppConfig->GetFloat(TEXT("Display"), TEXT("Gamma"), 1.0f); float brightness = AppConfig->GetFloat(TEXT("Display"), TEXT("Brightness"), 1.0f); float contrast = AppConfig->GetFloat(TEXT("Display"), TEXT("Contrast"), 1.0f); AdjustDisplayColors(gamma, brightness, contrast); GS->ClearColorBuffer(); GameModule *module = (GameModule*)CreateFactoryObject(TEXT("MainGameModule")); if(!module) OSMessageBox(TEXT("Could not load the class 'MainGameModule'.")); else { if(module->ModuleStartup(lp, c)) { //loop exitcode = BaseLoop(); module->ModuleExit(); } DestroyObject(module); } TerminateBase(); } //CoUninitialize(); return 0; }
int main(int argc, char **argv) { setlocale(LC_ALL, "C"); DisableDataExecution(); WStrVec argList; ParseCmdLine(GetCommandLine(), argList); if (argList.Count() < 2) { Usage: ErrOut("%s [-pwd <password>][-quick][-render <path-%%d.tga>] <filename>", path::GetBaseName(argList.At(0))); return 2; } ScopedMem<WCHAR> filePath; WCHAR *password = NULL; bool fullDump = true; WCHAR *renderPath = NULL; float renderZoom = 1.f; bool useAlternateHandlers = false; bool loadOnly = false, silent = false; #ifdef DEBUG int breakAlloc = 0; #endif for (size_t i = 1; i < argList.Count(); i++) { if (str::Eq(argList.At(i), L"-pwd") && i + 1 < argList.Count() && !password) password = argList.At(++i); else if (str::Eq(argList.At(i), L"-quick")) fullDump = false; else if (str::Eq(argList.At(i), L"-render") && i + 1 < argList.Count() && !renderPath) { // optional zoom argument (e.g. -render 50% file.pdf) float zoom; if (i + 2 < argList.Count() && str::Parse(argList.At(i + 1), L"%f%%%$", &zoom) && zoom > 0.f) { renderZoom = zoom / 100.f; i++; } renderPath = argList.At(++i); } // -alt is for debugging alternate rendering methods else if (str::Eq(argList.At(i), L"-alt")) useAlternateHandlers = true; // -loadonly and -silent are only meant for profiling else if (str::Eq(argList.At(i), L"-loadonly")) loadOnly = true; else if (str::Eq(argList.At(i), L"-silent")) silent = true; // -full is for backward compatibility else if (str::Eq(argList.At(i), L"-full")) fullDump = true; #ifdef DEBUG else if (str::Eq(argList.At(i), L"-breakalloc") && i + 1 < argList.Count()) breakAlloc = _wtoi(argList.At(++i)); #endif else if (!filePath) filePath.Set(str::Dup(argList.At(i))); else goto Usage; } if (!filePath) goto Usage; #ifdef DEBUG if (breakAlloc) { _CrtSetBreakAlloc(breakAlloc); if (!IsDebuggerPresent()) MessageBox(NULL, L"Keep your debugger ready for the allocation breakpoint...", L"EngineDump", MB_ICONINFORMATION); } #endif if (silent) { FILE *nul; freopen_s(&nul, "NUL", "w", stdout); freopen_s(&nul, "NUL", "w", stderr); } // optionally use GDI+ rendering for PDF/XPS DebugGdiPlusDevice(useAlternateHandlers); ScopedGdiPlus gdiPlus; ScopedMiniMui miniMui; WIN32_FIND_DATA fdata; HANDLE hfind = FindFirstFile(filePath, &fdata); // embedded documents are referred to by an invalid path // containing more information after a colon (e.g. "C:\file.pdf:3:0") if (INVALID_HANDLE_VALUE != hfind) { ScopedMem<WCHAR> dir(path::GetDir(filePath)); filePath.Set(path::Join(dir, fdata.cFileName)); FindClose(hfind); } EngineType engineType; PasswordHolder pwdUI(password); BaseEngine *engine = EngineManager::CreateEngine(filePath, &pwdUI, &engineType); if (!engine) { ErrOut("Error: Couldn't create an engine for %s!", path::GetBaseName(filePath)); return 1; } Vec<PageAnnotation> *userAnnots = LoadFileModifications(engine->FileName()); engine->UpdateUserAnnotations(userAnnots); delete userAnnots; if (!loadOnly) DumpData(engine, fullDump); if (renderPath) RenderDocument(engine, renderPath, renderZoom, silent); delete engine; #ifdef DEBUG // report memory leaks on stderr for engines that shouldn't leak if (engineType != Engine_DjVu) { _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); } #endif return 0; }
void D3DTexture::CreateBuffer() { traceIn(D3DTexture::CreateBuffer); HRESULT problemo; if(dwTexType == D3DTEXTURE_FRAME_BUFFER) { switch(dwFormat) { case GS_RGBA: dwInternalFormat = D3DFMT_A8R8G8B8; bNeedsBlending = 1; break; case GS_RGBA16: dwInternalFormat = D3DFMT_A16B16G16R16; break; case GS_RGBA16F: dwInternalFormat = D3DFMT_A16B16G16R16F; break; case GS_RGBA32F: dwInternalFormat = D3DFMT_A32B32G32R32F; break; case GS_RG16F: dwInternalFormat = D3DFMT_G16R16F; break; case GS_RG32F: dwInternalFormat = D3DFMT_G32R32F; break; default: ErrOut(TEXT("render target texture format not supported")); } problemo = d3d->d3dDevice->CreateTexture(texWidth, texHeight, !bHasMipMaps, (bHasMipMaps ? D3DUSAGE_AUTOGENMIPMAP : 0) | D3DUSAGE_RENDERTARGET | (bDynamic ? D3DUSAGE_DYNAMIC : 0), (D3DFORMAT)dwInternalFormat, D3DPOOL_DEFAULT, &GetTex(), NULL); if(!SUCCEEDED(problemo)) { if(problemo == D3DERR_OUTOFVIDEOMEMORY) ErrOut(TEXT("Error Creating D3D Render Texture: Out of Video Memory!")); else if(problemo == D3DERR_INVALIDCALL) ErrOut(TEXT("Error Creating D3D Render Texture: Invalid call, Format 0x%lX"), dwFormat); else if(problemo == E_OUTOFMEMORY) ErrOut(TEXT("Error Creating D3D Render Texture: Out of general memory!")); else if(problemo == D3DERR_DRIVERINTERNALERROR) ErrOut(TEXT("Error Creating D3D Render Texture: Internal driver error")); else ErrOut(TEXT("Could not create D3D Render Texture for some unknown reason: exact error code is 0x%lX"), problemo); } } else { switch(dwFormat) { case GS_GRAYSCALE: dwInternalFormat = D3DFMT_L8; break; case GS_L16: dwInternalFormat = D3DFMT_L16; break; case GS_ALPHA: bNeedsBlending = 1; if(d3d->bA8Supported) dwInternalFormat = D3DFMT_A8; else dwInternalFormat = D3DFMT_A8L8; break; case GS_RGB: dwInternalFormat = D3DFMT_X8R8G8B8; break; case GS_RGBA: dwInternalFormat = D3DFMT_A8R8G8B8; bNeedsBlending = 1; break; case GS_RGBA16: dwInternalFormat = D3DFMT_A16B16G16R16; break; case GS_RGBA16F: dwInternalFormat = D3DFMT_A16B16G16R16F; break; case GS_RGBA32F: dwInternalFormat = D3DFMT_A32B32G32R32F; break; case GS_RG16F: dwInternalFormat = D3DFMT_G16R16F; break; case GS_RG32F: dwInternalFormat = D3DFMT_G32R32F; break; case GS_A8L8: dwInternalFormat = D3DFMT_A8L8; break; case GS_DXT1: dwInternalFormat = D3DFMT_DXT1; break; case GS_DXT3: dwInternalFormat = D3DFMT_DXT3; break; case GS_DXT5: dwInternalFormat = D3DFMT_DXT5; break; default: ErrOut(TEXT("texture format not supported")); } problemo = d3d->d3dDevice->CreateTexture(texWidth, texHeight, bHasMipMaps ? 0 : 1, bDynamic ? D3DUSAGE_DYNAMIC : 0, (D3DFORMAT)dwInternalFormat, bDynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED, &GetTex(), NULL); if(!SUCCEEDED(problemo)) { if(problemo == D3DERR_OUTOFVIDEOMEMORY) ErrOut(TEXT("Error Creating D3D Texture: Out of Video Memory!")); else if(problemo == D3DERR_INVALIDCALL) ErrOut(TEXT("Error Creating D3D Texture: Invalid call, Format 0x%lX"), dwFormat); else if(problemo == E_OUTOFMEMORY) ErrOut(TEXT("Error Creating D3D Texture: Out of general memory!")); else ErrOut(TEXT("Could not create D3D Texture for some unknown reason: exact error code is 0x%lX"), problemo); } } traceOut; }
void D3DTexture::SetImage(void *lpData) { traceInFast(D3DTexture::SetImage); assert(lpData); D3DLOCKED_RECT d3dRect; int i,j; HRESULT problemo = GetTex()->LockRect(0, &d3dRect, NULL, 0); if(!d3dRect.pBits) return; if(dwFormat <= GS_GRAYSCALE) // if dwFormat is GS_ALPHA or GS_GRAYSCALE { if(dwInternalFormat == D3DFMT_A8L8) { LPWORD lpBits = (LPWORD)d3dRect.pBits; LPBYTE lpInput = (LPBYTE)lpData; for(i=0; i<texHeight; i++) { for(j=0; j<texWidth; j++) { WORD val = ((lpInput[(i*texWidth)+j]) << 8) | 0xFF; lpBits[(i*(d3dRect.Pitch/2))+j] = val; } } } else { LPBYTE lpBits = (LPBYTE)d3dRect.pBits; LPBYTE lpInput = (LPBYTE)lpData; for(i=0; i<texHeight; i++) mcpy(lpBits+(i*(d3dRect.Pitch)), lpInput+(i*texWidth), texWidth); } } else if((dwFormat == GS_A8L8) || (dwFormat == GS_L16)) { LPWORD lpBits = (LPWORD)d3dRect.pBits; LPWORD lpInput = (LPWORD)lpData; DWORD widthX2 = texWidth*2; for(i=0; i<texHeight; i++) mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX2), widthX2); } else if(dwFormat == GS_RGB) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData; //DWORD widthX3 = texWidth*3; for(i=0; i<texHeight; i++) { //mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX3), widthX3); DWORD curY = (i*texWidth*3); DWORD curD3DY = (i*d3dRect.Pitch); for(j=0; j<texWidth; j++) { DWORD curX = curY+(j*3); DWORD curD3DX = curD3DY+(j*4); lpBits[curD3DX] = lpInput[curX]; lpBits[curD3DX+1] = lpInput[curX+1]; lpBits[curD3DX+2] = lpInput[curX+2]; } } } else if(dwFormat == GS_DXT1) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData; DWORD tempWidth = (texWidth+3)/4; DWORD tempHeight = (texHeight+3)/4; mcpy(lpBits, lpInput, tempWidth*tempHeight*8); } else if((dwFormat == GS_DXT3) || (dwFormat == GS_DXT5)) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData; DWORD tempWidth = (texWidth+3)/4; DWORD tempHeight = (texHeight+3)/4; mcpy(lpBits, lpInput, tempWidth*tempHeight*16); } else if((dwFormat == GS_RGBA) || (dwFormat == GS_RG16F)) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData; DWORD widthX4 = texWidth*4; for(i=0; i<texHeight; i++) { mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX4), widthX4); /*DWORD curY = (i*texWidth*4); DWORD curD3DY = (i*d3dRect.Pitch); for(j=0; j<texWidth; j++) { DWORD jx4 = (j*4); DWORD curX = curY+jx4; DWORD curD3DX = curD3DY+jx4; lpBits[curD3DX] = lpInput[curX+2]; lpBits[curD3DX+1] = lpInput[curX+1]; lpBits[curD3DX+2] = lpInput[curX]; lpBits[curD3DX+3] = lpInput[curX+3]; }*/ } } else if((dwFormat == GS_RGBA16) || (dwFormat == GS_RGBA16F) || (dwFormat == GS_RG32F)) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits; LPWORD lpInput = (LPWORD)lpData; DWORD widthX8 = texWidth*8; for(i=0; i<texHeight; i++) { mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX8), widthX8); /*DWORD yOffset = (i*(texWidth*8)); DWORD yTexOffset = (i*d3dRect.Pitch); for(j=0; j<texWidth; j++) { WORD *lpColors = (WORD*)&lpBits[yTexOffset+(j*8)]; DWORD offset = yOffset+(j*8); lpColors[3] = lpInput[offset+2]; lpColors[2] = lpInput[offset+1]; lpColors[1] = lpInput[offset]; lpColors[0] = lpInput[offset+3]; }*/ } } else if(dwFormat == GS_RGBA32F) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits; LPDWORD lpInput = (LPDWORD)lpData; DWORD widthX16 = texWidth*16; for(i=0; i<texHeight; i++) { mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX16), widthX16); /*DWORD yOffset = (i*(texWidth*16)); DWORD yTexOffset = (i*d3dRect.Pitch); for(j=0; j<texWidth; j++) { LPDWORD lpColors = (LPDWORD)&lpBits[yTexOffset+(j*8)]; DWORD offset = yOffset+(j*16); lpColors[3] = lpInput[offset+2]; lpColors[2] = lpInput[offset+1]; lpColors[1] = lpInput[offset]; lpColors[0] = lpInput[offset+3]; }*/ } } else { GetTex()->UnlockRect(0); ErrOut(TEXT("eep-chi, this message is required because a texture format needs Texture::SetImage implementation.")); return; } GetTex()->UnlockRect(0); if(bHasMipMaps && (dwTexType == D3DTEXTURE_STANDARD_BUFFER)) D3DXFilterTexture(GetTex(), NULL, 0, D3DX_DEFAULT); if(bDynamic && (textureData != lpData)) { Free(textureData); textureData = (LPBYTE)lpData; } traceOutFast; }
void* D3DTexture::GetImage(BOOL bForce, void *lpInputPtr) { if(!bForce || (bDynamic && (dwTexType != D3DTEXTURE_FRAME_BUFFER))) { if(dwTexType == D3DTEXTURE_FRAME_BUFFER) ErrOut(TEXT("Tried to query image for frame buffer")); if(!bDynamic) ErrOut(TEXT("Tried to query image for non-dynamic texture")); } else { IDirect3DSurface9 *RenderSurface=NULL, *CopySurface=NULL; BOOL bSuccess=FALSE; LPVOID lpData=NULL; D3DLOCKED_RECT d3dRect; int i,j; if(dwTexType == D3DTEXTURE_FRAME_BUFFER) { if(SUCCEEDED(GetTex()->GetSurfaceLevel(0, &RenderSurface))) { profileSegment("is it this?"); //3.14% if(SUCCEEDED(d3d->d3dDevice->CreateOffscreenPlainSurface(Width(), Height(), (D3DFORMAT)dwInternalFormat, D3DPOOL_SYSTEMMEM, &CopySurface, NULL))) { profileSegment("or is it this?"); //5.48% if(SUCCEEDED(d3d->d3dDevice->GetRenderTargetData(RenderSurface, CopySurface))) { profileSegment("or how about this?"); if(SUCCEEDED(CopySurface->LockRect(&d3dRect, NULL, 0))) bSuccess = TRUE; } } } if(RenderSurface) RenderSurface->Release(); if(!bSuccess) { if(CopySurface) CopySurface->Release(); return NULL; } } else { if(!SUCCEEDED(GetTex()->GetSurfaceLevel(0, &CopySurface))) return NULL; if(!SUCCEEDED(CopySurface->LockRect(&d3dRect, NULL, 0))) { CopySurface->Release(); return NULL; } } //------------------------------------------------------- if(dwFormat <= GS_GRAYSCALE) { lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()); LPBYTE lpBits = (LPBYTE)d3dRect.pBits; LPBYTE lpInput = (LPBYTE)lpData; for(i=0; i<texHeight; i++) mcpy(lpInput+(i*texWidth), lpBits+(i*(d3dRect.Pitch)), texWidth); } else if(dwFormat == GS_A8L8) { lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*2); LPWORD lpBits = (LPWORD)d3dRect.pBits; LPWORD lpInput = (LPWORD)lpData; DWORD widthX2 = texWidth*2; for(i=0; i<texHeight; i++) mcpy(lpInput+(i*widthX2), lpBits+(i*d3dRect.Pitch), widthX2); } else if(dwFormat == GS_RGB) { lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*3); LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData; //DWORD widthX3 = texWidth*3; for(i=0; i<texHeight; i++) { //mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX3), widthX3); DWORD curY = (i*texWidth*3); DWORD curD3DY = (i*d3dRect.Pitch); for(j=0; j<texWidth; j++) { DWORD curX = curY+(j*3); DWORD curD3DX = curD3DY+(j*4); lpInput[curX] = lpBits[curD3DX]; lpInput[curX+1] = lpBits[curD3DX+1]; lpInput[curX+2] = lpBits[curD3DX+2]; } } } else if(dwFormat == GS_DXT1) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits; DWORD tempWidth = (texWidth+3)/4; DWORD tempHeight = (texHeight+3)/4; lpData = lpInputPtr ? lpInputPtr : Allocate(tempWidth*tempHeight*8); mcpy(lpData, lpBits, tempWidth*tempHeight*8); } else if((dwFormat == GS_DXT3) || (dwFormat == GS_DXT5)) { LPBYTE lpBits = (LPBYTE)d3dRect.pBits; DWORD tempWidth = (texWidth+3)/4; DWORD tempHeight = (texHeight+3)/4; lpData = lpInputPtr ? lpInputPtr : Allocate(tempWidth*tempHeight*16); mcpy(lpData, lpBits, tempWidth*tempHeight*16); } else if((dwFormat == GS_RGBA) || (dwFormat == GS_RG16F)) { lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*4); LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData; DWORD widthX4 = texWidth*4; for(i=0; i<texHeight; i++) mcpy(lpInput+(i*widthX4), lpBits+(i*d3dRect.Pitch), widthX4); } else if((dwFormat == GS_RGBA16) || (dwFormat == GS_RG32F)) { lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*2*4); LPBYTE lpBits = (LPBYTE)d3dRect.pBits; LPWORD lpInput = (LPWORD)lpData; DWORD widthX8 = texWidth*8; for(i=0; i<texHeight; i++) mcpy(lpInput+(i*widthX8), lpBits+(i*d3dRect.Pitch), widthX8); } else if(dwFormat == GS_RGBA16F) //converts to 8bit RGBA { lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*sizeof(Vect4)); LPBYTE lpBits = (LPBYTE)d3dRect.pBits; Vect4* lpInput = (Vect4*)lpData; DWORD widthXVect = texWidth*sizeof(Vect4); for(i=0; i<texHeight; i++) { DWORD curY = (i*texWidth); DWORD curD3DY = (i*d3dRect.Pitch); for(j=0; j<texWidth; j++) { DWORD curX = curY+(j*4); DWORD curD3DX = curD3DY+(j*2*4); lpInput[curY+j].x = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX))); lpInput[curY+j].y = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX+2))); lpInput[curY+j].z = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX+4))); lpInput[curY+j].w = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX+6))); } } } else if(dwFormat == GS_RGBA32F) //converts to 8bit RGBA { lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*sizeof(Vect4)); LPBYTE lpBits = (LPBYTE)d3dRect.pBits; Vect4* lpInput = (Vect4*)lpData; DWORD widthXVect = texWidth*sizeof(Vect4); if(widthXVect == d3dRect.Pitch) mcpy(lpInput, lpBits, widthXVect*texHeight); else { for(i=0; i<texHeight; i++) mcpy(lpInput+(i*texWidth), lpBits+(i*d3dRect.Pitch), widthXVect); } } //------------------------------------------------------- CopySurface->UnlockRect(); CopySurface->Release(); return lpData; } return textureData; }