void Read <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { string[] names = kInfo.kValuesEnum.GetEnumNames(); foreach (var element in s.ElementsByName(kEntryElementName)) { using (s.EnterCursorBookmark(element)) { string name = null; s.ReadAttribute(kEntryAttrKeyName, ref name); int name_index = Array.IndexOf(names, name); if (name_index < 0) { s.ThrowReadException(new System.IO.InvalidDataException("Invalid name value: " + name)); } mArray[name_index] = 0.0f; if (s.ReadAttributeOpt(kEntryAttrValueName, ref mArray[name_index])) // #HACK_BLAM: IgnoreWritePredicates hack! didn't used to be Opt { mValidFlags |= 1U << name_index; } } } }
void Read <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s, bool embedValues) where TDoc : class where TCursor : class { int param_index = 0; foreach (var node in s.ElementsByName("Param")) { using (s.EnterCursorBookmark(node)) { if (embedValues) { MegaloScriptValueBase.SerializeValueForEmbed(model, s, ref mValueIds[param_index]); } else { s.StreamCursor(ref mValueIds[param_index]); } Contract.Assert(mValueIds[param_index].IsNotNone()); param_index++; if (param_index == mValueIds.Length) { break; } } } }
public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { using (s.EnterCursorBookmark("Language")) { s.StreamAttribute("name", ref mLanguage); if (s.IsReading) { var temp_list = new List <LocString>(); bool is_sorted = true; LocString prev_str = null; foreach (var n in s.ElementsByName("String")) { using (s.EnterCursorBookmark(n)) { var str = new LocString(); str.Serialize(s); temp_list.Add(str); if (is_sorted && prev_str != null && prev_str.ID >= str.ID) { is_sorted = false; } prev_str = str; } } if (!is_sorted) { temp_list.Sort((x, y) => x.ID.CompareTo(y.ID)); } int last_id = temp_list[temp_list.Count - 1].ID; UsedIndices.Length = last_id + 1; mDoNotUpdateUsedIndices = true; foreach (var str in temp_list) { int id = str.ID; if (UsedIndices[id]) { s.ThrowReadException(new System.IO.InvalidDataException(string.Format( "Duplicate LocString: #{0} '{1}'", str.ID, str.Text))); } UsedIndices[id] = true; } this.AddRange(temp_list); mDoNotUpdateUsedIndices = false; } else if (s.IsWriting) { s.WriteStreamableElements("String", this); } } }
public static void ReadElements(IO.TagElementStream <TDoc, TCursor, string> s, string elementName, ActiveList <T> list, TContext ctxt, Func <IO.TagElementStream <TDoc, TCursor, string>, TContext, T> ctor, Func <TContext, TagElementStreamReadMode> getReadMode) { ReadElements(s, s.ElementsByName(elementName), list, ctxt, ctor, getReadMode); }
protected virtual IEnumerable <TCursor> ReadGetNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { return(Params.UseElementName ? s.ElementsByName(Params.ElementName) : s.Elements); }
public static IEnumerable <TCursor> ReadGetNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, string xmlName, IO.TagElementNodeType xmlSource) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); Contract.Requires(xmlSource != IO.TagElementNodeType.Attribute); return(xmlSource == IO.TagElementNodeType.Text ? s.ElementsByName(xmlName) : s.Elements); }
public void LoadScenarioScripts <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, StreamTriggerScriptContext ctxt) where TDoc : class where TCursor : class { s.SetSerializerInterface(this); foreach (var e in s.ElementsByName(Phx.BTriggerSystem.kXmlRootName)) { using (s.EnterCursorBookmark(e)) new Phx.BTriggerSystem().Serialize(s); } }
void ReadNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); Collections.IProtoEnum penum = Bits.InitializeFromEnum(xs.Database); if (Params.ElementItselfMeansTrue) { var getDefault = Bits.Params.kGetMemberDefaultValue; foreach (var e in s.Elements) { var element_name = s.GetElementName(e); int id = penum.TryGetMemberId(element_name); if (id.IsNone()) { continue; } bool flag = true; s.StreamElementOpt(element_name, ref flag); if (getDefault != null && flag != getDefault(id)) { // do nothing, allow the Set call below } else if (!flag) { continue; } Bits.Set(id, flag); } } else { foreach (var n in s.ElementsByName(Params.ElementName)) { using (s.EnterCursorBookmark(n)) { string name = null; Params.StreamDataName(s, ref name); int id = penum.GetMemberId(name); Bits.Set(id); } } } Bits.OptimizeStorage(); }
void ReadEngineLanguageTable <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { const string kElementNameEntry = "E"; const string kAttributeNameGameIndex = "id"; const string kAttributeNameLangIndex = "lang"; const string kAttributeNameOptional = "optional"; // number of languages for this build of the engine int lang_count = 0; foreach (var e in s.ElementsByName(kElementNameEntry)) { using (s.EnterCursorBookmark(e)) { int game_index = TypeExtensions.kNone; int lang_index = TypeExtensions.kNone; bool is_optional = false; s.ReadAttribute(kAttributeNameGameIndex, ref game_index, NumeralBase.Decimal); LanguageRegistry.SerializeLanguageId(s, kAttributeNameLangIndex, ref lang_index); s.ReadAttributeOpt(kAttributeNameOptional, ref is_optional); if (IsInvalidGameIndexFromStream(game_index) || lang_index.IsNone()) { s.ThrowReadException(new System.IO.InvalidDataException("Invalid table entry data")); } mEngineLanguageTable[lang_index] = new GameLanguageHandle(mBuildHandle, lang_index, game_index); if (is_optional) { mOptionalEngineLanguageFlags[lang_index] = true; mOptionalGameLanguageFlags[game_index] = true; } lang_count++; } } if (lang_count == 0) { s.ThrowReadException(new System.IO.InvalidDataException("Table has no entries")); } if (!InitializeGameLanguageTableFromEngineTable(lang_count)) { s.ThrowReadException(new System.IO.InvalidDataException("Invalid game index data")); } }
void NameOverridesFromStream <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { mNameOverrides = new Dictionary <int, string>(); foreach (var node in s.ElementsByName(kNameOverrideElementName)) { using (s.EnterCursorBookmark(node)) { var pair = MegaloScriptProtoParam.SigIdNamePairFromStream(s); mNameOverrides.Add(pair.Key, pair.Value); } } }
void FromStream <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { foreach (var element in s.ElementsByName("Sound")) { using (s.EnterCursorBookmark(element)) { string name = null; uint event_id = 0; s.StreamElement("CueName", ref name); s.StreamElement("CueIndex", ref event_id); mEventsMap.Add(event_id, name); } } }
protected override void SerializeExternBody <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) { const string kElementNameLanguageTable = "T"; using (s.EnterCursorBookmark("LanguageTables")) { #if LANGUAGE_SYSTEM_USE_ONLY_ONE_TABLE using (s.EnterCursorBookmark(kElementNameLanguageTable)) { mEngineTable.Serialize(s); } if (s.IsReading) { Contract.Assert(s.ElementsByName(kElementNameLanguageTable).Count() == 1, "Engine has multiple tables defined! This is unexpected, backend code needs to be rewritten"); } #else s.StreamableElements(kElementNameLanguageTable, mEngineTables, this.RootBuildHandle, Blam.Engine.EngineBuildHandle.SerializeWithBaseline); #endif } }