Example #1
0
        private void ConsoleVariablesMemoryManagementTest()
        {
            Debug.Log(LogLevel.Display, "Starting " + MethodBase.GetCurrentMethod().Name + "...");

            const string variableName = "TestVariable";

            try {
                ConsoleVariable variable = ConsoleManager.RegisterVariable(variableName, "A test variable", 64);

                if (!ConsoleManager.IsRegisteredVariable(variableName))
                {
                    Debug.Log(LogLevel.Error, "Variable registration check failed!");

                    return;
                }

                ConsoleManager.UnregisterObject(variableName);

                Debug.Log(LogLevel.Display, "Triggering invalid actions after the destruction");

                variable.GetInt();
            }

            catch (Exception exception) {
                Debug.Log(LogLevel.Display, "The exception has successfully reached: " + exception.Message);

                return;
            }

            Debug.Log(LogLevel.Error, "Test failed!");
        }
 public DynamicsConsistency()
 {
     playerController = World.GetFirstPlayerController();
     playerInput      = playerController.GetPlayerInput();
     variable         = ConsoleManager.RegisterVariable(consoleVariable, "A test variable", variableValue);
     commandsCount    = 0;
 }
        private static void ProcessConsoleVariableProperty(ConsoleVariableAttribute consoleVariableAttribute, object property, out ICVar icvar)
        {
            icvar = null;
            var stringProperty = property as ConsoleVariableAttributeStringProperty;

            if (stringProperty != null)
            {
                var    stringAttribute = consoleVariableAttribute as ConsoleVariableStringAttribute;
                string value           = stringProperty.Content ?? stringAttribute.Content;
                var    success         = ConsoleVariable.Register(consoleVariableAttribute.Name, value, consoleVariableAttribute.Flags, consoleVariableAttribute.Comments, stringProperty.OnValueChanged, out icvar);
                if (success)
                {
                    stringProperty.SetInternalContent(value, icvar);
                }
                return;
            }

            var integerProperty = property as ConsoleVariableAttributeIntegerProperty;

            if (integerProperty != null)
            {
                var integerAttribute = consoleVariableAttribute as ConsoleVariableIntegerAttribute;
                int value            = integerAttribute.Content.HasValue ? integerAttribute.Content.Value : integerProperty.Content;
                var success          = ConsoleVariable.Register(consoleVariableAttribute.Name, value, consoleVariableAttribute.Flags, consoleVariableAttribute.Comments, integerProperty.OnValueChanged, out icvar);
                if (success)
                {
                    integerProperty.SetInternalContent(value, icvar);
                }
                return;
            }

            var floatProperty = property as ConsoleVariableAttributeFloatProperty;

            if (floatProperty != null)
            {
                var   floatAttribute = consoleVariableAttribute as ConsoleVariableFloatAttribute;
                float value          = floatAttribute.Content.HasValue ? floatAttribute.Content.Value : floatProperty.Content;
                var   success        = ConsoleVariable.Register(consoleVariableAttribute.Name, value, consoleVariableAttribute.Flags, consoleVariableAttribute.Comments, floatProperty.OnValueChanged, out icvar);
                if (success)
                {
                    floatProperty.SetInternalContent(value, icvar);
                }
                return;
            }

            var integer64Property = property as ConsoleVariableAttributeInteger64Property;

            if (integer64Property != null)
            {
                var  integer64Attribute = consoleVariableAttribute as ConsoleVariableInteger64Attribute;
                long value   = integer64Attribute.Content.HasValue ? integer64Attribute.Content.Value : integer64Property.Content;
                var  success = ConsoleVariable.Register(consoleVariableAttribute.Name, value, consoleVariableAttribute.Flags, consoleVariableAttribute.Comments, integer64Property.OnValueChanged, out icvar);
                if (success)
                {
                    integer64Property.SetInternalContent(value, icvar);
                }
            }
        }
        internal ConsoleVariableAttributeStringProperty(string name, string value, string comments, uint flags)
        {
            ICVar icVar      = null;
            var   registered = ConsoleVariable.Register(name, value, flags, comments, OnValueChanged, out icVar);

            if (!registered)
            {
                throw new ConsoleVariableConfigurationException(GetType() + " cannot be created for attribute name " + name);
            }
            SetInternalContent(value, icVar);
        }
 /// <summary>
 /// Disposes this instance.
 /// </summary>
 /// <param name="isDisposing"></param>
 protected virtual void Dispose(bool isDisposing)
 {
     if (m_disposed)
     {
         return;
     }
     if (m_icVar != null)
     {
         ConsoleVariable.UnRegister(ref m_icVar);
     }
     m_disposed = true;
 }
        public void OnBeginPlay()
        {
            ConsoleVariable variable = ConsoleManager.RegisterVariable(consoleVariable, "A test variable", 0);

            ConsoleManager.RegisterCommand(consoleCommand, "A test command", ConsoleCommand);

            variable.SetOnChangedCallback(VariableEvent);

            PlayerController playerController = World.GetFirstPlayerController();

            playerController.ConsoleCommand(consoleVariable + " 1");
            playerController.ConsoleCommand(consoleCommand + " 1.5");

            throw new Exception("Test exception (OnBeginPlay)");
        }
Example #7
0
        /// <summary>
        ///     Create a console variable
        ///     e.g. SmartConsole.Variable
        ///     < bool>
        ///         showFPS = SmartConsole.CreateVariable
        ///         < bool>( "show.fps", "whether to draw framerate counter or not", false );
        /// </summary>
        public static ConsoleVariable <T> CreateVariable <T>(string name, string description, T initialValue) where T : new()
        {
            if (VariableDictionary.ContainsKey(name))
            {
                Debug.LogError("Tried to add already existing console variable!");
                return(null);
            }

            var returnValue = new ConsoleVariable <T>(name, description, initialValue);

            VariableDictionary.Add(name, returnValue);
            MasterDictionary.Add(name, returnValue);

            return(returnValue);
        }
 /// <summary>
 /// Disposes this instance.
 /// </summary>
 /// <param name="isDisposing"></param>
 protected virtual void Dispose(bool isDisposing)
 {
     if (m_disposed)
     {
         return;
     }
     if (m_icVar != null)
     {
         ConsoleVariable.UnRegister(ref m_icVar);
     }
     if (isDisposing)
     {
         m_valueInText.Clear();
         m_valueInText = null;
     }
     m_disposed = true;
 }
Example #9
0
 private static void InitialiseVariables()
 {
     sLogging = CreateVariable("console.log", "whether to redirect log to the console", true);
 }
Example #10
0
 /// <summary>
 ///     Destroy a console variable (so its name can be reused)
 /// </summary>
 public static void DestroyVariable <T>(ConsoleVariable <T> consoleVariable) where T : new()
 {
     VariableDictionary.Remove(consoleVariable.Name);
     MasterDictionary.Remove(consoleVariable.Name);
 }