コード例 #1
0
        public void Serialize <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) != 0)
            {
                s.StreamElements("E", mElements, model, MegaloScriptModelObjectHandle.SerializeForEmbed);
            }
            else
            {
                s.StreamElements("E", mElements, model, MegaloScriptModelObjectHandle.Serialize);
            }

            if (s.IsReading)
            {
                // auto-create union groups if needed
                if (model.TagElementStreamSerializeFlags.EmbedObjectsWriteSansIds())
                {
                    MegaloScriptUnionGroup.PostprocessConditionsForEmbedObjectsWriteSansIds(model, s, mElements);
                }
                else
                {
                    MegaloScriptUnionGroup.ReadPostprocessConditions(model, s, mElements);
                }
            }
        }
コード例 #2
0
        void Decompile(MegaloScriptConditionActionReferences refs)
        {
            short first_cond, cond_count;
            short first_action, action_count;

            refs.Get(out first_cond, out cond_count, out first_action, out action_count);

            // predict the amount we're adding to avoid realloc'ing
            if (cond_count > 0 || action_count > 0)
            {
                refs.SetCapacity(cond_count + action_count);
            }

            // first, just add the actions
            for (int x = 0, id = first_action; x < action_count; x++, id++)
            {
                refs.Add(Model.Actions[id].Handle);
            }

            // We do conditions second as to keep the execute-before-action handling
            // simple. Although, insert operations aren't computationally simple...
            MegaloScriptUnionGroup global_union_group = null;

            for (int prev_union_group_id = TypeExtensions.kNone,
                 x = cond_count - 1, id = first_cond + x; x >= 0; x--, id--)
            {
                var cond = Model.Conditions[id];

                int insert_index = cond.ExecuteBeforeAction;
                Contract.Assert(insert_index.IsNotNone(), "Did we already process this condition?");
                refs.Insert(insert_index, cond.Handle);
                cond.ExecuteBeforeAction = TypeExtensions.kNone;

                if (prev_union_group_id != cond.UnionGroup)
                {
                    prev_union_group_id = cond.UnionGroup;
                    global_union_group  = Model.CreateUnionGroup();
                }
                global_union_group.Add(cond);
            }
        }
コード例 #3
0
        internal static void PostprocessConditionsForEmbedObjectsWriteSansIds <TDoc, TCursor>(
            MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s,
            IEnumerable <MegaloScriptModelObjectHandle> elements)
            where TDoc : class
            where TCursor : class
        {
            Util.MarkUnusedVariable(ref s);

            MegaloScriptUnionGroup prev_union_group = null;

            foreach (var obj in elements)
            {
                if (obj.Type != MegaloScriptModelObjectType.Condition)
                {
                    continue;
                }
                var cond = model.Conditions[obj.Id];

                if (cond.UnionGroup >= 0)                                  // id is already valid
                {
                    prev_union_group = model.UnionGroups[cond.UnionGroup]; // mark it as prev in case it was inserted into existing code
                    continue;
                }
                else if (cond.UnionGroup == MegaloScriptCondition.kUseNewUnionGroupId)
                {
                    prev_union_group = model.CreateUnionGroup();
                    prev_union_group.Add(cond);
                }
                else if (cond.UnionGroup == MegaloScriptCondition.kUsePrevUnionGroupId)
                {
                    Contract.Assert(prev_union_group != null);
                    prev_union_group.Add(cond);
                }
                else
                {
                    throw new KSoft.Debug.UnreachableException(cond.UnionGroup.ToString(Util.InvariantCultureInfo));
                }
            }
        }
コード例 #4
0
 internal void AssociateWith(MegaloScriptUnionGroup unionGroup)
 {
     UnionGroup = unionGroup.Id;
 }
コード例 #5
0
 internal void HandleRemoval(MegaloScriptUnionGroup unionGroup)
 {
     UnionGroups[unionGroup.Id] = null;
 }