void SetTransform(const btTransform& aT, VectorMap<void*, int>& set){ if (set.Find(mSelf) != set.end()) return; mSelf->setWorldTransform(aT); mSelf->clearForces(); set[mSelf] = 1; if (mGameFlag != 0) Logger::Log(FB_DEFAULT_LOG_ARG, FormatString("(info) Setting rigid body transform for %d", mGameFlag).c_str()); auto numConstraints = mSelf->getNumConstraintRefs(); for (int i = 0; i < numConstraints; ++i){ auto con = mSelf->getConstraintRef(i); auto conType = con->getConstraintType(); if (conType == FIXED_CONSTRAINT_TYPE || conType == D6_SPRING_2_CONSTRAINT_TYPE){ btFixedConstraint* fixedCon = (btFixedConstraint*)con; auto a = &con->getRigidBodyA(); auto b = &con->getRigidBodyB(); auto trA = fixedCon->getFrameOffsetA(); auto trB = fixedCon->getFrameOffsetB(); if (b->getUserPointer() == mSelf){ std::swap(a, b); std::swap(trA, trB); } auto bT = aT * trA * trB.inverse(); auto rigidBodyImpl = (RigidBodyImpl*)b->getUserPointer(); rigidBodyImpl->mImpl->SetTransform(bT, set); } } mSelf->activate(); }
int GetClipboardFormatCode(const char *format_id) { GuiLock ___; int x = (int)(intptr_t)format_id; if(x >= 0 && x < 65535) return x; String fmt = format_id; if(fmt == "text") return CF_TEXT; if(fmt == "wtext") return CF_UNICODETEXT; if(fmt == "dib") return CF_DIB; if(fmt == "files") return CF_HDROP; static StaticMutex m; Mutex::Lock __(m); static VectorMap<String, int> format_map; int f = format_map.Find(format_id); if(f < 0) { f = format_map.GetCount(); format_map.Add(format_id, #ifdef PLATFORM_WINCE ::RegisterClipboardFormat(ToSystemCharset(format_id)) #else ::RegisterClipboardFormat(format_id) #endif ); } return format_map[f]; }
void Themed::ReadTheme() { int q = theme.Find(ToLower(GetClass())); if(q < 0) return; ClassTheme& cm = theme[q]; ThemeProperties tm(cm.data.property, cm.data.image, true); Properties(tm); Ctrl *p = dynamic_cast<Ctrl *>(this); if(p) for(Ctrl *q = p->GetFirstChild(); q; q = q->GetNext()) { Themed *t = dynamic_cast<Themed *>(q); if(t) { int i = cm.child.Find(t->GetClass()); if(i >= 0) { ThemeProperties tm(cm.child[i].property, cm.child[i].image, true); t->Properties(tm); } i = cm.child.Find(t->id); if(i >= 0) { q->SetPos(cm.child[i].pos); ThemeProperties tm(cm.child[i].property, cm.child[i].image, true); t->Properties(tm); } } } }
PPMacro *FindPPMacro(const String& id, Index<int>& segment_id, int& segmenti) { Index<int> undef; PPMacro *r; int best; for(int pass = 0; pass < 2; pass++) { r = NULL; best = segmenti; int line = -1; int q = sAllMacros.Find(id); while(q >= 0) { PPMacro& m = sAllMacros[q]; if(m.macro.IsUndef()) { if(pass == 0 && segment_id.Find(m.segment_id) >= 0) undef.FindAdd(m.segment_id); // cancel out undefined macro... } else if(pass == 0 || m.segment_id == 0 || undef.Find(m.undef_segment_id) < 0) { int si = m.segment_id == 0 ? INT_MAX : segment_id.Find(m.segment_id); // defs macros always override if(si > best || si >= 0 && si == best && m.line > line) { best = si; line = m.line; r = &m; } } q = sAllMacros.FindNext(q); } if(undef.GetCount() == 0) break; } segmenti = best; return r; }
Time GetFileTimeCached(const String& p) { LTIMING("GetFileTimeCached"); int q = sPathFileTime.Find(p); if(q >= 0) return sPathFileTime[q]; Time m = FileGetTime(p); sPathFileTime.Put(p, m); return m; }
void MarkChanged(const VectorMap<String, String>& m, ArrayCtrl& data) { GuiLock __; for(int i = 0; i < data.GetCount(); i++) { int q = m.Find(data.Get(i, 0)); if(q >= 0 && m[q] != data.Get(i, 1)) data.SetDisplay(i, 1, Single<RedDisplay>()); else data.SetDisplay(i, 1, StdDisplay()); } }
String DnDLoop::GetData(const String& f) { GuiLock __; int i = data->Find(f); String d; if(i >= 0) d = (*data)[i].Render(); else if(sDnDSource) d = sDnDSource->GetDropData(f); return d; }
virtual bool operator()(int pos, const RichPara& para) { for(int i = 0; i < para.GetCount(); i++) { String l = para[i].format.link; if(!IsNull(l)) { if(l[0] == ':') { int q = reflink->Find(l); int w = q; if(q < 0) q = reflink->Find(l + "::class"); if(q < 0) q = reflink->Find(l + "::struct"); if(q < 0) q = reflink->Find(l + "::union"); if(q >= 0) l = (*reflink)[q]; } link.FindAdd(Nvl(reflink->Get(l, Null), l)); } } return false; }
ShaderPtr GetShader(int ResourceTypes_Shaders){ auto it = mShaders.Find(ResourceTypes_Shaders); if (it == mShaders.end()){ auto shader = CreateShader(ResourceTypes_Shaders); if (!shader){ Logger::Log(FB_ERROR_LOG_ARG, FormatString("Resource Provider - Failed to create the shader (%d)", ResourceTypes_Shaders).c_str()); return 0; } mShaders[ResourceTypes_Shaders] = shader; return shader; } return it->second; }
String GetIncludePath(const String& s, const String& filedir) { LTIMING("GetIncludePath"); String key; key << s << "#" << filedir; int q = sIncludePath.Find(key); if(q >= 0) return sIncludePath[q]; LTIMING("GetIncludePath 2"); String p = GetIncludePath0(s, filedir); sIncludePath.Add(key, p); LLOG("GetIncludePath " << s << " " << filedir << ": " << p); return p; }
SamplerStatePtr GetSamplerState(int ResourceTypes_SamplerStates){ auto it = mSamplerStates.Find(ResourceTypes_SamplerStates); if (it == mSamplerStates.end()){ auto state = CreateSamplerState(ResourceTypes_SamplerStates); if (!state){ Logger::Log(FB_ERROR_LOG_ARG, "Resource Provider - Failed to create a depth stencil state(%d)", ResourceTypes_SamplerStates); return 0; } mSamplerStates[ResourceTypes_SamplerStates] = state; return state; } return it->second; }
BlendStatePtr GetBlendState(int ResourceTypes_BlendStates){ auto it = mBlendStates.Find(ResourceTypes_BlendStates); if (it == mBlendStates.end()){ auto state = CreateBlendState(ResourceTypes_BlendStates); if (!state){ Logger::Log(FB_ERROR_LOG_ARG, "Resource Provider - Failed to create a rasterizer state(%d)", ResourceTypes_BlendStates); return 0; } mBlendStates[ResourceTypes_BlendStates] = state; return state; } return it->second; }
MaterialPtr GetMaterial(int ResourceTypes_Materials){ auto it = mMaterials.Find(ResourceTypes_Materials); if (it == mMaterials.end()){ auto material = CreateMaterial(ResourceTypes_Materials); if (!material){ Logger::Log(FB_ERROR_LOG_ARG, "Resource Provider - Failed to create a material(%d)", ResourceTypes_Materials); return 0; } mMaterials[ResourceTypes_Materials] = material; return material; } return it->second; }
TexturePtr GetTexture(int ResourceTypes_Textures, int index){ auto it = mTextures.Find(ResourceTypes_Textures); if (it == mTextures.end() || index >= (int)it->second.size()){ auto textures = CreateTexture(ResourceTypes_Textures); mTextures[ResourceTypes_Textures] = textures; if (index < (int)textures.size()){ return textures[index]; } } else{ if (index < (int)it->second.size()) return it->second[index]; } return 0; }
Value Pdb::Vis(const String& key, const VectorMap<String, Value>& prev, Visual rval_ vis, bool& ch) { int q = prev.Find(key); ch = false; for(int i = 0; i < vis.part.GetCount(); i++) { VisualPart& p = vis.part[i]; p.mark = false; if(q >= 0 && IsType<Visual>(prev[q])) { const Visual& v = ValueTo<Visual>(prev[q]); if(v.part.GetCount() == vis.part.GetCount() && v.part[i].text != p.text) ch = p.mark = true; } } return RawPickToValue(vis); }
void MainDlg::OnLanguage(Bar& bar ) { const int* languages = GetAllLanguages(); // We have a tremendous amount of redundancy here... we'll use this as a filter. // Note that sometimes, the number changes, but it still comes up as 'English'. // This is perhaps because we don't have any translations for the other languages. VectorMap< String, int > oldLangs; for (int i = 0; languages[i] != 0; i++ ) { String langName = ::GetNativeLangName( languages[ i ] ); if ( oldLangs.Find( langName ) < 0 ) { bar.Add( langName , THISBACK1( OnChangeLanguage, languages[i] ) ); oldLangs.Add( langName, languages[i] ); } } }
/// returns true, when playable /// should be called after the position for this audioex has set. /// Audio Thread + Main Thread bool CheckSimultaneous(){ if (mFilePathKey.empty()) return true; if (mProperty.mNumSimultaneous == 0) return true; VectorMap< std::string, std::vector<AudioExWeakPtr>>::iterator audioListIt; { READ_LOCK l(sAudioExListLock); audioListIt = sAudioExList.Find(mFilePathKey); if (audioListIt == sAudioExList.end()) return true; } std::vector<AudioExPtr> audioExesInRange; audioExesInRange.reserve(10); auto& audioList = audioListIt->second; float rangeSQ = mProperty.mSimultaneousCheckRange * mProperty.mSimultaneousCheckRange; // gather audioList in range for (auto it = audioList.begin(); it != audioList.end(); /**/){ IteratingWeakContainer(audioList, it, audio); if (!audio->IsPlaying()) continue; if (mProperty.mSimultaneousCheckRange == 0.f){ audioExesInRange.push_back(audio); } else{ // check distance const auto& position = audio->GetPosition(); auto distSq = GetDistanceSQBetween(position, mProperty.mPosition); if (distSq <= rangeSQ){ audioExesInRange.push_back(audio); } } } if (audioExesInRange.size() < mProperty.mNumSimultaneous) return true; return false; }
//---------------------------------------------------------------------------- Ray3 ScreenPosToRay(long x, long y) { Update(); auto it = mRayCache.Find(Vec2I(x, y)); if (it != mRayCache.end()){ return it->second; } Real fx = 2.0f * x / GetWidth() - 1.0f; Real fy = 1.0f - 2.0f * y / GetHeight(); Vec3 screenPos((Real)fx, (Real)fy, -1.0f); Vec3 screenMidPos((Real)fx, (Real)fy, 0.0f); Vec3 origin = mMatrices[InverseViewProj]* screenPos; Vec3 target = mMatrices[InverseViewProj] * screenMidPos; Vec3 dir = target - origin; dir.Normalize(); Ray3 ray(mTransformation.GetTranslation(), dir); mRayCache[Vec2I(x, y)] = ray; return ray; }
void PreRender(const RenderParam& renderParam, RenderParamOut* renderParamOut){ mRenderPass = (RENDER_PASS)renderParam.mRenderPass; if (!mSkipSpatialObjects) { auto cam = renderParam.mCamera; assert(cam); auto it = mLastPreRenderFramePerCam.Find(cam); if (it != mLastPreRenderFramePerCam.end() && it->second == gpTimer->GetFrame()) return; mLastPreRenderFramePerCam[cam] = gpTimer->GetFrame(); MakeVisibleSet(renderParam, renderParamOut); auto objIt = mPreRenderList[cam].begin(), objItEnd = mPreRenderList[cam].end(); for (; objIt != objItEnd; objIt++) { // Only objects that have a valid renderable is in the render lists. (*objIt)->PreRender(renderParam, renderParamOut); } } if (mSkyRendering) { if (mSkySphere) { mSkySphere->PreRender(renderParam, renderParamOut); } } for (auto it = mObjects.begin(); it != mObjects.end(); /**/){ auto obj = it->lock(); if (!obj){ it = mObjects.erase(it); continue; } ++it; obj->PreRender(renderParam, renderParamOut); } }
void CodeBrowser::LoadScope() { String find = ToUpper((String)~search); Value key = item.GetKey(); int sc = item.GetCursorSc(); item.Clear(); if(!scope.IsCursor()) return; Value x = scope.Get(2); int file = IsNumber(x) ? (int)x : -1; String scope = file < 0 ? String(x) : String(); int q = CodeBase().Find(scope); bool filematch = file >= 0 && MatchCib(GetFileText(GetSourceFilePath(file)), find); bool scopematch = !filematch && MatchCib(scope, find); if(q >= 0) { const Array<CppItem>& n = CodeBase()[q]; VectorMap<String, bool> inherited; if(file < 0) GatherMethods(scope, inherited, false); Index<String> set; for(int i = 0; i < n.GetCount(); i++) { CppItemInfo m; (CppItem&) m = n[i]; if((find.GetCount() && m.uname.StartsWith(find) || filematch && m.file == file || scopematch) && set.Find(m.qitem) < 0) { set.Add(m.qitem); int q = inherited.Find(m.qitem); if(q >= 0) { m.over = true; m.virt = m.virt || inherited[q]; } item.Add(m.qitem, RawToValue(m)); } } } item.Sort(1, sort ? ItemCompareLexical : ItemCompare); if(item.FindSetCursor(key)) item.ScCursor(sc); // clear.Enable(IsSearch()); }
PackageInfo GetPackageInfo(const String& name) { String path = PackagePath(name); Time tm = FileGetTime(path); int q = sPi.Find(name); if(q >= 0) { if(path == sPi[q].path && tm == sPi[q].stamp) return sPi[q]; } else { q = sPi.GetCount(); sPi.Add(name); } PackageInfo& pi = sPi[q]; pi.path = path; pi.stamp = tm; Package p; p.Load(path); pi.ink = p.ink; pi.italic = p.italic; pi.bold = p.bold; return pi; }
void ExtToMime::Load(const char *fn) { FileIn in(fn); if(in) while(!in.IsEof()) { String ln = TrimLeft(TrimRight(in.GetLine())); if(ln[0] != '#') { int q = ln.Find(':'); if(q >= 0) { String h = ln.Mid(0, q); int w = h.Find('/'); if(w >= 0) { int x = ln.Find("*.", q); if(x >= 0) { String ext = ln.Mid(x + 2); if(ext.GetCount() && map.Find(ext) < 0) map.Add(ext, MAKELONG(minor.FindAdd(h.Mid(w + 1)), major.FindAdd(h.Mid(0, w)))); } } } } } }
bool Speller::CheckOld(const WString& wstr) const { int len = wstr.GetLength(); if(len == 1) return true; if(len < 64) { String w = FromUnicode(wstr, charset); String wl = FromUnicode(ToLower(wstr), charset); int i; if(len == 2) { w.Cat(127); wl.Cat(127); } i = line.Find(ToLower(wl[0], charset) + (ToLower(wl[1], charset) << 8) + (ToLower(wl[2], charset) << 16)); if(i >= 0) { const byte *s = line[i].begin; const byte *e = line[i].end; String q; while(s < e) if(*s < dict) { if(q == w || q == wl) return true; q.Trim(*s++); } else { ASSERT(*s >= dict); const char *x = voc[(int)*s++ - dict]; q.Cat(x); } if(q == w || q == wl) return true; } } return user.Find(wstr) >= 0;; }
void GetAllMacros(Md5Stream& md5, const String& id, Index<int>& segment_id) { Vector< Tuple2<int, int> > pos; Vector<const CppMacro *> def; String r; int q = sAllMacros.Find(id); while(q >= 0) { const PPMacro& m = sAllMacros[q]; int si = segment_id.Find(m.segment_id); if(si >= 0) { pos.Add(MakeTuple(si, m.line)); def.Add(&m.macro); } q = sAllMacros.FindNext(q); } IndexSort(pos, def); int n = def.GetCount(); if(n) { md5.Put(&n, sizeof(int)); md5.Put(id); for(int i = 0; i < n; i++) md5.Put(def[i]->md5, 16); } }
void InvalidatePackageInfo(const String& name) { int q = sPi.Find(name); if(q >= 0) sPi[q].path.Clear(); }
void DeleteTexture(int ResourceTypes_Textures){ auto it = mTextures.Find(ResourceTypes_Textures); if (it != mTextures.end()) mTextures.erase(it); }
void DeleteShader(int ResourceTypes_Shaders){ auto it = mShaders.Find(ResourceTypes_Shaders); if (it != mShaders.end()) mShaders.erase(it); }