DerJantob / TSW2_Controller

Control TSW2 with a joystick or other controllers
25 stars 4 forks source link

Simple code cleanup #50

Closed asdf1280 closed 1 year ago

asdf1280 commented 1 year ago

in FormMain.cs

        public void ReadTrainNamesFromTrainconfig()
        {
            trainNames.Clear();
            comboBox_Zugauswahl.Items.Clear();
            comboBox_Zugauswahl.Items.Add(Sprache.Translate("_Zugauswahl", "_Select train"));
            comboBox_Zugauswahl.SelectedItem = Sprache.Translate("_Zugauswahl", "_Select train");

            foreach (string[] str in trainConfig)
            {
                bool alreadyExists = false;
                foreach (string tN in trainNames)
                {
                    if (str[0] == tN)
                    {
                        alreadyExists = true;
                    }
                }

                if (!alreadyExists && str[0] != "Zug" && str[0] != Tcfg.nameForGlobal)
                {
                    trainNames.Add(str[0]);
                }
            }
            comboBox_Zugauswahl.Items.AddRange(trainNames.ToArray());
        }

Optimized code:

                bool alreadyExists = trainNames.Contains(str[0]);
asdf1280 commented 1 year ago
        void stickHandle(Joystick stick, int id)
        {
            try
            {
                bool[] buttons;
                int[] joyInputs = new int[8];

                JoystickState state = new JoystickState();

                //Bekomme alle Infos über den mit id ausgewählten Stick
                state = stick.GetCurrentState();

Possible unnecessary construction that can lead to leaked memory and unnecessary GC

                JoystickState state = stick.GetCurrentState();
DerJantob commented 1 year ago

Thank you for the suggestions! I have saved your changes in the develop branch. However, I would say that it's not worth releasing it as an update yet. Once a few more improvements or features accumulate, I will release it :)

Regards Jannik