//文字列の表示 void Player::DrawStrings() { //文字列表示 wstring Mess(L"Aでジャンプ、Xボタンで発射、Bでステージ切替\n"); //オブジェクト数 auto ObjCount = GetStage()->GetGameObjectVec().size(); wstring OBJ_COUNT(L"OBJ_COUNT: "); OBJ_COUNT += Util::UintToWStr(ObjCount); OBJ_COUNT += L"\n"; //物理オブジェクト数 wstring PS_OBJ_COUNT(L"PS_OBJ_COUNT: "); PS_OBJ_COUNT += Util::UintToWStr(GetStage()->GetBasePhysics().GetNumBodies()); PS_OBJ_COUNT += L"\n"; auto fps = App::GetApp()->GetStepTimer().GetFramesPerSecond(); wstring FPS(L"FPS: "); FPS += Util::UintToWStr(fps); FPS += L"\nElapsedTime: "; float ElapsedTime = App::GetApp()->GetElapsedTime(); FPS += Util::FloatToWStr(ElapsedTime); FPS += L"\n"; auto Pos = GetComponent<Transform>()->GetPosition(); wstring PositionStr(L"Position:\t"); PositionStr += L"X=" + Util::FloatToWStr(Pos.x, 6, Util::FloatModify::Fixed) + L",\t"; PositionStr += L"Y=" + Util::FloatToWStr(Pos.y, 6, Util::FloatModify::Fixed) + L",\t"; PositionStr += L"Z=" + Util::FloatToWStr(Pos.z, 6, Util::FloatModify::Fixed) + L"\n"; wstring str = Mess + OBJ_COUNT + PS_OBJ_COUNT + FPS + PositionStr; //文字列をつける auto PtrString = GetComponent<StringSprite>(); PtrString->SetText(str); }
bool GMenu::OnKey(GView *v, GKey &k) { GMenuItem *m = MatchShortcut(k); if (m) { if (!k.Down() && Window) { BMessage Cmd(M_COMMAND); Cmd.AddInt32("Cmd", m->Id()); BMessenger Mess(Window->Handle()); status_t Status = Mess.SendMessage(&Cmd); } return true; } return false; }
bool CTarArchive::Create(std::list<std::string> filenames, const std::string& output, IProgressbar* callback) { bool Ret = false; std::list<std::string>::iterator It; int Size = filenames.size(); int Done = 0; bool Error = false; bool Continue; for(It = filenames.begin(); It != filenames.end(); ++It) { ++Done; if(!WriteData(*It, output)) { Error = true; break; } int Res = Done*50/Size; std::string Mess(i8n("Adding\n")); Mess += *It; Continue = callback->UpdateProgress(Mess, false, Res); if(!Continue) break; #if defined DEBUG && defined VERBOSE std::cout <<"[DBG] " << *It << i8n(" appended to ") << output << '\n'; #endif } if(Error | !Continue) { unlink(output.c_str()); if(Error) std::cout << i8n("[ERR] Due to error(s) on WriteData, I delete ") << output << '\n'; else std::cout << i8n("[ERR] User cancel so I delete ") << output << '\n'; Ret = false; } else { if(CleanClose(output)) Ret = true; else { unlink(output.c_str()); std::cerr << i8n("[ERR] Due to error(s) on CleanClose, I delete ") << output << '\n'; Ret = false; } } if(Ret && Continue) //Delete files here if(Engine::CSettingsManager::Instance()->GetDelete()) for(It = filenames.begin(); It != filenames.end(); ++It) { #if defined DEBUG Log::CLog::Instance()->Log(__FILE__, __LINE__, It->c_str()); Log::CLog::Instance()->Log(__FILE__, __LINE__, " deleted ! \n"); #endif unlink(It->c_str()); } return Ret; }
//Private methods bool CtbzPlugin::Compress(const std::string& input, const std::string& output, IProgressbar* callback) { bool Ret = false; FILE* Out = fopen(output.c_str(), "wb"); // Open up the output file if(!Out) { std::cout << i8n("Error out file!") << '\n'; Ret = false; } else { BZFILE* BZ = 0; int Err = 0; BZ = BZ2_bzWriteOpen(&Err, Out, 9, 0, 90); if(Err != BZ_OK) { std::cout << i8n("Error bzWriteOpen!") << '\n'; Ret = false; } else { // Open up the input file std::ifstream In(input.c_str(), std::ios::in | std::ios::binary); if(!In.good()) { std::cout << i8n("Error in file!") << '\n'; Ret = false; } else { // Get the file size. (I hate C I/O, so don't use them :D ) struct stat Info; double Total; //Try to stat file. if(stat(input.c_str(), &Info) == -1) { std::cout << i8n("Cannot stat ") << input.c_str() << '\n'; Ret = false; } else { char Buffer[4096]; memset(Buffer, 0, 4096); Total = Info.st_size; double Done = 0; do { In.read(Buffer, 4096); std::streamsize BytesRead = In.gcount(); Done += BytesRead; int Result = static_cast<int>((Done*50)/Total)+50; std::string Mess(i8n("bz2 compression of\n")); std::stringstream DoneStr; DoneStr << (Result-50)*2; Mess += output + " : " + DoneStr.str() + "%"; bool Continue = callback->UpdateProgress(Mess, false, Result); if(!Continue) break; BZ2_bzWrite(&Err, BZ, Buffer, BytesRead); } while(In.good()); if( In.bad() || !In.eof() ) Ret = false; else Ret = true; In.close(); } // Close up. BZ2_bzWriteClose(&Err, BZ, 0, 0, 0); fclose(Out); Out = 0; } } } return Ret; }
void cLogLight::Add(const DWORD error,const TCHAR* Format, ...) { PTCHAR Mess(NULL); try { va_list args; va_start( args, Format ); // Init the user arguments list. unsigned int i=1; unsigned mult=1; int result; for(Mess=new TCHAR[MSG_BUF_SIZE]; (result=_vsntprintf_s( Mess, MSG_BUF_SIZE*mult,_TRUNCATE, Format, args ))<0 && i<MSG_BUF_SIZE_DOUBLING; i++, mult <<= 1) { delete [] Mess; Mess = NULL; Mess=new TCHAR[MSG_BUF_SIZE * (mult << 1)]; } tstring winError; if (result<0) { TCHAR truncated[]=_T("MESSAGE TRUNCATED"); _tcscpy_s(Mess+MSG_BUF_SIZE*mult-_countof(truncated)-1,_countof(truncated),truncated); } else { if(error!=ERROR_SUCCESS) { LPVOID lpBuffer; if(FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpBuffer, 16, NULL) != 0) { winError+=_T(". (0x")+i2tstring(error,16)+_T(") ")+reinterpret_cast<PTCHAR>(lpBuffer); LocalFree(lpBuffer); } else { winError+=_T(". Unknown WinError code ")+i2tstring(error,16); } } } AddList(Mess+winError); delete [] Mess; Mess = NULL; } catch(...) { try { if (Mess) delete [] Mess; //Preventing memory leaks AddList(_T("cLog::Add: Exception happened")); } catch(...) { //One more exception happened //going further } } }