ECode WifiP2pServiceResponse::ToString( /* [out] */ String* string) { VALIDATE_NOT_NULL(string); StringBuilder sb("serviceType:"); sb += mServiceType; sb += " status:"; sb += StatusToString(mStatus); String temp; FAIL_RETURN(mDevice->GetDeviceAddress(&temp)); sb += " srcAddr:"; sb += temp; sb += " data:"; sb += mData ? (const char*)mData->GetPayload() : ""; *string = sb.ToString(); return NOERROR; }
void CTaskModel::RemovePrerequisite(unsigned __int64 prereq) { MSXML2::IXMLDOMNode *pNode = 0, *pOld = 0; StringBuffer sb(_T("prerequisite[@taskid=\"")); StringBuffer buf(32); sb.append(ModelUtils::toHexString(prereq, buf)); sb.append(_T("\"]")); BSTR xpath = SysAllocString(sb); HRESULT hr = m_pNode->selectSingleNode(xpath, &pNode); SysFreeString(xpath); if(hr == S_OK && pNode) { hr = m_pNode->removeChild(pNode, &pOld); if(hr == S_OK) { pOld->Release(); } pNode->Release(); } //TODO: notify?.. }
bool System::Execute(const String& s) { STARTUPINFOW si= {sizeof(STARTUPINFO)}; PROCESS_INFORMATION pi; StringBuffer<wchar_t> sb(s); sb.push_back(0); if(!::CreateProcessW(NULL,sb.data(),NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) { System::LogTrace("System::Exectue:%s FAILED",s); return false; } System::LogTrace("System::Exectue:%s",s); ::CloseHandle(pi.hProcess); ::CloseHandle(pi.hThread); return true; }
void testShape() { Util util; FrameBuffer fb; ShadowBuffer sb(fb.width, fb.height, 0, 0, fb.finfo.line_length); fb.backgroundColor = Color(0, 20, 30); sb.backgroundColor = Color(0, 20, 30); map<string, vector<Point> > point = util.readObject("Peta.txt"); Shape shape(util.convertPoint(point, "Baling", 0, 0, 2, 2)[0]); for (int i = 0; i < 360; i++) { Point * tipPoints = shape.getTipPoints(); Point midAxis((tipPoints[0].x + tipPoints[1].x) / 2, (tipPoints[0].y + tipPoints[1].y) / 2, 0 ); shape.rotate(midAxis, 5); shape.scale(midAxis, 1.005, 1.005); shape.color = Color(rand() % 255, rand() % 255, rand() % 255); sb.clear(); shape.draw(sb); fb.draw(sb); } }
//*********************************************************************************************** void CParticleWorkspace::CNode::createEmptyPS() { nlassert(_WS); NL3D::CParticleSystem emptyPS; NL3D::CParticleSystemShape *pss = new NL3D::CParticleSystemShape; pss->buildFromPS(emptyPS); std::auto_ptr<NL3D::CShapeBank> sb(new NL3D::CShapeBank); std::string shapeName = NLMISC::CFile::getFilename(_RelativePath); sb->add(shapeName, pss); NL3D::CShapeBank *oldSB = NL3D::CNELU::Scene->getShapeBank(); NL3D::CNELU::Scene->setShapeBank(sb.get()); NL3D::CParticleSystemModel *psm = NLMISC::safe_cast<NL3D::CParticleSystemModel *>(NL3D::CNELU::Scene->createInstance(shapeName)); nlassert(psm); NL3D::CNELU::Scene->setShapeBank(oldSB); setup(*psm); unload(); // commit new values _PS = psm->getPS(); _PSM = psm; _ShapeBank = sb.release(); _Modified = false; }
void FocusableListView::mouseMoveEvent(QMouseEvent * _e) { if (selectByMouseHoverEnabled_) { const auto index = indexAt(_e->pos()); if (index.isValid()) { auto sm = selectionModel(); auto prevSelected = sm->currentIndex(); { QSignalBlocker sb(sm); sm->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); } if (prevSelected.isValid()) model()->dataChanged(prevSelected, prevSelected); } } QListView::mouseMoveEvent(_e); }
void LengthDoubleSpinBox::setLength(double v) { d->m_orgLengthMm = v; d->m_valueHasChanged = false; cpp::ScopedBool sb(d->m_isInternalUpdateContext, true); Q_UNUSED(sb); switch (this->measurementSystem()) { case QLocale::MetricSystem: this->setValue(AbstractLengthEditor::asMetricLength( v, this->preferredMetricUnit())); break; #if QT_VERSION >= 0x050000 case QLocale::ImperialUKSystem: #endif // QT_VERSION case QLocale::ImperialSystem: this->setValue(AbstractLengthEditor::asImperialLength( v, this->preferredImperialUnit())); break; } }
ECode WifiTile::CallbackInfo::ToString( /* [out] */ String* str) { VALIDATE_NOT_NULL(str); StringBuilder sb("CallbackInfo["); sb.Append("enabled="); sb.Append(mEnabled); sb.Append(",connected="); sb.Append(mConnected); sb.Append(",wifiSignalIconId="); sb.Append(mWifiSignalIconId); sb.Append(",enabledDesc="); sb.Append(mEnabledDesc); sb.Append(",activityIn="); sb.Append(mActivityIn); sb.Append(",activityOut="); sb.Append(mActivityOut); sb.Append(",wifiSignalContentDescription="); sb.Append(mWifiSignalContentDescription); sb.Append(']'); return sb.ToString(str); }
bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { SkASSERT(NULL == rt->renderTargetPriv().getStencilBuffer()); GrUniqueKey sbKey; int width = rt->width(); int height = rt->height(); if (this->caps()->oversizedStencilSupport()) { width = SkNextPow2(width); height = SkNextPow2(height); } GrStencilBuffer::ComputeSharedStencilBufferKey(width, height, rt->numSamples(), &sbKey); SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>( this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey))); if (sb) { if (this->attachStencilBufferToRenderTarget(sb, rt)) { rt->renderTargetPriv().didAttachStencilBuffer(sb); return true; } return false; } if (this->createStencilBufferForRenderTarget(rt, width, height)) { // Right now we're clearing the stencil buffer here after it is // attached to an RT for the first time. When we start matching // stencil buffers with smaller color targets this will no longer // be correct because it won't be guaranteed to clear the entire // sb. // We used to clear down in the GL subclass using a special purpose // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported // FBO status. this->clearStencil(rt); GrStencilBuffer* sb = rt->renderTargetPriv().getStencilBuffer(); sb->resourcePriv().setUniqueKey(sbKey); return true; } else { return false; } }
Stringp StackTrace::format(AvmCore* core) { if(!stringRep) { Stringp s = core->kEmptyString; int displayDepth = depth; if (displayDepth > kMaxDisplayDepth) { displayDepth = kMaxDisplayDepth; } const Element *e = elements; for (int i=0; i<displayDepth; i++, e++) { // env will be NULL if the element is from a fake CallStackNode // omit them since they are only for profiling purposes if (!e->info()) continue; if(i != 0) s = s->appendLatin1("\r\n"); Stringp filename=NULL; if(e->filename()) { StringBuffer sb(core->gc); dumpFilename(e->filename(), sb); filename = core->newStringUTF8(sb.c_str()); } s = core->concatStrings(s, getStackTraceLine(e->info(), filename)); if(e->filename()) { s = core->concatStrings(s, core->intToString(e->linenum())); s = s->appendLatin1("]"); } } stringRep = s; } return stringRep; }
int checker_calc(t_e *e) { char *line; while (get_next_line(0, &line) != 0) { if (ft_strcmp("sa", line) == 0) sa(e->l_a); else if (ft_strcmp("sb", line) == 0) sb(e->l_b); else if (ft_strcmp("ss", line) == 0) ss(e->l_a, e->l_b); else if (ft_strcmp("ra", line) == 0) ra(e->l_a); else if (ft_strcmp("rb", line) == 0) rb(e->l_b); else if (ft_strcmp("rr", line) == 0) rr(e->l_a, e->l_b); else if (ft_strcmp("rra", line) == 0) rra(e->l_a); else if (ft_strcmp("rrb", line) == 0) rrb(e->l_b); else if (ft_strcmp("rrr", line) == 0) rrr(e->l_a, e->l_b); else if (ft_strcmp("pa", line) == 0) pa(e->l_a, e->l_b); else if (ft_strcmp("pb", line) == 0) pb(e->l_a, e->l_b); else { ft_putendl_fd("Error", 2); ft_memdel((void **)&line); return (0); } ft_memdel((void **)&line); } return (1); }
void testLine() { Util util; FrameBuffer fb; ShadowBuffer sb(fb.width, fb.height, 0, 0, fb.finfo.line_length); fb.backgroundColor = Color(0, 20, 30); sb.backgroundColor = Color(0, 20, 30); vector<Point> points; points.push_back(Point(0, 20,20)); points.push_back(Point(800, 500, 300)); Line line(points); for (int i = 0; i < 360; i++) { Point * tipPoints = line.getTipPoints(); Point midAxis((tipPoints[0].x + tipPoints[1].x) / 2, (tipPoints[0].y + tipPoints[1].y) / 2, 0); line.rotate(midAxis, 5); line.color = Color(rand() % 255, rand() % 255, rand() % 255); sb.clear(); line.draw(sb); fb.draw(sb); } }
void CategoryPage::btOk_Click(Web::HttpConnector& h) { Sql::StringBuilder sb(L"category", L"category_id", category_id); sb.Bind(L"descr", tbxDescr); Sql::SqlConnection conn; int rows = 0; try { //conn.OpenSession(DSN, USERNAME, PASSWORD); //Control Panel>Administrative Tools>Data Sources (ODBC)>Create dsn_myDatabase conn.OpenSession(NULL, CONNECTION_STRING); rows = conn.ExecuteNonQuery(sb.GetString()); if (rows!=1) { this->MessageBox(Sys::Convert::ToString(rows), L"Error -number of rows", MB_OK | MB_ICONERROR); } } catch (Sql::SqlException e) { this->MessageBox(e.GetDescription(), L"Error", MB_OK | MB_ICONERROR); } h.NavigateTo(L"Index"); }
String IntentBindRecord::ToString() { if (!mStringName.IsNull()) { return mStringName; } StringBuilder sb(128); sb += "IntentBindRecord{"; sb += StringUtils::ToString(Int32(this), 16); sb += ' '; if ((CollectFlags()& IContext::BIND_AUTO_CREATE) != 0) { sb += "CR "; } sb += mService->mShortName; sb += ':'; if (mIntent != NULL) { AutoPtr<IIntent> intent; mIntent->GetIntent((IIntent**)&intent); intent->ToShortString(&sb, FALSE, FALSE, FALSE, FALSE); } sb += '}'; return mStringName = sb.ToString(); }
template< class T > T Correlation< T >::operator () (const vector < T > & a, const vector < T > & b) const { static char F_Name[] = "template< class T > T Correlation< T >::operator () (const vector < T > & a, const vector < T > & b) const"; if(a.size() != b.size()) { TKVPairList kvlist; kvlist.push_back(TKVPair("Size", a.size())); kvlist.push_back(TKVPair("Size", b.size())); throw IndexError(F_Name, kvlist); } T av_a, av_b, d_a, d_b, sp(0), sa(0), sb(0); av_a = average(a); av_b = average(b); for(unsigned i=0; i<a.size(); i++) { d_a = a[i] - av_a; d_b = b[i] - av_b; sp += d_a * d_b; sa += SQR(d_a); sb += SQR(d_b); } return sp / sqrt(sa * sb); }
int main(int, char**) { { char buf[10] = "123"; test sb(buf, 0, buf + 3); assert(sb.underflow() == '1'); assert(sb.underflow() == '1'); assert(sb.snextc() == '2'); assert(sb.underflow() == '2'); assert(sb.underflow() == '2'); assert(sb.snextc() == '3'); assert(sb.underflow() == '3'); assert(sb.underflow() == '3'); assert(sb.snextc() == EOF); assert(sb.underflow() == EOF); assert(sb.underflow() == EOF); sb.sputc('4'); assert(sb.underflow() == '4'); assert(sb.underflow() == '4'); } return 0; }
String BackupRecord::ToString() { if (!mStringName.IsNull()) { return mStringName; } StringBuilder sb(128); sb.Append("BackupRecord{"); sb.Append((Int32)this); // (Integer.toHexString(System.identityHashCode(this))) sb.AppendChar(' '); String pkgName; mAppInfo->GetPackageName(&pkgName); sb.Append(pkgName); sb.AppendChar(' '); String name; mAppInfo->GetName(&name); sb.Append(name); sb.AppendChar(' '); String bName; mAppInfo->GetBackupAgentName(&bName); sb.Append(bName); sb.AppendChar('}'); return mStringName = sb.ToString(); }
void Handle80211DataFromAP(const struct timeval& t, const data_hdr_t *hdr, const u_char *rest, int len) { if (opt_enforce_80211_frame_checksum && !fcs_ok) return; #ifdef DEBUG_WIFI cout << hdr->sa; cout << " " << "802.11 data from AP:\t" << hdr->sa << " -> " << hdr->da << "\t" << len << endl; #endif struct timeval tv; /* TK1: Does the pcap header make sense? */ /* TK2: How do we get and preserve the the three MAC addresses? */ printf("DATA_HDRLEN=%d DATA_WDS_HDRLEN=%d\n",DATA_HDRLEN,DATA_WDS_HDRLEN); sbuf_t sb(pos0_t(),rest,len,len,0); sb.hex_dump(std::cout); rest += 10; // where does 10 come from? len -= 10; be13::packet_info pi(DLT_IEEE802_11,(const pcap_pkthdr *)0,(const u_char *)0,tvshift(tv,t),rest,len); printf("pi.ip_version=%d\n",pi.ip_version()); process_packet_info(pi); }
//*********************************************************************************************** bool CParticleWorkspace::CNode::loadPS() { nlassert(_WS); // manually load the PS shape (so that we can deal with exceptions) NL3D::CShapeStream ss; NLMISC::CIFile inputFile; // collapse name inputFile.open(getFullPath()); ss.serial(inputFile); std::auto_ptr<NL3D::CShapeBank> sb(new NL3D::CShapeBank); std::string shapeName = NLMISC::CFile::getFilename(_RelativePath); sb->add(shapeName, ss.getShapePointer()); NL3D::CShapeBank *oldSB = NL3D::CNELU::Scene->getShapeBank(); NL3D::CNELU::Scene->setShapeBank(sb.get()); NL3D::CTransformShape *trs = NL3D::CNELU::Scene->createInstance(shapeName); if (!trs) { NL3D::CNELU::Scene->setShapeBank(oldSB); return false; } NL3D::CParticleSystemModel *psm = dynamic_cast<NL3D::CParticleSystemModel *>(trs); if (!psm) { // Not a particle system NL3D::CNELU::Scene->deleteInstance(trs); return false; } NL3D::CNELU::Scene->setShapeBank(oldSB); setup(*psm); unload(); // commit new values _PS = psm->getPS(); _PSM = psm; _ShapeBank = sb.release(); _Modified = false; return true; }
void testShapeGroup() { Util util; FrameBuffer fb; ShadowBuffer sb(fb.width, fb.height, 0, 0, fb.finfo.line_length); fb.backgroundColor = Color(0, 20, 30); sb.backgroundColor = Color(0, 20, 30); ShapeGroup indonesia("Peta"); for (int i = 0; i < 180; i++) { Point * tipPoints = indonesia.getTipPoints(); Point midAxis((tipPoints[0].x + tipPoints[1].x) / 2, (tipPoints[0].y + tipPoints[1].y) / 2, 0); indonesia.rotate(midAxis, 5); indonesia.scale(midAxis, 1.005, 1.005); for (int i = 0; i < indonesia.shapes.size(); i++) { indonesia.shapes[i].color = Color(rand() % 255, rand() % 255, rand() % 255); } sb.clear(); indonesia.draw(sb); fb.draw(sb); } }
int main(){ long n, m, W; scanf("%ld %ld %ld", &n, &m, &W); std::vector<long> w(n); for(long p = 0; p < n; p++){scanf("%ld", &w[p]);} std::vector<long> b(n); for(long p = 0; p < n; p++){scanf("%ld", &b[p]);} std::vector<std::vector<long> > g(n); for(long p = 0; p < m; p++){ long x, y; scanf("%ld %ld", &x, &y); --x; --y; g[x].push_back(y); g[y].push_back(x); } std::vector<long> head(n, -1); for(long p = 0; p < n; p++){dfs(p, g, head, p);} std::vector<long> sw(n, 0); std::vector<long> sb(n, 0); std::vector<std::vector<long> > sv(n); for(long p = 0; p < n; p++){sw[head[p]] += w[p]; sb[head[p]] += b[p]; sv[head[p]].push_back(p);} std::vector<long> f(W + 1, 0); for(long p = 0; p < n; p++){ if(head[p] != p){continue;} for(long ww = W; ww >= 0; ww--){ if(sw[p] <= ww){f[ww] = std::max(f[ww], f[ww - sw[p]] + sb[p]);} for(long t = 0; t < sv[p].size(); t++){ long u = sv[p][t]; if(w[u] <= ww){f[ww] = std::max(f[ww], f[ww - w[u]] + b[u]);} } } } printf("%ld\n", f[W]); return 0; }
void CCompressionStream::Create(CNcbiIos& stream, CCompressionStreamProcessor* read_sp, CCompressionStreamProcessor* write_sp, TOwnership ownership) { if ( m_Stream ) { // Already initialized, do nothing return; } // Initialize members m_Stream = &stream; m_Reader = read_sp; m_Writer = write_sp; m_Ownership = ownership; // Create a new stream buffer auto_ptr<CCompressionStreambuf> sb( new CCompressionStreambuf(&stream, read_sp, write_sp)); init(sb.get()); m_StreamBuf = sb.release(); if ( !m_StreamBuf->IsOkay() ) { setstate(badbit | eofbit); } }
void DynamicContentCache::store(const std::string &name, const char *data, int size) { assert(!name.empty()); assert(size > 0); ResourceFilePtr f(new ResourceFile()); CstrBufferPtr sb(new CstrBuffer(size)); sb->append(data, size); // makes a copy f->file = sb; int len = sb->size(); char *compressed = gzencode(sb->data(), len, 9, CODING_GZIP); if (compressed) { if (unsigned(len) < sb->size()) { f->compressed = CstrBufferPtr(new CstrBuffer(compressed, len)); } else { free(compressed); } } WriteLock lock(m_mutex); if (m_files.find(name) == m_files.end()) { m_files[name] = f; } }
// 与えられたスケーリングで曲面の変換を行いオブジェクトを生成する。 //Scaling. MGSBRep MGSBRep::operator* (double scale) const{ MGSBRep sb(*this); sb *=scale; return sb; }
void StaticContentCache::load() { Timer timer(Timer::WallTime, "loading static content"); if (!RuntimeOption::FileCache.empty()) { TheFileCache = FileCachePtr(new FileCache()); TheFileCache->load(RuntimeOption::FileCache.c_str()); Logger::Info("loaded file cache from %s", RuntimeOption::FileCache.c_str()); return; } int rootSize = RuntimeOption::SourceRoot.size(); if (rootSize == 0) return; // get a list of all files, one for each extension Logger::Info("searching all files under source root..."); int count = 0; map<string, vector<string> > ext2files; { const char *argv[] = {"", (char*)RuntimeOption::SourceRoot.c_str(), "-type", "f", NULL}; string files; vector<string> out; Process::Exec("find", argv, NULL, files); Util::split('\n', files.c_str(), out, true); for (unsigned int i = 0; i < out.size(); i++) { const string &name = out[i]; size_t pos = name.rfind('.'); if (pos != string::npos) { ext2files[name.substr(pos+1)].push_back(name); ++count; } } } Logger::Info("analyzing %d files under source root...", count); for (map<string, string>::const_iterator iter = RuntimeOption::StaticFileExtensions.begin(); iter != RuntimeOption::StaticFileExtensions.end(); ++iter) { if (ext2files.find(iter->first) == ext2files.end()) { continue; } const vector<string> &out = ext2files[iter->first]; int total = 0; for (unsigned int i = 0; i < out.size(); i++) { ResourceFilePtr f(new ResourceFile()); StringBufferPtr sb(new StringBuffer(out[i].c_str())); if (sb->valid() && sb->size() > 0) { string url = out[i].substr(rootSize + 1); f->file = sb; m_files[url] = f; // prepare gzipped content, skipping image and swf files if (iter->second.find("image/") != 0 && iter->first != "swf") { int len = sb->size(); char *data = gzencode(sb->data(), len, 9, CODING_GZIP); if (data) { if (len < sb->size()) { f->compressed = StringBufferPtr(new StringBuffer(data, len)); } else { free(data); } } } total += sb->size(); } } Logger::Info("..loaded %d bytes of %s files", total, iter->first.c_str()); m_totalSize += total; } Logger::Info("loaded %d bytes of static content in total", m_totalSize); }
TagsEditor::TagsEditor(wxWindow * parent, const wxString &title, Tags * tags, bool editTitle, bool editTrack) : wxDialogWrapper(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), mTags(tags), mEditTitle(editTitle), mEditTrack(editTrack) { SetName(GetTitle()); mGrid = NULL; // Make a local copy of the passed in tags mLocal = *mTags; // Build, size, and position the dialog ShuttleGui S(this, eIsCreating); PopulateOrExchange(S); TransferDataToWindow(); Layout(); Fit(); Center(); SetSizeHints(GetSize()); // Restore the original tags because TransferDataToWindow() will be called again mLocal.Clear(); mLocal = *mTags; // Override size and position with last saved wxRect r = GetRect(); gPrefs->Read(wxT("/TagsEditor/x"), &r.x, r.x); gPrefs->Read(wxT("/TagsEditor/y"), &r.y, r.y); gPrefs->Read(wxT("/TagsEditor/width"), &r.width, r.width); gPrefs->Read(wxT("/TagsEditor/height"), &r.height, r.height); //On multi-monitor systems, there's a chance the last saved window position is //on a monitor that has been removed or is unavailable. if (IsWindowRectValid(&r)) Move(r.GetPosition()); SetSize(r.GetSize()); Layout(); // Resize value column width based on width of columns and the vertical scrollbar wxScrollBar sb(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL); r = mGrid->GetClientRect(); r.width -= mGrid->GetColSize(0); r.width -= sb.GetSize().GetWidth(); r.width -= 10; r.width -= r.x; mGrid->SetColSize(1, r.width); //Bug 2038 mGrid->SetFocus(); // Load the genres PopulateGenres(); }
int main(int argc, char *argv[]) { XSqlQuery main; Q_INIT_RESOURCE(guiclient); QString username; QString databaseURL; QString passwd; bool haveUsername = FALSE; bool haveDatabaseURL = FALSE; bool loggedIn = FALSE; bool haveEnhancedAuth= false; bool _enhancedAuth = false; bool havePasswd = false; bool forceWelcomeStub= false; qInstallMsgHandler(xTupleMessageOutput); QApplication app(argc, argv); app.setOrganizationDomain("xTuple.com"); app.setOrganizationName("xTuple"); app.setApplicationName("xTuple"); app.setApplicationVersion(_Version); #if QT_VERSION >= 0x040400 // This is the correct place for this call but on versions less // than 4.4 it causes a crash for an unknown reason so it is // called later on earlier versions. QCoreApplication::addLibraryPath(QString(".")); #endif #ifndef Q_WS_MACX QApplication::setWindowIcon(QIcon(":/images/icon32x32.png")); #endif app.processEvents(); if (argc > 1) { for (int intCounter = 1; intCounter < argc; intCounter++) { QString argument(argv[intCounter]); if (argument.contains("-databaseURL=", Qt::CaseInsensitive)) { haveDatabaseURL = TRUE; databaseURL = argument.right(argument.length() - 13); } else if (argument.contains("-username="******"-passwd=", Qt::CaseInsensitive)) { havePasswd = TRUE; passwd = argument.right(argument.length() - 8); } else if (argument.contains("-noAuth", Qt::CaseInsensitive)) { haveUsername = TRUE; havePasswd = TRUE; } else if (argument.contains("-enhancedAuth", Qt::CaseInsensitive)) { haveEnhancedAuth = true; _enhancedAuth = true; if(argument.contains("=no", Qt::CaseInsensitive) || argument.contains("=false", Qt::CaseInsensitive)) _enhancedAuth = false; } else if (argument.contains("-forceWelcomeStub", Qt::CaseInsensitive)) forceWelcomeStub = true; } } // Try and load a default translation file and install it // otherwise if we are non-english inform the user that translation are available bool checkLanguage = false; QLocale sysl = QLocale::system(); QTranslator defaultTranslator(&app); if (defaultTranslator.load(translationFile(sysl.name().toLower(), "default"))) app.installTranslator(&defaultTranslator); else if(!xtsettingsValue("LanguageCheckIgnore", false).toBool() && sysl.language() != QLocale::C && sysl.language() != QLocale::English) checkLanguage = translationFile(sysl.name().toLower(), "xTuple").isNull(); if (forceWelcomeStub || checkLanguage) { QTranslator * translator = new QTranslator(&app); if (translator->load(translationFile(sysl.name().toLower(), "welcome/wmsg"))) app.installTranslator(translator); welcomeStub wsdlg; wsdlg.checkBox->setChecked(xtsettingsValue("LanguageCheckIgnore", false).toBool()); wsdlg.exec(); xtsettingsSetValue("LanguageCheckIgnore", wsdlg.checkBox->isChecked()); } _splash = new QSplashScreen(); _splash->setPixmap(QPixmap(":/images/splashEmpty.png")); _evaluation = FALSE; if (!loggedIn) { ParameterList params; params.append("copyright", _Copyright); params.append("version", _Version); params.append("build", _Build.arg(__DATE__).arg(__TIME__)); params.append("setSearchPath", true); if (haveUsername) params.append("username", username); if (havePasswd) params.append("password", passwd); if (haveDatabaseURL) params.append("databaseURL", databaseURL); if (haveEnhancedAuth) params.append("enhancedAuth", _enhancedAuth); if (_evaluation) params.append("evaluation"); if ( (haveDatabaseURL) && (haveUsername) && (havePasswd) ) params.append("login"); login2 newdlg(0, "", TRUE); newdlg.set(params, _splash); if(newdlg.result() != QDialog::Accepted) { if (newdlg.exec() == QDialog::Rejected) return -1; else { databaseURL = newdlg._databaseURL; username = newdlg.username(); __password = newdlg.password(); } } } // TODO: can/should we compose the splash screen on the fly from parts? QList<editionDesc> edition; edition << editionDesc( "Enterprise", ":/images/splashEnterprise.png", true, "SELECT fetchMetricText('Application') = 'Standard' AND COUNT(*) = 4" " FROM pkghead" " WHERE pkghead_name IN ('xtmfg', 'xtprjaccnt', 'asset', 'assetdepn');" ) << editionDesc( "Manufacturing", ":/images/splashMfgEdition.png", true, "SELECT fetchMetricText('Application') = 'Standard' AND COUNT(*) = 1" " FROM pkghead" " WHERE pkghead_name IN ('xtmfg');" ) << editionDesc( "Distribution", ":/images/splashDistEdition.png", true, "SELECT fetchMetricText('Application') = 'Standard';" ) << editionDesc( "PostBooks", ":/images/splashPostBooks.png", true, "SELECT fetchMetricText('Application') = 'PostBooks';" ) ; XSqlQuery metric; int editionIdx; // we'll use this after the loop for (editionIdx = 0; editionIdx < edition.size(); editionIdx++) { metric.exec(edition[editionIdx].queryString); if (metric.first() && metric.value(0).toBool()) break; } if (editionIdx >= edition.size()) editionIdx = edition.size(); // default to PostBooks _splash->setPixmap(QPixmap(edition[editionIdx].splashResource)); _Name = _Name.arg(edition[editionIdx].editionName); if (edition[editionIdx].shouldCheckLicense) { _splash->showMessage(QObject::tr("Checking License Key"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); // PostgreSQL changed the column "procpid" to just "pid" in 9.2.0+ Incident #21852 XSqlQuery checkVersion(QString("select compareversion('9.2.0');")); if(checkVersion.first()) { if(checkVersion.value("compareversion").toInt() > 0) { metric.exec("SELECT count(*) AS registered, (SELECT count(*) FROM pg_stat_activity WHERE datname=current_database()) AS total" " FROM pg_stat_activity, pg_locks" " WHERE((database=datid)" " AND (classid=datid)" " AND (objsubid=2)" " AND (procpid = pg_backend_pid()));"); } else { metric.exec("SELECT count(*) AS registered, (SELECT count(*) FROM pg_stat_activity WHERE datname=current_database()) AS total" " FROM pg_stat_activity, pg_locks" " WHERE((database=datid)" " AND (classid=datid)" " AND (objsubid=2)" " AND (pg_stat_activity.pid = pg_backend_pid()));"); } } int cnt = 50000; int tot = 50000; if(metric.first()) { cnt = metric.value("registered").toInt(); tot = metric.value("total").toInt(); } metric.exec("SELECT packageIsEnabled('drupaluserinfo') AS result;"); bool xtweb = false; if(metric.first()) xtweb = metric.value("result").toBool(); metric.exec("SELECT fetchMetricBool('ForceLicenseLimit') as metric_value;"); bool forceLimit = false; bool forced = false; if(metric.first()) forceLimit = metric.value("metric_value").toBool(); metric.exec("SELECT metric_value" " FROM metric" " WHERE(metric_name = 'RegistrationKey');"); bool checkPass = true; bool checkLock = false; bool expired = false; QString checkPassReason; QString rkey = ""; if(metric.first()) rkey = metric.value("metric_value").toString(); XTupleProductKey pkey(rkey); QString application; metric.exec("SELECT fetchMetricText('Application') as app;"); if(metric.first()) { application = metric.value("app").toString(); } if(pkey.valid() && (pkey.version() == 1 || pkey.version() == 2 || pkey.version() == 3)) { if(pkey.expiration() < QDate::currentDate()) { checkPass = false; checkPassReason = QObject::tr("<p>Your license has expired."); if(!pkey.perpetual()) { int daysTo = pkey.expiration().daysTo(QDate::currentDate()); if(daysTo > 30) { checkLock = true; expired = true; checkPassReason = QObject::tr("<p>Your xTuple license expired over 30 days ago, and this software will no longer function. Please contact xTuple immediately to reinstate your software."); } else checkPassReason = QObject::tr("<p>Attention: Your xTuple license has expired, and in %1 days this software will cease to function. Please make arrangements for immediate payment").arg(30 - daysTo); } else expired = true; } else if(application == "PostBooks" && pkey.users() == 1) { if(pkey.users() < cnt) { checkPass = false; checkPassReason = QObject::tr("<p>Multiple concurrent users of xTuple PostBooks require a license key. Please contact [email protected] to request a free license key for your local installation, or [email protected] to purchase additional users in the xTuple Cloud Service. <p>Thank you."); checkLock = forced = forceLimit; } } else if(pkey.users() != 0 && (pkey.users() < cnt || (!xtweb && (pkey.users() * 2 < tot)))) { checkPass = false; checkPassReason = QObject::tr("<p>You have exceeded the number of allowed concurrent users for your license."); checkLock = forced = forceLimit; } else { int daysTo = QDate::currentDate().daysTo(pkey.expiration()); if(!pkey.perpetual() && daysTo <= 15) { checkPass = false; checkPassReason = QObject::tr("<p>Please note: your xTuple license will expire in %1 days. You should already have received your renewal invoice; please contact xTuple at your earliest convenience.").arg(daysTo); } } } else { checkPass = false; checkPassReason = QObject::tr("<p>The Registration key installed for this system does not appear to be valid."); } if(!checkPass) { _splash->hide(); if (expired) { registrationKeyDialog newdlg(0, "", TRUE); if(newdlg.exec() == -1) { QMessageBox::critical(0, QObject::tr("Registration Key"), checkPassReason); return 0; } } else if(checkLock) { QMessageBox::critical(0, QObject::tr("Registration Key"), checkPassReason); if(!forced) return 0; } else { if(QMessageBox::critical(0, QObject::tr("Registration Key"), QObject::tr("%1\n<p>Would you like to continue anyway?").arg(checkPassReason), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) return 0; } if(forced) checkPassReason.append(" FORCED!"); metric.exec("SELECT current_database() AS db," " fetchMetricText('DatabaseName') AS dbname," " fetchMetricText('remitto_name') AS name;"); QString db = ""; QString dbname = ""; QString name = ""; if(metric.first()) { db = metric.value("db").toString(); dbname = metric.value("dbname").toString(); name = metric.value("name").toString(); } QHttp *http = new QHttp(); QUrl url; url.setPath("/api/regviolation.php"); url.addQueryItem("key", QUrl::toPercentEncoding(rkey)); url.addQueryItem("error", QUrl::toPercentEncoding(checkPassReason)); url.addQueryItem("name", QUrl::toPercentEncoding(name)); url.addQueryItem("dbname", QUrl::toPercentEncoding(dbname)); url.addQueryItem("db", QUrl::toPercentEncoding(db)); url.addQueryItem("cnt", QString::number(cnt)); url.addQueryItem("tot", QString::number(tot)); url.addQueryItem("ver", _Version); http->setHost("www.xtuple.org"); http->get(url.toString()); if(forced) return 0; _splash->show(); } } bool disallowMismatch = false; bool shouldCheckForUpdates = false; metric.exec("SELECT metric_value" " FROM metric" " WHERE (metric_name = 'ServerVersion')"); if (!metric.first() || (metric.value("metric_value").toString() != _dbVersion)) { int result = 0; metric.exec("SELECT metric_value FROM metric WHERE (metric_name = 'DisallowMismatchClientVersion')"); if (metric.first() && (metric.value("metric_value").toString() == "t")) { disallowMismatch = true; } metric.exec("SELECT metric_value FROM metric WHERE (metric_name = 'CheckForUpdates')"); if (metric.first()) { shouldCheckForUpdates = (metric.value("metric_value").toString() == "t" ? true : false); } if (shouldCheckForUpdates) { _splash->hide(); checkForUpdates newdlg(0,"", TRUE); result = newdlg.exec(); if (result == QDialog::Rejected) { return 0; } } else if (!shouldCheckForUpdates && disallowMismatch) { _splash->hide(); result = QMessageBox::warning( 0, QObject::tr("Version Mismatch"), QObject::tr("<p>The version of the database you are connecting to is " "not the version this client was designed to work against. " "This client was designed to work against the database " "version %1. The system has been configured to disallow " "access in this case.<p>Please contact your systems " "administrator.").arg(_Version), QMessageBox::Ok | QMessageBox::Escape | QMessageBox::Default ); return 0; } else { _splash->hide(); result = QMessageBox::warning( 0, QObject::tr("Version Mismatch"), QObject::tr("<p>The version of the database you are connecting to is " "not the version this client was designed to work against. " "This client was designed to work against the database " "version %1. If you continue some or all functionality may " "not work properly or at all. You may also cause other " "problems on the database.<p>Do you want to continue " "anyway?").arg(_Version), QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default ); if (result != QMessageBox::Yes) { return 0; } else { _splash->show(); } } } _splash->showMessage(QObject::tr("Loading Database Metrics"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); _metrics = new Metrics(); _splash->showMessage(QObject::tr("Loading User Preferences"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); _preferences = new Preferences(username); _splash->showMessage(QObject::tr("Loading User Privileges"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); _privileges = new Privileges(); // Load the translator and set the locale from the User's preferences _splash->showMessage(QObject::tr("Loading Translation Dictionary"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); XSqlQuery langq("SELECT * " "FROM usr, locale LEFT OUTER JOIN" " lang ON (locale_lang_id=lang_id) LEFT OUTER JOIN" " country ON (locale_country_id=country_id) " "WHERE ( (usr_username=getEffectiveXtUser())" " AND (usr_locale_id=locale_id) );" ); if (langq.first()) { QStringList files; if (!langq.value("locale_lang_file").toString().isEmpty()) files << langq.value("locale_lang_file").toString(); QString langext; if (!langq.value("lang_abbr2").toString().isEmpty() && !langq.value("country_abbr").toString().isEmpty()) { langext = langq.value("lang_abbr2").toString() + "_" + langq.value("country_abbr").toString().toLower(); } else if (!langq.value("lang_abbr2").toString().isEmpty()) { langext = langq.value("lang_abbr2").toString(); } if(!langext.isEmpty()) { files << "qt"; files << "xTuple"; files << "openrpt"; files << "reports"; XSqlQuery pkglist("SELECT pkghead_name" " FROM pkghead" " WHERE packageIsEnabled(pkghead_name);"); while(pkglist.next()) files << pkglist.value("pkghead_name").toString(); } if (files.size() > 0) { QStringList notfound; QTranslator *translator = new QTranslator(&app); for (QStringList::Iterator fit = files.begin(); fit != files.end(); ++fit) { if (DEBUG) qDebug("looking for %s", (*fit).toAscii().data()); if (translator->load(translationFile(langext, *fit))) { app.installTranslator(translator); qDebug("installed %s", (*fit).toAscii().data()); translator = new QTranslator(&app); } else { notfound << *fit; } } if (! notfound.isEmpty() && !_preferences->boolean("IngoreMissingTranslationFiles")) QMessageBox::warning( 0, QObject::tr("Cannot Load Dictionary"), QObject::tr("<p>The Translation Dictionaries %1 " "cannot be loaded. Reverting " "to the default dictionary." ) .arg(notfound.join(QObject::tr(", ")))); } /* set the locale to langabbr_countryabbr, langabbr, {lang# country#}, or lang#, depending on what information is available */ QString langAbbr = langq.value("lang_abbr2").toString(); QString cntryAbbr = langq.value("country_abbr").toString().toUpper(); if(cntryAbbr == "UK") cntryAbbr = "GB"; if (! langAbbr.isEmpty() && ! cntryAbbr.isEmpty()) QLocale::setDefault(QLocale(langAbbr + "_" + cntryAbbr)); else if (! langAbbr.isEmpty()) QLocale::setDefault(QLocale(langq.value("lang_abbr2").toString())); else if (langq.value("lang_qt_number").toInt() && langq.value("country_qt_number").toInt()) QLocale::setDefault( QLocale(QLocale::Language(langq.value("lang_qt_number").toInt()), QLocale::Country(langq.value("country_qt_number").toInt()))); else QLocale::setDefault(QLocale::system()); qDebug("Locale set to language %s and country %s", QLocale().languageToString(QLocale().language()).toAscii().data(), QLocale().countryToString(QLocale().country()).toAscii().data()); } else if (langq.lastError().type() != QSqlError::NoError) { systemError(0, langq.lastError().databaseText(), __FILE__, __LINE__); } qApp->processEvents(); QString key; // TODO: Add code to check a few locations - Hopefully done QString keypath; QString keyname; QString keytogether; #ifdef Q_WS_WIN keypath = _metrics->value("CCWinEncKey"); #elif defined Q_WS_MACX keypath = _metrics->value("CCMacEncKey"); #elif defined Q_WS_X11 keypath = _metrics->value("CCLinEncKey"); #endif if (keypath.isEmpty()) keypath = app.applicationDirPath(); if (! keypath.endsWith(QDir::separator())) keypath += QDir::separator(); keyname = _metrics->value("CCEncKeyName"); if (keyname.isEmpty()) { keyname = "xTuple.key"; keytogether = keypath + keyname; QFile kn(keytogether); if(!kn.exists()) keyname = "OpenMFG.key"; } keytogether = keypath + keyname; // qDebug("keytogether: %s", keytogether.toAscii().data()); QFile keyFile(keytogether); if(keyFile.exists()) { if(keyFile.open(QIODevice::ReadOnly)) { key = keyFile.readLine(1024); // strip off any newline characters key = key.trimmed(); } } omfgThis = 0; omfgThis = new GUIClient(databaseURL, username); omfgThis->_key = key; if (key.length() > 0) { _splash->showMessage(QObject::tr("Loading Database Encryption Metrics"), SplashTextAlignment, SplashTextColor); qApp->processEvents(); _metricsenc = new Metricsenc(key); } initializePlugin(_preferences, _metrics, _privileges, omfgThis->username(), omfgThis->workspace()); // START code for updating the locale settings if they haven't been already XSqlQuery lc; lc.exec("SELECT count(*) FROM metric WHERE metric_name='AutoUpdateLocaleHasRun';"); lc.first(); if(lc.value(0).toInt() == 0) { lc.exec("INSERT INTO metric (metric_name, metric_value) values('AutoUpdateLocaleHasRun', 't');"); lc.exec("SELECT locale_id from locale;"); while(lc.next()) { ParameterList params; params.append("mode","edit"); params.append("locale_id", lc.value(0)); sysLocale lcdlg; lcdlg.set(params); lcdlg.sSave(); } } // END code for updating locale settings QObject::connect(&app, SIGNAL(aboutToQuit()), &app, SLOT(closeAllWindows())); if (omfgThis->_singleWindow.isEmpty()) { omfgThis->setAttribute(Qt::WA_DeleteOnClose); omfgThis->show(); } // keep this synchronized with GUIClient and user.ui.h else if (omfgThis->_singleWindow == "woTimeClock") { ScriptToolbox sb(0); QWidget* newdlg = sb.openWindow("woTimeClock"); if(newdlg) { XMainWindow *mw = qobject_cast<XMainWindow*>(newdlg); if(mw) { ParameterList params; params.append("captive"); mw->set(params); } newdlg->setAttribute(Qt::WA_DeleteOnClose); QObject::connect(omfgThis, SIGNAL(destroyed(QObject*)), &app, SLOT(quit())); newdlg->show(); } else {
int exe(FILE* program) //program指向存有待执行程序机器码的文件 { char* tmp_instru=(char*)malloc(33*sizeof(char)); //读机器码 programTail=programHead; while(fscanf(program,"%s",tmp_instru)!=EOF) { instru=0; int i=0; unsigned j=1; for(i=31;i>=0;i--) { if(tmp_instru[i]=='1') { instru+=j; j*=2; } else { j*=2; } }//将机器码转为unsi unsigned char* tmp_R=&instru; for(i=0;i<4;i++) { writeMymemory(programTail+i,tmp_R+i);//装载指令 } programTail+=4;//最后一条指令的下一条指令的地址,用来判断程序是否执行完 } pcShort=programHead; pc=pcShort; while(pcShort!=programTail) { instru=0; //指令寄存器清零 unsigned char* tmp_R=&instru; unsigned short addr=addrToMyAddr(pc); int i; for(i=0;i<4;i++) { readMymemory(addr+i,tmp_R+i);//取指令 } unsigned tmp=instru>>26;//得到指令op //printf("the op is : %u\n",tmp); unsigned numRs=0,numRt=0,numRd=0,numFs=0,numFt=0,numFd=0,tmp_fuc=0; switch(tmp) { case 0x00000023: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=lw(pc); break; case 0x0000002B: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=sw(pc); break; case 0x00000008: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=addi(pc); break; case 0x00000009: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=addiu(pc); break; case 0x0000000A: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=slti(pc); break; case 0x0000000B: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=sltiu(pc); break; case 0x0000000C: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=andi(pc); break; case 0x0000000D: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=ori(pc); break; case 0x0000000E: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=xori(pc); break; case 0x00000024: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=lbu(pc); break; case 0x00000020: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=lb(pc); break; case 0x00000028: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=sb(pc); break; case 0x0000000F: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=lui(pc); break; case 0x00000004: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=beq(pc); break; case 0x00000005: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; //printf("%u,%u,%u,%u\n",numRt,numRs,*RS1,*RS2); lig=instru<<16>>16; // printf("%u\n",lig); pc=bne(pc); break; case 0x00000006: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=blez(pc); break; case 0x00000007: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=bgtz(pc); break; case 0x00000001: numRs=instru<<6>>27; numRt=instru<<11>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; lig=instru<<16>>16; pc=bltz(pc); break; case 0x00000002: pc=j(pc); break; case 0x00000003: pc=jal(pc); break; case 0x00000000: numRs=instru<<6>>27; numRt=instru<<11>>27; numRd=instru<<16>>27; RS1=myRegister+numRt; RS2=myRegister+numRs; RD=myRegister+numRd; tmp_fuc=instru%64; switch(tmp_fuc) { case 32: pc=add(pc); break; case 33: pc=addu(pc); break; case 34: pc=sub(pc); break; case 35: pc=subu(pc); break; case 24: pc=mul(pc); break; case 25: pc=mulu(pc); break; case 26: pc=myDiv(pc); break; case 27: pc=divu(pc); break; case 42: pc=slt(pc); break; case 43: pc=sltu(pc); break; case 36: pc=myAnd(pc); break; case 37: pc=myOr(pc); break; case 39: pc=nor(pc); break; case 40: pc=myXor(pc); break; case 8: pc=jr(pc); break; case 9: pc=jalr(pc); break; case 0: pc=nop(pc); break; case 16: pc=mfhi(pc); break; case 18: pc=mflo(pc); break; default: break; } break; case 0x00000010: numRt=instru<<11>>27; numRd=instru<<16>>27; RS1=myRegister+numRt; if(numRd==14) { pc=mfepc(pc); } else if(numRd==13) { pc=mfco(pc); } else return -1; break; case 0x00000031: numRs=instru<<6>>27; numFt=instru<<11>>27; RS2=myRegister+numRs; FS1=myFloatReg+numFt; lig=instru<<16>>16; pc=lwc1(pc); //printf("/********\nL.S %u %u\n****************/\n",numFt,numRs); break; case 0x0000001F: numRs=instru<<6>>27; numFt=instru<<11>>27; RS2=myRegister+numRs; FS1=myFloatReg+numFt; lig=instru<<16>>16; pc=S_D(pc); //printf("/********\nL.D %u %u\n****************/\n",numFt,numRs); break; case 0x0000001E: numRs=instru<<6>>27; numFt=instru<<11>>27; RS2=myRegister+numRs; FS1=myFloatReg+numFt; lig=instru<<16>>16; //printf("/********\nS.D %u %u\n****************/\n",numFt,numRs); pc=S_D(pc); break; case 0x00000039: numRs=instru<<6>>27; numFt=instru<<11>>27; RS2=myRegister+numRs; FS1=myFloatReg+numFt; lig=instru<<16>>16; //printf("/********\nS.S %u %u\n****************/\n",numFt,numRs); pc=swc1(pc); break; case 0x00000011: numFt=instru<<11>>27; numFs=instru<<16>>27; numFd=instru<<21>>27; FS1=myFloatReg+numFt; FS2=myFloatReg+numFs; FD=myFloatReg+numFd; numRs=instru<<6>>27; tmp_fuc=instru%64; //printf("%u %u\n",tmp_fuc,numRs); if(numRs==0) { switch(tmp_fuc) { case 0: pc=add_s(pc); break; case 1: pc=sub_s(pc); break; case 2: pc=mul_s(pc); case 3: pc=div_s(pc); default: break; } } else if(numRs==1) { switch(tmp_fuc) { case 0: pc=add_d(pc); //printf("/****************\nADD.D %u %u %u\n*****************/\n",numFd,numFt,numFs); break; case 1: pc=sub_d(pc); break; case 2: pc=mul_d(pc); case 3: pc=div_d(pc); default: break; } } default:break; } pcShort=pc%0x00010000; //printf("%u %u\n",pc,pcShort); //printf("%u %u\n",pcShort,programTail); } return 0; }
void _create_body_shape_data() { VisualServer *vs = VisualServer::get_singleton(); Physics2DServer *ps = Physics2DServer::get_singleton(); // SEGMENT { DVector<uint8_t> pixels; pixels.resize(32*2*2); for(int i=0;i<2;i++) { for(int j=0;j<32;j++) { pixels.set(i*32*2+j*2+0,(j==0)?255:0); pixels.set(i*32*2+j*2+1,255); } } Image image(32,2,0,Image::FORMAT_LA8,pixels); body_shape_data[Physics2DServer::SHAPE_SEGMENT].image=vs->texture_create_from_image(image); RID segment_shape = ps->shape_create(Physics2DServer::SHAPE_SEGMENT); Rect2 sg(Point2(-16,0),Point2(16,0)); ps->shape_set_data(segment_shape,sg); body_shape_data[Physics2DServer::SHAPE_SEGMENT].shape = segment_shape; } // CIRCLE { DVector<uint8_t> pixels; pixels.resize(32*32*2); for(int i=0;i<32;i++) { for(int j=0;j<32;j++) { bool black=Vector2(i-16,j-16).length_squared() < 16*16; pixels.set(i*32*2+j*2+0,(i==16 || j==16)?255:0); pixels.set(i*32*2+j*2+1,black?255:0); } } Image image(32,32,0,Image::FORMAT_LA8,pixels); body_shape_data[Physics2DServer::SHAPE_CIRCLE].image=vs->texture_create_from_image(image); RID circle_shape = ps->shape_create(Physics2DServer::SHAPE_CIRCLE); ps->shape_set_data(circle_shape,16); body_shape_data[Physics2DServer::SHAPE_CIRCLE].shape = circle_shape; } // BOX { DVector<uint8_t> pixels; pixels.resize(32*32*2); for(int i=0;i<32;i++) { for(int j=0;j<32;j++) { bool black=i>0 && i<31 && j>0 && j<31; pixels.set(i*32*2+j*2+0,black?0:255); pixels.set(i*32*2+j*2+1,255); } } Image image(32,32,0,Image::FORMAT_LA8,pixels); body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image=vs->texture_create_from_image(image); RID rectangle_shape = ps->shape_create(Physics2DServer::SHAPE_RECTANGLE); ps->shape_set_data(rectangle_shape,Vector2(16,16)); body_shape_data[Physics2DServer::SHAPE_RECTANGLE].shape = rectangle_shape; } // CAPSULE { DVector<uint8_t> pixels; pixels.resize(32*64*2); for(int i=0;i<64;i++) { for(int j=0;j<32;j++) { int si = i>48 ? i - 32 : (i<16 ? i : 16); bool black=Vector2(si-16,j-16).length_squared() < 16*16; pixels.set(i*32*2+j*2+0,(i==16 || j==16 || i==48)?255:0); pixels.set(i*32*2+j*2+1,black?255:0); } } Image image(32,64,0,Image::FORMAT_LA8,pixels); body_shape_data[Physics2DServer::SHAPE_CAPSULE].image=vs->texture_create_from_image(image); RID capsule_shape = ps->shape_create(Physics2DServer::SHAPE_CAPSULE); ps->shape_set_data(capsule_shape,Vector2(16,32)); body_shape_data[Physics2DServer::SHAPE_CAPSULE].shape = capsule_shape; } // CONVEX { Image image(convex_png); body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].image=vs->texture_create_from_image(image); RID convex_polygon_shape = ps->shape_create(Physics2DServer::SHAPE_CONVEX_POLYGON); DVector<Vector2> arr; Point2 sb(32,32); arr.push_back(Point2(20,3)-sb); arr.push_back(Point2(58,23)-sb); arr.push_back(Point2(55,54)-sb); arr.push_back(Point2(27,60)-sb); arr.push_back(Point2(5,56)-sb); arr.push_back(Point2(4,20)-sb); arr.push_back(Point2(11,7)-sb); ps->shape_set_data(convex_polygon_shape,arr); body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].shape = convex_polygon_shape; } }
void ShowTip() { Lock(); if( !IsHidden() ) Hide(); //if( !IsMinimized() ) Minimize(true); delete fRunner; fRunner = 0; delete fAnim; fAnim = 0; printf("Start show with %ld children\n", CountChildren()); if( fTip ) { fTip->RemoveSelf(); delete fTip; fTip = 0; } printf("Now have %ld children\n", CountChildren()); delete fBackPic; fBackPic = 0; delete fForePic; fForePic = 0; delete fMixPic; fMixPic = 0; fTip = new TipView(Bounds(), "TipView"); float w, h; fTip->GetPreferredSize(&w, &h); ResizeTo(w, h); fTip->ResizeTo(w, h); BScreen s(this); BRect sb(s.Frame()); float x = floor(sb.left + (sb.right-w)*drand48() + .5); float y = floor(sb.top + (sb.bottom-h)*drand48() + .5); MoveTo(x, y); fRunner = new BMessageRunner(BMessenger(this), new BMessage('puls'), (bigtime_t)(5*1000*1000*drand48())); BRect bbnd(Bounds()); bbnd.bottom++; BRect wfrm(Frame()); //printf("Getting screen bitmap frame "); wfrm.PrintToStream(); fBackPic = new BBitmap(bbnd, 0, s.ColorSpace(), B_ANY_BYTES_PER_ROW, s.ID()); s.ReadBitmap(fBackPic, false, &wfrm); //s.GetBitmap(&fBackPic, false, &wfrm); if( !fBackPic ) { printf("*** ERROR GETTING SCREEN BITMAP.\n"); Show(); //Minimize(false); return; } fCurAlpha = 0.0; fDestAlpha = 1.0; fForePic = new BBitmap(bbnd, B_BITMAP_CLEAR_TO_WHITE|B_BITMAP_ACCEPTS_VIEWS, fBackPic->ColorSpace(), B_ANY_BYTES_PER_ROW, s.ID()); fForePic->Lock(); fForePic->AddChild(fTip); fTip->PushState(); fTip->Draw(fTip->Bounds()); fTip->PopState(); fTip->Sync(); fTip->RemoveSelf(); fForePic->Unlock(); fMixPic = new BBitmap(bbnd, 0, fBackPic->ColorSpace(), B_ANY_BYTES_PER_ROW, s.ID()); fAnim = new BMessageRunner(BMessenger(this), new BMessage('anim'), 50*1000); Show(); Minimize(false); Unlock(); }