/** * Override the contents of this definition set with another. */ public virtual void OverrideBy(MyDefinitionSet definitionSet) { MyDefinitionPostprocessor.Bundle myBundle = new MyDefinitionPostprocessor.Bundle() { Set = this, Context = Context }; MyDefinitionPostprocessor.Bundle thyBundle = new MyDefinitionPostprocessor.Bundle() { Set = definitionSet, Context = definitionSet.Context }; foreach (var defgrp in definitionSet.Definitions) { Dictionary <MyStringHash, MyDefinitionBase> dict; if (!Definitions.TryGetValue(defgrp.Key, out dict)) { dict = new Dictionary <MyStringHash, MyDefinitionBase>(); Definitions[defgrp.Key] = dict; } var pp = MyDefinitionManagerBase.GetPostProcessor(defgrp.Key); myBundle.Definitions = dict; thyBundle.Definitions = defgrp.Value; pp.OverrideBy(ref myBundle, ref thyBundle); } }
/** * Override the contents of this definition set with another. */ public virtual void OverrideBy(MyDefinitionSet definitionSet) { MyDefinitionPostprocessor.Bundle myBundle = new MyDefinitionPostprocessor.Bundle() { Set = this, Context = Context }; MyDefinitionPostprocessor.Bundle thyBundle = new MyDefinitionPostprocessor.Bundle() { Set = definitionSet, Context = definitionSet.Context }; foreach (var defgrp in definitionSet.Definitions) { Dictionary <MyStringHash, MyDefinitionBase> dict; if (!Definitions.TryGetValue(defgrp.Key, out dict)) { dict = new Dictionary <MyStringHash, MyDefinitionBase>(); Definitions[defgrp.Key] = dict; } // TODO: Postprocessing should be per definition type, not typeid. var pp = MyDefinitionManagerBase.GetPostProcessor(defgrp.Key); // Since that is too big a refactor this should fix it in the meantime. // This line gets me sick :( if (pp == null) { pp = MyDefinitionManagerBase.GetPostProcessor( MyDefinitionManagerBase.GetObjectBuilderType(defgrp.Value.First().Value.GetType())); } myBundle.Definitions = dict; thyBundle.Definitions = defgrp.Value; pp.OverrideBy(ref myBundle, ref thyBundle); } }
public override void AfterLoaded(ref MyDefinitionPostprocessor.Bundle definitions) { }
// receiving messages private void LiveDebugging_ReceivedMessageHandler(MyExternalDebugStructures.CommonMsgHeader messageHeader, IntPtr messageData) { MyExternalDebugStructures.ACReloadInGameMsg msgReload; if (MyExternalDebugStructures.ReadMessageFromPtr(ref messageHeader, messageData, out msgReload)) { try { string acContentPath = msgReload.ACContentAddress; string acAddress = msgReload.ACAddress; string acName = msgReload.ACName; MyObjectBuilder_Definitions allDefinitions; // = null; // load animation controller definition from SBC file if (MyObjectBuilderSerializer.DeserializeXML(acAddress, out allDefinitions) && allDefinitions.Definitions != null && allDefinitions.Definitions.Length > 0) { var firstDef = allDefinitions.Definitions[0]; MyModContext context = new MyModContext(); context.Init("AnimationControllerDefinition", acAddress, acContentPath); MyAnimationControllerDefinition animationControllerDefinition = new MyAnimationControllerDefinition(); animationControllerDefinition.Init(firstDef, context); MyStringHash animSubtypeNameHash = MyStringHash.GetOrCompute(acName); // post process and update in def. manager MyAnimationControllerDefinition originalAnimationControllerDefinition = MyDefinitionManagerBase.Static.GetDefinition <MyAnimationControllerDefinition>( animSubtypeNameHash); var postprocessor = MyDefinitionManagerBase.GetPostProcessor(typeof(MyObjectBuilder_AnimationControllerDefinition)); if (postprocessor != null) { MyDefinitionPostprocessor.Bundle originalBundle = new MyDefinitionPostprocessor.Bundle { Context = MyModContext.BaseGame, Definitions = new Dictionary <MyStringHash, MyDefinitionBase> { { animSubtypeNameHash, originalAnimationControllerDefinition } }, Set = new MyDefinitionSet() }; originalBundle.Set.AddDefinition(originalAnimationControllerDefinition); MyDefinitionPostprocessor.Bundle overridingBundle = new MyDefinitionPostprocessor.Bundle { Context = context, Definitions = new Dictionary <MyStringHash, MyDefinitionBase> { { animSubtypeNameHash, animationControllerDefinition } }, Set = new MyDefinitionSet() }; overridingBundle.Set.AddDefinition(animationControllerDefinition); // postprocess -> override existing definition in memory postprocessor.AfterLoaded(ref overridingBundle); postprocessor.OverrideBy(ref originalBundle, ref overridingBundle); } // swap animation controller for each entity foreach (var component in m_skinnedEntityComponents) { if (component != null && component.SourceId.SubtypeName == acName) { component.Clear(); component.InitFromDefinition(originalAnimationControllerDefinition, forceReloadMwm: true); // reload from original def that was modified by postprocessor if (component.ReloadBonesNeeded != null) { component.ReloadBonesNeeded(); } } } } } catch (Exception e) { MyLog.Default.WriteLine(e); } } }
// receiving messages private void LiveDebugging_ReceivedMessageHandler(MyExternalDebugStructures.CommonMsgHeader messageHeader, IntPtr messageData) { MyExternalDebugStructures.ACReloadInGameMsg msgReload; if (MyExternalDebugStructures.ReadMessageFromPtr(ref messageHeader, messageData, out msgReload)) { try { string acContentPath = msgReload.ACContentAddress; string acAddress = msgReload.ACAddress; string acName = msgReload.ACName; MyObjectBuilder_Definitions allDefinitions; // = null; // load animation controller definition from SBC file if (MyObjectBuilderSerializer.DeserializeXML(acAddress, out allDefinitions) && allDefinitions.Definitions != null && allDefinitions.Definitions.Length > 0) { var firstDef = allDefinitions.Definitions[0]; MyModContext context = new MyModContext(); context.Init("AnimationControllerDefinition", acAddress, acContentPath); MyAnimationControllerDefinition animationControllerDefinition = new MyAnimationControllerDefinition(); animationControllerDefinition.Init(firstDef, context); MyStringHash animSubtypeNameHash = MyStringHash.GetOrCompute(acName); // post process and update in def. manager MyAnimationControllerDefinition originalAnimationControllerDefinition = MyDefinitionManagerBase.Static.GetDefinition<MyAnimationControllerDefinition>( animSubtypeNameHash); var postprocessor = MyDefinitionManagerBase.GetPostProcessor(typeof(MyObjectBuilder_AnimationControllerDefinition)); if (postprocessor != null) { MyDefinitionPostprocessor.Bundle originalBundle = new MyDefinitionPostprocessor.Bundle { Context = MyModContext.BaseGame, Definitions = new Dictionary<MyStringHash, MyDefinitionBase> { {animSubtypeNameHash, originalAnimationControllerDefinition} }, Set = new MyDefinitionSet() }; originalBundle.Set.AddDefinition(originalAnimationControllerDefinition); MyDefinitionPostprocessor.Bundle overridingBundle = new MyDefinitionPostprocessor.Bundle { Context = context, Definitions = new Dictionary<MyStringHash, MyDefinitionBase> { {animSubtypeNameHash, animationControllerDefinition} }, Set = new MyDefinitionSet() }; overridingBundle.Set.AddDefinition(animationControllerDefinition); // postprocess -> override existing definition in memory postprocessor.AfterLoaded(ref overridingBundle); postprocessor.OverrideBy(ref originalBundle, ref overridingBundle); } // swap animation controller for each entity foreach (var component in m_skinnedEntityComponents) { if (component != null && component.SourceId.SubtypeName == acName) { component.Clear(); component.InitFromDefinition(originalAnimationControllerDefinition, forceReloadMwm: true); // reload from original def that was modified by postprocessor if (component.ReloadBonesNeeded != null) component.ReloadBonesNeeded(); } } } } catch (Exception e) { MyLog.Default.WriteLine(e); } } }