public override bool TryResolve(FailMode failReportMode) { failReportMode = FailMode.LogErrors; bool flag = typeof(Def).IsAssignableFrom(typeof(K)); bool flag2 = typeof(Def).IsAssignableFrom(typeof(V)); List <Pair <K, V> > list = new List <Pair <K, V> >(); foreach (XmlNode wantedDictRef in this.wantedDictRefs) { XmlNode xmlNode = wantedDictRef["key"]; XmlNode xmlNode2 = wantedDictRef["value"]; K first = (!flag) ? DirectXmlToObject.ObjectFromXml <K>(xmlNode, true) : DirectXmlCrossRefLoader.TryResolveDef <K>(xmlNode.InnerText, failReportMode); V second = (!flag2) ? DirectXmlToObject.ObjectFromXml <V>(xmlNode2, true) : DirectXmlCrossRefLoader.TryResolveDef <V>(xmlNode2.InnerText, failReportMode); list.Add(new Pair <K, V>(first, second)); } Dictionary <K, V> dictionary = (Dictionary <K, V>)base.wanter; dictionary.Clear(); foreach (Pair <K, V> item in list) { try { dictionary.Add(item.First, item.Second); } catch { Log.Error("Failed to load key/value pair: " + item.First + ", " + item.Second); } } return(true); }
public static T TryResolveDef <T>(string defName, FailMode failReportMode, object debugWanterInfo = null) { T t = (T)((object)GenDefDatabase.GetDefSilentFail(typeof(T), defName, true)); if (t != null) { return(t); } if (failReportMode == FailMode.LogErrors) { string text = string.Concat(new object[] { "Could not resolve cross-reference to ", typeof(T), " named ", defName }); if (debugWanterInfo != null) { text = text + " (wanter=" + debugWanterInfo.ToStringSafe <object>() + ")"; } Log.Error(text, false); } return(default(T)); }
public override bool TryResolve(FailMode failReportMode) { if (this.fi == null) { Log.Error("Trying to resolve null field for def named " + this.defName.ToStringSafe()); return(false); } Def defSilentFail = GenDefDatabase.GetDefSilentFail(this.fi.FieldType, this.defName); if (defSilentFail == null) { if (failReportMode == FailMode.LogErrors) { Log.Error("Could not resolve cross-reference: No " + this.fi.FieldType + " named " + this.defName.ToStringSafe() + " found to give to " + base.wanter.GetType() + " " + base.wanter.ToStringSafe()); } return(false); } SoundDef soundDef = defSilentFail as SoundDef; if (soundDef != null && soundDef.isUndefined) { Log.Warning("Could not resolve cross-reference: No " + this.fi.FieldType + " named " + this.defName.ToStringSafe() + " found to give to " + base.wanter.GetType() + " " + base.wanter.ToStringSafe() + " (using undefined sound instead)"); } this.fi.SetValue(base.wanter, defSilentFail); return(true); }
public override bool TryResolve(FailMode failReportMode) { if (fi == null) { Log.Error("Trying to resolve null field for def named " + defName.ToStringSafe()); return(false); } Type type = overrideFieldType ?? fi.FieldType; resolvedDef = GenDefDatabase.GetDefSilentFail(type, defName); if (resolvedDef == null) { if (failReportMode == FailMode.LogErrors && !BadCrossRefAllowed) { Log.Error(string.Concat("Could not resolve cross-reference: No ", type, " named ", defName.ToStringSafe(), " found to give to ", wanter.GetType(), " ", wanter.ToStringSafe())); } return(false); } SoundDef soundDef = resolvedDef as SoundDef; if (soundDef != null && soundDef.isUndefined) { Log.Warning(string.Concat("Could not resolve cross-reference: No ", type, " named ", defName.ToStringSafe(), " found to give to ", wanter.GetType(), " ", wanter.ToStringSafe(), " (using undefined sound instead)")); } fi.SetValue(wanter, resolvedDef); return(true); }
public static T TryResolveDef <T>(string defName, FailMode failReportMode, object debugWanterInfo = null) { DeepProfiler.Start("TryResolveDef"); try { T val = (T)(object)GenDefDatabase.GetDefSilentFail(typeof(T), defName); if (val != null) { return(val); } if (failReportMode == FailMode.LogErrors) { string text = string.Concat("Could not resolve cross-reference to ", typeof(T), " named ", defName); if (debugWanterInfo != null) { text = text + " (wanter=" + debugWanterInfo.ToStringSafe() + ")"; } Log.Error(text); } return(default(T)); } finally { DeepProfiler.End(); } }
public static void ResolveAllWantedCrossReferences(FailMode failReportMode) { DeepProfiler.Start("ResolveAllWantedCrossReferences"); try { HashSet <WantedRef> resolvedRefs = new HashSet <WantedRef>(); object resolvedRefsLock = new object(); DeepProfiler.enabled = false; GenThreading.ParallelForEach(wantedRefs, delegate(WantedRef wantedRef) { if (wantedRef.TryResolve(failReportMode)) { lock (resolvedRefsLock) { resolvedRefs.Add(wantedRef); } } }); foreach (WantedRef item in resolvedRefs) { item.Apply(); } wantedRefs.RemoveAll((WantedRef x) => resolvedRefs.Contains(x)); DeepProfiler.enabled = true; } finally { DeepProfiler.End(); } }
public override bool TryResolve(FailMode failReportMode) { bool flag = false; for (int i = 0; i < defNames.Count; i++) { bool flag2 = mayRequireMods != null && i < mayRequireMods.Count && !mayRequireMods[i].NullOrEmpty() && !ModsConfig.IsActive(mayRequireMods[i]); T val = TryResolveDef <T>(defNames[i], (!flag2) ? failReportMode : FailMode.Silent, debugWanterInfo); if (val != null) { ((List <T>)wanter).Add(val); defNames.RemoveAt(i); if (mayRequireMods != null && i < mayRequireMods.Count) { mayRequireMods.RemoveAt(i); } i--; } else { flag = true; } } return(!flag); }
public static void ResolveAllWantedCrossReferences(FailMode failReportMode) { foreach (WantedRef item in DirectXmlCrossRefLoader.wantedRefs.ListFullCopy()) { if (item.TryResolve(failReportMode)) { DirectXmlCrossRefLoader.wantedRefs.Remove(item); } } }
public static void ResolveAllWantedCrossReferences(FailMode failReportMode) { foreach (DirectXmlCrossRefLoader.WantedRef wantedRef in DirectXmlCrossRefLoader.wantedRefs.ListFullCopy <DirectXmlCrossRefLoader.WantedRef>()) { if (wantedRef.TryResolve(failReportMode)) { DirectXmlCrossRefLoader.wantedRefs.Remove(wantedRef); } } }
public override bool TryResolve(FailMode failReportMode) { bool result; if (this.fi == null) { Log.Error("Trying to resolve null field for def named " + this.defName.ToStringSafe <string>(), false); result = false; } else { Def defSilentFail = GenDefDatabase.GetDefSilentFail(this.fi.FieldType, this.defName, true); if (defSilentFail == null) { if (failReportMode == FailMode.LogErrors) { Log.Error(string.Concat(new object[] { "Could not resolve cross-reference: No ", this.fi.FieldType, " named ", this.defName.ToStringSafe <string>(), " found to give to ", this.wanter.GetType(), " ", this.wanter.ToStringSafe <object>() }), false); } result = false; } else { SoundDef soundDef = defSilentFail as SoundDef; if (soundDef != null && soundDef.isUndefined) { Log.Warning(string.Concat(new object[] { "Could not resolve cross-reference: No ", this.fi.FieldType, " named ", this.defName.ToStringSafe <string>(), " found to give to ", this.wanter.GetType(), " ", this.wanter.ToStringSafe <object>(), " (using undefined sound instead)" }), false); } this.fi.SetValue(this.wanter, defSilentFail); result = true; } } return(result); }
/// <summary> /// Exhaustively check that verts and edges of this EdgeSpan are consistent. Not for production use. /// </summary> public bool CheckValidity(FailMode eFailMode = FailMode.Throw) { bool is_ok = true; Action <bool> CheckOrFailF = (b) => { is_ok = is_ok && b; }; if (eFailMode == FailMode.DebugAssert) { CheckOrFailF = (b) => { Debug.Assert(b); is_ok = is_ok && b; }; } else if (eFailMode == FailMode.gDevAssert) { CheckOrFailF = (b) => { Util.gDevAssert(b); is_ok = is_ok && b; }; } else if (eFailMode == FailMode.Throw) { CheckOrFailF = (b) => { if (b == false) { throw new Exception("EdgeSpan.CheckValidity: check failed"); } }; } CheckOrFailF(Vertices.Length == Edges.Length + 1); for (int ei = 0; ei < Edges.Length; ++ei) { Index2i ev = Mesh.GetEdgeV(Edges[ei]); CheckOrFailF(Mesh.IsVertex(ev.a)); CheckOrFailF(Mesh.IsVertex(ev.b)); CheckOrFailF(Mesh.FindEdge(ev.a, ev.b) != DMesh3.InvalidID); CheckOrFailF(Vertices[ei] == ev.a || Vertices[ei] == ev.b); CheckOrFailF(Vertices[ei + 1] == ev.a || Vertices[ei + 1] == ev.b); } for (int vi = 0; vi < Vertices.Length - 1; ++vi) { int a = Vertices[vi], b = Vertices[vi + 1]; CheckOrFailF(Mesh.IsVertex(a)); CheckOrFailF(Mesh.IsVertex(b)); CheckOrFailF(Mesh.FindEdge(a, b) != DMesh3.InvalidID); if (vi < Vertices.Length - 2) { int n = 0, edge_before_b = Edges[vi], edge_after_b = Edges[vi + 1]; foreach (int nbr_e in Mesh.VtxEdgesItr(b)) { if (nbr_e == edge_before_b || nbr_e == edge_after_b) { n++; } } CheckOrFailF(n == 2); } } return(true); }
public override bool TryResolve(FailMode failReportMode) { failReportMode = FailMode.LogErrors; bool flag = typeof(Def).IsAssignableFrom(typeof(K)); bool flag2 = typeof(Def).IsAssignableFrom(typeof(V)); List <Pair <K, V> > list = new List <Pair <K, V> >(); foreach (XmlNode xmlNode in this.wantedDictRefs) { XmlNode xmlNode2 = xmlNode["key"]; XmlNode xmlNode3 = xmlNode["value"]; K first; if (flag) { first = DirectXmlCrossRefLoader.TryResolveDef <K>(xmlNode2.InnerText, failReportMode, this.debugWanterInfo); } else { first = DirectXmlToObject.ObjectFromXml <K>(xmlNode2, true); } V second; if (flag2) { second = DirectXmlCrossRefLoader.TryResolveDef <V>(xmlNode3.InnerText, failReportMode, this.debugWanterInfo); } else { second = DirectXmlToObject.ObjectFromXml <V>(xmlNode3, true); } list.Add(new Pair <K, V>(first, second)); } Dictionary <K, V> dictionary = (Dictionary <K, V>) this.wanter; dictionary.Clear(); foreach (Pair <K, V> pair in list) { try { dictionary.Add(pair.First, pair.Second); } catch { Log.Error(string.Concat(new object[] { "Failed to load key/value pair: ", pair.First, ", ", pair.Second }), false); } } return(true); }
public static T TryResolveDef <T>(string defName, FailMode failReportMode) { T val = (T)(object)GenDefDatabase.GetDefSilentFail(typeof(T), defName); if (val != null) { return(val); } if (failReportMode == FailMode.LogErrors) { Log.Error("Could not resolve cross-reference to " + typeof(T) + " named " + defName); } return(default(T)); }
public override bool TryResolve(FailMode failReportMode) { failReportMode = FailMode.LogErrors; bool flag = typeof(Def).IsAssignableFrom(typeof(K)); bool flag2 = typeof(Def).IsAssignableFrom(typeof(V)); foreach (XmlNode wantedDictRef in wantedDictRefs) { XmlNode xmlNode = wantedDictRef["key"]; XmlNode xmlNode2 = wantedDictRef["value"]; object first = ((!flag) ? xmlNode : ((object)TryResolveDef <K>(xmlNode.InnerText, failReportMode, debugWanterInfo))); object second = ((!flag2) ? xmlNode2 : ((object)TryResolveDef <V>(xmlNode2.InnerText, failReportMode, debugWanterInfo))); makingData.Add(new Pair <object, object>(first, second)); } return(true); }
public static T TryResolveDef <T>(string defName, FailMode failReportMode, object debugWanterInfo = null) { T val = (T)(object)GenDefDatabase.GetDefSilentFail(typeof(T), defName); if (val != null) { return(val); } if (failReportMode == FailMode.LogErrors) { string text = "Could not resolve cross-reference to " + typeof(T) + " named " + defName; if (debugWanterInfo != null) { text = text + " (wanter=" + debugWanterInfo.ToStringSafe() + ")"; } Log.Error(text); } return(default(T)); }
public static T TryResolveDef <T>(string defName, FailMode failReportMode) { T t = (T)((object)GenDefDatabase.GetDefSilentFail(typeof(T), defName)); if (t != null) { return(t); } if (failReportMode == FailMode.LogErrors) { Log.Error(string.Concat(new object[] { "Could not resolve cross-reference to ", typeof(T), " named ", defName })); } return(default(T)); }
public override bool TryResolve(FailMode failReportMode) { bool flag = false; for (int i = 0; i < defNames.Count; i++) { T val = TryResolveDef <T>(defNames[i], failReportMode, debugWanterInfo); if (val != null) { ((List <T>)wanter).Add(val); defNames.RemoveAt(i); i--; } else { flag = true; } } return(!flag); }
public override bool TryResolve(FailMode failReportMode) { bool flag = false; for (int i = 0; i < this.defNames.Count; i++) { T t = DirectXmlCrossRefLoader.TryResolveDef <T>(this.defNames[i], failReportMode, this.debugWanterInfo); if (t != null) { ((List <T>) this.wanter).Add(t); this.defNames.RemoveAt(i); i--; } else { flag = true; } } return(!flag); }
/// <summary> // This function checks that the graph is well-formed, ie all internal data // structures are consistent /// </summary> public virtual bool CheckValidity(FailMode eFailMode = FailMode.Throw) { bool is_ok = true; Action <bool> CheckOrFailF = (b) => { is_ok = is_ok && b; }; if (eFailMode == FailMode.DebugAssert) { CheckOrFailF = (b) => { Debug.Assert(b); is_ok = is_ok && b; }; } else if (eFailMode == FailMode.gDevAssert) { CheckOrFailF = (b) => { Util.gDevAssert(b); is_ok = is_ok && b; }; } else if (eFailMode == FailMode.Throw) { CheckOrFailF = (b) => { if (b == false) { throw new Exception("DGraph3.CheckValidity: check failed"); } }; } // edge verts/tris must exist foreach (int eID in EdgeIndices()) { CheckOrFailF(IsEdge(eID)); CheckOrFailF(edges_refcount.refCount(eID) == 1); Index2i ev = GetEdgeV(eID); CheckOrFailF(IsVertex(ev[0])); CheckOrFailF(IsVertex(ev[1])); CheckOrFailF(ev[0] < ev[1]); } // verify compact check bool is_compact = vertices_refcount.is_dense; if (is_compact) { for (int vid = 0; vid < VertexCount; ++vid) { CheckOrFailF(vertices_refcount.isValid(vid)); } } // vertex edges must exist and reference this vert foreach (int vID in VertexIndices()) { CheckOrFailF(IsVertex(vID)); //Vector3d v = GetVertex(vID); //CheckOrFailF(double.IsNaN(v.LengthSquared) == false); //CheckOrFailF(double.IsInfinity(v.LengthSquared) == false); List <int> l = vertex_edges[vID]; foreach (int edgeid in l) { CheckOrFailF(IsEdge(edgeid)); CheckOrFailF(edge_has_v(edgeid, vID)); int otherV = edge_other_v(edgeid, vID); int e2 = FindEdge(vID, otherV); CheckOrFailF(e2 != InvalidID); CheckOrFailF(e2 == edgeid); e2 = FindEdge(otherV, vID); CheckOrFailF(e2 != InvalidID); CheckOrFailF(e2 == edgeid); } CheckOrFailF(vertices_refcount.refCount(vID) == l.Count + 1); } subclass_validity_checks(CheckOrFailF); return(is_ok); }
public abstract bool TryResolve(FailMode failReportMode);
/// <summary> // This function checks that the mesh is well-formed, ie all internal data // structures are consistent /// </summary> public bool CheckValidity(bool bAllowNonManifoldVertices = false, FailMode eFailMode = FailMode.Throw) { int[] triToVtxRefs = new int[this.MaxVertexID]; bool is_ok = true; Action <bool> CheckOrFailF = (b) => { is_ok = is_ok && b; }; if (eFailMode == FailMode.DebugAssert) { CheckOrFailF = (b) => { Debug.Assert(b); is_ok = is_ok && b; }; } else if (eFailMode == FailMode.gDevAssert) { CheckOrFailF = (b) => { Util.gDevAssert(b); is_ok = is_ok && b; }; } else if (eFailMode == FailMode.Throw) { CheckOrFailF = (b) => { if (b == false) { throw new Exception("DMesh3.CheckValidity: check failed"); } }; } if (normals != null) { CheckOrFailF(normals.size == vertices.size); } if (colors != null) { CheckOrFailF(colors.size == vertices.size); } if (uv != null) { CheckOrFailF(uv.size / 2 == vertices.size / 3); } if (triangle_groups != null) { CheckOrFailF(triangle_groups.size == triangles.size / 3); } foreach (int tID in TriangleIndices()) { CheckOrFailF(IsTriangle(tID)); CheckOrFailF(triangles_refcount.refCount(tID) == 1); // vertices must exist Index3i tv = GetTriangle(tID); for (int j = 0; j < 3; ++j) { CheckOrFailF(IsVertex(tv[j])); triToVtxRefs[tv[j]] += 1; } // edges must exist and reference this tri Index3i e = new Index3i(); for (int j = 0; j < 3; ++j) { int a = tv[j], b = tv[(j + 1) % 3]; e[j] = FindEdge(a, b); CheckOrFailF(e[j] != InvalidID); CheckOrFailF(edge_has_t(e[j], tID)); CheckOrFailF(e[j] == FindEdgeFromTri(a, b, tID)); } CheckOrFailF(e[0] != e[1] && e[0] != e[2] && e[1] != e[2]); // tri nbrs must exist and reference this tri, or same edge must be boundary edge Index3i te = GetTriEdges(tID); for (int j = 0; j < 3; ++j) { int eid = te[j]; CheckOrFailF(IsEdge(eid)); int tOther = edge_other_t(eid, tID); if (tOther == InvalidID) { CheckOrFailF(tri_is_boundary(tID)); continue; } CheckOrFailF(tri_has_neighbour_t(tOther, tID) == true); // edge must have same two verts as tri for same index int a = tv[j], b = tv[(j + 1) % 3]; Index2i ev = GetEdgeV(te[j]); CheckOrFailF(IndexUtil.same_pair_unordered(a, b, ev[0], ev[1])); // also check that nbr edge has opposite orientation Index3i othertv = GetTriangle(tOther); int found = IndexUtil.find_tri_ordered_edge(b, a, othertv.array); CheckOrFailF(found != InvalidID); } } // edge verts/tris must exist foreach (int eID in EdgeIndices()) { CheckOrFailF(IsEdge(eID)); CheckOrFailF(edges_refcount.refCount(eID) == 1); Index2i ev = GetEdgeV(eID); Index2i et = GetEdgeT(eID); CheckOrFailF(IsVertex(ev[0])); CheckOrFailF(IsVertex(ev[1])); CheckOrFailF(et[0] != InvalidID); CheckOrFailF(ev[0] < ev[1]); CheckOrFailF(IsTriangle(et[0])); if (et[1] != InvalidID) { CheckOrFailF(IsTriangle(et[1])); } } // verify compact check bool is_compact = vertices_refcount.is_dense; if (is_compact) { for (int vid = 0; vid < vertices.Length / 3; ++vid) { CheckOrFailF(vertices_refcount.isValid(vid)); } } // vertex edges must exist and reference this vert foreach (int vID in VertexIndices()) { CheckOrFailF(IsVertex(vID)); Vector3d v = GetVertex(vID); CheckOrFailF(double.IsNaN(v.LengthSquared) == false); CheckOrFailF(double.IsInfinity(v.LengthSquared) == false); List <int> l = vertex_edges[vID]; foreach (int edgeid in l) { CheckOrFailF(IsEdge(edgeid)); CheckOrFailF(edge_has_v(edgeid, vID)); int otherV = edge_other_v(edgeid, vID); int e2 = find_edge(vID, otherV); CheckOrFailF(e2 != InvalidID); CheckOrFailF(e2 == edgeid); e2 = find_edge(otherV, vID); CheckOrFailF(e2 != InvalidID); CheckOrFailF(e2 == edgeid); } List <int> vTris = new List <int>(), vTris2 = new List <int>(); GetVtxTriangles(vID, vTris, false); GetVtxTriangles(vID, vTris2, true); CheckOrFailF(vTris.Count == vTris2.Count); //System.Console.WriteLine(string.Format("{0} {1} {2}", vID, vTris.Count, GetVtxEdges(vID).Count)); if (bAllowNonManifoldVertices) { CheckOrFailF(vTris.Count <= GetVtxEdges(vID).Count); } else { CheckOrFailF(vTris.Count == GetVtxEdges(vID).Count || vTris.Count == GetVtxEdges(vID).Count - 1); } CheckOrFailF(vertices_refcount.refCount(vID) == vTris.Count + 1); CheckOrFailF(triToVtxRefs[vID] == vTris.Count); foreach (int tID in vTris) { CheckOrFailF(tri_has_v(tID, vID)); } // check that edges around vert only references tris above, and reference all of them! List <int> vRemoveTris = new List <int>(vTris); foreach (int edgeid in l) { Index2i edget = GetEdgeT(edgeid); CheckOrFailF(vTris.Contains(edget[0])); if (edget[1] != InvalidID) { CheckOrFailF(vTris.Contains(edget[1])); } vRemoveTris.Remove(edget[0]); if (edget[1] != InvalidID) { vRemoveTris.Remove(edget[1]); } } CheckOrFailF(vRemoveTris.Count == 0); } return(is_ok); }