public static void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, ref EngineBuildHandle value) where TDoc : class where TCursor : class { bool reading = s.IsReading; var engine_index = reading ? TypeExtensions.kNone : value.EngineIndex; var branch_index = reading ? TypeExtensions.kNone : value.BranchIndex; var revisn_index = reading ? TypeExtensions.kNone : value.RevisionIndex; if (BlamEngine.SerializeId(s, kAttributeNameEngine, ref engine_index, true)) { var repo = EngineRegistry.Engines[engine_index].BuildRepository; if (repo.SerializeBranchId(s, kAttributeNameBranch, ref branch_index, true)) { var branch = repo.Branches[branch_index]; branch.SerializeRevisionId(s, kAttributeNameRevisn, ref revisn_index, true); } } if (reading) { value = new EngineBuildHandle(engine_index, branch_index, revisn_index); } }
static void StreamSystemPrototypeKey <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, BlamEngine engine, ref Values.KGuid systemGuid) where TDoc : class where TCursor : class { s.StreamAttribute("guid", ref systemGuid); if (s.IsReading) { string invalid_guid_msg = null; if (systemGuid == Values.KGuid.Empty) { invalid_guid_msg = "Invalid system guid: "; } else if (EngineRegistry.TryGetRegisteredSystem(systemGuid) == null) { invalid_guid_msg = "Unknown system guid: "; } if (invalid_guid_msg != null) { s.ThrowReadException(new System.IO.InvalidDataException( invalid_guid_msg + systemGuid.ToString(Values.KGuid.kFormatHyphenated, Util.InvariantCultureInfo))); } } }
static void InitializePrototypes() { // #TODO_BLAM: if we use a 'null' engine entry, add it here, before the prototypes are read using (var s = OpenRegistryTagElementStream()) { SerializePrototypes(s); SerializeTargets(s); } KSoft.Debug.ValueCheck.IsLessThanEqualTo("EngineRegistry: Too many registered engines", BlamEngine.kMaxCount, Engines.Count); KSoft.Debug.ValueCheck.IsLessThanEqualTo("EngineRegistry: Too many registered target platforms", EngineTargetPlatform.kMaxCount, TargetPlatforms.Count); KSoft.Debug.ValueCheck.IsLessThanEqualTo("EngineRegistry: Too many registered resource models", kMaxResourceModels, ResourceModels.Count); KSoft.Debug.ValueCheck.IsDistinct("EngineRegistry: Duplicate engines registered", "name", Engines.Select(e => e.Name)); KSoft.Debug.ValueCheck.IsDistinct("EngineRegistry: Duplicate target platforms registered", "name", TargetPlatforms.Select(e => e.Name)); KSoft.Debug.ValueCheck.IsDistinct("EngineRegistry: Duplicate resource models registered", "name", ResourceModels); gEngines.TrimExcess(); gTargetPlatforms.TrimExcess(); gResourceModels.TrimExcess(); BlamEngine.InitializeEngineBuildHandles(); kNullValidTargetPlatforms = new Collections.BitSet(TargetPlatforms.Count); InitializeTargetPlatformIndicies(); }
static string GetTagElementStreamPath(BlamEngine engine, string fileName) { Contract.Assert(engine != null); Contract.Assert(!string.IsNullOrEmpty(fileName)); return(Path.Combine(GetEngineRootPath(engine), fileName)); }
internal static void SerializePrototype <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, object _context, ref BlamEngine engine) where TDoc : class where TCursor : class { s.StreamAttributeEnum("generation", engine, obj => obj.Generation); s.StreamAttribute("name", engine, obj => obj.Name); }
public static EngineBuildHandle Create(int engineIndex, int branchIndex = TypeExtensions.kNone, int revisionIndex = TypeExtensions.kNone) { Contract.Requires <ArgumentOutOfRangeException>(BlamEngine.IsValidIndex(engineIndex)); Contract.Requires <ArgumentOutOfRangeException>(branchIndex.IsNoneOrPositive()); Contract.Requires <ArgumentOutOfRangeException>(revisionIndex.IsNoneOrPositive()); return(new EngineBuildHandle(engineIndex, branchIndex, revisionIndex)); }
internal static bool IsValidTagElmentStreamFile(BlamEngine engine, string fileName) { Contract.Requires(engine != null); Contract.Requires(!string.IsNullOrEmpty(fileName)); string path = GetTagElementStreamPath(engine, fileName); return(File.Exists(path)); }
static void ResolveWellKnownEngines() { EngineBranchHalo1 = BlamEngine.ResolveWellKnownEngineBranch("Halo1", "Halo1"); EngineBranchHalo2 = BlamEngine.ResolveWellKnownEngineBranch("Halo2", "Halo2"); EngineBranchHalo3 = BlamEngine.ResolveWellKnownEngineBranch("Halo3", "Halo3"); EngineBranchHaloOdst = BlamEngine.ResolveWellKnownEngineBranch("Halo3", "HaloOdst"); EngineBranchHaloReach = BlamEngine.ResolveWellKnownEngineBranch("HaloReach", "HaloReach"); EngineBranchHalo4 = BlamEngine.ResolveWellKnownEngineBranch("Halo4", "Halo4"); EngineBranchHalo2A = BlamEngine.ResolveWellKnownEngineBranch("Halo4", "Halo2A"); }
static void InitializeEngines() { foreach (var e in gEngines) { using (var s = OpenEngineTagElementStream(e)) e.Serialize(s); } BlamEngine.InitializeEngineRepositoryBuildHandles(); }
static void InitializeHandle(out uint handle, int engineIndex, int branchIndex, int revisionIndex) { var encoder = new Bitwise.HandleBitEncoder(); EngineBuildRevision.BitEncodeIndex(ref encoder, revisionIndex); EngineBuildBranch.BitEncodeIndex(ref encoder, branchIndex); BlamEngine.BitEncodeIndex(ref encoder, engineIndex); Contract.Assert(encoder.UsedBitCount == EngineBuildHandle.BitCount); handle = encoder.GetHandle32(); }
internal static dynamic OpenEngineSystemTagElementStream(BlamEngine engine, Values.KGuid systemGuid, string externFileName, FileAccess streamMode = FileAccess.Read) { Contract.Assert(engine != null); string extern_stream_path = GetTagElementStreamPath(engine, externFileName); if (!File.Exists(extern_stream_path)) { throw new FileNotFoundException(string.Format( "Can't initialize the {0} engine's {1} system, need the following file: {2}", engine.Name, GetSystemDebugDisplayString(systemGuid), extern_stream_path)); } var stream = IO.TagElementStreamFactory.Open(extern_stream_path); stream.StreamMode = streamMode; return(stream); }
static dynamic OpenEngineTagElementStream(BlamEngine engine, FileAccess streamMode = FileAccess.Read) { Contract.Assert(engine != null); string engine_stream_path = GetTagElementStreamPath(engine, engine.Name); engine_stream_path += ".xml"; if (!File.Exists(engine_stream_path)) { throw new FileNotFoundException(string.Format( "Can't initialize the {0} engine, need the following file: {1}", engine.Name, engine_stream_path)); } var stream = IO.TagElementStreamFactory.Open(engine_stream_path); stream.StreamMode = streamMode; return(stream); }
/// <summary>Serialize a build handle, using a 'baseline' to populate or cull (from writing) root build information</summary> /// <param name="s"></param> /// <param name="baseline">Root build information (ie, engine, or engine and branch)</param> /// <param name="value"></param> public static void SerializeWithBaseline <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, EngineBuildHandle baseline, ref EngineBuildHandle value) where TDoc : class where TCursor : class { int engine_index = baseline.EngineIndex; int branch_index = baseline.BranchIndex; int revisn_index = baseline.RevisionIndex; EngineBuildRepository repo = null; EngineBuildBranch branch = null; if (s.IsWriting) { #region prepare engine_index if (value.EngineIndex == engine_index) { repo = EngineRegistry.Engines[engine_index].BuildRepository; // cause engine_index not to be written engine_index = TypeExtensions.kNone; } else { engine_index = value.EngineIndex; } #endregion #region prepare branch_index if (value.BranchIndex == branch_index) { branch = repo.Branches[branch_index]; // cause branch_index not to be written branch_index = TypeExtensions.kNone; } else { branch_index = value.BranchIndex; } #endregion #region prepare revisn_index if (value.BranchIndex == revisn_index) { // cause branch_index not to be written branch_index = TypeExtensions.kNone; } else { revisn_index = value.RevisionIndex; } #endregion } // This is a logic driven mess, but having branches for both IsReading and IsWriting would result in more copy&paste code // reading: baseline EngineIndex is valid, or index is serialized // writing: value EngineIndex mismatches baseline if (engine_index.IsNotNone() || BlamEngine.SerializeId(s, kAttributeNameEngine, ref engine_index, true)) { repo = EngineRegistry.Engines[engine_index].BuildRepository; } // precondition: someone's EngineIndex was valid // reading: baseline BranchIndex is valid, or index is serialized // writing: value BranchIndex mismatches baseline if (repo != null && (branch_index.IsNotNone() || repo.SerializeBranchId(s, kAttributeNameBranch, ref branch_index, true))) { branch = repo.Branches[branch_index]; } // precondition: someone's BranchIndex was valid // reading: baseline RevisionIndex is valid // writing: value RevisionIndex mismatches baseline if (branch != null && (revisn_index.IsNotNone() || s.IsReading)) { branch.SerializeRevisionId(s, kAttributeNameRevisn, ref revisn_index, true); } if (s.IsReading) { if (engine_index.IsNotNone()) { value = new EngineBuildHandle(engine_index, branch_index, revisn_index); } else // engine_index is NONE, don't even bother trying to encode a new handle that should be all NONE anyway { value = EngineBuildHandle.None; } } }
static string GetEngineRootPath(BlamEngine engine) { Contract.Assert(engine != null); return(Path.Combine(@"Games\", engine.Name)); }