public frmC机械手(Form _Owner, int iTop) { InitializeComponent(); this.MdiParent = _Owner; cForm.iTop = iTop; LoadWins(); this.Top = (int)cForm.m_Location.Y + cForm.iTop; CMach.MachByStation(40); this.DoubleBuffered = true; CStation Sta = frmMain.staComm.GetStaByStaName("NJ301"); SPLC = (CProtcolFINS)Sta; DI074 = frmMain.staComm.GetVarByStaNameVarName("NJ301", "DI074"); DI075 = frmMain.staComm.GetVarByStaNameVarName("NJ301", "DI075"); DI076 = frmMain.staComm.GetVarByStaNameVarName("NJ301", "DI076"); DI110 = frmMain.staComm.GetVarByStaNameVarName("NJ301", "DI110"); DI111 = frmMain.staComm.GetVarByStaNameVarName("NJ301", "DI111"); //启动端口数据收发线程 CTran.Setting = CMach.Setting; CTran.fm = this; CTran.Open(); TPortThread = new Thread(new ThreadStart(CTPortThread)); TPortThread.Name = "TPortThread"; TPortThread.IsBackground = true; TPortThread.Start(); splitContainer2.Visible = false; }
private protected CVarDef(string name, object defaultValue, CVar flags, string?desc) { Name = name; DefaultValue = defaultValue; Flags = flags; Desc = desc; }
public void TestBoolDelegateRemoveAllDelegatesInLoop() { CVarChangedDelegate del1 = delegate(CVar cvar) { m_result.Add("delegate1 " + cvar.BoolValue); }; CVarChangedDelegate del2 = delegate(CVar cvar) { m_result.Add("delegate2 " + cvar.BoolValue); }; CVarChangedDelegate del3 = delegate(CVar cvar) { m_result.Add("delegate3 " + cvar.BoolValue); cvar.RemoveDelegates(del1.Target); }; CVar cvarBool = new CVar("bool", false); cvarBool.AddDelegate(del3); cvarBool.AddDelegate(del2); cvarBool.AddDelegate(del1); Execute("bool 1"); AssertList(m_result, "delegate3 True" ); m_result.Clear(); }
protected virtual void RegisterCommandNotifications() { // cvar value changed m_notificationCenter.Register(CCommandNotifications.CVarValueChanged, delegate(CNotification n) { bool manual = n.Get <bool>(CCommandNotifications.KeyManualMode); CVar cvar = n.Get <CVar>(CCommandNotifications.CVarValueChangedKeyVar); CAssert.IsNotNull(cvar); OnCVarValueChanged(cvar, manual); }); // binding changed m_notificationCenter.Register(CCommandNotifications.CBindingsChanged, delegate(CNotification n) { bool manual = n.Get <bool>(CCommandNotifications.KeyManualMode); OnCBindingsChanged(manual); }); // alias changed m_notificationCenter.Register(CCommandNotifications.CAliasesChanged, delegate(CNotification n) { bool manual = n.Get <bool>(CCommandNotifications.KeyManualMode); OnCAliasesChanged(manual); }); }
private void button1_Click(object sender, EventArgs e) { CVar nVar1 = frmMain.staComm.GetVarByStaNameVarName(sListStaName[0], "I_W"); CVar nVar2 = frmMain.staComm.GetVarByStaNameVarName(sListStaName[1], "I_W"); CVar nVar3 = frmMain.staComm.GetVarByStaNameVarName(sListStaName[2], "I_W"); CStation Sta1 = frmMain.staComm.GetStaByStaName(sListStaName[0]); CProtcolModbusTCP STCP1 = (CProtcolModbusTCP)Sta1; CStation Sta2 = frmMain.staComm.GetStaByStaName(sListStaName[1]); CProtcolModbusTCP STCP2 = (CProtcolModbusTCP)Sta2; CStation Sta3 = frmMain.staComm.GetStaByStaName(sListStaName[2]); CProtcolModbusTCP STCP3 = (CProtcolModbusTCP)Sta3; double iValue1 = nVar1.GetDoubleValue() + Convert.ToDouble(textBox1.Text); int fSend1 = (int)Math.Round(iValue1 / nVar1.RatioValue); STCP1.SendAODO(nVar1.ByteAddr, (int)fSend1, 6); double iValue2 = nVar2.GetDoubleValue() + Convert.ToDouble(textBox2.Text); int fSend2 = (int)Math.Round(iValue2 / nVar2.RatioValue); STCP2.SendAODO(nVar3.ByteAddr, (int)fSend2, 6); double iValue3 = nVar3.GetDoubleValue() + Convert.ToDouble(textBox3.Text); int fSend3 = (int)Math.Round(iValue3 / nVar3.RatioValue); STCP3.SendAODO(nVar3.ByteAddr, (int)fSend3, 6); }
public CVar Clone() { CVar varClone = new CVar(); varClone.Name = this.Name; varClone.Desc = this.Desc; varClone.DataType = this.DataType; varClone.Length = this.Length; varClone.BitOffset = this.BitOffset; varClone.ByteOffset = this.ByteOffset; varClone.Unit = this.Unit; varClone.Default = this.Default; varClone.Multiple = this.Multiple; varClone.Table = this.Table; varClone.Memo = this.Memo; varClone.MinValue = this.MinValue; varClone.MaxValue = this.MaxValue; varClone.OwnerMessage = this.OwnerMessage; if (this.Tables != null) { varClone.Tables = new List <CTable>(); varClone.Tables.AddRange(this.Tables); } return(varClone); }
////////////////////////////////////////////////////////////////////////////// #region Config protected virtual void OnCVarValueChanged(CVar cvar, bool manual) { if (manual) { ScheduleSaveConfig(); } }
public void TestBoolDelegateMultipleDelegates() { CVar cvarBool = new CVar("bool", false); cvarBool.AddDelegate(delegate(CVar cvar) { m_result.Add("delegate1 " + cvar.BoolValue); }); cvarBool.AddDelegate(delegate(CVar cvar) { m_result.Add("delegate2 " + cvar.BoolValue); }); cvarBool.AddDelegate(delegate(CVar cvar) { m_result.Add("delegate3 " + cvar.BoolValue); }); Execute("bool 0"); AssertList(m_result); Execute("bool 1"); AssertList(m_result, "delegate1 True", "delegate2 True", "delegate3 True" ); }
public void TestCvarBool2() { CVar cvar = new CVar("var", true); Assert.IsTrue(cvar.IsBool); Assert.IsTrue(cvar.IsInt); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual("1", cvar.DefaultValue); Assert.AreEqual(true, cvar.BoolValue); Assert.AreEqual(1, cvar.IntValue); Assert.AreEqual(1.0f, cvar.FloatValue); Assert.AreEqual("1", cvar.Value); Execute("var 0"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(false, cvar.BoolValue); Assert.AreEqual(0, cvar.IntValue); Assert.AreEqual(0.0f, cvar.FloatValue); Assert.AreEqual("0", cvar.Value); Execute("var 1"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(true, cvar.BoolValue); Assert.AreEqual(1, cvar.IntValue); Assert.AreEqual(1.0f, cvar.FloatValue); Assert.AreEqual("1", cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(true, cvar.BoolValue); Assert.AreEqual(1, cvar.IntValue); Assert.AreEqual(1.0f, cvar.FloatValue); Assert.AreEqual("1", cvar.Value); }
public void Init() { var spawns = Entity.GetByClass <SpawnPoint>(); if (spawns.Count() > 0) { Position = spawns.First().Position; Rotation = spawns.First().Rotation; } View = View.Get(Id); View.Position = Position; View.Rotation = Rotation; View.FieldOfView = Math.DegreesToRadians(60); ReceiveUpdates = true; // Defined in Libs/Config/defaultprofile.xml Input.RegisterAction("zoom_in", OnActionZoomIn); Input.RegisterAction("zoom_out", OnActionZoomOut); Input.MouseEvents += ProcessMouseEvents; MaxZoomLevel = 5; MaxDistanceFromTarget = 100; CurrentZoomLevel = MaxZoomLevel; // The CVar attribute isn't functional at the moment, so we use this workaround. CVar.RegisterInt("g_camMaxZoomLevel", ref MaxZoomLevel); CVar.RegisterFloat("g_camMaxDistanceFromTarget", ref MaxDistanceFromTarget); TargetEntity = Launcher.Instance; }
public void TestListVars() { CRegistery.Clear(); CVar a11 = new CVar("a11", "value"); CVar a12 = new CVar("a12", "value"); CVar b11 = new CVar("b11", "value"); CVar b12 = new CVar("b12", "value"); IList <CVar> vars = CRegistery.ListVars(); AssertList(vars, a11, a12, b11, b12); vars = CRegistery.ListVars("a"); AssertList(vars, a11, a12); vars = CRegistery.ListVars("a1"); AssertList(vars, a11, a12); vars = CRegistery.ListVars("a11"); AssertList(vars, a11); vars = CRegistery.ListVars("a13"); AssertList(vars); }
public override void Initialize(IServiceProvider serviceProvider) { ServiceProvider = serviceProvider; Engine.Server = ServiceProvider.GetRequiredService <IEngineServer>(); Engine.Globals = ServiceProvider.GetRequiredService <IGlobalVars>(); Engine.FileSystem = ServiceProvider.GetRequiredService <IFileSystem>(); Server.Game.Engine.Trace.EngineTrace = ServiceProvider.GetRequiredService <ITrace>(); Engine.EntityDictionary = ServiceProvider.GetRequiredService <IEntityDictionary>(); Engine.EntityRegistry = ServiceProvider.GetRequiredService <IEntityRegistry>(); Engine.Entities = ServiceProvider.GetRequiredService <IEngineEntities>(); Engine.Sound = ServiceProvider.GetRequiredService <ISoundSystem>(); CVar.EngineCVar = ServiceProvider.GetRequiredService <ICVar>(); NetMessage.EngineNetworking = ServiceProvider.GetRequiredService <IEngineNetworking>(); NetMessage.NetworkMessages = ServiceProvider.GetRequiredService <INetworkMessages>(); EntUtils.Initialize(ServiceProvider.GetRequiredService <IEntityDictionary>()); SetupFileSystem(); Globals.g_psv_gravity = CVar.GetCVar("sv_gravity"); Globals.g_psv_aim = CVar.GetCVar("sv_aim"); Globals.g_footsteps = CVar.GetCVar("mp_footsteps"); //Set up our own entities var entities = EntityRegistryUtils.CollectEntityClasses(Assembly.GetExecutingAssembly()); entities.ForEach(i => Engine.EntityRegistry.AddEntityClass(i)); //Link messages now so it gets done LinkUserMessages(); }
void OnVariableGUI(CVar cvar) { if (cvar.IsHidden) { return; } if (cvar.IsDefault) { OnVariableFieldGUI(cvar); } else { GUILayout.BeginHorizontal(); { OnVariableFieldGUI(cvar); GUI.SetNextControlName("Reset Button"); if (GUILayout.Button("Reset", resetButtonStyle, GUILayout.Width(60))) { cvar.Value = cvar.DefaultValue; GUI.FocusControl("Reset Button"); LunarConsole.instance.MarkVariablesDirty(); } } GUILayout.EndHorizontal(); } }
public void TestCvarString() { CVar cvar = new CVar("var", "Default string"); Assert.IsTrue(cvar.IsString); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual("Default string", cvar.DefaultValue); Assert.AreEqual("Default string", cvar.Value); Execute("var 'Some string'"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual("Some string", cvar.Value); Execute("var 'Default string'"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual("Default string", cvar.Value); Execute("var 'Some other string'"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual("Some other string", cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual("Default string", cvar.Value); }
public CLSCurve(string strSta, string strVar) { StaName = strSta; VarName = strVar; cVar = frmMain.staComm.GetVarByStaNameVarName(strSta, strVar); //UpdateReal(); }
public IEnumerable <Type> GetTypes(IEnumerable <Assembly> assemblies) { var scripts = new List <Type>(); foreach (var assembly in assemblies) { var assemblyScripts = ProcessAssembly(assembly); if (assemblyScripts.Count() > 0) { scripts.AddRange(assemblyScripts); } } var compileScriptsCVar = CVar.Get("mono_compileScripts"); if (compileScriptsCVar != null && compileScriptsCVar.IVal != 0) { if (!CompileAndProcess("CSharp", "*.cs", ref scripts) && !CompileAndProcess("VisualBasic", "*.vb", ref scripts)) { Debug.DisplayException(new ScriptCompilationException("No scripts to compile were found in the Game/Scripts directory.\n This is not a fatal error, and can be ignored.")); } } return(scripts); }
public void RegisterCVar <T>(string name, T defaultValue, CVar flags = CVar.NONE, Action <T> onValueChanged = null) { Action <object> valueChangedDelegate = null; if (onValueChanged != null) { valueChangedDelegate = v => onValueChanged((T)v); } if (_configVars.TryGetValue(name, out ConfigVar cVar)) { if (cVar.Registered) { Logger.ErrorS("cfg", $"The variable '{name}' has already been registered."); } cVar.DefaultValue = defaultValue; cVar.Flags = flags; cVar.Registered = true; cVar.ValueChanged = valueChangedDelegate; if (cVar.OverrideValue != null) { cVar.OverrideValueParsed = ParseOverrideValue(cVar.OverrideValue, typeof(T)); } return; } _configVars.Add(name, new ConfigVar(name, defaultValue, flags) { Registered = true, Value = defaultValue, ValueChanged = valueChangedDelegate }); }
public void SetParamValue(CVar Var, Object VarValue) { if (ParamDocument == null) { return; } XmlNode deviceNode = ParamDocument.SelectSingleNode("Device"); XmlElement varNode = (XmlElement)deviceNode.SelectSingleNode("Message/Var[@Name='" + Var.Name + "']"); if (varNode != null) { varNode.SetAttribute("Value", VarValue.ToString()); } else { XmlElement messageNode = (XmlElement)deviceNode.SelectSingleNode("Message[@Index=" + (((CMessage)Var.OwnerMessage).Index).ToString() + "]"); if (messageNode == null) { messageNode = ParamDocument.CreateElement("Message"); messageNode.SetAttribute("Index", (((CMessage)Var.OwnerMessage).Index).ToString()); deviceNode.AppendChild(messageNode); } varNode = ParamDocument.CreateElement("Var"); varNode.SetAttribute("Name", Var.Name); varNode.SetAttribute("Value", VarValue.ToString()); messageNode.AppendChild(varNode); } }
public static CVarDef <T> Create <T>( string name, T defaultValue, CVar flag = CVar.NONE, string?desc = null) where T : notnull { return(new(name, defaultValue, flag, desc)); }
/// <summary> /// Adds a single or list variable with the given value. /// </summary> /// <param name="data">The BotData used for variable replacement and insertion</param> /// <param name="isCapture">Whether the variable should be marked for Capture</param> /// <param name="recursive">Whether the variable to add should be a list or a single value</param> /// <param name="values">The list of values. In case recursive is set to false, only the first value of the list will be taken.</param> /// <param name="variableName">The name of the variable to create</param> /// <param name="prefix">The string to add at the start of the value</param> /// <param name="suffix">The string to add at the end of the value</param> /// <param name="urlEncode">Whether to URLencode the values before creating the variables</param> /// <param name="createEmpty">Whether to create an empty (single) variable if the list of values is empty</param> internal static void InsertVariable(BotData data, bool isCapture, bool recursive, IEnumerable <string> values, string variableName, string prefix = "", string suffix = "", bool urlEncode = false, bool createEmpty = true) { var list = values.Select(v => ReplaceValues(prefix, data) + v.Trim() + ReplaceValues(suffix, data)).ToList(); if (urlEncode) { list = list.Select(v => Uri.EscapeDataString(v)).ToList(); } CVar variable = null; if (recursive) { if (list.Count == 0) { if (createEmpty) { variable = new CVar(variableName, list, isCapture); } } else { variable = new CVar(variableName, list, isCapture); } } else { if (list.Count == 0) { if (createEmpty) { variable = new CVar(variableName, "", isCapture); } } else { variable = new CVar(variableName, list.First(), isCapture); } } // If we don't want to save empty captures, and it's a capture, and the list is either an empty string or a list made of an empty string if (!data.ConfigSettings.SaveEmptyCaptures && isCapture && (list.Count == 0 || list.Count > 0 && string.IsNullOrWhiteSpace(list.First()))) { variable = null; } if (variable != null) { data.Variables.Set(variable); data.Log(new LogEntry("Parsed variable" + " | Name: " + variable.Name + " | Value: " + variable.ToString() + Environment.NewLine, isCapture ? Colors.OrangeRed : Colors.Gold)); } else { data.Log(new LogEntry("Could not parse any data. The variable was not created.", Colors.White)); } }
private void ExecuteCommand(string rawCmd) { string[] parts = rawCmd.Split(' '); string cvarOrCmd = parts[0].ToLower(); if (Array.IndexOf(CVars.GetNames(), cvarOrCmd) > -1) { string value = rawCmd.Substring(cvarOrCmd.Length).Trim(); if (value.Length > 0) { string oldValue = CVars.RawGet(cvarOrCmd).Serialize(); CVars.RawGet(cvarOrCmd).Deserialize(value); Console.WriteLine("Updated `{0}` from '{1}' to '{2}'.", cvarOrCmd, oldValue, value); } else { CVar <bool> boolCVar = CVars.RawGet(cvarOrCmd) as CVar <bool>; if (boolCVar != null) { bool oldValue = boolCVar.Value; boolCVar.Value = !oldValue; Console.WriteLine("Updated `{0}` from '{1}' to '{2}'.", cvarOrCmd, oldValue, boolCVar.Value); } } } else if (cvarOrCmd == "clear") { _consoleItems.Clear(); } else if (cvarOrCmd == "help") { if (parts.Length > 1) { if (Array.IndexOf(CVars.GetNames(), parts[1].ToLower()) > -1) { ICVar rawCVar = CVars.RawGet(parts[1].ToLower()); Console.WriteLine("`{0}`: {1}", parts[1].ToLower(), rawCVar.GetDescription()); Console.WriteLine("\tDefault value: {0}", rawCVar.SerializeDefault()); Console.WriteLine("\tCurrent value: {0}", rawCVar.Serialize()); } else { Console.WriteLine("`{0}` is not a valid CVar.", parts[1]); } } else { Console.WriteLine("Prints the description of a CVar."); Console.WriteLine("Format: `help <cvar name>`"); } } else { Console.WriteLine("CVar `{0}` not found.", cvarOrCmd); } }
public void Register(CVar cvar) { m_vars.Add(cvar); if (m_delegate != null) { m_delegate.OnVariableRegistered(this, cvar); } }
public CVarCommand(CVar cvar) { this.cvar = cvar; this.Name = cvar.Name; this.IsDebug = cvar.IsDebug; this.IsHidden = cvar.IsHidden; this.IsSystem = cvar.IsSystem; }
/// <summary> /// Prepares the CVar system, generating default CVars. /// </summary> public static void Init(Outputter output) { system = new CVarSystem(output); // System CVars s_filepath = Register("s_filepath", FileHandler.BaseDirectory, CVarFlag.Textual | CVarFlag.ReadOnly); // The current system environment filepath (The directory of /data). // Game CVars g_fps = Register("g_fps", "40", CVarFlag.Numeric); // What tickrate to use for the general game tick. }
public CLSCurve(CVar nVar) { cVar = nVar; Text = cVar.StaName + "." + cVar.Name + ":" + cVar.Description; StaName = cVar.StaName; VarName = cVar.Name; //UpdateReal(); }
public CVarSetPacketOut(CVar var, Server tserver) { UsageType = NetUsageType.GENERAL; ID = ServerToClientPacket.CVAR_SET; DataStream ds = new DataStream(); DataWriter dw = new DataWriter(ds); dw.WriteInt(tserver.Networking.Strings.IndexForString(var.Name.ToLowerFast())); dw.WriteFullString(var.Value); Data = ds.ToArray(); }
////////////////////////////////////////////////////////////////////////////// private void ConsoleVariableChanged(Notification notification) { CVar cvar = notification.GetData <CVar>(); if (cvar == CVars.roundsToWin) { int totalRounds = cvar.intValue; m_totalRounds = Math.Max(totalRounds, roundIndex + 1); } }
protected virtual bool Execute() { CVar cvar = ResolveCvar(this.Identifier); if (cvar != null) { return(ExecuteCvar(cvar)); } return(false); }
public void RegisterCVar <T>(string name, T defaultValue, CVar flags = CVar.NONE, Action <T>?onValueChanged = null) { Action <object>?valueChangedDelegate = null; if (onValueChanged != null) { valueChangedDelegate = v => onValueChanged((T)v); } RegisterCVar(name, typeof(T), defaultValue, flags, valueChangedDelegate); }
public override void Precache() { // Do all of this in here because we need to 'convert' old saved games Solid = Solid.Not; Skin = (int)Contents.Ladder; if (CVar.GetFloat("showtriggers") == 0) { RenderMode = RenderMode.TransTexture; RenderAmount = 0; } Effects &= ~EntityEffects.NoDraw; }
public void TestDelegates() { bool delegateCalled = false; CVar cvar = new CVar("var", "Default value"); cvar.AddDelegate(delegate(CVar v) { delegateCalled = true; }); Execute("bind v 'var value'"); TapKeys(KeyCode.V); Assert.IsTrue(delegateCalled); }
////////////////////////////////////////////////////////////////////////////// #region CVars private bool ExecuteCvar(CVar cvar) { switch (this.Operation) { case kOpPlus: { cvar.BoolValue = true; return true; } case kOpMinus: { cvar.BoolValue = false; return true; } } PrintError("Unknown operation: '{0}'", this.Operation.ToString()); return false; }
/// <summary> /// Prepares the CVar system, generating default CVars. /// </summary> public void Init(Server tserver, Outputter output) { system = new CVarSystem(output); // System CVars s_filepath = Register("s_filepath", tserver.Files.BaseDirectory, CVarFlag.Textual | CVarFlag.ReadOnly, "The current system environment filepath (The directory of /data)."); // TODO: Scrap this! Tags! s_debug = Register("s_debug", "true", CVarFlag.Boolean, "Whether to output debug information."); // Game CVars //g_timescale = Register("g_timescale", "1", CVarFlag.Numeric, "The current game time scaling value."); g_fps = Register("g_fps", "30", CVarFlag.Numeric, "What framerate to use."); g_maxheight = Register("g_maxheight", "5000", CVarFlag.Numeric, "What the highest possible Z coordinate should be (for building)."); // TODO: Also per-world? g_minheight = Register("g_minheight", "-5000", CVarFlag.Numeric, "What the lowest possible Z coordinate should be (for building)."); // TODO: Also per-world? g_maxdist = Register("g_maxdist", "50000", CVarFlag.Numeric, "How far on the X or Y axis a player may travel from the origin."); // TODO: Also per-world? g_renderblocks = Register("g_renderblocks", "false", CVarFlag.Boolean, "Whether to render blocks for mapping purposes."); // TODO: Also per-world? // Network CVars n_verifyip = Register("n_verifyip", "true", CVarFlag.Boolean, "Whether to verify connecting users' IP addresses with the global server. Disabling this may help allow LAN connections."); n_rendersides = Register("n_rendersides", "false", CVarFlag.Boolean, "Whether to render the side-on map view for the linked webpage."); // TODO: Also per-world? n_chunkspertick = Register("n_chunkspertick", "15", CVarFlag.Numeric, "How many chunks can be sent in a single server tick, per player."); n_online = Register("n_online", "true", CVarFlag.Boolean, "Whether the server with authorize connections against the global server. Disable this if you want to play singleplayer without a live internet connection."); // Text CVars t_translateurls = Register("t_translateurls", "true", CVarFlag.Boolean, "Whether to automatically translate URLs posted in chat."); t_blockurls = Register("t_blockurls", "false", CVarFlag.Boolean, "Whether to block URLs as input to chat."); t_blockcolors = Register("t_blockcolors", "false", CVarFlag.Boolean, "Whether to block colors as input to chat."); }
public void TestListVars() { CRegistery.Clear(); CVar a11 = new CVar("a11", "value"); CVar a12 = new CVar("a12", "value"); CVar b11 = new CVar("b11", "value"); CVar b12 = new CVar("b12", "value"); IList<CVar> vars = CRegistery.ListVars(); AssertList(vars, a11, a12, b11, b12); vars = CRegistery.ListVars("a"); AssertList(vars, a11, a12); vars = CRegistery.ListVars("a1"); AssertList(vars, a11, a12); vars = CRegistery.ListVars("a11"); AssertList(vars, a11); vars = CRegistery.ListVars("a13"); AssertList(vars); }
////////////////////////////////////////////////////////////////////////////// #region Cvars public static bool Register(CVar cvar) { return Register(new CVarCommand(cvar)); }
public CVarItem(string varname, string[] values) : base(varname) { Values = values; cvar = CVar.Get(varname); }
public void TestHoldPositiveKeyBoolVar() { CVar cvar = new CVar("bool", false); Execute("bind mouse0 +bool"); PressKeys(KeyCode.Mouse0); Assert.IsTrue(cvar.BoolValue); RunUpdate(); Assert.IsTrue(cvar.BoolValue); RunUpdate(); Assert.IsTrue(cvar.BoolValue); ReleaseKeys(KeyCode.Mouse0); Assert.IsFalse(cvar.BoolValue); }
public void TestCvarVector2() { float x = 1.2f; float y = 3.4f; Vector2 value = new Vector2(x, y); string valueString = string.Format("{0} {1}", x, y); CVar cvar = new CVar("var", value); Assert.IsTrue(cvar.IsVector2); Assert.AreEqual(valueString, cvar.DefaultValue); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(value, cvar.Vector2Value); Assert.AreEqual(new Vector3(x, y), cvar.Vector3Value); Assert.AreEqual(new Vector4(x, y), cvar.Vector4Value); Assert.AreEqual(valueString, cvar.Value); Vector2 anotherValue = new Vector2(-1.2f, -3.4f); string anotherValueString = string.Format("{0} {1}", anotherValue.x, anotherValue.y); Execute("var {0} {1}", anotherValue.x, anotherValue.y ); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(anotherValue, cvar.Vector2Value); Assert.AreEqual(new Vector3(anotherValue.x, anotherValue.y), cvar.Vector3Value); Assert.AreEqual(new Vector4(anotherValue.x, anotherValue.y), cvar.Vector4Value); Assert.AreEqual(anotherValueString, cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(value, cvar.Vector2Value); Assert.AreEqual(new Vector3(x, y), cvar.Vector3Value); Assert.AreEqual(new Vector4(x, y), cvar.Vector4Value); Assert.AreEqual(valueString, cvar.Value); }
public void TestCvarString2() { CVar cvar = new CVar("var", null); Assert.IsTrue(cvar.IsString); Assert.IsTrue(cvar.IsDefault); Assert.IsNull(cvar.DefaultValue); Assert.IsNull(cvar.Value); Execute("var 'Some string'"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual("Some string", cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.IsNull(cvar.Value); }
/// <summary> /// Prepares the CVar system, generating default CVars. /// </summary> public void Init(Client tclient, Outputter output) { system = new CVarSystem(output); // System CVars s_filepath = Register("s_filepath", tclient.Files.BaseDirectory, CVarFlag.Textual | CVarFlag.ReadOnly, "The current system environment filepath (The directory of /data)."); // TODO: Tag! s_glversion = Register("s_glversion", "UNKNOWN", CVarFlag.Textual | CVarFlag.ReadOnly, "What version of OpenGL is in use."); s_glrenderer = Register("s_glrenderer", "UNKNOWN", CVarFlag.Textual | CVarFlag.ReadOnly, "What renderer for OpenGL is in use."); s_glvendor = Register("s_glvendor", "UNKNOWN", CVarFlag.Textual | CVarFlag.ReadOnly, "What graphics card vendor made the device being used for rendering."); // Game CVars g_timescale = Register("g_timescale", "1", CVarFlag.Numeric | CVarFlag.ServerControl, "The current game time scale value."); g_firstperson = Register("g_firstperson", "true", CVarFlag.Boolean, "Whether to be in FirstPerson view mode."); g_weathermode = Register("g_weathermode", "0", CVarFlag.Numeric | CVarFlag.ServerControl, "What weather mode is currently shown. 0 = none, 1 = rain, 2 = snow."); // Network CVars n_first = Register("n_first", "ipv4", CVarFlag.Textual, "Whether to prefer IPv4 or IPv6."); n_debugmovement = Register("n_debugmovement", "false", CVarFlag.Boolean, "Whether to debug movement networking."); n_movement_maxdistance = Register("n_movement_maxdistance", "20", CVarFlag.Numeric, "How far apart the client can move from the serverside player before snapping to the correct location."); n_movement_adjustment = Register("n_movement_adjustment", "0.1", CVarFlag.Numeric, "How rapidly to adjust the player's position to better match the server. Smaller numbers yield quicker results."); n_movemode = Register("n_movemode", "2", CVarFlag.Numeric, "Which movement mode to use. 1 = run-and-adjust, 2 = back-trace."); n_ourvehiclelerp = Register("n_ourvehiclelerp", "0.1", CVarFlag.Numeric, "How strongly to lerp our own vehicle's movement."); n_online = Register("n_online", "true", CVarFlag.Boolean, "Whether to only connect to servers with a valid login key. Disable this to play singleplayer without internet."); // Renderer CVars r_fullscreen = Register("r_fullscreen", "false", CVarFlag.Boolean | CVarFlag.Delayed, "Whether to use fullscreen mode."); r_width = Register("r_width", "1280", CVarFlag.Numeric | CVarFlag.Delayed, "What width the window should be."); r_height = Register("r_height", "720", CVarFlag.Numeric | CVarFlag.Delayed, "What height the window should be."); r_vsync = Register("r_vsync", "true", CVarFlag.Boolean, "Whether to use vertical synchronization mode."); r_lighting = Register("r_lighting", "true", CVarFlag.Boolean, "Whether to enable 3D lighting (Otherwise, use FullBright)."); r_renderwireframe = Register("r_renderwireframe", "false", CVarFlag.Boolean, "Whether to render a wireframe."); r_fov = Register("r_fov", "70", CVarFlag.Numeric, "What Field of Vision range value to use."); r_znear = Register("r_znear", "0.1", CVarFlag.Numeric, "How close the near plane should be to the camera."); r_zfar = Register("r_zfar", "3500", CVarFlag.Numeric, "How far the far plane should be from the camera."); r_dof_strength = Register("r_dof_strength", "4", CVarFlag.Numeric, "How strong the Depth Of Field effect should be."); r_maxfps = Register("r_maxfps", "60", CVarFlag.Numeric | CVarFlag.Delayed, "What the FPS cap should be."); r_lightmaxdistance = Register("r_lightmaxdistance", "35", CVarFlag.Numeric, "How far away a light can be from the camera before it is disabled."); r_fallbacklighting = Register("r_fallbacklighting", "true", CVarFlag.Boolean, "Whether to calculate fallback block lighting (Requires chunk reload)."); r_shadowquality = Register("r_shadowquality", "1024", CVarFlag.Numeric, "What texture size to use for shadow maps."); r_shadowblur = Register("r_shadowblur", "0.25", CVarFlag.Numeric, "What factor to use for shadow blurring. Smaller = blurrier."); r_shadowpace = Register("r_shadowpace", "1", CVarFlag.Numeric, "How rapidly to rerender shadows, in frames."); r_shadows = Register("r_shadows", "false", CVarFlag.Boolean, "Whether to render shadows at all."); r_cloudshadows = Register("r_cloudshadows", "false", CVarFlag.Boolean, "Whether to display shadows from clouds."); r_good_graphics = Register("r_good_graphics", "true", CVarFlag.Boolean | CVarFlag.Delayed, "Whether to use 'good' graphics."); // TODO: Callback to auto-set r_skybox = Register("r_skybox", "default", CVarFlag.ServerControl | CVarFlag.Textual, "What skybox to use."); r_blocktexturelinear = Register("r_blocktexturelinear", "true", CVarFlag.Boolean | CVarFlag.Delayed, "Whether block textures are to use a linear blur or nearest-pixel mode."); r_blocktexturewidth = Register("r_blocktexturewidth", "256", CVarFlag.Numeric | CVarFlag.Delayed, "What texture width (pixels) block textures should use."); r_toonify = Register("r_toonify", "false", CVarFlag.Boolean, "Whether to use a 'toonify' post-processing effect."); r_transplighting = Register("r_transplighting", "true", CVarFlag.Boolean, "Whether transparent objects should be lit properly (otherwise, fullbright)."); r_transpshadows = Register("r_transpshadows", "false", CVarFlag.Boolean, "Whether transparent objects should be lit using HD shadows (Requires r_shadows true)."); r_3d_enable = Register("r_3d_enable", "false", CVarFlag.Boolean, "Whether to use 3D side-by-side rendering mode."); r_fast = Register("r_fast", "false", CVarFlag.Boolean, "Whether to use 'fast' rendering mode."); r_chunksatonce = Register("r_chunksatonce", "100", CVarFlag.Numeric, "How many chunks can render at once."); r_chunkoverrender = Register("r_chunkoverrender", "true", CVarFlag.Boolean, "Whether to render chunks more often for quality's sake, at risk of performance."); r_transpll = Register("r_transpll", "false", CVarFlag.Boolean, "Whether to use GPU linked lists when rendering transparent objects."); r_noblockshapes = Register("r_noblockshapes", "false", CVarFlag.Boolean, "Whether block shapes are disabled or not."); r_treeshadows = Register("r_treeshadows", "true", CVarFlag.Boolean, "Whether trees cast shadows."); r_godrays = Register("r_godrays", "true", CVarFlag.Boolean, "Whether to render GodRays (rays of light from the sun."); // TODO: Validate? r_hdr = Register("r_hdr", "true", CVarFlag.Boolean, "Whether to render with high dynamic range adjustments enabled."); r_chunkmarch = Register("r_chunkmarch", "false", CVarFlag.Boolean, "Whether to use 'chunk marching' method to render chunks (if false, uses a generic loop)."); r_clouds = Register("r_clouds", "true", CVarFlag.Boolean, "Whether to render clouds."); // TODO: Inform the server of this to reduce bandwidth. r_motionblur = Register("r_motionblur", "false", CVarFlag.Boolean, "Whether to blur the screen to better represent motion."); r_plants = Register("r_plants", "true", CVarFlag.Boolean, "Whether to render small plants around the view."); // Audio CVars a_musicvolume = Register("a_musicvolume", "0.5", CVarFlag.Numeric, "What volume the music should be."); a_musicpitch = Register("a_musicpitch", "1", CVarFlag.Numeric, "What pitch the music should be."); a_globalvolume = Register("a_globalvolume", "1", CVarFlag.Numeric, "What volume all sounds should be."); a_globalpitch = Register("a_globalpitch", "1", CVarFlag.Numeric, "What pitch all sounds should be."); a_music = Register("a_music", "music/epic/bcvoxalia_adventure", CVarFlag.Textual | CVarFlag.ServerControl, "What music should be played."); a_quietondeselect = Register("a_quietondeselect", "true", CVarFlag.Boolean, "Whether to quiet music when the window is deselected."); a_echovolume = Register("a_echovolume", "0", CVarFlag.Numeric, "What volume to echo microphone pickup at, for audio testing purposes. Specify 0 to not listen to the microphone at all."); // UI CVars u_mouse_sensitivity = Register("u_mouse_sensitivity", "1", CVarFlag.Numeric, "How sensitive the mouse is."); u_reticle = Register("u_reticle", "1", CVarFlag.Textual, "What reticle to use."); u_reticlescale = Register("u_reticlescale", "32", CVarFlag.Numeric, "How big the reticle should be."); u_showhud = Register("u_showhud", "true", CVarFlag.Boolean, "Whether to render the HUD."); u_highlight_targetblock = Register("u_highlight_targetblock", "true", CVarFlag.Boolean, "Whether to highlight the targeted block."); u_highlight_placeblock = Register("u_highlight_placeblock", "true", CVarFlag.Boolean, "Whether to highlight the targeted placement block."); u_debug = Register("u_debug", "false", CVarFlag.Boolean, "Whether to display debug information on the HUD."); u_showmap = Register("u_showmap", "false", CVarFlag.Boolean | CVarFlag.ServerControl, "Whether to display a map on the HUD."); u_showrangefinder = Register("u_showrangefinder", "false", CVarFlag.Boolean | CVarFlag.ServerControl, "Whether to display a range finder on the HUD."); u_showping = Register("u_showping", "true", CVarFlag.Boolean, "Whether to display the current ping on the UI."); u_showcompass = Register("u_showcompass", "false", CVarFlag.Boolean | CVarFlag.ServerControl, "Whether to display a compass on the HUD."); u_colortyping = Register("u_colortyping", "false", CVarFlag.Boolean, "Whether to color the text currently being typed typed (chat, console, ...)."); }
public void TestReadConfigVars() { WriteVarsConfig(); CVar c_int = new CVar("int", 10); CVar c_bool = new CVar("bool", true); CVar c_float = new CVar("float", 3.14f); CVar c_string = new CVar("string", "Default string"); // load default config Execute("exec " + Constants.ConfigDefault); // TODO: make a convinience method for it // check loaded values Assert.AreEqual(20, c_int.IntValue); Assert.AreEqual(false, c_bool.BoolValue); Assert.AreEqual(6.28f, c_float.FloatValue); Assert.AreEqual("New value", c_string.Value); }
public static bool Unregister(CVar cvar) { CCommand cmd = FindCvarCommand(cvar.Name); return cmd != null && Unregister(cmd); }
public void TestCvarColor() { Color color = ColorUtils.FromRGBA(0x12345678); string colorDefault = string.Format("{0} {1} {2} {3}", color.r, color.g, color.b, color.a); CVar cvar = new CVar("var", color); Assert.IsTrue(cvar.IsColor); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(colorDefault, cvar.DefaultValue); Assert.AreEqual(color, cvar.ColorValue); Assert.AreEqual(0x12345678, cvar.IntValue); Assert.AreEqual(colorDefault, cvar.Value); Color otherColor = new Color(0.1f, 0.2f, 0.3f, 0.4f); uint otherColorValue = ColorUtils.ToRGBA(ref otherColor); Execute("var 0.1 0.2 0.3 0.4"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(otherColor, cvar.ColorValue); Assert.AreEqual(otherColorValue, (uint)cvar.IntValue); Assert.AreEqual("0.1 0.2 0.3 0.4", cvar.Value); otherColorValue = 0x87654321; otherColor = ColorUtils.FromRGBA(0x87654321); Execute("var 0x{0}", otherColorValue.ToString("X")); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(otherColor, cvar.ColorValue); Assert.AreEqual(otherColorValue, (uint)cvar.IntValue); Assert.AreEqual("0.5294118 0.3960785 0.2627451 0.1294118", cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(colorDefault, cvar.Value); Assert.AreEqual(color, cvar.ColorValue); Assert.AreEqual(0x12345678, cvar.IntValue); }
public void TestCvarFloat() { CVar cvar = new CVar("var", 3.14f); Assert.IsTrue(cvar.IsFloat); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual("3.14", cvar.DefaultValue); Assert.AreEqual(3, cvar.IntValue); Assert.AreEqual(3.14f, cvar.FloatValue); Assert.AreEqual("3.14", cvar.Value); Execute("var -3.14"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(-3, cvar.IntValue); Assert.AreEqual(-3.14f, cvar.FloatValue); Assert.AreEqual("-3.14", cvar.Value); Execute("var 3.14"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(3, cvar.IntValue); Assert.AreEqual(3.14f, cvar.FloatValue); Assert.AreEqual("3.14", cvar.Value); Execute("var 0"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(0, cvar.IntValue); Assert.AreEqual(0.0f, cvar.FloatValue); Assert.AreEqual("0", cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(3, cvar.IntValue); Assert.AreEqual(3.14f, cvar.FloatValue); Assert.AreEqual("3.14", cvar.Value); }
public void TestCvarInt() { CVar cvar = new CVar("var", 128); Assert.IsTrue(cvar.IsInt); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual("128", cvar.DefaultValue); Assert.AreEqual(128, cvar.IntValue); Assert.AreEqual(128.0f, cvar.FloatValue); Assert.AreEqual("128", cvar.Value); Execute("var -128"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(-128, cvar.IntValue); Assert.AreEqual(-128.0f, cvar.FloatValue); Assert.AreEqual("-128", cvar.Value); Execute("var 128"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(128, cvar.IntValue); Assert.AreEqual(128.0f, cvar.FloatValue); Assert.AreEqual("128", cvar.Value); Execute("var 0"); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(0, cvar.IntValue); Assert.AreEqual(0.0f, cvar.FloatValue); Assert.AreEqual("0", cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(128, cvar.IntValue); Assert.AreEqual(128.0f, cvar.FloatValue); Assert.AreEqual("128", cvar.Value); }
public void TestCvarRect() { float x = 1.2f; float y = 3.4f; float w = 5.6f; float h = 7.8f; Rect rect = new Rect(x, y, w, h); string rectValue = string.Format("{0} {1} {2} {3}", rect.x, rect.y, rect.width, rect.height); CVar cvar = new CVar("var", rect); Assert.IsTrue(cvar.IsRect); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(rectValue, cvar.DefaultValue); Assert.AreEqual(rect, cvar.RectValue); Assert.AreEqual(new Color(x, y, w, h), cvar.ColorValue); Assert.AreEqual(new Vector2(x, y), cvar.Vector2Value); Assert.AreEqual(new Vector3(x, y, w), cvar.Vector3Value); Assert.AreEqual(new Vector4(x, y, w, h), cvar.Vector4Value); Assert.AreEqual(rectValue, cvar.Value); Rect anotherRect = new Rect(-1.2f, -3.4f, -5.6f, -7.8f); string anotherRectValue = string.Format("{0} {1} {2} {3}", anotherRect.x, anotherRect.y, anotherRect.width, anotherRect.height); Execute("var {0}", anotherRectValue); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(anotherRect, cvar.RectValue); Assert.AreEqual(new Vector2(anotherRect.x, anotherRect.y), cvar.Vector2Value); Assert.AreEqual(new Vector3(anotherRect.x, anotherRect.y, anotherRect.width), cvar.Vector3Value); Assert.AreEqual(new Vector4(anotherRect.x, anotherRect.y, anotherRect.width, anotherRect.height), cvar.Vector4Value); Assert.AreEqual(anotherRectValue, cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(new Color(x, y, w, h), cvar.ColorValue); Assert.AreEqual(new Vector2(x, y), cvar.Vector2Value); Assert.AreEqual(new Vector3(x, y, w), cvar.Vector3Value); Assert.AreEqual(new Vector4(x, y, w, h), cvar.Vector4Value); Assert.AreEqual(rectValue, cvar.Value); }
public override bool compare(CVar var, Posision pos, EnegyData data, VariabelDatabase db) { return var.type() == type() && var.toBoolean(pos, data, db) == toBoolean(pos, data, db);//here wee control if it is same as this }
public void TestDelegatesOperationCommand() { string delegateValue = null; CVar cvar = new CVar("var", false); cvar.AddDelegate(delegate(CVar v) { delegateValue = v.BoolValue.ToString(); }); Execute("bind v +var"); PressKeys(KeyCode.V); Assert.AreEqual("True", delegateValue); ReleaseKeys(KeyCode.V); Assert.AreEqual("False", delegateValue); }
public override bool compare(CVar var, Posision pos, EnegyData data, VariabelDatabase db) { return var.type() == type(); }
public abstract bool compare(CVar var, Posision pos, EnegyData data, VariabelDatabase db);
public void TestCvarVector4() { float x = 1.2f; float y = 3.4f; float z = 5.6f; float w = 7.8f; Vector4 value = new Vector4(x, y, z, w); string valueString = string.Format("{0} {1} {2} {3}", x, y, z, w); CVar cvar = new CVar("var", value); Assert.IsTrue(cvar.IsVector4); Assert.AreEqual(valueString, cvar.DefaultValue); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(value, cvar.Vector4Value); Assert.AreEqual(new Vector2(x, y), cvar.Vector2Value); Assert.AreEqual(new Vector3(x, y, z), cvar.Vector3Value); Assert.AreEqual(valueString, cvar.Value); Vector4 anotherValue = new Vector4(-1.2f, -3.4f, -5.6f, -7.8f); string anotherValueString = string.Format("{0} {1} {2} {3}", anotherValue.x, anotherValue.y, anotherValue.z, anotherValue.w); Execute("var {0} {1} {2} {3}", anotherValue.x, anotherValue.y, anotherValue.z, anotherValue.w ); Assert.IsFalse(cvar.IsDefault); Assert.AreEqual(anotherValue, cvar.Vector4Value); Assert.AreEqual(new Vector2(anotherValue.x, anotherValue.y), cvar.Vector2Value); Assert.AreEqual(new Vector3(anotherValue.x, anotherValue.y, anotherValue.z), cvar.Vector3Value); Assert.AreEqual(anotherValueString, cvar.Value); Execute("reset var"); Assert.IsTrue(cvar.IsDefault); Assert.AreEqual(value, cvar.Vector4Value); Assert.AreEqual(new Vector2(x, y), cvar.Vector2Value); Assert.AreEqual(new Vector3(x, y, z), cvar.Vector3Value); Assert.AreEqual(valueString, cvar.Value); }