Esempio n. 1
0
        public void EmitSimplePropertyMembers(CodeTypeDeclaration type, CodeSnippetExpression storage,
                                              CodeTypeReference interfaceType, bool changed, string name)
        {
            CodeIndexerExpression index = new CodeIndexerExpression(storage.Field("Values"),
                                                                    "this.OffsetStorage + {0}".Expr(Decorator.OffsetStorage));

            // getter method
            Action <CodeStatementCollection> getter = get =>
            {
                get.Add(
                    new CodeMethodReturnStatement(
                        new CodeFieldReferenceExpression(index, StorageField)
                        )
                    );
            };

            // setter method
            Action <CodeStatementCollection> setter = set =>
            {
                PropertyStateSettings s = Decorator.Definition.StateAssetSettings;
                if (s != null && VerifyModify)
                {
                    EmitAllowedCheck(set);
                }

                // allows emission of a validator snippet
                EmitSetPropertyValidator(set, type, storage, interfaceType, changed, name);

                if (changed)
                {
                    set.Add("{0} oldValue".Expr(Decorator.ClrType));
                    set.Add("oldValue".Expr().Assign(new CodeFieldReferenceExpression(index, StorageField)));
                }

                set.Add(new CodeAssignStatement(
                            new CodeFieldReferenceExpression(index, StorageField),
                            new CodeVariableReferenceExpression("value")
                            ));

                if (changed)
                {
                    string diff = Decorator.Definition.PropertyType.StrictCompare ? "Diff_Strict" : "Diff";
                    set.If("Ascension.Networking.NetworkValue.{0}(oldValue, value)".Expr(diff),
                           body => { EmitPropertyChanged(body, storage); });
                }
            };

            if (!AllowSetter)
            {
                setter = null;
            }

            CodeMemberProperty property = type.DeclareProperty(Decorator.ClrType, name, getter, setter);

            property.PrivateImplementationType = interfaceType;
            property.Attributes = Decorator.Attributes;
        }
Esempio n. 2
0
        public void EmitAddSettings(CodeExpression expr, CodeStatementCollection statements, Offsets offsets)
        {
            // fix for transfer from old system
            if (Decorator.Definition.Controller)
            {
                Decorator.Definition.ReplicationMode = ReplicationMode.Everyone;
            }

            int filters = 0;

            switch (Decorator.Definition.ReplicationMode)
            {
            case ReplicationMode.Everyone:
                filters |= (1 << 30);
                filters |= (1 << 31);
                break;

            case ReplicationMode.EveryoneExceptController:
                filters |= (1 << 30);
                break;

            case ReplicationMode.OnlyOwnerAndController:
                filters |= (1 << 31);
                break;
            }

            statements.Call(expr, "Settings_Property",
                            Decorator.Definition.Name.Literal(),
                            Decorator.Definition.Priority.Literal(),
                            filters.Literal()
                            );

            statements.Call(expr, "Settings_Offsets",
                            offsets.OffsetProperties,
                            offsets.OffsetStorage
                            );

            // mecanim for states settings
            if ((Decorator.DefiningAsset is StateDecorator) && Decorator.Definition.PropertyType.MecanimApplicable)
            {
                PropertyStateSettings s = Decorator.Definition.StateAssetSettings;

                statements.Call(expr, "Settings_Mecanim",
                                s.MecanimMode.Literal(),
                                s.MecanimDirection.Literal(),
                                s.MecanimDamping.Literal(),
                                s.MecanimLayer.Literal()
                                );
            }

            // collecting property specific settings
            AddSettings(expr, statements);
        }
        private void EmitExtrapolationSettings(CodeExpression expr, CodeStatementCollection stmts)
        {
            PropertyStateSettings s = Decorator.Definition.StateAssetSettings;

            stmts.Call(expr, "Settings_Extrapolation",
                "Ascension.Networking.PropertyExtrapolationSettings".Expr().Call("Create",
                    s.ExtrapolationMaxFrames.Literal(),
                    s.ExtrapolationErrorTolerance.Literal(),
                    s.SnapMagnitude.Literal(),
                    Decorator.PropertyType.ExtrapolationVelocityMode.Literal()
                    )
                );
        }
Esempio n. 4
0
        public void EmitInterpolationSettings(CodeExpression expr, CodeStatementCollection statements)
        {
            PropertyStateSettings   s = Decorator.Definition.StateAssetSettings;
            PropertyCommandSettings c = Decorator.Definition.CommandAssetSettings;

            if (s != null)
            {
                if (s.SmoothingAlgorithm != SmoothingAlgorithms.None)
                {
                    statements.Add(expr.Call("Settings_Interpolation", s.SnapMagnitude.Literal(), true.Literal()));
                }
            }

            if (c != null)
            {
                if (c.SmoothCorrection)
                {
                    statements.Add(expr.Call("Settings_Interpolation", c.SnapMagnitude.Literal(), false.Literal()));
                }
            }
        }
Esempio n. 5
0
        public override void EmitObjectMembers(CodeTypeDeclaration type)
        {
            EmitSimplePropertyMembers(type, new CodeSnippetExpression("Storage"), null, false, Decorator.TriggerListener);

            PropertyStateSettings s = Decorator.Definition.StateAssetSettings;

            // don't emit this method if we we are pulling data from mecanim
            if (s.MecanimMode == MecanimMode.Disabled || s.MecanimDirection == MecanimDirection.UsingAscensionProperties)
            {
                type.DeclareMethod(typeof(void).FullName, Decorator.TriggerMethod, method =>
                {
                    // make sure this peer is allowed to modify this property
                    EmitAllowedCheck(method.Statements);

                    // update local trigger
                    method.Statements.Expr(
                        "Storage.Values[this.OffsetStorage + {0}].TriggerLocal.Update(Ascension.Networking.Core.Frame, true)",
                        Decorator.OffsetStorage);

                    // flag this property as changed
                    EmitPropertyChanged(method.Statements, new CodeSnippetExpression("Storage"));
                });
            }
        }