void Compile(MegaloScriptConditionActionReferences refs)
        {
            short first_cond = (short)ConditionWriteOrder.Count;
            short first_action = (short)ActionWriteOrder.Count;
            short cond_count = 0, action_count = 0;

            int prev_union_group = TypeExtensions.kNone, local_union_group_count = 0;

            foreach (var handle in refs)
            {
                switch (handle.Type)
                {
                case MegaloScriptModelObjectType.Condition:
                {
                    var cond = Model.Conditions[handle.Id];
                    if (cond.CommentOut)
                    {
                        cond.ExecuteBeforeAction = -1;
                        break;
                    }

                    cond_count++;
                    ConditionWriteOrder.Add(handle.Id);

                    // We've encountered a new union group, create a new remapping entry for localizing
                    if (prev_union_group != cond.UnionGroup)
                    {
                        UnionGroupRemappings.Add(cond.UnionGroup, local_union_group_count++);
                        prev_union_group = cond.UnionGroup;
                    }

                    cond.ExecuteBeforeAction = action_count;
                } break;

                case MegaloScriptModelObjectType.Action:
                {
                    var action = Model.Actions[handle.Id];
                    if (action.CommentOut)
                    {
                        break;
                    }

                    action_count++;
                    ActionWriteOrder.Add(handle.Id);
                } break;
                }
            }

            refs.Set(first_cond, cond_count, first_action, action_count);
        }
        void ReferencesSwapLogicUnits(MegaloScriptConditionActionReferences refs,
                                      MegaloScriptModelObjectHandle lhs, MegaloScriptModelObjectHandle rhs)
        {
            Contract.Requires(lhs.IsNotNone);
            Contract.Requires(rhs.IsNotNone);

            refs.Swap(lhs, rhs);

            if (lhs.Type == MegaloScriptModelObjectType.Condition && rhs.Type == MegaloScriptModelObjectType.Condition)
            {
                var lhs_cond = Conditions[lhs.Id];
                var rhs_cond = Conditions[rhs.Id];

                if (lhs_cond.UnionGroup == rhs_cond.UnionGroup)
                {
                    UnionGroupSwapLogicUnits(lhs_cond.UnionGroup, lhs, rhs);
                }
            }
        }
        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);
            }
        }
예제 #4
0
 protected MegaloScriptTriggerBase(MegaloScriptConditionActionReferences refs)
 {
     References = refs;
 }
예제 #5
0
 protected MegaloScriptTriggerBase()
 {
     References = new MegaloScriptConditionActionReferences();
 }